Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
Complex classes like EEH_MSG_Template often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use EEH_MSG_Template, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 29 | class EEH_MSG_Template { |
||
| 30 | |||
| 31 | |||
| 32 | /** |
||
| 33 | * Holds a collection of EE_Message_Template_Pack objects. |
||
| 34 | * @type EE_Messages_Template_Pack_Collection |
||
| 35 | */ |
||
| 36 | protected static $_template_pack_collection; |
||
| 37 | |||
| 38 | |||
| 39 | |||
| 40 | |||
| 41 | private static function _set_autoloader() { |
||
| 44 | |||
| 45 | |||
| 46 | /** |
||
| 47 | * generate_new_templates |
||
| 48 | * This will handle the messenger, message_type selection when "adding a new custom template" for an event and will automatically create the defaults for the event. The user would then be redirected to edit the default context for the event. |
||
| 49 | * |
||
| 50 | * @access protected |
||
| 51 | * @param string $messenger the messenger we are generating templates for |
||
| 52 | * @param array $message_types array of message types that the templates are generated for. |
||
| 53 | * @param int $GRP_ID If a non global template is being generated then it is expected we'll have a GRP_ID to use as the base for the new generated template. |
||
| 54 | * @param bool $global true indicates generating templates on messenger activation. false requires GRP_ID for event specific template generation. |
||
| 55 | * @throws \EE_Error |
||
| 56 | * @return array @see EEH_MSG_Template::_create_new_templates for the return value of each element in the array for templates |
||
| 57 | * that are generated. If this is an empty array then it means no templates were generated which usually |
||
| 58 | * means there was an error. Anything in the array with an empty value for `MTP_context` means that it |
||
| 59 | * was not a new generated template but just reactivated (which only happens for global templates that |
||
| 60 | * already exist in the database. |
||
| 61 | */ |
||
| 62 | public static function generate_new_templates( $messenger, $message_types, $GRP_ID = 0, $global = false ) { |
||
| 112 | |||
| 113 | |||
| 114 | /** |
||
| 115 | * The purpose of this method is to determine if there are already generated templates in the database for the given variables. |
||
| 116 | * @param string $messenger messenger |
||
| 117 | * @param string $message_type message type |
||
| 118 | * @param int $GRP_ID GRP ID ( if a custom template) (if not provided then we're just doing global template check) |
||
| 119 | * @return bool true = generated, false = hasn't been generated. |
||
| 120 | */ |
||
| 121 | public static function already_generated( $messenger, $message_type, $GRP_ID = 0 ) { |
||
| 138 | |||
| 139 | |||
| 140 | |||
| 141 | |||
| 142 | /** |
||
| 143 | * Updates all message templates matching the incoming messengers and message types to active status. |
||
| 144 | * |
||
| 145 | * @static |
||
| 146 | * @param array $messenger_names Messenger slug |
||
| 147 | * @param array $message_type_names Message type slug |
||
| 148 | * @return int count of updated records. |
||
| 149 | */ |
||
| 150 | public static function update_to_active( $messenger_names, $message_type_names ) { |
||
| 163 | |||
| 164 | |||
| 165 | |||
| 166 | /** |
||
| 167 | * Updates all message template groups matching the incoming arguments to inactive status. |
||
| 168 | * |
||
| 169 | * @static |
||
| 170 | * @param array $messenger_names The messenger slugs. |
||
| 171 | * If empty then all templates matching the message types are marked inactive. |
||
| 172 | * Otherwise only templates matching the messengers and message types. |
||
| 173 | * @param array $message_type_names The message type slugs. |
||
| 174 | * If empty then all templates matching the messengers are marked inactive. |
||
| 175 | * Otherwise only templates matching the messengers and message types. |
||
| 176 | * |
||
| 177 | * @return int count of updated records. |
||
| 178 | */ |
||
| 179 | public static function update_to_inactive( $messenger_names = array(), $message_type_names = array() ) { |
||
| 185 | |||
| 186 | |||
| 187 | /** |
||
| 188 | * The purpose of this function is to return all installed message objects |
||
| 189 | * (messengers and message type regardless of whether they are ACTIVE or not) |
||
| 190 | * |
||
| 191 | * @deprecated 4.9.0 |
||
| 192 | * @static |
||
| 193 | * @param string $type |
||
| 194 | * @return array array consisting of installed messenger objects and installed message type objects. |
||
| 195 | */ |
||
| 196 | public static function get_installed_message_objects( $type = 'all' ) { |
||
| 204 | |||
| 205 | |||
| 206 | /** |
||
| 207 | * This will return an array of shortcodes => labels from the |
||
| 208 | * messenger and message_type objects associated with this |
||
| 209 | * template. |
||
| 210 | * |
||
| 211 | * @since 4.3.0 |
||
| 212 | * |
||
| 213 | * @param string $message_type |
||
| 214 | * @param string $messenger |
||
| 215 | * @param array $fields What fields we're returning valid shortcodes for. |
||
| 216 | * If empty then we assume all fields are to be returned. Optional. |
||
| 217 | * @param string $context What context we're going to return shortcodes for. Optional. |
||
| 218 | * @param bool $merged If TRUE then we don't return shortcodes indexed by field, |
||
| 219 | * but instead an array of the unique shortcodes for all the given ( or all) fields. |
||
| 220 | * Optional. |
||
| 221 | * @throws \EE_Error |
||
| 222 | * @return mixed (array|bool) an array of shortcodes in the format |
||
| 223 | * array( '[shortcode] => 'label') |
||
| 224 | * OR |
||
| 225 | * FALSE if no shortcodes found. |
||
| 226 | */ |
||
| 227 | public static function get_shortcodes( |
||
| 228 | $message_type, |
||
| 229 | $messenger, |
||
| 230 | $fields = array(), |
||
| 231 | $context = 'admin', |
||
| 232 | $merged = false |
||
| 233 | ) { |
||
| 234 | $messenger_name = str_replace( ' ', '_', ucwords( str_replace( '_', ' ', $messenger ) ) ); |
||
| 235 | $mt_name = str_replace( ' ', '_', ucwords( str_replace( '_', ' ', $message_type ) ) ); |
||
| 236 | /** @var EE_Message_Resource_Manager $message_resource_manager */ |
||
| 237 | $message_resource_manager = EE_Registry::instance()->load_lib( 'Message_Resource_Manager' ); |
||
| 238 | //convert slug to object |
||
| 239 | $messenger = $message_resource_manager->get_messenger( $messenger ); |
||
| 240 | |||
| 241 | //if messenger isn't a EE_messenger resource then bail. |
||
| 242 | if ( ! $messenger instanceof EE_messenger ) { |
||
| 243 | return array(); |
||
| 244 | } |
||
| 245 | |||
| 246 | //validate class for getting our list of shortcodes |
||
| 247 | $classname = 'EE_Messages_' . $messenger_name . '_' . $mt_name . '_Validator'; |
||
| 248 | if ( ! class_exists( $classname ) ) { |
||
| 249 | $msg[] = __( 'The Validator class was unable to load', 'event_espresso' ); |
||
| 250 | $msg[] = sprintf( |
||
| 251 | __( 'The class name compiled was %s. Please check and make sure the spelling and case is correct for the class name and that there is an autoloader in place for this class', 'event_espresso' ), |
||
| 252 | $classname |
||
| 253 | ); |
||
| 254 | throw new EE_Error( implode( '||', $msg ) ); |
||
| 255 | } |
||
| 256 | |||
| 257 | /** @type EE_Messages_Validator $_VLD */ |
||
| 258 | $_VLD = new $classname( array(), $context ); |
||
| 259 | $valid_shortcodes = $_VLD->get_validators(); |
||
| 260 | |||
| 261 | //let's make sure we're only getting the shortcode part of the validators |
||
| 262 | $shortcodes = array(); |
||
| 263 | foreach ( $valid_shortcodes as $field => $validators ) { |
||
| 264 | $shortcodes[ $field ] = $validators['shortcodes']; |
||
| 265 | } |
||
| 266 | $valid_shortcodes = $shortcodes; |
||
| 267 | |||
| 268 | //if not all fields let's make sure we ONLY include the shortcodes for the specified fields. |
||
| 269 | if ( ! empty( $fields ) ) { |
||
| 270 | $specified_shortcodes = array(); |
||
| 271 | foreach ( $fields as $field ) { |
||
| 272 | if ( isset( $valid_shortcodes[ $field ] ) ) { |
||
| 273 | $specified_shortcodes[ $field ] = $valid_shortcodes[ $field ]; |
||
| 274 | } |
||
| 275 | } |
||
| 276 | $valid_shortcodes = $specified_shortcodes; |
||
| 277 | } |
||
| 278 | |||
| 279 | //if not merged then let's replace the fields with the localized fields |
||
| 280 | if ( ! $merged ) { |
||
| 281 | //let's get all the fields for the set messenger so that we can get the localized label and use that in the returned array. |
||
| 282 | $field_settings = $messenger->get_template_fields(); |
||
| 283 | $localized = array(); |
||
| 284 | foreach ( $valid_shortcodes as $field => $shortcodes ) { |
||
| 285 | //get localized field label |
||
| 286 | if ( isset( $field_settings[ $field ] ) ) { |
||
| 287 | //possible that this is used as a main field. |
||
| 288 | if ( empty( $field_settings[ $field ] ) ) { |
||
| 289 | if ( isset( $field_settings['extra'][ $field ] ) ) { |
||
| 290 | $_field = $field_settings['extra'][ $field ]['main']['label']; |
||
| 291 | } else { |
||
| 292 | $_field = $field; |
||
| 293 | } |
||
| 294 | } else { |
||
| 295 | $_field = $field_settings[ $field ]['label']; |
||
| 296 | } |
||
| 297 | } else if ( isset( $field_settings['extra'] ) ) { |
||
| 298 | //loop through extra "main fields" and see if any of their children have our field |
||
| 299 | foreach ( $field_settings['extra'] as $main_field => $fields ) { |
||
| 300 | if ( isset( $fields[ $field ] ) ) { |
||
| 301 | $_field = $fields[ $field ]['label']; |
||
| 302 | } else { |
||
| 303 | $_field = $field; |
||
| 304 | } |
||
| 305 | } |
||
| 306 | } else { |
||
| 307 | $_field = $field; |
||
| 308 | } |
||
| 309 | if ( isset( $_field ) ) { |
||
| 310 | $localized[ $_field ] = $shortcodes; |
||
| 311 | } |
||
| 312 | } |
||
| 313 | $valid_shortcodes = $localized; |
||
| 314 | } |
||
| 315 | |||
| 316 | //if $merged then let's merge all the shortcodes into one list NOT indexed by field. |
||
| 317 | if ( $merged ) { |
||
| 318 | $merged_codes = array(); |
||
| 319 | foreach ( $valid_shortcodes as $field => $shortcode ) { |
||
| 320 | foreach ( $shortcode as $code => $label ) { |
||
| 321 | if ( isset( $merged_codes[ $code ] ) ) { |
||
| 322 | continue; |
||
| 323 | } else { |
||
| 324 | $merged_codes[ $code ] = $label; |
||
| 325 | } |
||
| 326 | } |
||
| 327 | } |
||
| 328 | $valid_shortcodes = $merged_codes; |
||
| 329 | } |
||
| 330 | |||
| 331 | return $valid_shortcodes; |
||
| 332 | } |
||
| 333 | |||
| 334 | |||
| 335 | /** |
||
| 336 | * Get Messenger object. |
||
| 337 | * |
||
| 338 | * @since 4.3.0 |
||
| 339 | * @deprecated 4.9.0 |
||
| 340 | * @param string $messenger messenger slug for the messenger object we want to retrieve. |
||
| 341 | * @throws \EE_Error |
||
| 342 | * @return EE_messenger |
||
| 343 | */ |
||
| 344 | public static function messenger_obj( $messenger ) { |
||
| 349 | |||
| 350 | |||
| 351 | /** |
||
| 352 | * get Message type object |
||
| 353 | * |
||
| 354 | * @since 4.3.0 |
||
| 355 | * @deprecated 4.9.0 |
||
| 356 | * @param string $message_type the slug for the message type object to retrieve |
||
| 357 | * @throws \EE_Error |
||
| 358 | * @return EE_message_type |
||
| 359 | */ |
||
| 360 | public static function message_type_obj( $message_type ) { |
||
| 365 | |||
| 366 | |||
| 367 | |||
| 368 | |||
| 369 | |||
| 370 | /** |
||
| 371 | * Given a message_type slug, will return whether that message type is active in the system or not. |
||
| 372 | * |
||
| 373 | * @since 4.3.0 |
||
| 374 | * @param string $message_type message type to check for. |
||
| 375 | * @return boolean |
||
| 376 | */ |
||
| 377 | public static function is_mt_active( $message_type ) { |
||
| 383 | |||
| 384 | |||
| 385 | |||
| 386 | /** |
||
| 387 | * Given a messenger slug, will return whether that messenger is active in the system or not. |
||
| 388 | * |
||
| 389 | * @since 4.3.0 |
||
| 390 | * |
||
| 391 | * @param string $messenger slug for messenger to check. |
||
| 392 | * @return boolean |
||
| 393 | */ |
||
| 394 | public static function is_messenger_active( $messenger ) { |
||
| 400 | |||
| 401 | |||
| 402 | |||
| 403 | /** |
||
| 404 | * Used to return active messengers array stored in the wp options table. |
||
| 405 | * If no value is present in the option then an empty array is returned. |
||
| 406 | * |
||
| 407 | * @deprecated 4.9 |
||
| 408 | * @since 4.3.1 |
||
| 409 | * |
||
| 410 | * @return array |
||
| 411 | */ |
||
| 412 | View Code Duplication | public static function get_active_messengers_in_db() { |
|
| 413 | EE_Error::doing_it_wrong( |
||
| 414 | __METHOD__, |
||
| 415 | __( 'Please use EE_Message_Resource_Manager::get_active_messengers_option() instead.', 'event_espresso' ), |
||
| 416 | '4.9.0' |
||
| 417 | ); |
||
| 418 | /** @var EE_Message_Resource_Manager $Message_Resource_Manager */ |
||
| 419 | $Message_Resource_Manager = EE_Registry::instance()->load_lib( 'Message_Resource_Manager' ); |
||
| 420 | return $Message_Resource_Manager->get_active_messengers_option(); |
||
| 421 | } |
||
| 422 | |||
| 423 | |||
| 424 | |||
| 425 | |||
| 426 | /** |
||
| 427 | * Used to update the active messengers array stored in the wp options table. |
||
| 428 | * |
||
| 429 | * @since 4.3.1 |
||
| 430 | * @deprecated 4.9.0 |
||
| 431 | * |
||
| 432 | * @param array $data_to_save Incoming data to save. |
||
| 433 | * |
||
| 434 | * @return bool FALSE if not updated, TRUE if updated. |
||
| 435 | */ |
||
| 436 | View Code Duplication | public static function update_active_messengers_in_db( $data_to_save ) { |
|
| 437 | EE_Error::doing_it_wrong( |
||
| 438 | __METHOD__, |
||
| 439 | __( 'Please use EE_Message_Resource_Manager::update_active_messengers_option() instead.', 'event_espresso' ), |
||
| 440 | '4.9.0' |
||
| 441 | ); |
||
| 442 | /** @var EE_Message_Resource_Manager $Message_Resource_Manager */ |
||
| 443 | $Message_Resource_Manager = EE_Registry::instance()->load_lib( 'Message_Resource_Manager' ); |
||
| 444 | return $Message_Resource_Manager->update_active_messengers_option( $data_to_save ); |
||
| 445 | } |
||
| 446 | |||
| 447 | |||
| 448 | /** |
||
| 449 | * This does some validation of incoming params, determines what type of url is being prepped and returns the |
||
| 450 | * appropriate url trigger |
||
| 451 | * |
||
| 452 | * @param EE_message_type $message_type |
||
| 453 | * @param EE_Message $message |
||
| 454 | * @param EE_Registration | null $registration The registration object must be included if this |
||
| 455 | * is going to be a registration trigger url. |
||
| 456 | * @param string $sending_messenger The (optional) sending messenger for the url. |
||
| 457 | * |
||
| 458 | * @return string |
||
| 459 | * @throws EE_Error |
||
| 460 | */ |
||
| 461 | public static function get_url_trigger( |
||
| 519 | |||
| 520 | |||
| 521 | /** |
||
| 522 | * This returns the url for triggering a in browser view of a specific EE_Message object. |
||
| 523 | * @param EE_Message $message |
||
| 524 | * @return string. |
||
| 525 | */ |
||
| 526 | View Code Duplication | public static function generate_browser_trigger( EE_Message $message ) { |
|
| 537 | |||
| 538 | |||
| 539 | |||
| 540 | |||
| 541 | |||
| 542 | |||
| 543 | /** |
||
| 544 | * This returns the url for triggering an in browser view of the error saved on the incoming message object. |
||
| 545 | * @param EE_Message $message |
||
| 546 | * @return string |
||
| 547 | */ |
||
| 548 | View Code Duplication | public static function generate_error_display_trigger( EE_Message $message ) { |
|
| 561 | |||
| 562 | |||
| 563 | |||
| 564 | |||
| 565 | |||
| 566 | |||
| 567 | /** |
||
| 568 | * This generates a url trigger for the msg_url_trigger route using the given arguments |
||
| 569 | * |
||
| 570 | * @param string $sending_messenger The sending messenger slug. |
||
| 571 | * @param string $generating_messenger The generating messenger slug. |
||
| 572 | * @param string $context The context for the template. |
||
| 573 | * @param string $message_type The message type slug |
||
| 574 | * @param EE_Registration $registration |
||
| 575 | * @param integer $message_template_group id The EE_Message_Template_Group ID for the template. |
||
| 576 | * @param integer $data_id The id to the EE_Base_Class for getting the data used by the trigger. |
||
| 577 | * @return string The generated url. |
||
| 578 | */ |
||
| 579 | public static function generate_url_trigger( |
||
| 614 | |||
| 615 | |||
| 616 | |||
| 617 | |||
| 618 | /** |
||
| 619 | * Return the specific css for the action icon given. |
||
| 620 | * |
||
| 621 | * @since 4.9.0 |
||
| 622 | * |
||
| 623 | * @param string $type What action to return. |
||
| 624 | * @return string |
||
| 625 | */ |
||
| 626 | public static function get_message_action_icon( $type ) { |
||
| 630 | |||
| 631 | |||
| 632 | /** |
||
| 633 | * This is used for retrieving the css classes used for the icons representing message actions. |
||
| 634 | * |
||
| 635 | * @since 4.9.0 |
||
| 636 | * |
||
| 637 | * @return array |
||
| 638 | */ |
||
| 639 | public static function get_message_action_icons() { |
||
| 673 | |||
| 674 | |||
| 675 | /** |
||
| 676 | * This returns the url for a given action related to EE_Message. |
||
| 677 | * |
||
| 678 | * @since 4.9.0 |
||
| 679 | * |
||
| 680 | * @param string $type What type of action to return the url for. |
||
| 681 | * @param EE_Message $message Required for generating the correct url for some types. |
||
| 682 | * @param array $query_params Any additional query params to be included with the generated url. |
||
| 683 | * |
||
| 684 | * @return string |
||
| 685 | */ |
||
| 686 | public static function get_message_action_url( $type, EE_Message $message = null, $query_params = array() ) { |
||
| 690 | |||
| 691 | |||
| 692 | |||
| 693 | /** |
||
| 694 | * This returns all the current urls for EE_Message actions. |
||
| 695 | * |
||
| 696 | * @since 4.9.0 |
||
| 697 | * |
||
| 698 | * @param EE_Message $message The EE_Message object required to generate correct urls for some types. |
||
| 699 | * @param array $query_params Any additional query_params to be included with the generated url. |
||
| 700 | * |
||
| 701 | * @return array |
||
| 702 | */ |
||
| 703 | public static function get_message_action_urls( EE_Message $message = null, $query_params = array() ) { |
||
| 770 | |||
| 771 | |||
| 772 | /** |
||
| 773 | * This returns a generated link html including the icon used for the action link for EE_Message actions. |
||
| 774 | * |
||
| 775 | * @since 4.9.0 |
||
| 776 | * |
||
| 777 | * @param string $type What type of action the link is for (if invalid type is passed in then an |
||
| 778 | * empty string is returned) |
||
| 779 | * @param EE_Message|null $message The EE_Message object (required for some actions to generate correctly) |
||
| 780 | * @param array $query_params Any extra query params to include in the generated link. |
||
| 781 | * |
||
| 782 | * @return string |
||
| 783 | */ |
||
| 784 | public static function get_message_action_link( $type, EE_Message $message = null, $query_params = array() ) { |
||
| 785 | $url = EEH_MSG_Template::get_message_action_url( $type, $message, $query_params ); |
||
| 786 | $icon_css = EEH_MSG_Template::get_message_action_icon( $type ); |
||
| 787 | $title = isset( $icon_css['label'] ) ? 'title="' . $icon_css['label'] . '"' : ''; |
||
| 788 | |||
| 789 | if ( empty( $url ) || empty( $icon_css ) || ! isset( $icon_css['css_class'] ) ) { |
||
| 790 | return ''; |
||
| 791 | } |
||
| 792 | |||
| 793 | $icon_css['css_class'] .= esc_attr( |
||
| 794 | apply_filters( |
||
| 795 | 'FHEE__EEH_MSG_Template__get_message_action_link__icon_css_class', |
||
| 796 | ' js-ee-message-action-link ee-message-action-link-' . $type, |
||
| 797 | $type, |
||
| 798 | $message, |
||
| 799 | $query_params |
||
| 800 | ) |
||
| 801 | ); |
||
| 802 | |||
| 803 | return '<a href="' . $url . '"' . $title . '><span class="' . esc_attr( $icon_css['css_class'] ) . '"></span></a>'; |
||
| 804 | |||
| 805 | } |
||
| 806 | |||
| 807 | |||
| 808 | |||
| 809 | |||
| 810 | |||
| 811 | /** |
||
| 812 | * This returns an array with keys as reg statuses and values as the corresponding message type slug (filtered). |
||
| 813 | * |
||
| 814 | * @since 4.9.0 |
||
| 815 | * @return array |
||
| 816 | */ |
||
| 817 | public static function reg_status_to_message_type_array() { |
||
| 829 | |||
| 830 | |||
| 831 | |||
| 832 | |||
| 833 | /** |
||
| 834 | * This returns the corresponding registration message type slug to the given reg status. If there isn't a |
||
| 835 | * match, then returns an empty string. |
||
| 836 | * |
||
| 837 | * @since 4.9.0 |
||
| 838 | * @param $reg_status |
||
| 839 | * @return string |
||
| 840 | */ |
||
| 841 | public static function convert_reg_status_to_message_type( $reg_status ) { |
||
| 845 | |||
| 846 | |||
| 847 | /** |
||
| 848 | * This returns an array with keys as payment stati and values as the corresponding message type slug (filtered). |
||
| 849 | * |
||
| 850 | * @since 4.9.0 |
||
| 851 | * @return array |
||
| 852 | */ |
||
| 853 | public static function payment_status_to_message_type_array() { |
||
| 865 | |||
| 866 | |||
| 867 | |||
| 868 | |||
| 869 | /** |
||
| 870 | * This returns the corresponding payment message type slug to the given payment status. If there isn't a match then |
||
| 871 | * an empty string is returned |
||
| 872 | * |
||
| 873 | * @since 4.9.0 |
||
| 874 | * @param $payment_status |
||
| 875 | * @return string |
||
| 876 | */ |
||
| 877 | public static function convert_payment_status_to_message_type( $payment_status ) { |
||
| 881 | |||
| 882 | |||
| 883 | /** |
||
| 884 | * This is used to retrieve the template pack for the given name. |
||
| 885 | * |
||
| 886 | * @param string $template_pack_name should match the set `dbref` property value on the EE_Messages_Template_Pack. |
||
| 887 | * |
||
| 888 | * @return EE_Messages_Template_Pack |
||
| 889 | */ |
||
| 890 | public static function get_template_pack( $template_pack_name ) { |
||
| 919 | |||
| 920 | |||
| 921 | |||
| 922 | |||
| 923 | /** |
||
| 924 | * Globs template packs installed in core and returns the template pack collection with all installed template packs |
||
| 925 | * in it. |
||
| 926 | * |
||
| 927 | * @since 4.9.0 |
||
| 928 | * |
||
| 929 | * @return EE_Messages_Template_Pack_Collection |
||
| 930 | */ |
||
| 931 | public static function get_template_pack_collection() { |
||
| 981 | |||
| 982 | |||
| 983 | |||
| 984 | /** |
||
| 985 | * This is a wrapper for the protected _create_new_templates function |
||
| 986 | * |
||
| 987 | * @param string $messenger_name |
||
| 988 | * @param string $message_type_name message type that the templates are being created for |
||
| 989 | * @param int $GRP_ID |
||
| 990 | * @param bool $global |
||
| 991 | * @return array |
||
| 992 | * @throws \EE_Error |
||
| 993 | */ |
||
| 994 | public static function create_new_templates( $messenger_name, $message_type_name, $GRP_ID = 0, $global = false ) { |
||
| 1005 | |||
| 1006 | |||
| 1007 | |||
| 1008 | /** |
||
| 1009 | * @param \EE_messenger $messenger |
||
| 1010 | * @param \EE_message_type $message_type |
||
| 1011 | * @param $GRP_ID |
||
| 1012 | * @param $global |
||
| 1013 | * @return array|mixed |
||
| 1014 | */ |
||
| 1015 | protected static function _create_new_templates( EE_messenger $messenger, EE_message_type $message_type, $GRP_ID, $global ) { |
||
| 1046 | |||
| 1047 | |||
| 1048 | |||
| 1049 | /** |
||
| 1050 | * This creates a custom template using the incoming GRP_ID |
||
| 1051 | * |
||
| 1052 | * @param \EE_messenger $messenger |
||
| 1053 | * @param \EE_message_type $message_type |
||
| 1054 | * @param int $GRP_ID GRP_ID for the template_group being used as the base |
||
| 1055 | * @return array $success This will be an array in the format: |
||
| 1056 | * array( |
||
| 1057 | * 'GRP_ID' => $new_grp_id, |
||
| 1058 | * 'MTP_context' => $first_context_in_created_template |
||
| 1059 | * ) |
||
| 1060 | * @access private |
||
| 1061 | */ |
||
| 1062 | private static function _create_custom_template_group( EE_messenger $messenger, EE_message_type $message_type, $GRP_ID ) { |
||
| 1137 | |||
| 1138 | |||
| 1139 | |||
| 1140 | /** |
||
| 1141 | * message_type_has_active_templates_for_messenger |
||
| 1142 | * |
||
| 1143 | * @param \EE_messenger $messenger |
||
| 1144 | * @param \EE_message_type $message_type |
||
| 1145 | * @param bool $global |
||
| 1146 | * @return bool |
||
| 1147 | */ |
||
| 1148 | public static function message_type_has_active_templates_for_messenger( |
||
| 1184 | |||
| 1185 | |||
| 1186 | |||
| 1187 | /** |
||
| 1188 | * get_fields |
||
| 1189 | * This takes a given messenger and message type and returns all the template fields indexed by context (and with field type). |
||
| 1190 | * |
||
| 1191 | * @param string $messenger_name name of EE_messenger |
||
| 1192 | * @param string $message_type_name name of EE_message_type |
||
| 1193 | * @return array |
||
| 1194 | */ |
||
| 1195 | public static function get_fields( $messenger_name, $message_type_name ) { |
||
| 1221 | |||
| 1222 | } |
||
| 1223 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.