/**
  * Constructor
  *
  * @param   string    $sending_messenger_slug 	  This is used to set what messenger is used to "send"
  *                                            	  the EE_Message retrieved from the DB via the given token.
  * @param   string $token                         This is a token for a Message that should already exist int the db.
  *                                                This is then used to populate the properties in here.
  * @param   EE_Message_Resource_Manager $message_resource_manager
  */
 public function __construct($token, $sending_messenger_slug = 'html', EE_Message_Resource_Manager $message_resource_manager)
 {
     $this->token = $token;
     $this->_sending_messenger = $this->_set_sending_messenger($sending_messenger_slug, $message_resource_manager);
     $this->_message = $this->_generate_message();
     //set params for parent from the message object
     parent::__construct($this->_message->messenger(), $this->_message->message_type(), array(), $this->_message->context(), false);
 }
 /**
  * @param string            $messenger_name  The messenger being used to send the message
  * @param string            $message_type_name  The message type being used to grab variations etc.
  * @param EE_Messages_Queue $queue
  * @param string            $custom_subject  Used if a custom subject is desired for the generated aggregate EE_Message object
  */
 public function __construct($messenger_name, $message_type_name, EE_Messages_Queue $queue, $custom_subject = '')
 {
     $this->queue = $queue;
     parent::__construct($messenger_name, $message_type_name, array(), '', false, EEM_Message::status_idle);
     if ($this->valid()) {
         $this->_message->set_content($this->_get_content());
         $this->_message->set_subject($this->_get_subject($custom_subject));
     }
 }
 /**
  * Constructor
  * This instantiates the object using arguments from the given request and calling the parent constructor.
  *
  * @param   EE_Message_Resource_Manager $message_resource_manager
  * @param   EE_Request_Handler 			$request
  */
 public function __construct(EE_Message_Resource_Manager $message_resource_manager, EE_Request_Handler $request)
 {
     parent::__construct($request->get('gen_msgr'), $request->get('message_type'), array(), $request->get('context'));
     if (!$this->valid()) {
         return;
     }
     $this->_sending_messenger = $message_resource_manager->get_active_messenger($request->get('snd_msgr'));
     $this->token = $request->get('token');
     $this->_validate_request();
     $this->_data = $this->_get_data_from_request($request->get('id'));
 }
 /**
  * This simply loops through all active messengers and takes care of setting up the
  * EE_Message_To_Generate objects.
  * @param $message_type
  * @param $data
  *
  * @return EE_Message_To_Generate[]
  */
 public function setup_mtgs_for_all_active_messengers($message_type, $data)
 {
     $messages_to_generate = array();
     foreach ($this->_message_resource_manager->active_messengers() as $messenger_slug => $messenger_object) {
         $message_to_generate = new EE_Message_To_Generate($messenger_slug, $message_type, $data);
         if ($message_to_generate->valid()) {
             $messages_to_generate[] = $message_to_generate;
         }
     }
     return $messages_to_generate;
 }
 /**
  * This returns the data_handler class name for the internal message type set.
  * Note: this also verifies that the data handler class exists.  If it doesn't then $_valid is set to false
  * and the data_handler_class name is set to an empty string.
  *
  * @param   bool    $preview    Used to indicate that the preview data handler is to be returned.
  * @return  string
  */
 public function get_data_handler_class_name($preview = false)
 {
     if ($this->_data_handler_class_name === '' && $this->valid()) {
         $ref = $preview ? 'Preview' : $this->_message_type->get_data_handler($this->_data);
         //make sure internal data is updated.
         $this->_data = $this->_message_type->get_data();
         //verify
         $this->_data_handler_class_name = EE_Message_To_Generate::verify_and_retrieve_class_name_for_data_handler_reference($ref);
         if ($this->_data_handler_class_name === '') {
             $this->_valid = false;
         }
     }
     return $this->_data_handler_class_name;
 }
 /**
  * The queued EE_Message for generation does not save the data used for generation as objects
  * because serialization of those objects could be problematic if the data is saved to the db.
  * So this method calls the static method on the associated data_handler for the given message_type
  * and that preps the data for later instantiation when generating.
  *
  * @param EE_Message_To_Generate $message_to_generate
  * @param bool                   $preview Indicate whether this is being used for a preview or not.
  * @return mixed Prepped data for persisting to the queue.  false is returned if unable to prep data.
  */
 protected function _prepare_data_for_queue(EE_Message_To_Generate $message_to_generate, $preview)
 {
     /** @type EE_Messages_incoming_data $data_handler - well not really... just the class name actually */
     $data_handler = $message_to_generate->get_data_handler_class_name($preview);
     if (!$message_to_generate->valid()) {
         return false;
         //unable to get the data because the info in the EE_Message_To_Generate class is invalid.
     }
     return $data_handler::convert_data_for_persistent_storage($message_to_generate->data());
 }