@@ -153,18 +153,18 @@ |
||
153 | 153 | |
154 | 154 | |
155 | 155 | /** |
156 | - * This loads scripts and styles for the EE_Admin system |
|
157 | - * that must be available on ALL WP admin pages (i.e. EE_menu items) |
|
158 | - * |
|
156 | + * This loads scripts and styles for the EE_Admin system |
|
157 | + * that must be available on ALL WP admin pages (i.e. EE_menu items) |
|
158 | + * |
|
159 | 159 | * @return void |
160 | 160 | */ |
161 | 161 | public function load_wp_global_scripts_styles() { |
162 | 162 | wp_register_style( |
163 | - 'espresso_menu', |
|
164 | - EE_ADMIN_URL . 'assets/admin-menu-styles.css', |
|
165 | - array('dashicons'), |
|
166 | - EVENT_ESPRESSO_VERSION |
|
167 | - ); |
|
163 | + 'espresso_menu', |
|
164 | + EE_ADMIN_URL . 'assets/admin-menu-styles.css', |
|
165 | + array('dashicons'), |
|
166 | + EVENT_ESPRESSO_VERSION |
|
167 | + ); |
|
168 | 168 | wp_enqueue_style('espresso_menu'); |
169 | 169 | } |
170 | 170 |
@@ -88,16 +88,16 @@ discard block |
||
88 | 88 | $this->_set_init_properties(); |
89 | 89 | |
90 | 90 | //global styles/scripts across all wp admin pages |
91 | - add_action('admin_enqueue_scripts', array($this, 'load_wp_global_scripts_styles'), 5 ); |
|
91 | + add_action('admin_enqueue_scripts', array($this, 'load_wp_global_scripts_styles'), 5); |
|
92 | 92 | |
93 | 93 | //load initial stuff. |
94 | 94 | $this->_set_file_and_folder_name(); |
95 | 95 | |
96 | 96 | $this->_set_menu_map(); |
97 | 97 | |
98 | - if ( empty( $this->_menu_map ) || is_array( $this->_menu_map ) ) |
|
98 | + if (empty($this->_menu_map) || is_array($this->_menu_map)) |
|
99 | 99 | { |
100 | - EE_Error::doing_it_wrong( get_class( $this ) . '::$_menu_map', sprintf( __('The EE4 addon with the class %s is setting up the _menu_map property incorrectly for this version of EE core. Please see Admin_Page_Init class examples in core for the new way of setting this property up.', 'event_espresso' ), get_class( $this ) ), '4.4.0' ); |
|
100 | + EE_Error::doing_it_wrong(get_class($this).'::$_menu_map', sprintf(__('The EE4 addon with the class %s is setting up the _menu_map property incorrectly for this version of EE core. Please see Admin_Page_Init class examples in core for the new way of setting this property up.', 'event_espresso'), get_class($this)), '4.4.0'); |
|
101 | 101 | return; |
102 | 102 | } |
103 | 103 | |
@@ -161,7 +161,7 @@ discard block |
||
161 | 161 | public function load_wp_global_scripts_styles() { |
162 | 162 | wp_register_style( |
163 | 163 | 'espresso_menu', |
164 | - EE_ADMIN_URL . 'assets/admin-menu-styles.css', |
|
164 | + EE_ADMIN_URL.'assets/admin-menu-styles.css', |
|
165 | 165 | array('dashicons'), |
166 | 166 | EVENT_ESPRESSO_VERSION |
167 | 167 | ); |
@@ -193,8 +193,8 @@ discard block |
||
193 | 193 | |
194 | 194 | |
195 | 195 | protected function _set_capability() { |
196 | - $capability = empty($this->capability) ? $this->_menu_map->capability : $this->capability; |
|
197 | - $this->capability = apply_filters( 'FHEE_' . $this->_menu_map->menu_slug . '_capability', $capability ); |
|
196 | + $capability = empty($this->capability) ? $this->_menu_map->capability : $this->capability; |
|
197 | + $this->capability = apply_filters('FHEE_'.$this->_menu_map->menu_slug.'_capability', $capability); |
|
198 | 198 | } |
199 | 199 | |
200 | 200 | |
@@ -212,7 +212,7 @@ discard block |
||
212 | 212 | public function initialize_admin_page() { |
213 | 213 | //let's check user access first |
214 | 214 | $this->_check_user_access(); |
215 | - if ( !is_object( $this->_loaded_page_object) ) return; |
|
215 | + if ( ! is_object($this->_loaded_page_object)) return; |
|
216 | 216 | $this->_loaded_page_object->route_admin_request(); |
217 | 217 | return; |
218 | 218 | } |
@@ -224,25 +224,25 @@ discard block |
||
224 | 224 | |
225 | 225 | |
226 | 226 | public function set_page_dependencies($wp_page_slug) { |
227 | - if ( !$this->_load_page ) return; |
|
227 | + if ( ! $this->_load_page) return; |
|
228 | 228 | |
229 | - if ( !is_object($this->_loaded_page_object) ) { |
|
229 | + if ( ! is_object($this->_loaded_page_object)) { |
|
230 | 230 | $msg[] = __('We can\'t load the page because we\'re missing a valid page object that tells us what to load', 'event_espresso'); |
231 | - $msg[] = $msg[0] . "\r\n" . sprintf( |
|
231 | + $msg[] = $msg[0]."\r\n".sprintf( |
|
232 | 232 | __('The custom slug you have set for this page is %s. This means we\'re looking for the class %s_Admin_Page (found in %s_Admin_Page.core.php) within your %s directory', 'event_espresso'), |
233 | 233 | $this->_file_name, |
234 | 234 | $this->_file_name, |
235 | - $this->_folder_path . $this->_file_name, |
|
235 | + $this->_folder_path.$this->_file_name, |
|
236 | 236 | $this->_menu_map->menu_slug |
237 | 237 | ); |
238 | - throw new EE_Error( implode( '||', $msg) ); |
|
238 | + throw new EE_Error(implode('||', $msg)); |
|
239 | 239 | } |
240 | 240 | |
241 | 241 | $this->_loaded_page_object->set_wp_page_slug($wp_page_slug); |
242 | - $page_hook = 'load-' . $wp_page_slug; |
|
242 | + $page_hook = 'load-'.$wp_page_slug; |
|
243 | 243 | //hook into page load hook so all page specific stuff get's loaded. |
244 | - if ( !empty($wp_page_slug) ) |
|
245 | - add_action($page_hook, array($this->_loaded_page_object, 'load_page_dependencies') ); |
|
244 | + if ( ! empty($wp_page_slug)) |
|
245 | + add_action($page_hook, array($this->_loaded_page_object, 'load_page_dependencies')); |
|
246 | 246 | } |
247 | 247 | |
248 | 248 | |
@@ -253,7 +253,7 @@ discard block |
||
253 | 253 | */ |
254 | 254 | public function do_initial_loads() { |
255 | 255 | //no loading or initializing if menu map is setup incorrectly. |
256 | - if ( empty( $this->_menu_map ) || is_array( $this->_menu_map ) ) { |
|
256 | + if (empty($this->_menu_map) || is_array($this->_menu_map)) { |
|
257 | 257 | return; |
258 | 258 | } |
259 | 259 | $this->_initialize_admin_page(); |
@@ -270,19 +270,19 @@ discard block |
||
270 | 270 | $bt = debug_backtrace(); |
271 | 271 | //for more reliable determination of folder name |
272 | 272 | //we're using this to get the actual folder name of the CALLING class (i.e. the child class that extends this). Why? Because $this->menu_slug may be different than the folder name (to avoid conflicts with other plugins) |
273 | - $class = get_class( $this ); |
|
274 | - foreach ( $bt as $index => $values ) { |
|
275 | - if ( isset( $values['class'] ) && $values['class'] == $class ) { |
|
273 | + $class = get_class($this); |
|
274 | + foreach ($bt as $index => $values) { |
|
275 | + if (isset($values['class']) && $values['class'] == $class) { |
|
276 | 276 | $file_index = $index - 1; |
277 | - $this->_folder_name = basename(dirname($bt[$file_index]['file']) ); |
|
278 | - if ( !empty( $this->_folder_name ) ) break; |
|
277 | + $this->_folder_name = basename(dirname($bt[$file_index]['file'])); |
|
278 | + if ( ! empty($this->_folder_name)) break; |
|
279 | 279 | } |
280 | 280 | } |
281 | 281 | |
282 | - $this->_folder_path = EE_ADMIN_PAGES . $this->_folder_name . DS; |
|
282 | + $this->_folder_path = EE_ADMIN_PAGES.$this->_folder_name.DS; |
|
283 | 283 | |
284 | - $this->_file_name = preg_replace( '/^ee/' , 'EE', $this->_folder_name ); |
|
285 | - $this->_file_name = ucwords( str_replace('_', ' ', $this->_file_name) ); |
|
284 | + $this->_file_name = preg_replace('/^ee/', 'EE', $this->_folder_name); |
|
285 | + $this->_file_name = ucwords(str_replace('_', ' ', $this->_file_name)); |
|
286 | 286 | $this->_file_name = str_replace(' ', '_', $this->_file_name); |
287 | 287 | } |
288 | 288 | |
@@ -294,19 +294,19 @@ discard block |
||
294 | 294 | * @param bool $extend This indicates whether we're checking the extend directory for any register_hooks files/classes |
295 | 295 | * @return array |
296 | 296 | */ |
297 | - public function register_hooks( $extend = FALSE ) { |
|
297 | + public function register_hooks($extend = FALSE) { |
|
298 | 298 | |
299 | 299 | //get a list of files in the directory that have the "Hook" in their name an |
300 | 300 | |
301 | 301 | //if this is an extended check (i.e. caf is active) then we will scan the caffeinated/extend directory first and any hook files that are found will be have their reference added to the $_files_hook array property. Then, we make sure that when we loop through the core decaf directories to find hook files that we skip over any hooks files that have already been set by caf. |
302 | - if ( $extend ) { |
|
303 | - $hook_files_glob_path = apply_filters( 'FHEE__EE_Admin_Page_Init__register_hooks__hook_files_glob_path__extend', EE_CORE_CAF_ADMIN_EXTEND . $this->_folder_name . DS . '*' . $this->_file_name . '_Hooks_Extend.class.php' ); |
|
304 | - $this->_hook_paths = $this->_register_hook_files( $hook_files_glob_path, $extend ); |
|
302 | + if ($extend) { |
|
303 | + $hook_files_glob_path = apply_filters('FHEE__EE_Admin_Page_Init__register_hooks__hook_files_glob_path__extend', EE_CORE_CAF_ADMIN_EXTEND.$this->_folder_name.DS.'*'.$this->_file_name.'_Hooks_Extend.class.php'); |
|
304 | + $this->_hook_paths = $this->_register_hook_files($hook_files_glob_path, $extend); |
|
305 | 305 | } |
306 | 306 | |
307 | 307 | //loop through decaf folders |
308 | - $hook_files_glob_path = apply_filters( 'FHEE__EE_Admin_Page_Init__register_hooks__hook_files_glob_path', $this->_folder_path . '*' . $this->_file_name . '_Hooks.class.php' ); |
|
309 | - $this->_hook_paths = array_merge( $this->_register_hook_files( $hook_files_glob_path ), $this->_hook_paths ); //making sure any extended hook paths are later in the array than the core hook paths! |
|
308 | + $hook_files_glob_path = apply_filters('FHEE__EE_Admin_Page_Init__register_hooks__hook_files_glob_path', $this->_folder_path.'*'.$this->_file_name.'_Hooks.class.php'); |
|
309 | + $this->_hook_paths = array_merge($this->_register_hook_files($hook_files_glob_path), $this->_hook_paths); //making sure any extended hook paths are later in the array than the core hook paths! |
|
310 | 310 | |
311 | 311 | return $this->_hook_paths; |
312 | 312 | |
@@ -314,27 +314,27 @@ discard block |
||
314 | 314 | |
315 | 315 | |
316 | 316 | |
317 | - protected function _register_hook_files( $hook_files_glob_path, $extend = FALSE ) { |
|
317 | + protected function _register_hook_files($hook_files_glob_path, $extend = FALSE) { |
|
318 | 318 | $hook_paths = array(); |
319 | - if ( $hook_files = glob( $hook_files_glob_path ) ) { |
|
320 | - if ( empty( $hook_files ) ) { |
|
319 | + if ($hook_files = glob($hook_files_glob_path)) { |
|
320 | + if (empty($hook_files)) { |
|
321 | 321 | return array(); |
322 | 322 | } |
323 | - foreach ( $hook_files as $file ) { |
|
323 | + foreach ($hook_files as $file) { |
|
324 | 324 | //lets get the linked admin. |
325 | - $hook_file = $extend ? str_replace( EE_CORE_CAF_ADMIN_EXTEND . $this->_folder_name . DS, '', $file ) : str_replace($this->_folder_path, '', $file ); |
|
326 | - $replace = $extend ? '_' . $this->_file_name . '_Hooks_Extend.class.php' : '_' . $this->_file_name . '_Hooks.class.php'; |
|
327 | - $rel_admin = str_replace( $replace, '', $hook_file); |
|
325 | + $hook_file = $extend ? str_replace(EE_CORE_CAF_ADMIN_EXTEND.$this->_folder_name.DS, '', $file) : str_replace($this->_folder_path, '', $file); |
|
326 | + $replace = $extend ? '_'.$this->_file_name.'_Hooks_Extend.class.php' : '_'.$this->_file_name.'_Hooks.class.php'; |
|
327 | + $rel_admin = str_replace($replace, '', $hook_file); |
|
328 | 328 | $rel_admin = strtolower($rel_admin); |
329 | 329 | $hook_paths[] = $file; |
330 | 330 | |
331 | 331 | //make sure we haven't already got a hook setup for this page path |
332 | - if ( in_array( $rel_admin, $this->_files_hooked ) ) |
|
332 | + if (in_array($rel_admin, $this->_files_hooked)) |
|
333 | 333 | continue; |
334 | 334 | |
335 | 335 | $this->hook_file = $hook_file; |
336 | - $rel_admin_hook = 'FHEE_do_other_page_hooks_' . $rel_admin; |
|
337 | - $filter = add_filter( $rel_admin_hook, array($this, 'load_admin_hook') ); |
|
336 | + $rel_admin_hook = 'FHEE_do_other_page_hooks_'.$rel_admin; |
|
337 | + $filter = add_filter($rel_admin_hook, array($this, 'load_admin_hook')); |
|
338 | 338 | $this->_files_hooked[] = $rel_admin; |
339 | 339 | } |
340 | 340 | } |
@@ -359,7 +359,7 @@ discard block |
||
359 | 359 | protected function _initialize_admin_page() { |
360 | 360 | |
361 | 361 | //JUST CHECK WE'RE ON RIGHT PAGE. |
362 | - if ( (!isset( $_REQUEST['page'] ) || $_REQUEST['page'] != $this->_menu_map->menu_slug) && $this->_routing ) |
|
362 | + if (( ! isset($_REQUEST['page']) || $_REQUEST['page'] != $this->_menu_map->menu_slug) && $this->_routing) |
|
363 | 363 | return; //not on the right page so let's get out. |
364 | 364 | $this->_load_page = TRUE; |
365 | 365 | |
@@ -367,30 +367,30 @@ discard block |
||
367 | 367 | // spl_autoload_register(array( $this, 'set_autoloaders') ); |
368 | 368 | |
369 | 369 | //we don't need to do a page_request check here because it's only called via WP menu system. |
370 | - $admin_page = $this->_file_name . '_Admin_Page'; |
|
371 | - $hook_suffix = $this->_menu_map->menu_slug . '_' . $admin_page; |
|
370 | + $admin_page = $this->_file_name.'_Admin_Page'; |
|
371 | + $hook_suffix = $this->_menu_map->menu_slug.'_'.$admin_page; |
|
372 | 372 | $admin_page = apply_filters("FHEE__EE_Admin_Page_Init___initialize_admin_page__admin_page__{$hook_suffix}", $admin_page); |
373 | 373 | |
374 | 374 | // define requested admin page class name then load the file and instantiate |
375 | - $path_to_file = str_replace( array( '\\', '/' ), DS, $this->_folder_path . $admin_page . '.core.php' ); |
|
376 | - $path_to_file=apply_filters("FHEE__EE_Admin_Page_Init___initialize_admin_page__path_to_file__{$hook_suffix}",$path_to_file );//so if the file would be in EE_ADMIN/attendees/Attendee_Admin_Page.core.php, the filter would be FHEE__EE_Admin_Page_Init___initialize_admin_page__path_to_file__attendees_Attendee_Admin_Page |
|
375 | + $path_to_file = str_replace(array('\\', '/'), DS, $this->_folder_path.$admin_page.'.core.php'); |
|
376 | + $path_to_file = apply_filters("FHEE__EE_Admin_Page_Init___initialize_admin_page__path_to_file__{$hook_suffix}", $path_to_file); //so if the file would be in EE_ADMIN/attendees/Attendee_Admin_Page.core.php, the filter would be FHEE__EE_Admin_Page_Init___initialize_admin_page__path_to_file__attendees_Attendee_Admin_Page |
|
377 | 377 | |
378 | - if ( is_readable( $path_to_file )) { |
|
378 | + if (is_readable($path_to_file)) { |
|
379 | 379 | // This is a place where EE plugins can hook in to make sure their own files are required in the appropriate place |
380 | - do_action( 'AHEE__EE_Admin_Page___initialize_admin_page__before_initialization' ); |
|
381 | - do_action( 'AHEE__EE_Admin_Page___initialize_admin_page__before_initialization_' . $this->_menu_map->menu_slug ); |
|
382 | - require_once( $path_to_file ); |
|
383 | - $a = new ReflectionClass( $admin_page ); |
|
384 | - $this->_loaded_page_object = $a->newInstance( $this->_routing ); |
|
380 | + do_action('AHEE__EE_Admin_Page___initialize_admin_page__before_initialization'); |
|
381 | + do_action('AHEE__EE_Admin_Page___initialize_admin_page__before_initialization_'.$this->_menu_map->menu_slug); |
|
382 | + require_once($path_to_file); |
|
383 | + $a = new ReflectionClass($admin_page); |
|
384 | + $this->_loaded_page_object = $a->newInstance($this->_routing); |
|
385 | 385 | } |
386 | - do_action( 'AHEE__EE_Admin_Page___initialize_admin_page__after_initialization' ); |
|
387 | - do_action( 'AHEE__EE_Admin_Page___initialize_admin_page__after_initialization_' . $this->_menu_map->menu_slug ); |
|
386 | + do_action('AHEE__EE_Admin_Page___initialize_admin_page__after_initialization'); |
|
387 | + do_action('AHEE__EE_Admin_Page___initialize_admin_page__after_initialization_'.$this->_menu_map->menu_slug); |
|
388 | 388 | } |
389 | 389 | |
390 | 390 | |
391 | 391 | |
392 | 392 | public function get_admin_page_name() { |
393 | - return $this->_file_name . '_Admin_Page'; |
|
393 | + return $this->_file_name.'_Admin_Page'; |
|
394 | 394 | } |
395 | 395 | |
396 | 396 | |
@@ -422,8 +422,8 @@ discard block |
||
422 | 422 | * @return bool|die true if pass (or admin) wp_die if fail |
423 | 423 | */ |
424 | 424 | private function _check_user_access() { |
425 | - if ( ! EE_Registry::instance()->CAP->current_user_can( $this->_menu_map->capability, $this->_menu_map->menu_slug ) ) { |
|
426 | - wp_die( __('You don\'t have access to this page.'), '', array( 'back_link' => true ) ); |
|
425 | + if ( ! EE_Registry::instance()->CAP->current_user_can($this->_menu_map->capability, $this->_menu_map->menu_slug)) { |
|
426 | + wp_die(__('You don\'t have access to this page.'), '', array('back_link' => true)); |
|
427 | 427 | } |
428 | 428 | return true; |
429 | 429 | } |
@@ -14,132 +14,132 @@ |
||
14 | 14 | class EE_Div_Per_Section_Layout extends EE_Form_Section_Layout_Base |
15 | 15 | { |
16 | 16 | |
17 | - /** |
|
18 | - * opening div tag for a form |
|
19 | - * |
|
20 | - * @return string |
|
21 | - */ |
|
22 | - public function layout_form_begin() |
|
23 | - { |
|
24 | - return EEH_HTML::div( |
|
25 | - '', |
|
26 | - $this->_form_section->html_id(), |
|
27 | - $this->_form_section->html_class(), |
|
28 | - $this->_form_section->html_style() |
|
29 | - ); |
|
30 | - } |
|
31 | - |
|
32 | - |
|
33 | - |
|
34 | - /** |
|
35 | - * Lays out the row for the input, including label and errors |
|
36 | - * |
|
37 | - * @param EE_Form_Input_Base $input |
|
38 | - * @return string |
|
39 | - * @throws \EE_Error |
|
40 | - */ |
|
41 | - public function layout_input($input) |
|
42 | - { |
|
43 | - $html = ''; |
|
44 | - // set something unique for the id |
|
45 | - $html_id = (string)$input->html_id() !== '' |
|
46 | - ? (string)$input->html_id() |
|
47 | - : spl_object_hash($input); |
|
48 | - // and add a generic input type class |
|
49 | - $html_class = sanitize_key(str_replace('_', '-', get_class($input))) . '-dv'; |
|
50 | - if ($input instanceof EE_Hidden_Input) { |
|
51 | - $html .= EEH_HTML::nl() . $input->get_html_for_input(); |
|
52 | - } else if ($input instanceof EE_Submit_Input) { |
|
53 | - $html .= EEH_HTML::div( |
|
54 | - $input->get_html_for_input(), |
|
55 | - $html_id . '-submit-dv', |
|
56 | - "{$input->html_class()}-submit-dv {$html_class}" |
|
57 | - ); |
|
58 | - } else if ($input instanceof EE_Select_Input) { |
|
59 | - $html .= EEH_HTML::div( |
|
60 | - EEH_HTML::nl(1) . $input->get_html_for_label() . |
|
61 | - EEH_HTML::nl() . $input->get_html_for_errors() . |
|
62 | - EEH_HTML::nl() . $input->get_html_for_input() . |
|
63 | - EEH_HTML::nl() . $input->get_html_for_help(), |
|
64 | - $html_id . '-input-dv', |
|
65 | - "{$input->html_class()}-input-dv {$html_class}" |
|
66 | - ); |
|
67 | - } else if ($input instanceof EE_Form_Input_With_Options_Base) { |
|
68 | - $html .= EEH_HTML::div( |
|
69 | - EEH_HTML::nl() . $this->_display_label_for_option_type_question($input) . |
|
70 | - EEH_HTML::nl() . $input->get_html_for_errors() . |
|
71 | - EEH_HTML::nl() . $input->get_html_for_input() . |
|
72 | - EEH_HTML::nl() . $input->get_html_for_help(), |
|
73 | - $html_id . '-input-dv', |
|
74 | - "{$input->html_class()}-input-dv {$html_class}" |
|
75 | - ); |
|
76 | - } else { |
|
77 | - $html .= EEH_HTML::div( |
|
78 | - EEH_HTML::nl(1) . $input->get_html_for_label() . |
|
79 | - EEH_HTML::nl() . $input->get_html_for_errors() . |
|
80 | - EEH_HTML::nl() . $input->get_html_for_input() . |
|
81 | - EEH_HTML::nl() . $input->get_html_for_help(), |
|
82 | - $html_id . '-input-dv', |
|
83 | - "{$input->html_class()}-input-dv {$html_class}" |
|
84 | - ); |
|
85 | - } |
|
86 | - return $html; |
|
87 | - } |
|
88 | - |
|
89 | - |
|
90 | - |
|
91 | - /** |
|
92 | - * |
|
93 | - * _display_label_for_option_type_question |
|
94 | - * Gets the HTML for the 'label', which is just text for this (because labels |
|
95 | - * should be for each input) |
|
96 | - * |
|
97 | - * @param EE_Form_Input_With_Options_Base $input |
|
98 | - * @return string |
|
99 | - */ |
|
100 | - protected function _display_label_for_option_type_question(EE_Form_Input_With_Options_Base $input) |
|
101 | - { |
|
102 | - if ($input->display_html_label_text() !== '') { |
|
103 | - return EEH_HTML::div( |
|
104 | - $input->required() |
|
105 | - ? $input->html_label_text() . EEH_HTML::span('*', '', 'ee-asterisk') |
|
106 | - : $input->html_label_text(), |
|
107 | - $input->html_label_id(), |
|
108 | - $input->required() |
|
109 | - ? 'ee-required-label ' . $input->html_label_class() |
|
110 | - : $input->html_label_class(), |
|
111 | - $input->html_label_style(), |
|
112 | - $input->html_other_attributes() |
|
113 | - ); |
|
114 | - } |
|
115 | - return ''; |
|
116 | - } |
|
117 | - |
|
118 | - |
|
119 | - |
|
120 | - /** |
|
121 | - * Lays out a row for the subsection |
|
122 | - * |
|
123 | - * @param EE_Form_Section_Proper $form_section |
|
124 | - * @return string |
|
125 | - */ |
|
126 | - public function layout_subsection($form_section) |
|
127 | - { |
|
128 | - // d( $form_section ); |
|
129 | - return EEH_HTML::nl(1) . $form_section->get_html() . EEH_HTML::nl(-1); |
|
130 | - } |
|
131 | - |
|
132 | - |
|
133 | - |
|
134 | - /** |
|
135 | - * closing div tag for a form |
|
136 | - * |
|
137 | - * @return string |
|
138 | - */ |
|
139 | - public function layout_form_end() |
|
140 | - { |
|
141 | - return EEH_HTML::divx($this->_form_section->html_id(), $this->_form_section->html_class()); |
|
142 | - } |
|
17 | + /** |
|
18 | + * opening div tag for a form |
|
19 | + * |
|
20 | + * @return string |
|
21 | + */ |
|
22 | + public function layout_form_begin() |
|
23 | + { |
|
24 | + return EEH_HTML::div( |
|
25 | + '', |
|
26 | + $this->_form_section->html_id(), |
|
27 | + $this->_form_section->html_class(), |
|
28 | + $this->_form_section->html_style() |
|
29 | + ); |
|
30 | + } |
|
31 | + |
|
32 | + |
|
33 | + |
|
34 | + /** |
|
35 | + * Lays out the row for the input, including label and errors |
|
36 | + * |
|
37 | + * @param EE_Form_Input_Base $input |
|
38 | + * @return string |
|
39 | + * @throws \EE_Error |
|
40 | + */ |
|
41 | + public function layout_input($input) |
|
42 | + { |
|
43 | + $html = ''; |
|
44 | + // set something unique for the id |
|
45 | + $html_id = (string)$input->html_id() !== '' |
|
46 | + ? (string)$input->html_id() |
|
47 | + : spl_object_hash($input); |
|
48 | + // and add a generic input type class |
|
49 | + $html_class = sanitize_key(str_replace('_', '-', get_class($input))) . '-dv'; |
|
50 | + if ($input instanceof EE_Hidden_Input) { |
|
51 | + $html .= EEH_HTML::nl() . $input->get_html_for_input(); |
|
52 | + } else if ($input instanceof EE_Submit_Input) { |
|
53 | + $html .= EEH_HTML::div( |
|
54 | + $input->get_html_for_input(), |
|
55 | + $html_id . '-submit-dv', |
|
56 | + "{$input->html_class()}-submit-dv {$html_class}" |
|
57 | + ); |
|
58 | + } else if ($input instanceof EE_Select_Input) { |
|
59 | + $html .= EEH_HTML::div( |
|
60 | + EEH_HTML::nl(1) . $input->get_html_for_label() . |
|
61 | + EEH_HTML::nl() . $input->get_html_for_errors() . |
|
62 | + EEH_HTML::nl() . $input->get_html_for_input() . |
|
63 | + EEH_HTML::nl() . $input->get_html_for_help(), |
|
64 | + $html_id . '-input-dv', |
|
65 | + "{$input->html_class()}-input-dv {$html_class}" |
|
66 | + ); |
|
67 | + } else if ($input instanceof EE_Form_Input_With_Options_Base) { |
|
68 | + $html .= EEH_HTML::div( |
|
69 | + EEH_HTML::nl() . $this->_display_label_for_option_type_question($input) . |
|
70 | + EEH_HTML::nl() . $input->get_html_for_errors() . |
|
71 | + EEH_HTML::nl() . $input->get_html_for_input() . |
|
72 | + EEH_HTML::nl() . $input->get_html_for_help(), |
|
73 | + $html_id . '-input-dv', |
|
74 | + "{$input->html_class()}-input-dv {$html_class}" |
|
75 | + ); |
|
76 | + } else { |
|
77 | + $html .= EEH_HTML::div( |
|
78 | + EEH_HTML::nl(1) . $input->get_html_for_label() . |
|
79 | + EEH_HTML::nl() . $input->get_html_for_errors() . |
|
80 | + EEH_HTML::nl() . $input->get_html_for_input() . |
|
81 | + EEH_HTML::nl() . $input->get_html_for_help(), |
|
82 | + $html_id . '-input-dv', |
|
83 | + "{$input->html_class()}-input-dv {$html_class}" |
|
84 | + ); |
|
85 | + } |
|
86 | + return $html; |
|
87 | + } |
|
88 | + |
|
89 | + |
|
90 | + |
|
91 | + /** |
|
92 | + * |
|
93 | + * _display_label_for_option_type_question |
|
94 | + * Gets the HTML for the 'label', which is just text for this (because labels |
|
95 | + * should be for each input) |
|
96 | + * |
|
97 | + * @param EE_Form_Input_With_Options_Base $input |
|
98 | + * @return string |
|
99 | + */ |
|
100 | + protected function _display_label_for_option_type_question(EE_Form_Input_With_Options_Base $input) |
|
101 | + { |
|
102 | + if ($input->display_html_label_text() !== '') { |
|
103 | + return EEH_HTML::div( |
|
104 | + $input->required() |
|
105 | + ? $input->html_label_text() . EEH_HTML::span('*', '', 'ee-asterisk') |
|
106 | + : $input->html_label_text(), |
|
107 | + $input->html_label_id(), |
|
108 | + $input->required() |
|
109 | + ? 'ee-required-label ' . $input->html_label_class() |
|
110 | + : $input->html_label_class(), |
|
111 | + $input->html_label_style(), |
|
112 | + $input->html_other_attributes() |
|
113 | + ); |
|
114 | + } |
|
115 | + return ''; |
|
116 | + } |
|
117 | + |
|
118 | + |
|
119 | + |
|
120 | + /** |
|
121 | + * Lays out a row for the subsection |
|
122 | + * |
|
123 | + * @param EE_Form_Section_Proper $form_section |
|
124 | + * @return string |
|
125 | + */ |
|
126 | + public function layout_subsection($form_section) |
|
127 | + { |
|
128 | + // d( $form_section ); |
|
129 | + return EEH_HTML::nl(1) . $form_section->get_html() . EEH_HTML::nl(-1); |
|
130 | + } |
|
131 | + |
|
132 | + |
|
133 | + |
|
134 | + /** |
|
135 | + * closing div tag for a form |
|
136 | + * |
|
137 | + * @return string |
|
138 | + */ |
|
139 | + public function layout_form_end() |
|
140 | + { |
|
141 | + return EEH_HTML::divx($this->_form_section->html_id(), $this->_form_section->html_class()); |
|
142 | + } |
|
143 | 143 | |
144 | 144 | |
145 | 145 |
@@ -42,44 +42,44 @@ discard block |
||
42 | 42 | { |
43 | 43 | $html = ''; |
44 | 44 | // set something unique for the id |
45 | - $html_id = (string)$input->html_id() !== '' |
|
46 | - ? (string)$input->html_id() |
|
45 | + $html_id = (string) $input->html_id() !== '' |
|
46 | + ? (string) $input->html_id() |
|
47 | 47 | : spl_object_hash($input); |
48 | 48 | // and add a generic input type class |
49 | - $html_class = sanitize_key(str_replace('_', '-', get_class($input))) . '-dv'; |
|
49 | + $html_class = sanitize_key(str_replace('_', '-', get_class($input))).'-dv'; |
|
50 | 50 | if ($input instanceof EE_Hidden_Input) { |
51 | - $html .= EEH_HTML::nl() . $input->get_html_for_input(); |
|
51 | + $html .= EEH_HTML::nl().$input->get_html_for_input(); |
|
52 | 52 | } else if ($input instanceof EE_Submit_Input) { |
53 | 53 | $html .= EEH_HTML::div( |
54 | 54 | $input->get_html_for_input(), |
55 | - $html_id . '-submit-dv', |
|
55 | + $html_id.'-submit-dv', |
|
56 | 56 | "{$input->html_class()}-submit-dv {$html_class}" |
57 | 57 | ); |
58 | 58 | } else if ($input instanceof EE_Select_Input) { |
59 | 59 | $html .= EEH_HTML::div( |
60 | - EEH_HTML::nl(1) . $input->get_html_for_label() . |
|
61 | - EEH_HTML::nl() . $input->get_html_for_errors() . |
|
62 | - EEH_HTML::nl() . $input->get_html_for_input() . |
|
63 | - EEH_HTML::nl() . $input->get_html_for_help(), |
|
64 | - $html_id . '-input-dv', |
|
60 | + EEH_HTML::nl(1).$input->get_html_for_label(). |
|
61 | + EEH_HTML::nl().$input->get_html_for_errors(). |
|
62 | + EEH_HTML::nl().$input->get_html_for_input(). |
|
63 | + EEH_HTML::nl().$input->get_html_for_help(), |
|
64 | + $html_id.'-input-dv', |
|
65 | 65 | "{$input->html_class()}-input-dv {$html_class}" |
66 | 66 | ); |
67 | 67 | } else if ($input instanceof EE_Form_Input_With_Options_Base) { |
68 | 68 | $html .= EEH_HTML::div( |
69 | - EEH_HTML::nl() . $this->_display_label_for_option_type_question($input) . |
|
70 | - EEH_HTML::nl() . $input->get_html_for_errors() . |
|
71 | - EEH_HTML::nl() . $input->get_html_for_input() . |
|
72 | - EEH_HTML::nl() . $input->get_html_for_help(), |
|
73 | - $html_id . '-input-dv', |
|
69 | + EEH_HTML::nl().$this->_display_label_for_option_type_question($input). |
|
70 | + EEH_HTML::nl().$input->get_html_for_errors(). |
|
71 | + EEH_HTML::nl().$input->get_html_for_input(). |
|
72 | + EEH_HTML::nl().$input->get_html_for_help(), |
|
73 | + $html_id.'-input-dv', |
|
74 | 74 | "{$input->html_class()}-input-dv {$html_class}" |
75 | 75 | ); |
76 | 76 | } else { |
77 | 77 | $html .= EEH_HTML::div( |
78 | - EEH_HTML::nl(1) . $input->get_html_for_label() . |
|
79 | - EEH_HTML::nl() . $input->get_html_for_errors() . |
|
80 | - EEH_HTML::nl() . $input->get_html_for_input() . |
|
81 | - EEH_HTML::nl() . $input->get_html_for_help(), |
|
82 | - $html_id . '-input-dv', |
|
78 | + EEH_HTML::nl(1).$input->get_html_for_label(). |
|
79 | + EEH_HTML::nl().$input->get_html_for_errors(). |
|
80 | + EEH_HTML::nl().$input->get_html_for_input(). |
|
81 | + EEH_HTML::nl().$input->get_html_for_help(), |
|
82 | + $html_id.'-input-dv', |
|
83 | 83 | "{$input->html_class()}-input-dv {$html_class}" |
84 | 84 | ); |
85 | 85 | } |
@@ -102,11 +102,11 @@ discard block |
||
102 | 102 | if ($input->display_html_label_text() !== '') { |
103 | 103 | return EEH_HTML::div( |
104 | 104 | $input->required() |
105 | - ? $input->html_label_text() . EEH_HTML::span('*', '', 'ee-asterisk') |
|
105 | + ? $input->html_label_text().EEH_HTML::span('*', '', 'ee-asterisk') |
|
106 | 106 | : $input->html_label_text(), |
107 | 107 | $input->html_label_id(), |
108 | 108 | $input->required() |
109 | - ? 'ee-required-label ' . $input->html_label_class() |
|
109 | + ? 'ee-required-label '.$input->html_label_class() |
|
110 | 110 | : $input->html_label_class(), |
111 | 111 | $input->html_label_style(), |
112 | 112 | $input->html_other_attributes() |
@@ -126,7 +126,7 @@ discard block |
||
126 | 126 | public function layout_subsection($form_section) |
127 | 127 | { |
128 | 128 | // d( $form_section ); |
129 | - return EEH_HTML::nl(1) . $form_section->get_html() . EEH_HTML::nl(-1); |
|
129 | + return EEH_HTML::nl(1).$form_section->get_html().EEH_HTML::nl(-1); |
|
130 | 130 | } |
131 | 131 | |
132 | 132 |
@@ -211,7 +211,7 @@ |
||
211 | 211 | * appropriately. |
212 | 212 | * |
213 | 213 | * @throws EE_Error |
214 | - * @return EE_message_type|false if exception thrown. |
|
214 | + * @return null|EE_message_type if exception thrown. |
|
215 | 215 | */ |
216 | 216 | public function message_type_obj() |
217 | 217 | { |
@@ -15,486 +15,486 @@ |
||
15 | 15 | class EE_Message_Template_Group extends EE_Soft_Delete_Base_Class |
16 | 16 | { |
17 | 17 | |
18 | - /** |
|
19 | - * Extra Meta key prefix for whether a given context for this message tmeplate group is active or not. |
|
20 | - */ |
|
21 | - const ACTIVE_CONTEXT_RECORD_META_KEY_PREFIX = 'active_context_'; |
|
22 | - |
|
23 | - /** |
|
24 | - * @param array $props_n_values |
|
25 | - * @param string $timezone |
|
26 | - * @return EE_Message_Template_Group|mixed |
|
27 | - * @throws EE_Error |
|
28 | - */ |
|
29 | - public static function new_instance($props_n_values = array(), $timezone = '') |
|
30 | - { |
|
31 | - $has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone); |
|
32 | - return $has_object ? $has_object : new self($props_n_values, false, $timezone); |
|
33 | - } |
|
34 | - |
|
35 | - |
|
36 | - /** |
|
37 | - * @param array $props_n_values |
|
38 | - * @param string $timezone |
|
39 | - * @return EE_Message_Template_Group |
|
40 | - */ |
|
41 | - public static function new_instance_from_db($props_n_values = array(), $timezone = '') |
|
42 | - { |
|
43 | - return new self($props_n_values, true, $timezone); |
|
44 | - } |
|
45 | - |
|
46 | - |
|
47 | - /** |
|
48 | - * @param bool $message_type |
|
49 | - * @throws EE_Error |
|
50 | - */ |
|
51 | - public function set_message_type($message_type = false) |
|
52 | - { |
|
53 | - if (! $message_type) { |
|
54 | - throw new EE_Error(esc_html__('Missing required value for the message_type parameter', 'event_espresso')); |
|
55 | - } |
|
56 | - $this->set('MTP_message_type', $message_type); |
|
57 | - } |
|
58 | - |
|
59 | - |
|
60 | - /** |
|
61 | - * @param bool $messenger |
|
62 | - * @throws EE_Error |
|
63 | - */ |
|
64 | - public function set_messenger($messenger = false) |
|
65 | - { |
|
66 | - if (! $messenger) { |
|
67 | - throw new EE_Error(esc_html__('Missing required value for the messenger parameter', 'event_espresso')); |
|
68 | - } |
|
69 | - $this->set('MTP_messenger', $messenger); |
|
70 | - } |
|
71 | - |
|
72 | - |
|
73 | - /** |
|
74 | - * @param bool $GRP_ID |
|
75 | - * @throws EE_Error |
|
76 | - */ |
|
77 | - public function set_group_template_id($GRP_ID = false) |
|
78 | - { |
|
79 | - if (! $GRP_ID) { |
|
80 | - throw new EE_Error( |
|
81 | - esc_html__( |
|
82 | - 'Missing required value for the message template group id', |
|
83 | - 'event_espresso' |
|
84 | - ) |
|
85 | - ); |
|
86 | - } |
|
87 | - $this->set('GRP_ID', $GRP_ID); |
|
88 | - } |
|
89 | - |
|
90 | - |
|
91 | - /** |
|
92 | - * get Group ID |
|
93 | - * |
|
94 | - * @access public |
|
95 | - * @return int |
|
96 | - * @throws EE_Error |
|
97 | - */ |
|
98 | - public function GRP_ID() |
|
99 | - { |
|
100 | - return $this->get('GRP_ID'); |
|
101 | - } |
|
102 | - |
|
103 | - |
|
104 | - /** |
|
105 | - * get User ID |
|
106 | - * |
|
107 | - * @access public |
|
108 | - * @return int |
|
109 | - * @throws EE_Error |
|
110 | - */ |
|
111 | - public function user() |
|
112 | - { |
|
113 | - $user_id = $this->get('MTP_user_id'); |
|
114 | - return empty($user_id) ? get_current_user_id() : $user_id; |
|
115 | - } |
|
116 | - |
|
117 | - |
|
118 | - /** |
|
119 | - * Wrapper for the user function() (preserve backward compat) |
|
120 | - * |
|
121 | - * @since 4.5.0 |
|
122 | - * @return int |
|
123 | - * @throws EE_Error |
|
124 | - */ |
|
125 | - public function wp_user() |
|
126 | - { |
|
127 | - return $this->user(); |
|
128 | - } |
|
129 | - |
|
130 | - |
|
131 | - /** |
|
132 | - * This simply returns a count of all related events to this message template group |
|
133 | - * |
|
134 | - * @return int |
|
135 | - */ |
|
136 | - public function count_events() |
|
137 | - { |
|
138 | - return $this->count_related('Event'); |
|
139 | - } |
|
140 | - |
|
141 | - |
|
142 | - /** |
|
143 | - * returns the name saved in the db for this template |
|
144 | - * |
|
145 | - * @return string |
|
146 | - * @throws EE_Error |
|
147 | - */ |
|
148 | - public function name() |
|
149 | - { |
|
150 | - return $this->get('MTP_name'); |
|
151 | - } |
|
152 | - |
|
153 | - |
|
154 | - /** |
|
155 | - * Returns the description saved in the db for this template group |
|
156 | - * |
|
157 | - * @return string |
|
158 | - * @throws EE_Error |
|
159 | - */ |
|
160 | - public function description() |
|
161 | - { |
|
162 | - return $this->get('MTP_description'); |
|
163 | - } |
|
164 | - |
|
165 | - |
|
166 | - /** |
|
167 | - * returns all related EE_Message_Template objects |
|
168 | - * |
|
169 | - * @param array $query_params like EEM_Base::get_all() |
|
170 | - * @return EE_Message_Template[] |
|
171 | - * @throws EE_Error |
|
172 | - */ |
|
173 | - public function message_templates($query_params = array()) |
|
174 | - { |
|
175 | - return $this->get_many_related('Message_Template', $query_params); |
|
176 | - } |
|
177 | - |
|
178 | - |
|
179 | - /** |
|
180 | - * get Message Messenger |
|
181 | - * |
|
182 | - * @access public |
|
183 | - * @return string |
|
184 | - * @throws EE_Error |
|
185 | - */ |
|
186 | - public function messenger() |
|
187 | - { |
|
188 | - return $this->get('MTP_messenger'); |
|
189 | - } |
|
190 | - |
|
191 | - |
|
192 | - /** |
|
193 | - * get Message Messenger OBJECT |
|
194 | - * If an attempt to get the corresponding messenger object fails, then we set this message |
|
195 | - * template group to inactive, and save to db. Then return null so client code can handle |
|
196 | - * appropriately. |
|
197 | - * |
|
198 | - * @return EE_messenger |
|
199 | - * @throws EE_Error |
|
200 | - */ |
|
201 | - public function messenger_obj() |
|
202 | - { |
|
203 | - $messenger = $this->messenger(); |
|
204 | - try { |
|
205 | - $messenger = EEH_MSG_Template::messenger_obj($messenger); |
|
206 | - } catch (EE_Error $e) { |
|
207 | - //if an exception was thrown then let's deactivate this message template group because it means there is no |
|
208 | - // class for this messenger in this group. |
|
209 | - $this->set('MTP_is_active', false); |
|
210 | - $this->save(); |
|
211 | - return null; |
|
212 | - } |
|
213 | - return $messenger; |
|
214 | - } |
|
215 | - |
|
216 | - |
|
217 | - /** |
|
218 | - * get Message Type |
|
219 | - * |
|
220 | - * @access public |
|
221 | - * @return string |
|
222 | - * @throws EE_Error |
|
223 | - */ |
|
224 | - public function message_type() |
|
225 | - { |
|
226 | - return $this->get('MTP_message_type'); |
|
227 | - } |
|
228 | - |
|
229 | - |
|
230 | - /** |
|
231 | - * get Message type OBJECT |
|
232 | - * If an attempt to get the corresponding message type object fails, then we set this message |
|
233 | - * template group to inactive, and save to db. Then return null so client code can handle |
|
234 | - * appropriately. |
|
235 | - * |
|
236 | - * @throws EE_Error |
|
237 | - * @return EE_message_type|false if exception thrown. |
|
238 | - */ |
|
239 | - public function message_type_obj() |
|
240 | - { |
|
241 | - $message_type = $this->message_type(); |
|
242 | - try { |
|
243 | - $message_type = EEH_MSG_Template::message_type_obj($message_type); |
|
244 | - } catch (EE_Error $e) { |
|
245 | - //if an exception was thrown then let's deactivate this message template group because it means there is no |
|
246 | - // class for the message type in this group. |
|
247 | - $this->set('MTP_is_active', false); |
|
248 | - $this->save(); |
|
249 | - return null; |
|
250 | - } |
|
251 | - return $message_type; |
|
252 | - } |
|
253 | - |
|
254 | - |
|
255 | - /** |
|
256 | - * @return array |
|
257 | - * @throws EE_Error |
|
258 | - */ |
|
259 | - public function contexts_config() |
|
260 | - { |
|
261 | - return $this->message_type_obj()->get_contexts(); |
|
262 | - } |
|
263 | - |
|
264 | - |
|
265 | - /** |
|
266 | - * This returns the context_label for contexts as set in the message type object |
|
267 | - * Note this is an array with singular and plural keys |
|
268 | - * |
|
269 | - * @access public |
|
270 | - * @return array labels for "context" |
|
271 | - * @throws EE_Error |
|
272 | - */ |
|
273 | - public function context_label() |
|
274 | - { |
|
275 | - $obj = $this->message_type_obj(); |
|
276 | - return $obj->get_context_label(); |
|
277 | - } |
|
278 | - |
|
279 | - |
|
280 | - /** |
|
281 | - * This returns an array of EE_Message_Template objects indexed by context and field. |
|
282 | - * |
|
283 | - * @return array () |
|
284 | - * @throws EE_Error |
|
285 | - */ |
|
286 | - public function context_templates() |
|
287 | - { |
|
288 | - $mtps_arr = array(); |
|
289 | - $mtps = $this->get_many_related('Message_Template'); |
|
290 | - if (empty($mtps)) { |
|
291 | - return array(); |
|
292 | - } |
|
293 | - //note contexts could have CHECKBOX fields per context. So we return the objects indexed by context AND field. |
|
294 | - foreach ($mtps as $mtp) { |
|
295 | - $mtps_arr[$mtp->get('MTP_context')][$mtp->get('MTP_template_field')] = $mtp; |
|
296 | - } |
|
297 | - return $mtps_arr; |
|
298 | - } |
|
299 | - |
|
300 | - |
|
301 | - /** |
|
302 | - * this returns if the template group this template belongs to is global |
|
303 | - * |
|
304 | - * @return bool true if it is, false if it isn't |
|
305 | - * @throws EE_Error |
|
306 | - */ |
|
307 | - public function is_global() |
|
308 | - { |
|
309 | - return $this->get('MTP_is_global'); |
|
310 | - } |
|
311 | - |
|
312 | - |
|
313 | - /** |
|
314 | - * this returns if the template group this template belongs to is active (i.e. turned "on" or not) |
|
315 | - * |
|
316 | - * @return bool true if it is, false if it isn't |
|
317 | - * @throws EE_Error |
|
318 | - */ |
|
319 | - public function is_active() |
|
320 | - { |
|
321 | - return $this->get('MTP_is_active'); |
|
322 | - } |
|
323 | - |
|
324 | - |
|
325 | - /** |
|
326 | - * This will return an array of shortcodes => labels from the messenger and message_type objects associated with |
|
327 | - * this template. |
|
328 | - * |
|
329 | - * @since 4.3.0 |
|
330 | - * @uses EEH_MSG_Template::get_shortcodes() |
|
331 | - * @param string $context what context we're going to return shortcodes for |
|
332 | - * @param array $fields what fields we're returning valid shortcodes for. If empty then we assume all fields are |
|
333 | - * to be returned. |
|
334 | - * @param bool $merged If TRUE then we don't return shortcodes indexed by field but instead an array of the |
|
335 | - * unique shortcodes for all the given (or all) fields. |
|
336 | - * @return mixed (array|bool) an array of shortcodes in the format array( '[shortcode] => 'label') OR FALSE if no |
|
337 | - * shortcodes found. |
|
338 | - * @throws EE_Error |
|
339 | - */ |
|
340 | - public function get_shortcodes($context, $fields = array(), $merged = false) |
|
341 | - { |
|
342 | - $messenger = $this->messenger(); |
|
343 | - $message_type = $this->message_type(); |
|
344 | - return EEH_MSG_Template::get_shortcodes($message_type, $messenger, $fields, $context, $merged); |
|
345 | - } |
|
346 | - |
|
347 | - |
|
348 | - /** |
|
349 | - * This just gets the template pack name assigned to this message template group. If it's not set, then we just |
|
350 | - * use the default template pack. |
|
351 | - * |
|
352 | - * @since 4.5.0 |
|
353 | - * @return string |
|
354 | - * @throws EE_Error |
|
355 | - */ |
|
356 | - public function get_template_pack_name() |
|
357 | - { |
|
358 | - return $this->get_extra_meta('MTP_template_pack', true, 'default'); |
|
359 | - } |
|
360 | - |
|
361 | - |
|
362 | - /** |
|
363 | - * This returns the specific template pack object referenced by the template pack name attached to this message |
|
364 | - * template group. If no template pack is assigned then the default template pack is retrieved. |
|
365 | - * |
|
366 | - * @since 4.5.0 |
|
367 | - * @return EE_Messages_Template_Pack |
|
368 | - * @throws EE_Error |
|
369 | - * @throws InvalidArgumentException |
|
370 | - * @throws ReflectionException |
|
371 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
372 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
373 | - */ |
|
374 | - public function get_template_pack() |
|
375 | - { |
|
376 | - $pack_name = $this->get_template_pack_name(); |
|
377 | - EE_Registry::instance()->load_helper('MSG_Template'); |
|
378 | - return EEH_MSG_Template::get_template_pack($pack_name); |
|
379 | - } |
|
380 | - |
|
381 | - |
|
382 | - /** |
|
383 | - * This retrieves the template variation assigned to this message template group. If it's not set, then we just |
|
384 | - * use the default template variation. |
|
385 | - * |
|
386 | - * @since 4.5.0 |
|
387 | - * @return string |
|
388 | - * @throws EE_Error |
|
389 | - */ |
|
390 | - public function get_template_pack_variation() |
|
391 | - { |
|
392 | - return $this->get_extra_meta('MTP_variation', true, 'default'); |
|
393 | - } |
|
394 | - |
|
395 | - |
|
396 | - /** |
|
397 | - * This just sets the template pack name attached to this message template group. |
|
398 | - * |
|
399 | - * @since 4.5.0 |
|
400 | - * @param string $template_pack_name What message template pack is assigned. |
|
401 | - * @return int |
|
402 | - * @throws EE_Error |
|
403 | - */ |
|
404 | - public function set_template_pack_name($template_pack_name) |
|
405 | - { |
|
406 | - return $this->update_extra_meta('MTP_template_pack', $template_pack_name); |
|
407 | - } |
|
408 | - |
|
409 | - |
|
410 | - /** |
|
411 | - * This just sets the template pack variation attached to this message template group. |
|
412 | - * |
|
413 | - * @since 4.5.0 |
|
414 | - * @param string $variation What variation is being set on the message template group. |
|
415 | - * @return int |
|
416 | - * @throws EE_Error |
|
417 | - */ |
|
418 | - public function set_template_pack_variation($variation) |
|
419 | - { |
|
420 | - return $this->update_extra_meta('MTP_variation', $variation); |
|
421 | - } |
|
422 | - |
|
423 | - |
|
424 | - /** |
|
425 | - * Deactivates the given context. |
|
426 | - * |
|
427 | - * @param $context |
|
428 | - * @return bool|int |
|
429 | - * @throws EE_Error |
|
430 | - * @throws InvalidIdentifierException |
|
431 | - */ |
|
432 | - public function deactivate_context($context) |
|
433 | - { |
|
434 | - $this->validate_context($context); |
|
435 | - return $this->update_extra_meta(self::ACTIVE_CONTEXT_RECORD_META_KEY_PREFIX . $context, false); |
|
436 | - } |
|
437 | - |
|
438 | - |
|
439 | - /** |
|
440 | - * Activates the given context. |
|
441 | - * |
|
442 | - * @param $context |
|
443 | - * @return bool|int |
|
444 | - * @throws EE_Error |
|
445 | - * @throws InvalidIdentifierException |
|
446 | - */ |
|
447 | - public function activate_context($context) |
|
448 | - { |
|
449 | - $this->validate_context($context); |
|
450 | - return $this->update_extra_meta(self::ACTIVE_CONTEXT_RECORD_META_KEY_PREFIX . $context, true); |
|
451 | - } |
|
452 | - |
|
453 | - |
|
454 | - /** |
|
455 | - * Returns whether the context is active or not. |
|
456 | - * Note, this will default to true if the extra meta record doesn't exist. |
|
457 | - * Also, this does NOT account for whether the "To" field is empty or not. Some messengers may allow the "To" field |
|
458 | - * to be empty (@see EE_Messenger::allow_empty_to_field()) so an empty "To" field is not always an indicator of |
|
459 | - * whether a context is "active" or not. |
|
460 | - * |
|
461 | - * @param $context |
|
462 | - * @return bool |
|
463 | - * @throws EE_Error |
|
464 | - * @throws InvalidIdentifierException |
|
465 | - */ |
|
466 | - public function is_context_active($context) |
|
467 | - { |
|
468 | - $this->validate_context($context); |
|
469 | - return filter_var( |
|
470 | - $this->get_extra_meta(self::ACTIVE_CONTEXT_RECORD_META_KEY_PREFIX . $context, true, true), |
|
471 | - FILTER_VALIDATE_BOOLEAN |
|
472 | - ); |
|
473 | - } |
|
474 | - |
|
475 | - |
|
476 | - /** |
|
477 | - * Validates the incoming context to verify it matches a registered context for the related message type. |
|
478 | - * @param string $context |
|
479 | - * @throws EE_Error |
|
480 | - * @throws InvalidIdentifierException |
|
481 | - */ |
|
482 | - public function validate_context($context) |
|
483 | - { |
|
484 | - $contexts = $this->contexts_config(); |
|
485 | - if (! isset($contexts[$context])) { |
|
486 | - throw new InvalidIdentifierException( |
|
487 | - '', |
|
488 | - '', |
|
489 | - sprintf( |
|
490 | - esc_html__( |
|
491 | - 'An invalid string identifying a context was provided. "%1$s" was received, and one of "%2$s" was expected.', |
|
492 | - 'event_espresso' |
|
493 | - ), |
|
494 | - $context, |
|
495 | - implode(',', array_keys($contexts)) |
|
496 | - ) |
|
497 | - ); |
|
498 | - } |
|
499 | - } |
|
18 | + /** |
|
19 | + * Extra Meta key prefix for whether a given context for this message tmeplate group is active or not. |
|
20 | + */ |
|
21 | + const ACTIVE_CONTEXT_RECORD_META_KEY_PREFIX = 'active_context_'; |
|
22 | + |
|
23 | + /** |
|
24 | + * @param array $props_n_values |
|
25 | + * @param string $timezone |
|
26 | + * @return EE_Message_Template_Group|mixed |
|
27 | + * @throws EE_Error |
|
28 | + */ |
|
29 | + public static function new_instance($props_n_values = array(), $timezone = '') |
|
30 | + { |
|
31 | + $has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone); |
|
32 | + return $has_object ? $has_object : new self($props_n_values, false, $timezone); |
|
33 | + } |
|
34 | + |
|
35 | + |
|
36 | + /** |
|
37 | + * @param array $props_n_values |
|
38 | + * @param string $timezone |
|
39 | + * @return EE_Message_Template_Group |
|
40 | + */ |
|
41 | + public static function new_instance_from_db($props_n_values = array(), $timezone = '') |
|
42 | + { |
|
43 | + return new self($props_n_values, true, $timezone); |
|
44 | + } |
|
45 | + |
|
46 | + |
|
47 | + /** |
|
48 | + * @param bool $message_type |
|
49 | + * @throws EE_Error |
|
50 | + */ |
|
51 | + public function set_message_type($message_type = false) |
|
52 | + { |
|
53 | + if (! $message_type) { |
|
54 | + throw new EE_Error(esc_html__('Missing required value for the message_type parameter', 'event_espresso')); |
|
55 | + } |
|
56 | + $this->set('MTP_message_type', $message_type); |
|
57 | + } |
|
58 | + |
|
59 | + |
|
60 | + /** |
|
61 | + * @param bool $messenger |
|
62 | + * @throws EE_Error |
|
63 | + */ |
|
64 | + public function set_messenger($messenger = false) |
|
65 | + { |
|
66 | + if (! $messenger) { |
|
67 | + throw new EE_Error(esc_html__('Missing required value for the messenger parameter', 'event_espresso')); |
|
68 | + } |
|
69 | + $this->set('MTP_messenger', $messenger); |
|
70 | + } |
|
71 | + |
|
72 | + |
|
73 | + /** |
|
74 | + * @param bool $GRP_ID |
|
75 | + * @throws EE_Error |
|
76 | + */ |
|
77 | + public function set_group_template_id($GRP_ID = false) |
|
78 | + { |
|
79 | + if (! $GRP_ID) { |
|
80 | + throw new EE_Error( |
|
81 | + esc_html__( |
|
82 | + 'Missing required value for the message template group id', |
|
83 | + 'event_espresso' |
|
84 | + ) |
|
85 | + ); |
|
86 | + } |
|
87 | + $this->set('GRP_ID', $GRP_ID); |
|
88 | + } |
|
89 | + |
|
90 | + |
|
91 | + /** |
|
92 | + * get Group ID |
|
93 | + * |
|
94 | + * @access public |
|
95 | + * @return int |
|
96 | + * @throws EE_Error |
|
97 | + */ |
|
98 | + public function GRP_ID() |
|
99 | + { |
|
100 | + return $this->get('GRP_ID'); |
|
101 | + } |
|
102 | + |
|
103 | + |
|
104 | + /** |
|
105 | + * get User ID |
|
106 | + * |
|
107 | + * @access public |
|
108 | + * @return int |
|
109 | + * @throws EE_Error |
|
110 | + */ |
|
111 | + public function user() |
|
112 | + { |
|
113 | + $user_id = $this->get('MTP_user_id'); |
|
114 | + return empty($user_id) ? get_current_user_id() : $user_id; |
|
115 | + } |
|
116 | + |
|
117 | + |
|
118 | + /** |
|
119 | + * Wrapper for the user function() (preserve backward compat) |
|
120 | + * |
|
121 | + * @since 4.5.0 |
|
122 | + * @return int |
|
123 | + * @throws EE_Error |
|
124 | + */ |
|
125 | + public function wp_user() |
|
126 | + { |
|
127 | + return $this->user(); |
|
128 | + } |
|
129 | + |
|
130 | + |
|
131 | + /** |
|
132 | + * This simply returns a count of all related events to this message template group |
|
133 | + * |
|
134 | + * @return int |
|
135 | + */ |
|
136 | + public function count_events() |
|
137 | + { |
|
138 | + return $this->count_related('Event'); |
|
139 | + } |
|
140 | + |
|
141 | + |
|
142 | + /** |
|
143 | + * returns the name saved in the db for this template |
|
144 | + * |
|
145 | + * @return string |
|
146 | + * @throws EE_Error |
|
147 | + */ |
|
148 | + public function name() |
|
149 | + { |
|
150 | + return $this->get('MTP_name'); |
|
151 | + } |
|
152 | + |
|
153 | + |
|
154 | + /** |
|
155 | + * Returns the description saved in the db for this template group |
|
156 | + * |
|
157 | + * @return string |
|
158 | + * @throws EE_Error |
|
159 | + */ |
|
160 | + public function description() |
|
161 | + { |
|
162 | + return $this->get('MTP_description'); |
|
163 | + } |
|
164 | + |
|
165 | + |
|
166 | + /** |
|
167 | + * returns all related EE_Message_Template objects |
|
168 | + * |
|
169 | + * @param array $query_params like EEM_Base::get_all() |
|
170 | + * @return EE_Message_Template[] |
|
171 | + * @throws EE_Error |
|
172 | + */ |
|
173 | + public function message_templates($query_params = array()) |
|
174 | + { |
|
175 | + return $this->get_many_related('Message_Template', $query_params); |
|
176 | + } |
|
177 | + |
|
178 | + |
|
179 | + /** |
|
180 | + * get Message Messenger |
|
181 | + * |
|
182 | + * @access public |
|
183 | + * @return string |
|
184 | + * @throws EE_Error |
|
185 | + */ |
|
186 | + public function messenger() |
|
187 | + { |
|
188 | + return $this->get('MTP_messenger'); |
|
189 | + } |
|
190 | + |
|
191 | + |
|
192 | + /** |
|
193 | + * get Message Messenger OBJECT |
|
194 | + * If an attempt to get the corresponding messenger object fails, then we set this message |
|
195 | + * template group to inactive, and save to db. Then return null so client code can handle |
|
196 | + * appropriately. |
|
197 | + * |
|
198 | + * @return EE_messenger |
|
199 | + * @throws EE_Error |
|
200 | + */ |
|
201 | + public function messenger_obj() |
|
202 | + { |
|
203 | + $messenger = $this->messenger(); |
|
204 | + try { |
|
205 | + $messenger = EEH_MSG_Template::messenger_obj($messenger); |
|
206 | + } catch (EE_Error $e) { |
|
207 | + //if an exception was thrown then let's deactivate this message template group because it means there is no |
|
208 | + // class for this messenger in this group. |
|
209 | + $this->set('MTP_is_active', false); |
|
210 | + $this->save(); |
|
211 | + return null; |
|
212 | + } |
|
213 | + return $messenger; |
|
214 | + } |
|
215 | + |
|
216 | + |
|
217 | + /** |
|
218 | + * get Message Type |
|
219 | + * |
|
220 | + * @access public |
|
221 | + * @return string |
|
222 | + * @throws EE_Error |
|
223 | + */ |
|
224 | + public function message_type() |
|
225 | + { |
|
226 | + return $this->get('MTP_message_type'); |
|
227 | + } |
|
228 | + |
|
229 | + |
|
230 | + /** |
|
231 | + * get Message type OBJECT |
|
232 | + * If an attempt to get the corresponding message type object fails, then we set this message |
|
233 | + * template group to inactive, and save to db. Then return null so client code can handle |
|
234 | + * appropriately. |
|
235 | + * |
|
236 | + * @throws EE_Error |
|
237 | + * @return EE_message_type|false if exception thrown. |
|
238 | + */ |
|
239 | + public function message_type_obj() |
|
240 | + { |
|
241 | + $message_type = $this->message_type(); |
|
242 | + try { |
|
243 | + $message_type = EEH_MSG_Template::message_type_obj($message_type); |
|
244 | + } catch (EE_Error $e) { |
|
245 | + //if an exception was thrown then let's deactivate this message template group because it means there is no |
|
246 | + // class for the message type in this group. |
|
247 | + $this->set('MTP_is_active', false); |
|
248 | + $this->save(); |
|
249 | + return null; |
|
250 | + } |
|
251 | + return $message_type; |
|
252 | + } |
|
253 | + |
|
254 | + |
|
255 | + /** |
|
256 | + * @return array |
|
257 | + * @throws EE_Error |
|
258 | + */ |
|
259 | + public function contexts_config() |
|
260 | + { |
|
261 | + return $this->message_type_obj()->get_contexts(); |
|
262 | + } |
|
263 | + |
|
264 | + |
|
265 | + /** |
|
266 | + * This returns the context_label for contexts as set in the message type object |
|
267 | + * Note this is an array with singular and plural keys |
|
268 | + * |
|
269 | + * @access public |
|
270 | + * @return array labels for "context" |
|
271 | + * @throws EE_Error |
|
272 | + */ |
|
273 | + public function context_label() |
|
274 | + { |
|
275 | + $obj = $this->message_type_obj(); |
|
276 | + return $obj->get_context_label(); |
|
277 | + } |
|
278 | + |
|
279 | + |
|
280 | + /** |
|
281 | + * This returns an array of EE_Message_Template objects indexed by context and field. |
|
282 | + * |
|
283 | + * @return array () |
|
284 | + * @throws EE_Error |
|
285 | + */ |
|
286 | + public function context_templates() |
|
287 | + { |
|
288 | + $mtps_arr = array(); |
|
289 | + $mtps = $this->get_many_related('Message_Template'); |
|
290 | + if (empty($mtps)) { |
|
291 | + return array(); |
|
292 | + } |
|
293 | + //note contexts could have CHECKBOX fields per context. So we return the objects indexed by context AND field. |
|
294 | + foreach ($mtps as $mtp) { |
|
295 | + $mtps_arr[$mtp->get('MTP_context')][$mtp->get('MTP_template_field')] = $mtp; |
|
296 | + } |
|
297 | + return $mtps_arr; |
|
298 | + } |
|
299 | + |
|
300 | + |
|
301 | + /** |
|
302 | + * this returns if the template group this template belongs to is global |
|
303 | + * |
|
304 | + * @return bool true if it is, false if it isn't |
|
305 | + * @throws EE_Error |
|
306 | + */ |
|
307 | + public function is_global() |
|
308 | + { |
|
309 | + return $this->get('MTP_is_global'); |
|
310 | + } |
|
311 | + |
|
312 | + |
|
313 | + /** |
|
314 | + * this returns if the template group this template belongs to is active (i.e. turned "on" or not) |
|
315 | + * |
|
316 | + * @return bool true if it is, false if it isn't |
|
317 | + * @throws EE_Error |
|
318 | + */ |
|
319 | + public function is_active() |
|
320 | + { |
|
321 | + return $this->get('MTP_is_active'); |
|
322 | + } |
|
323 | + |
|
324 | + |
|
325 | + /** |
|
326 | + * This will return an array of shortcodes => labels from the messenger and message_type objects associated with |
|
327 | + * this template. |
|
328 | + * |
|
329 | + * @since 4.3.0 |
|
330 | + * @uses EEH_MSG_Template::get_shortcodes() |
|
331 | + * @param string $context what context we're going to return shortcodes for |
|
332 | + * @param array $fields what fields we're returning valid shortcodes for. If empty then we assume all fields are |
|
333 | + * to be returned. |
|
334 | + * @param bool $merged If TRUE then we don't return shortcodes indexed by field but instead an array of the |
|
335 | + * unique shortcodes for all the given (or all) fields. |
|
336 | + * @return mixed (array|bool) an array of shortcodes in the format array( '[shortcode] => 'label') OR FALSE if no |
|
337 | + * shortcodes found. |
|
338 | + * @throws EE_Error |
|
339 | + */ |
|
340 | + public function get_shortcodes($context, $fields = array(), $merged = false) |
|
341 | + { |
|
342 | + $messenger = $this->messenger(); |
|
343 | + $message_type = $this->message_type(); |
|
344 | + return EEH_MSG_Template::get_shortcodes($message_type, $messenger, $fields, $context, $merged); |
|
345 | + } |
|
346 | + |
|
347 | + |
|
348 | + /** |
|
349 | + * This just gets the template pack name assigned to this message template group. If it's not set, then we just |
|
350 | + * use the default template pack. |
|
351 | + * |
|
352 | + * @since 4.5.0 |
|
353 | + * @return string |
|
354 | + * @throws EE_Error |
|
355 | + */ |
|
356 | + public function get_template_pack_name() |
|
357 | + { |
|
358 | + return $this->get_extra_meta('MTP_template_pack', true, 'default'); |
|
359 | + } |
|
360 | + |
|
361 | + |
|
362 | + /** |
|
363 | + * This returns the specific template pack object referenced by the template pack name attached to this message |
|
364 | + * template group. If no template pack is assigned then the default template pack is retrieved. |
|
365 | + * |
|
366 | + * @since 4.5.0 |
|
367 | + * @return EE_Messages_Template_Pack |
|
368 | + * @throws EE_Error |
|
369 | + * @throws InvalidArgumentException |
|
370 | + * @throws ReflectionException |
|
371 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
372 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
373 | + */ |
|
374 | + public function get_template_pack() |
|
375 | + { |
|
376 | + $pack_name = $this->get_template_pack_name(); |
|
377 | + EE_Registry::instance()->load_helper('MSG_Template'); |
|
378 | + return EEH_MSG_Template::get_template_pack($pack_name); |
|
379 | + } |
|
380 | + |
|
381 | + |
|
382 | + /** |
|
383 | + * This retrieves the template variation assigned to this message template group. If it's not set, then we just |
|
384 | + * use the default template variation. |
|
385 | + * |
|
386 | + * @since 4.5.0 |
|
387 | + * @return string |
|
388 | + * @throws EE_Error |
|
389 | + */ |
|
390 | + public function get_template_pack_variation() |
|
391 | + { |
|
392 | + return $this->get_extra_meta('MTP_variation', true, 'default'); |
|
393 | + } |
|
394 | + |
|
395 | + |
|
396 | + /** |
|
397 | + * This just sets the template pack name attached to this message template group. |
|
398 | + * |
|
399 | + * @since 4.5.0 |
|
400 | + * @param string $template_pack_name What message template pack is assigned. |
|
401 | + * @return int |
|
402 | + * @throws EE_Error |
|
403 | + */ |
|
404 | + public function set_template_pack_name($template_pack_name) |
|
405 | + { |
|
406 | + return $this->update_extra_meta('MTP_template_pack', $template_pack_name); |
|
407 | + } |
|
408 | + |
|
409 | + |
|
410 | + /** |
|
411 | + * This just sets the template pack variation attached to this message template group. |
|
412 | + * |
|
413 | + * @since 4.5.0 |
|
414 | + * @param string $variation What variation is being set on the message template group. |
|
415 | + * @return int |
|
416 | + * @throws EE_Error |
|
417 | + */ |
|
418 | + public function set_template_pack_variation($variation) |
|
419 | + { |
|
420 | + return $this->update_extra_meta('MTP_variation', $variation); |
|
421 | + } |
|
422 | + |
|
423 | + |
|
424 | + /** |
|
425 | + * Deactivates the given context. |
|
426 | + * |
|
427 | + * @param $context |
|
428 | + * @return bool|int |
|
429 | + * @throws EE_Error |
|
430 | + * @throws InvalidIdentifierException |
|
431 | + */ |
|
432 | + public function deactivate_context($context) |
|
433 | + { |
|
434 | + $this->validate_context($context); |
|
435 | + return $this->update_extra_meta(self::ACTIVE_CONTEXT_RECORD_META_KEY_PREFIX . $context, false); |
|
436 | + } |
|
437 | + |
|
438 | + |
|
439 | + /** |
|
440 | + * Activates the given context. |
|
441 | + * |
|
442 | + * @param $context |
|
443 | + * @return bool|int |
|
444 | + * @throws EE_Error |
|
445 | + * @throws InvalidIdentifierException |
|
446 | + */ |
|
447 | + public function activate_context($context) |
|
448 | + { |
|
449 | + $this->validate_context($context); |
|
450 | + return $this->update_extra_meta(self::ACTIVE_CONTEXT_RECORD_META_KEY_PREFIX . $context, true); |
|
451 | + } |
|
452 | + |
|
453 | + |
|
454 | + /** |
|
455 | + * Returns whether the context is active or not. |
|
456 | + * Note, this will default to true if the extra meta record doesn't exist. |
|
457 | + * Also, this does NOT account for whether the "To" field is empty or not. Some messengers may allow the "To" field |
|
458 | + * to be empty (@see EE_Messenger::allow_empty_to_field()) so an empty "To" field is not always an indicator of |
|
459 | + * whether a context is "active" or not. |
|
460 | + * |
|
461 | + * @param $context |
|
462 | + * @return bool |
|
463 | + * @throws EE_Error |
|
464 | + * @throws InvalidIdentifierException |
|
465 | + */ |
|
466 | + public function is_context_active($context) |
|
467 | + { |
|
468 | + $this->validate_context($context); |
|
469 | + return filter_var( |
|
470 | + $this->get_extra_meta(self::ACTIVE_CONTEXT_RECORD_META_KEY_PREFIX . $context, true, true), |
|
471 | + FILTER_VALIDATE_BOOLEAN |
|
472 | + ); |
|
473 | + } |
|
474 | + |
|
475 | + |
|
476 | + /** |
|
477 | + * Validates the incoming context to verify it matches a registered context for the related message type. |
|
478 | + * @param string $context |
|
479 | + * @throws EE_Error |
|
480 | + * @throws InvalidIdentifierException |
|
481 | + */ |
|
482 | + public function validate_context($context) |
|
483 | + { |
|
484 | + $contexts = $this->contexts_config(); |
|
485 | + if (! isset($contexts[$context])) { |
|
486 | + throw new InvalidIdentifierException( |
|
487 | + '', |
|
488 | + '', |
|
489 | + sprintf( |
|
490 | + esc_html__( |
|
491 | + 'An invalid string identifying a context was provided. "%1$s" was received, and one of "%2$s" was expected.', |
|
492 | + 'event_espresso' |
|
493 | + ), |
|
494 | + $context, |
|
495 | + implode(',', array_keys($contexts)) |
|
496 | + ) |
|
497 | + ); |
|
498 | + } |
|
499 | + } |
|
500 | 500 | } |
@@ -50,7 +50,7 @@ discard block |
||
50 | 50 | */ |
51 | 51 | public function set_message_type($message_type = false) |
52 | 52 | { |
53 | - if (! $message_type) { |
|
53 | + if ( ! $message_type) { |
|
54 | 54 | throw new EE_Error(esc_html__('Missing required value for the message_type parameter', 'event_espresso')); |
55 | 55 | } |
56 | 56 | $this->set('MTP_message_type', $message_type); |
@@ -63,7 +63,7 @@ discard block |
||
63 | 63 | */ |
64 | 64 | public function set_messenger($messenger = false) |
65 | 65 | { |
66 | - if (! $messenger) { |
|
66 | + if ( ! $messenger) { |
|
67 | 67 | throw new EE_Error(esc_html__('Missing required value for the messenger parameter', 'event_espresso')); |
68 | 68 | } |
69 | 69 | $this->set('MTP_messenger', $messenger); |
@@ -76,7 +76,7 @@ discard block |
||
76 | 76 | */ |
77 | 77 | public function set_group_template_id($GRP_ID = false) |
78 | 78 | { |
79 | - if (! $GRP_ID) { |
|
79 | + if ( ! $GRP_ID) { |
|
80 | 80 | throw new EE_Error( |
81 | 81 | esc_html__( |
82 | 82 | 'Missing required value for the message template group id', |
@@ -432,7 +432,7 @@ discard block |
||
432 | 432 | public function deactivate_context($context) |
433 | 433 | { |
434 | 434 | $this->validate_context($context); |
435 | - return $this->update_extra_meta(self::ACTIVE_CONTEXT_RECORD_META_KEY_PREFIX . $context, false); |
|
435 | + return $this->update_extra_meta(self::ACTIVE_CONTEXT_RECORD_META_KEY_PREFIX.$context, false); |
|
436 | 436 | } |
437 | 437 | |
438 | 438 | |
@@ -447,7 +447,7 @@ discard block |
||
447 | 447 | public function activate_context($context) |
448 | 448 | { |
449 | 449 | $this->validate_context($context); |
450 | - return $this->update_extra_meta(self::ACTIVE_CONTEXT_RECORD_META_KEY_PREFIX . $context, true); |
|
450 | + return $this->update_extra_meta(self::ACTIVE_CONTEXT_RECORD_META_KEY_PREFIX.$context, true); |
|
451 | 451 | } |
452 | 452 | |
453 | 453 | |
@@ -467,7 +467,7 @@ discard block |
||
467 | 467 | { |
468 | 468 | $this->validate_context($context); |
469 | 469 | return filter_var( |
470 | - $this->get_extra_meta(self::ACTIVE_CONTEXT_RECORD_META_KEY_PREFIX . $context, true, true), |
|
470 | + $this->get_extra_meta(self::ACTIVE_CONTEXT_RECORD_META_KEY_PREFIX.$context, true, true), |
|
471 | 471 | FILTER_VALIDATE_BOOLEAN |
472 | 472 | ); |
473 | 473 | } |
@@ -482,7 +482,7 @@ discard block |
||
482 | 482 | public function validate_context($context) |
483 | 483 | { |
484 | 484 | $contexts = $this->contexts_config(); |
485 | - if (! isset($contexts[$context])) { |
|
485 | + if ( ! isset($contexts[$context])) { |
|
486 | 486 | throw new InvalidIdentifierException( |
487 | 487 | '', |
488 | 488 | '', |
@@ -459,7 +459,7 @@ discard block |
||
459 | 459 | * there's a single shared message template group among all the events. Otherwise it returns null. |
460 | 460 | * |
461 | 461 | * @param array $event_ids |
462 | - * @return EE_Message_Template_Group|null |
|
462 | + * @return null|EE_Base_Class |
|
463 | 463 | * @throws EE_Error |
464 | 464 | * @throws InvalidArgumentException |
465 | 465 | * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
@@ -495,7 +495,7 @@ discard block |
||
495 | 495 | /** |
496 | 496 | * Retrieves the global message template group for the current messenger and message type. |
497 | 497 | * |
498 | - * @return EE_Message_Template_Group|null |
|
498 | + * @return null|EE_Base_Class |
|
499 | 499 | * @throws EE_Error |
500 | 500 | * @throws InvalidArgumentException |
501 | 501 | * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
@@ -641,7 +641,7 @@ discard block |
||
641 | 641 | * @param EE_Messages_Addressee $recipient |
642 | 642 | * @param array $templates formatted array of templates used for parsing data. |
643 | 643 | * @param EE_Message_Template_Group $message_template_group |
644 | - * @return bool|EE_Message |
|
644 | + * @return EE_Message |
|
645 | 645 | * @throws EE_Error |
646 | 646 | */ |
647 | 647 | protected function _setup_message_object( |
@@ -13,970 +13,970 @@ |
||
13 | 13 | { |
14 | 14 | |
15 | 15 | |
16 | - /** |
|
17 | - * @type EE_Messages_Data_Handler_Collection |
|
18 | - */ |
|
19 | - protected $_data_handler_collection; |
|
20 | - |
|
21 | - /** |
|
22 | - * @type EE_Message_Template_Group_Collection |
|
23 | - */ |
|
24 | - protected $_template_collection; |
|
25 | - |
|
26 | - /** |
|
27 | - * This will hold the data handler for the current EE_Message being generated. |
|
28 | - * |
|
29 | - * @type EE_Messages_incoming_data |
|
30 | - */ |
|
31 | - protected $_current_data_handler; |
|
32 | - |
|
33 | - /** |
|
34 | - * This holds the EE_Messages_Queue that contains the messages to generate. |
|
35 | - * |
|
36 | - * @type EE_Messages_Queue |
|
37 | - */ |
|
38 | - protected $_generation_queue; |
|
39 | - |
|
40 | - /** |
|
41 | - * This holds the EE_Messages_Queue that will store the generated EE_Message objects. |
|
42 | - * |
|
43 | - * @type EE_Messages_Queue |
|
44 | - */ |
|
45 | - protected $_ready_queue; |
|
46 | - |
|
47 | - /** |
|
48 | - * This is a container for any error messages that get created through the generation |
|
49 | - * process. |
|
50 | - * |
|
51 | - * @type array |
|
52 | - */ |
|
53 | - protected $_error_msg = array(); |
|
54 | - |
|
55 | - /** |
|
56 | - * Flag used to set when the current EE_Message in the generation queue has been verified. |
|
57 | - * |
|
58 | - * @type bool |
|
59 | - */ |
|
60 | - protected $_verified = false; |
|
61 | - |
|
62 | - /** |
|
63 | - * This will hold the current messenger object corresponding with the current EE_Message in the generation queue. |
|
64 | - * |
|
65 | - * @type EE_messenger |
|
66 | - */ |
|
67 | - protected $_current_messenger; |
|
68 | - |
|
69 | - /** |
|
70 | - * This will hold the current message type object corresponding with the current EE_Message in the generation queue. |
|
71 | - * |
|
72 | - * @type EE_message_type |
|
73 | - */ |
|
74 | - protected $_current_message_type; |
|
75 | - |
|
76 | - /** |
|
77 | - * @type EEH_Parse_Shortcodes |
|
78 | - */ |
|
79 | - protected $_shortcode_parser; |
|
80 | - |
|
81 | - |
|
82 | - /** |
|
83 | - * @param EE_Messages_Queue $generation_queue |
|
84 | - * @param \EE_Messages_Queue $ready_queue |
|
85 | - * @param \EE_Messages_Data_Handler_Collection $data_handler_collection |
|
86 | - * @param \EE_Message_Template_Group_Collection $template_collection |
|
87 | - * @param \EEH_Parse_Shortcodes $shortcode_parser |
|
88 | - */ |
|
89 | - public function __construct( |
|
90 | - EE_Messages_Queue $generation_queue, |
|
91 | - EE_Messages_Queue $ready_queue, |
|
92 | - EE_Messages_Data_Handler_Collection $data_handler_collection, |
|
93 | - EE_Message_Template_Group_Collection $template_collection, |
|
94 | - EEH_Parse_Shortcodes $shortcode_parser |
|
95 | - ) { |
|
96 | - $this->_generation_queue = $generation_queue; |
|
97 | - $this->_ready_queue = $ready_queue; |
|
98 | - $this->_data_handler_collection = $data_handler_collection; |
|
99 | - $this->_template_collection = $template_collection; |
|
100 | - $this->_shortcode_parser = $shortcode_parser; |
|
101 | - } |
|
102 | - |
|
103 | - |
|
104 | - /** |
|
105 | - * @return EE_Messages_Queue |
|
106 | - */ |
|
107 | - public function generation_queue() |
|
108 | - { |
|
109 | - return $this->_generation_queue; |
|
110 | - } |
|
111 | - |
|
112 | - |
|
113 | - /** |
|
114 | - * This iterates through the provided queue and generates the EE_Message objects. |
|
115 | - * When iterating through the queue, the queued item that served as the base for generating other EE_Message |
|
116 | - * objects gets removed and the new EE_Message objects get added to a NEW queue. The NEW queue is then returned |
|
117 | - * for the caller to decide what to do with it. |
|
118 | - * |
|
119 | - * @param bool $save Whether to save the EE_Message objects in the new queue or just return. |
|
120 | - * @return EE_Messages_Queue The new queue for holding generated EE_Message objects. |
|
121 | - * @throws EE_Error |
|
122 | - * @throws ReflectionException |
|
123 | - */ |
|
124 | - public function generate($save = true) |
|
125 | - { |
|
126 | - //iterate through the messages in the queue, generate, and add to new queue. |
|
127 | - $this->_generation_queue->get_message_repository()->rewind(); |
|
128 | - while ($this->_generation_queue->get_message_repository()->valid()) { |
|
129 | - //reset "current" properties |
|
130 | - $this->_reset_current_properties(); |
|
131 | - |
|
132 | - /** @type EE_Message $msg */ |
|
133 | - $msg = $this->_generation_queue->get_message_repository()->current(); |
|
134 | - |
|
135 | - /** |
|
136 | - * need to get the next object and capture it for setting manually after deletes. The reason is that when |
|
137 | - * an object is removed from the repo then valid for the next object will fail. |
|
138 | - */ |
|
139 | - $this->_generation_queue->get_message_repository()->next(); |
|
140 | - $next_msg = $this->_generation_queue->get_message_repository()->current(); |
|
141 | - //restore pointer to current item |
|
142 | - $this->_generation_queue->get_message_repository()->set_current($msg); |
|
143 | - |
|
144 | - //skip and delete if the current $msg is NOT incomplete (queued for generation) |
|
145 | - if ($msg->STS_ID() !== EEM_Message::status_incomplete) { |
|
146 | - //we keep this item in the db just remove from the repo. |
|
147 | - $this->_generation_queue->get_message_repository()->remove($msg); |
|
148 | - //next item |
|
149 | - $this->_generation_queue->get_message_repository()->set_current($next_msg); |
|
150 | - continue; |
|
151 | - } |
|
152 | - |
|
153 | - if ($this->_verify()) { |
|
154 | - //let's get generating! |
|
155 | - $this->_generate(); |
|
156 | - } |
|
157 | - |
|
158 | - //don't persist debug_only messages if the messages system is not in debug mode. |
|
159 | - if ($msg->STS_ID() === EEM_Message::status_debug_only |
|
160 | - && ! EEM_Message::debug() |
|
161 | - ) { |
|
162 | - do_action( |
|
163 | - 'AHEE__EE_Messages_Generator__generate__before_debug_delete', |
|
164 | - $msg, |
|
165 | - $this->_error_msg, |
|
166 | - $this->_current_messenger, |
|
167 | - $this->_current_message_type, |
|
168 | - $this->_current_data_handler |
|
169 | - ); |
|
170 | - $this->_generation_queue->get_message_repository()->delete(); |
|
171 | - $this->_generation_queue->get_message_repository()->set_current($next_msg); |
|
172 | - continue; |
|
173 | - } |
|
174 | - |
|
175 | - //if there are error messages then let's set the status and the error message. |
|
176 | - if ($this->_error_msg) { |
|
177 | - //if the status is already debug only, then let's leave it at that. |
|
178 | - if ($msg->STS_ID() !== EEM_Message::status_debug_only) { |
|
179 | - $msg->set_STS_ID(EEM_Message::status_failed); |
|
180 | - } |
|
181 | - do_action( |
|
182 | - 'AHEE__EE_Messages_Generator__generate__processing_failed_message', |
|
183 | - $msg, |
|
184 | - $this->_error_msg, |
|
185 | - $this->_current_messenger, |
|
186 | - $this->_current_message_type, |
|
187 | - $this->_current_data_handler |
|
188 | - ); |
|
189 | - $msg->set_error_message( |
|
190 | - esc_html__('Message failed to generate for the following reasons: ', 'event_espresso') |
|
191 | - . "\n" |
|
192 | - . implode("\n", $this->_error_msg) |
|
193 | - ); |
|
194 | - $msg->set_modified(time()); |
|
195 | - } else { |
|
196 | - do_action( |
|
197 | - 'AHEE__EE_Messages_Generator__generate__before_successful_generated_message_delete', |
|
198 | - $msg, |
|
199 | - $this->_error_msg, |
|
200 | - $this->_current_messenger, |
|
201 | - $this->_current_message_type, |
|
202 | - $this->_current_data_handler |
|
203 | - ); |
|
204 | - //remove from db |
|
205 | - $this->_generation_queue->get_message_repository()->delete(); |
|
206 | - } |
|
207 | - //next item |
|
208 | - $this->_generation_queue->get_message_repository()->set_current($next_msg); |
|
209 | - } |
|
210 | - |
|
211 | - //generation queue is ALWAYS saved to record any errors in the generation process. |
|
212 | - $this->_generation_queue->save(); |
|
213 | - |
|
214 | - /** |
|
215 | - * save _ready_queue if flag set. |
|
216 | - * Note: The EE_Message objects have values set via the EE_Base_Class::set_field_or_extra_meta() method. This |
|
217 | - * means if a field was added that is not a valid database column. The EE_Message was already saved to the db |
|
218 | - * so a EE_Extra_Meta entry could be created and attached to the EE_Message. In those cases the save flag is |
|
219 | - * irrelevant. |
|
220 | - */ |
|
221 | - if ($save) { |
|
222 | - $this->_ready_queue->save(); |
|
223 | - } |
|
224 | - |
|
225 | - //final reset of properties |
|
226 | - $this->_reset_current_properties(); |
|
227 | - |
|
228 | - return $this->_ready_queue; |
|
229 | - } |
|
230 | - |
|
231 | - |
|
232 | - /** |
|
233 | - * This resets all the properties used for holding "current" values corresponding to the current EE_Message object |
|
234 | - * in the generation queue. |
|
235 | - */ |
|
236 | - protected function _reset_current_properties() |
|
237 | - { |
|
238 | - $this->_verified = false; |
|
239 | - //make sure any _data value in the current message type is reset |
|
240 | - if ($this->_current_message_type instanceof EE_message_type) { |
|
241 | - $this->_current_message_type->reset_data(); |
|
242 | - } |
|
243 | - $this->_current_messenger = $this->_current_message_type = $this->_current_data_handler = null; |
|
244 | - } |
|
245 | - |
|
246 | - |
|
247 | - /** |
|
248 | - * This proceeds with the actual generation of a message. By the time this is called, there should already be a |
|
249 | - * $_current_data_handler set and all incoming information should be validated for the current EE_Message in the |
|
250 | - * _generating_queue. |
|
251 | - * |
|
252 | - * @return bool Whether the message was successfully generated or not. |
|
253 | - * @throws EE_Error |
|
254 | - * @throws InvalidArgumentException |
|
255 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
256 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
257 | - */ |
|
258 | - protected function _generate() |
|
259 | - { |
|
260 | - //double check verification has run and that everything is ready to work with (saves us having to validate |
|
261 | - // everything again). |
|
262 | - if (! $this->_verified) { |
|
263 | - return false; //get out because we don't have a valid setup to work with. |
|
264 | - } |
|
265 | - |
|
266 | - |
|
267 | - try { |
|
268 | - $addressees = $this->_current_message_type->get_addressees( |
|
269 | - $this->_current_data_handler, |
|
270 | - $this->_generation_queue->get_message_repository()->current()->context() |
|
271 | - ); |
|
272 | - } catch (EE_Error $e) { |
|
273 | - $this->_error_msg[] = $e->getMessage(); |
|
274 | - return false; |
|
275 | - } |
|
276 | - |
|
277 | - |
|
278 | - //if no addressees then get out because there is nothing to generation (possible bad data). |
|
279 | - if (! $this->_valid_addressees($addressees)) { |
|
280 | - do_action( |
|
281 | - 'AHEE__EE_Messages_Generator___generate__invalid_addressees', |
|
282 | - $this->_generation_queue->get_message_repository()->current(), |
|
283 | - $addressees, |
|
284 | - $this->_current_messenger, |
|
285 | - $this->_current_message_type, |
|
286 | - $this->_current_data_handler |
|
287 | - ); |
|
288 | - $this->_generation_queue->get_message_repository()->current()->set_STS_ID( |
|
289 | - EEM_Message::status_debug_only |
|
290 | - ); |
|
291 | - $this->_error_msg[] = esc_html__( |
|
292 | - 'This is not a critical error but an informational notice. Unable to generate messages EE_Messages_Addressee objects. There were no attendees prepared by the data handler. Sometimes this is because messages only get generated for certain registration statuses. For example, the ticket notice message type only goes to approved registrations.', |
|
293 | - 'event_espresso' |
|
294 | - ); |
|
295 | - return false; |
|
296 | - } |
|
297 | - |
|
298 | - $message_template_group = $this->_get_message_template_group(); |
|
299 | - |
|
300 | - //in the unlikely event there is no EE_Message_Template_Group available, get out! |
|
301 | - if (! $message_template_group instanceof EE_Message_Template_Group) { |
|
302 | - $this->_error_msg[] = esc_html__( |
|
303 | - 'Unable to get the Message Templates for the Message being generated. No message template group accessible.', |
|
304 | - 'event_espresso' |
|
305 | - ); |
|
306 | - return false; |
|
307 | - } |
|
308 | - |
|
309 | - //get formatted templates for using to parse and setup EE_Message objects. |
|
310 | - $templates = $this->_get_templates($message_template_group); |
|
311 | - |
|
312 | - |
|
313 | - //setup new EE_Message objects (and add to _ready_queue) |
|
314 | - return $this->_assemble_messages($addressees, $templates, $message_template_group); |
|
315 | - } |
|
316 | - |
|
317 | - |
|
318 | - /** |
|
319 | - * Retrieves the message template group being used for generating messages. |
|
320 | - * Note: this also utilizes the EE_Message_Template_Group_Collection to avoid having to hit the db multiple times. |
|
321 | - * |
|
322 | - * @return EE_Message_Template_Group|null |
|
323 | - * @throws EE_Error |
|
324 | - * @throws InvalidArgumentException |
|
325 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
326 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
327 | - */ |
|
328 | - protected function _get_message_template_group() |
|
329 | - { |
|
330 | - //first see if there is a specific message template group requested (current message in the queue has a specific |
|
331 | - //GRP_ID |
|
332 | - $message_template_group = $this->_specific_message_template_group_from_queue(); |
|
333 | - if ($message_template_group instanceof EE_Message_Template_Group) { |
|
334 | - return $message_template_group; |
|
335 | - } |
|
336 | - |
|
337 | - //get event_ids from the datahandler so we can check to see if there's already a message template group for them |
|
338 | - //in the collection. |
|
339 | - $event_ids = $this->_get_event_ids_from_current_data_handler(); |
|
340 | - $message_template_group = $this->_template_collection->get_by_key( |
|
341 | - $this->_template_collection->getKey( |
|
342 | - $this->_current_messenger->name, |
|
343 | - $this->_current_message_type->name, |
|
344 | - $event_ids |
|
345 | - ) |
|
346 | - ); |
|
347 | - |
|
348 | - //if we have a message template group then no need to hit the database, just return it. |
|
349 | - if ($message_template_group instanceof EE_Message_Template_Group) { |
|
350 | - return $message_template_group; |
|
351 | - } |
|
352 | - |
|
353 | - //okay made it here, so let's get the global group first for this messenger and message type to ensure |
|
354 | - //there is no override set. |
|
355 | - $global_message_template_group = |
|
356 | - $this->_get_global_message_template_group_for_current_messenger_and_message_type(); |
|
357 | - |
|
358 | - if ($global_message_template_group instanceof EE_Message_Template_Group |
|
359 | - && $global_message_template_group->get('MTP_is_override') |
|
360 | - ) { |
|
361 | - return $global_message_template_group; |
|
362 | - } |
|
363 | - |
|
364 | - //if we're still here, that means there was no message template group for the events in the collection and |
|
365 | - //the global message template group for the messenger and message type is not set for override. So next step is |
|
366 | - //to see if there is a common shared custom message template group for this set of events. |
|
367 | - $message_template_group = $this->_get_shared_message_template_for_events($event_ids); |
|
368 | - if ($message_template_group instanceof EE_Message_Template_Group) { |
|
369 | - return $message_template_group; |
|
370 | - } |
|
371 | - |
|
372 | - //STILL here? Okay that means the fallback is to just use the global message template group for this event set. |
|
373 | - //So we'll cache the global group for this event set (so this logic doesn't have to be repeated in this request) |
|
374 | - //and return it. |
|
375 | - if ($global_message_template_group instanceof EE_Message_Template_Group) { |
|
376 | - $this->_template_collection->add( |
|
377 | - $global_message_template_group, |
|
378 | - $event_ids |
|
379 | - ); |
|
380 | - return $global_message_template_group; |
|
381 | - } |
|
382 | - |
|
383 | - //if we land here that means there's NO active message template group for this set. |
|
384 | - //TODO this will be a good target for some optimization down the road. Whenever there is no active message |
|
385 | - //template group for a given event set then cache that result so we don't repeat the logic. However, for now, |
|
386 | - //this should likely bit hit rarely enough that it's not a significant issue. |
|
387 | - return null; |
|
388 | - } |
|
389 | - |
|
390 | - |
|
391 | - /** |
|
392 | - * This checks the current message in the queue and determines if there is a specific Message Template Group |
|
393 | - * requested for that message. |
|
394 | - * |
|
395 | - * @return EE_Message_Template_Group|null |
|
396 | - * @throws EE_Error |
|
397 | - * @throws InvalidArgumentException |
|
398 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
399 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
400 | - */ |
|
401 | - protected function _specific_message_template_group_from_queue() |
|
402 | - { |
|
403 | - //is there a GRP_ID already on the EE_Message object? If there is, then a specific template has been requested |
|
404 | - //so let's use that. |
|
405 | - $GRP_ID = $this->_generation_queue->get_message_repository()->current()->GRP_ID(); |
|
406 | - |
|
407 | - if ($GRP_ID) { |
|
408 | - //attempt to retrieve from repo first |
|
409 | - $message_template_group = $this->_template_collection->get_by_ID($GRP_ID); |
|
410 | - if ($message_template_group instanceof EE_Message_Template_Group) { |
|
411 | - return $message_template_group; //got it! |
|
412 | - } |
|
413 | - |
|
414 | - //nope don't have it yet. Get from DB then add to repo if its not here, then that means the current GRP_ID |
|
415 | - //is not valid, so we'll continue on in the code assuming there's NO GRP_ID. |
|
416 | - $message_template_group = EEM_Message_Template_Group::instance()->get_one_by_ID($GRP_ID); |
|
417 | - if ($message_template_group instanceof EE_Message_Template_Group) { |
|
418 | - $this->_template_collection->add($message_template_group); |
|
419 | - return $message_template_group; |
|
420 | - } |
|
421 | - } |
|
422 | - return null; |
|
423 | - } |
|
424 | - |
|
425 | - |
|
426 | - /** |
|
427 | - * Returns whether the event ids passed in all share the same message template group for the current message type |
|
428 | - * and messenger. |
|
429 | - * |
|
430 | - * @param array $event_ids |
|
431 | - * @return bool true means they DO share the same message template group, false means they don't. |
|
432 | - * @throws EE_Error |
|
433 | - * @throws InvalidArgumentException |
|
434 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
435 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
436 | - */ |
|
437 | - protected function _queue_shares_same_message_template_group_for_events(array $event_ids) |
|
438 | - { |
|
439 | - foreach ($this->_current_data_handler->events as $event) { |
|
440 | - $event_ids[$event['ID']] = $event['ID']; |
|
441 | - } |
|
442 | - $count_of_message_template_groups = EEM_Message_Template_Group::instance()->count( |
|
443 | - array( |
|
444 | - array( |
|
445 | - 'Event.EVT_ID' => array('IN', $event_ids), |
|
446 | - 'MTP_messenger' => $this->_current_messenger->name, |
|
447 | - 'MTP_message_type' => $this->_current_message_type->name, |
|
448 | - ), |
|
449 | - ), |
|
450 | - 'GRP_ID', |
|
451 | - true |
|
452 | - ); |
|
453 | - return $count_of_message_template_groups === 1; |
|
454 | - } |
|
455 | - |
|
456 | - |
|
457 | - /** |
|
458 | - * This will get the shared message template group for events that are in the current data handler but ONLY if |
|
459 | - * there's a single shared message template group among all the events. Otherwise it returns null. |
|
460 | - * |
|
461 | - * @param array $event_ids |
|
462 | - * @return EE_Message_Template_Group|null |
|
463 | - * @throws EE_Error |
|
464 | - * @throws InvalidArgumentException |
|
465 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
466 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
467 | - */ |
|
468 | - protected function _get_shared_message_template_for_events(array $event_ids) |
|
469 | - { |
|
470 | - $message_template_group = null; |
|
471 | - if ($this->_queue_shares_same_message_template_group_for_events($event_ids)) { |
|
472 | - $message_template_group = EEM_Message_Template_Group::instance()->get_one( |
|
473 | - array( |
|
474 | - array( |
|
475 | - 'Event.EVT_ID' => array('IN', $event_ids), |
|
476 | - 'MTP_messenger' => $this->_current_messenger->name, |
|
477 | - 'MTP_message_type' => $this->_current_message_type->name, |
|
478 | - 'MTP_is_active' => true, |
|
479 | - ), |
|
480 | - 'group_by' => 'GRP_ID', |
|
481 | - ) |
|
482 | - ); |
|
483 | - //store this in the collection if its valid |
|
484 | - if ($message_template_group instanceof EE_Message_Template_Group) { |
|
485 | - $this->_template_collection->add( |
|
486 | - $message_template_group, |
|
487 | - $event_ids |
|
488 | - ); |
|
489 | - } |
|
490 | - } |
|
491 | - return $message_template_group; |
|
492 | - } |
|
493 | - |
|
494 | - |
|
495 | - /** |
|
496 | - * Retrieves the global message template group for the current messenger and message type. |
|
497 | - * |
|
498 | - * @return EE_Message_Template_Group|null |
|
499 | - * @throws EE_Error |
|
500 | - * @throws InvalidArgumentException |
|
501 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
502 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
503 | - */ |
|
504 | - protected function _get_global_message_template_group_for_current_messenger_and_message_type() |
|
505 | - { |
|
506 | - //first check the collection (we use an array with 0 in it to represent global groups). |
|
507 | - $global_message_template_group = $this->_template_collection->get_by_key( |
|
508 | - $this->_template_collection->getKey( |
|
509 | - $this->_current_messenger->name, |
|
510 | - $this->_current_message_type->name, |
|
511 | - array(0) |
|
512 | - ) |
|
513 | - ); |
|
514 | - |
|
515 | - //if we don't have a group lets hit the db. |
|
516 | - if (! $global_message_template_group instanceof EE_Message_Template_Group) { |
|
517 | - $global_message_template_group = EEM_Message_Template_Group::instance()->get_one( |
|
518 | - array( |
|
519 | - array( |
|
520 | - 'MTP_messenger' => $this->_current_messenger->name, |
|
521 | - 'MTP_message_type' => $this->_current_message_type->name, |
|
522 | - 'MTP_is_active' => true, |
|
523 | - 'MTP_is_global' => true, |
|
524 | - ), |
|
525 | - ) |
|
526 | - ); |
|
527 | - //if we have a group, add it to the collection. |
|
528 | - if ($global_message_template_group instanceof EE_Message_Template_Group) { |
|
529 | - $this->_template_collection->add( |
|
530 | - $global_message_template_group, |
|
531 | - array(0) |
|
532 | - ); |
|
533 | - } |
|
534 | - } |
|
535 | - return $global_message_template_group; |
|
536 | - } |
|
537 | - |
|
538 | - |
|
539 | - /** |
|
540 | - * Returns an array of event ids for all the events within the current data handler. |
|
541 | - * |
|
542 | - * @return array |
|
543 | - */ |
|
544 | - protected function _get_event_ids_from_current_data_handler() |
|
545 | - { |
|
546 | - $event_ids = array(); |
|
547 | - foreach ($this->_current_data_handler->events as $event) { |
|
548 | - $event_ids[$event['ID']] = $event['ID']; |
|
549 | - } |
|
550 | - return $event_ids; |
|
551 | - } |
|
552 | - |
|
553 | - |
|
554 | - /** |
|
555 | - * Retrieves formatted array of template information for each context specific to the given |
|
556 | - * EE_Message_Template_Group |
|
557 | - * |
|
558 | - * @param EE_Message_Template_Group $message_template_group |
|
559 | - * @return array The returned array is in this structure: |
|
560 | - * array( |
|
561 | - * 'field_name' => array( |
|
562 | - * 'context' => 'content' |
|
563 | - * ) |
|
564 | - * ) |
|
565 | - * @throws EE_Error |
|
566 | - */ |
|
567 | - protected function _get_templates(EE_Message_Template_Group $message_template_group) |
|
568 | - { |
|
569 | - $templates = array(); |
|
570 | - $context_templates = $message_template_group->context_templates(); |
|
571 | - foreach ($context_templates as $context => $template_fields) { |
|
572 | - foreach ($template_fields as $template_field => $template_obj) { |
|
573 | - if (! $template_obj instanceof EE_Message_Template) { |
|
574 | - continue; |
|
575 | - } |
|
576 | - $templates[$template_field][$context] = $template_obj->get('MTP_content'); |
|
577 | - } |
|
578 | - } |
|
579 | - return $templates; |
|
580 | - } |
|
581 | - |
|
582 | - |
|
583 | - /** |
|
584 | - * Assembles new fully generated EE_Message objects and adds to _ready_queue |
|
585 | - * |
|
586 | - * @param array $addressees Array of EE_Messages_Addressee objects indexed by message type |
|
587 | - * context. |
|
588 | - * @param array $templates formatted array of templates used for parsing data. |
|
589 | - * @param EE_Message_Template_Group $message_template_group |
|
590 | - * @return bool true if message generation went a-ok. false if some sort of exception occurred. Note: The |
|
591 | - * method will attempt to generate ALL EE_Message objects and add to |
|
592 | - * the _ready_queue. Successfully generated messages get added to the |
|
593 | - * queue with EEM_Message::status_idle, unsuccessfully generated |
|
594 | - * messages will get added to the queue as EEM_Message::status_failed. |
|
595 | - * Very rarely should "false" be returned from this method. |
|
596 | - * @throws EE_Error |
|
597 | - */ |
|
598 | - protected function _assemble_messages($addressees, $templates, EE_Message_Template_Group $message_template_group) |
|
599 | - { |
|
600 | - |
|
601 | - //if templates are empty then get out because we can't generate anything. |
|
602 | - if (! $templates) { |
|
603 | - $this->_error_msg[] = esc_html__( |
|
604 | - 'Unable to assemble messages because there are no templates retrieved for generating the messages with', |
|
605 | - 'event_espresso' |
|
606 | - ); |
|
607 | - return false; |
|
608 | - } |
|
609 | - |
|
610 | - //We use this as the counter for generated messages because don't forget we may be executing this inside of a |
|
611 | - //generation_queue. So _ready_queue may have generated EE_Message objects already. |
|
612 | - $generated_count = 0; |
|
613 | - foreach ($addressees as $context => $recipients) { |
|
614 | - foreach ($recipients as $recipient) { |
|
615 | - $message = $this->_setup_message_object($context, $recipient, $templates, $message_template_group); |
|
616 | - if ($message instanceof EE_Message) { |
|
617 | - $this->_ready_queue->add( |
|
618 | - $message, |
|
619 | - array(), |
|
620 | - $this->_generation_queue->get_message_repository()->is_preview(), |
|
621 | - $this->_generation_queue->get_message_repository()->is_test_send() |
|
622 | - ); |
|
623 | - $generated_count++; |
|
624 | - } |
|
625 | - |
|
626 | - //if the current MSG being generated is for a test send then we'll only use ONE message in the |
|
627 | - // generation. |
|
628 | - if ($this->_generation_queue->get_message_repository()->is_test_send()) { |
|
629 | - break 2; |
|
630 | - } |
|
631 | - } |
|
632 | - } |
|
633 | - |
|
634 | - //if there are no generated messages then something else fatal went wrong. |
|
635 | - return $generated_count > 0; |
|
636 | - } |
|
637 | - |
|
638 | - |
|
639 | - /** |
|
640 | - * @param string $context The context for the generated message. |
|
641 | - * @param EE_Messages_Addressee $recipient |
|
642 | - * @param array $templates formatted array of templates used for parsing data. |
|
643 | - * @param EE_Message_Template_Group $message_template_group |
|
644 | - * @return bool|EE_Message |
|
645 | - * @throws EE_Error |
|
646 | - */ |
|
647 | - protected function _setup_message_object( |
|
648 | - $context, |
|
649 | - EE_Messages_Addressee $recipient, |
|
650 | - $templates, |
|
651 | - EE_Message_Template_Group $message_template_group |
|
652 | - ) { |
|
653 | - //stuff we already know |
|
654 | - $transaction_id = $recipient->txn instanceof EE_Transaction ? $recipient->txn->ID() : 0; |
|
655 | - $transaction_id = empty($transaction_id) && $this->_current_data_handler->txn instanceof EE_Transaction |
|
656 | - ? $this->_current_data_handler->txn->ID() |
|
657 | - : $transaction_id; |
|
658 | - $message_fields = array( |
|
659 | - 'GRP_ID' => $message_template_group->ID(), |
|
660 | - 'TXN_ID' => $transaction_id, |
|
661 | - 'MSG_messenger' => $this->_current_messenger->name, |
|
662 | - 'MSG_message_type' => $this->_current_message_type->name, |
|
663 | - 'MSG_context' => $context, |
|
664 | - ); |
|
665 | - |
|
666 | - //recipient id and type should be on the EE_Messages_Addressee object but if this is empty, let's try to grab |
|
667 | - // the info from the att_obj found in the EE_Messages_Addressee object. |
|
668 | - if (empty($recipient->recipient_id) || empty($recipient->recipient_type)) { |
|
669 | - $message_fields['MSG_recipient_ID'] = $recipient->att_obj instanceof EE_Attendee |
|
670 | - ? $recipient->att_obj->ID() |
|
671 | - : 0; |
|
672 | - $message_fields['MSG_recipient_type'] = 'Attendee'; |
|
673 | - } else { |
|
674 | - $message_fields['MSG_recipient_ID'] = $recipient->recipient_id; |
|
675 | - $message_fields['MSG_recipient_type'] = $recipient->recipient_type; |
|
676 | - } |
|
677 | - $message = EE_Message_Factory::create($message_fields); |
|
678 | - |
|
679 | - //grab valid shortcodes for shortcode parser |
|
680 | - $mt_shortcodes = $this->_current_message_type->get_valid_shortcodes(); |
|
681 | - $m_shortcodes = $this->_current_messenger->get_valid_shortcodes(); |
|
682 | - |
|
683 | - //if the 'to' field is empty or the context is inactive we skip EXCEPT if we're previewing |
|
684 | - if (( |
|
685 | - ( |
|
686 | - empty($templates['to'][$context]) |
|
687 | - && ! $this->_current_messenger->allow_empty_to_field() |
|
688 | - ) |
|
689 | - || ! $message_template_group->is_context_active($context) |
|
690 | - ) |
|
691 | - && ! $this->_generation_queue->get_message_repository()->is_preview() |
|
692 | - ) { |
|
693 | - //we silently exit here and do NOT record a fail because the message is "turned off" by having no "to" |
|
694 | - //field. |
|
695 | - return false; |
|
696 | - } |
|
697 | - $error_msg = array(); |
|
698 | - foreach ($templates as $field => $field_context) { |
|
699 | - $error_msg = array(); |
|
700 | - //let's setup the valid shortcodes for the incoming context. |
|
701 | - $valid_shortcodes = $mt_shortcodes[$context]; |
|
702 | - //merge in valid shortcodes for the field. |
|
703 | - $shortcodes = isset($m_shortcodes[$field]) ? $m_shortcodes[$field] : $valid_shortcodes; |
|
704 | - if (isset($templates[$field][$context])) { |
|
705 | - //prefix field. |
|
706 | - $column_name = 'MSG_' . $field; |
|
707 | - try { |
|
708 | - $content = $this->_shortcode_parser->parse_message_template( |
|
709 | - $templates[$field][$context], |
|
710 | - $recipient, |
|
711 | - $shortcodes, |
|
712 | - $this->_current_message_type, |
|
713 | - $this->_current_messenger, |
|
714 | - $message |
|
715 | - ); |
|
716 | - $message->set_field_or_extra_meta($column_name, $content); |
|
717 | - } catch (EE_Error $e) { |
|
718 | - $error_msg[] = sprintf( |
|
719 | - esc_html__( |
|
720 | - 'There was a problem generating the content for the field %s: %s', |
|
721 | - 'event_espresso' |
|
722 | - ), |
|
723 | - $field, |
|
724 | - $e->getMessage() |
|
725 | - ); |
|
726 | - $message->set_STS_ID(EEM_Message::status_failed); |
|
727 | - } |
|
728 | - } |
|
729 | - } |
|
730 | - |
|
731 | - if ($message->STS_ID() === EEM_Message::status_failed) { |
|
732 | - $error_msg = esc_html__('There were problems generating this message:', 'event_espresso') |
|
733 | - . "\n" |
|
734 | - . implode("\n", $error_msg); |
|
735 | - $message->set_error_message($error_msg); |
|
736 | - } else { |
|
737 | - $message->set_STS_ID(EEM_Message::status_idle); |
|
738 | - } |
|
739 | - return $message; |
|
740 | - } |
|
741 | - |
|
742 | - |
|
743 | - /** |
|
744 | - * This verifies that the incoming array has a EE_messenger object and a EE_message_type object and sets appropriate |
|
745 | - * error message if either is missing. |
|
746 | - * |
|
747 | - * @return bool true means there were no errors, false means there were errors. |
|
748 | - * @throws EE_Error |
|
749 | - * @throws ReflectionException |
|
750 | - */ |
|
751 | - protected function _verify() |
|
752 | - { |
|
753 | - //reset error message to an empty array. |
|
754 | - $this->_error_msg = array(); |
|
755 | - $valid = true; |
|
756 | - $valid = $valid ? $this->_validate_messenger_and_message_type() : $valid; |
|
757 | - $valid = $valid ? $this->_validate_and_setup_data() : $valid; |
|
758 | - |
|
759 | - //set the verified flag so we know everything has been validated. |
|
760 | - $this->_verified = $valid; |
|
761 | - |
|
762 | - return $valid; |
|
763 | - } |
|
764 | - |
|
765 | - |
|
766 | - /** |
|
767 | - * This accepts an array and validates that it is an array indexed by context with each value being an array of |
|
768 | - * EE_Messages_Addressee objects. |
|
769 | - * |
|
770 | - * @param array $addressees Keys correspond to contexts for the message type and values are EE_Messages_Addressee[] |
|
771 | - * @return bool |
|
772 | - */ |
|
773 | - protected function _valid_addressees($addressees) |
|
774 | - { |
|
775 | - if (! $addressees || ! is_array($addressees)) { |
|
776 | - return false; |
|
777 | - } |
|
778 | - |
|
779 | - foreach ($addressees as $addressee_array) { |
|
780 | - foreach ($addressee_array as $addressee) { |
|
781 | - if (! $addressee instanceof EE_Messages_Addressee) { |
|
782 | - return false; |
|
783 | - } |
|
784 | - } |
|
785 | - } |
|
786 | - return true; |
|
787 | - } |
|
788 | - |
|
789 | - |
|
790 | - /** |
|
791 | - * This validates the messenger, message type, and presences of generation data for the current EE_Message in the |
|
792 | - * queue. This process sets error messages if something is wrong. |
|
793 | - * |
|
794 | - * @return bool true is if there are no errors. false is if there is. |
|
795 | - */ |
|
796 | - protected function _validate_messenger_and_message_type() |
|
797 | - { |
|
798 | - |
|
799 | - //first are there any existing error messages? If so then return. |
|
800 | - if ($this->_error_msg) { |
|
801 | - return false; |
|
802 | - } |
|
803 | - /** @type EE_Message $message */ |
|
804 | - $message = $this->_generation_queue->get_message_repository()->current(); |
|
805 | - try { |
|
806 | - $this->_current_messenger = $message->valid_messenger(true) |
|
807 | - ? $message->messenger_object() |
|
808 | - : null; |
|
809 | - } catch (Exception $e) { |
|
810 | - $this->_error_msg[] = $e->getMessage(); |
|
811 | - } |
|
812 | - try { |
|
813 | - $this->_current_message_type = $message->valid_message_type(true) |
|
814 | - ? $message->message_type_object() |
|
815 | - : null; |
|
816 | - } catch (Exception $e) { |
|
817 | - $this->_error_msg[] = $e->getMessage(); |
|
818 | - } |
|
819 | - |
|
820 | - /** |
|
821 | - * Check if there is any generation data, but only if this is not for a preview. |
|
822 | - */ |
|
823 | - if (! $this->_generation_queue->get_message_repository()->get_generation_data() |
|
824 | - && ( |
|
825 | - ! $this->_generation_queue->get_message_repository()->is_preview() |
|
826 | - && $this->_generation_queue->get_message_repository()->get_data_handler() |
|
827 | - !== 'EE_Messages_Preview_incoming_data' |
|
828 | - ) |
|
829 | - ) { |
|
830 | - $this->_error_msg[] = esc_html__( |
|
831 | - 'There is no generation data for this message. Unable to generate.', |
|
832 | - 'event_espresso' |
|
833 | - ); |
|
834 | - } |
|
835 | - |
|
836 | - return empty($this->_error_msg); |
|
837 | - } |
|
838 | - |
|
839 | - |
|
840 | - /** |
|
841 | - * This method retrieves the expected data handler for the message type and validates the generation data for that |
|
842 | - * data handler. |
|
843 | - * |
|
844 | - * @return bool true means there are no errors. false means there were errors (and handler did not get setup). |
|
845 | - * @throws EE_Error |
|
846 | - * @throws ReflectionException |
|
847 | - */ |
|
848 | - protected function _validate_and_setup_data() |
|
849 | - { |
|
850 | - |
|
851 | - //First, are there any existing error messages? If so, return because if there were errors elsewhere this can't |
|
852 | - //be used anyways. |
|
853 | - if ($this->_error_msg) { |
|
854 | - return false; |
|
855 | - } |
|
856 | - |
|
857 | - $generation_data = $this->_generation_queue->get_message_repository()->get_generation_data(); |
|
858 | - |
|
859 | - /** @type EE_Messages_incoming_data $data_handler_class_name - well not really... just the class name actually*/ |
|
860 | - $data_handler_class_name = $this->_generation_queue->get_message_repository()->get_data_handler() |
|
861 | - ? $this->_generation_queue->get_message_repository()->get_data_handler() |
|
862 | - : 'EE_Messages_' . $this->_current_message_type->get_data_handler($generation_data) . '_incoming_data'; |
|
863 | - |
|
864 | - //If this EE_Message is for a preview, then let's switch out to the preview data handler. |
|
865 | - if ($this->_generation_queue->get_message_repository()->is_preview()) { |
|
866 | - $data_handler_class_name = 'EE_Messages_Preview_incoming_data'; |
|
867 | - } |
|
868 | - |
|
869 | - //First get the class name for the data handler (and also verifies it exists. |
|
870 | - if (! class_exists($data_handler_class_name)) { |
|
871 | - $this->_error_msg[] = sprintf( |
|
872 | - esc_html__( |
|
873 | - 'The included data handler class name does not match any valid, accessible, "%1$s" classes. Looking for %2$s.', |
|
874 | - 'event_espresso' |
|
875 | - ), |
|
876 | - 'EE_Messages_incoming_data', |
|
877 | - $data_handler_class_name |
|
878 | - ); |
|
879 | - return false; |
|
880 | - } |
|
881 | - |
|
882 | - //convert generation_data for data_handler_instantiation. |
|
883 | - $generation_data = $data_handler_class_name::convert_data_from_persistent_storage($generation_data); |
|
884 | - |
|
885 | - //note, this may set error messages as well. |
|
886 | - $this->_set_data_handler($generation_data, $data_handler_class_name); |
|
887 | - |
|
888 | - return empty($this->_error_msg); |
|
889 | - } |
|
890 | - |
|
891 | - |
|
892 | - /** |
|
893 | - * Sets the $_current_data_handler property that is used for generating the current EE_Message in the queue, and |
|
894 | - * adds it to the _data repository. |
|
895 | - * |
|
896 | - * @param mixed $generating_data This is data expected by the instantiated data handler. |
|
897 | - * @param string $data_handler_class_name This is the reference string indicating what data handler is being |
|
898 | - * instantiated. |
|
899 | - * @return void . |
|
900 | - * @throws EE_Error |
|
901 | - * @throws ReflectionException |
|
902 | - */ |
|
903 | - protected function _set_data_handler($generating_data, $data_handler_class_name) |
|
904 | - { |
|
905 | - //valid classname for the data handler. Now let's setup the key for the data handler repository to see if there |
|
906 | - //is already a ready data handler in the repository. |
|
907 | - $this->_current_data_handler = $this->_data_handler_collection->get_by_key( |
|
908 | - $this->_data_handler_collection->get_key( |
|
909 | - $data_handler_class_name, |
|
910 | - $generating_data |
|
911 | - ) |
|
912 | - ); |
|
913 | - if (! $this->_current_data_handler instanceof EE_Messages_incoming_data) { |
|
914 | - //no saved data_handler in the repo so let's set one up and add it to the repo. |
|
915 | - try { |
|
916 | - $this->_current_data_handler = new $data_handler_class_name($generating_data); |
|
917 | - $this->_data_handler_collection->add($this->_current_data_handler, $generating_data); |
|
918 | - } catch (EE_Error $e) { |
|
919 | - $this->_error_msg[] = $e->get_error(); |
|
920 | - } |
|
921 | - } |
|
922 | - } |
|
923 | - |
|
924 | - |
|
925 | - /** |
|
926 | - * The queued EE_Message for generation does not save the data used for generation as objects |
|
927 | - * because serialization of those objects could be problematic if the data is saved to the db. |
|
928 | - * So this method calls the static method on the associated data_handler for the given message_type |
|
929 | - * and that preps the data for later instantiation when generating. |
|
930 | - * |
|
931 | - * @param EE_Message_To_Generate $message_to_generate |
|
932 | - * @param bool $preview Indicate whether this is being used for a preview or not. |
|
933 | - * @return mixed Prepped data for persisting to the queue. false is returned if unable to prep data. |
|
934 | - */ |
|
935 | - protected function _prepare_data_for_queue(EE_Message_To_Generate $message_to_generate, $preview) |
|
936 | - { |
|
937 | - /** @type EE_Messages_incoming_data $data_handler - well not really... just the class name actually */ |
|
938 | - $data_handler = $message_to_generate->get_data_handler_class_name($preview); |
|
939 | - if (! $message_to_generate->valid()) { |
|
940 | - return false; //unable to get the data because the info in the EE_Message_To_Generate class is invalid. |
|
941 | - } |
|
942 | - return $data_handler::convert_data_for_persistent_storage($message_to_generate->data()); |
|
943 | - } |
|
944 | - |
|
945 | - |
|
946 | - /** |
|
947 | - * This sets up a EEM_Message::status_incomplete EE_Message object and adds it to the generation queue. |
|
948 | - * |
|
949 | - * @param EE_Message_To_Generate $message_to_generate |
|
950 | - * @param bool $test_send Whether this is just a test send or not. Typically used for previews. |
|
951 | - * @throws InvalidArgumentException |
|
952 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
953 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
954 | - */ |
|
955 | - public function create_and_add_message_to_queue(EE_Message_To_Generate $message_to_generate, $test_send = false) |
|
956 | - { |
|
957 | - //prep data |
|
958 | - $data = $this->_prepare_data_for_queue($message_to_generate, $message_to_generate->preview()); |
|
959 | - |
|
960 | - $message = $message_to_generate->get_EE_Message(); |
|
961 | - |
|
962 | - //is there a GRP_ID in the request? |
|
963 | - if ($GRP_ID = EE_Registry::instance()->REQ->get('GRP_ID')) { |
|
964 | - $message->set_GRP_ID($GRP_ID); |
|
965 | - } |
|
966 | - |
|
967 | - if ($data === false) { |
|
968 | - $message->set_STS_ID(EEM_Message::status_failed); |
|
969 | - $message->set_error_message( |
|
970 | - esc_html__( |
|
971 | - 'Unable to prepare data for persistence to the database.', |
|
972 | - 'event_espresso' |
|
973 | - ) |
|
974 | - ); |
|
975 | - } else { |
|
976 | - //make sure that the data handler is cached on the message as well |
|
977 | - $data['data_handler_class_name'] = $message_to_generate->get_data_handler_class_name(); |
|
978 | - } |
|
979 | - |
|
980 | - $this->_generation_queue->add($message, $data, $message_to_generate->preview(), $test_send); |
|
981 | - } |
|
16 | + /** |
|
17 | + * @type EE_Messages_Data_Handler_Collection |
|
18 | + */ |
|
19 | + protected $_data_handler_collection; |
|
20 | + |
|
21 | + /** |
|
22 | + * @type EE_Message_Template_Group_Collection |
|
23 | + */ |
|
24 | + protected $_template_collection; |
|
25 | + |
|
26 | + /** |
|
27 | + * This will hold the data handler for the current EE_Message being generated. |
|
28 | + * |
|
29 | + * @type EE_Messages_incoming_data |
|
30 | + */ |
|
31 | + protected $_current_data_handler; |
|
32 | + |
|
33 | + /** |
|
34 | + * This holds the EE_Messages_Queue that contains the messages to generate. |
|
35 | + * |
|
36 | + * @type EE_Messages_Queue |
|
37 | + */ |
|
38 | + protected $_generation_queue; |
|
39 | + |
|
40 | + /** |
|
41 | + * This holds the EE_Messages_Queue that will store the generated EE_Message objects. |
|
42 | + * |
|
43 | + * @type EE_Messages_Queue |
|
44 | + */ |
|
45 | + protected $_ready_queue; |
|
46 | + |
|
47 | + /** |
|
48 | + * This is a container for any error messages that get created through the generation |
|
49 | + * process. |
|
50 | + * |
|
51 | + * @type array |
|
52 | + */ |
|
53 | + protected $_error_msg = array(); |
|
54 | + |
|
55 | + /** |
|
56 | + * Flag used to set when the current EE_Message in the generation queue has been verified. |
|
57 | + * |
|
58 | + * @type bool |
|
59 | + */ |
|
60 | + protected $_verified = false; |
|
61 | + |
|
62 | + /** |
|
63 | + * This will hold the current messenger object corresponding with the current EE_Message in the generation queue. |
|
64 | + * |
|
65 | + * @type EE_messenger |
|
66 | + */ |
|
67 | + protected $_current_messenger; |
|
68 | + |
|
69 | + /** |
|
70 | + * This will hold the current message type object corresponding with the current EE_Message in the generation queue. |
|
71 | + * |
|
72 | + * @type EE_message_type |
|
73 | + */ |
|
74 | + protected $_current_message_type; |
|
75 | + |
|
76 | + /** |
|
77 | + * @type EEH_Parse_Shortcodes |
|
78 | + */ |
|
79 | + protected $_shortcode_parser; |
|
80 | + |
|
81 | + |
|
82 | + /** |
|
83 | + * @param EE_Messages_Queue $generation_queue |
|
84 | + * @param \EE_Messages_Queue $ready_queue |
|
85 | + * @param \EE_Messages_Data_Handler_Collection $data_handler_collection |
|
86 | + * @param \EE_Message_Template_Group_Collection $template_collection |
|
87 | + * @param \EEH_Parse_Shortcodes $shortcode_parser |
|
88 | + */ |
|
89 | + public function __construct( |
|
90 | + EE_Messages_Queue $generation_queue, |
|
91 | + EE_Messages_Queue $ready_queue, |
|
92 | + EE_Messages_Data_Handler_Collection $data_handler_collection, |
|
93 | + EE_Message_Template_Group_Collection $template_collection, |
|
94 | + EEH_Parse_Shortcodes $shortcode_parser |
|
95 | + ) { |
|
96 | + $this->_generation_queue = $generation_queue; |
|
97 | + $this->_ready_queue = $ready_queue; |
|
98 | + $this->_data_handler_collection = $data_handler_collection; |
|
99 | + $this->_template_collection = $template_collection; |
|
100 | + $this->_shortcode_parser = $shortcode_parser; |
|
101 | + } |
|
102 | + |
|
103 | + |
|
104 | + /** |
|
105 | + * @return EE_Messages_Queue |
|
106 | + */ |
|
107 | + public function generation_queue() |
|
108 | + { |
|
109 | + return $this->_generation_queue; |
|
110 | + } |
|
111 | + |
|
112 | + |
|
113 | + /** |
|
114 | + * This iterates through the provided queue and generates the EE_Message objects. |
|
115 | + * When iterating through the queue, the queued item that served as the base for generating other EE_Message |
|
116 | + * objects gets removed and the new EE_Message objects get added to a NEW queue. The NEW queue is then returned |
|
117 | + * for the caller to decide what to do with it. |
|
118 | + * |
|
119 | + * @param bool $save Whether to save the EE_Message objects in the new queue or just return. |
|
120 | + * @return EE_Messages_Queue The new queue for holding generated EE_Message objects. |
|
121 | + * @throws EE_Error |
|
122 | + * @throws ReflectionException |
|
123 | + */ |
|
124 | + public function generate($save = true) |
|
125 | + { |
|
126 | + //iterate through the messages in the queue, generate, and add to new queue. |
|
127 | + $this->_generation_queue->get_message_repository()->rewind(); |
|
128 | + while ($this->_generation_queue->get_message_repository()->valid()) { |
|
129 | + //reset "current" properties |
|
130 | + $this->_reset_current_properties(); |
|
131 | + |
|
132 | + /** @type EE_Message $msg */ |
|
133 | + $msg = $this->_generation_queue->get_message_repository()->current(); |
|
134 | + |
|
135 | + /** |
|
136 | + * need to get the next object and capture it for setting manually after deletes. The reason is that when |
|
137 | + * an object is removed from the repo then valid for the next object will fail. |
|
138 | + */ |
|
139 | + $this->_generation_queue->get_message_repository()->next(); |
|
140 | + $next_msg = $this->_generation_queue->get_message_repository()->current(); |
|
141 | + //restore pointer to current item |
|
142 | + $this->_generation_queue->get_message_repository()->set_current($msg); |
|
143 | + |
|
144 | + //skip and delete if the current $msg is NOT incomplete (queued for generation) |
|
145 | + if ($msg->STS_ID() !== EEM_Message::status_incomplete) { |
|
146 | + //we keep this item in the db just remove from the repo. |
|
147 | + $this->_generation_queue->get_message_repository()->remove($msg); |
|
148 | + //next item |
|
149 | + $this->_generation_queue->get_message_repository()->set_current($next_msg); |
|
150 | + continue; |
|
151 | + } |
|
152 | + |
|
153 | + if ($this->_verify()) { |
|
154 | + //let's get generating! |
|
155 | + $this->_generate(); |
|
156 | + } |
|
157 | + |
|
158 | + //don't persist debug_only messages if the messages system is not in debug mode. |
|
159 | + if ($msg->STS_ID() === EEM_Message::status_debug_only |
|
160 | + && ! EEM_Message::debug() |
|
161 | + ) { |
|
162 | + do_action( |
|
163 | + 'AHEE__EE_Messages_Generator__generate__before_debug_delete', |
|
164 | + $msg, |
|
165 | + $this->_error_msg, |
|
166 | + $this->_current_messenger, |
|
167 | + $this->_current_message_type, |
|
168 | + $this->_current_data_handler |
|
169 | + ); |
|
170 | + $this->_generation_queue->get_message_repository()->delete(); |
|
171 | + $this->_generation_queue->get_message_repository()->set_current($next_msg); |
|
172 | + continue; |
|
173 | + } |
|
174 | + |
|
175 | + //if there are error messages then let's set the status and the error message. |
|
176 | + if ($this->_error_msg) { |
|
177 | + //if the status is already debug only, then let's leave it at that. |
|
178 | + if ($msg->STS_ID() !== EEM_Message::status_debug_only) { |
|
179 | + $msg->set_STS_ID(EEM_Message::status_failed); |
|
180 | + } |
|
181 | + do_action( |
|
182 | + 'AHEE__EE_Messages_Generator__generate__processing_failed_message', |
|
183 | + $msg, |
|
184 | + $this->_error_msg, |
|
185 | + $this->_current_messenger, |
|
186 | + $this->_current_message_type, |
|
187 | + $this->_current_data_handler |
|
188 | + ); |
|
189 | + $msg->set_error_message( |
|
190 | + esc_html__('Message failed to generate for the following reasons: ', 'event_espresso') |
|
191 | + . "\n" |
|
192 | + . implode("\n", $this->_error_msg) |
|
193 | + ); |
|
194 | + $msg->set_modified(time()); |
|
195 | + } else { |
|
196 | + do_action( |
|
197 | + 'AHEE__EE_Messages_Generator__generate__before_successful_generated_message_delete', |
|
198 | + $msg, |
|
199 | + $this->_error_msg, |
|
200 | + $this->_current_messenger, |
|
201 | + $this->_current_message_type, |
|
202 | + $this->_current_data_handler |
|
203 | + ); |
|
204 | + //remove from db |
|
205 | + $this->_generation_queue->get_message_repository()->delete(); |
|
206 | + } |
|
207 | + //next item |
|
208 | + $this->_generation_queue->get_message_repository()->set_current($next_msg); |
|
209 | + } |
|
210 | + |
|
211 | + //generation queue is ALWAYS saved to record any errors in the generation process. |
|
212 | + $this->_generation_queue->save(); |
|
213 | + |
|
214 | + /** |
|
215 | + * save _ready_queue if flag set. |
|
216 | + * Note: The EE_Message objects have values set via the EE_Base_Class::set_field_or_extra_meta() method. This |
|
217 | + * means if a field was added that is not a valid database column. The EE_Message was already saved to the db |
|
218 | + * so a EE_Extra_Meta entry could be created and attached to the EE_Message. In those cases the save flag is |
|
219 | + * irrelevant. |
|
220 | + */ |
|
221 | + if ($save) { |
|
222 | + $this->_ready_queue->save(); |
|
223 | + } |
|
224 | + |
|
225 | + //final reset of properties |
|
226 | + $this->_reset_current_properties(); |
|
227 | + |
|
228 | + return $this->_ready_queue; |
|
229 | + } |
|
230 | + |
|
231 | + |
|
232 | + /** |
|
233 | + * This resets all the properties used for holding "current" values corresponding to the current EE_Message object |
|
234 | + * in the generation queue. |
|
235 | + */ |
|
236 | + protected function _reset_current_properties() |
|
237 | + { |
|
238 | + $this->_verified = false; |
|
239 | + //make sure any _data value in the current message type is reset |
|
240 | + if ($this->_current_message_type instanceof EE_message_type) { |
|
241 | + $this->_current_message_type->reset_data(); |
|
242 | + } |
|
243 | + $this->_current_messenger = $this->_current_message_type = $this->_current_data_handler = null; |
|
244 | + } |
|
245 | + |
|
246 | + |
|
247 | + /** |
|
248 | + * This proceeds with the actual generation of a message. By the time this is called, there should already be a |
|
249 | + * $_current_data_handler set and all incoming information should be validated for the current EE_Message in the |
|
250 | + * _generating_queue. |
|
251 | + * |
|
252 | + * @return bool Whether the message was successfully generated or not. |
|
253 | + * @throws EE_Error |
|
254 | + * @throws InvalidArgumentException |
|
255 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
256 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
257 | + */ |
|
258 | + protected function _generate() |
|
259 | + { |
|
260 | + //double check verification has run and that everything is ready to work with (saves us having to validate |
|
261 | + // everything again). |
|
262 | + if (! $this->_verified) { |
|
263 | + return false; //get out because we don't have a valid setup to work with. |
|
264 | + } |
|
265 | + |
|
266 | + |
|
267 | + try { |
|
268 | + $addressees = $this->_current_message_type->get_addressees( |
|
269 | + $this->_current_data_handler, |
|
270 | + $this->_generation_queue->get_message_repository()->current()->context() |
|
271 | + ); |
|
272 | + } catch (EE_Error $e) { |
|
273 | + $this->_error_msg[] = $e->getMessage(); |
|
274 | + return false; |
|
275 | + } |
|
276 | + |
|
277 | + |
|
278 | + //if no addressees then get out because there is nothing to generation (possible bad data). |
|
279 | + if (! $this->_valid_addressees($addressees)) { |
|
280 | + do_action( |
|
281 | + 'AHEE__EE_Messages_Generator___generate__invalid_addressees', |
|
282 | + $this->_generation_queue->get_message_repository()->current(), |
|
283 | + $addressees, |
|
284 | + $this->_current_messenger, |
|
285 | + $this->_current_message_type, |
|
286 | + $this->_current_data_handler |
|
287 | + ); |
|
288 | + $this->_generation_queue->get_message_repository()->current()->set_STS_ID( |
|
289 | + EEM_Message::status_debug_only |
|
290 | + ); |
|
291 | + $this->_error_msg[] = esc_html__( |
|
292 | + 'This is not a critical error but an informational notice. Unable to generate messages EE_Messages_Addressee objects. There were no attendees prepared by the data handler. Sometimes this is because messages only get generated for certain registration statuses. For example, the ticket notice message type only goes to approved registrations.', |
|
293 | + 'event_espresso' |
|
294 | + ); |
|
295 | + return false; |
|
296 | + } |
|
297 | + |
|
298 | + $message_template_group = $this->_get_message_template_group(); |
|
299 | + |
|
300 | + //in the unlikely event there is no EE_Message_Template_Group available, get out! |
|
301 | + if (! $message_template_group instanceof EE_Message_Template_Group) { |
|
302 | + $this->_error_msg[] = esc_html__( |
|
303 | + 'Unable to get the Message Templates for the Message being generated. No message template group accessible.', |
|
304 | + 'event_espresso' |
|
305 | + ); |
|
306 | + return false; |
|
307 | + } |
|
308 | + |
|
309 | + //get formatted templates for using to parse and setup EE_Message objects. |
|
310 | + $templates = $this->_get_templates($message_template_group); |
|
311 | + |
|
312 | + |
|
313 | + //setup new EE_Message objects (and add to _ready_queue) |
|
314 | + return $this->_assemble_messages($addressees, $templates, $message_template_group); |
|
315 | + } |
|
316 | + |
|
317 | + |
|
318 | + /** |
|
319 | + * Retrieves the message template group being used for generating messages. |
|
320 | + * Note: this also utilizes the EE_Message_Template_Group_Collection to avoid having to hit the db multiple times. |
|
321 | + * |
|
322 | + * @return EE_Message_Template_Group|null |
|
323 | + * @throws EE_Error |
|
324 | + * @throws InvalidArgumentException |
|
325 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
326 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
327 | + */ |
|
328 | + protected function _get_message_template_group() |
|
329 | + { |
|
330 | + //first see if there is a specific message template group requested (current message in the queue has a specific |
|
331 | + //GRP_ID |
|
332 | + $message_template_group = $this->_specific_message_template_group_from_queue(); |
|
333 | + if ($message_template_group instanceof EE_Message_Template_Group) { |
|
334 | + return $message_template_group; |
|
335 | + } |
|
336 | + |
|
337 | + //get event_ids from the datahandler so we can check to see if there's already a message template group for them |
|
338 | + //in the collection. |
|
339 | + $event_ids = $this->_get_event_ids_from_current_data_handler(); |
|
340 | + $message_template_group = $this->_template_collection->get_by_key( |
|
341 | + $this->_template_collection->getKey( |
|
342 | + $this->_current_messenger->name, |
|
343 | + $this->_current_message_type->name, |
|
344 | + $event_ids |
|
345 | + ) |
|
346 | + ); |
|
347 | + |
|
348 | + //if we have a message template group then no need to hit the database, just return it. |
|
349 | + if ($message_template_group instanceof EE_Message_Template_Group) { |
|
350 | + return $message_template_group; |
|
351 | + } |
|
352 | + |
|
353 | + //okay made it here, so let's get the global group first for this messenger and message type to ensure |
|
354 | + //there is no override set. |
|
355 | + $global_message_template_group = |
|
356 | + $this->_get_global_message_template_group_for_current_messenger_and_message_type(); |
|
357 | + |
|
358 | + if ($global_message_template_group instanceof EE_Message_Template_Group |
|
359 | + && $global_message_template_group->get('MTP_is_override') |
|
360 | + ) { |
|
361 | + return $global_message_template_group; |
|
362 | + } |
|
363 | + |
|
364 | + //if we're still here, that means there was no message template group for the events in the collection and |
|
365 | + //the global message template group for the messenger and message type is not set for override. So next step is |
|
366 | + //to see if there is a common shared custom message template group for this set of events. |
|
367 | + $message_template_group = $this->_get_shared_message_template_for_events($event_ids); |
|
368 | + if ($message_template_group instanceof EE_Message_Template_Group) { |
|
369 | + return $message_template_group; |
|
370 | + } |
|
371 | + |
|
372 | + //STILL here? Okay that means the fallback is to just use the global message template group for this event set. |
|
373 | + //So we'll cache the global group for this event set (so this logic doesn't have to be repeated in this request) |
|
374 | + //and return it. |
|
375 | + if ($global_message_template_group instanceof EE_Message_Template_Group) { |
|
376 | + $this->_template_collection->add( |
|
377 | + $global_message_template_group, |
|
378 | + $event_ids |
|
379 | + ); |
|
380 | + return $global_message_template_group; |
|
381 | + } |
|
382 | + |
|
383 | + //if we land here that means there's NO active message template group for this set. |
|
384 | + //TODO this will be a good target for some optimization down the road. Whenever there is no active message |
|
385 | + //template group for a given event set then cache that result so we don't repeat the logic. However, for now, |
|
386 | + //this should likely bit hit rarely enough that it's not a significant issue. |
|
387 | + return null; |
|
388 | + } |
|
389 | + |
|
390 | + |
|
391 | + /** |
|
392 | + * This checks the current message in the queue and determines if there is a specific Message Template Group |
|
393 | + * requested for that message. |
|
394 | + * |
|
395 | + * @return EE_Message_Template_Group|null |
|
396 | + * @throws EE_Error |
|
397 | + * @throws InvalidArgumentException |
|
398 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
399 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
400 | + */ |
|
401 | + protected function _specific_message_template_group_from_queue() |
|
402 | + { |
|
403 | + //is there a GRP_ID already on the EE_Message object? If there is, then a specific template has been requested |
|
404 | + //so let's use that. |
|
405 | + $GRP_ID = $this->_generation_queue->get_message_repository()->current()->GRP_ID(); |
|
406 | + |
|
407 | + if ($GRP_ID) { |
|
408 | + //attempt to retrieve from repo first |
|
409 | + $message_template_group = $this->_template_collection->get_by_ID($GRP_ID); |
|
410 | + if ($message_template_group instanceof EE_Message_Template_Group) { |
|
411 | + return $message_template_group; //got it! |
|
412 | + } |
|
413 | + |
|
414 | + //nope don't have it yet. Get from DB then add to repo if its not here, then that means the current GRP_ID |
|
415 | + //is not valid, so we'll continue on in the code assuming there's NO GRP_ID. |
|
416 | + $message_template_group = EEM_Message_Template_Group::instance()->get_one_by_ID($GRP_ID); |
|
417 | + if ($message_template_group instanceof EE_Message_Template_Group) { |
|
418 | + $this->_template_collection->add($message_template_group); |
|
419 | + return $message_template_group; |
|
420 | + } |
|
421 | + } |
|
422 | + return null; |
|
423 | + } |
|
424 | + |
|
425 | + |
|
426 | + /** |
|
427 | + * Returns whether the event ids passed in all share the same message template group for the current message type |
|
428 | + * and messenger. |
|
429 | + * |
|
430 | + * @param array $event_ids |
|
431 | + * @return bool true means they DO share the same message template group, false means they don't. |
|
432 | + * @throws EE_Error |
|
433 | + * @throws InvalidArgumentException |
|
434 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
435 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
436 | + */ |
|
437 | + protected function _queue_shares_same_message_template_group_for_events(array $event_ids) |
|
438 | + { |
|
439 | + foreach ($this->_current_data_handler->events as $event) { |
|
440 | + $event_ids[$event['ID']] = $event['ID']; |
|
441 | + } |
|
442 | + $count_of_message_template_groups = EEM_Message_Template_Group::instance()->count( |
|
443 | + array( |
|
444 | + array( |
|
445 | + 'Event.EVT_ID' => array('IN', $event_ids), |
|
446 | + 'MTP_messenger' => $this->_current_messenger->name, |
|
447 | + 'MTP_message_type' => $this->_current_message_type->name, |
|
448 | + ), |
|
449 | + ), |
|
450 | + 'GRP_ID', |
|
451 | + true |
|
452 | + ); |
|
453 | + return $count_of_message_template_groups === 1; |
|
454 | + } |
|
455 | + |
|
456 | + |
|
457 | + /** |
|
458 | + * This will get the shared message template group for events that are in the current data handler but ONLY if |
|
459 | + * there's a single shared message template group among all the events. Otherwise it returns null. |
|
460 | + * |
|
461 | + * @param array $event_ids |
|
462 | + * @return EE_Message_Template_Group|null |
|
463 | + * @throws EE_Error |
|
464 | + * @throws InvalidArgumentException |
|
465 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
466 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
467 | + */ |
|
468 | + protected function _get_shared_message_template_for_events(array $event_ids) |
|
469 | + { |
|
470 | + $message_template_group = null; |
|
471 | + if ($this->_queue_shares_same_message_template_group_for_events($event_ids)) { |
|
472 | + $message_template_group = EEM_Message_Template_Group::instance()->get_one( |
|
473 | + array( |
|
474 | + array( |
|
475 | + 'Event.EVT_ID' => array('IN', $event_ids), |
|
476 | + 'MTP_messenger' => $this->_current_messenger->name, |
|
477 | + 'MTP_message_type' => $this->_current_message_type->name, |
|
478 | + 'MTP_is_active' => true, |
|
479 | + ), |
|
480 | + 'group_by' => 'GRP_ID', |
|
481 | + ) |
|
482 | + ); |
|
483 | + //store this in the collection if its valid |
|
484 | + if ($message_template_group instanceof EE_Message_Template_Group) { |
|
485 | + $this->_template_collection->add( |
|
486 | + $message_template_group, |
|
487 | + $event_ids |
|
488 | + ); |
|
489 | + } |
|
490 | + } |
|
491 | + return $message_template_group; |
|
492 | + } |
|
493 | + |
|
494 | + |
|
495 | + /** |
|
496 | + * Retrieves the global message template group for the current messenger and message type. |
|
497 | + * |
|
498 | + * @return EE_Message_Template_Group|null |
|
499 | + * @throws EE_Error |
|
500 | + * @throws InvalidArgumentException |
|
501 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
502 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
503 | + */ |
|
504 | + protected function _get_global_message_template_group_for_current_messenger_and_message_type() |
|
505 | + { |
|
506 | + //first check the collection (we use an array with 0 in it to represent global groups). |
|
507 | + $global_message_template_group = $this->_template_collection->get_by_key( |
|
508 | + $this->_template_collection->getKey( |
|
509 | + $this->_current_messenger->name, |
|
510 | + $this->_current_message_type->name, |
|
511 | + array(0) |
|
512 | + ) |
|
513 | + ); |
|
514 | + |
|
515 | + //if we don't have a group lets hit the db. |
|
516 | + if (! $global_message_template_group instanceof EE_Message_Template_Group) { |
|
517 | + $global_message_template_group = EEM_Message_Template_Group::instance()->get_one( |
|
518 | + array( |
|
519 | + array( |
|
520 | + 'MTP_messenger' => $this->_current_messenger->name, |
|
521 | + 'MTP_message_type' => $this->_current_message_type->name, |
|
522 | + 'MTP_is_active' => true, |
|
523 | + 'MTP_is_global' => true, |
|
524 | + ), |
|
525 | + ) |
|
526 | + ); |
|
527 | + //if we have a group, add it to the collection. |
|
528 | + if ($global_message_template_group instanceof EE_Message_Template_Group) { |
|
529 | + $this->_template_collection->add( |
|
530 | + $global_message_template_group, |
|
531 | + array(0) |
|
532 | + ); |
|
533 | + } |
|
534 | + } |
|
535 | + return $global_message_template_group; |
|
536 | + } |
|
537 | + |
|
538 | + |
|
539 | + /** |
|
540 | + * Returns an array of event ids for all the events within the current data handler. |
|
541 | + * |
|
542 | + * @return array |
|
543 | + */ |
|
544 | + protected function _get_event_ids_from_current_data_handler() |
|
545 | + { |
|
546 | + $event_ids = array(); |
|
547 | + foreach ($this->_current_data_handler->events as $event) { |
|
548 | + $event_ids[$event['ID']] = $event['ID']; |
|
549 | + } |
|
550 | + return $event_ids; |
|
551 | + } |
|
552 | + |
|
553 | + |
|
554 | + /** |
|
555 | + * Retrieves formatted array of template information for each context specific to the given |
|
556 | + * EE_Message_Template_Group |
|
557 | + * |
|
558 | + * @param EE_Message_Template_Group $message_template_group |
|
559 | + * @return array The returned array is in this structure: |
|
560 | + * array( |
|
561 | + * 'field_name' => array( |
|
562 | + * 'context' => 'content' |
|
563 | + * ) |
|
564 | + * ) |
|
565 | + * @throws EE_Error |
|
566 | + */ |
|
567 | + protected function _get_templates(EE_Message_Template_Group $message_template_group) |
|
568 | + { |
|
569 | + $templates = array(); |
|
570 | + $context_templates = $message_template_group->context_templates(); |
|
571 | + foreach ($context_templates as $context => $template_fields) { |
|
572 | + foreach ($template_fields as $template_field => $template_obj) { |
|
573 | + if (! $template_obj instanceof EE_Message_Template) { |
|
574 | + continue; |
|
575 | + } |
|
576 | + $templates[$template_field][$context] = $template_obj->get('MTP_content'); |
|
577 | + } |
|
578 | + } |
|
579 | + return $templates; |
|
580 | + } |
|
581 | + |
|
582 | + |
|
583 | + /** |
|
584 | + * Assembles new fully generated EE_Message objects and adds to _ready_queue |
|
585 | + * |
|
586 | + * @param array $addressees Array of EE_Messages_Addressee objects indexed by message type |
|
587 | + * context. |
|
588 | + * @param array $templates formatted array of templates used for parsing data. |
|
589 | + * @param EE_Message_Template_Group $message_template_group |
|
590 | + * @return bool true if message generation went a-ok. false if some sort of exception occurred. Note: The |
|
591 | + * method will attempt to generate ALL EE_Message objects and add to |
|
592 | + * the _ready_queue. Successfully generated messages get added to the |
|
593 | + * queue with EEM_Message::status_idle, unsuccessfully generated |
|
594 | + * messages will get added to the queue as EEM_Message::status_failed. |
|
595 | + * Very rarely should "false" be returned from this method. |
|
596 | + * @throws EE_Error |
|
597 | + */ |
|
598 | + protected function _assemble_messages($addressees, $templates, EE_Message_Template_Group $message_template_group) |
|
599 | + { |
|
600 | + |
|
601 | + //if templates are empty then get out because we can't generate anything. |
|
602 | + if (! $templates) { |
|
603 | + $this->_error_msg[] = esc_html__( |
|
604 | + 'Unable to assemble messages because there are no templates retrieved for generating the messages with', |
|
605 | + 'event_espresso' |
|
606 | + ); |
|
607 | + return false; |
|
608 | + } |
|
609 | + |
|
610 | + //We use this as the counter for generated messages because don't forget we may be executing this inside of a |
|
611 | + //generation_queue. So _ready_queue may have generated EE_Message objects already. |
|
612 | + $generated_count = 0; |
|
613 | + foreach ($addressees as $context => $recipients) { |
|
614 | + foreach ($recipients as $recipient) { |
|
615 | + $message = $this->_setup_message_object($context, $recipient, $templates, $message_template_group); |
|
616 | + if ($message instanceof EE_Message) { |
|
617 | + $this->_ready_queue->add( |
|
618 | + $message, |
|
619 | + array(), |
|
620 | + $this->_generation_queue->get_message_repository()->is_preview(), |
|
621 | + $this->_generation_queue->get_message_repository()->is_test_send() |
|
622 | + ); |
|
623 | + $generated_count++; |
|
624 | + } |
|
625 | + |
|
626 | + //if the current MSG being generated is for a test send then we'll only use ONE message in the |
|
627 | + // generation. |
|
628 | + if ($this->_generation_queue->get_message_repository()->is_test_send()) { |
|
629 | + break 2; |
|
630 | + } |
|
631 | + } |
|
632 | + } |
|
633 | + |
|
634 | + //if there are no generated messages then something else fatal went wrong. |
|
635 | + return $generated_count > 0; |
|
636 | + } |
|
637 | + |
|
638 | + |
|
639 | + /** |
|
640 | + * @param string $context The context for the generated message. |
|
641 | + * @param EE_Messages_Addressee $recipient |
|
642 | + * @param array $templates formatted array of templates used for parsing data. |
|
643 | + * @param EE_Message_Template_Group $message_template_group |
|
644 | + * @return bool|EE_Message |
|
645 | + * @throws EE_Error |
|
646 | + */ |
|
647 | + protected function _setup_message_object( |
|
648 | + $context, |
|
649 | + EE_Messages_Addressee $recipient, |
|
650 | + $templates, |
|
651 | + EE_Message_Template_Group $message_template_group |
|
652 | + ) { |
|
653 | + //stuff we already know |
|
654 | + $transaction_id = $recipient->txn instanceof EE_Transaction ? $recipient->txn->ID() : 0; |
|
655 | + $transaction_id = empty($transaction_id) && $this->_current_data_handler->txn instanceof EE_Transaction |
|
656 | + ? $this->_current_data_handler->txn->ID() |
|
657 | + : $transaction_id; |
|
658 | + $message_fields = array( |
|
659 | + 'GRP_ID' => $message_template_group->ID(), |
|
660 | + 'TXN_ID' => $transaction_id, |
|
661 | + 'MSG_messenger' => $this->_current_messenger->name, |
|
662 | + 'MSG_message_type' => $this->_current_message_type->name, |
|
663 | + 'MSG_context' => $context, |
|
664 | + ); |
|
665 | + |
|
666 | + //recipient id and type should be on the EE_Messages_Addressee object but if this is empty, let's try to grab |
|
667 | + // the info from the att_obj found in the EE_Messages_Addressee object. |
|
668 | + if (empty($recipient->recipient_id) || empty($recipient->recipient_type)) { |
|
669 | + $message_fields['MSG_recipient_ID'] = $recipient->att_obj instanceof EE_Attendee |
|
670 | + ? $recipient->att_obj->ID() |
|
671 | + : 0; |
|
672 | + $message_fields['MSG_recipient_type'] = 'Attendee'; |
|
673 | + } else { |
|
674 | + $message_fields['MSG_recipient_ID'] = $recipient->recipient_id; |
|
675 | + $message_fields['MSG_recipient_type'] = $recipient->recipient_type; |
|
676 | + } |
|
677 | + $message = EE_Message_Factory::create($message_fields); |
|
678 | + |
|
679 | + //grab valid shortcodes for shortcode parser |
|
680 | + $mt_shortcodes = $this->_current_message_type->get_valid_shortcodes(); |
|
681 | + $m_shortcodes = $this->_current_messenger->get_valid_shortcodes(); |
|
682 | + |
|
683 | + //if the 'to' field is empty or the context is inactive we skip EXCEPT if we're previewing |
|
684 | + if (( |
|
685 | + ( |
|
686 | + empty($templates['to'][$context]) |
|
687 | + && ! $this->_current_messenger->allow_empty_to_field() |
|
688 | + ) |
|
689 | + || ! $message_template_group->is_context_active($context) |
|
690 | + ) |
|
691 | + && ! $this->_generation_queue->get_message_repository()->is_preview() |
|
692 | + ) { |
|
693 | + //we silently exit here and do NOT record a fail because the message is "turned off" by having no "to" |
|
694 | + //field. |
|
695 | + return false; |
|
696 | + } |
|
697 | + $error_msg = array(); |
|
698 | + foreach ($templates as $field => $field_context) { |
|
699 | + $error_msg = array(); |
|
700 | + //let's setup the valid shortcodes for the incoming context. |
|
701 | + $valid_shortcodes = $mt_shortcodes[$context]; |
|
702 | + //merge in valid shortcodes for the field. |
|
703 | + $shortcodes = isset($m_shortcodes[$field]) ? $m_shortcodes[$field] : $valid_shortcodes; |
|
704 | + if (isset($templates[$field][$context])) { |
|
705 | + //prefix field. |
|
706 | + $column_name = 'MSG_' . $field; |
|
707 | + try { |
|
708 | + $content = $this->_shortcode_parser->parse_message_template( |
|
709 | + $templates[$field][$context], |
|
710 | + $recipient, |
|
711 | + $shortcodes, |
|
712 | + $this->_current_message_type, |
|
713 | + $this->_current_messenger, |
|
714 | + $message |
|
715 | + ); |
|
716 | + $message->set_field_or_extra_meta($column_name, $content); |
|
717 | + } catch (EE_Error $e) { |
|
718 | + $error_msg[] = sprintf( |
|
719 | + esc_html__( |
|
720 | + 'There was a problem generating the content for the field %s: %s', |
|
721 | + 'event_espresso' |
|
722 | + ), |
|
723 | + $field, |
|
724 | + $e->getMessage() |
|
725 | + ); |
|
726 | + $message->set_STS_ID(EEM_Message::status_failed); |
|
727 | + } |
|
728 | + } |
|
729 | + } |
|
730 | + |
|
731 | + if ($message->STS_ID() === EEM_Message::status_failed) { |
|
732 | + $error_msg = esc_html__('There were problems generating this message:', 'event_espresso') |
|
733 | + . "\n" |
|
734 | + . implode("\n", $error_msg); |
|
735 | + $message->set_error_message($error_msg); |
|
736 | + } else { |
|
737 | + $message->set_STS_ID(EEM_Message::status_idle); |
|
738 | + } |
|
739 | + return $message; |
|
740 | + } |
|
741 | + |
|
742 | + |
|
743 | + /** |
|
744 | + * This verifies that the incoming array has a EE_messenger object and a EE_message_type object and sets appropriate |
|
745 | + * error message if either is missing. |
|
746 | + * |
|
747 | + * @return bool true means there were no errors, false means there were errors. |
|
748 | + * @throws EE_Error |
|
749 | + * @throws ReflectionException |
|
750 | + */ |
|
751 | + protected function _verify() |
|
752 | + { |
|
753 | + //reset error message to an empty array. |
|
754 | + $this->_error_msg = array(); |
|
755 | + $valid = true; |
|
756 | + $valid = $valid ? $this->_validate_messenger_and_message_type() : $valid; |
|
757 | + $valid = $valid ? $this->_validate_and_setup_data() : $valid; |
|
758 | + |
|
759 | + //set the verified flag so we know everything has been validated. |
|
760 | + $this->_verified = $valid; |
|
761 | + |
|
762 | + return $valid; |
|
763 | + } |
|
764 | + |
|
765 | + |
|
766 | + /** |
|
767 | + * This accepts an array and validates that it is an array indexed by context with each value being an array of |
|
768 | + * EE_Messages_Addressee objects. |
|
769 | + * |
|
770 | + * @param array $addressees Keys correspond to contexts for the message type and values are EE_Messages_Addressee[] |
|
771 | + * @return bool |
|
772 | + */ |
|
773 | + protected function _valid_addressees($addressees) |
|
774 | + { |
|
775 | + if (! $addressees || ! is_array($addressees)) { |
|
776 | + return false; |
|
777 | + } |
|
778 | + |
|
779 | + foreach ($addressees as $addressee_array) { |
|
780 | + foreach ($addressee_array as $addressee) { |
|
781 | + if (! $addressee instanceof EE_Messages_Addressee) { |
|
782 | + return false; |
|
783 | + } |
|
784 | + } |
|
785 | + } |
|
786 | + return true; |
|
787 | + } |
|
788 | + |
|
789 | + |
|
790 | + /** |
|
791 | + * This validates the messenger, message type, and presences of generation data for the current EE_Message in the |
|
792 | + * queue. This process sets error messages if something is wrong. |
|
793 | + * |
|
794 | + * @return bool true is if there are no errors. false is if there is. |
|
795 | + */ |
|
796 | + protected function _validate_messenger_and_message_type() |
|
797 | + { |
|
798 | + |
|
799 | + //first are there any existing error messages? If so then return. |
|
800 | + if ($this->_error_msg) { |
|
801 | + return false; |
|
802 | + } |
|
803 | + /** @type EE_Message $message */ |
|
804 | + $message = $this->_generation_queue->get_message_repository()->current(); |
|
805 | + try { |
|
806 | + $this->_current_messenger = $message->valid_messenger(true) |
|
807 | + ? $message->messenger_object() |
|
808 | + : null; |
|
809 | + } catch (Exception $e) { |
|
810 | + $this->_error_msg[] = $e->getMessage(); |
|
811 | + } |
|
812 | + try { |
|
813 | + $this->_current_message_type = $message->valid_message_type(true) |
|
814 | + ? $message->message_type_object() |
|
815 | + : null; |
|
816 | + } catch (Exception $e) { |
|
817 | + $this->_error_msg[] = $e->getMessage(); |
|
818 | + } |
|
819 | + |
|
820 | + /** |
|
821 | + * Check if there is any generation data, but only if this is not for a preview. |
|
822 | + */ |
|
823 | + if (! $this->_generation_queue->get_message_repository()->get_generation_data() |
|
824 | + && ( |
|
825 | + ! $this->_generation_queue->get_message_repository()->is_preview() |
|
826 | + && $this->_generation_queue->get_message_repository()->get_data_handler() |
|
827 | + !== 'EE_Messages_Preview_incoming_data' |
|
828 | + ) |
|
829 | + ) { |
|
830 | + $this->_error_msg[] = esc_html__( |
|
831 | + 'There is no generation data for this message. Unable to generate.', |
|
832 | + 'event_espresso' |
|
833 | + ); |
|
834 | + } |
|
835 | + |
|
836 | + return empty($this->_error_msg); |
|
837 | + } |
|
838 | + |
|
839 | + |
|
840 | + /** |
|
841 | + * This method retrieves the expected data handler for the message type and validates the generation data for that |
|
842 | + * data handler. |
|
843 | + * |
|
844 | + * @return bool true means there are no errors. false means there were errors (and handler did not get setup). |
|
845 | + * @throws EE_Error |
|
846 | + * @throws ReflectionException |
|
847 | + */ |
|
848 | + protected function _validate_and_setup_data() |
|
849 | + { |
|
850 | + |
|
851 | + //First, are there any existing error messages? If so, return because if there were errors elsewhere this can't |
|
852 | + //be used anyways. |
|
853 | + if ($this->_error_msg) { |
|
854 | + return false; |
|
855 | + } |
|
856 | + |
|
857 | + $generation_data = $this->_generation_queue->get_message_repository()->get_generation_data(); |
|
858 | + |
|
859 | + /** @type EE_Messages_incoming_data $data_handler_class_name - well not really... just the class name actually*/ |
|
860 | + $data_handler_class_name = $this->_generation_queue->get_message_repository()->get_data_handler() |
|
861 | + ? $this->_generation_queue->get_message_repository()->get_data_handler() |
|
862 | + : 'EE_Messages_' . $this->_current_message_type->get_data_handler($generation_data) . '_incoming_data'; |
|
863 | + |
|
864 | + //If this EE_Message is for a preview, then let's switch out to the preview data handler. |
|
865 | + if ($this->_generation_queue->get_message_repository()->is_preview()) { |
|
866 | + $data_handler_class_name = 'EE_Messages_Preview_incoming_data'; |
|
867 | + } |
|
868 | + |
|
869 | + //First get the class name for the data handler (and also verifies it exists. |
|
870 | + if (! class_exists($data_handler_class_name)) { |
|
871 | + $this->_error_msg[] = sprintf( |
|
872 | + esc_html__( |
|
873 | + 'The included data handler class name does not match any valid, accessible, "%1$s" classes. Looking for %2$s.', |
|
874 | + 'event_espresso' |
|
875 | + ), |
|
876 | + 'EE_Messages_incoming_data', |
|
877 | + $data_handler_class_name |
|
878 | + ); |
|
879 | + return false; |
|
880 | + } |
|
881 | + |
|
882 | + //convert generation_data for data_handler_instantiation. |
|
883 | + $generation_data = $data_handler_class_name::convert_data_from_persistent_storage($generation_data); |
|
884 | + |
|
885 | + //note, this may set error messages as well. |
|
886 | + $this->_set_data_handler($generation_data, $data_handler_class_name); |
|
887 | + |
|
888 | + return empty($this->_error_msg); |
|
889 | + } |
|
890 | + |
|
891 | + |
|
892 | + /** |
|
893 | + * Sets the $_current_data_handler property that is used for generating the current EE_Message in the queue, and |
|
894 | + * adds it to the _data repository. |
|
895 | + * |
|
896 | + * @param mixed $generating_data This is data expected by the instantiated data handler. |
|
897 | + * @param string $data_handler_class_name This is the reference string indicating what data handler is being |
|
898 | + * instantiated. |
|
899 | + * @return void . |
|
900 | + * @throws EE_Error |
|
901 | + * @throws ReflectionException |
|
902 | + */ |
|
903 | + protected function _set_data_handler($generating_data, $data_handler_class_name) |
|
904 | + { |
|
905 | + //valid classname for the data handler. Now let's setup the key for the data handler repository to see if there |
|
906 | + //is already a ready data handler in the repository. |
|
907 | + $this->_current_data_handler = $this->_data_handler_collection->get_by_key( |
|
908 | + $this->_data_handler_collection->get_key( |
|
909 | + $data_handler_class_name, |
|
910 | + $generating_data |
|
911 | + ) |
|
912 | + ); |
|
913 | + if (! $this->_current_data_handler instanceof EE_Messages_incoming_data) { |
|
914 | + //no saved data_handler in the repo so let's set one up and add it to the repo. |
|
915 | + try { |
|
916 | + $this->_current_data_handler = new $data_handler_class_name($generating_data); |
|
917 | + $this->_data_handler_collection->add($this->_current_data_handler, $generating_data); |
|
918 | + } catch (EE_Error $e) { |
|
919 | + $this->_error_msg[] = $e->get_error(); |
|
920 | + } |
|
921 | + } |
|
922 | + } |
|
923 | + |
|
924 | + |
|
925 | + /** |
|
926 | + * The queued EE_Message for generation does not save the data used for generation as objects |
|
927 | + * because serialization of those objects could be problematic if the data is saved to the db. |
|
928 | + * So this method calls the static method on the associated data_handler for the given message_type |
|
929 | + * and that preps the data for later instantiation when generating. |
|
930 | + * |
|
931 | + * @param EE_Message_To_Generate $message_to_generate |
|
932 | + * @param bool $preview Indicate whether this is being used for a preview or not. |
|
933 | + * @return mixed Prepped data for persisting to the queue. false is returned if unable to prep data. |
|
934 | + */ |
|
935 | + protected function _prepare_data_for_queue(EE_Message_To_Generate $message_to_generate, $preview) |
|
936 | + { |
|
937 | + /** @type EE_Messages_incoming_data $data_handler - well not really... just the class name actually */ |
|
938 | + $data_handler = $message_to_generate->get_data_handler_class_name($preview); |
|
939 | + if (! $message_to_generate->valid()) { |
|
940 | + return false; //unable to get the data because the info in the EE_Message_To_Generate class is invalid. |
|
941 | + } |
|
942 | + return $data_handler::convert_data_for_persistent_storage($message_to_generate->data()); |
|
943 | + } |
|
944 | + |
|
945 | + |
|
946 | + /** |
|
947 | + * This sets up a EEM_Message::status_incomplete EE_Message object and adds it to the generation queue. |
|
948 | + * |
|
949 | + * @param EE_Message_To_Generate $message_to_generate |
|
950 | + * @param bool $test_send Whether this is just a test send or not. Typically used for previews. |
|
951 | + * @throws InvalidArgumentException |
|
952 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
953 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
954 | + */ |
|
955 | + public function create_and_add_message_to_queue(EE_Message_To_Generate $message_to_generate, $test_send = false) |
|
956 | + { |
|
957 | + //prep data |
|
958 | + $data = $this->_prepare_data_for_queue($message_to_generate, $message_to_generate->preview()); |
|
959 | + |
|
960 | + $message = $message_to_generate->get_EE_Message(); |
|
961 | + |
|
962 | + //is there a GRP_ID in the request? |
|
963 | + if ($GRP_ID = EE_Registry::instance()->REQ->get('GRP_ID')) { |
|
964 | + $message->set_GRP_ID($GRP_ID); |
|
965 | + } |
|
966 | + |
|
967 | + if ($data === false) { |
|
968 | + $message->set_STS_ID(EEM_Message::status_failed); |
|
969 | + $message->set_error_message( |
|
970 | + esc_html__( |
|
971 | + 'Unable to prepare data for persistence to the database.', |
|
972 | + 'event_espresso' |
|
973 | + ) |
|
974 | + ); |
|
975 | + } else { |
|
976 | + //make sure that the data handler is cached on the message as well |
|
977 | + $data['data_handler_class_name'] = $message_to_generate->get_data_handler_class_name(); |
|
978 | + } |
|
979 | + |
|
980 | + $this->_generation_queue->add($message, $data, $message_to_generate->preview(), $test_send); |
|
981 | + } |
|
982 | 982 | } |
@@ -259,7 +259,7 @@ discard block |
||
259 | 259 | { |
260 | 260 | //double check verification has run and that everything is ready to work with (saves us having to validate |
261 | 261 | // everything again). |
262 | - if (! $this->_verified) { |
|
262 | + if ( ! $this->_verified) { |
|
263 | 263 | return false; //get out because we don't have a valid setup to work with. |
264 | 264 | } |
265 | 265 | |
@@ -276,7 +276,7 @@ discard block |
||
276 | 276 | |
277 | 277 | |
278 | 278 | //if no addressees then get out because there is nothing to generation (possible bad data). |
279 | - if (! $this->_valid_addressees($addressees)) { |
|
279 | + if ( ! $this->_valid_addressees($addressees)) { |
|
280 | 280 | do_action( |
281 | 281 | 'AHEE__EE_Messages_Generator___generate__invalid_addressees', |
282 | 282 | $this->_generation_queue->get_message_repository()->current(), |
@@ -298,7 +298,7 @@ discard block |
||
298 | 298 | $message_template_group = $this->_get_message_template_group(); |
299 | 299 | |
300 | 300 | //in the unlikely event there is no EE_Message_Template_Group available, get out! |
301 | - if (! $message_template_group instanceof EE_Message_Template_Group) { |
|
301 | + if ( ! $message_template_group instanceof EE_Message_Template_Group) { |
|
302 | 302 | $this->_error_msg[] = esc_html__( |
303 | 303 | 'Unable to get the Message Templates for the Message being generated. No message template group accessible.', |
304 | 304 | 'event_espresso' |
@@ -408,7 +408,7 @@ discard block |
||
408 | 408 | //attempt to retrieve from repo first |
409 | 409 | $message_template_group = $this->_template_collection->get_by_ID($GRP_ID); |
410 | 410 | if ($message_template_group instanceof EE_Message_Template_Group) { |
411 | - return $message_template_group; //got it! |
|
411 | + return $message_template_group; //got it! |
|
412 | 412 | } |
413 | 413 | |
414 | 414 | //nope don't have it yet. Get from DB then add to repo if its not here, then that means the current GRP_ID |
@@ -513,7 +513,7 @@ discard block |
||
513 | 513 | ); |
514 | 514 | |
515 | 515 | //if we don't have a group lets hit the db. |
516 | - if (! $global_message_template_group instanceof EE_Message_Template_Group) { |
|
516 | + if ( ! $global_message_template_group instanceof EE_Message_Template_Group) { |
|
517 | 517 | $global_message_template_group = EEM_Message_Template_Group::instance()->get_one( |
518 | 518 | array( |
519 | 519 | array( |
@@ -570,7 +570,7 @@ discard block |
||
570 | 570 | $context_templates = $message_template_group->context_templates(); |
571 | 571 | foreach ($context_templates as $context => $template_fields) { |
572 | 572 | foreach ($template_fields as $template_field => $template_obj) { |
573 | - if (! $template_obj instanceof EE_Message_Template) { |
|
573 | + if ( ! $template_obj instanceof EE_Message_Template) { |
|
574 | 574 | continue; |
575 | 575 | } |
576 | 576 | $templates[$template_field][$context] = $template_obj->get('MTP_content'); |
@@ -599,7 +599,7 @@ discard block |
||
599 | 599 | { |
600 | 600 | |
601 | 601 | //if templates are empty then get out because we can't generate anything. |
602 | - if (! $templates) { |
|
602 | + if ( ! $templates) { |
|
603 | 603 | $this->_error_msg[] = esc_html__( |
604 | 604 | 'Unable to assemble messages because there are no templates retrieved for generating the messages with', |
605 | 605 | 'event_espresso' |
@@ -703,7 +703,7 @@ discard block |
||
703 | 703 | $shortcodes = isset($m_shortcodes[$field]) ? $m_shortcodes[$field] : $valid_shortcodes; |
704 | 704 | if (isset($templates[$field][$context])) { |
705 | 705 | //prefix field. |
706 | - $column_name = 'MSG_' . $field; |
|
706 | + $column_name = 'MSG_'.$field; |
|
707 | 707 | try { |
708 | 708 | $content = $this->_shortcode_parser->parse_message_template( |
709 | 709 | $templates[$field][$context], |
@@ -772,13 +772,13 @@ discard block |
||
772 | 772 | */ |
773 | 773 | protected function _valid_addressees($addressees) |
774 | 774 | { |
775 | - if (! $addressees || ! is_array($addressees)) { |
|
775 | + if ( ! $addressees || ! is_array($addressees)) { |
|
776 | 776 | return false; |
777 | 777 | } |
778 | 778 | |
779 | 779 | foreach ($addressees as $addressee_array) { |
780 | 780 | foreach ($addressee_array as $addressee) { |
781 | - if (! $addressee instanceof EE_Messages_Addressee) { |
|
781 | + if ( ! $addressee instanceof EE_Messages_Addressee) { |
|
782 | 782 | return false; |
783 | 783 | } |
784 | 784 | } |
@@ -820,7 +820,7 @@ discard block |
||
820 | 820 | /** |
821 | 821 | * Check if there is any generation data, but only if this is not for a preview. |
822 | 822 | */ |
823 | - if (! $this->_generation_queue->get_message_repository()->get_generation_data() |
|
823 | + if ( ! $this->_generation_queue->get_message_repository()->get_generation_data() |
|
824 | 824 | && ( |
825 | 825 | ! $this->_generation_queue->get_message_repository()->is_preview() |
826 | 826 | && $this->_generation_queue->get_message_repository()->get_data_handler() |
@@ -859,7 +859,7 @@ discard block |
||
859 | 859 | /** @type EE_Messages_incoming_data $data_handler_class_name - well not really... just the class name actually*/ |
860 | 860 | $data_handler_class_name = $this->_generation_queue->get_message_repository()->get_data_handler() |
861 | 861 | ? $this->_generation_queue->get_message_repository()->get_data_handler() |
862 | - : 'EE_Messages_' . $this->_current_message_type->get_data_handler($generation_data) . '_incoming_data'; |
|
862 | + : 'EE_Messages_'.$this->_current_message_type->get_data_handler($generation_data).'_incoming_data'; |
|
863 | 863 | |
864 | 864 | //If this EE_Message is for a preview, then let's switch out to the preview data handler. |
865 | 865 | if ($this->_generation_queue->get_message_repository()->is_preview()) { |
@@ -867,7 +867,7 @@ discard block |
||
867 | 867 | } |
868 | 868 | |
869 | 869 | //First get the class name for the data handler (and also verifies it exists. |
870 | - if (! class_exists($data_handler_class_name)) { |
|
870 | + if ( ! class_exists($data_handler_class_name)) { |
|
871 | 871 | $this->_error_msg[] = sprintf( |
872 | 872 | esc_html__( |
873 | 873 | 'The included data handler class name does not match any valid, accessible, "%1$s" classes. Looking for %2$s.', |
@@ -910,7 +910,7 @@ discard block |
||
910 | 910 | $generating_data |
911 | 911 | ) |
912 | 912 | ); |
913 | - if (! $this->_current_data_handler instanceof EE_Messages_incoming_data) { |
|
913 | + if ( ! $this->_current_data_handler instanceof EE_Messages_incoming_data) { |
|
914 | 914 | //no saved data_handler in the repo so let's set one up and add it to the repo. |
915 | 915 | try { |
916 | 916 | $this->_current_data_handler = new $data_handler_class_name($generating_data); |
@@ -936,7 +936,7 @@ discard block |
||
936 | 936 | { |
937 | 937 | /** @type EE_Messages_incoming_data $data_handler - well not really... just the class name actually */ |
938 | 938 | $data_handler = $message_to_generate->get_data_handler_class_name($preview); |
939 | - if (! $message_to_generate->valid()) { |
|
939 | + if ( ! $message_to_generate->valid()) { |
|
940 | 940 | return false; //unable to get the data because the info in the EE_Message_To_Generate class is invalid. |
941 | 941 | } |
942 | 942 | return $data_handler::convert_data_for_persistent_storage($message_to_generate->data()); |
@@ -10,22 +10,22 @@ discard block |
||
10 | 10 | * @var int $message_template_group_id The ID for the message template group this context belongs to. |
11 | 11 | */ |
12 | 12 | $active_message = sprintf( |
13 | - esc_html__( |
|
14 | - 'The template for %1$s is currently %2$sactive%3$s.', |
|
15 | - 'event_espresso' |
|
16 | - ), |
|
17 | - $context_label, |
|
18 | - '<strong>', |
|
19 | - '</strong>' |
|
13 | + esc_html__( |
|
14 | + 'The template for %1$s is currently %2$sactive%3$s.', |
|
15 | + 'event_espresso' |
|
16 | + ), |
|
17 | + $context_label, |
|
18 | + '<strong>', |
|
19 | + '</strong>' |
|
20 | 20 | ); |
21 | 21 | $inactive_message = sprintf( |
22 | - esc_html__( |
|
23 | - 'The template for %1$s is currently %2$sinactive%3$s.', |
|
24 | - 'event_espresso' |
|
25 | - ), |
|
26 | - $context_label, |
|
27 | - '<strong>', |
|
28 | - '</strong>' |
|
22 | + esc_html__( |
|
23 | + 'The template for %1$s is currently %2$sinactive%3$s.', |
|
24 | + 'event_espresso' |
|
25 | + ), |
|
26 | + $context_label, |
|
27 | + '<strong>', |
|
28 | + '</strong>' |
|
29 | 29 | ); |
30 | 30 | ?> |
31 | 31 | <div class="context-active-control-container"> |
@@ -34,8 +34,8 @@ discard block |
||
34 | 34 | <span id="on-off-nonce-<?php echo $context; ?>" class="hidden"><?php echo $nonce; ?></span> |
35 | 35 | <span class="ee-on-off-toggle-label"> |
36 | 36 | <?php |
37 | - echo $is_active ? $active_message : $inactive_message; |
|
38 | - ?> |
|
37 | + echo $is_active ? $active_message : $inactive_message; |
|
38 | + ?> |
|
39 | 39 | </span> |
40 | 40 | <div class="hidden js-data"> |
41 | 41 | <span class="ee-active-message"><?php echo $active_message; ?></span> |
@@ -43,8 +43,8 @@ discard block |
||
43 | 43 | </div> |
44 | 44 | <div class="switch"> |
45 | 45 | <?php |
46 | - $checked = $is_active ? ' checked="checked"' : ''; |
|
47 | - ?> |
|
46 | + $checked = $is_active ? ' checked="checked"' : ''; |
|
47 | + ?> |
|
48 | 48 | <input data-grpid="<?php echo $message_template_group_id; ?>" id="ee-on-off-toggle-<?php echo $context; ?>" type="checkbox" class="ee-on-off-toggle ee-toggle-round-flat"<?php echo $checked; ?> value="<?php echo $on_off_action; ?>"> |
49 | 49 | <label for="ee-on-off-toggle-<?php echo $context; ?>"></label> |
50 | 50 | </div> |
@@ -13,373 +13,373 @@ |
||
13 | 13 | { |
14 | 14 | |
15 | 15 | |
16 | - /** |
|
17 | - * @return Messages_Admin_Page |
|
18 | - */ |
|
19 | - public function get_admin_page() |
|
20 | - { |
|
21 | - return $this->_admin_page; |
|
22 | - } |
|
23 | - |
|
24 | - |
|
25 | - /** |
|
26 | - * Setup data object |
|
27 | - */ |
|
28 | - protected function _setup_data() |
|
29 | - { |
|
30 | - $this->_data = $this->get_admin_page()->get_message_templates( |
|
31 | - $this->_per_page, |
|
32 | - $this->_view, |
|
33 | - false |
|
34 | - ); |
|
35 | - $this->_all_data_count = $this->get_admin_page()->get_message_templates( |
|
36 | - $this->_per_page, |
|
37 | - $this->_view, |
|
38 | - true, |
|
39 | - true |
|
40 | - ); |
|
41 | - } |
|
42 | - |
|
43 | - |
|
44 | - /** |
|
45 | - * Set internal properties |
|
46 | - */ |
|
47 | - protected function _set_properties() |
|
48 | - { |
|
49 | - $this->_wp_list_args = array( |
|
50 | - 'singular' => esc_html__('Message Template Group', 'event_espresso'), |
|
51 | - 'plural' => esc_html__('Message Template', 'event_espresso'), |
|
52 | - 'ajax' => true, //for now, |
|
53 | - 'screen' => $this->get_admin_page()->get_current_screen()->id, |
|
54 | - ); |
|
55 | - $this->_columns = array( |
|
56 | - //'cb' => '<input type="checkbox" />', //no deleting default (global) templates! |
|
57 | - 'message_type' => esc_html__('Message Type', 'event_espresso'), |
|
58 | - 'messenger' => esc_html__('Messenger', 'event_espresso'), |
|
59 | - 'description' => esc_html__('Description', 'event_espresso'), |
|
60 | - ); |
|
61 | - |
|
62 | - $this->_sortable_columns = array( |
|
63 | - 'messenger' => array('MTP_messenger' => true), |
|
64 | - ); |
|
65 | - |
|
66 | - $this->_hidden_columns = array(); |
|
67 | - } |
|
68 | - |
|
69 | - |
|
70 | - /** |
|
71 | - * Overriding the single_row method from parent to verify whether the $item has an accessible |
|
72 | - * message_type or messenger object before generating the row. |
|
73 | - * |
|
74 | - * @param EE_Message_Template_Group $item |
|
75 | - * @return string |
|
76 | - * @throws EE_Error |
|
77 | - */ |
|
78 | - public function single_row($item) |
|
79 | - { |
|
80 | - $message_type = $item->message_type_obj(); |
|
81 | - $messenger = $item->messenger_obj(); |
|
82 | - |
|
83 | - if (! $message_type instanceof EE_message_type || ! $messenger instanceof EE_messenger) { |
|
84 | - echo ''; |
|
85 | - return; |
|
86 | - } |
|
87 | - |
|
88 | - parent::single_row($item); |
|
89 | - } |
|
90 | - |
|
91 | - |
|
92 | - /** |
|
93 | - * @return array |
|
94 | - * @throws EE_Error |
|
95 | - */ |
|
96 | - protected function _get_table_filters() |
|
97 | - { |
|
98 | - $filters = array(); |
|
99 | - |
|
100 | - //get select inputs |
|
101 | - $select_inputs = array( |
|
102 | - $this->_get_messengers_dropdown_filter(), |
|
103 | - $this->_get_message_types_dropdown_filter(), |
|
104 | - ); |
|
105 | - |
|
106 | - //set filters to select inputs if they aren't empty |
|
107 | - foreach ($select_inputs as $select_input) { |
|
108 | - if ($select_input) { |
|
109 | - $filters[] = $select_input; |
|
110 | - } |
|
111 | - } |
|
112 | - return $filters; |
|
113 | - } |
|
114 | - |
|
115 | - /** |
|
116 | - * We're just removing the search box for message templates, not needed. |
|
117 | - * |
|
118 | - * @param string $text |
|
119 | - * @param string $input_id |
|
120 | - * @return string ; |
|
121 | - */ |
|
122 | - public function search_box($text, $input_id) |
|
123 | - { |
|
124 | - return ''; |
|
125 | - } |
|
126 | - |
|
127 | - |
|
128 | - /** |
|
129 | - * Add counts to the _views property |
|
130 | - */ |
|
131 | - protected function _add_view_counts() |
|
132 | - { |
|
133 | - foreach ($this->_views as $view => $args) { |
|
134 | - $this->_views[$view]['count'] = $this->get_admin_page()->get_message_templates( |
|
135 | - $this->_per_page, |
|
136 | - $view, |
|
137 | - true, |
|
138 | - true |
|
139 | - ); |
|
140 | - } |
|
141 | - } |
|
142 | - |
|
143 | - |
|
144 | - /** |
|
145 | - * @param EE_Message_Template_Group $item |
|
146 | - * @return string |
|
147 | - */ |
|
148 | - public function column_cb($item) |
|
149 | - { |
|
150 | - return ''; |
|
151 | - } |
|
152 | - |
|
153 | - |
|
154 | - /** |
|
155 | - * @param EE_Message_Template_Group $item |
|
156 | - * @return string |
|
157 | - * @throws EE_Error |
|
158 | - */ |
|
159 | - public function column_description($item) |
|
160 | - { |
|
161 | - return '<p>' . $item->message_type_obj()->description . '</p>'; |
|
162 | - } |
|
163 | - |
|
164 | - |
|
165 | - /** |
|
166 | - * @param EE_Message_Template_Group $item |
|
167 | - * @return string |
|
168 | - * @throws EE_Error |
|
169 | - */ |
|
170 | - public function column_messenger($item) |
|
171 | - { |
|
172 | - //Return the name contents |
|
173 | - return sprintf( |
|
174 | - '%1$s <span style="color:silver">(id:%2$s)</span><br />%3$s%4$s', |
|
175 | - /* $1%s */ |
|
176 | - $this->_get_name_link_for_messenger($item), |
|
177 | - /* $2%s */ |
|
178 | - $item->GRP_ID(), |
|
179 | - /* %4$s */ |
|
180 | - $this->_get_context_links($item), |
|
181 | - /* $3%s */ |
|
182 | - $this->row_actions($this->_get_actions_for_messenger_column($item)) |
|
183 | - ); |
|
184 | - } |
|
185 | - |
|
186 | - /** |
|
187 | - * column_message_type |
|
188 | - * |
|
189 | - * @param EE_Message_Template_Group $item message info for the row |
|
190 | - * @return string message_type name |
|
191 | - * @throws EE_Error |
|
192 | - */ |
|
193 | - public function column_message_type($item) |
|
194 | - { |
|
195 | - return ucwords($item->message_type_obj()->label['singular']); |
|
196 | - } |
|
197 | - |
|
198 | - |
|
199 | - /** |
|
200 | - * Generate dropdown filter select input for messengers |
|
201 | - * |
|
202 | - * @param bool $global |
|
203 | - * @return string |
|
204 | - * @throws EE_Error |
|
205 | - */ |
|
206 | - protected function _get_messengers_dropdown_filter($global = true) |
|
207 | - { |
|
208 | - $messenger_options = array(); |
|
209 | - $active_message_template_groups_grouped_by_messenger = EEM_Message_Template_Group::instance()->get_all( |
|
210 | - array( |
|
211 | - array( |
|
212 | - 'MTP_is_active' => true, |
|
213 | - 'MTP_is_global' => $global, |
|
214 | - ), |
|
215 | - 'group_by' => 'MTP_messenger', |
|
216 | - ) |
|
217 | - ); |
|
218 | - |
|
219 | - foreach ($active_message_template_groups_grouped_by_messenger as $active_message_template_group) { |
|
220 | - if ($active_message_template_group instanceof EE_Message_Template_Group) { |
|
221 | - $messenger = $active_message_template_group->messenger_obj(); |
|
222 | - $messenger_label = $messenger instanceof EE_messenger |
|
223 | - ? $messenger->label['singular'] |
|
224 | - : $active_message_template_group->messenger(); |
|
225 | - $messenger_options[$active_message_template_group->messenger()] = ucwords($messenger_label); |
|
226 | - } |
|
227 | - } |
|
228 | - return $this->get_admin_page()->get_messengers_select_input($messenger_options); |
|
229 | - } |
|
230 | - |
|
231 | - |
|
232 | - /** |
|
233 | - * Generate dropdown filter select input for message types |
|
234 | - * |
|
235 | - * @param bool $global |
|
236 | - * @return string |
|
237 | - * @throws EE_Error |
|
238 | - */ |
|
239 | - protected function _get_message_types_dropdown_filter($global = true) |
|
240 | - { |
|
241 | - $message_type_options = array(); |
|
242 | - $active_message_template_groups_grouped_by_message_type = EEM_Message_Template_Group::instance()->get_all( |
|
243 | - array( |
|
244 | - array( |
|
245 | - 'MTP_is_active' => true, |
|
246 | - 'MTP_is_global' => true, |
|
247 | - ), |
|
248 | - 'group_by' => 'MTP_message_type', |
|
249 | - ) |
|
250 | - ); |
|
251 | - |
|
252 | - foreach ($active_message_template_groups_grouped_by_message_type as $active_message_template_group) { |
|
253 | - if ($active_message_template_group instanceof EE_Message_Template_Group) { |
|
254 | - $message_type = $active_message_template_group->message_type_obj(); |
|
255 | - $message_type_label = $message_type instanceof EE_message_type |
|
256 | - ? $message_type->label['singular'] |
|
257 | - : $active_message_template_group->message_type(); |
|
258 | - $message_type_options[$active_message_template_group->message_type()] = ucwords($message_type_label); |
|
259 | - } |
|
260 | - } |
|
261 | - return $this->get_admin_page()->get_message_types_select_input($message_type_options); |
|
262 | - } |
|
263 | - |
|
264 | - |
|
265 | - /** |
|
266 | - * Return the edit url for the message template group. |
|
267 | - * @param EE_Message_Template_Group $item |
|
268 | - * @return string |
|
269 | - * @throws EE_Error |
|
270 | - */ |
|
271 | - protected function _get_edit_url(EE_Message_Template_Group $item) |
|
272 | - { |
|
273 | - $edit_url = ''; |
|
274 | - // edit link but only if item isn't trashed. |
|
275 | - if (! $item->get('MTP_deleted') |
|
276 | - && EE_Registry::instance()->CAP->current_user_can( |
|
277 | - 'ee_edit_message', |
|
278 | - 'espresso_messages_edit_message_template', |
|
279 | - $item->ID() |
|
280 | - )) { |
|
281 | - $edit_url = EE_Admin_Page::add_query_args_and_nonce( |
|
282 | - array( |
|
283 | - 'action' => 'edit_message_template', |
|
284 | - 'id' => $item->GRP_ID(), |
|
285 | - ), |
|
286 | - EE_MSG_ADMIN_URL |
|
287 | - ); |
|
288 | - } |
|
289 | - return $edit_url; |
|
290 | - } |
|
291 | - |
|
292 | - |
|
293 | - /** |
|
294 | - * Get the context link string for the messenger column. |
|
295 | - * @param EE_Message_Template_Group $item |
|
296 | - * @return string |
|
297 | - * @throws EE_Error |
|
298 | - */ |
|
299 | - protected function _get_context_links(EE_Message_Template_Group $item) |
|
300 | - { |
|
301 | - //first check if we even show the context links or not. |
|
302 | - if (! EE_Registry::instance()->CAP->current_user_can( |
|
303 | - 'ee_edit_message', |
|
304 | - 'espresso_messages_edit_message_template', |
|
305 | - $item->ID() |
|
306 | - ) |
|
307 | - || $item->get('MTP_deleted') |
|
308 | - ) { |
|
309 | - return ''; |
|
310 | - } |
|
311 | - //we want to display the contexts in here so we need to set them up |
|
312 | - $c_label = $item->context_label(); |
|
313 | - $c_configs = $item->contexts_config(); |
|
314 | - $ctxt = array(); |
|
315 | - $context_templates = $item->context_templates(); |
|
316 | - foreach ($context_templates as $context => $template_fields) { |
|
317 | - $mtp_to = ! empty($context_templates[$context]['to']) |
|
318 | - && $context_templates[$context]['to'] instanceof EE_Message_Template |
|
319 | - ? $context_templates[$context]['to']->get('MTP_content') |
|
320 | - : null; |
|
321 | - $inactive_class = ( |
|
322 | - empty($mtp_to) |
|
323 | - && ! empty($context_templates[$context]['to']) |
|
324 | - ) |
|
325 | - || ! $item->is_context_active($context) |
|
326 | - ? ' mtp-inactive' |
|
327 | - : ''; |
|
328 | - $context_title = ucwords($c_configs[$context]['label']); |
|
329 | - $edit_link = EE_Admin_Page::add_query_args_and_nonce(array( |
|
330 | - 'action' => 'edit_message_template', |
|
331 | - 'id' => $item->GRP_ID(), |
|
332 | - 'context' => $context, |
|
333 | - ), EE_MSG_ADMIN_URL); |
|
334 | - $ctxt[] = '<a' |
|
335 | - . ' href="' . $edit_link . '"' |
|
336 | - . ' class="' . $item->message_type() . '-' . $context . '-edit-link' .$inactive_class . '"' |
|
337 | - . ' title="' . esc_attr__('Edit Context', 'event_espresso') . '">' |
|
338 | - . $context_title |
|
339 | - . '</a>'; |
|
340 | - } |
|
341 | - |
|
342 | - return sprintf('<strong>%s:</strong> ', ucwords($c_label['plural'])) . implode(' | ', $ctxt); |
|
343 | - } |
|
344 | - |
|
345 | - |
|
346 | - /** |
|
347 | - * Get the Name string from the messenger column (linked to edit if the context allows for that). |
|
348 | - * @param EE_Message_Template_Group $item |
|
349 | - * @return string |
|
350 | - * @throws EE_Error |
|
351 | - */ |
|
352 | - protected function _get_name_link_for_messenger(EE_Message_Template_Group $item) |
|
353 | - { |
|
354 | - $edit_url = $this->_get_edit_url($item); |
|
355 | - return $edit_url |
|
356 | - ? '<a href="' . $edit_url . '"' |
|
357 | - . ' title="' . esc_attr__('Edit Template Group', 'event_espresso') . '">' |
|
358 | - . ucwords($item->messenger_obj()->label['singular']) |
|
359 | - . '</a>' |
|
360 | - : ucwords($item->messenger_obj()->label['singular']); |
|
361 | - } |
|
362 | - |
|
363 | - |
|
364 | - /** |
|
365 | - * Return the actions array for the messenger column. |
|
366 | - * @param EE_Message_Template_Group $item |
|
367 | - * @return array |
|
368 | - * @throws EE_Error |
|
369 | - */ |
|
370 | - protected function _get_actions_for_messenger_column(EE_Message_Template_Group $item) |
|
371 | - { |
|
372 | - $actions = array(); |
|
373 | - if ($edit_url = $this->_get_edit_url($item)) { |
|
374 | - $actions = array( |
|
375 | - 'edit' => '<a href="' . $edit_url . '"' |
|
376 | - . ' class="' . $item->message_type() . '-edit-link"' |
|
377 | - . ' title="' . esc_attr__('Edit Template Group', 'event_espresso') . '">' |
|
378 | - . esc_html__('Edit', 'event_espresso') |
|
379 | - . '</a>' |
|
380 | - ); |
|
381 | - } |
|
382 | - return $actions; |
|
383 | - } |
|
16 | + /** |
|
17 | + * @return Messages_Admin_Page |
|
18 | + */ |
|
19 | + public function get_admin_page() |
|
20 | + { |
|
21 | + return $this->_admin_page; |
|
22 | + } |
|
23 | + |
|
24 | + |
|
25 | + /** |
|
26 | + * Setup data object |
|
27 | + */ |
|
28 | + protected function _setup_data() |
|
29 | + { |
|
30 | + $this->_data = $this->get_admin_page()->get_message_templates( |
|
31 | + $this->_per_page, |
|
32 | + $this->_view, |
|
33 | + false |
|
34 | + ); |
|
35 | + $this->_all_data_count = $this->get_admin_page()->get_message_templates( |
|
36 | + $this->_per_page, |
|
37 | + $this->_view, |
|
38 | + true, |
|
39 | + true |
|
40 | + ); |
|
41 | + } |
|
42 | + |
|
43 | + |
|
44 | + /** |
|
45 | + * Set internal properties |
|
46 | + */ |
|
47 | + protected function _set_properties() |
|
48 | + { |
|
49 | + $this->_wp_list_args = array( |
|
50 | + 'singular' => esc_html__('Message Template Group', 'event_espresso'), |
|
51 | + 'plural' => esc_html__('Message Template', 'event_espresso'), |
|
52 | + 'ajax' => true, //for now, |
|
53 | + 'screen' => $this->get_admin_page()->get_current_screen()->id, |
|
54 | + ); |
|
55 | + $this->_columns = array( |
|
56 | + //'cb' => '<input type="checkbox" />', //no deleting default (global) templates! |
|
57 | + 'message_type' => esc_html__('Message Type', 'event_espresso'), |
|
58 | + 'messenger' => esc_html__('Messenger', 'event_espresso'), |
|
59 | + 'description' => esc_html__('Description', 'event_espresso'), |
|
60 | + ); |
|
61 | + |
|
62 | + $this->_sortable_columns = array( |
|
63 | + 'messenger' => array('MTP_messenger' => true), |
|
64 | + ); |
|
65 | + |
|
66 | + $this->_hidden_columns = array(); |
|
67 | + } |
|
68 | + |
|
69 | + |
|
70 | + /** |
|
71 | + * Overriding the single_row method from parent to verify whether the $item has an accessible |
|
72 | + * message_type or messenger object before generating the row. |
|
73 | + * |
|
74 | + * @param EE_Message_Template_Group $item |
|
75 | + * @return string |
|
76 | + * @throws EE_Error |
|
77 | + */ |
|
78 | + public function single_row($item) |
|
79 | + { |
|
80 | + $message_type = $item->message_type_obj(); |
|
81 | + $messenger = $item->messenger_obj(); |
|
82 | + |
|
83 | + if (! $message_type instanceof EE_message_type || ! $messenger instanceof EE_messenger) { |
|
84 | + echo ''; |
|
85 | + return; |
|
86 | + } |
|
87 | + |
|
88 | + parent::single_row($item); |
|
89 | + } |
|
90 | + |
|
91 | + |
|
92 | + /** |
|
93 | + * @return array |
|
94 | + * @throws EE_Error |
|
95 | + */ |
|
96 | + protected function _get_table_filters() |
|
97 | + { |
|
98 | + $filters = array(); |
|
99 | + |
|
100 | + //get select inputs |
|
101 | + $select_inputs = array( |
|
102 | + $this->_get_messengers_dropdown_filter(), |
|
103 | + $this->_get_message_types_dropdown_filter(), |
|
104 | + ); |
|
105 | + |
|
106 | + //set filters to select inputs if they aren't empty |
|
107 | + foreach ($select_inputs as $select_input) { |
|
108 | + if ($select_input) { |
|
109 | + $filters[] = $select_input; |
|
110 | + } |
|
111 | + } |
|
112 | + return $filters; |
|
113 | + } |
|
114 | + |
|
115 | + /** |
|
116 | + * We're just removing the search box for message templates, not needed. |
|
117 | + * |
|
118 | + * @param string $text |
|
119 | + * @param string $input_id |
|
120 | + * @return string ; |
|
121 | + */ |
|
122 | + public function search_box($text, $input_id) |
|
123 | + { |
|
124 | + return ''; |
|
125 | + } |
|
126 | + |
|
127 | + |
|
128 | + /** |
|
129 | + * Add counts to the _views property |
|
130 | + */ |
|
131 | + protected function _add_view_counts() |
|
132 | + { |
|
133 | + foreach ($this->_views as $view => $args) { |
|
134 | + $this->_views[$view]['count'] = $this->get_admin_page()->get_message_templates( |
|
135 | + $this->_per_page, |
|
136 | + $view, |
|
137 | + true, |
|
138 | + true |
|
139 | + ); |
|
140 | + } |
|
141 | + } |
|
142 | + |
|
143 | + |
|
144 | + /** |
|
145 | + * @param EE_Message_Template_Group $item |
|
146 | + * @return string |
|
147 | + */ |
|
148 | + public function column_cb($item) |
|
149 | + { |
|
150 | + return ''; |
|
151 | + } |
|
152 | + |
|
153 | + |
|
154 | + /** |
|
155 | + * @param EE_Message_Template_Group $item |
|
156 | + * @return string |
|
157 | + * @throws EE_Error |
|
158 | + */ |
|
159 | + public function column_description($item) |
|
160 | + { |
|
161 | + return '<p>' . $item->message_type_obj()->description . '</p>'; |
|
162 | + } |
|
163 | + |
|
164 | + |
|
165 | + /** |
|
166 | + * @param EE_Message_Template_Group $item |
|
167 | + * @return string |
|
168 | + * @throws EE_Error |
|
169 | + */ |
|
170 | + public function column_messenger($item) |
|
171 | + { |
|
172 | + //Return the name contents |
|
173 | + return sprintf( |
|
174 | + '%1$s <span style="color:silver">(id:%2$s)</span><br />%3$s%4$s', |
|
175 | + /* $1%s */ |
|
176 | + $this->_get_name_link_for_messenger($item), |
|
177 | + /* $2%s */ |
|
178 | + $item->GRP_ID(), |
|
179 | + /* %4$s */ |
|
180 | + $this->_get_context_links($item), |
|
181 | + /* $3%s */ |
|
182 | + $this->row_actions($this->_get_actions_for_messenger_column($item)) |
|
183 | + ); |
|
184 | + } |
|
185 | + |
|
186 | + /** |
|
187 | + * column_message_type |
|
188 | + * |
|
189 | + * @param EE_Message_Template_Group $item message info for the row |
|
190 | + * @return string message_type name |
|
191 | + * @throws EE_Error |
|
192 | + */ |
|
193 | + public function column_message_type($item) |
|
194 | + { |
|
195 | + return ucwords($item->message_type_obj()->label['singular']); |
|
196 | + } |
|
197 | + |
|
198 | + |
|
199 | + /** |
|
200 | + * Generate dropdown filter select input for messengers |
|
201 | + * |
|
202 | + * @param bool $global |
|
203 | + * @return string |
|
204 | + * @throws EE_Error |
|
205 | + */ |
|
206 | + protected function _get_messengers_dropdown_filter($global = true) |
|
207 | + { |
|
208 | + $messenger_options = array(); |
|
209 | + $active_message_template_groups_grouped_by_messenger = EEM_Message_Template_Group::instance()->get_all( |
|
210 | + array( |
|
211 | + array( |
|
212 | + 'MTP_is_active' => true, |
|
213 | + 'MTP_is_global' => $global, |
|
214 | + ), |
|
215 | + 'group_by' => 'MTP_messenger', |
|
216 | + ) |
|
217 | + ); |
|
218 | + |
|
219 | + foreach ($active_message_template_groups_grouped_by_messenger as $active_message_template_group) { |
|
220 | + if ($active_message_template_group instanceof EE_Message_Template_Group) { |
|
221 | + $messenger = $active_message_template_group->messenger_obj(); |
|
222 | + $messenger_label = $messenger instanceof EE_messenger |
|
223 | + ? $messenger->label['singular'] |
|
224 | + : $active_message_template_group->messenger(); |
|
225 | + $messenger_options[$active_message_template_group->messenger()] = ucwords($messenger_label); |
|
226 | + } |
|
227 | + } |
|
228 | + return $this->get_admin_page()->get_messengers_select_input($messenger_options); |
|
229 | + } |
|
230 | + |
|
231 | + |
|
232 | + /** |
|
233 | + * Generate dropdown filter select input for message types |
|
234 | + * |
|
235 | + * @param bool $global |
|
236 | + * @return string |
|
237 | + * @throws EE_Error |
|
238 | + */ |
|
239 | + protected function _get_message_types_dropdown_filter($global = true) |
|
240 | + { |
|
241 | + $message_type_options = array(); |
|
242 | + $active_message_template_groups_grouped_by_message_type = EEM_Message_Template_Group::instance()->get_all( |
|
243 | + array( |
|
244 | + array( |
|
245 | + 'MTP_is_active' => true, |
|
246 | + 'MTP_is_global' => true, |
|
247 | + ), |
|
248 | + 'group_by' => 'MTP_message_type', |
|
249 | + ) |
|
250 | + ); |
|
251 | + |
|
252 | + foreach ($active_message_template_groups_grouped_by_message_type as $active_message_template_group) { |
|
253 | + if ($active_message_template_group instanceof EE_Message_Template_Group) { |
|
254 | + $message_type = $active_message_template_group->message_type_obj(); |
|
255 | + $message_type_label = $message_type instanceof EE_message_type |
|
256 | + ? $message_type->label['singular'] |
|
257 | + : $active_message_template_group->message_type(); |
|
258 | + $message_type_options[$active_message_template_group->message_type()] = ucwords($message_type_label); |
|
259 | + } |
|
260 | + } |
|
261 | + return $this->get_admin_page()->get_message_types_select_input($message_type_options); |
|
262 | + } |
|
263 | + |
|
264 | + |
|
265 | + /** |
|
266 | + * Return the edit url for the message template group. |
|
267 | + * @param EE_Message_Template_Group $item |
|
268 | + * @return string |
|
269 | + * @throws EE_Error |
|
270 | + */ |
|
271 | + protected function _get_edit_url(EE_Message_Template_Group $item) |
|
272 | + { |
|
273 | + $edit_url = ''; |
|
274 | + // edit link but only if item isn't trashed. |
|
275 | + if (! $item->get('MTP_deleted') |
|
276 | + && EE_Registry::instance()->CAP->current_user_can( |
|
277 | + 'ee_edit_message', |
|
278 | + 'espresso_messages_edit_message_template', |
|
279 | + $item->ID() |
|
280 | + )) { |
|
281 | + $edit_url = EE_Admin_Page::add_query_args_and_nonce( |
|
282 | + array( |
|
283 | + 'action' => 'edit_message_template', |
|
284 | + 'id' => $item->GRP_ID(), |
|
285 | + ), |
|
286 | + EE_MSG_ADMIN_URL |
|
287 | + ); |
|
288 | + } |
|
289 | + return $edit_url; |
|
290 | + } |
|
291 | + |
|
292 | + |
|
293 | + /** |
|
294 | + * Get the context link string for the messenger column. |
|
295 | + * @param EE_Message_Template_Group $item |
|
296 | + * @return string |
|
297 | + * @throws EE_Error |
|
298 | + */ |
|
299 | + protected function _get_context_links(EE_Message_Template_Group $item) |
|
300 | + { |
|
301 | + //first check if we even show the context links or not. |
|
302 | + if (! EE_Registry::instance()->CAP->current_user_can( |
|
303 | + 'ee_edit_message', |
|
304 | + 'espresso_messages_edit_message_template', |
|
305 | + $item->ID() |
|
306 | + ) |
|
307 | + || $item->get('MTP_deleted') |
|
308 | + ) { |
|
309 | + return ''; |
|
310 | + } |
|
311 | + //we want to display the contexts in here so we need to set them up |
|
312 | + $c_label = $item->context_label(); |
|
313 | + $c_configs = $item->contexts_config(); |
|
314 | + $ctxt = array(); |
|
315 | + $context_templates = $item->context_templates(); |
|
316 | + foreach ($context_templates as $context => $template_fields) { |
|
317 | + $mtp_to = ! empty($context_templates[$context]['to']) |
|
318 | + && $context_templates[$context]['to'] instanceof EE_Message_Template |
|
319 | + ? $context_templates[$context]['to']->get('MTP_content') |
|
320 | + : null; |
|
321 | + $inactive_class = ( |
|
322 | + empty($mtp_to) |
|
323 | + && ! empty($context_templates[$context]['to']) |
|
324 | + ) |
|
325 | + || ! $item->is_context_active($context) |
|
326 | + ? ' mtp-inactive' |
|
327 | + : ''; |
|
328 | + $context_title = ucwords($c_configs[$context]['label']); |
|
329 | + $edit_link = EE_Admin_Page::add_query_args_and_nonce(array( |
|
330 | + 'action' => 'edit_message_template', |
|
331 | + 'id' => $item->GRP_ID(), |
|
332 | + 'context' => $context, |
|
333 | + ), EE_MSG_ADMIN_URL); |
|
334 | + $ctxt[] = '<a' |
|
335 | + . ' href="' . $edit_link . '"' |
|
336 | + . ' class="' . $item->message_type() . '-' . $context . '-edit-link' .$inactive_class . '"' |
|
337 | + . ' title="' . esc_attr__('Edit Context', 'event_espresso') . '">' |
|
338 | + . $context_title |
|
339 | + . '</a>'; |
|
340 | + } |
|
341 | + |
|
342 | + return sprintf('<strong>%s:</strong> ', ucwords($c_label['plural'])) . implode(' | ', $ctxt); |
|
343 | + } |
|
344 | + |
|
345 | + |
|
346 | + /** |
|
347 | + * Get the Name string from the messenger column (linked to edit if the context allows for that). |
|
348 | + * @param EE_Message_Template_Group $item |
|
349 | + * @return string |
|
350 | + * @throws EE_Error |
|
351 | + */ |
|
352 | + protected function _get_name_link_for_messenger(EE_Message_Template_Group $item) |
|
353 | + { |
|
354 | + $edit_url = $this->_get_edit_url($item); |
|
355 | + return $edit_url |
|
356 | + ? '<a href="' . $edit_url . '"' |
|
357 | + . ' title="' . esc_attr__('Edit Template Group', 'event_espresso') . '">' |
|
358 | + . ucwords($item->messenger_obj()->label['singular']) |
|
359 | + . '</a>' |
|
360 | + : ucwords($item->messenger_obj()->label['singular']); |
|
361 | + } |
|
362 | + |
|
363 | + |
|
364 | + /** |
|
365 | + * Return the actions array for the messenger column. |
|
366 | + * @param EE_Message_Template_Group $item |
|
367 | + * @return array |
|
368 | + * @throws EE_Error |
|
369 | + */ |
|
370 | + protected function _get_actions_for_messenger_column(EE_Message_Template_Group $item) |
|
371 | + { |
|
372 | + $actions = array(); |
|
373 | + if ($edit_url = $this->_get_edit_url($item)) { |
|
374 | + $actions = array( |
|
375 | + 'edit' => '<a href="' . $edit_url . '"' |
|
376 | + . ' class="' . $item->message_type() . '-edit-link"' |
|
377 | + . ' title="' . esc_attr__('Edit Template Group', 'event_espresso') . '">' |
|
378 | + . esc_html__('Edit', 'event_espresso') |
|
379 | + . '</a>' |
|
380 | + ); |
|
381 | + } |
|
382 | + return $actions; |
|
383 | + } |
|
384 | 384 | } |
385 | 385 |
@@ -27,7 +27,7 @@ discard block |
||
27 | 27 | */ |
28 | 28 | protected function _setup_data() |
29 | 29 | { |
30 | - $this->_data = $this->get_admin_page()->get_message_templates( |
|
30 | + $this->_data = $this->get_admin_page()->get_message_templates( |
|
31 | 31 | $this->_per_page, |
32 | 32 | $this->_view, |
33 | 33 | false |
@@ -52,7 +52,7 @@ discard block |
||
52 | 52 | 'ajax' => true, //for now, |
53 | 53 | 'screen' => $this->get_admin_page()->get_current_screen()->id, |
54 | 54 | ); |
55 | - $this->_columns = array( |
|
55 | + $this->_columns = array( |
|
56 | 56 | //'cb' => '<input type="checkbox" />', //no deleting default (global) templates! |
57 | 57 | 'message_type' => esc_html__('Message Type', 'event_espresso'), |
58 | 58 | 'messenger' => esc_html__('Messenger', 'event_espresso'), |
@@ -80,7 +80,7 @@ discard block |
||
80 | 80 | $message_type = $item->message_type_obj(); |
81 | 81 | $messenger = $item->messenger_obj(); |
82 | 82 | |
83 | - if (! $message_type instanceof EE_message_type || ! $messenger instanceof EE_messenger) { |
|
83 | + if ( ! $message_type instanceof EE_message_type || ! $messenger instanceof EE_messenger) { |
|
84 | 84 | echo ''; |
85 | 85 | return; |
86 | 86 | } |
@@ -158,7 +158,7 @@ discard block |
||
158 | 158 | */ |
159 | 159 | public function column_description($item) |
160 | 160 | { |
161 | - return '<p>' . $item->message_type_obj()->description . '</p>'; |
|
161 | + return '<p>'.$item->message_type_obj()->description.'</p>'; |
|
162 | 162 | } |
163 | 163 | |
164 | 164 | |
@@ -272,7 +272,7 @@ discard block |
||
272 | 272 | { |
273 | 273 | $edit_url = ''; |
274 | 274 | // edit link but only if item isn't trashed. |
275 | - if (! $item->get('MTP_deleted') |
|
275 | + if ( ! $item->get('MTP_deleted') |
|
276 | 276 | && EE_Registry::instance()->CAP->current_user_can( |
277 | 277 | 'ee_edit_message', |
278 | 278 | 'espresso_messages_edit_message_template', |
@@ -299,7 +299,7 @@ discard block |
||
299 | 299 | protected function _get_context_links(EE_Message_Template_Group $item) |
300 | 300 | { |
301 | 301 | //first check if we even show the context links or not. |
302 | - if (! EE_Registry::instance()->CAP->current_user_can( |
|
302 | + if ( ! EE_Registry::instance()->CAP->current_user_can( |
|
303 | 303 | 'ee_edit_message', |
304 | 304 | 'espresso_messages_edit_message_template', |
305 | 305 | $item->ID() |
@@ -318,7 +318,7 @@ discard block |
||
318 | 318 | && $context_templates[$context]['to'] instanceof EE_Message_Template |
319 | 319 | ? $context_templates[$context]['to']->get('MTP_content') |
320 | 320 | : null; |
321 | - $inactive_class = ( |
|
321 | + $inactive_class = ( |
|
322 | 322 | empty($mtp_to) |
323 | 323 | && ! empty($context_templates[$context]['to']) |
324 | 324 | ) |
@@ -331,15 +331,15 @@ discard block |
||
331 | 331 | 'id' => $item->GRP_ID(), |
332 | 332 | 'context' => $context, |
333 | 333 | ), EE_MSG_ADMIN_URL); |
334 | - $ctxt[] = '<a' |
|
335 | - . ' href="' . $edit_link . '"' |
|
336 | - . ' class="' . $item->message_type() . '-' . $context . '-edit-link' .$inactive_class . '"' |
|
337 | - . ' title="' . esc_attr__('Edit Context', 'event_espresso') . '">' |
|
334 | + $ctxt[] = '<a' |
|
335 | + . ' href="'.$edit_link.'"' |
|
336 | + . ' class="'.$item->message_type().'-'.$context.'-edit-link'.$inactive_class.'"' |
|
337 | + . ' title="'.esc_attr__('Edit Context', 'event_espresso').'">' |
|
338 | 338 | . $context_title |
339 | 339 | . '</a>'; |
340 | 340 | } |
341 | 341 | |
342 | - return sprintf('<strong>%s:</strong> ', ucwords($c_label['plural'])) . implode(' | ', $ctxt); |
|
342 | + return sprintf('<strong>%s:</strong> ', ucwords($c_label['plural'])).implode(' | ', $ctxt); |
|
343 | 343 | } |
344 | 344 | |
345 | 345 | |
@@ -353,8 +353,8 @@ discard block |
||
353 | 353 | { |
354 | 354 | $edit_url = $this->_get_edit_url($item); |
355 | 355 | return $edit_url |
356 | - ? '<a href="' . $edit_url . '"' |
|
357 | - . ' title="' . esc_attr__('Edit Template Group', 'event_espresso') . '">' |
|
356 | + ? '<a href="'.$edit_url.'"' |
|
357 | + . ' title="'.esc_attr__('Edit Template Group', 'event_espresso').'">' |
|
358 | 358 | . ucwords($item->messenger_obj()->label['singular']) |
359 | 359 | . '</a>' |
360 | 360 | : ucwords($item->messenger_obj()->label['singular']); |
@@ -372,9 +372,9 @@ discard block |
||
372 | 372 | $actions = array(); |
373 | 373 | if ($edit_url = $this->_get_edit_url($item)) { |
374 | 374 | $actions = array( |
375 | - 'edit' => '<a href="' . $edit_url . '"' |
|
376 | - . ' class="' . $item->message_type() . '-edit-link"' |
|
377 | - . ' title="' . esc_attr__('Edit Template Group', 'event_espresso') . '">' |
|
375 | + 'edit' => '<a href="'.$edit_url.'"' |
|
376 | + . ' class="'.$item->message_type().'-edit-link"' |
|
377 | + . ' title="'.esc_attr__('Edit Template Group', 'event_espresso').'">' |
|
378 | 378 | . esc_html__('Edit', 'event_espresso') |
379 | 379 | . '</a>' |
380 | 380 | ); |
@@ -14,286 +14,286 @@ |
||
14 | 14 | class MessagesAdmin extends CoreAdmin |
15 | 15 | { |
16 | 16 | |
17 | - /** |
|
18 | - * Context slug for the admin messages context. |
|
19 | - * @var string |
|
20 | - */ |
|
21 | - const ADMIN_CONTEXT_SLUG = 'admin'; |
|
17 | + /** |
|
18 | + * Context slug for the admin messages context. |
|
19 | + * @var string |
|
20 | + */ |
|
21 | + const ADMIN_CONTEXT_SLUG = 'admin'; |
|
22 | 22 | |
23 | - /** |
|
24 | - * Context slug for the primary attendee messages context |
|
25 | - * @var string |
|
26 | - */ |
|
27 | - const PRIMARY_ATTENDEE_CONTEXT_SLUG = 'primary_attendee'; |
|
23 | + /** |
|
24 | + * Context slug for the primary attendee messages context |
|
25 | + * @var string |
|
26 | + */ |
|
27 | + const PRIMARY_ATTENDEE_CONTEXT_SLUG = 'primary_attendee'; |
|
28 | 28 | |
29 | 29 | |
30 | - /** |
|
31 | - * Status reference for the EEM_Message::status_sent status. |
|
32 | - * @var string |
|
33 | - */ |
|
34 | - const MESSAGE_STATUS_SENT = 'MSN'; |
|
30 | + /** |
|
31 | + * Status reference for the EEM_Message::status_sent status. |
|
32 | + * @var string |
|
33 | + */ |
|
34 | + const MESSAGE_STATUS_SENT = 'MSN'; |
|
35 | 35 | |
36 | 36 | |
37 | - /** |
|
38 | - * Message type slug for the Payment Failed message type |
|
39 | - */ |
|
40 | - const PAYMENT_FAILED_MESSAGE_TYPE_SLUG = 'payment_failed'; |
|
37 | + /** |
|
38 | + * Message type slug for the Payment Failed message type |
|
39 | + */ |
|
40 | + const PAYMENT_FAILED_MESSAGE_TYPE_SLUG = 'payment_failed'; |
|
41 | 41 | |
42 | 42 | |
43 | - /** |
|
44 | - * Selector for the Global Messages "Send on same request" field in the Messages Settings tab. |
|
45 | - * @var string |
|
46 | - */ |
|
47 | - const GLOBAL_MESSAGES_SETTINGS_ON_REQUEST_SELECTION_SELECTOR = |
|
48 | - '#global_messages_settings-do-messages-on-same-request'; |
|
43 | + /** |
|
44 | + * Selector for the Global Messages "Send on same request" field in the Messages Settings tab. |
|
45 | + * @var string |
|
46 | + */ |
|
47 | + const GLOBAL_MESSAGES_SETTINGS_ON_REQUEST_SELECTION_SELECTOR = |
|
48 | + '#global_messages_settings-do-messages-on-same-request'; |
|
49 | 49 | |
50 | 50 | |
51 | - /** |
|
52 | - * Selector for the Global Messages Settings submit button in the Messages Settings tab. |
|
53 | - * @var string |
|
54 | - */ |
|
55 | - const GLOBAL_MESSAGES_SETTINGS_SUBMIT_SELECTOR = '#global_messages_settings-update-settings-submit'; |
|
56 | - |
|
51 | + /** |
|
52 | + * Selector for the Global Messages Settings submit button in the Messages Settings tab. |
|
53 | + * @var string |
|
54 | + */ |
|
55 | + const GLOBAL_MESSAGES_SETTINGS_SUBMIT_SELECTOR = '#global_messages_settings-update-settings-submit'; |
|
56 | + |
|
57 | 57 | |
58 | - /** |
|
59 | - * This is the container where active message types for a messenger are found/dragged to. |
|
60 | - * @var string |
|
61 | - */ |
|
62 | - const MESSAGES_SETTINGS_ACTIVE_MESSAGE_TYPES_CONTAINER_SELECTOR = '#active-message-types'; |
|
63 | - |
|
64 | - |
|
65 | - /** |
|
66 | - * Locator for the context switcher selector on the Message Template Editor page. |
|
67 | - * @var string |
|
68 | - */ |
|
69 | - const MESSAGES_CONTEXT_SWITCHER_SELECTOR = "//form[@id='ee-msg-context-switcher-frm']/select"; |
|
70 | - |
|
71 | - |
|
72 | - /** |
|
73 | - * Locator for the context switcher submit button in the Message Template Editor page. |
|
74 | - * @var string |
|
75 | - */ |
|
76 | - const MESSAGES_CONTEXT_SWITCHER_BUTTON_SELECTOR = "#submit-msg-context-switcher-sbmt"; |
|
77 | - |
|
78 | - |
|
79 | - /** |
|
80 | - * Locator for the dialog container used for housing viewed messages in the message activity list table. |
|
81 | - * @var string |
|
82 | - */ |
|
83 | - const MESSAGES_LIST_TABLE_VIEW_MESSAGE_DIALOG_CONTAINER_SELECTOR = '.ee-admin-dialog-container-inner-content'; |
|
84 | - |
|
85 | - |
|
86 | - /** |
|
87 | - * Returns the selector for the on/off toggle for context on the message template editor. |
|
88 | - */ |
|
89 | - const MESSAGES_CONTEXT_ACTIVE_STATE_TOGGLE = |
|
90 | - "//div[@class='activate_context_on_off_toggle_container']/div[@class='switch']/label"; |
|
91 | - |
|
92 | - |
|
93 | - |
|
94 | - /** |
|
95 | - * @param string $additional_params Any additional request parameters for the generated url should be included as |
|
96 | - * a string. |
|
97 | - * @return string |
|
98 | - */ |
|
99 | - public static function messageActivityListTableUrl($additional_params = '') |
|
100 | - { |
|
101 | - return self::adminUrl('espresso_messages', 'default', $additional_params); |
|
102 | - } |
|
103 | - |
|
104 | - |
|
105 | - /** |
|
106 | - * @param string $additional_params Any additional request parameters for the generated url should be included as |
|
107 | - * a string. |
|
108 | - * @return string |
|
109 | - */ |
|
110 | - public static function defaultMessageTemplateListTableUrl($additional_params = '') |
|
111 | - { |
|
112 | - return self::adminUrl('espresso_messages', 'global_mtps', $additional_params); |
|
113 | - } |
|
114 | - |
|
115 | - |
|
116 | - /** |
|
117 | - * @param string $additional_params Any additional request parameters for the generated url should be included as |
|
118 | - * a string. |
|
119 | - * @return string |
|
120 | - */ |
|
121 | - public static function customMessageTemplateListTableUrl($additional_params = '') |
|
122 | - { |
|
123 | - return self::adminUrl('espresso_messages', 'custom_mtps', $additional_params); |
|
124 | - } |
|
125 | - |
|
126 | - |
|
127 | - /** |
|
128 | - * @return string |
|
129 | - */ |
|
130 | - public static function messageSettingsUrl() |
|
131 | - { |
|
132 | - return self::adminUrl('espresso_messages', 'settings'); |
|
133 | - } |
|
134 | - |
|
135 | - |
|
136 | - |
|
137 | - public static function draggableSettingsBoxSelectorForMessageTypeAndMessenger( |
|
138 | - $message_type_slug, |
|
139 | - $messenger_slug = 'email' |
|
140 | - ) { |
|
141 | - return "#$message_type_slug-messagetype-$messenger_slug"; |
|
142 | - } |
|
143 | - |
|
144 | - |
|
145 | - /** |
|
146 | - * @param string $message_type_slug |
|
147 | - * @param string $context |
|
148 | - * @return string |
|
149 | - */ |
|
150 | - public static function editMessageTemplateClassByMessageType($message_type_slug, $context = '') |
|
151 | - { |
|
152 | - return $context |
|
153 | - ? '.' . $message_type_slug . '-' . $context . '-edit-link' |
|
154 | - : '.' . $message_type_slug . '-edit-link'; |
|
155 | - } |
|
156 | - |
|
157 | - |
|
158 | - /** |
|
159 | - * Selector for (a) specific table cell(s) in the Messages Activity list table for the given parameters. |
|
160 | - * |
|
161 | - * @param $field |
|
162 | - * @param $message_type_label |
|
163 | - * @param string $message_status |
|
164 | - * @param string $messenger |
|
165 | - * @param string $context |
|
166 | - * @param string $table_cell_content_for_field |
|
167 | - * @param int $number_in_set It's possible that the given parameters could match multiple items in the view. |
|
168 | - * This allows you to indicate which item from the set to match. If this is set to 0 |
|
169 | - * then all matches for the locator will be returned. |
|
170 | - * @return string |
|
171 | - * @throws \InvalidArgumentException |
|
172 | - */ |
|
173 | - public static function messagesActivityListTableCellSelectorFor( |
|
174 | - $field, |
|
175 | - $message_type_label, |
|
176 | - $message_status = self::MESSAGE_STATUS_SENT, |
|
177 | - $messenger = 'Email', |
|
178 | - $context = 'Event Admin', |
|
179 | - $table_cell_content_for_field = '', |
|
180 | - $number_in_set = 1 |
|
181 | - ) { |
|
182 | - $selector = "//tbody[@id='the-list']"; |
|
183 | - $selector .= "//tr[contains(@class, 'msg-status-$message_status')]" |
|
184 | - . "//td[contains(@class, 'message_type') and text()='$message_type_label']"; |
|
185 | - if ($messenger) { |
|
186 | - $selector .= "/ancestor::tr/td[contains(@class, 'messenger') and text()='$messenger']"; |
|
187 | - } |
|
188 | - $selector .= "/ancestor::tr/td[contains(@class, 'column-context') and text()='$context']"; |
|
189 | - $selector .= $table_cell_content_for_field |
|
190 | - ? "/ancestor::tr/td[contains(@class, 'column-$field') and text()='$table_cell_content_for_field']" |
|
191 | - : "/ancestor::tr/td[contains(@class, 'column-$field')]"; |
|
192 | - return $number_in_set > 0 ? Locator::elementAt($selector, $number_in_set) : $selector; |
|
193 | - } |
|
194 | - |
|
195 | - |
|
196 | - /** |
|
197 | - * Selector for the Create Custom button found in the message template list table. |
|
198 | - * @param string $message_type_label |
|
199 | - * @param string $messenger_label |
|
200 | - * @return string |
|
201 | - */ |
|
202 | - public static function createCustomButtonForMessageTypeAndMessenger($message_type_label, $messenger_label) |
|
203 | - { |
|
204 | - $selector = "//tr/td[contains(@class, 'message_type') and text()='$message_type_label']" |
|
205 | - . "//ancestor::tr/td[contains(@class, 'messenger') and contains(., '$messenger_label')]" |
|
206 | - . "//ancestor::tr/td/a[@class='button button-small']"; |
|
207 | - return $selector; |
|
208 | - } |
|
209 | - |
|
210 | - |
|
211 | - /** |
|
212 | - * Note, this could potentially match multiple buttons in the view so the selector is intentionally restricted to |
|
213 | - * the FIRST match (which will be the latest message sent if the table is default sorted). |
|
214 | - * |
|
215 | - * @param string $message_type_label The visible message type label for the row you want to match |
|
216 | - * @param string $message_status The status of the message for the row you want to match. |
|
217 | - * @param string $messenger The visible messenger label for the row you want to match. |
|
218 | - * @param string $context The visible context label for the row you want to match. |
|
219 | - * @param int $number_in_set It's possible that the given parameters could match multiple items in the |
|
220 | - * view. This allows you to indicate which item from the set to match. |
|
221 | - * @return string |
|
222 | - * @throws \InvalidArgumentException |
|
223 | - */ |
|
224 | - public static function messagesActivityListTableViewButtonSelectorFor( |
|
225 | - $message_type_label, |
|
226 | - $message_status = self::MESSAGE_STATUS_SENT, |
|
227 | - $messenger = 'Email', |
|
228 | - $context = 'Event Admin', |
|
229 | - $number_in_set = 1 |
|
230 | - ) { |
|
231 | - $selector = self::messagesActivityListTableCellSelectorFor( |
|
232 | - 'action', |
|
233 | - $message_type_label, |
|
234 | - $message_status, |
|
235 | - $messenger, |
|
236 | - $context, |
|
237 | - '', |
|
238 | - $number_in_set |
|
239 | - ); |
|
240 | - $selector .= "/a/span[contains(@class, 'ee-message-action-link-view')" |
|
241 | - . " and not(contains(@class, 'ee-message-action-link-view_transaction'))]"; |
|
242 | - return $selector; |
|
243 | - } |
|
244 | - |
|
245 | - |
|
246 | - /** |
|
247 | - * Locator for the delete action link for a message item in the message activity list table. |
|
248 | - * Note: The link is not visible by default, so the column would need hovered over for the link to appear. |
|
249 | - * |
|
250 | - * @param $message_type_label |
|
251 | - * @param string $message_status |
|
252 | - * @param string $messenger |
|
253 | - * @param string $context |
|
254 | - * @param int $number_in_set |
|
255 | - * @return string |
|
256 | - * @throws \InvalidArgumentException |
|
257 | - */ |
|
258 | - public static function messagesActivityListTableDeleteActionSelectorFor( |
|
259 | - $message_type_label, |
|
260 | - $message_status = self::MESSAGE_STATUS_SENT, |
|
261 | - $messenger = 'Email', |
|
262 | - $context = 'Event Admin', |
|
263 | - $number_in_set = 1 |
|
264 | - ) { |
|
265 | - $selector = self::messagesActivityListTableCellSelectorFor( |
|
266 | - 'to', |
|
267 | - $message_type_label, |
|
268 | - $message_status, |
|
269 | - $messenger, |
|
270 | - $context, |
|
271 | - '', |
|
272 | - $number_in_set |
|
273 | - ); |
|
274 | - $selector .= "/div/span[@class='delete']/a"; |
|
275 | - return $selector; |
|
276 | - } |
|
277 | - |
|
278 | - |
|
279 | - |
|
280 | - /** |
|
281 | - * Returns the input selector for a given field in the message template editor. |
|
282 | - * Assumes one is already viewing the Message Template Editor. |
|
283 | - * @param string $field |
|
284 | - * @return string |
|
285 | - */ |
|
286 | - public static function messageInputFieldSelectorFor($field) |
|
287 | - { |
|
288 | - return "//div[@id='post-body']//input[@id='$field-content']"; |
|
289 | - } |
|
290 | - |
|
291 | - |
|
292 | - /** |
|
293 | - * Wrapper for self::messageInputFieldSelectorFor('to') that takes care of getting the input for the To field. |
|
294 | - */ |
|
295 | - public static function messageTemplateToFieldSelector() |
|
296 | - { |
|
297 | - return self::messageInputFieldSelectorFor('to'); |
|
298 | - } |
|
58 | + /** |
|
59 | + * This is the container where active message types for a messenger are found/dragged to. |
|
60 | + * @var string |
|
61 | + */ |
|
62 | + const MESSAGES_SETTINGS_ACTIVE_MESSAGE_TYPES_CONTAINER_SELECTOR = '#active-message-types'; |
|
63 | + |
|
64 | + |
|
65 | + /** |
|
66 | + * Locator for the context switcher selector on the Message Template Editor page. |
|
67 | + * @var string |
|
68 | + */ |
|
69 | + const MESSAGES_CONTEXT_SWITCHER_SELECTOR = "//form[@id='ee-msg-context-switcher-frm']/select"; |
|
70 | + |
|
71 | + |
|
72 | + /** |
|
73 | + * Locator for the context switcher submit button in the Message Template Editor page. |
|
74 | + * @var string |
|
75 | + */ |
|
76 | + const MESSAGES_CONTEXT_SWITCHER_BUTTON_SELECTOR = "#submit-msg-context-switcher-sbmt"; |
|
77 | + |
|
78 | + |
|
79 | + /** |
|
80 | + * Locator for the dialog container used for housing viewed messages in the message activity list table. |
|
81 | + * @var string |
|
82 | + */ |
|
83 | + const MESSAGES_LIST_TABLE_VIEW_MESSAGE_DIALOG_CONTAINER_SELECTOR = '.ee-admin-dialog-container-inner-content'; |
|
84 | + |
|
85 | + |
|
86 | + /** |
|
87 | + * Returns the selector for the on/off toggle for context on the message template editor. |
|
88 | + */ |
|
89 | + const MESSAGES_CONTEXT_ACTIVE_STATE_TOGGLE = |
|
90 | + "//div[@class='activate_context_on_off_toggle_container']/div[@class='switch']/label"; |
|
91 | + |
|
92 | + |
|
93 | + |
|
94 | + /** |
|
95 | + * @param string $additional_params Any additional request parameters for the generated url should be included as |
|
96 | + * a string. |
|
97 | + * @return string |
|
98 | + */ |
|
99 | + public static function messageActivityListTableUrl($additional_params = '') |
|
100 | + { |
|
101 | + return self::adminUrl('espresso_messages', 'default', $additional_params); |
|
102 | + } |
|
103 | + |
|
104 | + |
|
105 | + /** |
|
106 | + * @param string $additional_params Any additional request parameters for the generated url should be included as |
|
107 | + * a string. |
|
108 | + * @return string |
|
109 | + */ |
|
110 | + public static function defaultMessageTemplateListTableUrl($additional_params = '') |
|
111 | + { |
|
112 | + return self::adminUrl('espresso_messages', 'global_mtps', $additional_params); |
|
113 | + } |
|
114 | + |
|
115 | + |
|
116 | + /** |
|
117 | + * @param string $additional_params Any additional request parameters for the generated url should be included as |
|
118 | + * a string. |
|
119 | + * @return string |
|
120 | + */ |
|
121 | + public static function customMessageTemplateListTableUrl($additional_params = '') |
|
122 | + { |
|
123 | + return self::adminUrl('espresso_messages', 'custom_mtps', $additional_params); |
|
124 | + } |
|
125 | + |
|
126 | + |
|
127 | + /** |
|
128 | + * @return string |
|
129 | + */ |
|
130 | + public static function messageSettingsUrl() |
|
131 | + { |
|
132 | + return self::adminUrl('espresso_messages', 'settings'); |
|
133 | + } |
|
134 | + |
|
135 | + |
|
136 | + |
|
137 | + public static function draggableSettingsBoxSelectorForMessageTypeAndMessenger( |
|
138 | + $message_type_slug, |
|
139 | + $messenger_slug = 'email' |
|
140 | + ) { |
|
141 | + return "#$message_type_slug-messagetype-$messenger_slug"; |
|
142 | + } |
|
143 | + |
|
144 | + |
|
145 | + /** |
|
146 | + * @param string $message_type_slug |
|
147 | + * @param string $context |
|
148 | + * @return string |
|
149 | + */ |
|
150 | + public static function editMessageTemplateClassByMessageType($message_type_slug, $context = '') |
|
151 | + { |
|
152 | + return $context |
|
153 | + ? '.' . $message_type_slug . '-' . $context . '-edit-link' |
|
154 | + : '.' . $message_type_slug . '-edit-link'; |
|
155 | + } |
|
156 | + |
|
157 | + |
|
158 | + /** |
|
159 | + * Selector for (a) specific table cell(s) in the Messages Activity list table for the given parameters. |
|
160 | + * |
|
161 | + * @param $field |
|
162 | + * @param $message_type_label |
|
163 | + * @param string $message_status |
|
164 | + * @param string $messenger |
|
165 | + * @param string $context |
|
166 | + * @param string $table_cell_content_for_field |
|
167 | + * @param int $number_in_set It's possible that the given parameters could match multiple items in the view. |
|
168 | + * This allows you to indicate which item from the set to match. If this is set to 0 |
|
169 | + * then all matches for the locator will be returned. |
|
170 | + * @return string |
|
171 | + * @throws \InvalidArgumentException |
|
172 | + */ |
|
173 | + public static function messagesActivityListTableCellSelectorFor( |
|
174 | + $field, |
|
175 | + $message_type_label, |
|
176 | + $message_status = self::MESSAGE_STATUS_SENT, |
|
177 | + $messenger = 'Email', |
|
178 | + $context = 'Event Admin', |
|
179 | + $table_cell_content_for_field = '', |
|
180 | + $number_in_set = 1 |
|
181 | + ) { |
|
182 | + $selector = "//tbody[@id='the-list']"; |
|
183 | + $selector .= "//tr[contains(@class, 'msg-status-$message_status')]" |
|
184 | + . "//td[contains(@class, 'message_type') and text()='$message_type_label']"; |
|
185 | + if ($messenger) { |
|
186 | + $selector .= "/ancestor::tr/td[contains(@class, 'messenger') and text()='$messenger']"; |
|
187 | + } |
|
188 | + $selector .= "/ancestor::tr/td[contains(@class, 'column-context') and text()='$context']"; |
|
189 | + $selector .= $table_cell_content_for_field |
|
190 | + ? "/ancestor::tr/td[contains(@class, 'column-$field') and text()='$table_cell_content_for_field']" |
|
191 | + : "/ancestor::tr/td[contains(@class, 'column-$field')]"; |
|
192 | + return $number_in_set > 0 ? Locator::elementAt($selector, $number_in_set) : $selector; |
|
193 | + } |
|
194 | + |
|
195 | + |
|
196 | + /** |
|
197 | + * Selector for the Create Custom button found in the message template list table. |
|
198 | + * @param string $message_type_label |
|
199 | + * @param string $messenger_label |
|
200 | + * @return string |
|
201 | + */ |
|
202 | + public static function createCustomButtonForMessageTypeAndMessenger($message_type_label, $messenger_label) |
|
203 | + { |
|
204 | + $selector = "//tr/td[contains(@class, 'message_type') and text()='$message_type_label']" |
|
205 | + . "//ancestor::tr/td[contains(@class, 'messenger') and contains(., '$messenger_label')]" |
|
206 | + . "//ancestor::tr/td/a[@class='button button-small']"; |
|
207 | + return $selector; |
|
208 | + } |
|
209 | + |
|
210 | + |
|
211 | + /** |
|
212 | + * Note, this could potentially match multiple buttons in the view so the selector is intentionally restricted to |
|
213 | + * the FIRST match (which will be the latest message sent if the table is default sorted). |
|
214 | + * |
|
215 | + * @param string $message_type_label The visible message type label for the row you want to match |
|
216 | + * @param string $message_status The status of the message for the row you want to match. |
|
217 | + * @param string $messenger The visible messenger label for the row you want to match. |
|
218 | + * @param string $context The visible context label for the row you want to match. |
|
219 | + * @param int $number_in_set It's possible that the given parameters could match multiple items in the |
|
220 | + * view. This allows you to indicate which item from the set to match. |
|
221 | + * @return string |
|
222 | + * @throws \InvalidArgumentException |
|
223 | + */ |
|
224 | + public static function messagesActivityListTableViewButtonSelectorFor( |
|
225 | + $message_type_label, |
|
226 | + $message_status = self::MESSAGE_STATUS_SENT, |
|
227 | + $messenger = 'Email', |
|
228 | + $context = 'Event Admin', |
|
229 | + $number_in_set = 1 |
|
230 | + ) { |
|
231 | + $selector = self::messagesActivityListTableCellSelectorFor( |
|
232 | + 'action', |
|
233 | + $message_type_label, |
|
234 | + $message_status, |
|
235 | + $messenger, |
|
236 | + $context, |
|
237 | + '', |
|
238 | + $number_in_set |
|
239 | + ); |
|
240 | + $selector .= "/a/span[contains(@class, 'ee-message-action-link-view')" |
|
241 | + . " and not(contains(@class, 'ee-message-action-link-view_transaction'))]"; |
|
242 | + return $selector; |
|
243 | + } |
|
244 | + |
|
245 | + |
|
246 | + /** |
|
247 | + * Locator for the delete action link for a message item in the message activity list table. |
|
248 | + * Note: The link is not visible by default, so the column would need hovered over for the link to appear. |
|
249 | + * |
|
250 | + * @param $message_type_label |
|
251 | + * @param string $message_status |
|
252 | + * @param string $messenger |
|
253 | + * @param string $context |
|
254 | + * @param int $number_in_set |
|
255 | + * @return string |
|
256 | + * @throws \InvalidArgumentException |
|
257 | + */ |
|
258 | + public static function messagesActivityListTableDeleteActionSelectorFor( |
|
259 | + $message_type_label, |
|
260 | + $message_status = self::MESSAGE_STATUS_SENT, |
|
261 | + $messenger = 'Email', |
|
262 | + $context = 'Event Admin', |
|
263 | + $number_in_set = 1 |
|
264 | + ) { |
|
265 | + $selector = self::messagesActivityListTableCellSelectorFor( |
|
266 | + 'to', |
|
267 | + $message_type_label, |
|
268 | + $message_status, |
|
269 | + $messenger, |
|
270 | + $context, |
|
271 | + '', |
|
272 | + $number_in_set |
|
273 | + ); |
|
274 | + $selector .= "/div/span[@class='delete']/a"; |
|
275 | + return $selector; |
|
276 | + } |
|
277 | + |
|
278 | + |
|
279 | + |
|
280 | + /** |
|
281 | + * Returns the input selector for a given field in the message template editor. |
|
282 | + * Assumes one is already viewing the Message Template Editor. |
|
283 | + * @param string $field |
|
284 | + * @return string |
|
285 | + */ |
|
286 | + public static function messageInputFieldSelectorFor($field) |
|
287 | + { |
|
288 | + return "//div[@id='post-body']//input[@id='$field-content']"; |
|
289 | + } |
|
290 | + |
|
291 | + |
|
292 | + /** |
|
293 | + * Wrapper for self::messageInputFieldSelectorFor('to') that takes care of getting the input for the To field. |
|
294 | + */ |
|
295 | + public static function messageTemplateToFieldSelector() |
|
296 | + { |
|
297 | + return self::messageInputFieldSelectorFor('to'); |
|
298 | + } |
|
299 | 299 | } |
300 | 300 | \ No newline at end of file |
@@ -10,276 +10,276 @@ |
||
10 | 10 | */ |
11 | 11 | trait MessagesAdmin |
12 | 12 | { |
13 | - /** |
|
14 | - * @param string $additional_params Any additional request parameters for the generated url should be included as |
|
15 | - * a string. |
|
16 | - */ |
|
17 | - public function amOnMessagesActivityListTablePage($additional_params = '') |
|
18 | - { |
|
19 | - $this->actor()->amOnAdminPage(MessagesPage::messageActivityListTableUrl($additional_params)); |
|
20 | - } |
|
13 | + /** |
|
14 | + * @param string $additional_params Any additional request parameters for the generated url should be included as |
|
15 | + * a string. |
|
16 | + */ |
|
17 | + public function amOnMessagesActivityListTablePage($additional_params = '') |
|
18 | + { |
|
19 | + $this->actor()->amOnAdminPage(MessagesPage::messageActivityListTableUrl($additional_params)); |
|
20 | + } |
|
21 | 21 | |
22 | - /** |
|
23 | - * @param string $additional_params Any additional request parameters for the generated url should be included as |
|
24 | - * a string. |
|
25 | - */ |
|
26 | - public function amOnDefaultMessageTemplateListTablePage($additional_params = '') |
|
27 | - { |
|
28 | - $this->actor()->amOnAdminPage(MessagesPage::defaultMessageTemplateListTableUrl($additional_params)); |
|
29 | - } |
|
22 | + /** |
|
23 | + * @param string $additional_params Any additional request parameters for the generated url should be included as |
|
24 | + * a string. |
|
25 | + */ |
|
26 | + public function amOnDefaultMessageTemplateListTablePage($additional_params = '') |
|
27 | + { |
|
28 | + $this->actor()->amOnAdminPage(MessagesPage::defaultMessageTemplateListTableUrl($additional_params)); |
|
29 | + } |
|
30 | 30 | |
31 | 31 | |
32 | - /** |
|
33 | - * @param string $additional_params Any additional request parameters for the generated url should be included as |
|
34 | - * a string. |
|
35 | - */ |
|
36 | - public function amOnCustomMessageTemplateListTablePage($additional_params = '') |
|
37 | - { |
|
38 | - $this->actor()->amOnAdminPage(MessagesPage::customMessageTemplateListTableUrl($additional_params)); |
|
39 | - } |
|
32 | + /** |
|
33 | + * @param string $additional_params Any additional request parameters for the generated url should be included as |
|
34 | + * a string. |
|
35 | + */ |
|
36 | + public function amOnCustomMessageTemplateListTablePage($additional_params = '') |
|
37 | + { |
|
38 | + $this->actor()->amOnAdminPage(MessagesPage::customMessageTemplateListTableUrl($additional_params)); |
|
39 | + } |
|
40 | 40 | |
41 | 41 | |
42 | - /** |
|
43 | - * Directs to message settings page |
|
44 | - */ |
|
45 | - public function amOnMessageSettingsPage() |
|
46 | - { |
|
47 | - $this->actor()->amOnAdminPage(MessagesPage::messageSettingsUrl()); |
|
48 | - } |
|
42 | + /** |
|
43 | + * Directs to message settings page |
|
44 | + */ |
|
45 | + public function amOnMessageSettingsPage() |
|
46 | + { |
|
47 | + $this->actor()->amOnAdminPage(MessagesPage::messageSettingsUrl()); |
|
48 | + } |
|
49 | 49 | |
50 | 50 | |
51 | - public function activateMessageTypeForMessenger($message_type_slug, $messenger_slug = 'email') |
|
52 | - { |
|
53 | - $this->actor()->dragAndDrop( |
|
54 | - MessagesPage::draggableSettingsBoxSelectorForMessageTypeAndMessenger($message_type_slug, $messenger_slug), |
|
55 | - MessagesPage::MESSAGES_SETTINGS_ACTIVE_MESSAGE_TYPES_CONTAINER_SELECTOR |
|
56 | - ); |
|
57 | - } |
|
51 | + public function activateMessageTypeForMessenger($message_type_slug, $messenger_slug = 'email') |
|
52 | + { |
|
53 | + $this->actor()->dragAndDrop( |
|
54 | + MessagesPage::draggableSettingsBoxSelectorForMessageTypeAndMessenger($message_type_slug, $messenger_slug), |
|
55 | + MessagesPage::MESSAGES_SETTINGS_ACTIVE_MESSAGE_TYPES_CONTAINER_SELECTOR |
|
56 | + ); |
|
57 | + } |
|
58 | 58 | |
59 | 59 | |
60 | - /** |
|
61 | - * Assumes you are already on the list table page that has the ui for editing the template. |
|
62 | - * @param string $message_type_slug |
|
63 | - * @param string $context [optional] if you want to click directly to the given context in the editor |
|
64 | - */ |
|
65 | - public function clickToEditMessageTemplateByMessageType($message_type_slug, $context = '') |
|
66 | - { |
|
67 | - $this->actor()->click(MessagesPage::editMessageTemplateClassByMessageType($message_type_slug, $context)); |
|
68 | - } |
|
60 | + /** |
|
61 | + * Assumes you are already on the list table page that has the ui for editing the template. |
|
62 | + * @param string $message_type_slug |
|
63 | + * @param string $context [optional] if you want to click directly to the given context in the editor |
|
64 | + */ |
|
65 | + public function clickToEditMessageTemplateByMessageType($message_type_slug, $context = '') |
|
66 | + { |
|
67 | + $this->actor()->click(MessagesPage::editMessageTemplateClassByMessageType($message_type_slug, $context)); |
|
68 | + } |
|
69 | 69 | |
70 | 70 | |
71 | - /** |
|
72 | - * Use this action to verify that the count for the given text in the specified field is as expected. For example |
|
73 | - * filling the condition of, "There should only be 1 instance of `[email protected]` in all the 'to' column. |
|
74 | - * |
|
75 | - * @param int $expected_occurence_count |
|
76 | - * @param string $text_to_check_for |
|
77 | - * @param string $field |
|
78 | - * @param string $message_type_label |
|
79 | - * @param string $message_status |
|
80 | - * @param string $messenger |
|
81 | - * @param string $context |
|
82 | - */ |
|
83 | - public function verifyMatchingCountofTextInMessageActivityListTableFor( |
|
84 | - $expected_occurence_count, |
|
85 | - $text_to_check_for, |
|
86 | - $field, |
|
87 | - $message_type_label, |
|
88 | - $message_status = MessagesPage::MESSAGE_STATUS_SENT, |
|
89 | - $messenger = 'Email', |
|
90 | - $context = 'Event Admin' |
|
91 | - ) { |
|
92 | - $elements = $this->actor()->grabMultiple(MessagesPage::messagesActivityListTableCellSelectorFor( |
|
93 | - $field, |
|
94 | - $message_type_label, |
|
95 | - $message_status, |
|
96 | - $messenger, |
|
97 | - $context, |
|
98 | - $text_to_check_for, |
|
99 | - 0 |
|
100 | - )); |
|
101 | - $actual_count = count($elements); |
|
102 | - $this->actor()->assertEquals( |
|
103 | - $expected_occurence_count, |
|
104 | - $actual_count, |
|
105 | - sprintf( |
|
106 | - 'Expected %s of the %s text for the %s field but there were actually %s counted.', |
|
107 | - $expected_occurence_count, |
|
108 | - $text_to_check_for, |
|
109 | - $field, |
|
110 | - $actual_count |
|
111 | - ) |
|
112 | - ); |
|
113 | - } |
|
71 | + /** |
|
72 | + * Use this action to verify that the count for the given text in the specified field is as expected. For example |
|
73 | + * filling the condition of, "There should only be 1 instance of `[email protected]` in all the 'to' column. |
|
74 | + * |
|
75 | + * @param int $expected_occurence_count |
|
76 | + * @param string $text_to_check_for |
|
77 | + * @param string $field |
|
78 | + * @param string $message_type_label |
|
79 | + * @param string $message_status |
|
80 | + * @param string $messenger |
|
81 | + * @param string $context |
|
82 | + */ |
|
83 | + public function verifyMatchingCountofTextInMessageActivityListTableFor( |
|
84 | + $expected_occurence_count, |
|
85 | + $text_to_check_for, |
|
86 | + $field, |
|
87 | + $message_type_label, |
|
88 | + $message_status = MessagesPage::MESSAGE_STATUS_SENT, |
|
89 | + $messenger = 'Email', |
|
90 | + $context = 'Event Admin' |
|
91 | + ) { |
|
92 | + $elements = $this->actor()->grabMultiple(MessagesPage::messagesActivityListTableCellSelectorFor( |
|
93 | + $field, |
|
94 | + $message_type_label, |
|
95 | + $message_status, |
|
96 | + $messenger, |
|
97 | + $context, |
|
98 | + $text_to_check_for, |
|
99 | + 0 |
|
100 | + )); |
|
101 | + $actual_count = count($elements); |
|
102 | + $this->actor()->assertEquals( |
|
103 | + $expected_occurence_count, |
|
104 | + $actual_count, |
|
105 | + sprintf( |
|
106 | + 'Expected %s of the %s text for the %s field but there were actually %s counted.', |
|
107 | + $expected_occurence_count, |
|
108 | + $text_to_check_for, |
|
109 | + $field, |
|
110 | + $actual_count |
|
111 | + ) |
|
112 | + ); |
|
113 | + } |
|
114 | 114 | |
115 | 115 | |
116 | - /** |
|
117 | - * This will create a custom message template for the given messenger and message type from the context of the |
|
118 | - * default (global) message template list table. |
|
119 | - * Also takes care of verifying the template was created. |
|
120 | - * @param string $message_type_label |
|
121 | - * @param string $messenger_label |
|
122 | - */ |
|
123 | - public function createCustomMessageTemplateFromDefaultFor($message_type_label, $messenger_label) |
|
124 | - { |
|
125 | - $this->amOnDefaultMessageTemplateListTablePage(); |
|
126 | - $this->actor()->click( |
|
127 | - MessagesPage::createCustomButtonForMessageTypeAndMessenger( |
|
128 | - $message_type_label, |
|
129 | - $messenger_label |
|
130 | - ) |
|
131 | - ); |
|
132 | - $this->actor()->seeInField('#title', 'New Custom Template'); |
|
133 | - } |
|
116 | + /** |
|
117 | + * This will create a custom message template for the given messenger and message type from the context of the |
|
118 | + * default (global) message template list table. |
|
119 | + * Also takes care of verifying the template was created. |
|
120 | + * @param string $message_type_label |
|
121 | + * @param string $messenger_label |
|
122 | + */ |
|
123 | + public function createCustomMessageTemplateFromDefaultFor($message_type_label, $messenger_label) |
|
124 | + { |
|
125 | + $this->amOnDefaultMessageTemplateListTablePage(); |
|
126 | + $this->actor()->click( |
|
127 | + MessagesPage::createCustomButtonForMessageTypeAndMessenger( |
|
128 | + $message_type_label, |
|
129 | + $messenger_label |
|
130 | + ) |
|
131 | + ); |
|
132 | + $this->actor()->seeInField('#title', 'New Custom Template'); |
|
133 | + } |
|
134 | 134 | |
135 | 135 | |
136 | - /** |
|
137 | - * This switches the context of the current messages template to the given reference. |
|
138 | - * @param string $context_reference This should be the visible label for the option. |
|
139 | - */ |
|
140 | - public function switchContextTo($context_reference) |
|
141 | - { |
|
142 | - $this->actor()->selectOption(MessagesPage::MESSAGES_CONTEXT_SWITCHER_SELECTOR, $context_reference); |
|
143 | - $this->actor()->click(MessagesPage::MESSAGES_CONTEXT_SWITCHER_BUTTON_SELECTOR); |
|
144 | - $this->actor()->waitForText($context_reference, 10, 'h1'); |
|
145 | - } |
|
136 | + /** |
|
137 | + * This switches the context of the current messages template to the given reference. |
|
138 | + * @param string $context_reference This should be the visible label for the option. |
|
139 | + */ |
|
140 | + public function switchContextTo($context_reference) |
|
141 | + { |
|
142 | + $this->actor()->selectOption(MessagesPage::MESSAGES_CONTEXT_SWITCHER_SELECTOR, $context_reference); |
|
143 | + $this->actor()->click(MessagesPage::MESSAGES_CONTEXT_SWITCHER_BUTTON_SELECTOR); |
|
144 | + $this->actor()->waitForText($context_reference, 10, 'h1'); |
|
145 | + } |
|
146 | 146 | |
147 | 147 | |
148 | - /** |
|
149 | - * Toggles Context so its turned off or on (depending on where it started) and verifies the expected state after |
|
150 | - * toggling. |
|
151 | - * |
|
152 | - * @param string $context_string What context is being switched (used for the expected state text) |
|
153 | - * @param bool $expected_state_is_active Used to indicate whether the expected state is active (true) or inactive |
|
154 | - * (false) |
|
155 | - */ |
|
156 | - public function toggleContextState($context_string, $expected_state_is_active = true) |
|
157 | - { |
|
158 | - $this->actor()->click(MessagesPage::MESSAGES_CONTEXT_ACTIVE_STATE_TOGGLE); |
|
159 | - if ($expected_state_is_active) { |
|
160 | - $this->actor()->waitForText("The template for $context_string is currently active."); |
|
161 | - } else { |
|
162 | - $this->actor()->waitForText("The template for $context_string is currently inactive"); |
|
163 | - } |
|
164 | - } |
|
148 | + /** |
|
149 | + * Toggles Context so its turned off or on (depending on where it started) and verifies the expected state after |
|
150 | + * toggling. |
|
151 | + * |
|
152 | + * @param string $context_string What context is being switched (used for the expected state text) |
|
153 | + * @param bool $expected_state_is_active Used to indicate whether the expected state is active (true) or inactive |
|
154 | + * (false) |
|
155 | + */ |
|
156 | + public function toggleContextState($context_string, $expected_state_is_active = true) |
|
157 | + { |
|
158 | + $this->actor()->click(MessagesPage::MESSAGES_CONTEXT_ACTIVE_STATE_TOGGLE); |
|
159 | + if ($expected_state_is_active) { |
|
160 | + $this->actor()->waitForText("The template for $context_string is currently active."); |
|
161 | + } else { |
|
162 | + $this->actor()->waitForText("The template for $context_string is currently inactive"); |
|
163 | + } |
|
164 | + } |
|
165 | 165 | |
166 | 166 | |
167 | - /** |
|
168 | - * Triggers saving the message template. |
|
169 | - * @param bool $and_close Use to indicate to click the Save and Close button. |
|
170 | - */ |
|
171 | - public function saveMessageTemplate($and_close = false) |
|
172 | - { |
|
173 | - if ($and_close) { |
|
174 | - $this->actor()->click('Save and Close'); |
|
175 | - } else { |
|
176 | - $this->actor()->click('Save'); |
|
177 | - } |
|
178 | - $this->actor()->waitForText('successfully updated'); |
|
179 | - } |
|
167 | + /** |
|
168 | + * Triggers saving the message template. |
|
169 | + * @param bool $and_close Use to indicate to click the Save and Close button. |
|
170 | + */ |
|
171 | + public function saveMessageTemplate($and_close = false) |
|
172 | + { |
|
173 | + if ($and_close) { |
|
174 | + $this->actor()->click('Save and Close'); |
|
175 | + } else { |
|
176 | + $this->actor()->click('Save'); |
|
177 | + } |
|
178 | + $this->actor()->waitForText('successfully updated'); |
|
179 | + } |
|
180 | 180 | |
181 | 181 | |
182 | - /** |
|
183 | - * This takes care of clicking the View Message icon for the given parameters. |
|
184 | - * Assumes you are already viewing the messages activity list table. |
|
185 | - * @param $message_type_label |
|
186 | - * @param $message_status |
|
187 | - * @param string $messenger |
|
188 | - * @param string $context |
|
189 | - * @param int $number_in_set |
|
190 | - */ |
|
191 | - public function viewMessageInMessagesListTableFor( |
|
192 | - $message_type_label, |
|
193 | - $message_status = MessagesPage::MESSAGE_STATUS_SENT, |
|
194 | - $messenger = 'Email', |
|
195 | - $context = 'Event Admin', |
|
196 | - $number_in_set = 1 |
|
197 | - ) { |
|
198 | - $this->actor()->click(MessagesPage::messagesActivityListTableViewButtonSelectorFor( |
|
199 | - $message_type_label, |
|
200 | - $message_status, |
|
201 | - $messenger, |
|
202 | - $context, |
|
203 | - $number_in_set |
|
204 | - )); |
|
205 | - } |
|
182 | + /** |
|
183 | + * This takes care of clicking the View Message icon for the given parameters. |
|
184 | + * Assumes you are already viewing the messages activity list table. |
|
185 | + * @param $message_type_label |
|
186 | + * @param $message_status |
|
187 | + * @param string $messenger |
|
188 | + * @param string $context |
|
189 | + * @param int $number_in_set |
|
190 | + */ |
|
191 | + public function viewMessageInMessagesListTableFor( |
|
192 | + $message_type_label, |
|
193 | + $message_status = MessagesPage::MESSAGE_STATUS_SENT, |
|
194 | + $messenger = 'Email', |
|
195 | + $context = 'Event Admin', |
|
196 | + $number_in_set = 1 |
|
197 | + ) { |
|
198 | + $this->actor()->click(MessagesPage::messagesActivityListTableViewButtonSelectorFor( |
|
199 | + $message_type_label, |
|
200 | + $message_status, |
|
201 | + $messenger, |
|
202 | + $context, |
|
203 | + $number_in_set |
|
204 | + )); |
|
205 | + } |
|
206 | 206 | |
207 | 207 | |
208 | - /** |
|
209 | - * Takes care of deleting a message matching the given parameters via the message activity list table. |
|
210 | - * Assumes you are already viewing the messages activity list table. |
|
211 | - * @param $message_type_label |
|
212 | - * @param $message_status |
|
213 | - * @param string $messenger |
|
214 | - * @param string $context |
|
215 | - * @param int $number_in_set |
|
216 | - */ |
|
217 | - public function deleteMessageInMessagesListTableFor( |
|
218 | - $message_type_label, |
|
219 | - $message_status = MessagesPage::MESSAGE_STATUS_SENT, |
|
220 | - $messenger = 'Email', |
|
221 | - $context = 'Event Admin', |
|
222 | - $number_in_set = 1 |
|
223 | - ) { |
|
224 | - $delete_action_selector = MessagesPage::messagesActivityListTableDeleteActionSelectorFor( |
|
225 | - $message_type_label, |
|
226 | - $message_status, |
|
227 | - $messenger, |
|
228 | - $context, |
|
229 | - $number_in_set |
|
230 | - ); |
|
231 | - $this->actor()->moveMouseOver( |
|
232 | - MessagesPage::messagesActivityListTableCellSelectorFor( |
|
233 | - 'to', |
|
234 | - $message_type_label, |
|
235 | - $message_status, |
|
236 | - $messenger, |
|
237 | - $context, |
|
238 | - '', |
|
239 | - $number_in_set |
|
240 | - ), |
|
241 | - 5, |
|
242 | - 5 |
|
243 | - ); |
|
244 | - $this->actor()->waitForElementVisible( |
|
245 | - $delete_action_selector |
|
246 | - ); |
|
247 | - $this->actor()->click( |
|
248 | - $delete_action_selector |
|
249 | - ); |
|
250 | - $this->actor()->waitForText('successfully deleted'); |
|
251 | - } |
|
208 | + /** |
|
209 | + * Takes care of deleting a message matching the given parameters via the message activity list table. |
|
210 | + * Assumes you are already viewing the messages activity list table. |
|
211 | + * @param $message_type_label |
|
212 | + * @param $message_status |
|
213 | + * @param string $messenger |
|
214 | + * @param string $context |
|
215 | + * @param int $number_in_set |
|
216 | + */ |
|
217 | + public function deleteMessageInMessagesListTableFor( |
|
218 | + $message_type_label, |
|
219 | + $message_status = MessagesPage::MESSAGE_STATUS_SENT, |
|
220 | + $messenger = 'Email', |
|
221 | + $context = 'Event Admin', |
|
222 | + $number_in_set = 1 |
|
223 | + ) { |
|
224 | + $delete_action_selector = MessagesPage::messagesActivityListTableDeleteActionSelectorFor( |
|
225 | + $message_type_label, |
|
226 | + $message_status, |
|
227 | + $messenger, |
|
228 | + $context, |
|
229 | + $number_in_set |
|
230 | + ); |
|
231 | + $this->actor()->moveMouseOver( |
|
232 | + MessagesPage::messagesActivityListTableCellSelectorFor( |
|
233 | + 'to', |
|
234 | + $message_type_label, |
|
235 | + $message_status, |
|
236 | + $messenger, |
|
237 | + $context, |
|
238 | + '', |
|
239 | + $number_in_set |
|
240 | + ), |
|
241 | + 5, |
|
242 | + 5 |
|
243 | + ); |
|
244 | + $this->actor()->waitForElementVisible( |
|
245 | + $delete_action_selector |
|
246 | + ); |
|
247 | + $this->actor()->click( |
|
248 | + $delete_action_selector |
|
249 | + ); |
|
250 | + $this->actor()->waitForText('successfully deleted'); |
|
251 | + } |
|
252 | 252 | |
253 | 253 | |
254 | - /** |
|
255 | - * Assuming you have already triggered the view modal for a single message from the context of the message activity |
|
256 | - * list table, this will take care of validating the given text is in that window. |
|
257 | - * @param string $text_to_view |
|
258 | - */ |
|
259 | - public function seeTextInViewMessageModal($text_to_view, $should_not_see = false) |
|
260 | - { |
|
261 | - $this->actor()->waitForElementVisible('.ee-admin-dialog-container-inner-content'); |
|
262 | - $this->actor()->switchToIframe('message-view-window'); |
|
263 | - $should_not_see ? $this->actor()->dontSee($text_to_view) : $this->actor()->see($text_to_view); |
|
264 | - $this->actor()->switchToIframe(); |
|
265 | - } |
|
254 | + /** |
|
255 | + * Assuming you have already triggered the view modal for a single message from the context of the message activity |
|
256 | + * list table, this will take care of validating the given text is in that window. |
|
257 | + * @param string $text_to_view |
|
258 | + */ |
|
259 | + public function seeTextInViewMessageModal($text_to_view, $should_not_see = false) |
|
260 | + { |
|
261 | + $this->actor()->waitForElementVisible('.ee-admin-dialog-container-inner-content'); |
|
262 | + $this->actor()->switchToIframe('message-view-window'); |
|
263 | + $should_not_see ? $this->actor()->dontSee($text_to_view) : $this->actor()->see($text_to_view); |
|
264 | + $this->actor()->switchToIframe(); |
|
265 | + } |
|
266 | 266 | |
267 | 267 | |
268 | - /** |
|
269 | - * Assuming you have already triggered the view modal for a single message from the context of the message activity |
|
270 | - * list table, this will take care of validating the given text is NOT that window. |
|
271 | - * @param string $text_to_view |
|
272 | - */ |
|
273 | - public function dontSeeTextInViewMessageModal($text_to_view) |
|
274 | - { |
|
275 | - $this->seeTextInViewMessageModal($text_to_view, true); |
|
276 | - } |
|
268 | + /** |
|
269 | + * Assuming you have already triggered the view modal for a single message from the context of the message activity |
|
270 | + * list table, this will take care of validating the given text is NOT that window. |
|
271 | + * @param string $text_to_view |
|
272 | + */ |
|
273 | + public function dontSeeTextInViewMessageModal($text_to_view) |
|
274 | + { |
|
275 | + $this->seeTextInViewMessageModal($text_to_view, true); |
|
276 | + } |
|
277 | 277 | |
278 | 278 | |
279 | - public function dismissMessageModal() |
|
280 | - { |
|
281 | - $this->actor()->click('#espresso-admin-page-overlay-dv'); |
|
282 | - //this is needed otherwise phantom js gets stuck in the wrong context and any future element events will fail. |
|
283 | - $this->actor()->click('form#EE_Message_List_Table-table-frm'); |
|
284 | - } |
|
279 | + public function dismissMessageModal() |
|
280 | + { |
|
281 | + $this->actor()->click('#espresso-admin-page-overlay-dv'); |
|
282 | + //this is needed otherwise phantom js gets stuck in the wrong context and any future element events will fail. |
|
283 | + $this->actor()->click('form#EE_Message_List_Table-table-frm'); |
|
284 | + } |
|
285 | 285 | } |
@@ -8,8 +8,8 @@ discard block |
||
8 | 8 | $event_label = 'Testing Context Deactivation'; |
9 | 9 | |
10 | 10 | $I->wantTo( |
11 | - 'Test that the context activation toggle for turning on or off specific contexts for message sending works as' |
|
12 | - . ' expected' |
|
11 | + 'Test that the context activation toggle for turning on or off specific contexts for message sending works as' |
|
12 | + . ' expected' |
|
13 | 13 | ); |
14 | 14 | |
15 | 15 | $I->loginAsAdmin(); |
@@ -34,7 +34,7 @@ discard block |
||
34 | 34 | $I->see('The template for Primary Registrant Recipient is currently inactive.'); |
35 | 35 | |
36 | 36 | $I->amGoingTo( |
37 | - 'Trigger Registration Approved Messages and verify primary registrant context is excluded from sent messages.' |
|
37 | + 'Trigger Registration Approved Messages and verify primary registrant context is excluded from sent messages.' |
|
38 | 38 | ); |
39 | 39 | $I->amOnDefaultEventsListTablePage(); |
40 | 40 | $I->click(EventsAdmin::ADD_NEW_EVENT_BUTTON_SELECTOR); |
@@ -44,9 +44,9 @@ discard block |
||
44 | 44 | $event_link = $I->observeLinkUrlAt(EventsAdmin::EVENT_EDITOR_VIEW_LINK_AFTER_PUBLISH_SELECTOR); |
45 | 45 | $event_id = $I->observeValueFromInputAt(EventsAdmin::EVENT_EDITOR_EVT_ID_SELECTOR); |
46 | 46 | $test_registration_details = array( |
47 | - 'fname' => 'ContextTestGuy', |
|
48 | - 'lname' => 'ContextTestDude', |
|
49 | - 'email' => '[email protected]', |
|
47 | + 'fname' => 'ContextTestGuy', |
|
48 | + 'lname' => 'ContextTestDude', |
|
49 | + 'email' => '[email protected]', |
|
50 | 50 | ); |
51 | 51 | $I->logOut(); |
52 | 52 | $I->amOnUrl($event_link); |
@@ -63,48 +63,48 @@ discard block |
||
63 | 63 | $I->amOnMessagesActivityListTablePage(); |
64 | 64 | //verify registrant context |
65 | 65 | $I->see( |
66 | - $test_registration_details['email'], |
|
67 | - MessagesAdmin::messagesActivityListTableCellSelectorFor( |
|
68 | - 'to', |
|
69 | - 'Registration Approved', |
|
70 | - MessagesAdmin::MESSAGE_STATUS_SENT, |
|
71 | - '', |
|
72 | - 'Registrant' |
|
73 | - ) |
|
66 | + $test_registration_details['email'], |
|
67 | + MessagesAdmin::messagesActivityListTableCellSelectorFor( |
|
68 | + 'to', |
|
69 | + 'Registration Approved', |
|
70 | + MessagesAdmin::MESSAGE_STATUS_SENT, |
|
71 | + '', |
|
72 | + 'Registrant' |
|
73 | + ) |
|
74 | 74 | ); |
75 | 75 | $I->deleteMessageInMessagesListTableFor( |
76 | - 'Registration Approved', |
|
77 | - MessagesAdmin::MESSAGE_STATUS_SENT, |
|
78 | - 'Email', |
|
79 | - 'Registrant' |
|
76 | + 'Registration Approved', |
|
77 | + MessagesAdmin::MESSAGE_STATUS_SENT, |
|
78 | + 'Email', |
|
79 | + 'Registrant' |
|
80 | 80 | ); |
81 | 81 | //verify admin context |
82 | 82 | $I->see( |
83 | - '[email protected]', |
|
84 | - MessagesAdmin::messagesActivityListTableCellSelectorFor( |
|
85 | - 'to', |
|
86 | - 'Registration Approved', |
|
87 | - MessagesAdmin::MESSAGE_STATUS_SENT |
|
88 | - ) |
|
83 | + '[email protected]', |
|
84 | + MessagesAdmin::messagesActivityListTableCellSelectorFor( |
|
85 | + 'to', |
|
86 | + 'Registration Approved', |
|
87 | + MessagesAdmin::MESSAGE_STATUS_SENT |
|
88 | + ) |
|
89 | 89 | ); |
90 | 90 | $I->deleteMessageInMessagesListTableFor( |
91 | - 'Registration Approved' |
|
91 | + 'Registration Approved' |
|
92 | 92 | ); |
93 | 93 | //verify primary registrant context is NOT present. |
94 | 94 | $I->dontSee( |
95 | - $test_registration_details['email'], |
|
96 | - MessagesAdmin::messagesActivityListTableCellSelectorFor( |
|
97 | - 'to', |
|
98 | - 'Registration Approved', |
|
99 | - MessagesAdmin::MESSAGE_STATUS_SENT, |
|
100 | - '', |
|
101 | - 'Primary Registrant' |
|
102 | - ) |
|
95 | + $test_registration_details['email'], |
|
96 | + MessagesAdmin::messagesActivityListTableCellSelectorFor( |
|
97 | + 'to', |
|
98 | + 'Registration Approved', |
|
99 | + MessagesAdmin::MESSAGE_STATUS_SENT, |
|
100 | + '', |
|
101 | + 'Primary Registrant' |
|
102 | + ) |
|
103 | 103 | ); |
104 | 104 | |
105 | 105 | $I->amGoingTo( |
106 | - 'Deactivate primary registrant context for Registration Approved Message Templates and restore the "To"' |
|
107 | - . ' field to an empty string to verify the message does not send for that context.' |
|
106 | + 'Deactivate primary registrant context for Registration Approved Message Templates and restore the "To"' |
|
107 | + . ' field to an empty string to verify the message does not send for that context.' |
|
108 | 108 | ); |
109 | 109 | $I->amOnDefaultMessageTemplateListTablePage(); |
110 | 110 | $I->clickToEditMessageTemplateByMessageType('registration', 'primary_attendee'); |
@@ -128,41 +128,41 @@ discard block |
||
128 | 128 | $I->amOnMessagesActivityListTablePage(); |
129 | 129 | //verify registrant context |
130 | 130 | $I->see( |
131 | - $test_registration_details['email'], |
|
132 | - MessagesAdmin::messagesActivityListTableCellSelectorFor( |
|
133 | - 'to', |
|
134 | - 'Registration Approved', |
|
135 | - MessagesAdmin::MESSAGE_STATUS_SENT, |
|
136 | - '', |
|
137 | - 'Registrant' |
|
138 | - ) |
|
131 | + $test_registration_details['email'], |
|
132 | + MessagesAdmin::messagesActivityListTableCellSelectorFor( |
|
133 | + 'to', |
|
134 | + 'Registration Approved', |
|
135 | + MessagesAdmin::MESSAGE_STATUS_SENT, |
|
136 | + '', |
|
137 | + 'Registrant' |
|
138 | + ) |
|
139 | 139 | ); |
140 | 140 | $I->deleteMessageInMessagesListTableFor( |
141 | - 'Registration Approved', |
|
142 | - MessagesAdmin::MESSAGE_STATUS_SENT, |
|
143 | - 'Email', |
|
144 | - 'Registrant' |
|
141 | + 'Registration Approved', |
|
142 | + MessagesAdmin::MESSAGE_STATUS_SENT, |
|
143 | + 'Email', |
|
144 | + 'Registrant' |
|
145 | 145 | ); |
146 | 146 | //verify admin context |
147 | 147 | $I->see( |
148 | - '[email protected]', |
|
149 | - MessagesAdmin::messagesActivityListTableCellSelectorFor( |
|
150 | - 'to', |
|
151 | - 'Registration Approved', |
|
152 | - MessagesAdmin::MESSAGE_STATUS_SENT |
|
153 | - ) |
|
148 | + '[email protected]', |
|
149 | + MessagesAdmin::messagesActivityListTableCellSelectorFor( |
|
150 | + 'to', |
|
151 | + 'Registration Approved', |
|
152 | + MessagesAdmin::MESSAGE_STATUS_SENT |
|
153 | + ) |
|
154 | 154 | ); |
155 | 155 | $I->deleteMessageInMessagesListTableFor( |
156 | - 'Registration Approved' |
|
156 | + 'Registration Approved' |
|
157 | 157 | ); |
158 | 158 | //verify primary registrant context is NOT present. |
159 | 159 | $I->dontSee( |
160 | - $test_registration_details['email'], |
|
161 | - MessagesAdmin::messagesActivityListTableCellSelectorFor( |
|
162 | - 'to', |
|
163 | - 'Registration Approved', |
|
164 | - MessagesAdmin::MESSAGE_STATUS_SENT, |
|
165 | - '', |
|
166 | - 'Primary Registrant' |
|
167 | - ) |
|
160 | + $test_registration_details['email'], |
|
161 | + MessagesAdmin::messagesActivityListTableCellSelectorFor( |
|
162 | + 'to', |
|
163 | + 'Registration Approved', |
|
164 | + MessagesAdmin::MESSAGE_STATUS_SENT, |
|
165 | + '', |
|
166 | + 'Primary Registrant' |
|
167 | + ) |
|
168 | 168 | ); |
169 | 169 | \ No newline at end of file |