/** * * @param array $props_n_values * @param string $timezone * @param array $date_formats incoming date formats in an array. First value is the date_format, second is time format. * @return EE_Message */ public static function new_instance($props_n_values = array(), $timezone = null, $date_formats = array()) { $has_object = parent::_check_for_object($props_n_values, __CLASS__); //if object doesn't exist, let's generate a unique token on instantiation so that its available even before saving to db. if (!$has_object) { EE_Registry::instance()->load_helper('URL'); $props_n_values['MSG_token'] = EEH_URL::generate_unique_token(); } return $has_object ? $has_object : new self($props_n_values, false, $timezone, $date_formats); }
/** * Private constructor to prevent direct creation. * * @param string $timezone string representing the timezone we want to set for returned Date Time Strings (and * any incoming timezone data that gets saved). Note this just sends the timezone info to the * date time model field objects. Default is null (and will be assumed using the set timezone * in the 'timezone_string' wp option) * * @return EEM_Message */ protected function __construct($timezone = null) { $this->singular_item = __('Message', 'event_espresso'); $this->plural_item = __('Messages', 'event_espresso'); //used for token generator EE_Registry::instance()->load_helper('URL'); $this->_tables = array('Message' => new EE_Primary_Table('esp_message', 'MSG_ID')); $allowed_priority = array(self::priority_high => __('high', 'event_espresso'), self::priority_medium => __('medium', 'event_espresso'), self::priority_low => __('low', 'event_espresso')); $this->_fields = array('Message' => array('MSG_ID' => new EE_Primary_Key_Int_Field('MSG_ID', __('Message ID', 'event_espresso')), 'MSG_token' => new EE_Plain_Text_Field('MSG_token', __('Unique Token used to represent this row in publicly viewable contexts (eg. a url).', 'event_espresso'), false, EEH_URL::generate_unique_token()), 'GRP_ID' => new EE_Foreign_Key_Int_Field('GRP_ID', __('Foreign key to the EEM_Message_Template_Group table.', 'event_espresso'), true, 0, 'Message_Template_Group'), 'TXN_ID' => new EE_Foreign_Key_Int_Field('TXN_ID', __('Foreign key to the related EE_Transaction. This is required to give context for regenerating the specific message', 'event_espresso'), true, 0, 'Transaction'), 'MSG_messenger' => new EE_Plain_Text_Field('MSG_messenger', __('Corresponds to the EE_messenger::name used to send this message. This will also be used to attempt any resending of the message.', 'event_espresso'), false, 'email'), 'MSG_message_type' => new EE_Plain_Text_Field('MSG_message_type', __('Corresponds to the EE_message_type::name used to generate this message.', 'event_espresso'), false, 'receipt'), 'MSG_context' => new EE_Plain_Text_Field('MSG_context', __('Context', 'event_espresso'), false), 'MSG_recipient_ID' => new EE_Foreign_Key_Int_Field('MSG_recipient_ID', __('Recipient ID', 'event_espresso'), true, null, array('Registration', 'Attendee', 'WP_User')), 'MSG_recipient_type' => new EE_Any_Foreign_Model_Name_Field('MSG_recipient_type', __('Recipient Type', 'event_espresso'), true, null, array('Registration', 'Attendee', 'WP_User')), 'MSG_content' => new EE_Maybe_Serialized_Text_Field('MSG_content', __('Content', 'event_espresso'), true, ''), 'MSG_to' => new EE_Maybe_Serialized_Text_Field('MSG_to', __('Address To', 'event_espresso'), true), 'MSG_from' => new EE_Maybe_Serialized_Text_Field('MSG_from', __('Address From', 'event_espresso'), true), 'MSG_subject' => new EE_Maybe_Serialized_Text_Field('MSG_subject', __('Subject', 'event_espresso'), true, ''), 'MSG_priority' => new EE_Enum_Integer_Field('MSG_priority', __('Priority', 'event_espresso'), false, self::priority_low, $allowed_priority), 'STS_ID' => new EE_Foreign_Key_String_Field('STS_ID', __('Status', 'event_espresso'), false, self::status_incomplete, 'Status'), 'MSG_created' => new EE_Datetime_Field('MSG_created', __('Created', 'event_espresso'), false, time()), 'MSG_modified' => new EE_Datetime_Field('MSG_modified', __('Modified', 'event_espresso'), true, time()))); $this->_model_relations = array('Attendee' => new EE_Belongs_To_Any_Relation(), 'Registration' => new EE_Belongs_To_Any_Relation(), 'WP_User' => new EE_Belongs_To_Any_Relation(), 'Message_Template_Group' => new EE_Belongs_To_Relation(), 'Transaction' => new EE_Belongs_To_Relation()); parent::__construct($timezone); }