Completed
Branch BUG/chicken-is-a-required-ques... (12feb4)
by
unknown
27:48 queued 14:38
created
core/db_classes/EE_Message_Template_Group.class.php 3 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -211,7 +211,7 @@
 block discarded – undo
211 211
      * appropriately.
212 212
      *
213 213
      * @throws EE_Error
214
-     * @return EE_message_type|false if exception thrown.
214
+     * @return null|EE_message_type if exception thrown.
215 215
      */
216 216
     public function message_type_obj()
217 217
     {
Please login to merge, or discard this patch.
Indentation   +483 added lines, -483 removed lines patch added patch discarded remove patch
@@ -13,487 +13,487 @@
 block discarded – undo
13 13
 class EE_Message_Template_Group extends EE_Soft_Delete_Base_Class
14 14
 {
15 15
 
16
-    /**
17
-     * Extra Meta key prefix for whether a given context for this message tmeplate group is active or not.
18
-     */
19
-    const ACTIVE_CONTEXT_RECORD_META_KEY_PREFIX = 'active_context_';
20
-
21
-    /**
22
-     * @param array  $props_n_values
23
-     * @param string $timezone
24
-     * @return EE_Message_Template_Group|mixed
25
-     * @throws EE_Error
26
-     */
27
-    public static function new_instance($props_n_values = array(), $timezone = '')
28
-    {
29
-        $has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone);
30
-        return $has_object ? $has_object : new self($props_n_values, false, $timezone);
31
-    }
32
-
33
-
34
-    /**
35
-     * @param array  $props_n_values
36
-     * @param string $timezone
37
-     * @return EE_Message_Template_Group
38
-     */
39
-    public static function new_instance_from_db($props_n_values = array(), $timezone = '')
40
-    {
41
-        return new self($props_n_values, true, $timezone);
42
-    }
43
-
44
-
45
-    /**
46
-     * @param bool $message_type
47
-     * @throws EE_Error
48
-     */
49
-    public function set_message_type($message_type = false)
50
-    {
51
-        if (! $message_type) {
52
-            throw new EE_Error(esc_html__('Missing required value for the message_type parameter', 'event_espresso'));
53
-        }
54
-        $this->set('MTP_message_type', $message_type);
55
-    }
56
-
57
-
58
-    /**
59
-     * @param bool $messenger
60
-     * @throws EE_Error
61
-     */
62
-    public function set_messenger($messenger = false)
63
-    {
64
-        if (! $messenger) {
65
-            throw new EE_Error(esc_html__('Missing required value for the messenger parameter', 'event_espresso'));
66
-        }
67
-        $this->set('MTP_messenger', $messenger);
68
-    }
69
-
70
-
71
-    /**
72
-     * @param bool $GRP_ID
73
-     * @throws EE_Error
74
-     */
75
-    public function set_group_template_id($GRP_ID = false)
76
-    {
77
-        if (! $GRP_ID) {
78
-            throw new EE_Error(
79
-                esc_html__(
80
-                    'Missing required value for the message template group id',
81
-                    'event_espresso'
82
-                )
83
-            );
84
-        }
85
-        $this->set('GRP_ID', $GRP_ID);
86
-    }
87
-
88
-
89
-    /**
90
-     * get Group ID
91
-     *
92
-     * @access public
93
-     * @return int
94
-     * @throws EE_Error
95
-     */
96
-    public function GRP_ID()
97
-    {
98
-        return $this->get('GRP_ID');
99
-    }
100
-
101
-
102
-    /**
103
-     * get User ID
104
-     *
105
-     * @access public
106
-     * @return int
107
-     * @throws EE_Error
108
-     */
109
-    public function user()
110
-    {
111
-        $user_id = $this->get('MTP_user_id');
112
-        return empty($user_id) ? get_current_user_id() : $user_id;
113
-    }
114
-
115
-
116
-    /**
117
-     * Wrapper for the user function() (preserve backward compat)
118
-     *
119
-     * @since  4.5.0
120
-     * @return int
121
-     * @throws EE_Error
122
-     */
123
-    public function wp_user()
124
-    {
125
-        return $this->user();
126
-    }
127
-
128
-
129
-    /**
130
-     * This simply returns a count of all related events to this message template group
131
-     *
132
-     * @return int
133
-     */
134
-    public function count_events()
135
-    {
136
-        return $this->count_related('Event');
137
-    }
138
-
139
-
140
-    /**
141
-     * returns the name saved in the db for this template
142
-     *
143
-     * @return string
144
-     * @throws EE_Error
145
-     */
146
-    public function name()
147
-    {
148
-        return $this->get('MTP_name');
149
-    }
150
-
151
-
152
-    /**
153
-     * Returns the description saved in the db for this template group
154
-     *
155
-     * @return string
156
-     * @throws EE_Error
157
-     */
158
-    public function description()
159
-    {
160
-        return $this->get('MTP_description');
161
-    }
162
-
163
-
164
-    /**
165
-     * returns all related EE_Message_Template objects
166
-     *
167
-     * @param  array $query_params like EEM_Base::get_all()
168
-     * @return EE_Message_Template[]
169
-     * @throws EE_Error
170
-     */
171
-    public function message_templates($query_params = array())
172
-    {
173
-        return $this->get_many_related('Message_Template', $query_params);
174
-    }
175
-
176
-
177
-    /**
178
-     * get Message Messenger
179
-     *
180
-     * @access public
181
-     * @return string
182
-     * @throws EE_Error
183
-     */
184
-    public function messenger()
185
-    {
186
-        return $this->get('MTP_messenger');
187
-    }
188
-
189
-
190
-    /**
191
-     * get Message Messenger OBJECT
192
-     * If an attempt to get the corresponding messenger object fails, then we set this message
193
-     * template group to inactive, and save to db.  Then return null so client code can handle
194
-     * appropriately.
195
-     *
196
-     * @return EE_messenger
197
-     * @throws EE_Error
198
-     */
199
-    public function messenger_obj()
200
-    {
201
-        $messenger = $this->messenger();
202
-        try {
203
-            $messenger = EEH_MSG_Template::messenger_obj($messenger);
204
-        } catch (EE_Error $e) {
205
-            // if an exception was thrown then let's deactivate this message template group because it means there is no
206
-            // class for this messenger in this group.
207
-            $this->set('MTP_is_active', false);
208
-            $this->save();
209
-            return null;
210
-        }
211
-        return $messenger;
212
-    }
213
-
214
-
215
-    /**
216
-     * get Message Type
217
-     *
218
-     * @access public
219
-     * @return string
220
-     * @throws EE_Error
221
-     */
222
-    public function message_type()
223
-    {
224
-        return $this->get('MTP_message_type');
225
-    }
226
-
227
-
228
-    /**
229
-     * get Message type OBJECT
230
-     * If an attempt to get the corresponding message type object fails, then we set this message
231
-     * template group to inactive, and save to db.  Then return null so client code can handle
232
-     * appropriately.
233
-     *
234
-     * @throws EE_Error
235
-     * @return EE_message_type|false if exception thrown.
236
-     */
237
-    public function message_type_obj()
238
-    {
239
-        $message_type = $this->message_type();
240
-        try {
241
-            $message_type = EEH_MSG_Template::message_type_obj($message_type);
242
-        } catch (EE_Error $e) {
243
-            // if an exception was thrown then let's deactivate this message template group because it means there is no
244
-            // class for the message type in this group.
245
-            $this->set('MTP_is_active', false);
246
-            $this->save();
247
-            return null;
248
-        }
249
-        return $message_type;
250
-    }
251
-
252
-
253
-    /**
254
-     * @return array
255
-     * @throws EE_Error
256
-     */
257
-    public function contexts_config()
258
-    {
259
-        return $this->message_type_obj()->get_contexts();
260
-    }
261
-
262
-
263
-    /**
264
-     * This returns the context_label for contexts as set in the message type object
265
-     * Note this is an array with singular and plural keys
266
-     *
267
-     * @access public
268
-     * @return array labels for "context"
269
-     * @throws EE_Error
270
-     */
271
-    public function context_label()
272
-    {
273
-        $obj = $this->message_type_obj();
274
-        return $obj->get_context_label();
275
-    }
276
-
277
-
278
-    /**
279
-     * This returns an array of EE_Message_Template objects indexed by context and field.
280
-     *
281
-     * @return array ()
282
-     * @throws EE_Error
283
-     */
284
-    public function context_templates()
285
-    {
286
-        $mtps_arr = array();
287
-        $mtps = $this->get_many_related('Message_Template');
288
-        if (empty($mtps)) {
289
-            return array();
290
-        }
291
-        // note contexts could have CHECKBOX fields per context. So we return the objects indexed by context AND field.
292
-        foreach ($mtps as $mtp) {
293
-            $mtps_arr[ $mtp->get('MTP_context') ][ $mtp->get('MTP_template_field') ] = $mtp;
294
-        }
295
-        return $mtps_arr;
296
-    }
297
-
298
-
299
-    /**
300
-     * this returns if the template group this template belongs to is global
301
-     *
302
-     * @return bool true if it is, false if it isn't
303
-     * @throws EE_Error
304
-     */
305
-    public function is_global()
306
-    {
307
-        return $this->get('MTP_is_global');
308
-    }
309
-
310
-
311
-    /**
312
-     * this returns if the template group this template belongs to is active (i.e. turned "on" or not)
313
-     *
314
-     * @return bool true if it is, false if it isn't
315
-     * @throws EE_Error
316
-     */
317
-    public function is_active()
318
-    {
319
-        return $this->get('MTP_is_active');
320
-    }
321
-
322
-
323
-    /**
324
-     * This will return an array of shortcodes => labels from the messenger and message_type objects associated with
325
-     * this template.
326
-     *
327
-     * @since 4.3.0
328
-     * @uses  EEH_MSG_Template::get_shortcodes()
329
-     * @param string $context what context we're going to return shortcodes for
330
-     * @param array  $fields  what fields we're returning valid shortcodes for.  If empty then we assume all fields are
331
-     *                        to be returned.
332
-     * @param bool   $merged  If TRUE then we don't return shortcodes indexed by field but instead an array of the
333
-     *                        unique shortcodes for all the given (or all) fields.
334
-     * @return mixed (array|bool) an array of shortcodes in the format array( '[shortcode] => 'label') OR FALSE if no
335
-     *                        shortcodes found.
336
-     * @throws EE_Error
337
-     */
338
-    public function get_shortcodes($context, $fields = array(), $merged = false)
339
-    {
340
-        $messenger = $this->messenger();
341
-        $message_type = $this->message_type();
342
-        return EEH_MSG_Template::get_shortcodes($message_type, $messenger, $fields, $context, $merged);
343
-    }
344
-
345
-
346
-    /**
347
-     * This just gets the template pack name assigned to this message template group.  If it's not set, then we just
348
-     * use the default template pack.
349
-     *
350
-     * @since 4.5.0
351
-     * @return string
352
-     * @throws EE_Error
353
-     */
354
-    public function get_template_pack_name()
355
-    {
356
-        return $this->get_extra_meta('MTP_template_pack', true, 'default');
357
-    }
358
-
359
-
360
-    /**
361
-     * This returns the specific template pack object referenced by the template pack name attached to this message
362
-     * template group.  If no template pack is assigned then the default template pack is retrieved.
363
-     *
364
-     * @since 4.5.0
365
-     * @return EE_Messages_Template_Pack
366
-     * @throws EE_Error
367
-     * @throws InvalidArgumentException
368
-     * @throws ReflectionException
369
-     * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
370
-     * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
371
-     */
372
-    public function get_template_pack()
373
-    {
374
-        $pack_name = $this->get_template_pack_name();
375
-        EE_Registry::instance()->load_helper('MSG_Template');
376
-        return EEH_MSG_Template::get_template_pack($pack_name);
377
-    }
378
-
379
-
380
-    /**
381
-     * This retrieves the template variation assigned to this message template group.  If it's not set, then we just
382
-     * use the default template variation.
383
-     *
384
-     * @since 4.5.0
385
-     * @return string
386
-     * @throws EE_Error
387
-     */
388
-    public function get_template_pack_variation()
389
-    {
390
-        return $this->get_extra_meta('MTP_variation', true, 'default');
391
-    }
392
-
393
-
394
-    /**
395
-     * This just sets the template pack name attached to this message template group.
396
-     *
397
-     * @since 4.5.0
398
-     * @param string $template_pack_name What message template pack is assigned.
399
-     * @return int
400
-     * @throws EE_Error
401
-     */
402
-    public function set_template_pack_name($template_pack_name)
403
-    {
404
-        return $this->update_extra_meta('MTP_template_pack', $template_pack_name);
405
-    }
406
-
407
-
408
-    /**
409
-     * This just sets the template pack variation attached to this message template group.
410
-     *
411
-     * @since 4.5.0
412
-     * @param string $variation What variation is being set on the message template group.
413
-     * @return int
414
-     * @throws EE_Error
415
-     */
416
-    public function set_template_pack_variation($variation)
417
-    {
418
-        return $this->update_extra_meta('MTP_variation', $variation);
419
-    }
420
-
421
-
422
-    /**
423
-     * Deactivates the given context.
424
-     *
425
-     * @param $context
426
-     * @return bool|int
427
-     * @throws EE_Error
428
-     * @throws InvalidIdentifierException
429
-     */
430
-    public function deactivate_context($context)
431
-    {
432
-        $this->validate_context($context);
433
-        return $this->update_extra_meta(self::ACTIVE_CONTEXT_RECORD_META_KEY_PREFIX . $context, false);
434
-    }
435
-
436
-
437
-    /**
438
-     * Activates the given context.
439
-     *
440
-     * @param $context
441
-     * @return bool|int
442
-     * @throws EE_Error
443
-     * @throws InvalidIdentifierException
444
-     */
445
-    public function activate_context($context)
446
-    {
447
-        $this->validate_context($context);
448
-        return $this->update_extra_meta(self::ACTIVE_CONTEXT_RECORD_META_KEY_PREFIX . $context, true);
449
-    }
450
-
451
-
452
-    /**
453
-     * Returns whether the context is active or not.
454
-     * Note, this will default to true if the extra meta record doesn't exist.
455
-     * Also, this does NOT account for whether the "To" field is empty or not. Some messengers may allow the "To" field
456
-     * to be empty (@see EE_Messenger::allow_empty_to_field()) so an empty "To" field is not always an indicator of
457
-     * whether a context is "active" or not.
458
-     *
459
-     * @param $context
460
-     * @return bool
461
-     * @throws EE_Error
462
-     * @throws InvalidIdentifierException
463
-     */
464
-    public function is_context_active($context)
465
-    {
466
-        $this->validate_context($context);
467
-        return filter_var(
468
-            $this->get_extra_meta(self::ACTIVE_CONTEXT_RECORD_META_KEY_PREFIX . $context, true, true),
469
-            FILTER_VALIDATE_BOOLEAN
470
-        );
471
-    }
472
-
473
-
474
-    /**
475
-     * Validates the incoming context to verify it matches a registered context for the related message type.
476
-     *
477
-     * @param string $context
478
-     * @throws EE_Error
479
-     * @throws InvalidIdentifierException
480
-     */
481
-    public function validate_context($context)
482
-    {
483
-        $contexts = $this->contexts_config();
484
-        if (! isset($contexts[ $context ])) {
485
-            throw new InvalidIdentifierException(
486
-                '',
487
-                '',
488
-                sprintf(
489
-                    esc_html__(
490
-                        'An invalid string identifying a context was provided.  "%1$s" was received, and one of "%2$s" was expected.',
491
-                        'event_espresso'
492
-                    ),
493
-                    $context,
494
-                    implode(',', array_keys($contexts))
495
-                )
496
-            );
497
-        }
498
-    }
16
+	/**
17
+	 * Extra Meta key prefix for whether a given context for this message tmeplate group is active or not.
18
+	 */
19
+	const ACTIVE_CONTEXT_RECORD_META_KEY_PREFIX = 'active_context_';
20
+
21
+	/**
22
+	 * @param array  $props_n_values
23
+	 * @param string $timezone
24
+	 * @return EE_Message_Template_Group|mixed
25
+	 * @throws EE_Error
26
+	 */
27
+	public static function new_instance($props_n_values = array(), $timezone = '')
28
+	{
29
+		$has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone);
30
+		return $has_object ? $has_object : new self($props_n_values, false, $timezone);
31
+	}
32
+
33
+
34
+	/**
35
+	 * @param array  $props_n_values
36
+	 * @param string $timezone
37
+	 * @return EE_Message_Template_Group
38
+	 */
39
+	public static function new_instance_from_db($props_n_values = array(), $timezone = '')
40
+	{
41
+		return new self($props_n_values, true, $timezone);
42
+	}
43
+
44
+
45
+	/**
46
+	 * @param bool $message_type
47
+	 * @throws EE_Error
48
+	 */
49
+	public function set_message_type($message_type = false)
50
+	{
51
+		if (! $message_type) {
52
+			throw new EE_Error(esc_html__('Missing required value for the message_type parameter', 'event_espresso'));
53
+		}
54
+		$this->set('MTP_message_type', $message_type);
55
+	}
56
+
57
+
58
+	/**
59
+	 * @param bool $messenger
60
+	 * @throws EE_Error
61
+	 */
62
+	public function set_messenger($messenger = false)
63
+	{
64
+		if (! $messenger) {
65
+			throw new EE_Error(esc_html__('Missing required value for the messenger parameter', 'event_espresso'));
66
+		}
67
+		$this->set('MTP_messenger', $messenger);
68
+	}
69
+
70
+
71
+	/**
72
+	 * @param bool $GRP_ID
73
+	 * @throws EE_Error
74
+	 */
75
+	public function set_group_template_id($GRP_ID = false)
76
+	{
77
+		if (! $GRP_ID) {
78
+			throw new EE_Error(
79
+				esc_html__(
80
+					'Missing required value for the message template group id',
81
+					'event_espresso'
82
+				)
83
+			);
84
+		}
85
+		$this->set('GRP_ID', $GRP_ID);
86
+	}
87
+
88
+
89
+	/**
90
+	 * get Group ID
91
+	 *
92
+	 * @access public
93
+	 * @return int
94
+	 * @throws EE_Error
95
+	 */
96
+	public function GRP_ID()
97
+	{
98
+		return $this->get('GRP_ID');
99
+	}
100
+
101
+
102
+	/**
103
+	 * get User ID
104
+	 *
105
+	 * @access public
106
+	 * @return int
107
+	 * @throws EE_Error
108
+	 */
109
+	public function user()
110
+	{
111
+		$user_id = $this->get('MTP_user_id');
112
+		return empty($user_id) ? get_current_user_id() : $user_id;
113
+	}
114
+
115
+
116
+	/**
117
+	 * Wrapper for the user function() (preserve backward compat)
118
+	 *
119
+	 * @since  4.5.0
120
+	 * @return int
121
+	 * @throws EE_Error
122
+	 */
123
+	public function wp_user()
124
+	{
125
+		return $this->user();
126
+	}
127
+
128
+
129
+	/**
130
+	 * This simply returns a count of all related events to this message template group
131
+	 *
132
+	 * @return int
133
+	 */
134
+	public function count_events()
135
+	{
136
+		return $this->count_related('Event');
137
+	}
138
+
139
+
140
+	/**
141
+	 * returns the name saved in the db for this template
142
+	 *
143
+	 * @return string
144
+	 * @throws EE_Error
145
+	 */
146
+	public function name()
147
+	{
148
+		return $this->get('MTP_name');
149
+	}
150
+
151
+
152
+	/**
153
+	 * Returns the description saved in the db for this template group
154
+	 *
155
+	 * @return string
156
+	 * @throws EE_Error
157
+	 */
158
+	public function description()
159
+	{
160
+		return $this->get('MTP_description');
161
+	}
162
+
163
+
164
+	/**
165
+	 * returns all related EE_Message_Template objects
166
+	 *
167
+	 * @param  array $query_params like EEM_Base::get_all()
168
+	 * @return EE_Message_Template[]
169
+	 * @throws EE_Error
170
+	 */
171
+	public function message_templates($query_params = array())
172
+	{
173
+		return $this->get_many_related('Message_Template', $query_params);
174
+	}
175
+
176
+
177
+	/**
178
+	 * get Message Messenger
179
+	 *
180
+	 * @access public
181
+	 * @return string
182
+	 * @throws EE_Error
183
+	 */
184
+	public function messenger()
185
+	{
186
+		return $this->get('MTP_messenger');
187
+	}
188
+
189
+
190
+	/**
191
+	 * get Message Messenger OBJECT
192
+	 * If an attempt to get the corresponding messenger object fails, then we set this message
193
+	 * template group to inactive, and save to db.  Then return null so client code can handle
194
+	 * appropriately.
195
+	 *
196
+	 * @return EE_messenger
197
+	 * @throws EE_Error
198
+	 */
199
+	public function messenger_obj()
200
+	{
201
+		$messenger = $this->messenger();
202
+		try {
203
+			$messenger = EEH_MSG_Template::messenger_obj($messenger);
204
+		} catch (EE_Error $e) {
205
+			// if an exception was thrown then let's deactivate this message template group because it means there is no
206
+			// class for this messenger in this group.
207
+			$this->set('MTP_is_active', false);
208
+			$this->save();
209
+			return null;
210
+		}
211
+		return $messenger;
212
+	}
213
+
214
+
215
+	/**
216
+	 * get Message Type
217
+	 *
218
+	 * @access public
219
+	 * @return string
220
+	 * @throws EE_Error
221
+	 */
222
+	public function message_type()
223
+	{
224
+		return $this->get('MTP_message_type');
225
+	}
226
+
227
+
228
+	/**
229
+	 * get Message type OBJECT
230
+	 * If an attempt to get the corresponding message type object fails, then we set this message
231
+	 * template group to inactive, and save to db.  Then return null so client code can handle
232
+	 * appropriately.
233
+	 *
234
+	 * @throws EE_Error
235
+	 * @return EE_message_type|false if exception thrown.
236
+	 */
237
+	public function message_type_obj()
238
+	{
239
+		$message_type = $this->message_type();
240
+		try {
241
+			$message_type = EEH_MSG_Template::message_type_obj($message_type);
242
+		} catch (EE_Error $e) {
243
+			// if an exception was thrown then let's deactivate this message template group because it means there is no
244
+			// class for the message type in this group.
245
+			$this->set('MTP_is_active', false);
246
+			$this->save();
247
+			return null;
248
+		}
249
+		return $message_type;
250
+	}
251
+
252
+
253
+	/**
254
+	 * @return array
255
+	 * @throws EE_Error
256
+	 */
257
+	public function contexts_config()
258
+	{
259
+		return $this->message_type_obj()->get_contexts();
260
+	}
261
+
262
+
263
+	/**
264
+	 * This returns the context_label for contexts as set in the message type object
265
+	 * Note this is an array with singular and plural keys
266
+	 *
267
+	 * @access public
268
+	 * @return array labels for "context"
269
+	 * @throws EE_Error
270
+	 */
271
+	public function context_label()
272
+	{
273
+		$obj = $this->message_type_obj();
274
+		return $obj->get_context_label();
275
+	}
276
+
277
+
278
+	/**
279
+	 * This returns an array of EE_Message_Template objects indexed by context and field.
280
+	 *
281
+	 * @return array ()
282
+	 * @throws EE_Error
283
+	 */
284
+	public function context_templates()
285
+	{
286
+		$mtps_arr = array();
287
+		$mtps = $this->get_many_related('Message_Template');
288
+		if (empty($mtps)) {
289
+			return array();
290
+		}
291
+		// note contexts could have CHECKBOX fields per context. So we return the objects indexed by context AND field.
292
+		foreach ($mtps as $mtp) {
293
+			$mtps_arr[ $mtp->get('MTP_context') ][ $mtp->get('MTP_template_field') ] = $mtp;
294
+		}
295
+		return $mtps_arr;
296
+	}
297
+
298
+
299
+	/**
300
+	 * this returns if the template group this template belongs to is global
301
+	 *
302
+	 * @return bool true if it is, false if it isn't
303
+	 * @throws EE_Error
304
+	 */
305
+	public function is_global()
306
+	{
307
+		return $this->get('MTP_is_global');
308
+	}
309
+
310
+
311
+	/**
312
+	 * this returns if the template group this template belongs to is active (i.e. turned "on" or not)
313
+	 *
314
+	 * @return bool true if it is, false if it isn't
315
+	 * @throws EE_Error
316
+	 */
317
+	public function is_active()
318
+	{
319
+		return $this->get('MTP_is_active');
320
+	}
321
+
322
+
323
+	/**
324
+	 * This will return an array of shortcodes => labels from the messenger and message_type objects associated with
325
+	 * this template.
326
+	 *
327
+	 * @since 4.3.0
328
+	 * @uses  EEH_MSG_Template::get_shortcodes()
329
+	 * @param string $context what context we're going to return shortcodes for
330
+	 * @param array  $fields  what fields we're returning valid shortcodes for.  If empty then we assume all fields are
331
+	 *                        to be returned.
332
+	 * @param bool   $merged  If TRUE then we don't return shortcodes indexed by field but instead an array of the
333
+	 *                        unique shortcodes for all the given (or all) fields.
334
+	 * @return mixed (array|bool) an array of shortcodes in the format array( '[shortcode] => 'label') OR FALSE if no
335
+	 *                        shortcodes found.
336
+	 * @throws EE_Error
337
+	 */
338
+	public function get_shortcodes($context, $fields = array(), $merged = false)
339
+	{
340
+		$messenger = $this->messenger();
341
+		$message_type = $this->message_type();
342
+		return EEH_MSG_Template::get_shortcodes($message_type, $messenger, $fields, $context, $merged);
343
+	}
344
+
345
+
346
+	/**
347
+	 * This just gets the template pack name assigned to this message template group.  If it's not set, then we just
348
+	 * use the default template pack.
349
+	 *
350
+	 * @since 4.5.0
351
+	 * @return string
352
+	 * @throws EE_Error
353
+	 */
354
+	public function get_template_pack_name()
355
+	{
356
+		return $this->get_extra_meta('MTP_template_pack', true, 'default');
357
+	}
358
+
359
+
360
+	/**
361
+	 * This returns the specific template pack object referenced by the template pack name attached to this message
362
+	 * template group.  If no template pack is assigned then the default template pack is retrieved.
363
+	 *
364
+	 * @since 4.5.0
365
+	 * @return EE_Messages_Template_Pack
366
+	 * @throws EE_Error
367
+	 * @throws InvalidArgumentException
368
+	 * @throws ReflectionException
369
+	 * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
370
+	 * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
371
+	 */
372
+	public function get_template_pack()
373
+	{
374
+		$pack_name = $this->get_template_pack_name();
375
+		EE_Registry::instance()->load_helper('MSG_Template');
376
+		return EEH_MSG_Template::get_template_pack($pack_name);
377
+	}
378
+
379
+
380
+	/**
381
+	 * This retrieves the template variation assigned to this message template group.  If it's not set, then we just
382
+	 * use the default template variation.
383
+	 *
384
+	 * @since 4.5.0
385
+	 * @return string
386
+	 * @throws EE_Error
387
+	 */
388
+	public function get_template_pack_variation()
389
+	{
390
+		return $this->get_extra_meta('MTP_variation', true, 'default');
391
+	}
392
+
393
+
394
+	/**
395
+	 * This just sets the template pack name attached to this message template group.
396
+	 *
397
+	 * @since 4.5.0
398
+	 * @param string $template_pack_name What message template pack is assigned.
399
+	 * @return int
400
+	 * @throws EE_Error
401
+	 */
402
+	public function set_template_pack_name($template_pack_name)
403
+	{
404
+		return $this->update_extra_meta('MTP_template_pack', $template_pack_name);
405
+	}
406
+
407
+
408
+	/**
409
+	 * This just sets the template pack variation attached to this message template group.
410
+	 *
411
+	 * @since 4.5.0
412
+	 * @param string $variation What variation is being set on the message template group.
413
+	 * @return int
414
+	 * @throws EE_Error
415
+	 */
416
+	public function set_template_pack_variation($variation)
417
+	{
418
+		return $this->update_extra_meta('MTP_variation', $variation);
419
+	}
420
+
421
+
422
+	/**
423
+	 * Deactivates the given context.
424
+	 *
425
+	 * @param $context
426
+	 * @return bool|int
427
+	 * @throws EE_Error
428
+	 * @throws InvalidIdentifierException
429
+	 */
430
+	public function deactivate_context($context)
431
+	{
432
+		$this->validate_context($context);
433
+		return $this->update_extra_meta(self::ACTIVE_CONTEXT_RECORD_META_KEY_PREFIX . $context, false);
434
+	}
435
+
436
+
437
+	/**
438
+	 * Activates the given context.
439
+	 *
440
+	 * @param $context
441
+	 * @return bool|int
442
+	 * @throws EE_Error
443
+	 * @throws InvalidIdentifierException
444
+	 */
445
+	public function activate_context($context)
446
+	{
447
+		$this->validate_context($context);
448
+		return $this->update_extra_meta(self::ACTIVE_CONTEXT_RECORD_META_KEY_PREFIX . $context, true);
449
+	}
450
+
451
+
452
+	/**
453
+	 * Returns whether the context is active or not.
454
+	 * Note, this will default to true if the extra meta record doesn't exist.
455
+	 * Also, this does NOT account for whether the "To" field is empty or not. Some messengers may allow the "To" field
456
+	 * to be empty (@see EE_Messenger::allow_empty_to_field()) so an empty "To" field is not always an indicator of
457
+	 * whether a context is "active" or not.
458
+	 *
459
+	 * @param $context
460
+	 * @return bool
461
+	 * @throws EE_Error
462
+	 * @throws InvalidIdentifierException
463
+	 */
464
+	public function is_context_active($context)
465
+	{
466
+		$this->validate_context($context);
467
+		return filter_var(
468
+			$this->get_extra_meta(self::ACTIVE_CONTEXT_RECORD_META_KEY_PREFIX . $context, true, true),
469
+			FILTER_VALIDATE_BOOLEAN
470
+		);
471
+	}
472
+
473
+
474
+	/**
475
+	 * Validates the incoming context to verify it matches a registered context for the related message type.
476
+	 *
477
+	 * @param string $context
478
+	 * @throws EE_Error
479
+	 * @throws InvalidIdentifierException
480
+	 */
481
+	public function validate_context($context)
482
+	{
483
+		$contexts = $this->contexts_config();
484
+		if (! isset($contexts[ $context ])) {
485
+			throw new InvalidIdentifierException(
486
+				'',
487
+				'',
488
+				sprintf(
489
+					esc_html__(
490
+						'An invalid string identifying a context was provided.  "%1$s" was received, and one of "%2$s" was expected.',
491
+						'event_espresso'
492
+					),
493
+					$context,
494
+					implode(',', array_keys($contexts))
495
+				)
496
+			);
497
+		}
498
+	}
499 499
 }
Please login to merge, or discard this patch.
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -48,7 +48,7 @@  discard block
 block discarded – undo
48 48
      */
49 49
     public function set_message_type($message_type = false)
50 50
     {
51
-        if (! $message_type) {
51
+        if ( ! $message_type) {
52 52
             throw new EE_Error(esc_html__('Missing required value for the message_type parameter', 'event_espresso'));
53 53
         }
54 54
         $this->set('MTP_message_type', $message_type);
@@ -61,7 +61,7 @@  discard block
 block discarded – undo
61 61
      */
62 62
     public function set_messenger($messenger = false)
63 63
     {
64
-        if (! $messenger) {
64
+        if ( ! $messenger) {
65 65
             throw new EE_Error(esc_html__('Missing required value for the messenger parameter', 'event_espresso'));
66 66
         }
67 67
         $this->set('MTP_messenger', $messenger);
@@ -74,7 +74,7 @@  discard block
 block discarded – undo
74 74
      */
75 75
     public function set_group_template_id($GRP_ID = false)
76 76
     {
77
-        if (! $GRP_ID) {
77
+        if ( ! $GRP_ID) {
78 78
             throw new EE_Error(
79 79
                 esc_html__(
80 80
                     'Missing required value for the message template group id',
@@ -290,7 +290,7 @@  discard block
 block discarded – undo
290 290
         }
291 291
         // note contexts could have CHECKBOX fields per context. So we return the objects indexed by context AND field.
292 292
         foreach ($mtps as $mtp) {
293
-            $mtps_arr[ $mtp->get('MTP_context') ][ $mtp->get('MTP_template_field') ] = $mtp;
293
+            $mtps_arr[$mtp->get('MTP_context')][$mtp->get('MTP_template_field')] = $mtp;
294 294
         }
295 295
         return $mtps_arr;
296 296
     }
@@ -430,7 +430,7 @@  discard block
 block discarded – undo
430 430
     public function deactivate_context($context)
431 431
     {
432 432
         $this->validate_context($context);
433
-        return $this->update_extra_meta(self::ACTIVE_CONTEXT_RECORD_META_KEY_PREFIX . $context, false);
433
+        return $this->update_extra_meta(self::ACTIVE_CONTEXT_RECORD_META_KEY_PREFIX.$context, false);
434 434
     }
435 435
 
436 436
 
@@ -445,7 +445,7 @@  discard block
 block discarded – undo
445 445
     public function activate_context($context)
446 446
     {
447 447
         $this->validate_context($context);
448
-        return $this->update_extra_meta(self::ACTIVE_CONTEXT_RECORD_META_KEY_PREFIX . $context, true);
448
+        return $this->update_extra_meta(self::ACTIVE_CONTEXT_RECORD_META_KEY_PREFIX.$context, true);
449 449
     }
450 450
 
451 451
 
@@ -465,7 +465,7 @@  discard block
 block discarded – undo
465 465
     {
466 466
         $this->validate_context($context);
467 467
         return filter_var(
468
-            $this->get_extra_meta(self::ACTIVE_CONTEXT_RECORD_META_KEY_PREFIX . $context, true, true),
468
+            $this->get_extra_meta(self::ACTIVE_CONTEXT_RECORD_META_KEY_PREFIX.$context, true, true),
469 469
             FILTER_VALIDATE_BOOLEAN
470 470
         );
471 471
     }
@@ -481,7 +481,7 @@  discard block
 block discarded – undo
481 481
     public function validate_context($context)
482 482
     {
483 483
         $contexts = $this->contexts_config();
484
-        if (! isset($contexts[ $context ])) {
484
+        if ( ! isset($contexts[$context])) {
485 485
             throw new InvalidIdentifierException(
486 486
                 '',
487 487
                 '',
Please login to merge, or discard this patch.
core/libraries/messages/EE_Messages_Generator.lib.php 3 patches
Doc Comments   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -459,7 +459,7 @@  discard block
 block discarded – undo
459 459
      * there's a single shared message template group among all the events.  Otherwise it returns null.
460 460
      *
461 461
      * @param array $event_ids
462
-     * @return EE_Message_Template_Group|null
462
+     * @return null|EE_Base_Class
463 463
      * @throws EE_Error
464 464
      * @throws InvalidArgumentException
465 465
      * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
@@ -495,7 +495,7 @@  discard block
 block discarded – undo
495 495
     /**
496 496
      * Retrieves the global message template group for the current messenger and message type.
497 497
      *
498
-     * @return EE_Message_Template_Group|null
498
+     * @return null|EE_Base_Class
499 499
      * @throws EE_Error
500 500
      * @throws InvalidArgumentException
501 501
      * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
@@ -641,7 +641,7 @@  discard block
 block discarded – undo
641 641
      * @param EE_Messages_Addressee     $recipient
642 642
      * @param array                     $templates formatted array of templates used for parsing data.
643 643
      * @param EE_Message_Template_Group $message_template_group
644
-     * @return bool|EE_Message
644
+     * @return EE_Message
645 645
      * @throws EE_Error
646 646
      */
647 647
     protected function _setup_message_object(
Please login to merge, or discard this patch.
Indentation   +969 added lines, -969 removed lines patch added patch discarded remove patch
@@ -12,973 +12,973 @@
 block discarded – undo
12 12
 {
13 13
 
14 14
 
15
-    /**
16
-     * @type EE_Messages_Data_Handler_Collection
17
-     */
18
-    protected $_data_handler_collection;
19
-
20
-    /**
21
-     * @type  EE_Message_Template_Group_Collection
22
-     */
23
-    protected $_template_collection;
24
-
25
-    /**
26
-     * This will hold the data handler for the current EE_Message being generated.
27
-     *
28
-     * @type EE_Messages_incoming_data
29
-     */
30
-    protected $_current_data_handler;
31
-
32
-    /**
33
-     * This holds the EE_Messages_Queue that contains the messages to generate.
34
-     *
35
-     * @type EE_Messages_Queue
36
-     */
37
-    protected $_generation_queue;
38
-
39
-    /**
40
-     * This holds the EE_Messages_Queue that will store the generated EE_Message objects.
41
-     *
42
-     * @type EE_Messages_Queue
43
-     */
44
-    protected $_ready_queue;
45
-
46
-    /**
47
-     * This is a container for any error messages that get created through the generation
48
-     * process.
49
-     *
50
-     * @type array
51
-     */
52
-    protected $_error_msg = array();
53
-
54
-    /**
55
-     * Flag used to set when the current EE_Message in the generation queue has been verified.
56
-     *
57
-     * @type bool
58
-     */
59
-    protected $_verified = false;
60
-
61
-    /**
62
-     * This will hold the current messenger object corresponding with the current EE_Message in the generation queue.
63
-     *
64
-     * @type EE_messenger
65
-     */
66
-    protected $_current_messenger;
67
-
68
-    /**
69
-     * This will hold the current message type object corresponding with the current EE_Message in the generation queue.
70
-     *
71
-     * @type EE_message_type
72
-     */
73
-    protected $_current_message_type;
74
-
75
-    /**
76
-     * @type EEH_Parse_Shortcodes
77
-     */
78
-    protected $_shortcode_parser;
79
-
80
-
81
-    /**
82
-     * @param EE_Messages_Queue                     $generation_queue
83
-     * @param \EE_Messages_Queue                    $ready_queue
84
-     * @param \EE_Messages_Data_Handler_Collection  $data_handler_collection
85
-     * @param \EE_Message_Template_Group_Collection $template_collection
86
-     * @param \EEH_Parse_Shortcodes                 $shortcode_parser
87
-     */
88
-    public function __construct(
89
-        EE_Messages_Queue $generation_queue,
90
-        EE_Messages_Queue $ready_queue,
91
-        EE_Messages_Data_Handler_Collection $data_handler_collection,
92
-        EE_Message_Template_Group_Collection $template_collection,
93
-        EEH_Parse_Shortcodes $shortcode_parser
94
-    ) {
95
-        $this->_generation_queue        = $generation_queue;
96
-        $this->_ready_queue             = $ready_queue;
97
-        $this->_data_handler_collection = $data_handler_collection;
98
-        $this->_template_collection     = $template_collection;
99
-        $this->_shortcode_parser        = $shortcode_parser;
100
-    }
101
-
102
-
103
-    /**
104
-     * @return EE_Messages_Queue
105
-     */
106
-    public function generation_queue()
107
-    {
108
-        return $this->_generation_queue;
109
-    }
110
-
111
-
112
-    /**
113
-     *  This iterates through the provided queue and generates the EE_Message objects.
114
-     *  When iterating through the queue, the queued item that served as the base for generating other EE_Message
115
-     *  objects gets removed and the new EE_Message objects get added to a NEW queue.  The NEW queue is then returned
116
-     *  for the caller to decide what to do with it.
117
-     *
118
-     * @param   bool $save Whether to save the EE_Message objects in the new queue or just return.
119
-     * @return EE_Messages_Queue The new queue for holding generated EE_Message objects.
120
-     * @throws EE_Error
121
-     * @throws ReflectionException
122
-     */
123
-    public function generate($save = true)
124
-    {
125
-        // iterate through the messages in the queue, generate, and add to new queue.
126
-        $this->_generation_queue->get_message_repository()->rewind();
127
-        while ($this->_generation_queue->get_message_repository()->valid()) {
128
-            // reset "current" properties
129
-            $this->_reset_current_properties();
130
-
131
-            /** @type EE_Message $msg */
132
-            $msg = $this->_generation_queue->get_message_repository()->current();
133
-
134
-            /**
135
-             * need to get the next object and capture it for setting manually after deletes.  The reason is that when
136
-             * an object is removed from the repo then valid for the next object will fail.
137
-             */
138
-            $this->_generation_queue->get_message_repository()->next();
139
-            $next_msg = $this->_generation_queue->get_message_repository()->current();
140
-            // restore pointer to current item
141
-            $this->_generation_queue->get_message_repository()->set_current($msg);
142
-
143
-            // skip and delete if the current $msg is NOT incomplete (queued for generation)
144
-            if ($msg->STS_ID() !== EEM_Message::status_incomplete) {
145
-                // we keep this item in the db just remove from the repo.
146
-                $this->_generation_queue->get_message_repository()->remove($msg);
147
-                // next item
148
-                $this->_generation_queue->get_message_repository()->set_current($next_msg);
149
-                continue;
150
-            }
151
-
152
-            if ($this->_verify()) {
153
-                // let's get generating!
154
-                $this->_generate();
155
-            }
156
-
157
-            // don't persist debug_only messages if the messages system is not in debug mode.
158
-            if ($msg->STS_ID() === EEM_Message::status_debug_only
159
-                && ! EEM_Message::debug()
160
-            ) {
161
-                do_action(
162
-                    'AHEE__EE_Messages_Generator__generate__before_debug_delete',
163
-                    $msg,
164
-                    $this->_error_msg,
165
-                    $this->_current_messenger,
166
-                    $this->_current_message_type,
167
-                    $this->_current_data_handler
168
-                );
169
-                $this->_generation_queue->get_message_repository()->delete();
170
-                $this->_generation_queue->get_message_repository()->set_current($next_msg);
171
-                continue;
172
-            }
173
-
174
-            // if there are error messages then let's set the status and the error message.
175
-            if ($this->_error_msg) {
176
-                // if the status is already debug only, then let's leave it at that.
177
-                if ($msg->STS_ID() !== EEM_Message::status_debug_only) {
178
-                    $msg->set_STS_ID(EEM_Message::status_failed);
179
-                }
180
-                do_action(
181
-                    'AHEE__EE_Messages_Generator__generate__processing_failed_message',
182
-                    $msg,
183
-                    $this->_error_msg,
184
-                    $this->_current_messenger,
185
-                    $this->_current_message_type,
186
-                    $this->_current_data_handler
187
-                );
188
-                $msg->set_error_message(
189
-                    esc_html__('Message failed to generate for the following reasons: ', 'event_espresso')
190
-                    . "\n"
191
-                    . implode("\n", $this->_error_msg)
192
-                );
193
-                $msg->set_modified(time());
194
-            } else {
195
-                do_action(
196
-                    'AHEE__EE_Messages_Generator__generate__before_successful_generated_message_delete',
197
-                    $msg,
198
-                    $this->_error_msg,
199
-                    $this->_current_messenger,
200
-                    $this->_current_message_type,
201
-                    $this->_current_data_handler
202
-                );
203
-                // remove from db
204
-                $this->_generation_queue->get_message_repository()->delete();
205
-            }
206
-            // next item
207
-            $this->_generation_queue->get_message_repository()->set_current($next_msg);
208
-        }
209
-
210
-        // generation queue is ALWAYS saved to record any errors in the generation process.
211
-        $this->_generation_queue->save();
212
-
213
-        /**
214
-         * save _ready_queue if flag set.
215
-         * Note: The EE_Message objects have values set via the EE_Base_Class::set_field_or_extra_meta() method.  This
216
-         * means if a field was added that is not a valid database column.  The EE_Message was already saved to the db
217
-         * so a EE_Extra_Meta entry could be created and attached to the EE_Message.  In those cases the save flag is
218
-         * irrelevant.
219
-         */
220
-        if ($save) {
221
-            $this->_ready_queue->save();
222
-        }
223
-
224
-        // final reset of properties
225
-        $this->_reset_current_properties();
226
-
227
-        return $this->_ready_queue;
228
-    }
229
-
230
-
231
-    /**
232
-     * This resets all the properties used for holding "current" values corresponding to the current EE_Message object
233
-     * in the generation queue.
234
-     */
235
-    protected function _reset_current_properties()
236
-    {
237
-        $this->_verified = false;
238
-        // make sure any _data value in the current message type is reset
239
-        if ($this->_current_message_type instanceof EE_message_type) {
240
-            $this->_current_message_type->reset_data();
241
-        }
242
-        $this->_current_messenger = $this->_current_message_type = $this->_current_data_handler = null;
243
-    }
244
-
245
-
246
-    /**
247
-     * This proceeds with the actual generation of a message.  By the time this is called, there should already be a
248
-     * $_current_data_handler set and all incoming information should be validated for the current EE_Message in the
249
-     * _generating_queue.
250
-     *
251
-     * @return bool Whether the message was successfully generated or not.
252
-     * @throws EE_Error
253
-     * @throws InvalidArgumentException
254
-     * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
255
-     * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
256
-     */
257
-    protected function _generate()
258
-    {
259
-        // double check verification has run and that everything is ready to work with (saves us having to validate
260
-        // everything again).
261
-        if (! $this->_verified) {
262
-            return false; // get out because we don't have a valid setup to work with.
263
-        }
264
-
265
-
266
-        try {
267
-            $addressees = $this->_current_message_type->get_addressees(
268
-                $this->_current_data_handler,
269
-                $this->_generation_queue->get_message_repository()->current()->context()
270
-            );
271
-        } catch (EE_Error $e) {
272
-            $this->_error_msg[] = $e->getMessage();
273
-            return false;
274
-        }
275
-
276
-
277
-        // if no addressees then get out because there is nothing to generation (possible bad data).
278
-        if (! $this->_valid_addressees($addressees)) {
279
-            do_action(
280
-                'AHEE__EE_Messages_Generator___generate__invalid_addressees',
281
-                $this->_generation_queue->get_message_repository()->current(),
282
-                $addressees,
283
-                $this->_current_messenger,
284
-                $this->_current_message_type,
285
-                $this->_current_data_handler
286
-            );
287
-            $this->_generation_queue->get_message_repository()->current()->set_STS_ID(
288
-                EEM_Message::status_debug_only
289
-            );
290
-            $this->_error_msg[] = esc_html__(
291
-                'This is not a critical error but an informational notice. Unable to generate messages EE_Messages_Addressee objects.  There were no attendees prepared by the data handler. Sometimes this is because messages only get generated for certain registration statuses. For example, the ticket notice message type only goes to approved registrations.',
292
-                'event_espresso'
293
-            );
294
-            return false;
295
-        }
296
-
297
-        $message_template_group = $this->_get_message_template_group();
298
-
299
-        // in the unlikely event there is no EE_Message_Template_Group available, get out!
300
-        if (! $message_template_group instanceof EE_Message_Template_Group) {
301
-            $this->_error_msg[] = esc_html__(
302
-                'Unable to get the Message Templates for the Message being generated.  No message template group accessible.',
303
-                'event_espresso'
304
-            );
305
-            return false;
306
-        }
307
-
308
-        // get formatted templates for using to parse and setup EE_Message objects.
309
-        $templates = $this->_get_templates($message_template_group);
310
-
311
-
312
-        // setup new EE_Message objects (and add to _ready_queue)
313
-        return $this->_assemble_messages($addressees, $templates, $message_template_group);
314
-    }
315
-
316
-
317
-    /**
318
-     * Retrieves the message template group being used for generating messages.
319
-     * Note: this also utilizes the EE_Message_Template_Group_Collection to avoid having to hit the db multiple times.
320
-     *
321
-     * @return EE_Message_Template_Group|null
322
-     * @throws EE_Error
323
-     * @throws InvalidArgumentException
324
-     * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
325
-     * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
326
-     */
327
-    protected function _get_message_template_group()
328
-    {
329
-        // first see if there is a specific message template group requested (current message in the queue has a specific
330
-        // GRP_ID
331
-        $message_template_group = $this->_specific_message_template_group_from_queue();
332
-        if ($message_template_group instanceof EE_Message_Template_Group) {
333
-            return $message_template_group;
334
-        }
335
-
336
-        // get event_ids from the datahandler so we can check to see if there's already a message template group for them
337
-        // in the collection.
338
-        $event_ids              = $this->_get_event_ids_from_current_data_handler();
339
-        $message_template_group = $this->_template_collection->get_by_key(
340
-            $this->_template_collection->getKey(
341
-                $this->_current_messenger->name,
342
-                $this->_current_message_type->name,
343
-                $event_ids
344
-            )
345
-        );
346
-
347
-        // if we have a message template group then no need to hit the database, just return it.
348
-        if ($message_template_group instanceof EE_Message_Template_Group) {
349
-            return $message_template_group;
350
-        }
351
-
352
-        // okay made it here, so let's get the global group first for this messenger and message type to ensure
353
-        // there is no override set.
354
-        $global_message_template_group =
355
-            $this->_get_global_message_template_group_for_current_messenger_and_message_type();
356
-
357
-        if ($global_message_template_group instanceof EE_Message_Template_Group
358
-            && $global_message_template_group->get('MTP_is_override')
359
-        ) {
360
-            return $global_message_template_group;
361
-        }
362
-
363
-        // if we're still here, that means there was no message template group for the events in the collection and
364
-        // the global message template group for the messenger and message type is not set for override.  So next step is
365
-        // to see if there is a common shared custom message template group for this set of events.
366
-        $message_template_group = $this->_get_shared_message_template_for_events($event_ids);
367
-        if ($message_template_group instanceof EE_Message_Template_Group) {
368
-            return $message_template_group;
369
-        }
370
-
371
-        // STILL here?  Okay that means the fallback is to just use the global message template group for this event set.
372
-        // So we'll cache the global group for this event set (so this logic doesn't have to be repeated in this request)
373
-        // and return it.
374
-        if ($global_message_template_group instanceof EE_Message_Template_Group) {
375
-            $this->_template_collection->add(
376
-                $global_message_template_group,
377
-                $event_ids
378
-            );
379
-            return $global_message_template_group;
380
-        }
381
-
382
-        // if we land here that means there's NO active message template group for this set.
383
-        // TODO this will be a good target for some optimization down the road.  Whenever there is no active message
384
-        // template group for a given event set then cache that result so we don't repeat the logic.  However, for now,
385
-        // this should likely bit hit rarely enough that it's not a significant issue.
386
-        return null;
387
-    }
388
-
389
-
390
-    /**
391
-     * This checks the current message in the queue and determines if there is a specific Message Template Group
392
-     * requested for that message.
393
-     *
394
-     * @return EE_Message_Template_Group|null
395
-     * @throws EE_Error
396
-     * @throws InvalidArgumentException
397
-     * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
398
-     * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
399
-     */
400
-    protected function _specific_message_template_group_from_queue()
401
-    {
402
-        // is there a GRP_ID already on the EE_Message object?  If there is, then a specific template has been requested
403
-        // so let's use that.
404
-        $GRP_ID = $this->_generation_queue->get_message_repository()->current()->GRP_ID();
405
-
406
-        if ($GRP_ID) {
407
-            // attempt to retrieve from repo first
408
-            $message_template_group = $this->_template_collection->get_by_ID($GRP_ID);
409
-            if ($message_template_group instanceof EE_Message_Template_Group) {
410
-                return $message_template_group;  // got it!
411
-            }
412
-
413
-            // nope don't have it yet.  Get from DB then add to repo if its not here, then that means the current GRP_ID
414
-            // is not valid, so we'll continue on in the code assuming there's NO GRP_ID.
415
-            $message_template_group = EEM_Message_Template_Group::instance()->get_one_by_ID($GRP_ID);
416
-            if ($message_template_group instanceof EE_Message_Template_Group) {
417
-                $this->_template_collection->add($message_template_group);
418
-                return $message_template_group;
419
-            }
420
-        }
421
-        return null;
422
-    }
423
-
424
-
425
-    /**
426
-     * Returns whether the event ids passed in all share the same message template group for the current message type
427
-     * and messenger.
428
-     *
429
-     * @param array $event_ids
430
-     * @return bool true means they DO share the same message template group, false means they don't.
431
-     * @throws EE_Error
432
-     * @throws InvalidArgumentException
433
-     * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
434
-     * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
435
-     */
436
-    protected function _queue_shares_same_message_template_group_for_events(array $event_ids)
437
-    {
438
-        foreach ($this->_current_data_handler->events as $event) {
439
-            $event_ids[ $event['ID'] ] = $event['ID'];
440
-        }
441
-        $count_of_message_template_groups = EEM_Message_Template_Group::instance()->count(
442
-            array(
443
-                array(
444
-                    'Event.EVT_ID'           => array('IN', $event_ids),
445
-                    'MTP_messenger'    => $this->_current_messenger->name,
446
-                    'MTP_message_type' => $this->_current_message_type->name,
447
-                ),
448
-            ),
449
-            'GRP_ID',
450
-            true
451
-        );
452
-        return $count_of_message_template_groups === 1;
453
-    }
454
-
455
-
456
-    /**
457
-     * This will get the shared message template group for events that are in the current data handler but ONLY if
458
-     * there's a single shared message template group among all the events.  Otherwise it returns null.
459
-     *
460
-     * @param array $event_ids
461
-     * @return EE_Message_Template_Group|null
462
-     * @throws EE_Error
463
-     * @throws InvalidArgumentException
464
-     * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
465
-     * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
466
-     */
467
-    protected function _get_shared_message_template_for_events(array $event_ids)
468
-    {
469
-        $message_template_group = null;
470
-        if ($this->_queue_shares_same_message_template_group_for_events($event_ids)) {
471
-            $message_template_group = EEM_Message_Template_Group::instance()->get_one(
472
-                array(
473
-                    array(
474
-                        'Event.EVT_ID'           => array('IN', $event_ids),
475
-                        'MTP_messenger'    => $this->_current_messenger->name,
476
-                        'MTP_message_type' => $this->_current_message_type->name,
477
-                        'MTP_is_active'    => true,
478
-                    ),
479
-                    'group_by' => 'GRP_ID',
480
-                )
481
-            );
482
-            // store this in the collection if its valid
483
-            if ($message_template_group instanceof EE_Message_Template_Group) {
484
-                $this->_template_collection->add(
485
-                    $message_template_group,
486
-                    $event_ids
487
-                );
488
-            }
489
-        }
490
-        return $message_template_group;
491
-    }
492
-
493
-
494
-    /**
495
-     * Retrieves the global message template group for the current messenger and message type.
496
-     *
497
-     * @return EE_Message_Template_Group|null
498
-     * @throws EE_Error
499
-     * @throws InvalidArgumentException
500
-     * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
501
-     * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
502
-     */
503
-    protected function _get_global_message_template_group_for_current_messenger_and_message_type()
504
-    {
505
-        // first check the collection (we use an array with 0 in it to represent global groups).
506
-        $global_message_template_group = $this->_template_collection->get_by_key(
507
-            $this->_template_collection->getKey(
508
-                $this->_current_messenger->name,
509
-                $this->_current_message_type->name,
510
-                array(0)
511
-            )
512
-        );
513
-
514
-        // if we don't have a group lets hit the db.
515
-        if (! $global_message_template_group instanceof EE_Message_Template_Group) {
516
-            $global_message_template_group = EEM_Message_Template_Group::instance()->get_one(
517
-                array(
518
-                    array(
519
-                        'MTP_messenger'    => $this->_current_messenger->name,
520
-                        'MTP_message_type' => $this->_current_message_type->name,
521
-                        'MTP_is_active'    => true,
522
-                        'MTP_is_global'    => true,
523
-                    ),
524
-                )
525
-            );
526
-            // if we have a group, add it to the collection.
527
-            if ($global_message_template_group instanceof EE_Message_Template_Group) {
528
-                $this->_template_collection->add(
529
-                    $global_message_template_group,
530
-                    array(0)
531
-                );
532
-            }
533
-        }
534
-        return $global_message_template_group;
535
-    }
536
-
537
-
538
-    /**
539
-     * Returns an array of event ids for all the events within the current data handler.
540
-     *
541
-     * @return array
542
-     */
543
-    protected function _get_event_ids_from_current_data_handler()
544
-    {
545
-        $event_ids = array();
546
-        foreach ($this->_current_data_handler->events as $event) {
547
-            $event_ids[ $event['ID'] ] = $event['ID'];
548
-        }
549
-        return $event_ids;
550
-    }
551
-
552
-
553
-    /**
554
-     *  Retrieves formatted array of template information for each context specific to the given
555
-     *  EE_Message_Template_Group
556
-     *
557
-     * @param EE_Message_Template_Group $message_template_group
558
-     * @return array The returned array is in this structure:
559
-     *                          array(
560
-     *                          'field_name' => array(
561
-     *                          'context' => 'content'
562
-     *                          )
563
-     *                          )
564
-     * @throws EE_Error
565
-     */
566
-    protected function _get_templates(EE_Message_Template_Group $message_template_group)
567
-    {
568
-        $templates         = array();
569
-        $context_templates = $message_template_group->context_templates();
570
-        foreach ($context_templates as $context => $template_fields) {
571
-            foreach ($template_fields as $template_field => $template_obj) {
572
-                if (! $template_obj instanceof EE_Message_Template) {
573
-                    continue;
574
-                }
575
-                $templates[ $template_field ][ $context ] = $template_obj->get('MTP_content');
576
-            }
577
-        }
578
-        return $templates;
579
-    }
580
-
581
-
582
-    /**
583
-     * Assembles new fully generated EE_Message objects and adds to _ready_queue
584
-     *
585
-     * @param array                     $addressees  Array of EE_Messages_Addressee objects indexed by message type
586
-     *                                               context.
587
-     * @param array                     $templates   formatted array of templates used for parsing data.
588
-     * @param EE_Message_Template_Group $message_template_group
589
-     * @return bool true if message generation went a-ok.  false if some sort of exception occurred.  Note: The
590
-     *                                               method will attempt to generate ALL EE_Message objects and add to
591
-     *                                               the _ready_queue.  Successfully generated messages get added to the
592
-     *                                               queue with EEM_Message::status_idle, unsuccessfully generated
593
-     *                                               messages will get added to the queue as EEM_Message::status_failed.
594
-     *                                               Very rarely should "false" be returned from this method.
595
-     * @throws EE_Error
596
-     */
597
-    protected function _assemble_messages($addressees, $templates, EE_Message_Template_Group $message_template_group)
598
-    {
599
-
600
-        // if templates are empty then get out because we can't generate anything.
601
-        if (! $templates) {
602
-            $this->_error_msg[] = esc_html__(
603
-                'Unable to assemble messages because there are no templates retrieved for generating the messages with',
604
-                'event_espresso'
605
-            );
606
-            return false;
607
-        }
608
-
609
-        // We use this as the counter for generated messages because don't forget we may be executing this inside of a
610
-        // generation_queue.  So _ready_queue may have generated EE_Message objects already.
611
-        $generated_count = 0;
612
-        foreach ($addressees as $context => $recipients) {
613
-            foreach ($recipients as $recipient) {
614
-                $message = $this->_setup_message_object($context, $recipient, $templates, $message_template_group);
615
-                if ($message instanceof EE_Message) {
616
-                    $this->_ready_queue->add(
617
-                        $message,
618
-                        array(),
619
-                        $this->_generation_queue->get_message_repository()->is_preview(),
620
-                        $this->_generation_queue->get_message_repository()->is_test_send()
621
-                    );
622
-                    $generated_count++;
623
-                }
624
-
625
-                // if the current MSG being generated is for a test send then we'll only use ONE message in the
626
-                // generation.
627
-                if ($this->_generation_queue->get_message_repository()->is_test_send()) {
628
-                    break 2;
629
-                }
630
-            }
631
-        }
632
-
633
-        // if there are no generated messages then something else fatal went wrong.
634
-        return $generated_count > 0;
635
-    }
636
-
637
-
638
-    /**
639
-     * @param string                    $context   The context for the generated message.
640
-     * @param EE_Messages_Addressee     $recipient
641
-     * @param array                     $templates formatted array of templates used for parsing data.
642
-     * @param EE_Message_Template_Group $message_template_group
643
-     * @return bool|EE_Message
644
-     * @throws EE_Error
645
-     */
646
-    protected function _setup_message_object(
647
-        $context,
648
-        EE_Messages_Addressee $recipient,
649
-        $templates,
650
-        EE_Message_Template_Group $message_template_group
651
-    ) {
652
-        // stuff we already know
653
-        $transaction_id = $recipient->txn instanceof EE_Transaction ? $recipient->txn->ID() : 0;
654
-        $transaction_id = empty($transaction_id) && $this->_current_data_handler->txn instanceof EE_Transaction
655
-            ? $this->_current_data_handler->txn->ID()
656
-            : $transaction_id;
657
-        $message_fields = array(
658
-            'GRP_ID'           => $message_template_group->ID(),
659
-            'TXN_ID'           => $transaction_id,
660
-            'MSG_messenger'    => $this->_current_messenger->name,
661
-            'MSG_message_type' => $this->_current_message_type->name,
662
-            'MSG_context'      => $context,
663
-        );
664
-
665
-        // recipient id and type should be on the EE_Messages_Addressee object but if this is empty, let's try to grab
666
-        // the info from the att_obj found in the EE_Messages_Addressee object.
667
-        if (empty($recipient->recipient_id) || empty($recipient->recipient_type)) {
668
-            $message_fields['MSG_recipient_ID']   = $recipient->att_obj instanceof EE_Attendee
669
-                ? $recipient->att_obj->ID()
670
-                : 0;
671
-            $message_fields['MSG_recipient_type'] = 'Attendee';
672
-        } else {
673
-            $message_fields['MSG_recipient_ID']   = $recipient->recipient_id;
674
-            $message_fields['MSG_recipient_type'] = $recipient->recipient_type;
675
-        }
676
-        $message = EE_Message_Factory::create($message_fields);
677
-
678
-        // grab valid shortcodes for shortcode parser
679
-        $mt_shortcodes = $this->_current_message_type->get_valid_shortcodes();
680
-        $m_shortcodes  = $this->_current_messenger->get_valid_shortcodes();
681
-
682
-        // if the 'to' field is empty or the context is inactive we skip EXCEPT if we're previewing
683
-        if ((
684
-                (
685
-                    empty($templates['to'][ $context ])
686
-                    && ! $this->_current_messenger->allow_empty_to_field()
687
-                )
688
-                || ! $message_template_group->is_context_active($context)
689
-            )
690
-            && ! $this->_generation_queue->get_message_repository()->is_preview()
691
-        ) {
692
-            // we silently exit here and do NOT record a fail because the message is "turned off" by having no "to"
693
-            // field.
694
-            return false;
695
-        }
696
-        $error_msg = array();
697
-        foreach ($templates as $field => $field_context) {
698
-            $error_msg = array();
699
-            // let's setup the valid shortcodes for the incoming context.
700
-            $valid_shortcodes = $mt_shortcodes[ $context ];
701
-            // merge in valid shortcodes for the field.
702
-            $shortcodes = isset($m_shortcodes[ $field ]) ? $m_shortcodes[ $field ] : $valid_shortcodes;
703
-            if (isset($templates[ $field ][ $context ])) {
704
-                // prefix field.
705
-                $column_name = 'MSG_' . $field;
706
-                try {
707
-                    $content = $this->_shortcode_parser->parse_message_template(
708
-                        $templates[ $field ][ $context ],
709
-                        $recipient,
710
-                        $shortcodes,
711
-                        $this->_current_message_type,
712
-                        $this->_current_messenger,
713
-                        $message
714
-                    );
715
-                    // the model field removes slashes when setting (usually necessary when the input is from the
716
-                    // request) but this value is from another model and has no slashes. So add them so it matchces
717
-                    // what the field expected (otherwise slashes will have been stripped from this an extra time)
718
-                    $message->set_field_or_extra_meta($column_name, addslashes($content));
719
-                } catch (EE_Error $e) {
720
-                    $error_msg[] = sprintf(
721
-                        esc_html__(
722
-                            'There was a problem generating the content for the field %s: %s',
723
-                            'event_espresso'
724
-                        ),
725
-                        $field,
726
-                        $e->getMessage()
727
-                    );
728
-                    $message->set_STS_ID(EEM_Message::status_failed);
729
-                }
730
-            }
731
-        }
732
-
733
-        if ($message->STS_ID() === EEM_Message::status_failed) {
734
-            $error_msg = esc_html__('There were problems generating this message:', 'event_espresso')
735
-                         . "\n"
736
-                         . implode("\n", $error_msg);
737
-            $message->set_error_message($error_msg);
738
-        } else {
739
-            $message->set_STS_ID(EEM_Message::status_idle);
740
-        }
741
-        return $message;
742
-    }
743
-
744
-
745
-    /**
746
-     * This verifies that the incoming array has a EE_messenger object and a EE_message_type object and sets appropriate
747
-     * error message if either is missing.
748
-     *
749
-     * @return bool true means there were no errors, false means there were errors.
750
-     * @throws EE_Error
751
-     * @throws ReflectionException
752
-     */
753
-    protected function _verify()
754
-    {
755
-        // reset error message to an empty array.
756
-        $this->_error_msg = array();
757
-        $valid            = true;
758
-        $valid            = $valid ? $this->_validate_messenger_and_message_type() : $valid;
759
-        $valid            = $valid ? $this->_validate_and_setup_data() : $valid;
760
-
761
-        // set the verified flag so we know everything has been validated.
762
-        $this->_verified = $valid;
763
-
764
-        return $valid;
765
-    }
766
-
767
-
768
-    /**
769
-     * This accepts an array and validates that it is an array indexed by context with each value being an array of
770
-     * EE_Messages_Addressee objects.
771
-     *
772
-     * @param array $addressees Keys correspond to contexts for the message type and values are EE_Messages_Addressee[]
773
-     * @return bool
774
-     */
775
-    protected function _valid_addressees($addressees)
776
-    {
777
-        if (! $addressees || ! is_array($addressees)) {
778
-            return false;
779
-        }
780
-
781
-        foreach ($addressees as $addressee_array) {
782
-            foreach ($addressee_array as $addressee) {
783
-                if (! $addressee instanceof EE_Messages_Addressee) {
784
-                    return false;
785
-                }
786
-            }
787
-        }
788
-        return true;
789
-    }
790
-
791
-
792
-    /**
793
-     * This validates the messenger, message type, and presences of generation data for the current EE_Message in the
794
-     * queue. This process sets error messages if something is wrong.
795
-     *
796
-     * @return bool   true is if there are no errors.  false is if there is.
797
-     */
798
-    protected function _validate_messenger_and_message_type()
799
-    {
800
-
801
-        // first are there any existing error messages?  If so then return.
802
-        if ($this->_error_msg) {
803
-            return false;
804
-        }
805
-        /** @type EE_Message $message */
806
-        $message = $this->_generation_queue->get_message_repository()->current();
807
-        try {
808
-            $this->_current_messenger = $message->valid_messenger(true)
809
-                ? $message->messenger_object()
810
-                : null;
811
-        } catch (Exception $e) {
812
-            $this->_error_msg[] = $e->getMessage();
813
-        }
814
-        try {
815
-            $this->_current_message_type = $message->valid_message_type(true)
816
-                ? $message->message_type_object()
817
-                : null;
818
-        } catch (Exception $e) {
819
-            $this->_error_msg[] = $e->getMessage();
820
-        }
821
-
822
-        /**
823
-         * Check if there is any generation data, but only if this is not for a preview.
824
-         */
825
-        if (! $this->_generation_queue->get_message_repository()->get_generation_data()
826
-            && (
827
-                ! $this->_generation_queue->get_message_repository()->is_preview()
828
-                && $this->_generation_queue->get_message_repository()->get_data_handler()
829
-                   !== 'EE_Messages_Preview_incoming_data'
830
-            )
831
-        ) {
832
-            $this->_error_msg[] = esc_html__(
833
-                'There is no generation data for this message. Unable to generate.',
834
-                'event_espresso'
835
-            );
836
-        }
837
-
838
-        return empty($this->_error_msg);
839
-    }
840
-
841
-
842
-    /**
843
-     * This method retrieves the expected data handler for the message type and validates the generation data for that
844
-     * data handler.
845
-     *
846
-     * @return bool true means there are no errors.  false means there were errors (and handler did not get setup).
847
-     * @throws EE_Error
848
-     * @throws ReflectionException
849
-     */
850
-    protected function _validate_and_setup_data()
851
-    {
852
-
853
-        // First, are there any existing error messages?  If so, return because if there were errors elsewhere this can't
854
-        // be used anyways.
855
-        if ($this->_error_msg) {
856
-            return false;
857
-        }
858
-
859
-        $generation_data = $this->_generation_queue->get_message_repository()->get_generation_data();
860
-
861
-        /** @type EE_Messages_incoming_data $data_handler_class_name - well not really... just the class name actually*/
862
-        $data_handler_class_name = $this->_generation_queue->get_message_repository()->get_data_handler()
863
-            ? $this->_generation_queue->get_message_repository()->get_data_handler()
864
-            : 'EE_Messages_' . $this->_current_message_type->get_data_handler($generation_data) . '_incoming_data';
865
-
866
-        // If this EE_Message is for a preview, then let's switch out to the preview data handler.
867
-        if ($this->_generation_queue->get_message_repository()->is_preview()) {
868
-            $data_handler_class_name = 'EE_Messages_Preview_incoming_data';
869
-        }
870
-
871
-        // First get the class name for the data handler (and also verifies it exists.
872
-        if (! class_exists($data_handler_class_name)) {
873
-            $this->_error_msg[] = sprintf(
874
-                esc_html__(
875
-                    'The included data handler class name does not match any valid, accessible, "%1$s" classes.  Looking for %2$s.',
876
-                    'event_espresso'
877
-                ),
878
-                'EE_Messages_incoming_data',
879
-                $data_handler_class_name
880
-            );
881
-            return false;
882
-        }
883
-
884
-        // convert generation_data for data_handler_instantiation.
885
-        $generation_data = $data_handler_class_name::convert_data_from_persistent_storage($generation_data);
886
-
887
-        // note, this may set error messages as well.
888
-        $this->_set_data_handler($generation_data, $data_handler_class_name);
889
-
890
-        return empty($this->_error_msg);
891
-    }
892
-
893
-
894
-    /**
895
-     * Sets the $_current_data_handler property that is used for generating the current EE_Message in the queue, and
896
-     * adds it to the _data repository.
897
-     *
898
-     * @param mixed  $generating_data           This is data expected by the instantiated data handler.
899
-     * @param string $data_handler_class_name   This is the reference string indicating what data handler is being
900
-     *                                          instantiated.
901
-     * @return void .
902
-     * @throws EE_Error
903
-     * @throws ReflectionException
904
-     */
905
-    protected function _set_data_handler($generating_data, $data_handler_class_name)
906
-    {
907
-        // valid classname for the data handler.  Now let's setup the key for the data handler repository to see if there
908
-        // is already a ready data handler in the repository.
909
-        $this->_current_data_handler = $this->_data_handler_collection->get_by_key(
910
-            $this->_data_handler_collection->get_key(
911
-                $data_handler_class_name,
912
-                $generating_data
913
-            )
914
-        );
915
-        if (! $this->_current_data_handler instanceof EE_Messages_incoming_data) {
916
-            // no saved data_handler in the repo so let's set one up and add it to the repo.
917
-            try {
918
-                $this->_current_data_handler = new $data_handler_class_name($generating_data);
919
-                $this->_data_handler_collection->add($this->_current_data_handler, $generating_data);
920
-            } catch (EE_Error $e) {
921
-                $this->_error_msg[] = $e->get_error();
922
-            }
923
-        }
924
-    }
925
-
926
-
927
-    /**
928
-     * The queued EE_Message for generation does not save the data used for generation as objects
929
-     * because serialization of those objects could be problematic if the data is saved to the db.
930
-     * So this method calls the static method on the associated data_handler for the given message_type
931
-     * and that preps the data for later instantiation when generating.
932
-     *
933
-     * @param EE_Message_To_Generate $message_to_generate
934
-     * @param bool                   $preview Indicate whether this is being used for a preview or not.
935
-     * @return mixed Prepped data for persisting to the queue.  false is returned if unable to prep data.
936
-     */
937
-    protected function _prepare_data_for_queue(EE_Message_To_Generate $message_to_generate, $preview)
938
-    {
939
-        /** @type EE_Messages_incoming_data $data_handler - well not really... just the class name actually */
940
-        $data_handler = $message_to_generate->get_data_handler_class_name($preview);
941
-        if (! $message_to_generate->valid()) {
942
-            return false; // unable to get the data because the info in the EE_Message_To_Generate class is invalid.
943
-        }
944
-        return $data_handler::convert_data_for_persistent_storage($message_to_generate->data());
945
-    }
946
-
947
-
948
-    /**
949
-     * This sets up a EEM_Message::status_incomplete EE_Message object and adds it to the generation queue.
950
-     *
951
-     * @param EE_Message_To_Generate $message_to_generate
952
-     * @param bool                   $test_send Whether this is just a test send or not.  Typically used for previews.
953
-     * @throws InvalidArgumentException
954
-     * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
955
-     * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
956
-     */
957
-    public function create_and_add_message_to_queue(EE_Message_To_Generate $message_to_generate, $test_send = false)
958
-    {
959
-        // prep data
960
-        $data = $this->_prepare_data_for_queue($message_to_generate, $message_to_generate->preview());
961
-
962
-        $message = $message_to_generate->get_EE_Message();
963
-
964
-        // is there a GRP_ID in the request?
965
-        if ($GRP_ID = EE_Registry::instance()->REQ->get('GRP_ID')) {
966
-            $message->set_GRP_ID($GRP_ID);
967
-        }
968
-
969
-        if ($data === false) {
970
-            $message->set_STS_ID(EEM_Message::status_failed);
971
-            $message->set_error_message(
972
-                esc_html__(
973
-                    'Unable to prepare data for persistence to the database.',
974
-                    'event_espresso'
975
-                )
976
-            );
977
-        } else {
978
-            // make sure that the data handler is cached on the message as well
979
-            $data['data_handler_class_name'] = $message_to_generate->get_data_handler_class_name();
980
-        }
981
-
982
-        $this->_generation_queue->add($message, $data, $message_to_generate->preview(), $test_send);
983
-    }
15
+	/**
16
+	 * @type EE_Messages_Data_Handler_Collection
17
+	 */
18
+	protected $_data_handler_collection;
19
+
20
+	/**
21
+	 * @type  EE_Message_Template_Group_Collection
22
+	 */
23
+	protected $_template_collection;
24
+
25
+	/**
26
+	 * This will hold the data handler for the current EE_Message being generated.
27
+	 *
28
+	 * @type EE_Messages_incoming_data
29
+	 */
30
+	protected $_current_data_handler;
31
+
32
+	/**
33
+	 * This holds the EE_Messages_Queue that contains the messages to generate.
34
+	 *
35
+	 * @type EE_Messages_Queue
36
+	 */
37
+	protected $_generation_queue;
38
+
39
+	/**
40
+	 * This holds the EE_Messages_Queue that will store the generated EE_Message objects.
41
+	 *
42
+	 * @type EE_Messages_Queue
43
+	 */
44
+	protected $_ready_queue;
45
+
46
+	/**
47
+	 * This is a container for any error messages that get created through the generation
48
+	 * process.
49
+	 *
50
+	 * @type array
51
+	 */
52
+	protected $_error_msg = array();
53
+
54
+	/**
55
+	 * Flag used to set when the current EE_Message in the generation queue has been verified.
56
+	 *
57
+	 * @type bool
58
+	 */
59
+	protected $_verified = false;
60
+
61
+	/**
62
+	 * This will hold the current messenger object corresponding with the current EE_Message in the generation queue.
63
+	 *
64
+	 * @type EE_messenger
65
+	 */
66
+	protected $_current_messenger;
67
+
68
+	/**
69
+	 * This will hold the current message type object corresponding with the current EE_Message in the generation queue.
70
+	 *
71
+	 * @type EE_message_type
72
+	 */
73
+	protected $_current_message_type;
74
+
75
+	/**
76
+	 * @type EEH_Parse_Shortcodes
77
+	 */
78
+	protected $_shortcode_parser;
79
+
80
+
81
+	/**
82
+	 * @param EE_Messages_Queue                     $generation_queue
83
+	 * @param \EE_Messages_Queue                    $ready_queue
84
+	 * @param \EE_Messages_Data_Handler_Collection  $data_handler_collection
85
+	 * @param \EE_Message_Template_Group_Collection $template_collection
86
+	 * @param \EEH_Parse_Shortcodes                 $shortcode_parser
87
+	 */
88
+	public function __construct(
89
+		EE_Messages_Queue $generation_queue,
90
+		EE_Messages_Queue $ready_queue,
91
+		EE_Messages_Data_Handler_Collection $data_handler_collection,
92
+		EE_Message_Template_Group_Collection $template_collection,
93
+		EEH_Parse_Shortcodes $shortcode_parser
94
+	) {
95
+		$this->_generation_queue        = $generation_queue;
96
+		$this->_ready_queue             = $ready_queue;
97
+		$this->_data_handler_collection = $data_handler_collection;
98
+		$this->_template_collection     = $template_collection;
99
+		$this->_shortcode_parser        = $shortcode_parser;
100
+	}
101
+
102
+
103
+	/**
104
+	 * @return EE_Messages_Queue
105
+	 */
106
+	public function generation_queue()
107
+	{
108
+		return $this->_generation_queue;
109
+	}
110
+
111
+
112
+	/**
113
+	 *  This iterates through the provided queue and generates the EE_Message objects.
114
+	 *  When iterating through the queue, the queued item that served as the base for generating other EE_Message
115
+	 *  objects gets removed and the new EE_Message objects get added to a NEW queue.  The NEW queue is then returned
116
+	 *  for the caller to decide what to do with it.
117
+	 *
118
+	 * @param   bool $save Whether to save the EE_Message objects in the new queue or just return.
119
+	 * @return EE_Messages_Queue The new queue for holding generated EE_Message objects.
120
+	 * @throws EE_Error
121
+	 * @throws ReflectionException
122
+	 */
123
+	public function generate($save = true)
124
+	{
125
+		// iterate through the messages in the queue, generate, and add to new queue.
126
+		$this->_generation_queue->get_message_repository()->rewind();
127
+		while ($this->_generation_queue->get_message_repository()->valid()) {
128
+			// reset "current" properties
129
+			$this->_reset_current_properties();
130
+
131
+			/** @type EE_Message $msg */
132
+			$msg = $this->_generation_queue->get_message_repository()->current();
133
+
134
+			/**
135
+			 * need to get the next object and capture it for setting manually after deletes.  The reason is that when
136
+			 * an object is removed from the repo then valid for the next object will fail.
137
+			 */
138
+			$this->_generation_queue->get_message_repository()->next();
139
+			$next_msg = $this->_generation_queue->get_message_repository()->current();
140
+			// restore pointer to current item
141
+			$this->_generation_queue->get_message_repository()->set_current($msg);
142
+
143
+			// skip and delete if the current $msg is NOT incomplete (queued for generation)
144
+			if ($msg->STS_ID() !== EEM_Message::status_incomplete) {
145
+				// we keep this item in the db just remove from the repo.
146
+				$this->_generation_queue->get_message_repository()->remove($msg);
147
+				// next item
148
+				$this->_generation_queue->get_message_repository()->set_current($next_msg);
149
+				continue;
150
+			}
151
+
152
+			if ($this->_verify()) {
153
+				// let's get generating!
154
+				$this->_generate();
155
+			}
156
+
157
+			// don't persist debug_only messages if the messages system is not in debug mode.
158
+			if ($msg->STS_ID() === EEM_Message::status_debug_only
159
+				&& ! EEM_Message::debug()
160
+			) {
161
+				do_action(
162
+					'AHEE__EE_Messages_Generator__generate__before_debug_delete',
163
+					$msg,
164
+					$this->_error_msg,
165
+					$this->_current_messenger,
166
+					$this->_current_message_type,
167
+					$this->_current_data_handler
168
+				);
169
+				$this->_generation_queue->get_message_repository()->delete();
170
+				$this->_generation_queue->get_message_repository()->set_current($next_msg);
171
+				continue;
172
+			}
173
+
174
+			// if there are error messages then let's set the status and the error message.
175
+			if ($this->_error_msg) {
176
+				// if the status is already debug only, then let's leave it at that.
177
+				if ($msg->STS_ID() !== EEM_Message::status_debug_only) {
178
+					$msg->set_STS_ID(EEM_Message::status_failed);
179
+				}
180
+				do_action(
181
+					'AHEE__EE_Messages_Generator__generate__processing_failed_message',
182
+					$msg,
183
+					$this->_error_msg,
184
+					$this->_current_messenger,
185
+					$this->_current_message_type,
186
+					$this->_current_data_handler
187
+				);
188
+				$msg->set_error_message(
189
+					esc_html__('Message failed to generate for the following reasons: ', 'event_espresso')
190
+					. "\n"
191
+					. implode("\n", $this->_error_msg)
192
+				);
193
+				$msg->set_modified(time());
194
+			} else {
195
+				do_action(
196
+					'AHEE__EE_Messages_Generator__generate__before_successful_generated_message_delete',
197
+					$msg,
198
+					$this->_error_msg,
199
+					$this->_current_messenger,
200
+					$this->_current_message_type,
201
+					$this->_current_data_handler
202
+				);
203
+				// remove from db
204
+				$this->_generation_queue->get_message_repository()->delete();
205
+			}
206
+			// next item
207
+			$this->_generation_queue->get_message_repository()->set_current($next_msg);
208
+		}
209
+
210
+		// generation queue is ALWAYS saved to record any errors in the generation process.
211
+		$this->_generation_queue->save();
212
+
213
+		/**
214
+		 * save _ready_queue if flag set.
215
+		 * Note: The EE_Message objects have values set via the EE_Base_Class::set_field_or_extra_meta() method.  This
216
+		 * means if a field was added that is not a valid database column.  The EE_Message was already saved to the db
217
+		 * so a EE_Extra_Meta entry could be created and attached to the EE_Message.  In those cases the save flag is
218
+		 * irrelevant.
219
+		 */
220
+		if ($save) {
221
+			$this->_ready_queue->save();
222
+		}
223
+
224
+		// final reset of properties
225
+		$this->_reset_current_properties();
226
+
227
+		return $this->_ready_queue;
228
+	}
229
+
230
+
231
+	/**
232
+	 * This resets all the properties used for holding "current" values corresponding to the current EE_Message object
233
+	 * in the generation queue.
234
+	 */
235
+	protected function _reset_current_properties()
236
+	{
237
+		$this->_verified = false;
238
+		// make sure any _data value in the current message type is reset
239
+		if ($this->_current_message_type instanceof EE_message_type) {
240
+			$this->_current_message_type->reset_data();
241
+		}
242
+		$this->_current_messenger = $this->_current_message_type = $this->_current_data_handler = null;
243
+	}
244
+
245
+
246
+	/**
247
+	 * This proceeds with the actual generation of a message.  By the time this is called, there should already be a
248
+	 * $_current_data_handler set and all incoming information should be validated for the current EE_Message in the
249
+	 * _generating_queue.
250
+	 *
251
+	 * @return bool Whether the message was successfully generated or not.
252
+	 * @throws EE_Error
253
+	 * @throws InvalidArgumentException
254
+	 * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
255
+	 * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
256
+	 */
257
+	protected function _generate()
258
+	{
259
+		// double check verification has run and that everything is ready to work with (saves us having to validate
260
+		// everything again).
261
+		if (! $this->_verified) {
262
+			return false; // get out because we don't have a valid setup to work with.
263
+		}
264
+
265
+
266
+		try {
267
+			$addressees = $this->_current_message_type->get_addressees(
268
+				$this->_current_data_handler,
269
+				$this->_generation_queue->get_message_repository()->current()->context()
270
+			);
271
+		} catch (EE_Error $e) {
272
+			$this->_error_msg[] = $e->getMessage();
273
+			return false;
274
+		}
275
+
276
+
277
+		// if no addressees then get out because there is nothing to generation (possible bad data).
278
+		if (! $this->_valid_addressees($addressees)) {
279
+			do_action(
280
+				'AHEE__EE_Messages_Generator___generate__invalid_addressees',
281
+				$this->_generation_queue->get_message_repository()->current(),
282
+				$addressees,
283
+				$this->_current_messenger,
284
+				$this->_current_message_type,
285
+				$this->_current_data_handler
286
+			);
287
+			$this->_generation_queue->get_message_repository()->current()->set_STS_ID(
288
+				EEM_Message::status_debug_only
289
+			);
290
+			$this->_error_msg[] = esc_html__(
291
+				'This is not a critical error but an informational notice. Unable to generate messages EE_Messages_Addressee objects.  There were no attendees prepared by the data handler. Sometimes this is because messages only get generated for certain registration statuses. For example, the ticket notice message type only goes to approved registrations.',
292
+				'event_espresso'
293
+			);
294
+			return false;
295
+		}
296
+
297
+		$message_template_group = $this->_get_message_template_group();
298
+
299
+		// in the unlikely event there is no EE_Message_Template_Group available, get out!
300
+		if (! $message_template_group instanceof EE_Message_Template_Group) {
301
+			$this->_error_msg[] = esc_html__(
302
+				'Unable to get the Message Templates for the Message being generated.  No message template group accessible.',
303
+				'event_espresso'
304
+			);
305
+			return false;
306
+		}
307
+
308
+		// get formatted templates for using to parse and setup EE_Message objects.
309
+		$templates = $this->_get_templates($message_template_group);
310
+
311
+
312
+		// setup new EE_Message objects (and add to _ready_queue)
313
+		return $this->_assemble_messages($addressees, $templates, $message_template_group);
314
+	}
315
+
316
+
317
+	/**
318
+	 * Retrieves the message template group being used for generating messages.
319
+	 * Note: this also utilizes the EE_Message_Template_Group_Collection to avoid having to hit the db multiple times.
320
+	 *
321
+	 * @return EE_Message_Template_Group|null
322
+	 * @throws EE_Error
323
+	 * @throws InvalidArgumentException
324
+	 * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
325
+	 * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
326
+	 */
327
+	protected function _get_message_template_group()
328
+	{
329
+		// first see if there is a specific message template group requested (current message in the queue has a specific
330
+		// GRP_ID
331
+		$message_template_group = $this->_specific_message_template_group_from_queue();
332
+		if ($message_template_group instanceof EE_Message_Template_Group) {
333
+			return $message_template_group;
334
+		}
335
+
336
+		// get event_ids from the datahandler so we can check to see if there's already a message template group for them
337
+		// in the collection.
338
+		$event_ids              = $this->_get_event_ids_from_current_data_handler();
339
+		$message_template_group = $this->_template_collection->get_by_key(
340
+			$this->_template_collection->getKey(
341
+				$this->_current_messenger->name,
342
+				$this->_current_message_type->name,
343
+				$event_ids
344
+			)
345
+		);
346
+
347
+		// if we have a message template group then no need to hit the database, just return it.
348
+		if ($message_template_group instanceof EE_Message_Template_Group) {
349
+			return $message_template_group;
350
+		}
351
+
352
+		// okay made it here, so let's get the global group first for this messenger and message type to ensure
353
+		// there is no override set.
354
+		$global_message_template_group =
355
+			$this->_get_global_message_template_group_for_current_messenger_and_message_type();
356
+
357
+		if ($global_message_template_group instanceof EE_Message_Template_Group
358
+			&& $global_message_template_group->get('MTP_is_override')
359
+		) {
360
+			return $global_message_template_group;
361
+		}
362
+
363
+		// if we're still here, that means there was no message template group for the events in the collection and
364
+		// the global message template group for the messenger and message type is not set for override.  So next step is
365
+		// to see if there is a common shared custom message template group for this set of events.
366
+		$message_template_group = $this->_get_shared_message_template_for_events($event_ids);
367
+		if ($message_template_group instanceof EE_Message_Template_Group) {
368
+			return $message_template_group;
369
+		}
370
+
371
+		// STILL here?  Okay that means the fallback is to just use the global message template group for this event set.
372
+		// So we'll cache the global group for this event set (so this logic doesn't have to be repeated in this request)
373
+		// and return it.
374
+		if ($global_message_template_group instanceof EE_Message_Template_Group) {
375
+			$this->_template_collection->add(
376
+				$global_message_template_group,
377
+				$event_ids
378
+			);
379
+			return $global_message_template_group;
380
+		}
381
+
382
+		// if we land here that means there's NO active message template group for this set.
383
+		// TODO this will be a good target for some optimization down the road.  Whenever there is no active message
384
+		// template group for a given event set then cache that result so we don't repeat the logic.  However, for now,
385
+		// this should likely bit hit rarely enough that it's not a significant issue.
386
+		return null;
387
+	}
388
+
389
+
390
+	/**
391
+	 * This checks the current message in the queue and determines if there is a specific Message Template Group
392
+	 * requested for that message.
393
+	 *
394
+	 * @return EE_Message_Template_Group|null
395
+	 * @throws EE_Error
396
+	 * @throws InvalidArgumentException
397
+	 * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
398
+	 * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
399
+	 */
400
+	protected function _specific_message_template_group_from_queue()
401
+	{
402
+		// is there a GRP_ID already on the EE_Message object?  If there is, then a specific template has been requested
403
+		// so let's use that.
404
+		$GRP_ID = $this->_generation_queue->get_message_repository()->current()->GRP_ID();
405
+
406
+		if ($GRP_ID) {
407
+			// attempt to retrieve from repo first
408
+			$message_template_group = $this->_template_collection->get_by_ID($GRP_ID);
409
+			if ($message_template_group instanceof EE_Message_Template_Group) {
410
+				return $message_template_group;  // got it!
411
+			}
412
+
413
+			// nope don't have it yet.  Get from DB then add to repo if its not here, then that means the current GRP_ID
414
+			// is not valid, so we'll continue on in the code assuming there's NO GRP_ID.
415
+			$message_template_group = EEM_Message_Template_Group::instance()->get_one_by_ID($GRP_ID);
416
+			if ($message_template_group instanceof EE_Message_Template_Group) {
417
+				$this->_template_collection->add($message_template_group);
418
+				return $message_template_group;
419
+			}
420
+		}
421
+		return null;
422
+	}
423
+
424
+
425
+	/**
426
+	 * Returns whether the event ids passed in all share the same message template group for the current message type
427
+	 * and messenger.
428
+	 *
429
+	 * @param array $event_ids
430
+	 * @return bool true means they DO share the same message template group, false means they don't.
431
+	 * @throws EE_Error
432
+	 * @throws InvalidArgumentException
433
+	 * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
434
+	 * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
435
+	 */
436
+	protected function _queue_shares_same_message_template_group_for_events(array $event_ids)
437
+	{
438
+		foreach ($this->_current_data_handler->events as $event) {
439
+			$event_ids[ $event['ID'] ] = $event['ID'];
440
+		}
441
+		$count_of_message_template_groups = EEM_Message_Template_Group::instance()->count(
442
+			array(
443
+				array(
444
+					'Event.EVT_ID'           => array('IN', $event_ids),
445
+					'MTP_messenger'    => $this->_current_messenger->name,
446
+					'MTP_message_type' => $this->_current_message_type->name,
447
+				),
448
+			),
449
+			'GRP_ID',
450
+			true
451
+		);
452
+		return $count_of_message_template_groups === 1;
453
+	}
454
+
455
+
456
+	/**
457
+	 * This will get the shared message template group for events that are in the current data handler but ONLY if
458
+	 * there's a single shared message template group among all the events.  Otherwise it returns null.
459
+	 *
460
+	 * @param array $event_ids
461
+	 * @return EE_Message_Template_Group|null
462
+	 * @throws EE_Error
463
+	 * @throws InvalidArgumentException
464
+	 * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
465
+	 * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
466
+	 */
467
+	protected function _get_shared_message_template_for_events(array $event_ids)
468
+	{
469
+		$message_template_group = null;
470
+		if ($this->_queue_shares_same_message_template_group_for_events($event_ids)) {
471
+			$message_template_group = EEM_Message_Template_Group::instance()->get_one(
472
+				array(
473
+					array(
474
+						'Event.EVT_ID'           => array('IN', $event_ids),
475
+						'MTP_messenger'    => $this->_current_messenger->name,
476
+						'MTP_message_type' => $this->_current_message_type->name,
477
+						'MTP_is_active'    => true,
478
+					),
479
+					'group_by' => 'GRP_ID',
480
+				)
481
+			);
482
+			// store this in the collection if its valid
483
+			if ($message_template_group instanceof EE_Message_Template_Group) {
484
+				$this->_template_collection->add(
485
+					$message_template_group,
486
+					$event_ids
487
+				);
488
+			}
489
+		}
490
+		return $message_template_group;
491
+	}
492
+
493
+
494
+	/**
495
+	 * Retrieves the global message template group for the current messenger and message type.
496
+	 *
497
+	 * @return EE_Message_Template_Group|null
498
+	 * @throws EE_Error
499
+	 * @throws InvalidArgumentException
500
+	 * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
501
+	 * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
502
+	 */
503
+	protected function _get_global_message_template_group_for_current_messenger_and_message_type()
504
+	{
505
+		// first check the collection (we use an array with 0 in it to represent global groups).
506
+		$global_message_template_group = $this->_template_collection->get_by_key(
507
+			$this->_template_collection->getKey(
508
+				$this->_current_messenger->name,
509
+				$this->_current_message_type->name,
510
+				array(0)
511
+			)
512
+		);
513
+
514
+		// if we don't have a group lets hit the db.
515
+		if (! $global_message_template_group instanceof EE_Message_Template_Group) {
516
+			$global_message_template_group = EEM_Message_Template_Group::instance()->get_one(
517
+				array(
518
+					array(
519
+						'MTP_messenger'    => $this->_current_messenger->name,
520
+						'MTP_message_type' => $this->_current_message_type->name,
521
+						'MTP_is_active'    => true,
522
+						'MTP_is_global'    => true,
523
+					),
524
+				)
525
+			);
526
+			// if we have a group, add it to the collection.
527
+			if ($global_message_template_group instanceof EE_Message_Template_Group) {
528
+				$this->_template_collection->add(
529
+					$global_message_template_group,
530
+					array(0)
531
+				);
532
+			}
533
+		}
534
+		return $global_message_template_group;
535
+	}
536
+
537
+
538
+	/**
539
+	 * Returns an array of event ids for all the events within the current data handler.
540
+	 *
541
+	 * @return array
542
+	 */
543
+	protected function _get_event_ids_from_current_data_handler()
544
+	{
545
+		$event_ids = array();
546
+		foreach ($this->_current_data_handler->events as $event) {
547
+			$event_ids[ $event['ID'] ] = $event['ID'];
548
+		}
549
+		return $event_ids;
550
+	}
551
+
552
+
553
+	/**
554
+	 *  Retrieves formatted array of template information for each context specific to the given
555
+	 *  EE_Message_Template_Group
556
+	 *
557
+	 * @param EE_Message_Template_Group $message_template_group
558
+	 * @return array The returned array is in this structure:
559
+	 *                          array(
560
+	 *                          'field_name' => array(
561
+	 *                          'context' => 'content'
562
+	 *                          )
563
+	 *                          )
564
+	 * @throws EE_Error
565
+	 */
566
+	protected function _get_templates(EE_Message_Template_Group $message_template_group)
567
+	{
568
+		$templates         = array();
569
+		$context_templates = $message_template_group->context_templates();
570
+		foreach ($context_templates as $context => $template_fields) {
571
+			foreach ($template_fields as $template_field => $template_obj) {
572
+				if (! $template_obj instanceof EE_Message_Template) {
573
+					continue;
574
+				}
575
+				$templates[ $template_field ][ $context ] = $template_obj->get('MTP_content');
576
+			}
577
+		}
578
+		return $templates;
579
+	}
580
+
581
+
582
+	/**
583
+	 * Assembles new fully generated EE_Message objects and adds to _ready_queue
584
+	 *
585
+	 * @param array                     $addressees  Array of EE_Messages_Addressee objects indexed by message type
586
+	 *                                               context.
587
+	 * @param array                     $templates   formatted array of templates used for parsing data.
588
+	 * @param EE_Message_Template_Group $message_template_group
589
+	 * @return bool true if message generation went a-ok.  false if some sort of exception occurred.  Note: The
590
+	 *                                               method will attempt to generate ALL EE_Message objects and add to
591
+	 *                                               the _ready_queue.  Successfully generated messages get added to the
592
+	 *                                               queue with EEM_Message::status_idle, unsuccessfully generated
593
+	 *                                               messages will get added to the queue as EEM_Message::status_failed.
594
+	 *                                               Very rarely should "false" be returned from this method.
595
+	 * @throws EE_Error
596
+	 */
597
+	protected function _assemble_messages($addressees, $templates, EE_Message_Template_Group $message_template_group)
598
+	{
599
+
600
+		// if templates are empty then get out because we can't generate anything.
601
+		if (! $templates) {
602
+			$this->_error_msg[] = esc_html__(
603
+				'Unable to assemble messages because there are no templates retrieved for generating the messages with',
604
+				'event_espresso'
605
+			);
606
+			return false;
607
+		}
608
+
609
+		// We use this as the counter for generated messages because don't forget we may be executing this inside of a
610
+		// generation_queue.  So _ready_queue may have generated EE_Message objects already.
611
+		$generated_count = 0;
612
+		foreach ($addressees as $context => $recipients) {
613
+			foreach ($recipients as $recipient) {
614
+				$message = $this->_setup_message_object($context, $recipient, $templates, $message_template_group);
615
+				if ($message instanceof EE_Message) {
616
+					$this->_ready_queue->add(
617
+						$message,
618
+						array(),
619
+						$this->_generation_queue->get_message_repository()->is_preview(),
620
+						$this->_generation_queue->get_message_repository()->is_test_send()
621
+					);
622
+					$generated_count++;
623
+				}
624
+
625
+				// if the current MSG being generated is for a test send then we'll only use ONE message in the
626
+				// generation.
627
+				if ($this->_generation_queue->get_message_repository()->is_test_send()) {
628
+					break 2;
629
+				}
630
+			}
631
+		}
632
+
633
+		// if there are no generated messages then something else fatal went wrong.
634
+		return $generated_count > 0;
635
+	}
636
+
637
+
638
+	/**
639
+	 * @param string                    $context   The context for the generated message.
640
+	 * @param EE_Messages_Addressee     $recipient
641
+	 * @param array                     $templates formatted array of templates used for parsing data.
642
+	 * @param EE_Message_Template_Group $message_template_group
643
+	 * @return bool|EE_Message
644
+	 * @throws EE_Error
645
+	 */
646
+	protected function _setup_message_object(
647
+		$context,
648
+		EE_Messages_Addressee $recipient,
649
+		$templates,
650
+		EE_Message_Template_Group $message_template_group
651
+	) {
652
+		// stuff we already know
653
+		$transaction_id = $recipient->txn instanceof EE_Transaction ? $recipient->txn->ID() : 0;
654
+		$transaction_id = empty($transaction_id) && $this->_current_data_handler->txn instanceof EE_Transaction
655
+			? $this->_current_data_handler->txn->ID()
656
+			: $transaction_id;
657
+		$message_fields = array(
658
+			'GRP_ID'           => $message_template_group->ID(),
659
+			'TXN_ID'           => $transaction_id,
660
+			'MSG_messenger'    => $this->_current_messenger->name,
661
+			'MSG_message_type' => $this->_current_message_type->name,
662
+			'MSG_context'      => $context,
663
+		);
664
+
665
+		// recipient id and type should be on the EE_Messages_Addressee object but if this is empty, let's try to grab
666
+		// the info from the att_obj found in the EE_Messages_Addressee object.
667
+		if (empty($recipient->recipient_id) || empty($recipient->recipient_type)) {
668
+			$message_fields['MSG_recipient_ID']   = $recipient->att_obj instanceof EE_Attendee
669
+				? $recipient->att_obj->ID()
670
+				: 0;
671
+			$message_fields['MSG_recipient_type'] = 'Attendee';
672
+		} else {
673
+			$message_fields['MSG_recipient_ID']   = $recipient->recipient_id;
674
+			$message_fields['MSG_recipient_type'] = $recipient->recipient_type;
675
+		}
676
+		$message = EE_Message_Factory::create($message_fields);
677
+
678
+		// grab valid shortcodes for shortcode parser
679
+		$mt_shortcodes = $this->_current_message_type->get_valid_shortcodes();
680
+		$m_shortcodes  = $this->_current_messenger->get_valid_shortcodes();
681
+
682
+		// if the 'to' field is empty or the context is inactive we skip EXCEPT if we're previewing
683
+		if ((
684
+				(
685
+					empty($templates['to'][ $context ])
686
+					&& ! $this->_current_messenger->allow_empty_to_field()
687
+				)
688
+				|| ! $message_template_group->is_context_active($context)
689
+			)
690
+			&& ! $this->_generation_queue->get_message_repository()->is_preview()
691
+		) {
692
+			// we silently exit here and do NOT record a fail because the message is "turned off" by having no "to"
693
+			// field.
694
+			return false;
695
+		}
696
+		$error_msg = array();
697
+		foreach ($templates as $field => $field_context) {
698
+			$error_msg = array();
699
+			// let's setup the valid shortcodes for the incoming context.
700
+			$valid_shortcodes = $mt_shortcodes[ $context ];
701
+			// merge in valid shortcodes for the field.
702
+			$shortcodes = isset($m_shortcodes[ $field ]) ? $m_shortcodes[ $field ] : $valid_shortcodes;
703
+			if (isset($templates[ $field ][ $context ])) {
704
+				// prefix field.
705
+				$column_name = 'MSG_' . $field;
706
+				try {
707
+					$content = $this->_shortcode_parser->parse_message_template(
708
+						$templates[ $field ][ $context ],
709
+						$recipient,
710
+						$shortcodes,
711
+						$this->_current_message_type,
712
+						$this->_current_messenger,
713
+						$message
714
+					);
715
+					// the model field removes slashes when setting (usually necessary when the input is from the
716
+					// request) but this value is from another model and has no slashes. So add them so it matchces
717
+					// what the field expected (otherwise slashes will have been stripped from this an extra time)
718
+					$message->set_field_or_extra_meta($column_name, addslashes($content));
719
+				} catch (EE_Error $e) {
720
+					$error_msg[] = sprintf(
721
+						esc_html__(
722
+							'There was a problem generating the content for the field %s: %s',
723
+							'event_espresso'
724
+						),
725
+						$field,
726
+						$e->getMessage()
727
+					);
728
+					$message->set_STS_ID(EEM_Message::status_failed);
729
+				}
730
+			}
731
+		}
732
+
733
+		if ($message->STS_ID() === EEM_Message::status_failed) {
734
+			$error_msg = esc_html__('There were problems generating this message:', 'event_espresso')
735
+						 . "\n"
736
+						 . implode("\n", $error_msg);
737
+			$message->set_error_message($error_msg);
738
+		} else {
739
+			$message->set_STS_ID(EEM_Message::status_idle);
740
+		}
741
+		return $message;
742
+	}
743
+
744
+
745
+	/**
746
+	 * This verifies that the incoming array has a EE_messenger object and a EE_message_type object and sets appropriate
747
+	 * error message if either is missing.
748
+	 *
749
+	 * @return bool true means there were no errors, false means there were errors.
750
+	 * @throws EE_Error
751
+	 * @throws ReflectionException
752
+	 */
753
+	protected function _verify()
754
+	{
755
+		// reset error message to an empty array.
756
+		$this->_error_msg = array();
757
+		$valid            = true;
758
+		$valid            = $valid ? $this->_validate_messenger_and_message_type() : $valid;
759
+		$valid            = $valid ? $this->_validate_and_setup_data() : $valid;
760
+
761
+		// set the verified flag so we know everything has been validated.
762
+		$this->_verified = $valid;
763
+
764
+		return $valid;
765
+	}
766
+
767
+
768
+	/**
769
+	 * This accepts an array and validates that it is an array indexed by context with each value being an array of
770
+	 * EE_Messages_Addressee objects.
771
+	 *
772
+	 * @param array $addressees Keys correspond to contexts for the message type and values are EE_Messages_Addressee[]
773
+	 * @return bool
774
+	 */
775
+	protected function _valid_addressees($addressees)
776
+	{
777
+		if (! $addressees || ! is_array($addressees)) {
778
+			return false;
779
+		}
780
+
781
+		foreach ($addressees as $addressee_array) {
782
+			foreach ($addressee_array as $addressee) {
783
+				if (! $addressee instanceof EE_Messages_Addressee) {
784
+					return false;
785
+				}
786
+			}
787
+		}
788
+		return true;
789
+	}
790
+
791
+
792
+	/**
793
+	 * This validates the messenger, message type, and presences of generation data for the current EE_Message in the
794
+	 * queue. This process sets error messages if something is wrong.
795
+	 *
796
+	 * @return bool   true is if there are no errors.  false is if there is.
797
+	 */
798
+	protected function _validate_messenger_and_message_type()
799
+	{
800
+
801
+		// first are there any existing error messages?  If so then return.
802
+		if ($this->_error_msg) {
803
+			return false;
804
+		}
805
+		/** @type EE_Message $message */
806
+		$message = $this->_generation_queue->get_message_repository()->current();
807
+		try {
808
+			$this->_current_messenger = $message->valid_messenger(true)
809
+				? $message->messenger_object()
810
+				: null;
811
+		} catch (Exception $e) {
812
+			$this->_error_msg[] = $e->getMessage();
813
+		}
814
+		try {
815
+			$this->_current_message_type = $message->valid_message_type(true)
816
+				? $message->message_type_object()
817
+				: null;
818
+		} catch (Exception $e) {
819
+			$this->_error_msg[] = $e->getMessage();
820
+		}
821
+
822
+		/**
823
+		 * Check if there is any generation data, but only if this is not for a preview.
824
+		 */
825
+		if (! $this->_generation_queue->get_message_repository()->get_generation_data()
826
+			&& (
827
+				! $this->_generation_queue->get_message_repository()->is_preview()
828
+				&& $this->_generation_queue->get_message_repository()->get_data_handler()
829
+				   !== 'EE_Messages_Preview_incoming_data'
830
+			)
831
+		) {
832
+			$this->_error_msg[] = esc_html__(
833
+				'There is no generation data for this message. Unable to generate.',
834
+				'event_espresso'
835
+			);
836
+		}
837
+
838
+		return empty($this->_error_msg);
839
+	}
840
+
841
+
842
+	/**
843
+	 * This method retrieves the expected data handler for the message type and validates the generation data for that
844
+	 * data handler.
845
+	 *
846
+	 * @return bool true means there are no errors.  false means there were errors (and handler did not get setup).
847
+	 * @throws EE_Error
848
+	 * @throws ReflectionException
849
+	 */
850
+	protected function _validate_and_setup_data()
851
+	{
852
+
853
+		// First, are there any existing error messages?  If so, return because if there were errors elsewhere this can't
854
+		// be used anyways.
855
+		if ($this->_error_msg) {
856
+			return false;
857
+		}
858
+
859
+		$generation_data = $this->_generation_queue->get_message_repository()->get_generation_data();
860
+
861
+		/** @type EE_Messages_incoming_data $data_handler_class_name - well not really... just the class name actually*/
862
+		$data_handler_class_name = $this->_generation_queue->get_message_repository()->get_data_handler()
863
+			? $this->_generation_queue->get_message_repository()->get_data_handler()
864
+			: 'EE_Messages_' . $this->_current_message_type->get_data_handler($generation_data) . '_incoming_data';
865
+
866
+		// If this EE_Message is for a preview, then let's switch out to the preview data handler.
867
+		if ($this->_generation_queue->get_message_repository()->is_preview()) {
868
+			$data_handler_class_name = 'EE_Messages_Preview_incoming_data';
869
+		}
870
+
871
+		// First get the class name for the data handler (and also verifies it exists.
872
+		if (! class_exists($data_handler_class_name)) {
873
+			$this->_error_msg[] = sprintf(
874
+				esc_html__(
875
+					'The included data handler class name does not match any valid, accessible, "%1$s" classes.  Looking for %2$s.',
876
+					'event_espresso'
877
+				),
878
+				'EE_Messages_incoming_data',
879
+				$data_handler_class_name
880
+			);
881
+			return false;
882
+		}
883
+
884
+		// convert generation_data for data_handler_instantiation.
885
+		$generation_data = $data_handler_class_name::convert_data_from_persistent_storage($generation_data);
886
+
887
+		// note, this may set error messages as well.
888
+		$this->_set_data_handler($generation_data, $data_handler_class_name);
889
+
890
+		return empty($this->_error_msg);
891
+	}
892
+
893
+
894
+	/**
895
+	 * Sets the $_current_data_handler property that is used for generating the current EE_Message in the queue, and
896
+	 * adds it to the _data repository.
897
+	 *
898
+	 * @param mixed  $generating_data           This is data expected by the instantiated data handler.
899
+	 * @param string $data_handler_class_name   This is the reference string indicating what data handler is being
900
+	 *                                          instantiated.
901
+	 * @return void .
902
+	 * @throws EE_Error
903
+	 * @throws ReflectionException
904
+	 */
905
+	protected function _set_data_handler($generating_data, $data_handler_class_name)
906
+	{
907
+		// valid classname for the data handler.  Now let's setup the key for the data handler repository to see if there
908
+		// is already a ready data handler in the repository.
909
+		$this->_current_data_handler = $this->_data_handler_collection->get_by_key(
910
+			$this->_data_handler_collection->get_key(
911
+				$data_handler_class_name,
912
+				$generating_data
913
+			)
914
+		);
915
+		if (! $this->_current_data_handler instanceof EE_Messages_incoming_data) {
916
+			// no saved data_handler in the repo so let's set one up and add it to the repo.
917
+			try {
918
+				$this->_current_data_handler = new $data_handler_class_name($generating_data);
919
+				$this->_data_handler_collection->add($this->_current_data_handler, $generating_data);
920
+			} catch (EE_Error $e) {
921
+				$this->_error_msg[] = $e->get_error();
922
+			}
923
+		}
924
+	}
925
+
926
+
927
+	/**
928
+	 * The queued EE_Message for generation does not save the data used for generation as objects
929
+	 * because serialization of those objects could be problematic if the data is saved to the db.
930
+	 * So this method calls the static method on the associated data_handler for the given message_type
931
+	 * and that preps the data for later instantiation when generating.
932
+	 *
933
+	 * @param EE_Message_To_Generate $message_to_generate
934
+	 * @param bool                   $preview Indicate whether this is being used for a preview or not.
935
+	 * @return mixed Prepped data for persisting to the queue.  false is returned if unable to prep data.
936
+	 */
937
+	protected function _prepare_data_for_queue(EE_Message_To_Generate $message_to_generate, $preview)
938
+	{
939
+		/** @type EE_Messages_incoming_data $data_handler - well not really... just the class name actually */
940
+		$data_handler = $message_to_generate->get_data_handler_class_name($preview);
941
+		if (! $message_to_generate->valid()) {
942
+			return false; // unable to get the data because the info in the EE_Message_To_Generate class is invalid.
943
+		}
944
+		return $data_handler::convert_data_for_persistent_storage($message_to_generate->data());
945
+	}
946
+
947
+
948
+	/**
949
+	 * This sets up a EEM_Message::status_incomplete EE_Message object and adds it to the generation queue.
950
+	 *
951
+	 * @param EE_Message_To_Generate $message_to_generate
952
+	 * @param bool                   $test_send Whether this is just a test send or not.  Typically used for previews.
953
+	 * @throws InvalidArgumentException
954
+	 * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
955
+	 * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
956
+	 */
957
+	public function create_and_add_message_to_queue(EE_Message_To_Generate $message_to_generate, $test_send = false)
958
+	{
959
+		// prep data
960
+		$data = $this->_prepare_data_for_queue($message_to_generate, $message_to_generate->preview());
961
+
962
+		$message = $message_to_generate->get_EE_Message();
963
+
964
+		// is there a GRP_ID in the request?
965
+		if ($GRP_ID = EE_Registry::instance()->REQ->get('GRP_ID')) {
966
+			$message->set_GRP_ID($GRP_ID);
967
+		}
968
+
969
+		if ($data === false) {
970
+			$message->set_STS_ID(EEM_Message::status_failed);
971
+			$message->set_error_message(
972
+				esc_html__(
973
+					'Unable to prepare data for persistence to the database.',
974
+					'event_espresso'
975
+				)
976
+			);
977
+		} else {
978
+			// make sure that the data handler is cached on the message as well
979
+			$data['data_handler_class_name'] = $message_to_generate->get_data_handler_class_name();
980
+		}
981
+
982
+		$this->_generation_queue->add($message, $data, $message_to_generate->preview(), $test_send);
983
+	}
984 984
 }
Please login to merge, or discard this patch.
Spacing   +23 added lines, -23 removed lines patch added patch discarded remove patch
@@ -258,7 +258,7 @@  discard block
 block discarded – undo
258 258
     {
259 259
         // double check verification has run and that everything is ready to work with (saves us having to validate
260 260
         // everything again).
261
-        if (! $this->_verified) {
261
+        if ( ! $this->_verified) {
262 262
             return false; // get out because we don't have a valid setup to work with.
263 263
         }
264 264
 
@@ -275,7 +275,7 @@  discard block
 block discarded – undo
275 275
 
276 276
 
277 277
         // if no addressees then get out because there is nothing to generation (possible bad data).
278
-        if (! $this->_valid_addressees($addressees)) {
278
+        if ( ! $this->_valid_addressees($addressees)) {
279 279
             do_action(
280 280
                 'AHEE__EE_Messages_Generator___generate__invalid_addressees',
281 281
                 $this->_generation_queue->get_message_repository()->current(),
@@ -297,7 +297,7 @@  discard block
 block discarded – undo
297 297
         $message_template_group = $this->_get_message_template_group();
298 298
 
299 299
         // in the unlikely event there is no EE_Message_Template_Group available, get out!
300
-        if (! $message_template_group instanceof EE_Message_Template_Group) {
300
+        if ( ! $message_template_group instanceof EE_Message_Template_Group) {
301 301
             $this->_error_msg[] = esc_html__(
302 302
                 'Unable to get the Message Templates for the Message being generated.  No message template group accessible.',
303 303
                 'event_espresso'
@@ -407,7 +407,7 @@  discard block
 block discarded – undo
407 407
             // attempt to retrieve from repo first
408 408
             $message_template_group = $this->_template_collection->get_by_ID($GRP_ID);
409 409
             if ($message_template_group instanceof EE_Message_Template_Group) {
410
-                return $message_template_group;  // got it!
410
+                return $message_template_group; // got it!
411 411
             }
412 412
 
413 413
             // nope don't have it yet.  Get from DB then add to repo if its not here, then that means the current GRP_ID
@@ -436,7 +436,7 @@  discard block
 block discarded – undo
436 436
     protected function _queue_shares_same_message_template_group_for_events(array $event_ids)
437 437
     {
438 438
         foreach ($this->_current_data_handler->events as $event) {
439
-            $event_ids[ $event['ID'] ] = $event['ID'];
439
+            $event_ids[$event['ID']] = $event['ID'];
440 440
         }
441 441
         $count_of_message_template_groups = EEM_Message_Template_Group::instance()->count(
442 442
             array(
@@ -512,7 +512,7 @@  discard block
 block discarded – undo
512 512
         );
513 513
 
514 514
         // if we don't have a group lets hit the db.
515
-        if (! $global_message_template_group instanceof EE_Message_Template_Group) {
515
+        if ( ! $global_message_template_group instanceof EE_Message_Template_Group) {
516 516
             $global_message_template_group = EEM_Message_Template_Group::instance()->get_one(
517 517
                 array(
518 518
                     array(
@@ -544,7 +544,7 @@  discard block
 block discarded – undo
544 544
     {
545 545
         $event_ids = array();
546 546
         foreach ($this->_current_data_handler->events as $event) {
547
-            $event_ids[ $event['ID'] ] = $event['ID'];
547
+            $event_ids[$event['ID']] = $event['ID'];
548 548
         }
549 549
         return $event_ids;
550 550
     }
@@ -569,10 +569,10 @@  discard block
 block discarded – undo
569 569
         $context_templates = $message_template_group->context_templates();
570 570
         foreach ($context_templates as $context => $template_fields) {
571 571
             foreach ($template_fields as $template_field => $template_obj) {
572
-                if (! $template_obj instanceof EE_Message_Template) {
572
+                if ( ! $template_obj instanceof EE_Message_Template) {
573 573
                     continue;
574 574
                 }
575
-                $templates[ $template_field ][ $context ] = $template_obj->get('MTP_content');
575
+                $templates[$template_field][$context] = $template_obj->get('MTP_content');
576 576
             }
577 577
         }
578 578
         return $templates;
@@ -598,7 +598,7 @@  discard block
 block discarded – undo
598 598
     {
599 599
 
600 600
         // if templates are empty then get out because we can't generate anything.
601
-        if (! $templates) {
601
+        if ( ! $templates) {
602 602
             $this->_error_msg[] = esc_html__(
603 603
                 'Unable to assemble messages because there are no templates retrieved for generating the messages with',
604 604
                 'event_espresso'
@@ -682,7 +682,7 @@  discard block
 block discarded – undo
682 682
         // if the 'to' field is empty or the context is inactive we skip EXCEPT if we're previewing
683 683
         if ((
684 684
                 (
685
-                    empty($templates['to'][ $context ])
685
+                    empty($templates['to'][$context])
686 686
                     && ! $this->_current_messenger->allow_empty_to_field()
687 687
                 )
688 688
                 || ! $message_template_group->is_context_active($context)
@@ -697,15 +697,15 @@  discard block
 block discarded – undo
697 697
         foreach ($templates as $field => $field_context) {
698 698
             $error_msg = array();
699 699
             // let's setup the valid shortcodes for the incoming context.
700
-            $valid_shortcodes = $mt_shortcodes[ $context ];
700
+            $valid_shortcodes = $mt_shortcodes[$context];
701 701
             // merge in valid shortcodes for the field.
702
-            $shortcodes = isset($m_shortcodes[ $field ]) ? $m_shortcodes[ $field ] : $valid_shortcodes;
703
-            if (isset($templates[ $field ][ $context ])) {
702
+            $shortcodes = isset($m_shortcodes[$field]) ? $m_shortcodes[$field] : $valid_shortcodes;
703
+            if (isset($templates[$field][$context])) {
704 704
                 // prefix field.
705
-                $column_name = 'MSG_' . $field;
705
+                $column_name = 'MSG_'.$field;
706 706
                 try {
707 707
                     $content = $this->_shortcode_parser->parse_message_template(
708
-                        $templates[ $field ][ $context ],
708
+                        $templates[$field][$context],
709 709
                         $recipient,
710 710
                         $shortcodes,
711 711
                         $this->_current_message_type,
@@ -774,13 +774,13 @@  discard block
 block discarded – undo
774 774
      */
775 775
     protected function _valid_addressees($addressees)
776 776
     {
777
-        if (! $addressees || ! is_array($addressees)) {
777
+        if ( ! $addressees || ! is_array($addressees)) {
778 778
             return false;
779 779
         }
780 780
 
781 781
         foreach ($addressees as $addressee_array) {
782 782
             foreach ($addressee_array as $addressee) {
783
-                if (! $addressee instanceof EE_Messages_Addressee) {
783
+                if ( ! $addressee instanceof EE_Messages_Addressee) {
784 784
                     return false;
785 785
                 }
786 786
             }
@@ -822,7 +822,7 @@  discard block
 block discarded – undo
822 822
         /**
823 823
          * Check if there is any generation data, but only if this is not for a preview.
824 824
          */
825
-        if (! $this->_generation_queue->get_message_repository()->get_generation_data()
825
+        if ( ! $this->_generation_queue->get_message_repository()->get_generation_data()
826 826
             && (
827 827
                 ! $this->_generation_queue->get_message_repository()->is_preview()
828 828
                 && $this->_generation_queue->get_message_repository()->get_data_handler()
@@ -861,7 +861,7 @@  discard block
 block discarded – undo
861 861
         /** @type EE_Messages_incoming_data $data_handler_class_name - well not really... just the class name actually*/
862 862
         $data_handler_class_name = $this->_generation_queue->get_message_repository()->get_data_handler()
863 863
             ? $this->_generation_queue->get_message_repository()->get_data_handler()
864
-            : 'EE_Messages_' . $this->_current_message_type->get_data_handler($generation_data) . '_incoming_data';
864
+            : 'EE_Messages_'.$this->_current_message_type->get_data_handler($generation_data).'_incoming_data';
865 865
 
866 866
         // If this EE_Message is for a preview, then let's switch out to the preview data handler.
867 867
         if ($this->_generation_queue->get_message_repository()->is_preview()) {
@@ -869,7 +869,7 @@  discard block
 block discarded – undo
869 869
         }
870 870
 
871 871
         // First get the class name for the data handler (and also verifies it exists.
872
-        if (! class_exists($data_handler_class_name)) {
872
+        if ( ! class_exists($data_handler_class_name)) {
873 873
             $this->_error_msg[] = sprintf(
874 874
                 esc_html__(
875 875
                     'The included data handler class name does not match any valid, accessible, "%1$s" classes.  Looking for %2$s.',
@@ -912,7 +912,7 @@  discard block
 block discarded – undo
912 912
                 $generating_data
913 913
             )
914 914
         );
915
-        if (! $this->_current_data_handler instanceof EE_Messages_incoming_data) {
915
+        if ( ! $this->_current_data_handler instanceof EE_Messages_incoming_data) {
916 916
             // no saved data_handler in the repo so let's set one up and add it to the repo.
917 917
             try {
918 918
                 $this->_current_data_handler = new $data_handler_class_name($generating_data);
@@ -938,7 +938,7 @@  discard block
 block discarded – undo
938 938
     {
939 939
         /** @type EE_Messages_incoming_data $data_handler - well not really... just the class name actually */
940 940
         $data_handler = $message_to_generate->get_data_handler_class_name($preview);
941
-        if (! $message_to_generate->valid()) {
941
+        if ( ! $message_to_generate->valid()) {
942 942
             return false; // unable to get the data because the info in the EE_Message_To_Generate class is invalid.
943 943
         }
944 944
         return $data_handler::convert_data_for_persistent_storage($message_to_generate->data());
Please login to merge, or discard this patch.
messages/templates/ee_msg_editor_active_context_element.template.php 1 patch
Indentation   +18 added lines, -18 removed lines patch added patch discarded remove patch
@@ -10,22 +10,22 @@  discard block
 block discarded – undo
10 10
  * @var int    $message_template_group_id The ID for the message template group this context belongs to.
11 11
  */
12 12
 $active_message = sprintf(
13
-    esc_html__(
14
-        'The template for %1$s is currently %2$sactive%3$s.',
15
-        'event_espresso'
16
-    ),
17
-    $context_label,
18
-    '<strong>',
19
-    '</strong>'
13
+	esc_html__(
14
+		'The template for %1$s is currently %2$sactive%3$s.',
15
+		'event_espresso'
16
+	),
17
+	$context_label,
18
+	'<strong>',
19
+	'</strong>'
20 20
 );
21 21
 $inactive_message = sprintf(
22
-    esc_html__(
23
-        'The template for %1$s is currently %2$sinactive%3$s.',
24
-        'event_espresso'
25
-    ),
26
-    $context_label,
27
-    '<strong>',
28
-    '</strong>'
22
+	esc_html__(
23
+		'The template for %1$s is currently %2$sinactive%3$s.',
24
+		'event_espresso'
25
+	),
26
+	$context_label,
27
+	'<strong>',
28
+	'</strong>'
29 29
 );
30 30
 ?>
31 31
 <div class="context-active-control-container">
@@ -34,8 +34,8 @@  discard block
 block discarded – undo
34 34
         <span id="on-off-nonce-<?php echo $context; ?>" class="hidden"><?php echo $nonce; ?></span>
35 35
         <span class="ee-on-off-toggle-label">
36 36
             <?php
37
-            echo $is_active ? $active_message : $inactive_message;
38
-            ?>
37
+			echo $is_active ? $active_message : $inactive_message;
38
+			?>
39 39
         </span>
40 40
         <div class="hidden js-data">
41 41
             <span class="ee-active-message"><?php echo $active_message; ?></span>
@@ -43,8 +43,8 @@  discard block
 block discarded – undo
43 43
         </div>
44 44
         <div class="switch">
45 45
             <?php
46
-            $checked = $is_active ? ' checked="checked"' : '';
47
-            ?>
46
+			$checked = $is_active ? ' checked="checked"' : '';
47
+			?>
48 48
             <input data-grpid="<?php echo $message_template_group_id; ?>" id="ee-on-off-toggle-<?php echo $context; ?>" type="checkbox" class="ee-on-off-toggle ee-toggle-round-flat"<?php echo $checked; ?> value="<?php echo $on_off_action; ?>">
49 49
             <label for="ee-on-off-toggle-<?php echo $context; ?>"></label>
50 50
         </div>
Please login to merge, or discard this patch.
acceptance_tests/tests/e-TestContextActivationToggleCept.php 1 patch
Indentation   +62 added lines, -62 removed lines patch added patch discarded remove patch
@@ -8,8 +8,8 @@  discard block
 block discarded – undo
8 8
 $event_label = 'Testing Context Deactivation';
9 9
 
10 10
 $I->wantTo(
11
-    'Test that the context activation toggle for turning on or off specific contexts for message sending works as'
12
-    . ' expected'
11
+	'Test that the context activation toggle for turning on or off specific contexts for message sending works as'
12
+	. ' expected'
13 13
 );
14 14
 
15 15
 $I->loginAsAdmin();
@@ -34,7 +34,7 @@  discard block
 block discarded – undo
34 34
 $I->see('The template for Primary Registrant Recipient is currently inactive.');
35 35
 
36 36
 $I->amGoingTo(
37
-    'Trigger Registration Approved Messages and verify primary registrant context is excluded from sent messages.'
37
+	'Trigger Registration Approved Messages and verify primary registrant context is excluded from sent messages.'
38 38
 );
39 39
 $I->amOnDefaultEventsListTablePage();
40 40
 $I->click(EventsAdmin::ADD_NEW_EVENT_BUTTON_SELECTOR);
@@ -44,9 +44,9 @@  discard block
 block discarded – undo
44 44
 $event_link = $I->observeLinkUrlAt(EventsAdmin::EVENT_EDITOR_VIEW_LINK_AFTER_PUBLISH_SELECTOR);
45 45
 $event_id = $I->observeValueFromInputAt(EventsAdmin::EVENT_EDITOR_EVT_ID_SELECTOR);
46 46
 $test_registration_details = array(
47
-    'fname' => 'ContextTestGuy',
48
-    'lname' => 'ContextTestDude',
49
-    'email' => '[email protected]',
47
+	'fname' => 'ContextTestGuy',
48
+	'lname' => 'ContextTestDude',
49
+	'email' => '[email protected]',
50 50
 );
51 51
 $I->logOut();
52 52
 $I->amOnUrl($event_link);
@@ -63,48 +63,48 @@  discard block
 block discarded – undo
63 63
 $I->amOnMessagesActivityListTablePage();
64 64
 //verify registrant context
65 65
 $I->see(
66
-    $test_registration_details['email'],
67
-    MessagesAdmin::messagesActivityListTableCellSelectorFor(
68
-        'to',
69
-        'Registration Approved',
70
-        MessagesAdmin::MESSAGE_STATUS_SENT,
71
-        '',
72
-        'Registrant'
73
-    )
66
+	$test_registration_details['email'],
67
+	MessagesAdmin::messagesActivityListTableCellSelectorFor(
68
+		'to',
69
+		'Registration Approved',
70
+		MessagesAdmin::MESSAGE_STATUS_SENT,
71
+		'',
72
+		'Registrant'
73
+	)
74 74
 );
75 75
 $I->deleteMessageInMessagesListTableFor(
76
-    'Registration Approved',
77
-    MessagesAdmin::MESSAGE_STATUS_SENT,
78
-    'Email',
79
-    'Registrant'
76
+	'Registration Approved',
77
+	MessagesAdmin::MESSAGE_STATUS_SENT,
78
+	'Email',
79
+	'Registrant'
80 80
 );
81 81
 //verify admin context
82 82
 $I->see(
83
-    '[email protected]',
84
-    MessagesAdmin::messagesActivityListTableCellSelectorFor(
85
-        'to',
86
-        'Registration Approved',
87
-        MessagesAdmin::MESSAGE_STATUS_SENT
88
-    )
83
+	'[email protected]',
84
+	MessagesAdmin::messagesActivityListTableCellSelectorFor(
85
+		'to',
86
+		'Registration Approved',
87
+		MessagesAdmin::MESSAGE_STATUS_SENT
88
+	)
89 89
 );
90 90
 $I->deleteMessageInMessagesListTableFor(
91
-    'Registration Approved'
91
+	'Registration Approved'
92 92
 );
93 93
 //verify primary registrant context is NOT present.
94 94
 $I->dontSee(
95
-    $test_registration_details['email'],
96
-    MessagesAdmin::messagesActivityListTableCellSelectorFor(
97
-        'to',
98
-        'Registration Approved',
99
-        MessagesAdmin::MESSAGE_STATUS_SENT,
100
-        '',
101
-        'Primary Registrant'
102
-    )
95
+	$test_registration_details['email'],
96
+	MessagesAdmin::messagesActivityListTableCellSelectorFor(
97
+		'to',
98
+		'Registration Approved',
99
+		MessagesAdmin::MESSAGE_STATUS_SENT,
100
+		'',
101
+		'Primary Registrant'
102
+	)
103 103
 );
104 104
 
105 105
 $I->amGoingTo(
106
-    'Deactivate primary registrant context for Registration Approved Message Templates and restore the "To"'
107
-    . ' field to an empty string to verify the message does not send for that context.'
106
+	'Deactivate primary registrant context for Registration Approved Message Templates and restore the "To"'
107
+	. ' field to an empty string to verify the message does not send for that context.'
108 108
 );
109 109
 $I->amOnDefaultMessageTemplateListTablePage();
110 110
 $I->clickToEditMessageTemplateByMessageType('registration', 'primary_attendee');
@@ -128,41 +128,41 @@  discard block
 block discarded – undo
128 128
 $I->amOnMessagesActivityListTablePage();
129 129
 //verify registrant context
130 130
 $I->see(
131
-    $test_registration_details['email'],
132
-    MessagesAdmin::messagesActivityListTableCellSelectorFor(
133
-        'to',
134
-        'Registration Approved',
135
-        MessagesAdmin::MESSAGE_STATUS_SENT,
136
-        '',
137
-        'Registrant'
138
-    )
131
+	$test_registration_details['email'],
132
+	MessagesAdmin::messagesActivityListTableCellSelectorFor(
133
+		'to',
134
+		'Registration Approved',
135
+		MessagesAdmin::MESSAGE_STATUS_SENT,
136
+		'',
137
+		'Registrant'
138
+	)
139 139
 );
140 140
 $I->deleteMessageInMessagesListTableFor(
141
-    'Registration Approved',
142
-    MessagesAdmin::MESSAGE_STATUS_SENT,
143
-    'Email',
144
-    'Registrant'
141
+	'Registration Approved',
142
+	MessagesAdmin::MESSAGE_STATUS_SENT,
143
+	'Email',
144
+	'Registrant'
145 145
 );
146 146
 //verify admin context
147 147
 $I->see(
148
-    '[email protected]',
149
-    MessagesAdmin::messagesActivityListTableCellSelectorFor(
150
-        'to',
151
-        'Registration Approved',
152
-        MessagesAdmin::MESSAGE_STATUS_SENT
153
-    )
148
+	'[email protected]',
149
+	MessagesAdmin::messagesActivityListTableCellSelectorFor(
150
+		'to',
151
+		'Registration Approved',
152
+		MessagesAdmin::MESSAGE_STATUS_SENT
153
+	)
154 154
 );
155 155
 $I->deleteMessageInMessagesListTableFor(
156
-    'Registration Approved'
156
+	'Registration Approved'
157 157
 );
158 158
 //verify primary registrant context is NOT present.
159 159
 $I->dontSee(
160
-    $test_registration_details['email'],
161
-    MessagesAdmin::messagesActivityListTableCellSelectorFor(
162
-        'to',
163
-        'Registration Approved',
164
-        MessagesAdmin::MESSAGE_STATUS_SENT,
165
-        '',
166
-        'Primary Registrant'
167
-    )
160
+	$test_registration_details['email'],
161
+	MessagesAdmin::messagesActivityListTableCellSelectorFor(
162
+		'to',
163
+		'Registration Approved',
164
+		MessagesAdmin::MESSAGE_STATUS_SENT,
165
+		'',
166
+		'Primary Registrant'
167
+	)
168 168
 );
169 169
\ No newline at end of file
Please login to merge, or discard this patch.
public/Espresso_Arabica_2014/functions.php 1 patch
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -9,9 +9,9 @@  discard block
 block discarded – undo
9 9
  * @ link			http://www.eventespresso.com
10 10
  * @ version		4+
11 11
  */
12
-define( 'EE_THEME_FUNCTIONS_LOADED', TRUE );
12
+define('EE_THEME_FUNCTIONS_LOADED', TRUE);
13 13
 
14
-if ( ! function_exists( 'espresso_pagination' ) ) {
14
+if ( ! function_exists('espresso_pagination')) {
15 15
 	/**
16 16
 	 *    espresso_pagination
17 17
 	 *
@@ -23,21 +23,21 @@  discard block
 block discarded – undo
23 23
 		$big = 999999999; // need an unlikely integer
24 24
 		$pagination = paginate_links(
25 25
 			array(
26
-				'base'         => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
26
+				'base'         => str_replace($big, '%#%', esc_url(get_pagenum_link($big))),
27 27
 				'format'       => '?paged=%#%',
28
-				'current'      => max( 1, get_query_var( 'paged' ) ),
28
+				'current'      => max(1, get_query_var('paged')),
29 29
 				'total'        => $wp_query->max_num_pages,
30 30
 				'show_all'     => true,
31 31
 				'end_size'     => 10,
32 32
 				'mid_size'     => 6,
33 33
 				'prev_next'    => true,
34
-				'prev_text'    => __( '&lsaquo; PREV', 'event_espresso' ),
35
-				'next_text'    => __( 'NEXT &rsaquo;', 'event_espresso' ),
34
+				'prev_text'    => __('&lsaquo; PREV', 'event_espresso'),
35
+				'next_text'    => __('NEXT &rsaquo;', 'event_espresso'),
36 36
 				'type'         => 'plain',
37 37
 				'add_args'     => false,
38 38
 				'add_fragment' => ''
39 39
 			)
40 40
 		);
41
-		echo ! empty( $pagination ) ? '<div class="ee-pagination-dv ee-clear-float">' . $pagination . '</div>' : '';
41
+		echo ! empty($pagination) ? '<div class="ee-pagination-dv ee-clear-float">'.$pagination.'</div>' : '';
42 42
 	}
43 43
 }
44 44
\ No newline at end of file
Please login to merge, or discard this patch.
admin_pages/messages/help_tabs/messages_settings_messengers.help_tab.php 2 patches
Indentation   +50 added lines, -50 removed lines patch added patch discarded remove patch
@@ -3,79 +3,79 @@
 block discarded – undo
3 3
 </p>
4 4
 <p>
5 5
     <?php esc_html_e(
6
-        'You can select Messengers via the tabs across the top of the settings page. The available messengers you see depends on what version of Event Espresso you have and what addons are installed. Every install include an "Email" messenger tab.  When you click one of those tabs it will display that messenger.',
7
-        'event_espresso'
8
-    ); ?>
6
+		'You can select Messengers via the tabs across the top of the settings page. The available messengers you see depends on what version of Event Espresso you have and what addons are installed. Every install include an "Email" messenger tab.  When you click one of those tabs it will display that messenger.',
7
+		'event_espresso'
8
+	); ?>
9 9
 </p>
10 10
 <p>
11 11
     <?php esc_html_e(
12
-        'There are two ways to determine whether a messenger is active or not.  The first way is via the messenger tab itself.',
13
-        'event_espresso'
14
-    ); ?>
12
+		'There are two ways to determine whether a messenger is active or not.  The first way is via the messenger tab itself.',
13
+		'event_espresso'
14
+	); ?>
15 15
 </p>
16 16
 <p>
17 17
     <?php printf(
18
-        esc_html__(
19
-            'The green colored gear %s indicates that this messenger is currently active.',
20
-            'event_espresso'
21
-        ),
22
-        '<img class="inline-text" src="' . EE_MSG_ASSETS_URL . 'images/email-tab-active.png' . '"'
23
-        . ' alt="' . esc_attr__('Active Email Tab', 'event_espresso') . '" />'
24
-    );
25
-    printf(
26
-        esc_html__(
27
-            ' The white colored gear %s indicates the messenger is inactive. This is very helpful for seeing at a glance all the messengers that are active when you first view the page.',
28
-            'event_espresso'
29
-        ),
30
-        '<img class="inline-text" src="' . EE_MSG_ASSETS_URL . 'images/email-tab-inactive.png'
31
-        . '" alt="' . esc_attr__('Inactive Email Tab', 'event_espresso') . '" />'
32
-    ); ?>
18
+		esc_html__(
19
+			'The green colored gear %s indicates that this messenger is currently active.',
20
+			'event_espresso'
21
+		),
22
+		'<img class="inline-text" src="' . EE_MSG_ASSETS_URL . 'images/email-tab-active.png' . '"'
23
+		. ' alt="' . esc_attr__('Active Email Tab', 'event_espresso') . '" />'
24
+	);
25
+	printf(
26
+		esc_html__(
27
+			' The white colored gear %s indicates the messenger is inactive. This is very helpful for seeing at a glance all the messengers that are active when you first view the page.',
28
+			'event_espresso'
29
+		),
30
+		'<img class="inline-text" src="' . EE_MSG_ASSETS_URL . 'images/email-tab-inactive.png'
31
+		. '" alt="' . esc_attr__('Inactive Email Tab', 'event_espresso') . '" />'
32
+	); ?>
33 33
 </p>
34 34
 <p>
35 35
     <?php esc_html_e(
36
-        'The second way to determine whether a messenger is active or not is via the "on/off" button in the top right corner of the active messenger displayed content:',
37
-        'event_espresso'
38
-    ); ?>
36
+		'The second way to determine whether a messenger is active or not is via the "on/off" button in the top right corner of the active messenger displayed content:',
37
+		'event_espresso'
38
+	); ?>
39 39
 </p>
40 40
 <p>
41 41
     <?php printf(
42
-        esc_html__(
43
-            '%1$s means of course that the messenger is active and %2$s means the messenger is inactive.',
44
-            'event_espresso'
45
-        ),
46
-        '<div class="switch">'
47
-            . '<input class="ee-on-off-toggle ee-toggle-round-flat" type="checkbox" checked="checked" disabled>'
48
-            . '<label for="ee-on-off-toggle-on"></label>'
49
-        . '</div>',
50
-        '<div class="switch">'
51
-            . '<input class="ee-on-off-toggle ee-toggle-round-flat" type="checkbox" disabled>'
52
-            . '<label for="ee-on-off-toggle-on"></label>'
53
-        . '</div>'
54
-    ); ?>
42
+		esc_html__(
43
+			'%1$s means of course that the messenger is active and %2$s means the messenger is inactive.',
44
+			'event_espresso'
45
+		),
46
+		'<div class="switch">'
47
+			. '<input class="ee-on-off-toggle ee-toggle-round-flat" type="checkbox" checked="checked" disabled>'
48
+			. '<label for="ee-on-off-toggle-on"></label>'
49
+		. '</div>',
50
+		'<div class="switch">'
51
+			. '<input class="ee-on-off-toggle ee-toggle-round-flat" type="checkbox" disabled>'
52
+			. '<label for="ee-on-off-toggle-on"></label>'
53
+		. '</div>'
54
+	); ?>
55 55
 </p>
56 56
 <p>
57 57
     <?php
58
-        esc_html_e(
59
-            'The on/off toggle is also what you use to activate or deactivate a messenger.',
60
-            'event_espresso'
61
-        ); ?>
58
+		esc_html_e(
59
+			'The on/off toggle is also what you use to activate or deactivate a messenger.',
60
+			'event_espresso'
61
+		); ?>
62 62
 </p>
63 63
 <p>
64 64
     <?php esc_html_e(
65
-        'What happens when you click the toggle to activate is the messenger is activated and the system determines what default message types are activated with the messenger.  Then, if there are any default settings for either the messenger or message types those settings are saved.  Next, the system will generate any default templates (if none have been generated before, if there are previously generated templates then they are reactivated).  Finally, you will see the display change to reflect that the messenger is active. If the messenger has settings you can modify them then. Any message types that have settings will also automatically expand so you can see the default settings and make any changes as necessary to fit your needs. Usually the defaults are sufficient however.',
66
-        'event_espresso'
67
-    ); ?>
65
+		'What happens when you click the toggle to activate is the messenger is activated and the system determines what default message types are activated with the messenger.  Then, if there are any default settings for either the messenger or message types those settings are saved.  Next, the system will generate any default templates (if none have been generated before, if there are previously generated templates then they are reactivated).  Finally, you will see the display change to reflect that the messenger is active. If the messenger has settings you can modify them then. Any message types that have settings will also automatically expand so you can see the default settings and make any changes as necessary to fit your needs. Usually the defaults are sufficient however.',
66
+		'event_espresso'
67
+	); ?>
68 68
 </p>
69 69
 <p>
70 70
     <?php esc_html_e(
71
-        'When you deactivate a messenger, the system will first check if there are any custom event templates for that messenger. If there are you will be unable to deactivate the messenger. This is a fail safe to make sure you know that no messages will go out for those specific events so you don\'t accidentally deactivate.  If this check passes, then the system will deactivate any global templates for that messenger (note the templates are not erased, they just become inactive, so if you decide to reactivate the messenger later all your customizations are preserved). Then the display will change to reflect the deactivation.',
72
-        'event_espresso'
73
-    ); ?>
71
+		'When you deactivate a messenger, the system will first check if there are any custom event templates for that messenger. If there are you will be unable to deactivate the messenger. This is a fail safe to make sure you know that no messages will go out for those specific events so you don\'t accidentally deactivate.  If this check passes, then the system will deactivate any global templates for that messenger (note the templates are not erased, they just become inactive, so if you decide to reactivate the messenger later all your customizations are preserved). Then the display will change to reflect the deactivation.',
72
+		'event_espresso'
73
+	); ?>
74 74
 </p>
75 75
 <p>
76 76
     <strong><?php esc_html_e('Important', 'event_espresso'); ?></strong><br/>
77 77
     <?php esc_html_e(
78
-        'Although customizations made to global templates are preserved when a messenger is deactivated, any settings for that messenger (or the message types that were attached to it) are lost on deactivation.  Also, once you deactivate a messenger, no more messages will be delivered using that messenger for any of your events.',
79
-        'event_espresso'
80
-    ); ?>
78
+		'Although customizations made to global templates are preserved when a messenger is deactivated, any settings for that messenger (or the message types that were attached to it) are lost on deactivation.  Also, once you deactivate a messenger, no more messages will be delivered using that messenger for any of your events.',
79
+		'event_espresso'
80
+	); ?>
81 81
 </p>
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -19,16 +19,16 @@
 block discarded – undo
19 19
             'The green colored gear %s indicates that this messenger is currently active.',
20 20
             'event_espresso'
21 21
         ),
22
-        '<img class="inline-text" src="' . EE_MSG_ASSETS_URL . 'images/email-tab-active.png' . '"'
23
-        . ' alt="' . esc_attr__('Active Email Tab', 'event_espresso') . '" />'
22
+        '<img class="inline-text" src="'.EE_MSG_ASSETS_URL.'images/email-tab-active.png'.'"'
23
+        . ' alt="'.esc_attr__('Active Email Tab', 'event_espresso').'" />'
24 24
     );
25 25
     printf(
26 26
         esc_html__(
27 27
             ' The white colored gear %s indicates the messenger is inactive. This is very helpful for seeing at a glance all the messengers that are active when you first view the page.',
28 28
             'event_espresso'
29 29
         ),
30
-        '<img class="inline-text" src="' . EE_MSG_ASSETS_URL . 'images/email-tab-inactive.png'
31
-        . '" alt="' . esc_attr__('Inactive Email Tab', 'event_espresso') . '" />'
30
+        '<img class="inline-text" src="'.EE_MSG_ASSETS_URL.'images/email-tab-inactive.png'
31
+        . '" alt="'.esc_attr__('Inactive Email Tab', 'event_espresso').'" />'
32 32
     ); ?>
33 33
 </p>
34 34
 <p>
Please login to merge, or discard this patch.
core/libraries/shortcodes/EE_Venue_Shortcodes.lib.php 3 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -176,7 +176,7 @@
 block discarded – undo
176 176
     /**
177 177
      * This retrieves the EE_Venue from the available data object.
178 178
      *
179
-     * @return EE_Venue|null
179
+     * @return EE_Base_Class|null
180 180
      * @throws EE_Error
181 181
      * @throws EntityNotFoundException
182 182
      */
Please login to merge, or discard this patch.
Indentation   +311 added lines, -311 removed lines patch added patch discarded remove patch
@@ -17,315 +17,315 @@
 block discarded – undo
17 17
 {
18 18
 
19 19
 
20
-    /**
21
-     * Will hold the EE_Event if available
22
-     *
23
-     * @var EE_Event
24
-     */
25
-    protected $_event;
26
-
27
-    /**
28
-     * Will hold the EE_Venue if available
29
-     *
30
-     * @var EE_Venue
31
-     */
32
-    protected $_venue;
33
-
34
-
35
-    /**
36
-     * Initialize properties
37
-     */
38
-    protected function _init_props()
39
-    {
40
-        $this->label = esc_html__('Venue Shortcodes', 'event_espresso');
41
-        $this->description = esc_html__('All shortcodes specific to venue related data', 'event_espresso');
42
-        $this->_shortcodes = array(
43
-            '[VENUE_TITLE]'             => esc_html__('The title for the event venue', 'event_espresso'),
44
-            '[VENUE_DESCRIPTION]'       => esc_html__('The description for the event venue', 'event_espresso'),
45
-            '[VENUE_URL]'               => esc_html__('A url to a webpage for the venue', 'event_espresso'),
46
-            '[VENUE_DETAILS_URL]'       => sprintf(
47
-                esc_html__(
48
-                    'This shortcode outputs the url or website address to the venue details page on this website. This differs from %s which outputs what is entered in the "url" field in the venue details page.',
49
-                    'event_espresso'
50
-                ),
51
-                '[VENUE_URL]'
52
-            ),
53
-            '[VENUE_IMAGE]'             => esc_html__('An image representing the event venue', 'event_espresso'),
54
-            '[VENUE_PHONE]'             => esc_html__('The phone number for the venue', 'event_espresso'),
55
-            '[VENUE_ADDRESS]'           => esc_html__('The address for the venue', 'event_espresso'),
56
-            '[VENUE_ADDRESS2]'          => esc_html__('Address 2 for the venue', 'event_espresso'),
57
-            '[VENUE_CITY]'              => esc_html__('The city the venue is in', 'event_espresso'),
58
-            '[VENUE_STATE]'             => esc_html__('The state the venue is located in', 'event_espresso'),
59
-            '[VENUE_COUNTRY]'           => esc_html__('The country the venue is located in', 'event_espresso'),
60
-            '[VENUE_FORMATTED_ADDRESS]' => esc_html__(
61
-                'This just outputs the venue address in a semantic address format.',
62
-                'event_espresso'
63
-            ),
64
-            '[VENUE_ZIP]'               => esc_html__('The zip code for the venue address', 'event_espresso'),
65
-            '[VENUE_META_*]'            => esc_html__(
66
-                'This is a special dynamic shortcode. After the "*", add the exact name for your custom field, if there is a value set for that custom field within the venue then it will be output in place of this shortcode.',
67
-                'event_espresso'
68
-            ),
69
-            '[GOOGLE_MAP_URL]'          => esc_html__(
70
-                'URL for the google map associated with the venue.',
71
-                'event_espresso'
72
-            ),
73
-            '[GOOGLE_MAP_LINK]'         => esc_html__('Link to a google map for the venue', 'event_espresso'),
74
-            '[GOOGLE_MAP_IMAGE]'        => esc_html__('Google map for venue wrapped in image tags', 'event_espresso'),
75
-        );
76
-    }
77
-
78
-
79
-    /**
80
-     * Parse incoming shortcode
81
-     *
82
-     * @param string $shortcode
83
-     * @return string
84
-     * @throws EE_Error
85
-     * @throws EntityNotFoundException
86
-     */
87
-    protected function _parser($shortcode)
88
-    {
89
-        $this->_venue = $this->_get_venue();
90
-        // If there is no venue object by now then get out.
91
-        if (! $this->_venue instanceof EE_Venue) {
92
-            return '';
93
-        }
94
-
95
-        switch ($shortcode) {
96
-            case '[VENUE_TITLE]':
97
-                return $this->_venue('title');
98
-                break;
99
-
100
-            case '[VENUE_DESCRIPTION]':
101
-                return $this->_venue('description');
102
-                break;
103
-
104
-            case '[VENUE_URL]':
105
-                return $this->_venue('url');
106
-                break;
107
-
108
-            case '[VENUE_IMAGE]':
109
-                return $this->_venue('image');
110
-                break;
111
-
112
-            case '[VENUE_PHONE]':
113
-                return $this->_venue('phone');
114
-                break;
115
-
116
-            case '[VENUE_ADDRESS]':
117
-                return $this->_venue('address');
118
-                break;
119
-
120
-            case '[VENUE_ADDRESS2]':
121
-                return $this->_venue('address2');
122
-                break;
123
-
124
-            case '[VENUE_CITY]':
125
-                return $this->_venue('city');
126
-                break;
127
-
128
-            case '[VENUE_COUNTRY]':
129
-                return $this->_venue('country');
130
-                break;
131
-
132
-            case '[VENUE_STATE]':
133
-                return $this->_venue('state');
134
-                break;
135
-
136
-            case '[VENUE_ZIP]':
137
-                return $this->_venue('zip');
138
-                break;
139
-
140
-            case '[VENUE_FORMATTED_ADDRESS]':
141
-                return $this->_venue('formatted_address');
142
-                break;
143
-
144
-            case '[GOOGLE_MAP_URL]':
145
-                return $this->_venue('gmap_url');
146
-                break;
147
-
148
-            case '[GOOGLE_MAP_LINK]':
149
-                return $this->_venue('gmap_link');
150
-                break;
151
-
152
-            case '[GOOGLE_MAP_IMAGE]':
153
-                return $this->_venue('gmap_link_img');
154
-                break;
155
-
156
-            case '[VENUE_DETAILS_URL]':
157
-                return $this->_venue('permalink');
158
-                break;
159
-        }
160
-
161
-        if (strpos($shortcode, '[VENUE_META_*') !== false) {
162
-            $shortcode = str_replace('[VENUE_META_*', '', $shortcode);
163
-            $shortcode = trim(str_replace(']', '', $shortcode));
164
-
165
-            // pull the meta value from the venue post
166
-            $venue_meta = $this->_venue->get_post_meta($shortcode, true);
167
-
168
-            return ! empty($venue_meta) ? $venue_meta : '';
169
-        }
170
-    }
171
-
172
-    /**
173
-     * This retrieves the EE_Venue from the available data object.
174
-     *
175
-     * @return EE_Venue|null
176
-     * @throws EE_Error
177
-     * @throws EntityNotFoundException
178
-     */
179
-    private function _get_venue()
180
-    {
181
-
182
-        // we need the EE_Event object to get the venue.
183
-        $this->_event = $this->_data instanceof EE_Event ? $this->_data : null;
184
-
185
-        // if no event, then let's see if there is a reg_obj.  If there IS, then we'll try and grab the event from the
186
-        // reg_obj instead.
187
-        if (! $this->_event instanceof EE_Event) {
188
-            $aee = $this->_data instanceof EE_Messages_Addressee ? $this->_data : null;
189
-            $aee = $this->_extra_data instanceof EE_Messages_Addressee ? $this->_extra_data : $aee;
190
-
191
-            $this->_event = $aee instanceof EE_Messages_Addressee && $aee->reg_obj instanceof EE_Registration
192
-                ? $aee->reg_obj->event()
193
-                : null;
194
-
195
-            // if still empty do we have a ticket data item?
196
-            $this->_event = ! $this->_event instanceof EE_Event
197
-                            && $this->_data instanceof EE_Ticket
198
-                            && $this->_extra_data['data'] instanceof EE_Messages_Addressee
199
-                ? $this->_extra_data['data']->tickets[ $this->_data->ID() ]['EE_Event']
200
-                : $this->_event;
201
-
202
-            // if STILL empty event, let's try to get the first event in the list of events via EE_Messages_Addressee
203
-            // and use that.
204
-            $this->_event = ! $this->_event instanceof EE_Event && $aee instanceof EE_Messages_Addressee
205
-                ? reset($aee->events)
206
-                : $this->_event;
207
-        }
208
-
209
-        // If we have an event object use it to pull the venue.
210
-        if ($this->_event instanceof EE_Event) {
211
-            return $this->_event->get_first_related('Venue');
212
-        }
213
-
214
-        return null;
215
-    }
216
-
217
-    /**
218
-     * This retrieves the specified venue information
219
-     *
220
-     * @param string $field What Venue field to retrieve
221
-     * @return string What was retrieved!
222
-     * @throws EE_Error
223
-     * @throws EntityNotFoundException
224
-     */
225
-    private function _venue($field)
226
-    {
227
-
228
-        if (! $this->_venue instanceof EE_Venue) {
229
-            return '';
230
-        } //no venue so get out.
231
-
232
-        switch ($field) {
233
-            case 'title':
234
-                return $this->_venue->get('VNU_name');
235
-                break;
236
-
237
-            case 'description':
238
-                return $this->_venue->get('VNU_desc');
239
-                break;
240
-
241
-            case 'url':
242
-                $url = $this->_venue->get('VNU_url');
243
-                return empty($url) ? $this->_venue->get_permalink() : $url;
244
-                break;
245
-
246
-            case 'permalink':
247
-                return $this->_venue->get_permalink();
248
-                break;
249
-
250
-            case 'image':
251
-                return '<img src="' . $this->_venue->feature_image_url(array(200, 200,))
252
-                       . '" alt="' . sprintf(
253
-                           esc_attr__('%s Feature Image', 'event_espresso'),
254
-                           $this->_venue->get('VNU_name')
255
-                       ) . '" />';
256
-                break;
257
-
258
-            case 'phone':
259
-                return $this->_venue->get('VNU_phone');
260
-                break;
261
-
262
-            case 'address':
263
-                return $this->_venue->get('VNU_address');
264
-                break;
265
-
266
-            case 'address2':
267
-                return $this->_venue->get('VNU_address2');
268
-                break;
269
-
270
-            case 'city':
271
-                return $this->_venue->get('VNU_city');
272
-                break;
273
-
274
-            case 'state':
275
-                $state = $this->_venue->state_obj();
276
-                return is_object($state) ? $state->get('STA_name') : '';
277
-                break;
278
-
279
-            case 'country':
280
-                $country = $this->_venue->country_obj();
281
-                return is_object($country) ? $country->get('CNT_name') : '';
282
-                break;
283
-
284
-            case 'zip':
285
-                return $this->_venue->get('VNU_zip');
286
-                break;
287
-
288
-            case 'formatted_address':
289
-                return EEH_Address::format($this->_venue);
290
-                break;
291
-
292
-            case 'gmap_link':
293
-            case 'gmap_url':
294
-            case 'gmap_link_img':
295
-                $atts = $this->get_map_attributes($this->_venue, $field);
296
-                return EEH_Maps::google_map_link($atts);
297
-                break;
298
-        }
299
-        return '';
300
-    }
301
-
302
-
303
-    /**
304
-     * Generates the attributes for retrieving a google_map artifact.
305
-     *
306
-     * @param EE_Venue $venue
307
-     * @param string   $field
308
-     * @return array
309
-     * @throws EE_Error
310
-     */
311
-    protected function get_map_attributes(EE_Venue $venue, $field = 'gmap_link')
312
-    {
313
-        $state = $venue->state_obj();
314
-        $country = $venue->country_obj();
315
-        $atts = array(
316
-            'id'      => $venue->ID(),
317
-            'address' => $venue->get('VNU_address'),
318
-            'city'    => $venue->get('VNU_city'),
319
-            'state'   => is_object($state) ? $state->get('STA_name') : '',
320
-            'zip'     => $venue->get('VNU_zip'),
321
-            'country' => is_object($country) ? $country->get('CNT_name') : '',
322
-            'type'    => $field === 'gmap_link' ? 'url' : 'map',
323
-            'map_w'   => 200,
324
-            'map_h'   => 200,
325
-        );
326
-        if ($field === 'gmap_url') {
327
-            $atts['type'] = 'url_only';
328
-        }
329
-        return $atts;
330
-    }
20
+	/**
21
+	 * Will hold the EE_Event if available
22
+	 *
23
+	 * @var EE_Event
24
+	 */
25
+	protected $_event;
26
+
27
+	/**
28
+	 * Will hold the EE_Venue if available
29
+	 *
30
+	 * @var EE_Venue
31
+	 */
32
+	protected $_venue;
33
+
34
+
35
+	/**
36
+	 * Initialize properties
37
+	 */
38
+	protected function _init_props()
39
+	{
40
+		$this->label = esc_html__('Venue Shortcodes', 'event_espresso');
41
+		$this->description = esc_html__('All shortcodes specific to venue related data', 'event_espresso');
42
+		$this->_shortcodes = array(
43
+			'[VENUE_TITLE]'             => esc_html__('The title for the event venue', 'event_espresso'),
44
+			'[VENUE_DESCRIPTION]'       => esc_html__('The description for the event venue', 'event_espresso'),
45
+			'[VENUE_URL]'               => esc_html__('A url to a webpage for the venue', 'event_espresso'),
46
+			'[VENUE_DETAILS_URL]'       => sprintf(
47
+				esc_html__(
48
+					'This shortcode outputs the url or website address to the venue details page on this website. This differs from %s which outputs what is entered in the "url" field in the venue details page.',
49
+					'event_espresso'
50
+				),
51
+				'[VENUE_URL]'
52
+			),
53
+			'[VENUE_IMAGE]'             => esc_html__('An image representing the event venue', 'event_espresso'),
54
+			'[VENUE_PHONE]'             => esc_html__('The phone number for the venue', 'event_espresso'),
55
+			'[VENUE_ADDRESS]'           => esc_html__('The address for the venue', 'event_espresso'),
56
+			'[VENUE_ADDRESS2]'          => esc_html__('Address 2 for the venue', 'event_espresso'),
57
+			'[VENUE_CITY]'              => esc_html__('The city the venue is in', 'event_espresso'),
58
+			'[VENUE_STATE]'             => esc_html__('The state the venue is located in', 'event_espresso'),
59
+			'[VENUE_COUNTRY]'           => esc_html__('The country the venue is located in', 'event_espresso'),
60
+			'[VENUE_FORMATTED_ADDRESS]' => esc_html__(
61
+				'This just outputs the venue address in a semantic address format.',
62
+				'event_espresso'
63
+			),
64
+			'[VENUE_ZIP]'               => esc_html__('The zip code for the venue address', 'event_espresso'),
65
+			'[VENUE_META_*]'            => esc_html__(
66
+				'This is a special dynamic shortcode. After the "*", add the exact name for your custom field, if there is a value set for that custom field within the venue then it will be output in place of this shortcode.',
67
+				'event_espresso'
68
+			),
69
+			'[GOOGLE_MAP_URL]'          => esc_html__(
70
+				'URL for the google map associated with the venue.',
71
+				'event_espresso'
72
+			),
73
+			'[GOOGLE_MAP_LINK]'         => esc_html__('Link to a google map for the venue', 'event_espresso'),
74
+			'[GOOGLE_MAP_IMAGE]'        => esc_html__('Google map for venue wrapped in image tags', 'event_espresso'),
75
+		);
76
+	}
77
+
78
+
79
+	/**
80
+	 * Parse incoming shortcode
81
+	 *
82
+	 * @param string $shortcode
83
+	 * @return string
84
+	 * @throws EE_Error
85
+	 * @throws EntityNotFoundException
86
+	 */
87
+	protected function _parser($shortcode)
88
+	{
89
+		$this->_venue = $this->_get_venue();
90
+		// If there is no venue object by now then get out.
91
+		if (! $this->_venue instanceof EE_Venue) {
92
+			return '';
93
+		}
94
+
95
+		switch ($shortcode) {
96
+			case '[VENUE_TITLE]':
97
+				return $this->_venue('title');
98
+				break;
99
+
100
+			case '[VENUE_DESCRIPTION]':
101
+				return $this->_venue('description');
102
+				break;
103
+
104
+			case '[VENUE_URL]':
105
+				return $this->_venue('url');
106
+				break;
107
+
108
+			case '[VENUE_IMAGE]':
109
+				return $this->_venue('image');
110
+				break;
111
+
112
+			case '[VENUE_PHONE]':
113
+				return $this->_venue('phone');
114
+				break;
115
+
116
+			case '[VENUE_ADDRESS]':
117
+				return $this->_venue('address');
118
+				break;
119
+
120
+			case '[VENUE_ADDRESS2]':
121
+				return $this->_venue('address2');
122
+				break;
123
+
124
+			case '[VENUE_CITY]':
125
+				return $this->_venue('city');
126
+				break;
127
+
128
+			case '[VENUE_COUNTRY]':
129
+				return $this->_venue('country');
130
+				break;
131
+
132
+			case '[VENUE_STATE]':
133
+				return $this->_venue('state');
134
+				break;
135
+
136
+			case '[VENUE_ZIP]':
137
+				return $this->_venue('zip');
138
+				break;
139
+
140
+			case '[VENUE_FORMATTED_ADDRESS]':
141
+				return $this->_venue('formatted_address');
142
+				break;
143
+
144
+			case '[GOOGLE_MAP_URL]':
145
+				return $this->_venue('gmap_url');
146
+				break;
147
+
148
+			case '[GOOGLE_MAP_LINK]':
149
+				return $this->_venue('gmap_link');
150
+				break;
151
+
152
+			case '[GOOGLE_MAP_IMAGE]':
153
+				return $this->_venue('gmap_link_img');
154
+				break;
155
+
156
+			case '[VENUE_DETAILS_URL]':
157
+				return $this->_venue('permalink');
158
+				break;
159
+		}
160
+
161
+		if (strpos($shortcode, '[VENUE_META_*') !== false) {
162
+			$shortcode = str_replace('[VENUE_META_*', '', $shortcode);
163
+			$shortcode = trim(str_replace(']', '', $shortcode));
164
+
165
+			// pull the meta value from the venue post
166
+			$venue_meta = $this->_venue->get_post_meta($shortcode, true);
167
+
168
+			return ! empty($venue_meta) ? $venue_meta : '';
169
+		}
170
+	}
171
+
172
+	/**
173
+	 * This retrieves the EE_Venue from the available data object.
174
+	 *
175
+	 * @return EE_Venue|null
176
+	 * @throws EE_Error
177
+	 * @throws EntityNotFoundException
178
+	 */
179
+	private function _get_venue()
180
+	{
181
+
182
+		// we need the EE_Event object to get the venue.
183
+		$this->_event = $this->_data instanceof EE_Event ? $this->_data : null;
184
+
185
+		// if no event, then let's see if there is a reg_obj.  If there IS, then we'll try and grab the event from the
186
+		// reg_obj instead.
187
+		if (! $this->_event instanceof EE_Event) {
188
+			$aee = $this->_data instanceof EE_Messages_Addressee ? $this->_data : null;
189
+			$aee = $this->_extra_data instanceof EE_Messages_Addressee ? $this->_extra_data : $aee;
190
+
191
+			$this->_event = $aee instanceof EE_Messages_Addressee && $aee->reg_obj instanceof EE_Registration
192
+				? $aee->reg_obj->event()
193
+				: null;
194
+
195
+			// if still empty do we have a ticket data item?
196
+			$this->_event = ! $this->_event instanceof EE_Event
197
+							&& $this->_data instanceof EE_Ticket
198
+							&& $this->_extra_data['data'] instanceof EE_Messages_Addressee
199
+				? $this->_extra_data['data']->tickets[ $this->_data->ID() ]['EE_Event']
200
+				: $this->_event;
201
+
202
+			// if STILL empty event, let's try to get the first event in the list of events via EE_Messages_Addressee
203
+			// and use that.
204
+			$this->_event = ! $this->_event instanceof EE_Event && $aee instanceof EE_Messages_Addressee
205
+				? reset($aee->events)
206
+				: $this->_event;
207
+		}
208
+
209
+		// If we have an event object use it to pull the venue.
210
+		if ($this->_event instanceof EE_Event) {
211
+			return $this->_event->get_first_related('Venue');
212
+		}
213
+
214
+		return null;
215
+	}
216
+
217
+	/**
218
+	 * This retrieves the specified venue information
219
+	 *
220
+	 * @param string $field What Venue field to retrieve
221
+	 * @return string What was retrieved!
222
+	 * @throws EE_Error
223
+	 * @throws EntityNotFoundException
224
+	 */
225
+	private function _venue($field)
226
+	{
227
+
228
+		if (! $this->_venue instanceof EE_Venue) {
229
+			return '';
230
+		} //no venue so get out.
231
+
232
+		switch ($field) {
233
+			case 'title':
234
+				return $this->_venue->get('VNU_name');
235
+				break;
236
+
237
+			case 'description':
238
+				return $this->_venue->get('VNU_desc');
239
+				break;
240
+
241
+			case 'url':
242
+				$url = $this->_venue->get('VNU_url');
243
+				return empty($url) ? $this->_venue->get_permalink() : $url;
244
+				break;
245
+
246
+			case 'permalink':
247
+				return $this->_venue->get_permalink();
248
+				break;
249
+
250
+			case 'image':
251
+				return '<img src="' . $this->_venue->feature_image_url(array(200, 200,))
252
+					   . '" alt="' . sprintf(
253
+						   esc_attr__('%s Feature Image', 'event_espresso'),
254
+						   $this->_venue->get('VNU_name')
255
+					   ) . '" />';
256
+				break;
257
+
258
+			case 'phone':
259
+				return $this->_venue->get('VNU_phone');
260
+				break;
261
+
262
+			case 'address':
263
+				return $this->_venue->get('VNU_address');
264
+				break;
265
+
266
+			case 'address2':
267
+				return $this->_venue->get('VNU_address2');
268
+				break;
269
+
270
+			case 'city':
271
+				return $this->_venue->get('VNU_city');
272
+				break;
273
+
274
+			case 'state':
275
+				$state = $this->_venue->state_obj();
276
+				return is_object($state) ? $state->get('STA_name') : '';
277
+				break;
278
+
279
+			case 'country':
280
+				$country = $this->_venue->country_obj();
281
+				return is_object($country) ? $country->get('CNT_name') : '';
282
+				break;
283
+
284
+			case 'zip':
285
+				return $this->_venue->get('VNU_zip');
286
+				break;
287
+
288
+			case 'formatted_address':
289
+				return EEH_Address::format($this->_venue);
290
+				break;
291
+
292
+			case 'gmap_link':
293
+			case 'gmap_url':
294
+			case 'gmap_link_img':
295
+				$atts = $this->get_map_attributes($this->_venue, $field);
296
+				return EEH_Maps::google_map_link($atts);
297
+				break;
298
+		}
299
+		return '';
300
+	}
301
+
302
+
303
+	/**
304
+	 * Generates the attributes for retrieving a google_map artifact.
305
+	 *
306
+	 * @param EE_Venue $venue
307
+	 * @param string   $field
308
+	 * @return array
309
+	 * @throws EE_Error
310
+	 */
311
+	protected function get_map_attributes(EE_Venue $venue, $field = 'gmap_link')
312
+	{
313
+		$state = $venue->state_obj();
314
+		$country = $venue->country_obj();
315
+		$atts = array(
316
+			'id'      => $venue->ID(),
317
+			'address' => $venue->get('VNU_address'),
318
+			'city'    => $venue->get('VNU_city'),
319
+			'state'   => is_object($state) ? $state->get('STA_name') : '',
320
+			'zip'     => $venue->get('VNU_zip'),
321
+			'country' => is_object($country) ? $country->get('CNT_name') : '',
322
+			'type'    => $field === 'gmap_link' ? 'url' : 'map',
323
+			'map_w'   => 200,
324
+			'map_h'   => 200,
325
+		);
326
+		if ($field === 'gmap_url') {
327
+			$atts['type'] = 'url_only';
328
+		}
329
+		return $atts;
330
+	}
331 331
 }
Please login to merge, or discard this patch.
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -88,7 +88,7 @@  discard block
 block discarded – undo
88 88
     {
89 89
         $this->_venue = $this->_get_venue();
90 90
         // If there is no venue object by now then get out.
91
-        if (! $this->_venue instanceof EE_Venue) {
91
+        if ( ! $this->_venue instanceof EE_Venue) {
92 92
             return '';
93 93
         }
94 94
 
@@ -184,7 +184,7 @@  discard block
 block discarded – undo
184 184
 
185 185
         // if no event, then let's see if there is a reg_obj.  If there IS, then we'll try and grab the event from the
186 186
         // reg_obj instead.
187
-        if (! $this->_event instanceof EE_Event) {
187
+        if ( ! $this->_event instanceof EE_Event) {
188 188
             $aee = $this->_data instanceof EE_Messages_Addressee ? $this->_data : null;
189 189
             $aee = $this->_extra_data instanceof EE_Messages_Addressee ? $this->_extra_data : $aee;
190 190
 
@@ -196,7 +196,7 @@  discard block
 block discarded – undo
196 196
             $this->_event = ! $this->_event instanceof EE_Event
197 197
                             && $this->_data instanceof EE_Ticket
198 198
                             && $this->_extra_data['data'] instanceof EE_Messages_Addressee
199
-                ? $this->_extra_data['data']->tickets[ $this->_data->ID() ]['EE_Event']
199
+                ? $this->_extra_data['data']->tickets[$this->_data->ID()]['EE_Event']
200 200
                 : $this->_event;
201 201
 
202 202
             // if STILL empty event, let's try to get the first event in the list of events via EE_Messages_Addressee
@@ -225,7 +225,7 @@  discard block
 block discarded – undo
225 225
     private function _venue($field)
226 226
     {
227 227
 
228
-        if (! $this->_venue instanceof EE_Venue) {
228
+        if ( ! $this->_venue instanceof EE_Venue) {
229 229
             return '';
230 230
         } //no venue so get out.
231 231
 
@@ -248,11 +248,11 @@  discard block
 block discarded – undo
248 248
                 break;
249 249
 
250 250
             case 'image':
251
-                return '<img src="' . $this->_venue->feature_image_url(array(200, 200,))
252
-                       . '" alt="' . sprintf(
251
+                return '<img src="'.$this->_venue->feature_image_url(array(200, 200,))
252
+                       . '" alt="'.sprintf(
253 253
                            esc_attr__('%s Feature Image', 'event_espresso'),
254 254
                            $this->_venue->get('VNU_name')
255
-                       ) . '" />';
255
+                       ).'" />';
256 256
                 break;
257 257
 
258 258
             case 'phone':
Please login to merge, or discard this patch.
core/libraries/form_sections/inputs/EE_Radio_Button_Input.input.php 1 patch
Indentation   +17 added lines, -17 removed lines patch added patch discarded remove patch
@@ -15,22 +15,22 @@
 block discarded – undo
15 15
 class EE_Radio_Button_Input extends EE_Form_Input_With_Options_Base
16 16
 {
17 17
 
18
-    /**
19
-     * @param array $answer_options
20
-     * @param array $input_settings
21
-     */
22
-    public function __construct($answer_options, $input_settings = array())
23
-    {
24
-        $this->_set_display_strategy(new EE_Radio_Button_Display_Strategy());
25
-        $this->_add_validation_strategy(
26
-            new EE_Enum_Validation_Strategy(
27
-                isset($input_settings['validation_error_message'])
28
-                    ? $input_settings['validation_error_message']
29
-                    : null
30
-            )
31
-        );
32
-        $this->_multiple_selections = false;
33
-        parent::__construct($answer_options, $input_settings);
34
-    }
18
+	/**
19
+	 * @param array $answer_options
20
+	 * @param array $input_settings
21
+	 */
22
+	public function __construct($answer_options, $input_settings = array())
23
+	{
24
+		$this->_set_display_strategy(new EE_Radio_Button_Display_Strategy());
25
+		$this->_add_validation_strategy(
26
+			new EE_Enum_Validation_Strategy(
27
+				isset($input_settings['validation_error_message'])
28
+					? $input_settings['validation_error_message']
29
+					: null
30
+			)
31
+		);
32
+		$this->_multiple_selections = false;
33
+		parent::__construct($answer_options, $input_settings);
34
+	}
35 35
 
36 36
 }
Please login to merge, or discard this patch.
core/libraries/form_sections/inputs/EE_Datepicker_Input.php 2 patches
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -29,7 +29,7 @@  discard block
 block discarded – undo
29 29
             )
30 30
         );
31 31
         parent::__construct($input_settings);
32
-        $this->set_html_class($this->html_class() . ' datepicker');
32
+        $this->set_html_class($this->html_class().' datepicker');
33 33
         // add some style and make it dance
34 34
         add_action('wp_enqueue_scripts', array('EE_Datepicker_Input', 'enqueue_styles_and_scripts'));
35 35
         add_action('admin_enqueue_scripts', array('EE_Datepicker_Input', 'enqueue_styles_and_scripts'));
@@ -48,7 +48,7 @@  discard block
 block discarded – undo
48 48
         // load css
49 49
         wp_register_style(
50 50
             'espresso-ui-theme',
51
-            EE_GLOBAL_ASSETS_URL . 'css/espresso-ui-theme/jquery-ui-1.10.3.custom.min.css',
51
+            EE_GLOBAL_ASSETS_URL.'css/espresso-ui-theme/jquery-ui-1.10.3.custom.min.css',
52 52
             array(),
53 53
             EVENT_ESPRESSO_VERSION
54 54
         );
Please login to merge, or discard this patch.
Indentation   +38 added lines, -38 removed lines patch added patch discarded remove patch
@@ -10,45 +10,45 @@
 block discarded – undo
10 10
 class EE_Datepicker_Input extends EE_Form_Input_Base
11 11
 {
12 12
 
13
-    /**
14
-     * @param array $input_settings
15
-     */
16
-    public function __construct($input_settings = array())
17
-    {
18
-        $this->_set_display_strategy(new EE_Text_Input_Display_Strategy('datepicker'));
19
-        $this->_set_normalization_strategy(new EE_Text_Normalization());
20
-        // we could do better for validation, but at least verify its plaintext
21
-        $this->_add_validation_strategy(
22
-            new EE_Plaintext_Validation_Strategy(
23
-                isset($input_settings['validation_error_message'])
24
-                    ? $input_settings['validation_error_message']
25
-                    : null
26
-            )
27
-        );
28
-        parent::__construct($input_settings);
29
-        $this->set_html_class($this->html_class() . ' datepicker');
30
-        // add some style and make it dance
31
-        add_action('wp_enqueue_scripts', array('EE_Datepicker_Input', 'enqueue_styles_and_scripts'));
32
-        add_action('admin_enqueue_scripts', array('EE_Datepicker_Input', 'enqueue_styles_and_scripts'));
33
-    }
13
+	/**
14
+	 * @param array $input_settings
15
+	 */
16
+	public function __construct($input_settings = array())
17
+	{
18
+		$this->_set_display_strategy(new EE_Text_Input_Display_Strategy('datepicker'));
19
+		$this->_set_normalization_strategy(new EE_Text_Normalization());
20
+		// we could do better for validation, but at least verify its plaintext
21
+		$this->_add_validation_strategy(
22
+			new EE_Plaintext_Validation_Strategy(
23
+				isset($input_settings['validation_error_message'])
24
+					? $input_settings['validation_error_message']
25
+					: null
26
+			)
27
+		);
28
+		parent::__construct($input_settings);
29
+		$this->set_html_class($this->html_class() . ' datepicker');
30
+		// add some style and make it dance
31
+		add_action('wp_enqueue_scripts', array('EE_Datepicker_Input', 'enqueue_styles_and_scripts'));
32
+		add_action('admin_enqueue_scripts', array('EE_Datepicker_Input', 'enqueue_styles_and_scripts'));
33
+	}
34 34
 
35 35
 
36 36
 
37
-    /**
38
-     *    enqueue_styles_and_scripts
39
-     *
40
-     * @access        public
41
-     * @return        void
42
-     */
43
-    public static function enqueue_styles_and_scripts()
44
-    {
45
-        // load css
46
-        wp_register_style(
47
-            'espresso-ui-theme',
48
-            EE_GLOBAL_ASSETS_URL . 'css/espresso-ui-theme/jquery-ui-1.10.3.custom.min.css',
49
-            array(),
50
-            EVENT_ESPRESSO_VERSION
51
-        );
52
-        wp_enqueue_style('espresso-ui-theme');
53
-    }
37
+	/**
38
+	 *    enqueue_styles_and_scripts
39
+	 *
40
+	 * @access        public
41
+	 * @return        void
42
+	 */
43
+	public static function enqueue_styles_and_scripts()
44
+	{
45
+		// load css
46
+		wp_register_style(
47
+			'espresso-ui-theme',
48
+			EE_GLOBAL_ASSETS_URL . 'css/espresso-ui-theme/jquery-ui-1.10.3.custom.min.css',
49
+			array(),
50
+			EVENT_ESPRESSO_VERSION
51
+		);
52
+		wp_enqueue_style('espresso-ui-theme');
53
+	}
54 54
 }
Please login to merge, or discard this patch.