/**
  * EE_Messages_Template_Defaults constructor.
  *
  * @param EE_messenger               $messenger
  * @param EE_message_type            $message_type
  * @param int                        $GRP_ID                      Optional.  If included then we're just regenerating
  *                                                                the template fields for the given group not the
  *                                                                message template group itself
  * @param EEM_Message_Template_Group $message_template_group_model
  * @param EEM_Message_Template       $message_template_model
  * @throws EE_Error
  */
 public function __construct(EE_messenger $messenger, EE_message_type $message_type, $GRP_ID = 0, EEM_Message_Template_Group $message_template_group_model, EEM_Message_Template $message_template_model)
 {
     $this->_messenger = $messenger;
     $this->_message_type = $message_type;
     $this->_GRP_ID = $GRP_ID;
     //set the model object
     $this->_message_template_group_model = $message_template_group_model;
     $this->_message_template_model = $message_template_model;
     $this->_fields = $this->_messenger->get_template_fields();
     $this->_contexts = $this->_message_type->get_contexts();
 }
 public function __construct()
 {
     //setup type details for reference
     $this->name = 'payment';
     $this->description = __('This message type is used for all payment notification messages that go out including any manual payments entered by an event administrator.', 'event_espresso');
     $this->label = array('singular' => __('payment received', 'event_espresso'), 'plural' => __('payments received', 'event_espresso'));
     parent::__construct();
 }
 public function __construct()
 {
     //setup type details for reference
     $this->name = 'payment_refund';
     $this->description = __('This message type is used for all payment notification messages that go out for refunds.', 'event_espresso');
     $this->label = array('singular' => __('refund issued', 'event_espresso'), 'plural' => __('refunds issued', 'event_espresso'));
     parent::__construct();
 }
 /**
  * used to set the valid shortcodes.
  *
  * For the newsletter message type we only have two valid shortcode libraries in use, recipient details and organization.  That's it!
  *
  * @since   4.3.0
  *
  * @return  void
  */
 protected function _set_valid_shortcodes()
 {
     parent::_set_valid_shortcodes();
     $included_shortcodes = array('recipient_details', 'organization', 'newsletter');
     foreach ($this->_valid_shortcodes as $context => $shortcodes) {
         foreach ($shortcodes as $key => $shortcode) {
             if (!in_array($shortcode, $included_shortcodes)) {
                 unset($this->_valid_shortcodes[$context][$key]);
             }
         }
         $this->_valid_shortcodes[$context][] = 'newsletter';
     }
 }
 protected function _primary_attendee_addressees()
 {
     if ($this->_single_message) {
         return array();
     }
     return parent::_primary_attendee_addressees();
 }
 /**
  * This takes the incoming messenger and message type objects, uses them to get the set fields and contexts, then attempts to retrieve the templates matching those for this given template pack.
  *
  * @since 4.5.0
  *
  * @param EE_messenger      $messenger
  * @param EE_message_type $message_type
  *
  * @return array          Returns an multi-level associative array indexed by template context and field in the format:
  *                                array( 'context' => array( 'field' => 'value', 'another-field', 'value' ) );
  */
 protected function _get_templates(EE_messenger $messenger, EE_message_type $message_type)
 {
     $templates = array();
     /**
      * Retrieving the default pack for later usage of default templates for template packs that
      * are NOT the default pack ( or an extension of the default pack ).
      * We ONLY set this variable to be the default pack IF the loaded class is NOT the default
      * pack.  This prevents recursion in _get_specific_template().  The intention is that for
      * template packs that are NOT default packs, we use the default template pack to provide
      * the final fallback templates if there aren't any defined for the called template pack.
      *
      * @type EE_Messages_Template_Pack_Default | null $default_pack
      */
     $default_pack = !$this instanceof EE_Messages_Template_Pack_Default ? new EE_Messages_Template_Pack_Default() : null;
     $fields = $messenger->get_template_fields();
     $contexts = $message_type->get_contexts();
     foreach ($contexts as $context => $details) {
         foreach ($fields as $field => $field_details) {
             if (empty($field_details)) {
                 continue;
             }
             /**
              * is this a field array (linked to a main field)?
              */
             if ($field == 'extra') {
                 foreach ($field_details as $main_field => $sub_fields) {
                     foreach ($sub_fields as $sub_field => $sub_field_details) {
                         //make sure that the template_field_ref matches what the main template field is for this template group.
                         $template_field_ref = $sub_field == 'main' ? $main_field : $sub_field;
                         $templates[$context][$main_field][$sub_field] = $this->_get_specific_template($default_pack, $messenger, $message_type, $template_field_ref, $context);
                     }
                 }
             } else {
                 $templates[$context][$field] = $this->_get_specific_template($default_pack, $messenger, $message_type, $field, $context);
             }
         }
     }
     $templates = apply_filters('FHEE__EE_Template_Pack___get_templates__templates', $templates, $messenger, $message_type, $this);
     $this->_templates[$messenger->name][$message_type->name] = $templates;
     return $templates;
 }
 /**
  * Used to verify if a message can be sent for the given messenger and message type and that it is a generating messenger (used for generating message templates).
  *
  * @param EE_messenger $messenger    messenger used in trigger
  * @param EE_messagetype $message_type message type used in trigger
  *
  * @return bool true is a generating messenger and can be sent OR FALSE meaning cannot send.
  */
 private function _is_generating_messenger_and_active(EE_messenger $messenger, EE_message_type $message_type)
 {
     $generating_msgrs = array();
     //get the $messengers the message type says it can be used with.
     $used_with = $message_type->with_messengers();
     foreach ($used_with as $generating_msgr => $secondary_msgrs) {
         if ($messenger->name == $generating_msgr && isset($this->_active_message_types[$generating_msgr][$message_type->name])) {
             return true;
         }
     }
     return false;
 }
 /**
  * returns an array of addressee objects for event_admins
  *
  * @access protected
  * @return array array of EE_Messages_Addressee objects
  */
 protected function _admin_addressees()
 {
     if ($this->_single_message) {
         return array();
     }
     return parent::_admin_addressees();
 }
 protected function _purchaser_addressees()
 {
     return parent::_primary_attendee_addressees();
 }
 /**
  * This does some validation of incoming params, determines what type of url is being prepped and returns the
  * appropriate url trigger
  *
  * @param EE_message_type $message_type
  * @param EE_Message $message
  * @param EE_Registration | null $registration  The registration object must be included if this
  *                                              is going to be a registration trigger url.
  * @param string $sending_messenger             The (optional) sending messenger for the url.
  *
  * @return string
  * @throws EE_Error
  */
 public static function get_url_trigger(EE_message_type $message_type, EE_Message $message, $registration = null, $sending_messenger = '')
 {
     //first determine if the url can be to the EE_Message object.
     if (!$message_type->always_generate()) {
         return EEH_MSG_Template::generate_browser_trigger($message);
     }
     //if $registration object is not valid then exit early because there's nothing that can be generated.
     if (!$registration instanceof EE_Registration) {
         throw new EE_Error(__('Incoming value for registration is not a valid EE_Registration object.', 'event_espresso'));
     }
     //validate given context
     $contexts = $message_type->get_contexts();
     if ($message->context() !== '' && !isset($contexts[$message->context()])) {
         throw new EE_Error(sprintf(__('The context %s is not a valid context for %s.', 'event_espresso'), $message->context(), get_class($message_type)));
     }
     //valid sending messenger but only if sending messenger set.  Otherwise generating messenger is used.
     if (!empty($sending_messenger)) {
         $with_messengers = $message_type->with_messengers();
         if (!isset($with_messengers[$message->messenger()]) || !in_array($sending_messenger, $with_messengers[$message->messenger()])) {
             throw new EE_Error(sprintf(__('The given sending messenger string (%1$s) does not match a valid sending messenger with the %2$s.  If this is incorrect, make sure that the message type has defined this messenger as a sending messenger in its $_with_messengers array.', 'event_espresso'), $sending_messenger, get_class($message_type)));
         }
     } else {
         $sending_messenger = $message->messenger();
     }
     return EEH_MSG_Template::generate_url_trigger($sending_messenger, $message->messenger(), $message->context(), $message->message_type(), $registration, $message->GRP_ID());
 }
 /**
  * Used to verify if a message can be sent for the given messenger and message type
  * and that it is a generating messenger (used for generating message templates).
  *
  * @param EE_messenger    $messenger    messenger used in trigger
  * @param EE_message_type $message_type message type used in trigger
  *
  * @return bool true is a generating messenger and can be sent OR FALSE meaning cannot send.
  */
 public function is_generating_messenger_and_active(EE_messenger $messenger, EE_message_type $message_type)
 {
     //get the $messengers the message type says it can be used with.
     foreach ($message_type->with_messengers() as $generating_messenger => $secondary_messengers) {
         if ($messenger->name === $generating_messenger && $this->is_message_type_active_for_messenger($messenger->name, $message_type->name)) {
             return true;
         }
     }
     return false;
 }