Completed
Branch ENH/optimize-reset-reservation... (ea022f)
by
unknown
06:52 queued 04:53
created
core/libraries/messages/EE_messenger.lib.php 2 patches
Indentation   +722 added lines, -722 removed lines patch added patch discarded remove patch
@@ -18,182 +18,182 @@  discard block
 block discarded – undo
18 18
 
19 19
 
20 20
 
21
-    /**
22
-     * This property holds the default message types associated with this messenger when it is activated. The values of the array must match a valid message type.
23
-     * This property gets set by the _set_default_message_types() method.
24
-     *
25
-     * @var array
26
-     */
27
-    protected $_default_message_types = array();
21
+	/**
22
+	 * This property holds the default message types associated with this messenger when it is activated. The values of the array must match a valid message type.
23
+	 * This property gets set by the _set_default_message_types() method.
24
+	 *
25
+	 * @var array
26
+	 */
27
+	protected $_default_message_types = array();
28 28
 
29 29
 
30 30
 
31 31
 
32
-    /**
33
-     * This property holds the message types that are valid for use with this messenger.
34
-     * It gets set by the _set_valid_message_types() method.
35
-     *
36
-     * @var array
37
-     */
38
-    protected $_valid_message_types = array();
32
+	/**
33
+	 * This property holds the message types that are valid for use with this messenger.
34
+	 * It gets set by the _set_valid_message_types() method.
35
+	 *
36
+	 * @var array
37
+	 */
38
+	protected $_valid_message_types = array();
39 39
 
40 40
 
41 41
 
42
-    /**
43
-     * Holds the configuration for the EE_Messages_Validator class to know how to validated the different fields. Note that the Validator will match each field here with the allowed shortcodes set in the "valid_shortcodes" array for the matched message type context.  So message types don't need to set a $_validator_config property.
44
-     *
45
-     * Remember, ALL fields must be declared in this array.  However, an empty value for the field means that the field will accept all valid shortcodes set for the given context in the message type (by default).
46
-     *
47
-     * Array should be in this format:
48
-     *
49
-     * array(
50
-     *  'field_name(i.e.to)' => array(
51
-     *      'shortcodes' => array('email'), //an array of shortcode groups (correspond to EE_Shortcodes library class) that are allowed in the field. Typically you can just include $this->_valid_shortcodes['field_name'] as the value here (because they will match).
52
-     *      'specific_shortcodes' => array( array('[EVENT_AUTHOR_EMAIL]' => __('Admin Email', 'event_espresso')), //if this index is present you can further restrict the field to ONLY specific shortcodes if an entire group isn't sufficient. Specific shortcodes need to be listed as an array with the index the shortcode and the value = the label.
53
-     *      'type' => 'email' //this is the field type and should match one of the validator types (see EE_Messages_Validator::validator() for all the possible types).  If not required you can just leave empty.,
54
-     *      'required' => array'[SHORTCODE]') //this is used to indicate the shortcodes that MUST be in the assembled array of shortcodes by the validator in order for this field to be included in validation.  Otherwise the validator will always assign shortcodes for this field (regardless of whether the field settings for the given messenger/message_type/context use the field or not.).. please note, this does NOT mean that the shortcodes listed here MUST be in the given field.
55
-     *  )
56
-     * )
57
-     *
58
-     * @var array
59
-     */
60
-    protected $_validator_config = array();
42
+	/**
43
+	 * Holds the configuration for the EE_Messages_Validator class to know how to validated the different fields. Note that the Validator will match each field here with the allowed shortcodes set in the "valid_shortcodes" array for the matched message type context.  So message types don't need to set a $_validator_config property.
44
+	 *
45
+	 * Remember, ALL fields must be declared in this array.  However, an empty value for the field means that the field will accept all valid shortcodes set for the given context in the message type (by default).
46
+	 *
47
+	 * Array should be in this format:
48
+	 *
49
+	 * array(
50
+	 *  'field_name(i.e.to)' => array(
51
+	 *      'shortcodes' => array('email'), //an array of shortcode groups (correspond to EE_Shortcodes library class) that are allowed in the field. Typically you can just include $this->_valid_shortcodes['field_name'] as the value here (because they will match).
52
+	 *      'specific_shortcodes' => array( array('[EVENT_AUTHOR_EMAIL]' => __('Admin Email', 'event_espresso')), //if this index is present you can further restrict the field to ONLY specific shortcodes if an entire group isn't sufficient. Specific shortcodes need to be listed as an array with the index the shortcode and the value = the label.
53
+	 *      'type' => 'email' //this is the field type and should match one of the validator types (see EE_Messages_Validator::validator() for all the possible types).  If not required you can just leave empty.,
54
+	 *      'required' => array'[SHORTCODE]') //this is used to indicate the shortcodes that MUST be in the assembled array of shortcodes by the validator in order for this field to be included in validation.  Otherwise the validator will always assign shortcodes for this field (regardless of whether the field settings for the given messenger/message_type/context use the field or not.).. please note, this does NOT mean that the shortcodes listed here MUST be in the given field.
55
+	 *  )
56
+	 * )
57
+	 *
58
+	 * @var array
59
+	 */
60
+	protected $_validator_config = array();
61 61
 
62 62
 
63 63
 
64
-    /**
65
-     * This will hold the EEM_message_templates model for interacting with the database and retrieving active templates for the messenger
66
-     * @var object
67
-     */
68
-    protected $_EEM_data;
64
+	/**
65
+	 * This will hold the EEM_message_templates model for interacting with the database and retrieving active templates for the messenger
66
+	 * @var object
67
+	 */
68
+	protected $_EEM_data;
69 69
 
70 70
 
71 71
 
72
-    /**
73
-     * this property just holds an array of the various template refs.
74
-     * @var array
75
-     */
76
-    protected $_template_fields = array();
72
+	/**
73
+	 * this property just holds an array of the various template refs.
74
+	 * @var array
75
+	 */
76
+	protected $_template_fields = array();
77 77
 
78 78
 
79 79
 
80 80
 
81
-    /**
82
-     * This holds an array of the arguments used in parsing a template for the sender.
83
-     * @var array
84
-     */
85
-    protected $_template_args = array();
81
+	/**
82
+	 * This holds an array of the arguments used in parsing a template for the sender.
83
+	 * @var array
84
+	 */
85
+	protected $_template_args = array();
86 86
 
87 87
 
88 88
 
89 89
 
90 90
 
91 91
 
92
-    /**
93
-     * This property will hold the configuration for any test settings fields that are required for the "test" button that is used to trigger an actual test of this messenger
94
-     *
95
-     * @protected
96
-     * @var array
97
-     */
98
-    protected $_test_settings_fields = array();
92
+	/**
93
+	 * This property will hold the configuration for any test settings fields that are required for the "test" button that is used to trigger an actual test of this messenger
94
+	 *
95
+	 * @protected
96
+	 * @var array
97
+	 */
98
+	protected $_test_settings_fields = array();
99 99
 
100 100
 
101 101
 
102 102
 
103 103
 
104 104
 
105
-    /**
106
-     * This will hold the EE_Messages_Template_Pack object when set on the messenger.  This is set via the validate and setup method which grabs the template pack from the incoming messages object.
107
-     *
108
-     * @since 4.5.0
109
-     *
110
-     * @var EE_Messages_Template_Pack
111
-     */
112
-    protected $_tmp_pack;
105
+	/**
106
+	 * This will hold the EE_Messages_Template_Pack object when set on the messenger.  This is set via the validate and setup method which grabs the template pack from the incoming messages object.
107
+	 *
108
+	 * @since 4.5.0
109
+	 *
110
+	 * @var EE_Messages_Template_Pack
111
+	 */
112
+	protected $_tmp_pack;
113 113
 
114 114
 
115 115
 
116 116
 
117
-    /**
118
-     * This will hold the variation to use when performing a send.  It is set via the validate and setup method which grabs the variation from the incoming messages object on the send method.
119
-     *
120
-     * @since 4.5.0
121
-     *
122
-     * @var string
123
-     */
124
-    protected $_variation;
117
+	/**
118
+	 * This will hold the variation to use when performing a send.  It is set via the validate and setup method which grabs the variation from the incoming messages object on the send method.
119
+	 *
120
+	 * @since 4.5.0
121
+	 *
122
+	 * @var string
123
+	 */
124
+	protected $_variation;
125 125
 
126 126
 
127 127
 
128 128
 
129 129
 
130
-    /**
131
-     * This property is a stdClass that holds labels for all the various supporting properties for this messenger.  These labels are set via the _set_supports_labels() method in children classes. Initially this will include the label for:
132
-     *
133
-     *  - template pack
134
-     *  - template variation
135
-     *
136
-     * @since 4.5.0
137
-     *
138
-     * @var stdClass
139
-     */
140
-    protected $_supports_labels;
130
+	/**
131
+	 * This property is a stdClass that holds labels for all the various supporting properties for this messenger.  These labels are set via the _set_supports_labels() method in children classes. Initially this will include the label for:
132
+	 *
133
+	 *  - template pack
134
+	 *  - template variation
135
+	 *
136
+	 * @since 4.5.0
137
+	 *
138
+	 * @var stdClass
139
+	 */
140
+	protected $_supports_labels;
141 141
 
142 142
 
143 143
 
144 144
 
145 145
 
146
-    /**
147
-     * This property is set when the send_message() method is called and holds the Message Type used to generate templates with this messenger for the messages.
148
-     *
149
-     * @var EE_message_type
150
-     */
151
-    protected $_incoming_message_type;
146
+	/**
147
+	 * This property is set when the send_message() method is called and holds the Message Type used to generate templates with this messenger for the messages.
148
+	 *
149
+	 * @var EE_message_type
150
+	 */
151
+	protected $_incoming_message_type;
152 152
 
153 153
 
154 154
 
155
-    /**
156
-     * This flag sets whether a messenger is activated by default  on installation (or reactivation) of EE core or not.
157
-     *
158
-     * @var bool
159
-     */
160
-    public $activate_on_install = false;
155
+	/**
156
+	 * This flag sets whether a messenger is activated by default  on installation (or reactivation) of EE core or not.
157
+	 *
158
+	 * @var bool
159
+	 */
160
+	public $activate_on_install = false;
161 161
 
162 162
 
163 163
 
164 164
 
165 165
 
166
-    public function __construct()
167
-    {
168
-        $this->_EEM_data = EEM_Message_Template_Group::instance();
169
-        $this->_messages_item_type = 'messenger';
166
+	public function __construct()
167
+	{
168
+		$this->_EEM_data = EEM_Message_Template_Group::instance();
169
+		$this->_messages_item_type = 'messenger';
170 170
 
171
-        parent::__construct();
171
+		parent::__construct();
172 172
 
173
-        $this->_set_test_settings_fields();
174
-        $this->_set_template_fields();
175
-        $this->_set_default_message_types();
176
-        $this->_set_valid_message_types();
177
-        $this->_set_validator_config();
173
+		$this->_set_test_settings_fields();
174
+		$this->_set_template_fields();
175
+		$this->_set_default_message_types();
176
+		$this->_set_valid_message_types();
177
+		$this->_set_validator_config();
178 178
 
179 179
 
180
-        $this->_supports_labels = new stdClass();
181
-        $this->_set_supports_labels();
182
-    }
180
+		$this->_supports_labels = new stdClass();
181
+		$this->_set_supports_labels();
182
+	}
183 183
 
184 184
 
185 185
 
186 186
 
187 187
 
188
-    /**
189
-     * _set_template_fields
190
-     * This sets up the fields that a messenger requires for the message to go out.
191
-     *
192
-     * @abstract
193
-     * @access  protected
194
-     * @return void
195
-     */
196
-    abstract protected function _set_template_fields();
188
+	/**
189
+	 * _set_template_fields
190
+	 * This sets up the fields that a messenger requires for the message to go out.
191
+	 *
192
+	 * @abstract
193
+	 * @access  protected
194
+	 * @return void
195
+	 */
196
+	abstract protected function _set_template_fields();
197 197
 
198 198
 
199 199
 
@@ -203,14 +203,14 @@  discard block
 block discarded – undo
203 203
 
204 204
 
205 205
 
206
-    /**
207
-     * This method sets the _default_message_type property (see definition in docs attached to property)
208
-     *
209
-     * @abstract
210
-     * @access protected
211
-     * @return void
212
-     */
213
-    abstract protected function _set_default_message_types();
206
+	/**
207
+	 * This method sets the _default_message_type property (see definition in docs attached to property)
208
+	 *
209
+	 * @abstract
210
+	 * @access protected
211
+	 * @return void
212
+	 */
213
+	abstract protected function _set_default_message_types();
214 214
 
215 215
 
216 216
 
@@ -218,15 +218,15 @@  discard block
 block discarded – undo
218 218
 
219 219
 
220 220
 
221
-    /**
222
-     * Sets the _valid_message_types property (see definition in cods attached to property)
223
-     *
224
-     * @since 4.5.0
225
-     *
226
-     * @abstract
227
-     * @return void
228
-     */
229
-    abstract protected function _set_valid_message_types();
221
+	/**
222
+	 * Sets the _valid_message_types property (see definition in cods attached to property)
223
+	 *
224
+	 * @since 4.5.0
225
+	 *
226
+	 * @abstract
227
+	 * @return void
228
+	 */
229
+	abstract protected function _set_valid_message_types();
230 230
 
231 231
 
232 232
 
@@ -234,171 +234,171 @@  discard block
 block discarded – undo
234 234
 
235 235
 
236 236
 
237
-    /**
238
-     * Child classes must declare the $_validator_config property using this method.
239
-     * See comments for $_validator_config for details on what it is used for.
240
-     *
241
-     * NOTE:  messengers should set an array of valid shortcodes for ALL scenarios.  The corresponding validator class (validators/{messenger}) can be used to restrict only certain shortcodes per template so users cannot add certain shortcodes.
242
-     *
243
-     * @access protected
244
-     * @return void
245
-     */
246
-    abstract protected function _set_validator_config();
237
+	/**
238
+	 * Child classes must declare the $_validator_config property using this method.
239
+	 * See comments for $_validator_config for details on what it is used for.
240
+	 *
241
+	 * NOTE:  messengers should set an array of valid shortcodes for ALL scenarios.  The corresponding validator class (validators/{messenger}) can be used to restrict only certain shortcodes per template so users cannot add certain shortcodes.
242
+	 *
243
+	 * @access protected
244
+	 * @return void
245
+	 */
246
+	abstract protected function _set_validator_config();
247 247
 
248 248
 
249 249
 
250 250
 
251 251
 
252 252
 
253
-    /**
254
-     * We just deliver the messages don't kill us!!  This method will need to be modified by child classes for whatever action is taken to actually send a message.
255
-     *
256
-     * @return bool|WP_Error
257
-     * @throw \Exception
258
-     */
259
-    abstract protected function _send_message();
253
+	/**
254
+	 * We just deliver the messages don't kill us!!  This method will need to be modified by child classes for whatever action is taken to actually send a message.
255
+	 *
256
+	 * @return bool|WP_Error
257
+	 * @throw \Exception
258
+	 */
259
+	abstract protected function _send_message();
260 260
 
261 261
 
262 262
 
263 263
 
264
-    /**
265
-     * We give you pretty previews of the messages!
266
-     * @return string html body for message content.
267
-     */
268
-    abstract protected function _preview();
264
+	/**
265
+	 * We give you pretty previews of the messages!
266
+	 * @return string html body for message content.
267
+	 */
268
+	abstract protected function _preview();
269 269
 
270 270
 
271 271
 
272 272
 
273
-    /**
274
-     * Used by messengers (or preview) for enqueueing any scripts or styles need in message generation.
275
-     *
276
-     * @since 4.5.0
277
-     *
278
-     * @return void
279
-     */
280
-    public function enqueue_scripts_styles()
281
-    {
282
-        do_action('AHEE__EE_messenger__enqueue_scripts_styles');
283
-    }
273
+	/**
274
+	 * Used by messengers (or preview) for enqueueing any scripts or styles need in message generation.
275
+	 *
276
+	 * @since 4.5.0
277
+	 *
278
+	 * @return void
279
+	 */
280
+	public function enqueue_scripts_styles()
281
+	{
282
+		do_action('AHEE__EE_messenger__enqueue_scripts_styles');
283
+	}
284 284
 
285 285
 
286 286
 
287 287
 
288 288
 
289
-    /**
290
-     * This is used to indicate whether a messenger must be sent immediately or not.
291
-     * eg. The HTML messenger will override this to return true because it should be displayed in user's browser right
292
-     * away.  The PDF messenger is similar.
293
-     *
294
-     * This flag thus overrides any priorities that may be set on the message type used to generate the message.
295
-     *
296
-     * Default for this is false.  So children classes must override this if they want a message to be executed immediately.
297
-     *
298
-     * @since  4.9.0
299
-     * @return bool
300
-     */
301
-    public function send_now()
302
-    {
303
-        return false;
304
-    }
289
+	/**
290
+	 * This is used to indicate whether a messenger must be sent immediately or not.
291
+	 * eg. The HTML messenger will override this to return true because it should be displayed in user's browser right
292
+	 * away.  The PDF messenger is similar.
293
+	 *
294
+	 * This flag thus overrides any priorities that may be set on the message type used to generate the message.
295
+	 *
296
+	 * Default for this is false.  So children classes must override this if they want a message to be executed immediately.
297
+	 *
298
+	 * @since  4.9.0
299
+	 * @return bool
300
+	 */
301
+	public function send_now()
302
+	{
303
+		return false;
304
+	}
305 305
 
306 306
 
307 307
 
308 308
 
309 309
 
310
-    /**
311
-     * This is a way for a messenger to indicate whether it allows an empty to field or not.
312
-     * Note: If the generated message is a for a preview, this value is ignored.
313
-     * @since 4.9.0
314
-     * @return bool
315
-     */
316
-    public function allow_empty_to_field()
317
-    {
318
-        return false;
319
-    }
310
+	/**
311
+	 * This is a way for a messenger to indicate whether it allows an empty to field or not.
312
+	 * Note: If the generated message is a for a preview, this value is ignored.
313
+	 * @since 4.9.0
314
+	 * @return bool
315
+	 */
316
+	public function allow_empty_to_field()
317
+	{
318
+		return false;
319
+	}
320 320
 
321 321
 
322 322
 
323 323
 
324 324
 
325
-    /**
326
-     * Sets the defaults for the _supports_labels property.  Can be overridden by child classes.
327
-     * @see property definition for info on how its formatted.
328
-     *
329
-     * @since 4.5.0;
330
-     * @return void
331
-     */
332
-    protected function _set_supports_labels()
333
-    {
334
-        $this->_set_supports_labels_defaults();
335
-    }
325
+	/**
326
+	 * Sets the defaults for the _supports_labels property.  Can be overridden by child classes.
327
+	 * @see property definition for info on how its formatted.
328
+	 *
329
+	 * @since 4.5.0;
330
+	 * @return void
331
+	 */
332
+	protected function _set_supports_labels()
333
+	{
334
+		$this->_set_supports_labels_defaults();
335
+	}
336 336
 
337 337
 
338 338
 
339 339
 
340 340
 
341
-    /**
342
-     * Sets the defaults for the _supports_labels property.
343
-     *
344
-     * @since 4.5.0
345
-     *
346
-     * @return void
347
-     */
348
-    private function _set_supports_labels_defaults()
349
-    {
350
-        $this->_supports_labels->template_pack = __('Template Structure', 'event_espresso');
351
-        $this->_supports_labels->template_variation = __('Template Style', 'event_espresso');
352
-        $this->_supports_labels->template_pack_description = __('Template Structure options are bundled structural changes for templates.', 'event_espresso');
341
+	/**
342
+	 * Sets the defaults for the _supports_labels property.
343
+	 *
344
+	 * @since 4.5.0
345
+	 *
346
+	 * @return void
347
+	 */
348
+	private function _set_supports_labels_defaults()
349
+	{
350
+		$this->_supports_labels->template_pack = __('Template Structure', 'event_espresso');
351
+		$this->_supports_labels->template_variation = __('Template Style', 'event_espresso');
352
+		$this->_supports_labels->template_pack_description = __('Template Structure options are bundled structural changes for templates.', 'event_espresso');
353 353
 
354
-        $this->_supports_labels->template_variation_description = __('These are different styles to choose from for the selected template structure.  Usually these affect things like font style, color, borders etc.  In some cases the styles will also make minor layout changes.', 'event_espresso');
354
+		$this->_supports_labels->template_variation_description = __('These are different styles to choose from for the selected template structure.  Usually these affect things like font style, color, borders etc.  In some cases the styles will also make minor layout changes.', 'event_espresso');
355 355
 
356
-        $this->_supports_labels = apply_filters('FHEE__EE_messenger___set_supports_labels_defaults___supports_labels', $this->_supports_labels, $this);
357
-    }
356
+		$this->_supports_labels = apply_filters('FHEE__EE_messenger___set_supports_labels_defaults___supports_labels', $this->_supports_labels, $this);
357
+	}
358 358
 
359 359
 
360 360
 
361 361
 
362 362
 
363
-    /**
364
-     * This returns the _supports_labels property.
365
-     *
366
-     * @since 4.5.0
367
-     *
368
-     * @return stdClass
369
-     */
370
-    public function get_supports_labels()
371
-    {
372
-        if (empty($this->_supports_labels->template_pack) || empty($this->_supports_labels->template_variation)) {
373
-            $this->_set_supports_labels_defaults();
374
-        }
375
-        return apply_filters('FHEE__EE_messenger__get_supports_labels', $this->_supports_labels, $this);
376
-    }
363
+	/**
364
+	 * This returns the _supports_labels property.
365
+	 *
366
+	 * @since 4.5.0
367
+	 *
368
+	 * @return stdClass
369
+	 */
370
+	public function get_supports_labels()
371
+	{
372
+		if (empty($this->_supports_labels->template_pack) || empty($this->_supports_labels->template_variation)) {
373
+			$this->_set_supports_labels_defaults();
374
+		}
375
+		return apply_filters('FHEE__EE_messenger__get_supports_labels', $this->_supports_labels, $this);
376
+	}
377 377
 
378 378
 
379 379
 
380 380
 
381
-    /**
382
-     * Used to retrieve a variation (typically the path/url to a css file)
383
-     *
384
-     * @since 4.5.0
385
-     *
386
-     * @param EE_Messages_Template_Pack $pack   The template pack used for retrieving the variation.
387
-     * @param string                    $message_type_name The name property of the message type that we need the variation for.
388
-     * @param bool                      $url   Whether to return url (true) or path (false). Default is false.
389
-     * @param string                    $type What variation type to return. Default is 'main'.
390
-     * @param string               $variation What variation for the template pack
391
-     * @param bool             $skip_filters This allows messengers to add a filter for another messengers get_variation but call skip filters on the callback so there is no recursion on apply_filters.
392
-     *
393
-     * @return string                    path or url for the requested variation.
394
-     */
395
-    public function get_variation(EE_Messages_Template_Pack $pack, $message_type_name, $url = false, $type = 'main', $variation = 'default', $skip_filters = false)
396
-    {
397
-        $this->_tmp_pack = $pack;
398
-        $variation_path = apply_filters('EE_messenger__get_variation__variation', false, $pack, $this->name, $message_type_name, $url, $type, $variation, $skip_filters);
399
-        $variation_path = empty($variation_path) ? $this->_tmp_pack->get_variation($this->name, $message_type_name, $type, $variation, $url, '.css', $skip_filters) : $variation_path;
400
-        return $variation_path;
401
-    }
381
+	/**
382
+	 * Used to retrieve a variation (typically the path/url to a css file)
383
+	 *
384
+	 * @since 4.5.0
385
+	 *
386
+	 * @param EE_Messages_Template_Pack $pack   The template pack used for retrieving the variation.
387
+	 * @param string                    $message_type_name The name property of the message type that we need the variation for.
388
+	 * @param bool                      $url   Whether to return url (true) or path (false). Default is false.
389
+	 * @param string                    $type What variation type to return. Default is 'main'.
390
+	 * @param string               $variation What variation for the template pack
391
+	 * @param bool             $skip_filters This allows messengers to add a filter for another messengers get_variation but call skip filters on the callback so there is no recursion on apply_filters.
392
+	 *
393
+	 * @return string                    path or url for the requested variation.
394
+	 */
395
+	public function get_variation(EE_Messages_Template_Pack $pack, $message_type_name, $url = false, $type = 'main', $variation = 'default', $skip_filters = false)
396
+	{
397
+		$this->_tmp_pack = $pack;
398
+		$variation_path = apply_filters('EE_messenger__get_variation__variation', false, $pack, $this->name, $message_type_name, $url, $type, $variation, $skip_filters);
399
+		$variation_path = empty($variation_path) ? $this->_tmp_pack->get_variation($this->name, $message_type_name, $type, $variation, $url, '.css', $skip_filters) : $variation_path;
400
+		return $variation_path;
401
+	}
402 402
 
403 403
 
404 404
 
@@ -406,479 +406,479 @@  discard block
 block discarded – undo
406 406
 
407 407
 
408 408
 
409
-    /**
410
-     * This just returns the default message types associated with this messenger when it is first activated.
411
-     *
412
-     * @access public
413
-     * @return array
414
-     */
415
-    public function get_default_message_types()
416
-    {
417
-        $class = get_class($this);
409
+	/**
410
+	 * This just returns the default message types associated with this messenger when it is first activated.
411
+	 *
412
+	 * @access public
413
+	 * @return array
414
+	 */
415
+	public function get_default_message_types()
416
+	{
417
+		$class = get_class($this);
418 418
 
419
-        // messenger specific filter
420
-        $default_types = apply_filters('FHEE__' . $class . '__get_default_message_types__default_types', $this->_default_message_types, $this);
419
+		// messenger specific filter
420
+		$default_types = apply_filters('FHEE__' . $class . '__get_default_message_types__default_types', $this->_default_message_types, $this);
421 421
 
422
-        // all messengers filter
423
-        $default_types = apply_filters('FHEE__EE_messenger__get_default_message_types__default_types', $default_types, $this);
424
-        return $default_types;
425
-    }
422
+		// all messengers filter
423
+		$default_types = apply_filters('FHEE__EE_messenger__get_default_message_types__default_types', $default_types, $this);
424
+		return $default_types;
425
+	}
426 426
 
427 427
 
428 428
 
429 429
 
430
-    /**
431
-     * Returns the valid message types associated with this messenger.
432
-     *
433
-     * @since 4.5.0
434
-     *
435
-     * @return array
436
-     */
437
-    public function get_valid_message_types()
438
-    {
439
-        $class = get_class($this);
440
-
441
-        // messenger specific filter
442
-        // messenger specific filter
443
-        $valid_types = apply_filters('FHEE__' . $class . '__get_valid_message_types__valid_types', $this->_valid_message_types, $this);
444
-
445
-        // all messengers filter
446
-        $valid_types = apply_filters('FHEE__EE_messenger__get_valid_message_types__valid_types', $valid_types, $this);
447
-        return $valid_types;
448
-    }
449
-
450
-
451
-
452
-
453
-
454
-    /**
455
-     * this is just used by the custom validators (EE_Messages_Validator classes) to modify the _validator_config for certain message_type/messenger combos where a context may only use certain shortcodes etc.
456
-     *
457
-     * @access public
458
-     * @param array $new_config Whatever is put in here will reset the _validator_config property
459
-     */
460
-    public function set_validator_config($new_config)
461
-    {
462
-        $this->_validator_config = $new_config;
463
-    }
464
-
465
-
466
-
467
-
468
-    /**
469
-     * This returns the _validator_config property
470
-     *
471
-     * @access public
472
-     * @return array
473
-     */
474
-    public function get_validator_config()
475
-    {
476
-        $class = get_class($this);
477
-
478
-        $config = apply_filters('FHEE__' . $class . '__get_validator_config', $this->_validator_config, $this);
479
-        $config = apply_filters('FHEE__EE_messenger__get_validator_config', $config, $this);
480
-        return $config;
481
-    }
482
-
483
-
484
-
485
-
486
-    /**
487
-     * this public method accepts a page slug (for an EE_admin page) and will return the response from the child class callback function if that page is registered via the `_admin_registered_page` property set by the child class.
488
-     *
489
-     * @param string $page the slug of the EE admin page
490
-     * @param array $message_types an array of active message type objects
491
-     * @param string $action the page action (to allow for more specific handling - i.e. edit vs. add pages)
492
-     * @param array $extra  This is just an extra argument that can be used to pass additional data for setting up page content.
493
-     * @access public
494
-     * @return string content for page
495
-     */
496
-    public function get_messenger_admin_page_content($page, $action = null, $extra = array(), $message_types = array())
497
-    {
498
-        return $this->_get_admin_page_content($page, $action, $extra, $message_types);
499
-    }
500
-
501
-
502
-
503
-    /**
504
-     * @param $message_types
505
-     * @param array $extra
506
-     * @return mixed|string
507
-     */
508
-    protected function _get_admin_content_events_edit($message_types, $extra)
509
-    {
510
-        // defaults
511
-        $template_args = array();
512
-        $selector_rows = '';
513
-
514
-        // we don't need message types here so we're just going to ignore. we do, however, expect the event id here. The event id is needed to provide a link to setup a custom template for this event.
515
-        $event_id = isset($extra['event']) ? $extra['event'] : null;
516
-
517
-        $template_wrapper_path = EE_LIBRARIES . 'messages/messenger/admin_templates/event_switcher_wrapper.template.php';
518
-        $template_row_path = EE_LIBRARIES . 'messages/messenger/admin_templates/event_switcher_row.template.php';
519
-
520
-        // array of template objects for global and custom (non-trashed) (but remember just for this messenger!)
521
-        $global_templates = EEM_Message_Template_Group::instance()->get_all(
522
-            array( array( 'MTP_messenger' => $this->name, 'MTP_is_global' => true, 'MTP_is_active' => true ) )
523
-        );
524
-        $templates_for_event = EEM_Message_Template_Group::instance()->get_all_custom_templates_by_event(
525
-            $event_id,
526
-            array(
527
-                'MTP_messenger' => $this->name,
528
-                'MTP_is_active' => true
529
-            )
530
-        );
531
-        $templates_for_event = !empty($templates_for_event) ? $templates_for_event : array();
532
-
533
-        // so we need to setup the rows for the selectors and we use the global mtpgs (cause those will the active message template groups)
534
-        foreach ($global_templates as $mtpgID => $mtpg) {
535
-            if ($mtpg instanceof EE_Message_Template_Group) {
536
-                // verify this message type is supposed to show on this page
537
-                $mtp_obj = $mtpg->message_type_obj();
538
-                if (! $mtp_obj instanceof EE_message_type) {
539
-                    continue;
540
-                }
541
-                $mtp_obj->admin_registered_pages = (array) $mtp_obj->admin_registered_pages;
542
-                if (! in_array('events_edit', $mtp_obj->admin_registered_pages)) {
543
-                    continue;
544
-                }
545
-                $select_values = array();
546
-                $select_values[ $mtpgID ] = __('Global', 'event_espresso');
547
-                $default_value = array_key_exists($mtpgID, $templates_for_event) && ! $mtpg->get('MTP_is_override') ? $mtpgID : null;
548
-                // if the override has been set for the global template, then that means even if there are custom templates already created we ignore them because of the set override.
549
-                if (! $mtpg->get('MTP_is_override')) {
550
-                    // any custom templates for this message type?
551
-                    $custom_templates = EEM_Message_Template_Group::instance()->get_custom_message_template_by_m_and_mt($this->name, $mtpg->message_type());
552
-                    foreach ($custom_templates as $cmtpgID => $cmtpg) {
553
-                        $select_values[ $cmtpgID ] = $cmtpg->name();
554
-                        $default_value = array_key_exists($cmtpgID, $templates_for_event) ? $cmtpgID : $default_value;
555
-                    }
556
-                }
557
-                // if there is no $default_value then we set it as the global
558
-                $default_value = empty($default_value) ? $mtpgID : $default_value;
559
-                $edit_url = EEH_URL::add_query_args_and_nonce(array( 'page' => 'espresso_messages', 'action' => 'edit_message_template', 'id' => $default_value ), admin_url('admin.php'));
560
-                $create_url = EEH_URL::add_query_args_and_nonce(array( 'page' => 'espresso_messages', 'action' => 'add_new_message_template', 'GRP_ID' => $default_value ), admin_url('admin.php'));
561
-                $st_args['mt_name'] = ucwords($mtp_obj->label['singular']);
562
-                $st_args['mt_slug'] = $mtpg->message_type();
563
-                $st_args['messenger_slug'] = $this->name;
564
-                $st_args['selector'] = EEH_Form_Fields::select_input('event_message_templates_relation[' . $mtpgID . ']', $select_values, $default_value, 'data-messenger="' . $this->name . '" data-messagetype="' . $mtpg->message_type() . '"', 'message-template-selector');
565
-                // note that  message template group that has override_all_custom set will remove the ability to set a custom message template based off of the global (and that also in turn overrides any other custom templates).
566
-                $st_args['create_button'] = $mtpg->get('MTP_is_override') ? '' : '<a data-messenger="' . $this->name . '" data-messagetype="' . $mtpg->message_type() . '" data-grpid="' . $default_value . '" target="_blank" href="' . $create_url . '" class="button button-small create-mtpg-button">' . __('Create New Custom', 'event_espresso') . '</a>';
567
-                $st_args['create_button'] = EE_Registry::instance()->CAP->current_user_can('ee_edit_messages', 'espresso_messages_add_new_message_template') ? $st_args['create_button'] : '';
568
-                $st_args['edit_button'] = EE_Registry::instance()->CAP->current_user_can('ee_edit_message', 'espresso_messages_edit_message_template', $mtpgID) ? '<a data-messagetype="' . $mtpg->message_type() . '" data-grpid="' . $default_value . '" target="_blank" href="' . $edit_url . '" class="button button-small edit-mtpg-button">' . __('Edit', 'event_espresso') . '</a>' : '';
569
-                $selector_rows .= EEH_Template::display_template($template_row_path, $st_args, true);
570
-            }
571
-        }
572
-
573
-        // if no selectors present then get out.
574
-        if (empty($selector_rows)) {
575
-            return '';
576
-        }
577
-
578
-        $template_args['selector_rows'] = $selector_rows;
579
-        return EEH_Template::display_template($template_wrapper_path, $template_args, true);
580
-    }
581
-
582
-
583
-
584
-
585
-
586
-
587
-    /**
588
-     * get_template_fields
589
-     *
590
-     * @access public
591
-     * @return array $this->_template_fields
592
-     */
593
-    public function get_template_fields()
594
-    {
595
-        $template_fields = apply_filters('FHEE__' . get_class($this) . '__get_template_fields', $this->_template_fields, $this);
596
-        $template_fields = apply_filters('FHEE__EE_messenger__get_template_fields', $template_fields, $this);
597
-        return $template_fields;
598
-    }
599
-
600
-
601
-
602
-
603
-    /** SETUP METHODS **/
604
-    /**
605
-     * The following method doesn't NEED to be used by child classes but might be modified by the specific messenger
606
-     * @param string $item
607
-     * @param mixed $value
608
-     */
609
-    protected function _set_template_value($item, $value)
610
-    {
611
-        if (array_key_exists($item, $this->_template_fields)) {
612
-            $prop = '_' . $item;
613
-            $this->{$prop}= $value;
614
-        }
615
-    }
616
-
617
-    /**
618
-     * Sets up the message for sending.
619
-     *
620
-     * @param  EE_message $message the message object that contains details about the message.
621
-     * @param EE_message_type $message_type The message type object used in combination with this messenger to generate the provided message.
622
-     *
623
-     * @return bool Very important that all messengers return bool for successful send or not.  Error messages can be
624
-     *              added to EE_Error.
625
-     *              true = message sent successfully
626
-     *              false = message not sent but can be retried (i.e. the failure might be just due to communication issues at the time of send).
627
-     *              Throwing a SendMessageException means the message failed sending and cannot be retried.
628
-     *
629
-     * @throws SendMessageException
630
-     */
631
-    final public function send_message($message, EE_message_type $message_type)
632
-    {
633
-        try {
634
-            $this->_validate_and_setup($message);
635
-            $this->_incoming_message_type = $message_type;
636
-            $response = $this->_send_message();
637
-            if ($response instanceof WP_Error) {
638
-                EE_Error::add_error($response->get_error_message(), __FILE__, __FUNCTION__, __LINE__);
639
-                $response = false;
640
-            }
641
-        } catch (\Exception $e) {
642
-            // convert to an instance of SendMessageException
643
-            throw new SendMessageException($e->getMessage());
644
-        }
645
-        return $response;
646
-    }
647
-
648
-
649
-
650
-    /**
651
-     * Sets up and returns message preview
652
-     * @param  EE_Message $message incoming message object
653
-     * @param EE_message_type $message_type This is whatever message type was used in combination with this messenger to generate the message.
654
-     * @param  bool   $send    true we will actually use the _send method (for test sends). FALSE we just return preview
655
-     * @return string          return the message html content
656
-     */
657
-    public function get_preview(EE_Message $message, EE_message_type $message_type, $send = false)
658
-    {
659
-        $this->_validate_and_setup($message);
660
-
661
-        $this->_incoming_message_type = $message_type;
662
-
663
-        if ($send) {
664
-            // are we overriding any existing template fields?
665
-            $settings = apply_filters(
666
-                'FHEE__EE_messenger__get_preview__messenger_test_settings',
667
-                $this->get_existing_test_settings(),
668
-                $this,
669
-                $send,
670
-                $message,
671
-                $message_type
672
-            );
673
-            if (! empty($settings)) {
674
-                foreach ($settings as $field => $value) {
675
-                    $this->_set_template_value($field, $value);
676
-                }
677
-            }
678
-        }
679
-
680
-        // enqueue preview js so that any links/buttons on the page are disabled.
681
-        if (! $send) {
682
-            // the below may seem like duplication.  However, typically if a messenger enqueues scripts/styles,
683
-            // it deregisters all existing wp scripts and styles first.  So the second hook ensures our previewer still gets setup.
684
-            add_action('admin_enqueue_scripts', array( $this, 'add_preview_script' ), 10);
685
-            add_action('wp_enqueue_scripts', array( $this, 'add_preview_script' ), 10);
686
-            add_action('AHEE__EE_messenger__enqueue_scripts_styles', array( $this, 'add_preview_script' ), 10);
687
-        }
688
-
689
-        return $send ? $this->_send_message() : $this->_preview();
690
-    }
691
-
692
-
693
-
694
-
695
-    /**
696
-     * Callback for enqueue_scripts so that we setup the preview script for all previews.
697
-     *
698
-     * @since 4.5.0
699
-     *
700
-     * @return void
701
-     */
702
-    public function add_preview_script()
703
-    {
704
-        // error message
705
-        EE_Registry::$i18n_js_strings['links_disabled'] = __('All the links on this page have been disabled because this is a generated preview message for the purpose of ensuring layout, style, and content setup.  To test generated links, you must trigger an actual message notification.', 'event_espresso');
706
-        wp_register_script('ee-messages-preview-js', EE_LIBRARIES_URL . 'messages/messenger/assets/js/ee-messages-preview.js', array( 'jquery' ), EVENT_ESPRESSO_VERSION, true);
707
-        wp_localize_script('ee-messages-preview-js', 'eei18n', EE_Registry::$i18n_js_strings);
708
-        wp_enqueue_script('ee-messages-preview-js');
709
-    }
710
-
711
-
712
-
713
-
714
-    /**
715
-     * simply validates the incoming message object and then sets up the properties for the messenger
716
-     * @param  EE_Message $message
717
-     * @throws EE_Error
718
-     */
719
-    protected function _validate_and_setup(EE_Message $message)
720
-    {
721
-        $template_pack = $message->get_template_pack();
722
-        $variation = $message->get_template_pack_variation();
723
-
724
-        // verify we have the required template pack value on the $message object.
725
-        if (! $template_pack instanceof EE_Messages_Template_Pack) {
726
-            throw new EE_Error(__('Incoming $message object must have an EE_Messages_Template_Pack object available.', 'event_espresso'));
727
-        }
728
-
729
-        $this->_tmp_pack = $template_pack;
730
-
731
-        $this->_variation = $variation ? $variation : 'default';
732
-
733
-        $template_fields = $this->get_template_fields();
734
-
735
-        foreach ($template_fields as $template => $value) {
736
-            if ($template !== 'extra') {
737
-                $column_value = $message->get_field_or_extra_meta('MSG_' . $template);
738
-                $message_template_value = $column_value ? $column_value : null;
739
-                $this->_set_template_value($template, $message_template_value);
740
-            }
741
-        }
742
-    }
743
-
744
-
745
-
746
-    /**
747
-     * Utility method for child classes to get the contents of a template file and return
748
-     *
749
-     * We're assuming the child messenger class has already setup template args!
750
-     * @param  bool $preview if true we use the preview wrapper otherwise we use main wrapper.
751
-     * @return string
752
-     * @throws \EE_Error
753
-     */
754
-    protected function _get_main_template($preview = false)
755
-    {
756
-        $type = $preview ? 'preview' : 'main';
757
-
758
-        $wrapper_template = $this->_tmp_pack->get_wrapper($this->name, $type);
759
-
760
-        // check file exists and is readable
761
-        if (!is_readable($wrapper_template)) {
762
-            throw new EE_Error(sprintf(__('Unable to access the template file for the %s messenger main content wrapper.  The location being attempted is %s.', 'event_espresso'), ucwords($this->label['singular']), $wrapper_template));
763
-        }
764
-
765
-        // add message type to template args
766
-        $this->_template_args['message_type'] = $this->_incoming_message_type;
767
-
768
-        return EEH_Template::display_template($wrapper_template, $this->_template_args, true);
769
-    }
770
-
771
-
772
-
773
-    /**
774
-     * set the _test_settings_fields property
775
-     *
776
-     * @access protected
777
-     * @return void
778
-     */
779
-    protected function _set_test_settings_fields()
780
-    {
781
-        $this->_test_settings_fields = array();
782
-    }
783
-
784
-
785
-
786
-    /**
787
-     * return the _test_settings_fields property
788
-     * @return array
789
-     */
790
-    public function get_test_settings_fields()
791
-    {
792
-        return $this->_test_settings_fields;
793
-    }
794
-
795
-
796
-
797
-
798
-    /**
799
-     * This just returns any existing test settings that might be saved in the database
800
-     *
801
-     * @access public
802
-     * @return array
803
-     */
804
-    public function get_existing_test_settings()
805
-    {
806
-        /** @var EE_Message_Resource_Manager $Message_Resource_Manager */
807
-        $Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
808
-        $settings = $Message_Resource_Manager->get_active_messengers_option();
809
-        return isset($settings[ $this->name ]['test_settings']) ? $settings[ $this->name ]['test_settings'] : array();
810
-    }
811
-
812
-
813
-
814
-    /**
815
-     * All this does is set the existing test settings (in the db) for the messenger
816
-     *
817
-     * @access public
818
-     * @param $settings
819
-     * @return bool success/fail
820
-     */
821
-    public function set_existing_test_settings($settings)
822
-    {
823
-        /** @var EE_Message_Resource_Manager $Message_Resource_Manager */
824
-        $Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
825
-        $existing = $Message_Resource_Manager->get_active_messengers_option();
826
-        $existing[ $this->name ]['test_settings'] = $settings;
827
-        return $Message_Resource_Manager->update_active_messengers_option($existing);
828
-    }
829
-
830
-
831
-
832
-    /**
833
-     * This just returns the field label for a given field setup in the _template_fields property.
834
-     *
835
-     * @since   4.3.0
836
-     *
837
-     * @param string $field The field to retrieve the label for
838
-     * @return string             The label
839
-     */
840
-    public function get_field_label($field)
841
-    {
842
-        // first let's see if the field requests is in the top level array.
843
-        if (isset($this->_template_fields[ $field ]) && !empty($this->_template_fields[ $field ]['label'])) {
844
-            return $this->_template[ $field ]['label'];
845
-        }
846
-
847
-        // nope so let's look in the extra array to see if it's there HOWEVER if the field exists as a top level index in the extra array then we know the label is in the 'main' index.
848
-        if (isset($this->_template_fields['extra']) && !empty($this->_template_fields['extra'][ $field ]) && !empty($this->_template_fields['extra'][ $field ]['main']['label'])) {
849
-            return $this->_template_fields['extra'][ $field ]['main']['label'];
850
-        }
851
-
852
-        // now it's possible this field may just be existing in any of the extra array items.
853
-        if (!empty($this->_template_fields['extra']) && is_array($this->_template_fields['extra'])) {
854
-            foreach ($this->_template_fields['extra'] as $main_field => $subfields) {
855
-                if (!is_array($subfields)) {
856
-                    continue;
857
-                }
858
-                if (isset($subfields[ $field ]) && !empty($subfields[ $field ]['label'])) {
859
-                    return $subfields[ $field ]['label'];
860
-                }
861
-            }
862
-        }
863
-
864
-        // if we made it here then there's no label set so let's just return the $field.
865
-        return $field;
866
-    }
867
-
868
-
869
-
870
-
871
-    /**
872
-     * This is a method called from EE_messages when this messenger is a generating messenger and the sending messenger is a different messenger.  Child messengers can set hooks for the sending messenger to callback on if necessary (i.e. swap out css files or something else).
873
-     *
874
-     * @since 4.5.0
875
-     *
876
-     * @param string $sending_messenger_name the name of the sending messenger so we only set the hooks needed.
877
-     *
878
-     * @return void
879
-     */
880
-    public function do_secondary_messenger_hooks($sending_messenger_name)
881
-    {
882
-        return;
883
-    }
430
+	/**
431
+	 * Returns the valid message types associated with this messenger.
432
+	 *
433
+	 * @since 4.5.0
434
+	 *
435
+	 * @return array
436
+	 */
437
+	public function get_valid_message_types()
438
+	{
439
+		$class = get_class($this);
440
+
441
+		// messenger specific filter
442
+		// messenger specific filter
443
+		$valid_types = apply_filters('FHEE__' . $class . '__get_valid_message_types__valid_types', $this->_valid_message_types, $this);
444
+
445
+		// all messengers filter
446
+		$valid_types = apply_filters('FHEE__EE_messenger__get_valid_message_types__valid_types', $valid_types, $this);
447
+		return $valid_types;
448
+	}
449
+
450
+
451
+
452
+
453
+
454
+	/**
455
+	 * this is just used by the custom validators (EE_Messages_Validator classes) to modify the _validator_config for certain message_type/messenger combos where a context may only use certain shortcodes etc.
456
+	 *
457
+	 * @access public
458
+	 * @param array $new_config Whatever is put in here will reset the _validator_config property
459
+	 */
460
+	public function set_validator_config($new_config)
461
+	{
462
+		$this->_validator_config = $new_config;
463
+	}
464
+
465
+
466
+
467
+
468
+	/**
469
+	 * This returns the _validator_config property
470
+	 *
471
+	 * @access public
472
+	 * @return array
473
+	 */
474
+	public function get_validator_config()
475
+	{
476
+		$class = get_class($this);
477
+
478
+		$config = apply_filters('FHEE__' . $class . '__get_validator_config', $this->_validator_config, $this);
479
+		$config = apply_filters('FHEE__EE_messenger__get_validator_config', $config, $this);
480
+		return $config;
481
+	}
482
+
483
+
484
+
485
+
486
+	/**
487
+	 * this public method accepts a page slug (for an EE_admin page) and will return the response from the child class callback function if that page is registered via the `_admin_registered_page` property set by the child class.
488
+	 *
489
+	 * @param string $page the slug of the EE admin page
490
+	 * @param array $message_types an array of active message type objects
491
+	 * @param string $action the page action (to allow for more specific handling - i.e. edit vs. add pages)
492
+	 * @param array $extra  This is just an extra argument that can be used to pass additional data for setting up page content.
493
+	 * @access public
494
+	 * @return string content for page
495
+	 */
496
+	public function get_messenger_admin_page_content($page, $action = null, $extra = array(), $message_types = array())
497
+	{
498
+		return $this->_get_admin_page_content($page, $action, $extra, $message_types);
499
+	}
500
+
501
+
502
+
503
+	/**
504
+	 * @param $message_types
505
+	 * @param array $extra
506
+	 * @return mixed|string
507
+	 */
508
+	protected function _get_admin_content_events_edit($message_types, $extra)
509
+	{
510
+		// defaults
511
+		$template_args = array();
512
+		$selector_rows = '';
513
+
514
+		// we don't need message types here so we're just going to ignore. we do, however, expect the event id here. The event id is needed to provide a link to setup a custom template for this event.
515
+		$event_id = isset($extra['event']) ? $extra['event'] : null;
516
+
517
+		$template_wrapper_path = EE_LIBRARIES . 'messages/messenger/admin_templates/event_switcher_wrapper.template.php';
518
+		$template_row_path = EE_LIBRARIES . 'messages/messenger/admin_templates/event_switcher_row.template.php';
519
+
520
+		// array of template objects for global and custom (non-trashed) (but remember just for this messenger!)
521
+		$global_templates = EEM_Message_Template_Group::instance()->get_all(
522
+			array( array( 'MTP_messenger' => $this->name, 'MTP_is_global' => true, 'MTP_is_active' => true ) )
523
+		);
524
+		$templates_for_event = EEM_Message_Template_Group::instance()->get_all_custom_templates_by_event(
525
+			$event_id,
526
+			array(
527
+				'MTP_messenger' => $this->name,
528
+				'MTP_is_active' => true
529
+			)
530
+		);
531
+		$templates_for_event = !empty($templates_for_event) ? $templates_for_event : array();
532
+
533
+		// so we need to setup the rows for the selectors and we use the global mtpgs (cause those will the active message template groups)
534
+		foreach ($global_templates as $mtpgID => $mtpg) {
535
+			if ($mtpg instanceof EE_Message_Template_Group) {
536
+				// verify this message type is supposed to show on this page
537
+				$mtp_obj = $mtpg->message_type_obj();
538
+				if (! $mtp_obj instanceof EE_message_type) {
539
+					continue;
540
+				}
541
+				$mtp_obj->admin_registered_pages = (array) $mtp_obj->admin_registered_pages;
542
+				if (! in_array('events_edit', $mtp_obj->admin_registered_pages)) {
543
+					continue;
544
+				}
545
+				$select_values = array();
546
+				$select_values[ $mtpgID ] = __('Global', 'event_espresso');
547
+				$default_value = array_key_exists($mtpgID, $templates_for_event) && ! $mtpg->get('MTP_is_override') ? $mtpgID : null;
548
+				// if the override has been set for the global template, then that means even if there are custom templates already created we ignore them because of the set override.
549
+				if (! $mtpg->get('MTP_is_override')) {
550
+					// any custom templates for this message type?
551
+					$custom_templates = EEM_Message_Template_Group::instance()->get_custom_message_template_by_m_and_mt($this->name, $mtpg->message_type());
552
+					foreach ($custom_templates as $cmtpgID => $cmtpg) {
553
+						$select_values[ $cmtpgID ] = $cmtpg->name();
554
+						$default_value = array_key_exists($cmtpgID, $templates_for_event) ? $cmtpgID : $default_value;
555
+					}
556
+				}
557
+				// if there is no $default_value then we set it as the global
558
+				$default_value = empty($default_value) ? $mtpgID : $default_value;
559
+				$edit_url = EEH_URL::add_query_args_and_nonce(array( 'page' => 'espresso_messages', 'action' => 'edit_message_template', 'id' => $default_value ), admin_url('admin.php'));
560
+				$create_url = EEH_URL::add_query_args_and_nonce(array( 'page' => 'espresso_messages', 'action' => 'add_new_message_template', 'GRP_ID' => $default_value ), admin_url('admin.php'));
561
+				$st_args['mt_name'] = ucwords($mtp_obj->label['singular']);
562
+				$st_args['mt_slug'] = $mtpg->message_type();
563
+				$st_args['messenger_slug'] = $this->name;
564
+				$st_args['selector'] = EEH_Form_Fields::select_input('event_message_templates_relation[' . $mtpgID . ']', $select_values, $default_value, 'data-messenger="' . $this->name . '" data-messagetype="' . $mtpg->message_type() . '"', 'message-template-selector');
565
+				// note that  message template group that has override_all_custom set will remove the ability to set a custom message template based off of the global (and that also in turn overrides any other custom templates).
566
+				$st_args['create_button'] = $mtpg->get('MTP_is_override') ? '' : '<a data-messenger="' . $this->name . '" data-messagetype="' . $mtpg->message_type() . '" data-grpid="' . $default_value . '" target="_blank" href="' . $create_url . '" class="button button-small create-mtpg-button">' . __('Create New Custom', 'event_espresso') . '</a>';
567
+				$st_args['create_button'] = EE_Registry::instance()->CAP->current_user_can('ee_edit_messages', 'espresso_messages_add_new_message_template') ? $st_args['create_button'] : '';
568
+				$st_args['edit_button'] = EE_Registry::instance()->CAP->current_user_can('ee_edit_message', 'espresso_messages_edit_message_template', $mtpgID) ? '<a data-messagetype="' . $mtpg->message_type() . '" data-grpid="' . $default_value . '" target="_blank" href="' . $edit_url . '" class="button button-small edit-mtpg-button">' . __('Edit', 'event_espresso') . '</a>' : '';
569
+				$selector_rows .= EEH_Template::display_template($template_row_path, $st_args, true);
570
+			}
571
+		}
572
+
573
+		// if no selectors present then get out.
574
+		if (empty($selector_rows)) {
575
+			return '';
576
+		}
577
+
578
+		$template_args['selector_rows'] = $selector_rows;
579
+		return EEH_Template::display_template($template_wrapper_path, $template_args, true);
580
+	}
581
+
582
+
583
+
584
+
585
+
586
+
587
+	/**
588
+	 * get_template_fields
589
+	 *
590
+	 * @access public
591
+	 * @return array $this->_template_fields
592
+	 */
593
+	public function get_template_fields()
594
+	{
595
+		$template_fields = apply_filters('FHEE__' . get_class($this) . '__get_template_fields', $this->_template_fields, $this);
596
+		$template_fields = apply_filters('FHEE__EE_messenger__get_template_fields', $template_fields, $this);
597
+		return $template_fields;
598
+	}
599
+
600
+
601
+
602
+
603
+	/** SETUP METHODS **/
604
+	/**
605
+	 * The following method doesn't NEED to be used by child classes but might be modified by the specific messenger
606
+	 * @param string $item
607
+	 * @param mixed $value
608
+	 */
609
+	protected function _set_template_value($item, $value)
610
+	{
611
+		if (array_key_exists($item, $this->_template_fields)) {
612
+			$prop = '_' . $item;
613
+			$this->{$prop}= $value;
614
+		}
615
+	}
616
+
617
+	/**
618
+	 * Sets up the message for sending.
619
+	 *
620
+	 * @param  EE_message $message the message object that contains details about the message.
621
+	 * @param EE_message_type $message_type The message type object used in combination with this messenger to generate the provided message.
622
+	 *
623
+	 * @return bool Very important that all messengers return bool for successful send or not.  Error messages can be
624
+	 *              added to EE_Error.
625
+	 *              true = message sent successfully
626
+	 *              false = message not sent but can be retried (i.e. the failure might be just due to communication issues at the time of send).
627
+	 *              Throwing a SendMessageException means the message failed sending and cannot be retried.
628
+	 *
629
+	 * @throws SendMessageException
630
+	 */
631
+	final public function send_message($message, EE_message_type $message_type)
632
+	{
633
+		try {
634
+			$this->_validate_and_setup($message);
635
+			$this->_incoming_message_type = $message_type;
636
+			$response = $this->_send_message();
637
+			if ($response instanceof WP_Error) {
638
+				EE_Error::add_error($response->get_error_message(), __FILE__, __FUNCTION__, __LINE__);
639
+				$response = false;
640
+			}
641
+		} catch (\Exception $e) {
642
+			// convert to an instance of SendMessageException
643
+			throw new SendMessageException($e->getMessage());
644
+		}
645
+		return $response;
646
+	}
647
+
648
+
649
+
650
+	/**
651
+	 * Sets up and returns message preview
652
+	 * @param  EE_Message $message incoming message object
653
+	 * @param EE_message_type $message_type This is whatever message type was used in combination with this messenger to generate the message.
654
+	 * @param  bool   $send    true we will actually use the _send method (for test sends). FALSE we just return preview
655
+	 * @return string          return the message html content
656
+	 */
657
+	public function get_preview(EE_Message $message, EE_message_type $message_type, $send = false)
658
+	{
659
+		$this->_validate_and_setup($message);
660
+
661
+		$this->_incoming_message_type = $message_type;
662
+
663
+		if ($send) {
664
+			// are we overriding any existing template fields?
665
+			$settings = apply_filters(
666
+				'FHEE__EE_messenger__get_preview__messenger_test_settings',
667
+				$this->get_existing_test_settings(),
668
+				$this,
669
+				$send,
670
+				$message,
671
+				$message_type
672
+			);
673
+			if (! empty($settings)) {
674
+				foreach ($settings as $field => $value) {
675
+					$this->_set_template_value($field, $value);
676
+				}
677
+			}
678
+		}
679
+
680
+		// enqueue preview js so that any links/buttons on the page are disabled.
681
+		if (! $send) {
682
+			// the below may seem like duplication.  However, typically if a messenger enqueues scripts/styles,
683
+			// it deregisters all existing wp scripts and styles first.  So the second hook ensures our previewer still gets setup.
684
+			add_action('admin_enqueue_scripts', array( $this, 'add_preview_script' ), 10);
685
+			add_action('wp_enqueue_scripts', array( $this, 'add_preview_script' ), 10);
686
+			add_action('AHEE__EE_messenger__enqueue_scripts_styles', array( $this, 'add_preview_script' ), 10);
687
+		}
688
+
689
+		return $send ? $this->_send_message() : $this->_preview();
690
+	}
691
+
692
+
693
+
694
+
695
+	/**
696
+	 * Callback for enqueue_scripts so that we setup the preview script for all previews.
697
+	 *
698
+	 * @since 4.5.0
699
+	 *
700
+	 * @return void
701
+	 */
702
+	public function add_preview_script()
703
+	{
704
+		// error message
705
+		EE_Registry::$i18n_js_strings['links_disabled'] = __('All the links on this page have been disabled because this is a generated preview message for the purpose of ensuring layout, style, and content setup.  To test generated links, you must trigger an actual message notification.', 'event_espresso');
706
+		wp_register_script('ee-messages-preview-js', EE_LIBRARIES_URL . 'messages/messenger/assets/js/ee-messages-preview.js', array( 'jquery' ), EVENT_ESPRESSO_VERSION, true);
707
+		wp_localize_script('ee-messages-preview-js', 'eei18n', EE_Registry::$i18n_js_strings);
708
+		wp_enqueue_script('ee-messages-preview-js');
709
+	}
710
+
711
+
712
+
713
+
714
+	/**
715
+	 * simply validates the incoming message object and then sets up the properties for the messenger
716
+	 * @param  EE_Message $message
717
+	 * @throws EE_Error
718
+	 */
719
+	protected function _validate_and_setup(EE_Message $message)
720
+	{
721
+		$template_pack = $message->get_template_pack();
722
+		$variation = $message->get_template_pack_variation();
723
+
724
+		// verify we have the required template pack value on the $message object.
725
+		if (! $template_pack instanceof EE_Messages_Template_Pack) {
726
+			throw new EE_Error(__('Incoming $message object must have an EE_Messages_Template_Pack object available.', 'event_espresso'));
727
+		}
728
+
729
+		$this->_tmp_pack = $template_pack;
730
+
731
+		$this->_variation = $variation ? $variation : 'default';
732
+
733
+		$template_fields = $this->get_template_fields();
734
+
735
+		foreach ($template_fields as $template => $value) {
736
+			if ($template !== 'extra') {
737
+				$column_value = $message->get_field_or_extra_meta('MSG_' . $template);
738
+				$message_template_value = $column_value ? $column_value : null;
739
+				$this->_set_template_value($template, $message_template_value);
740
+			}
741
+		}
742
+	}
743
+
744
+
745
+
746
+	/**
747
+	 * Utility method for child classes to get the contents of a template file and return
748
+	 *
749
+	 * We're assuming the child messenger class has already setup template args!
750
+	 * @param  bool $preview if true we use the preview wrapper otherwise we use main wrapper.
751
+	 * @return string
752
+	 * @throws \EE_Error
753
+	 */
754
+	protected function _get_main_template($preview = false)
755
+	{
756
+		$type = $preview ? 'preview' : 'main';
757
+
758
+		$wrapper_template = $this->_tmp_pack->get_wrapper($this->name, $type);
759
+
760
+		// check file exists and is readable
761
+		if (!is_readable($wrapper_template)) {
762
+			throw new EE_Error(sprintf(__('Unable to access the template file for the %s messenger main content wrapper.  The location being attempted is %s.', 'event_espresso'), ucwords($this->label['singular']), $wrapper_template));
763
+		}
764
+
765
+		// add message type to template args
766
+		$this->_template_args['message_type'] = $this->_incoming_message_type;
767
+
768
+		return EEH_Template::display_template($wrapper_template, $this->_template_args, true);
769
+	}
770
+
771
+
772
+
773
+	/**
774
+	 * set the _test_settings_fields property
775
+	 *
776
+	 * @access protected
777
+	 * @return void
778
+	 */
779
+	protected function _set_test_settings_fields()
780
+	{
781
+		$this->_test_settings_fields = array();
782
+	}
783
+
784
+
785
+
786
+	/**
787
+	 * return the _test_settings_fields property
788
+	 * @return array
789
+	 */
790
+	public function get_test_settings_fields()
791
+	{
792
+		return $this->_test_settings_fields;
793
+	}
794
+
795
+
796
+
797
+
798
+	/**
799
+	 * This just returns any existing test settings that might be saved in the database
800
+	 *
801
+	 * @access public
802
+	 * @return array
803
+	 */
804
+	public function get_existing_test_settings()
805
+	{
806
+		/** @var EE_Message_Resource_Manager $Message_Resource_Manager */
807
+		$Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
808
+		$settings = $Message_Resource_Manager->get_active_messengers_option();
809
+		return isset($settings[ $this->name ]['test_settings']) ? $settings[ $this->name ]['test_settings'] : array();
810
+	}
811
+
812
+
813
+
814
+	/**
815
+	 * All this does is set the existing test settings (in the db) for the messenger
816
+	 *
817
+	 * @access public
818
+	 * @param $settings
819
+	 * @return bool success/fail
820
+	 */
821
+	public function set_existing_test_settings($settings)
822
+	{
823
+		/** @var EE_Message_Resource_Manager $Message_Resource_Manager */
824
+		$Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
825
+		$existing = $Message_Resource_Manager->get_active_messengers_option();
826
+		$existing[ $this->name ]['test_settings'] = $settings;
827
+		return $Message_Resource_Manager->update_active_messengers_option($existing);
828
+	}
829
+
830
+
831
+
832
+	/**
833
+	 * This just returns the field label for a given field setup in the _template_fields property.
834
+	 *
835
+	 * @since   4.3.0
836
+	 *
837
+	 * @param string $field The field to retrieve the label for
838
+	 * @return string             The label
839
+	 */
840
+	public function get_field_label($field)
841
+	{
842
+		// first let's see if the field requests is in the top level array.
843
+		if (isset($this->_template_fields[ $field ]) && !empty($this->_template_fields[ $field ]['label'])) {
844
+			return $this->_template[ $field ]['label'];
845
+		}
846
+
847
+		// nope so let's look in the extra array to see if it's there HOWEVER if the field exists as a top level index in the extra array then we know the label is in the 'main' index.
848
+		if (isset($this->_template_fields['extra']) && !empty($this->_template_fields['extra'][ $field ]) && !empty($this->_template_fields['extra'][ $field ]['main']['label'])) {
849
+			return $this->_template_fields['extra'][ $field ]['main']['label'];
850
+		}
851
+
852
+		// now it's possible this field may just be existing in any of the extra array items.
853
+		if (!empty($this->_template_fields['extra']) && is_array($this->_template_fields['extra'])) {
854
+			foreach ($this->_template_fields['extra'] as $main_field => $subfields) {
855
+				if (!is_array($subfields)) {
856
+					continue;
857
+				}
858
+				if (isset($subfields[ $field ]) && !empty($subfields[ $field ]['label'])) {
859
+					return $subfields[ $field ]['label'];
860
+				}
861
+			}
862
+		}
863
+
864
+		// if we made it here then there's no label set so let's just return the $field.
865
+		return $field;
866
+	}
867
+
868
+
869
+
870
+
871
+	/**
872
+	 * This is a method called from EE_messages when this messenger is a generating messenger and the sending messenger is a different messenger.  Child messengers can set hooks for the sending messenger to callback on if necessary (i.e. swap out css files or something else).
873
+	 *
874
+	 * @since 4.5.0
875
+	 *
876
+	 * @param string $sending_messenger_name the name of the sending messenger so we only set the hooks needed.
877
+	 *
878
+	 * @return void
879
+	 */
880
+	public function do_secondary_messenger_hooks($sending_messenger_name)
881
+	{
882
+		return;
883
+	}
884 884
 }
Please login to merge, or discard this patch.
Spacing   +39 added lines, -39 removed lines patch added patch discarded remove patch
@@ -417,7 +417,7 @@  discard block
 block discarded – undo
417 417
         $class = get_class($this);
418 418
 
419 419
         // messenger specific filter
420
-        $default_types = apply_filters('FHEE__' . $class . '__get_default_message_types__default_types', $this->_default_message_types, $this);
420
+        $default_types = apply_filters('FHEE__'.$class.'__get_default_message_types__default_types', $this->_default_message_types, $this);
421 421
 
422 422
         // all messengers filter
423 423
         $default_types = apply_filters('FHEE__EE_messenger__get_default_message_types__default_types', $default_types, $this);
@@ -440,7 +440,7 @@  discard block
 block discarded – undo
440 440
 
441 441
         // messenger specific filter
442 442
         // messenger specific filter
443
-        $valid_types = apply_filters('FHEE__' . $class . '__get_valid_message_types__valid_types', $this->_valid_message_types, $this);
443
+        $valid_types = apply_filters('FHEE__'.$class.'__get_valid_message_types__valid_types', $this->_valid_message_types, $this);
444 444
 
445 445
         // all messengers filter
446 446
         $valid_types = apply_filters('FHEE__EE_messenger__get_valid_message_types__valid_types', $valid_types, $this);
@@ -475,7 +475,7 @@  discard block
 block discarded – undo
475 475
     {
476 476
         $class = get_class($this);
477 477
 
478
-        $config = apply_filters('FHEE__' . $class . '__get_validator_config', $this->_validator_config, $this);
478
+        $config = apply_filters('FHEE__'.$class.'__get_validator_config', $this->_validator_config, $this);
479 479
         $config = apply_filters('FHEE__EE_messenger__get_validator_config', $config, $this);
480 480
         return $config;
481 481
     }
@@ -514,12 +514,12 @@  discard block
 block discarded – undo
514 514
         // we don't need message types here so we're just going to ignore. we do, however, expect the event id here. The event id is needed to provide a link to setup a custom template for this event.
515 515
         $event_id = isset($extra['event']) ? $extra['event'] : null;
516 516
 
517
-        $template_wrapper_path = EE_LIBRARIES . 'messages/messenger/admin_templates/event_switcher_wrapper.template.php';
518
-        $template_row_path = EE_LIBRARIES . 'messages/messenger/admin_templates/event_switcher_row.template.php';
517
+        $template_wrapper_path = EE_LIBRARIES.'messages/messenger/admin_templates/event_switcher_wrapper.template.php';
518
+        $template_row_path = EE_LIBRARIES.'messages/messenger/admin_templates/event_switcher_row.template.php';
519 519
 
520 520
         // array of template objects for global and custom (non-trashed) (but remember just for this messenger!)
521 521
         $global_templates = EEM_Message_Template_Group::instance()->get_all(
522
-            array( array( 'MTP_messenger' => $this->name, 'MTP_is_global' => true, 'MTP_is_active' => true ) )
522
+            array(array('MTP_messenger' => $this->name, 'MTP_is_global' => true, 'MTP_is_active' => true))
523 523
         );
524 524
         $templates_for_event = EEM_Message_Template_Group::instance()->get_all_custom_templates_by_event(
525 525
             $event_id,
@@ -528,44 +528,44 @@  discard block
 block discarded – undo
528 528
                 'MTP_is_active' => true
529 529
             )
530 530
         );
531
-        $templates_for_event = !empty($templates_for_event) ? $templates_for_event : array();
531
+        $templates_for_event = ! empty($templates_for_event) ? $templates_for_event : array();
532 532
 
533 533
         // so we need to setup the rows for the selectors and we use the global mtpgs (cause those will the active message template groups)
534 534
         foreach ($global_templates as $mtpgID => $mtpg) {
535 535
             if ($mtpg instanceof EE_Message_Template_Group) {
536 536
                 // verify this message type is supposed to show on this page
537 537
                 $mtp_obj = $mtpg->message_type_obj();
538
-                if (! $mtp_obj instanceof EE_message_type) {
538
+                if ( ! $mtp_obj instanceof EE_message_type) {
539 539
                     continue;
540 540
                 }
541 541
                 $mtp_obj->admin_registered_pages = (array) $mtp_obj->admin_registered_pages;
542
-                if (! in_array('events_edit', $mtp_obj->admin_registered_pages)) {
542
+                if ( ! in_array('events_edit', $mtp_obj->admin_registered_pages)) {
543 543
                     continue;
544 544
                 }
545 545
                 $select_values = array();
546
-                $select_values[ $mtpgID ] = __('Global', 'event_espresso');
546
+                $select_values[$mtpgID] = __('Global', 'event_espresso');
547 547
                 $default_value = array_key_exists($mtpgID, $templates_for_event) && ! $mtpg->get('MTP_is_override') ? $mtpgID : null;
548 548
                 // if the override has been set for the global template, then that means even if there are custom templates already created we ignore them because of the set override.
549
-                if (! $mtpg->get('MTP_is_override')) {
549
+                if ( ! $mtpg->get('MTP_is_override')) {
550 550
                     // any custom templates for this message type?
551 551
                     $custom_templates = EEM_Message_Template_Group::instance()->get_custom_message_template_by_m_and_mt($this->name, $mtpg->message_type());
552 552
                     foreach ($custom_templates as $cmtpgID => $cmtpg) {
553
-                        $select_values[ $cmtpgID ] = $cmtpg->name();
553
+                        $select_values[$cmtpgID] = $cmtpg->name();
554 554
                         $default_value = array_key_exists($cmtpgID, $templates_for_event) ? $cmtpgID : $default_value;
555 555
                     }
556 556
                 }
557 557
                 // if there is no $default_value then we set it as the global
558 558
                 $default_value = empty($default_value) ? $mtpgID : $default_value;
559
-                $edit_url = EEH_URL::add_query_args_and_nonce(array( 'page' => 'espresso_messages', 'action' => 'edit_message_template', 'id' => $default_value ), admin_url('admin.php'));
560
-                $create_url = EEH_URL::add_query_args_and_nonce(array( 'page' => 'espresso_messages', 'action' => 'add_new_message_template', 'GRP_ID' => $default_value ), admin_url('admin.php'));
559
+                $edit_url = EEH_URL::add_query_args_and_nonce(array('page' => 'espresso_messages', 'action' => 'edit_message_template', 'id' => $default_value), admin_url('admin.php'));
560
+                $create_url = EEH_URL::add_query_args_and_nonce(array('page' => 'espresso_messages', 'action' => 'add_new_message_template', 'GRP_ID' => $default_value), admin_url('admin.php'));
561 561
                 $st_args['mt_name'] = ucwords($mtp_obj->label['singular']);
562 562
                 $st_args['mt_slug'] = $mtpg->message_type();
563 563
                 $st_args['messenger_slug'] = $this->name;
564
-                $st_args['selector'] = EEH_Form_Fields::select_input('event_message_templates_relation[' . $mtpgID . ']', $select_values, $default_value, 'data-messenger="' . $this->name . '" data-messagetype="' . $mtpg->message_type() . '"', 'message-template-selector');
564
+                $st_args['selector'] = EEH_Form_Fields::select_input('event_message_templates_relation['.$mtpgID.']', $select_values, $default_value, 'data-messenger="'.$this->name.'" data-messagetype="'.$mtpg->message_type().'"', 'message-template-selector');
565 565
                 // note that  message template group that has override_all_custom set will remove the ability to set a custom message template based off of the global (and that also in turn overrides any other custom templates).
566
-                $st_args['create_button'] = $mtpg->get('MTP_is_override') ? '' : '<a data-messenger="' . $this->name . '" data-messagetype="' . $mtpg->message_type() . '" data-grpid="' . $default_value . '" target="_blank" href="' . $create_url . '" class="button button-small create-mtpg-button">' . __('Create New Custom', 'event_espresso') . '</a>';
566
+                $st_args['create_button'] = $mtpg->get('MTP_is_override') ? '' : '<a data-messenger="'.$this->name.'" data-messagetype="'.$mtpg->message_type().'" data-grpid="'.$default_value.'" target="_blank" href="'.$create_url.'" class="button button-small create-mtpg-button">'.__('Create New Custom', 'event_espresso').'</a>';
567 567
                 $st_args['create_button'] = EE_Registry::instance()->CAP->current_user_can('ee_edit_messages', 'espresso_messages_add_new_message_template') ? $st_args['create_button'] : '';
568
-                $st_args['edit_button'] = EE_Registry::instance()->CAP->current_user_can('ee_edit_message', 'espresso_messages_edit_message_template', $mtpgID) ? '<a data-messagetype="' . $mtpg->message_type() . '" data-grpid="' . $default_value . '" target="_blank" href="' . $edit_url . '" class="button button-small edit-mtpg-button">' . __('Edit', 'event_espresso') . '</a>' : '';
568
+                $st_args['edit_button'] = EE_Registry::instance()->CAP->current_user_can('ee_edit_message', 'espresso_messages_edit_message_template', $mtpgID) ? '<a data-messagetype="'.$mtpg->message_type().'" data-grpid="'.$default_value.'" target="_blank" href="'.$edit_url.'" class="button button-small edit-mtpg-button">'.__('Edit', 'event_espresso').'</a>' : '';
569 569
                 $selector_rows .= EEH_Template::display_template($template_row_path, $st_args, true);
570 570
             }
571 571
         }
@@ -592,7 +592,7 @@  discard block
 block discarded – undo
592 592
      */
593 593
     public function get_template_fields()
594 594
     {
595
-        $template_fields = apply_filters('FHEE__' . get_class($this) . '__get_template_fields', $this->_template_fields, $this);
595
+        $template_fields = apply_filters('FHEE__'.get_class($this).'__get_template_fields', $this->_template_fields, $this);
596 596
         $template_fields = apply_filters('FHEE__EE_messenger__get_template_fields', $template_fields, $this);
597 597
         return $template_fields;
598 598
     }
@@ -609,8 +609,8 @@  discard block
 block discarded – undo
609 609
     protected function _set_template_value($item, $value)
610 610
     {
611 611
         if (array_key_exists($item, $this->_template_fields)) {
612
-            $prop = '_' . $item;
613
-            $this->{$prop}= $value;
612
+            $prop = '_'.$item;
613
+            $this->{$prop} = $value;
614 614
         }
615 615
     }
616 616
 
@@ -670,7 +670,7 @@  discard block
 block discarded – undo
670 670
                 $message,
671 671
                 $message_type
672 672
             );
673
-            if (! empty($settings)) {
673
+            if ( ! empty($settings)) {
674 674
                 foreach ($settings as $field => $value) {
675 675
                     $this->_set_template_value($field, $value);
676 676
                 }
@@ -678,12 +678,12 @@  discard block
 block discarded – undo
678 678
         }
679 679
 
680 680
         // enqueue preview js so that any links/buttons on the page are disabled.
681
-        if (! $send) {
681
+        if ( ! $send) {
682 682
             // the below may seem like duplication.  However, typically if a messenger enqueues scripts/styles,
683 683
             // it deregisters all existing wp scripts and styles first.  So the second hook ensures our previewer still gets setup.
684
-            add_action('admin_enqueue_scripts', array( $this, 'add_preview_script' ), 10);
685
-            add_action('wp_enqueue_scripts', array( $this, 'add_preview_script' ), 10);
686
-            add_action('AHEE__EE_messenger__enqueue_scripts_styles', array( $this, 'add_preview_script' ), 10);
684
+            add_action('admin_enqueue_scripts', array($this, 'add_preview_script'), 10);
685
+            add_action('wp_enqueue_scripts', array($this, 'add_preview_script'), 10);
686
+            add_action('AHEE__EE_messenger__enqueue_scripts_styles', array($this, 'add_preview_script'), 10);
687 687
         }
688 688
 
689 689
         return $send ? $this->_send_message() : $this->_preview();
@@ -703,7 +703,7 @@  discard block
 block discarded – undo
703 703
     {
704 704
         // error message
705 705
         EE_Registry::$i18n_js_strings['links_disabled'] = __('All the links on this page have been disabled because this is a generated preview message for the purpose of ensuring layout, style, and content setup.  To test generated links, you must trigger an actual message notification.', 'event_espresso');
706
-        wp_register_script('ee-messages-preview-js', EE_LIBRARIES_URL . 'messages/messenger/assets/js/ee-messages-preview.js', array( 'jquery' ), EVENT_ESPRESSO_VERSION, true);
706
+        wp_register_script('ee-messages-preview-js', EE_LIBRARIES_URL.'messages/messenger/assets/js/ee-messages-preview.js', array('jquery'), EVENT_ESPRESSO_VERSION, true);
707 707
         wp_localize_script('ee-messages-preview-js', 'eei18n', EE_Registry::$i18n_js_strings);
708 708
         wp_enqueue_script('ee-messages-preview-js');
709 709
     }
@@ -722,7 +722,7 @@  discard block
 block discarded – undo
722 722
         $variation = $message->get_template_pack_variation();
723 723
 
724 724
         // verify we have the required template pack value on the $message object.
725
-        if (! $template_pack instanceof EE_Messages_Template_Pack) {
725
+        if ( ! $template_pack instanceof EE_Messages_Template_Pack) {
726 726
             throw new EE_Error(__('Incoming $message object must have an EE_Messages_Template_Pack object available.', 'event_espresso'));
727 727
         }
728 728
 
@@ -734,7 +734,7 @@  discard block
 block discarded – undo
734 734
 
735 735
         foreach ($template_fields as $template => $value) {
736 736
             if ($template !== 'extra') {
737
-                $column_value = $message->get_field_or_extra_meta('MSG_' . $template);
737
+                $column_value = $message->get_field_or_extra_meta('MSG_'.$template);
738 738
                 $message_template_value = $column_value ? $column_value : null;
739 739
                 $this->_set_template_value($template, $message_template_value);
740 740
             }
@@ -758,7 +758,7 @@  discard block
 block discarded – undo
758 758
         $wrapper_template = $this->_tmp_pack->get_wrapper($this->name, $type);
759 759
 
760 760
         // check file exists and is readable
761
-        if (!is_readable($wrapper_template)) {
761
+        if ( ! is_readable($wrapper_template)) {
762 762
             throw new EE_Error(sprintf(__('Unable to access the template file for the %s messenger main content wrapper.  The location being attempted is %s.', 'event_espresso'), ucwords($this->label['singular']), $wrapper_template));
763 763
         }
764 764
 
@@ -806,7 +806,7 @@  discard block
 block discarded – undo
806 806
         /** @var EE_Message_Resource_Manager $Message_Resource_Manager */
807 807
         $Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
808 808
         $settings = $Message_Resource_Manager->get_active_messengers_option();
809
-        return isset($settings[ $this->name ]['test_settings']) ? $settings[ $this->name ]['test_settings'] : array();
809
+        return isset($settings[$this->name]['test_settings']) ? $settings[$this->name]['test_settings'] : array();
810 810
     }
811 811
 
812 812
 
@@ -823,7 +823,7 @@  discard block
 block discarded – undo
823 823
         /** @var EE_Message_Resource_Manager $Message_Resource_Manager */
824 824
         $Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
825 825
         $existing = $Message_Resource_Manager->get_active_messengers_option();
826
-        $existing[ $this->name ]['test_settings'] = $settings;
826
+        $existing[$this->name]['test_settings'] = $settings;
827 827
         return $Message_Resource_Manager->update_active_messengers_option($existing);
828 828
     }
829 829
 
@@ -840,23 +840,23 @@  discard block
 block discarded – undo
840 840
     public function get_field_label($field)
841 841
     {
842 842
         // first let's see if the field requests is in the top level array.
843
-        if (isset($this->_template_fields[ $field ]) && !empty($this->_template_fields[ $field ]['label'])) {
844
-            return $this->_template[ $field ]['label'];
843
+        if (isset($this->_template_fields[$field]) && ! empty($this->_template_fields[$field]['label'])) {
844
+            return $this->_template[$field]['label'];
845 845
         }
846 846
 
847 847
         // nope so let's look in the extra array to see if it's there HOWEVER if the field exists as a top level index in the extra array then we know the label is in the 'main' index.
848
-        if (isset($this->_template_fields['extra']) && !empty($this->_template_fields['extra'][ $field ]) && !empty($this->_template_fields['extra'][ $field ]['main']['label'])) {
849
-            return $this->_template_fields['extra'][ $field ]['main']['label'];
848
+        if (isset($this->_template_fields['extra']) && ! empty($this->_template_fields['extra'][$field]) && ! empty($this->_template_fields['extra'][$field]['main']['label'])) {
849
+            return $this->_template_fields['extra'][$field]['main']['label'];
850 850
         }
851 851
 
852 852
         // now it's possible this field may just be existing in any of the extra array items.
853
-        if (!empty($this->_template_fields['extra']) && is_array($this->_template_fields['extra'])) {
853
+        if ( ! empty($this->_template_fields['extra']) && is_array($this->_template_fields['extra'])) {
854 854
             foreach ($this->_template_fields['extra'] as $main_field => $subfields) {
855
-                if (!is_array($subfields)) {
855
+                if ( ! is_array($subfields)) {
856 856
                     continue;
857 857
                 }
858
-                if (isset($subfields[ $field ]) && !empty($subfields[ $field ]['label'])) {
859
-                    return $subfields[ $field ]['label'];
858
+                if (isset($subfields[$field]) && ! empty($subfields[$field]['label'])) {
859
+                    return $subfields[$field]['label'];
860 860
                 }
861 861
             }
862 862
         }
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
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 = null;
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 = null;
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.
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.
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/EE_Message_To_Generate_From_Request.php 2 patches
Indentation   +103 added lines, -103 removed lines patch added patch discarded remove patch
@@ -16,107 +16,107 @@
 block discarded – undo
16 16
 {
17 17
 
18 18
 
19
-    /**
20
-     * This messenger is used to send the generated message.
21
-     *
22
-     * @type EE_messenger
23
-     */
24
-    protected $_sending_messenger = '';
25
-
26
-
27
-    /**
28
-     * Holds the token from the request.
29
-     * @type string
30
-     */
31
-    public $token = '';
32
-
33
-
34
-    /**
35
-     * Constructor
36
-     * This instantiates the object using arguments from the given request and calling the parent constructor.
37
-     *
38
-     * @param   EE_Message_Resource_Manager $message_resource_manager
39
-     * @param   EE_Request_Handler          $request
40
-     */
41
-    public function __construct(EE_Message_Resource_Manager $message_resource_manager, EE_Request_Handler $request)
42
-    {
43
-        parent::__construct(
44
-            $request->get('gen_msgr'),
45
-            $request->get('message_type'),
46
-            array(),
47
-            $request->get('context')
48
-        );
49
-        if (! $this->valid()) {
50
-            return;
51
-        }
52
-        $this->_sending_messenger = $message_resource_manager->get_active_messenger($request->get('snd_msgr'));
53
-        $this->token = $request->get('token');
54
-        $this->_validate_request();
55
-        $this->_data = $this->_get_data_from_request($request->get('id'));
56
-    }
57
-
58
-
59
-
60
-
61
-    /**
62
-     * @return EE_messenger
63
-     */
64
-    public function sending_messenger()
65
-    {
66
-        return $this->_sending_messenger;
67
-    }
68
-
69
-
70
-
71
-    /**
72
-     * This validates set properties from the incoming request.
73
-     * @throws EE_Error
74
-     */
75
-    protected function _validate_request()
76
-    {
77
-        if (! $this->_sending_messenger instanceof EE_messenger
78
-            || ! $this->_messenger instanceof EE_messenger
79
-            || ! $this->_message_type instanceof EE_message_type
80
-            || empty($this->_context)
81
-            || empty($this->token)
82
-        ) {
83
-            throw new EE_Error(__('The request for the "msg_url_trigger" route has a malformed url.', 'event_espresso'));
84
-        }
85
-    }
86
-
87
-
88
-
89
-    /**
90
-     * This returns the data property according to what is expected from the request.
91
-     * @param $id
92
-     * @throws EE_Error
93
-     * @return mixed (whatever the data is returned from the message type).
94
-     */
95
-    protected function _get_data_from_request($id)
96
-    {
97
-        // get the EE_Registration from the token
98
-        /** @type EE_Registration $registration */
99
-        $registration = EEM_Registration::instance()->get_one(array( array( 'REG_url_link' => $this->token ) ));
100
-        // if no registration then bail early.
101
-        if (! $registration instanceof EE_Registration) {
102
-            throw new EE_Error(__('Unable to complete the request because the token is invalid.', 'event_espresso'));
103
-        }
104
-
105
-        return $this->_get_data_to_use($registration, $id);
106
-    }
107
-
108
-
109
-
110
-    /**
111
-     * This uses the set message type to retrieve the data in the correct format as it came from the url.
112
-     * @throws EE_Error
113
-     * @param EE_Registration $registration
114
-     * @param int             $data_id   This is sometimes used for secondary data a message type requires.
115
-     * @return mixed   Data prepared as needed for generating this message.
116
-     */
117
-    protected function _get_data_to_use($registration, $data_id)
118
-    {
119
-        // use incoming data from url to setup data for the message type requirements
120
-        return $this->_message_type->get_data_for_context($this->_context, $registration, $data_id);
121
-    }
19
+	/**
20
+	 * This messenger is used to send the generated message.
21
+	 *
22
+	 * @type EE_messenger
23
+	 */
24
+	protected $_sending_messenger = '';
25
+
26
+
27
+	/**
28
+	 * Holds the token from the request.
29
+	 * @type string
30
+	 */
31
+	public $token = '';
32
+
33
+
34
+	/**
35
+	 * Constructor
36
+	 * This instantiates the object using arguments from the given request and calling the parent constructor.
37
+	 *
38
+	 * @param   EE_Message_Resource_Manager $message_resource_manager
39
+	 * @param   EE_Request_Handler          $request
40
+	 */
41
+	public function __construct(EE_Message_Resource_Manager $message_resource_manager, EE_Request_Handler $request)
42
+	{
43
+		parent::__construct(
44
+			$request->get('gen_msgr'),
45
+			$request->get('message_type'),
46
+			array(),
47
+			$request->get('context')
48
+		);
49
+		if (! $this->valid()) {
50
+			return;
51
+		}
52
+		$this->_sending_messenger = $message_resource_manager->get_active_messenger($request->get('snd_msgr'));
53
+		$this->token = $request->get('token');
54
+		$this->_validate_request();
55
+		$this->_data = $this->_get_data_from_request($request->get('id'));
56
+	}
57
+
58
+
59
+
60
+
61
+	/**
62
+	 * @return EE_messenger
63
+	 */
64
+	public function sending_messenger()
65
+	{
66
+		return $this->_sending_messenger;
67
+	}
68
+
69
+
70
+
71
+	/**
72
+	 * This validates set properties from the incoming request.
73
+	 * @throws EE_Error
74
+	 */
75
+	protected function _validate_request()
76
+	{
77
+		if (! $this->_sending_messenger instanceof EE_messenger
78
+			|| ! $this->_messenger instanceof EE_messenger
79
+			|| ! $this->_message_type instanceof EE_message_type
80
+			|| empty($this->_context)
81
+			|| empty($this->token)
82
+		) {
83
+			throw new EE_Error(__('The request for the "msg_url_trigger" route has a malformed url.', 'event_espresso'));
84
+		}
85
+	}
86
+
87
+
88
+
89
+	/**
90
+	 * This returns the data property according to what is expected from the request.
91
+	 * @param $id
92
+	 * @throws EE_Error
93
+	 * @return mixed (whatever the data is returned from the message type).
94
+	 */
95
+	protected function _get_data_from_request($id)
96
+	{
97
+		// get the EE_Registration from the token
98
+		/** @type EE_Registration $registration */
99
+		$registration = EEM_Registration::instance()->get_one(array( array( 'REG_url_link' => $this->token ) ));
100
+		// if no registration then bail early.
101
+		if (! $registration instanceof EE_Registration) {
102
+			throw new EE_Error(__('Unable to complete the request because the token is invalid.', 'event_espresso'));
103
+		}
104
+
105
+		return $this->_get_data_to_use($registration, $id);
106
+	}
107
+
108
+
109
+
110
+	/**
111
+	 * This uses the set message type to retrieve the data in the correct format as it came from the url.
112
+	 * @throws EE_Error
113
+	 * @param EE_Registration $registration
114
+	 * @param int             $data_id   This is sometimes used for secondary data a message type requires.
115
+	 * @return mixed   Data prepared as needed for generating this message.
116
+	 */
117
+	protected function _get_data_to_use($registration, $data_id)
118
+	{
119
+		// use incoming data from url to setup data for the message type requirements
120
+		return $this->_message_type->get_data_for_context($this->_context, $registration, $data_id);
121
+	}
122 122
 }
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -46,7 +46,7 @@  discard block
 block discarded – undo
46 46
             array(),
47 47
             $request->get('context')
48 48
         );
49
-        if (! $this->valid()) {
49
+        if ( ! $this->valid()) {
50 50
             return;
51 51
         }
52 52
         $this->_sending_messenger = $message_resource_manager->get_active_messenger($request->get('snd_msgr'));
@@ -74,7 +74,7 @@  discard block
 block discarded – undo
74 74
      */
75 75
     protected function _validate_request()
76 76
     {
77
-        if (! $this->_sending_messenger instanceof EE_messenger
77
+        if ( ! $this->_sending_messenger instanceof EE_messenger
78 78
             || ! $this->_messenger instanceof EE_messenger
79 79
             || ! $this->_message_type instanceof EE_message_type
80 80
             || empty($this->_context)
@@ -96,9 +96,9 @@  discard block
 block discarded – undo
96 96
     {
97 97
         // get the EE_Registration from the token
98 98
         /** @type EE_Registration $registration */
99
-        $registration = EEM_Registration::instance()->get_one(array( array( 'REG_url_link' => $this->token ) ));
99
+        $registration = EEM_Registration::instance()->get_one(array(array('REG_url_link' => $this->token)));
100 100
         // if no registration then bail early.
101
-        if (! $registration instanceof EE_Registration) {
101
+        if ( ! $registration instanceof EE_Registration) {
102 102
             throw new EE_Error(__('Unable to complete the request because the token is invalid.', 'event_espresso'));
103 103
         }
104 104
 
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.
core/libraries/messages/data_class/EE_Messages_REG_incoming_data.class.php 2 patches
Indentation   +132 added lines, -132 removed lines patch added patch discarded remove patch
@@ -18,136 +18,136 @@
 block discarded – undo
18 18
 
19 19
 
20 20
 
21
-    /**
22
-     * For the constructor of this special preview class.
23
-     *
24
-     * The data is expected to be an array that came from the $_POST and $_GET and should have at least one property from the list looked for.
25
-     *
26
-     * @param EE_Registration|array $data
27
-     * @throws \EE_Error
28
-     */
29
-    public function __construct($data)
30
-    {
31
-        $filtered_reg_status = null;
32
-
33
-        if (! is_array($data) && $data instanceof EE_Registration) {
34
-            $this->reg_obj = $data;
35
-        } else {
36
-            $this->reg_obj = is_array($data) && isset($data[0]) && $data[0] instanceof EE_Registration ? $data[0] : null;
37
-            $filtered_reg_status = is_array($data) && ! empty($data[1]) ? $data[1] : null;
38
-        }
39
-
40
-        if (! $this->reg_obj instanceof EE_Registration) {
41
-            throw new EE_Error(
42
-                sprintf(
43
-                    __('%1$s requires the incoming data argument to be an instance of %2$s or an array where the first value is an instance of %2$s', 'event_espresso'),
44
-                    'EE_Messages_REG_incoming_data',
45
-                    'EE_Registration'
46
-                )
47
-            );
48
-        }
49
-
50
-        $data = array(
51
-            'reg_obj' => $this->reg_obj,
52
-            'filtered_reg_status' => $filtered_reg_status
53
-            );
54
-
55
-        parent::__construct($data);
56
-    }
57
-
58
-    /**
59
-     * Returns database safe representation of the data later used to when instantiating this object.
60
-     *
61
-     * @param mixed $data The incoming data to be prepped.
62
-     *
63
-     * @return array   The prepped data for db
64
-     */
65
-    public static function convert_data_for_persistent_storage($data)
66
-    {
67
-        $prepped_data = array();
68
-        if (! is_array($data) && $data instanceof EE_Registration) {
69
-            $prepped_data['Registration'] = $data->ID();
70
-            return $prepped_data;
71
-        } elseif (! is_array($data)) {
72
-            return array();
73
-        } else {
74
-            if ($data[0] instanceof EE_Registration) {
75
-                $prepped_data['Registration'] = $data[0];
76
-            }
77
-            if (! empty($data[1])) {
78
-                $prepped_data['filter'] = $data[1];
79
-            }
80
-        }
81
-
82
-        return $prepped_data;
83
-    }
84
-
85
-    /**
86
-     * Data that has been stored in persistent storage that was prepped by _convert_data_for_persistent_storage
87
-     * can be sent into this method and converted back into the format used for instantiating with this data handler.
88
-     *
89
-     * @param $data
90
-     *
91
-     * @return mixed
92
-     */
93
-    public static function convert_data_from_persistent_storage($data)
94
-    {
95
-        $registration = null;
96
-        // $data['Registration'] could be either an ID (back compat) or a registration object (prepped using old system).
97
-        if (isset($data['Registration'])) {
98
-            $registration = $data['Registration'] instanceof EE_Registration
99
-                ? $data['Registration']
100
-                : EEM_Registration::instance()->get_one_by_ID($data['Registration']);
101
-        }
102
-        $prepped_data = array(
103
-            0 => $registration,
104
-            1 => isset($data['filter']) ? $data['filter'] : null
105
-        );
106
-        return $prepped_data;
107
-    }
108
-
109
-
110
-    /**
111
-     * This will just setup the _events property in the expected format.
112
-     * @return void
113
-     */
114
-    protected function _setup_data()
115
-    {
116
-
117
-        // now let's loop and set up the _events property.  At the same time we'll set up attendee properties.
118
-        $this->filtered_reg_status = $this->_data['filtered_reg_status'];
119
-        // get txn
120
-        $this->txn = $this->reg_obj->transaction();
121
-        // possible session stuff?
122
-        $session = $this->txn->session_data();
123
-        $session_data =  $session instanceof EE_Session ? $session->get_session_data() : array();
124
-
125
-        // other data from the session (if possible)
126
-        $this->user_id = isset($session_data['user_id']) ? $session_data['user_id'] : '';
127
-        $this->ip_address = isset($session_data['ip_address']) ? $session_data['ip_address'] : '';
128
-        $this->user_agent = isset($session_data['user_agent']) ? $session_data['user_agent'] : '';
129
-        $this->init_access = $this->last_access = '';
130
-
131
-        $this->payment = $this->txn->get_first_related('Payment');
132
-        // if there is no payments associated with the transaction
133
-        // then we just create a default payment object for potential parsing.
134
-        $this->payment = empty($this->payment)
135
-            ? EE_Payment::new_instance(
136
-                array(
137
-                    'STS_ID'               => EEM_Payment::status_id_pending,
138
-                    'PAY_timestamp'        => time(),
139
-                    'PMD_ID'               => $this->txn->payment_method_ID(),
140
-                    'PAY_gateway_response' => $this->txn->gateway_response_on_transaction(),
141
-                )
142
-            )
143
-            : $this->payment;
144
-
145
-
146
-        // get reg_objs for txn
147
-        $this->reg_objs = $this->txn->registrations();
148
-
149
-        // now we can set things up like we do for other handlers
150
-
151
-        $this->_assemble_data();
152
-    }
21
+	/**
22
+	 * For the constructor of this special preview class.
23
+	 *
24
+	 * The data is expected to be an array that came from the $_POST and $_GET and should have at least one property from the list looked for.
25
+	 *
26
+	 * @param EE_Registration|array $data
27
+	 * @throws \EE_Error
28
+	 */
29
+	public function __construct($data)
30
+	{
31
+		$filtered_reg_status = null;
32
+
33
+		if (! is_array($data) && $data instanceof EE_Registration) {
34
+			$this->reg_obj = $data;
35
+		} else {
36
+			$this->reg_obj = is_array($data) && isset($data[0]) && $data[0] instanceof EE_Registration ? $data[0] : null;
37
+			$filtered_reg_status = is_array($data) && ! empty($data[1]) ? $data[1] : null;
38
+		}
39
+
40
+		if (! $this->reg_obj instanceof EE_Registration) {
41
+			throw new EE_Error(
42
+				sprintf(
43
+					__('%1$s requires the incoming data argument to be an instance of %2$s or an array where the first value is an instance of %2$s', 'event_espresso'),
44
+					'EE_Messages_REG_incoming_data',
45
+					'EE_Registration'
46
+				)
47
+			);
48
+		}
49
+
50
+		$data = array(
51
+			'reg_obj' => $this->reg_obj,
52
+			'filtered_reg_status' => $filtered_reg_status
53
+			);
54
+
55
+		parent::__construct($data);
56
+	}
57
+
58
+	/**
59
+	 * Returns database safe representation of the data later used to when instantiating this object.
60
+	 *
61
+	 * @param mixed $data The incoming data to be prepped.
62
+	 *
63
+	 * @return array   The prepped data for db
64
+	 */
65
+	public static function convert_data_for_persistent_storage($data)
66
+	{
67
+		$prepped_data = array();
68
+		if (! is_array($data) && $data instanceof EE_Registration) {
69
+			$prepped_data['Registration'] = $data->ID();
70
+			return $prepped_data;
71
+		} elseif (! is_array($data)) {
72
+			return array();
73
+		} else {
74
+			if ($data[0] instanceof EE_Registration) {
75
+				$prepped_data['Registration'] = $data[0];
76
+			}
77
+			if (! empty($data[1])) {
78
+				$prepped_data['filter'] = $data[1];
79
+			}
80
+		}
81
+
82
+		return $prepped_data;
83
+	}
84
+
85
+	/**
86
+	 * Data that has been stored in persistent storage that was prepped by _convert_data_for_persistent_storage
87
+	 * can be sent into this method and converted back into the format used for instantiating with this data handler.
88
+	 *
89
+	 * @param $data
90
+	 *
91
+	 * @return mixed
92
+	 */
93
+	public static function convert_data_from_persistent_storage($data)
94
+	{
95
+		$registration = null;
96
+		// $data['Registration'] could be either an ID (back compat) or a registration object (prepped using old system).
97
+		if (isset($data['Registration'])) {
98
+			$registration = $data['Registration'] instanceof EE_Registration
99
+				? $data['Registration']
100
+				: EEM_Registration::instance()->get_one_by_ID($data['Registration']);
101
+		}
102
+		$prepped_data = array(
103
+			0 => $registration,
104
+			1 => isset($data['filter']) ? $data['filter'] : null
105
+		);
106
+		return $prepped_data;
107
+	}
108
+
109
+
110
+	/**
111
+	 * This will just setup the _events property in the expected format.
112
+	 * @return void
113
+	 */
114
+	protected function _setup_data()
115
+	{
116
+
117
+		// now let's loop and set up the _events property.  At the same time we'll set up attendee properties.
118
+		$this->filtered_reg_status = $this->_data['filtered_reg_status'];
119
+		// get txn
120
+		$this->txn = $this->reg_obj->transaction();
121
+		// possible session stuff?
122
+		$session = $this->txn->session_data();
123
+		$session_data =  $session instanceof EE_Session ? $session->get_session_data() : array();
124
+
125
+		// other data from the session (if possible)
126
+		$this->user_id = isset($session_data['user_id']) ? $session_data['user_id'] : '';
127
+		$this->ip_address = isset($session_data['ip_address']) ? $session_data['ip_address'] : '';
128
+		$this->user_agent = isset($session_data['user_agent']) ? $session_data['user_agent'] : '';
129
+		$this->init_access = $this->last_access = '';
130
+
131
+		$this->payment = $this->txn->get_first_related('Payment');
132
+		// if there is no payments associated with the transaction
133
+		// then we just create a default payment object for potential parsing.
134
+		$this->payment = empty($this->payment)
135
+			? EE_Payment::new_instance(
136
+				array(
137
+					'STS_ID'               => EEM_Payment::status_id_pending,
138
+					'PAY_timestamp'        => time(),
139
+					'PMD_ID'               => $this->txn->payment_method_ID(),
140
+					'PAY_gateway_response' => $this->txn->gateway_response_on_transaction(),
141
+				)
142
+			)
143
+			: $this->payment;
144
+
145
+
146
+		// get reg_objs for txn
147
+		$this->reg_objs = $this->txn->registrations();
148
+
149
+		// now we can set things up like we do for other handlers
150
+
151
+		$this->_assemble_data();
152
+	}
153 153
 }
Please login to merge, or discard this patch.
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -30,14 +30,14 @@  discard block
 block discarded – undo
30 30
     {
31 31
         $filtered_reg_status = null;
32 32
 
33
-        if (! is_array($data) && $data instanceof EE_Registration) {
33
+        if ( ! is_array($data) && $data instanceof EE_Registration) {
34 34
             $this->reg_obj = $data;
35 35
         } else {
36 36
             $this->reg_obj = is_array($data) && isset($data[0]) && $data[0] instanceof EE_Registration ? $data[0] : null;
37 37
             $filtered_reg_status = is_array($data) && ! empty($data[1]) ? $data[1] : null;
38 38
         }
39 39
 
40
-        if (! $this->reg_obj instanceof EE_Registration) {
40
+        if ( ! $this->reg_obj instanceof EE_Registration) {
41 41
             throw new EE_Error(
42 42
                 sprintf(
43 43
                     __('%1$s requires the incoming data argument to be an instance of %2$s or an array where the first value is an instance of %2$s', 'event_espresso'),
@@ -65,16 +65,16 @@  discard block
 block discarded – undo
65 65
     public static function convert_data_for_persistent_storage($data)
66 66
     {
67 67
         $prepped_data = array();
68
-        if (! is_array($data) && $data instanceof EE_Registration) {
68
+        if ( ! is_array($data) && $data instanceof EE_Registration) {
69 69
             $prepped_data['Registration'] = $data->ID();
70 70
             return $prepped_data;
71
-        } elseif (! is_array($data)) {
71
+        } elseif ( ! is_array($data)) {
72 72
             return array();
73 73
         } else {
74 74
             if ($data[0] instanceof EE_Registration) {
75 75
                 $prepped_data['Registration'] = $data[0];
76 76
             }
77
-            if (! empty($data[1])) {
77
+            if ( ! empty($data[1])) {
78 78
                 $prepped_data['filter'] = $data[1];
79 79
             }
80 80
         }
@@ -120,7 +120,7 @@  discard block
 block discarded – undo
120 120
         $this->txn = $this->reg_obj->transaction();
121 121
         // possible session stuff?
122 122
         $session = $this->txn->session_data();
123
-        $session_data =  $session instanceof EE_Session ? $session->get_session_data() : array();
123
+        $session_data = $session instanceof EE_Session ? $session->get_session_data() : array();
124 124
 
125 125
         // other data from the session (if possible)
126 126
         $this->user_id = isset($session_data['user_id']) ? $session_data['user_id'] : '';
Please login to merge, or discard this patch.
libraries/messages/data_class/EE_Messages_Preview_incoming_data.class.php 2 patches
Indentation   +554 added lines, -554 removed lines patch added patch discarded remove patch
@@ -20,586 +20,586 @@
 block discarded – undo
20 20
 class EE_Messages_Preview_incoming_data extends EE_Messages_incoming_data
21 21
 {
22 22
     
23
-    // some specific properties we need for this class
24
-    private $_events = array();
25
-    private $_attendees = array();
26
-    private $_registrations = array();
23
+	// some specific properties we need for this class
24
+	private $_events = array();
25
+	private $_attendees = array();
26
+	private $_registrations = array();
27 27
     
28 28
     
29
-    /**
30
-     * For the constructor of this special preview class.  We're either looking for an event id or empty data.  If we
31
-     * have an event id (or ids) then we'll use that as the source for the "dummy" data.  If the data is empty then
32
-     * we'll get the first three published events from the users database and use that as a source.
33
-     *
34
-     * @param array $data
35
-     */
36
-    public function __construct($data = array())
37
-    {
38
-        $this->_data = isset($data['event_ids']) ? $data['event_ids'] : array();
39
-        $this->_setup_attendees_events();
40
-        parent::__construct($data);
41
-    }
29
+	/**
30
+	 * For the constructor of this special preview class.  We're either looking for an event id or empty data.  If we
31
+	 * have an event id (or ids) then we'll use that as the source for the "dummy" data.  If the data is empty then
32
+	 * we'll get the first three published events from the users database and use that as a source.
33
+	 *
34
+	 * @param array $data
35
+	 */
36
+	public function __construct($data = array())
37
+	{
38
+		$this->_data = isset($data['event_ids']) ? $data['event_ids'] : array();
39
+		$this->_setup_attendees_events();
40
+		parent::__construct($data);
41
+	}
42 42
     
43 43
     
44
-    /**
45
-     * Returns database safe representation of the data later used to when instantiating this object.
46
-     *
47
-     * @param array $data The incoming data to be prepped.
48
-     *
49
-     * @return array   The prepped data for db
50
-     */
51
-    public static function convert_data_for_persistent_storage($data)
52
-    {
53
-        return $data;
54
-    }
44
+	/**
45
+	 * Returns database safe representation of the data later used to when instantiating this object.
46
+	 *
47
+	 * @param array $data The incoming data to be prepped.
48
+	 *
49
+	 * @return array   The prepped data for db
50
+	 */
51
+	public static function convert_data_for_persistent_storage($data)
52
+	{
53
+		return $data;
54
+	}
55 55
     
56 56
     
57
-    /**
58
-     * Data that has been stored in persistent storage that was prepped by _convert_data_for_persistent_storage
59
-     * can be sent into this method and converted back into the format used for instantiating with this data handler.
60
-     *
61
-     * @param array $data
62
-     *
63
-     * @return array
64
-     */
65
-    public static function convert_data_from_persistent_storage($data)
66
-    {
67
-        return $data;
68
-    }
57
+	/**
58
+	 * Data that has been stored in persistent storage that was prepped by _convert_data_for_persistent_storage
59
+	 * can be sent into this method and converted back into the format used for instantiating with this data handler.
60
+	 *
61
+	 * @param array $data
62
+	 *
63
+	 * @return array
64
+	 */
65
+	public static function convert_data_from_persistent_storage($data)
66
+	{
67
+		return $data;
68
+	}
69 69
     
70 70
     
71
-    /**
72
-     * This will just setup the _events property in the expected format.
73
-     *
74
-     * @throws \EE_Error
75
-     */
76
-    private function _setup_attendees_events()
77
-    {
78
-        
79
-        // setup some attendee objects
80
-        $attendees = $this->_get_some_attendees();
81
-        
82
-        // if empty $data we'll do a query to get some events from the server. otherwise we'll retrieve the event data for the given ids.
83
-        $events = $this->_get_some_events($this->_data);
84
-        
85
-        $answers_n_questions = $this->_get_some_q_and_as();
86
-        
87
-        if (count($events) < 1) {
88
-            throw new EE_Error(__(
89
-                'We can\'t generate a preview for you because there are no active events in your database',
90
-                'event_espresso'
91
-            ));
92
-        }
93
-        
94
-        
95
-        // now let's loop and set up the _events property.  At the same time we'll set up attendee properties.
96
-        
97
-        
98
-        // we'll actually use the generated line_item identifiers for our loop
99
-        $dtts = $tkts = array();
100
-        foreach ($events as $id => $event) {
101
-            if (! $event instanceof EE_Event) {
102
-                continue;
103
-            }
104
-            $this->_events[ $id ]['ID']       = $id;
105
-            $this->_events[ $id ]['name']     = $event->get('EVT_name');
106
-            $datetime                       = $event->get_first_related('Datetime');
107
-            $tickets                        = $datetime instanceof EE_Datetime ? $datetime->get_many_related(
108
-                'Ticket',
109
-                array('default_where_conditions' => 'none')
110
-            ) : array();
111
-            $this->_events[ $id ]['event']    = $event;
112
-            $this->_events[ $id ]['reg_objs'] = array();
113
-            $this->_events[ $id ]['tkt_objs'] = $tickets;
114
-            $this->_events[ $id ]['dtt_objs'] = array();
71
+	/**
72
+	 * This will just setup the _events property in the expected format.
73
+	 *
74
+	 * @throws \EE_Error
75
+	 */
76
+	private function _setup_attendees_events()
77
+	{
78
+        
79
+		// setup some attendee objects
80
+		$attendees = $this->_get_some_attendees();
81
+        
82
+		// if empty $data we'll do a query to get some events from the server. otherwise we'll retrieve the event data for the given ids.
83
+		$events = $this->_get_some_events($this->_data);
84
+        
85
+		$answers_n_questions = $this->_get_some_q_and_as();
86
+        
87
+		if (count($events) < 1) {
88
+			throw new EE_Error(__(
89
+				'We can\'t generate a preview for you because there are no active events in your database',
90
+				'event_espresso'
91
+			));
92
+		}
93
+        
94
+        
95
+		// now let's loop and set up the _events property.  At the same time we'll set up attendee properties.
96
+        
97
+        
98
+		// we'll actually use the generated line_item identifiers for our loop
99
+		$dtts = $tkts = array();
100
+		foreach ($events as $id => $event) {
101
+			if (! $event instanceof EE_Event) {
102
+				continue;
103
+			}
104
+			$this->_events[ $id ]['ID']       = $id;
105
+			$this->_events[ $id ]['name']     = $event->get('EVT_name');
106
+			$datetime                       = $event->get_first_related('Datetime');
107
+			$tickets                        = $datetime instanceof EE_Datetime ? $datetime->get_many_related(
108
+				'Ticket',
109
+				array('default_where_conditions' => 'none')
110
+			) : array();
111
+			$this->_events[ $id ]['event']    = $event;
112
+			$this->_events[ $id ]['reg_objs'] = array();
113
+			$this->_events[ $id ]['tkt_objs'] = $tickets;
114
+			$this->_events[ $id ]['dtt_objs'] = array();
115 115
             
116
-            $dttcache = array();
117
-            $tkts     = array();
118
-            foreach ($tickets as $ticket) {
119
-                if (! $ticket instanceof EE_Ticket) {
120
-                    continue;
121
-                }
122
-                $reldatetime                     = $ticket->datetimes();
123
-                $tkts[ $ticket->ID() ]             = array();
124
-                $tkts[ $ticket->ID() ]['ticket']   = $ticket;
125
-                $tkts[ $ticket->ID() ]['dtt_objs'] = $reldatetime;
126
-                $tkts[ $ticket->ID() ]['att_objs'] = $attendees;
127
-                $tkts[ $ticket->ID() ]['count']    = count($attendees);
128
-                $tkts[ $ticket->ID() ]['EE_Event'] = $event;
129
-                foreach ($reldatetime as $datetime) {
130
-                    if ($datetime instanceof EE_Datetime && ! isset($dtts[ $datetime->ID() ])) {
131
-                        $this->_events[ $id ]['dtt_objs'][ $datetime->ID() ] = $datetime;
132
-                        $dtts[ $datetime->ID() ]['datetime']               = $datetime;
133
-                        $dtts[ $datetime->ID() ]['tkt_objs'][]             = $ticket;
134
-                        $dtts[ $datetime->ID() ]['evt_objs'][]             = $event;
135
-                        $dttcache[ $datetime->ID() ]                       = $datetime;
136
-                    }
137
-                }
138
-            }
116
+			$dttcache = array();
117
+			$tkts     = array();
118
+			foreach ($tickets as $ticket) {
119
+				if (! $ticket instanceof EE_Ticket) {
120
+					continue;
121
+				}
122
+				$reldatetime                     = $ticket->datetimes();
123
+				$tkts[ $ticket->ID() ]             = array();
124
+				$tkts[ $ticket->ID() ]['ticket']   = $ticket;
125
+				$tkts[ $ticket->ID() ]['dtt_objs'] = $reldatetime;
126
+				$tkts[ $ticket->ID() ]['att_objs'] = $attendees;
127
+				$tkts[ $ticket->ID() ]['count']    = count($attendees);
128
+				$tkts[ $ticket->ID() ]['EE_Event'] = $event;
129
+				foreach ($reldatetime as $datetime) {
130
+					if ($datetime instanceof EE_Datetime && ! isset($dtts[ $datetime->ID() ])) {
131
+						$this->_events[ $id ]['dtt_objs'][ $datetime->ID() ] = $datetime;
132
+						$dtts[ $datetime->ID() ]['datetime']               = $datetime;
133
+						$dtts[ $datetime->ID() ]['tkt_objs'][]             = $ticket;
134
+						$dtts[ $datetime->ID() ]['evt_objs'][]             = $event;
135
+						$dttcache[ $datetime->ID() ]                       = $datetime;
136
+					}
137
+				}
138
+			}
139 139
             
140
-            $this->_events[ $id ]['total_attendees'] = count($attendees);
141
-            $this->_events[ $id ]['att_objs']        = $attendees;
140
+			$this->_events[ $id ]['total_attendees'] = count($attendees);
141
+			$this->_events[ $id ]['att_objs']        = $attendees;
142 142
             
143
-            // let's also setup the dummy attendees property!
144
-            foreach ($attendees as $att_key => $attendee) {
145
-                if (! $attendee instanceof EE_Attendee) {
146
-                    continue;
147
-                }
148
-                $this->_attendees[ $att_key ]['line_ref'][] = $id;  // so later it can be determined what events this attendee registered for!
149
-                $this->_attendees[ $att_key ]['evt_objs'][] = $event;
150
-                $this->_attendees[ $att_key ]['att_obj']    = $attendee;
151
-                // $this->_attendees[$att_key]['registration_id'] = 0;
152
-                $this->_attendees[ $att_key ]['attendee_email'] = $attendee->email();
153
-                $this->_attendees[ $att_key ]['tkt_objs']       = $tickets;
154
-                if ($att_key == 999999991) {
155
-                    $this->_attendees[ $att_key ]['ans_objs'][999]  = $answers_n_questions['answers'][999];
156
-                    $this->_attendees[ $att_key ]['ans_objs'][1002] = $answers_n_questions['answers'][1002];
157
-                    $this->_attendees[ $att_key ]['ans_objs'][1005] = $answers_n_questions['answers'][1005];
158
-                } elseif ($att_key == 999999992) {
159
-                    $this->_attendees[ $att_key ]['ans_objs'][1000] = $answers_n_questions['answers'][1000];
160
-                    $this->_attendees[ $att_key ]['ans_objs'][1003] = $answers_n_questions['answers'][1003];
161
-                    $this->_attendees[ $att_key ]['ans_objs'][1006] = $answers_n_questions['answers'][1006];
162
-                } elseif ($att_key == 999999993) {
163
-                    $this->_attendees[ $att_key ]['ans_objs'][1001] = $answers_n_questions['answers'][1001];
164
-                    $this->_attendees[ $att_key ]['ans_objs'][1004] = $answers_n_questions['answers'][1004];
165
-                    $this->_attendees[ $att_key ]['ans_objs'][1007] = $answers_n_questions['answers'][1007];
166
-                }
167
-            }
168
-        }
169
-        
170
-        $this->tickets            = $tkts;
171
-        $this->datetimes          = $dtts;
172
-        $this->answers            = $answers_n_questions['answers'];
173
-        $this->questions          = $answers_n_questions['questions'];
174
-        $this->total_ticket_count = count($tkts) * count($this->_attendees);
175
-    }
143
+			// let's also setup the dummy attendees property!
144
+			foreach ($attendees as $att_key => $attendee) {
145
+				if (! $attendee instanceof EE_Attendee) {
146
+					continue;
147
+				}
148
+				$this->_attendees[ $att_key ]['line_ref'][] = $id;  // so later it can be determined what events this attendee registered for!
149
+				$this->_attendees[ $att_key ]['evt_objs'][] = $event;
150
+				$this->_attendees[ $att_key ]['att_obj']    = $attendee;
151
+				// $this->_attendees[$att_key]['registration_id'] = 0;
152
+				$this->_attendees[ $att_key ]['attendee_email'] = $attendee->email();
153
+				$this->_attendees[ $att_key ]['tkt_objs']       = $tickets;
154
+				if ($att_key == 999999991) {
155
+					$this->_attendees[ $att_key ]['ans_objs'][999]  = $answers_n_questions['answers'][999];
156
+					$this->_attendees[ $att_key ]['ans_objs'][1002] = $answers_n_questions['answers'][1002];
157
+					$this->_attendees[ $att_key ]['ans_objs'][1005] = $answers_n_questions['answers'][1005];
158
+				} elseif ($att_key == 999999992) {
159
+					$this->_attendees[ $att_key ]['ans_objs'][1000] = $answers_n_questions['answers'][1000];
160
+					$this->_attendees[ $att_key ]['ans_objs'][1003] = $answers_n_questions['answers'][1003];
161
+					$this->_attendees[ $att_key ]['ans_objs'][1006] = $answers_n_questions['answers'][1006];
162
+				} elseif ($att_key == 999999993) {
163
+					$this->_attendees[ $att_key ]['ans_objs'][1001] = $answers_n_questions['answers'][1001];
164
+					$this->_attendees[ $att_key ]['ans_objs'][1004] = $answers_n_questions['answers'][1004];
165
+					$this->_attendees[ $att_key ]['ans_objs'][1007] = $answers_n_questions['answers'][1007];
166
+				}
167
+			}
168
+		}
169
+        
170
+		$this->tickets            = $tkts;
171
+		$this->datetimes          = $dtts;
172
+		$this->answers            = $answers_n_questions['answers'];
173
+		$this->questions          = $answers_n_questions['questions'];
174
+		$this->total_ticket_count = count($tkts) * count($this->_attendees);
175
+	}
176 176
     
177 177
     
178
-    /**
179
-     * This just returns an array of dummy attendee objects that we'll use to attach to events for our preview data
180
-     *
181
-     * @access private
182
-     * @return array an array of attendee objects
183
-     */
184
-    private function _get_some_attendees()
185
-    {
186
-        // let's just setup a dummy array of various attendee details
187
-        $dummy_attendees = array(
188
-            0 => array(
189
-                'Luke',
190
-                'Skywalker',
191
-                '[email protected]',
192
-                '804 Bantha Dr.',
193
-                'Complex 8',
194
-                'Mos Eisley',
195
-                32,
196
-                'US',
197
-                'f0r3e',
198
-                '222-333-4763',
199
-                false,
200
-                '999999991'
201
-            ),
202
-            1 => array(
203
-                'Princess',
204
-                'Leia',
205
-                '[email protected]',
206
-                '1456 Valley Way Boulevard',
207
-                'Suite 9',
208
-                'Alderaan',
209
-                15,
210
-                'US',
211
-                'c1h2c',
212
-                '78-123-111-1111',
213
-                false,
214
-                '999999992'
215
-            ),
216
-            2 => array(
217
-                'Yoda',
218
-                'I Am',
219
-                '[email protected]',
220
-                '4th Tree',
221
-                '5th Knot',
222
-                'Marsh',
223
-                22,
224
-                'US',
225
-                'l18n',
226
-                '999-999-9999',
227
-                false,
228
-                '999999993'
229
-            ),
230
-        );
231
-        
232
-        // let's generate the attendee objects
233
-        $attendees = array();
234
-        $var_array = array(
235
-            'fname',
236
-            'lname',
237
-            'email',
238
-            'address',
239
-            'address2',
240
-            'city',
241
-            'staid',
242
-            'cntry',
243
-            'zip',
244
-            'phone',
245
-            'deleted',
246
-            'attid'
247
-        );
248
-        
249
-        // EE_Registry::instance()->load_class( 'Attendee', array(), FALSE, false, TRUE );
250
-        foreach ($dummy_attendees as $dummy) {
251
-            $att = array_combine($var_array, $dummy);
252
-            extract($att);
253
-            /** @var $fname string */
254
-            /** @var $lname string */
255
-            /** @var $address string */
256
-            /** @var $address2 string */
257
-            /** @var $city string */
258
-            /** @var $staid string */
259
-            /** @var $cntry string */
260
-            /** @var $zip string */
261
-            /** @var $email string */
262
-            /** @var $phone string */
263
-            /** @var $attid string */
264
-            $attendees[ $attid ] = EE_Attendee::new_instance(
265
-                array(
266
-                    'ATT_fname'    => $fname,
267
-                    'ATT_lname'    => $lname,
268
-                    'ATT_address'  => $address,
269
-                    'ATT_address2' => $address2,
270
-                    'ATT_city'     => $city,
271
-                    'STA_ID'       => $staid,
272
-                    'CNT_ISO'      => $cntry,
273
-                    'ATT_zip'      => $zip,
274
-                    'ATT_email'    => $email,
275
-                    'ATT_phone'    => $phone,
276
-                    'ATT_ID'       => $attid
277
-                )
278
-            );
279
-        }
280
-        
281
-        return $attendees;
282
-    }
178
+	/**
179
+	 * This just returns an array of dummy attendee objects that we'll use to attach to events for our preview data
180
+	 *
181
+	 * @access private
182
+	 * @return array an array of attendee objects
183
+	 */
184
+	private function _get_some_attendees()
185
+	{
186
+		// let's just setup a dummy array of various attendee details
187
+		$dummy_attendees = array(
188
+			0 => array(
189
+				'Luke',
190
+				'Skywalker',
191
+				'[email protected]',
192
+				'804 Bantha Dr.',
193
+				'Complex 8',
194
+				'Mos Eisley',
195
+				32,
196
+				'US',
197
+				'f0r3e',
198
+				'222-333-4763',
199
+				false,
200
+				'999999991'
201
+			),
202
+			1 => array(
203
+				'Princess',
204
+				'Leia',
205
+				'[email protected]',
206
+				'1456 Valley Way Boulevard',
207
+				'Suite 9',
208
+				'Alderaan',
209
+				15,
210
+				'US',
211
+				'c1h2c',
212
+				'78-123-111-1111',
213
+				false,
214
+				'999999992'
215
+			),
216
+			2 => array(
217
+				'Yoda',
218
+				'I Am',
219
+				'[email protected]',
220
+				'4th Tree',
221
+				'5th Knot',
222
+				'Marsh',
223
+				22,
224
+				'US',
225
+				'l18n',
226
+				'999-999-9999',
227
+				false,
228
+				'999999993'
229
+			),
230
+		);
231
+        
232
+		// let's generate the attendee objects
233
+		$attendees = array();
234
+		$var_array = array(
235
+			'fname',
236
+			'lname',
237
+			'email',
238
+			'address',
239
+			'address2',
240
+			'city',
241
+			'staid',
242
+			'cntry',
243
+			'zip',
244
+			'phone',
245
+			'deleted',
246
+			'attid'
247
+		);
248
+        
249
+		// EE_Registry::instance()->load_class( 'Attendee', array(), FALSE, false, TRUE );
250
+		foreach ($dummy_attendees as $dummy) {
251
+			$att = array_combine($var_array, $dummy);
252
+			extract($att);
253
+			/** @var $fname string */
254
+			/** @var $lname string */
255
+			/** @var $address string */
256
+			/** @var $address2 string */
257
+			/** @var $city string */
258
+			/** @var $staid string */
259
+			/** @var $cntry string */
260
+			/** @var $zip string */
261
+			/** @var $email string */
262
+			/** @var $phone string */
263
+			/** @var $attid string */
264
+			$attendees[ $attid ] = EE_Attendee::new_instance(
265
+				array(
266
+					'ATT_fname'    => $fname,
267
+					'ATT_lname'    => $lname,
268
+					'ATT_address'  => $address,
269
+					'ATT_address2' => $address2,
270
+					'ATT_city'     => $city,
271
+					'STA_ID'       => $staid,
272
+					'CNT_ISO'      => $cntry,
273
+					'ATT_zip'      => $zip,
274
+					'ATT_email'    => $email,
275
+					'ATT_phone'    => $phone,
276
+					'ATT_ID'       => $attid
277
+				)
278
+			);
279
+		}
280
+        
281
+		return $attendees;
282
+	}
283 283
     
284 284
     
285
-    /**
286
-     * Return an array of dummy question objects indexed by answer id and dummy answer objects indexed by answer id.
287
-     * This will be used in our dummy data setup
288
-     * @return array
289
-     */
290
-    private function _get_some_q_and_as()
291
-    {
292
-        
293
-        
294
-        $quests_array = array(
295
-            0 => array(
296
-                555,
297
-                __('What is your favorite planet?', 'event_espresso'),
298
-                0
299
-            ),
300
-            1 => array(
301
-                556,
302
-                __('What is your favorite food?', 'event_espresso'),
303
-                0
304
-            ),
305
-            2 => array(
306
-                557,
307
-                __('How many lightyears have you travelled', 'event_espresso'),
308
-                0
309
-            )
310
-        );
311
-        
312
-        
313
-        $ans_array = array(
314
-            0 => array(
315
-                999,
316
-                555,
317
-                'Tattoine'
318
-            ),
319
-            1 => array(
320
-                1000,
321
-                555,
322
-                'Alderaan'
323
-            ),
324
-            2 => array(
325
-                1001,
326
-                555,
327
-                'Dantooine'
328
-            ),
329
-            3 => array(
330
-                1002,
331
-                556,
332
-                'Fish Fingers'
333
-            ),
334
-            4 => array(
335
-                1003,
336
-                556,
337
-                'Sushi'
338
-            ),
339
-            5 => array(
340
-                1004,
341
-                556,
342
-                'Water'
343
-            ),
344
-            6 => array(
345
-                1005,
346
-                557,
347
-                'A lot',
348
-            ),
349
-            7 => array(
350
-                1006,
351
-                557,
352
-                "That's none of your business."
353
-            ),
354
-            8 => array(
355
-                1007,
356
-                557,
357
-                "People less travel me then."
358
-            )
359
-        );
360
-        
361
-        $qst_columns = array('QST_ID', 'QST_display_text', 'QST_system');
362
-        $ans_columns = array('ANS_ID', 'QST_ID', 'ANS_value');
363
-        
364
-        // EE_Registry::instance()->load_class( 'Question', array(), FALSE, TRUE, TRUE );
365
-        // EE_Registry::instance()->load_class( 'Answer', array(), FALSE, TRUE, TRUE );
366
-        
367
-        $qsts = array();
368
-        // first the questions
369
-        foreach ($quests_array as $qst) {
370
-            $qstobj                  = array_combine($qst_columns, $qst);
371
-            $qsts[ $qstobj['QST_ID'] ] = EE_Question::new_instance($qstobj);
372
-        }
373
-        
374
-        // now the answers (and we'll setup our arrays)
375
-        $q_n_as = array();
376
-        foreach ($ans_array as $ans) {
377
-            $ansobj                             = array_combine($ans_columns, $ans);
378
-            $ansobj                             = EE_Answer::new_instance($ansobj);
379
-            $q_n_as['answers'][ $ansobj->ID() ]   = $ansobj;
380
-            $q_n_as['questions'][ $ansobj->ID() ] = $qsts[ $ansobj->get('QST_ID') ];
381
-        }
382
-        
383
-        return $q_n_as;
384
-    }
285
+	/**
286
+	 * Return an array of dummy question objects indexed by answer id and dummy answer objects indexed by answer id.
287
+	 * This will be used in our dummy data setup
288
+	 * @return array
289
+	 */
290
+	private function _get_some_q_and_as()
291
+	{
292
+        
293
+        
294
+		$quests_array = array(
295
+			0 => array(
296
+				555,
297
+				__('What is your favorite planet?', 'event_espresso'),
298
+				0
299
+			),
300
+			1 => array(
301
+				556,
302
+				__('What is your favorite food?', 'event_espresso'),
303
+				0
304
+			),
305
+			2 => array(
306
+				557,
307
+				__('How many lightyears have you travelled', 'event_espresso'),
308
+				0
309
+			)
310
+		);
311
+        
312
+        
313
+		$ans_array = array(
314
+			0 => array(
315
+				999,
316
+				555,
317
+				'Tattoine'
318
+			),
319
+			1 => array(
320
+				1000,
321
+				555,
322
+				'Alderaan'
323
+			),
324
+			2 => array(
325
+				1001,
326
+				555,
327
+				'Dantooine'
328
+			),
329
+			3 => array(
330
+				1002,
331
+				556,
332
+				'Fish Fingers'
333
+			),
334
+			4 => array(
335
+				1003,
336
+				556,
337
+				'Sushi'
338
+			),
339
+			5 => array(
340
+				1004,
341
+				556,
342
+				'Water'
343
+			),
344
+			6 => array(
345
+				1005,
346
+				557,
347
+				'A lot',
348
+			),
349
+			7 => array(
350
+				1006,
351
+				557,
352
+				"That's none of your business."
353
+			),
354
+			8 => array(
355
+				1007,
356
+				557,
357
+				"People less travel me then."
358
+			)
359
+		);
360
+        
361
+		$qst_columns = array('QST_ID', 'QST_display_text', 'QST_system');
362
+		$ans_columns = array('ANS_ID', 'QST_ID', 'ANS_value');
363
+        
364
+		// EE_Registry::instance()->load_class( 'Question', array(), FALSE, TRUE, TRUE );
365
+		// EE_Registry::instance()->load_class( 'Answer', array(), FALSE, TRUE, TRUE );
366
+        
367
+		$qsts = array();
368
+		// first the questions
369
+		foreach ($quests_array as $qst) {
370
+			$qstobj                  = array_combine($qst_columns, $qst);
371
+			$qsts[ $qstobj['QST_ID'] ] = EE_Question::new_instance($qstobj);
372
+		}
373
+        
374
+		// now the answers (and we'll setup our arrays)
375
+		$q_n_as = array();
376
+		foreach ($ans_array as $ans) {
377
+			$ansobj                             = array_combine($ans_columns, $ans);
378
+			$ansobj                             = EE_Answer::new_instance($ansobj);
379
+			$q_n_as['answers'][ $ansobj->ID() ]   = $ansobj;
380
+			$q_n_as['questions'][ $ansobj->ID() ] = $qsts[ $ansobj->get('QST_ID') ];
381
+		}
382
+        
383
+		return $q_n_as;
384
+	}
385 385
     
386 386
     
387
-    /**
388
-     * Return an array of event objects from the database
389
-     *
390
-     * If event ids are not included then we'll just retrieve the first published event from the database.
391
-     *
392
-     * @param  array $event_ids if set, this will be an array of event ids to obtain events for.
393
-     *
394
-     * @return array    An array of event objects from the db.
395
-     */
396
-    private function _get_some_events($event_ids = array())
397
-    {
398
-        
399
-        // HEY, if we have an evt_id then we want to make sure we use that for the preview (because a specific event template is being viewed);
400
-        $event_ids = isset($_REQUEST['evt_id']) && ! empty($_REQUEST['evt_id'])
401
-            ? array($_REQUEST['evt_id'])
402
-            : $event_ids;
403
-        
404
-        $limit = ! empty($event_ids)
405
-            ? null
406
-            : apply_filters('FHEE__EE_Messages_Preview_incoming_data___get_some_events__limit', '0,1');
407
-        
408
-        $where = ! empty($event_ids)
409
-            ? array(
410
-                'EVT_ID'                 => array('IN', $event_ids),
411
-                'Datetime.Ticket.TKT_ID' => array('>', 1)
412
-            )
413
-            : array('Datetime.Ticket.TKT_ID' => array('>', 1));
414
-        
415
-        $events = EE_Registry::instance()->load_model('Event')->get_all(array($where, 'limit' => $limit));
416
-        
417
-        return $events;
418
-    }
387
+	/**
388
+	 * Return an array of event objects from the database
389
+	 *
390
+	 * If event ids are not included then we'll just retrieve the first published event from the database.
391
+	 *
392
+	 * @param  array $event_ids if set, this will be an array of event ids to obtain events for.
393
+	 *
394
+	 * @return array    An array of event objects from the db.
395
+	 */
396
+	private function _get_some_events($event_ids = array())
397
+	{
398
+        
399
+		// HEY, if we have an evt_id then we want to make sure we use that for the preview (because a specific event template is being viewed);
400
+		$event_ids = isset($_REQUEST['evt_id']) && ! empty($_REQUEST['evt_id'])
401
+			? array($_REQUEST['evt_id'])
402
+			: $event_ids;
403
+        
404
+		$limit = ! empty($event_ids)
405
+			? null
406
+			: apply_filters('FHEE__EE_Messages_Preview_incoming_data___get_some_events__limit', '0,1');
407
+        
408
+		$where = ! empty($event_ids)
409
+			? array(
410
+				'EVT_ID'                 => array('IN', $event_ids),
411
+				'Datetime.Ticket.TKT_ID' => array('>', 1)
412
+			)
413
+			: array('Datetime.Ticket.TKT_ID' => array('>', 1));
414
+        
415
+		$events = EE_Registry::instance()->load_model('Event')->get_all(array($where, 'limit' => $limit));
416
+        
417
+		return $events;
418
+	}
419 419
     
420 420
     
421
-    protected function _setup_data()
422
-    {
423
-        
424
-        // need to figure out the running total for test purposes so... we're going to create a temp cart and add the tickets to it!
425
-        if (EE_Registry::instance()->SSN instanceof EE_Session) {
426
-            EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
427
-            $session = EE_Registry::instance()->SSN;
428
-        } else {
429
-            $session = EE_Registry::instance()->load_core('Session');
430
-        }
431
-        $cart = EE_Cart::instance(null, $session);
432
-        
433
-        
434
-        // add tickets to cart
435
-        foreach ($this->tickets as $ticket) {
436
-            $cart->add_ticket_to_cart($ticket['ticket']);
437
-        }
438
-        
439
-        
440
-        // setup txn property
441
-        $this->txn = EE_Transaction::new_instance(
442
-            array(
443
-                'TXN_timestamp'    => time(), // unix timestamp
444
-                'TXN_total'        => 0, // txn_total
445
-                'TXN_paid'         => 0, // txn_paid
446
-                'STS_ID'           => EEM_Transaction::incomplete_status_code, // sts_id
447
-                'TXN_session_data' => null, // dump of txn session object (we're just going to leave blank here)
448
-                'TXN_hash_salt'    => null, // hash salt blank as well
449
-                'TXN_ID'           => 999999
450
-            )
451
-        );
452
-        
453
-        
454
-        // setup reg_objects
455
-        // note we're setting up a reg object for each attendee in each event but ALSO adding to the reg_object array.
456
-        $this->reg_objs = array();
457
-        $regid          = 9999990;
458
-        foreach ($this->_attendees as $key => $attendee) {
459
-            // note we need to setup reg_objects for each event this attendee belongs to
460
-            $regatt = $attendee['att_obj'] instanceof EE_Attendee ? $attendee['att_obj']->ID() : null;
461
-            $regtxn = $this->txn->ID();
462
-            $regcnt = 1;
463
-            foreach ($attendee['line_ref'] as $evtid) {
464
-                foreach ($this->_events[ $evtid ]['tkt_objs'] as $ticket) {
465
-                    if (! $ticket instanceof EE_Ticket) {
466
-                        continue;
467
-                    }
468
-                    $reg_array                                        = array(
469
-                        'EVT_ID'           => $evtid,
470
-                        'ATT_ID'           => $regatt,
471
-                        'TXN_ID'           => $regtxn,
472
-                        'TKT_ID'           => $ticket->ID(),
473
-                        'STS_ID'           => EEM_Registration::status_id_pending_payment,
474
-                        'REG_date'         => time(),
475
-                        'REG_final_price'  => $ticket->get('TKT_price'),
476
-                        'REG_session'      => 'dummy_session_id',
477
-                        'REG_code'         => $regid . '-dummy-generated-code',
478
-                        'REG_url_link'     => $regcnt . '-daafpapasdlfakasdfpqasdfasdf',
479
-                        'REG_count'        => $regcnt,
480
-                        'REG_group_size'   => $this->_events[ $evtid ]['total_attendees'],
481
-                        'REG_att_is_going' => true,
482
-                        'REG_ID'           => $regid
483
-                    );
484
-                    $REG_OBJ                                          = EE_Registration::new_instance($reg_array);
485
-                    $this->_attendees[ $key ]['reg_objs'][ $regid ]       = $REG_OBJ;
486
-                    $this->_events[ $evtid ]['reg_objs'][]              = $REG_OBJ;
487
-                    $this->reg_objs[]                                 = $REG_OBJ;
488
-                    $this->tickets[ $ticket->ID() ]['reg_objs'][ $regid ] = $REG_OBJ;
421
+	protected function _setup_data()
422
+	{
423
+        
424
+		// need to figure out the running total for test purposes so... we're going to create a temp cart and add the tickets to it!
425
+		if (EE_Registry::instance()->SSN instanceof EE_Session) {
426
+			EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
427
+			$session = EE_Registry::instance()->SSN;
428
+		} else {
429
+			$session = EE_Registry::instance()->load_core('Session');
430
+		}
431
+		$cart = EE_Cart::instance(null, $session);
432
+        
433
+        
434
+		// add tickets to cart
435
+		foreach ($this->tickets as $ticket) {
436
+			$cart->add_ticket_to_cart($ticket['ticket']);
437
+		}
438
+        
439
+        
440
+		// setup txn property
441
+		$this->txn = EE_Transaction::new_instance(
442
+			array(
443
+				'TXN_timestamp'    => time(), // unix timestamp
444
+				'TXN_total'        => 0, // txn_total
445
+				'TXN_paid'         => 0, // txn_paid
446
+				'STS_ID'           => EEM_Transaction::incomplete_status_code, // sts_id
447
+				'TXN_session_data' => null, // dump of txn session object (we're just going to leave blank here)
448
+				'TXN_hash_salt'    => null, // hash salt blank as well
449
+				'TXN_ID'           => 999999
450
+			)
451
+		);
452
+        
453
+        
454
+		// setup reg_objects
455
+		// note we're setting up a reg object for each attendee in each event but ALSO adding to the reg_object array.
456
+		$this->reg_objs = array();
457
+		$regid          = 9999990;
458
+		foreach ($this->_attendees as $key => $attendee) {
459
+			// note we need to setup reg_objects for each event this attendee belongs to
460
+			$regatt = $attendee['att_obj'] instanceof EE_Attendee ? $attendee['att_obj']->ID() : null;
461
+			$regtxn = $this->txn->ID();
462
+			$regcnt = 1;
463
+			foreach ($attendee['line_ref'] as $evtid) {
464
+				foreach ($this->_events[ $evtid ]['tkt_objs'] as $ticket) {
465
+					if (! $ticket instanceof EE_Ticket) {
466
+						continue;
467
+					}
468
+					$reg_array                                        = array(
469
+						'EVT_ID'           => $evtid,
470
+						'ATT_ID'           => $regatt,
471
+						'TXN_ID'           => $regtxn,
472
+						'TKT_ID'           => $ticket->ID(),
473
+						'STS_ID'           => EEM_Registration::status_id_pending_payment,
474
+						'REG_date'         => time(),
475
+						'REG_final_price'  => $ticket->get('TKT_price'),
476
+						'REG_session'      => 'dummy_session_id',
477
+						'REG_code'         => $regid . '-dummy-generated-code',
478
+						'REG_url_link'     => $regcnt . '-daafpapasdlfakasdfpqasdfasdf',
479
+						'REG_count'        => $regcnt,
480
+						'REG_group_size'   => $this->_events[ $evtid ]['total_attendees'],
481
+						'REG_att_is_going' => true,
482
+						'REG_ID'           => $regid
483
+					);
484
+					$REG_OBJ                                          = EE_Registration::new_instance($reg_array);
485
+					$this->_attendees[ $key ]['reg_objs'][ $regid ]       = $REG_OBJ;
486
+					$this->_events[ $evtid ]['reg_objs'][]              = $REG_OBJ;
487
+					$this->reg_objs[]                                 = $REG_OBJ;
488
+					$this->tickets[ $ticket->ID() ]['reg_objs'][ $regid ] = $REG_OBJ;
489 489
                     
490
-                    $regcnt++;
491
-                    $regid++;
492
-                }
493
-            }
494
-        }
495
-        
496
-        
497
-        // setup line items!
498
-        $line_item_total = EEH_Line_Item::create_total_line_item($this->txn);
499
-        
500
-        // add tickets
501
-        foreach ($this->tickets as $tktid => $item) {
502
-            $qty    = $item['count'];
503
-            $ticket = $item['ticket'];
504
-            EEH_Line_Item::add_ticket_purchase($line_item_total, $ticket, $qty);
505
-        }
506
-        
507
-        $shipping_line_item = EE_Line_Item::new_instance(array(
508
-            'LIN_name'       => __('Shipping Surcharge', 'event_espresso'),
509
-            'LIN_desc'       => __('Sent via Millenium Falcon', 'event_espresso'),
510
-            'LIN_unit_price' => 20,
511
-            'LIN_quantity'   => 1,
512
-            'LIN_is_taxable' => true,
513
-            'LIN_total'      => 20,
514
-            'LIN_type'       => EEM_Line_Item::type_line_item
515
-        ));
516
-        EEH_Line_Item::add_item($line_item_total, $shipping_line_item);
517
-        $this->additional_line_items = array($shipping_line_item);
518
-        
519
-        // now let's add taxes
520
-        EEH_Line_Item::apply_taxes($line_item_total);
521
-        
522
-        // now we should be able to get the items we need from this object
523
-        $event_line_items = EEH_Line_Item::get_pre_tax_subtotal($line_item_total)->children();
524
-        $line_items       = array();
525
-        foreach ($event_line_items as $line_id => $line_item) {
526
-            if (! $line_item instanceof EE_Line_Item || $line_item->OBJ_type() !== 'Event') {
527
-                continue;
528
-            }
529
-            $ticket_line_items = EEH_Line_Item::get_ticket_line_items($line_item);
530
-            foreach ($ticket_line_items as $ticket_line_id => $ticket_line_item) {
531
-                if (! $ticket_line_item instanceof EE_Line_Item) {
532
-                    continue;
533
-                }
534
-                $this->tickets[ $ticket_line_item->OBJ_ID() ]['line_item']      = $ticket_line_item;
535
-                $this->tickets[ $ticket_line_item->OBJ_ID() ]['sub_line_items'] = $ticket_line_item->children();
536
-                $line_items[ $ticket_line_item->ID() ]['children']              = $ticket_line_item->children();
537
-                $line_items[ $ticket_line_item->ID() ]['EE_Ticket']             = $this->tickets[ $ticket_line_item->OBJ_ID() ]['ticket'];
538
-            }
539
-        }
540
-        
541
-        $this->line_items_with_children = $line_items;
542
-        $this->tax_line_items           = $line_item_total->tax_descendants();
543
-        
544
-        // add proper total to transaction object.
545
-        $grand_total                 = $line_item_total->recalculate_total_including_taxes();
546
-        $this->grand_total_line_item = $line_item_total;
547
-        $this->txn->set_total($grand_total);
548
-        
549
-        
550
-        // add additional details for each registration
551
-        foreach ($this->reg_objs as $reg) {
552
-            if (! $reg instanceof EE_Registration) {
553
-                continue;
554
-            }
555
-            $this->_registrations[ $reg->ID() ]['tkt_obj']  = $this->tickets[ $reg->get('TKT_ID') ]['ticket'];
556
-            $this->_registrations[ $reg->ID() ]['evt_obj']  = $this->_events[ $reg->get('EVT_ID') ]['event'];
557
-            $this->_registrations[ $reg->ID() ]['reg_obj']  = $reg;
558
-            $this->_registrations[ $reg->ID() ]['ans_objs'] = $this->_attendees[ $reg->get('ATT_ID') ]['ans_objs'];
559
-            $this->_registrations[ $reg->ID() ]['att_obj']  = $this->_attendees[ $reg->get('ATT_ID') ]['att_obj'];
560
-            $this->_registrations[ $reg->ID() ]['dtt_objs'] = $this->tickets[ $reg->get('TKT_ID') ]['dtt_objs'];
561
-        }
562
-        
563
-        
564
-        // events and attendees
565
-        $this->events        = $this->_events;
566
-        $this->attendees     = $this->_attendees;
567
-        $this->registrations = $this->_registrations;
568
-        
569
-        $attendees_to_shift = $this->_attendees;
570
-        
571
-        // setup primary attendee property
572
-        $this->primary_attendee_data = array(
573
-            'fname' => $this->_attendees[999999991]['att_obj'] instanceof EE_Attendee
574
-                ? $this->_attendees[999999991]['att_obj']->fname()
575
-                : '',
490
+					$regcnt++;
491
+					$regid++;
492
+				}
493
+			}
494
+		}
495
+        
496
+        
497
+		// setup line items!
498
+		$line_item_total = EEH_Line_Item::create_total_line_item($this->txn);
499
+        
500
+		// add tickets
501
+		foreach ($this->tickets as $tktid => $item) {
502
+			$qty    = $item['count'];
503
+			$ticket = $item['ticket'];
504
+			EEH_Line_Item::add_ticket_purchase($line_item_total, $ticket, $qty);
505
+		}
506
+        
507
+		$shipping_line_item = EE_Line_Item::new_instance(array(
508
+			'LIN_name'       => __('Shipping Surcharge', 'event_espresso'),
509
+			'LIN_desc'       => __('Sent via Millenium Falcon', 'event_espresso'),
510
+			'LIN_unit_price' => 20,
511
+			'LIN_quantity'   => 1,
512
+			'LIN_is_taxable' => true,
513
+			'LIN_total'      => 20,
514
+			'LIN_type'       => EEM_Line_Item::type_line_item
515
+		));
516
+		EEH_Line_Item::add_item($line_item_total, $shipping_line_item);
517
+		$this->additional_line_items = array($shipping_line_item);
518
+        
519
+		// now let's add taxes
520
+		EEH_Line_Item::apply_taxes($line_item_total);
521
+        
522
+		// now we should be able to get the items we need from this object
523
+		$event_line_items = EEH_Line_Item::get_pre_tax_subtotal($line_item_total)->children();
524
+		$line_items       = array();
525
+		foreach ($event_line_items as $line_id => $line_item) {
526
+			if (! $line_item instanceof EE_Line_Item || $line_item->OBJ_type() !== 'Event') {
527
+				continue;
528
+			}
529
+			$ticket_line_items = EEH_Line_Item::get_ticket_line_items($line_item);
530
+			foreach ($ticket_line_items as $ticket_line_id => $ticket_line_item) {
531
+				if (! $ticket_line_item instanceof EE_Line_Item) {
532
+					continue;
533
+				}
534
+				$this->tickets[ $ticket_line_item->OBJ_ID() ]['line_item']      = $ticket_line_item;
535
+				$this->tickets[ $ticket_line_item->OBJ_ID() ]['sub_line_items'] = $ticket_line_item->children();
536
+				$line_items[ $ticket_line_item->ID() ]['children']              = $ticket_line_item->children();
537
+				$line_items[ $ticket_line_item->ID() ]['EE_Ticket']             = $this->tickets[ $ticket_line_item->OBJ_ID() ]['ticket'];
538
+			}
539
+		}
540
+        
541
+		$this->line_items_with_children = $line_items;
542
+		$this->tax_line_items           = $line_item_total->tax_descendants();
543
+        
544
+		// add proper total to transaction object.
545
+		$grand_total                 = $line_item_total->recalculate_total_including_taxes();
546
+		$this->grand_total_line_item = $line_item_total;
547
+		$this->txn->set_total($grand_total);
548
+        
549
+        
550
+		// add additional details for each registration
551
+		foreach ($this->reg_objs as $reg) {
552
+			if (! $reg instanceof EE_Registration) {
553
+				continue;
554
+			}
555
+			$this->_registrations[ $reg->ID() ]['tkt_obj']  = $this->tickets[ $reg->get('TKT_ID') ]['ticket'];
556
+			$this->_registrations[ $reg->ID() ]['evt_obj']  = $this->_events[ $reg->get('EVT_ID') ]['event'];
557
+			$this->_registrations[ $reg->ID() ]['reg_obj']  = $reg;
558
+			$this->_registrations[ $reg->ID() ]['ans_objs'] = $this->_attendees[ $reg->get('ATT_ID') ]['ans_objs'];
559
+			$this->_registrations[ $reg->ID() ]['att_obj']  = $this->_attendees[ $reg->get('ATT_ID') ]['att_obj'];
560
+			$this->_registrations[ $reg->ID() ]['dtt_objs'] = $this->tickets[ $reg->get('TKT_ID') ]['dtt_objs'];
561
+		}
562
+        
563
+        
564
+		// events and attendees
565
+		$this->events        = $this->_events;
566
+		$this->attendees     = $this->_attendees;
567
+		$this->registrations = $this->_registrations;
568
+        
569
+		$attendees_to_shift = $this->_attendees;
570
+        
571
+		// setup primary attendee property
572
+		$this->primary_attendee_data = array(
573
+			'fname' => $this->_attendees[999999991]['att_obj'] instanceof EE_Attendee
574
+				? $this->_attendees[999999991]['att_obj']->fname()
575
+				: '',
576 576
             
577
-            'lname' => $this->_attendees[999999991]['att_obj'] instanceof EE_Attendee
578
-                ? $this->_attendees[999999991]['att_obj']->lname()
579
-                : '',
577
+			'lname' => $this->_attendees[999999991]['att_obj'] instanceof EE_Attendee
578
+				? $this->_attendees[999999991]['att_obj']->lname()
579
+				: '',
580 580
             
581
-            'email' => $this->_attendees[999999991]['att_obj'] instanceof EE_Attendee
582
-                ? $this->_attendees[999999991]['att_obj']->email()
583
-                : '',
581
+			'email' => $this->_attendees[999999991]['att_obj'] instanceof EE_Attendee
582
+				? $this->_attendees[999999991]['att_obj']->email()
583
+				: '',
584 584
             
585
-            'att_obj' => $this->_attendees[999999991]['att_obj'],
585
+			'att_obj' => $this->_attendees[999999991]['att_obj'],
586 586
             
587
-            'reg_obj' => array_shift($attendees_to_shift[999999991]['reg_objs'])
588
-        );
587
+			'reg_obj' => array_shift($attendees_to_shift[999999991]['reg_objs'])
588
+		);
589 589
         
590
-        // reg_info property
591
-        // note this isn't referenced by any shortcode parsers so we'll ignore for now.
592
-        $this->reg_info = array();
590
+		// reg_info property
591
+		// note this isn't referenced by any shortcode parsers so we'll ignore for now.
592
+		$this->reg_info = array();
593 593
         
594
-        // let's set a reg_obj for messengers expecting one.
595
-        $this->reg_obj = array_pop($this->_attendees[999999991]['reg_objs']);
594
+		// let's set a reg_obj for messengers expecting one.
595
+		$this->reg_obj = array_pop($this->_attendees[999999991]['reg_objs']);
596 596
         
597 597
         
598
-        // the below are just dummy items.
599
-        $this->user_id     = 1;
600
-        $this->ip_address  = '192.0.2.1';
601
-        $this->user_agent  = '';
602
-        $this->init_access = time();
603
-        $this->last_access = time();
604
-    }
598
+		// the below are just dummy items.
599
+		$this->user_id     = 1;
600
+		$this->ip_address  = '192.0.2.1';
601
+		$this->user_agent  = '';
602
+		$this->init_access = time();
603
+		$this->last_access = time();
604
+	}
605 605
 }
Please login to merge, or discard this patch.
Spacing   +65 added lines, -65 removed lines patch added patch discarded remove patch
@@ -98,71 +98,71 @@  discard block
 block discarded – undo
98 98
         // we'll actually use the generated line_item identifiers for our loop
99 99
         $dtts = $tkts = array();
100 100
         foreach ($events as $id => $event) {
101
-            if (! $event instanceof EE_Event) {
101
+            if ( ! $event instanceof EE_Event) {
102 102
                 continue;
103 103
             }
104
-            $this->_events[ $id ]['ID']       = $id;
105
-            $this->_events[ $id ]['name']     = $event->get('EVT_name');
104
+            $this->_events[$id]['ID']       = $id;
105
+            $this->_events[$id]['name']     = $event->get('EVT_name');
106 106
             $datetime                       = $event->get_first_related('Datetime');
107 107
             $tickets                        = $datetime instanceof EE_Datetime ? $datetime->get_many_related(
108 108
                 'Ticket',
109 109
                 array('default_where_conditions' => 'none')
110 110
             ) : array();
111
-            $this->_events[ $id ]['event']    = $event;
112
-            $this->_events[ $id ]['reg_objs'] = array();
113
-            $this->_events[ $id ]['tkt_objs'] = $tickets;
114
-            $this->_events[ $id ]['dtt_objs'] = array();
111
+            $this->_events[$id]['event']    = $event;
112
+            $this->_events[$id]['reg_objs'] = array();
113
+            $this->_events[$id]['tkt_objs'] = $tickets;
114
+            $this->_events[$id]['dtt_objs'] = array();
115 115
             
116 116
             $dttcache = array();
117 117
             $tkts     = array();
118 118
             foreach ($tickets as $ticket) {
119
-                if (! $ticket instanceof EE_Ticket) {
119
+                if ( ! $ticket instanceof EE_Ticket) {
120 120
                     continue;
121 121
                 }
122
-                $reldatetime                     = $ticket->datetimes();
123
-                $tkts[ $ticket->ID() ]             = array();
124
-                $tkts[ $ticket->ID() ]['ticket']   = $ticket;
125
-                $tkts[ $ticket->ID() ]['dtt_objs'] = $reldatetime;
126
-                $tkts[ $ticket->ID() ]['att_objs'] = $attendees;
127
-                $tkts[ $ticket->ID() ]['count']    = count($attendees);
128
-                $tkts[ $ticket->ID() ]['EE_Event'] = $event;
122
+                $reldatetime = $ticket->datetimes();
123
+                $tkts[$ticket->ID()]             = array();
124
+                $tkts[$ticket->ID()]['ticket']   = $ticket;
125
+                $tkts[$ticket->ID()]['dtt_objs'] = $reldatetime;
126
+                $tkts[$ticket->ID()]['att_objs'] = $attendees;
127
+                $tkts[$ticket->ID()]['count']    = count($attendees);
128
+                $tkts[$ticket->ID()]['EE_Event'] = $event;
129 129
                 foreach ($reldatetime as $datetime) {
130
-                    if ($datetime instanceof EE_Datetime && ! isset($dtts[ $datetime->ID() ])) {
131
-                        $this->_events[ $id ]['dtt_objs'][ $datetime->ID() ] = $datetime;
132
-                        $dtts[ $datetime->ID() ]['datetime']               = $datetime;
133
-                        $dtts[ $datetime->ID() ]['tkt_objs'][]             = $ticket;
134
-                        $dtts[ $datetime->ID() ]['evt_objs'][]             = $event;
135
-                        $dttcache[ $datetime->ID() ]                       = $datetime;
130
+                    if ($datetime instanceof EE_Datetime && ! isset($dtts[$datetime->ID()])) {
131
+                        $this->_events[$id]['dtt_objs'][$datetime->ID()] = $datetime;
132
+                        $dtts[$datetime->ID()]['datetime']               = $datetime;
133
+                        $dtts[$datetime->ID()]['tkt_objs'][]             = $ticket;
134
+                        $dtts[$datetime->ID()]['evt_objs'][]             = $event;
135
+                        $dttcache[$datetime->ID()]                       = $datetime;
136 136
                     }
137 137
                 }
138 138
             }
139 139
             
140
-            $this->_events[ $id ]['total_attendees'] = count($attendees);
141
-            $this->_events[ $id ]['att_objs']        = $attendees;
140
+            $this->_events[$id]['total_attendees'] = count($attendees);
141
+            $this->_events[$id]['att_objs']        = $attendees;
142 142
             
143 143
             // let's also setup the dummy attendees property!
144 144
             foreach ($attendees as $att_key => $attendee) {
145
-                if (! $attendee instanceof EE_Attendee) {
145
+                if ( ! $attendee instanceof EE_Attendee) {
146 146
                     continue;
147 147
                 }
148
-                $this->_attendees[ $att_key ]['line_ref'][] = $id;  // so later it can be determined what events this attendee registered for!
149
-                $this->_attendees[ $att_key ]['evt_objs'][] = $event;
150
-                $this->_attendees[ $att_key ]['att_obj']    = $attendee;
148
+                $this->_attendees[$att_key]['line_ref'][] = $id; // so later it can be determined what events this attendee registered for!
149
+                $this->_attendees[$att_key]['evt_objs'][] = $event;
150
+                $this->_attendees[$att_key]['att_obj']    = $attendee;
151 151
                 // $this->_attendees[$att_key]['registration_id'] = 0;
152
-                $this->_attendees[ $att_key ]['attendee_email'] = $attendee->email();
153
-                $this->_attendees[ $att_key ]['tkt_objs']       = $tickets;
152
+                $this->_attendees[$att_key]['attendee_email'] = $attendee->email();
153
+                $this->_attendees[$att_key]['tkt_objs']       = $tickets;
154 154
                 if ($att_key == 999999991) {
155
-                    $this->_attendees[ $att_key ]['ans_objs'][999]  = $answers_n_questions['answers'][999];
156
-                    $this->_attendees[ $att_key ]['ans_objs'][1002] = $answers_n_questions['answers'][1002];
157
-                    $this->_attendees[ $att_key ]['ans_objs'][1005] = $answers_n_questions['answers'][1005];
155
+                    $this->_attendees[$att_key]['ans_objs'][999]  = $answers_n_questions['answers'][999];
156
+                    $this->_attendees[$att_key]['ans_objs'][1002] = $answers_n_questions['answers'][1002];
157
+                    $this->_attendees[$att_key]['ans_objs'][1005] = $answers_n_questions['answers'][1005];
158 158
                 } elseif ($att_key == 999999992) {
159
-                    $this->_attendees[ $att_key ]['ans_objs'][1000] = $answers_n_questions['answers'][1000];
160
-                    $this->_attendees[ $att_key ]['ans_objs'][1003] = $answers_n_questions['answers'][1003];
161
-                    $this->_attendees[ $att_key ]['ans_objs'][1006] = $answers_n_questions['answers'][1006];
159
+                    $this->_attendees[$att_key]['ans_objs'][1000] = $answers_n_questions['answers'][1000];
160
+                    $this->_attendees[$att_key]['ans_objs'][1003] = $answers_n_questions['answers'][1003];
161
+                    $this->_attendees[$att_key]['ans_objs'][1006] = $answers_n_questions['answers'][1006];
162 162
                 } elseif ($att_key == 999999993) {
163
-                    $this->_attendees[ $att_key ]['ans_objs'][1001] = $answers_n_questions['answers'][1001];
164
-                    $this->_attendees[ $att_key ]['ans_objs'][1004] = $answers_n_questions['answers'][1004];
165
-                    $this->_attendees[ $att_key ]['ans_objs'][1007] = $answers_n_questions['answers'][1007];
163
+                    $this->_attendees[$att_key]['ans_objs'][1001] = $answers_n_questions['answers'][1001];
164
+                    $this->_attendees[$att_key]['ans_objs'][1004] = $answers_n_questions['answers'][1004];
165
+                    $this->_attendees[$att_key]['ans_objs'][1007] = $answers_n_questions['answers'][1007];
166 166
                 }
167 167
             }
168 168
         }
@@ -261,7 +261,7 @@  discard block
 block discarded – undo
261 261
             /** @var $email string */
262 262
             /** @var $phone string */
263 263
             /** @var $attid string */
264
-            $attendees[ $attid ] = EE_Attendee::new_instance(
264
+            $attendees[$attid] = EE_Attendee::new_instance(
265 265
                 array(
266 266
                     'ATT_fname'    => $fname,
267 267
                     'ATT_lname'    => $lname,
@@ -367,8 +367,8 @@  discard block
 block discarded – undo
367 367
         $qsts = array();
368 368
         // first the questions
369 369
         foreach ($quests_array as $qst) {
370
-            $qstobj                  = array_combine($qst_columns, $qst);
371
-            $qsts[ $qstobj['QST_ID'] ] = EE_Question::new_instance($qstobj);
370
+            $qstobj = array_combine($qst_columns, $qst);
371
+            $qsts[$qstobj['QST_ID']] = EE_Question::new_instance($qstobj);
372 372
         }
373 373
         
374 374
         // now the answers (and we'll setup our arrays)
@@ -376,8 +376,8 @@  discard block
 block discarded – undo
376 376
         foreach ($ans_array as $ans) {
377 377
             $ansobj                             = array_combine($ans_columns, $ans);
378 378
             $ansobj                             = EE_Answer::new_instance($ansobj);
379
-            $q_n_as['answers'][ $ansobj->ID() ]   = $ansobj;
380
-            $q_n_as['questions'][ $ansobj->ID() ] = $qsts[ $ansobj->get('QST_ID') ];
379
+            $q_n_as['answers'][$ansobj->ID()]   = $ansobj;
380
+            $q_n_as['questions'][$ansobj->ID()] = $qsts[$ansobj->get('QST_ID')];
381 381
         }
382 382
         
383 383
         return $q_n_as;
@@ -461,11 +461,11 @@  discard block
 block discarded – undo
461 461
             $regtxn = $this->txn->ID();
462 462
             $regcnt = 1;
463 463
             foreach ($attendee['line_ref'] as $evtid) {
464
-                foreach ($this->_events[ $evtid ]['tkt_objs'] as $ticket) {
465
-                    if (! $ticket instanceof EE_Ticket) {
464
+                foreach ($this->_events[$evtid]['tkt_objs'] as $ticket) {
465
+                    if ( ! $ticket instanceof EE_Ticket) {
466 466
                         continue;
467 467
                     }
468
-                    $reg_array                                        = array(
468
+                    $reg_array = array(
469 469
                         'EVT_ID'           => $evtid,
470 470
                         'ATT_ID'           => $regatt,
471 471
                         'TXN_ID'           => $regtxn,
@@ -474,18 +474,18 @@  discard block
 block discarded – undo
474 474
                         'REG_date'         => time(),
475 475
                         'REG_final_price'  => $ticket->get('TKT_price'),
476 476
                         'REG_session'      => 'dummy_session_id',
477
-                        'REG_code'         => $regid . '-dummy-generated-code',
478
-                        'REG_url_link'     => $regcnt . '-daafpapasdlfakasdfpqasdfasdf',
477
+                        'REG_code'         => $regid.'-dummy-generated-code',
478
+                        'REG_url_link'     => $regcnt.'-daafpapasdlfakasdfpqasdfasdf',
479 479
                         'REG_count'        => $regcnt,
480
-                        'REG_group_size'   => $this->_events[ $evtid ]['total_attendees'],
480
+                        'REG_group_size'   => $this->_events[$evtid]['total_attendees'],
481 481
                         'REG_att_is_going' => true,
482 482
                         'REG_ID'           => $regid
483 483
                     );
484 484
                     $REG_OBJ                                          = EE_Registration::new_instance($reg_array);
485
-                    $this->_attendees[ $key ]['reg_objs'][ $regid ]       = $REG_OBJ;
486
-                    $this->_events[ $evtid ]['reg_objs'][]              = $REG_OBJ;
485
+                    $this->_attendees[$key]['reg_objs'][$regid]       = $REG_OBJ;
486
+                    $this->_events[$evtid]['reg_objs'][] = $REG_OBJ;
487 487
                     $this->reg_objs[]                                 = $REG_OBJ;
488
-                    $this->tickets[ $ticket->ID() ]['reg_objs'][ $regid ] = $REG_OBJ;
488
+                    $this->tickets[$ticket->ID()]['reg_objs'][$regid] = $REG_OBJ;
489 489
                     
490 490
                     $regcnt++;
491 491
                     $regid++;
@@ -523,18 +523,18 @@  discard block
 block discarded – undo
523 523
         $event_line_items = EEH_Line_Item::get_pre_tax_subtotal($line_item_total)->children();
524 524
         $line_items       = array();
525 525
         foreach ($event_line_items as $line_id => $line_item) {
526
-            if (! $line_item instanceof EE_Line_Item || $line_item->OBJ_type() !== 'Event') {
526
+            if ( ! $line_item instanceof EE_Line_Item || $line_item->OBJ_type() !== 'Event') {
527 527
                 continue;
528 528
             }
529 529
             $ticket_line_items = EEH_Line_Item::get_ticket_line_items($line_item);
530 530
             foreach ($ticket_line_items as $ticket_line_id => $ticket_line_item) {
531
-                if (! $ticket_line_item instanceof EE_Line_Item) {
531
+                if ( ! $ticket_line_item instanceof EE_Line_Item) {
532 532
                     continue;
533 533
                 }
534
-                $this->tickets[ $ticket_line_item->OBJ_ID() ]['line_item']      = $ticket_line_item;
535
-                $this->tickets[ $ticket_line_item->OBJ_ID() ]['sub_line_items'] = $ticket_line_item->children();
536
-                $line_items[ $ticket_line_item->ID() ]['children']              = $ticket_line_item->children();
537
-                $line_items[ $ticket_line_item->ID() ]['EE_Ticket']             = $this->tickets[ $ticket_line_item->OBJ_ID() ]['ticket'];
534
+                $this->tickets[$ticket_line_item->OBJ_ID()]['line_item']      = $ticket_line_item;
535
+                $this->tickets[$ticket_line_item->OBJ_ID()]['sub_line_items'] = $ticket_line_item->children();
536
+                $line_items[$ticket_line_item->ID()]['children']              = $ticket_line_item->children();
537
+                $line_items[$ticket_line_item->ID()]['EE_Ticket']             = $this->tickets[$ticket_line_item->OBJ_ID()]['ticket'];
538 538
             }
539 539
         }
540 540
         
@@ -549,15 +549,15 @@  discard block
 block discarded – undo
549 549
         
550 550
         // add additional details for each registration
551 551
         foreach ($this->reg_objs as $reg) {
552
-            if (! $reg instanceof EE_Registration) {
552
+            if ( ! $reg instanceof EE_Registration) {
553 553
                 continue;
554 554
             }
555
-            $this->_registrations[ $reg->ID() ]['tkt_obj']  = $this->tickets[ $reg->get('TKT_ID') ]['ticket'];
556
-            $this->_registrations[ $reg->ID() ]['evt_obj']  = $this->_events[ $reg->get('EVT_ID') ]['event'];
557
-            $this->_registrations[ $reg->ID() ]['reg_obj']  = $reg;
558
-            $this->_registrations[ $reg->ID() ]['ans_objs'] = $this->_attendees[ $reg->get('ATT_ID') ]['ans_objs'];
559
-            $this->_registrations[ $reg->ID() ]['att_obj']  = $this->_attendees[ $reg->get('ATT_ID') ]['att_obj'];
560
-            $this->_registrations[ $reg->ID() ]['dtt_objs'] = $this->tickets[ $reg->get('TKT_ID') ]['dtt_objs'];
555
+            $this->_registrations[$reg->ID()]['tkt_obj']  = $this->tickets[$reg->get('TKT_ID')]['ticket'];
556
+            $this->_registrations[$reg->ID()]['evt_obj']  = $this->_events[$reg->get('EVT_ID')]['event'];
557
+            $this->_registrations[$reg->ID()]['reg_obj']  = $reg;
558
+            $this->_registrations[$reg->ID()]['ans_objs'] = $this->_attendees[$reg->get('ATT_ID')]['ans_objs'];
559
+            $this->_registrations[$reg->ID()]['att_obj']  = $this->_attendees[$reg->get('ATT_ID')]['att_obj'];
560
+            $this->_registrations[$reg->ID()]['dtt_objs'] = $this->tickets[$reg->get('TKT_ID')]['dtt_objs'];
561 561
         }
562 562
         
563 563
         
Please login to merge, or discard this patch.
libraries/messages/data_class/EE_Messages_Gateways_incoming_data.class.php 2 patches
Indentation   +136 added lines, -136 removed lines patch added patch discarded remove patch
@@ -14,141 +14,141 @@
 block discarded – undo
14 14
 class EE_Messages_Gateways_incoming_data extends EE_Messages_incoming_data
15 15
 {
16 16
 
17
-    /**
18
-     * This holds the incoming payment object
19
-     * @var EE_Payment
20
-     */
21
-    public $payment;
22
-
23
-
24
-
25
-    /**
26
-     * incoming data is expected to be a EE_Transaction object and (possibly) EE_Payment object in an array.
27
-     *
28
-     * @param array $data
29
-     * @throws EE_Error
30
-     */
31
-    public function __construct($data)
32
-    {
33
-
34
-        // test for valid params
35
-        if (! ( $data[0] instanceof EE_Transaction )) {
36
-            throw new EE_Error(__('Incoming data for the Gateways data handler must have an EE_Transaction object as the value for the first array index.', 'event_espresso'));
37
-        }
38
-
39
-        if (empty($data[1]) || ! $data[1] instanceof  EE_Payment) {
40
-            $pmt_obj = $this->_get_empty_payment_obj($data[0]);
41
-        }
42
-
43
-        if (! empty($data[2])) {
44
-            $filtered_reg_status = $data[2];
45
-        }
17
+	/**
18
+	 * This holds the incoming payment object
19
+	 * @var EE_Payment
20
+	 */
21
+	public $payment;
22
+
23
+
24
+
25
+	/**
26
+	 * incoming data is expected to be a EE_Transaction object and (possibly) EE_Payment object in an array.
27
+	 *
28
+	 * @param array $data
29
+	 * @throws EE_Error
30
+	 */
31
+	public function __construct($data)
32
+	{
33
+
34
+		// test for valid params
35
+		if (! ( $data[0] instanceof EE_Transaction )) {
36
+			throw new EE_Error(__('Incoming data for the Gateways data handler must have an EE_Transaction object as the value for the first array index.', 'event_espresso'));
37
+		}
38
+
39
+		if (empty($data[1]) || ! $data[1] instanceof  EE_Payment) {
40
+			$pmt_obj = $this->_get_empty_payment_obj($data[0]);
41
+		}
42
+
43
+		if (! empty($data[2])) {
44
+			$filtered_reg_status = $data[2];
45
+		}
46 46
 
47
-        $data = array(
48
-            'txn_obj' => $data[0],
49
-            'pmt_obj' => isset($pmt_obj) ? $pmt_obj : $data[1],
50
-            'filtered_reg_status' => isset($filtered_reg_status) ? $filtered_reg_status : null
51
-            );
52
-        parent::__construct($data);
53
-    }
54
-
55
-
56
-
57
-
58
-
59
-    /**
60
-     * Returns database safe representation of the data later used to when instantiating this object.
61
-     *
62
-     * @param array $data The incoming data to be prepped.
63
-     *
64
-     * @return array   The prepped data for db
65
-     */
66
-    public static function convert_data_for_persistent_storage($data)
67
-    {
68
-        $prepped_data = array();
69
-
70
-        if ($data[0] instanceof EE_Transaction) {
71
-            $prepped_data['Transaction'] = $data[0]->ID();
72
-        }
73
-
74
-        if (isset($data[1]) && $data[1] instanceof EE_Payment) {
75
-            $prepped_data['Payment'] = $data[1]->ID();
76
-        }
77
-
78
-        if (! empty($data[2])) {
79
-            $prepped_data['filter'] = $data[2];
80
-        }
81
-
82
-        return $prepped_data;
83
-    }
84
-
85
-
86
-
87
-
88
-
89
-
90
-    /**
91
-     * Data that has been stored in persistent storage that was prepped by _convert_data_for_persistent_storage
92
-     * can be sent into this method and converted back into the format used for instantiating with this data handler.
93
-     *
94
-     * @param array  $data
95
-     *
96
-     * @return array
97
-     */
98
-    public static function convert_data_from_persistent_storage($data)
99
-    {
100
-        $prepped_data = array(
101
-            0 => isset($data['Transaction']) ? EEM_Transaction::instance()->get_one_by_ID($data['Transaction']) : null,
102
-            1 => isset($data['Payment']) ? EEM_Payment::instance()->get_one_by_ID($data['Payment']) : null,
103
-            2 => isset($data['filter']) ? $data['filter'] : null
104
-        );
105
-        return $prepped_data;
106
-    }
107
-
108
-
109
-    /**
110
-     * This sets up an empty EE_Payment object for the purpose of shortcode parsing.  Note that this doesn't actually get saved to the db.
111
-     * @param \EE_Transaction $txn
112
-     * @return \EE_Payment
113
-     */
114
-    private function _get_empty_payment_obj(EE_Transaction $txn)
115
-    {
116
-        $PMT = EE_Payment::new_instance(array(
117
-            'STS_ID' => EEM_Payment::status_id_pending,
118
-            'PAY_timestamp' => time(),
119
-            'PMD_ID' => $txn->payment_method_ID(),
120
-            'PAY_gateway_response' => $txn->gateway_response_on_transaction(),
121
-            ));
122
-        return $PMT;
123
-    }
124
-
125
-
126
-
127
-    /**
128
-     * _setup_data
129
-     *
130
-     * @throws EE_Error
131
-     */
132
-    protected function _setup_data()
133
-    {
134
-
135
-        $this->reg_info = array();
136
-
137
-        $this->txn = $this->_data['txn_obj'];
138
-        $this->payment = $this->_data['pmt_obj'];
139
-        $this->filtered_reg_status = $this->_data['filtered_reg_status'];
140
-        $this->incoming_data = $this->_data;
141
-
142
-        $session_data = $this->txn->session_data();
143
-
144
-
145
-        // other data from the session (if possible)
146
-        $this->user_id = isset($session_data['user_id']) ? $session_data['user_id'] : '';
147
-        $this->ip_address = isset($session_data['ip_address']) ? $session_data['ip_address'] : '';
148
-        $this->user_agent = isset($session_data['user_agent']) ? $session_data['user_agent'] : '';
149
-        $this->init_access = $this->last_access = '';
150
-        // get all non-trashed registrations
151
-        $this->reg_objs = $this->txn->registrations(array(array('REG_deleted' => false)));
152
-        $this->_assemble_data();
153
-    }
47
+		$data = array(
48
+			'txn_obj' => $data[0],
49
+			'pmt_obj' => isset($pmt_obj) ? $pmt_obj : $data[1],
50
+			'filtered_reg_status' => isset($filtered_reg_status) ? $filtered_reg_status : null
51
+			);
52
+		parent::__construct($data);
53
+	}
54
+
55
+
56
+
57
+
58
+
59
+	/**
60
+	 * Returns database safe representation of the data later used to when instantiating this object.
61
+	 *
62
+	 * @param array $data The incoming data to be prepped.
63
+	 *
64
+	 * @return array   The prepped data for db
65
+	 */
66
+	public static function convert_data_for_persistent_storage($data)
67
+	{
68
+		$prepped_data = array();
69
+
70
+		if ($data[0] instanceof EE_Transaction) {
71
+			$prepped_data['Transaction'] = $data[0]->ID();
72
+		}
73
+
74
+		if (isset($data[1]) && $data[1] instanceof EE_Payment) {
75
+			$prepped_data['Payment'] = $data[1]->ID();
76
+		}
77
+
78
+		if (! empty($data[2])) {
79
+			$prepped_data['filter'] = $data[2];
80
+		}
81
+
82
+		return $prepped_data;
83
+	}
84
+
85
+
86
+
87
+
88
+
89
+
90
+	/**
91
+	 * Data that has been stored in persistent storage that was prepped by _convert_data_for_persistent_storage
92
+	 * can be sent into this method and converted back into the format used for instantiating with this data handler.
93
+	 *
94
+	 * @param array  $data
95
+	 *
96
+	 * @return array
97
+	 */
98
+	public static function convert_data_from_persistent_storage($data)
99
+	{
100
+		$prepped_data = array(
101
+			0 => isset($data['Transaction']) ? EEM_Transaction::instance()->get_one_by_ID($data['Transaction']) : null,
102
+			1 => isset($data['Payment']) ? EEM_Payment::instance()->get_one_by_ID($data['Payment']) : null,
103
+			2 => isset($data['filter']) ? $data['filter'] : null
104
+		);
105
+		return $prepped_data;
106
+	}
107
+
108
+
109
+	/**
110
+	 * This sets up an empty EE_Payment object for the purpose of shortcode parsing.  Note that this doesn't actually get saved to the db.
111
+	 * @param \EE_Transaction $txn
112
+	 * @return \EE_Payment
113
+	 */
114
+	private function _get_empty_payment_obj(EE_Transaction $txn)
115
+	{
116
+		$PMT = EE_Payment::new_instance(array(
117
+			'STS_ID' => EEM_Payment::status_id_pending,
118
+			'PAY_timestamp' => time(),
119
+			'PMD_ID' => $txn->payment_method_ID(),
120
+			'PAY_gateway_response' => $txn->gateway_response_on_transaction(),
121
+			));
122
+		return $PMT;
123
+	}
124
+
125
+
126
+
127
+	/**
128
+	 * _setup_data
129
+	 *
130
+	 * @throws EE_Error
131
+	 */
132
+	protected function _setup_data()
133
+	{
134
+
135
+		$this->reg_info = array();
136
+
137
+		$this->txn = $this->_data['txn_obj'];
138
+		$this->payment = $this->_data['pmt_obj'];
139
+		$this->filtered_reg_status = $this->_data['filtered_reg_status'];
140
+		$this->incoming_data = $this->_data;
141
+
142
+		$session_data = $this->txn->session_data();
143
+
144
+
145
+		// other data from the session (if possible)
146
+		$this->user_id = isset($session_data['user_id']) ? $session_data['user_id'] : '';
147
+		$this->ip_address = isset($session_data['ip_address']) ? $session_data['ip_address'] : '';
148
+		$this->user_agent = isset($session_data['user_agent']) ? $session_data['user_agent'] : '';
149
+		$this->init_access = $this->last_access = '';
150
+		// get all non-trashed registrations
151
+		$this->reg_objs = $this->txn->registrations(array(array('REG_deleted' => false)));
152
+		$this->_assemble_data();
153
+	}
154 154
 }
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -32,7 +32,7 @@  discard block
 block discarded – undo
32 32
     {
33 33
 
34 34
         // test for valid params
35
-        if (! ( $data[0] instanceof EE_Transaction )) {
35
+        if ( ! ($data[0] instanceof EE_Transaction)) {
36 36
             throw new EE_Error(__('Incoming data for the Gateways data handler must have an EE_Transaction object as the value for the first array index.', 'event_espresso'));
37 37
         }
38 38
 
@@ -40,7 +40,7 @@  discard block
 block discarded – undo
40 40
             $pmt_obj = $this->_get_empty_payment_obj($data[0]);
41 41
         }
42 42
 
43
-        if (! empty($data[2])) {
43
+        if ( ! empty($data[2])) {
44 44
             $filtered_reg_status = $data[2];
45 45
         }
46 46
 
@@ -75,7 +75,7 @@  discard block
 block discarded – undo
75 75
             $prepped_data['Payment'] = $data[1]->ID();
76 76
         }
77 77
 
78
-        if (! empty($data[2])) {
78
+        if ( ! empty($data[2])) {
79 79
             $prepped_data['filter'] = $data[2];
80 80
         }
81 81
 
Please login to merge, or discard this patch.