Completed
Branch models-cleanup/model-relations (db5ca7)
by
unknown
13:03 queued 08:35
created
core/libraries/messages/EE_Message_Type_Collection.lib.php 2 patches
Indentation   +164 added lines, -164 removed lines patch added patch discarded remove patch
@@ -14,168 +14,168 @@
 block discarded – undo
14 14
 class EE_Message_Type_Collection extends EE_Object_Collection
15 15
 {
16 16
 
17
-    /**
18
-     * EE_Message_Type_Collection constructor.
19
-     */
20
-    public function __construct()
21
-    {
22
-        $this->interface = 'EE_message_type';
23
-    }
24
-
25
-
26
-
27
-    /**
28
-     * add
29
-     *
30
-     * attaches an object to the Collection
31
-     * and sets any supplied data associated with the current iterator entry
32
-     * by calling EE_Object_Collection::set_info()
33
-     *
34
-     * @access public
35
-     * @param object $object
36
-     * @param mixed  $info
37
-     * @return bool
38
-     */
39
-    public function add($object, $info = null)
40
-    {
41
-        $info = empty($info) && $object instanceof $this->interface ? $object->name : $info;
42
-        return parent::add($object, $info);
43
-    }
44
-
45
-
46
-
47
-    /**
48
-     * set_info
49
-     *
50
-     * Sets the data associated with an object in the Collection
51
-     * if no $info is supplied, then the spl_object_hash() is used
52
-     *
53
-     * @access public
54
-     * @param object $object
55
-     * @param mixed  $info
56
-     * @return bool
57
-     */
58
-    public function set_info($object, $info = null)
59
-    {
60
-        $info = empty($info) && $object instanceof $this->interface ? $object->name : $info;
61
-        return parent::set_info($object, $info);
62
-    }
63
-
64
-
65
-
66
-    /**
67
-     * get_by_info
68
-     *
69
-     * finds and returns an object in the Collection based on the info that was set using addObject()
70
-     * PLZ NOTE: the pointer is reset to the beginning of the collection before returning
71
-     *
72
-     * @access public
73
-     * @param mixed
74
-     * @return null | object
75
-     */
76
-    public function get_by_info($info)
77
-    {
78
-        return parent::get_by_info(str_replace(' ', '_', strtolower($info)));
79
-    }
80
-
81
-
82
-
83
-    /**
84
-     * has
85
-     *
86
-     * returns TRUE or FALSE depending on whether the supplied object is within the Collection
87
-     *
88
-     * @access public
89
-     * @param object $object
90
-     * @return bool
91
-     */
92
-    public function has($object)
93
-    {
94
-        return parent::has($object);
95
-    }
96
-
97
-
98
-
99
-    /**
100
-     * has_by_name
101
-     *
102
-     * returns TRUE or FALSE depending on whether the supplied message_type classname is within the Collection
103
-     *
104
-     * @access public
105
-     * @param string $message_type_name
106
-     * @return bool
107
-     */
108
-    public function has_by_name($message_type_name)
109
-    {
110
-        return $this->get_by_info($message_type_name) instanceof $this->interface ? true : false;
111
-    }
112
-
113
-
114
-
115
-    /**
116
-     * remove
117
-     *
118
-     * detaches an object from the Collection
119
-     *
120
-     * @access public
121
-     * @param $object
122
-     * @return bool
123
-     */
124
-    public function remove($object)
125
-    {
126
-        return parent::remove($object);
127
-    }
128
-
129
-
130
-
131
-    /**
132
-     * set_current
133
-     *
134
-     * advances pointer to the provided object
135
-     *
136
-     * @access public
137
-     * @param $object
138
-     * @return void
139
-     */
140
-    public function set_current($object)
141
-    {
142
-        parent::set_current($object);
143
-    }
144
-
145
-
146
-
147
-    /**
148
-     * set_current_by_info
149
-     *
150
-     * advances pointer to the object whose info matches that which was provided
151
-     *
152
-     * @access public
153
-     * @param $info
154
-     * @return void
155
-     */
156
-    public function set_current_by_info($info)
157
-    {
158
-        parent::set_current_by_info($info);
159
-    }
160
-
161
-
162
-
163
-    /**
164
-     * show_collection_classes
165
-     *
166
-     * displays list of collection classes if WP_DEBUG is on
167
-     *
168
-     * @access public
169
-     * @return void
170
-     */
171
-    public function show_collection_classes()
172
-    {
173
-        if (WP_DEBUG) {
174
-            $this->rewind();
175
-            while ($this->valid()) {
176
-                echo '<h5 style="color:#2EA2CC;">' . __CLASS__ . ' class : <span style="color:#E76700">' . $this->getInfo() . '</span></h5>';
177
-                $this->next();
178
-            }
179
-        }
180
-    }
17
+	/**
18
+	 * EE_Message_Type_Collection constructor.
19
+	 */
20
+	public function __construct()
21
+	{
22
+		$this->interface = 'EE_message_type';
23
+	}
24
+
25
+
26
+
27
+	/**
28
+	 * add
29
+	 *
30
+	 * attaches an object to the Collection
31
+	 * and sets any supplied data associated with the current iterator entry
32
+	 * by calling EE_Object_Collection::set_info()
33
+	 *
34
+	 * @access public
35
+	 * @param object $object
36
+	 * @param mixed  $info
37
+	 * @return bool
38
+	 */
39
+	public function add($object, $info = null)
40
+	{
41
+		$info = empty($info) && $object instanceof $this->interface ? $object->name : $info;
42
+		return parent::add($object, $info);
43
+	}
44
+
45
+
46
+
47
+	/**
48
+	 * set_info
49
+	 *
50
+	 * Sets the data associated with an object in the Collection
51
+	 * if no $info is supplied, then the spl_object_hash() is used
52
+	 *
53
+	 * @access public
54
+	 * @param object $object
55
+	 * @param mixed  $info
56
+	 * @return bool
57
+	 */
58
+	public function set_info($object, $info = null)
59
+	{
60
+		$info = empty($info) && $object instanceof $this->interface ? $object->name : $info;
61
+		return parent::set_info($object, $info);
62
+	}
63
+
64
+
65
+
66
+	/**
67
+	 * get_by_info
68
+	 *
69
+	 * finds and returns an object in the Collection based on the info that was set using addObject()
70
+	 * PLZ NOTE: the pointer is reset to the beginning of the collection before returning
71
+	 *
72
+	 * @access public
73
+	 * @param mixed
74
+	 * @return null | object
75
+	 */
76
+	public function get_by_info($info)
77
+	{
78
+		return parent::get_by_info(str_replace(' ', '_', strtolower($info)));
79
+	}
80
+
81
+
82
+
83
+	/**
84
+	 * has
85
+	 *
86
+	 * returns TRUE or FALSE depending on whether the supplied object is within the Collection
87
+	 *
88
+	 * @access public
89
+	 * @param object $object
90
+	 * @return bool
91
+	 */
92
+	public function has($object)
93
+	{
94
+		return parent::has($object);
95
+	}
96
+
97
+
98
+
99
+	/**
100
+	 * has_by_name
101
+	 *
102
+	 * returns TRUE or FALSE depending on whether the supplied message_type classname is within the Collection
103
+	 *
104
+	 * @access public
105
+	 * @param string $message_type_name
106
+	 * @return bool
107
+	 */
108
+	public function has_by_name($message_type_name)
109
+	{
110
+		return $this->get_by_info($message_type_name) instanceof $this->interface ? true : false;
111
+	}
112
+
113
+
114
+
115
+	/**
116
+	 * remove
117
+	 *
118
+	 * detaches an object from the Collection
119
+	 *
120
+	 * @access public
121
+	 * @param $object
122
+	 * @return bool
123
+	 */
124
+	public function remove($object)
125
+	{
126
+		return parent::remove($object);
127
+	}
128
+
129
+
130
+
131
+	/**
132
+	 * set_current
133
+	 *
134
+	 * advances pointer to the provided object
135
+	 *
136
+	 * @access public
137
+	 * @param $object
138
+	 * @return void
139
+	 */
140
+	public function set_current($object)
141
+	{
142
+		parent::set_current($object);
143
+	}
144
+
145
+
146
+
147
+	/**
148
+	 * set_current_by_info
149
+	 *
150
+	 * advances pointer to the object whose info matches that which was provided
151
+	 *
152
+	 * @access public
153
+	 * @param $info
154
+	 * @return void
155
+	 */
156
+	public function set_current_by_info($info)
157
+	{
158
+		parent::set_current_by_info($info);
159
+	}
160
+
161
+
162
+
163
+	/**
164
+	 * show_collection_classes
165
+	 *
166
+	 * displays list of collection classes if WP_DEBUG is on
167
+	 *
168
+	 * @access public
169
+	 * @return void
170
+	 */
171
+	public function show_collection_classes()
172
+	{
173
+		if (WP_DEBUG) {
174
+			$this->rewind();
175
+			while ($this->valid()) {
176
+				echo '<h5 style="color:#2EA2CC;">' . __CLASS__ . ' class : <span style="color:#E76700">' . $this->getInfo() . '</span></h5>';
177
+				$this->next();
178
+			}
179
+		}
180
+	}
181 181
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -173,7 +173,7 @@
 block discarded – undo
173 173
         if (WP_DEBUG) {
174 174
             $this->rewind();
175 175
             while ($this->valid()) {
176
-                echo '<h5 style="color:#2EA2CC;">' . __CLASS__ . ' class : <span style="color:#E76700">' . $this->getInfo() . '</span></h5>';
176
+                echo '<h5 style="color:#2EA2CC;">'.__CLASS__.' class : <span style="color:#E76700">'.$this->getInfo().'</span></h5>';
177 177
                 $this->next();
178 178
             }
179 179
         }
Please login to merge, or discard this patch.
messages/defaults/default/html_receipt_ticket_line_item_no_pms.template.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -6,7 +6,7 @@
 block discarded – undo
6 6
 <tr class="item">
7 7
     <td>[LINE_ITEM_NAME][LINE_ITEM_TAXABLE_*]</td>
8 8
     <td colspan="2">[LINE_ITEM_DESCRIPTION]
9
-        <p class="ticket-note"><?php echo sprintf(__('This ticket can be used once at %s of the dates/times below.', 'event_espresso'), '[TKT_USES_* schema=' . __('any', 'event_espresso') . ']'); ?></p>
9
+        <p class="ticket-note"><?php echo sprintf(__('This ticket can be used once at %s of the dates/times below.', 'event_espresso'), '[TKT_USES_* schema='.__('any', 'event_espresso').']'); ?></p>
10 10
     </td>
11 11
     <td class="item_c">[LINE_ITEM_QUANTITY]</td>
12 12
     <td class="item_c">[LINE_ITEM_AMOUNT]</td>
Please login to merge, or discard this patch.
libraries/messages/defaults/default/html_receipt_ticket_list.template.php 1 patch
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -22,13 +22,13 @@  discard block
 block discarded – undo
22 22
         <div class="ticket-time-and-place-details">
23 23
             <div class="ticket-time-details">
24 24
                 <h4 class="sub-section-title no-bottom-margin">
25
-                    <img class="icon" src="<?php echo EE_IMAGES_URL . 'clock-16x16.png'; ?>"><?php _e('Date/Time:', 'event_espresso'); ?>
25
+                    <img class="icon" src="<?php echo EE_IMAGES_URL.'clock-16x16.png'; ?>"><?php _e('Date/Time:', 'event_espresso'); ?>
26 26
                 </h4>
27 27
                 <ul class="event-dates">[DATETIME_LIST]</ul>
28 28
             </div>
29 29
             <div class="ticket-place-details">
30 30
                 <h4 class="sub-section-title no-bottom-margin">
31
-                    <img class="icon" src="<?php echo EE_IMAGES_URL . 'location-pin-16x16.png'; ?>"><?php _e('Venue', 'event_espresso'); ?>
31
+                    <img class="icon" src="<?php echo EE_IMAGES_URL.'location-pin-16x16.png'; ?>"><?php _e('Venue', 'event_espresso'); ?>
32 32
                 </h4>
33 33
                 <ul class="event-venues">
34 34
                     <li>[VENUE_TITLE]
@@ -39,7 +39,7 @@  discard block
 block discarded – undo
39 39
         </div>
40 40
         <div class="ticket-registrations-area">
41 41
             <h4 class="sub-section-title">
42
-                <img class="icon" src="<?php echo EE_IMAGES_URL . 'users-16x16.png'; ?>"><?php _e("Registration Details", "event_espresso"); ?>
42
+                <img class="icon" src="<?php echo EE_IMAGES_URL.'users-16x16.png'; ?>"><?php _e("Registration Details", "event_espresso"); ?>
43 43
                 <span class="small-text link">( <a class="print_button noPrint" href="[PRIMARY_REGISTRANT_FRONTEND_EDIT_REG_LINK]"><?php _e('edit', 'event_espresso'); ?></a> )</span>
44 44
             </h4>
45 45
             <ul class="ticket-registrations-list">[ATTENDEE_LIST]</ul>
Please login to merge, or discard this patch.
libraries/messages/defaults/default/html_receipt_attendee_list.template.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -6,11 +6,11 @@
 block discarded – undo
6 6
 <li class="ticket-registration">
7 7
     <table class="registration-details">
8 8
         <tr class="odd">
9
-            <th><?php	_e('Attendee', 'event_espresso');?></th>
9
+            <th><?php	_e('Attendee', 'event_espresso'); ?></th>
10 10
             <td>[FNAME] [LNAME] ([ATTENDEE_EMAIL])</td>
11 11
         </tr>
12 12
         <tr>
13
-            <th><?php _e("Registration Code:", "event_espresso");?></th>
13
+            <th><?php _e("Registration Code:", "event_espresso"); ?></th>
14 14
             <td>[REGISTRATION_CODE] - <span class="[REGISTRATION_STATUS_ID]">[REGISTRATION_STATUS_LABEL]</span></td>
15 15
         </tr>
16 16
     </table>
Please login to merge, or discard this patch.
core/libraries/messages/defaults/EE_Messages_Template_Defaults.lib.php 2 patches
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -113,9 +113,9 @@  discard block
 block discarded – undo
113 113
         // get the corresponding template pack object (if present.  If not then we just load the default and add a
114 114
         // notice).  The class name should be something like 'EE_Messages_Template_Pack_Default' where "default' would be
115 115
         // the incoming template pack reference.
116
-        $class_name = 'EE_Messages_Template_Pack_' . str_replace(' ', '_', ucwords(str_replace('_', ' ', $template_pack)));
116
+        $class_name = 'EE_Messages_Template_Pack_'.str_replace(' ', '_', ucwords(str_replace('_', ' ', $template_pack)));
117 117
 
118
-        if (! class_exists($class_name)) {
118
+        if ( ! class_exists($class_name)) {
119 119
             EE_Error::add_error(
120 120
                 sprintf(
121 121
                     __(
@@ -160,7 +160,7 @@  discard block
 block discarded – undo
160 160
     {
161 161
         $template_pack = 'default';
162 162
         // if we have the GRP_ID then let's use that to see if there is a set template pack and use that for the new templates.
163
-        if (! empty($this->_GRP_ID)) {
163
+        if ( ! empty($this->_GRP_ID)) {
164 164
             $message_template_group = $this->_message_template_group_model->get_one_by_ID($this->_GRP_ID);
165 165
             $template_pack = $message_template_group instanceof EE_Message_Template_Group
166 166
                 ? $message_template_group->get_template_pack_name()
@@ -206,17 +206,17 @@  discard block
 block discarded – undo
206 206
             $this->_GRP_ID = $grp_id;
207 207
         }
208 208
 
209
-        $template_data = array( 'GRP_ID' => $this->_GRP_ID );
209
+        $template_data = array('GRP_ID' => $this->_GRP_ID);
210 210
 
211 211
         foreach ($this->_contexts as $context => $details) {
212 212
             foreach ($this->_fields as $field => $field_type) {
213 213
                 if ($field != 'extra') {
214 214
                     $template_data['MTP_context'] = $context;
215 215
                     $template_data['MTP_template_field'] = $field;
216
-                    $template_data['MTP_content'] = $this->_templates[ $context ][ $field ];
216
+                    $template_data['MTP_content'] = $this->_templates[$context][$field];
217 217
 
218 218
                     $MTP = $this->_message_template_model->insert($template_data);
219
-                    if (! $MTP) {
219
+                    if ( ! $MTP) {
220 220
                         EE_Error::add_error(
221 221
                             sprintf(
222 222
                                 __(
Please login to merge, or discard this patch.
Indentation   +228 added lines, -228 removed lines patch added patch discarded remove patch
@@ -15,232 +15,232 @@
 block discarded – undo
15 15
 {
16 16
 
17 17
 
18
-    /**
19
-     * Used for holding the EE_Message_Template GRP_ID field value.
20
-     * @var [type]
21
-     */
22
-    protected $_GRP_ID;
23
-
24
-    /**
25
-     * holds the messenger object
26
-     *
27
-     * @var EE_messenger
28
-     */
29
-    protected $_messenger;
30
-
31
-    /**
32
-     * holds the message type object
33
-     *
34
-     * @var EE_message_type
35
-     */
36
-    protected $_message_type;
37
-
38
-    /**
39
-     * holds the fields used (this is retrieved from the messenger)
40
-     *
41
-     * @var array
42
-     */
43
-    protected $_fields;
44
-
45
-    /**
46
-     * holds the assembled template (with defaults) for creation in the database
47
-     *
48
-     * @var array
49
-     */
50
-    protected $_templates;
51
-
52
-    /**
53
-     * holds the contexts used (this is retrieved from the message type)
54
-     *
55
-     * @var array
56
-     */
57
-    protected $_contexts;
58
-
59
-
60
-    /**
61
-     *  @var EEM_Message_Template_Group
62
-     */
63
-    protected $_message_template_group_model;
64
-
65
-
66
-    /**
67
-     * @var EEM_Message_Template
68
-     */
69
-    protected $_message_template_model;
70
-
71
-
72
-    /**
73
-     * EE_Messages_Template_Defaults constructor.
74
-     *
75
-     * @param EE_messenger               $messenger
76
-     * @param EE_message_type            $message_type
77
-     * @param int                        $GRP_ID                      Optional.  If included then we're just regenerating
78
-     *                                                                the template fields for the given group not the
79
-     *                                                                message template group itself
80
-     * @param EEM_Message_Template_Group $message_template_group_model
81
-     * @param EEM_Message_Template       $message_template_model
82
-     * @throws EE_Error
83
-     */
84
-    public function __construct(
85
-        EE_messenger $messenger,
86
-        EE_message_type $message_type,
87
-        $GRP_ID = 0,
88
-        EEM_Message_Template_Group $message_template_group_model,
89
-        EEM_Message_Template $message_template_model
90
-    ) {
91
-        $this->_messenger = $messenger;
92
-        $this->_message_type = $message_type;
93
-        $this->_GRP_ID = $GRP_ID;
94
-        // set the model object
95
-        $this->_message_template_group_model = $message_template_group_model;
96
-        $this->_message_template_model = $message_template_model;
97
-        $this->_fields = $this->_messenger->get_template_fields();
98
-        $this->_contexts = $this->_message_type->get_contexts();
99
-    }
100
-
101
-
102
-    /**
103
-     * Setup the _template_data property.
104
-     * This method sets the _templates property array before templates are created.
105
-     *
106
-     * @param string $template_pack This corresponds to a template pack class reference which will contain information
107
-     *                              about where to obtain the templates.
108
-     *
109
-     */
110
-    final private function _set_templates($template_pack)
111
-    {
112
-
113
-        // get the corresponding template pack object (if present.  If not then we just load the default and add a
114
-        // notice).  The class name should be something like 'EE_Messages_Template_Pack_Default' where "default' would be
115
-        // the incoming template pack reference.
116
-        $class_name = 'EE_Messages_Template_Pack_' . str_replace(' ', '_', ucwords(str_replace('_', ' ', $template_pack)));
117
-
118
-        if (! class_exists($class_name)) {
119
-            EE_Error::add_error(
120
-                sprintf(
121
-                    __(
122
-                        'The template pack represented by a class corresponding to "%1$s" does not exist. Likely the autoloader for this class has the wrong path or the incoming reference is misspelled. The default template pack has been used to generate the templates instead.',
123
-                        'event_espresso'
124
-                    ),
125
-                    $class_name
126
-                ),
127
-                __FILE__,
128
-                __FUNCTION__,
129
-                __LINE__
130
-            );
131
-            $class_name = 'EE_Messages_Template_Pack_Default';
132
-        }
133
-        /** @type EE_Messages_Template_Pack $template_pack */
134
-        $template_pack = new $class_name();
135
-
136
-        // get all the templates from the template pack.
137
-        $this->_templates = $template_pack->get_templates($this->_messenger, $this->_message_type);
138
-    }
139
-
140
-
141
-    /**
142
-     * Return the contexts for the message type as cached on this instance.
143
-     * @return array
144
-     */
145
-    public function get_contexts()
146
-    {
147
-        return $this->_contexts;
148
-    }
149
-
150
-
151
-
152
-
153
-
154
-    /**
155
-     * public facing create new templates method
156
-     *
157
-     * @return mixed (array|bool)            success array or false.
158
-     */
159
-    public function create_new_templates()
160
-    {
161
-        $template_pack = 'default';
162
-        // if we have the GRP_ID then let's use that to see if there is a set template pack and use that for the new templates.
163
-        if (! empty($this->_GRP_ID)) {
164
-            $message_template_group = $this->_message_template_group_model->get_one_by_ID($this->_GRP_ID);
165
-            $template_pack = $message_template_group instanceof EE_Message_Template_Group
166
-                ? $message_template_group->get_template_pack_name()
167
-                : 'default';
168
-            // we also need to reset the template variation to default
169
-            $message_template_group->set_template_pack_variation('default');
170
-        }
171
-        return $this->_create_new_templates($template_pack);
172
-    }
173
-
174
-
175
-
176
-
177
-
178
-    /**
179
-     *  Handles creating new default templates.
180
-     *
181
-     * @param string $template_pack This corresponds to a template pack class reference
182
-     *                              which will contain information about where to obtain the templates.
183
-     * @return mixed (array|bool)   success array or false.
184
-     */
185
-    protected function _create_new_templates($template_pack)
186
-    {
187
-
188
-        $this->_set_templates($template_pack);
189
-
190
-        // necessary properties are set, let's save the default templates
191
-        if (empty($this->_GRP_ID)) {
192
-            $main_template_data = array(
193
-                'MTP_messenger'    => $this->_messenger->name,
194
-                'MTP_message_type' => $this->_message_type->name,
195
-                'MTP_is_override'  => 0,
196
-                'MTP_deleted'      => 0,
197
-                'MTP_is_global'    => 1,
198
-                'MTP_user_id'      => EEH_Activation::get_default_creator_id(),
199
-                'MTP_is_active'    => 1,
200
-            );
201
-            // let's insert the above and get our GRP_ID, then reset the template data array to just include the GRP_ID
202
-            $grp_id = $this->_message_template_group_model->insert($main_template_data);
203
-            if (empty($grp_id)) {
204
-                return $grp_id;
205
-            }
206
-            $this->_GRP_ID = $grp_id;
207
-        }
208
-
209
-        $template_data = array( 'GRP_ID' => $this->_GRP_ID );
210
-
211
-        foreach ($this->_contexts as $context => $details) {
212
-            foreach ($this->_fields as $field => $field_type) {
213
-                if ($field != 'extra') {
214
-                    $template_data['MTP_context'] = $context;
215
-                    $template_data['MTP_template_field'] = $field;
216
-                    $template_data['MTP_content'] = $this->_templates[ $context ][ $field ];
217
-
218
-                    $MTP = $this->_message_template_model->insert($template_data);
219
-                    if (! $MTP) {
220
-                        EE_Error::add_error(
221
-                            sprintf(
222
-                                __(
223
-                                    'There was an error in saving new template data for %1$s messenger, %2$s message type, %3$s context and %4$s template field.',
224
-                                    'event_espresso'
225
-                                ),
226
-                                $this->_messenger->name,
227
-                                $this->_message_type->name,
228
-                                $context,
229
-                                $field
230
-                            ),
231
-                            __FILE__,
232
-                            __FUNCTION__,
233
-                            __LINE__
234
-                        );
235
-                        return false;
236
-                    }
237
-                }
238
-            }
239
-        }
240
-
241
-        return array(
242
-            'GRP_ID'      => $this->_GRP_ID,
243
-            'MTP_context' => key($this->_contexts)
244
-        );
245
-    }
18
+	/**
19
+	 * Used for holding the EE_Message_Template GRP_ID field value.
20
+	 * @var [type]
21
+	 */
22
+	protected $_GRP_ID;
23
+
24
+	/**
25
+	 * holds the messenger object
26
+	 *
27
+	 * @var EE_messenger
28
+	 */
29
+	protected $_messenger;
30
+
31
+	/**
32
+	 * holds the message type object
33
+	 *
34
+	 * @var EE_message_type
35
+	 */
36
+	protected $_message_type;
37
+
38
+	/**
39
+	 * holds the fields used (this is retrieved from the messenger)
40
+	 *
41
+	 * @var array
42
+	 */
43
+	protected $_fields;
44
+
45
+	/**
46
+	 * holds the assembled template (with defaults) for creation in the database
47
+	 *
48
+	 * @var array
49
+	 */
50
+	protected $_templates;
51
+
52
+	/**
53
+	 * holds the contexts used (this is retrieved from the message type)
54
+	 *
55
+	 * @var array
56
+	 */
57
+	protected $_contexts;
58
+
59
+
60
+	/**
61
+	 *  @var EEM_Message_Template_Group
62
+	 */
63
+	protected $_message_template_group_model;
64
+
65
+
66
+	/**
67
+	 * @var EEM_Message_Template
68
+	 */
69
+	protected $_message_template_model;
70
+
71
+
72
+	/**
73
+	 * EE_Messages_Template_Defaults constructor.
74
+	 *
75
+	 * @param EE_messenger               $messenger
76
+	 * @param EE_message_type            $message_type
77
+	 * @param int                        $GRP_ID                      Optional.  If included then we're just regenerating
78
+	 *                                                                the template fields for the given group not the
79
+	 *                                                                message template group itself
80
+	 * @param EEM_Message_Template_Group $message_template_group_model
81
+	 * @param EEM_Message_Template       $message_template_model
82
+	 * @throws EE_Error
83
+	 */
84
+	public function __construct(
85
+		EE_messenger $messenger,
86
+		EE_message_type $message_type,
87
+		$GRP_ID = 0,
88
+		EEM_Message_Template_Group $message_template_group_model,
89
+		EEM_Message_Template $message_template_model
90
+	) {
91
+		$this->_messenger = $messenger;
92
+		$this->_message_type = $message_type;
93
+		$this->_GRP_ID = $GRP_ID;
94
+		// set the model object
95
+		$this->_message_template_group_model = $message_template_group_model;
96
+		$this->_message_template_model = $message_template_model;
97
+		$this->_fields = $this->_messenger->get_template_fields();
98
+		$this->_contexts = $this->_message_type->get_contexts();
99
+	}
100
+
101
+
102
+	/**
103
+	 * Setup the _template_data property.
104
+	 * This method sets the _templates property array before templates are created.
105
+	 *
106
+	 * @param string $template_pack This corresponds to a template pack class reference which will contain information
107
+	 *                              about where to obtain the templates.
108
+	 *
109
+	 */
110
+	final private function _set_templates($template_pack)
111
+	{
112
+
113
+		// get the corresponding template pack object (if present.  If not then we just load the default and add a
114
+		// notice).  The class name should be something like 'EE_Messages_Template_Pack_Default' where "default' would be
115
+		// the incoming template pack reference.
116
+		$class_name = 'EE_Messages_Template_Pack_' . str_replace(' ', '_', ucwords(str_replace('_', ' ', $template_pack)));
117
+
118
+		if (! class_exists($class_name)) {
119
+			EE_Error::add_error(
120
+				sprintf(
121
+					__(
122
+						'The template pack represented by a class corresponding to "%1$s" does not exist. Likely the autoloader for this class has the wrong path or the incoming reference is misspelled. The default template pack has been used to generate the templates instead.',
123
+						'event_espresso'
124
+					),
125
+					$class_name
126
+				),
127
+				__FILE__,
128
+				__FUNCTION__,
129
+				__LINE__
130
+			);
131
+			$class_name = 'EE_Messages_Template_Pack_Default';
132
+		}
133
+		/** @type EE_Messages_Template_Pack $template_pack */
134
+		$template_pack = new $class_name();
135
+
136
+		// get all the templates from the template pack.
137
+		$this->_templates = $template_pack->get_templates($this->_messenger, $this->_message_type);
138
+	}
139
+
140
+
141
+	/**
142
+	 * Return the contexts for the message type as cached on this instance.
143
+	 * @return array
144
+	 */
145
+	public function get_contexts()
146
+	{
147
+		return $this->_contexts;
148
+	}
149
+
150
+
151
+
152
+
153
+
154
+	/**
155
+	 * public facing create new templates method
156
+	 *
157
+	 * @return mixed (array|bool)            success array or false.
158
+	 */
159
+	public function create_new_templates()
160
+	{
161
+		$template_pack = 'default';
162
+		// if we have the GRP_ID then let's use that to see if there is a set template pack and use that for the new templates.
163
+		if (! empty($this->_GRP_ID)) {
164
+			$message_template_group = $this->_message_template_group_model->get_one_by_ID($this->_GRP_ID);
165
+			$template_pack = $message_template_group instanceof EE_Message_Template_Group
166
+				? $message_template_group->get_template_pack_name()
167
+				: 'default';
168
+			// we also need to reset the template variation to default
169
+			$message_template_group->set_template_pack_variation('default');
170
+		}
171
+		return $this->_create_new_templates($template_pack);
172
+	}
173
+
174
+
175
+
176
+
177
+
178
+	/**
179
+	 *  Handles creating new default templates.
180
+	 *
181
+	 * @param string $template_pack This corresponds to a template pack class reference
182
+	 *                              which will contain information about where to obtain the templates.
183
+	 * @return mixed (array|bool)   success array or false.
184
+	 */
185
+	protected function _create_new_templates($template_pack)
186
+	{
187
+
188
+		$this->_set_templates($template_pack);
189
+
190
+		// necessary properties are set, let's save the default templates
191
+		if (empty($this->_GRP_ID)) {
192
+			$main_template_data = array(
193
+				'MTP_messenger'    => $this->_messenger->name,
194
+				'MTP_message_type' => $this->_message_type->name,
195
+				'MTP_is_override'  => 0,
196
+				'MTP_deleted'      => 0,
197
+				'MTP_is_global'    => 1,
198
+				'MTP_user_id'      => EEH_Activation::get_default_creator_id(),
199
+				'MTP_is_active'    => 1,
200
+			);
201
+			// let's insert the above and get our GRP_ID, then reset the template data array to just include the GRP_ID
202
+			$grp_id = $this->_message_template_group_model->insert($main_template_data);
203
+			if (empty($grp_id)) {
204
+				return $grp_id;
205
+			}
206
+			$this->_GRP_ID = $grp_id;
207
+		}
208
+
209
+		$template_data = array( 'GRP_ID' => $this->_GRP_ID );
210
+
211
+		foreach ($this->_contexts as $context => $details) {
212
+			foreach ($this->_fields as $field => $field_type) {
213
+				if ($field != 'extra') {
214
+					$template_data['MTP_context'] = $context;
215
+					$template_data['MTP_template_field'] = $field;
216
+					$template_data['MTP_content'] = $this->_templates[ $context ][ $field ];
217
+
218
+					$MTP = $this->_message_template_model->insert($template_data);
219
+					if (! $MTP) {
220
+						EE_Error::add_error(
221
+							sprintf(
222
+								__(
223
+									'There was an error in saving new template data for %1$s messenger, %2$s message type, %3$s context and %4$s template field.',
224
+									'event_espresso'
225
+								),
226
+								$this->_messenger->name,
227
+								$this->_message_type->name,
228
+								$context,
229
+								$field
230
+							),
231
+							__FILE__,
232
+							__FUNCTION__,
233
+							__LINE__
234
+						);
235
+						return false;
236
+					}
237
+				}
238
+			}
239
+		}
240
+
241
+		return array(
242
+			'GRP_ID'      => $this->_GRP_ID,
243
+			'MTP_context' => key($this->_contexts)
244
+		);
245
+	}
246 246
 }
Please login to merge, or discard this patch.
core/libraries/messages/EE_Messages_Template_Pack_Collection.lib.php 1 patch
Indentation   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -11,19 +11,19 @@
 block discarded – undo
11 11
 {
12 12
 
13 13
 
14
-    public function __construct()
15
-    {
16
-        $this->interface = 'EE_Messages_Template_Pack';
17
-    }
14
+	public function __construct()
15
+	{
16
+		$this->interface = 'EE_Messages_Template_Pack';
17
+	}
18 18
 
19
-    public function get_by_name($template_pack_name)
20
-    {
21
-        $this->rewind();
22
-        while ($this->valid()) {
23
-            if ($this->current()->dbref == $template_pack_name) {
24
-                return $this->current();
25
-            }
26
-            $this->next();
27
-        }
28
-    }
19
+	public function get_by_name($template_pack_name)
20
+	{
21
+		$this->rewind();
22
+		while ($this->valid()) {
23
+			if ($this->current()->dbref == $template_pack_name) {
24
+				return $this->current();
25
+			}
26
+			$this->next();
27
+		}
28
+	}
29 29
 }
Please login to merge, or discard this patch.
core/libraries/messages/EE_Message_Factory.lib.php 2 patches
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -51,7 +51,7 @@  discard block
 block discarded – undo
51 51
     public static function instance(EE_Message_Resource_Manager $Message_Resource_Manager)
52 52
     {
53 53
         // check if class object is instantiated, and instantiated properly
54
-        if (! self::$_instance instanceof EE_Message_Factory) {
54
+        if ( ! self::$_instance instanceof EE_Message_Factory) {
55 55
             self::$_instance = new EE_Message_Factory($Message_Resource_Manager);
56 56
         }
57 57
         return self::$_instance;
@@ -127,7 +127,7 @@  discard block
 block discarded – undo
127 127
     protected function _create($props_n_values = array())
128 128
     {
129 129
         $new_instance = false;
130
-        if (! empty($props_n_values['MSG_ID'])) {
130
+        if ( ! empty($props_n_values['MSG_ID'])) {
131 131
             $message = EE_Message::new_instance_from_db($props_n_values);
132 132
         } else {
133 133
             $message = EE_Message::new_instance($props_n_values);
Please login to merge, or discard this patch.
Indentation   +171 added lines, -171 removed lines patch added patch discarded remove patch
@@ -15,175 +15,175 @@
 block discarded – undo
15 15
 {
16 16
 
17 17
 
18
-    /**
19
-     * @type EE_Message_Factory $_instance
20
-     */
21
-    protected static $_instance;
22
-
23
-
24
-    /**
25
-     * @type EE_Message_Resource_Manager $_message_resource_manager
26
-     */
27
-    protected $_message_resource_manager;
28
-
29
-
30
-
31
-    /**
32
-     * EE_Message_Factory constructor.
33
-     *
34
-     * @access protected
35
-     * @param \EE_Message_Resource_Manager $Message_Resource_Manager
36
-     */
37
-    protected function __construct(
38
-        EE_Message_Resource_Manager $Message_Resource_Manager
39
-    ) {
40
-        $this->_message_resource_manager = $Message_Resource_Manager;
41
-    }
42
-
43
-
44
-
45
-    /**
46
-     * @singleton method used to instantiate class object
47
-     * @access    public
48
-     * @param \EE_Message_Resource_Manager $Message_Resource_Manager
49
-     * @return \EE_Message_Factory instance
50
-     */
51
-    public static function instance(EE_Message_Resource_Manager $Message_Resource_Manager)
52
-    {
53
-        // check if class object is instantiated, and instantiated properly
54
-        if (! self::$_instance instanceof EE_Message_Factory) {
55
-            self::$_instance = new EE_Message_Factory($Message_Resource_Manager);
56
-        }
57
-        return self::$_instance;
58
-    }
59
-
60
-
61
-
62
-    /**
63
-     * @access public
64
-     * @param  array $props_n_values
65
-     * @return EE_Message
66
-     */
67
-    public static function create($props_n_values = array())
68
-    {
69
-        /** @type EE_Message_Factory $Message_Factory */
70
-        $Message_Factory = EE_Registry::instance()->load_lib('Message_Factory');
71
-        return $Message_Factory->_create($props_n_values);
72
-    }
73
-
74
-
75
-
76
-    /**
77
-     * @access public
78
-     * @param  \EE_Message $message
79
-     * @return \EE_Message
80
-     * @throws \EE_Error
81
-     */
82
-    public static function set_messenger_and_message_type(EE_Message $message)
83
-    {
84
-        /** @type EE_Message_Factory $Message_Factory */
85
-        $Message_Factory = EE_Registry::instance()->load_lib('Message_Factory');
86
-        return $Message_Factory->_set_messenger_and_message_type($message);
87
-    }
88
-
89
-
90
-
91
-    /**
92
-     * @access public
93
-     * @param  \EE_Message $message
94
-     * @return \EE_Message
95
-     * @throws \EE_Error
96
-     */
97
-    public static function set_messenger(EE_Message $message)
98
-    {
99
-        /** @type EE_Message_Factory $Message_Factory */
100
-        $Message_Factory = EE_Registry::instance()->load_lib('Message_Factory');
101
-        return $Message_Factory->_set_messenger($message);
102
-    }
103
-
104
-
105
-
106
-    /**
107
-     * @access public
108
-     * @param  \EE_Message $message
109
-     * @return \EE_Message
110
-     * @throws \EE_Error
111
-     */
112
-    public static function set_message_type(EE_Message $message)
113
-    {
114
-        /** @type EE_Message_Factory $Message_Factory */
115
-        $Message_Factory = EE_Registry::instance()->load_lib('Message_Factory');
116
-        return $Message_Factory->_set_message_type($message);
117
-    }
118
-
119
-
120
-
121
-    /**
122
-     * @access protected
123
-     * @param  array $props_n_values
124
-     * @return \EE_Message
125
-     * @throws \EE_Error
126
-     */
127
-    protected function _create($props_n_values = array())
128
-    {
129
-        $new_instance = false;
130
-        if (! empty($props_n_values['MSG_ID'])) {
131
-            $message = EE_Message::new_instance_from_db($props_n_values);
132
-        } else {
133
-            $message = EE_Message::new_instance($props_n_values);
134
-            $new_instance = true;
135
-        }
136
-        return $this->_set_messenger_and_message_type($message, $new_instance);
137
-    }
138
-
139
-
140
-
141
-    /**
142
-     * @access public
143
-     * @param  \EE_Message $message
144
-     * @param  bool        $new_instance Whether the message type was setup from the database (false) or not (true)
145
-     * @return \EE_Message
146
-     * @throws \EE_Error
147
-     */
148
-    protected function _set_messenger_and_message_type(EE_Message $message, $new_instance = false)
149
-    {
150
-        $message = $this->_set_messenger($message);
151
-        $message = $this->_set_message_type($message, $new_instance);
152
-        return $message;
153
-    }
154
-
155
-
156
-
157
-    /**
158
-     * @access protected
159
-     * @param  \EE_Message $message
160
-     * @return \EE_Message
161
-     * @throws \EE_Error
162
-     */
163
-    protected function _set_messenger(EE_Message $message)
164
-    {
165
-        $messenger = $this->_message_resource_manager->get_messenger($message->messenger());
166
-        if ($messenger instanceof EE_messenger) {
167
-            $message->set_messenger_object($messenger);
168
-        }
169
-        return $message;
170
-    }
171
-
172
-
173
-
174
-    /**
175
-     * @access protected
176
-     * @param  \EE_Message $message
177
-     * @param  bool        $new_instance Whether the message type was setup from the database (false) or not (true)
178
-     * @return \EE_Message
179
-     * @throws \EE_Error
180
-     */
181
-    protected function _set_message_type(EE_Message $message, $new_instance = false)
182
-    {
183
-        $message_type = $this->_message_resource_manager->get_message_type($message->message_type());
184
-        if ($message_type instanceof EE_message_type) {
185
-            $message->set_message_type_object($message_type, $new_instance);
186
-        }
187
-        return $message;
188
-    }
18
+	/**
19
+	 * @type EE_Message_Factory $_instance
20
+	 */
21
+	protected static $_instance;
22
+
23
+
24
+	/**
25
+	 * @type EE_Message_Resource_Manager $_message_resource_manager
26
+	 */
27
+	protected $_message_resource_manager;
28
+
29
+
30
+
31
+	/**
32
+	 * EE_Message_Factory constructor.
33
+	 *
34
+	 * @access protected
35
+	 * @param \EE_Message_Resource_Manager $Message_Resource_Manager
36
+	 */
37
+	protected function __construct(
38
+		EE_Message_Resource_Manager $Message_Resource_Manager
39
+	) {
40
+		$this->_message_resource_manager = $Message_Resource_Manager;
41
+	}
42
+
43
+
44
+
45
+	/**
46
+	 * @singleton method used to instantiate class object
47
+	 * @access    public
48
+	 * @param \EE_Message_Resource_Manager $Message_Resource_Manager
49
+	 * @return \EE_Message_Factory instance
50
+	 */
51
+	public static function instance(EE_Message_Resource_Manager $Message_Resource_Manager)
52
+	{
53
+		// check if class object is instantiated, and instantiated properly
54
+		if (! self::$_instance instanceof EE_Message_Factory) {
55
+			self::$_instance = new EE_Message_Factory($Message_Resource_Manager);
56
+		}
57
+		return self::$_instance;
58
+	}
59
+
60
+
61
+
62
+	/**
63
+	 * @access public
64
+	 * @param  array $props_n_values
65
+	 * @return EE_Message
66
+	 */
67
+	public static function create($props_n_values = array())
68
+	{
69
+		/** @type EE_Message_Factory $Message_Factory */
70
+		$Message_Factory = EE_Registry::instance()->load_lib('Message_Factory');
71
+		return $Message_Factory->_create($props_n_values);
72
+	}
73
+
74
+
75
+
76
+	/**
77
+	 * @access public
78
+	 * @param  \EE_Message $message
79
+	 * @return \EE_Message
80
+	 * @throws \EE_Error
81
+	 */
82
+	public static function set_messenger_and_message_type(EE_Message $message)
83
+	{
84
+		/** @type EE_Message_Factory $Message_Factory */
85
+		$Message_Factory = EE_Registry::instance()->load_lib('Message_Factory');
86
+		return $Message_Factory->_set_messenger_and_message_type($message);
87
+	}
88
+
89
+
90
+
91
+	/**
92
+	 * @access public
93
+	 * @param  \EE_Message $message
94
+	 * @return \EE_Message
95
+	 * @throws \EE_Error
96
+	 */
97
+	public static function set_messenger(EE_Message $message)
98
+	{
99
+		/** @type EE_Message_Factory $Message_Factory */
100
+		$Message_Factory = EE_Registry::instance()->load_lib('Message_Factory');
101
+		return $Message_Factory->_set_messenger($message);
102
+	}
103
+
104
+
105
+
106
+	/**
107
+	 * @access public
108
+	 * @param  \EE_Message $message
109
+	 * @return \EE_Message
110
+	 * @throws \EE_Error
111
+	 */
112
+	public static function set_message_type(EE_Message $message)
113
+	{
114
+		/** @type EE_Message_Factory $Message_Factory */
115
+		$Message_Factory = EE_Registry::instance()->load_lib('Message_Factory');
116
+		return $Message_Factory->_set_message_type($message);
117
+	}
118
+
119
+
120
+
121
+	/**
122
+	 * @access protected
123
+	 * @param  array $props_n_values
124
+	 * @return \EE_Message
125
+	 * @throws \EE_Error
126
+	 */
127
+	protected function _create($props_n_values = array())
128
+	{
129
+		$new_instance = false;
130
+		if (! empty($props_n_values['MSG_ID'])) {
131
+			$message = EE_Message::new_instance_from_db($props_n_values);
132
+		} else {
133
+			$message = EE_Message::new_instance($props_n_values);
134
+			$new_instance = true;
135
+		}
136
+		return $this->_set_messenger_and_message_type($message, $new_instance);
137
+	}
138
+
139
+
140
+
141
+	/**
142
+	 * @access public
143
+	 * @param  \EE_Message $message
144
+	 * @param  bool        $new_instance Whether the message type was setup from the database (false) or not (true)
145
+	 * @return \EE_Message
146
+	 * @throws \EE_Error
147
+	 */
148
+	protected function _set_messenger_and_message_type(EE_Message $message, $new_instance = false)
149
+	{
150
+		$message = $this->_set_messenger($message);
151
+		$message = $this->_set_message_type($message, $new_instance);
152
+		return $message;
153
+	}
154
+
155
+
156
+
157
+	/**
158
+	 * @access protected
159
+	 * @param  \EE_Message $message
160
+	 * @return \EE_Message
161
+	 * @throws \EE_Error
162
+	 */
163
+	protected function _set_messenger(EE_Message $message)
164
+	{
165
+		$messenger = $this->_message_resource_manager->get_messenger($message->messenger());
166
+		if ($messenger instanceof EE_messenger) {
167
+			$message->set_messenger_object($messenger);
168
+		}
169
+		return $message;
170
+	}
171
+
172
+
173
+
174
+	/**
175
+	 * @access protected
176
+	 * @param  \EE_Message $message
177
+	 * @param  bool        $new_instance Whether the message type was setup from the database (false) or not (true)
178
+	 * @return \EE_Message
179
+	 * @throws \EE_Error
180
+	 */
181
+	protected function _set_message_type(EE_Message $message, $new_instance = false)
182
+	{
183
+		$message_type = $this->_message_resource_manager->get_message_type($message->message_type());
184
+		if ($message_type instanceof EE_message_type) {
185
+			$message->set_message_type_object($message_type, $new_instance);
186
+		}
187
+		return $message;
188
+	}
189 189
 }
Please login to merge, or discard this patch.
core/libraries/messages/EE_Messages_Processor.lib.php 2 patches
Indentation   +582 added lines, -582 removed lines patch added patch discarded remove patch
@@ -12,590 +12,590 @@
 block discarded – undo
12 12
 {
13 13
 
14 14
 
15
-    /**
16
-     * @type EE_Message_Resource_Manager $_message_resource_manager
17
-     */
18
-    protected $_message_resource_manager;
19
-
20
-    /**
21
-     * @type EE_Messages_Queue
22
-     */
23
-    protected $_queue;
24
-
25
-    /**
26
-     * @type  EE_Messages_Generator
27
-     */
28
-    protected $_generator;
29
-
30
-
31
-
32
-
33
-    /**
34
-     * constructor
35
-     *
36
-     * @param EE_Message_Resource_Manager $message_resource_manager
37
-     */
38
-    public function __construct(EE_Message_Resource_Manager $message_resource_manager)
39
-    {
40
-        $this->_message_resource_manager = $message_resource_manager;
41
-        $this->_init_queue_and_generator();
42
-    }
43
-
44
-
45
-
46
-
47
-    /**
48
-     * This method sets (or resets) the various properties for use.
49
-     *
50
-     * - $_queue = holds the messages queue
51
-     * - $_generator = holds the messages generator
52
-     */
53
-    protected function _init_queue_and_generator()
54
-    {
55
-        $this->_generator = EE_Registry::factory('EE_Messages_Generator');
56
-        $this->_queue = $this->_generator->generation_queue();
57
-    }
58
-
59
-
60
-
61
-
62
-    /**
63
-     * This returns the current set queue.
64
-     * @return EE_Messages_Queue
65
-     */
66
-    public function get_queue()
67
-    {
68
-        return $this->_queue;
69
-    }
70
-
71
-
72
-
73
-    /**
74
-     * This method can be utilized to process messages from a queue and they will be processed immediately on the same request.
75
-     * Please note that this method alone does not bypass the usual "locks" for generation/sending (it assumes client code
76
-     * has already filtered those if necessary).
77
-     *
78
-     * @param EE_Messages_Queue $queue_to_process
79
-     * @return bool  true for success false for error.
80
-     */
81
-    public function process_immediately_from_queue(EE_Messages_Queue $queue_to_process)
82
-    {
83
-        $success = false;
84
-        $messages_to_send = array();
85
-        $messages_to_generate = array();
86
-        // loop through and setup the various messages from the queue so we know what is being processed
87
-        $queue_to_process->get_message_repository()->rewind();
88
-        foreach ($queue_to_process->get_message_repository() as $message) {
89
-            if ($message->STS_ID() === EEM_Message::status_incomplete) {
90
-                $messages_to_generate[] = $message;
91
-                continue;
92
-            }
93
-
94
-            if (in_array($message->STS_ID(), EEM_Message::instance()->stati_indicating_to_send())) {
95
-                $messages_to_send[] = $message;
96
-                continue;
97
-            }
98
-        }
99
-
100
-        // do generation/sends
101
-        if ($messages_to_generate) {
102
-            $success = $this->batch_generate_from_queue($messages_to_generate, true);
103
-        }
104
-
105
-        if ($messages_to_send) {
106
-            $sent = $this->batch_send_from_queue($messages_to_send, true);
107
-            // if there was messages to generate and it failed, then we override any success value for the sending process
108
-            // otherwise we just use the return from batch send.  The intent is that there is a simple response for success/fail.
109
-            // Either everything was successful or we consider it a fail.  To be clear, this is a limitation of doing
110
-            // all messages processing on the same request.
111
-            $success = $messages_to_generate && ! $success ? false : $sent;
112
-        }
113
-        return $success;
114
-    }
115
-
116
-
117
-    /**
118
-     * Calls the EE_Messages_Queue::get_batch_to_generate() method and sends to EE_Messages_Generator.
119
-     *
120
-     * @param  EE_Message[] $messages    Array of EE_Message objects (optional) to build the queue with.
121
-     * @param  bool         $clear_queue Whether to ensure a fresh queue or not.
122
-     *
123
-     * @return bool|EE_Messages_Queue return false if nothing generated.  This returns a new EE_Message_Queue with
124
-     *                                   generated messages.
125
-     */
126
-    public function batch_generate_from_queue($messages = array(), $clear_queue = false)
127
-    {
128
-        if ($this->_build_queue_for_generation($messages, $clear_queue)) {
129
-            $new_queue = $this->_generator->generate();
130
-            if ($new_queue instanceof EE_Messages_Queue) {
131
-                // unlock queue
132
-                $this->_queue->unlock_queue();
133
-                $new_queue->initiate_request_by_priority('send');
134
-                return $new_queue;
135
-            }
136
-        }
137
-        $this->_queue->unlock_queue();
138
-        return false;
139
-    }
140
-
141
-
142
-
143
-    /**
144
-     * This method preps a queue for generation.
145
-     *
146
-     * @since    4.9.0
147
-     *
148
-     * @param EE_Message[] $messages    Array of EE_Message objects to build the queue with
149
-     *
150
-     * @param   bool       $clear_queue This indicates whether the existing queue should be dumped or not.
151
-     *
152
-     * @return bool true means queue prepped, false means there was a lock so no generation please.
153
-     */
154
-    protected function _build_queue_for_generation($messages = array(), $clear_queue = false)
155
-    {
156
-
157
-        if ($clear_queue) {
158
-            $this->_init_queue_and_generator();
159
-        }
160
-
161
-        if ($messages) {
162
-            // if generation is locked then get out now because that means processing is already happening.
163
-            if ($this->_queue->is_locked()) {
164
-                return false;
165
-            }
166
-
167
-            $this->_queue->lock_queue();
168
-            $messages = is_array($messages) ? $messages : array( $messages );
169
-            foreach ($messages as $message) {
170
-                if ($message instanceof EE_Message) {
171
-                    $data = $message->all_extra_meta_array();
172
-                    $this->_queue->add($message, $data);
173
-                }
174
-            }
175
-            return true;
176
-        } else {
177
-            return $this->_queue->get_batch_to_generate();
178
-        }
179
-    }
180
-
181
-
182
-    /**
183
-     * This method preps a queue for sending.
184
-     *
185
-     * @param EE_Message[] $messages
186
-     * @param bool  $clear_queue Used to indicate whether to start with a fresh queue or not.
187
-     *
188
-     * @return bool true means queue prepped, false means there was a lock so no queue prepped.
189
-     */
190
-    protected function _build_queue_for_sending($messages, $clear_queue = false)
191
-    {
192
-        // if sending is locked then get out now because that means processing is already happening.
193
-        if ($this->_queue->is_locked(EE_Messages_Queue::action_sending)) {
194
-            return false;
195
-        }
196
-
197
-        $this->_queue->lock_queue(EE_Messages_Queue::action_sending);
198
-
199
-        if ($clear_queue) {
200
-            $this->_init_queue_and_generator();
201
-        }
202
-
203
-        $messages = is_array($messages) ? $messages : array( $messages );
204
-
205
-        foreach ($messages as $message) {
206
-            $this->_queue->add($message);
207
-        }
208
-        return true;
209
-    }
210
-
211
-
212
-    /**
213
-     * Calls the EE_Message_Queue::get_to_send_batch_and_send() method and then immediately just calls EE_Message_Queue::execute()
214
-     * to iterate and send unsent messages.
215
-     *
216
-     * @param EE_Message[] $messages    If an array of messages is sent in then use it.
217
-     *
218
-     * @param bool         $clear_queue Whether to initialize a new queue or keep the existing one.
219
-     *
220
-     * @return EE_Messages_Queue
221
-     */
222
-    public function batch_send_from_queue($messages = array(), $clear_queue = false)
223
-    {
224
-
225
-        if ($messages && $this->_build_queue_for_sending($messages, $clear_queue)) {
226
-            $this->_queue->execute();
227
-            $this->_queue->unlock_queue(EE_Messages_Queue::action_sending);
228
-        } else {
229
-            // get messages to send and execute.
230
-            $this->_queue->get_to_send_batch_and_send();
231
-        }
232
-        // note: callers can use the EE_Messages_Queue::count_STS_in_queue() method to find out if there were any failed
233
-        // messages in the queue and decide how to handle at that point.
234
-        return $this->_queue;
235
-    }
236
-
237
-
238
-
239
-
240
-
241
-
242
-    /**
243
-     * This immediately generates messages using the given array of EE_Message_To_Generate objects and returns the
244
-     * EE_Message_Queue with the generated messages for the caller to work with.  Note, this does NOT save the generated
245
-     * messages in the queue, leaving it up to the caller to do so.
246
-     *
247
-     * @param EE_Message_To_Generate[] $messages_to_generate
248
-     * @return EE_Messages_Queue
249
-     */
250
-    public function generate_and_return($messages_to_generate)
251
-    {
252
-        $this->_init_queue_and_generator();
253
-        $this->_queue_for_generation_loop($messages_to_generate);
254
-        return $this->_generator->generate(false);
255
-    }
256
-
257
-
258
-
259
-
260
-    /**
261
-     * Executes the generator generate method on the current internal queue, and returns the generated queue.
262
-     * @param  bool     $persist    Indicate whether to instruct the generator to persist the generated queue (true) or not (false).
263
-     * @return EE_Messages_Queue
264
-     */
265
-    public function generate_queue($persist = true)
266
-    {
267
-        return $this->_generator->generate($persist);
268
-    }
15
+	/**
16
+	 * @type EE_Message_Resource_Manager $_message_resource_manager
17
+	 */
18
+	protected $_message_resource_manager;
19
+
20
+	/**
21
+	 * @type EE_Messages_Queue
22
+	 */
23
+	protected $_queue;
24
+
25
+	/**
26
+	 * @type  EE_Messages_Generator
27
+	 */
28
+	protected $_generator;
29
+
30
+
31
+
32
+
33
+	/**
34
+	 * constructor
35
+	 *
36
+	 * @param EE_Message_Resource_Manager $message_resource_manager
37
+	 */
38
+	public function __construct(EE_Message_Resource_Manager $message_resource_manager)
39
+	{
40
+		$this->_message_resource_manager = $message_resource_manager;
41
+		$this->_init_queue_and_generator();
42
+	}
43
+
44
+
45
+
46
+
47
+	/**
48
+	 * This method sets (or resets) the various properties for use.
49
+	 *
50
+	 * - $_queue = holds the messages queue
51
+	 * - $_generator = holds the messages generator
52
+	 */
53
+	protected function _init_queue_and_generator()
54
+	{
55
+		$this->_generator = EE_Registry::factory('EE_Messages_Generator');
56
+		$this->_queue = $this->_generator->generation_queue();
57
+	}
58
+
59
+
60
+
61
+
62
+	/**
63
+	 * This returns the current set queue.
64
+	 * @return EE_Messages_Queue
65
+	 */
66
+	public function get_queue()
67
+	{
68
+		return $this->_queue;
69
+	}
70
+
71
+
72
+
73
+	/**
74
+	 * This method can be utilized to process messages from a queue and they will be processed immediately on the same request.
75
+	 * Please note that this method alone does not bypass the usual "locks" for generation/sending (it assumes client code
76
+	 * has already filtered those if necessary).
77
+	 *
78
+	 * @param EE_Messages_Queue $queue_to_process
79
+	 * @return bool  true for success false for error.
80
+	 */
81
+	public function process_immediately_from_queue(EE_Messages_Queue $queue_to_process)
82
+	{
83
+		$success = false;
84
+		$messages_to_send = array();
85
+		$messages_to_generate = array();
86
+		// loop through and setup the various messages from the queue so we know what is being processed
87
+		$queue_to_process->get_message_repository()->rewind();
88
+		foreach ($queue_to_process->get_message_repository() as $message) {
89
+			if ($message->STS_ID() === EEM_Message::status_incomplete) {
90
+				$messages_to_generate[] = $message;
91
+				continue;
92
+			}
93
+
94
+			if (in_array($message->STS_ID(), EEM_Message::instance()->stati_indicating_to_send())) {
95
+				$messages_to_send[] = $message;
96
+				continue;
97
+			}
98
+		}
99
+
100
+		// do generation/sends
101
+		if ($messages_to_generate) {
102
+			$success = $this->batch_generate_from_queue($messages_to_generate, true);
103
+		}
104
+
105
+		if ($messages_to_send) {
106
+			$sent = $this->batch_send_from_queue($messages_to_send, true);
107
+			// if there was messages to generate and it failed, then we override any success value for the sending process
108
+			// otherwise we just use the return from batch send.  The intent is that there is a simple response for success/fail.
109
+			// Either everything was successful or we consider it a fail.  To be clear, this is a limitation of doing
110
+			// all messages processing on the same request.
111
+			$success = $messages_to_generate && ! $success ? false : $sent;
112
+		}
113
+		return $success;
114
+	}
115
+
116
+
117
+	/**
118
+	 * Calls the EE_Messages_Queue::get_batch_to_generate() method and sends to EE_Messages_Generator.
119
+	 *
120
+	 * @param  EE_Message[] $messages    Array of EE_Message objects (optional) to build the queue with.
121
+	 * @param  bool         $clear_queue Whether to ensure a fresh queue or not.
122
+	 *
123
+	 * @return bool|EE_Messages_Queue return false if nothing generated.  This returns a new EE_Message_Queue with
124
+	 *                                   generated messages.
125
+	 */
126
+	public function batch_generate_from_queue($messages = array(), $clear_queue = false)
127
+	{
128
+		if ($this->_build_queue_for_generation($messages, $clear_queue)) {
129
+			$new_queue = $this->_generator->generate();
130
+			if ($new_queue instanceof EE_Messages_Queue) {
131
+				// unlock queue
132
+				$this->_queue->unlock_queue();
133
+				$new_queue->initiate_request_by_priority('send');
134
+				return $new_queue;
135
+			}
136
+		}
137
+		$this->_queue->unlock_queue();
138
+		return false;
139
+	}
140
+
141
+
142
+
143
+	/**
144
+	 * This method preps a queue for generation.
145
+	 *
146
+	 * @since    4.9.0
147
+	 *
148
+	 * @param EE_Message[] $messages    Array of EE_Message objects to build the queue with
149
+	 *
150
+	 * @param   bool       $clear_queue This indicates whether the existing queue should be dumped or not.
151
+	 *
152
+	 * @return bool true means queue prepped, false means there was a lock so no generation please.
153
+	 */
154
+	protected function _build_queue_for_generation($messages = array(), $clear_queue = false)
155
+	{
156
+
157
+		if ($clear_queue) {
158
+			$this->_init_queue_and_generator();
159
+		}
160
+
161
+		if ($messages) {
162
+			// if generation is locked then get out now because that means processing is already happening.
163
+			if ($this->_queue->is_locked()) {
164
+				return false;
165
+			}
166
+
167
+			$this->_queue->lock_queue();
168
+			$messages = is_array($messages) ? $messages : array( $messages );
169
+			foreach ($messages as $message) {
170
+				if ($message instanceof EE_Message) {
171
+					$data = $message->all_extra_meta_array();
172
+					$this->_queue->add($message, $data);
173
+				}
174
+			}
175
+			return true;
176
+		} else {
177
+			return $this->_queue->get_batch_to_generate();
178
+		}
179
+	}
180
+
181
+
182
+	/**
183
+	 * This method preps a queue for sending.
184
+	 *
185
+	 * @param EE_Message[] $messages
186
+	 * @param bool  $clear_queue Used to indicate whether to start with a fresh queue or not.
187
+	 *
188
+	 * @return bool true means queue prepped, false means there was a lock so no queue prepped.
189
+	 */
190
+	protected function _build_queue_for_sending($messages, $clear_queue = false)
191
+	{
192
+		// if sending is locked then get out now because that means processing is already happening.
193
+		if ($this->_queue->is_locked(EE_Messages_Queue::action_sending)) {
194
+			return false;
195
+		}
196
+
197
+		$this->_queue->lock_queue(EE_Messages_Queue::action_sending);
198
+
199
+		if ($clear_queue) {
200
+			$this->_init_queue_and_generator();
201
+		}
202
+
203
+		$messages = is_array($messages) ? $messages : array( $messages );
204
+
205
+		foreach ($messages as $message) {
206
+			$this->_queue->add($message);
207
+		}
208
+		return true;
209
+	}
210
+
211
+
212
+	/**
213
+	 * Calls the EE_Message_Queue::get_to_send_batch_and_send() method and then immediately just calls EE_Message_Queue::execute()
214
+	 * to iterate and send unsent messages.
215
+	 *
216
+	 * @param EE_Message[] $messages    If an array of messages is sent in then use it.
217
+	 *
218
+	 * @param bool         $clear_queue Whether to initialize a new queue or keep the existing one.
219
+	 *
220
+	 * @return EE_Messages_Queue
221
+	 */
222
+	public function batch_send_from_queue($messages = array(), $clear_queue = false)
223
+	{
224
+
225
+		if ($messages && $this->_build_queue_for_sending($messages, $clear_queue)) {
226
+			$this->_queue->execute();
227
+			$this->_queue->unlock_queue(EE_Messages_Queue::action_sending);
228
+		} else {
229
+			// get messages to send and execute.
230
+			$this->_queue->get_to_send_batch_and_send();
231
+		}
232
+		// note: callers can use the EE_Messages_Queue::count_STS_in_queue() method to find out if there were any failed
233
+		// messages in the queue and decide how to handle at that point.
234
+		return $this->_queue;
235
+	}
236
+
237
+
238
+
239
+
240
+
241
+
242
+	/**
243
+	 * This immediately generates messages using the given array of EE_Message_To_Generate objects and returns the
244
+	 * EE_Message_Queue with the generated messages for the caller to work with.  Note, this does NOT save the generated
245
+	 * messages in the queue, leaving it up to the caller to do so.
246
+	 *
247
+	 * @param EE_Message_To_Generate[] $messages_to_generate
248
+	 * @return EE_Messages_Queue
249
+	 */
250
+	public function generate_and_return($messages_to_generate)
251
+	{
252
+		$this->_init_queue_and_generator();
253
+		$this->_queue_for_generation_loop($messages_to_generate);
254
+		return $this->_generator->generate(false);
255
+	}
256
+
257
+
258
+
259
+
260
+	/**
261
+	 * Executes the generator generate method on the current internal queue, and returns the generated queue.
262
+	 * @param  bool     $persist    Indicate whether to instruct the generator to persist the generated queue (true) or not (false).
263
+	 * @return EE_Messages_Queue
264
+	 */
265
+	public function generate_queue($persist = true)
266
+	{
267
+		return $this->_generator->generate($persist);
268
+	}
269 269
 
270 270
 
271 271
 
272 272
 
273
-    /**
274
-     * Queue for generation.  Note this does NOT persist to the db.  Client code should call get_message_repository()->save() if desire
275
-     * to persist.  This method is provided to client code to decide what it wants to do with queued messages for generation.
276
-     * @param EE_Message_To_Generate $message_to_generate
277
-     * @param bool                   $test_send             Whether this item is for a test send or not.
278
-     * @return  EE_Messages_Queue
279
-     */
280
-    public function queue_for_generation(EE_Message_To_Generate $message_to_generate, $test_send = false)
281
-    {
282
-        if ($message_to_generate->valid()) {
283
-            $this->_generator->create_and_add_message_to_queue($message_to_generate, $test_send);
284
-        }
285
-    }
286
-
287
-
288
-
289
-
290
-
291
-
292
-
293
-    /**
294
-     * This receives an array of EE_Message_To_Generate objects, converts them to EE_Message adds them to the generation queue
295
-     * and then persists to storage.
296
-     *
297
-     * @param EE_Message_To_Generate[] $messages_to_generate
298
-     */
299
-    public function batch_queue_for_generation_and_persist($messages_to_generate)
300
-    {
301
-        $this->_init_queue_and_generator();
302
-        $this->_queue_for_generation_loop($messages_to_generate);
303
-        $this->_queue->save();
304
-    }
305
-
306
-
307
-
308
-
309
-
310
-
311
-    /**
312
-     * This receives an array of EE_Message_To_Generate objects, converts them to EE_Message and adds them to the generation
313
-     * queue.  Does NOT persist to storage (unless there is an error.
314
-     * Client code can retrieve the generated queue by calling EEM_Messages_Processor::get_queue()
315
-     *
316
-     * @param EE_Message_To_Generate[]  $messages_to_generate
317
-     */
318
-    public function batch_queue_for_generation_no_persist($messages_to_generate)
319
-    {
320
-        $this->_init_queue_and_generator();
321
-        $this->_queue_for_generation_loop($messages_to_generate);
322
-    }
323
-
324
-
325
-
326
-
327
-    /**
328
-     * Simply loops through the given array of EE_Message_To_Generate objects and adds them to the _queue as EE_Message
329
-     * objects.
330
-     *
331
-     * @param EE_Message_To_Generate[] $messages_to_generate
332
-     */
333
-    protected function _queue_for_generation_loop($messages_to_generate)
334
-    {
335
-        // make sure is in an array.
336
-        if (! is_array($messages_to_generate)) {
337
-            $messages_to_generate = array( $messages_to_generate );
338
-        }
339
-
340
-        foreach ($messages_to_generate as $message_to_generate) {
341
-            if ($message_to_generate instanceof EE_Message_To_Generate && $message_to_generate->valid()) {
342
-                $this->queue_for_generation($message_to_generate);
343
-            }
344
-        }
345
-    }
346
-
347
-
348
-
349
-
350
-
351
-    /**
352
-     * Receives an array of EE_Message_To_Generate objects and generates the EE_Message objects, then persists (so its
353
-     * queued for sending).
354
-     * @param  EE_Message_To_Generate[]
355
-     * @return EE_Messages_Queue
356
-     */
357
-    public function generate_and_queue_for_sending($messages_to_generate)
358
-    {
359
-        $this->_init_queue_and_generator();
360
-        $this->_queue_for_generation_loop($messages_to_generate);
361
-        return $this->_generator->generate(true);
362
-    }
363
-
364
-
365
-
366
-
367
-
368
-    /**
369
-     * Generate for preview and execute right away.
370
-     *
371
-     * @param   EE_Message_To_Generate $message_to_generate
372
-     * @param   bool                   $test_send                Whether this is a test send or not.
373
-     * @return  EE_Messages_Queue | bool   false if unable to generate otherwise the generated queue.
374
-     */
375
-    public function generate_for_preview(EE_Message_To_Generate $message_to_generate, $test_send = false)
376
-    {
377
-        if (! $message_to_generate->valid()) {
378
-            EE_Error::add_error(
379
-                __('Unable to generate preview because of invalid data', 'event_espresso'),
380
-                __FILE__,
381
-                __FUNCTION__,
382
-                __LINE__
383
-            );
384
-            return false;
385
-        }
386
-        // just make sure preview is set on the $message_to_generate (in case client forgot)
387
-        $message_to_generate->set_preview(true);
388
-        $this->_init_queue_and_generator();
389
-        $this->queue_for_generation($message_to_generate, $test_send);
390
-        $generated_queue = $this->_generator->generate(false);
391
-        if ($generated_queue->execute(false)) {
392
-            // the first queue item should be the preview
393
-            $generated_queue->get_message_repository()->rewind();
394
-            if (! $generated_queue->get_message_repository()->valid()) {
395
-                return $generated_queue;
396
-            }
397
-            return $generated_queue;
398
-        } else {
399
-            return false;
400
-        }
401
-    }
402
-
403
-
404
-    /**
405
-     * This queues for sending.
406
-     * The messenger send now method is also verified to see if sending immediately is requested.
407
-     * otherwise its just saved to the queue.
408
-     * @param EE_Message_To_Generate $message_to_generate
409
-     * @return bool true or false for success.
410
-     */
411
-    public function queue_for_sending(EE_Message_To_Generate $message_to_generate)
412
-    {
413
-        if (! $message_to_generate->valid()) {
414
-            return false;
415
-        }
416
-        $this->_init_queue_and_generator();
417
-        $message = $message_to_generate->get_EE_Message();
418
-        $this->_queue->add($message);
419
-        if ($message->send_now()) {
420
-            $this->_queue->execute(false);
421
-        } else {
422
-            $this->_queue->save();
423
-        }
424
-        return true;
425
-    }
426
-
427
-
428
-    /**
429
-     * This generates and sends from the given EE_Message_To_Generate class immediately.
430
-     * @param EE_Message_To_Generate $message_to_generate
431
-     * @return EE_Messages_Queue | null
432
-     */
433
-    public function generate_and_send_now(EE_Message_To_Generate $message_to_generate)
434
-    {
435
-        if (! $message_to_generate->valid()) {
436
-            return null;
437
-        }
438
-        // is there supposed to be a sending messenger for this message?
439
-        if ($message_to_generate instanceof EEI_Has_Sending_Messenger) {
440
-            // make sure it's valid, but if it's not,
441
-            // then set the value of $sending_messenger to an EE_Error object
442
-            // so that downstream code can easily see that things went wrong.
443
-            $sending_messenger = $message_to_generate->sending_messenger() instanceof EE_messenger
444
-                ? $message_to_generate->sending_messenger()
445
-                : new EE_Error(
446
-                    __(
447
-                        'There was a specific sending messenger requested for the send action, but it was either invalid or not active at time of sending.',
448
-                        'event_espresso'
449
-                    )
450
-                );
451
-        } else {
452
-            $sending_messenger = null;
453
-        }
454
-
455
-        if ($message_to_generate->get_EE_Message()->STS_ID() === EEM_Message::status_idle) {
456
-            $this->_init_queue_and_generator();
457
-            $this->_queue->add($message_to_generate->get_EE_Message());
458
-            $this->_queue->execute(false, $sending_messenger);
459
-            return $this->_queue;
460
-        } elseif ($message_to_generate->get_EE_Message()->STS_ID() === EEM_Message::status_incomplete) {
461
-            $generated_queue = $this->generate_and_return(array( $message_to_generate ));
462
-            $generated_queue->execute(false, $sending_messenger);
463
-            return $generated_queue;
464
-        }
465
-        return null;
466
-    }
467
-
468
-
469
-
470
-
471
-    /**
472
-     * Creates mtg objects for all active messengers and queues for generation.
473
-     * This method also calls the execute by priority method on the queue which will optionally kick off a new non-blocking
474
-     * request to complete the action if the priority for the message requires immediate action.
475
-     * @param string $message_type
476
-     * @param mixed  $data   The data being used for generation.
477
-     * @param bool   $persist   Whether to persist the queued messages to the db or not.
478
-     */
479
-    public function generate_for_all_active_messengers($message_type, $data, $persist = true)
480
-    {
481
-        $messages_to_generate = $this->setup_mtgs_for_all_active_messengers($message_type, $data);
482
-        if ($persist) {
483
-            $this->batch_queue_for_generation_and_persist($messages_to_generate);
484
-            $this->_queue->initiate_request_by_priority();
485
-        } else {
486
-            $this->batch_queue_for_generation_no_persist($messages_to_generate);
487
-        }
488
-    }
489
-
490
-
491
-
492
-
493
-    /**
494
-     * This simply loops through all active messengers and takes care of setting up the
495
-     * EE_Message_To_Generate objects.
496
-     * @param $message_type
497
-     * @param $data
498
-     *
499
-     * @return EE_Message_To_Generate[]
500
-     */
501
-    public function setup_mtgs_for_all_active_messengers($message_type, $data)
502
-    {
503
-        $messages_to_generate = array();
504
-        foreach ($this->_message_resource_manager->active_messengers() as $messenger_slug => $messenger_object) {
505
-            $message_to_generate = new EE_Message_To_Generate($messenger_slug, $message_type, $data);
506
-            if ($message_to_generate->valid()) {
507
-                $messages_to_generate[] = $message_to_generate;
508
-            }
509
-        }
510
-        return $messages_to_generate;
511
-    }
512
-
513
-
514
-
515
-
516
-    /**
517
-     * This accepts an array of EE_Message::MSG_ID values and will use that to retrieve the objects from the database
518
-     * and send.
519
-     * @param array $message_ids
520
-     */
521
-    public function setup_messages_from_ids_and_send($message_ids)
522
-    {
523
-        $this->_init_queue_and_generator();
524
-        $messages = EEM_Message::instance()->get_all(array(
525
-            array(
526
-                'MSG_ID' => array( 'IN', $message_ids ),
527
-                'STS_ID' => array(
528
-                    'IN',
529
-                    array_merge(
530
-                        EEM_Message::instance()->stati_indicating_sent(),
531
-                        array( EEM_Message::status_retry )
532
-                    ),
533
-                ),
534
-            ),
535
-        ));
536
-        // set the Messages to resend.
537
-        foreach ($messages as $message) {
538
-            if ($message instanceof EE_Message) {
539
-                $message->set_STS_ID(EEM_Message::status_resend);
540
-                $this->_queue->add($message);
541
-            }
542
-        }
543
-
544
-        $this->_queue->initiate_request_by_priority('send');
545
-    }
546
-
547
-
548
-
549
-    /**
550
-     * This method checks for registration IDs in the request via the given key and creates the messages to generate
551
-     * objects from them, then returns the array of messages to generate objects.
552
-     * Note, this sets up registrations for the registration family of message types.
553
-     *
554
-     * @param string $registration_ids_key  This is used to indicate what represents the registration ids in the request.
555
-     *
556
-     * @return EE_Message_To_Generate[]
557
-     */
558
-    public function setup_messages_to_generate_from_registration_ids_in_request($registration_ids_key = '_REG_ID')
559
-    {
560
-        EE_Registry::instance()->load_core('Request_Handler');
561
-        EE_Registry::instance()->load_helper('MSG_Template');
562
-        $regs_to_send = array();
563
-        $regIDs = EE_Registry::instance()->REQ->get($registration_ids_key);
564
-        if (empty($regIDs)) {
565
-            EE_Error::add_error(__('Something went wrong because we\'re missing the registration ID', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__);
566
-            return false;
567
-        }
568
-
569
-        // make sure is an array
570
-        $regIDs = is_array($regIDs) ? $regIDs : array( $regIDs );
571
-
572
-        foreach ($regIDs as $regID) {
573
-            $reg = EEM_Registration::instance()->get_one_by_ID($regID);
574
-            if (! $reg instanceof EE_Registration) {
575
-                EE_Error::add_error(sprintf(__('Unable to retrieve a registration object for the given reg id (%s)', 'event_espresso'), $regID));
576
-                return false;
577
-            }
578
-            $regs_to_send[ $reg->transaction_ID() ][ $reg->status_ID() ][] = $reg;
579
-        }
580
-
581
-        $messages_to_generate = array();
582
-
583
-        foreach ($regs_to_send as $status_group) {
584
-            foreach ($status_group as $status_id => $registrations) {
585
-                $message_type = EEH_MSG_Template::convert_reg_status_to_message_type($status_id);
586
-                if (! $message_type) {
587
-                    continue;
588
-                }
589
-                $messages_to_generate = array_merge(
590
-                    $messages_to_generate,
591
-                    $this->setup_mtgs_for_all_active_messengers(
592
-                        $message_type,
593
-                        array( $registrations, $status_id )
594
-                    )
595
-                );
596
-            }
597
-        }
598
-
599
-        return $messages_to_generate;
600
-    }
273
+	/**
274
+	 * Queue for generation.  Note this does NOT persist to the db.  Client code should call get_message_repository()->save() if desire
275
+	 * to persist.  This method is provided to client code to decide what it wants to do with queued messages for generation.
276
+	 * @param EE_Message_To_Generate $message_to_generate
277
+	 * @param bool                   $test_send             Whether this item is for a test send or not.
278
+	 * @return  EE_Messages_Queue
279
+	 */
280
+	public function queue_for_generation(EE_Message_To_Generate $message_to_generate, $test_send = false)
281
+	{
282
+		if ($message_to_generate->valid()) {
283
+			$this->_generator->create_and_add_message_to_queue($message_to_generate, $test_send);
284
+		}
285
+	}
286
+
287
+
288
+
289
+
290
+
291
+
292
+
293
+	/**
294
+	 * This receives an array of EE_Message_To_Generate objects, converts them to EE_Message adds them to the generation queue
295
+	 * and then persists to storage.
296
+	 *
297
+	 * @param EE_Message_To_Generate[] $messages_to_generate
298
+	 */
299
+	public function batch_queue_for_generation_and_persist($messages_to_generate)
300
+	{
301
+		$this->_init_queue_and_generator();
302
+		$this->_queue_for_generation_loop($messages_to_generate);
303
+		$this->_queue->save();
304
+	}
305
+
306
+
307
+
308
+
309
+
310
+
311
+	/**
312
+	 * This receives an array of EE_Message_To_Generate objects, converts them to EE_Message and adds them to the generation
313
+	 * queue.  Does NOT persist to storage (unless there is an error.
314
+	 * Client code can retrieve the generated queue by calling EEM_Messages_Processor::get_queue()
315
+	 *
316
+	 * @param EE_Message_To_Generate[]  $messages_to_generate
317
+	 */
318
+	public function batch_queue_for_generation_no_persist($messages_to_generate)
319
+	{
320
+		$this->_init_queue_and_generator();
321
+		$this->_queue_for_generation_loop($messages_to_generate);
322
+	}
323
+
324
+
325
+
326
+
327
+	/**
328
+	 * Simply loops through the given array of EE_Message_To_Generate objects and adds them to the _queue as EE_Message
329
+	 * objects.
330
+	 *
331
+	 * @param EE_Message_To_Generate[] $messages_to_generate
332
+	 */
333
+	protected function _queue_for_generation_loop($messages_to_generate)
334
+	{
335
+		// make sure is in an array.
336
+		if (! is_array($messages_to_generate)) {
337
+			$messages_to_generate = array( $messages_to_generate );
338
+		}
339
+
340
+		foreach ($messages_to_generate as $message_to_generate) {
341
+			if ($message_to_generate instanceof EE_Message_To_Generate && $message_to_generate->valid()) {
342
+				$this->queue_for_generation($message_to_generate);
343
+			}
344
+		}
345
+	}
346
+
347
+
348
+
349
+
350
+
351
+	/**
352
+	 * Receives an array of EE_Message_To_Generate objects and generates the EE_Message objects, then persists (so its
353
+	 * queued for sending).
354
+	 * @param  EE_Message_To_Generate[]
355
+	 * @return EE_Messages_Queue
356
+	 */
357
+	public function generate_and_queue_for_sending($messages_to_generate)
358
+	{
359
+		$this->_init_queue_and_generator();
360
+		$this->_queue_for_generation_loop($messages_to_generate);
361
+		return $this->_generator->generate(true);
362
+	}
363
+
364
+
365
+
366
+
367
+
368
+	/**
369
+	 * Generate for preview and execute right away.
370
+	 *
371
+	 * @param   EE_Message_To_Generate $message_to_generate
372
+	 * @param   bool                   $test_send                Whether this is a test send or not.
373
+	 * @return  EE_Messages_Queue | bool   false if unable to generate otherwise the generated queue.
374
+	 */
375
+	public function generate_for_preview(EE_Message_To_Generate $message_to_generate, $test_send = false)
376
+	{
377
+		if (! $message_to_generate->valid()) {
378
+			EE_Error::add_error(
379
+				__('Unable to generate preview because of invalid data', 'event_espresso'),
380
+				__FILE__,
381
+				__FUNCTION__,
382
+				__LINE__
383
+			);
384
+			return false;
385
+		}
386
+		// just make sure preview is set on the $message_to_generate (in case client forgot)
387
+		$message_to_generate->set_preview(true);
388
+		$this->_init_queue_and_generator();
389
+		$this->queue_for_generation($message_to_generate, $test_send);
390
+		$generated_queue = $this->_generator->generate(false);
391
+		if ($generated_queue->execute(false)) {
392
+			// the first queue item should be the preview
393
+			$generated_queue->get_message_repository()->rewind();
394
+			if (! $generated_queue->get_message_repository()->valid()) {
395
+				return $generated_queue;
396
+			}
397
+			return $generated_queue;
398
+		} else {
399
+			return false;
400
+		}
401
+	}
402
+
403
+
404
+	/**
405
+	 * This queues for sending.
406
+	 * The messenger send now method is also verified to see if sending immediately is requested.
407
+	 * otherwise its just saved to the queue.
408
+	 * @param EE_Message_To_Generate $message_to_generate
409
+	 * @return bool true or false for success.
410
+	 */
411
+	public function queue_for_sending(EE_Message_To_Generate $message_to_generate)
412
+	{
413
+		if (! $message_to_generate->valid()) {
414
+			return false;
415
+		}
416
+		$this->_init_queue_and_generator();
417
+		$message = $message_to_generate->get_EE_Message();
418
+		$this->_queue->add($message);
419
+		if ($message->send_now()) {
420
+			$this->_queue->execute(false);
421
+		} else {
422
+			$this->_queue->save();
423
+		}
424
+		return true;
425
+	}
426
+
427
+
428
+	/**
429
+	 * This generates and sends from the given EE_Message_To_Generate class immediately.
430
+	 * @param EE_Message_To_Generate $message_to_generate
431
+	 * @return EE_Messages_Queue | null
432
+	 */
433
+	public function generate_and_send_now(EE_Message_To_Generate $message_to_generate)
434
+	{
435
+		if (! $message_to_generate->valid()) {
436
+			return null;
437
+		}
438
+		// is there supposed to be a sending messenger for this message?
439
+		if ($message_to_generate instanceof EEI_Has_Sending_Messenger) {
440
+			// make sure it's valid, but if it's not,
441
+			// then set the value of $sending_messenger to an EE_Error object
442
+			// so that downstream code can easily see that things went wrong.
443
+			$sending_messenger = $message_to_generate->sending_messenger() instanceof EE_messenger
444
+				? $message_to_generate->sending_messenger()
445
+				: new EE_Error(
446
+					__(
447
+						'There was a specific sending messenger requested for the send action, but it was either invalid or not active at time of sending.',
448
+						'event_espresso'
449
+					)
450
+				);
451
+		} else {
452
+			$sending_messenger = null;
453
+		}
454
+
455
+		if ($message_to_generate->get_EE_Message()->STS_ID() === EEM_Message::status_idle) {
456
+			$this->_init_queue_and_generator();
457
+			$this->_queue->add($message_to_generate->get_EE_Message());
458
+			$this->_queue->execute(false, $sending_messenger);
459
+			return $this->_queue;
460
+		} elseif ($message_to_generate->get_EE_Message()->STS_ID() === EEM_Message::status_incomplete) {
461
+			$generated_queue = $this->generate_and_return(array( $message_to_generate ));
462
+			$generated_queue->execute(false, $sending_messenger);
463
+			return $generated_queue;
464
+		}
465
+		return null;
466
+	}
467
+
468
+
469
+
470
+
471
+	/**
472
+	 * Creates mtg objects for all active messengers and queues for generation.
473
+	 * This method also calls the execute by priority method on the queue which will optionally kick off a new non-blocking
474
+	 * request to complete the action if the priority for the message requires immediate action.
475
+	 * @param string $message_type
476
+	 * @param mixed  $data   The data being used for generation.
477
+	 * @param bool   $persist   Whether to persist the queued messages to the db or not.
478
+	 */
479
+	public function generate_for_all_active_messengers($message_type, $data, $persist = true)
480
+	{
481
+		$messages_to_generate = $this->setup_mtgs_for_all_active_messengers($message_type, $data);
482
+		if ($persist) {
483
+			$this->batch_queue_for_generation_and_persist($messages_to_generate);
484
+			$this->_queue->initiate_request_by_priority();
485
+		} else {
486
+			$this->batch_queue_for_generation_no_persist($messages_to_generate);
487
+		}
488
+	}
489
+
490
+
491
+
492
+
493
+	/**
494
+	 * This simply loops through all active messengers and takes care of setting up the
495
+	 * EE_Message_To_Generate objects.
496
+	 * @param $message_type
497
+	 * @param $data
498
+	 *
499
+	 * @return EE_Message_To_Generate[]
500
+	 */
501
+	public function setup_mtgs_for_all_active_messengers($message_type, $data)
502
+	{
503
+		$messages_to_generate = array();
504
+		foreach ($this->_message_resource_manager->active_messengers() as $messenger_slug => $messenger_object) {
505
+			$message_to_generate = new EE_Message_To_Generate($messenger_slug, $message_type, $data);
506
+			if ($message_to_generate->valid()) {
507
+				$messages_to_generate[] = $message_to_generate;
508
+			}
509
+		}
510
+		return $messages_to_generate;
511
+	}
512
+
513
+
514
+
515
+
516
+	/**
517
+	 * This accepts an array of EE_Message::MSG_ID values and will use that to retrieve the objects from the database
518
+	 * and send.
519
+	 * @param array $message_ids
520
+	 */
521
+	public function setup_messages_from_ids_and_send($message_ids)
522
+	{
523
+		$this->_init_queue_and_generator();
524
+		$messages = EEM_Message::instance()->get_all(array(
525
+			array(
526
+				'MSG_ID' => array( 'IN', $message_ids ),
527
+				'STS_ID' => array(
528
+					'IN',
529
+					array_merge(
530
+						EEM_Message::instance()->stati_indicating_sent(),
531
+						array( EEM_Message::status_retry )
532
+					),
533
+				),
534
+			),
535
+		));
536
+		// set the Messages to resend.
537
+		foreach ($messages as $message) {
538
+			if ($message instanceof EE_Message) {
539
+				$message->set_STS_ID(EEM_Message::status_resend);
540
+				$this->_queue->add($message);
541
+			}
542
+		}
543
+
544
+		$this->_queue->initiate_request_by_priority('send');
545
+	}
546
+
547
+
548
+
549
+	/**
550
+	 * This method checks for registration IDs in the request via the given key and creates the messages to generate
551
+	 * objects from them, then returns the array of messages to generate objects.
552
+	 * Note, this sets up registrations for the registration family of message types.
553
+	 *
554
+	 * @param string $registration_ids_key  This is used to indicate what represents the registration ids in the request.
555
+	 *
556
+	 * @return EE_Message_To_Generate[]
557
+	 */
558
+	public function setup_messages_to_generate_from_registration_ids_in_request($registration_ids_key = '_REG_ID')
559
+	{
560
+		EE_Registry::instance()->load_core('Request_Handler');
561
+		EE_Registry::instance()->load_helper('MSG_Template');
562
+		$regs_to_send = array();
563
+		$regIDs = EE_Registry::instance()->REQ->get($registration_ids_key);
564
+		if (empty($regIDs)) {
565
+			EE_Error::add_error(__('Something went wrong because we\'re missing the registration ID', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__);
566
+			return false;
567
+		}
568
+
569
+		// make sure is an array
570
+		$regIDs = is_array($regIDs) ? $regIDs : array( $regIDs );
571
+
572
+		foreach ($regIDs as $regID) {
573
+			$reg = EEM_Registration::instance()->get_one_by_ID($regID);
574
+			if (! $reg instanceof EE_Registration) {
575
+				EE_Error::add_error(sprintf(__('Unable to retrieve a registration object for the given reg id (%s)', 'event_espresso'), $regID));
576
+				return false;
577
+			}
578
+			$regs_to_send[ $reg->transaction_ID() ][ $reg->status_ID() ][] = $reg;
579
+		}
580
+
581
+		$messages_to_generate = array();
582
+
583
+		foreach ($regs_to_send as $status_group) {
584
+			foreach ($status_group as $status_id => $registrations) {
585
+				$message_type = EEH_MSG_Template::convert_reg_status_to_message_type($status_id);
586
+				if (! $message_type) {
587
+					continue;
588
+				}
589
+				$messages_to_generate = array_merge(
590
+					$messages_to_generate,
591
+					$this->setup_mtgs_for_all_active_messengers(
592
+						$message_type,
593
+						array( $registrations, $status_id )
594
+					)
595
+				);
596
+			}
597
+		}
598
+
599
+		return $messages_to_generate;
600
+	}
601 601
 }
Please login to merge, or discard this patch.
Spacing   +16 added lines, -16 removed lines patch added patch discarded remove patch
@@ -165,7 +165,7 @@  discard block
 block discarded – undo
165 165
             }
166 166
 
167 167
             $this->_queue->lock_queue();
168
-            $messages = is_array($messages) ? $messages : array( $messages );
168
+            $messages = is_array($messages) ? $messages : array($messages);
169 169
             foreach ($messages as $message) {
170 170
                 if ($message instanceof EE_Message) {
171 171
                     $data = $message->all_extra_meta_array();
@@ -200,7 +200,7 @@  discard block
 block discarded – undo
200 200
             $this->_init_queue_and_generator();
201 201
         }
202 202
 
203
-        $messages = is_array($messages) ? $messages : array( $messages );
203
+        $messages = is_array($messages) ? $messages : array($messages);
204 204
 
205 205
         foreach ($messages as $message) {
206 206
             $this->_queue->add($message);
@@ -333,8 +333,8 @@  discard block
 block discarded – undo
333 333
     protected function _queue_for_generation_loop($messages_to_generate)
334 334
     {
335 335
         // make sure is in an array.
336
-        if (! is_array($messages_to_generate)) {
337
-            $messages_to_generate = array( $messages_to_generate );
336
+        if ( ! is_array($messages_to_generate)) {
337
+            $messages_to_generate = array($messages_to_generate);
338 338
         }
339 339
 
340 340
         foreach ($messages_to_generate as $message_to_generate) {
@@ -374,7 +374,7 @@  discard block
 block discarded – undo
374 374
      */
375 375
     public function generate_for_preview(EE_Message_To_Generate $message_to_generate, $test_send = false)
376 376
     {
377
-        if (! $message_to_generate->valid()) {
377
+        if ( ! $message_to_generate->valid()) {
378 378
             EE_Error::add_error(
379 379
                 __('Unable to generate preview because of invalid data', 'event_espresso'),
380 380
                 __FILE__,
@@ -391,7 +391,7 @@  discard block
 block discarded – undo
391 391
         if ($generated_queue->execute(false)) {
392 392
             // the first queue item should be the preview
393 393
             $generated_queue->get_message_repository()->rewind();
394
-            if (! $generated_queue->get_message_repository()->valid()) {
394
+            if ( ! $generated_queue->get_message_repository()->valid()) {
395 395
                 return $generated_queue;
396 396
             }
397 397
             return $generated_queue;
@@ -410,7 +410,7 @@  discard block
 block discarded – undo
410 410
      */
411 411
     public function queue_for_sending(EE_Message_To_Generate $message_to_generate)
412 412
     {
413
-        if (! $message_to_generate->valid()) {
413
+        if ( ! $message_to_generate->valid()) {
414 414
             return false;
415 415
         }
416 416
         $this->_init_queue_and_generator();
@@ -432,7 +432,7 @@  discard block
 block discarded – undo
432 432
      */
433 433
     public function generate_and_send_now(EE_Message_To_Generate $message_to_generate)
434 434
     {
435
-        if (! $message_to_generate->valid()) {
435
+        if ( ! $message_to_generate->valid()) {
436 436
             return null;
437 437
         }
438 438
         // is there supposed to be a sending messenger for this message?
@@ -458,7 +458,7 @@  discard block
 block discarded – undo
458 458
             $this->_queue->execute(false, $sending_messenger);
459 459
             return $this->_queue;
460 460
         } elseif ($message_to_generate->get_EE_Message()->STS_ID() === EEM_Message::status_incomplete) {
461
-            $generated_queue = $this->generate_and_return(array( $message_to_generate ));
461
+            $generated_queue = $this->generate_and_return(array($message_to_generate));
462 462
             $generated_queue->execute(false, $sending_messenger);
463 463
             return $generated_queue;
464 464
         }
@@ -523,12 +523,12 @@  discard block
 block discarded – undo
523 523
         $this->_init_queue_and_generator();
524 524
         $messages = EEM_Message::instance()->get_all(array(
525 525
             array(
526
-                'MSG_ID' => array( 'IN', $message_ids ),
526
+                'MSG_ID' => array('IN', $message_ids),
527 527
                 'STS_ID' => array(
528 528
                     'IN',
529 529
                     array_merge(
530 530
                         EEM_Message::instance()->stati_indicating_sent(),
531
-                        array( EEM_Message::status_retry )
531
+                        array(EEM_Message::status_retry)
532 532
                     ),
533 533
                 ),
534 534
             ),
@@ -567,15 +567,15 @@  discard block
 block discarded – undo
567 567
         }
568 568
 
569 569
         // make sure is an array
570
-        $regIDs = is_array($regIDs) ? $regIDs : array( $regIDs );
570
+        $regIDs = is_array($regIDs) ? $regIDs : array($regIDs);
571 571
 
572 572
         foreach ($regIDs as $regID) {
573 573
             $reg = EEM_Registration::instance()->get_one_by_ID($regID);
574
-            if (! $reg instanceof EE_Registration) {
574
+            if ( ! $reg instanceof EE_Registration) {
575 575
                 EE_Error::add_error(sprintf(__('Unable to retrieve a registration object for the given reg id (%s)', 'event_espresso'), $regID));
576 576
                 return false;
577 577
             }
578
-            $regs_to_send[ $reg->transaction_ID() ][ $reg->status_ID() ][] = $reg;
578
+            $regs_to_send[$reg->transaction_ID()][$reg->status_ID()][] = $reg;
579 579
         }
580 580
 
581 581
         $messages_to_generate = array();
@@ -583,14 +583,14 @@  discard block
 block discarded – undo
583 583
         foreach ($regs_to_send as $status_group) {
584 584
             foreach ($status_group as $status_id => $registrations) {
585 585
                 $message_type = EEH_MSG_Template::convert_reg_status_to_message_type($status_id);
586
-                if (! $message_type) {
586
+                if ( ! $message_type) {
587 587
                     continue;
588 588
                 }
589 589
                 $messages_to_generate = array_merge(
590 590
                     $messages_to_generate,
591 591
                     $this->setup_mtgs_for_all_active_messengers(
592 592
                         $message_type,
593
-                        array( $registrations, $status_id )
593
+                        array($registrations, $status_id)
594 594
                     )
595 595
                 );
596 596
             }
Please login to merge, or discard this patch.
core/libraries/messages/data_class/EE_Messages_Addressee.class.php 2 patches
Indentation   +295 added lines, -295 removed lines patch added patch discarded remove patch
@@ -15,299 +15,299 @@
 block discarded – undo
15 15
 {
16 16
 
17 17
 
18
-    /**
19
-     * Identifier properties for the recipient
20
-     */
21
-
22
-    /**
23
-     * if available we'll use this to set the fname and lname (admin)
24
-     *
25
-     * @var int
26
-     */
27
-    public $user_id;
28
-
29
-    /**
30
-     * this will always be the admin fname (set later via incoming user_id)
31
-     *
32
-     * @var string
33
-     */
34
-    public $fname;
35
-
36
-    /**
37
-     * this will always be the admin lname (set later via incoming user_id)
38
-     *
39
-     * @var string
40
-     */
41
-    public $lname;
42
-
43
-    /**
44
-     * @var int
45
-     */
46
-    public $primary_registration_id;
47
-
48
-    /**
49
-     * @var int
50
-     */
51
-    public $attendee_registration_id;
52
-
53
-    /**
54
-     * This is should represent the data object that can be used to regenerate this addressee if needed.
55
-     * It is saved to the MSG_recipient_ID column in the generated EE_Message using this data.
56
-     *
57
-     * @var int
58
-     */
59
-    public $recipient_id;
60
-
61
-    /**
62
-     * This represents the reference to the EE_Base_Class child that the $recipient_ID is for (eg. 'Registration',
63
-     * 'Attendee') It is saved to the MSG_recipient_type column in the generated EE_Message using this data.
64
-     *
65
-     * @var string
66
-     */
67
-    public $recipient_type;
68
-
69
-    /**
70
-     * communication related
71
-     */
72
-    /**
73
-     * @var string
74
-     */
75
-    public $attendee_email;
76
-
77
-    /**
78
-     * @var string
79
-     */
80
-    public $primary_attendee_email;
81
-
82
-    /**
83
-     * @var string
84
-     */
85
-    public $admin_email;
86
-
87
-
88
-
89
-    /**
90
-     * Attendee related
91
-     */
92
-
93
-    /**
94
-     * holds the attendee object for the primary attendee
95
-     *
96
-     * @var EE_Attendee
97
-     */
98
-    public $primary_att_obj;
99
-
100
-    /**
101
-     * holds the registration object for the primary attendee
102
-     *
103
-     * @var EE_Registration
104
-     */
105
-    public $primary_reg_obj;
106
-
107
-    /**
108
-     * holds the attendee object for an attendee
109
-     *
110
-     * @var EE_Attendee
111
-     */
112
-    public $att_obj;
113
-
114
-    /**
115
-     * holds the registration object for an attendee
116
-     *
117
-     * @var EE_Registration
118
-     */
119
-    public $reg_obj;
120
-
121
-    /**
122
-     * array of EE_Question objects (indexed by EE_Answer->ID())
123
-     *
124
-     * @var EE_Question[]
125
-     */
126
-    public $questions;
127
-
128
-    /**
129
-     * array of EE_Answer objects
130
-     *
131
-     * @var EE_Answer[]
132
-     */
133
-    public $answers;
134
-
135
-
136
-
137
-    /**
138
-     * event related
139
-     */
140
-
141
-    /**
142
-     * This will hold all event info/
143
-     * @var EE_Event[]
144
-     */
145
-    public $events;
146
-
147
-    /**
148
-     * holds all the attendees for an event.
149
-     *
150
-     * @var EE_Attendee[]
151
-     */
152
-    public $attendees;
153
-
154
-    /**
155
-     * holds all the purchased tickets for an event
156
-     *
157
-     * @var EE_Ticket[]
158
-     */
159
-    public $tickets;
160
-
161
-    /**
162
-     * holds an array of line items indexed by parent ticket line item ids and values are array of children of that
163
-     * line item
164
-     *
165
-     * @var EE_Line_Item[]
166
-     */
167
-    public $line_items_with_children;
168
-
169
-    /**
170
-     * holds all the datetimes accessed via the tickets purchased for the event
171
-     *
172
-     * @var EE_Datetime[]
173
-     */
174
-    public $datetimes;
175
-
176
-    /**
177
-     * holds all registrations for a transaction (with cached relations on that registration)
178
-     *
179
-     * @var EE_Registration[]
180
-     */
181
-    public $registrations;
182
-
183
-
184
-
185
-    /**
186
-     * txn related
187
-     */
188
-
189
-    /**
190
-     * @var array
191
-     */
192
-    public $billing;
193
-
194
-    /**
195
-     *total taxes
196
-     *
197
-     * @var array
198
-     */
199
-    public $taxes;
200
-
201
-    /**
202
-     * @var EE_Line_Item[]
203
-     */
204
-    public $tax_line_items;
205
-
206
-    /**
207
-     * @var EE_Line_Item[]
208
-     */
209
-    public $additional_line_items;
210
-
211
-    /**
212
-     * @var EE_Line_Item
213
-     */
214
-    public $grand_total_line_item;
215
-
216
-    /**
217
-     * @var EE_Transaction
218
-     */
219
-    public $txn;
220
-
221
-    /**
222
-     * @var EE_Payment
223
-     */
224
-    public $payment;
225
-
226
-    /**
227
-     * @var EE_Payment[]
228
-     */
229
-    public $payments;
230
-
231
-    /**
232
-     * @var EE_Transaction[]
233
-     */
234
-    public $txn_objs;
235
-
236
-    /**
237
-     * @var EE_Registration[]
238
-     */
239
-    public $reg_objs;
240
-
241
-    /**
242
-     * total number of ALL tickets purchased for the txn.
243
-     *
244
-     * @var int
245
-     */
246
-    public $total_ticket_count;
247
-
248
-
249
-
250
-    /**
251
-     * things that get set later by parsers
252
-     */
253
-
254
-    /**
255
-     * @var string $event_list
256
-     */
257
-    public $event_list;
258
-
259
-    /**
260
-     * @var string
261
-     */
262
-    public $attendee_list;
263
-
264
-
265
-
266
-    /**
267
-     * This just holds the incoming data
268
-     *
269
-     * @var array
270
-     */
271
-    protected $_data;
272
-
273
-
274
-
275
-    /**
276
-     * constructor
277
-     *
278
-     * @access public
279
-     * @param array $addressee_data We're expecting an incoming array of data that will be used to fill the properties
280
-     *                              for the object.
281
-     */
282
-    public function __construct($addressee_data)
283
-    {
284
-        $this->_data = $addressee_data;
285
-        $this->_set_properties();
286
-    }
287
-
288
-
289
-
290
-    /**
291
-     * This simply loops through the data and makes sure that each item is present in the incoming data.  If it is then
292
-     * it is assigned to the property.
293
-     *
294
-     * @access protected
295
-     * @return void.
296
-     */
297
-    protected function _set_properties()
298
-    {
299
-        foreach ($this->_data as $prop => $value) {
300
-            if (property_exists($this, $prop)) {
301
-                $this->{$prop} = $value;
302
-            }
303
-        }
304
-        // if user_id present we'll use this to set the fname and lname and admin_email.
305
-        if (! empty($this->user_id)) {
306
-            $this->user_id = (int) $this->user_id;
307
-            $user = get_userdata($this->user_id);
308
-            $this->fname = $user->user_firstname;
309
-            $this->lname = $user->user_lastname;
310
-            $this->admin_email = $user->user_email;
311
-        }
312
-    }
18
+	/**
19
+	 * Identifier properties for the recipient
20
+	 */
21
+
22
+	/**
23
+	 * if available we'll use this to set the fname and lname (admin)
24
+	 *
25
+	 * @var int
26
+	 */
27
+	public $user_id;
28
+
29
+	/**
30
+	 * this will always be the admin fname (set later via incoming user_id)
31
+	 *
32
+	 * @var string
33
+	 */
34
+	public $fname;
35
+
36
+	/**
37
+	 * this will always be the admin lname (set later via incoming user_id)
38
+	 *
39
+	 * @var string
40
+	 */
41
+	public $lname;
42
+
43
+	/**
44
+	 * @var int
45
+	 */
46
+	public $primary_registration_id;
47
+
48
+	/**
49
+	 * @var int
50
+	 */
51
+	public $attendee_registration_id;
52
+
53
+	/**
54
+	 * This is should represent the data object that can be used to regenerate this addressee if needed.
55
+	 * It is saved to the MSG_recipient_ID column in the generated EE_Message using this data.
56
+	 *
57
+	 * @var int
58
+	 */
59
+	public $recipient_id;
60
+
61
+	/**
62
+	 * This represents the reference to the EE_Base_Class child that the $recipient_ID is for (eg. 'Registration',
63
+	 * 'Attendee') It is saved to the MSG_recipient_type column in the generated EE_Message using this data.
64
+	 *
65
+	 * @var string
66
+	 */
67
+	public $recipient_type;
68
+
69
+	/**
70
+	 * communication related
71
+	 */
72
+	/**
73
+	 * @var string
74
+	 */
75
+	public $attendee_email;
76
+
77
+	/**
78
+	 * @var string
79
+	 */
80
+	public $primary_attendee_email;
81
+
82
+	/**
83
+	 * @var string
84
+	 */
85
+	public $admin_email;
86
+
87
+
88
+
89
+	/**
90
+	 * Attendee related
91
+	 */
92
+
93
+	/**
94
+	 * holds the attendee object for the primary attendee
95
+	 *
96
+	 * @var EE_Attendee
97
+	 */
98
+	public $primary_att_obj;
99
+
100
+	/**
101
+	 * holds the registration object for the primary attendee
102
+	 *
103
+	 * @var EE_Registration
104
+	 */
105
+	public $primary_reg_obj;
106
+
107
+	/**
108
+	 * holds the attendee object for an attendee
109
+	 *
110
+	 * @var EE_Attendee
111
+	 */
112
+	public $att_obj;
113
+
114
+	/**
115
+	 * holds the registration object for an attendee
116
+	 *
117
+	 * @var EE_Registration
118
+	 */
119
+	public $reg_obj;
120
+
121
+	/**
122
+	 * array of EE_Question objects (indexed by EE_Answer->ID())
123
+	 *
124
+	 * @var EE_Question[]
125
+	 */
126
+	public $questions;
127
+
128
+	/**
129
+	 * array of EE_Answer objects
130
+	 *
131
+	 * @var EE_Answer[]
132
+	 */
133
+	public $answers;
134
+
135
+
136
+
137
+	/**
138
+	 * event related
139
+	 */
140
+
141
+	/**
142
+	 * This will hold all event info/
143
+	 * @var EE_Event[]
144
+	 */
145
+	public $events;
146
+
147
+	/**
148
+	 * holds all the attendees for an event.
149
+	 *
150
+	 * @var EE_Attendee[]
151
+	 */
152
+	public $attendees;
153
+
154
+	/**
155
+	 * holds all the purchased tickets for an event
156
+	 *
157
+	 * @var EE_Ticket[]
158
+	 */
159
+	public $tickets;
160
+
161
+	/**
162
+	 * holds an array of line items indexed by parent ticket line item ids and values are array of children of that
163
+	 * line item
164
+	 *
165
+	 * @var EE_Line_Item[]
166
+	 */
167
+	public $line_items_with_children;
168
+
169
+	/**
170
+	 * holds all the datetimes accessed via the tickets purchased for the event
171
+	 *
172
+	 * @var EE_Datetime[]
173
+	 */
174
+	public $datetimes;
175
+
176
+	/**
177
+	 * holds all registrations for a transaction (with cached relations on that registration)
178
+	 *
179
+	 * @var EE_Registration[]
180
+	 */
181
+	public $registrations;
182
+
183
+
184
+
185
+	/**
186
+	 * txn related
187
+	 */
188
+
189
+	/**
190
+	 * @var array
191
+	 */
192
+	public $billing;
193
+
194
+	/**
195
+	 *total taxes
196
+	 *
197
+	 * @var array
198
+	 */
199
+	public $taxes;
200
+
201
+	/**
202
+	 * @var EE_Line_Item[]
203
+	 */
204
+	public $tax_line_items;
205
+
206
+	/**
207
+	 * @var EE_Line_Item[]
208
+	 */
209
+	public $additional_line_items;
210
+
211
+	/**
212
+	 * @var EE_Line_Item
213
+	 */
214
+	public $grand_total_line_item;
215
+
216
+	/**
217
+	 * @var EE_Transaction
218
+	 */
219
+	public $txn;
220
+
221
+	/**
222
+	 * @var EE_Payment
223
+	 */
224
+	public $payment;
225
+
226
+	/**
227
+	 * @var EE_Payment[]
228
+	 */
229
+	public $payments;
230
+
231
+	/**
232
+	 * @var EE_Transaction[]
233
+	 */
234
+	public $txn_objs;
235
+
236
+	/**
237
+	 * @var EE_Registration[]
238
+	 */
239
+	public $reg_objs;
240
+
241
+	/**
242
+	 * total number of ALL tickets purchased for the txn.
243
+	 *
244
+	 * @var int
245
+	 */
246
+	public $total_ticket_count;
247
+
248
+
249
+
250
+	/**
251
+	 * things that get set later by parsers
252
+	 */
253
+
254
+	/**
255
+	 * @var string $event_list
256
+	 */
257
+	public $event_list;
258
+
259
+	/**
260
+	 * @var string
261
+	 */
262
+	public $attendee_list;
263
+
264
+
265
+
266
+	/**
267
+	 * This just holds the incoming data
268
+	 *
269
+	 * @var array
270
+	 */
271
+	protected $_data;
272
+
273
+
274
+
275
+	/**
276
+	 * constructor
277
+	 *
278
+	 * @access public
279
+	 * @param array $addressee_data We're expecting an incoming array of data that will be used to fill the properties
280
+	 *                              for the object.
281
+	 */
282
+	public function __construct($addressee_data)
283
+	{
284
+		$this->_data = $addressee_data;
285
+		$this->_set_properties();
286
+	}
287
+
288
+
289
+
290
+	/**
291
+	 * This simply loops through the data and makes sure that each item is present in the incoming data.  If it is then
292
+	 * it is assigned to the property.
293
+	 *
294
+	 * @access protected
295
+	 * @return void.
296
+	 */
297
+	protected function _set_properties()
298
+	{
299
+		foreach ($this->_data as $prop => $value) {
300
+			if (property_exists($this, $prop)) {
301
+				$this->{$prop} = $value;
302
+			}
303
+		}
304
+		// if user_id present we'll use this to set the fname and lname and admin_email.
305
+		if (! empty($this->user_id)) {
306
+			$this->user_id = (int) $this->user_id;
307
+			$user = get_userdata($this->user_id);
308
+			$this->fname = $user->user_firstname;
309
+			$this->lname = $user->user_lastname;
310
+			$this->admin_email = $user->user_email;
311
+		}
312
+	}
313 313
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -302,7 +302,7 @@
 block discarded – undo
302 302
             }
303 303
         }
304 304
         // if user_id present we'll use this to set the fname and lname and admin_email.
305
-        if (! empty($this->user_id)) {
305
+        if ( ! empty($this->user_id)) {
306 306
             $this->user_id = (int) $this->user_id;
307 307
             $user = get_userdata($this->user_id);
308 308
             $this->fname = $user->user_firstname;
Please login to merge, or discard this patch.