Completed
Branch dependabot/npm_and_yarn/@wordp... (e9f48b)
by
unknown
60:52 queued 52:34
created
strategies/validation/EE_Float_Validation_Strategy.strategy.php 3 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -27,7 +27,7 @@
 block discarded – undo
27 27
     /**
28 28
      *
29 29
      * @param $normalized_value
30
-     * @return bool
30
+     * @return boolean|null
31 31
      */
32 32
     public function validate($normalized_value)
33 33
     {
Please login to merge, or discard this patch.
Indentation   +26 added lines, -26 removed lines patch added patch discarded remove patch
@@ -11,36 +11,36 @@
 block discarded – undo
11 11
 class EE_Float_Validation_Strategy extends EE_Validation_Strategy_Base
12 12
 {
13 13
 
14
-    /**
15
-     * @param null $validation_error_message
16
-     */
17
-    public function __construct($validation_error_message = null)
18
-    {
19
-        if (! $validation_error_message) {
20
-            $validation_error_message = sprintf(__("Only numeric characters, commas, periods, and spaces, please!", "event_espresso"));
21
-        }
22
-        parent::__construct($validation_error_message);
23
-    }
14
+	/**
15
+	 * @param null $validation_error_message
16
+	 */
17
+	public function __construct($validation_error_message = null)
18
+	{
19
+		if (! $validation_error_message) {
20
+			$validation_error_message = sprintf(__("Only numeric characters, commas, periods, and spaces, please!", "event_espresso"));
21
+		}
22
+		parent::__construct($validation_error_message);
23
+	}
24 24
 
25 25
 
26 26
 
27
-    /**
28
-     *
29
-     * @param $normalized_value
30
-     * @return bool
31
-     */
32
-    public function validate($normalized_value)
33
-    {
34
-        // errors should have been detected by the normalization strategy
35
-    }
27
+	/**
28
+	 *
29
+	 * @param $normalized_value
30
+	 * @return bool
31
+	 */
32
+	public function validate($normalized_value)
33
+	{
34
+		// errors should have been detected by the normalization strategy
35
+	}
36 36
 
37 37
 
38 38
 
39
-    /**
40
-     * @return array
41
-     */
42
-    public function get_jquery_validation_rule_array()
43
-    {
44
-        return array('number'=>true, 'messages' => array( 'number' => $this->get_validation_error_message() ) );
45
-    }
39
+	/**
40
+	 * @return array
41
+	 */
42
+	public function get_jquery_validation_rule_array()
43
+	{
44
+		return array('number'=>true, 'messages' => array( 'number' => $this->get_validation_error_message() ) );
45
+	}
46 46
 }
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -16,7 +16,7 @@  discard block
 block discarded – undo
16 16
      */
17 17
     public function __construct($validation_error_message = null)
18 18
     {
19
-        if (! $validation_error_message) {
19
+        if ( ! $validation_error_message) {
20 20
             $validation_error_message = sprintf(__("Only numeric characters, commas, periods, and spaces, please!", "event_espresso"));
21 21
         }
22 22
         parent::__construct($validation_error_message);
@@ -41,6 +41,6 @@  discard block
 block discarded – undo
41 41
      */
42 42
     public function get_jquery_validation_rule_array()
43 43
     {
44
-        return array('number'=>true, 'messages' => array( 'number' => $this->get_validation_error_message() ) );
44
+        return array('number'=>true, 'messages' => array('number' => $this->get_validation_error_message()));
45 45
     }
46 46
 }
Please login to merge, or discard this patch.
line_item_display/EE_Admin_Table_Line_Item_Display_Strategy.strategy.php 3 patches
Doc Comments   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -49,7 +49,7 @@  discard block
 block discarded – undo
49 49
      * This is used to output a single
50 50
      * @param EE_Line_Item $line_item
51 51
      * @param array        $options
52
-     * @return mixed
52
+     * @return string
53 53
      */
54 54
     public function display_line_item(EE_Line_Item $line_item, $options = array())
55 55
     {
@@ -166,7 +166,7 @@  discard block
 block discarded – undo
166 166
      *
167 167
      * @param EE_Line_Item $line_item
168 168
      * @param array        $options
169
-     * @return mixed
169
+     * @return string
170 170
      */
171 171
     protected function _item_row(EE_Line_Item $line_item, $options = array())
172 172
     {
@@ -264,7 +264,7 @@  discard block
 block discarded – undo
264 264
      *
265 265
      * @param EE_Line_Item $line_item
266 266
      * @param array        $options
267
-     * @return mixed
267
+     * @return string
268 268
      */
269 269
     protected function _sub_item_row(EE_Line_Item $line_item, $options = array())
270 270
     {
@@ -279,7 +279,7 @@  discard block
 block discarded – undo
279 279
      *
280 280
      * @param EE_Line_Item $line_item
281 281
      * @param array        $options
282
-     * @return mixed
282
+     * @return string
283 283
      */
284 284
     protected function _tax_row(EE_Line_Item $line_item, $options = array())
285 285
     {
@@ -303,7 +303,7 @@  discard block
 block discarded – undo
303 303
      * @param EE_Line_Item $line_item
304 304
      * @param string       $text
305 305
      * @param array        $options
306
-     * @return mixed
306
+     * @return string
307 307
      */
308 308
     protected function _sub_total_row(EE_Line_Item $line_item, $text = '', $options = array())
309 309
     {
@@ -318,7 +318,7 @@  discard block
 block discarded – undo
318 318
      *
319 319
      * @param EE_Line_Item $line_item
320 320
      * @param array        $options
321
-     * @return mixed
321
+     * @return string
322 322
      */
323 323
     protected function _total_row(EE_Line_Item $line_item, $options = array())
324 324
     {
Please login to merge, or discard this patch.
Indentation   +320 added lines, -320 removed lines patch added patch discarded remove patch
@@ -14,324 +14,324 @@
 block discarded – undo
14 14
 {
15 15
 
16 16
 
17
-    /**
18
-     * whether to display the taxes row or not
19
-     * @type bool $_show_taxes
20
-     */
21
-    protected $_show_taxes = false;
22
-
23
-    /**
24
-     * html for any tax rows
25
-     * @type string $_show_taxes
26
-     */
27
-    protected $_taxes_html = '';
28
-
29
-
30
-    /**
31
-     * total amount including tax we can bill for at this time
32
-     * @type float $_grand_total
33
-     */
34
-    protected $_grand_total = 0.00;
35
-
36
-
37
-
38
-    /**
39
-     * @return float
40
-     */
41
-    public function grand_total()
42
-    {
43
-        return $this->_grand_total;
44
-    }
45
-
46
-
47
-
48
-    /**
49
-     * This is used to output a single
50
-     * @param EE_Line_Item $line_item
51
-     * @param array        $options
52
-     * @return mixed
53
-     */
54
-    public function display_line_item(EE_Line_Item $line_item, $options = array())
55
-    {
56
-
57
-        $html = '';
58
-        // set some default options and merge with incoming
59
-        $default_options = array(
60
-            'odd' => true,
61
-            'use_table_wrapper' => true,
62
-            'table_css_class' => 'admin-primary-mbox-tbl',
63
-            'taxes_tr_css_class' => 'admin-primary-mbox-taxes-tr',
64
-            'total_tr_css_class' => 'admin-primary-mbox-total-tr'
65
-        );
66
-        $options = array_merge($default_options, (array) $options);
67
-
68
-        switch ($line_item->type()) {
69
-            case EEM_Line_Item::type_line_item:
70
-                // item row
71
-                $html .= $this->_item_row($line_item, $options);
72
-                break;
73
-
74
-            case EEM_Line_Item::type_sub_line_item:
75
-                $html .= $this->_sub_item_row($line_item, $options);
76
-                break;
77
-
78
-            case EEM_Line_Item::type_sub_total:
79
-                if ($line_item->quantity() === 0) {
80
-                    return $html;
81
-                }
82
-                // loop through children
83
-                $child_line_items = $line_item->children();
84
-                // loop through children
85
-                foreach ($child_line_items as $child_line_item) {
86
-                    // recursively feed children back into this method
87
-                    $html .= $this->display_line_item($child_line_item, $options);
88
-                }
89
-                $html .= $this->_sub_total_row($line_item, $options);
90
-                break;
91
-
92
-            case EEM_Line_Item::type_tax:
93
-                if ($this->_show_taxes) {
94
-                    $this->_taxes_html .= $this->_tax_row($line_item, $options);
95
-                }
96
-                break;
97
-
98
-            case EEM_Line_Item::type_tax_sub_total:
99
-                foreach ($line_item->children() as $child_line_item) {
100
-                    if ($child_line_item->type() == EEM_Line_Item::type_tax) {
101
-                        $this->display_line_item($child_line_item, $options);
102
-                    }
103
-                }
104
-                break;
105
-
106
-            case EEM_Line_Item::type_total:
107
-                // determine whether to display taxes or not
108
-                $this->_show_taxes = $line_item->get_total_tax() > 0 ? true : false;
109
-                // get all child line items
110
-                $children = $line_item->children();
111
-
112
-                // loop thru all non-tax child line items
113
-                foreach ($children as $child_line_item) {
114
-                        $html .= $this->display_line_item($child_line_item, $options);
115
-                }
116
-
117
-                $html .= $this->_taxes_html;
118
-                $html .= $this->_total_row($line_item, $options);
119
-                if ($options['use_table_wrapper']) {
120
-                    $html = $this->_table_header($options) . $html . $this->_table_footer($options);
121
-                }
122
-                break;
123
-        }
124
-
125
-        return $html;
126
-    }
127
-
128
-
129
-
130
-    /**
131
-     * Table header for display.
132
-     * @since   4.8
133
-     * @param array $options
134
-     * @return string
135
-     */
136
-    protected function _table_header($options)
137
-    {
138
-        $html = EEH_HTML::table('', '', $options['table_css_class']);
139
-        $html .= EEH_HTML::thead();
140
-        $html .= EEH_HTML::tr();
141
-        $html .= EEH_HTML::th(__('Name', 'event_espresso'), '', 'jst-left');
142
-        $html .= EEH_HTML::th(__('Type', 'event_espresso'), '', 'jst-left');
143
-        $html .= EEH_HTML::th(__('Amount', 'event_espresso'), '', 'jst-cntr');
144
-        $html .= EEH_HTML::th(__('Qty', 'event_espresso'), '', 'jst-cntr');
145
-        $html .= EEH_HTML::th(__('Line Total', 'event_espresso'), '', 'jst-cntr');
146
-        $html .= EEH_HTML::tbody();
147
-        return $html;
148
-    }
149
-
150
-
151
-    /**
152
-     * Table footer for display
153
-     * @since 4.8
154
-     * @param array $options array of options for the table.
155
-     * @return string
156
-     */
157
-    protected function _table_footer($options)
158
-    {
159
-        return EEH_HTML::tbodyx() .  EEH_HTML::tablex();
160
-    }
161
-
162
-
163
-
164
-    /**
165
-     *    _item_row
166
-     *
167
-     * @param EE_Line_Item $line_item
168
-     * @param array        $options
169
-     * @return mixed
170
-     */
171
-    protected function _item_row(EE_Line_Item $line_item, $options = array())
172
-    {
173
-        $line_item_related_object = $line_item->get_object();
174
-        $parent_line_item_related_object = $line_item->parent() instanceof EE_Line_Item ? $line_item->parent()->get_object() : null;
175
-        // start of row
176
-        $row_class = $options['odd'] ? 'item odd' : 'item';
177
-        $html = EEH_HTML::tr('', '', $row_class);
178
-
179
-
180
-        // Name Column
181
-        $name_link = $line_item_related_object instanceof EEI_Admin_Links ? $line_item_related_object->get_admin_details_link() : '';
182
-
183
-        // related object scope.
184
-        $parent_related_object_name = $parent_line_item_related_object instanceof EEI_Line_Item_Object ? $parent_line_item_related_object->name() : '';
185
-        $parent_related_object_name = empty($parent_related_object_name) && $line_item->parent() instanceof EE_Line_Item ? $line_item->parent()->name() : $parent_related_object_name;
186
-        $parent_related_object_link = $parent_line_item_related_object instanceof EEI_Admin_Links ? $parent_line_item_related_object->get_admin_details_link() : '';
187
-
188
-
189
-        $name_html = $line_item_related_object instanceof EEI_Line_Item_Object ? $line_item_related_object->name() : $line_item->name();
190
-        $name_html = $name_link ? '<a href="' . $name_link . '">' . $name_html . '</a>' : $name_html;
191
-        $name_html .= $line_item->is_taxable() ? ' *' : '';
192
-        // maybe preface with icon?
193
-        $name_html = $line_item_related_object instanceof EEI_Has_Icon ? $line_item_related_object->get_icon() . $name_html : $name_html;
194
-        $name_html = '<span class="ee-line-item-name linked">' . $name_html . '</span><br>';
195
-        $name_html .=  sprintf(
196
-            _x('%1$sfor the %2$s: %3$s%4$s', 'eg. "for the Event: My Cool Event"', 'event_espresso'),
197
-            '<span class="ee-line-item-related-parent-object">',
198
-            $line_item->parent() instanceof EE_Line_Item ? $line_item->parent()->OBJ_type_i18n() : __('Item:', 'event_espresso'),
199
-            $parent_related_object_link ? '<a href="' . $parent_related_object_link . '">' . $parent_related_object_name . '</a>' : $parent_related_object_name,
200
-            '</span>'
201
-        );
202
-        $html .= EEH_HTML::td($name_html, '', 'jst-left');
203
-        // Type Column
204
-        $type_html = $line_item->OBJ_type() ? $line_item->OBJ_type_i18n() : '';
205
-        $type_html .= $this->_get_cancellations($line_item);
206
-        $type_html .= $line_item->OBJ_type() ? '<br />' : '';
207
-        $code = $line_item_related_object instanceof EEI_Has_Code ? $line_item_related_object->code() : '';
208
-        $type_html .= ! empty($code) ? '<span class="ee-line-item-id">' . sprintf(__('Code: %s', 'event_espresso'), $code) . '</span>' : '';
209
-        $html .= EEH_HTML::td($type_html, '', 'jst-left');
210
-
211
-
212
-        // Amount Column
213
-        if ($line_item->is_percent()) {
214
-            $html .= EEH_HTML::td($line_item->percent() . '%', '', 'jst-rght');
215
-        } else {
216
-            $html .= EEH_HTML::td($line_item->unit_price_no_code(), '', 'jst-rght');
217
-        }
218
-
219
-        // QTY column
220
-        $html .= EEH_HTML::td($line_item->quantity(), '', 'jst-rght');
221
-
222
-        // total column
223
-        $html .= EEH_HTML::td(EEH_Template::format_currency($line_item->total(), false, false), '', 'jst-rght');
224
-
225
-        // finish things off and return
226
-        $html .= EEH_HTML::trx();
227
-        return $html;
228
-    }
229
-
230
-
231
-
232
-    /**
233
-     *    _get_cancellations
234
-     *
235
-     * @param EE_Line_Item $line_item
236
-     * @return string
237
-     */
238
-    protected function _get_cancellations(EE_Line_Item $line_item)
239
-    {
240
-        $html = '';
241
-        $cancellations = $line_item->get_cancellations();
242
-        $cancellation = reset($cancellations);
243
-        // \EEH_Debug_Tools::printr( $cancellation, '$cancellation', __FILE__, __LINE__ );
244
-        if ($cancellation instanceof EE_Line_Item) {
245
-            $html .= ' <span class="ee-line-item-id">';
246
-            $html .= sprintf(
247
-                _n(
248
-                    '(%1$s Cancellation)',
249
-                    '(%1$s Cancellations)',
250
-                    $cancellation->quantity(),
251
-                    'event_espresso'
252
-                ),
253
-                $cancellation->quantity()
254
-            );
255
-            $html .= '</span>';
256
-        }
257
-        return $html;
258
-    }
259
-
260
-
261
-
262
-    /**
263
-     *  _sub_item_row
264
-     *
265
-     * @param EE_Line_Item $line_item
266
-     * @param array        $options
267
-     * @return mixed
268
-     */
269
-    protected function _sub_item_row(EE_Line_Item $line_item, $options = array())
270
-    {
271
-        // for now we're not showing sub-items
272
-        return '';
273
-    }
274
-
275
-
276
-
277
-    /**
278
-     *  _tax_row
279
-     *
280
-     * @param EE_Line_Item $line_item
281
-     * @param array        $options
282
-     * @return mixed
283
-     */
284
-    protected function _tax_row(EE_Line_Item $line_item, $options = array())
285
-    {
286
-        // start of row
287
-        $html = EEH_HTML::tr('', 'admin-primary-mbox-taxes-tr');
288
-        // name th
289
-        $html .= EEH_HTML::th($line_item->name() . '(' . $line_item->get_pretty('LIN_percent') . '%)', '', 'jst-rght', '', ' colspan="4"');
290
-        // total th
291
-        $html .= EEH_HTML::th(EEH_Template::format_currency($line_item->total(), false, false), '', 'jst-rght');
292
-        // end of row
293
-        $html .= EEH_HTML::trx();
294
-        return $html;
295
-    }
296
-
297
-
298
-
299
-
300
-    /**
301
-     *  _total_row
302
-     *
303
-     * @param EE_Line_Item $line_item
304
-     * @param string       $text
305
-     * @param array        $options
306
-     * @return mixed
307
-     */
308
-    protected function _sub_total_row(EE_Line_Item $line_item, $text = '', $options = array())
309
-    {
310
-        // currently not showing subtotal row
311
-        return '';
312
-    }
313
-
314
-
315
-
316
-    /**
317
-     *  _total_row
318
-     *
319
-     * @param EE_Line_Item $line_item
320
-     * @param array        $options
321
-     * @return mixed
322
-     */
323
-    protected function _total_row(EE_Line_Item $line_item, $options = array())
324
-    {
325
-        // start of row
326
-        $html = EEH_HTML::tr('', '', 'admin-primary-mbox-total-tr');
327
-        // Total th label
328
-        $total_label = sprintf(__('Transaction Total %s', 'event_espresso'), '(' . EE_Registry::instance()->CFG->currency->code . ')');
329
-        $html .= EEH_HTML::th($total_label, '', 'jst-rght', '', ' colspan="4"');
330
-        // total th
331
-
332
-        $html .= EEH_HTML::th(EEH_Template::format_currency($line_item->total(), false, false), '', 'jst-rght');
333
-        // end of row
334
-        $html .= EEH_HTML::trx();
335
-        return $html;
336
-    }
17
+	/**
18
+	 * whether to display the taxes row or not
19
+	 * @type bool $_show_taxes
20
+	 */
21
+	protected $_show_taxes = false;
22
+
23
+	/**
24
+	 * html for any tax rows
25
+	 * @type string $_show_taxes
26
+	 */
27
+	protected $_taxes_html = '';
28
+
29
+
30
+	/**
31
+	 * total amount including tax we can bill for at this time
32
+	 * @type float $_grand_total
33
+	 */
34
+	protected $_grand_total = 0.00;
35
+
36
+
37
+
38
+	/**
39
+	 * @return float
40
+	 */
41
+	public function grand_total()
42
+	{
43
+		return $this->_grand_total;
44
+	}
45
+
46
+
47
+
48
+	/**
49
+	 * This is used to output a single
50
+	 * @param EE_Line_Item $line_item
51
+	 * @param array        $options
52
+	 * @return mixed
53
+	 */
54
+	public function display_line_item(EE_Line_Item $line_item, $options = array())
55
+	{
56
+
57
+		$html = '';
58
+		// set some default options and merge with incoming
59
+		$default_options = array(
60
+			'odd' => true,
61
+			'use_table_wrapper' => true,
62
+			'table_css_class' => 'admin-primary-mbox-tbl',
63
+			'taxes_tr_css_class' => 'admin-primary-mbox-taxes-tr',
64
+			'total_tr_css_class' => 'admin-primary-mbox-total-tr'
65
+		);
66
+		$options = array_merge($default_options, (array) $options);
67
+
68
+		switch ($line_item->type()) {
69
+			case EEM_Line_Item::type_line_item:
70
+				// item row
71
+				$html .= $this->_item_row($line_item, $options);
72
+				break;
73
+
74
+			case EEM_Line_Item::type_sub_line_item:
75
+				$html .= $this->_sub_item_row($line_item, $options);
76
+				break;
77
+
78
+			case EEM_Line_Item::type_sub_total:
79
+				if ($line_item->quantity() === 0) {
80
+					return $html;
81
+				}
82
+				// loop through children
83
+				$child_line_items = $line_item->children();
84
+				// loop through children
85
+				foreach ($child_line_items as $child_line_item) {
86
+					// recursively feed children back into this method
87
+					$html .= $this->display_line_item($child_line_item, $options);
88
+				}
89
+				$html .= $this->_sub_total_row($line_item, $options);
90
+				break;
91
+
92
+			case EEM_Line_Item::type_tax:
93
+				if ($this->_show_taxes) {
94
+					$this->_taxes_html .= $this->_tax_row($line_item, $options);
95
+				}
96
+				break;
97
+
98
+			case EEM_Line_Item::type_tax_sub_total:
99
+				foreach ($line_item->children() as $child_line_item) {
100
+					if ($child_line_item->type() == EEM_Line_Item::type_tax) {
101
+						$this->display_line_item($child_line_item, $options);
102
+					}
103
+				}
104
+				break;
105
+
106
+			case EEM_Line_Item::type_total:
107
+				// determine whether to display taxes or not
108
+				$this->_show_taxes = $line_item->get_total_tax() > 0 ? true : false;
109
+				// get all child line items
110
+				$children = $line_item->children();
111
+
112
+				// loop thru all non-tax child line items
113
+				foreach ($children as $child_line_item) {
114
+						$html .= $this->display_line_item($child_line_item, $options);
115
+				}
116
+
117
+				$html .= $this->_taxes_html;
118
+				$html .= $this->_total_row($line_item, $options);
119
+				if ($options['use_table_wrapper']) {
120
+					$html = $this->_table_header($options) . $html . $this->_table_footer($options);
121
+				}
122
+				break;
123
+		}
124
+
125
+		return $html;
126
+	}
127
+
128
+
129
+
130
+	/**
131
+	 * Table header for display.
132
+	 * @since   4.8
133
+	 * @param array $options
134
+	 * @return string
135
+	 */
136
+	protected function _table_header($options)
137
+	{
138
+		$html = EEH_HTML::table('', '', $options['table_css_class']);
139
+		$html .= EEH_HTML::thead();
140
+		$html .= EEH_HTML::tr();
141
+		$html .= EEH_HTML::th(__('Name', 'event_espresso'), '', 'jst-left');
142
+		$html .= EEH_HTML::th(__('Type', 'event_espresso'), '', 'jst-left');
143
+		$html .= EEH_HTML::th(__('Amount', 'event_espresso'), '', 'jst-cntr');
144
+		$html .= EEH_HTML::th(__('Qty', 'event_espresso'), '', 'jst-cntr');
145
+		$html .= EEH_HTML::th(__('Line Total', 'event_espresso'), '', 'jst-cntr');
146
+		$html .= EEH_HTML::tbody();
147
+		return $html;
148
+	}
149
+
150
+
151
+	/**
152
+	 * Table footer for display
153
+	 * @since 4.8
154
+	 * @param array $options array of options for the table.
155
+	 * @return string
156
+	 */
157
+	protected function _table_footer($options)
158
+	{
159
+		return EEH_HTML::tbodyx() .  EEH_HTML::tablex();
160
+	}
161
+
162
+
163
+
164
+	/**
165
+	 *    _item_row
166
+	 *
167
+	 * @param EE_Line_Item $line_item
168
+	 * @param array        $options
169
+	 * @return mixed
170
+	 */
171
+	protected function _item_row(EE_Line_Item $line_item, $options = array())
172
+	{
173
+		$line_item_related_object = $line_item->get_object();
174
+		$parent_line_item_related_object = $line_item->parent() instanceof EE_Line_Item ? $line_item->parent()->get_object() : null;
175
+		// start of row
176
+		$row_class = $options['odd'] ? 'item odd' : 'item';
177
+		$html = EEH_HTML::tr('', '', $row_class);
178
+
179
+
180
+		// Name Column
181
+		$name_link = $line_item_related_object instanceof EEI_Admin_Links ? $line_item_related_object->get_admin_details_link() : '';
182
+
183
+		// related object scope.
184
+		$parent_related_object_name = $parent_line_item_related_object instanceof EEI_Line_Item_Object ? $parent_line_item_related_object->name() : '';
185
+		$parent_related_object_name = empty($parent_related_object_name) && $line_item->parent() instanceof EE_Line_Item ? $line_item->parent()->name() : $parent_related_object_name;
186
+		$parent_related_object_link = $parent_line_item_related_object instanceof EEI_Admin_Links ? $parent_line_item_related_object->get_admin_details_link() : '';
187
+
188
+
189
+		$name_html = $line_item_related_object instanceof EEI_Line_Item_Object ? $line_item_related_object->name() : $line_item->name();
190
+		$name_html = $name_link ? '<a href="' . $name_link . '">' . $name_html . '</a>' : $name_html;
191
+		$name_html .= $line_item->is_taxable() ? ' *' : '';
192
+		// maybe preface with icon?
193
+		$name_html = $line_item_related_object instanceof EEI_Has_Icon ? $line_item_related_object->get_icon() . $name_html : $name_html;
194
+		$name_html = '<span class="ee-line-item-name linked">' . $name_html . '</span><br>';
195
+		$name_html .=  sprintf(
196
+			_x('%1$sfor the %2$s: %3$s%4$s', 'eg. "for the Event: My Cool Event"', 'event_espresso'),
197
+			'<span class="ee-line-item-related-parent-object">',
198
+			$line_item->parent() instanceof EE_Line_Item ? $line_item->parent()->OBJ_type_i18n() : __('Item:', 'event_espresso'),
199
+			$parent_related_object_link ? '<a href="' . $parent_related_object_link . '">' . $parent_related_object_name . '</a>' : $parent_related_object_name,
200
+			'</span>'
201
+		);
202
+		$html .= EEH_HTML::td($name_html, '', 'jst-left');
203
+		// Type Column
204
+		$type_html = $line_item->OBJ_type() ? $line_item->OBJ_type_i18n() : '';
205
+		$type_html .= $this->_get_cancellations($line_item);
206
+		$type_html .= $line_item->OBJ_type() ? '<br />' : '';
207
+		$code = $line_item_related_object instanceof EEI_Has_Code ? $line_item_related_object->code() : '';
208
+		$type_html .= ! empty($code) ? '<span class="ee-line-item-id">' . sprintf(__('Code: %s', 'event_espresso'), $code) . '</span>' : '';
209
+		$html .= EEH_HTML::td($type_html, '', 'jst-left');
210
+
211
+
212
+		// Amount Column
213
+		if ($line_item->is_percent()) {
214
+			$html .= EEH_HTML::td($line_item->percent() . '%', '', 'jst-rght');
215
+		} else {
216
+			$html .= EEH_HTML::td($line_item->unit_price_no_code(), '', 'jst-rght');
217
+		}
218
+
219
+		// QTY column
220
+		$html .= EEH_HTML::td($line_item->quantity(), '', 'jst-rght');
221
+
222
+		// total column
223
+		$html .= EEH_HTML::td(EEH_Template::format_currency($line_item->total(), false, false), '', 'jst-rght');
224
+
225
+		// finish things off and return
226
+		$html .= EEH_HTML::trx();
227
+		return $html;
228
+	}
229
+
230
+
231
+
232
+	/**
233
+	 *    _get_cancellations
234
+	 *
235
+	 * @param EE_Line_Item $line_item
236
+	 * @return string
237
+	 */
238
+	protected function _get_cancellations(EE_Line_Item $line_item)
239
+	{
240
+		$html = '';
241
+		$cancellations = $line_item->get_cancellations();
242
+		$cancellation = reset($cancellations);
243
+		// \EEH_Debug_Tools::printr( $cancellation, '$cancellation', __FILE__, __LINE__ );
244
+		if ($cancellation instanceof EE_Line_Item) {
245
+			$html .= ' <span class="ee-line-item-id">';
246
+			$html .= sprintf(
247
+				_n(
248
+					'(%1$s Cancellation)',
249
+					'(%1$s Cancellations)',
250
+					$cancellation->quantity(),
251
+					'event_espresso'
252
+				),
253
+				$cancellation->quantity()
254
+			);
255
+			$html .= '</span>';
256
+		}
257
+		return $html;
258
+	}
259
+
260
+
261
+
262
+	/**
263
+	 *  _sub_item_row
264
+	 *
265
+	 * @param EE_Line_Item $line_item
266
+	 * @param array        $options
267
+	 * @return mixed
268
+	 */
269
+	protected function _sub_item_row(EE_Line_Item $line_item, $options = array())
270
+	{
271
+		// for now we're not showing sub-items
272
+		return '';
273
+	}
274
+
275
+
276
+
277
+	/**
278
+	 *  _tax_row
279
+	 *
280
+	 * @param EE_Line_Item $line_item
281
+	 * @param array        $options
282
+	 * @return mixed
283
+	 */
284
+	protected function _tax_row(EE_Line_Item $line_item, $options = array())
285
+	{
286
+		// start of row
287
+		$html = EEH_HTML::tr('', 'admin-primary-mbox-taxes-tr');
288
+		// name th
289
+		$html .= EEH_HTML::th($line_item->name() . '(' . $line_item->get_pretty('LIN_percent') . '%)', '', 'jst-rght', '', ' colspan="4"');
290
+		// total th
291
+		$html .= EEH_HTML::th(EEH_Template::format_currency($line_item->total(), false, false), '', 'jst-rght');
292
+		// end of row
293
+		$html .= EEH_HTML::trx();
294
+		return $html;
295
+	}
296
+
297
+
298
+
299
+
300
+	/**
301
+	 *  _total_row
302
+	 *
303
+	 * @param EE_Line_Item $line_item
304
+	 * @param string       $text
305
+	 * @param array        $options
306
+	 * @return mixed
307
+	 */
308
+	protected function _sub_total_row(EE_Line_Item $line_item, $text = '', $options = array())
309
+	{
310
+		// currently not showing subtotal row
311
+		return '';
312
+	}
313
+
314
+
315
+
316
+	/**
317
+	 *  _total_row
318
+	 *
319
+	 * @param EE_Line_Item $line_item
320
+	 * @param array        $options
321
+	 * @return mixed
322
+	 */
323
+	protected function _total_row(EE_Line_Item $line_item, $options = array())
324
+	{
325
+		// start of row
326
+		$html = EEH_HTML::tr('', '', 'admin-primary-mbox-total-tr');
327
+		// Total th label
328
+		$total_label = sprintf(__('Transaction Total %s', 'event_espresso'), '(' . EE_Registry::instance()->CFG->currency->code . ')');
329
+		$html .= EEH_HTML::th($total_label, '', 'jst-rght', '', ' colspan="4"');
330
+		// total th
331
+
332
+		$html .= EEH_HTML::th(EEH_Template::format_currency($line_item->total(), false, false), '', 'jst-rght');
333
+		// end of row
334
+		$html .= EEH_HTML::trx();
335
+		return $html;
336
+	}
337 337
 }
Please login to merge, or discard this patch.
Spacing   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -117,7 +117,7 @@  discard block
 block discarded – undo
117 117
                 $html .= $this->_taxes_html;
118 118
                 $html .= $this->_total_row($line_item, $options);
119 119
                 if ($options['use_table_wrapper']) {
120
-                    $html = $this->_table_header($options) . $html . $this->_table_footer($options);
120
+                    $html = $this->_table_header($options).$html.$this->_table_footer($options);
121 121
                 }
122 122
                 break;
123 123
         }
@@ -156,7 +156,7 @@  discard block
 block discarded – undo
156 156
      */
157 157
     protected function _table_footer($options)
158 158
     {
159
-        return EEH_HTML::tbodyx() .  EEH_HTML::tablex();
159
+        return EEH_HTML::tbodyx().EEH_HTML::tablex();
160 160
     }
161 161
 
162 162
 
@@ -187,16 +187,16 @@  discard block
 block discarded – undo
187 187
 
188 188
 
189 189
         $name_html = $line_item_related_object instanceof EEI_Line_Item_Object ? $line_item_related_object->name() : $line_item->name();
190
-        $name_html = $name_link ? '<a href="' . $name_link . '">' . $name_html . '</a>' : $name_html;
190
+        $name_html = $name_link ? '<a href="'.$name_link.'">'.$name_html.'</a>' : $name_html;
191 191
         $name_html .= $line_item->is_taxable() ? ' *' : '';
192 192
         // maybe preface with icon?
193
-        $name_html = $line_item_related_object instanceof EEI_Has_Icon ? $line_item_related_object->get_icon() . $name_html : $name_html;
194
-        $name_html = '<span class="ee-line-item-name linked">' . $name_html . '</span><br>';
195
-        $name_html .=  sprintf(
193
+        $name_html = $line_item_related_object instanceof EEI_Has_Icon ? $line_item_related_object->get_icon().$name_html : $name_html;
194
+        $name_html = '<span class="ee-line-item-name linked">'.$name_html.'</span><br>';
195
+        $name_html .= sprintf(
196 196
             _x('%1$sfor the %2$s: %3$s%4$s', 'eg. "for the Event: My Cool Event"', 'event_espresso'),
197 197
             '<span class="ee-line-item-related-parent-object">',
198 198
             $line_item->parent() instanceof EE_Line_Item ? $line_item->parent()->OBJ_type_i18n() : __('Item:', 'event_espresso'),
199
-            $parent_related_object_link ? '<a href="' . $parent_related_object_link . '">' . $parent_related_object_name . '</a>' : $parent_related_object_name,
199
+            $parent_related_object_link ? '<a href="'.$parent_related_object_link.'">'.$parent_related_object_name.'</a>' : $parent_related_object_name,
200 200
             '</span>'
201 201
         );
202 202
         $html .= EEH_HTML::td($name_html, '', 'jst-left');
@@ -205,13 +205,13 @@  discard block
 block discarded – undo
205 205
         $type_html .= $this->_get_cancellations($line_item);
206 206
         $type_html .= $line_item->OBJ_type() ? '<br />' : '';
207 207
         $code = $line_item_related_object instanceof EEI_Has_Code ? $line_item_related_object->code() : '';
208
-        $type_html .= ! empty($code) ? '<span class="ee-line-item-id">' . sprintf(__('Code: %s', 'event_espresso'), $code) . '</span>' : '';
208
+        $type_html .= ! empty($code) ? '<span class="ee-line-item-id">'.sprintf(__('Code: %s', 'event_espresso'), $code).'</span>' : '';
209 209
         $html .= EEH_HTML::td($type_html, '', 'jst-left');
210 210
 
211 211
 
212 212
         // Amount Column
213 213
         if ($line_item->is_percent()) {
214
-            $html .= EEH_HTML::td($line_item->percent() . '%', '', 'jst-rght');
214
+            $html .= EEH_HTML::td($line_item->percent().'%', '', 'jst-rght');
215 215
         } else {
216 216
             $html .= EEH_HTML::td($line_item->unit_price_no_code(), '', 'jst-rght');
217 217
         }
@@ -286,7 +286,7 @@  discard block
 block discarded – undo
286 286
         // start of row
287 287
         $html = EEH_HTML::tr('', 'admin-primary-mbox-taxes-tr');
288 288
         // name th
289
-        $html .= EEH_HTML::th($line_item->name() . '(' . $line_item->get_pretty('LIN_percent') . '%)', '', 'jst-rght', '', ' colspan="4"');
289
+        $html .= EEH_HTML::th($line_item->name().'('.$line_item->get_pretty('LIN_percent').'%)', '', 'jst-rght', '', ' colspan="4"');
290 290
         // total th
291 291
         $html .= EEH_HTML::th(EEH_Template::format_currency($line_item->total(), false, false), '', 'jst-rght');
292 292
         // end of row
@@ -325,7 +325,7 @@  discard block
 block discarded – undo
325 325
         // start of row
326 326
         $html = EEH_HTML::tr('', '', 'admin-primary-mbox-total-tr');
327 327
         // Total th label
328
-        $total_label = sprintf(__('Transaction Total %s', 'event_espresso'), '(' . EE_Registry::instance()->CFG->currency->code . ')');
328
+        $total_label = sprintf(__('Transaction Total %s', 'event_espresso'), '('.EE_Registry::instance()->CFG->currency->code.')');
329 329
         $html .= EEH_HTML::th($total_label, '', 'jst-rght', '', ' colspan="4"');
330 330
         // total th
331 331
 
Please login to merge, or discard this patch.
line_item_display/EE_Default_Line_Item_Display_Strategy.strategy.php 3 patches
Doc Comments   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -58,7 +58,7 @@  discard block
 block discarded – undo
58 58
     /**
59 59
      * @param EE_Line_Item $line_item
60 60
      * @param array        $options
61
-     * @return mixed
61
+     * @return string
62 62
      */
63 63
     public function display_line_item(EE_Line_Item $line_item, $options = array())
64 64
     {
@@ -134,7 +134,7 @@  discard block
 block discarded – undo
134 134
      *
135 135
      * @param EE_Line_Item $line_item
136 136
      * @param array        $options
137
-     * @return mixed
137
+     * @return string
138 138
      */
139 139
     private function _item_row(EE_Line_Item $line_item, $options = array())
140 140
     {
@@ -189,7 +189,7 @@  discard block
 block discarded – undo
189 189
      *
190 190
      * @param EE_Line_Item $line_item
191 191
      * @param array        $options
192
-     * @return mixed
192
+     * @return string
193 193
      */
194 194
     private function _sub_item_row(EE_Line_Item $line_item, $options = array())
195 195
     {
Please login to merge, or discard this patch.
Indentation   +208 added lines, -208 removed lines patch added patch discarded remove patch
@@ -1,215 +1,215 @@
 block discarded – undo
1 1
 <?php
2 2
  /**
3
- *
4
- * Class EE_Default_Line_Item_Display_Strategy
5
- *
6
- * Description
7
- *
8
- * @package         Event Espresso
9
- * @subpackage    core
10
- * @author              Brent Christensen
11
- *
12
- *
13
- */
3
+  *
4
+  * Class EE_Default_Line_Item_Display_Strategy
5
+  *
6
+  * Description
7
+  *
8
+  * @package         Event Espresso
9
+  * @subpackage    core
10
+  * @author              Brent Christensen
11
+  *
12
+  *
13
+  */
14 14
 
15 15
 class EE_Default_Line_Item_Display_Strategy implements EEI_Line_Item_Display
16 16
 {
17 17
 
18
-    /**
19
-     * total amount of tax to apply
20
-     * @type float $_tax_rate
21
-     */
22
-    private $_tax_rate = 0;
23
-
24
-    /**
25
-     * total amount including tax we can bill for at this time
26
-     * @type float $_grand_total
27
-     */
28
-    private $_grand_total = 0.00;
29
-
30
-    /**
31
-     * total number of items being billed for
32
-     * @type int $_total_items
33
-     */
34
-    private $_total_items = 0;
35
-
36
-
37
-
38
-    /**
39
-     * @return float
40
-     */
41
-    public function grand_total()
42
-    {
43
-        return $this->_grand_total;
44
-    }
45
-
46
-
47
-
48
-    /**
49
-     * @return int
50
-     */
51
-    public function total_items()
52
-    {
53
-        return $this->_total_items;
54
-    }
55
-
56
-
57
-
58
-    /**
59
-     * @param EE_Line_Item $line_item
60
-     * @param array        $options
61
-     * @return mixed
62
-     */
63
-    public function display_line_item(EE_Line_Item $line_item, $options = array())
64
-    {
65
-
66
-        $html = '';
67
-        // set some default options and merge with incoming
68
-        $default_options = array(
69
-            'show_desc' => true,  //    TRUE        FALSE
70
-            'odd' => false
71
-        );
72
-        $options = array_merge($default_options, (array) $options);
73
-
74
-        switch ($line_item->type()) {
75
-            case EEM_Line_Item::type_line_item:
76
-                // item row
77
-                $html .= $this->_item_row($line_item, $options);
78
-                // got any kids?
79
-                foreach ($line_item->children() as $child_line_item) {
80
-                    $this->display_line_item($child_line_item, $options);
81
-                }
82
-                break;
83
-
84
-            case EEM_Line_Item::type_sub_line_item:
85
-                $html .= $this->_sub_item_row($line_item, $options);
86
-                break;
87
-
88
-            case EEM_Line_Item::type_sub_total:
89
-                break;
90
-
91
-            case EEM_Line_Item::type_tax:
92
-                $this->_tax_rate += $line_item->percent();
93
-                break;
94
-
95
-            case EEM_Line_Item::type_tax_sub_total:
96
-                foreach ($line_item->children() as $child_line_item) {
97
-                    if ($child_line_item->type() == EEM_Line_Item::type_tax) {
98
-                        // recursively feed children back into this method
99
-                        $this->display_line_item($child_line_item, $options);
100
-                    }
101
-                }
102
-                break;
103
-
104
-            case EEM_Line_Item::type_total:
105
-                // get all child line items
106
-                $children = $line_item->children();
107
-                if ($options['set_tax_rate'] === true) {
108
-                    // loop thru tax child line items just to determine tax rate
109
-                    foreach ($children as $child_line_item) {
110
-                        if ($child_line_item->type() == EEM_Line_Item::type_tax_sub_total) {
111
-                            // recursively feed children back into this method
112
-                            $this->display_line_item($child_line_item, $options);
113
-                        }
114
-                    }
115
-                } else {
116
-                    // now loop thru all non-tax child line items
117
-                    foreach ($children as $child_line_item) {
118
-                        if ($child_line_item->type() != EEM_Line_Item::type_tax_sub_total) {
119
-                            // recursively feed children back into this method
120
-                            $html .= $this->display_line_item($child_line_item, $options);
121
-                        }
122
-                    }
123
-                }
124
-                break;
125
-        }
126
-
127
-        return $html;
128
-    }
129
-
130
-
131
-
132
-    /**
133
-     *  _total_row
134
-     *
135
-     * @param EE_Line_Item $line_item
136
-     * @param array        $options
137
-     * @return mixed
138
-     */
139
-    private function _item_row(EE_Line_Item $line_item, $options = array())
140
-    {
141
-        // start of row
142
-        $row_class = $options['odd'] ? 'item odd' : 'item';
143
-        $html = EEH_HTML::tr('', '', $row_class);
144
-        // name && desc
145
-        $name_and_desc = apply_filters(
146
-            'FHEE__EE_Default_Line_Item_Display_Strategy__item_row__name',
147
-            $line_item->name(),
148
-            $line_item
149
-        );
150
-        $name_and_desc .= apply_filters(
151
-            'FHEE__EE_Default_Line_Item_Display_Strategy__item_row__desc',
152
-            ( $options['show_desc'] ? '<span class="line-item-desc-spn smaller-text">: ' . $line_item->desc() . '</span>' : '' ),
153
-            $line_item,
154
-            $options
155
-        );
156
-        if ($line_item->is_taxable()) {
157
-            $ticket_price_includes_taxes = EE_Registry::instance()->CFG->tax_settings->prices_displayed_including_taxes
158
-                ? __('* price includes taxes', 'event_espresso')
159
-                : __('* price does not include taxes', 'event_espresso');
160
-            $name_and_desc .= '<span class="smaller-text lt-grey-text" style="margin:0 0 0 2em;">'
161
-                  . $ticket_price_includes_taxes
162
-                  . '</span>';
163
-        }
164
-
165
-        // name td
166
-        $html .= EEH_HTML::td($name_and_desc, '', 'item_l');
167
-        // quantity td
168
-        $html .= EEH_HTML::td($line_item->quantity(), '', 'item_l jst-rght');
169
-        $tax_rate = $line_item->is_taxable()
170
-                    && EE_Registry::instance()->CFG->tax_settings->prices_displayed_including_taxes
171
-            ? 1 + ( $this->_tax_rate / 100 )
172
-            : 1;
173
-        // price td
174
-        $unit_price = EEH_Template::format_currency($line_item->unit_price() * $tax_rate, false, false);
175
-        $html .= EEH_HTML::td($unit_price, '', 'item_c jst-rght');
176
-        // total td
177
-        $total = EEH_Template::format_currency($line_item->unit_price() * $line_item->quantity() * $tax_rate, false, false);
178
-        $html .= EEH_HTML::td($total, '', 'item_r jst-rght');
179
-        // end of row
180
-        $html .= EEH_HTML::trx();
181
-
182
-        return $html;
183
-    }
184
-
185
-
186
-
187
-    /**
188
-     *  _sub_item_row
189
-     *
190
-     * @param EE_Line_Item $line_item
191
-     * @param array        $options
192
-     * @return mixed
193
-     */
194
-    private function _sub_item_row(EE_Line_Item $line_item, $options = array())
195
-    {
196
-        // start of row
197
-        $html = EEH_HTML::tr('', 'item sub-item-row');
198
-        // name && desc
199
-        $name_and_desc = $line_item->name();
200
-        $name_and_desc .= $options['show_desc'] ? '<span class="line-sub-item-desc-spn smaller-text">: ' . $line_item->desc() . '</span>' : '';
201
-        // name td
202
-        $html .= EEH_HTML::td(/*__FUNCTION__ .*/ $name_and_desc, '', 'item_l sub-item');
203
-        // discount/surcharge td
204
-        if ($line_item->is_percent()) {
205
-            $html .= EEH_HTML::td($line_item->percent() . '%', '', 'item_c');
206
-        } else {
207
-            $html .= EEH_HTML::td($line_item->unit_price_no_code(), '', 'item_c jst-rght');
208
-        }
209
-        // total td
210
-        $html .= EEH_HTML::td(EEH_Template::format_currency($line_item->total(), false, false), '', 'item_r jst-rght');
211
-        // end of row
212
-        $html .= EEH_HTML::trx();
213
-        return $html;
214
-    }
18
+	/**
19
+	 * total amount of tax to apply
20
+	 * @type float $_tax_rate
21
+	 */
22
+	private $_tax_rate = 0;
23
+
24
+	/**
25
+	 * total amount including tax we can bill for at this time
26
+	 * @type float $_grand_total
27
+	 */
28
+	private $_grand_total = 0.00;
29
+
30
+	/**
31
+	 * total number of items being billed for
32
+	 * @type int $_total_items
33
+	 */
34
+	private $_total_items = 0;
35
+
36
+
37
+
38
+	/**
39
+	 * @return float
40
+	 */
41
+	public function grand_total()
42
+	{
43
+		return $this->_grand_total;
44
+	}
45
+
46
+
47
+
48
+	/**
49
+	 * @return int
50
+	 */
51
+	public function total_items()
52
+	{
53
+		return $this->_total_items;
54
+	}
55
+
56
+
57
+
58
+	/**
59
+	 * @param EE_Line_Item $line_item
60
+	 * @param array        $options
61
+	 * @return mixed
62
+	 */
63
+	public function display_line_item(EE_Line_Item $line_item, $options = array())
64
+	{
65
+
66
+		$html = '';
67
+		// set some default options and merge with incoming
68
+		$default_options = array(
69
+			'show_desc' => true,  //    TRUE        FALSE
70
+			'odd' => false
71
+		);
72
+		$options = array_merge($default_options, (array) $options);
73
+
74
+		switch ($line_item->type()) {
75
+			case EEM_Line_Item::type_line_item:
76
+				// item row
77
+				$html .= $this->_item_row($line_item, $options);
78
+				// got any kids?
79
+				foreach ($line_item->children() as $child_line_item) {
80
+					$this->display_line_item($child_line_item, $options);
81
+				}
82
+				break;
83
+
84
+			case EEM_Line_Item::type_sub_line_item:
85
+				$html .= $this->_sub_item_row($line_item, $options);
86
+				break;
87
+
88
+			case EEM_Line_Item::type_sub_total:
89
+				break;
90
+
91
+			case EEM_Line_Item::type_tax:
92
+				$this->_tax_rate += $line_item->percent();
93
+				break;
94
+
95
+			case EEM_Line_Item::type_tax_sub_total:
96
+				foreach ($line_item->children() as $child_line_item) {
97
+					if ($child_line_item->type() == EEM_Line_Item::type_tax) {
98
+						// recursively feed children back into this method
99
+						$this->display_line_item($child_line_item, $options);
100
+					}
101
+				}
102
+				break;
103
+
104
+			case EEM_Line_Item::type_total:
105
+				// get all child line items
106
+				$children = $line_item->children();
107
+				if ($options['set_tax_rate'] === true) {
108
+					// loop thru tax child line items just to determine tax rate
109
+					foreach ($children as $child_line_item) {
110
+						if ($child_line_item->type() == EEM_Line_Item::type_tax_sub_total) {
111
+							// recursively feed children back into this method
112
+							$this->display_line_item($child_line_item, $options);
113
+						}
114
+					}
115
+				} else {
116
+					// now loop thru all non-tax child line items
117
+					foreach ($children as $child_line_item) {
118
+						if ($child_line_item->type() != EEM_Line_Item::type_tax_sub_total) {
119
+							// recursively feed children back into this method
120
+							$html .= $this->display_line_item($child_line_item, $options);
121
+						}
122
+					}
123
+				}
124
+				break;
125
+		}
126
+
127
+		return $html;
128
+	}
129
+
130
+
131
+
132
+	/**
133
+	 *  _total_row
134
+	 *
135
+	 * @param EE_Line_Item $line_item
136
+	 * @param array        $options
137
+	 * @return mixed
138
+	 */
139
+	private function _item_row(EE_Line_Item $line_item, $options = array())
140
+	{
141
+		// start of row
142
+		$row_class = $options['odd'] ? 'item odd' : 'item';
143
+		$html = EEH_HTML::tr('', '', $row_class);
144
+		// name && desc
145
+		$name_and_desc = apply_filters(
146
+			'FHEE__EE_Default_Line_Item_Display_Strategy__item_row__name',
147
+			$line_item->name(),
148
+			$line_item
149
+		);
150
+		$name_and_desc .= apply_filters(
151
+			'FHEE__EE_Default_Line_Item_Display_Strategy__item_row__desc',
152
+			( $options['show_desc'] ? '<span class="line-item-desc-spn smaller-text">: ' . $line_item->desc() . '</span>' : '' ),
153
+			$line_item,
154
+			$options
155
+		);
156
+		if ($line_item->is_taxable()) {
157
+			$ticket_price_includes_taxes = EE_Registry::instance()->CFG->tax_settings->prices_displayed_including_taxes
158
+				? __('* price includes taxes', 'event_espresso')
159
+				: __('* price does not include taxes', 'event_espresso');
160
+			$name_and_desc .= '<span class="smaller-text lt-grey-text" style="margin:0 0 0 2em;">'
161
+				  . $ticket_price_includes_taxes
162
+				  . '</span>';
163
+		}
164
+
165
+		// name td
166
+		$html .= EEH_HTML::td($name_and_desc, '', 'item_l');
167
+		// quantity td
168
+		$html .= EEH_HTML::td($line_item->quantity(), '', 'item_l jst-rght');
169
+		$tax_rate = $line_item->is_taxable()
170
+					&& EE_Registry::instance()->CFG->tax_settings->prices_displayed_including_taxes
171
+			? 1 + ( $this->_tax_rate / 100 )
172
+			: 1;
173
+		// price td
174
+		$unit_price = EEH_Template::format_currency($line_item->unit_price() * $tax_rate, false, false);
175
+		$html .= EEH_HTML::td($unit_price, '', 'item_c jst-rght');
176
+		// total td
177
+		$total = EEH_Template::format_currency($line_item->unit_price() * $line_item->quantity() * $tax_rate, false, false);
178
+		$html .= EEH_HTML::td($total, '', 'item_r jst-rght');
179
+		// end of row
180
+		$html .= EEH_HTML::trx();
181
+
182
+		return $html;
183
+	}
184
+
185
+
186
+
187
+	/**
188
+	 *  _sub_item_row
189
+	 *
190
+	 * @param EE_Line_Item $line_item
191
+	 * @param array        $options
192
+	 * @return mixed
193
+	 */
194
+	private function _sub_item_row(EE_Line_Item $line_item, $options = array())
195
+	{
196
+		// start of row
197
+		$html = EEH_HTML::tr('', 'item sub-item-row');
198
+		// name && desc
199
+		$name_and_desc = $line_item->name();
200
+		$name_and_desc .= $options['show_desc'] ? '<span class="line-sub-item-desc-spn smaller-text">: ' . $line_item->desc() . '</span>' : '';
201
+		// name td
202
+		$html .= EEH_HTML::td(/*__FUNCTION__ .*/ $name_and_desc, '', 'item_l sub-item');
203
+		// discount/surcharge td
204
+		if ($line_item->is_percent()) {
205
+			$html .= EEH_HTML::td($line_item->percent() . '%', '', 'item_c');
206
+		} else {
207
+			$html .= EEH_HTML::td($line_item->unit_price_no_code(), '', 'item_c jst-rght');
208
+		}
209
+		// total td
210
+		$html .= EEH_HTML::td(EEH_Template::format_currency($line_item->total(), false, false), '', 'item_r jst-rght');
211
+		// end of row
212
+		$html .= EEH_HTML::trx();
213
+		return $html;
214
+	}
215 215
 }
Please login to merge, or discard this patch.
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -66,7 +66,7 @@  discard block
 block discarded – undo
66 66
         $html = '';
67 67
         // set some default options and merge with incoming
68 68
         $default_options = array(
69
-            'show_desc' => true,  //    TRUE        FALSE
69
+            'show_desc' => true, //    TRUE        FALSE
70 70
             'odd' => false
71 71
         );
72 72
         $options = array_merge($default_options, (array) $options);
@@ -149,7 +149,7 @@  discard block
 block discarded – undo
149 149
         );
150 150
         $name_and_desc .= apply_filters(
151 151
             'FHEE__EE_Default_Line_Item_Display_Strategy__item_row__desc',
152
-            ( $options['show_desc'] ? '<span class="line-item-desc-spn smaller-text">: ' . $line_item->desc() . '</span>' : '' ),
152
+            ($options['show_desc'] ? '<span class="line-item-desc-spn smaller-text">: '.$line_item->desc().'</span>' : ''),
153 153
             $line_item,
154 154
             $options
155 155
         );
@@ -168,7 +168,7 @@  discard block
 block discarded – undo
168 168
         $html .= EEH_HTML::td($line_item->quantity(), '', 'item_l jst-rght');
169 169
         $tax_rate = $line_item->is_taxable()
170 170
                     && EE_Registry::instance()->CFG->tax_settings->prices_displayed_including_taxes
171
-            ? 1 + ( $this->_tax_rate / 100 )
171
+            ? 1 + ($this->_tax_rate / 100)
172 172
             : 1;
173 173
         // price td
174 174
         $unit_price = EEH_Template::format_currency($line_item->unit_price() * $tax_rate, false, false);
@@ -197,12 +197,12 @@  discard block
 block discarded – undo
197 197
         $html = EEH_HTML::tr('', 'item sub-item-row');
198 198
         // name && desc
199 199
         $name_and_desc = $line_item->name();
200
-        $name_and_desc .= $options['show_desc'] ? '<span class="line-sub-item-desc-spn smaller-text">: ' . $line_item->desc() . '</span>' : '';
200
+        $name_and_desc .= $options['show_desc'] ? '<span class="line-sub-item-desc-spn smaller-text">: '.$line_item->desc().'</span>' : '';
201 201
         // name td
202 202
         $html .= EEH_HTML::td(/*__FUNCTION__ .*/ $name_and_desc, '', 'item_l sub-item');
203 203
         // discount/surcharge td
204 204
         if ($line_item->is_percent()) {
205
-            $html .= EEH_HTML::td($line_item->percent() . '%', '', 'item_c');
205
+            $html .= EEH_HTML::td($line_item->percent().'%', '', 'item_c');
206 206
         } else {
207 207
             $html .= EEH_HTML::td($line_item->unit_price_no_code(), '', 'item_c jst-rght');
208 208
         }
Please login to merge, or discard this patch.
line_item_display/EE_Invoice_Line_Item_Display_Strategy.strategy.php 3 patches
Doc Comments   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -17,7 +17,7 @@  discard block
 block discarded – undo
17 17
     /**
18 18
      * @param EE_Line_Item $line_item
19 19
      * @param array        $options
20
-     * @return mixed
20
+     * @return string
21 21
      */
22 22
     public function display_line_item(EE_Line_Item $line_item, $options = array())
23 23
     {
@@ -92,7 +92,7 @@  discard block
 block discarded – undo
92 92
      *
93 93
      * @param EE_Line_Item $line_item
94 94
      * @param array        $options
95
-     * @return mixed
95
+     * @return string
96 96
      */
97 97
     private function _item_row(EE_Line_Item $line_item, $options = array())
98 98
     {
@@ -122,7 +122,7 @@  discard block
 block discarded – undo
122 122
      *
123 123
      * @param EE_Line_Item $line_item
124 124
      * @param array        $options
125
-     * @return mixed
125
+     * @return string
126 126
      */
127 127
     private function _sub_item_row(EE_Line_Item $line_item, $options = array())
128 128
     {
@@ -153,7 +153,7 @@  discard block
 block discarded – undo
153 153
      *
154 154
      * @param EE_Line_Item $line_item
155 155
      * @param array        $options
156
-     * @return mixed
156
+     * @return string
157 157
      */
158 158
     private function _tax_row(EE_Line_Item $line_item, $options = array())
159 159
     {
@@ -180,7 +180,7 @@  discard block
 block discarded – undo
180 180
      * @param EE_Line_Item $line_item
181 181
      * @param string       $text
182 182
      * @param array        $options
183
-     * @return mixed
183
+     * @return string
184 184
      */
185 185
     private function _total_row(EE_Line_Item $line_item, $text = '', $options = array())
186 186
     {
@@ -205,7 +205,7 @@  discard block
 block discarded – undo
205 205
      *  _separator_row
206 206
      *
207 207
      * @param array        $options
208
-     * @return mixed
208
+     * @return string
209 209
      */
210 210
     private function _separator_row($options = array())
211 211
     {
Please login to merge, or discard this patch.
Indentation   +212 added lines, -212 removed lines patch added patch discarded remove patch
@@ -1,222 +1,222 @@
 block discarded – undo
1 1
 <?php
2 2
  /**
3
- *
4
- * Class EE_Invoice_Line_Item_Display_Strategy
5
- *
6
- * Description
7
- *
8
- * @package         Event Espresso
9
- * @subpackage    core
10
- * @author              Brent Christensen
11
- *
12
- *
13
- */
3
+  *
4
+  * Class EE_Invoice_Line_Item_Display_Strategy
5
+  *
6
+  * Description
7
+  *
8
+  * @package         Event Espresso
9
+  * @subpackage    core
10
+  * @author              Brent Christensen
11
+  *
12
+  *
13
+  */
14 14
 class EE_Invoice_Line_Item_Display_Strategy implements EEI_Line_Item_Display
15 15
 {
16 16
 
17
-    /**
18
-     * @param EE_Line_Item $line_item
19
-     * @param array        $options
20
-     * @return mixed
21
-     */
22
-    public function display_line_item(EE_Line_Item $line_item, $options = array())
23
-    {
24
-
25
-        $html = '';
26
-        // set some default options and merge with incoming
27
-        $default_options = array(
28
-            'show_desc' => true,
29
-            'odd' => false
30
-        );
31
-        $options = array_merge($default_options, (array) $options);
32
-
33
-        switch ($line_item->type()) {
34
-            case EEM_Line_Item::type_total:
35
-                // loop thru children
36
-                foreach ($line_item->children() as $child_line_item) {
37
-                    // recursively feed children back into this method
38
-                    $html .= $this->display_line_item($child_line_item, $options);
39
-                }
40
-                $html .= $this->_separator_row($options);
41
-                $html .= $this->_total_row($line_item, __('Total', 'event_espresso'), $options);
42
-                break;
43
-
44
-
45
-            case EEM_Line_Item::type_sub_total:
46
-                // loop thru children
47
-                foreach ($line_item->children() as $child_line_item) {
48
-                    // recursively feed children back into this method
49
-                    $html .= $this->display_line_item($child_line_item, $options);
50
-                }
51
-                $html .= $this->_total_row($line_item, __('Sub-Total', 'event_espresso'), $options);
52
-                break;
53
-
54
-
55
-            case EEM_Line_Item::type_tax_sub_total:
56
-                // loop thru children
57
-                foreach ($line_item->children() as $child_line_item) {
58
-                    // recursively feed children back into this method
59
-                    $html .= $this->display_line_item($child_line_item, $options);
60
-                }
61
-                $html .= $this->_total_row($line_item, __('Tax Total', 'event_espresso'), $options);
62
-                break;
63
-
64
-
65
-            case EEM_Line_Item::type_line_item:
66
-                // item row
67
-                $html .= $this->_item_row($line_item, $options);
68
-                // got any kids?
69
-                foreach ($line_item->children() as $child_line_item) {
70
-                    $this->display_line_item($child_line_item, $options);
71
-                }
72
-                break;
73
-
74
-
75
-            case EEM_Line_Item::type_sub_line_item:
76
-                $html .= $this->_sub_item_row($line_item, $options);
77
-                break;
78
-
79
-
80
-            case EEM_Line_Item::type_tax:
81
-                $html .= $this->_tax_row($line_item, $options);
82
-                break;
83
-        }
84
-
85
-        return $html;
86
-    }
87
-
88
-
89
-
90
-    /**
91
-     *  _total_row
92
-     *
93
-     * @param EE_Line_Item $line_item
94
-     * @param array        $options
95
-     * @return mixed
96
-     */
97
-    private function _item_row(EE_Line_Item $line_item, $options = array())
98
-    {
99
-        // start of row
100
-        $row_class = $options['odd'] ? 'item odd' : 'item';
101
-        $html = EEH_HTML::tr('', $row_class);
102
-        // name td
103
-        $html .= EEH_HTML::td($line_item->name(), '', 'item_l');
104
-        // desc td
105
-        $html .= $options['show_desc'] ? EEH_HTML::td($line_item->desc(), '', 'item_l') : '';
106
-        // quantity td
107
-        $html .= EEH_HTML::td($line_item->quantity(), '', 'item_l');
108
-        // price td
109
-        $html .= EEH_HTML::td($line_item->unit_price_no_code(), '', 'item_c');
110
-        // total td
111
-        $total = $line_item->is_taxable() ? $line_item->total_no_code() . '*' : $line_item->total_no_code();
112
-        $html .= EEH_HTML::td($total, '', 'item_r');
113
-        // end of row
114
-        $html .= EEH_HTML::trx();
115
-        return $html;
116
-    }
117
-
118
-
119
-
120
-    /**
121
-     *  _sub_item_row
122
-     *
123
-     * @param EE_Line_Item $line_item
124
-     * @param array        $options
125
-     * @return mixed
126
-     */
127
-    private function _sub_item_row(EE_Line_Item $line_item, $options = array())
128
-    {
129
-        // start of row
130
-        $html = EEH_HTML::tr('', 'item sub-item-row');
131
-        // name td
132
-        $html .= EEH_HTML::td($line_item->name(), '', 'item_l sub-item');
133
-        // desc td
134
-        $html .= $options['show_desc'] ? EEH_HTML::td($line_item->desc(), '', 'item_l') : '';
135
-        $html .= EEH_HTML::td() . EEH_HTML::tdx();
136
-        // discount/surcharge td
137
-        if ($line_item->is_percent()) {
138
-            $html .= EEH_HTML::td($line_item->percent() . '%', '', 'item_c');
139
-        } else {
140
-            $html .= EEH_HTML::td($line_item->unit_price_no_code(), '', 'item_c');
141
-        }
142
-        // total td
143
-        $html .= EEH_HTML::td($line_item->total_no_code(), '', 'item_r');
144
-        // end of row
145
-        $html .= EEH_HTML::trx();
146
-        return $html;
147
-    }
148
-
149
-
150
-
151
-    /**
152
-     *  _tax_row
153
-     *
154
-     * @param EE_Line_Item $line_item
155
-     * @param array        $options
156
-     * @return mixed
157
-     */
158
-    private function _tax_row(EE_Line_Item $line_item, $options = array())
159
-    {
160
-        // start of row
161
-        $html = EEH_HTML::tr('', 'item sub-item tax-total');
162
-        // name td
163
-        $html .= EEH_HTML::td($line_item->name(), '', 'item_l sub-item');
164
-        // desc td
165
-        $html .= $options['show_desc'] ? EEH_HTML::td($line_item->desc(), '', 'item_l') : '';
166
-        // percent td
167
-        $html .= EEH_HTML::td($line_item->percent() . '%', '', 'item_c', '', ' colspan="2"');
168
-        // total td
169
-        $html .= EEH_HTML::td($line_item->total_no_code(), '', 'item_r');
170
-        // end of row
171
-        $html .= EEH_HTML::trx();
172
-        return $html;
173
-    }
174
-
175
-
176
-
177
-    /**
178
-     *  _total_row
179
-     *
180
-     * @param EE_Line_Item $line_item
181
-     * @param string       $text
182
-     * @param array        $options
183
-     * @return mixed
184
-     */
185
-    private function _total_row(EE_Line_Item $line_item, $text = '', $options = array())
186
-    {
187
-        // colspan
188
-        $colspan = $options['show_desc'] ? ' colspan="2"' : '';
189
-        // start of row
190
-        $html = EEH_HTML::tr('', '', 'total_tr odd');
191
-        // empty td
192
-        $html .= EEH_HTML::td(EEH_HTML::nbsp(), '', '', '', $colspan);
193
-        // total td
194
-        $html .= EEH_HTML::td($text, '', 'total_currency total', '', $colspan);
195
-        // total td
196
-        $html .= EEH_HTML::td($line_item->total_no_code(), '', 'total');
197
-        // end of row
198
-        $html .= EEH_HTML::trx();
199
-        return $html;
200
-    }
201
-
202
-
203
-
204
-    /**
205
-     *  _separator_row
206
-     *
207
-     * @param array        $options
208
-     * @return mixed
209
-     */
210
-    private function _separator_row($options = array())
211
-    {
212
-        // colspan
213
-        $colspan = $options['show_desc'] ? ' colspan="5"' : ' colspan="4"';
214
-        // start of row
215
-        $html = EEH_HTML::tr(EEH_HTML::td('<hr>', '', '', '', $colspan));
17
+	/**
18
+	 * @param EE_Line_Item $line_item
19
+	 * @param array        $options
20
+	 * @return mixed
21
+	 */
22
+	public function display_line_item(EE_Line_Item $line_item, $options = array())
23
+	{
24
+
25
+		$html = '';
26
+		// set some default options and merge with incoming
27
+		$default_options = array(
28
+			'show_desc' => true,
29
+			'odd' => false
30
+		);
31
+		$options = array_merge($default_options, (array) $options);
32
+
33
+		switch ($line_item->type()) {
34
+			case EEM_Line_Item::type_total:
35
+				// loop thru children
36
+				foreach ($line_item->children() as $child_line_item) {
37
+					// recursively feed children back into this method
38
+					$html .= $this->display_line_item($child_line_item, $options);
39
+				}
40
+				$html .= $this->_separator_row($options);
41
+				$html .= $this->_total_row($line_item, __('Total', 'event_espresso'), $options);
42
+				break;
43
+
44
+
45
+			case EEM_Line_Item::type_sub_total:
46
+				// loop thru children
47
+				foreach ($line_item->children() as $child_line_item) {
48
+					// recursively feed children back into this method
49
+					$html .= $this->display_line_item($child_line_item, $options);
50
+				}
51
+				$html .= $this->_total_row($line_item, __('Sub-Total', 'event_espresso'), $options);
52
+				break;
53
+
54
+
55
+			case EEM_Line_Item::type_tax_sub_total:
56
+				// loop thru children
57
+				foreach ($line_item->children() as $child_line_item) {
58
+					// recursively feed children back into this method
59
+					$html .= $this->display_line_item($child_line_item, $options);
60
+				}
61
+				$html .= $this->_total_row($line_item, __('Tax Total', 'event_espresso'), $options);
62
+				break;
63
+
64
+
65
+			case EEM_Line_Item::type_line_item:
66
+				// item row
67
+				$html .= $this->_item_row($line_item, $options);
68
+				// got any kids?
69
+				foreach ($line_item->children() as $child_line_item) {
70
+					$this->display_line_item($child_line_item, $options);
71
+				}
72
+				break;
73
+
74
+
75
+			case EEM_Line_Item::type_sub_line_item:
76
+				$html .= $this->_sub_item_row($line_item, $options);
77
+				break;
78
+
79
+
80
+			case EEM_Line_Item::type_tax:
81
+				$html .= $this->_tax_row($line_item, $options);
82
+				break;
83
+		}
84
+
85
+		return $html;
86
+	}
87
+
88
+
89
+
90
+	/**
91
+	 *  _total_row
92
+	 *
93
+	 * @param EE_Line_Item $line_item
94
+	 * @param array        $options
95
+	 * @return mixed
96
+	 */
97
+	private function _item_row(EE_Line_Item $line_item, $options = array())
98
+	{
99
+		// start of row
100
+		$row_class = $options['odd'] ? 'item odd' : 'item';
101
+		$html = EEH_HTML::tr('', $row_class);
102
+		// name td
103
+		$html .= EEH_HTML::td($line_item->name(), '', 'item_l');
104
+		// desc td
105
+		$html .= $options['show_desc'] ? EEH_HTML::td($line_item->desc(), '', 'item_l') : '';
106
+		// quantity td
107
+		$html .= EEH_HTML::td($line_item->quantity(), '', 'item_l');
108
+		// price td
109
+		$html .= EEH_HTML::td($line_item->unit_price_no_code(), '', 'item_c');
110
+		// total td
111
+		$total = $line_item->is_taxable() ? $line_item->total_no_code() . '*' : $line_item->total_no_code();
112
+		$html .= EEH_HTML::td($total, '', 'item_r');
113
+		// end of row
114
+		$html .= EEH_HTML::trx();
115
+		return $html;
116
+	}
117
+
118
+
119
+
120
+	/**
121
+	 *  _sub_item_row
122
+	 *
123
+	 * @param EE_Line_Item $line_item
124
+	 * @param array        $options
125
+	 * @return mixed
126
+	 */
127
+	private function _sub_item_row(EE_Line_Item $line_item, $options = array())
128
+	{
129
+		// start of row
130
+		$html = EEH_HTML::tr('', 'item sub-item-row');
131
+		// name td
132
+		$html .= EEH_HTML::td($line_item->name(), '', 'item_l sub-item');
133
+		// desc td
134
+		$html .= $options['show_desc'] ? EEH_HTML::td($line_item->desc(), '', 'item_l') : '';
135
+		$html .= EEH_HTML::td() . EEH_HTML::tdx();
136
+		// discount/surcharge td
137
+		if ($line_item->is_percent()) {
138
+			$html .= EEH_HTML::td($line_item->percent() . '%', '', 'item_c');
139
+		} else {
140
+			$html .= EEH_HTML::td($line_item->unit_price_no_code(), '', 'item_c');
141
+		}
142
+		// total td
143
+		$html .= EEH_HTML::td($line_item->total_no_code(), '', 'item_r');
144
+		// end of row
145
+		$html .= EEH_HTML::trx();
146
+		return $html;
147
+	}
148
+
149
+
150
+
151
+	/**
152
+	 *  _tax_row
153
+	 *
154
+	 * @param EE_Line_Item $line_item
155
+	 * @param array        $options
156
+	 * @return mixed
157
+	 */
158
+	private function _tax_row(EE_Line_Item $line_item, $options = array())
159
+	{
160
+		// start of row
161
+		$html = EEH_HTML::tr('', 'item sub-item tax-total');
162
+		// name td
163
+		$html .= EEH_HTML::td($line_item->name(), '', 'item_l sub-item');
164
+		// desc td
165
+		$html .= $options['show_desc'] ? EEH_HTML::td($line_item->desc(), '', 'item_l') : '';
166
+		// percent td
167
+		$html .= EEH_HTML::td($line_item->percent() . '%', '', 'item_c', '', ' colspan="2"');
168
+		// total td
169
+		$html .= EEH_HTML::td($line_item->total_no_code(), '', 'item_r');
170
+		// end of row
171
+		$html .= EEH_HTML::trx();
172
+		return $html;
173
+	}
174
+
175
+
176
+
177
+	/**
178
+	 *  _total_row
179
+	 *
180
+	 * @param EE_Line_Item $line_item
181
+	 * @param string       $text
182
+	 * @param array        $options
183
+	 * @return mixed
184
+	 */
185
+	private function _total_row(EE_Line_Item $line_item, $text = '', $options = array())
186
+	{
187
+		// colspan
188
+		$colspan = $options['show_desc'] ? ' colspan="2"' : '';
189
+		// start of row
190
+		$html = EEH_HTML::tr('', '', 'total_tr odd');
191
+		// empty td
192
+		$html .= EEH_HTML::td(EEH_HTML::nbsp(), '', '', '', $colspan);
193
+		// total td
194
+		$html .= EEH_HTML::td($text, '', 'total_currency total', '', $colspan);
195
+		// total td
196
+		$html .= EEH_HTML::td($line_item->total_no_code(), '', 'total');
197
+		// end of row
198
+		$html .= EEH_HTML::trx();
199
+		return $html;
200
+	}
201
+
202
+
203
+
204
+	/**
205
+	 *  _separator_row
206
+	 *
207
+	 * @param array        $options
208
+	 * @return mixed
209
+	 */
210
+	private function _separator_row($options = array())
211
+	{
212
+		// colspan
213
+		$colspan = $options['show_desc'] ? ' colspan="5"' : ' colspan="4"';
214
+		// start of row
215
+		$html = EEH_HTML::tr(EEH_HTML::td('<hr>', '', '', '', $colspan));
216 216
 //      // separator td
217 217
 //      $html .= EEH_HTML::td( '<hr>', '',  '',  '',  $colspan );
218 218
 //      // end of row
219 219
 //      $html .= EEH_HTML::trx();
220
-        return $html;
221
-    }
220
+		return $html;
221
+	}
222 222
 }
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -108,7 +108,7 @@  discard block
 block discarded – undo
108 108
         // price td
109 109
         $html .= EEH_HTML::td($line_item->unit_price_no_code(), '', 'item_c');
110 110
         // total td
111
-        $total = $line_item->is_taxable() ? $line_item->total_no_code() . '*' : $line_item->total_no_code();
111
+        $total = $line_item->is_taxable() ? $line_item->total_no_code().'*' : $line_item->total_no_code();
112 112
         $html .= EEH_HTML::td($total, '', 'item_r');
113 113
         // end of row
114 114
         $html .= EEH_HTML::trx();
@@ -132,10 +132,10 @@  discard block
 block discarded – undo
132 132
         $html .= EEH_HTML::td($line_item->name(), '', 'item_l sub-item');
133 133
         // desc td
134 134
         $html .= $options['show_desc'] ? EEH_HTML::td($line_item->desc(), '', 'item_l') : '';
135
-        $html .= EEH_HTML::td() . EEH_HTML::tdx();
135
+        $html .= EEH_HTML::td().EEH_HTML::tdx();
136 136
         // discount/surcharge td
137 137
         if ($line_item->is_percent()) {
138
-            $html .= EEH_HTML::td($line_item->percent() . '%', '', 'item_c');
138
+            $html .= EEH_HTML::td($line_item->percent().'%', '', 'item_c');
139 139
         } else {
140 140
             $html .= EEH_HTML::td($line_item->unit_price_no_code(), '', 'item_c');
141 141
         }
@@ -164,7 +164,7 @@  discard block
 block discarded – undo
164 164
         // desc td
165 165
         $html .= $options['show_desc'] ? EEH_HTML::td($line_item->desc(), '', 'item_l') : '';
166 166
         // percent td
167
-        $html .= EEH_HTML::td($line_item->percent() . '%', '', 'item_c', '', ' colspan="2"');
167
+        $html .= EEH_HTML::td($line_item->percent().'%', '', 'item_c', '', ' colspan="2"');
168 168
         // total td
169 169
         $html .= EEH_HTML::td($line_item->total_no_code(), '', 'item_r');
170 170
         // end of row
Please login to merge, or discard this patch.
line_item_display/EE_Receipt_Line_Item_Display_Strategy.strategy.php 2 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -32,7 +32,7 @@
 block discarded – undo
32 32
     /**
33 33
      * @param EE_Line_Item $line_item
34 34
      * @param array        $options
35
-     * @return mixed
35
+     * @return string
36 36
      */
37 37
     public function display_line_item(EE_Line_Item $line_item, $options = array())
38 38
     {
Please login to merge, or discard this patch.
Indentation   +57 added lines, -57 removed lines patch added patch discarded remove patch
@@ -14,88 +14,88 @@
 block discarded – undo
14 14
  * ------------------------------------------------------------------------
15 15
  */
16 16
  /**
17
- *
18
- * Class EE_Receipt_Line_Item_Display_Strategy
19
- *
20
- * Description
21
- *
22
- * @package         Event Espresso
23
- * @subpackage    core
24
- * @author              Brent Christensen
25
- *
26
- *
27
- */
17
+  *
18
+  * Class EE_Receipt_Line_Item_Display_Strategy
19
+  *
20
+  * Description
21
+  *
22
+  * @package         Event Espresso
23
+  * @subpackage    core
24
+  * @author              Brent Christensen
25
+  *
26
+  *
27
+  */
28 28
 
29 29
 class EE_Receipt_Line_Item_Display_Strategy implements EEI_Line_Item_Display
30 30
 {
31 31
 
32
-    /**
33
-     * @param EE_Line_Item $line_item
34
-     * @param array        $options
35
-     * @return mixed
36
-     */
37
-    public function display_line_item(EE_Line_Item $line_item, $options = array())
38
-    {
32
+	/**
33
+	 * @param EE_Line_Item $line_item
34
+	 * @param array        $options
35
+	 * @return mixed
36
+	 */
37
+	public function display_line_item(EE_Line_Item $line_item, $options = array())
38
+	{
39 39
 
40
-        $html = '';
41
-        // set some default options and merge with incoming
42
-        $default_options = array(
43
-            'show_desc' => true,
44
-            'odd' => false
45
-        );
46
-        $options = array_merge($default_options, (array) $options);
47
-        switch ($line_item->type()) {
48
-            case EEM_Line_Item::type_total:
49
-                // loop thru children
50
-                foreach ($line_item->children() as $child_line_item) {
51
-                    // recursively feed children back into this method
40
+		$html = '';
41
+		// set some default options and merge with incoming
42
+		$default_options = array(
43
+			'show_desc' => true,
44
+			'odd' => false
45
+		);
46
+		$options = array_merge($default_options, (array) $options);
47
+		switch ($line_item->type()) {
48
+			case EEM_Line_Item::type_total:
49
+				// loop thru children
50
+				foreach ($line_item->children() as $child_line_item) {
51
+					// recursively feed children back into this method
52 52
 //                  $html .= $this->display_line_item( $child_line_item, $options );
53
-                }
53
+				}
54 54
 //              $html .= $this->_separator_row( $options );
55 55
 //              $html .= $this->_total_row( $line_item, __('Total', 'event_espresso'), $options );
56
-                break;
56
+				break;
57 57
 
58 58
 
59
-            case EEM_Line_Item::type_sub_total:
60
-                // loop thru children
61
-                foreach ($line_item->children() as $child_line_item) {
62
-                    // recursively feed children back into this method
59
+			case EEM_Line_Item::type_sub_total:
60
+				// loop thru children
61
+				foreach ($line_item->children() as $child_line_item) {
62
+					// recursively feed children back into this method
63 63
 //                  $html .= $this->display_line_item( $child_line_item, $options );
64
-                }
64
+				}
65 65
 //              $html .= $this->_total_row( $line_item, __('Sub-Total', 'event_espresso'), $options );
66
-                break;
66
+				break;
67 67
 
68 68
 
69
-            case EEM_Line_Item::type_tax_sub_total:
70
-                // loop thru children
71
-                foreach ($line_item->children() as $child_line_item) {
72
-                    // recursively feed children back into this method
69
+			case EEM_Line_Item::type_tax_sub_total:
70
+				// loop thru children
71
+				foreach ($line_item->children() as $child_line_item) {
72
+					// recursively feed children back into this method
73 73
 //                  $html .= $this->display_line_item( $child_line_item, $options );
74
-                }
74
+				}
75 75
 //              $html .= $this->_total_row( $line_item, __('Tax Total', 'event_espresso'), $options );
76
-                break;
76
+				break;
77 77
 
78 78
 
79
-            case EEM_Line_Item::type_line_item:
80
-                // item row
79
+			case EEM_Line_Item::type_line_item:
80
+				// item row
81 81
 //              $html .= $this->_item_row( $line_item, $options );
82
-                // got any kids?
83
-                foreach ($line_item->children() as $child_line_item) {
82
+				// got any kids?
83
+				foreach ($line_item->children() as $child_line_item) {
84 84
 //                  $this->display_line_item( $child_line_item, $options );
85
-                }
86
-                break;
85
+				}
86
+				break;
87 87
 
88 88
 
89
-            case EEM_Line_Item::type_sub_line_item:
89
+			case EEM_Line_Item::type_sub_line_item:
90 90
 //              $html .= $this->_sub_item_row( $line_item, $options );
91
-                break;
91
+				break;
92 92
 
93 93
 
94
-            case EEM_Line_Item::type_tax:
94
+			case EEM_Line_Item::type_tax:
95 95
 //              $html .= $this->_tax_row( $line_item, $options );
96
-                break;
97
-        }
96
+				break;
97
+		}
98 98
 
99
-        return $html;
100
-    }
99
+		return $html;
100
+	}
101 101
 }
Please login to merge, or discard this patch.
core/libraries/messages/defaults/EE_Messages_Template_Pack.core.php 3 patches
Doc Comments   +1 added lines patch added patch discarded remove patch
@@ -310,6 +310,7 @@
 block discarded – undo
310 310
      * @param EE_message_type                          $message_type
311 311
      * @param string                                   $field          The field reference for the specific template being looked up.
312 312
      * @param string                                   $context      The context reference for the specific template being looked up
313
+     * @param EE_Messages_Template_Pack_Default|null $default_pack
313 314
      *
314 315
      * @return string          The template contents.
315 316
      */
Please login to merge, or discard this patch.
Indentation   +469 added lines, -469 removed lines patch added patch discarded remove patch
@@ -14,511 +14,511 @@
 block discarded – undo
14 14
 {
15 15
 
16 16
 
17
-    /**
18
-     * This defines the base_path where the templates are located.
19
-     *
20
-     * @since            4.5.0
21
-     *
22
-     * @var string
23
-     */
24
-    protected $_base_path;
17
+	/**
18
+	 * This defines the base_path where the templates are located.
19
+	 *
20
+	 * @since            4.5.0
21
+	 *
22
+	 * @var string
23
+	 */
24
+	protected $_base_path;
25 25
 
26 26
 
27 27
 
28 28
 
29
-    /**
30
-     * This defines the base_url where things are found for this template pack (possibly variations).
31
-     *
32
-     * @since 4.5.0
33
-     *
34
-     * @var string
35
-     */
36
-    protected $_base_url;
29
+	/**
30
+	 * This defines the base_url where things are found for this template pack (possibly variations).
31
+	 *
32
+	 * @since 4.5.0
33
+	 *
34
+	 * @var string
35
+	 */
36
+	protected $_base_url;
37 37
 
38 38
 
39 39
 
40
-    /**
41
-     * localized label for this template pack
42
-     *
43
-     * @since            4.5.0
44
-     *
45
-     * @var string
46
-     */
47
-    public $label;
40
+	/**
41
+	 * localized label for this template pack
42
+	 *
43
+	 * @since            4.5.0
44
+	 *
45
+	 * @var string
46
+	 */
47
+	public $label;
48 48
 
49 49
 
50 50
 
51 51
 
52
-    /**
53
-     * used to contain a description for the template pack.
54
-     *
55
-     * @since 4.5.0
56
-     *
57
-     * @var string
58
-     */
59
-    public $description;
52
+	/**
53
+	 * used to contain a description for the template pack.
54
+	 *
55
+	 * @since 4.5.0
56
+	 *
57
+	 * @var string
58
+	 */
59
+	public $description;
60 60
 
61 61
 
62 62
 
63 63
 
64
-    /**
65
-     * How this template is referenced in the db
66
-     *
67
-     * @since 4.5.0
68
-     *
69
-     * @var string
70
-     */
71
-    public $dbref;
64
+	/**
65
+	 * How this template is referenced in the db
66
+	 *
67
+	 * @since 4.5.0
68
+	 *
69
+	 * @var string
70
+	 */
71
+	public $dbref;
72 72
 
73 73
 
74 74
 
75 75
 
76
-    /**
77
-     * This is an array indexed by messenger and with an array of message types as values that indicate what messenger and message type this template pack supports by default.  It is possible for this to be modified by plugins via filters, but out of the box, this is what the template pack supports.
78
-     *
79
-     * @since 4.5.0
80
-     *
81
-     * @var array.
82
-     */
83
-    protected $_supports = array();
76
+	/**
77
+	 * This is an array indexed by messenger and with an array of message types as values that indicate what messenger and message type this template pack supports by default.  It is possible for this to be modified by plugins via filters, but out of the box, this is what the template pack supports.
78
+	 *
79
+	 * @since 4.5.0
80
+	 *
81
+	 * @var array.
82
+	 */
83
+	protected $_supports = array();
84 84
 
85 85
 
86 86
 
87 87
 
88 88
 
89
-    /**
90
-     * Holds the retrieved default templates for this template pack in a multidimensional array indexed by context and field, for a given messenger and message type.  Example format:
91
-     *
92
-     * $templates = array(
93
-     *  'email' => array(
94
-     *      'registration' => array(
95
-     *          'admin' => array(
96
-     *              'to' => 'contents',
97
-     *              'from' => 'contents',
98
-     *              'subject' => 'contents',
99
-     *              'content' => 'contents',
100
-     *              'event_list' => 'contents',
101
-     *              'attendee_list' => 'contents'
102
-     *          ),
103
-     *          'attendee' => array(
104
-     *              'to' => 'contents',
105
-     *              'from' => 'contents',
106
-     *              'subject' => 'contents',
107
-     *              'content' => 'contents',
108
-     *              'event_list' => 'contents',
109
-     *              'attendee_list' => 'contents',
110
-     *          ),
111
-     *      )
112
-     *  )
113
-     * )
114
-     *
115
-     * @since 4.5.0
116
-     *
117
-     * @var array
118
-     */
119
-    protected $_templates = array();
89
+	/**
90
+	 * Holds the retrieved default templates for this template pack in a multidimensional array indexed by context and field, for a given messenger and message type.  Example format:
91
+	 *
92
+	 * $templates = array(
93
+	 *  'email' => array(
94
+	 *      'registration' => array(
95
+	 *          'admin' => array(
96
+	 *              'to' => 'contents',
97
+	 *              'from' => 'contents',
98
+	 *              'subject' => 'contents',
99
+	 *              'content' => 'contents',
100
+	 *              'event_list' => 'contents',
101
+	 *              'attendee_list' => 'contents'
102
+	 *          ),
103
+	 *          'attendee' => array(
104
+	 *              'to' => 'contents',
105
+	 *              'from' => 'contents',
106
+	 *              'subject' => 'contents',
107
+	 *              'content' => 'contents',
108
+	 *              'event_list' => 'contents',
109
+	 *              'attendee_list' => 'contents',
110
+	 *          ),
111
+	 *      )
112
+	 *  )
113
+	 * )
114
+	 *
115
+	 * @since 4.5.0
116
+	 *
117
+	 * @var array
118
+	 */
119
+	protected $_templates = array();
120 120
 
121 121
 
122 122
 
123 123
 
124 124
 
125 125
 
126
-    /**
127
-     * Template Packs must ALWAYS have a default variation defined.  This property allow one to override the default variation labels per messenger.
128
-     * example:
129
-     * $this->_default_variation_labels = array( 'email' =>  __('Default', 'event_espresso' ) );
130
-     *
131
-     * @var array
132
-     */
133
-    protected $_default_variation_labels = array();
126
+	/**
127
+	 * Template Packs must ALWAYS have a default variation defined.  This property allow one to override the default variation labels per messenger.
128
+	 * example:
129
+	 * $this->_default_variation_labels = array( 'email' =>  __('Default', 'event_espresso' ) );
130
+	 *
131
+	 * @var array
132
+	 */
133
+	protected $_default_variation_labels = array();
134 134
 
135 135
 
136 136
 
137 137
 
138
-    /**
139
-     * This is an array of extra css variations for message templates indexed by messenger with the values as an array or message types the variations apply to as the key  and then values are an array with variation slugs as the key and label as the value. Note the default variation is not included in this array.  So the structure is:
140
-     * array(
141
-     *  'email' => array(
142
-     *  )
143
-     * )
144
-     *
145
-     * Keep in mind that this property is used both for indicating valid variations for a given message type and messenger but the variation files themselves are ONLY unique to the messenger.  So if you have a variation for the html messenger referenced by the slug "sunset_red" Then the variation file for the main type will be html_main_sunset_red.css.  All the array in this property allows you to do, is indicate that with certain message types the sunset_red variation is available but for other message types its not.  But you could NOT have a sunset_red variation file for one messenger/message_type and a different one for another messenger/message_type.  If you want different css looks then you can define a different structural layout for the template , messenger, message type combination and in the same sunset_red.css variation file just add css specific to that layout.
146
-     *
147
-     * @since 4.5.0
148
-     *
149
-     * @var array
150
-     */
151
-    public $_variations = array();
152
-
153
-
154
-
155
-
156
-    /**
157
-     * Template pack constructor
158
-     *
159
-     * @since 4.5.0
160
-     */
161
-    public function __construct()
162
-    {
163
-        $this->_set_props();
164
-        // make sure classname is correct
165
-        $classname = get_class($this);
166
-        // make sure required props have been set
167
-
168
-        // if label is empty then throw an error because we should have it defined by now.
169
-        if (! isset($this->label)) {
170
-            throw new EE_Error(sprintf(__('The label property is not set for %s.  Please ensure that is set for the class.', 'event_espresso'), $classname));
171
-        }
172
-
173
-
174
-        // the reference for this template pack
175
-        if (! isset($this->dbref)) {
176
-            throw new EE_Error(sprintf(__('The dbref property is not set for %s.  Please ensure that is set for the class.', 'event_espresso'), $classname));
177
-        }
178
-
179
-        // make sure dbref is safe
180
-        $this->dbref = str_replace('-', '_', sanitize_key($this->dbref));
181
-
182
-        $should_be = 'EE_Messages_Template_Pack_' . str_replace(' ', '_', ucwords(str_replace('_', ' ', $this->dbref)));
183
-
184
-        if ($should_be !== $classname) {
185
-            throw new EE_Error(sprintf(__('The name of the template pack instantiated class is "%s".  It should be "%s".  Make sure that the name of the template pack class matches is prepended with "EE_Messages_Template_Pack_" and appended with a sentence case iteration of the value for your template pack\'s dbref property.', 'event_espresso'), $classname, $should_be));
186
-        }
187
-
188
-        // if _base_path is not set then throw an error because a base path string is needed.
189
-        if (empty($this->_base_path)) {
190
-            throw new EE_Error(sprintf(__('The _base_path property is not set for %s.  Please ensure that is set for the class.', 'event_espresso'), $classname));
191
-        }
192
-
193
-
194
-        // if _base_url is not set then throw an error because a  string is needed for variations.
195
-        if (empty($this->_base_url)) {
196
-            throw new EE_Error(sprintf(__('The _base_url property is not set for %s.  Please ensure that is set for the class.', 'event_espresso'), $classname));
197
-        }
198
-
199
-
200
-        // if $supports is not set then throw an error because that effectively means this template_pack does not have any templates!
201
-        if (empty($this->_supports)) {
202
-            throw new EE_Error(sprintf(__('The supports property is not set for %s.  Please ensure that is set for the class.', 'event_espresso'), $classname));
203
-        }
204
-    }
205
-
206
-
207
-
208
-    /**
209
-     * This method should be used to define the following properties:
210
-     * - label
211
-     * - dbref
212
-     * - description
213
-     * - _base_path
214
-     * - _base_url
215
-     * - supports
216
-     * - variations
217
-     *
218
-     * @since 4.5.0
219
-     * @return void.
220
-     * @abstract
221
-     */
222
-    abstract protected function _set_props();
223
-
224
-
225
-
226
-
227
-    /**
228
-     * Wrapper for get_templates() ( @see get_templates() for documentation)
229
-     *
230
-     * @since 4.5.0
231
-     *
232
-     * @param EE_messenger    $messenger
233
-     * @param EE_message_type $message_type
234
-     *
235
-     * @return array
236
-     */
237
-    public function get_templates(EE_messenger $messenger, EE_message_type $message_type)
238
-    {
239
-        return isset($this->_templates[ $messenger->name ][ $message_type->name ]) ? $this->_templates[ $messenger->name ][ $message_type->name ] : $this->_get_templates($messenger, $message_type);
240
-    }
241
-
242
-
243
-
244
-
245
-    /**
246
-     * This takes the incoming messenger and message type objects, uses them to get the set fields and contexts, then attempts to retrieve the templates matching those for this given template pack.
247
-     *
248
-     * @since 4.5.0
249
-     *
250
-     * @param EE_messenger    $messenger
251
-     * @param EE_message_type $message_type
252
-     *
253
-     * @return array          Returns an multi-level associative array indexed by template context and field in the format:
254
-     *                                array( 'context' => array( 'field' => 'value', 'another-field', 'value' ) );
255
-     */
256
-    protected function _get_templates(EE_messenger $messenger, EE_message_type $message_type)
257
-    {
258
-        $templates = array();
259
-
260
-        /**
261
-         * Retrieving the default pack for later usage of default templates for template packs that
262
-         * are NOT the default pack ( or an extension of the default pack ).
263
-         * We ONLY set this variable to be the default pack IF the loaded class is NOT the default
264
-         * pack.  This prevents recursion in _get_specific_template().  The intention is that for
265
-         * template packs that are NOT default packs, we use the default template pack to provide
266
-         * the final fallback templates if there aren't any defined for the called template pack.
267
-         *
268
-         * @type EE_Messages_Template_Pack_Default | null $default_pack
269
-         */
270
-        $default_pack = ! $this instanceof EE_Messages_Template_Pack_Default ? new EE_Messages_Template_Pack_Default() : null;
271
-
272
-        $fields = $messenger->get_template_fields();
273
-        $contexts = $message_type->get_contexts();
274
-
275
-
276
-        foreach ($contexts as $context => $details) {
277
-            foreach ($fields as $field => $field_details) {
278
-                if (empty($field_details)) {
279
-                    continue;
280
-                }
281
-                /**
282
-                 * is this a field array (linked to a main field)?
283
-                 */
284
-                if ($field == 'extra') {
285
-                    foreach ($field_details as $main_field => $sub_fields) {
286
-                        foreach ($sub_fields as $sub_field => $sub_field_details) {
287
-                            // make sure that the template_field_ref matches what the main template field is for this template group.
288
-                            $template_field_ref = $sub_field == 'main' ? $main_field : $sub_field;
289
-                            $templates[ $context ][ $main_field ][ $sub_field ] = $this->_get_specific_template($default_pack, $messenger, $message_type, $template_field_ref, $context);
290
-                        }
291
-                    }
292
-                } else {
293
-                    $templates[ $context ][ $field ] = $this->_get_specific_template($default_pack, $messenger, $message_type, $field, $context);
294
-                }
295
-            }
296
-        }
297
-
298
-        $templates = apply_filters('FHEE__EE_Template_Pack___get_templates__templates', $templates, $messenger, $message_type, $this);
299
-
300
-        $this->_templates[ $messenger->name ][ $message_type->name ] = $templates;
301
-         return $templates;
302
-    }
303
-
304
-
305
-    /**
306
-     * Utility method for retrieving a specific template matching the given parameters
307
-     *
308
-     * @param null | EE_Messages_Template_Pack_Default $default_pack
309
-     * @param EE_messenger                             $messenger
310
-     * @param EE_message_type                          $message_type
311
-     * @param string                                   $field          The field reference for the specific template being looked up.
312
-     * @param string                                   $context      The context reference for the specific template being looked up
313
-     *
314
-     * @return string          The template contents.
315
-     */
316
-    protected function _get_specific_template($default_pack, EE_messenger $messenger, EE_message_type $message_type, $field, $context)
317
-    {
318
-
319
-        // default templates
320
-        $default_templates = $default_pack instanceof EE_Messages_Template_Pack_Default ? $default_pack->get_templates($messenger, $message_type) : array();
321
-
322
-        // first we allow for the $_base_path to be filtered.  However, we assign this to a new variable so that we have the original base_path as a fallback.
323
-        $filtered_base_path = apply_filters('FHEE__EE_Template_Pack___get_specific_template__filtered_base_path', $this->_base_path, $messenger, $message_type, $field, $context, $this);
324
-
325
-        $master_templates = $message_type->get_master_templates();
326
-        $master_templates_mt = isset($master_templates[ $messenger->name ]) ? $master_templates[ $messenger->name ] : $message_type->name;
327
-        $full_path = $filtered_base_path . $messenger->name . '_' . $message_type->name . '_' . $field . '_' . $context . '.template.php';
328
-        $fallback_path = $filtered_base_path . $messenger->name . '_' . $message_type->name . '_' . $field . '.template.php';
329
-        $mt_defined_full_path = $filtered_base_path . $messenger->name . '_' . $master_templates_mt . '_' . $field . '_' . $context . '.template.php';
330
-        $mt_defined_fallback_path = $filtered_base_path . $messenger->name . '_' . $master_templates_mt . '_' . $field . '.template.php';
331
-        $base_defined_full_path = $this->_base_path . $messenger->name . '_' . $master_templates_mt . '_' . $field . '_' . $context . '.template.php';
332
-        $base_defined_fallback_path = $this->_base_path . $messenger->name . '_' . $master_templates_mt . '_' . $field . '.template.php';
333
-
334
-        /**
335
-         * Template checks are done hierarchically in the following order:
336
-         *
337
-         * - a match for the full messenger name, message type, context and field in the full path for the given template pack.
338
-         * - a match for the full messenger name, message type, field in the full path for the given template pack.
339
-         * - a match for the full messenger name, message type, field, context in the path grabbed for the related message type defined in the _master_templates property for the message type (i.e. all registration message types share the same template as the main registration message type).
340
-         * - match for the full messenger name, message type, field for the related message type defined in the _master templates property for the message type
341
-         * - a match for a default template matching the messenger, name, context, field (as set by the default template packs).
342
-         * - empty string.
343
-         */
344
-
345
-
346
-        if (is_readable($full_path)) {
347
-            $actual_path = $full_path;
348
-        } elseif (is_readable($fallback_path)) {
349
-            $actual_path = $fallback_path;
350
-        } elseif (is_readable($mt_defined_full_path)) {
351
-            $actual_path = $mt_defined_full_path;
352
-        } elseif (is_readable($mt_defined_fallback_path)) {
353
-            $actual_path = $mt_defined_fallback_path;
354
-        } elseif (is_readable($base_defined_full_path)) {
355
-            $actual_path = $base_defined_full_path;
356
-        } elseif (is_readable($base_defined_fallback_path)) {
357
-            $actual_path = $base_defined_fallback_path;
358
-        } else {
359
-            $actual_path = '';
360
-        }
361
-        if (empty($actual_path)) {
362
-            $contents = isset($default_templates[ $context ][ $field ]) ? $default_templates[ $context ][ $field ] : '';
363
-        } else {
364
-            $contents = EEH_Template::display_template($actual_path, array(), true);
365
-        }
366
-
367
-        return apply_filters('FHEE__EE_Messages_Template_Pack__get_specific_template__contents', $contents, $actual_path, $messenger, $message_type, $field, $context, $this);
368
-    }
369
-
370
-
371
-
372
-
373
-
374
-    /**
375
-     * Return filtered _supports property.
376
-     *
377
-     * @since 4.5.0
378
-     *
379
-     * @return array
380
-     */
381
-    public function get_supports()
382
-    {
383
-        $supports = apply_filters('FHEE__' . get_class($this) . '__get_supports', $this->_supports);
384
-        return apply_filters('FHEE__EE_Messages_Template_Pack__get_supports', $supports, $this);
385
-    }
386
-
387
-
388
-
389
-
390
-    /**
391
-     * This simply returns the $_default_variation_labels property value.
392
-     *
393
-     * @since 4.5.0
394
-     *
395
-     * @param string $messenger if the messenger slug is returned then the default label for the specific messenger is retrieved.  If it doesn't exist then the __('Default', 'event_espresso') is returned.  If NO value is provided then whatever is set on the _default_variation_labels property is returned.
396
-     *
397
-     * @return array|string
398
-     */
399
-    public function get_default_variation_labels($messenger = '')
400
-    {
401
-        $label = empty($messenger) ? $this->_default_variation_labels : array();
402
-        $label = empty($label) && ! empty($this->_default_variation_labels[ $messenger ]) ? $this->_default_variation_labels[ $messenger ] : __('Default', 'event_espresso');
403
-
404
-        return apply_filters('FHEE__EE_Messages_Template_Pack__get_default_variation_labels', $label, $this->_default_variation_labels, $messenger);
405
-    }
406
-
407
-
408
-
409
-
410
-
411
-    /**
412
-     * This simply returns the _variations property.
413
-     *
414
-     * @since 4.5.0
415
-     *
416
-     * @param string $messenger if included then css variations matching the messenger are returned.  Otherwise, just the default variation is included.  If both message type AND messenger are empty then all variations are returned.
417
-     * @param string $message_type if included then css variations matching the message_type are returned (must have $messenger set).  Otherwise the array of variations per message type are returned.  If message_type is provided but NOT the messenger, then just all variations for all messengers are returned.
418
-     * @return array
419
-     */
420
-    public function get_variations($messenger = '', $message_type = '')
421
-    {
422
-        $messenger_variations = ! empty($messenger) && isset($this->_variations[ $messenger ]) ? $this->_variations[ $messenger ] : array();
423
-
424
-        // message_type provided? IF so, then we've requested a specific set of variations, so we need to make sure we set it as empty if that's not present.
425
-        $variations = !empty($messenger) && !empty($message_type) && isset($messenger_variations[ $message_type ]) ? $messenger_variations[ $message_type ] : array();
426
-
427
-        // now let's account for the possibility we just want all the variations for a messenger (which is indicated by providing the messenger but not the message type).
428
-        $variations = empty($variations) && !empty($messenger) && empty($message_type) ? $messenger_variations : $variations;
429
-
430
-        // filter per template pack and globally.
431
-        $variations = apply_filters('FHEE__' . get_class($this) . '__get_variations', $variations, $messenger, $message_type);
432
-        $variations = apply_filters('FHEE__EE_Messages_Template_Pack__get_variations', $variations, $messenger, $message_type, $this);
433
-
434
-        // prepend the _default_variation, but ONLY if we're returning the fully validated array.
435
-        if (!empty($messenger) && !empty($message_type) && ! empty($variations)) {
436
-            $variations = array( 'default' => $this->get_default_variation_labels($messenger) ) + $variations;
437
-        }
438
-
439
-        return empty($variations) ? array( 'default' => $this->get_default_variation_labels('dft') ): $variations;
440
-    }
441
-
442
-
443
-
444
-
445
-    /**
446
-     * This is typically called by EE_messenger objects to get the specific css variation defined for the messenger, message_type and type (i.e. inline, wpeditor, preview etc.)
447
-     *
448
-     * @since 4.5.0
449
-     *
450
-     * @param string $messenger messenger slug
451
-     * @param string $message_type message_type slug
452
-     * @param string $type           variation type (i.e. inline, base, wpeditor, preview etc. //this varies per messenger).
453
-     * @param string $variation    this should match one of the defined variations in the _variations property on this class.
454
-     * @param string $file_extension  What type of file the variation file is (defaults to css)
455
-     * @param bool   $url          if true then return the url otherwise path.
456
-     * @param bool   $skip_filters This should not be set directly, its used internally to skip filters when the default template pack is called internally as the fallback.
457
-     *
458
-     * @return string The variation path or url (typically css reference)
459
-     */
460
-    public function get_variation($messenger, $message_type, $type, $variation, $url = true, $file_extension = '.css', $skip_filters = false)
461
-    {
138
+	/**
139
+	 * This is an array of extra css variations for message templates indexed by messenger with the values as an array or message types the variations apply to as the key  and then values are an array with variation slugs as the key and label as the value. Note the default variation is not included in this array.  So the structure is:
140
+	 * array(
141
+	 *  'email' => array(
142
+	 *  )
143
+	 * )
144
+	 *
145
+	 * Keep in mind that this property is used both for indicating valid variations for a given message type and messenger but the variation files themselves are ONLY unique to the messenger.  So if you have a variation for the html messenger referenced by the slug "sunset_red" Then the variation file for the main type will be html_main_sunset_red.css.  All the array in this property allows you to do, is indicate that with certain message types the sunset_red variation is available but for other message types its not.  But you could NOT have a sunset_red variation file for one messenger/message_type and a different one for another messenger/message_type.  If you want different css looks then you can define a different structural layout for the template , messenger, message type combination and in the same sunset_red.css variation file just add css specific to that layout.
146
+	 *
147
+	 * @since 4.5.0
148
+	 *
149
+	 * @var array
150
+	 */
151
+	public $_variations = array();
152
+
153
+
154
+
155
+
156
+	/**
157
+	 * Template pack constructor
158
+	 *
159
+	 * @since 4.5.0
160
+	 */
161
+	public function __construct()
162
+	{
163
+		$this->_set_props();
164
+		// make sure classname is correct
165
+		$classname = get_class($this);
166
+		// make sure required props have been set
167
+
168
+		// if label is empty then throw an error because we should have it defined by now.
169
+		if (! isset($this->label)) {
170
+			throw new EE_Error(sprintf(__('The label property is not set for %s.  Please ensure that is set for the class.', 'event_espresso'), $classname));
171
+		}
172
+
173
+
174
+		// the reference for this template pack
175
+		if (! isset($this->dbref)) {
176
+			throw new EE_Error(sprintf(__('The dbref property is not set for %s.  Please ensure that is set for the class.', 'event_espresso'), $classname));
177
+		}
178
+
179
+		// make sure dbref is safe
180
+		$this->dbref = str_replace('-', '_', sanitize_key($this->dbref));
181
+
182
+		$should_be = 'EE_Messages_Template_Pack_' . str_replace(' ', '_', ucwords(str_replace('_', ' ', $this->dbref)));
183
+
184
+		if ($should_be !== $classname) {
185
+			throw new EE_Error(sprintf(__('The name of the template pack instantiated class is "%s".  It should be "%s".  Make sure that the name of the template pack class matches is prepended with "EE_Messages_Template_Pack_" and appended with a sentence case iteration of the value for your template pack\'s dbref property.', 'event_espresso'), $classname, $should_be));
186
+		}
187
+
188
+		// if _base_path is not set then throw an error because a base path string is needed.
189
+		if (empty($this->_base_path)) {
190
+			throw new EE_Error(sprintf(__('The _base_path property is not set for %s.  Please ensure that is set for the class.', 'event_espresso'), $classname));
191
+		}
192
+
193
+
194
+		// if _base_url is not set then throw an error because a  string is needed for variations.
195
+		if (empty($this->_base_url)) {
196
+			throw new EE_Error(sprintf(__('The _base_url property is not set for %s.  Please ensure that is set for the class.', 'event_espresso'), $classname));
197
+		}
198
+
199
+
200
+		// if $supports is not set then throw an error because that effectively means this template_pack does not have any templates!
201
+		if (empty($this->_supports)) {
202
+			throw new EE_Error(sprintf(__('The supports property is not set for %s.  Please ensure that is set for the class.', 'event_espresso'), $classname));
203
+		}
204
+	}
205
+
206
+
207
+
208
+	/**
209
+	 * This method should be used to define the following properties:
210
+	 * - label
211
+	 * - dbref
212
+	 * - description
213
+	 * - _base_path
214
+	 * - _base_url
215
+	 * - supports
216
+	 * - variations
217
+	 *
218
+	 * @since 4.5.0
219
+	 * @return void.
220
+	 * @abstract
221
+	 */
222
+	abstract protected function _set_props();
223
+
224
+
225
+
226
+
227
+	/**
228
+	 * Wrapper for get_templates() ( @see get_templates() for documentation)
229
+	 *
230
+	 * @since 4.5.0
231
+	 *
232
+	 * @param EE_messenger    $messenger
233
+	 * @param EE_message_type $message_type
234
+	 *
235
+	 * @return array
236
+	 */
237
+	public function get_templates(EE_messenger $messenger, EE_message_type $message_type)
238
+	{
239
+		return isset($this->_templates[ $messenger->name ][ $message_type->name ]) ? $this->_templates[ $messenger->name ][ $message_type->name ] : $this->_get_templates($messenger, $message_type);
240
+	}
241
+
242
+
243
+
244
+
245
+	/**
246
+	 * This takes the incoming messenger and message type objects, uses them to get the set fields and contexts, then attempts to retrieve the templates matching those for this given template pack.
247
+	 *
248
+	 * @since 4.5.0
249
+	 *
250
+	 * @param EE_messenger    $messenger
251
+	 * @param EE_message_type $message_type
252
+	 *
253
+	 * @return array          Returns an multi-level associative array indexed by template context and field in the format:
254
+	 *                                array( 'context' => array( 'field' => 'value', 'another-field', 'value' ) );
255
+	 */
256
+	protected function _get_templates(EE_messenger $messenger, EE_message_type $message_type)
257
+	{
258
+		$templates = array();
259
+
260
+		/**
261
+		 * Retrieving the default pack for later usage of default templates for template packs that
262
+		 * are NOT the default pack ( or an extension of the default pack ).
263
+		 * We ONLY set this variable to be the default pack IF the loaded class is NOT the default
264
+		 * pack.  This prevents recursion in _get_specific_template().  The intention is that for
265
+		 * template packs that are NOT default packs, we use the default template pack to provide
266
+		 * the final fallback templates if there aren't any defined for the called template pack.
267
+		 *
268
+		 * @type EE_Messages_Template_Pack_Default | null $default_pack
269
+		 */
270
+		$default_pack = ! $this instanceof EE_Messages_Template_Pack_Default ? new EE_Messages_Template_Pack_Default() : null;
271
+
272
+		$fields = $messenger->get_template_fields();
273
+		$contexts = $message_type->get_contexts();
274
+
275
+
276
+		foreach ($contexts as $context => $details) {
277
+			foreach ($fields as $field => $field_details) {
278
+				if (empty($field_details)) {
279
+					continue;
280
+				}
281
+				/**
282
+				 * is this a field array (linked to a main field)?
283
+				 */
284
+				if ($field == 'extra') {
285
+					foreach ($field_details as $main_field => $sub_fields) {
286
+						foreach ($sub_fields as $sub_field => $sub_field_details) {
287
+							// make sure that the template_field_ref matches what the main template field is for this template group.
288
+							$template_field_ref = $sub_field == 'main' ? $main_field : $sub_field;
289
+							$templates[ $context ][ $main_field ][ $sub_field ] = $this->_get_specific_template($default_pack, $messenger, $message_type, $template_field_ref, $context);
290
+						}
291
+					}
292
+				} else {
293
+					$templates[ $context ][ $field ] = $this->_get_specific_template($default_pack, $messenger, $message_type, $field, $context);
294
+				}
295
+			}
296
+		}
297
+
298
+		$templates = apply_filters('FHEE__EE_Template_Pack___get_templates__templates', $templates, $messenger, $message_type, $this);
299
+
300
+		$this->_templates[ $messenger->name ][ $message_type->name ] = $templates;
301
+		 return $templates;
302
+	}
303
+
304
+
305
+	/**
306
+	 * Utility method for retrieving a specific template matching the given parameters
307
+	 *
308
+	 * @param null | EE_Messages_Template_Pack_Default $default_pack
309
+	 * @param EE_messenger                             $messenger
310
+	 * @param EE_message_type                          $message_type
311
+	 * @param string                                   $field          The field reference for the specific template being looked up.
312
+	 * @param string                                   $context      The context reference for the specific template being looked up
313
+	 *
314
+	 * @return string          The template contents.
315
+	 */
316
+	protected function _get_specific_template($default_pack, EE_messenger $messenger, EE_message_type $message_type, $field, $context)
317
+	{
318
+
319
+		// default templates
320
+		$default_templates = $default_pack instanceof EE_Messages_Template_Pack_Default ? $default_pack->get_templates($messenger, $message_type) : array();
321
+
322
+		// first we allow for the $_base_path to be filtered.  However, we assign this to a new variable so that we have the original base_path as a fallback.
323
+		$filtered_base_path = apply_filters('FHEE__EE_Template_Pack___get_specific_template__filtered_base_path', $this->_base_path, $messenger, $message_type, $field, $context, $this);
324
+
325
+		$master_templates = $message_type->get_master_templates();
326
+		$master_templates_mt = isset($master_templates[ $messenger->name ]) ? $master_templates[ $messenger->name ] : $message_type->name;
327
+		$full_path = $filtered_base_path . $messenger->name . '_' . $message_type->name . '_' . $field . '_' . $context . '.template.php';
328
+		$fallback_path = $filtered_base_path . $messenger->name . '_' . $message_type->name . '_' . $field . '.template.php';
329
+		$mt_defined_full_path = $filtered_base_path . $messenger->name . '_' . $master_templates_mt . '_' . $field . '_' . $context . '.template.php';
330
+		$mt_defined_fallback_path = $filtered_base_path . $messenger->name . '_' . $master_templates_mt . '_' . $field . '.template.php';
331
+		$base_defined_full_path = $this->_base_path . $messenger->name . '_' . $master_templates_mt . '_' . $field . '_' . $context . '.template.php';
332
+		$base_defined_fallback_path = $this->_base_path . $messenger->name . '_' . $master_templates_mt . '_' . $field . '.template.php';
333
+
334
+		/**
335
+		 * Template checks are done hierarchically in the following order:
336
+		 *
337
+		 * - a match for the full messenger name, message type, context and field in the full path for the given template pack.
338
+		 * - a match for the full messenger name, message type, field in the full path for the given template pack.
339
+		 * - a match for the full messenger name, message type, field, context in the path grabbed for the related message type defined in the _master_templates property for the message type (i.e. all registration message types share the same template as the main registration message type).
340
+		 * - match for the full messenger name, message type, field for the related message type defined in the _master templates property for the message type
341
+		 * - a match for a default template matching the messenger, name, context, field (as set by the default template packs).
342
+		 * - empty string.
343
+		 */
344
+
345
+
346
+		if (is_readable($full_path)) {
347
+			$actual_path = $full_path;
348
+		} elseif (is_readable($fallback_path)) {
349
+			$actual_path = $fallback_path;
350
+		} elseif (is_readable($mt_defined_full_path)) {
351
+			$actual_path = $mt_defined_full_path;
352
+		} elseif (is_readable($mt_defined_fallback_path)) {
353
+			$actual_path = $mt_defined_fallback_path;
354
+		} elseif (is_readable($base_defined_full_path)) {
355
+			$actual_path = $base_defined_full_path;
356
+		} elseif (is_readable($base_defined_fallback_path)) {
357
+			$actual_path = $base_defined_fallback_path;
358
+		} else {
359
+			$actual_path = '';
360
+		}
361
+		if (empty($actual_path)) {
362
+			$contents = isset($default_templates[ $context ][ $field ]) ? $default_templates[ $context ][ $field ] : '';
363
+		} else {
364
+			$contents = EEH_Template::display_template($actual_path, array(), true);
365
+		}
366
+
367
+		return apply_filters('FHEE__EE_Messages_Template_Pack__get_specific_template__contents', $contents, $actual_path, $messenger, $message_type, $field, $context, $this);
368
+	}
369
+
370
+
371
+
372
+
373
+
374
+	/**
375
+	 * Return filtered _supports property.
376
+	 *
377
+	 * @since 4.5.0
378
+	 *
379
+	 * @return array
380
+	 */
381
+	public function get_supports()
382
+	{
383
+		$supports = apply_filters('FHEE__' . get_class($this) . '__get_supports', $this->_supports);
384
+		return apply_filters('FHEE__EE_Messages_Template_Pack__get_supports', $supports, $this);
385
+	}
386
+
387
+
388
+
389
+
390
+	/**
391
+	 * This simply returns the $_default_variation_labels property value.
392
+	 *
393
+	 * @since 4.5.0
394
+	 *
395
+	 * @param string $messenger if the messenger slug is returned then the default label for the specific messenger is retrieved.  If it doesn't exist then the __('Default', 'event_espresso') is returned.  If NO value is provided then whatever is set on the _default_variation_labels property is returned.
396
+	 *
397
+	 * @return array|string
398
+	 */
399
+	public function get_default_variation_labels($messenger = '')
400
+	{
401
+		$label = empty($messenger) ? $this->_default_variation_labels : array();
402
+		$label = empty($label) && ! empty($this->_default_variation_labels[ $messenger ]) ? $this->_default_variation_labels[ $messenger ] : __('Default', 'event_espresso');
403
+
404
+		return apply_filters('FHEE__EE_Messages_Template_Pack__get_default_variation_labels', $label, $this->_default_variation_labels, $messenger);
405
+	}
406
+
407
+
408
+
409
+
410
+
411
+	/**
412
+	 * This simply returns the _variations property.
413
+	 *
414
+	 * @since 4.5.0
415
+	 *
416
+	 * @param string $messenger if included then css variations matching the messenger are returned.  Otherwise, just the default variation is included.  If both message type AND messenger are empty then all variations are returned.
417
+	 * @param string $message_type if included then css variations matching the message_type are returned (must have $messenger set).  Otherwise the array of variations per message type are returned.  If message_type is provided but NOT the messenger, then just all variations for all messengers are returned.
418
+	 * @return array
419
+	 */
420
+	public function get_variations($messenger = '', $message_type = '')
421
+	{
422
+		$messenger_variations = ! empty($messenger) && isset($this->_variations[ $messenger ]) ? $this->_variations[ $messenger ] : array();
423
+
424
+		// message_type provided? IF so, then we've requested a specific set of variations, so we need to make sure we set it as empty if that's not present.
425
+		$variations = !empty($messenger) && !empty($message_type) && isset($messenger_variations[ $message_type ]) ? $messenger_variations[ $message_type ] : array();
426
+
427
+		// now let's account for the possibility we just want all the variations for a messenger (which is indicated by providing the messenger but not the message type).
428
+		$variations = empty($variations) && !empty($messenger) && empty($message_type) ? $messenger_variations : $variations;
429
+
430
+		// filter per template pack and globally.
431
+		$variations = apply_filters('FHEE__' . get_class($this) . '__get_variations', $variations, $messenger, $message_type);
432
+		$variations = apply_filters('FHEE__EE_Messages_Template_Pack__get_variations', $variations, $messenger, $message_type, $this);
433
+
434
+		// prepend the _default_variation, but ONLY if we're returning the fully validated array.
435
+		if (!empty($messenger) && !empty($message_type) && ! empty($variations)) {
436
+			$variations = array( 'default' => $this->get_default_variation_labels($messenger) ) + $variations;
437
+		}
438
+
439
+		return empty($variations) ? array( 'default' => $this->get_default_variation_labels('dft') ): $variations;
440
+	}
441
+
442
+
443
+
444
+
445
+	/**
446
+	 * This is typically called by EE_messenger objects to get the specific css variation defined for the messenger, message_type and type (i.e. inline, wpeditor, preview etc.)
447
+	 *
448
+	 * @since 4.5.0
449
+	 *
450
+	 * @param string $messenger messenger slug
451
+	 * @param string $message_type message_type slug
452
+	 * @param string $type           variation type (i.e. inline, base, wpeditor, preview etc. //this varies per messenger).
453
+	 * @param string $variation    this should match one of the defined variations in the _variations property on this class.
454
+	 * @param string $file_extension  What type of file the variation file is (defaults to css)
455
+	 * @param bool   $url          if true then return the url otherwise path.
456
+	 * @param bool   $skip_filters This should not be set directly, its used internally to skip filters when the default template pack is called internally as the fallback.
457
+	 *
458
+	 * @return string The variation path or url (typically css reference)
459
+	 */
460
+	public function get_variation($messenger, $message_type, $type, $variation, $url = true, $file_extension = '.css', $skip_filters = false)
461
+	{
462 462
 
463
-        $base = $url ? $this->_base_url : $this->_base_path;
464
-        $base_path = $this->_base_path;
463
+		$base = $url ? $this->_base_url : $this->_base_path;
464
+		$base_path = $this->_base_path;
465 465
 
466
-        if (! $skip_filters) {
467
-            $base =  apply_filters('FHEE__EE_Messages_Template_Pack__get_variation__base_path_or_url', $base, $messenger, $message_type, $type, $variation, $url, $file_extension, $this);
468
-            $base_path = apply_filters('FHEE__EE_Messages_Template_Pack__get_variation__base_path', $base_path, $messenger, $message_type, $type, $variation, false, $file_extension, $this);
469
-        }
466
+		if (! $skip_filters) {
467
+			$base =  apply_filters('FHEE__EE_Messages_Template_Pack__get_variation__base_path_or_url', $base, $messenger, $message_type, $type, $variation, $url, $file_extension, $this);
468
+			$base_path = apply_filters('FHEE__EE_Messages_Template_Pack__get_variation__base_path', $base_path, $messenger, $message_type, $type, $variation, false, $file_extension, $this);
469
+		}
470 470
 
471
-        $default_pack = get_class($this) != 'EE_Messages_Template_Pack_Default' ? new EE_Messages_Template_Pack_Default() : $this;
472
-
473
-        // possible variation paths considering whether message type is present or not in the file name.
474
-        $path_string = 'variations/' . $messenger . '_' . $message_type . '_'  . $type . '_' . $variation . $file_extension;
475
-        $default_path_string = 'variations/' . $messenger . '_' . $type . '_' . $variation . $file_extension;
476
-
477
-        // first see if fully validated file exists.
478
-        if (is_readable($base_path . $path_string)) {
479
-            $variation_path = $base . $path_string;
480
-        // otherwise see if default exists.
481
-        } elseif (is_readable($base_path . $default_path_string)) {
482
-            $variation_path = $base . $default_path_string;
483
-        } else {
484
-            $variation_path = $default_pack instanceof EE_Messages_Template_Pack_Default ? $default_pack->get_default_variation($messenger, $message_type, $type, $url, $file_extension) : '';
485
-        }
471
+		$default_pack = get_class($this) != 'EE_Messages_Template_Pack_Default' ? new EE_Messages_Template_Pack_Default() : $this;
472
+
473
+		// possible variation paths considering whether message type is present or not in the file name.
474
+		$path_string = 'variations/' . $messenger . '_' . $message_type . '_'  . $type . '_' . $variation . $file_extension;
475
+		$default_path_string = 'variations/' . $messenger . '_' . $type . '_' . $variation . $file_extension;
476
+
477
+		// first see if fully validated file exists.
478
+		if (is_readable($base_path . $path_string)) {
479
+			$variation_path = $base . $path_string;
480
+		// otherwise see if default exists.
481
+		} elseif (is_readable($base_path . $default_path_string)) {
482
+			$variation_path = $base . $default_path_string;
483
+		} else {
484
+			$variation_path = $default_pack instanceof EE_Messages_Template_Pack_Default ? $default_pack->get_default_variation($messenger, $message_type, $type, $url, $file_extension) : '';
485
+		}
486 486
 
487
-        if ($skip_filters) {
488
-            return $variation_path;
489
-        }
490
-
491
-        // filter result
492
-        $variation_path = apply_filters('FHEE__' . get_class($this) . '__get_variation', $variation_path, $messenger, $message_type, $type, $variation, $file_extension, $url);
493
-        return apply_filters('FHEE__EE_Messages_Template_Pack__get_variation', $variation_path, $messenger, $message_type, $type, $variation, $file_extension, $url, $this);
494
-    }
495
-
496
-
497
-
498
-
499
-
500
-    /**
501
-     * This method is used to return the wrapper template for the given template pack.  If the given template pack does not include any wrapper templates then the default is used.
502
-     *
503
-     * @param string $messenger What messenger the wrapper is for.
504
-     * @param string $type           What type of wrapper is being returned ( for messengers that may have more than one wrapper )
505
-     *
506
-     * @return string returns the path for the requested wrapper template.
507
-     */
508
-    public function get_wrapper($messenger, $type = 'main')
509
-    {
510
-        $default_pack = get_class($this) !== 'EE_Messages_Template_Pack_Default' ? new EE_Messages_Template_Pack_Default() : null;
511
-
512
-        $path_string = $this->_base_path . $messenger . '_' . $type . '_wrapper.template.php';
513
-
514
-        if (is_readable($path_string)) {
515
-            $template = $path_string;
516
-        } else {
517
-            $template = $default_pack instanceof EE_Messages_Template_Pack_Default ? $default_pack->get_wrapper($messenger, $type) : '';
518
-        }
519
-
520
-        // filter
521
-        $template = apply_filters('FHEE__' . get_class($this) . '__get_wrapper', $template, $messenger, $type);
522
-        return apply_filters('FHEE__EE_Messages_Template_Pack__get_wrapper', $template, $messenger, $type, $this);
523
-    }
487
+		if ($skip_filters) {
488
+			return $variation_path;
489
+		}
490
+
491
+		// filter result
492
+		$variation_path = apply_filters('FHEE__' . get_class($this) . '__get_variation', $variation_path, $messenger, $message_type, $type, $variation, $file_extension, $url);
493
+		return apply_filters('FHEE__EE_Messages_Template_Pack__get_variation', $variation_path, $messenger, $message_type, $type, $variation, $file_extension, $url, $this);
494
+	}
495
+
496
+
497
+
498
+
499
+
500
+	/**
501
+	 * This method is used to return the wrapper template for the given template pack.  If the given template pack does not include any wrapper templates then the default is used.
502
+	 *
503
+	 * @param string $messenger What messenger the wrapper is for.
504
+	 * @param string $type           What type of wrapper is being returned ( for messengers that may have more than one wrapper )
505
+	 *
506
+	 * @return string returns the path for the requested wrapper template.
507
+	 */
508
+	public function get_wrapper($messenger, $type = 'main')
509
+	{
510
+		$default_pack = get_class($this) !== 'EE_Messages_Template_Pack_Default' ? new EE_Messages_Template_Pack_Default() : null;
511
+
512
+		$path_string = $this->_base_path . $messenger . '_' . $type . '_wrapper.template.php';
513
+
514
+		if (is_readable($path_string)) {
515
+			$template = $path_string;
516
+		} else {
517
+			$template = $default_pack instanceof EE_Messages_Template_Pack_Default ? $default_pack->get_wrapper($messenger, $type) : '';
518
+		}
519
+
520
+		// filter
521
+		$template = apply_filters('FHEE__' . get_class($this) . '__get_wrapper', $template, $messenger, $type);
522
+		return apply_filters('FHEE__EE_Messages_Template_Pack__get_wrapper', $template, $messenger, $type, $this);
523
+	}
524 524
 }
Please login to merge, or discard this patch.
Spacing   +35 added lines, -35 removed lines patch added patch discarded remove patch
@@ -166,20 +166,20 @@  discard block
 block discarded – undo
166 166
         // make sure required props have been set
167 167
 
168 168
         // if label is empty then throw an error because we should have it defined by now.
169
-        if (! isset($this->label)) {
169
+        if ( ! isset($this->label)) {
170 170
             throw new EE_Error(sprintf(__('The label property is not set for %s.  Please ensure that is set for the class.', 'event_espresso'), $classname));
171 171
         }
172 172
 
173 173
 
174 174
         // the reference for this template pack
175
-        if (! isset($this->dbref)) {
175
+        if ( ! isset($this->dbref)) {
176 176
             throw new EE_Error(sprintf(__('The dbref property is not set for %s.  Please ensure that is set for the class.', 'event_espresso'), $classname));
177 177
         }
178 178
 
179 179
         // make sure dbref is safe
180 180
         $this->dbref = str_replace('-', '_', sanitize_key($this->dbref));
181 181
 
182
-        $should_be = 'EE_Messages_Template_Pack_' . str_replace(' ', '_', ucwords(str_replace('_', ' ', $this->dbref)));
182
+        $should_be = 'EE_Messages_Template_Pack_'.str_replace(' ', '_', ucwords(str_replace('_', ' ', $this->dbref)));
183 183
 
184 184
         if ($should_be !== $classname) {
185 185
             throw new EE_Error(sprintf(__('The name of the template pack instantiated class is "%s".  It should be "%s".  Make sure that the name of the template pack class matches is prepended with "EE_Messages_Template_Pack_" and appended with a sentence case iteration of the value for your template pack\'s dbref property.', 'event_espresso'), $classname, $should_be));
@@ -236,7 +236,7 @@  discard block
 block discarded – undo
236 236
      */
237 237
     public function get_templates(EE_messenger $messenger, EE_message_type $message_type)
238 238
     {
239
-        return isset($this->_templates[ $messenger->name ][ $message_type->name ]) ? $this->_templates[ $messenger->name ][ $message_type->name ] : $this->_get_templates($messenger, $message_type);
239
+        return isset($this->_templates[$messenger->name][$message_type->name]) ? $this->_templates[$messenger->name][$message_type->name] : $this->_get_templates($messenger, $message_type);
240 240
     }
241 241
 
242 242
 
@@ -286,18 +286,18 @@  discard block
 block discarded – undo
286 286
                         foreach ($sub_fields as $sub_field => $sub_field_details) {
287 287
                             // make sure that the template_field_ref matches what the main template field is for this template group.
288 288
                             $template_field_ref = $sub_field == 'main' ? $main_field : $sub_field;
289
-                            $templates[ $context ][ $main_field ][ $sub_field ] = $this->_get_specific_template($default_pack, $messenger, $message_type, $template_field_ref, $context);
289
+                            $templates[$context][$main_field][$sub_field] = $this->_get_specific_template($default_pack, $messenger, $message_type, $template_field_ref, $context);
290 290
                         }
291 291
                     }
292 292
                 } else {
293
-                    $templates[ $context ][ $field ] = $this->_get_specific_template($default_pack, $messenger, $message_type, $field, $context);
293
+                    $templates[$context][$field] = $this->_get_specific_template($default_pack, $messenger, $message_type, $field, $context);
294 294
                 }
295 295
             }
296 296
         }
297 297
 
298 298
         $templates = apply_filters('FHEE__EE_Template_Pack___get_templates__templates', $templates, $messenger, $message_type, $this);
299 299
 
300
-        $this->_templates[ $messenger->name ][ $message_type->name ] = $templates;
300
+        $this->_templates[$messenger->name][$message_type->name] = $templates;
301 301
          return $templates;
302 302
     }
303 303
 
@@ -323,13 +323,13 @@  discard block
 block discarded – undo
323 323
         $filtered_base_path = apply_filters('FHEE__EE_Template_Pack___get_specific_template__filtered_base_path', $this->_base_path, $messenger, $message_type, $field, $context, $this);
324 324
 
325 325
         $master_templates = $message_type->get_master_templates();
326
-        $master_templates_mt = isset($master_templates[ $messenger->name ]) ? $master_templates[ $messenger->name ] : $message_type->name;
327
-        $full_path = $filtered_base_path . $messenger->name . '_' . $message_type->name . '_' . $field . '_' . $context . '.template.php';
328
-        $fallback_path = $filtered_base_path . $messenger->name . '_' . $message_type->name . '_' . $field . '.template.php';
329
-        $mt_defined_full_path = $filtered_base_path . $messenger->name . '_' . $master_templates_mt . '_' . $field . '_' . $context . '.template.php';
330
-        $mt_defined_fallback_path = $filtered_base_path . $messenger->name . '_' . $master_templates_mt . '_' . $field . '.template.php';
331
-        $base_defined_full_path = $this->_base_path . $messenger->name . '_' . $master_templates_mt . '_' . $field . '_' . $context . '.template.php';
332
-        $base_defined_fallback_path = $this->_base_path . $messenger->name . '_' . $master_templates_mt . '_' . $field . '.template.php';
326
+        $master_templates_mt = isset($master_templates[$messenger->name]) ? $master_templates[$messenger->name] : $message_type->name;
327
+        $full_path = $filtered_base_path.$messenger->name.'_'.$message_type->name.'_'.$field.'_'.$context.'.template.php';
328
+        $fallback_path = $filtered_base_path.$messenger->name.'_'.$message_type->name.'_'.$field.'.template.php';
329
+        $mt_defined_full_path = $filtered_base_path.$messenger->name.'_'.$master_templates_mt.'_'.$field.'_'.$context.'.template.php';
330
+        $mt_defined_fallback_path = $filtered_base_path.$messenger->name.'_'.$master_templates_mt.'_'.$field.'.template.php';
331
+        $base_defined_full_path = $this->_base_path.$messenger->name.'_'.$master_templates_mt.'_'.$field.'_'.$context.'.template.php';
332
+        $base_defined_fallback_path = $this->_base_path.$messenger->name.'_'.$master_templates_mt.'_'.$field.'.template.php';
333 333
 
334 334
         /**
335 335
          * Template checks are done hierarchically in the following order:
@@ -359,7 +359,7 @@  discard block
 block discarded – undo
359 359
             $actual_path = '';
360 360
         }
361 361
         if (empty($actual_path)) {
362
-            $contents = isset($default_templates[ $context ][ $field ]) ? $default_templates[ $context ][ $field ] : '';
362
+            $contents = isset($default_templates[$context][$field]) ? $default_templates[$context][$field] : '';
363 363
         } else {
364 364
             $contents = EEH_Template::display_template($actual_path, array(), true);
365 365
         }
@@ -380,7 +380,7 @@  discard block
 block discarded – undo
380 380
      */
381 381
     public function get_supports()
382 382
     {
383
-        $supports = apply_filters('FHEE__' . get_class($this) . '__get_supports', $this->_supports);
383
+        $supports = apply_filters('FHEE__'.get_class($this).'__get_supports', $this->_supports);
384 384
         return apply_filters('FHEE__EE_Messages_Template_Pack__get_supports', $supports, $this);
385 385
     }
386 386
 
@@ -399,7 +399,7 @@  discard block
 block discarded – undo
399 399
     public function get_default_variation_labels($messenger = '')
400 400
     {
401 401
         $label = empty($messenger) ? $this->_default_variation_labels : array();
402
-        $label = empty($label) && ! empty($this->_default_variation_labels[ $messenger ]) ? $this->_default_variation_labels[ $messenger ] : __('Default', 'event_espresso');
402
+        $label = empty($label) && ! empty($this->_default_variation_labels[$messenger]) ? $this->_default_variation_labels[$messenger] : __('Default', 'event_espresso');
403 403
 
404 404
         return apply_filters('FHEE__EE_Messages_Template_Pack__get_default_variation_labels', $label, $this->_default_variation_labels, $messenger);
405 405
     }
@@ -419,24 +419,24 @@  discard block
 block discarded – undo
419 419
      */
420 420
     public function get_variations($messenger = '', $message_type = '')
421 421
     {
422
-        $messenger_variations = ! empty($messenger) && isset($this->_variations[ $messenger ]) ? $this->_variations[ $messenger ] : array();
422
+        $messenger_variations = ! empty($messenger) && isset($this->_variations[$messenger]) ? $this->_variations[$messenger] : array();
423 423
 
424 424
         // message_type provided? IF so, then we've requested a specific set of variations, so we need to make sure we set it as empty if that's not present.
425
-        $variations = !empty($messenger) && !empty($message_type) && isset($messenger_variations[ $message_type ]) ? $messenger_variations[ $message_type ] : array();
425
+        $variations = ! empty($messenger) && ! empty($message_type) && isset($messenger_variations[$message_type]) ? $messenger_variations[$message_type] : array();
426 426
 
427 427
         // now let's account for the possibility we just want all the variations for a messenger (which is indicated by providing the messenger but not the message type).
428
-        $variations = empty($variations) && !empty($messenger) && empty($message_type) ? $messenger_variations : $variations;
428
+        $variations = empty($variations) && ! empty($messenger) && empty($message_type) ? $messenger_variations : $variations;
429 429
 
430 430
         // filter per template pack and globally.
431
-        $variations = apply_filters('FHEE__' . get_class($this) . '__get_variations', $variations, $messenger, $message_type);
431
+        $variations = apply_filters('FHEE__'.get_class($this).'__get_variations', $variations, $messenger, $message_type);
432 432
         $variations = apply_filters('FHEE__EE_Messages_Template_Pack__get_variations', $variations, $messenger, $message_type, $this);
433 433
 
434 434
         // prepend the _default_variation, but ONLY if we're returning the fully validated array.
435
-        if (!empty($messenger) && !empty($message_type) && ! empty($variations)) {
436
-            $variations = array( 'default' => $this->get_default_variation_labels($messenger) ) + $variations;
435
+        if ( ! empty($messenger) && ! empty($message_type) && ! empty($variations)) {
436
+            $variations = array('default' => $this->get_default_variation_labels($messenger)) + $variations;
437 437
         }
438 438
 
439
-        return empty($variations) ? array( 'default' => $this->get_default_variation_labels('dft') ): $variations;
439
+        return empty($variations) ? array('default' => $this->get_default_variation_labels('dft')) : $variations;
440 440
     }
441 441
 
442 442
 
@@ -463,23 +463,23 @@  discard block
 block discarded – undo
463 463
         $base = $url ? $this->_base_url : $this->_base_path;
464 464
         $base_path = $this->_base_path;
465 465
 
466
-        if (! $skip_filters) {
467
-            $base =  apply_filters('FHEE__EE_Messages_Template_Pack__get_variation__base_path_or_url', $base, $messenger, $message_type, $type, $variation, $url, $file_extension, $this);
466
+        if ( ! $skip_filters) {
467
+            $base = apply_filters('FHEE__EE_Messages_Template_Pack__get_variation__base_path_or_url', $base, $messenger, $message_type, $type, $variation, $url, $file_extension, $this);
468 468
             $base_path = apply_filters('FHEE__EE_Messages_Template_Pack__get_variation__base_path', $base_path, $messenger, $message_type, $type, $variation, false, $file_extension, $this);
469 469
         }
470 470
 
471 471
         $default_pack = get_class($this) != 'EE_Messages_Template_Pack_Default' ? new EE_Messages_Template_Pack_Default() : $this;
472 472
 
473 473
         // possible variation paths considering whether message type is present or not in the file name.
474
-        $path_string = 'variations/' . $messenger . '_' . $message_type . '_'  . $type . '_' . $variation . $file_extension;
475
-        $default_path_string = 'variations/' . $messenger . '_' . $type . '_' . $variation . $file_extension;
474
+        $path_string = 'variations/'.$messenger.'_'.$message_type.'_'.$type.'_'.$variation.$file_extension;
475
+        $default_path_string = 'variations/'.$messenger.'_'.$type.'_'.$variation.$file_extension;
476 476
 
477 477
         // first see if fully validated file exists.
478
-        if (is_readable($base_path . $path_string)) {
479
-            $variation_path = $base . $path_string;
478
+        if (is_readable($base_path.$path_string)) {
479
+            $variation_path = $base.$path_string;
480 480
         // otherwise see if default exists.
481
-        } elseif (is_readable($base_path . $default_path_string)) {
482
-            $variation_path = $base . $default_path_string;
481
+        } elseif (is_readable($base_path.$default_path_string)) {
482
+            $variation_path = $base.$default_path_string;
483 483
         } else {
484 484
             $variation_path = $default_pack instanceof EE_Messages_Template_Pack_Default ? $default_pack->get_default_variation($messenger, $message_type, $type, $url, $file_extension) : '';
485 485
         }
@@ -489,7 +489,7 @@  discard block
 block discarded – undo
489 489
         }
490 490
 
491 491
         // filter result
492
-        $variation_path = apply_filters('FHEE__' . get_class($this) . '__get_variation', $variation_path, $messenger, $message_type, $type, $variation, $file_extension, $url);
492
+        $variation_path = apply_filters('FHEE__'.get_class($this).'__get_variation', $variation_path, $messenger, $message_type, $type, $variation, $file_extension, $url);
493 493
         return apply_filters('FHEE__EE_Messages_Template_Pack__get_variation', $variation_path, $messenger, $message_type, $type, $variation, $file_extension, $url, $this);
494 494
     }
495 495
 
@@ -509,7 +509,7 @@  discard block
 block discarded – undo
509 509
     {
510 510
         $default_pack = get_class($this) !== 'EE_Messages_Template_Pack_Default' ? new EE_Messages_Template_Pack_Default() : null;
511 511
 
512
-        $path_string = $this->_base_path . $messenger . '_' . $type . '_wrapper.template.php';
512
+        $path_string = $this->_base_path.$messenger.'_'.$type.'_wrapper.template.php';
513 513
 
514 514
         if (is_readable($path_string)) {
515 515
             $template = $path_string;
@@ -518,7 +518,7 @@  discard block
 block discarded – undo
518 518
         }
519 519
 
520 520
         // filter
521
-        $template = apply_filters('FHEE__' . get_class($this) . '__get_wrapper', $template, $messenger, $type);
521
+        $template = apply_filters('FHEE__'.get_class($this).'__get_wrapper', $template, $messenger, $type);
522 522
         return apply_filters('FHEE__EE_Messages_Template_Pack__get_wrapper', $template, $messenger, $type, $this);
523 523
     }
524 524
 }
Please login to merge, or discard this patch.
core/libraries/messages/EE_Message_To_Generate.php 3 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -208,7 +208,7 @@
 block discarded – undo
208 208
      * generates an EE_Message using the supplied arguments and some defaults
209 209
      *
210 210
      * @param array $properties
211
-     * @return string
211
+     * @return EE_Message
212 212
      */
213 213
     protected function _generate_message($properties = array())
214 214
     {
Please login to merge, or discard this patch.
Indentation   +300 added lines, -300 removed lines patch added patch discarded remove patch
@@ -11,304 +11,304 @@
 block discarded – undo
11 11
 class EE_Message_To_Generate
12 12
 {
13 13
 
14
-    /**
15
-     * @type string name of EE_messenger
16
-     */
17
-    protected $_messenger_name = null;
18
-
19
-    /**
20
-     * @type string name of EE_message_type
21
-     */
22
-    protected $_message_type_name = null;
23
-
24
-    /**
25
-     * @type EE_messenger
26
-     */
27
-    protected $_messenger = null;
28
-
29
-    /**
30
-     * @type EE_message_type
31
-     */
32
-    protected $_message_type = null;
33
-
34
-    /**
35
-     * Identifier for the context the message is to be generated for.
36
-     * @type string
37
-     */
38
-    protected $_context = '';
39
-
40
-    /**
41
-     * Data that will be used to generate message.
42
-     * @type array
43
-     */
44
-    protected $_data = array();
45
-
46
-    /**
47
-     * Whether this message is for a preview or not.
48
-     * @type bool
49
-     */
50
-    protected $_preview = false;
51
-
52
-    /**
53
-     * @type EE_Message $_message
54
-     */
55
-    protected $_message = null;
56
-
57
-    /**
58
-     * This is set by the constructor to indicate whether the incoming messenger
59
-     * and message type are valid.  This can then be checked by callers to determine whether
60
-     * to generate this message or not.
61
-     * @type bool
62
-     */
63
-    protected $_valid = false;
64
-
65
-    /**
66
-     * If there are any errors (non exception errors) they get added to this array for callers to decide
67
-     * how to handle.
68
-     * @type array
69
-     */
70
-    protected $_error_msg = array();
71
-
72
-    /**
73
-     * Can be accessed via the send_now() method, this is set in the validation
74
-     * routine via the EE_messenger::send_now() method.
75
-     * @type bool
76
-     */
77
-    protected $_send_now = false;
78
-
79
-    /**
80
-     * Holds the classname for the data handler used by the current message type.
81
-     * This is set on the first call to the public `get_data_handler_class_name()` method.
82
-     * @type string
83
-     */
84
-    protected $_data_handler_class_name = '';
85
-
86
-    /**
87
-     * one of the message status constants on EEM_Message
88
-     *
89
-     * @type string
90
-     */
91
-    protected $_message_status = '';
92
-
93
-
94
-
95
-    /**
96
-     * Constructor
97
-     *
98
-     * @param string $messenger_name    Slug representing messenger
99
-     * @param string $message_type_name Slug representing message type.
100
-     * @param mixed  $data              Data used for generating message.
101
-     * @param string $context           Optional context to restrict message generated for.
102
-     * @param bool   $preview           Whether this is being used to generate a preview or not.
103
-     * @param string $status
104
-     */
105
-    public function __construct(
106
-        $messenger_name,
107
-        $message_type_name,
108
-        $data = array(),
109
-        $context = '',
110
-        $preview = false,
111
-        $status = EEM_Message::status_incomplete
112
-    ) {
113
-        $this->_messenger_name      = $messenger_name;
114
-        $this->_message_type_name   = $message_type_name;
115
-        $this->_data                = is_array($data) ? $data : array( $data );
116
-        $this->_context             = $context;
117
-        $this->_preview             = $preview;
118
-        $this->_status              = $status;
119
-        // attempt to generate message immediately
120
-        $this->_message = $this->_generate_message();
121
-    }
122
-
123
-
124
-
125
-    /**
126
-     * @return string
127
-     */
128
-    public function context()
129
-    {
130
-        return $this->_context;
131
-    }
132
-
133
-
134
-
135
-    /**
136
-     * @return array
137
-     */
138
-    public function data()
139
-    {
140
-        return $this->_data;
141
-    }
142
-
143
-
144
-
145
-    /**
146
-     * @return EE_messenger
147
-     */
148
-    public function messenger()
149
-    {
150
-        return $this->_messenger;
151
-    }
152
-
153
-
154
-
155
-    /**
156
-     * @return EE_message_type
157
-     */
158
-    public function message_type()
159
-    {
160
-        return $this->_message_type;
161
-    }
162
-
163
-
164
-
165
-    /**
166
-     * @return boolean
167
-     */
168
-    public function preview()
169
-    {
170
-        return $this->_preview;
171
-    }
172
-
173
-
174
-
175
-    /**
176
-     * @param boolean $preview
177
-     */
178
-    public function set_preview($preview)
179
-    {
180
-        $this->_preview = filter_var($preview, FILTER_VALIDATE_BOOLEAN);
181
-    }
182
-
183
-
184
-
185
-    /**
186
-     * @return bool
187
-     */
188
-    public function send_now()
189
-    {
190
-        return $this->_send_now;
191
-    }
192
-
193
-
194
-
195
-    /**
196
-     * Simply returns the state of the $_valid property.
197
-     *
198
-     * @return bool
199
-     */
200
-    public function valid()
201
-    {
202
-        return $this->_valid;
203
-    }
204
-
205
-
206
-
207
-    /**
208
-     * generates an EE_Message using the supplied arguments and some defaults
209
-     *
210
-     * @param array $properties
211
-     * @return string
212
-     */
213
-    protected function _generate_message($properties = array())
214
-    {
215
-        $message = EE_Message_Factory::create(
216
-            array_merge(
217
-                array(
218
-                    'MSG_messenger'    => $this->_messenger_name,
219
-                    'MSG_message_type' => $this->_message_type_name,
220
-                    'MSG_context'      => $this->_context,
221
-                    'STS_ID'           => $this->_status,
222
-                ),
223
-                $properties
224
-            )
225
-        );
226
-        // validate the message, and if it's good, set some properties
227
-        try {
228
-            $message->is_valid_for_sending_or_generation(true);
229
-            $this->_valid = true;
230
-            $this->_messenger = $message->messenger_object();
231
-            $this->_message_type = $message->message_type_object();
232
-            $this->_send_now = $message->send_now();
233
-        } catch (Exception $e) {
234
-            $this->_valid = false;
235
-            $this->_error_msg[] = $e->getMessage();
236
-        }
237
-        return $message;
238
-    }
239
-
240
-
241
-
242
-    /**
243
-     *  Returns an instantiated EE_Message object from the internal data.
244
-     *
245
-     * @return EE_Message
246
-     */
247
-    public function get_EE_Message()
248
-    {
249
-        // already set ?
250
-        if ($this->_message instanceof EE_Message) {
251
-            return $this->_message;
252
-        }
253
-        // no? then let's create one
254
-        $this->_message = $this->_generate_message();
255
-        return $this->_message;
256
-    }
257
-
258
-
259
-
260
-    /**
261
-     * This returns the data_handler class name for the internal message type set.
262
-     * Note: this also verifies that the data handler class exists.  If it doesn't then $_valid is set to false
263
-     * and the data_handler_class name is set to an empty string.
264
-     *
265
-     * @param   bool    $preview    Used to indicate that the preview data handler is to be returned.
266
-     * @return  string
267
-     */
268
-    public function get_data_handler_class_name($preview = false)
269
-    {
270
-        if ($this->_data_handler_class_name === '' && $this->valid()) {
271
-            $ref = $preview ? 'Preview' : $this->_message_type->get_data_handler($this->_data);
272
-            // make sure internal data is updated.
273
-            $this->_data = $this->_message_type->get_data();
274
-
275
-            // verify
276
-            $this->_data_handler_class_name = EE_Message_To_Generate::verify_and_retrieve_class_name_for_data_handler_reference($ref);
277
-            if ($this->_data_handler_class_name === '') {
278
-                $this->_valid = false;
279
-            }
280
-        }
281
-        return $this->_data_handler_class_name;
282
-    }
283
-
284
-
285
-
286
-    /**
287
-     * Validates the given string as a reference for an existing, accessible data handler and returns the class name
288
-     * For the handler the reference matches.
289
-     *
290
-     * @param string $data_handler_reference
291
-     * @return string
292
-     */
293
-    public static function verify_and_retrieve_class_name_for_data_handler_reference($data_handler_reference)
294
-    {
295
-        $class_name = 'EE_Messages_' . $data_handler_reference . '_incoming_data';
296
-        if (! class_exists($class_name)) {
297
-            EE_Error::add_error(
298
-                sprintf(
299
-                    __(
300
-                        'The included data handler reference (%s) does not match any valid, accessible, "EE_Messages_incoming_data" classes.  Looking for %s.',
301
-                        'event_espresso'
302
-                    ),
303
-                    $data_handler_reference,
304
-                    $class_name
305
-                ),
306
-                __FILE__,
307
-                __FUNCTION__,
308
-                __LINE__
309
-            );
310
-            $class_name = ''; // clear out class_name so caller knows this isn't valid.
311
-        }
312
-        return $class_name;
313
-    }
14
+	/**
15
+	 * @type string name of EE_messenger
16
+	 */
17
+	protected $_messenger_name = null;
18
+
19
+	/**
20
+	 * @type string name of EE_message_type
21
+	 */
22
+	protected $_message_type_name = null;
23
+
24
+	/**
25
+	 * @type EE_messenger
26
+	 */
27
+	protected $_messenger = null;
28
+
29
+	/**
30
+	 * @type EE_message_type
31
+	 */
32
+	protected $_message_type = null;
33
+
34
+	/**
35
+	 * Identifier for the context the message is to be generated for.
36
+	 * @type string
37
+	 */
38
+	protected $_context = '';
39
+
40
+	/**
41
+	 * Data that will be used to generate message.
42
+	 * @type array
43
+	 */
44
+	protected $_data = array();
45
+
46
+	/**
47
+	 * Whether this message is for a preview or not.
48
+	 * @type bool
49
+	 */
50
+	protected $_preview = false;
51
+
52
+	/**
53
+	 * @type EE_Message $_message
54
+	 */
55
+	protected $_message = null;
56
+
57
+	/**
58
+	 * This is set by the constructor to indicate whether the incoming messenger
59
+	 * and message type are valid.  This can then be checked by callers to determine whether
60
+	 * to generate this message or not.
61
+	 * @type bool
62
+	 */
63
+	protected $_valid = false;
64
+
65
+	/**
66
+	 * If there are any errors (non exception errors) they get added to this array for callers to decide
67
+	 * how to handle.
68
+	 * @type array
69
+	 */
70
+	protected $_error_msg = array();
71
+
72
+	/**
73
+	 * Can be accessed via the send_now() method, this is set in the validation
74
+	 * routine via the EE_messenger::send_now() method.
75
+	 * @type bool
76
+	 */
77
+	protected $_send_now = false;
78
+
79
+	/**
80
+	 * Holds the classname for the data handler used by the current message type.
81
+	 * This is set on the first call to the public `get_data_handler_class_name()` method.
82
+	 * @type string
83
+	 */
84
+	protected $_data_handler_class_name = '';
85
+
86
+	/**
87
+	 * one of the message status constants on EEM_Message
88
+	 *
89
+	 * @type string
90
+	 */
91
+	protected $_message_status = '';
92
+
93
+
94
+
95
+	/**
96
+	 * Constructor
97
+	 *
98
+	 * @param string $messenger_name    Slug representing messenger
99
+	 * @param string $message_type_name Slug representing message type.
100
+	 * @param mixed  $data              Data used for generating message.
101
+	 * @param string $context           Optional context to restrict message generated for.
102
+	 * @param bool   $preview           Whether this is being used to generate a preview or not.
103
+	 * @param string $status
104
+	 */
105
+	public function __construct(
106
+		$messenger_name,
107
+		$message_type_name,
108
+		$data = array(),
109
+		$context = '',
110
+		$preview = false,
111
+		$status = EEM_Message::status_incomplete
112
+	) {
113
+		$this->_messenger_name      = $messenger_name;
114
+		$this->_message_type_name   = $message_type_name;
115
+		$this->_data                = is_array($data) ? $data : array( $data );
116
+		$this->_context             = $context;
117
+		$this->_preview             = $preview;
118
+		$this->_status              = $status;
119
+		// attempt to generate message immediately
120
+		$this->_message = $this->_generate_message();
121
+	}
122
+
123
+
124
+
125
+	/**
126
+	 * @return string
127
+	 */
128
+	public function context()
129
+	{
130
+		return $this->_context;
131
+	}
132
+
133
+
134
+
135
+	/**
136
+	 * @return array
137
+	 */
138
+	public function data()
139
+	{
140
+		return $this->_data;
141
+	}
142
+
143
+
144
+
145
+	/**
146
+	 * @return EE_messenger
147
+	 */
148
+	public function messenger()
149
+	{
150
+		return $this->_messenger;
151
+	}
152
+
153
+
154
+
155
+	/**
156
+	 * @return EE_message_type
157
+	 */
158
+	public function message_type()
159
+	{
160
+		return $this->_message_type;
161
+	}
162
+
163
+
164
+
165
+	/**
166
+	 * @return boolean
167
+	 */
168
+	public function preview()
169
+	{
170
+		return $this->_preview;
171
+	}
172
+
173
+
174
+
175
+	/**
176
+	 * @param boolean $preview
177
+	 */
178
+	public function set_preview($preview)
179
+	{
180
+		$this->_preview = filter_var($preview, FILTER_VALIDATE_BOOLEAN);
181
+	}
182
+
183
+
184
+
185
+	/**
186
+	 * @return bool
187
+	 */
188
+	public function send_now()
189
+	{
190
+		return $this->_send_now;
191
+	}
192
+
193
+
194
+
195
+	/**
196
+	 * Simply returns the state of the $_valid property.
197
+	 *
198
+	 * @return bool
199
+	 */
200
+	public function valid()
201
+	{
202
+		return $this->_valid;
203
+	}
204
+
205
+
206
+
207
+	/**
208
+	 * generates an EE_Message using the supplied arguments and some defaults
209
+	 *
210
+	 * @param array $properties
211
+	 * @return string
212
+	 */
213
+	protected function _generate_message($properties = array())
214
+	{
215
+		$message = EE_Message_Factory::create(
216
+			array_merge(
217
+				array(
218
+					'MSG_messenger'    => $this->_messenger_name,
219
+					'MSG_message_type' => $this->_message_type_name,
220
+					'MSG_context'      => $this->_context,
221
+					'STS_ID'           => $this->_status,
222
+				),
223
+				$properties
224
+			)
225
+		);
226
+		// validate the message, and if it's good, set some properties
227
+		try {
228
+			$message->is_valid_for_sending_or_generation(true);
229
+			$this->_valid = true;
230
+			$this->_messenger = $message->messenger_object();
231
+			$this->_message_type = $message->message_type_object();
232
+			$this->_send_now = $message->send_now();
233
+		} catch (Exception $e) {
234
+			$this->_valid = false;
235
+			$this->_error_msg[] = $e->getMessage();
236
+		}
237
+		return $message;
238
+	}
239
+
240
+
241
+
242
+	/**
243
+	 *  Returns an instantiated EE_Message object from the internal data.
244
+	 *
245
+	 * @return EE_Message
246
+	 */
247
+	public function get_EE_Message()
248
+	{
249
+		// already set ?
250
+		if ($this->_message instanceof EE_Message) {
251
+			return $this->_message;
252
+		}
253
+		// no? then let's create one
254
+		$this->_message = $this->_generate_message();
255
+		return $this->_message;
256
+	}
257
+
258
+
259
+
260
+	/**
261
+	 * This returns the data_handler class name for the internal message type set.
262
+	 * Note: this also verifies that the data handler class exists.  If it doesn't then $_valid is set to false
263
+	 * and the data_handler_class name is set to an empty string.
264
+	 *
265
+	 * @param   bool    $preview    Used to indicate that the preview data handler is to be returned.
266
+	 * @return  string
267
+	 */
268
+	public function get_data_handler_class_name($preview = false)
269
+	{
270
+		if ($this->_data_handler_class_name === '' && $this->valid()) {
271
+			$ref = $preview ? 'Preview' : $this->_message_type->get_data_handler($this->_data);
272
+			// make sure internal data is updated.
273
+			$this->_data = $this->_message_type->get_data();
274
+
275
+			// verify
276
+			$this->_data_handler_class_name = EE_Message_To_Generate::verify_and_retrieve_class_name_for_data_handler_reference($ref);
277
+			if ($this->_data_handler_class_name === '') {
278
+				$this->_valid = false;
279
+			}
280
+		}
281
+		return $this->_data_handler_class_name;
282
+	}
283
+
284
+
285
+
286
+	/**
287
+	 * Validates the given string as a reference for an existing, accessible data handler and returns the class name
288
+	 * For the handler the reference matches.
289
+	 *
290
+	 * @param string $data_handler_reference
291
+	 * @return string
292
+	 */
293
+	public static function verify_and_retrieve_class_name_for_data_handler_reference($data_handler_reference)
294
+	{
295
+		$class_name = 'EE_Messages_' . $data_handler_reference . '_incoming_data';
296
+		if (! class_exists($class_name)) {
297
+			EE_Error::add_error(
298
+				sprintf(
299
+					__(
300
+						'The included data handler reference (%s) does not match any valid, accessible, "EE_Messages_incoming_data" classes.  Looking for %s.',
301
+						'event_espresso'
302
+					),
303
+					$data_handler_reference,
304
+					$class_name
305
+				),
306
+				__FILE__,
307
+				__FUNCTION__,
308
+				__LINE__
309
+			);
310
+			$class_name = ''; // clear out class_name so caller knows this isn't valid.
311
+		}
312
+		return $class_name;
313
+	}
314 314
 }
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -112,7 +112,7 @@  discard block
 block discarded – undo
112 112
     ) {
113 113
         $this->_messenger_name      = $messenger_name;
114 114
         $this->_message_type_name   = $message_type_name;
115
-        $this->_data                = is_array($data) ? $data : array( $data );
115
+        $this->_data                = is_array($data) ? $data : array($data);
116 116
         $this->_context             = $context;
117 117
         $this->_preview             = $preview;
118 118
         $this->_status              = $status;
@@ -292,8 +292,8 @@  discard block
 block discarded – undo
292 292
      */
293 293
     public static function verify_and_retrieve_class_name_for_data_handler_reference($data_handler_reference)
294 294
     {
295
-        $class_name = 'EE_Messages_' . $data_handler_reference . '_incoming_data';
296
-        if (! class_exists($class_name)) {
295
+        $class_name = 'EE_Messages_'.$data_handler_reference.'_incoming_data';
296
+        if ( ! class_exists($class_name)) {
297 297
             EE_Error::add_error(
298 298
                 sprintf(
299 299
                     __(
Please login to merge, or discard this patch.
core/libraries/messages/EE_Messages_Processor.lib.php 3 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -493,7 +493,7 @@
 block discarded – undo
493 493
     /**
494 494
      * This simply loops through all active messengers and takes care of setting up the
495 495
      * EE_Message_To_Generate objects.
496
-     * @param $message_type
496
+     * @param string $message_type
497 497
      * @param $data
498 498
      *
499 499
      * @return EE_Message_To_Generate[]
Please login to merge, or discard this patch.
Indentation   +582 added lines, -582 removed lines patch added patch discarded remove patch
@@ -12,590 +12,590 @@
 block discarded – undo
12 12
 {
13 13
 
14 14
 
15
-    /**
16
-     * @type EE_Message_Resource_Manager $_message_resource_manager
17
-     */
18
-    protected $_message_resource_manager;
19
-
20
-    /**
21
-     * @type EE_Messages_Queue
22
-     */
23
-    protected $_queue;
24
-
25
-    /**
26
-     * @type  EE_Messages_Generator
27
-     */
28
-    protected $_generator;
29
-
30
-
31
-
32
-
33
-    /**
34
-     * constructor
35
-     *
36
-     * @param EE_Message_Resource_Manager $message_resource_manager
37
-     */
38
-    public function __construct(EE_Message_Resource_Manager $message_resource_manager)
39
-    {
40
-        $this->_message_resource_manager = $message_resource_manager;
41
-        $this->_init_queue_and_generator();
42
-    }
43
-
44
-
45
-
46
-
47
-    /**
48
-     * This method sets (or resets) the various properties for use.
49
-     *
50
-     * - $_queue = holds the messages queue
51
-     * - $_generator = holds the messages generator
52
-     */
53
-    protected function _init_queue_and_generator()
54
-    {
55
-        $this->_generator = EE_Registry::factory('EE_Messages_Generator');
56
-        $this->_queue = $this->_generator->generation_queue();
57
-    }
58
-
59
-
60
-
61
-
62
-    /**
63
-     * This returns the current set queue.
64
-     * @return EE_Messages_Queue
65
-     */
66
-    public function get_queue()
67
-    {
68
-        return $this->_queue;
69
-    }
70
-
71
-
72
-
73
-    /**
74
-     * This method can be utilized to process messages from a queue and they will be processed immediately on the same request.
75
-     * Please note that this method alone does not bypass the usual "locks" for generation/sending (it assumes client code
76
-     * has already filtered those if necessary).
77
-     *
78
-     * @param EE_Messages_Queue $queue_to_process
79
-     * @return bool  true for success false for error.
80
-     */
81
-    public function process_immediately_from_queue(EE_Messages_Queue $queue_to_process)
82
-    {
83
-        $success = false;
84
-        $messages_to_send = array();
85
-        $messages_to_generate = array();
86
-        // loop through and setup the various messages from the queue so we know what is being processed
87
-        $queue_to_process->get_message_repository()->rewind();
88
-        foreach ($queue_to_process->get_message_repository() as $message) {
89
-            if ($message->STS_ID() === EEM_Message::status_incomplete) {
90
-                $messages_to_generate[] = $message;
91
-                continue;
92
-            }
93
-
94
-            if (in_array($message->STS_ID(), EEM_Message::instance()->stati_indicating_to_send())) {
95
-                $messages_to_send[] = $message;
96
-                continue;
97
-            }
98
-        }
99
-
100
-        // do generation/sends
101
-        if ($messages_to_generate) {
102
-            $success = $this->batch_generate_from_queue($messages_to_generate, true);
103
-        }
104
-
105
-        if ($messages_to_send) {
106
-            $sent = $this->batch_send_from_queue($messages_to_send, true);
107
-            // if there was messages to generate and it failed, then we override any success value for the sending process
108
-            // otherwise we just use the return from batch send.  The intent is that there is a simple response for success/fail.
109
-            // Either everything was successful or we consider it a fail.  To be clear, this is a limitation of doing
110
-            // all messages processing on the same request.
111
-            $success = $messages_to_generate && ! $success ? false : $sent;
112
-        }
113
-        return $success;
114
-    }
115
-
116
-
117
-    /**
118
-     * Calls the EE_Messages_Queue::get_batch_to_generate() method and sends to EE_Messages_Generator.
119
-     *
120
-     * @param  EE_Message[] $messages    Array of EE_Message objects (optional) to build the queue with.
121
-     * @param  bool         $clear_queue Whether to ensure a fresh queue or not.
122
-     *
123
-     * @return bool|EE_Messages_Queue return false if nothing generated.  This returns a new EE_Message_Queue with
124
-     *                                   generated messages.
125
-     */
126
-    public function batch_generate_from_queue($messages = array(), $clear_queue = false)
127
-    {
128
-        if ($this->_build_queue_for_generation($messages, $clear_queue)) {
129
-            $new_queue = $this->_generator->generate();
130
-            if ($new_queue instanceof EE_Messages_Queue) {
131
-                // unlock queue
132
-                $this->_queue->unlock_queue();
133
-                $new_queue->initiate_request_by_priority('send');
134
-                return $new_queue;
135
-            }
136
-        }
137
-        $this->_queue->unlock_queue();
138
-        return false;
139
-    }
140
-
141
-
142
-
143
-    /**
144
-     * This method preps a queue for generation.
145
-     *
146
-     * @since    4.9.0
147
-     *
148
-     * @param EE_Message[] $messages    Array of EE_Message objects to build the queue with
149
-     *
150
-     * @param   bool       $clear_queue This indicates whether the existing queue should be dumped or not.
151
-     *
152
-     * @return bool true means queue prepped, false means there was a lock so no generation please.
153
-     */
154
-    protected function _build_queue_for_generation($messages = array(), $clear_queue = false)
155
-    {
156
-
157
-        if ($clear_queue) {
158
-            $this->_init_queue_and_generator();
159
-        }
160
-
161
-        if ($messages) {
162
-            // if generation is locked then get out now because that means processing is already happening.
163
-            if ($this->_queue->is_locked()) {
164
-                return false;
165
-            }
166
-
167
-            $this->_queue->lock_queue();
168
-            $messages = is_array($messages) ? $messages : array( $messages );
169
-            foreach ($messages as $message) {
170
-                if ($message instanceof EE_Message) {
171
-                    $data = $message->all_extra_meta_array();
172
-                    $this->_queue->add($message, $data);
173
-                }
174
-            }
175
-            return true;
176
-        } else {
177
-            return $this->_queue->get_batch_to_generate();
178
-        }
179
-    }
180
-
181
-
182
-    /**
183
-     * This method preps a queue for sending.
184
-     *
185
-     * @param EE_Message[] $messages
186
-     * @param bool  $clear_queue Used to indicate whether to start with a fresh queue or not.
187
-     *
188
-     * @return bool true means queue prepped, false means there was a lock so no queue prepped.
189
-     */
190
-    protected function _build_queue_for_sending($messages, $clear_queue = false)
191
-    {
192
-        // if sending is locked then get out now because that means processing is already happening.
193
-        if ($this->_queue->is_locked(EE_Messages_Queue::action_sending)) {
194
-            return false;
195
-        }
196
-
197
-        $this->_queue->lock_queue(EE_Messages_Queue::action_sending);
198
-
199
-        if ($clear_queue) {
200
-            $this->_init_queue_and_generator();
201
-        }
202
-
203
-        $messages = is_array($messages) ? $messages : array( $messages );
204
-
205
-        foreach ($messages as $message) {
206
-            $this->_queue->add($message);
207
-        }
208
-        return true;
209
-    }
210
-
211
-
212
-    /**
213
-     * Calls the EE_Message_Queue::get_to_send_batch_and_send() method and then immediately just calls EE_Message_Queue::execute()
214
-     * to iterate and send unsent messages.
215
-     *
216
-     * @param EE_Message[] $messages    If an array of messages is sent in then use it.
217
-     *
218
-     * @param bool         $clear_queue Whether to initialize a new queue or keep the existing one.
219
-     *
220
-     * @return EE_Messages_Queue
221
-     */
222
-    public function batch_send_from_queue($messages = array(), $clear_queue = false)
223
-    {
224
-
225
-        if ($messages && $this->_build_queue_for_sending($messages, $clear_queue)) {
226
-            $this->_queue->execute();
227
-            $this->_queue->unlock_queue(EE_Messages_Queue::action_sending);
228
-        } else {
229
-            // get messages to send and execute.
230
-            $this->_queue->get_to_send_batch_and_send();
231
-        }
232
-        // note: callers can use the EE_Messages_Queue::count_STS_in_queue() method to find out if there were any failed
233
-        // messages in the queue and decide how to handle at that point.
234
-        return $this->_queue;
235
-    }
236
-
237
-
238
-
239
-
240
-
241
-
242
-    /**
243
-     * This immediately generates messages using the given array of EE_Message_To_Generate objects and returns the
244
-     * EE_Message_Queue with the generated messages for the caller to work with.  Note, this does NOT save the generated
245
-     * messages in the queue, leaving it up to the caller to do so.
246
-     *
247
-     * @param EE_Message_To_Generate[] $messages_to_generate
248
-     * @return EE_Messages_Queue
249
-     */
250
-    public function generate_and_return($messages_to_generate)
251
-    {
252
-        $this->_init_queue_and_generator();
253
-        $this->_queue_for_generation_loop($messages_to_generate);
254
-        return $this->_generator->generate(false);
255
-    }
256
-
257
-
258
-
259
-
260
-    /**
261
-     * Executes the generator generate method on the current internal queue, and returns the generated queue.
262
-     * @param  bool     $persist    Indicate whether to instruct the generator to persist the generated queue (true) or not (false).
263
-     * @return EE_Messages_Queue
264
-     */
265
-    public function generate_queue($persist = true)
266
-    {
267
-        return $this->_generator->generate($persist);
268
-    }
15
+	/**
16
+	 * @type EE_Message_Resource_Manager $_message_resource_manager
17
+	 */
18
+	protected $_message_resource_manager;
19
+
20
+	/**
21
+	 * @type EE_Messages_Queue
22
+	 */
23
+	protected $_queue;
24
+
25
+	/**
26
+	 * @type  EE_Messages_Generator
27
+	 */
28
+	protected $_generator;
29
+
30
+
31
+
32
+
33
+	/**
34
+	 * constructor
35
+	 *
36
+	 * @param EE_Message_Resource_Manager $message_resource_manager
37
+	 */
38
+	public function __construct(EE_Message_Resource_Manager $message_resource_manager)
39
+	{
40
+		$this->_message_resource_manager = $message_resource_manager;
41
+		$this->_init_queue_and_generator();
42
+	}
43
+
44
+
45
+
46
+
47
+	/**
48
+	 * This method sets (or resets) the various properties for use.
49
+	 *
50
+	 * - $_queue = holds the messages queue
51
+	 * - $_generator = holds the messages generator
52
+	 */
53
+	protected function _init_queue_and_generator()
54
+	{
55
+		$this->_generator = EE_Registry::factory('EE_Messages_Generator');
56
+		$this->_queue = $this->_generator->generation_queue();
57
+	}
58
+
59
+
60
+
61
+
62
+	/**
63
+	 * This returns the current set queue.
64
+	 * @return EE_Messages_Queue
65
+	 */
66
+	public function get_queue()
67
+	{
68
+		return $this->_queue;
69
+	}
70
+
71
+
72
+
73
+	/**
74
+	 * This method can be utilized to process messages from a queue and they will be processed immediately on the same request.
75
+	 * Please note that this method alone does not bypass the usual "locks" for generation/sending (it assumes client code
76
+	 * has already filtered those if necessary).
77
+	 *
78
+	 * @param EE_Messages_Queue $queue_to_process
79
+	 * @return bool  true for success false for error.
80
+	 */
81
+	public function process_immediately_from_queue(EE_Messages_Queue $queue_to_process)
82
+	{
83
+		$success = false;
84
+		$messages_to_send = array();
85
+		$messages_to_generate = array();
86
+		// loop through and setup the various messages from the queue so we know what is being processed
87
+		$queue_to_process->get_message_repository()->rewind();
88
+		foreach ($queue_to_process->get_message_repository() as $message) {
89
+			if ($message->STS_ID() === EEM_Message::status_incomplete) {
90
+				$messages_to_generate[] = $message;
91
+				continue;
92
+			}
93
+
94
+			if (in_array($message->STS_ID(), EEM_Message::instance()->stati_indicating_to_send())) {
95
+				$messages_to_send[] = $message;
96
+				continue;
97
+			}
98
+		}
99
+
100
+		// do generation/sends
101
+		if ($messages_to_generate) {
102
+			$success = $this->batch_generate_from_queue($messages_to_generate, true);
103
+		}
104
+
105
+		if ($messages_to_send) {
106
+			$sent = $this->batch_send_from_queue($messages_to_send, true);
107
+			// if there was messages to generate and it failed, then we override any success value for the sending process
108
+			// otherwise we just use the return from batch send.  The intent is that there is a simple response for success/fail.
109
+			// Either everything was successful or we consider it a fail.  To be clear, this is a limitation of doing
110
+			// all messages processing on the same request.
111
+			$success = $messages_to_generate && ! $success ? false : $sent;
112
+		}
113
+		return $success;
114
+	}
115
+
116
+
117
+	/**
118
+	 * Calls the EE_Messages_Queue::get_batch_to_generate() method and sends to EE_Messages_Generator.
119
+	 *
120
+	 * @param  EE_Message[] $messages    Array of EE_Message objects (optional) to build the queue with.
121
+	 * @param  bool         $clear_queue Whether to ensure a fresh queue or not.
122
+	 *
123
+	 * @return bool|EE_Messages_Queue return false if nothing generated.  This returns a new EE_Message_Queue with
124
+	 *                                   generated messages.
125
+	 */
126
+	public function batch_generate_from_queue($messages = array(), $clear_queue = false)
127
+	{
128
+		if ($this->_build_queue_for_generation($messages, $clear_queue)) {
129
+			$new_queue = $this->_generator->generate();
130
+			if ($new_queue instanceof EE_Messages_Queue) {
131
+				// unlock queue
132
+				$this->_queue->unlock_queue();
133
+				$new_queue->initiate_request_by_priority('send');
134
+				return $new_queue;
135
+			}
136
+		}
137
+		$this->_queue->unlock_queue();
138
+		return false;
139
+	}
140
+
141
+
142
+
143
+	/**
144
+	 * This method preps a queue for generation.
145
+	 *
146
+	 * @since    4.9.0
147
+	 *
148
+	 * @param EE_Message[] $messages    Array of EE_Message objects to build the queue with
149
+	 *
150
+	 * @param   bool       $clear_queue This indicates whether the existing queue should be dumped or not.
151
+	 *
152
+	 * @return bool true means queue prepped, false means there was a lock so no generation please.
153
+	 */
154
+	protected function _build_queue_for_generation($messages = array(), $clear_queue = false)
155
+	{
156
+
157
+		if ($clear_queue) {
158
+			$this->_init_queue_and_generator();
159
+		}
160
+
161
+		if ($messages) {
162
+			// if generation is locked then get out now because that means processing is already happening.
163
+			if ($this->_queue->is_locked()) {
164
+				return false;
165
+			}
166
+
167
+			$this->_queue->lock_queue();
168
+			$messages = is_array($messages) ? $messages : array( $messages );
169
+			foreach ($messages as $message) {
170
+				if ($message instanceof EE_Message) {
171
+					$data = $message->all_extra_meta_array();
172
+					$this->_queue->add($message, $data);
173
+				}
174
+			}
175
+			return true;
176
+		} else {
177
+			return $this->_queue->get_batch_to_generate();
178
+		}
179
+	}
180
+
181
+
182
+	/**
183
+	 * This method preps a queue for sending.
184
+	 *
185
+	 * @param EE_Message[] $messages
186
+	 * @param bool  $clear_queue Used to indicate whether to start with a fresh queue or not.
187
+	 *
188
+	 * @return bool true means queue prepped, false means there was a lock so no queue prepped.
189
+	 */
190
+	protected function _build_queue_for_sending($messages, $clear_queue = false)
191
+	{
192
+		// if sending is locked then get out now because that means processing is already happening.
193
+		if ($this->_queue->is_locked(EE_Messages_Queue::action_sending)) {
194
+			return false;
195
+		}
196
+
197
+		$this->_queue->lock_queue(EE_Messages_Queue::action_sending);
198
+
199
+		if ($clear_queue) {
200
+			$this->_init_queue_and_generator();
201
+		}
202
+
203
+		$messages = is_array($messages) ? $messages : array( $messages );
204
+
205
+		foreach ($messages as $message) {
206
+			$this->_queue->add($message);
207
+		}
208
+		return true;
209
+	}
210
+
211
+
212
+	/**
213
+	 * Calls the EE_Message_Queue::get_to_send_batch_and_send() method and then immediately just calls EE_Message_Queue::execute()
214
+	 * to iterate and send unsent messages.
215
+	 *
216
+	 * @param EE_Message[] $messages    If an array of messages is sent in then use it.
217
+	 *
218
+	 * @param bool         $clear_queue Whether to initialize a new queue or keep the existing one.
219
+	 *
220
+	 * @return EE_Messages_Queue
221
+	 */
222
+	public function batch_send_from_queue($messages = array(), $clear_queue = false)
223
+	{
224
+
225
+		if ($messages && $this->_build_queue_for_sending($messages, $clear_queue)) {
226
+			$this->_queue->execute();
227
+			$this->_queue->unlock_queue(EE_Messages_Queue::action_sending);
228
+		} else {
229
+			// get messages to send and execute.
230
+			$this->_queue->get_to_send_batch_and_send();
231
+		}
232
+		// note: callers can use the EE_Messages_Queue::count_STS_in_queue() method to find out if there were any failed
233
+		// messages in the queue and decide how to handle at that point.
234
+		return $this->_queue;
235
+	}
236
+
237
+
238
+
239
+
240
+
241
+
242
+	/**
243
+	 * This immediately generates messages using the given array of EE_Message_To_Generate objects and returns the
244
+	 * EE_Message_Queue with the generated messages for the caller to work with.  Note, this does NOT save the generated
245
+	 * messages in the queue, leaving it up to the caller to do so.
246
+	 *
247
+	 * @param EE_Message_To_Generate[] $messages_to_generate
248
+	 * @return EE_Messages_Queue
249
+	 */
250
+	public function generate_and_return($messages_to_generate)
251
+	{
252
+		$this->_init_queue_and_generator();
253
+		$this->_queue_for_generation_loop($messages_to_generate);
254
+		return $this->_generator->generate(false);
255
+	}
256
+
257
+
258
+
259
+
260
+	/**
261
+	 * Executes the generator generate method on the current internal queue, and returns the generated queue.
262
+	 * @param  bool     $persist    Indicate whether to instruct the generator to persist the generated queue (true) or not (false).
263
+	 * @return EE_Messages_Queue
264
+	 */
265
+	public function generate_queue($persist = true)
266
+	{
267
+		return $this->_generator->generate($persist);
268
+	}
269 269
 
270 270
 
271 271
 
272 272
 
273
-    /**
274
-     * Queue for generation.  Note this does NOT persist to the db.  Client code should call get_message_repository()->save() if desire
275
-     * to persist.  This method is provided to client code to decide what it wants to do with queued messages for generation.
276
-     * @param EE_Message_To_Generate $message_to_generate
277
-     * @param bool                   $test_send             Whether this item is for a test send or not.
278
-     * @return  EE_Messages_Queue
279
-     */
280
-    public function queue_for_generation(EE_Message_To_Generate $message_to_generate, $test_send = false)
281
-    {
282
-        if ($message_to_generate->valid()) {
283
-            $this->_generator->create_and_add_message_to_queue($message_to_generate, $test_send);
284
-        }
285
-    }
286
-
287
-
288
-
289
-
290
-
291
-
292
-
293
-    /**
294
-     * This receives an array of EE_Message_To_Generate objects, converts them to EE_Message adds them to the generation queue
295
-     * and then persists to storage.
296
-     *
297
-     * @param EE_Message_To_Generate[] $messages_to_generate
298
-     */
299
-    public function batch_queue_for_generation_and_persist($messages_to_generate)
300
-    {
301
-        $this->_init_queue_and_generator();
302
-        $this->_queue_for_generation_loop($messages_to_generate);
303
-        $this->_queue->save();
304
-    }
305
-
306
-
307
-
308
-
309
-
310
-
311
-    /**
312
-     * This receives an array of EE_Message_To_Generate objects, converts them to EE_Message and adds them to the generation
313
-     * queue.  Does NOT persist to storage (unless there is an error.
314
-     * Client code can retrieve the generated queue by calling EEM_Messages_Processor::get_queue()
315
-     *
316
-     * @param EE_Message_To_Generate[]  $messages_to_generate
317
-     */
318
-    public function batch_queue_for_generation_no_persist($messages_to_generate)
319
-    {
320
-        $this->_init_queue_and_generator();
321
-        $this->_queue_for_generation_loop($messages_to_generate);
322
-    }
323
-
324
-
325
-
326
-
327
-    /**
328
-     * Simply loops through the given array of EE_Message_To_Generate objects and adds them to the _queue as EE_Message
329
-     * objects.
330
-     *
331
-     * @param EE_Message_To_Generate[] $messages_to_generate
332
-     */
333
-    protected function _queue_for_generation_loop($messages_to_generate)
334
-    {
335
-        // make sure is in an array.
336
-        if (! is_array($messages_to_generate)) {
337
-            $messages_to_generate = array( $messages_to_generate );
338
-        }
339
-
340
-        foreach ($messages_to_generate as $message_to_generate) {
341
-            if ($message_to_generate instanceof EE_Message_To_Generate && $message_to_generate->valid()) {
342
-                $this->queue_for_generation($message_to_generate);
343
-            }
344
-        }
345
-    }
346
-
347
-
348
-
349
-
350
-
351
-    /**
352
-     * Receives an array of EE_Message_To_Generate objects and generates the EE_Message objects, then persists (so its
353
-     * queued for sending).
354
-     * @param  EE_Message_To_Generate[]
355
-     * @return EE_Messages_Queue
356
-     */
357
-    public function generate_and_queue_for_sending($messages_to_generate)
358
-    {
359
-        $this->_init_queue_and_generator();
360
-        $this->_queue_for_generation_loop($messages_to_generate);
361
-        return $this->_generator->generate(true);
362
-    }
363
-
364
-
365
-
366
-
367
-
368
-    /**
369
-     * Generate for preview and execute right away.
370
-     *
371
-     * @param   EE_Message_To_Generate $message_to_generate
372
-     * @param   bool                   $test_send                Whether this is a test send or not.
373
-     * @return  EE_Messages_Queue | bool   false if unable to generate otherwise the generated queue.
374
-     */
375
-    public function generate_for_preview(EE_Message_To_Generate $message_to_generate, $test_send = false)
376
-    {
377
-        if (! $message_to_generate->valid()) {
378
-            EE_Error::add_error(
379
-                __('Unable to generate preview because of invalid data', 'event_espresso'),
380
-                __FILE__,
381
-                __FUNCTION__,
382
-                __LINE__
383
-            );
384
-            return false;
385
-        }
386
-        // just make sure preview is set on the $message_to_generate (in case client forgot)
387
-        $message_to_generate->set_preview(true);
388
-        $this->_init_queue_and_generator();
389
-        $this->queue_for_generation($message_to_generate, $test_send);
390
-        $generated_queue = $this->_generator->generate(false);
391
-        if ($generated_queue->execute(false)) {
392
-            // the first queue item should be the preview
393
-            $generated_queue->get_message_repository()->rewind();
394
-            if (! $generated_queue->get_message_repository()->valid()) {
395
-                return $generated_queue;
396
-            }
397
-            return $generated_queue;
398
-        } else {
399
-            return false;
400
-        }
401
-    }
402
-
403
-
404
-    /**
405
-     * This queues for sending.
406
-     * The messenger send now method is also verified to see if sending immediately is requested.
407
-     * otherwise its just saved to the queue.
408
-     * @param EE_Message_To_Generate $message_to_generate
409
-     * @return bool true or false for success.
410
-     */
411
-    public function queue_for_sending(EE_Message_To_Generate $message_to_generate)
412
-    {
413
-        if (! $message_to_generate->valid()) {
414
-            return false;
415
-        }
416
-        $this->_init_queue_and_generator();
417
-        $message = $message_to_generate->get_EE_Message();
418
-        $this->_queue->add($message);
419
-        if ($message->send_now()) {
420
-            $this->_queue->execute(false);
421
-        } else {
422
-            $this->_queue->save();
423
-        }
424
-        return true;
425
-    }
426
-
427
-
428
-    /**
429
-     * This generates and sends from the given EE_Message_To_Generate class immediately.
430
-     * @param EE_Message_To_Generate $message_to_generate
431
-     * @return EE_Messages_Queue | null
432
-     */
433
-    public function generate_and_send_now(EE_Message_To_Generate $message_to_generate)
434
-    {
435
-        if (! $message_to_generate->valid()) {
436
-            return null;
437
-        }
438
-        // is there supposed to be a sending messenger for this message?
439
-        if ($message_to_generate instanceof EEI_Has_Sending_Messenger) {
440
-            // make sure it's valid, but if it's not,
441
-            // then set the value of $sending_messenger to an EE_Error object
442
-            // so that downstream code can easily see that things went wrong.
443
-            $sending_messenger = $message_to_generate->sending_messenger() instanceof EE_messenger
444
-                ? $message_to_generate->sending_messenger()
445
-                : new EE_Error(
446
-                    __(
447
-                        'There was a specific sending messenger requested for the send action, but it was either invalid or not active at time of sending.',
448
-                        'event_espresso'
449
-                    )
450
-                );
451
-        } else {
452
-            $sending_messenger = null;
453
-        }
454
-
455
-        if ($message_to_generate->get_EE_Message()->STS_ID() === EEM_Message::status_idle) {
456
-            $this->_init_queue_and_generator();
457
-            $this->_queue->add($message_to_generate->get_EE_Message());
458
-            $this->_queue->execute(false, $sending_messenger);
459
-            return $this->_queue;
460
-        } elseif ($message_to_generate->get_EE_Message()->STS_ID() === EEM_Message::status_incomplete) {
461
-            $generated_queue = $this->generate_and_return(array( $message_to_generate ));
462
-            $generated_queue->execute(false, $sending_messenger);
463
-            return $generated_queue;
464
-        }
465
-        return null;
466
-    }
467
-
468
-
469
-
470
-
471
-    /**
472
-     * Creates mtg objects for all active messengers and queues for generation.
473
-     * This method also calls the execute by priority method on the queue which will optionally kick off a new non-blocking
474
-     * request to complete the action if the priority for the message requires immediate action.
475
-     * @param string $message_type
476
-     * @param mixed  $data   The data being used for generation.
477
-     * @param bool   $persist   Whether to persist the queued messages to the db or not.
478
-     */
479
-    public function generate_for_all_active_messengers($message_type, $data, $persist = true)
480
-    {
481
-        $messages_to_generate = $this->setup_mtgs_for_all_active_messengers($message_type, $data);
482
-        if ($persist) {
483
-            $this->batch_queue_for_generation_and_persist($messages_to_generate);
484
-            $this->_queue->initiate_request_by_priority();
485
-        } else {
486
-            $this->batch_queue_for_generation_no_persist($messages_to_generate);
487
-        }
488
-    }
489
-
490
-
491
-
492
-
493
-    /**
494
-     * This simply loops through all active messengers and takes care of setting up the
495
-     * EE_Message_To_Generate objects.
496
-     * @param $message_type
497
-     * @param $data
498
-     *
499
-     * @return EE_Message_To_Generate[]
500
-     */
501
-    public function setup_mtgs_for_all_active_messengers($message_type, $data)
502
-    {
503
-        $messages_to_generate = array();
504
-        foreach ($this->_message_resource_manager->active_messengers() as $messenger_slug => $messenger_object) {
505
-            $message_to_generate = new EE_Message_To_Generate($messenger_slug, $message_type, $data);
506
-            if ($message_to_generate->valid()) {
507
-                $messages_to_generate[] = $message_to_generate;
508
-            }
509
-        }
510
-        return $messages_to_generate;
511
-    }
512
-
513
-
514
-
515
-
516
-    /**
517
-     * This accepts an array of EE_Message::MSG_ID values and will use that to retrieve the objects from the database
518
-     * and send.
519
-     * @param array $message_ids
520
-     */
521
-    public function setup_messages_from_ids_and_send($message_ids)
522
-    {
523
-        $this->_init_queue_and_generator();
524
-        $messages = EEM_Message::instance()->get_all(array(
525
-            array(
526
-                'MSG_ID' => array( 'IN', $message_ids ),
527
-                'STS_ID' => array(
528
-                    'IN',
529
-                    array_merge(
530
-                        EEM_Message::instance()->stati_indicating_sent(),
531
-                        array( EEM_Message::status_retry )
532
-                    ),
533
-                ),
534
-            ),
535
-        ));
536
-        // set the Messages to resend.
537
-        foreach ($messages as $message) {
538
-            if ($message instanceof EE_Message) {
539
-                $message->set_STS_ID(EEM_Message::status_resend);
540
-                $this->_queue->add($message);
541
-            }
542
-        }
543
-
544
-        $this->_queue->initiate_request_by_priority('send');
545
-    }
546
-
547
-
548
-
549
-    /**
550
-     * This method checks for registration IDs in the request via the given key and creates the messages to generate
551
-     * objects from them, then returns the array of messages to generate objects.
552
-     * Note, this sets up registrations for the registration family of message types.
553
-     *
554
-     * @param string $registration_ids_key  This is used to indicate what represents the registration ids in the request.
555
-     *
556
-     * @return EE_Message_To_Generate[]
557
-     */
558
-    public function setup_messages_to_generate_from_registration_ids_in_request($registration_ids_key = '_REG_ID')
559
-    {
560
-        EE_Registry::instance()->load_core('Request_Handler');
561
-        EE_Registry::instance()->load_helper('MSG_Template');
562
-        $regs_to_send = array();
563
-        $regIDs = EE_Registry::instance()->REQ->get($registration_ids_key);
564
-        if (empty($regIDs)) {
565
-            EE_Error::add_error(__('Something went wrong because we\'re missing the registration ID', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__);
566
-            return false;
567
-        }
568
-
569
-        // make sure is an array
570
-        $regIDs = is_array($regIDs) ? $regIDs : array( $regIDs );
571
-
572
-        foreach ($regIDs as $regID) {
573
-            $reg = EEM_Registration::instance()->get_one_by_ID($regID);
574
-            if (! $reg instanceof EE_Registration) {
575
-                EE_Error::add_error(sprintf(__('Unable to retrieve a registration object for the given reg id (%s)', 'event_espresso'), $regID));
576
-                return false;
577
-            }
578
-            $regs_to_send[ $reg->transaction_ID() ][ $reg->status_ID() ][] = $reg;
579
-        }
580
-
581
-        $messages_to_generate = array();
582
-
583
-        foreach ($regs_to_send as $status_group) {
584
-            foreach ($status_group as $status_id => $registrations) {
585
-                $message_type = EEH_MSG_Template::convert_reg_status_to_message_type($status_id);
586
-                if (! $message_type) {
587
-                    continue;
588
-                }
589
-                $messages_to_generate = array_merge(
590
-                    $messages_to_generate,
591
-                    $this->setup_mtgs_for_all_active_messengers(
592
-                        $message_type,
593
-                        array( $registrations, $status_id )
594
-                    )
595
-                );
596
-            }
597
-        }
598
-
599
-        return $messages_to_generate;
600
-    }
273
+	/**
274
+	 * Queue for generation.  Note this does NOT persist to the db.  Client code should call get_message_repository()->save() if desire
275
+	 * to persist.  This method is provided to client code to decide what it wants to do with queued messages for generation.
276
+	 * @param EE_Message_To_Generate $message_to_generate
277
+	 * @param bool                   $test_send             Whether this item is for a test send or not.
278
+	 * @return  EE_Messages_Queue
279
+	 */
280
+	public function queue_for_generation(EE_Message_To_Generate $message_to_generate, $test_send = false)
281
+	{
282
+		if ($message_to_generate->valid()) {
283
+			$this->_generator->create_and_add_message_to_queue($message_to_generate, $test_send);
284
+		}
285
+	}
286
+
287
+
288
+
289
+
290
+
291
+
292
+
293
+	/**
294
+	 * This receives an array of EE_Message_To_Generate objects, converts them to EE_Message adds them to the generation queue
295
+	 * and then persists to storage.
296
+	 *
297
+	 * @param EE_Message_To_Generate[] $messages_to_generate
298
+	 */
299
+	public function batch_queue_for_generation_and_persist($messages_to_generate)
300
+	{
301
+		$this->_init_queue_and_generator();
302
+		$this->_queue_for_generation_loop($messages_to_generate);
303
+		$this->_queue->save();
304
+	}
305
+
306
+
307
+
308
+
309
+
310
+
311
+	/**
312
+	 * This receives an array of EE_Message_To_Generate objects, converts them to EE_Message and adds them to the generation
313
+	 * queue.  Does NOT persist to storage (unless there is an error.
314
+	 * Client code can retrieve the generated queue by calling EEM_Messages_Processor::get_queue()
315
+	 *
316
+	 * @param EE_Message_To_Generate[]  $messages_to_generate
317
+	 */
318
+	public function batch_queue_for_generation_no_persist($messages_to_generate)
319
+	{
320
+		$this->_init_queue_and_generator();
321
+		$this->_queue_for_generation_loop($messages_to_generate);
322
+	}
323
+
324
+
325
+
326
+
327
+	/**
328
+	 * Simply loops through the given array of EE_Message_To_Generate objects and adds them to the _queue as EE_Message
329
+	 * objects.
330
+	 *
331
+	 * @param EE_Message_To_Generate[] $messages_to_generate
332
+	 */
333
+	protected function _queue_for_generation_loop($messages_to_generate)
334
+	{
335
+		// make sure is in an array.
336
+		if (! is_array($messages_to_generate)) {
337
+			$messages_to_generate = array( $messages_to_generate );
338
+		}
339
+
340
+		foreach ($messages_to_generate as $message_to_generate) {
341
+			if ($message_to_generate instanceof EE_Message_To_Generate && $message_to_generate->valid()) {
342
+				$this->queue_for_generation($message_to_generate);
343
+			}
344
+		}
345
+	}
346
+
347
+
348
+
349
+
350
+
351
+	/**
352
+	 * Receives an array of EE_Message_To_Generate objects and generates the EE_Message objects, then persists (so its
353
+	 * queued for sending).
354
+	 * @param  EE_Message_To_Generate[]
355
+	 * @return EE_Messages_Queue
356
+	 */
357
+	public function generate_and_queue_for_sending($messages_to_generate)
358
+	{
359
+		$this->_init_queue_and_generator();
360
+		$this->_queue_for_generation_loop($messages_to_generate);
361
+		return $this->_generator->generate(true);
362
+	}
363
+
364
+
365
+
366
+
367
+
368
+	/**
369
+	 * Generate for preview and execute right away.
370
+	 *
371
+	 * @param   EE_Message_To_Generate $message_to_generate
372
+	 * @param   bool                   $test_send                Whether this is a test send or not.
373
+	 * @return  EE_Messages_Queue | bool   false if unable to generate otherwise the generated queue.
374
+	 */
375
+	public function generate_for_preview(EE_Message_To_Generate $message_to_generate, $test_send = false)
376
+	{
377
+		if (! $message_to_generate->valid()) {
378
+			EE_Error::add_error(
379
+				__('Unable to generate preview because of invalid data', 'event_espresso'),
380
+				__FILE__,
381
+				__FUNCTION__,
382
+				__LINE__
383
+			);
384
+			return false;
385
+		}
386
+		// just make sure preview is set on the $message_to_generate (in case client forgot)
387
+		$message_to_generate->set_preview(true);
388
+		$this->_init_queue_and_generator();
389
+		$this->queue_for_generation($message_to_generate, $test_send);
390
+		$generated_queue = $this->_generator->generate(false);
391
+		if ($generated_queue->execute(false)) {
392
+			// the first queue item should be the preview
393
+			$generated_queue->get_message_repository()->rewind();
394
+			if (! $generated_queue->get_message_repository()->valid()) {
395
+				return $generated_queue;
396
+			}
397
+			return $generated_queue;
398
+		} else {
399
+			return false;
400
+		}
401
+	}
402
+
403
+
404
+	/**
405
+	 * This queues for sending.
406
+	 * The messenger send now method is also verified to see if sending immediately is requested.
407
+	 * otherwise its just saved to the queue.
408
+	 * @param EE_Message_To_Generate $message_to_generate
409
+	 * @return bool true or false for success.
410
+	 */
411
+	public function queue_for_sending(EE_Message_To_Generate $message_to_generate)
412
+	{
413
+		if (! $message_to_generate->valid()) {
414
+			return false;
415
+		}
416
+		$this->_init_queue_and_generator();
417
+		$message = $message_to_generate->get_EE_Message();
418
+		$this->_queue->add($message);
419
+		if ($message->send_now()) {
420
+			$this->_queue->execute(false);
421
+		} else {
422
+			$this->_queue->save();
423
+		}
424
+		return true;
425
+	}
426
+
427
+
428
+	/**
429
+	 * This generates and sends from the given EE_Message_To_Generate class immediately.
430
+	 * @param EE_Message_To_Generate $message_to_generate
431
+	 * @return EE_Messages_Queue | null
432
+	 */
433
+	public function generate_and_send_now(EE_Message_To_Generate $message_to_generate)
434
+	{
435
+		if (! $message_to_generate->valid()) {
436
+			return null;
437
+		}
438
+		// is there supposed to be a sending messenger for this message?
439
+		if ($message_to_generate instanceof EEI_Has_Sending_Messenger) {
440
+			// make sure it's valid, but if it's not,
441
+			// then set the value of $sending_messenger to an EE_Error object
442
+			// so that downstream code can easily see that things went wrong.
443
+			$sending_messenger = $message_to_generate->sending_messenger() instanceof EE_messenger
444
+				? $message_to_generate->sending_messenger()
445
+				: new EE_Error(
446
+					__(
447
+						'There was a specific sending messenger requested for the send action, but it was either invalid or not active at time of sending.',
448
+						'event_espresso'
449
+					)
450
+				);
451
+		} else {
452
+			$sending_messenger = null;
453
+		}
454
+
455
+		if ($message_to_generate->get_EE_Message()->STS_ID() === EEM_Message::status_idle) {
456
+			$this->_init_queue_and_generator();
457
+			$this->_queue->add($message_to_generate->get_EE_Message());
458
+			$this->_queue->execute(false, $sending_messenger);
459
+			return $this->_queue;
460
+		} elseif ($message_to_generate->get_EE_Message()->STS_ID() === EEM_Message::status_incomplete) {
461
+			$generated_queue = $this->generate_and_return(array( $message_to_generate ));
462
+			$generated_queue->execute(false, $sending_messenger);
463
+			return $generated_queue;
464
+		}
465
+		return null;
466
+	}
467
+
468
+
469
+
470
+
471
+	/**
472
+	 * Creates mtg objects for all active messengers and queues for generation.
473
+	 * This method also calls the execute by priority method on the queue which will optionally kick off a new non-blocking
474
+	 * request to complete the action if the priority for the message requires immediate action.
475
+	 * @param string $message_type
476
+	 * @param mixed  $data   The data being used for generation.
477
+	 * @param bool   $persist   Whether to persist the queued messages to the db or not.
478
+	 */
479
+	public function generate_for_all_active_messengers($message_type, $data, $persist = true)
480
+	{
481
+		$messages_to_generate = $this->setup_mtgs_for_all_active_messengers($message_type, $data);
482
+		if ($persist) {
483
+			$this->batch_queue_for_generation_and_persist($messages_to_generate);
484
+			$this->_queue->initiate_request_by_priority();
485
+		} else {
486
+			$this->batch_queue_for_generation_no_persist($messages_to_generate);
487
+		}
488
+	}
489
+
490
+
491
+
492
+
493
+	/**
494
+	 * This simply loops through all active messengers and takes care of setting up the
495
+	 * EE_Message_To_Generate objects.
496
+	 * @param $message_type
497
+	 * @param $data
498
+	 *
499
+	 * @return EE_Message_To_Generate[]
500
+	 */
501
+	public function setup_mtgs_for_all_active_messengers($message_type, $data)
502
+	{
503
+		$messages_to_generate = array();
504
+		foreach ($this->_message_resource_manager->active_messengers() as $messenger_slug => $messenger_object) {
505
+			$message_to_generate = new EE_Message_To_Generate($messenger_slug, $message_type, $data);
506
+			if ($message_to_generate->valid()) {
507
+				$messages_to_generate[] = $message_to_generate;
508
+			}
509
+		}
510
+		return $messages_to_generate;
511
+	}
512
+
513
+
514
+
515
+
516
+	/**
517
+	 * This accepts an array of EE_Message::MSG_ID values and will use that to retrieve the objects from the database
518
+	 * and send.
519
+	 * @param array $message_ids
520
+	 */
521
+	public function setup_messages_from_ids_and_send($message_ids)
522
+	{
523
+		$this->_init_queue_and_generator();
524
+		$messages = EEM_Message::instance()->get_all(array(
525
+			array(
526
+				'MSG_ID' => array( 'IN', $message_ids ),
527
+				'STS_ID' => array(
528
+					'IN',
529
+					array_merge(
530
+						EEM_Message::instance()->stati_indicating_sent(),
531
+						array( EEM_Message::status_retry )
532
+					),
533
+				),
534
+			),
535
+		));
536
+		// set the Messages to resend.
537
+		foreach ($messages as $message) {
538
+			if ($message instanceof EE_Message) {
539
+				$message->set_STS_ID(EEM_Message::status_resend);
540
+				$this->_queue->add($message);
541
+			}
542
+		}
543
+
544
+		$this->_queue->initiate_request_by_priority('send');
545
+	}
546
+
547
+
548
+
549
+	/**
550
+	 * This method checks for registration IDs in the request via the given key and creates the messages to generate
551
+	 * objects from them, then returns the array of messages to generate objects.
552
+	 * Note, this sets up registrations for the registration family of message types.
553
+	 *
554
+	 * @param string $registration_ids_key  This is used to indicate what represents the registration ids in the request.
555
+	 *
556
+	 * @return EE_Message_To_Generate[]
557
+	 */
558
+	public function setup_messages_to_generate_from_registration_ids_in_request($registration_ids_key = '_REG_ID')
559
+	{
560
+		EE_Registry::instance()->load_core('Request_Handler');
561
+		EE_Registry::instance()->load_helper('MSG_Template');
562
+		$regs_to_send = array();
563
+		$regIDs = EE_Registry::instance()->REQ->get($registration_ids_key);
564
+		if (empty($regIDs)) {
565
+			EE_Error::add_error(__('Something went wrong because we\'re missing the registration ID', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__);
566
+			return false;
567
+		}
568
+
569
+		// make sure is an array
570
+		$regIDs = is_array($regIDs) ? $regIDs : array( $regIDs );
571
+
572
+		foreach ($regIDs as $regID) {
573
+			$reg = EEM_Registration::instance()->get_one_by_ID($regID);
574
+			if (! $reg instanceof EE_Registration) {
575
+				EE_Error::add_error(sprintf(__('Unable to retrieve a registration object for the given reg id (%s)', 'event_espresso'), $regID));
576
+				return false;
577
+			}
578
+			$regs_to_send[ $reg->transaction_ID() ][ $reg->status_ID() ][] = $reg;
579
+		}
580
+
581
+		$messages_to_generate = array();
582
+
583
+		foreach ($regs_to_send as $status_group) {
584
+			foreach ($status_group as $status_id => $registrations) {
585
+				$message_type = EEH_MSG_Template::convert_reg_status_to_message_type($status_id);
586
+				if (! $message_type) {
587
+					continue;
588
+				}
589
+				$messages_to_generate = array_merge(
590
+					$messages_to_generate,
591
+					$this->setup_mtgs_for_all_active_messengers(
592
+						$message_type,
593
+						array( $registrations, $status_id )
594
+					)
595
+				);
596
+			}
597
+		}
598
+
599
+		return $messages_to_generate;
600
+	}
601 601
 }
Please login to merge, or discard this patch.
Spacing   +16 added lines, -16 removed lines patch added patch discarded remove patch
@@ -165,7 +165,7 @@  discard block
 block discarded – undo
165 165
             }
166 166
 
167 167
             $this->_queue->lock_queue();
168
-            $messages = is_array($messages) ? $messages : array( $messages );
168
+            $messages = is_array($messages) ? $messages : array($messages);
169 169
             foreach ($messages as $message) {
170 170
                 if ($message instanceof EE_Message) {
171 171
                     $data = $message->all_extra_meta_array();
@@ -200,7 +200,7 @@  discard block
 block discarded – undo
200 200
             $this->_init_queue_and_generator();
201 201
         }
202 202
 
203
-        $messages = is_array($messages) ? $messages : array( $messages );
203
+        $messages = is_array($messages) ? $messages : array($messages);
204 204
 
205 205
         foreach ($messages as $message) {
206 206
             $this->_queue->add($message);
@@ -333,8 +333,8 @@  discard block
 block discarded – undo
333 333
     protected function _queue_for_generation_loop($messages_to_generate)
334 334
     {
335 335
         // make sure is in an array.
336
-        if (! is_array($messages_to_generate)) {
337
-            $messages_to_generate = array( $messages_to_generate );
336
+        if ( ! is_array($messages_to_generate)) {
337
+            $messages_to_generate = array($messages_to_generate);
338 338
         }
339 339
 
340 340
         foreach ($messages_to_generate as $message_to_generate) {
@@ -374,7 +374,7 @@  discard block
 block discarded – undo
374 374
      */
375 375
     public function generate_for_preview(EE_Message_To_Generate $message_to_generate, $test_send = false)
376 376
     {
377
-        if (! $message_to_generate->valid()) {
377
+        if ( ! $message_to_generate->valid()) {
378 378
             EE_Error::add_error(
379 379
                 __('Unable to generate preview because of invalid data', 'event_espresso'),
380 380
                 __FILE__,
@@ -391,7 +391,7 @@  discard block
 block discarded – undo
391 391
         if ($generated_queue->execute(false)) {
392 392
             // the first queue item should be the preview
393 393
             $generated_queue->get_message_repository()->rewind();
394
-            if (! $generated_queue->get_message_repository()->valid()) {
394
+            if ( ! $generated_queue->get_message_repository()->valid()) {
395 395
                 return $generated_queue;
396 396
             }
397 397
             return $generated_queue;
@@ -410,7 +410,7 @@  discard block
 block discarded – undo
410 410
      */
411 411
     public function queue_for_sending(EE_Message_To_Generate $message_to_generate)
412 412
     {
413
-        if (! $message_to_generate->valid()) {
413
+        if ( ! $message_to_generate->valid()) {
414 414
             return false;
415 415
         }
416 416
         $this->_init_queue_and_generator();
@@ -432,7 +432,7 @@  discard block
 block discarded – undo
432 432
      */
433 433
     public function generate_and_send_now(EE_Message_To_Generate $message_to_generate)
434 434
     {
435
-        if (! $message_to_generate->valid()) {
435
+        if ( ! $message_to_generate->valid()) {
436 436
             return null;
437 437
         }
438 438
         // is there supposed to be a sending messenger for this message?
@@ -458,7 +458,7 @@  discard block
 block discarded – undo
458 458
             $this->_queue->execute(false, $sending_messenger);
459 459
             return $this->_queue;
460 460
         } elseif ($message_to_generate->get_EE_Message()->STS_ID() === EEM_Message::status_incomplete) {
461
-            $generated_queue = $this->generate_and_return(array( $message_to_generate ));
461
+            $generated_queue = $this->generate_and_return(array($message_to_generate));
462 462
             $generated_queue->execute(false, $sending_messenger);
463 463
             return $generated_queue;
464 464
         }
@@ -523,12 +523,12 @@  discard block
 block discarded – undo
523 523
         $this->_init_queue_and_generator();
524 524
         $messages = EEM_Message::instance()->get_all(array(
525 525
             array(
526
-                'MSG_ID' => array( 'IN', $message_ids ),
526
+                'MSG_ID' => array('IN', $message_ids),
527 527
                 'STS_ID' => array(
528 528
                     'IN',
529 529
                     array_merge(
530 530
                         EEM_Message::instance()->stati_indicating_sent(),
531
-                        array( EEM_Message::status_retry )
531
+                        array(EEM_Message::status_retry)
532 532
                     ),
533 533
                 ),
534 534
             ),
@@ -567,15 +567,15 @@  discard block
 block discarded – undo
567 567
         }
568 568
 
569 569
         // make sure is an array
570
-        $regIDs = is_array($regIDs) ? $regIDs : array( $regIDs );
570
+        $regIDs = is_array($regIDs) ? $regIDs : array($regIDs);
571 571
 
572 572
         foreach ($regIDs as $regID) {
573 573
             $reg = EEM_Registration::instance()->get_one_by_ID($regID);
574
-            if (! $reg instanceof EE_Registration) {
574
+            if ( ! $reg instanceof EE_Registration) {
575 575
                 EE_Error::add_error(sprintf(__('Unable to retrieve a registration object for the given reg id (%s)', 'event_espresso'), $regID));
576 576
                 return false;
577 577
             }
578
-            $regs_to_send[ $reg->transaction_ID() ][ $reg->status_ID() ][] = $reg;
578
+            $regs_to_send[$reg->transaction_ID()][$reg->status_ID()][] = $reg;
579 579
         }
580 580
 
581 581
         $messages_to_generate = array();
@@ -583,14 +583,14 @@  discard block
 block discarded – undo
583 583
         foreach ($regs_to_send as $status_group) {
584 584
             foreach ($status_group as $status_id => $registrations) {
585 585
                 $message_type = EEH_MSG_Template::convert_reg_status_to_message_type($status_id);
586
-                if (! $message_type) {
586
+                if ( ! $message_type) {
587 587
                     continue;
588 588
                 }
589 589
                 $messages_to_generate = array_merge(
590 590
                     $messages_to_generate,
591 591
                     $this->setup_mtgs_for_all_active_messengers(
592 592
                         $message_type,
593
-                        array( $registrations, $status_id )
593
+                        array($registrations, $status_id)
594 594
                     )
595 595
                 );
596 596
             }
Please login to merge, or discard this patch.
core/libraries/messages/EE_messenger.lib.php 3 patches
Doc Comments   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -503,7 +503,7 @@  discard block
 block discarded – undo
503 503
     /**
504 504
      * @param $message_types
505 505
      * @param array $extra
506
-     * @return mixed|string
506
+     * @return string
507 507
      */
508 508
     protected function _get_admin_content_events_edit($message_types, $extra)
509 509
     {
@@ -815,7 +815,7 @@  discard block
 block discarded – undo
815 815
      * All this does is set the existing test settings (in the db) for the messenger
816 816
      *
817 817
      * @access public
818
-     * @param $settings
818
+     * @param string $settings
819 819
      * @return bool success/fail
820 820
      */
821 821
     public function set_existing_test_settings($settings)
Please login to merge, or discard this patch.
Indentation   +722 added lines, -722 removed lines patch added patch discarded remove patch
@@ -18,182 +18,182 @@  discard block
 block discarded – undo
18 18
 
19 19
 
20 20
 
21
-    /**
22
-     * This property holds the default message types associated with this messenger when it is activated. The values of the array must match a valid message type.
23
-     * This property gets set by the _set_default_message_types() method.
24
-     *
25
-     * @var array
26
-     */
27
-    protected $_default_message_types = array();
21
+	/**
22
+	 * This property holds the default message types associated with this messenger when it is activated. The values of the array must match a valid message type.
23
+	 * This property gets set by the _set_default_message_types() method.
24
+	 *
25
+	 * @var array
26
+	 */
27
+	protected $_default_message_types = array();
28 28
 
29 29
 
30 30
 
31 31
 
32
-    /**
33
-     * This property holds the message types that are valid for use with this messenger.
34
-     * It gets set by the _set_valid_message_types() method.
35
-     *
36
-     * @var array
37
-     */
38
-    protected $_valid_message_types = array();
32
+	/**
33
+	 * This property holds the message types that are valid for use with this messenger.
34
+	 * It gets set by the _set_valid_message_types() method.
35
+	 *
36
+	 * @var array
37
+	 */
38
+	protected $_valid_message_types = array();
39 39
 
40 40
 
41 41
 
42
-    /**
43
-     * Holds the configuration for the EE_Messages_Validator class to know how to validated the different fields. Note that the Validator will match each field here with the allowed shortcodes set in the "valid_shortcodes" array for the matched message type context.  So message types don't need to set a $_validator_config property.
44
-     *
45
-     * Remember, ALL fields must be declared in this array.  However, an empty value for the field means that the field will accept all valid shortcodes set for the given context in the message type (by default).
46
-     *
47
-     * Array should be in this format:
48
-     *
49
-     * array(
50
-     *  'field_name(i.e.to)' => array(
51
-     *      'shortcodes' => array('email'), //an array of shortcode groups (correspond to EE_Shortcodes library class) that are allowed in the field. Typically you can just include $this->_valid_shortcodes['field_name'] as the value here (because they will match).
52
-     *      'specific_shortcodes' => array( array('[EVENT_AUTHOR_EMAIL]' => __('Admin Email', 'event_espresso')), //if this index is present you can further restrict the field to ONLY specific shortcodes if an entire group isn't sufficient. Specific shortcodes need to be listed as an array with the index the shortcode and the value = the label.
53
-     *      'type' => 'email' //this is the field type and should match one of the validator types (see EE_Messages_Validator::validator() for all the possible types).  If not required you can just leave empty.,
54
-     *      'required' => array'[SHORTCODE]') //this is used to indicate the shortcodes that MUST be in the assembled array of shortcodes by the validator in order for this field to be included in validation.  Otherwise the validator will always assign shortcodes for this field (regardless of whether the field settings for the given messenger/message_type/context use the field or not.).. please note, this does NOT mean that the shortcodes listed here MUST be in the given field.
55
-     *  )
56
-     * )
57
-     *
58
-     * @var array
59
-     */
60
-    protected $_validator_config = array();
42
+	/**
43
+	 * Holds the configuration for the EE_Messages_Validator class to know how to validated the different fields. Note that the Validator will match each field here with the allowed shortcodes set in the "valid_shortcodes" array for the matched message type context.  So message types don't need to set a $_validator_config property.
44
+	 *
45
+	 * Remember, ALL fields must be declared in this array.  However, an empty value for the field means that the field will accept all valid shortcodes set for the given context in the message type (by default).
46
+	 *
47
+	 * Array should be in this format:
48
+	 *
49
+	 * array(
50
+	 *  'field_name(i.e.to)' => array(
51
+	 *      'shortcodes' => array('email'), //an array of shortcode groups (correspond to EE_Shortcodes library class) that are allowed in the field. Typically you can just include $this->_valid_shortcodes['field_name'] as the value here (because they will match).
52
+	 *      'specific_shortcodes' => array( array('[EVENT_AUTHOR_EMAIL]' => __('Admin Email', 'event_espresso')), //if this index is present you can further restrict the field to ONLY specific shortcodes if an entire group isn't sufficient. Specific shortcodes need to be listed as an array with the index the shortcode and the value = the label.
53
+	 *      'type' => 'email' //this is the field type and should match one of the validator types (see EE_Messages_Validator::validator() for all the possible types).  If not required you can just leave empty.,
54
+	 *      'required' => array'[SHORTCODE]') //this is used to indicate the shortcodes that MUST be in the assembled array of shortcodes by the validator in order for this field to be included in validation.  Otherwise the validator will always assign shortcodes for this field (regardless of whether the field settings for the given messenger/message_type/context use the field or not.).. please note, this does NOT mean that the shortcodes listed here MUST be in the given field.
55
+	 *  )
56
+	 * )
57
+	 *
58
+	 * @var array
59
+	 */
60
+	protected $_validator_config = array();
61 61
 
62 62
 
63 63
 
64
-    /**
65
-     * This will hold the EEM_message_templates model for interacting with the database and retrieving active templates for the messenger
66
-     * @var object
67
-     */
68
-    protected $_EEM_data;
64
+	/**
65
+	 * This will hold the EEM_message_templates model for interacting with the database and retrieving active templates for the messenger
66
+	 * @var object
67
+	 */
68
+	protected $_EEM_data;
69 69
 
70 70
 
71 71
 
72
-    /**
73
-     * this property just holds an array of the various template refs.
74
-     * @var array
75
-     */
76
-    protected $_template_fields = array();
72
+	/**
73
+	 * this property just holds an array of the various template refs.
74
+	 * @var array
75
+	 */
76
+	protected $_template_fields = array();
77 77
 
78 78
 
79 79
 
80 80
 
81
-    /**
82
-     * This holds an array of the arguments used in parsing a template for the sender.
83
-     * @var array
84
-     */
85
-    protected $_template_args = array();
81
+	/**
82
+	 * This holds an array of the arguments used in parsing a template for the sender.
83
+	 * @var array
84
+	 */
85
+	protected $_template_args = array();
86 86
 
87 87
 
88 88
 
89 89
 
90 90
 
91 91
 
92
-    /**
93
-     * This property will hold the configuration for any test settings fields that are required for the "test" button that is used to trigger an actual test of this messenger
94
-     *
95
-     * @protected
96
-     * @var array
97
-     */
98
-    protected $_test_settings_fields = array();
92
+	/**
93
+	 * This property will hold the configuration for any test settings fields that are required for the "test" button that is used to trigger an actual test of this messenger
94
+	 *
95
+	 * @protected
96
+	 * @var array
97
+	 */
98
+	protected $_test_settings_fields = array();
99 99
 
100 100
 
101 101
 
102 102
 
103 103
 
104 104
 
105
-    /**
106
-     * This will hold the EE_Messages_Template_Pack object when set on the messenger.  This is set via the validate and setup method which grabs the template pack from the incoming messages object.
107
-     *
108
-     * @since 4.5.0
109
-     *
110
-     * @var EE_Messages_Template_Pack
111
-     */
112
-    protected $_tmp_pack;
105
+	/**
106
+	 * This will hold the EE_Messages_Template_Pack object when set on the messenger.  This is set via the validate and setup method which grabs the template pack from the incoming messages object.
107
+	 *
108
+	 * @since 4.5.0
109
+	 *
110
+	 * @var EE_Messages_Template_Pack
111
+	 */
112
+	protected $_tmp_pack;
113 113
 
114 114
 
115 115
 
116 116
 
117
-    /**
118
-     * This will hold the variation to use when performing a send.  It is set via the validate and setup method which grabs the variation from the incoming messages object on the send method.
119
-     *
120
-     * @since 4.5.0
121
-     *
122
-     * @var string
123
-     */
124
-    protected $_variation;
117
+	/**
118
+	 * This will hold the variation to use when performing a send.  It is set via the validate and setup method which grabs the variation from the incoming messages object on the send method.
119
+	 *
120
+	 * @since 4.5.0
121
+	 *
122
+	 * @var string
123
+	 */
124
+	protected $_variation;
125 125
 
126 126
 
127 127
 
128 128
 
129 129
 
130
-    /**
131
-     * This property is a stdClass that holds labels for all the various supporting properties for this messenger.  These labels are set via the _set_supports_labels() method in children classes. Initially this will include the label for:
132
-     *
133
-     *  - template pack
134
-     *  - template variation
135
-     *
136
-     * @since 4.5.0
137
-     *
138
-     * @var stdClass
139
-     */
140
-    protected $_supports_labels;
130
+	/**
131
+	 * This property is a stdClass that holds labels for all the various supporting properties for this messenger.  These labels are set via the _set_supports_labels() method in children classes. Initially this will include the label for:
132
+	 *
133
+	 *  - template pack
134
+	 *  - template variation
135
+	 *
136
+	 * @since 4.5.0
137
+	 *
138
+	 * @var stdClass
139
+	 */
140
+	protected $_supports_labels;
141 141
 
142 142
 
143 143
 
144 144
 
145 145
 
146
-    /**
147
-     * This property is set when the send_message() method is called and holds the Message Type used to generate templates with this messenger for the messages.
148
-     *
149
-     * @var EE_message_type
150
-     */
151
-    protected $_incoming_message_type;
146
+	/**
147
+	 * This property is set when the send_message() method is called and holds the Message Type used to generate templates with this messenger for the messages.
148
+	 *
149
+	 * @var EE_message_type
150
+	 */
151
+	protected $_incoming_message_type;
152 152
 
153 153
 
154 154
 
155
-    /**
156
-     * This flag sets whether a messenger is activated by default  on installation (or reactivation) of EE core or not.
157
-     *
158
-     * @var bool
159
-     */
160
-    public $activate_on_install = false;
155
+	/**
156
+	 * This flag sets whether a messenger is activated by default  on installation (or reactivation) of EE core or not.
157
+	 *
158
+	 * @var bool
159
+	 */
160
+	public $activate_on_install = false;
161 161
 
162 162
 
163 163
 
164 164
 
165 165
 
166
-    public function __construct()
167
-    {
168
-        $this->_EEM_data = EEM_Message_Template_Group::instance();
169
-        $this->_messages_item_type = 'messenger';
166
+	public function __construct()
167
+	{
168
+		$this->_EEM_data = EEM_Message_Template_Group::instance();
169
+		$this->_messages_item_type = 'messenger';
170 170
 
171
-        parent::__construct();
171
+		parent::__construct();
172 172
 
173
-        $this->_set_test_settings_fields();
174
-        $this->_set_template_fields();
175
-        $this->_set_default_message_types();
176
-        $this->_set_valid_message_types();
177
-        $this->_set_validator_config();
173
+		$this->_set_test_settings_fields();
174
+		$this->_set_template_fields();
175
+		$this->_set_default_message_types();
176
+		$this->_set_valid_message_types();
177
+		$this->_set_validator_config();
178 178
 
179 179
 
180
-        $this->_supports_labels = new stdClass();
181
-        $this->_set_supports_labels();
182
-    }
180
+		$this->_supports_labels = new stdClass();
181
+		$this->_set_supports_labels();
182
+	}
183 183
 
184 184
 
185 185
 
186 186
 
187 187
 
188
-    /**
189
-     * _set_template_fields
190
-     * This sets up the fields that a messenger requires for the message to go out.
191
-     *
192
-     * @abstract
193
-     * @access  protected
194
-     * @return void
195
-     */
196
-    abstract protected function _set_template_fields();
188
+	/**
189
+	 * _set_template_fields
190
+	 * This sets up the fields that a messenger requires for the message to go out.
191
+	 *
192
+	 * @abstract
193
+	 * @access  protected
194
+	 * @return void
195
+	 */
196
+	abstract protected function _set_template_fields();
197 197
 
198 198
 
199 199
 
@@ -203,14 +203,14 @@  discard block
 block discarded – undo
203 203
 
204 204
 
205 205
 
206
-    /**
207
-     * This method sets the _default_message_type property (see definition in docs attached to property)
208
-     *
209
-     * @abstract
210
-     * @access protected
211
-     * @return void
212
-     */
213
-    abstract protected function _set_default_message_types();
206
+	/**
207
+	 * This method sets the _default_message_type property (see definition in docs attached to property)
208
+	 *
209
+	 * @abstract
210
+	 * @access protected
211
+	 * @return void
212
+	 */
213
+	abstract protected function _set_default_message_types();
214 214
 
215 215
 
216 216
 
@@ -218,15 +218,15 @@  discard block
 block discarded – undo
218 218
 
219 219
 
220 220
 
221
-    /**
222
-     * Sets the _valid_message_types property (see definition in cods attached to property)
223
-     *
224
-     * @since 4.5.0
225
-     *
226
-     * @abstract
227
-     * @return void
228
-     */
229
-    abstract protected function _set_valid_message_types();
221
+	/**
222
+	 * Sets the _valid_message_types property (see definition in cods attached to property)
223
+	 *
224
+	 * @since 4.5.0
225
+	 *
226
+	 * @abstract
227
+	 * @return void
228
+	 */
229
+	abstract protected function _set_valid_message_types();
230 230
 
231 231
 
232 232
 
@@ -234,171 +234,171 @@  discard block
 block discarded – undo
234 234
 
235 235
 
236 236
 
237
-    /**
238
-     * Child classes must declare the $_validator_config property using this method.
239
-     * See comments for $_validator_config for details on what it is used for.
240
-     *
241
-     * NOTE:  messengers should set an array of valid shortcodes for ALL scenarios.  The corresponding validator class (validators/{messenger}) can be used to restrict only certain shortcodes per template so users cannot add certain shortcodes.
242
-     *
243
-     * @access protected
244
-     * @return void
245
-     */
246
-    abstract protected function _set_validator_config();
237
+	/**
238
+	 * Child classes must declare the $_validator_config property using this method.
239
+	 * See comments for $_validator_config for details on what it is used for.
240
+	 *
241
+	 * NOTE:  messengers should set an array of valid shortcodes for ALL scenarios.  The corresponding validator class (validators/{messenger}) can be used to restrict only certain shortcodes per template so users cannot add certain shortcodes.
242
+	 *
243
+	 * @access protected
244
+	 * @return void
245
+	 */
246
+	abstract protected function _set_validator_config();
247 247
 
248 248
 
249 249
 
250 250
 
251 251
 
252 252
 
253
-    /**
254
-     * We just deliver the messages don't kill us!!  This method will need to be modified by child classes for whatever action is taken to actually send a message.
255
-     *
256
-     * @return bool|WP_Error
257
-     * @throw \Exception
258
-     */
259
-    abstract protected function _send_message();
253
+	/**
254
+	 * We just deliver the messages don't kill us!!  This method will need to be modified by child classes for whatever action is taken to actually send a message.
255
+	 *
256
+	 * @return bool|WP_Error
257
+	 * @throw \Exception
258
+	 */
259
+	abstract protected function _send_message();
260 260
 
261 261
 
262 262
 
263 263
 
264
-    /**
265
-     * We give you pretty previews of the messages!
266
-     * @return string html body for message content.
267
-     */
268
-    abstract protected function _preview();
264
+	/**
265
+	 * We give you pretty previews of the messages!
266
+	 * @return string html body for message content.
267
+	 */
268
+	abstract protected function _preview();
269 269
 
270 270
 
271 271
 
272 272
 
273
-    /**
274
-     * Used by messengers (or preview) for enqueueing any scripts or styles need in message generation.
275
-     *
276
-     * @since 4.5.0
277
-     *
278
-     * @return void
279
-     */
280
-    public function enqueue_scripts_styles()
281
-    {
282
-        do_action('AHEE__EE_messenger__enqueue_scripts_styles');
283
-    }
273
+	/**
274
+	 * Used by messengers (or preview) for enqueueing any scripts or styles need in message generation.
275
+	 *
276
+	 * @since 4.5.0
277
+	 *
278
+	 * @return void
279
+	 */
280
+	public function enqueue_scripts_styles()
281
+	{
282
+		do_action('AHEE__EE_messenger__enqueue_scripts_styles');
283
+	}
284 284
 
285 285
 
286 286
 
287 287
 
288 288
 
289
-    /**
290
-     * This is used to indicate whether a messenger must be sent immediately or not.
291
-     * eg. The HTML messenger will override this to return true because it should be displayed in user's browser right
292
-     * away.  The PDF messenger is similar.
293
-     *
294
-     * This flag thus overrides any priorities that may be set on the message type used to generate the message.
295
-     *
296
-     * Default for this is false.  So children classes must override this if they want a message to be executed immediately.
297
-     *
298
-     * @since  4.9.0
299
-     * @return bool
300
-     */
301
-    public function send_now()
302
-    {
303
-        return false;
304
-    }
289
+	/**
290
+	 * This is used to indicate whether a messenger must be sent immediately or not.
291
+	 * eg. The HTML messenger will override this to return true because it should be displayed in user's browser right
292
+	 * away.  The PDF messenger is similar.
293
+	 *
294
+	 * This flag thus overrides any priorities that may be set on the message type used to generate the message.
295
+	 *
296
+	 * Default for this is false.  So children classes must override this if they want a message to be executed immediately.
297
+	 *
298
+	 * @since  4.9.0
299
+	 * @return bool
300
+	 */
301
+	public function send_now()
302
+	{
303
+		return false;
304
+	}
305 305
 
306 306
 
307 307
 
308 308
 
309 309
 
310
-    /**
311
-     * This is a way for a messenger to indicate whether it allows an empty to field or not.
312
-     * Note: If the generated message is a for a preview, this value is ignored.
313
-     * @since 4.9.0
314
-     * @return bool
315
-     */
316
-    public function allow_empty_to_field()
317
-    {
318
-        return false;
319
-    }
310
+	/**
311
+	 * This is a way for a messenger to indicate whether it allows an empty to field or not.
312
+	 * Note: If the generated message is a for a preview, this value is ignored.
313
+	 * @since 4.9.0
314
+	 * @return bool
315
+	 */
316
+	public function allow_empty_to_field()
317
+	{
318
+		return false;
319
+	}
320 320
 
321 321
 
322 322
 
323 323
 
324 324
 
325
-    /**
326
-     * Sets the defaults for the _supports_labels property.  Can be overridden by child classes.
327
-     * @see property definition for info on how its formatted.
328
-     *
329
-     * @since 4.5.0;
330
-     * @return void
331
-     */
332
-    protected function _set_supports_labels()
333
-    {
334
-        $this->_set_supports_labels_defaults();
335
-    }
325
+	/**
326
+	 * Sets the defaults for the _supports_labels property.  Can be overridden by child classes.
327
+	 * @see property definition for info on how its formatted.
328
+	 *
329
+	 * @since 4.5.0;
330
+	 * @return void
331
+	 */
332
+	protected function _set_supports_labels()
333
+	{
334
+		$this->_set_supports_labels_defaults();
335
+	}
336 336
 
337 337
 
338 338
 
339 339
 
340 340
 
341
-    /**
342
-     * Sets the defaults for the _supports_labels property.
343
-     *
344
-     * @since 4.5.0
345
-     *
346
-     * @return void
347
-     */
348
-    private function _set_supports_labels_defaults()
349
-    {
350
-        $this->_supports_labels->template_pack = __('Template Structure', 'event_espresso');
351
-        $this->_supports_labels->template_variation = __('Template Style', 'event_espresso');
352
-        $this->_supports_labels->template_pack_description = __('Template Structure options are bundled structural changes for templates.', 'event_espresso');
341
+	/**
342
+	 * Sets the defaults for the _supports_labels property.
343
+	 *
344
+	 * @since 4.5.0
345
+	 *
346
+	 * @return void
347
+	 */
348
+	private function _set_supports_labels_defaults()
349
+	{
350
+		$this->_supports_labels->template_pack = __('Template Structure', 'event_espresso');
351
+		$this->_supports_labels->template_variation = __('Template Style', 'event_espresso');
352
+		$this->_supports_labels->template_pack_description = __('Template Structure options are bundled structural changes for templates.', 'event_espresso');
353 353
 
354
-        $this->_supports_labels->template_variation_description = __('These are different styles to choose from for the selected template structure.  Usually these affect things like font style, color, borders etc.  In some cases the styles will also make minor layout changes.', 'event_espresso');
354
+		$this->_supports_labels->template_variation_description = __('These are different styles to choose from for the selected template structure.  Usually these affect things like font style, color, borders etc.  In some cases the styles will also make minor layout changes.', 'event_espresso');
355 355
 
356
-        $this->_supports_labels = apply_filters('FHEE__EE_messenger___set_supports_labels_defaults___supports_labels', $this->_supports_labels, $this);
357
-    }
356
+		$this->_supports_labels = apply_filters('FHEE__EE_messenger___set_supports_labels_defaults___supports_labels', $this->_supports_labels, $this);
357
+	}
358 358
 
359 359
 
360 360
 
361 361
 
362 362
 
363
-    /**
364
-     * This returns the _supports_labels property.
365
-     *
366
-     * @since 4.5.0
367
-     *
368
-     * @return stdClass
369
-     */
370
-    public function get_supports_labels()
371
-    {
372
-        if (empty($this->_supports_labels->template_pack) || empty($this->_supports_labels->template_variation)) {
373
-            $this->_set_supports_labels_defaults();
374
-        }
375
-        return apply_filters('FHEE__EE_messenger__get_supports_labels', $this->_supports_labels, $this);
376
-    }
363
+	/**
364
+	 * This returns the _supports_labels property.
365
+	 *
366
+	 * @since 4.5.0
367
+	 *
368
+	 * @return stdClass
369
+	 */
370
+	public function get_supports_labels()
371
+	{
372
+		if (empty($this->_supports_labels->template_pack) || empty($this->_supports_labels->template_variation)) {
373
+			$this->_set_supports_labels_defaults();
374
+		}
375
+		return apply_filters('FHEE__EE_messenger__get_supports_labels', $this->_supports_labels, $this);
376
+	}
377 377
 
378 378
 
379 379
 
380 380
 
381
-    /**
382
-     * Used to retrieve a variation (typically the path/url to a css file)
383
-     *
384
-     * @since 4.5.0
385
-     *
386
-     * @param EE_Messages_Template_Pack $pack   The template pack used for retrieving the variation.
387
-     * @param string                    $message_type_name The name property of the message type that we need the variation for.
388
-     * @param bool                      $url   Whether to return url (true) or path (false). Default is false.
389
-     * @param string                    $type What variation type to return. Default is 'main'.
390
-     * @param string               $variation What variation for the template pack
391
-     * @param bool             $skip_filters This allows messengers to add a filter for another messengers get_variation but call skip filters on the callback so there is no recursion on apply_filters.
392
-     *
393
-     * @return string                    path or url for the requested variation.
394
-     */
395
-    public function get_variation(EE_Messages_Template_Pack $pack, $message_type_name, $url = false, $type = 'main', $variation = 'default', $skip_filters = false)
396
-    {
397
-        $this->_tmp_pack = $pack;
398
-        $variation_path = apply_filters('EE_messenger__get_variation__variation', false, $pack, $this->name, $message_type_name, $url, $type, $variation, $skip_filters);
399
-        $variation_path = empty($variation_path) ? $this->_tmp_pack->get_variation($this->name, $message_type_name, $type, $variation, $url, '.css', $skip_filters) : $variation_path;
400
-        return $variation_path;
401
-    }
381
+	/**
382
+	 * Used to retrieve a variation (typically the path/url to a css file)
383
+	 *
384
+	 * @since 4.5.0
385
+	 *
386
+	 * @param EE_Messages_Template_Pack $pack   The template pack used for retrieving the variation.
387
+	 * @param string                    $message_type_name The name property of the message type that we need the variation for.
388
+	 * @param bool                      $url   Whether to return url (true) or path (false). Default is false.
389
+	 * @param string                    $type What variation type to return. Default is 'main'.
390
+	 * @param string               $variation What variation for the template pack
391
+	 * @param bool             $skip_filters This allows messengers to add a filter for another messengers get_variation but call skip filters on the callback so there is no recursion on apply_filters.
392
+	 *
393
+	 * @return string                    path or url for the requested variation.
394
+	 */
395
+	public function get_variation(EE_Messages_Template_Pack $pack, $message_type_name, $url = false, $type = 'main', $variation = 'default', $skip_filters = false)
396
+	{
397
+		$this->_tmp_pack = $pack;
398
+		$variation_path = apply_filters('EE_messenger__get_variation__variation', false, $pack, $this->name, $message_type_name, $url, $type, $variation, $skip_filters);
399
+		$variation_path = empty($variation_path) ? $this->_tmp_pack->get_variation($this->name, $message_type_name, $type, $variation, $url, '.css', $skip_filters) : $variation_path;
400
+		return $variation_path;
401
+	}
402 402
 
403 403
 
404 404
 
@@ -406,479 +406,479 @@  discard block
 block discarded – undo
406 406
 
407 407
 
408 408
 
409
-    /**
410
-     * This just returns the default message types associated with this messenger when it is first activated.
411
-     *
412
-     * @access public
413
-     * @return array
414
-     */
415
-    public function get_default_message_types()
416
-    {
417
-        $class = get_class($this);
409
+	/**
410
+	 * This just returns the default message types associated with this messenger when it is first activated.
411
+	 *
412
+	 * @access public
413
+	 * @return array
414
+	 */
415
+	public function get_default_message_types()
416
+	{
417
+		$class = get_class($this);
418 418
 
419
-        // messenger specific filter
420
-        $default_types = apply_filters('FHEE__' . $class . '__get_default_message_types__default_types', $this->_default_message_types, $this);
419
+		// messenger specific filter
420
+		$default_types = apply_filters('FHEE__' . $class . '__get_default_message_types__default_types', $this->_default_message_types, $this);
421 421
 
422
-        // all messengers filter
423
-        $default_types = apply_filters('FHEE__EE_messenger__get_default_message_types__default_types', $default_types, $this);
424
-        return $default_types;
425
-    }
422
+		// all messengers filter
423
+		$default_types = apply_filters('FHEE__EE_messenger__get_default_message_types__default_types', $default_types, $this);
424
+		return $default_types;
425
+	}
426 426
 
427 427
 
428 428
 
429 429
 
430
-    /**
431
-     * Returns the valid message types associated with this messenger.
432
-     *
433
-     * @since 4.5.0
434
-     *
435
-     * @return array
436
-     */
437
-    public function get_valid_message_types()
438
-    {
439
-        $class = get_class($this);
440
-
441
-        // messenger specific filter
442
-        // messenger specific filter
443
-        $valid_types = apply_filters('FHEE__' . $class . '__get_valid_message_types__valid_types', $this->_valid_message_types, $this);
444
-
445
-        // all messengers filter
446
-        $valid_types = apply_filters('FHEE__EE_messenger__get_valid_message_types__valid_types', $valid_types, $this);
447
-        return $valid_types;
448
-    }
449
-
450
-
451
-
452
-
453
-
454
-    /**
455
-     * this is just used by the custom validators (EE_Messages_Validator classes) to modify the _validator_config for certain message_type/messenger combos where a context may only use certain shortcodes etc.
456
-     *
457
-     * @access public
458
-     * @param array $new_config Whatever is put in here will reset the _validator_config property
459
-     */
460
-    public function set_validator_config($new_config)
461
-    {
462
-        $this->_validator_config = $new_config;
463
-    }
464
-
465
-
466
-
467
-
468
-    /**
469
-     * This returns the _validator_config property
470
-     *
471
-     * @access public
472
-     * @return array
473
-     */
474
-    public function get_validator_config()
475
-    {
476
-        $class = get_class($this);
477
-
478
-        $config = apply_filters('FHEE__' . $class . '__get_validator_config', $this->_validator_config, $this);
479
-        $config = apply_filters('FHEE__EE_messenger__get_validator_config', $config, $this);
480
-        return $config;
481
-    }
482
-
483
-
484
-
485
-
486
-    /**
487
-     * this public method accepts a page slug (for an EE_admin page) and will return the response from the child class callback function if that page is registered via the `_admin_registered_page` property set by the child class.
488
-     *
489
-     * @param string $page the slug of the EE admin page
490
-     * @param array $message_types an array of active message type objects
491
-     * @param string $action the page action (to allow for more specific handling - i.e. edit vs. add pages)
492
-     * @param array $extra  This is just an extra argument that can be used to pass additional data for setting up page content.
493
-     * @access public
494
-     * @return string content for page
495
-     */
496
-    public function get_messenger_admin_page_content($page, $action = null, $extra = array(), $message_types = array())
497
-    {
498
-        return $this->_get_admin_page_content($page, $action, $extra, $message_types);
499
-    }
500
-
501
-
502
-
503
-    /**
504
-     * @param $message_types
505
-     * @param array $extra
506
-     * @return mixed|string
507
-     */
508
-    protected function _get_admin_content_events_edit($message_types, $extra)
509
-    {
510
-        // defaults
511
-        $template_args = array();
512
-        $selector_rows = '';
513
-
514
-        // we don't need message types here so we're just going to ignore. we do, however, expect the event id here. The event id is needed to provide a link to setup a custom template for this event.
515
-        $event_id = isset($extra['event']) ? $extra['event'] : null;
516
-
517
-        $template_wrapper_path = EE_LIBRARIES . 'messages/messenger/admin_templates/event_switcher_wrapper.template.php';
518
-        $template_row_path = EE_LIBRARIES . 'messages/messenger/admin_templates/event_switcher_row.template.php';
519
-
520
-        // array of template objects for global and custom (non-trashed) (but remember just for this messenger!)
521
-        $global_templates = EEM_Message_Template_Group::instance()->get_all(
522
-            array( array( 'MTP_messenger' => $this->name, 'MTP_is_global' => true, 'MTP_is_active' => true ) )
523
-        );
524
-        $templates_for_event = EEM_Message_Template_Group::instance()->get_all_custom_templates_by_event(
525
-            $event_id,
526
-            array(
527
-                'MTP_messenger' => $this->name,
528
-                'MTP_is_active' => true
529
-            )
530
-        );
531
-        $templates_for_event = !empty($templates_for_event) ? $templates_for_event : array();
532
-
533
-        // so we need to setup the rows for the selectors and we use the global mtpgs (cause those will the active message template groups)
534
-        foreach ($global_templates as $mtpgID => $mtpg) {
535
-            if ($mtpg instanceof EE_Message_Template_Group) {
536
-                // verify this message type is supposed to show on this page
537
-                $mtp_obj = $mtpg->message_type_obj();
538
-                if (! $mtp_obj instanceof EE_message_type) {
539
-                    continue;
540
-                }
541
-                $mtp_obj->admin_registered_pages = (array) $mtp_obj->admin_registered_pages;
542
-                if (! in_array('events_edit', $mtp_obj->admin_registered_pages)) {
543
-                    continue;
544
-                }
545
-                $select_values = array();
546
-                $select_values[ $mtpgID ] = __('Global', 'event_espresso');
547
-                $default_value = array_key_exists($mtpgID, $templates_for_event) && ! $mtpg->get('MTP_is_override') ? $mtpgID : null;
548
-                // if the override has been set for the global template, then that means even if there are custom templates already created we ignore them because of the set override.
549
-                if (! $mtpg->get('MTP_is_override')) {
550
-                    // any custom templates for this message type?
551
-                    $custom_templates = EEM_Message_Template_Group::instance()->get_custom_message_template_by_m_and_mt($this->name, $mtpg->message_type());
552
-                    foreach ($custom_templates as $cmtpgID => $cmtpg) {
553
-                        $select_values[ $cmtpgID ] = $cmtpg->name();
554
-                        $default_value = array_key_exists($cmtpgID, $templates_for_event) ? $cmtpgID : $default_value;
555
-                    }
556
-                }
557
-                // if there is no $default_value then we set it as the global
558
-                $default_value = empty($default_value) ? $mtpgID : $default_value;
559
-                $edit_url = EEH_URL::add_query_args_and_nonce(array( 'page' => 'espresso_messages', 'action' => 'edit_message_template', 'id' => $default_value ), admin_url('admin.php'));
560
-                $create_url = EEH_URL::add_query_args_and_nonce(array( 'page' => 'espresso_messages', 'action' => 'add_new_message_template', 'GRP_ID' => $default_value ), admin_url('admin.php'));
561
-                $st_args['mt_name'] = ucwords($mtp_obj->label['singular']);
562
-                $st_args['mt_slug'] = $mtpg->message_type();
563
-                $st_args['messenger_slug'] = $this->name;
564
-                $st_args['selector'] = EEH_Form_Fields::select_input('event_message_templates_relation[' . $mtpgID . ']', $select_values, $default_value, 'data-messenger="' . $this->name . '" data-messagetype="' . $mtpg->message_type() . '"', 'message-template-selector');
565
-                // note that  message template group that has override_all_custom set will remove the ability to set a custom message template based off of the global (and that also in turn overrides any other custom templates).
566
-                $st_args['create_button'] = $mtpg->get('MTP_is_override') ? '' : '<a data-messenger="' . $this->name . '" data-messagetype="' . $mtpg->message_type() . '" data-grpid="' . $default_value . '" target="_blank" href="' . $create_url . '" class="button button-small create-mtpg-button">' . __('Create New Custom', 'event_espresso') . '</a>';
567
-                $st_args['create_button'] = EE_Registry::instance()->CAP->current_user_can('ee_edit_messages', 'espresso_messages_add_new_message_template') ? $st_args['create_button'] : '';
568
-                $st_args['edit_button'] = EE_Registry::instance()->CAP->current_user_can('ee_edit_message', 'espresso_messages_edit_message_template', $mtpgID) ? '<a data-messagetype="' . $mtpg->message_type() . '" data-grpid="' . $default_value . '" target="_blank" href="' . $edit_url . '" class="button button-small edit-mtpg-button">' . __('Edit', 'event_espresso') . '</a>' : '';
569
-                $selector_rows .= EEH_Template::display_template($template_row_path, $st_args, true);
570
-            }
571
-        }
572
-
573
-        // if no selectors present then get out.
574
-        if (empty($selector_rows)) {
575
-            return '';
576
-        }
577
-
578
-        $template_args['selector_rows'] = $selector_rows;
579
-        return EEH_Template::display_template($template_wrapper_path, $template_args, true);
580
-    }
581
-
582
-
583
-
584
-
585
-
586
-
587
-    /**
588
-     * get_template_fields
589
-     *
590
-     * @access public
591
-     * @return array $this->_template_fields
592
-     */
593
-    public function get_template_fields()
594
-    {
595
-        $template_fields = apply_filters('FHEE__' . get_class($this) . '__get_template_fields', $this->_template_fields, $this);
596
-        $template_fields = apply_filters('FHEE__EE_messenger__get_template_fields', $template_fields, $this);
597
-        return $template_fields;
598
-    }
599
-
600
-
601
-
602
-
603
-    /** SETUP METHODS **/
604
-    /**
605
-     * The following method doesn't NEED to be used by child classes but might be modified by the specific messenger
606
-     * @param string $item
607
-     * @param mixed $value
608
-     */
609
-    protected function _set_template_value($item, $value)
610
-    {
611
-        if (array_key_exists($item, $this->_template_fields)) {
612
-            $prop = '_' . $item;
613
-            $this->{$prop}= $value;
614
-        }
615
-    }
616
-
617
-    /**
618
-     * Sets up the message for sending.
619
-     *
620
-     * @param  EE_message $message the message object that contains details about the message.
621
-     * @param EE_message_type $message_type The message type object used in combination with this messenger to generate the provided message.
622
-     *
623
-     * @return bool Very important that all messengers return bool for successful send or not.  Error messages can be
624
-     *              added to EE_Error.
625
-     *              true = message sent successfully
626
-     *              false = message not sent but can be retried (i.e. the failure might be just due to communication issues at the time of send).
627
-     *              Throwing a SendMessageException means the message failed sending and cannot be retried.
628
-     *
629
-     * @throws SendMessageException
630
-     */
631
-    final public function send_message($message, EE_message_type $message_type)
632
-    {
633
-        try {
634
-            $this->_validate_and_setup($message);
635
-            $this->_incoming_message_type = $message_type;
636
-            $response = $this->_send_message();
637
-            if ($response instanceof WP_Error) {
638
-                EE_Error::add_error($response->get_error_message(), __FILE__, __FUNCTION__, __LINE__);
639
-                $response = false;
640
-            }
641
-        } catch (\Exception $e) {
642
-            // convert to an instance of SendMessageException
643
-            throw new SendMessageException($e->getMessage());
644
-        }
645
-        return $response;
646
-    }
647
-
648
-
649
-
650
-    /**
651
-     * Sets up and returns message preview
652
-     * @param  EE_Message $message incoming message object
653
-     * @param EE_message_type $message_type This is whatever message type was used in combination with this messenger to generate the message.
654
-     * @param  bool   $send    true we will actually use the _send method (for test sends). FALSE we just return preview
655
-     * @return string          return the message html content
656
-     */
657
-    public function get_preview(EE_Message $message, EE_message_type $message_type, $send = false)
658
-    {
659
-        $this->_validate_and_setup($message);
660
-
661
-        $this->_incoming_message_type = $message_type;
662
-
663
-        if ($send) {
664
-            // are we overriding any existing template fields?
665
-            $settings = apply_filters(
666
-                'FHEE__EE_messenger__get_preview__messenger_test_settings',
667
-                $this->get_existing_test_settings(),
668
-                $this,
669
-                $send,
670
-                $message,
671
-                $message_type
672
-            );
673
-            if (! empty($settings)) {
674
-                foreach ($settings as $field => $value) {
675
-                    $this->_set_template_value($field, $value);
676
-                }
677
-            }
678
-        }
679
-
680
-        // enqueue preview js so that any links/buttons on the page are disabled.
681
-        if (! $send) {
682
-            // the below may seem like duplication.  However, typically if a messenger enqueues scripts/styles,
683
-            // it deregisters all existing wp scripts and styles first.  So the second hook ensures our previewer still gets setup.
684
-            add_action('admin_enqueue_scripts', array( $this, 'add_preview_script' ), 10);
685
-            add_action('wp_enqueue_scripts', array( $this, 'add_preview_script' ), 10);
686
-            add_action('AHEE__EE_messenger__enqueue_scripts_styles', array( $this, 'add_preview_script' ), 10);
687
-        }
688
-
689
-        return $send ? $this->_send_message() : $this->_preview();
690
-    }
691
-
692
-
693
-
694
-
695
-    /**
696
-     * Callback for enqueue_scripts so that we setup the preview script for all previews.
697
-     *
698
-     * @since 4.5.0
699
-     *
700
-     * @return void
701
-     */
702
-    public function add_preview_script()
703
-    {
704
-        // error message
705
-        EE_Registry::$i18n_js_strings['links_disabled'] = __('All the links on this page have been disabled because this is a generated preview message for the purpose of ensuring layout, style, and content setup.  To test generated links, you must trigger an actual message notification.', 'event_espresso');
706
-        wp_register_script('ee-messages-preview-js', EE_LIBRARIES_URL . 'messages/messenger/assets/js/ee-messages-preview.js', array( 'jquery' ), EVENT_ESPRESSO_VERSION, true);
707
-        wp_localize_script('ee-messages-preview-js', 'eei18n', EE_Registry::$i18n_js_strings);
708
-        wp_enqueue_script('ee-messages-preview-js');
709
-    }
710
-
711
-
712
-
713
-
714
-    /**
715
-     * simply validates the incoming message object and then sets up the properties for the messenger
716
-     * @param  EE_Message $message
717
-     * @throws EE_Error
718
-     */
719
-    protected function _validate_and_setup(EE_Message $message)
720
-    {
721
-        $template_pack = $message->get_template_pack();
722
-        $variation = $message->get_template_pack_variation();
723
-
724
-        // verify we have the required template pack value on the $message object.
725
-        if (! $template_pack instanceof EE_Messages_Template_Pack) {
726
-            throw new EE_Error(__('Incoming $message object must have an EE_Messages_Template_Pack object available.', 'event_espresso'));
727
-        }
728
-
729
-        $this->_tmp_pack = $template_pack;
730
-
731
-        $this->_variation = $variation ? $variation : 'default';
732
-
733
-        $template_fields = $this->get_template_fields();
734
-
735
-        foreach ($template_fields as $template => $value) {
736
-            if ($template !== 'extra') {
737
-                $column_value = $message->get_field_or_extra_meta('MSG_' . $template);
738
-                $message_template_value = $column_value ? $column_value : null;
739
-                $this->_set_template_value($template, $message_template_value);
740
-            }
741
-        }
742
-    }
743
-
744
-
745
-
746
-    /**
747
-     * Utility method for child classes to get the contents of a template file and return
748
-     *
749
-     * We're assuming the child messenger class has already setup template args!
750
-     * @param  bool $preview if true we use the preview wrapper otherwise we use main wrapper.
751
-     * @return string
752
-     * @throws \EE_Error
753
-     */
754
-    protected function _get_main_template($preview = false)
755
-    {
756
-        $type = $preview ? 'preview' : 'main';
757
-
758
-        $wrapper_template = $this->_tmp_pack->get_wrapper($this->name, $type);
759
-
760
-        // check file exists and is readable
761
-        if (!is_readable($wrapper_template)) {
762
-            throw new EE_Error(sprintf(__('Unable to access the template file for the %s messenger main content wrapper.  The location being attempted is %s.', 'event_espresso'), ucwords($this->label['singular']), $wrapper_template));
763
-        }
764
-
765
-        // add message type to template args
766
-        $this->_template_args['message_type'] = $this->_incoming_message_type;
767
-
768
-        return EEH_Template::display_template($wrapper_template, $this->_template_args, true);
769
-    }
770
-
771
-
772
-
773
-    /**
774
-     * set the _test_settings_fields property
775
-     *
776
-     * @access protected
777
-     * @return void
778
-     */
779
-    protected function _set_test_settings_fields()
780
-    {
781
-        $this->_test_settings_fields = array();
782
-    }
783
-
784
-
785
-
786
-    /**
787
-     * return the _test_settings_fields property
788
-     * @return array
789
-     */
790
-    public function get_test_settings_fields()
791
-    {
792
-        return $this->_test_settings_fields;
793
-    }
794
-
795
-
796
-
797
-
798
-    /**
799
-     * This just returns any existing test settings that might be saved in the database
800
-     *
801
-     * @access public
802
-     * @return array
803
-     */
804
-    public function get_existing_test_settings()
805
-    {
806
-        /** @var EE_Message_Resource_Manager $Message_Resource_Manager */
807
-        $Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
808
-        $settings = $Message_Resource_Manager->get_active_messengers_option();
809
-        return isset($settings[ $this->name ]['test_settings']) ? $settings[ $this->name ]['test_settings'] : array();
810
-    }
811
-
812
-
813
-
814
-    /**
815
-     * All this does is set the existing test settings (in the db) for the messenger
816
-     *
817
-     * @access public
818
-     * @param $settings
819
-     * @return bool success/fail
820
-     */
821
-    public function set_existing_test_settings($settings)
822
-    {
823
-        /** @var EE_Message_Resource_Manager $Message_Resource_Manager */
824
-        $Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
825
-        $existing = $Message_Resource_Manager->get_active_messengers_option();
826
-        $existing[ $this->name ]['test_settings'] = $settings;
827
-        return $Message_Resource_Manager->update_active_messengers_option($existing);
828
-    }
829
-
830
-
831
-
832
-    /**
833
-     * This just returns the field label for a given field setup in the _template_fields property.
834
-     *
835
-     * @since   4.3.0
836
-     *
837
-     * @param string $field The field to retrieve the label for
838
-     * @return string             The label
839
-     */
840
-    public function get_field_label($field)
841
-    {
842
-        // first let's see if the field requests is in the top level array.
843
-        if (isset($this->_template_fields[ $field ]) && !empty($this->_template_fields[ $field ]['label'])) {
844
-            return $this->_template[ $field ]['label'];
845
-        }
846
-
847
-        // nope so let's look in the extra array to see if it's there HOWEVER if the field exists as a top level index in the extra array then we know the label is in the 'main' index.
848
-        if (isset($this->_template_fields['extra']) && !empty($this->_template_fields['extra'][ $field ]) && !empty($this->_template_fields['extra'][ $field ]['main']['label'])) {
849
-            return $this->_template_fields['extra'][ $field ]['main']['label'];
850
-        }
851
-
852
-        // now it's possible this field may just be existing in any of the extra array items.
853
-        if (!empty($this->_template_fields['extra']) && is_array($this->_template_fields['extra'])) {
854
-            foreach ($this->_template_fields['extra'] as $main_field => $subfields) {
855
-                if (!is_array($subfields)) {
856
-                    continue;
857
-                }
858
-                if (isset($subfields[ $field ]) && !empty($subfields[ $field ]['label'])) {
859
-                    return $subfields[ $field ]['label'];
860
-                }
861
-            }
862
-        }
863
-
864
-        // if we made it here then there's no label set so let's just return the $field.
865
-        return $field;
866
-    }
867
-
868
-
869
-
870
-
871
-    /**
872
-     * This is a method called from EE_messages when this messenger is a generating messenger and the sending messenger is a different messenger.  Child messengers can set hooks for the sending messenger to callback on if necessary (i.e. swap out css files or something else).
873
-     *
874
-     * @since 4.5.0
875
-     *
876
-     * @param string $sending_messenger_name the name of the sending messenger so we only set the hooks needed.
877
-     *
878
-     * @return void
879
-     */
880
-    public function do_secondary_messenger_hooks($sending_messenger_name)
881
-    {
882
-        return;
883
-    }
430
+	/**
431
+	 * Returns the valid message types associated with this messenger.
432
+	 *
433
+	 * @since 4.5.0
434
+	 *
435
+	 * @return array
436
+	 */
437
+	public function get_valid_message_types()
438
+	{
439
+		$class = get_class($this);
440
+
441
+		// messenger specific filter
442
+		// messenger specific filter
443
+		$valid_types = apply_filters('FHEE__' . $class . '__get_valid_message_types__valid_types', $this->_valid_message_types, $this);
444
+
445
+		// all messengers filter
446
+		$valid_types = apply_filters('FHEE__EE_messenger__get_valid_message_types__valid_types', $valid_types, $this);
447
+		return $valid_types;
448
+	}
449
+
450
+
451
+
452
+
453
+
454
+	/**
455
+	 * this is just used by the custom validators (EE_Messages_Validator classes) to modify the _validator_config for certain message_type/messenger combos where a context may only use certain shortcodes etc.
456
+	 *
457
+	 * @access public
458
+	 * @param array $new_config Whatever is put in here will reset the _validator_config property
459
+	 */
460
+	public function set_validator_config($new_config)
461
+	{
462
+		$this->_validator_config = $new_config;
463
+	}
464
+
465
+
466
+
467
+
468
+	/**
469
+	 * This returns the _validator_config property
470
+	 *
471
+	 * @access public
472
+	 * @return array
473
+	 */
474
+	public function get_validator_config()
475
+	{
476
+		$class = get_class($this);
477
+
478
+		$config = apply_filters('FHEE__' . $class . '__get_validator_config', $this->_validator_config, $this);
479
+		$config = apply_filters('FHEE__EE_messenger__get_validator_config', $config, $this);
480
+		return $config;
481
+	}
482
+
483
+
484
+
485
+
486
+	/**
487
+	 * this public method accepts a page slug (for an EE_admin page) and will return the response from the child class callback function if that page is registered via the `_admin_registered_page` property set by the child class.
488
+	 *
489
+	 * @param string $page the slug of the EE admin page
490
+	 * @param array $message_types an array of active message type objects
491
+	 * @param string $action the page action (to allow for more specific handling - i.e. edit vs. add pages)
492
+	 * @param array $extra  This is just an extra argument that can be used to pass additional data for setting up page content.
493
+	 * @access public
494
+	 * @return string content for page
495
+	 */
496
+	public function get_messenger_admin_page_content($page, $action = null, $extra = array(), $message_types = array())
497
+	{
498
+		return $this->_get_admin_page_content($page, $action, $extra, $message_types);
499
+	}
500
+
501
+
502
+
503
+	/**
504
+	 * @param $message_types
505
+	 * @param array $extra
506
+	 * @return mixed|string
507
+	 */
508
+	protected function _get_admin_content_events_edit($message_types, $extra)
509
+	{
510
+		// defaults
511
+		$template_args = array();
512
+		$selector_rows = '';
513
+
514
+		// we don't need message types here so we're just going to ignore. we do, however, expect the event id here. The event id is needed to provide a link to setup a custom template for this event.
515
+		$event_id = isset($extra['event']) ? $extra['event'] : null;
516
+
517
+		$template_wrapper_path = EE_LIBRARIES . 'messages/messenger/admin_templates/event_switcher_wrapper.template.php';
518
+		$template_row_path = EE_LIBRARIES . 'messages/messenger/admin_templates/event_switcher_row.template.php';
519
+
520
+		// array of template objects for global and custom (non-trashed) (but remember just for this messenger!)
521
+		$global_templates = EEM_Message_Template_Group::instance()->get_all(
522
+			array( array( 'MTP_messenger' => $this->name, 'MTP_is_global' => true, 'MTP_is_active' => true ) )
523
+		);
524
+		$templates_for_event = EEM_Message_Template_Group::instance()->get_all_custom_templates_by_event(
525
+			$event_id,
526
+			array(
527
+				'MTP_messenger' => $this->name,
528
+				'MTP_is_active' => true
529
+			)
530
+		);
531
+		$templates_for_event = !empty($templates_for_event) ? $templates_for_event : array();
532
+
533
+		// so we need to setup the rows for the selectors and we use the global mtpgs (cause those will the active message template groups)
534
+		foreach ($global_templates as $mtpgID => $mtpg) {
535
+			if ($mtpg instanceof EE_Message_Template_Group) {
536
+				// verify this message type is supposed to show on this page
537
+				$mtp_obj = $mtpg->message_type_obj();
538
+				if (! $mtp_obj instanceof EE_message_type) {
539
+					continue;
540
+				}
541
+				$mtp_obj->admin_registered_pages = (array) $mtp_obj->admin_registered_pages;
542
+				if (! in_array('events_edit', $mtp_obj->admin_registered_pages)) {
543
+					continue;
544
+				}
545
+				$select_values = array();
546
+				$select_values[ $mtpgID ] = __('Global', 'event_espresso');
547
+				$default_value = array_key_exists($mtpgID, $templates_for_event) && ! $mtpg->get('MTP_is_override') ? $mtpgID : null;
548
+				// if the override has been set for the global template, then that means even if there are custom templates already created we ignore them because of the set override.
549
+				if (! $mtpg->get('MTP_is_override')) {
550
+					// any custom templates for this message type?
551
+					$custom_templates = EEM_Message_Template_Group::instance()->get_custom_message_template_by_m_and_mt($this->name, $mtpg->message_type());
552
+					foreach ($custom_templates as $cmtpgID => $cmtpg) {
553
+						$select_values[ $cmtpgID ] = $cmtpg->name();
554
+						$default_value = array_key_exists($cmtpgID, $templates_for_event) ? $cmtpgID : $default_value;
555
+					}
556
+				}
557
+				// if there is no $default_value then we set it as the global
558
+				$default_value = empty($default_value) ? $mtpgID : $default_value;
559
+				$edit_url = EEH_URL::add_query_args_and_nonce(array( 'page' => 'espresso_messages', 'action' => 'edit_message_template', 'id' => $default_value ), admin_url('admin.php'));
560
+				$create_url = EEH_URL::add_query_args_and_nonce(array( 'page' => 'espresso_messages', 'action' => 'add_new_message_template', 'GRP_ID' => $default_value ), admin_url('admin.php'));
561
+				$st_args['mt_name'] = ucwords($mtp_obj->label['singular']);
562
+				$st_args['mt_slug'] = $mtpg->message_type();
563
+				$st_args['messenger_slug'] = $this->name;
564
+				$st_args['selector'] = EEH_Form_Fields::select_input('event_message_templates_relation[' . $mtpgID . ']', $select_values, $default_value, 'data-messenger="' . $this->name . '" data-messagetype="' . $mtpg->message_type() . '"', 'message-template-selector');
565
+				// note that  message template group that has override_all_custom set will remove the ability to set a custom message template based off of the global (and that also in turn overrides any other custom templates).
566
+				$st_args['create_button'] = $mtpg->get('MTP_is_override') ? '' : '<a data-messenger="' . $this->name . '" data-messagetype="' . $mtpg->message_type() . '" data-grpid="' . $default_value . '" target="_blank" href="' . $create_url . '" class="button button-small create-mtpg-button">' . __('Create New Custom', 'event_espresso') . '</a>';
567
+				$st_args['create_button'] = EE_Registry::instance()->CAP->current_user_can('ee_edit_messages', 'espresso_messages_add_new_message_template') ? $st_args['create_button'] : '';
568
+				$st_args['edit_button'] = EE_Registry::instance()->CAP->current_user_can('ee_edit_message', 'espresso_messages_edit_message_template', $mtpgID) ? '<a data-messagetype="' . $mtpg->message_type() . '" data-grpid="' . $default_value . '" target="_blank" href="' . $edit_url . '" class="button button-small edit-mtpg-button">' . __('Edit', 'event_espresso') . '</a>' : '';
569
+				$selector_rows .= EEH_Template::display_template($template_row_path, $st_args, true);
570
+			}
571
+		}
572
+
573
+		// if no selectors present then get out.
574
+		if (empty($selector_rows)) {
575
+			return '';
576
+		}
577
+
578
+		$template_args['selector_rows'] = $selector_rows;
579
+		return EEH_Template::display_template($template_wrapper_path, $template_args, true);
580
+	}
581
+
582
+
583
+
584
+
585
+
586
+
587
+	/**
588
+	 * get_template_fields
589
+	 *
590
+	 * @access public
591
+	 * @return array $this->_template_fields
592
+	 */
593
+	public function get_template_fields()
594
+	{
595
+		$template_fields = apply_filters('FHEE__' . get_class($this) . '__get_template_fields', $this->_template_fields, $this);
596
+		$template_fields = apply_filters('FHEE__EE_messenger__get_template_fields', $template_fields, $this);
597
+		return $template_fields;
598
+	}
599
+
600
+
601
+
602
+
603
+	/** SETUP METHODS **/
604
+	/**
605
+	 * The following method doesn't NEED to be used by child classes but might be modified by the specific messenger
606
+	 * @param string $item
607
+	 * @param mixed $value
608
+	 */
609
+	protected function _set_template_value($item, $value)
610
+	{
611
+		if (array_key_exists($item, $this->_template_fields)) {
612
+			$prop = '_' . $item;
613
+			$this->{$prop}= $value;
614
+		}
615
+	}
616
+
617
+	/**
618
+	 * Sets up the message for sending.
619
+	 *
620
+	 * @param  EE_message $message the message object that contains details about the message.
621
+	 * @param EE_message_type $message_type The message type object used in combination with this messenger to generate the provided message.
622
+	 *
623
+	 * @return bool Very important that all messengers return bool for successful send or not.  Error messages can be
624
+	 *              added to EE_Error.
625
+	 *              true = message sent successfully
626
+	 *              false = message not sent but can be retried (i.e. the failure might be just due to communication issues at the time of send).
627
+	 *              Throwing a SendMessageException means the message failed sending and cannot be retried.
628
+	 *
629
+	 * @throws SendMessageException
630
+	 */
631
+	final public function send_message($message, EE_message_type $message_type)
632
+	{
633
+		try {
634
+			$this->_validate_and_setup($message);
635
+			$this->_incoming_message_type = $message_type;
636
+			$response = $this->_send_message();
637
+			if ($response instanceof WP_Error) {
638
+				EE_Error::add_error($response->get_error_message(), __FILE__, __FUNCTION__, __LINE__);
639
+				$response = false;
640
+			}
641
+		} catch (\Exception $e) {
642
+			// convert to an instance of SendMessageException
643
+			throw new SendMessageException($e->getMessage());
644
+		}
645
+		return $response;
646
+	}
647
+
648
+
649
+
650
+	/**
651
+	 * Sets up and returns message preview
652
+	 * @param  EE_Message $message incoming message object
653
+	 * @param EE_message_type $message_type This is whatever message type was used in combination with this messenger to generate the message.
654
+	 * @param  bool   $send    true we will actually use the _send method (for test sends). FALSE we just return preview
655
+	 * @return string          return the message html content
656
+	 */
657
+	public function get_preview(EE_Message $message, EE_message_type $message_type, $send = false)
658
+	{
659
+		$this->_validate_and_setup($message);
660
+
661
+		$this->_incoming_message_type = $message_type;
662
+
663
+		if ($send) {
664
+			// are we overriding any existing template fields?
665
+			$settings = apply_filters(
666
+				'FHEE__EE_messenger__get_preview__messenger_test_settings',
667
+				$this->get_existing_test_settings(),
668
+				$this,
669
+				$send,
670
+				$message,
671
+				$message_type
672
+			);
673
+			if (! empty($settings)) {
674
+				foreach ($settings as $field => $value) {
675
+					$this->_set_template_value($field, $value);
676
+				}
677
+			}
678
+		}
679
+
680
+		// enqueue preview js so that any links/buttons on the page are disabled.
681
+		if (! $send) {
682
+			// the below may seem like duplication.  However, typically if a messenger enqueues scripts/styles,
683
+			// it deregisters all existing wp scripts and styles first.  So the second hook ensures our previewer still gets setup.
684
+			add_action('admin_enqueue_scripts', array( $this, 'add_preview_script' ), 10);
685
+			add_action('wp_enqueue_scripts', array( $this, 'add_preview_script' ), 10);
686
+			add_action('AHEE__EE_messenger__enqueue_scripts_styles', array( $this, 'add_preview_script' ), 10);
687
+		}
688
+
689
+		return $send ? $this->_send_message() : $this->_preview();
690
+	}
691
+
692
+
693
+
694
+
695
+	/**
696
+	 * Callback for enqueue_scripts so that we setup the preview script for all previews.
697
+	 *
698
+	 * @since 4.5.0
699
+	 *
700
+	 * @return void
701
+	 */
702
+	public function add_preview_script()
703
+	{
704
+		// error message
705
+		EE_Registry::$i18n_js_strings['links_disabled'] = __('All the links on this page have been disabled because this is a generated preview message for the purpose of ensuring layout, style, and content setup.  To test generated links, you must trigger an actual message notification.', 'event_espresso');
706
+		wp_register_script('ee-messages-preview-js', EE_LIBRARIES_URL . 'messages/messenger/assets/js/ee-messages-preview.js', array( 'jquery' ), EVENT_ESPRESSO_VERSION, true);
707
+		wp_localize_script('ee-messages-preview-js', 'eei18n', EE_Registry::$i18n_js_strings);
708
+		wp_enqueue_script('ee-messages-preview-js');
709
+	}
710
+
711
+
712
+
713
+
714
+	/**
715
+	 * simply validates the incoming message object and then sets up the properties for the messenger
716
+	 * @param  EE_Message $message
717
+	 * @throws EE_Error
718
+	 */
719
+	protected function _validate_and_setup(EE_Message $message)
720
+	{
721
+		$template_pack = $message->get_template_pack();
722
+		$variation = $message->get_template_pack_variation();
723
+
724
+		// verify we have the required template pack value on the $message object.
725
+		if (! $template_pack instanceof EE_Messages_Template_Pack) {
726
+			throw new EE_Error(__('Incoming $message object must have an EE_Messages_Template_Pack object available.', 'event_espresso'));
727
+		}
728
+
729
+		$this->_tmp_pack = $template_pack;
730
+
731
+		$this->_variation = $variation ? $variation : 'default';
732
+
733
+		$template_fields = $this->get_template_fields();
734
+
735
+		foreach ($template_fields as $template => $value) {
736
+			if ($template !== 'extra') {
737
+				$column_value = $message->get_field_or_extra_meta('MSG_' . $template);
738
+				$message_template_value = $column_value ? $column_value : null;
739
+				$this->_set_template_value($template, $message_template_value);
740
+			}
741
+		}
742
+	}
743
+
744
+
745
+
746
+	/**
747
+	 * Utility method for child classes to get the contents of a template file and return
748
+	 *
749
+	 * We're assuming the child messenger class has already setup template args!
750
+	 * @param  bool $preview if true we use the preview wrapper otherwise we use main wrapper.
751
+	 * @return string
752
+	 * @throws \EE_Error
753
+	 */
754
+	protected function _get_main_template($preview = false)
755
+	{
756
+		$type = $preview ? 'preview' : 'main';
757
+
758
+		$wrapper_template = $this->_tmp_pack->get_wrapper($this->name, $type);
759
+
760
+		// check file exists and is readable
761
+		if (!is_readable($wrapper_template)) {
762
+			throw new EE_Error(sprintf(__('Unable to access the template file for the %s messenger main content wrapper.  The location being attempted is %s.', 'event_espresso'), ucwords($this->label['singular']), $wrapper_template));
763
+		}
764
+
765
+		// add message type to template args
766
+		$this->_template_args['message_type'] = $this->_incoming_message_type;
767
+
768
+		return EEH_Template::display_template($wrapper_template, $this->_template_args, true);
769
+	}
770
+
771
+
772
+
773
+	/**
774
+	 * set the _test_settings_fields property
775
+	 *
776
+	 * @access protected
777
+	 * @return void
778
+	 */
779
+	protected function _set_test_settings_fields()
780
+	{
781
+		$this->_test_settings_fields = array();
782
+	}
783
+
784
+
785
+
786
+	/**
787
+	 * return the _test_settings_fields property
788
+	 * @return array
789
+	 */
790
+	public function get_test_settings_fields()
791
+	{
792
+		return $this->_test_settings_fields;
793
+	}
794
+
795
+
796
+
797
+
798
+	/**
799
+	 * This just returns any existing test settings that might be saved in the database
800
+	 *
801
+	 * @access public
802
+	 * @return array
803
+	 */
804
+	public function get_existing_test_settings()
805
+	{
806
+		/** @var EE_Message_Resource_Manager $Message_Resource_Manager */
807
+		$Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
808
+		$settings = $Message_Resource_Manager->get_active_messengers_option();
809
+		return isset($settings[ $this->name ]['test_settings']) ? $settings[ $this->name ]['test_settings'] : array();
810
+	}
811
+
812
+
813
+
814
+	/**
815
+	 * All this does is set the existing test settings (in the db) for the messenger
816
+	 *
817
+	 * @access public
818
+	 * @param $settings
819
+	 * @return bool success/fail
820
+	 */
821
+	public function set_existing_test_settings($settings)
822
+	{
823
+		/** @var EE_Message_Resource_Manager $Message_Resource_Manager */
824
+		$Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
825
+		$existing = $Message_Resource_Manager->get_active_messengers_option();
826
+		$existing[ $this->name ]['test_settings'] = $settings;
827
+		return $Message_Resource_Manager->update_active_messengers_option($existing);
828
+	}
829
+
830
+
831
+
832
+	/**
833
+	 * This just returns the field label for a given field setup in the _template_fields property.
834
+	 *
835
+	 * @since   4.3.0
836
+	 *
837
+	 * @param string $field The field to retrieve the label for
838
+	 * @return string             The label
839
+	 */
840
+	public function get_field_label($field)
841
+	{
842
+		// first let's see if the field requests is in the top level array.
843
+		if (isset($this->_template_fields[ $field ]) && !empty($this->_template_fields[ $field ]['label'])) {
844
+			return $this->_template[ $field ]['label'];
845
+		}
846
+
847
+		// nope so let's look in the extra array to see if it's there HOWEVER if the field exists as a top level index in the extra array then we know the label is in the 'main' index.
848
+		if (isset($this->_template_fields['extra']) && !empty($this->_template_fields['extra'][ $field ]) && !empty($this->_template_fields['extra'][ $field ]['main']['label'])) {
849
+			return $this->_template_fields['extra'][ $field ]['main']['label'];
850
+		}
851
+
852
+		// now it's possible this field may just be existing in any of the extra array items.
853
+		if (!empty($this->_template_fields['extra']) && is_array($this->_template_fields['extra'])) {
854
+			foreach ($this->_template_fields['extra'] as $main_field => $subfields) {
855
+				if (!is_array($subfields)) {
856
+					continue;
857
+				}
858
+				if (isset($subfields[ $field ]) && !empty($subfields[ $field ]['label'])) {
859
+					return $subfields[ $field ]['label'];
860
+				}
861
+			}
862
+		}
863
+
864
+		// if we made it here then there's no label set so let's just return the $field.
865
+		return $field;
866
+	}
867
+
868
+
869
+
870
+
871
+	/**
872
+	 * This is a method called from EE_messages when this messenger is a generating messenger and the sending messenger is a different messenger.  Child messengers can set hooks for the sending messenger to callback on if necessary (i.e. swap out css files or something else).
873
+	 *
874
+	 * @since 4.5.0
875
+	 *
876
+	 * @param string $sending_messenger_name the name of the sending messenger so we only set the hooks needed.
877
+	 *
878
+	 * @return void
879
+	 */
880
+	public function do_secondary_messenger_hooks($sending_messenger_name)
881
+	{
882
+		return;
883
+	}
884 884
 }
Please login to merge, or discard this patch.
Spacing   +39 added lines, -39 removed lines patch added patch discarded remove patch
@@ -417,7 +417,7 @@  discard block
 block discarded – undo
417 417
         $class = get_class($this);
418 418
 
419 419
         // messenger specific filter
420
-        $default_types = apply_filters('FHEE__' . $class . '__get_default_message_types__default_types', $this->_default_message_types, $this);
420
+        $default_types = apply_filters('FHEE__'.$class.'__get_default_message_types__default_types', $this->_default_message_types, $this);
421 421
 
422 422
         // all messengers filter
423 423
         $default_types = apply_filters('FHEE__EE_messenger__get_default_message_types__default_types', $default_types, $this);
@@ -440,7 +440,7 @@  discard block
 block discarded – undo
440 440
 
441 441
         // messenger specific filter
442 442
         // messenger specific filter
443
-        $valid_types = apply_filters('FHEE__' . $class . '__get_valid_message_types__valid_types', $this->_valid_message_types, $this);
443
+        $valid_types = apply_filters('FHEE__'.$class.'__get_valid_message_types__valid_types', $this->_valid_message_types, $this);
444 444
 
445 445
         // all messengers filter
446 446
         $valid_types = apply_filters('FHEE__EE_messenger__get_valid_message_types__valid_types', $valid_types, $this);
@@ -475,7 +475,7 @@  discard block
 block discarded – undo
475 475
     {
476 476
         $class = get_class($this);
477 477
 
478
-        $config = apply_filters('FHEE__' . $class . '__get_validator_config', $this->_validator_config, $this);
478
+        $config = apply_filters('FHEE__'.$class.'__get_validator_config', $this->_validator_config, $this);
479 479
         $config = apply_filters('FHEE__EE_messenger__get_validator_config', $config, $this);
480 480
         return $config;
481 481
     }
@@ -514,12 +514,12 @@  discard block
 block discarded – undo
514 514
         // we don't need message types here so we're just going to ignore. we do, however, expect the event id here. The event id is needed to provide a link to setup a custom template for this event.
515 515
         $event_id = isset($extra['event']) ? $extra['event'] : null;
516 516
 
517
-        $template_wrapper_path = EE_LIBRARIES . 'messages/messenger/admin_templates/event_switcher_wrapper.template.php';
518
-        $template_row_path = EE_LIBRARIES . 'messages/messenger/admin_templates/event_switcher_row.template.php';
517
+        $template_wrapper_path = EE_LIBRARIES.'messages/messenger/admin_templates/event_switcher_wrapper.template.php';
518
+        $template_row_path = EE_LIBRARIES.'messages/messenger/admin_templates/event_switcher_row.template.php';
519 519
 
520 520
         // array of template objects for global and custom (non-trashed) (but remember just for this messenger!)
521 521
         $global_templates = EEM_Message_Template_Group::instance()->get_all(
522
-            array( array( 'MTP_messenger' => $this->name, 'MTP_is_global' => true, 'MTP_is_active' => true ) )
522
+            array(array('MTP_messenger' => $this->name, 'MTP_is_global' => true, 'MTP_is_active' => true))
523 523
         );
524 524
         $templates_for_event = EEM_Message_Template_Group::instance()->get_all_custom_templates_by_event(
525 525
             $event_id,
@@ -528,44 +528,44 @@  discard block
 block discarded – undo
528 528
                 'MTP_is_active' => true
529 529
             )
530 530
         );
531
-        $templates_for_event = !empty($templates_for_event) ? $templates_for_event : array();
531
+        $templates_for_event = ! empty($templates_for_event) ? $templates_for_event : array();
532 532
 
533 533
         // so we need to setup the rows for the selectors and we use the global mtpgs (cause those will the active message template groups)
534 534
         foreach ($global_templates as $mtpgID => $mtpg) {
535 535
             if ($mtpg instanceof EE_Message_Template_Group) {
536 536
                 // verify this message type is supposed to show on this page
537 537
                 $mtp_obj = $mtpg->message_type_obj();
538
-                if (! $mtp_obj instanceof EE_message_type) {
538
+                if ( ! $mtp_obj instanceof EE_message_type) {
539 539
                     continue;
540 540
                 }
541 541
                 $mtp_obj->admin_registered_pages = (array) $mtp_obj->admin_registered_pages;
542
-                if (! in_array('events_edit', $mtp_obj->admin_registered_pages)) {
542
+                if ( ! in_array('events_edit', $mtp_obj->admin_registered_pages)) {
543 543
                     continue;
544 544
                 }
545 545
                 $select_values = array();
546
-                $select_values[ $mtpgID ] = __('Global', 'event_espresso');
546
+                $select_values[$mtpgID] = __('Global', 'event_espresso');
547 547
                 $default_value = array_key_exists($mtpgID, $templates_for_event) && ! $mtpg->get('MTP_is_override') ? $mtpgID : null;
548 548
                 // if the override has been set for the global template, then that means even if there are custom templates already created we ignore them because of the set override.
549
-                if (! $mtpg->get('MTP_is_override')) {
549
+                if ( ! $mtpg->get('MTP_is_override')) {
550 550
                     // any custom templates for this message type?
551 551
                     $custom_templates = EEM_Message_Template_Group::instance()->get_custom_message_template_by_m_and_mt($this->name, $mtpg->message_type());
552 552
                     foreach ($custom_templates as $cmtpgID => $cmtpg) {
553
-                        $select_values[ $cmtpgID ] = $cmtpg->name();
553
+                        $select_values[$cmtpgID] = $cmtpg->name();
554 554
                         $default_value = array_key_exists($cmtpgID, $templates_for_event) ? $cmtpgID : $default_value;
555 555
                     }
556 556
                 }
557 557
                 // if there is no $default_value then we set it as the global
558 558
                 $default_value = empty($default_value) ? $mtpgID : $default_value;
559
-                $edit_url = EEH_URL::add_query_args_and_nonce(array( 'page' => 'espresso_messages', 'action' => 'edit_message_template', 'id' => $default_value ), admin_url('admin.php'));
560
-                $create_url = EEH_URL::add_query_args_and_nonce(array( 'page' => 'espresso_messages', 'action' => 'add_new_message_template', 'GRP_ID' => $default_value ), admin_url('admin.php'));
559
+                $edit_url = EEH_URL::add_query_args_and_nonce(array('page' => 'espresso_messages', 'action' => 'edit_message_template', 'id' => $default_value), admin_url('admin.php'));
560
+                $create_url = EEH_URL::add_query_args_and_nonce(array('page' => 'espresso_messages', 'action' => 'add_new_message_template', 'GRP_ID' => $default_value), admin_url('admin.php'));
561 561
                 $st_args['mt_name'] = ucwords($mtp_obj->label['singular']);
562 562
                 $st_args['mt_slug'] = $mtpg->message_type();
563 563
                 $st_args['messenger_slug'] = $this->name;
564
-                $st_args['selector'] = EEH_Form_Fields::select_input('event_message_templates_relation[' . $mtpgID . ']', $select_values, $default_value, 'data-messenger="' . $this->name . '" data-messagetype="' . $mtpg->message_type() . '"', 'message-template-selector');
564
+                $st_args['selector'] = EEH_Form_Fields::select_input('event_message_templates_relation['.$mtpgID.']', $select_values, $default_value, 'data-messenger="'.$this->name.'" data-messagetype="'.$mtpg->message_type().'"', 'message-template-selector');
565 565
                 // note that  message template group that has override_all_custom set will remove the ability to set a custom message template based off of the global (and that also in turn overrides any other custom templates).
566
-                $st_args['create_button'] = $mtpg->get('MTP_is_override') ? '' : '<a data-messenger="' . $this->name . '" data-messagetype="' . $mtpg->message_type() . '" data-grpid="' . $default_value . '" target="_blank" href="' . $create_url . '" class="button button-small create-mtpg-button">' . __('Create New Custom', 'event_espresso') . '</a>';
566
+                $st_args['create_button'] = $mtpg->get('MTP_is_override') ? '' : '<a data-messenger="'.$this->name.'" data-messagetype="'.$mtpg->message_type().'" data-grpid="'.$default_value.'" target="_blank" href="'.$create_url.'" class="button button-small create-mtpg-button">'.__('Create New Custom', 'event_espresso').'</a>';
567 567
                 $st_args['create_button'] = EE_Registry::instance()->CAP->current_user_can('ee_edit_messages', 'espresso_messages_add_new_message_template') ? $st_args['create_button'] : '';
568
-                $st_args['edit_button'] = EE_Registry::instance()->CAP->current_user_can('ee_edit_message', 'espresso_messages_edit_message_template', $mtpgID) ? '<a data-messagetype="' . $mtpg->message_type() . '" data-grpid="' . $default_value . '" target="_blank" href="' . $edit_url . '" class="button button-small edit-mtpg-button">' . __('Edit', 'event_espresso') . '</a>' : '';
568
+                $st_args['edit_button'] = EE_Registry::instance()->CAP->current_user_can('ee_edit_message', 'espresso_messages_edit_message_template', $mtpgID) ? '<a data-messagetype="'.$mtpg->message_type().'" data-grpid="'.$default_value.'" target="_blank" href="'.$edit_url.'" class="button button-small edit-mtpg-button">'.__('Edit', 'event_espresso').'</a>' : '';
569 569
                 $selector_rows .= EEH_Template::display_template($template_row_path, $st_args, true);
570 570
             }
571 571
         }
@@ -592,7 +592,7 @@  discard block
 block discarded – undo
592 592
      */
593 593
     public function get_template_fields()
594 594
     {
595
-        $template_fields = apply_filters('FHEE__' . get_class($this) . '__get_template_fields', $this->_template_fields, $this);
595
+        $template_fields = apply_filters('FHEE__'.get_class($this).'__get_template_fields', $this->_template_fields, $this);
596 596
         $template_fields = apply_filters('FHEE__EE_messenger__get_template_fields', $template_fields, $this);
597 597
         return $template_fields;
598 598
     }
@@ -609,8 +609,8 @@  discard block
 block discarded – undo
609 609
     protected function _set_template_value($item, $value)
610 610
     {
611 611
         if (array_key_exists($item, $this->_template_fields)) {
612
-            $prop = '_' . $item;
613
-            $this->{$prop}= $value;
612
+            $prop = '_'.$item;
613
+            $this->{$prop} = $value;
614 614
         }
615 615
     }
616 616
 
@@ -670,7 +670,7 @@  discard block
 block discarded – undo
670 670
                 $message,
671 671
                 $message_type
672 672
             );
673
-            if (! empty($settings)) {
673
+            if ( ! empty($settings)) {
674 674
                 foreach ($settings as $field => $value) {
675 675
                     $this->_set_template_value($field, $value);
676 676
                 }
@@ -678,12 +678,12 @@  discard block
 block discarded – undo
678 678
         }
679 679
 
680 680
         // enqueue preview js so that any links/buttons on the page are disabled.
681
-        if (! $send) {
681
+        if ( ! $send) {
682 682
             // the below may seem like duplication.  However, typically if a messenger enqueues scripts/styles,
683 683
             // it deregisters all existing wp scripts and styles first.  So the second hook ensures our previewer still gets setup.
684
-            add_action('admin_enqueue_scripts', array( $this, 'add_preview_script' ), 10);
685
-            add_action('wp_enqueue_scripts', array( $this, 'add_preview_script' ), 10);
686
-            add_action('AHEE__EE_messenger__enqueue_scripts_styles', array( $this, 'add_preview_script' ), 10);
684
+            add_action('admin_enqueue_scripts', array($this, 'add_preview_script'), 10);
685
+            add_action('wp_enqueue_scripts', array($this, 'add_preview_script'), 10);
686
+            add_action('AHEE__EE_messenger__enqueue_scripts_styles', array($this, 'add_preview_script'), 10);
687 687
         }
688 688
 
689 689
         return $send ? $this->_send_message() : $this->_preview();
@@ -703,7 +703,7 @@  discard block
 block discarded – undo
703 703
     {
704 704
         // error message
705 705
         EE_Registry::$i18n_js_strings['links_disabled'] = __('All the links on this page have been disabled because this is a generated preview message for the purpose of ensuring layout, style, and content setup.  To test generated links, you must trigger an actual message notification.', 'event_espresso');
706
-        wp_register_script('ee-messages-preview-js', EE_LIBRARIES_URL . 'messages/messenger/assets/js/ee-messages-preview.js', array( 'jquery' ), EVENT_ESPRESSO_VERSION, true);
706
+        wp_register_script('ee-messages-preview-js', EE_LIBRARIES_URL.'messages/messenger/assets/js/ee-messages-preview.js', array('jquery'), EVENT_ESPRESSO_VERSION, true);
707 707
         wp_localize_script('ee-messages-preview-js', 'eei18n', EE_Registry::$i18n_js_strings);
708 708
         wp_enqueue_script('ee-messages-preview-js');
709 709
     }
@@ -722,7 +722,7 @@  discard block
 block discarded – undo
722 722
         $variation = $message->get_template_pack_variation();
723 723
 
724 724
         // verify we have the required template pack value on the $message object.
725
-        if (! $template_pack instanceof EE_Messages_Template_Pack) {
725
+        if ( ! $template_pack instanceof EE_Messages_Template_Pack) {
726 726
             throw new EE_Error(__('Incoming $message object must have an EE_Messages_Template_Pack object available.', 'event_espresso'));
727 727
         }
728 728
 
@@ -734,7 +734,7 @@  discard block
 block discarded – undo
734 734
 
735 735
         foreach ($template_fields as $template => $value) {
736 736
             if ($template !== 'extra') {
737
-                $column_value = $message->get_field_or_extra_meta('MSG_' . $template);
737
+                $column_value = $message->get_field_or_extra_meta('MSG_'.$template);
738 738
                 $message_template_value = $column_value ? $column_value : null;
739 739
                 $this->_set_template_value($template, $message_template_value);
740 740
             }
@@ -758,7 +758,7 @@  discard block
 block discarded – undo
758 758
         $wrapper_template = $this->_tmp_pack->get_wrapper($this->name, $type);
759 759
 
760 760
         // check file exists and is readable
761
-        if (!is_readable($wrapper_template)) {
761
+        if ( ! is_readable($wrapper_template)) {
762 762
             throw new EE_Error(sprintf(__('Unable to access the template file for the %s messenger main content wrapper.  The location being attempted is %s.', 'event_espresso'), ucwords($this->label['singular']), $wrapper_template));
763 763
         }
764 764
 
@@ -806,7 +806,7 @@  discard block
 block discarded – undo
806 806
         /** @var EE_Message_Resource_Manager $Message_Resource_Manager */
807 807
         $Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
808 808
         $settings = $Message_Resource_Manager->get_active_messengers_option();
809
-        return isset($settings[ $this->name ]['test_settings']) ? $settings[ $this->name ]['test_settings'] : array();
809
+        return isset($settings[$this->name]['test_settings']) ? $settings[$this->name]['test_settings'] : array();
810 810
     }
811 811
 
812 812
 
@@ -823,7 +823,7 @@  discard block
 block discarded – undo
823 823
         /** @var EE_Message_Resource_Manager $Message_Resource_Manager */
824 824
         $Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
825 825
         $existing = $Message_Resource_Manager->get_active_messengers_option();
826
-        $existing[ $this->name ]['test_settings'] = $settings;
826
+        $existing[$this->name]['test_settings'] = $settings;
827 827
         return $Message_Resource_Manager->update_active_messengers_option($existing);
828 828
     }
829 829
 
@@ -840,23 +840,23 @@  discard block
 block discarded – undo
840 840
     public function get_field_label($field)
841 841
     {
842 842
         // first let's see if the field requests is in the top level array.
843
-        if (isset($this->_template_fields[ $field ]) && !empty($this->_template_fields[ $field ]['label'])) {
844
-            return $this->_template[ $field ]['label'];
843
+        if (isset($this->_template_fields[$field]) && ! empty($this->_template_fields[$field]['label'])) {
844
+            return $this->_template[$field]['label'];
845 845
         }
846 846
 
847 847
         // nope so let's look in the extra array to see if it's there HOWEVER if the field exists as a top level index in the extra array then we know the label is in the 'main' index.
848
-        if (isset($this->_template_fields['extra']) && !empty($this->_template_fields['extra'][ $field ]) && !empty($this->_template_fields['extra'][ $field ]['main']['label'])) {
849
-            return $this->_template_fields['extra'][ $field ]['main']['label'];
848
+        if (isset($this->_template_fields['extra']) && ! empty($this->_template_fields['extra'][$field]) && ! empty($this->_template_fields['extra'][$field]['main']['label'])) {
849
+            return $this->_template_fields['extra'][$field]['main']['label'];
850 850
         }
851 851
 
852 852
         // now it's possible this field may just be existing in any of the extra array items.
853
-        if (!empty($this->_template_fields['extra']) && is_array($this->_template_fields['extra'])) {
853
+        if ( ! empty($this->_template_fields['extra']) && is_array($this->_template_fields['extra'])) {
854 854
             foreach ($this->_template_fields['extra'] as $main_field => $subfields) {
855
-                if (!is_array($subfields)) {
855
+                if ( ! is_array($subfields)) {
856 856
                     continue;
857 857
                 }
858
-                if (isset($subfields[ $field ]) && !empty($subfields[ $field ]['label'])) {
859
-                    return $subfields[ $field ]['label'];
858
+                if (isset($subfields[$field]) && ! empty($subfields[$field]['label'])) {
859
+                    return $subfields[$field]['label'];
860 860
                 }
861 861
             }
862 862
         }
Please login to merge, or discard this patch.