Completed
Branch rest-authorization (c7240a)
by
unknown
13:01 queued 10:45
created
modules/ticket_selector_caff/EED_Ticket_Selector_Caff.module.php 2 patches
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -52,7 +52,7 @@  discard block
 block discarded – undo
52 52
     {
53 53
         define(
54 54
             'TICKET_SELECTOR_CAFF_TEMPLATES_PATH',
55
-            str_replace('\\', '/', plugin_dir_path(__FILE__)) . 'templates/'
55
+            str_replace('\\', '/', plugin_dir_path(__FILE__)).'templates/'
56 56
         );
57 57
         add_action(
58 58
             'AHEE__template_settings__template__before_settings_form',
@@ -107,7 +107,7 @@  discard block
 block discarded – undo
107 107
                     'FHEE__EED_Ticket_Selector_Caff___ticket_selector_settings_form__form_subsections',
108 108
                     array(
109 109
                         'appearance_settings_hdr' => new EE_Form_Section_HTML(
110
-                            EEH_HTML::br(2) .
110
+                            EEH_HTML::br(2).
111 111
                             EEH_HTML::h2(esc_html__('Ticket Selector Template Settings', 'event_espresso'))
112 112
                         ),
113 113
                         'appearance_settings'     => EED_Ticket_Selector_Caff::_ticket_selector_appearance_settings(),
@@ -273,7 +273,7 @@  discard block
 block discarded – undo
273 273
      */
274 274
     public static function update_template_settings(EE_Template_Config $CFG, $REQ)
275 275
     {
276
-        if (! $CFG->EED_Ticket_Selector instanceof EE_Ticket_Selector_Config) {
276
+        if ( ! $CFG->EED_Ticket_Selector instanceof EE_Ticket_Selector_Config) {
277 277
             EED_Ticket_Selector::instance()->set_config();
278 278
             $CFG->EED_Ticket_Selector = EED_Ticket_Selector::instance()->config();
279 279
         }
Please login to merge, or discard this patch.
Indentation   +294 added lines, -294 removed lines patch added patch discarded remove patch
@@ -15,319 +15,319 @@
 block discarded – undo
15 15
  */
16 16
 class EED_Ticket_Selector_Caff extends EED_Ticket_Selector
17 17
 {
18
-    /**
19
-     * @return EED_Module|EED_Ticket_Selector_Caff
20
-     */
21
-    public static function instance()
22
-    {
23
-        return parent::get_instance(__CLASS__);
24
-    }
18
+	/**
19
+	 * @return EED_Module|EED_Ticket_Selector_Caff
20
+	 */
21
+	public static function instance()
22
+	{
23
+		return parent::get_instance(__CLASS__);
24
+	}
25 25
 
26 26
 
27
-    /**
28
-     *    set_hooks - for hooking into EE Core, other modules, etc
29
-     *
30
-     * @access    public
31
-     * @return    void
32
-     */
33
-    public static function set_hooks()
34
-    {
35
-        add_action(
36
-            'AHEE__ticket_selector_chart_template__ticket_details__after_description',
37
-            array('EED_Ticket_Selector_Caff', 'ticket_price_details'),
38
-            10,
39
-            3
40
-        );
41
-    }
27
+	/**
28
+	 *    set_hooks - for hooking into EE Core, other modules, etc
29
+	 *
30
+	 * @access    public
31
+	 * @return    void
32
+	 */
33
+	public static function set_hooks()
34
+	{
35
+		add_action(
36
+			'AHEE__ticket_selector_chart_template__ticket_details__after_description',
37
+			array('EED_Ticket_Selector_Caff', 'ticket_price_details'),
38
+			10,
39
+			3
40
+		);
41
+	}
42 42
 
43
-    /**
44
-     *    set_hooks_admin - for hooking into EE Admin Core, other modules, etc
45
-     *
46
-     * @access    public
47
-     * @return    void
48
-     */
49
-    public static function set_hooks_admin()
50
-    {
51
-        define(
52
-            'TICKET_SELECTOR_CAFF_TEMPLATES_PATH',
53
-            str_replace('\\', '/', plugin_dir_path(__FILE__)) . 'templates/'
54
-        );
55
-        add_action(
56
-            'AHEE__template_settings__template__before_settings_form',
57
-            array('EED_Ticket_Selector_Caff', 'template_settings_form'),
58
-            10
59
-        );
60
-        add_filter(
61
-            'FHEE__General_Settings_Admin_Page__update_template_settings__data',
62
-            array('EED_Ticket_Selector_Caff', 'update_template_settings'),
63
-            10,
64
-            2
65
-        );
66
-    }
43
+	/**
44
+	 *    set_hooks_admin - for hooking into EE Admin Core, other modules, etc
45
+	 *
46
+	 * @access    public
47
+	 * @return    void
48
+	 */
49
+	public static function set_hooks_admin()
50
+	{
51
+		define(
52
+			'TICKET_SELECTOR_CAFF_TEMPLATES_PATH',
53
+			str_replace('\\', '/', plugin_dir_path(__FILE__)) . 'templates/'
54
+		);
55
+		add_action(
56
+			'AHEE__template_settings__template__before_settings_form',
57
+			array('EED_Ticket_Selector_Caff', 'template_settings_form'),
58
+			10
59
+		);
60
+		add_filter(
61
+			'FHEE__General_Settings_Admin_Page__update_template_settings__data',
62
+			array('EED_Ticket_Selector_Caff', 'update_template_settings'),
63
+			10,
64
+			2
65
+		);
66
+	}
67 67
 
68 68
 
69
-    /**
70
-     * @param \WP $WP
71
-     */
72
-    public function run($WP)
73
-    {
74
-        $this->set_config();
75
-    }
69
+	/**
70
+	 * @param \WP $WP
71
+	 */
72
+	public function run($WP)
73
+	{
74
+		$this->set_config();
75
+	}
76 76
 
77 77
 
78
-    /**
79
-     * @static
80
-     * @return void
81
-     * @throws EE_Error
82
-     * @throws InvalidArgumentException
83
-     * @throws InvalidDataTypeException
84
-     * @throws InvalidInterfaceException
85
-     */
86
-    public static function template_settings_form()
87
-    {
88
-        echo EED_Ticket_Selector_Caff::_ticket_selector_settings_form()->get_html();
89
-    }
78
+	/**
79
+	 * @static
80
+	 * @return void
81
+	 * @throws EE_Error
82
+	 * @throws InvalidArgumentException
83
+	 * @throws InvalidDataTypeException
84
+	 * @throws InvalidInterfaceException
85
+	 */
86
+	public static function template_settings_form()
87
+	{
88
+		echo EED_Ticket_Selector_Caff::_ticket_selector_settings_form()->get_html();
89
+	}
90 90
 
91 91
 
92
-    /**
93
-     * @return \EE_Form_Section_Proper
94
-     * @throws \EE_Error
95
-     */
96
-    public static function _ticket_selector_settings_form()
97
-    {
92
+	/**
93
+	 * @return \EE_Form_Section_Proper
94
+	 * @throws \EE_Error
95
+	 */
96
+	public static function _ticket_selector_settings_form()
97
+	{
98 98
 
99
-        return new EE_Form_Section_Proper(
100
-            array(
101
-                'name'            => 'ticket_selector_settings_form',
102
-                'html_id'         => 'ticket_selector_settings_form',
103
-                'layout_strategy' => new EE_Div_Per_Section_Layout(),
104
-                'subsections'     => apply_filters(
105
-                    'FHEE__EED_Ticket_Selector_Caff___ticket_selector_settings_form__form_subsections',
106
-                    array(
107
-                        'appearance_settings_hdr' => new EE_Form_Section_HTML(
108
-                            EEH_HTML::br(2) .
109
-                            EEH_HTML::h2(esc_html__('Ticket Selector Template Settings', 'event_espresso'))
110
-                        ),
111
-                        'appearance_settings'     => EED_Ticket_Selector_Caff::_ticket_selector_appearance_settings(),
112
-                    )
113
-                ),
114
-            )
115
-        );
116
-    }
99
+		return new EE_Form_Section_Proper(
100
+			array(
101
+				'name'            => 'ticket_selector_settings_form',
102
+				'html_id'         => 'ticket_selector_settings_form',
103
+				'layout_strategy' => new EE_Div_Per_Section_Layout(),
104
+				'subsections'     => apply_filters(
105
+					'FHEE__EED_Ticket_Selector_Caff___ticket_selector_settings_form__form_subsections',
106
+					array(
107
+						'appearance_settings_hdr' => new EE_Form_Section_HTML(
108
+							EEH_HTML::br(2) .
109
+							EEH_HTML::h2(esc_html__('Ticket Selector Template Settings', 'event_espresso'))
110
+						),
111
+						'appearance_settings'     => EED_Ticket_Selector_Caff::_ticket_selector_appearance_settings(),
112
+					)
113
+				),
114
+			)
115
+		);
116
+	}
117 117
 
118 118
 
119
-    /**
120
-     * @return \EE_Form_Section_Proper
121
-     * @throws \EE_Error
122
-     */
123
-    public static function _ticket_selector_appearance_settings()
124
-    {
125
-        if (
126
-            ! EE_Registry::instance()->CFG->template_settings->EED_Ticket_Selector instanceof EE_Ticket_Selector_Config
127
-        ) {
128
-            EED_Ticket_Selector::instance()->set_config();
129
-            EE_Registry::instance()->CFG->template_settings->EED_Ticket_Selector = EED_Ticket_Selector::instance()
130
-                                                                                                      ->config();
131
-        }
132
-        $EE_Ticket_Selector_Config = EE_Registry::instance()->CFG->template_settings->EED_Ticket_Selector;
133
-        // get option for whether to show datetime selector in TS
134
-        $show_datetime_selector = $EE_Ticket_Selector_Config->getShowDatetimeSelector();
135
-        // and option for how may datetimes must exist if display is conditional
136
-        $datetime_selector_threshold = $EE_Ticket_Selector_Config->getDatetimeSelectorThreshold();
119
+	/**
120
+	 * @return \EE_Form_Section_Proper
121
+	 * @throws \EE_Error
122
+	 */
123
+	public static function _ticket_selector_appearance_settings()
124
+	{
125
+		if (
126
+			! EE_Registry::instance()->CFG->template_settings->EED_Ticket_Selector instanceof EE_Ticket_Selector_Config
127
+		) {
128
+			EED_Ticket_Selector::instance()->set_config();
129
+			EE_Registry::instance()->CFG->template_settings->EED_Ticket_Selector = EED_Ticket_Selector::instance()
130
+																									  ->config();
131
+		}
132
+		$EE_Ticket_Selector_Config = EE_Registry::instance()->CFG->template_settings->EED_Ticket_Selector;
133
+		// get option for whether to show datetime selector in TS
134
+		$show_datetime_selector = $EE_Ticket_Selector_Config->getShowDatetimeSelector();
135
+		// and option for how may datetimes must exist if display is conditional
136
+		$datetime_selector_threshold = $EE_Ticket_Selector_Config->getDatetimeSelectorThreshold();
137 137
 
138
-        return new EE_Form_Section_Proper(
139
-            array(
140
-                'name'            => 'ticket_selector_settings_tbl',
141
-                'html_id'         => 'ticket_selector_settings_tbl',
142
-                'html_class'      => 'form-table',
143
-                'layout_strategy' => new EE_Admin_Two_Column_Layout(),
144
-                'subsections'     => apply_filters(
145
-                    'FHEE__EED_Ticket_Selector_Caff___ticket_selector_appearance_settings__form_subsections',
146
-                    array(
147
-                        'show_ticket_details'         => new EE_Yes_No_Input(
148
-                            array(
149
-                                'html_label_text'         => esc_html__(
150
-                                    'Show Ticket Details?',
151
-                                    'event_espresso'
152
-                                ),
153
-                                'html_help_text'          => esc_html__(
154
-                                    'This lets you choose whether the extra ticket details section is displayed with the ticket selector.',
155
-                                    'event_espresso'
156
-                                ),
157
-                                'default'                 => isset($EE_Ticket_Selector_Config->show_ticket_details)
158
-                                    ? $EE_Ticket_Selector_Config->show_ticket_details
159
-                                    : true,
160
-                                'display_html_label_text' => false,
161
-                            )
162
-                        ),
163
-                        'show_ticket_sale_columns'    => new EE_Yes_No_Input(
164
-                            array(
165
-                                'html_label_text'         => esc_html__(
166
-                                    'Show Ticket Sale Info?',
167
-                                    'event_espresso'
168
-                                ),
169
-                                'html_help_text'          => esc_html__(
170
-                                    'This lets you indicate whether information about ticket sales is shown with ticket details in the ticket selector.',
171
-                                    'event_espresso'
172
-                                ),
173
-                                'default'                 => isset($EE_Ticket_Selector_Config->show_ticket_sale_columns)
174
-                                    ? $EE_Ticket_Selector_Config->show_ticket_sale_columns
175
-                                    : true,
176
-                                'display_html_label_text' => false,
177
-                            )
178
-                        ),
179
-                        'show_expired_tickets'        => new EE_Yes_No_Input(
180
-                            array(
181
-                                'html_label_text'         => esc_html__(
182
-                                    'Show Expired Tickets?',
183
-                                    'event_espresso'
184
-                                ),
185
-                                'html_help_text'          => esc_html__(
186
-                                    'Indicate whether to show expired tickets in the ticket selector',
187
-                                    'event_espresso'
188
-                                ),
189
-                                'default'                 => isset($EE_Ticket_Selector_Config->show_expired_tickets)
190
-                                    ? $EE_Ticket_Selector_Config->show_expired_tickets
191
-                                    : true,
192
-                                'display_html_label_text' => false,
193
-                            )
194
-                        ),
195
-                        'show_datetime_selector'      => new EE_Select_Input(
196
-                            $EE_Ticket_Selector_Config->getShowDatetimeSelectorOptions(false),
197
-                            array(
198
-                                'html_label_text'         => esc_html__(
199
-                                    'Show Date & Time Filter?',
200
-                                    'event_espresso'
201
-                                ),
202
-                                'html_help_text'          => sprintf(
203
-                                    esc_html__(
204
-                                        'Indicates whether or not to display a dropdown select box above each ticket selector that displays dates and times for the available tickets. Ticket options can be unselected, which removes (hides) them from the list of tickets being displayed.%1$sOptions include:%1$s • %2$sdo not show date & time filter%3$s%1$s   this option will NEVER display a date filter, regardless of how many dates exist.%1$s • %2$smaybe show date & time filter%3$s%1$s   this option will conditionally display the date filter when the number of dates for the event matches the value set for "Date Filter Threshold".',
205
-                                        'event_espresso'
206
-                                    ),
207
-                                    '<br>',
208
-                                    '<strong>',
209
-                                    '</strong>'
210
-                                ),
211
-                                'default'                 => ! empty($show_datetime_selector)
212
-                                    ? $show_datetime_selector
213
-                                    : EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR,
214
-                                'display_html_label_text' => false,
215
-                            )
216
-                        ),
217
-                        'datetime_selector_threshold' => new EE_Select_Input(
218
-                            array_combine($r = range(1, 10), $r),
219
-                            array(
220
-                                'html_label_text'         => esc_html__(
221
-                                    'Date & Time Filter Threshold',
222
-                                    'event_espresso'
223
-                                ),
224
-                                'html_help_text'          => esc_html__(
225
-                                    'The number of unique dates an event has to have before conditionally displaying a date & time filter',
226
-                                    'event_espresso'
227
-                                ),
228
-                                'default'                 => ! empty($datetime_selector_threshold)
229
-                                    ? $datetime_selector_threshold
230
-                                    : 3,
231
-                                'display_html_label_text' => false,
232
-                            )
233
-                        ),
234
-                        'datetime_selector_max_checked' => new EE_Integer_Input(
235
-                            array(
236
-                                'html_label_text'         => esc_html__(
237
-                                    'Date & Time Filter Max Checked',
238
-                                    'event_espresso'
239
-                                ),
240
-                                'html_help_text'          => sprintf(
241
-                                    esc_html__(
242
-                                        'Determines the maximum number of dates that will be checked upon initial loading for a Date and Time Filter.%1$sIf set to zero or left blank, then ALL dates will be checked upon initial loading.',
243
-                                        'event_espresso'
244
-                                    ),
245
-                                    '<br>'
246
-                                ),
247
-                                'default'                 => $EE_Ticket_Selector_Config->getDatetimeSelectorMaxChecked(),
248
-                                'display_html_label_text' => false,
249
-                                'min_value'               => 0,
250
-                            )
251
-                        ),
252
-                    )
253
-                ),
254
-            )
255
-        );
256
-    }
138
+		return new EE_Form_Section_Proper(
139
+			array(
140
+				'name'            => 'ticket_selector_settings_tbl',
141
+				'html_id'         => 'ticket_selector_settings_tbl',
142
+				'html_class'      => 'form-table',
143
+				'layout_strategy' => new EE_Admin_Two_Column_Layout(),
144
+				'subsections'     => apply_filters(
145
+					'FHEE__EED_Ticket_Selector_Caff___ticket_selector_appearance_settings__form_subsections',
146
+					array(
147
+						'show_ticket_details'         => new EE_Yes_No_Input(
148
+							array(
149
+								'html_label_text'         => esc_html__(
150
+									'Show Ticket Details?',
151
+									'event_espresso'
152
+								),
153
+								'html_help_text'          => esc_html__(
154
+									'This lets you choose whether the extra ticket details section is displayed with the ticket selector.',
155
+									'event_espresso'
156
+								),
157
+								'default'                 => isset($EE_Ticket_Selector_Config->show_ticket_details)
158
+									? $EE_Ticket_Selector_Config->show_ticket_details
159
+									: true,
160
+								'display_html_label_text' => false,
161
+							)
162
+						),
163
+						'show_ticket_sale_columns'    => new EE_Yes_No_Input(
164
+							array(
165
+								'html_label_text'         => esc_html__(
166
+									'Show Ticket Sale Info?',
167
+									'event_espresso'
168
+								),
169
+								'html_help_text'          => esc_html__(
170
+									'This lets you indicate whether information about ticket sales is shown with ticket details in the ticket selector.',
171
+									'event_espresso'
172
+								),
173
+								'default'                 => isset($EE_Ticket_Selector_Config->show_ticket_sale_columns)
174
+									? $EE_Ticket_Selector_Config->show_ticket_sale_columns
175
+									: true,
176
+								'display_html_label_text' => false,
177
+							)
178
+						),
179
+						'show_expired_tickets'        => new EE_Yes_No_Input(
180
+							array(
181
+								'html_label_text'         => esc_html__(
182
+									'Show Expired Tickets?',
183
+									'event_espresso'
184
+								),
185
+								'html_help_text'          => esc_html__(
186
+									'Indicate whether to show expired tickets in the ticket selector',
187
+									'event_espresso'
188
+								),
189
+								'default'                 => isset($EE_Ticket_Selector_Config->show_expired_tickets)
190
+									? $EE_Ticket_Selector_Config->show_expired_tickets
191
+									: true,
192
+								'display_html_label_text' => false,
193
+							)
194
+						),
195
+						'show_datetime_selector'      => new EE_Select_Input(
196
+							$EE_Ticket_Selector_Config->getShowDatetimeSelectorOptions(false),
197
+							array(
198
+								'html_label_text'         => esc_html__(
199
+									'Show Date & Time Filter?',
200
+									'event_espresso'
201
+								),
202
+								'html_help_text'          => sprintf(
203
+									esc_html__(
204
+										'Indicates whether or not to display a dropdown select box above each ticket selector that displays dates and times for the available tickets. Ticket options can be unselected, which removes (hides) them from the list of tickets being displayed.%1$sOptions include:%1$s &bull; %2$sdo not show date & time filter%3$s%1$s &nbsp; this option will NEVER display a date filter, regardless of how many dates exist.%1$s &bull; %2$smaybe show date & time filter%3$s%1$s &nbsp; this option will conditionally display the date filter when the number of dates for the event matches the value set for "Date Filter Threshold".',
205
+										'event_espresso'
206
+									),
207
+									'<br>',
208
+									'<strong>',
209
+									'</strong>'
210
+								),
211
+								'default'                 => ! empty($show_datetime_selector)
212
+									? $show_datetime_selector
213
+									: EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR,
214
+								'display_html_label_text' => false,
215
+							)
216
+						),
217
+						'datetime_selector_threshold' => new EE_Select_Input(
218
+							array_combine($r = range(1, 10), $r),
219
+							array(
220
+								'html_label_text'         => esc_html__(
221
+									'Date & Time Filter Threshold',
222
+									'event_espresso'
223
+								),
224
+								'html_help_text'          => esc_html__(
225
+									'The number of unique dates an event has to have before conditionally displaying a date & time filter',
226
+									'event_espresso'
227
+								),
228
+								'default'                 => ! empty($datetime_selector_threshold)
229
+									? $datetime_selector_threshold
230
+									: 3,
231
+								'display_html_label_text' => false,
232
+							)
233
+						),
234
+						'datetime_selector_max_checked' => new EE_Integer_Input(
235
+							array(
236
+								'html_label_text'         => esc_html__(
237
+									'Date & Time Filter Max Checked',
238
+									'event_espresso'
239
+								),
240
+								'html_help_text'          => sprintf(
241
+									esc_html__(
242
+										'Determines the maximum number of dates that will be checked upon initial loading for a Date and Time Filter.%1$sIf set to zero or left blank, then ALL dates will be checked upon initial loading.',
243
+										'event_espresso'
244
+									),
245
+									'<br>'
246
+								),
247
+								'default'                 => $EE_Ticket_Selector_Config->getDatetimeSelectorMaxChecked(),
248
+								'display_html_label_text' => false,
249
+								'min_value'               => 0,
250
+							)
251
+						),
252
+					)
253
+				),
254
+			)
255
+		);
256
+	}
257 257
 
258 258
 
259
-    /**
260
-     * callback for updating template settings
261
-     *
262
-     * @since 4.6.18.rc.006
263
-     * @param EE_Template_Config $CFG
264
-     * @param array              $REQ incoming request
265
-     * @return EE_Template_Config
266
-     * @throws EE_Error
267
-     * @throws InvalidArgumentException
268
-     * @throws ReflectionException
269
-     * @throws InvalidDataTypeException
270
-     * @throws InvalidInterfaceException
271
-     */
272
-    public static function update_template_settings(EE_Template_Config $CFG, $REQ)
273
-    {
274
-        if (! $CFG->EED_Ticket_Selector instanceof EE_Ticket_Selector_Config) {
275
-            EED_Ticket_Selector::instance()->set_config();
276
-            $CFG->EED_Ticket_Selector = EED_Ticket_Selector::instance()->config();
277
-        }
278
-        try {
279
-            $ticket_selector_form = EED_Ticket_Selector_Caff::_ticket_selector_settings_form();
259
+	/**
260
+	 * callback for updating template settings
261
+	 *
262
+	 * @since 4.6.18.rc.006
263
+	 * @param EE_Template_Config $CFG
264
+	 * @param array              $REQ incoming request
265
+	 * @return EE_Template_Config
266
+	 * @throws EE_Error
267
+	 * @throws InvalidArgumentException
268
+	 * @throws ReflectionException
269
+	 * @throws InvalidDataTypeException
270
+	 * @throws InvalidInterfaceException
271
+	 */
272
+	public static function update_template_settings(EE_Template_Config $CFG, $REQ)
273
+	{
274
+		if (! $CFG->EED_Ticket_Selector instanceof EE_Ticket_Selector_Config) {
275
+			EED_Ticket_Selector::instance()->set_config();
276
+			$CFG->EED_Ticket_Selector = EED_Ticket_Selector::instance()->config();
277
+		}
278
+		try {
279
+			$ticket_selector_form = EED_Ticket_Selector_Caff::_ticket_selector_settings_form();
280 280
 
281
-            // check for form submission
282
-            if ($ticket_selector_form->was_submitted()) {
283
-                // capture form data
284
-                $ticket_selector_form->receive_form_submission();
281
+			// check for form submission
282
+			if ($ticket_selector_form->was_submitted()) {
283
+				// capture form data
284
+				$ticket_selector_form->receive_form_submission();
285 285
 
286
-                // validate form data
287
-                if ($ticket_selector_form->is_valid()) {
288
-                    // grab validated data from form
289
-                    $valid_data = $ticket_selector_form->valid_data();
286
+				// validate form data
287
+				if ($ticket_selector_form->is_valid()) {
288
+					// grab validated data from form
289
+					$valid_data = $ticket_selector_form->valid_data();
290 290
 
291
-                    // set data on config
292
-                    $CFG->EED_Ticket_Selector->show_ticket_sale_columns = $valid_data['appearance_settings']['show_ticket_sale_columns'];
293
-                    $CFG->EED_Ticket_Selector->show_ticket_details = $valid_data['appearance_settings']['show_ticket_details'];
294
-                    $CFG->EED_Ticket_Selector->show_expired_tickets = $valid_data['appearance_settings']['show_expired_tickets'];
295
-                    $CFG->EED_Ticket_Selector->setShowDatetimeSelector(
296
-                        $valid_data['appearance_settings']['show_datetime_selector']
297
-                    );
298
-                    $CFG->EED_Ticket_Selector->setDatetimeSelectorThreshold(
299
-                        $valid_data['appearance_settings']['datetime_selector_threshold']
300
-                    );
301
-                    $CFG->EED_Ticket_Selector->setDatetimeSelectorMaxChecked(
302
-                        $valid_data['appearance_settings']['datetime_selector_max_checked']
303
-                    );
304
-                } else {
305
-                    if ($ticket_selector_form->submission_error_message() !== '') {
306
-                        EE_Error::add_error(
307
-                            $ticket_selector_form->submission_error_message(),
308
-                            __FILE__,
309
-                            __FUNCTION__,
310
-                            __LINE__
311
-                        );
312
-                    }
313
-                }
314
-            }
315
-        } catch (EE_Error $e) {
316
-            $e->get_error();
317
-        }
291
+					// set data on config
292
+					$CFG->EED_Ticket_Selector->show_ticket_sale_columns = $valid_data['appearance_settings']['show_ticket_sale_columns'];
293
+					$CFG->EED_Ticket_Selector->show_ticket_details = $valid_data['appearance_settings']['show_ticket_details'];
294
+					$CFG->EED_Ticket_Selector->show_expired_tickets = $valid_data['appearance_settings']['show_expired_tickets'];
295
+					$CFG->EED_Ticket_Selector->setShowDatetimeSelector(
296
+						$valid_data['appearance_settings']['show_datetime_selector']
297
+					);
298
+					$CFG->EED_Ticket_Selector->setDatetimeSelectorThreshold(
299
+						$valid_data['appearance_settings']['datetime_selector_threshold']
300
+					);
301
+					$CFG->EED_Ticket_Selector->setDatetimeSelectorMaxChecked(
302
+						$valid_data['appearance_settings']['datetime_selector_max_checked']
303
+					);
304
+				} else {
305
+					if ($ticket_selector_form->submission_error_message() !== '') {
306
+						EE_Error::add_error(
307
+							$ticket_selector_form->submission_error_message(),
308
+							__FILE__,
309
+							__FUNCTION__,
310
+							__LINE__
311
+						);
312
+					}
313
+				}
314
+			}
315
+		} catch (EE_Error $e) {
316
+			$e->get_error();
317
+		}
318 318
 
319
-        return $CFG;
320
-    }
319
+		return $CFG;
320
+	}
321 321
 
322 322
 
323
-    /**
324
-     * @param \EE_Ticket $ticket
325
-     * @param int        $ticket_price
326
-     * @param bool       $display_ticket_price
327
-     */
328
-    public static function ticket_price_details(EE_Ticket $ticket, $ticket_price = 0, $display_ticket_price = false)
329
-    {
330
-        require str_replace('\\', '/', plugin_dir_path(__FILE__))
331
-                . 'templates/ticket_selector_price_details.template.php';
332
-    }
323
+	/**
324
+	 * @param \EE_Ticket $ticket
325
+	 * @param int        $ticket_price
326
+	 * @param bool       $display_ticket_price
327
+	 */
328
+	public static function ticket_price_details(EE_Ticket $ticket, $ticket_price = 0, $display_ticket_price = false)
329
+	{
330
+		require str_replace('\\', '/', plugin_dir_path(__FILE__))
331
+				. 'templates/ticket_selector_price_details.template.php';
332
+	}
333 333
 }
Please login to merge, or discard this patch.
libraries/line_item_display/EE_SPCO_Line_Item_Display_Strategy.strategy.php 2 patches
Spacing   +19 added lines, -19 removed lines patch added patch discarded remove patch
@@ -84,7 +84,7 @@  discard block
 block discarded – undo
84 84
         $html = '';
85 85
         // set some default options and merge with incoming
86 86
         $default_options = array(
87
-            'show_desc' => true,  //    true        false
87
+            'show_desc' => true, //    true        false
88 88
             'odd'       => false,
89 89
         );
90 90
         $options = array_merge($default_options, (array) $options);
@@ -119,7 +119,7 @@  discard block
 block discarded – undo
119 119
                 $text = esc_html__('Sub-Total', 'event_espresso');
120 120
                 if ($line_item->OBJ_type() === 'Event') {
121 121
                     $options['event_id'] = $event_id = $line_item->OBJ_ID();
122
-                    if (! isset($this->_events[ $options['event_id'] ])) {
122
+                    if ( ! isset($this->_events[$options['event_id']])) {
123 123
                         $event = EEM_Event::instance()->get_one_by_ID($options['event_id']);
124 124
                         // if event has default reg status of Not Approved, then don't display info on it
125 125
                         if (
@@ -130,7 +130,7 @@  discard block
 block discarded – undo
130 130
                             // unless there are registrations for it that are returning to pay
131 131
                             if (isset($options['registrations']) && is_array($options['registrations'])) {
132 132
                                 foreach ($options['registrations'] as $registration) {
133
-                                    if (! $registration instanceof EE_Registration) {
133
+                                    if ( ! $registration instanceof EE_Registration) {
134 134
                                         continue;
135 135
                                     }
136 136
                                     $display_event = $registration->event_ID() === $options['event_id']
@@ -139,11 +139,11 @@  discard block
 block discarded – undo
139 139
                                         : $display_event;
140 140
                                 }
141 141
                             }
142
-                            if (! $display_event) {
142
+                            if ( ! $display_event) {
143 143
                                 return '';
144 144
                             }
145 145
                         }
146
-                        $this->_events[ $options['event_id'] ] = 0;
146
+                        $this->_events[$options['event_id']] = 0;
147 147
                         $html .= $this->_event_row($line_item);
148 148
                         $text = esc_html__('Event Sub-Total', 'event_espresso');
149 149
                     }
@@ -154,7 +154,7 @@  discard block
 block discarded – undo
154 154
                     // recursively feed children back into this method
155 155
                     $html .= $this->display_line_item($child_line_item, $options, $line_item);
156 156
                 }
157
-                $event_sub_total += isset($options['event_id']) ? $this->_events[ $options['event_id'] ] : 0;
157
+                $event_sub_total += isset($options['event_id']) ? $this->_events[$options['event_id']] : 0;
158 158
                 $sub_total += $event_sub_total;
159 159
                 if (
160 160
                     (
@@ -263,7 +263,7 @@  discard block
 block discarded – undo
263 263
             'FHEE__EE_SPCO_Line_Item_Display_Strategy__item_row__desc',
264 264
             (
265 265
                 $options['show_desc']
266
-                    ? '<span class="line-item-desc-spn smaller-text">: ' . $line_item->desc() . '</span>'
266
+                    ? '<span class="line-item-desc-spn smaller-text">: '.$line_item->desc().'</span>'
267 267
                     : ''
268 268
             ),
269 269
             $line_item,
@@ -299,7 +299,7 @@  discard block
 block discarded – undo
299 299
             $line_item->total(),
300 300
             $line_item
301 301
         );
302
-        $this->_events[ $options['event_id'] ] += $total;
302
+        $this->_events[$options['event_id']] += $total;
303 303
         // total td
304 304
         $html .= EEH_HTML::td(
305 305
             EEH_Template::format_currency($total, false, false),
@@ -326,18 +326,18 @@  discard block
 block discarded – undo
326 326
         // start of row
327 327
         $row_class = $options['odd'] ? 'item odd' : 'item';
328 328
         $html = EEH_HTML::tr('', '', $row_class);
329
-        $obj_name = $line_item->OBJ_type() ? $line_item->OBJ_type_i18n() . ': ' : '';
329
+        $obj_name = $line_item->OBJ_type() ? $line_item->OBJ_type_i18n().': ' : '';
330 330
         // name && desc
331 331
         $name_and_desc = apply_filters(
332 332
             'FHEE__EE_SPCO_Line_Item_Display_Strategy__item_row__name',
333
-            $obj_name . $line_item->name(),
333
+            $obj_name.$line_item->name(),
334 334
             $line_item
335 335
         );
336 336
         $name_and_desc .= apply_filters(
337 337
             'FHEE__EE_SPCO_Line_Item_Display_Strategy__item_row__desc',
338 338
             (
339 339
                 $options['show_desc']
340
-                ? '<span class="line-item-desc-spn smaller-text">: ' . $line_item->desc() . '</span>'
340
+                ? '<span class="line-item-desc-spn smaller-text">: '.$line_item->desc().'</span>'
341 341
                 : ''
342 342
             ),
343 343
             $line_item,
@@ -355,7 +355,7 @@  discard block
 block discarded – undo
355 355
         $html .= EEH_HTML::td($name_and_desc, '', 'item_l');
356 356
         // price td
357 357
         if ($line_item->is_percent()) {
358
-            $html .= EEH_HTML::td($line_item->percent() . '%', '', 'item_c jst-rght');
358
+            $html .= EEH_HTML::td($line_item->percent().'%', '', 'item_c jst-rght');
359 359
         } else {
360 360
             $html .= EEH_HTML::td($line_item->unit_price_no_code(), '', 'item_c jst-rght');
361 361
         }
@@ -363,8 +363,8 @@  discard block
 block discarded – undo
363 363
         $html .= EEH_HTML::td($line_item->quantity(), '', 'item_l jst-rght');
364 364
         // $total = $line_item->total() * $line_item->quantity();
365 365
         $total = $line_item->total();
366
-        if (isset($options['event_id'], $this->_events[ $options['event_id'] ])) {
367
-            $this->_events[ $options['event_id'] ] += $total;
366
+        if (isset($options['event_id'], $this->_events[$options['event_id']])) {
367
+            $this->_events[$options['event_id']] += $total;
368 368
         }
369 369
         // total td
370 370
         $html .= EEH_HTML::td(
@@ -459,8 +459,8 @@  discard block
 block discarded – undo
459 459
         // name && desc
460 460
         $name_and_desc = $line_item->name();
461 461
         $name_and_desc .= '<span class="smaller-text lt-grey-text" style="margin:0 0 0 2em;">'
462
-                          . esc_html__(' * taxable items', 'event_espresso') . '</span>';
463
-        $name_and_desc .= $options['show_desc'] ? '<br/>' . $line_item->desc() : '';
462
+                          . esc_html__(' * taxable items', 'event_espresso').'</span>';
463
+        $name_and_desc .= $options['show_desc'] ? '<br/>'.$line_item->desc() : '';
464 464
         // name td
465 465
         $html .= EEH_HTML::td( /*__FUNCTION__ .*/
466 466
             $name_and_desc,
@@ -468,7 +468,7 @@  discard block
 block discarded – undo
468 468
             'item_l sub-item'
469 469
         );
470 470
         // percent td
471
-        $html .= EEH_HTML::td($line_item->percent() . '%', '', ' jst-rght', '');
471
+        $html .= EEH_HTML::td($line_item->percent().'%', '', ' jst-rght', '');
472 472
         // empty td (price)
473 473
         $html .= EEH_HTML::td(EEH_HTML::nbsp());
474 474
         // total td
@@ -613,7 +613,7 @@  discard block
 block discarded – undo
613 613
                     $registration_payments += $registration->registration_payments();
614 614
                 }
615 615
             }
616
-            if (! empty($registration_payments)) {
616
+            if ( ! empty($registration_payments)) {
617 617
                 foreach ($registration_payments as $registration_payment) {
618 618
                     if ($registration_payment instanceof EE_Registration_Payment) {
619 619
                         $owing -= $registration_payment->amount();
@@ -623,7 +623,7 @@  discard block
 block discarded – undo
623 623
                             $payment_desc = sprintf(
624 624
                                 esc_html__('Payment%1$s Received: %2$s', 'event_espresso'),
625 625
                                 $payment->txn_id_chq_nmbr() !== ''
626
-                                    ? ' <span class="small-text">(#' . $payment->txn_id_chq_nmbr() . ')</span> '
626
+                                    ? ' <span class="small-text">(#'.$payment->txn_id_chq_nmbr().')</span> '
627 627
                                     : '',
628 628
                                 $payment->timestamp()
629 629
                             );
Please login to merge, or discard this patch.
Indentation   +659 added lines, -659 removed lines patch added patch discarded remove patch
@@ -11,663 +11,663 @@
 block discarded – undo
11 11
  */
12 12
 class EE_SPCO_Line_Item_Display_Strategy implements EEI_Line_Item_Display
13 13
 {
14
-    /**
15
-     * array of events
16
-     *
17
-     * @type EE_Line_Item[] $_events
18
-     */
19
-    private $_events = array();
20
-
21
-    /**
22
-     * whether to display the taxes row or not
23
-     *
24
-     * @type bool $_show_taxes
25
-     */
26
-    private $_show_taxes = false;
27
-
28
-    /**
29
-     * html for any tax rows
30
-     *
31
-     * @type string $_show_taxes
32
-     */
33
-    private $_taxes_html = '';
34
-
35
-    /**
36
-     * total amount including tax we can bill for at this time
37
-     *
38
-     * @type float $_grand_total
39
-     */
40
-    private $_grand_total = 0.00;
41
-
42
-    /**
43
-     * total number of items being billed for
44
-     *
45
-     * @type int $_total_items
46
-     */
47
-    private $_total_items = 0;
48
-
49
-
50
-
51
-    /**
52
-     * @return float
53
-     */
54
-    public function grand_total()
55
-    {
56
-        return $this->_grand_total;
57
-    }
58
-
59
-
60
-
61
-    /**
62
-     * @return int
63
-     */
64
-    public function total_items()
65
-    {
66
-        return $this->_total_items;
67
-    }
68
-
69
-
70
-
71
-    /**
72
-     * @param EE_Line_Item $line_item
73
-     * @param array        $options
74
-     * @param EE_Line_Item $parent_line_item
75
-     * @return mixed
76
-     * @throws EE_Error
77
-     */
78
-    public function display_line_item(
79
-        EE_Line_Item $line_item,
80
-        $options = array(),
81
-        EE_Line_Item $parent_line_item = null
82
-    ) {
83
-        $html = '';
84
-        // set some default options and merge with incoming
85
-        $default_options = array(
86
-            'show_desc' => true,  //    true        false
87
-            'odd'       => false,
88
-        );
89
-        $options = array_merge($default_options, (array) $options);
90
-        switch ($line_item->type()) {
91
-            case EEM_Line_Item::type_line_item:
92
-                $this->_show_taxes = $line_item->is_taxable() ? true : $this->_show_taxes;
93
-                if ($line_item->OBJ_type() === 'Ticket') {
94
-                    // item row
95
-                    $html .= $this->_ticket_row($line_item, $options);
96
-                } else {
97
-                    // item row
98
-                    $html .= $this->_item_row($line_item, $options);
99
-                }
100
-                if (
101
-                    apply_filters(
102
-                        'FHEE__EE_SPCO_Line_Item_Display_Strategy__display_line_item__display_sub_line_items',
103
-                        true
104
-                    )
105
-                ) {
106
-                    // got any kids?
107
-                    foreach ($line_item->children() as $child_line_item) {
108
-                        $html .= $this->display_line_item($child_line_item, $options, $line_item);
109
-                    }
110
-                }
111
-                break;
112
-            case EEM_Line_Item::type_sub_line_item:
113
-                $html .= $this->_sub_item_row($line_item, $options, $parent_line_item);
114
-                break;
115
-            case EEM_Line_Item::type_sub_total:
116
-                static $sub_total = 0;
117
-                $event_sub_total = 0;
118
-                $text = esc_html__('Sub-Total', 'event_espresso');
119
-                if ($line_item->OBJ_type() === 'Event') {
120
-                    $options['event_id'] = $event_id = $line_item->OBJ_ID();
121
-                    if (! isset($this->_events[ $options['event_id'] ])) {
122
-                        $event = EEM_Event::instance()->get_one_by_ID($options['event_id']);
123
-                        // if event has default reg status of Not Approved, then don't display info on it
124
-                        if (
125
-                            $event instanceof EE_Event
126
-                            && $event->default_registration_status() === EEM_Registration::status_id_not_approved
127
-                        ) {
128
-                            $display_event = false;
129
-                            // unless there are registrations for it that are returning to pay
130
-                            if (isset($options['registrations']) && is_array($options['registrations'])) {
131
-                                foreach ($options['registrations'] as $registration) {
132
-                                    if (! $registration instanceof EE_Registration) {
133
-                                        continue;
134
-                                    }
135
-                                    $display_event = $registration->event_ID() === $options['event_id']
136
-                                                     && $registration->status_ID() !== EEM_Registration::status_id_not_approved
137
-                                        ? true
138
-                                        : $display_event;
139
-                                }
140
-                            }
141
-                            if (! $display_event) {
142
-                                return '';
143
-                            }
144
-                        }
145
-                        $this->_events[ $options['event_id'] ] = 0;
146
-                        $html .= $this->_event_row($line_item);
147
-                        $text = esc_html__('Event Sub-Total', 'event_espresso');
148
-                    }
149
-                }
150
-                $child_line_items = $line_item->children();
151
-                // loop thru children
152
-                foreach ($child_line_items as $child_line_item) {
153
-                    // recursively feed children back into this method
154
-                    $html .= $this->display_line_item($child_line_item, $options, $line_item);
155
-                }
156
-                $event_sub_total += isset($options['event_id']) ? $this->_events[ $options['event_id'] ] : 0;
157
-                $sub_total += $event_sub_total;
158
-                if (
159
-                    (
160
-                        // event subtotals
161
-                        $line_item->code() !== 'pre-tax-subtotal' && count($child_line_items) > 1
162
-                    )
163
-                    || (
164
-                        // pre-tax subtotals
165
-                        $line_item->code() === 'pre-tax-subtotal' && count($this->_events) > 1
166
-                    )
167
-                ) {
168
-                    $options['sub_total'] = $line_item->OBJ_type() === 'Event' ? $event_sub_total : $sub_total;
169
-                    $html .= $this->_sub_total_row($line_item, $text, $options);
170
-                }
171
-                break;
172
-            case EEM_Line_Item::type_tax:
173
-                if ($this->_show_taxes) {
174
-                    $this->_taxes_html .= $this->_tax_row($line_item, $options);
175
-                }
176
-                break;
177
-            case EEM_Line_Item::type_tax_sub_total:
178
-                if ($this->_show_taxes) {
179
-                    $child_line_items = $line_item->children();
180
-                    // loop thru children
181
-                    foreach ($child_line_items as $child_line_item) {
182
-                        // recursively feed children back into this method
183
-                        $html .= $this->display_line_item($child_line_item, $options, $line_item);
184
-                    }
185
-                    if (count($child_line_items) > 1) {
186
-                        $this->_taxes_html .= $this->_total_tax_row($line_item, esc_html__('Tax Total', 'event_espresso'));
187
-                    }
188
-                }
189
-                break;
190
-            case EEM_Line_Item::type_total:
191
-                // get all child line items
192
-                $children = $line_item->children();
193
-                // loop thru all non-tax child line items
194
-                foreach ($children as $child_line_item) {
195
-                    if ($child_line_item->type() !== EEM_Line_Item::type_tax_sub_total) {
196
-                        // recursively feed children back into this method
197
-                        $html .= $this->display_line_item($child_line_item, $options, $line_item);
198
-                    }
199
-                }
200
-                // now loop thru  tax child line items
201
-                foreach ($children as $child_line_item) {
202
-                    if ($child_line_item->type() === EEM_Line_Item::type_tax_sub_total) {
203
-                        // recursively feed children back into this method
204
-                        $html .= $this->display_line_item($child_line_item, $options, $line_item);
205
-                    }
206
-                }
207
-                $html .= $this->_taxes_html;
208
-                $html .= $this->_total_row($line_item, esc_html__('Total', 'event_espresso'));
209
-                $html .= $this->_payments_and_amount_owing_rows($line_item, $options);
210
-                break;
211
-        }
212
-        return $html;
213
-    }
214
-
215
-
216
-
217
-    /**
218
-     * _event_row - basically a Heading row displayed once above each event's ticket rows
219
-     *
220
-     * @param EE_Line_Item $line_item
221
-     * @return mixed
222
-     */
223
-    private function _event_row(EE_Line_Item $line_item)
224
-    {
225
-        // start of row
226
-        $html = EEH_HTML::tr('', 'event-cart-total-row', 'total_tr odd');
227
-        // event name td
228
-        $html .= EEH_HTML::td(
229
-            EEH_HTML::strong($line_item->name()),
230
-            '',
231
-            'event-header',
232
-            '',
233
-            ' colspan="4"'
234
-        );
235
-        // end of row
236
-        $html .= EEH_HTML::trx();
237
-        return $html;
238
-    }
239
-
240
-
241
-
242
-    /**
243
-     * _ticket_row
244
-     *
245
-     * @param EE_Line_Item $line_item
246
-     * @param array        $options
247
-     * @return mixed
248
-     * @throws EE_Error
249
-     */
250
-    private function _ticket_row(EE_Line_Item $line_item, $options = array())
251
-    {
252
-        // start of row
253
-        $row_class = $options['odd'] ? 'item odd' : 'item';
254
-        $html = EEH_HTML::tr('', '', $row_class);
255
-        // name && desc
256
-        $name_and_desc = apply_filters(
257
-            'FHEE__EE_SPCO_Line_Item_Display_Strategy__item_row__name',
258
-            $line_item->name(),
259
-            $line_item
260
-        );
261
-        $name_and_desc .= apply_filters(
262
-            'FHEE__EE_SPCO_Line_Item_Display_Strategy__item_row__desc',
263
-            (
264
-                $options['show_desc']
265
-                    ? '<span class="line-item-desc-spn smaller-text">: ' . $line_item->desc() . '</span>'
266
-                    : ''
267
-            ),
268
-            $line_item,
269
-            $options
270
-        );
271
-        $name_and_desc .= $line_item->is_taxable() ? ' * ' : '';
272
-        $name_and_desc = apply_filters(
273
-            'FHEE__EE_SPCO_Line_Item_Display_Strategy___ticket_row__name_and_desc',
274
-            $name_and_desc,
275
-            $line_item,
276
-            $options
277
-        );
278
-
279
-        // name td
280
-        $html .= EEH_HTML::td( /*__FUNCTION__ .*/
281
-            $name_and_desc,
282
-            '',
283
-            'item_l'
284
-        );
285
-        // price td
286
-        $price = apply_filters(
287
-            'FHEE__EE_SPCO_Line_Item_Display_Strategy___ticket_row__price',
288
-            $line_item->unit_price_no_code(),
289
-            $line_item
290
-        );
291
-        $html .= EEH_HTML::td($price, '', 'item_c jst-rght');
292
-        // quantity td
293
-        $html .= EEH_HTML::td($line_item->quantity(), '', 'item_l jst-rght');
294
-        $this->_total_items += $line_item->quantity();
295
-        // determine total for line item
296
-        $total = apply_filters(
297
-            'FHEE__EE_SPCO_Line_Item_Display_Strategy___ticket_row__total',
298
-            $line_item->total(),
299
-            $line_item
300
-        );
301
-        $this->_events[ $options['event_id'] ] += $total;
302
-        // total td
303
-        $html .= EEH_HTML::td(
304
-            EEH_Template::format_currency($total, false, false),
305
-            '',
306
-            'item_r jst-rght'
307
-        );
308
-        // end of row
309
-        $html .= EEH_HTML::trx();
310
-        return $html;
311
-    }
312
-
313
-
314
-
315
-    /**
316
-     * _item_row
317
-     *
318
-     * @param EE_Line_Item $line_item
319
-     * @param array        $options
320
-     * @return mixed
321
-     * @throws EE_Error
322
-     */
323
-    private function _item_row(EE_Line_Item $line_item, $options = array())
324
-    {
325
-        // start of row
326
-        $row_class = $options['odd'] ? 'item odd' : 'item';
327
-        $html = EEH_HTML::tr('', '', $row_class);
328
-        $obj_name = $line_item->OBJ_type() ? $line_item->OBJ_type_i18n() . ': ' : '';
329
-        // name && desc
330
-        $name_and_desc = apply_filters(
331
-            'FHEE__EE_SPCO_Line_Item_Display_Strategy__item_row__name',
332
-            $obj_name . $line_item->name(),
333
-            $line_item
334
-        );
335
-        $name_and_desc .= apply_filters(
336
-            'FHEE__EE_SPCO_Line_Item_Display_Strategy__item_row__desc',
337
-            (
338
-                $options['show_desc']
339
-                ? '<span class="line-item-desc-spn smaller-text">: ' . $line_item->desc() . '</span>'
340
-                : ''
341
-            ),
342
-            $line_item,
343
-            $options
344
-        );
345
-        $name_and_desc .= $line_item->is_taxable() ? ' * ' : '';
346
-        $name_and_desc = apply_filters(
347
-            'FHEE__EE_SPCO_Line_Item_Display_Strategy___item_row__name_and_desc',
348
-            $name_and_desc,
349
-            $line_item,
350
-            $options
351
-        );
352
-
353
-        // name td
354
-        $html .= EEH_HTML::td($name_and_desc, '', 'item_l');
355
-        // price td
356
-        if ($line_item->is_percent()) {
357
-            $html .= EEH_HTML::td($line_item->percent() . '%', '', 'item_c jst-rght');
358
-        } else {
359
-            $html .= EEH_HTML::td($line_item->unit_price_no_code(), '', 'item_c jst-rght');
360
-        }
361
-        // quantity td
362
-        $html .= EEH_HTML::td($line_item->quantity(), '', 'item_l jst-rght');
363
-        // $total = $line_item->total() * $line_item->quantity();
364
-        $total = $line_item->total();
365
-        if (isset($options['event_id'], $this->_events[ $options['event_id'] ])) {
366
-            $this->_events[ $options['event_id'] ] += $total;
367
-        }
368
-        // total td
369
-        $html .= EEH_HTML::td(
370
-            EEH_Template::format_currency($total, false, false),
371
-            '',
372
-            'item_r jst-rght'
373
-        );
374
-        // end of row
375
-        $html .= EEH_HTML::trx();
376
-        return $html;
377
-    }
378
-
379
-
380
-
381
-    /**
382
-     * _sub_item_row
383
-     *
384
-     * @param EE_Line_Item $line_item
385
-     * @param array        $options
386
-     * @param EE_Line_Item $parent_line_item
387
-     * @return mixed
388
-     * @throws EE_Error
389
-     */
390
-    private function _sub_item_row(EE_Line_Item $line_item, $options = array(), EE_Line_Item $parent_line_item = null)
391
-    {
392
-        if (
393
-            $parent_line_item instanceof  EE_Line_Item
394
-            && $line_item->children() === array()
395
-            && $line_item->name() === $parent_line_item->name()
396
-            && apply_filters(
397
-                'FHEE__EE_SPCO_Line_Item_Display_Strategy___sub_item_row__hide_main_sub_line_item',
398
-                true
399
-            )
400
-        ) {
401
-            return '';
402
-        }
403
-        // start of row
404
-        $html = EEH_HTML::tr('', '', 'item sub-item-row');
405
-        // name && desc
406
-        $name_and_desc = EEH_HTML::span('', '', 'sub-item-row-bullet dashicons dashicons-arrow-right')
407
-                         . $line_item->name();
408
-        $name_and_desc .= $options['show_desc'] ? '<span class="line-sub-item-desc-spn smaller-text">: '
409
-                                                  . $line_item->desc()
410
-                                                  . '</span>' : '';
411
-        // name td
412
-        $html .= EEH_HTML::td($name_and_desc, '', 'item_l sub-item');
413
-        $qty = $parent_line_item instanceof EE_Line_Item ? $parent_line_item->quantity() : 1;
414
-        // discount/surcharge td
415
-        if ($line_item->is_percent()) {
416
-            $html .= EEH_HTML::td(
417
-                EEH_Template::format_currency(
418
-                    $line_item->total() / $qty,
419
-                    false,
420
-                    false
421
-                ),
422
-                '',
423
-                'item_c jst-rght'
424
-            );
425
-        } else {
426
-            $html .= EEH_HTML::td($line_item->unit_price_no_code(), '', 'item_c jst-rght');
427
-        }
428
-        // no quantity td
429
-        $html .= EEH_HTML::td();
430
-        // no total td
431
-        $html .= EEH_HTML::td();
432
-        // end of row
433
-        $html .= EEH_HTML::trx();
434
-        $html = apply_filters(
435
-            'FHEE__EE_SPCO_Line_Item_Display_Strategy___sub_item_row__html',
436
-            $html,
437
-            $line_item,
438
-            $options,
439
-            $parent_line_item
440
-        );
441
-        return $html;
442
-    }
443
-
444
-
445
-
446
-    /**
447
-     * _tax_row
448
-     *
449
-     * @param EE_Line_Item $line_item
450
-     * @param array        $options
451
-     * @return mixed
452
-     * @throws EE_Error
453
-     */
454
-    private function _tax_row(EE_Line_Item $line_item, $options = array())
455
-    {
456
-        // start of row
457
-        $html = EEH_HTML::tr('', 'item sub-item tax-total');
458
-        // name && desc
459
-        $name_and_desc = $line_item->name();
460
-        $name_and_desc .= '<span class="smaller-text lt-grey-text" style="margin:0 0 0 2em;">'
461
-                          . esc_html__(' * taxable items', 'event_espresso') . '</span>';
462
-        $name_and_desc .= $options['show_desc'] ? '<br/>' . $line_item->desc() : '';
463
-        // name td
464
-        $html .= EEH_HTML::td( /*__FUNCTION__ .*/
465
-            $name_and_desc,
466
-            '',
467
-            'item_l sub-item'
468
-        );
469
-        // percent td
470
-        $html .= EEH_HTML::td($line_item->percent() . '%', '', ' jst-rght', '');
471
-        // empty td (price)
472
-        $html .= EEH_HTML::td(EEH_HTML::nbsp());
473
-        // total td
474
-        $html .= EEH_HTML::td(
475
-            EEH_Template::format_currency(
476
-                $line_item->total(),
477
-                false,
478
-                false
479
-            ),
480
-            '',
481
-            'item_r jst-rght'
482
-        );
483
-        // end of row
484
-        $html .= EEH_HTML::trx();
485
-        return $html;
486
-    }
487
-
488
-
489
-
490
-    /**
491
-     * _total_row
492
-     *
493
-     * @param EE_Line_Item $line_item
494
-     * @param string       $text
495
-     * @return mixed
496
-     * @throws EE_Error
497
-     */
498
-    private function _total_tax_row(EE_Line_Item $line_item, $text = '')
499
-    {
500
-        $html = '';
501
-        if ($line_item->total()) {
502
-            // start of row
503
-            $html = EEH_HTML::tr('', '', 'total_tr odd');
504
-            // total td
505
-            $html .= EEH_HTML::td(
506
-                $text,
507
-                '',
508
-                'total_currency total jst-rght',
509
-                '',
510
-                ' colspan="2"'
511
-            );
512
-            // empty td (price)
513
-            $html .= EEH_HTML::td(EEH_HTML::nbsp());
514
-            // total td
515
-            $html .= EEH_HTML::td(
516
-                EEH_Template::format_currency($line_item->total(), false, false),
517
-                '',
518
-                'total jst-rght'
519
-            );
520
-            // end of row
521
-            $html .= EEH_HTML::trx();
522
-        }
523
-        return $html;
524
-    }
525
-
526
-
527
-
528
-    /**
529
-     * _total_row
530
-     *
531
-     * @param EE_Line_Item $line_item
532
-     * @param string       $text
533
-     * @param array        $options
534
-     * @return mixed
535
-     * @throws EE_Error
536
-     */
537
-    private function _sub_total_row(EE_Line_Item $line_item, $text = '', $options = array())
538
-    {
539
-        $html = '';
540
-        if ($line_item->total()) {
541
-            // start of row
542
-            $html = EEH_HTML::tr('', '', 'total_tr odd');
543
-            // total td
544
-            $html .= EEH_HTML::td(
545
-                $text,
546
-                '',
547
-                'total_currency total jst-rght',
548
-                '',
549
-                ' colspan="3"'
550
-            );
551
-            // total td
552
-            $html .= EEH_HTML::td(
553
-                EEH_Template::format_currency($options['sub_total'], false, false),
554
-                '',
555
-                'total jst-rght'
556
-            );
557
-            // end of row
558
-            $html .= EEH_HTML::trx();
559
-        }
560
-        return $html;
561
-    }
562
-
563
-
564
-
565
-    /**
566
-     * _total_row
567
-     *
568
-     * @param EE_Line_Item $line_item
569
-     * @param string       $text
570
-     * @return mixed
571
-     * @throws EE_Error
572
-     */
573
-    private function _total_row(EE_Line_Item $line_item, $text = '')
574
-    {
575
-        // start of row
576
-        $html = EEH_HTML::tr('', '', 'spco-grand-total total_tr odd');
577
-        // total td
578
-        $html .= EEH_HTML::td($text, '', 'total_currency total jst-rght', '', ' colspan="3"');
579
-        // total td
580
-        $html .= EEH_HTML::td(
581
-            EEH_Template::format_currency($line_item->total(), false, false),
582
-            '',
583
-            'total jst-rght'
584
-        );
585
-        // end of row
586
-        $html .= EEH_HTML::trx();
587
-        return $html;
588
-    }
589
-
590
-
591
-
592
-    /**
593
-     * _payments_and_amount_owing_rows
594
-     *
595
-     * @param EE_Line_Item $line_item
596
-     * @param array        $options
597
-     * @return mixed
598
-     * @throws EE_Error
599
-     */
600
-    private function _payments_and_amount_owing_rows(EE_Line_Item $line_item, $options = array())
601
-    {
602
-        $html = '';
603
-        $owing = $line_item->total();
604
-        $transaction = EEM_Transaction::instance()->get_one_by_ID($line_item->TXN_ID());
605
-        if ($transaction instanceof EE_Transaction) {
606
-            $registration_payments = array();
607
-            $registrations = ! empty($options['registrations'])
608
-                ? $options['registrations']
609
-                : $transaction->registrations();
610
-            foreach ($registrations as $registration) {
611
-                if ($registration instanceof EE_Registration && $registration->owes_monies_and_can_pay()) {
612
-                    $registration_payments += $registration->registration_payments();
613
-                }
614
-            }
615
-            if (! empty($registration_payments)) {
616
-                foreach ($registration_payments as $registration_payment) {
617
-                    if ($registration_payment instanceof EE_Registration_Payment) {
618
-                        $owing -= $registration_payment->amount();
619
-                        $payment = $registration_payment->payment();
620
-                        $payment_desc = '';
621
-                        if ($payment instanceof EE_Payment) {
622
-                            $payment_desc = sprintf(
623
-                                esc_html__('Payment%1$s Received: %2$s', 'event_espresso'),
624
-                                $payment->txn_id_chq_nmbr() !== ''
625
-                                    ? ' <span class="small-text">(#' . $payment->txn_id_chq_nmbr() . ')</span> '
626
-                                    : '',
627
-                                $payment->timestamp()
628
-                            );
629
-                        }
630
-                        // start of row
631
-                        $html .= EEH_HTML::tr('', '', 'total_tr odd');
632
-                        // payment desc
633
-                        $html .= EEH_HTML::td($payment_desc, '', '', '', ' colspan="3"');
634
-                        // total td
635
-                        $html .= EEH_HTML::td(
636
-                            EEH_Template::format_currency(
637
-                                $registration_payment->amount(),
638
-                                false,
639
-                                false
640
-                            ),
641
-                            '',
642
-                            'total jst-rght'
643
-                        );
644
-                        // end of row
645
-                        $html .= EEH_HTML::trx();
646
-                    }
647
-                }
648
-                if ($line_item->total()) {
649
-                    // start of row
650
-                    $html .= EEH_HTML::tr('', '', 'total_tr odd');
651
-                    // total td
652
-                    $html .= EEH_HTML::td(
653
-                        esc_html__('Amount Owing', 'event_espresso'),
654
-                        '',
655
-                        'total_currency total jst-rght',
656
-                        '',
657
-                        ' colspan="3"'
658
-                    );
659
-                    // total td
660
-                    $html .= EEH_HTML::td(
661
-                        EEH_Template::format_currency($owing, false, false),
662
-                        '',
663
-                        'total jst-rght'
664
-                    );
665
-                    // end of row
666
-                    $html .= EEH_HTML::trx();
667
-                }
668
-            }
669
-        }
670
-        $this->_grand_total = $owing;
671
-        return $html;
672
-    }
14
+	/**
15
+	 * array of events
16
+	 *
17
+	 * @type EE_Line_Item[] $_events
18
+	 */
19
+	private $_events = array();
20
+
21
+	/**
22
+	 * whether to display the taxes row or not
23
+	 *
24
+	 * @type bool $_show_taxes
25
+	 */
26
+	private $_show_taxes = false;
27
+
28
+	/**
29
+	 * html for any tax rows
30
+	 *
31
+	 * @type string $_show_taxes
32
+	 */
33
+	private $_taxes_html = '';
34
+
35
+	/**
36
+	 * total amount including tax we can bill for at this time
37
+	 *
38
+	 * @type float $_grand_total
39
+	 */
40
+	private $_grand_total = 0.00;
41
+
42
+	/**
43
+	 * total number of items being billed for
44
+	 *
45
+	 * @type int $_total_items
46
+	 */
47
+	private $_total_items = 0;
48
+
49
+
50
+
51
+	/**
52
+	 * @return float
53
+	 */
54
+	public function grand_total()
55
+	{
56
+		return $this->_grand_total;
57
+	}
58
+
59
+
60
+
61
+	/**
62
+	 * @return int
63
+	 */
64
+	public function total_items()
65
+	{
66
+		return $this->_total_items;
67
+	}
68
+
69
+
70
+
71
+	/**
72
+	 * @param EE_Line_Item $line_item
73
+	 * @param array        $options
74
+	 * @param EE_Line_Item $parent_line_item
75
+	 * @return mixed
76
+	 * @throws EE_Error
77
+	 */
78
+	public function display_line_item(
79
+		EE_Line_Item $line_item,
80
+		$options = array(),
81
+		EE_Line_Item $parent_line_item = null
82
+	) {
83
+		$html = '';
84
+		// set some default options and merge with incoming
85
+		$default_options = array(
86
+			'show_desc' => true,  //    true        false
87
+			'odd'       => false,
88
+		);
89
+		$options = array_merge($default_options, (array) $options);
90
+		switch ($line_item->type()) {
91
+			case EEM_Line_Item::type_line_item:
92
+				$this->_show_taxes = $line_item->is_taxable() ? true : $this->_show_taxes;
93
+				if ($line_item->OBJ_type() === 'Ticket') {
94
+					// item row
95
+					$html .= $this->_ticket_row($line_item, $options);
96
+				} else {
97
+					// item row
98
+					$html .= $this->_item_row($line_item, $options);
99
+				}
100
+				if (
101
+					apply_filters(
102
+						'FHEE__EE_SPCO_Line_Item_Display_Strategy__display_line_item__display_sub_line_items',
103
+						true
104
+					)
105
+				) {
106
+					// got any kids?
107
+					foreach ($line_item->children() as $child_line_item) {
108
+						$html .= $this->display_line_item($child_line_item, $options, $line_item);
109
+					}
110
+				}
111
+				break;
112
+			case EEM_Line_Item::type_sub_line_item:
113
+				$html .= $this->_sub_item_row($line_item, $options, $parent_line_item);
114
+				break;
115
+			case EEM_Line_Item::type_sub_total:
116
+				static $sub_total = 0;
117
+				$event_sub_total = 0;
118
+				$text = esc_html__('Sub-Total', 'event_espresso');
119
+				if ($line_item->OBJ_type() === 'Event') {
120
+					$options['event_id'] = $event_id = $line_item->OBJ_ID();
121
+					if (! isset($this->_events[ $options['event_id'] ])) {
122
+						$event = EEM_Event::instance()->get_one_by_ID($options['event_id']);
123
+						// if event has default reg status of Not Approved, then don't display info on it
124
+						if (
125
+							$event instanceof EE_Event
126
+							&& $event->default_registration_status() === EEM_Registration::status_id_not_approved
127
+						) {
128
+							$display_event = false;
129
+							// unless there are registrations for it that are returning to pay
130
+							if (isset($options['registrations']) && is_array($options['registrations'])) {
131
+								foreach ($options['registrations'] as $registration) {
132
+									if (! $registration instanceof EE_Registration) {
133
+										continue;
134
+									}
135
+									$display_event = $registration->event_ID() === $options['event_id']
136
+													 && $registration->status_ID() !== EEM_Registration::status_id_not_approved
137
+										? true
138
+										: $display_event;
139
+								}
140
+							}
141
+							if (! $display_event) {
142
+								return '';
143
+							}
144
+						}
145
+						$this->_events[ $options['event_id'] ] = 0;
146
+						$html .= $this->_event_row($line_item);
147
+						$text = esc_html__('Event Sub-Total', 'event_espresso');
148
+					}
149
+				}
150
+				$child_line_items = $line_item->children();
151
+				// loop thru children
152
+				foreach ($child_line_items as $child_line_item) {
153
+					// recursively feed children back into this method
154
+					$html .= $this->display_line_item($child_line_item, $options, $line_item);
155
+				}
156
+				$event_sub_total += isset($options['event_id']) ? $this->_events[ $options['event_id'] ] : 0;
157
+				$sub_total += $event_sub_total;
158
+				if (
159
+					(
160
+						// event subtotals
161
+						$line_item->code() !== 'pre-tax-subtotal' && count($child_line_items) > 1
162
+					)
163
+					|| (
164
+						// pre-tax subtotals
165
+						$line_item->code() === 'pre-tax-subtotal' && count($this->_events) > 1
166
+					)
167
+				) {
168
+					$options['sub_total'] = $line_item->OBJ_type() === 'Event' ? $event_sub_total : $sub_total;
169
+					$html .= $this->_sub_total_row($line_item, $text, $options);
170
+				}
171
+				break;
172
+			case EEM_Line_Item::type_tax:
173
+				if ($this->_show_taxes) {
174
+					$this->_taxes_html .= $this->_tax_row($line_item, $options);
175
+				}
176
+				break;
177
+			case EEM_Line_Item::type_tax_sub_total:
178
+				if ($this->_show_taxes) {
179
+					$child_line_items = $line_item->children();
180
+					// loop thru children
181
+					foreach ($child_line_items as $child_line_item) {
182
+						// recursively feed children back into this method
183
+						$html .= $this->display_line_item($child_line_item, $options, $line_item);
184
+					}
185
+					if (count($child_line_items) > 1) {
186
+						$this->_taxes_html .= $this->_total_tax_row($line_item, esc_html__('Tax Total', 'event_espresso'));
187
+					}
188
+				}
189
+				break;
190
+			case EEM_Line_Item::type_total:
191
+				// get all child line items
192
+				$children = $line_item->children();
193
+				// loop thru all non-tax child line items
194
+				foreach ($children as $child_line_item) {
195
+					if ($child_line_item->type() !== EEM_Line_Item::type_tax_sub_total) {
196
+						// recursively feed children back into this method
197
+						$html .= $this->display_line_item($child_line_item, $options, $line_item);
198
+					}
199
+				}
200
+				// now loop thru  tax child line items
201
+				foreach ($children as $child_line_item) {
202
+					if ($child_line_item->type() === EEM_Line_Item::type_tax_sub_total) {
203
+						// recursively feed children back into this method
204
+						$html .= $this->display_line_item($child_line_item, $options, $line_item);
205
+					}
206
+				}
207
+				$html .= $this->_taxes_html;
208
+				$html .= $this->_total_row($line_item, esc_html__('Total', 'event_espresso'));
209
+				$html .= $this->_payments_and_amount_owing_rows($line_item, $options);
210
+				break;
211
+		}
212
+		return $html;
213
+	}
214
+
215
+
216
+
217
+	/**
218
+	 * _event_row - basically a Heading row displayed once above each event's ticket rows
219
+	 *
220
+	 * @param EE_Line_Item $line_item
221
+	 * @return mixed
222
+	 */
223
+	private function _event_row(EE_Line_Item $line_item)
224
+	{
225
+		// start of row
226
+		$html = EEH_HTML::tr('', 'event-cart-total-row', 'total_tr odd');
227
+		// event name td
228
+		$html .= EEH_HTML::td(
229
+			EEH_HTML::strong($line_item->name()),
230
+			'',
231
+			'event-header',
232
+			'',
233
+			' colspan="4"'
234
+		);
235
+		// end of row
236
+		$html .= EEH_HTML::trx();
237
+		return $html;
238
+	}
239
+
240
+
241
+
242
+	/**
243
+	 * _ticket_row
244
+	 *
245
+	 * @param EE_Line_Item $line_item
246
+	 * @param array        $options
247
+	 * @return mixed
248
+	 * @throws EE_Error
249
+	 */
250
+	private function _ticket_row(EE_Line_Item $line_item, $options = array())
251
+	{
252
+		// start of row
253
+		$row_class = $options['odd'] ? 'item odd' : 'item';
254
+		$html = EEH_HTML::tr('', '', $row_class);
255
+		// name && desc
256
+		$name_and_desc = apply_filters(
257
+			'FHEE__EE_SPCO_Line_Item_Display_Strategy__item_row__name',
258
+			$line_item->name(),
259
+			$line_item
260
+		);
261
+		$name_and_desc .= apply_filters(
262
+			'FHEE__EE_SPCO_Line_Item_Display_Strategy__item_row__desc',
263
+			(
264
+				$options['show_desc']
265
+					? '<span class="line-item-desc-spn smaller-text">: ' . $line_item->desc() . '</span>'
266
+					: ''
267
+			),
268
+			$line_item,
269
+			$options
270
+		);
271
+		$name_and_desc .= $line_item->is_taxable() ? ' * ' : '';
272
+		$name_and_desc = apply_filters(
273
+			'FHEE__EE_SPCO_Line_Item_Display_Strategy___ticket_row__name_and_desc',
274
+			$name_and_desc,
275
+			$line_item,
276
+			$options
277
+		);
278
+
279
+		// name td
280
+		$html .= EEH_HTML::td( /*__FUNCTION__ .*/
281
+			$name_and_desc,
282
+			'',
283
+			'item_l'
284
+		);
285
+		// price td
286
+		$price = apply_filters(
287
+			'FHEE__EE_SPCO_Line_Item_Display_Strategy___ticket_row__price',
288
+			$line_item->unit_price_no_code(),
289
+			$line_item
290
+		);
291
+		$html .= EEH_HTML::td($price, '', 'item_c jst-rght');
292
+		// quantity td
293
+		$html .= EEH_HTML::td($line_item->quantity(), '', 'item_l jst-rght');
294
+		$this->_total_items += $line_item->quantity();
295
+		// determine total for line item
296
+		$total = apply_filters(
297
+			'FHEE__EE_SPCO_Line_Item_Display_Strategy___ticket_row__total',
298
+			$line_item->total(),
299
+			$line_item
300
+		);
301
+		$this->_events[ $options['event_id'] ] += $total;
302
+		// total td
303
+		$html .= EEH_HTML::td(
304
+			EEH_Template::format_currency($total, false, false),
305
+			'',
306
+			'item_r jst-rght'
307
+		);
308
+		// end of row
309
+		$html .= EEH_HTML::trx();
310
+		return $html;
311
+	}
312
+
313
+
314
+
315
+	/**
316
+	 * _item_row
317
+	 *
318
+	 * @param EE_Line_Item $line_item
319
+	 * @param array        $options
320
+	 * @return mixed
321
+	 * @throws EE_Error
322
+	 */
323
+	private function _item_row(EE_Line_Item $line_item, $options = array())
324
+	{
325
+		// start of row
326
+		$row_class = $options['odd'] ? 'item odd' : 'item';
327
+		$html = EEH_HTML::tr('', '', $row_class);
328
+		$obj_name = $line_item->OBJ_type() ? $line_item->OBJ_type_i18n() . ': ' : '';
329
+		// name && desc
330
+		$name_and_desc = apply_filters(
331
+			'FHEE__EE_SPCO_Line_Item_Display_Strategy__item_row__name',
332
+			$obj_name . $line_item->name(),
333
+			$line_item
334
+		);
335
+		$name_and_desc .= apply_filters(
336
+			'FHEE__EE_SPCO_Line_Item_Display_Strategy__item_row__desc',
337
+			(
338
+				$options['show_desc']
339
+				? '<span class="line-item-desc-spn smaller-text">: ' . $line_item->desc() . '</span>'
340
+				: ''
341
+			),
342
+			$line_item,
343
+			$options
344
+		);
345
+		$name_and_desc .= $line_item->is_taxable() ? ' * ' : '';
346
+		$name_and_desc = apply_filters(
347
+			'FHEE__EE_SPCO_Line_Item_Display_Strategy___item_row__name_and_desc',
348
+			$name_and_desc,
349
+			$line_item,
350
+			$options
351
+		);
352
+
353
+		// name td
354
+		$html .= EEH_HTML::td($name_and_desc, '', 'item_l');
355
+		// price td
356
+		if ($line_item->is_percent()) {
357
+			$html .= EEH_HTML::td($line_item->percent() . '%', '', 'item_c jst-rght');
358
+		} else {
359
+			$html .= EEH_HTML::td($line_item->unit_price_no_code(), '', 'item_c jst-rght');
360
+		}
361
+		// quantity td
362
+		$html .= EEH_HTML::td($line_item->quantity(), '', 'item_l jst-rght');
363
+		// $total = $line_item->total() * $line_item->quantity();
364
+		$total = $line_item->total();
365
+		if (isset($options['event_id'], $this->_events[ $options['event_id'] ])) {
366
+			$this->_events[ $options['event_id'] ] += $total;
367
+		}
368
+		// total td
369
+		$html .= EEH_HTML::td(
370
+			EEH_Template::format_currency($total, false, false),
371
+			'',
372
+			'item_r jst-rght'
373
+		);
374
+		// end of row
375
+		$html .= EEH_HTML::trx();
376
+		return $html;
377
+	}
378
+
379
+
380
+
381
+	/**
382
+	 * _sub_item_row
383
+	 *
384
+	 * @param EE_Line_Item $line_item
385
+	 * @param array        $options
386
+	 * @param EE_Line_Item $parent_line_item
387
+	 * @return mixed
388
+	 * @throws EE_Error
389
+	 */
390
+	private function _sub_item_row(EE_Line_Item $line_item, $options = array(), EE_Line_Item $parent_line_item = null)
391
+	{
392
+		if (
393
+			$parent_line_item instanceof  EE_Line_Item
394
+			&& $line_item->children() === array()
395
+			&& $line_item->name() === $parent_line_item->name()
396
+			&& apply_filters(
397
+				'FHEE__EE_SPCO_Line_Item_Display_Strategy___sub_item_row__hide_main_sub_line_item',
398
+				true
399
+			)
400
+		) {
401
+			return '';
402
+		}
403
+		// start of row
404
+		$html = EEH_HTML::tr('', '', 'item sub-item-row');
405
+		// name && desc
406
+		$name_and_desc = EEH_HTML::span('', '', 'sub-item-row-bullet dashicons dashicons-arrow-right')
407
+						 . $line_item->name();
408
+		$name_and_desc .= $options['show_desc'] ? '<span class="line-sub-item-desc-spn smaller-text">: '
409
+												  . $line_item->desc()
410
+												  . '</span>' : '';
411
+		// name td
412
+		$html .= EEH_HTML::td($name_and_desc, '', 'item_l sub-item');
413
+		$qty = $parent_line_item instanceof EE_Line_Item ? $parent_line_item->quantity() : 1;
414
+		// discount/surcharge td
415
+		if ($line_item->is_percent()) {
416
+			$html .= EEH_HTML::td(
417
+				EEH_Template::format_currency(
418
+					$line_item->total() / $qty,
419
+					false,
420
+					false
421
+				),
422
+				'',
423
+				'item_c jst-rght'
424
+			);
425
+		} else {
426
+			$html .= EEH_HTML::td($line_item->unit_price_no_code(), '', 'item_c jst-rght');
427
+		}
428
+		// no quantity td
429
+		$html .= EEH_HTML::td();
430
+		// no total td
431
+		$html .= EEH_HTML::td();
432
+		// end of row
433
+		$html .= EEH_HTML::trx();
434
+		$html = apply_filters(
435
+			'FHEE__EE_SPCO_Line_Item_Display_Strategy___sub_item_row__html',
436
+			$html,
437
+			$line_item,
438
+			$options,
439
+			$parent_line_item
440
+		);
441
+		return $html;
442
+	}
443
+
444
+
445
+
446
+	/**
447
+	 * _tax_row
448
+	 *
449
+	 * @param EE_Line_Item $line_item
450
+	 * @param array        $options
451
+	 * @return mixed
452
+	 * @throws EE_Error
453
+	 */
454
+	private function _tax_row(EE_Line_Item $line_item, $options = array())
455
+	{
456
+		// start of row
457
+		$html = EEH_HTML::tr('', 'item sub-item tax-total');
458
+		// name && desc
459
+		$name_and_desc = $line_item->name();
460
+		$name_and_desc .= '<span class="smaller-text lt-grey-text" style="margin:0 0 0 2em;">'
461
+						  . esc_html__(' * taxable items', 'event_espresso') . '</span>';
462
+		$name_and_desc .= $options['show_desc'] ? '<br/>' . $line_item->desc() : '';
463
+		// name td
464
+		$html .= EEH_HTML::td( /*__FUNCTION__ .*/
465
+			$name_and_desc,
466
+			'',
467
+			'item_l sub-item'
468
+		);
469
+		// percent td
470
+		$html .= EEH_HTML::td($line_item->percent() . '%', '', ' jst-rght', '');
471
+		// empty td (price)
472
+		$html .= EEH_HTML::td(EEH_HTML::nbsp());
473
+		// total td
474
+		$html .= EEH_HTML::td(
475
+			EEH_Template::format_currency(
476
+				$line_item->total(),
477
+				false,
478
+				false
479
+			),
480
+			'',
481
+			'item_r jst-rght'
482
+		);
483
+		// end of row
484
+		$html .= EEH_HTML::trx();
485
+		return $html;
486
+	}
487
+
488
+
489
+
490
+	/**
491
+	 * _total_row
492
+	 *
493
+	 * @param EE_Line_Item $line_item
494
+	 * @param string       $text
495
+	 * @return mixed
496
+	 * @throws EE_Error
497
+	 */
498
+	private function _total_tax_row(EE_Line_Item $line_item, $text = '')
499
+	{
500
+		$html = '';
501
+		if ($line_item->total()) {
502
+			// start of row
503
+			$html = EEH_HTML::tr('', '', 'total_tr odd');
504
+			// total td
505
+			$html .= EEH_HTML::td(
506
+				$text,
507
+				'',
508
+				'total_currency total jst-rght',
509
+				'',
510
+				' colspan="2"'
511
+			);
512
+			// empty td (price)
513
+			$html .= EEH_HTML::td(EEH_HTML::nbsp());
514
+			// total td
515
+			$html .= EEH_HTML::td(
516
+				EEH_Template::format_currency($line_item->total(), false, false),
517
+				'',
518
+				'total jst-rght'
519
+			);
520
+			// end of row
521
+			$html .= EEH_HTML::trx();
522
+		}
523
+		return $html;
524
+	}
525
+
526
+
527
+
528
+	/**
529
+	 * _total_row
530
+	 *
531
+	 * @param EE_Line_Item $line_item
532
+	 * @param string       $text
533
+	 * @param array        $options
534
+	 * @return mixed
535
+	 * @throws EE_Error
536
+	 */
537
+	private function _sub_total_row(EE_Line_Item $line_item, $text = '', $options = array())
538
+	{
539
+		$html = '';
540
+		if ($line_item->total()) {
541
+			// start of row
542
+			$html = EEH_HTML::tr('', '', 'total_tr odd');
543
+			// total td
544
+			$html .= EEH_HTML::td(
545
+				$text,
546
+				'',
547
+				'total_currency total jst-rght',
548
+				'',
549
+				' colspan="3"'
550
+			);
551
+			// total td
552
+			$html .= EEH_HTML::td(
553
+				EEH_Template::format_currency($options['sub_total'], false, false),
554
+				'',
555
+				'total jst-rght'
556
+			);
557
+			// end of row
558
+			$html .= EEH_HTML::trx();
559
+		}
560
+		return $html;
561
+	}
562
+
563
+
564
+
565
+	/**
566
+	 * _total_row
567
+	 *
568
+	 * @param EE_Line_Item $line_item
569
+	 * @param string       $text
570
+	 * @return mixed
571
+	 * @throws EE_Error
572
+	 */
573
+	private function _total_row(EE_Line_Item $line_item, $text = '')
574
+	{
575
+		// start of row
576
+		$html = EEH_HTML::tr('', '', 'spco-grand-total total_tr odd');
577
+		// total td
578
+		$html .= EEH_HTML::td($text, '', 'total_currency total jst-rght', '', ' colspan="3"');
579
+		// total td
580
+		$html .= EEH_HTML::td(
581
+			EEH_Template::format_currency($line_item->total(), false, false),
582
+			'',
583
+			'total jst-rght'
584
+		);
585
+		// end of row
586
+		$html .= EEH_HTML::trx();
587
+		return $html;
588
+	}
589
+
590
+
591
+
592
+	/**
593
+	 * _payments_and_amount_owing_rows
594
+	 *
595
+	 * @param EE_Line_Item $line_item
596
+	 * @param array        $options
597
+	 * @return mixed
598
+	 * @throws EE_Error
599
+	 */
600
+	private function _payments_and_amount_owing_rows(EE_Line_Item $line_item, $options = array())
601
+	{
602
+		$html = '';
603
+		$owing = $line_item->total();
604
+		$transaction = EEM_Transaction::instance()->get_one_by_ID($line_item->TXN_ID());
605
+		if ($transaction instanceof EE_Transaction) {
606
+			$registration_payments = array();
607
+			$registrations = ! empty($options['registrations'])
608
+				? $options['registrations']
609
+				: $transaction->registrations();
610
+			foreach ($registrations as $registration) {
611
+				if ($registration instanceof EE_Registration && $registration->owes_monies_and_can_pay()) {
612
+					$registration_payments += $registration->registration_payments();
613
+				}
614
+			}
615
+			if (! empty($registration_payments)) {
616
+				foreach ($registration_payments as $registration_payment) {
617
+					if ($registration_payment instanceof EE_Registration_Payment) {
618
+						$owing -= $registration_payment->amount();
619
+						$payment = $registration_payment->payment();
620
+						$payment_desc = '';
621
+						if ($payment instanceof EE_Payment) {
622
+							$payment_desc = sprintf(
623
+								esc_html__('Payment%1$s Received: %2$s', 'event_espresso'),
624
+								$payment->txn_id_chq_nmbr() !== ''
625
+									? ' <span class="small-text">(#' . $payment->txn_id_chq_nmbr() . ')</span> '
626
+									: '',
627
+								$payment->timestamp()
628
+							);
629
+						}
630
+						// start of row
631
+						$html .= EEH_HTML::tr('', '', 'total_tr odd');
632
+						// payment desc
633
+						$html .= EEH_HTML::td($payment_desc, '', '', '', ' colspan="3"');
634
+						// total td
635
+						$html .= EEH_HTML::td(
636
+							EEH_Template::format_currency(
637
+								$registration_payment->amount(),
638
+								false,
639
+								false
640
+							),
641
+							'',
642
+							'total jst-rght'
643
+						);
644
+						// end of row
645
+						$html .= EEH_HTML::trx();
646
+					}
647
+				}
648
+				if ($line_item->total()) {
649
+					// start of row
650
+					$html .= EEH_HTML::tr('', '', 'total_tr odd');
651
+					// total td
652
+					$html .= EEH_HTML::td(
653
+						esc_html__('Amount Owing', 'event_espresso'),
654
+						'',
655
+						'total_currency total jst-rght',
656
+						'',
657
+						' colspan="3"'
658
+					);
659
+					// total td
660
+					$html .= EEH_HTML::td(
661
+						EEH_Template::format_currency($owing, false, false),
662
+						'',
663
+						'total jst-rght'
664
+					);
665
+					// end of row
666
+					$html .= EEH_HTML::trx();
667
+				}
668
+			}
669
+		}
670
+		$this->_grand_total = $owing;
671
+		return $html;
672
+	}
673 673
 }
Please login to merge, or discard this patch.
core/libraries/rest_api/changes/ChangesIn40834.php 1 patch
Indentation   +33 added lines, -33 removed lines patch added patch discarded remove patch
@@ -12,39 +12,39 @@
 block discarded – undo
12 12
 class ChangesIn40834 extends ChangesInBase
13 13
 {
14 14
 
15
-    /**
16
-     * Adds hooks so requests to 4.8.29 don't have the checkin endpoints
17
-     */
18
-    public function setHooks()
19
-    {
20
-        // set a hook to remove the checkout/checkout endpoints if the request
21
-        // is for lower than 4.8.33
22
-        add_filter(
23
-            'FHEE__EventEspresso\core\libraries\rest_api\controllers\Base___get_response_headers',
24
-            array($this, 'removeResponseHeaders'),
25
-            10,
26
-            3
27
-        );
28
-    }
15
+	/**
16
+	 * Adds hooks so requests to 4.8.29 don't have the checkin endpoints
17
+	 */
18
+	public function setHooks()
19
+	{
20
+		// set a hook to remove the checkout/checkout endpoints if the request
21
+		// is for lower than 4.8.33
22
+		add_filter(
23
+			'FHEE__EventEspresso\core\libraries\rest_api\controllers\Base___get_response_headers',
24
+			array($this, 'removeResponseHeaders'),
25
+			10,
26
+			3
27
+		);
28
+	}
29 29
 
30 30
 
31
-    /**
32
-     * Removes the checkin and checkout endpoints from the index for requests
33
-     * to api versions lowers than 4.8.33
34
-     *
35
-     * @param array  $response_headers
36
-     * @param Base   $controller
37
-     * @param string $requested_version
38
-     * @return array like $routes_on_this_version
39
-     */
40
-    public function removeResponseHeaders($response_headers, $controller, $requested_version)
41
-    {
42
-        if (
43
-            $controller instanceof Base
44
-            && $this->appliesToVersion($requested_version)
45
-        ) {
46
-            return array();
47
-        }
48
-        return $response_headers;
49
-    }
31
+	/**
32
+	 * Removes the checkin and checkout endpoints from the index for requests
33
+	 * to api versions lowers than 4.8.33
34
+	 *
35
+	 * @param array  $response_headers
36
+	 * @param Base   $controller
37
+	 * @param string $requested_version
38
+	 * @return array like $routes_on_this_version
39
+	 */
40
+	public function removeResponseHeaders($response_headers, $controller, $requested_version)
41
+	{
42
+		if (
43
+			$controller instanceof Base
44
+			&& $this->appliesToVersion($requested_version)
45
+		) {
46
+			return array();
47
+		}
48
+		return $response_headers;
49
+	}
50 50
 }
Please login to merge, or discard this patch.
core/libraries/rest_api/calculations/Registration.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -96,7 +96,7 @@
 block discarded – undo
96 96
                     $status_pretty = 'NEVER';
97 97
                     break;
98 98
             }
99
-            $checkin_stati[ $datetime_id ] = $status_pretty;
99
+            $checkin_stati[$datetime_id] = $status_pretty;
100 100
         }
101 101
         return $checkin_stati;
102 102
     }
Please login to merge, or discard this patch.
Indentation   +101 added lines, -101 removed lines patch added patch discarded remove patch
@@ -24,109 +24,109 @@
 block discarded – undo
24 24
  */
25 25
 class Registration extends RegistrationCalculationBase
26 26
 {
27
-    /**
28
-     * @var EEM_Registration
29
-     */
30
-    protected $registration_model;
27
+	/**
28
+	 * @var EEM_Registration
29
+	 */
30
+	protected $registration_model;
31 31
 
32
-    /**
33
-     * Registration constructor.
34
-     * @param EEM_Registration $registration_model
35
-     */
36
-    public function __construct(EEM_Registration $registration_model)
37
-    {
38
-        $this->registration_model = $registration_model;
39
-    }
32
+	/**
33
+	 * Registration constructor.
34
+	 * @param EEM_Registration $registration_model
35
+	 */
36
+	public function __construct(EEM_Registration $registration_model)
37
+	{
38
+		$this->registration_model = $registration_model;
39
+	}
40 40
 
41
-    /**
42
-     * Calculates the checkin status for each datetime this registration has access to
43
-     *
44
-     * @param array            $wpdb_row
45
-     * @param WP_REST_Request $request
46
-     * @param RegistrationControllerBase $controller
47
-     * @return array
48
-     * @throws EE_Error
49
-     * @throws InvalidDataTypeException
50
-     * @throws InvalidInterfaceException
51
-     * @throws InvalidArgumentException
52
-     */
53
-    public function datetimeCheckinStati($wpdb_row, $request, $controller)
54
-    {
55
-        if (is_array($wpdb_row) && isset($wpdb_row['Registration.REG_ID'])) {
56
-            $reg = $this->registration_model->get_one_by_ID($wpdb_row['Registration.REG_ID']);
57
-        } else {
58
-            $reg = null;
59
-        }
60
-        if (
61
-            ! $reg instanceof EE_Registration
62
-        ) {
63
-            throw new EE_Error(
64
-                sprintf(
65
-                    esc_html__(
66
-                    // @codingStandardsIgnoreStart
67
-                        'Cannot calculate datetime_checkin_stati because the registration with ID %1$s (from database row %2$s) was not found',
68
-                        // @codingStandardsIgnoreEnd
69
-                        'event_espresso'
70
-                    ),
71
-                    $wpdb_row['Registration.REG_ID'],
72
-                    print_r($wpdb_row, true)
73
-                )
74
-            );
75
-        }
76
-        $datetime_ids = EEM_Datetime::instance()->get_col(
77
-            [
78
-                [
79
-                    'Ticket.TKT_ID' => $reg->ticket_ID(),
80
-                ],
81
-                'default_where_conditions' => EEM_Base::default_where_conditions_minimum_all,
82
-            ]
83
-        );
84
-        $checkin_stati = array();
85
-        foreach ($datetime_ids as $datetime_id) {
86
-            $status = $reg->check_in_status_for_datetime($datetime_id);
87
-            switch ($status) {
88
-                case EE_Checkin::status_checked_out:
89
-                    $status_pretty = 'OUT';
90
-                    break;
91
-                case EE_Checkin::status_checked_in:
92
-                    $status_pretty = 'IN';
93
-                    break;
94
-                case EE_Checkin::status_checked_never:
95
-                default:
96
-                    $status_pretty = 'NEVER';
97
-                    break;
98
-            }
99
-            $checkin_stati[ $datetime_id ] = $status_pretty;
100
-        }
101
-        return $checkin_stati;
102
-    }
41
+	/**
42
+	 * Calculates the checkin status for each datetime this registration has access to
43
+	 *
44
+	 * @param array            $wpdb_row
45
+	 * @param WP_REST_Request $request
46
+	 * @param RegistrationControllerBase $controller
47
+	 * @return array
48
+	 * @throws EE_Error
49
+	 * @throws InvalidDataTypeException
50
+	 * @throws InvalidInterfaceException
51
+	 * @throws InvalidArgumentException
52
+	 */
53
+	public function datetimeCheckinStati($wpdb_row, $request, $controller)
54
+	{
55
+		if (is_array($wpdb_row) && isset($wpdb_row['Registration.REG_ID'])) {
56
+			$reg = $this->registration_model->get_one_by_ID($wpdb_row['Registration.REG_ID']);
57
+		} else {
58
+			$reg = null;
59
+		}
60
+		if (
61
+			! $reg instanceof EE_Registration
62
+		) {
63
+			throw new EE_Error(
64
+				sprintf(
65
+					esc_html__(
66
+					// @codingStandardsIgnoreStart
67
+						'Cannot calculate datetime_checkin_stati because the registration with ID %1$s (from database row %2$s) was not found',
68
+						// @codingStandardsIgnoreEnd
69
+						'event_espresso'
70
+					),
71
+					$wpdb_row['Registration.REG_ID'],
72
+					print_r($wpdb_row, true)
73
+				)
74
+			);
75
+		}
76
+		$datetime_ids = EEM_Datetime::instance()->get_col(
77
+			[
78
+				[
79
+					'Ticket.TKT_ID' => $reg->ticket_ID(),
80
+				],
81
+				'default_where_conditions' => EEM_Base::default_where_conditions_minimum_all,
82
+			]
83
+		);
84
+		$checkin_stati = array();
85
+		foreach ($datetime_ids as $datetime_id) {
86
+			$status = $reg->check_in_status_for_datetime($datetime_id);
87
+			switch ($status) {
88
+				case EE_Checkin::status_checked_out:
89
+					$status_pretty = 'OUT';
90
+					break;
91
+				case EE_Checkin::status_checked_in:
92
+					$status_pretty = 'IN';
93
+					break;
94
+				case EE_Checkin::status_checked_never:
95
+				default:
96
+					$status_pretty = 'NEVER';
97
+					break;
98
+			}
99
+			$checkin_stati[ $datetime_id ] = $status_pretty;
100
+		}
101
+		return $checkin_stati;
102
+	}
103 103
 
104 104
 
105
-    /**
106
-     * Provides an array for all the calculations possible that outlines a json schema for those calculations.
107
-     * Array is indexed by calculation (snake case) and value is the schema for that calculation.
108
-     *
109
-     * @since 4.9.68.p
110
-     * @return array
111
-     */
112
-    public function schemaForCalculations()
113
-    {
114
-        return array(
115
-            'datetime_checkin_stati' => array(
116
-                'description' => esc_html__(
117
-                    'Returns the checkin status for each datetime this registration has access to.',
118
-                    'event_espresso'
119
-                ),
120
-                'type' => 'object',
121
-                'properties' => array(),
122
-                'additionalProperties' => array(
123
-                    'description' => esc_html__(
124
-                        'Keys are date-time ids and values are the check-in status',
125
-                        'event_espresso'
126
-                    ),
127
-                    'type' => 'string'
128
-                ),
129
-            ),
130
-        );
131
-    }
105
+	/**
106
+	 * Provides an array for all the calculations possible that outlines a json schema for those calculations.
107
+	 * Array is indexed by calculation (snake case) and value is the schema for that calculation.
108
+	 *
109
+	 * @since 4.9.68.p
110
+	 * @return array
111
+	 */
112
+	public function schemaForCalculations()
113
+	{
114
+		return array(
115
+			'datetime_checkin_stati' => array(
116
+				'description' => esc_html__(
117
+					'Returns the checkin status for each datetime this registration has access to.',
118
+					'event_espresso'
119
+				),
120
+				'type' => 'object',
121
+				'properties' => array(),
122
+				'additionalProperties' => array(
123
+					'description' => esc_html__(
124
+						'Keys are date-time ids and values are the check-in status',
125
+						'event_espresso'
126
+					),
127
+					'type' => 'string'
128
+				),
129
+			),
130
+		);
131
+	}
132 132
 }
Please login to merge, or discard this patch.
core/libraries/rest_api/CalculatedModelFields.php 2 patches
Spacing   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -57,7 +57,7 @@  discard block
 block discarded – undo
57 57
      */
58 58
     public function mapping($refresh = false)
59 59
     {
60
-        if (! $this->mapping || $refresh) {
60
+        if ( ! $this->mapping || $refresh) {
61 61
             $this->mapping = $this->generateNewMapping();
62 62
         }
63 63
         return $this->mapping;
@@ -81,7 +81,7 @@  discard block
 block discarded – undo
81 81
         foreach ($models_with_calculated_fields as $model_name) {
82 82
             $calculator = $this->factory->createFromModel($model_name);
83 83
             foreach (array_keys(call_user_func(array($calculator, 'schemaForCalculations'))) as $field_name) {
84
-                $mapping[ $model_name ][ $field_name ] = get_class($calculator);
84
+                $mapping[$model_name][$field_name] = get_class($calculator);
85 85
             }
86 86
         }
87 87
         return apply_filters(
@@ -108,8 +108,8 @@  discard block
 block discarded – undo
108 108
             foreach ($map_for_model as $calculation_index => $calculations_class) {
109 109
                 $calculator = $this->factory->createFromClassname($calculations_class);
110 110
                 $schema = call_user_func(array($calculator, 'schemaForCalculation'), $calculation_index);
111
-                if (! empty($schema)) {
112
-                    $schema_map[ $map_model ][ $calculation_index ] = $schema;
111
+                if ( ! empty($schema)) {
112
+                    $schema_map[$map_model][$calculation_index] = $schema;
113 113
                 }
114 114
             }
115 115
         }
@@ -126,8 +126,8 @@  discard block
 block discarded – undo
126 126
     public function retrieveCalculatedFieldsForModel(EEM_Base $model)
127 127
     {
128 128
         $mapping = $this->mapping();
129
-        if (isset($mapping[ $model->get_this_model_name() ])) {
130
-            return array_keys($mapping[ $model->get_this_model_name() ]);
129
+        if (isset($mapping[$model->get_this_model_name()])) {
130
+            return array_keys($mapping[$model->get_this_model_name()]);
131 131
         }
132 132
         return array();
133 133
     }
@@ -140,7 +140,7 @@  discard block
 block discarded – undo
140 140
      */
141 141
     public function getJsonSchemaForModel(EEM_Base $model)
142 142
     {
143
-        if (! $this->mapping_schema) {
143
+        if ( ! $this->mapping_schema) {
144 144
             $this->mapping_schema = $this->generateNewMappingSchema();
145 145
         }
146 146
         return array(
@@ -149,8 +149,8 @@  discard block
 block discarded – undo
149 149
                 'event_espresso'
150 150
             ),
151 151
             'type' => 'object',
152
-            'properties' => isset($this->mapping_schema[ $model->get_this_model_name() ])
153
-                ? $this->mapping_schema[ $model->get_this_model_name() ]
152
+            'properties' => isset($this->mapping_schema[$model->get_this_model_name()])
153
+                ? $this->mapping_schema[$model->get_this_model_name()]
154 154
                 : array(),
155 155
             'additionalProperties' => false,
156 156
             'readonly' => true,
@@ -179,10 +179,10 @@  discard block
 block discarded – undo
179 179
     ) {
180 180
         $mapping = $this->mapping();
181 181
         if (
182
-            isset($mapping[ $model->get_this_model_name() ])
183
-            && isset($mapping[ $model->get_this_model_name() ][ $field_name ])
182
+            isset($mapping[$model->get_this_model_name()])
183
+            && isset($mapping[$model->get_this_model_name()][$field_name])
184 184
         ) {
185
-            $classname = $mapping[ $model->get_this_model_name() ][ $field_name ];
185
+            $classname = $mapping[$model->get_this_model_name()][$field_name];
186 186
             $calculator = $this->factory->createFromClassname($classname);
187 187
             $class_method_name = EEH_Inflector::camelize_all_but_first($field_name);
188 188
             return call_user_func(array($calculator, $class_method_name), $wpdb_row, $rest_request, $controller);
Please login to merge, or discard this patch.
Indentation   +174 added lines, -174 removed lines patch added patch discarded remove patch
@@ -21,178 +21,178 @@
 block discarded – undo
21 21
  */
22 22
 class CalculatedModelFields
23 23
 {
24
-    /**
25
-     * @var array
26
-     */
27
-    protected $mapping;
28
-
29
-    /**
30
-     * @var array
31
-     */
32
-    protected $mapping_schema;
33
-
34
-    /**
35
-     * @var CalculatedModelFieldsFactory
36
-     */
37
-    private $factory;
38
-
39
-    /**
40
-     * CalculatedModelFields constructor.
41
-     * @param CalculatedModelFieldsFactory $factory
42
-     */
43
-    public function __construct(CalculatedModelFieldsFactory $factory)
44
-    {
45
-        $this->factory = $factory;
46
-    }
47
-    /**
48
-     * @param bool $refresh
49
-     * @return array top-level-keys are model names (eg "Event")
50
-     * next-level are the calculated field names AND method names on classes
51
-     * which perform calculations, values are the fully qualified classnames which do the calculations
52
-     * These callbacks should accept as arguments:
53
-     * the wpdb row results,
54
-     * the WP_Request object,
55
-     * the controller object
56
-     */
57
-    public function mapping($refresh = false)
58
-    {
59
-        if (! $this->mapping || $refresh) {
60
-            $this->mapping = $this->generateNewMapping();
61
-        }
62
-        return $this->mapping;
63
-    }
64
-
65
-
66
-    /**
67
-     * Generates a new mapping between model calculated fields and their callbacks
68
-     *
69
-     * @return array
70
-     */
71
-    protected function generateNewMapping()
72
-    {
73
-        $mapping = array();
74
-        $models_with_calculated_fields = array(
75
-            'Attendee',
76
-            'Datetime',
77
-            'Event',
78
-            'Registration'
79
-        );
80
-        foreach ($models_with_calculated_fields as $model_name) {
81
-            $calculator = $this->factory->createFromModel($model_name);
82
-            foreach (array_keys(call_user_func(array($calculator, 'schemaForCalculations'))) as $field_name) {
83
-                $mapping[ $model_name ][ $field_name ] = get_class($calculator);
84
-            }
85
-        }
86
-        return apply_filters(
87
-            'FHEE__EventEspresso\core\libraries\rest_api\Calculated_Model_Fields__mapping',
88
-            $mapping
89
-        );
90
-    }
91
-
92
-
93
-    /**
94
-     * Generates the schema for each calculation index in the calculation map.
95
-     *
96
-     * @return array
97
-     * @throws UnexpectedEntityException
98
-     */
99
-    protected function generateNewMappingSchema()
100
-    {
101
-        $schema_map = array();
102
-        foreach ($this->mapping() as $map_model => $map_for_model) {
103
-            /**
104
-             * @var string $calculation_index
105
-             * @var string $calculations_class
106
-             */
107
-            foreach ($map_for_model as $calculation_index => $calculations_class) {
108
-                $calculator = $this->factory->createFromClassname($calculations_class);
109
-                $schema = call_user_func(array($calculator, 'schemaForCalculation'), $calculation_index);
110
-                if (! empty($schema)) {
111
-                    $schema_map[ $map_model ][ $calculation_index ] = $schema;
112
-                }
113
-            }
114
-        }
115
-        return $schema_map;
116
-    }
117
-
118
-
119
-    /**
120
-     * Gets the known calculated fields for model
121
-     *
122
-     * @param EEM_Base $model
123
-     * @return array allowable values for this field
124
-     */
125
-    public function retrieveCalculatedFieldsForModel(EEM_Base $model)
126
-    {
127
-        $mapping = $this->mapping();
128
-        if (isset($mapping[ $model->get_this_model_name() ])) {
129
-            return array_keys($mapping[ $model->get_this_model_name() ]);
130
-        }
131
-        return array();
132
-    }
133
-
134
-
135
-    /**
136
-     * Returns the JsonSchema for the calculated fields on the given model.
137
-     * @param EEM_Base $model
138
-     * @return array
139
-     */
140
-    public function getJsonSchemaForModel(EEM_Base $model)
141
-    {
142
-        if (! $this->mapping_schema) {
143
-            $this->mapping_schema = $this->generateNewMappingSchema();
144
-        }
145
-        return array(
146
-            'description' => esc_html__(
147
-                'Available calculated fields for this model.  Fields are only present in the response if explicitly requested',
148
-                'event_espresso'
149
-            ),
150
-            'type' => 'object',
151
-            'properties' => isset($this->mapping_schema[ $model->get_this_model_name() ])
152
-                ? $this->mapping_schema[ $model->get_this_model_name() ]
153
-                : array(),
154
-            'additionalProperties' => false,
155
-            'readonly' => true,
156
-        );
157
-    }
158
-
159
-
160
-    /**
161
-     * Retrieves the value for this calculation
162
-     *
163
-     * @param EEM_Base $model
164
-     * @param string $field_name
165
-     * @param array $wpdb_row
166
-     * @param $rest_request
167
-     * @param BaseController $controller
168
-     * @return mixed|null
169
-     * @throws RestException
170
-     * @throws UnexpectedEntityException
171
-     */
172
-    public function retrieveCalculatedFieldValue(
173
-        EEM_Base $model,
174
-        $field_name,
175
-        $wpdb_row,
176
-        $rest_request,
177
-        Base $controller
178
-    ) {
179
-        $mapping = $this->mapping();
180
-        if (
181
-            isset($mapping[ $model->get_this_model_name() ])
182
-            && isset($mapping[ $model->get_this_model_name() ][ $field_name ])
183
-        ) {
184
-            $classname = $mapping[ $model->get_this_model_name() ][ $field_name ];
185
-            $calculator = $this->factory->createFromClassname($classname);
186
-            $class_method_name = EEH_Inflector::camelize_all_but_first($field_name);
187
-            return call_user_func(array($calculator, $class_method_name), $wpdb_row, $rest_request, $controller);
188
-        }
189
-        throw new RestException(
190
-            'calculated_field_does_not_exist',
191
-            sprintf(
192
-                esc_html__('There is no calculated field %1$s on resource %2$s', 'event_espresso'),
193
-                $field_name,
194
-                $model->get_this_model_name()
195
-            )
196
-        );
197
-    }
24
+	/**
25
+	 * @var array
26
+	 */
27
+	protected $mapping;
28
+
29
+	/**
30
+	 * @var array
31
+	 */
32
+	protected $mapping_schema;
33
+
34
+	/**
35
+	 * @var CalculatedModelFieldsFactory
36
+	 */
37
+	private $factory;
38
+
39
+	/**
40
+	 * CalculatedModelFields constructor.
41
+	 * @param CalculatedModelFieldsFactory $factory
42
+	 */
43
+	public function __construct(CalculatedModelFieldsFactory $factory)
44
+	{
45
+		$this->factory = $factory;
46
+	}
47
+	/**
48
+	 * @param bool $refresh
49
+	 * @return array top-level-keys are model names (eg "Event")
50
+	 * next-level are the calculated field names AND method names on classes
51
+	 * which perform calculations, values are the fully qualified classnames which do the calculations
52
+	 * These callbacks should accept as arguments:
53
+	 * the wpdb row results,
54
+	 * the WP_Request object,
55
+	 * the controller object
56
+	 */
57
+	public function mapping($refresh = false)
58
+	{
59
+		if (! $this->mapping || $refresh) {
60
+			$this->mapping = $this->generateNewMapping();
61
+		}
62
+		return $this->mapping;
63
+	}
64
+
65
+
66
+	/**
67
+	 * Generates a new mapping between model calculated fields and their callbacks
68
+	 *
69
+	 * @return array
70
+	 */
71
+	protected function generateNewMapping()
72
+	{
73
+		$mapping = array();
74
+		$models_with_calculated_fields = array(
75
+			'Attendee',
76
+			'Datetime',
77
+			'Event',
78
+			'Registration'
79
+		);
80
+		foreach ($models_with_calculated_fields as $model_name) {
81
+			$calculator = $this->factory->createFromModel($model_name);
82
+			foreach (array_keys(call_user_func(array($calculator, 'schemaForCalculations'))) as $field_name) {
83
+				$mapping[ $model_name ][ $field_name ] = get_class($calculator);
84
+			}
85
+		}
86
+		return apply_filters(
87
+			'FHEE__EventEspresso\core\libraries\rest_api\Calculated_Model_Fields__mapping',
88
+			$mapping
89
+		);
90
+	}
91
+
92
+
93
+	/**
94
+	 * Generates the schema for each calculation index in the calculation map.
95
+	 *
96
+	 * @return array
97
+	 * @throws UnexpectedEntityException
98
+	 */
99
+	protected function generateNewMappingSchema()
100
+	{
101
+		$schema_map = array();
102
+		foreach ($this->mapping() as $map_model => $map_for_model) {
103
+			/**
104
+			 * @var string $calculation_index
105
+			 * @var string $calculations_class
106
+			 */
107
+			foreach ($map_for_model as $calculation_index => $calculations_class) {
108
+				$calculator = $this->factory->createFromClassname($calculations_class);
109
+				$schema = call_user_func(array($calculator, 'schemaForCalculation'), $calculation_index);
110
+				if (! empty($schema)) {
111
+					$schema_map[ $map_model ][ $calculation_index ] = $schema;
112
+				}
113
+			}
114
+		}
115
+		return $schema_map;
116
+	}
117
+
118
+
119
+	/**
120
+	 * Gets the known calculated fields for model
121
+	 *
122
+	 * @param EEM_Base $model
123
+	 * @return array allowable values for this field
124
+	 */
125
+	public function retrieveCalculatedFieldsForModel(EEM_Base $model)
126
+	{
127
+		$mapping = $this->mapping();
128
+		if (isset($mapping[ $model->get_this_model_name() ])) {
129
+			return array_keys($mapping[ $model->get_this_model_name() ]);
130
+		}
131
+		return array();
132
+	}
133
+
134
+
135
+	/**
136
+	 * Returns the JsonSchema for the calculated fields on the given model.
137
+	 * @param EEM_Base $model
138
+	 * @return array
139
+	 */
140
+	public function getJsonSchemaForModel(EEM_Base $model)
141
+	{
142
+		if (! $this->mapping_schema) {
143
+			$this->mapping_schema = $this->generateNewMappingSchema();
144
+		}
145
+		return array(
146
+			'description' => esc_html__(
147
+				'Available calculated fields for this model.  Fields are only present in the response if explicitly requested',
148
+				'event_espresso'
149
+			),
150
+			'type' => 'object',
151
+			'properties' => isset($this->mapping_schema[ $model->get_this_model_name() ])
152
+				? $this->mapping_schema[ $model->get_this_model_name() ]
153
+				: array(),
154
+			'additionalProperties' => false,
155
+			'readonly' => true,
156
+		);
157
+	}
158
+
159
+
160
+	/**
161
+	 * Retrieves the value for this calculation
162
+	 *
163
+	 * @param EEM_Base $model
164
+	 * @param string $field_name
165
+	 * @param array $wpdb_row
166
+	 * @param $rest_request
167
+	 * @param BaseController $controller
168
+	 * @return mixed|null
169
+	 * @throws RestException
170
+	 * @throws UnexpectedEntityException
171
+	 */
172
+	public function retrieveCalculatedFieldValue(
173
+		EEM_Base $model,
174
+		$field_name,
175
+		$wpdb_row,
176
+		$rest_request,
177
+		Base $controller
178
+	) {
179
+		$mapping = $this->mapping();
180
+		if (
181
+			isset($mapping[ $model->get_this_model_name() ])
182
+			&& isset($mapping[ $model->get_this_model_name() ][ $field_name ])
183
+		) {
184
+			$classname = $mapping[ $model->get_this_model_name() ][ $field_name ];
185
+			$calculator = $this->factory->createFromClassname($classname);
186
+			$class_method_name = EEH_Inflector::camelize_all_but_first($field_name);
187
+			return call_user_func(array($calculator, $class_method_name), $wpdb_row, $rest_request, $controller);
188
+		}
189
+		throw new RestException(
190
+			'calculated_field_does_not_exist',
191
+			sprintf(
192
+				esc_html__('There is no calculated field %1$s on resource %2$s', 'event_espresso'),
193
+				$field_name,
194
+				$model->get_this_model_name()
195
+			)
196
+		);
197
+	}
198 198
 }
Please login to merge, or discard this patch.
core/libraries/messages/EE_Messages_Base.lib.php 2 patches
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -196,11 +196,11 @@  discard block
 block discarded – undo
196 196
             ! empty($messenger)
197 197
             && $Message_Resource_Manager->is_message_type_active_for_messenger($messenger, $this->name)
198 198
         ) {
199
-            $settings_to_use = $active_messengers[ $messenger ]['settings'][ $messenger . '-message_types' ];
199
+            $settings_to_use = $active_messengers[$messenger]['settings'][$messenger.'-message_types'];
200 200
         }
201 201
 
202
-        $this->_existing_admin_settings = isset($settings_to_use[ $this->name ]['settings'])
203
-            ? $settings_to_use[ $this->name ]['settings']
202
+        $this->_existing_admin_settings = isset($settings_to_use[$this->name]['settings'])
203
+            ? $settings_to_use[$this->name]['settings']
204 204
             : null;
205 205
     }
206 206
 
@@ -240,7 +240,7 @@  discard block
 block discarded – undo
240 240
     public function get_valid_shortcodes()
241 241
     {
242 242
         $valid_shortcodes = apply_filters(
243
-            'FHEE__' . get_class($this) . '__get_valid_shortcodes',
243
+            'FHEE__'.get_class($this).'__get_valid_shortcodes',
244 244
             $this->_valid_shortcodes,
245 245
             $this
246 246
         );
@@ -283,19 +283,19 @@  discard block
 block discarded – undo
283 283
     protected function _get_admin_page_content($page, $action, $extra, $actives)
284 284
     {
285 285
         // we can also further refine the context by action (if present).
286
-        if (!empty($action)) {
287
-            $page = $page . '_' . $action;
286
+        if ( ! empty($action)) {
287
+            $page = $page.'_'.$action;
288 288
         }
289 289
 
290
-        if (!isset($this->admin_registered_pages[ $page ])) {
290
+        if ( ! isset($this->admin_registered_pages[$page])) {
291 291
             // todo: a place to throw an exception?
292 292
             // We need to indicate there is no registered page so this function is not being called correctly.
293 293
             return false;
294 294
         }
295 295
         // k made it here so let's call the method
296 296
         $content = call_user_func_array(
297
-            array( $this, '_get_admin_content_' . $page ),
298
-            array( $actives, $extra )
297
+            array($this, '_get_admin_content_'.$page),
298
+            array($actives, $extra)
299 299
         );
300 300
         if ($content === false) {
301 301
             // todo this needs to be an exception once we've got exceptions in place.
Please login to merge, or discard this patch.
Indentation   +265 added lines, -265 removed lines patch added patch discarded remove patch
@@ -13,44 +13,44 @@  discard block
 block discarded – undo
13 13
  */
14 14
 abstract class EE_Messages_Base extends EE_Base
15 15
 {
16
-    /** DETAILS PROPERTIES **/
17
-    /**
18
-     * The following are used to hold details on the type for reference (i.e. on admin screens)
19
-     * and also used by the EE_message_type object to figure out where to get template data.
20
-     */
21
-    public $name;
22
-    public $description;
23
-    protected $_messages_item_type; // messenger OR message_type?
24
-
25
-
26
-    /**
27
-     * This is an array describing the ui facing labels
28
-     * that will be used whenever the messenger is referenced in the ui
29
-     *
30
-     * array(
31
-     *  'singular' => esc_html__('something'),
32
-     *  'plural' => esc_html__('somethings')
33
-     * )
34
-     *
35
-     * @var array
36
-     */
37
-    public $label;
38
-
39
-
40
-
41
-
42
-    /**
43
-     * This property when set will hold the slugs of all EE admin pages that we will need to retrieve fields for
44
-     * (and used to determine which callback method to call from the child class)
45
-     *
46
-     * structure should be
47
-     * array(
48
-     * 'page_action' => true
49
-     * )
50
-     *
16
+	/** DETAILS PROPERTIES **/
17
+	/**
18
+	 * The following are used to hold details on the type for reference (i.e. on admin screens)
19
+	 * and also used by the EE_message_type object to figure out where to get template data.
20
+	 */
21
+	public $name;
22
+	public $description;
23
+	protected $_messages_item_type; // messenger OR message_type?
24
+
25
+
26
+	/**
27
+	 * This is an array describing the ui facing labels
28
+	 * that will be used whenever the messenger is referenced in the ui
29
+	 *
30
+	 * array(
31
+	 *  'singular' => esc_html__('something'),
32
+	 *  'plural' => esc_html__('somethings')
33
+	 * )
34
+	 *
35
+	 * @var array
36
+	 */
37
+	public $label;
38
+
39
+
40
+
41
+
42
+	/**
43
+	 * This property when set will hold the slugs of all EE admin pages that we will need to retrieve fields for
44
+	 * (and used to determine which callback method to call from the child class)
45
+	 *
46
+	 * structure should be
47
+	 * array(
48
+	 * 'page_action' => true
49
+	 * )
50
+	 *
51 51
 *@var array
52
-     */
53
-    public $admin_registered_pages = array();
52
+	 */
53
+	public $admin_registered_pages = array();
54 54
 
55 55
 
56 56
 
@@ -59,265 +59,265 @@  discard block
 block discarded – undo
59 59
 
60 60
 
61 61
 
62
-    /**
63
-     * this property holds any specific fields for holding any settings related to a messenger (if any needed)
64
-     * @var array
65
-     */
66
-    protected $_admin_settings_fields = array();
62
+	/**
63
+	 * this property holds any specific fields for holding any settings related to a messenger (if any needed)
64
+	 * @var array
65
+	 */
66
+	protected $_admin_settings_fields = array();
67 67
 
68 68
 
69 69
 
70 70
 
71 71
 
72
-    /**
73
-     * this property will hold any existing settings that may have been set in the admin.
74
-     * @var array
75
-     */
76
-    protected $_existing_admin_settings = array();
72
+	/**
73
+	 * this property will hold any existing settings that may have been set in the admin.
74
+	 * @var array
75
+	 */
76
+	protected $_existing_admin_settings = array();
77 77
 
78 78
 
79 79
 
80 80
 
81 81
 
82
-    /**
83
-     * this property will hold an array of valid shortcodes for this message type and messengers.
84
-     * #For Message Types:
85
-     * This is an array of strings that correspond to defined EE_Shortcode libraries and per context.
86
-     * For example:
87
-     * array( 'admin' => array('transaction', 'event', 'attendee') )
88
-     * corresponds to 'EE_Transaction_Shortcodes.lib.php, EE_Event_Shortcodes.lib.php, EE_Attendee_Shortcodes.lib.php'
89
-     * for the admin context;
90
-     *
91
-     *
92
-     * #For Messengers:
93
-     * For example:
94
-     * array('subject' => array('transaction', 'event', 'attendee'))
95
-     * corresponds to 'EE_Transaction_Shortcodes.lib.php, EE_Event_Shortcodes.lib.php, EE_Attendee_Shortcodes.lib.php'
96
-     * for the 'subject' field;
97
-     * NOTE:  by default, with messengers, if the valid shortcodes for a field is left blank,
98
-     * that field will inherit whatever are set as valid shortcodes by message_type.
99
-     * This is so messenger can set specific valid codes for fields and leave other
100
-     * valid shortcodes up to the message type matched with the messenger.
101
-     *
102
-     * @access protected
103
-     * @var array
104
-     */
105
-    protected $_valid_shortcodes = array();
82
+	/**
83
+	 * this property will hold an array of valid shortcodes for this message type and messengers.
84
+	 * #For Message Types:
85
+	 * This is an array of strings that correspond to defined EE_Shortcode libraries and per context.
86
+	 * For example:
87
+	 * array( 'admin' => array('transaction', 'event', 'attendee') )
88
+	 * corresponds to 'EE_Transaction_Shortcodes.lib.php, EE_Event_Shortcodes.lib.php, EE_Attendee_Shortcodes.lib.php'
89
+	 * for the admin context;
90
+	 *
91
+	 *
92
+	 * #For Messengers:
93
+	 * For example:
94
+	 * array('subject' => array('transaction', 'event', 'attendee'))
95
+	 * corresponds to 'EE_Transaction_Shortcodes.lib.php, EE_Event_Shortcodes.lib.php, EE_Attendee_Shortcodes.lib.php'
96
+	 * for the 'subject' field;
97
+	 * NOTE:  by default, with messengers, if the valid shortcodes for a field is left blank,
98
+	 * that field will inherit whatever are set as valid shortcodes by message_type.
99
+	 * This is so messenger can set specific valid codes for fields and leave other
100
+	 * valid shortcodes up to the message type matched with the messenger.
101
+	 *
102
+	 * @access protected
103
+	 * @var array
104
+	 */
105
+	protected $_valid_shortcodes = array();
106 106
 
107 107
 
108 108
 
109 109
 
110 110
 
111
-    public function __construct()
112
-    {
113
-        $this->_set_admin_settings_fields();
114
-        $this->_set_valid_shortcodes();
115
-        $this->_set_admin_pages();
116
-    }
111
+	public function __construct()
112
+	{
113
+		$this->_set_admin_settings_fields();
114
+		$this->_set_valid_shortcodes();
115
+		$this->_set_admin_pages();
116
+	}
117 117
 
118 118
 
119 119
 
120 120
 
121 121
 
122
-    /**
123
-     * sets the _admin_settings_fields property which needs to be defined by child classes.
124
-     * You will want to set the _admin_settings_fields properties as a multi-dimensional array with the following format
125
-     * array(
126
-     *      {field_name - also used for setting index} => array(
127
-     *          'field_type' => {type of field: 'text', 'textarea', 'checkbox'},
128
-     *          'value_type' => {type of value: 'string', 'int', 'array', 'bool'},
129
-     *          'required' => {bool, required or not},
130
-     *          'validation' => {bool, true if we want validation, false if not},
131
-     *          'format' => {%d, or %s},
132
-     *          'label' => {label for the field, make sure it's localized},
133
-     *          'default' => {default value for the setting}
134
-     *      ),
135
-     * );
136
-     *
137
-     * @abstract
138
-     * @access protected
139
-     * @return void
140
-     */
141
-    abstract protected function _set_admin_settings_fields();
122
+	/**
123
+	 * sets the _admin_settings_fields property which needs to be defined by child classes.
124
+	 * You will want to set the _admin_settings_fields properties as a multi-dimensional array with the following format
125
+	 * array(
126
+	 *      {field_name - also used for setting index} => array(
127
+	 *          'field_type' => {type of field: 'text', 'textarea', 'checkbox'},
128
+	 *          'value_type' => {type of value: 'string', 'int', 'array', 'bool'},
129
+	 *          'required' => {bool, required or not},
130
+	 *          'validation' => {bool, true if we want validation, false if not},
131
+	 *          'format' => {%d, or %s},
132
+	 *          'label' => {label for the field, make sure it's localized},
133
+	 *          'default' => {default value for the setting}
134
+	 *      ),
135
+	 * );
136
+	 *
137
+	 * @abstract
138
+	 * @access protected
139
+	 * @return void
140
+	 */
141
+	abstract protected function _set_admin_settings_fields();
142 142
 
143 143
 
144 144
 
145 145
 
146 146
 
147
-    /**
148
-     * sets any properties on whether a message type or messenger interface shows up on a ee administration page.
149
-     * Child classes have to define this method but don't necessarily have to set the flags
150
-     * as they will be set to false by default.
151
-     *
152
-     * Child classes use this method to set the `_admin_registered_page` property.
153
-     * That property is to indicate what EE admin pages we have a corresponding callback for in the child class
154
-     * so Message Type/messenger fields/content is included on that admin page.
155
-     *
156
-     * @abstract
157
-     * @access protected
158
-     * @return void
159
-     */
160
-    abstract protected function _set_admin_pages();
147
+	/**
148
+	 * sets any properties on whether a message type or messenger interface shows up on a ee administration page.
149
+	 * Child classes have to define this method but don't necessarily have to set the flags
150
+	 * as they will be set to false by default.
151
+	 *
152
+	 * Child classes use this method to set the `_admin_registered_page` property.
153
+	 * That property is to indicate what EE admin pages we have a corresponding callback for in the child class
154
+	 * so Message Type/messenger fields/content is included on that admin page.
155
+	 *
156
+	 * @abstract
157
+	 * @access protected
158
+	 * @return void
159
+	 */
160
+	abstract protected function _set_admin_pages();
161 161
 
162 162
 
163 163
 
164 164
 
165 165
 
166
-    /**
167
-     * Child classes must declare the $_valid_shortcodes property using this method.
168
-     * See comments for $_valid_shortcodes property for details on what it is used for.
169
-     *
170
-     * @access protected
171
-     * @return void
172
-     */
173
-    abstract protected function _set_valid_shortcodes();
166
+	/**
167
+	 * Child classes must declare the $_valid_shortcodes property using this method.
168
+	 * See comments for $_valid_shortcodes property for details on what it is used for.
169
+	 *
170
+	 * @access protected
171
+	 * @return void
172
+	 */
173
+	abstract protected function _set_valid_shortcodes();
174 174
 
175 175
 
176 176
 
177
-    /**
178
-     * sets the _existing_admin_settings property can be overridden by child classes.
179
-     * We do this so we only do database calls if needed.
180
-     *
181
-     * @access protected
182
-     * @param string $messenger
183
-     */
184
-    protected function _set_existing_admin_settings($messenger = '')
185
-    {
186
-        /** @var EE_Message_Resource_Manager $Message_Resource_Manager */
187
-        $Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
188
-        $active_messengers = $Message_Resource_Manager->get_active_messengers_option();
189
-        $settings_to_use = $active_messengers;
190
-
191
-        /**
192
-         * This determines what will be used for the getting the settings.
193
-         */
194
-        if (
195
-            ! empty($messenger)
196
-            && $Message_Resource_Manager->is_message_type_active_for_messenger($messenger, $this->name)
197
-        ) {
198
-            $settings_to_use = $active_messengers[ $messenger ]['settings'][ $messenger . '-message_types' ];
199
-        }
200
-
201
-        $this->_existing_admin_settings = isset($settings_to_use[ $this->name ]['settings'])
202
-            ? $settings_to_use[ $this->name ]['settings']
203
-            : null;
204
-    }
205
-
206
-
207
-
208
-
209
-
210
-
211
-    /**
212
-     * get_existing_admin_settings
213
-     * (if needed) sets and returns the _existing_admin_settings property.
214
-     *
215
-     * @access public
216
-     * @param string $messenger
217
-     * @return array          settings
218
-     */
219
-    public function get_existing_admin_settings($messenger = '')
220
-    {
221
-        // if admin_settings property empty lets try setting it.
222
-        if (method_exists($this, '_set_existing_admin_settings') && empty($this->_existing_admin_settings)) {
223
-            $this->_set_existing_admin_settings($messenger);
224
-        }
225
-        return property_exists($this, '_existing_admin_settings')
226
-            ? $this->_existing_admin_settings
227
-            : null;
228
-    }
229
-
230
-
231
-
232
-
233
-
234
-
235
-    /**
236
-     * This returns the array of valid shortcodes for a message type or messenger as set by the child in the $_valid_shortcode property.
237
-     * @return array   an array of valid shortcodes.
238
-     */
239
-    public function get_valid_shortcodes()
240
-    {
241
-        $valid_shortcodes = apply_filters(
242
-            'FHEE__' . get_class($this) . '__get_valid_shortcodes',
243
-            $this->_valid_shortcodes,
244
-            $this
245
-        );
246
-        // The below filter applies to ALL messengers and message types so use with care!
247
-        $valid_shortcodes = apply_filters('FHEE__EE_Messages_Base__get_valid_shortcodes', $valid_shortcodes, $this);
248
-        return $valid_shortcodes;
249
-    }
250
-
251
-
252
-
253
-
254
-    /**
255
-     * getter that returns the protected admin_settings_fields property
256
-     *
257
-     * @access public
258
-     * @return array admin settings fields
259
-     */
260
-    public function get_admin_settings_fields()
261
-    {
262
-        return $this->_admin_settings_fields;
263
-    }
264
-
265
-
266
-
267
-
268
-
269
-    /**
270
-     * this public method accepts a page slug (for an EE_admin page)
271
-     * and will return the response from the child class callback function
272
-     * if that page is registered via the `_admin_registered_page` property set by the child class.
273
-     *
274
-     * @param string $page the slug of the EE admin page
275
-     * @param array $actives an array of active message type (or messenger) objects.
276
-     * @param string $action the page action (to allow for more specific handling - i.e. edit vs. add pages)
277
-     * @param array $extra This is just an extra argument that can be used
278
-     *                     to pass additional data for setting up page content.
279
-     * @access protected
280
-     * @return string $content for page.
281
-     */
282
-    protected function _get_admin_page_content($page, $action, $extra, $actives)
283
-    {
284
-        // we can also further refine the context by action (if present).
285
-        if (!empty($action)) {
286
-            $page = $page . '_' . $action;
287
-        }
288
-
289
-        if (!isset($this->admin_registered_pages[ $page ])) {
290
-            // todo: a place to throw an exception?
291
-            // We need to indicate there is no registered page so this function is not being called correctly.
292
-            return false;
293
-        }
294
-        // k made it here so let's call the method
295
-        $content = call_user_func_array(
296
-            array( $this, '_get_admin_content_' . $page ),
297
-            array( $actives, $extra )
298
-        );
299
-        if ($content === false) {
300
-            // todo this needs to be an exception once we've got exceptions in place.
301
-            return false;
302
-        }
303
-        return $content;
304
-    }
305
-
306
-
307
-    /**
308
-     * Allows a message type to specifically exclude template fields for the provided messenger.
309
-     * Filtered so this can be programmatically altered as well.
310
-     * @param string $messenger_name name of messenger
311
-     * @return array
312
-     */
313
-    public function excludedFieldsForMessenger($messenger_name)
314
-    {
315
-        return apply_filters(
316
-            'FHEE__EE_Messages_Base__excludedFieldForMessenger',
317
-            array(),
318
-            $messenger_name,
319
-            $this->name,
320
-            $this
321
-        );
322
-    }
177
+	/**
178
+	 * sets the _existing_admin_settings property can be overridden by child classes.
179
+	 * We do this so we only do database calls if needed.
180
+	 *
181
+	 * @access protected
182
+	 * @param string $messenger
183
+	 */
184
+	protected function _set_existing_admin_settings($messenger = '')
185
+	{
186
+		/** @var EE_Message_Resource_Manager $Message_Resource_Manager */
187
+		$Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
188
+		$active_messengers = $Message_Resource_Manager->get_active_messengers_option();
189
+		$settings_to_use = $active_messengers;
190
+
191
+		/**
192
+		 * This determines what will be used for the getting the settings.
193
+		 */
194
+		if (
195
+			! empty($messenger)
196
+			&& $Message_Resource_Manager->is_message_type_active_for_messenger($messenger, $this->name)
197
+		) {
198
+			$settings_to_use = $active_messengers[ $messenger ]['settings'][ $messenger . '-message_types' ];
199
+		}
200
+
201
+		$this->_existing_admin_settings = isset($settings_to_use[ $this->name ]['settings'])
202
+			? $settings_to_use[ $this->name ]['settings']
203
+			: null;
204
+	}
205
+
206
+
207
+
208
+
209
+
210
+
211
+	/**
212
+	 * get_existing_admin_settings
213
+	 * (if needed) sets and returns the _existing_admin_settings property.
214
+	 *
215
+	 * @access public
216
+	 * @param string $messenger
217
+	 * @return array          settings
218
+	 */
219
+	public function get_existing_admin_settings($messenger = '')
220
+	{
221
+		// if admin_settings property empty lets try setting it.
222
+		if (method_exists($this, '_set_existing_admin_settings') && empty($this->_existing_admin_settings)) {
223
+			$this->_set_existing_admin_settings($messenger);
224
+		}
225
+		return property_exists($this, '_existing_admin_settings')
226
+			? $this->_existing_admin_settings
227
+			: null;
228
+	}
229
+
230
+
231
+
232
+
233
+
234
+
235
+	/**
236
+	 * This returns the array of valid shortcodes for a message type or messenger as set by the child in the $_valid_shortcode property.
237
+	 * @return array   an array of valid shortcodes.
238
+	 */
239
+	public function get_valid_shortcodes()
240
+	{
241
+		$valid_shortcodes = apply_filters(
242
+			'FHEE__' . get_class($this) . '__get_valid_shortcodes',
243
+			$this->_valid_shortcodes,
244
+			$this
245
+		);
246
+		// The below filter applies to ALL messengers and message types so use with care!
247
+		$valid_shortcodes = apply_filters('FHEE__EE_Messages_Base__get_valid_shortcodes', $valid_shortcodes, $this);
248
+		return $valid_shortcodes;
249
+	}
250
+
251
+
252
+
253
+
254
+	/**
255
+	 * getter that returns the protected admin_settings_fields property
256
+	 *
257
+	 * @access public
258
+	 * @return array admin settings fields
259
+	 */
260
+	public function get_admin_settings_fields()
261
+	{
262
+		return $this->_admin_settings_fields;
263
+	}
264
+
265
+
266
+
267
+
268
+
269
+	/**
270
+	 * this public method accepts a page slug (for an EE_admin page)
271
+	 * and will return the response from the child class callback function
272
+	 * if that page is registered via the `_admin_registered_page` property set by the child class.
273
+	 *
274
+	 * @param string $page the slug of the EE admin page
275
+	 * @param array $actives an array of active message type (or messenger) objects.
276
+	 * @param string $action the page action (to allow for more specific handling - i.e. edit vs. add pages)
277
+	 * @param array $extra This is just an extra argument that can be used
278
+	 *                     to pass additional data for setting up page content.
279
+	 * @access protected
280
+	 * @return string $content for page.
281
+	 */
282
+	protected function _get_admin_page_content($page, $action, $extra, $actives)
283
+	{
284
+		// we can also further refine the context by action (if present).
285
+		if (!empty($action)) {
286
+			$page = $page . '_' . $action;
287
+		}
288
+
289
+		if (!isset($this->admin_registered_pages[ $page ])) {
290
+			// todo: a place to throw an exception?
291
+			// We need to indicate there is no registered page so this function is not being called correctly.
292
+			return false;
293
+		}
294
+		// k made it here so let's call the method
295
+		$content = call_user_func_array(
296
+			array( $this, '_get_admin_content_' . $page ),
297
+			array( $actives, $extra )
298
+		);
299
+		if ($content === false) {
300
+			// todo this needs to be an exception once we've got exceptions in place.
301
+			return false;
302
+		}
303
+		return $content;
304
+	}
305
+
306
+
307
+	/**
308
+	 * Allows a message type to specifically exclude template fields for the provided messenger.
309
+	 * Filtered so this can be programmatically altered as well.
310
+	 * @param string $messenger_name name of messenger
311
+	 * @return array
312
+	 */
313
+	public function excludedFieldsForMessenger($messenger_name)
314
+	{
315
+		return apply_filters(
316
+			'FHEE__EE_Messages_Base__excludedFieldForMessenger',
317
+			array(),
318
+			$messenger_name,
319
+			$this->name,
320
+			$this
321
+		);
322
+	}
323 323
 }
Please login to merge, or discard this patch.
core/libraries/messages/EE_Messages_Scheduler.lib.php 2 patches
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -26,7 +26,7 @@  discard block
 block discarded – undo
26 26
     public function __construct()
27 27
     {
28 28
         // register tasks (and make sure only registered once).
29
-        if (! has_action('FHEE__EEH_Activation__get_cron_tasks', array($this, 'register_scheduled_tasks'))) {
29
+        if ( ! has_action('FHEE__EEH_Activation__get_cron_tasks', array($this, 'register_scheduled_tasks'))) {
30 30
             add_action('FHEE__EEH_Activation__get_cron_tasks', array($this, 'register_scheduled_tasks'), 10);
31 31
         }
32 32
 
@@ -77,7 +77,7 @@  discard block
 block discarded – undo
77 77
         EE_Registry::instance()->load_helper('DTT_Helper');
78 78
         $tasks['AHEE__EE_Messages_Scheduler__generation'] = 'ee_message_cron';
79 79
         $tasks['AHEE__EE_Messages_Scheduler__sending']    = 'ee_message_cron';
80
-        $tasks['AHEE__EE_Messages_Scheduler__cleanup'] = array( EEH_DTT_Helper::tomorrow(), 'daily');
80
+        $tasks['AHEE__EE_Messages_Scheduler__cleanup'] = array(EEH_DTT_Helper::tomorrow(), 'daily');
81 81
         return $tasks;
82 82
     }
83 83
 
@@ -96,7 +96,7 @@  discard block
 block discarded – undo
96 96
                 true
97 97
             )
98 98
         ) {
99
-            $request_url  = add_query_arg(
99
+            $request_url = add_query_arg(
100 100
                 array_merge(
101 101
                     array('ee' => 'msg_cron_trigger'),
102 102
                     EE_Messages_Scheduler::get_request_params($task)
@@ -109,7 +109,7 @@  discard block
 block discarded – undo
109 109
                 'sslverify'   => false,
110 110
                 'redirection' => 10,
111 111
             );
112
-            $response     = wp_remote_get($request_url, $request_args);
112
+            $response = wp_remote_get($request_url, $request_args);
113 113
             if (is_wp_error($response)) {
114 114
                 trigger_error($response->get_error_message());
115 115
             }
@@ -129,7 +129,7 @@  discard block
 block discarded – undo
129 129
     public static function get_request_params($task)
130 130
     {
131 131
         // transient is used for flood control on msg_cron_trigger requests
132
-        $transient_key = 'ee_trans_' . uniqid($task);
132
+        $transient_key = 'ee_trans_'.uniqid($task);
133 133
         set_transient($transient_key, 1, 5 * MINUTE_IN_SECONDS);
134 134
         return array(
135 135
             'type' => $task,
@@ -202,7 +202,7 @@  discard block
 block discarded – undo
202 202
             'AHEE__EE_Messages_Scheduler__sending'    => 'ee_message_cron',
203 203
         );
204 204
         foreach ($message_crons_to_check as $hook_name => $frequency) {
205
-            if (! wp_next_scheduled($hook_name)) {
205
+            if ( ! wp_next_scheduled($hook_name)) {
206 206
                 wp_schedule_event(time(), $frequency, $hook_name);
207 207
             }
208 208
         }
Please login to merge, or discard this patch.
Indentation   +221 added lines, -221 removed lines patch added patch discarded remove patch
@@ -13,225 +13,225 @@
 block discarded – undo
13 13
  */
14 14
 class EE_Messages_Scheduler extends EE_Base
15 15
 {
16
-    /**
17
-     * Number of seconds between batch sends/generates on the cron job.
18
-     * Defaults to 5 minutes in seconds.  If you want to change this interval, you can use the native WordPress
19
-     * `cron_schedules` filter and modify the existing custom `ee_message_cron` schedule interval added.
20
-     *
21
-     * @type int
22
-     */
23
-    const message_cron_schedule = 300;
24
-
25
-    /**
26
-     * Constructor
27
-     */
28
-    public function __construct()
29
-    {
30
-        // register tasks (and make sure only registered once).
31
-        if (! has_action('FHEE__EEH_Activation__get_cron_tasks', array($this, 'register_scheduled_tasks'))) {
32
-            add_action('FHEE__EEH_Activation__get_cron_tasks', array($this, 'register_scheduled_tasks'), 10);
33
-        }
34
-
35
-        // register callbacks for scheduled events (but make sure they are set only once).
36
-        if (
37
-            ! has_action(
38
-                'AHEE__EE_Messages_Scheduler__generation',
39
-                array('EE_Messages_Scheduler', 'batch_generation')
40
-            )
41
-        ) {
42
-            add_action('AHEE__EE_Messages_Scheduler__generation', array('EE_Messages_Scheduler', 'batch_generation'));
43
-            add_action('AHEE__EE_Messages_Scheduler__sending', array('EE_Messages_Scheduler', 'batch_sending'));
44
-            add_action('AHEE__EE_Messages_Scheduler__cleanup', array('EE_Messages_Scheduler', 'cleanup'));
45
-        }
46
-
47
-        // add custom schedules
48
-        add_filter('cron_schedules', array($this, 'custom_schedules'));
49
-    }
50
-
51
-
52
-    /**
53
-     * Add custom schedules for wp_cron
54
-     *
55
-     * @param $schedules
56
-     */
57
-    public function custom_schedules($schedules)
58
-    {
59
-        $schedules['ee_message_cron'] = array(
60
-            'interval' => self::message_cron_schedule,
61
-            'display'  => esc_html__(
62
-                'This is the cron time interval for EE Message schedules (defaults to once every 5 minutes)',
63
-                'event_espresso'
64
-            ),
65
-        );
66
-        return $schedules;
67
-    }
68
-
69
-
70
-    /**
71
-     * Callback for FHEE__EEH_Activation__get_cron_tasks that is used to retrieve scheduled Cron events to add and
72
-     * remove.
73
-     *
74
-     * @param array $tasks already existing scheduled tasks
75
-     * @return array
76
-     * @throws EE_Error
77
-     * @throws ReflectionException
78
-     */
79
-    public function register_scheduled_tasks($tasks)
80
-    {
81
-        EE_Registry::instance()->load_helper('DTT_Helper');
82
-        $tasks['AHEE__EE_Messages_Scheduler__generation'] = 'ee_message_cron';
83
-        $tasks['AHEE__EE_Messages_Scheduler__sending']    = 'ee_message_cron';
84
-        $tasks['AHEE__EE_Messages_Scheduler__cleanup'] = array( EEH_DTT_Helper::tomorrow(), 'daily');
85
-        return $tasks;
86
-    }
87
-
88
-
89
-    /**
90
-     * This initiates a non-blocking separate request to execute on a scheduled task.
91
-     * Note: The EED_Messages module has the handlers for these requests.
92
-     *
93
-     * @param string $task The task the request is being generated for.
94
-     */
95
-    public static function initiate_scheduled_non_blocking_request($task)
96
-    {
97
-        if (
98
-            apply_filters(
99
-                'EE_Messages_Scheduler__initiate_scheduled_non_blocking_request__do_separate_request',
100
-                true
101
-            )
102
-        ) {
103
-            $request_url  = add_query_arg(
104
-                array_merge(
105
-                    array('ee' => 'msg_cron_trigger'),
106
-                    EE_Messages_Scheduler::get_request_params($task)
107
-                ),
108
-                site_url()
109
-            );
110
-            $request_args = array(
111
-                'timeout'     => 300,
112
-                'blocking'    => (defined('DOING_CRON') && DOING_CRON)
113
-                                 || (defined('DOING_AJAX') && DOING_AJAX),
114
-                'sslverify'   => false,
115
-                'redirection' => 10,
116
-            );
117
-            $response     = wp_remote_get($request_url, $request_args);
118
-            if (is_wp_error($response)) {
119
-                trigger_error($response->get_error_message());
120
-            }
121
-        } else {
122
-            EE_Messages_Scheduler::initiate_immediate_request_on_cron($task);
123
-        }
124
-    }
125
-
126
-
127
-    /**
128
-     * This returns
129
-     * the request params used for a scheduled message task request.
130
-     *
131
-     * @param string $task The task the request is for.
132
-     * @return array
133
-     */
134
-    public static function get_request_params($task)
135
-    {
136
-        // transient is used for flood control on msg_cron_trigger requests
137
-        $transient_key = 'ee_trans_' . uniqid($task);
138
-        set_transient($transient_key, 1, 5 * MINUTE_IN_SECONDS);
139
-        return array(
140
-            'type' => $task,
141
-            'key'  => $transient_key,
142
-        );
143
-    }
144
-
145
-
146
-    /**
147
-     * This is used to execute an immediate call to the run_cron task performed by EED_Messages
148
-     *
149
-     * @param string $task The task the request is being generated for.
150
-     */
151
-    public static function initiate_immediate_request_on_cron($task)
152
-    {
153
-        /** @var RequestInterface $request */
154
-        $request = LoaderFactory::getLoader()->getShared(RequestInterface::class);
155
-        $request_args = EE_Messages_Scheduler::get_request_params($task);
156
-        // set those request args in the request so it gets picked up
157
-        foreach ($request_args as $request_key => $request_value) {
158
-            $request->setRequestParam($request_key, $request_value);
159
-        }
160
-        EED_Messages::instance()->run_cron();
161
-    }
162
-
163
-
164
-    /**
165
-     * Callback for scheduled AHEE__EE_Messages_Scheduler__generation wp cron event
166
-     */
167
-    public static function batch_generation()
168
-    {
169
-        /**
170
-         * @see filter usage in EE_Messages_Queue::initiate_request_by_priority()
171
-         */
172
-        if (
173
-            ! apply_filters('FHEE__EE_Messages_Processor__initiate_request_by_priority__do_immediate_processing', false)
174
-            || ! EE_Registry::instance()->NET_CFG->core->do_messages_on_same_request
175
-        ) {
176
-            EE_Messages_Scheduler::initiate_immediate_request_on_cron('generate');
177
-        }
178
-    }
179
-
180
-
181
-    /**
182
-     * Callback for scheduled AHEE__EE_Messages_Scheduler__sending
183
-     */
184
-    public static function batch_sending()
185
-    {
186
-        /**
187
-         * @see filter usage in EE_Messages_Queue::initiate_request_by_priority()
188
-         */
189
-        if (
190
-            ! apply_filters('FHEE__EE_Messages_Processor__initiate_request_by_priority__do_immediate_processing', false)
191
-            || ! EE_Registry::instance()->NET_CFG->core->do_messages_on_same_request
192
-        ) {
193
-            EE_Messages_Scheduler::initiate_immediate_request_on_cron('send');
194
-        }
195
-    }
196
-
197
-
198
-    /**
199
-     * This is the callback for the `AHEE__EE_Messages_Scheduler__cleanup` scheduled event action.
200
-     * This runs once a day and if cleanup is active (set via messages settings), it will (by default) delete
201
-     * permanently from the database messages that have a MSG_modified date older than 30 days.
202
-     *
203
-     * @throws EE_Error
204
-     * @throws EE_Error
205
-     */
206
-    public static function cleanup()
207
-    {
208
-        // First, confirm that the generation and sending EE_Messages_Scheduler crons are
209
-        // set and reschedule them if they are not.
210
-        $message_crons_to_check = array(
211
-            'AHEE__EE_Messages_Scheduler__generation' => 'ee_message_cron',
212
-            'AHEE__EE_Messages_Scheduler__sending'    => 'ee_message_cron',
213
-        );
214
-        foreach ($message_crons_to_check as $hook_name => $frequency) {
215
-            if (! wp_next_scheduled($hook_name)) {
216
-                wp_schedule_event(time(), $frequency, $hook_name);
217
-            }
218
-        }
219
-
220
-        // check if user has cleanup turned on or if we're in maintenance mode.  If in maintenance mode we'll wait
221
-        // until the next scheduled event.
222
-        if (
223
-            ! EE_Registry::instance()->CFG->messages->delete_threshold
224
-            || ! EE_Maintenance_Mode::instance()->models_can_query()
225
-        ) {
226
-            return;
227
-        }
228
-
229
-        /**
230
-         * This filter switch allows other code (such as the EE_Worker_Queue add-on) to replace this with its own handling
231
-         * of deleting messages.
232
-         */
233
-        if (apply_filters('FHEE__EE_Messages_Scheduler__cleanup__handle_cleanup_on_cron', true)) {
234
-            EEM_Message::instance()->delete_old_messages(EE_Registry::instance()->CFG->messages->delete_threshold);
235
-        }
236
-    }
16
+	/**
17
+	 * Number of seconds between batch sends/generates on the cron job.
18
+	 * Defaults to 5 minutes in seconds.  If you want to change this interval, you can use the native WordPress
19
+	 * `cron_schedules` filter and modify the existing custom `ee_message_cron` schedule interval added.
20
+	 *
21
+	 * @type int
22
+	 */
23
+	const message_cron_schedule = 300;
24
+
25
+	/**
26
+	 * Constructor
27
+	 */
28
+	public function __construct()
29
+	{
30
+		// register tasks (and make sure only registered once).
31
+		if (! has_action('FHEE__EEH_Activation__get_cron_tasks', array($this, 'register_scheduled_tasks'))) {
32
+			add_action('FHEE__EEH_Activation__get_cron_tasks', array($this, 'register_scheduled_tasks'), 10);
33
+		}
34
+
35
+		// register callbacks for scheduled events (but make sure they are set only once).
36
+		if (
37
+			! has_action(
38
+				'AHEE__EE_Messages_Scheduler__generation',
39
+				array('EE_Messages_Scheduler', 'batch_generation')
40
+			)
41
+		) {
42
+			add_action('AHEE__EE_Messages_Scheduler__generation', array('EE_Messages_Scheduler', 'batch_generation'));
43
+			add_action('AHEE__EE_Messages_Scheduler__sending', array('EE_Messages_Scheduler', 'batch_sending'));
44
+			add_action('AHEE__EE_Messages_Scheduler__cleanup', array('EE_Messages_Scheduler', 'cleanup'));
45
+		}
46
+
47
+		// add custom schedules
48
+		add_filter('cron_schedules', array($this, 'custom_schedules'));
49
+	}
50
+
51
+
52
+	/**
53
+	 * Add custom schedules for wp_cron
54
+	 *
55
+	 * @param $schedules
56
+	 */
57
+	public function custom_schedules($schedules)
58
+	{
59
+		$schedules['ee_message_cron'] = array(
60
+			'interval' => self::message_cron_schedule,
61
+			'display'  => esc_html__(
62
+				'This is the cron time interval for EE Message schedules (defaults to once every 5 minutes)',
63
+				'event_espresso'
64
+			),
65
+		);
66
+		return $schedules;
67
+	}
68
+
69
+
70
+	/**
71
+	 * Callback for FHEE__EEH_Activation__get_cron_tasks that is used to retrieve scheduled Cron events to add and
72
+	 * remove.
73
+	 *
74
+	 * @param array $tasks already existing scheduled tasks
75
+	 * @return array
76
+	 * @throws EE_Error
77
+	 * @throws ReflectionException
78
+	 */
79
+	public function register_scheduled_tasks($tasks)
80
+	{
81
+		EE_Registry::instance()->load_helper('DTT_Helper');
82
+		$tasks['AHEE__EE_Messages_Scheduler__generation'] = 'ee_message_cron';
83
+		$tasks['AHEE__EE_Messages_Scheduler__sending']    = 'ee_message_cron';
84
+		$tasks['AHEE__EE_Messages_Scheduler__cleanup'] = array( EEH_DTT_Helper::tomorrow(), 'daily');
85
+		return $tasks;
86
+	}
87
+
88
+
89
+	/**
90
+	 * This initiates a non-blocking separate request to execute on a scheduled task.
91
+	 * Note: The EED_Messages module has the handlers for these requests.
92
+	 *
93
+	 * @param string $task The task the request is being generated for.
94
+	 */
95
+	public static function initiate_scheduled_non_blocking_request($task)
96
+	{
97
+		if (
98
+			apply_filters(
99
+				'EE_Messages_Scheduler__initiate_scheduled_non_blocking_request__do_separate_request',
100
+				true
101
+			)
102
+		) {
103
+			$request_url  = add_query_arg(
104
+				array_merge(
105
+					array('ee' => 'msg_cron_trigger'),
106
+					EE_Messages_Scheduler::get_request_params($task)
107
+				),
108
+				site_url()
109
+			);
110
+			$request_args = array(
111
+				'timeout'     => 300,
112
+				'blocking'    => (defined('DOING_CRON') && DOING_CRON)
113
+								 || (defined('DOING_AJAX') && DOING_AJAX),
114
+				'sslverify'   => false,
115
+				'redirection' => 10,
116
+			);
117
+			$response     = wp_remote_get($request_url, $request_args);
118
+			if (is_wp_error($response)) {
119
+				trigger_error($response->get_error_message());
120
+			}
121
+		} else {
122
+			EE_Messages_Scheduler::initiate_immediate_request_on_cron($task);
123
+		}
124
+	}
125
+
126
+
127
+	/**
128
+	 * This returns
129
+	 * the request params used for a scheduled message task request.
130
+	 *
131
+	 * @param string $task The task the request is for.
132
+	 * @return array
133
+	 */
134
+	public static function get_request_params($task)
135
+	{
136
+		// transient is used for flood control on msg_cron_trigger requests
137
+		$transient_key = 'ee_trans_' . uniqid($task);
138
+		set_transient($transient_key, 1, 5 * MINUTE_IN_SECONDS);
139
+		return array(
140
+			'type' => $task,
141
+			'key'  => $transient_key,
142
+		);
143
+	}
144
+
145
+
146
+	/**
147
+	 * This is used to execute an immediate call to the run_cron task performed by EED_Messages
148
+	 *
149
+	 * @param string $task The task the request is being generated for.
150
+	 */
151
+	public static function initiate_immediate_request_on_cron($task)
152
+	{
153
+		/** @var RequestInterface $request */
154
+		$request = LoaderFactory::getLoader()->getShared(RequestInterface::class);
155
+		$request_args = EE_Messages_Scheduler::get_request_params($task);
156
+		// set those request args in the request so it gets picked up
157
+		foreach ($request_args as $request_key => $request_value) {
158
+			$request->setRequestParam($request_key, $request_value);
159
+		}
160
+		EED_Messages::instance()->run_cron();
161
+	}
162
+
163
+
164
+	/**
165
+	 * Callback for scheduled AHEE__EE_Messages_Scheduler__generation wp cron event
166
+	 */
167
+	public static function batch_generation()
168
+	{
169
+		/**
170
+		 * @see filter usage in EE_Messages_Queue::initiate_request_by_priority()
171
+		 */
172
+		if (
173
+			! apply_filters('FHEE__EE_Messages_Processor__initiate_request_by_priority__do_immediate_processing', false)
174
+			|| ! EE_Registry::instance()->NET_CFG->core->do_messages_on_same_request
175
+		) {
176
+			EE_Messages_Scheduler::initiate_immediate_request_on_cron('generate');
177
+		}
178
+	}
179
+
180
+
181
+	/**
182
+	 * Callback for scheduled AHEE__EE_Messages_Scheduler__sending
183
+	 */
184
+	public static function batch_sending()
185
+	{
186
+		/**
187
+		 * @see filter usage in EE_Messages_Queue::initiate_request_by_priority()
188
+		 */
189
+		if (
190
+			! apply_filters('FHEE__EE_Messages_Processor__initiate_request_by_priority__do_immediate_processing', false)
191
+			|| ! EE_Registry::instance()->NET_CFG->core->do_messages_on_same_request
192
+		) {
193
+			EE_Messages_Scheduler::initiate_immediate_request_on_cron('send');
194
+		}
195
+	}
196
+
197
+
198
+	/**
199
+	 * This is the callback for the `AHEE__EE_Messages_Scheduler__cleanup` scheduled event action.
200
+	 * This runs once a day and if cleanup is active (set via messages settings), it will (by default) delete
201
+	 * permanently from the database messages that have a MSG_modified date older than 30 days.
202
+	 *
203
+	 * @throws EE_Error
204
+	 * @throws EE_Error
205
+	 */
206
+	public static function cleanup()
207
+	{
208
+		// First, confirm that the generation and sending EE_Messages_Scheduler crons are
209
+		// set and reschedule them if they are not.
210
+		$message_crons_to_check = array(
211
+			'AHEE__EE_Messages_Scheduler__generation' => 'ee_message_cron',
212
+			'AHEE__EE_Messages_Scheduler__sending'    => 'ee_message_cron',
213
+		);
214
+		foreach ($message_crons_to_check as $hook_name => $frequency) {
215
+			if (! wp_next_scheduled($hook_name)) {
216
+				wp_schedule_event(time(), $frequency, $hook_name);
217
+			}
218
+		}
219
+
220
+		// check if user has cleanup turned on or if we're in maintenance mode.  If in maintenance mode we'll wait
221
+		// until the next scheduled event.
222
+		if (
223
+			! EE_Registry::instance()->CFG->messages->delete_threshold
224
+			|| ! EE_Maintenance_Mode::instance()->models_can_query()
225
+		) {
226
+			return;
227
+		}
228
+
229
+		/**
230
+		 * This filter switch allows other code (such as the EE_Worker_Queue add-on) to replace this with its own handling
231
+		 * of deleting messages.
232
+		 */
233
+		if (apply_filters('FHEE__EE_Messages_Scheduler__cleanup__handle_cleanup_on_cron', true)) {
234
+			EEM_Message::instance()->delete_old_messages(EE_Registry::instance()->CFG->messages->delete_threshold);
235
+		}
236
+	}
237 237
 }
Please login to merge, or discard this patch.
core/libraries/messages/data_class/EE_Messages_incoming_data.core.php 2 patches
Spacing   +47 added lines, -47 removed lines patch added patch discarded remove patch
@@ -332,7 +332,7 @@  discard block
 block discarded – undo
332 332
         $answers            = $questions = $attendees = $line_items = $registrations = array();
333 333
         $total_ticket_count = 0;
334 334
 
335
-        if (! empty($this->reg_objs)) {
335
+        if ( ! empty($this->reg_objs)) {
336 336
             $event_attendee_count = array();
337 337
             /** @var EE_Registration $reg */
338 338
             foreach ($this->reg_objs as $reg) {
@@ -344,7 +344,7 @@  discard block
 block discarded – undo
344 344
 
345 345
                 $evt_id = $reg->event_ID();
346 346
                 /** @type EE_Ticket $ticket */
347
-                $ticket          = $reg->get_first_related('Ticket');
347
+                $ticket = $reg->get_first_related('Ticket');
348 348
                 $attendee = $reg->attendee();
349 349
                 $event = $reg->event();
350 350
                 // if none of the following entities are available, then we can't setup other data reliably,
@@ -358,67 +358,67 @@  discard block
 block discarded – undo
358 358
                 }
359 359
                 $relateddatetime = $ticket->datetimes();
360 360
                 $total_ticket_count++;
361
-                $tickets[ $ticket->ID() ]['ticket']                        = $ticket;
362
-                $tickets[ $ticket->ID() ]['count']                         = is_array($tickets[ $ticket->ID() ])
363
-                                                                           && isset($tickets[ $ticket->ID() ]['count'])
364
-                    ? $tickets[ $ticket->ID() ]['count'] + 1
361
+                $tickets[$ticket->ID()]['ticket']                        = $ticket;
362
+                $tickets[$ticket->ID()]['count']                         = is_array($tickets[$ticket->ID()])
363
+                                                                           && isset($tickets[$ticket->ID()]['count'])
364
+                    ? $tickets[$ticket->ID()]['count'] + 1
365 365
                     : 1;
366
-                $tickets[ $ticket->ID() ]['att_objs'][ $attendee->ID() ] = $attendee;
367
-                $tickets[ $ticket->ID() ]['dtt_objs']                      = $relateddatetime;
368
-                $tickets[ $ticket->ID() ]['reg_objs'][ $reg->ID() ]          = $reg;
369
-                $tickets[ $ticket->ID() ]['EE_Event']                      = $event;
370
-                $evtcache[ $evt_id ]                                       = $event;
371
-                $eventsetup[ $evt_id ]['reg_objs'][ $reg->ID() ]             = $reg;
372
-                $eventsetup[ $evt_id ]['tkt_objs'][ $ticket->ID() ]          = $ticket;
373
-                $eventsetup[ $evt_id ]['att_objs'][ $attendee->ID() ]    = $attendee;
374
-                $event_attendee_count[ $evt_id ]                           = isset($event_attendee_count[ $evt_id ])
375
-                    ? $event_attendee_count[ $evt_id ] + 1
366
+                $tickets[$ticket->ID()]['att_objs'][$attendee->ID()] = $attendee;
367
+                $tickets[$ticket->ID()]['dtt_objs']                      = $relateddatetime;
368
+                $tickets[$ticket->ID()]['reg_objs'][$reg->ID()]          = $reg;
369
+                $tickets[$ticket->ID()]['EE_Event']                      = $event;
370
+                $evtcache[$evt_id]                                       = $event;
371
+                $eventsetup[$evt_id]['reg_objs'][$reg->ID()]             = $reg;
372
+                $eventsetup[$evt_id]['tkt_objs'][$ticket->ID()]          = $ticket;
373
+                $eventsetup[$evt_id]['att_objs'][$attendee->ID()] = $attendee;
374
+                $event_attendee_count[$evt_id]                           = isset($event_attendee_count[$evt_id])
375
+                    ? $event_attendee_count[$evt_id] + 1
376 376
                     : 0;
377
-                $attendees[ $reg->attendee_ID() ]['line_ref'][]            = $evt_id;
378
-                $attendees[ $reg->attendee_ID() ]['att_obj']               = $attendee;
379
-                $attendees[ $reg->attendee_ID() ]['reg_objs'][ $reg->ID() ]  = $reg;
377
+                $attendees[$reg->attendee_ID()]['line_ref'][]            = $evt_id;
378
+                $attendees[$reg->attendee_ID()]['att_obj']               = $attendee;
379
+                $attendees[$reg->attendee_ID()]['reg_objs'][$reg->ID()]  = $reg;
380 380
                 // $attendees[ $reg->attendee_ID() ]['registration_id'] = $reg->ID();
381
-                $attendees[ $reg->attendee_ID() ]['attendee_email']          = $attendee->email();
382
-                $attendees[ $reg->attendee_ID() ]['tkt_objs'][ $ticket->ID() ] = $ticket;
383
-                $attendees[ $reg->attendee_ID() ]['evt_objs'][ $evt_id ]       = $event;
381
+                $attendees[$reg->attendee_ID()]['attendee_email']          = $attendee->email();
382
+                $attendees[$reg->attendee_ID()]['tkt_objs'][$ticket->ID()] = $ticket;
383
+                $attendees[$reg->attendee_ID()]['evt_objs'][$evt_id]       = $event;
384 384
 
385 385
                 // registrations
386
-                $registrations[ $reg->ID() ]['tkt_obj'] = $ticket;
387
-                $registrations[ $reg->ID() ]['evt_obj'] = $event;
388
-                $registrations[ $reg->ID() ]['reg_obj'] = $reg;
389
-                $registrations[ $reg->ID() ]['att_obj'] = $attendee;
386
+                $registrations[$reg->ID()]['tkt_obj'] = $ticket;
387
+                $registrations[$reg->ID()]['evt_obj'] = $event;
388
+                $registrations[$reg->ID()]['reg_obj'] = $reg;
389
+                $registrations[$reg->ID()]['att_obj'] = $attendee;
390 390
 
391 391
                 // set up answer objects
392 392
                 $rel_ans = $reg->get_many_related('Answer');
393 393
                 foreach ($rel_ans as $ansid => $answer) {
394
-                    if (! isset($questions[ $ansid ])) {
395
-                        $questions[ $ansid ] = $answer->get_first_related('Question');
394
+                    if ( ! isset($questions[$ansid])) {
395
+                        $questions[$ansid] = $answer->get_first_related('Question');
396 396
                     }
397
-                    $answers[ $ansid ]                               = $answer;
398
-                    $registrations[ $reg->ID() ]['ans_objs'][ $ansid ] = $answer;
397
+                    $answers[$ansid] = $answer;
398
+                    $registrations[$reg->ID()]['ans_objs'][$ansid] = $answer;
399 399
                 }
400 400
                 /**
401 401
                  * @var int $dtt_id
402 402
                  * @var EE_Datetime $datetime
403 403
                  */
404 404
                 foreach ($relateddatetime as $dtt_id => $datetime) {
405
-                    $eventsetup[ $evt_id ]['dtt_objs'][ $dtt_id ]       = $datetime;
406
-                    $registrations[ $reg->ID() ]['dtt_objs'][ $dtt_id ] = $datetime;
405
+                    $eventsetup[$evt_id]['dtt_objs'][$dtt_id]       = $datetime;
406
+                    $registrations[$reg->ID()]['dtt_objs'][$dtt_id] = $datetime;
407 407
 
408
-                    if (isset($datetimes[ $dtt_id ])) {
408
+                    if (isset($datetimes[$dtt_id])) {
409 409
                         continue; // already have this info in the datetimes array.
410 410
                     }
411 411
 
412
-                    $datetimes[ $dtt_id ]['tkt_objs'][]           = $ticket;
413
-                    $datetimes[ $dtt_id ]['datetime']             = $datetime;
414
-                    $datetimes[ $dtt_id ]['evt_objs'][ $evt_id ]    = $event;
415
-                    $datetimes[ $dtt_id ]['reg_objs'][ $reg->ID() ] = $reg;
412
+                    $datetimes[$dtt_id]['tkt_objs'][]           = $ticket;
413
+                    $datetimes[$dtt_id]['datetime']             = $datetime;
414
+                    $datetimes[$dtt_id]['evt_objs'][$evt_id]    = $event;
415
+                    $datetimes[$dtt_id]['reg_objs'][$reg->ID()] = $reg;
416 416
                 }
417 417
             }
418 418
 
419 419
             // let's loop through the unique event=>reg items and setup data on them
420 420
 
421
-            if (! empty($eventsetup)) {
421
+            if ( ! empty($eventsetup)) {
422 422
                 foreach ($eventsetup as $evt_id => $items) {
423 423
                     $ticket_line_items_for_event = array();
424 424
                     if ($this->txn instanceof EE_Transaction) {
@@ -432,11 +432,11 @@  discard block
 block discarded – undo
432 432
                             )
433 433
                         );
434 434
                     }
435
-                    $events[ $evt_id ] = array(
435
+                    $events[$evt_id] = array(
436 436
                         'ID'              => $evt_id,
437
-                        'event'           => $evtcache[ $evt_id ],
438
-                        'name'            => $evtcache[ $evt_id ] instanceof EE_Event ? $evtcache[ $evt_id ]->name() : '',
439
-                        'total_attendees' => $event_attendee_count[ $evt_id ],
437
+                        'event'           => $evtcache[$evt_id],
438
+                        'name'            => $evtcache[$evt_id] instanceof EE_Event ? $evtcache[$evt_id]->name() : '',
439
+                        'total_attendees' => $event_attendee_count[$evt_id],
440 440
                         'reg_objs'        => $items['reg_objs'],
441 441
                         'tkt_objs'        => $items['tkt_objs'],
442 442
                         'att_objs'        => $items['att_objs'],
@@ -447,11 +447,11 @@  discard block
 block discarded – undo
447 447
                     // make sure the tickets have the line items setup for them.
448 448
                     foreach ($ticket_line_items_for_event as $line_id => $line_item) {
449 449
                         // only add the ticket line items if we already have this ticket in the $tickets array.
450
-                        if ($line_item instanceof EE_Line_Item && isset($tickets[ $line_item->ticket()->ID() ])) {
451
-                            $tickets[ $line_item->ticket()->ID() ]['line_item']      = $line_item;
452
-                            $tickets[ $line_item->ticket()->ID() ]['sub_line_items'] = $line_item->children();
453
-                            $line_items[ $line_item->ID() ]['children']              = $line_item->children();
454
-                            $line_items[ $line_item->ID() ]['EE_Ticket']             = $line_item->ticket();
450
+                        if ($line_item instanceof EE_Line_Item && isset($tickets[$line_item->ticket()->ID()])) {
451
+                            $tickets[$line_item->ticket()->ID()]['line_item']      = $line_item;
452
+                            $tickets[$line_item->ticket()->ID()]['sub_line_items'] = $line_item->children();
453
+                            $line_items[$line_item->ID()]['children']              = $line_item->children();
454
+                            $line_items[$line_item->ID()]['EE_Ticket']             = $line_item->ticket();
455 455
                         }
456 456
                     }
457 457
                 }
Please login to merge, or discard this patch.
Indentation   +518 added lines, -518 removed lines patch added patch discarded remove patch
@@ -16,522 +16,522 @@
 block discarded – undo
16 16
  */
17 17
 abstract class EE_Messages_incoming_data
18 18
 {
19
-    /**
20
-     * user id for logged in user when data collected
21
-     *
22
-     * @var string $user_id
23
-     */
24
-    public $user_id;
25
-
26
-    /**
27
-     * IP Address of browser used
28
-     *
29
-     * @var string $ip_address
30
-     */
31
-    public $ip_address;
32
-
33
-    /**
34
-     * browser
35
-     *
36
-     * @var string $user_agent
37
-     */
38
-    public $user_agent;
39
-
40
-    /**
41
-     * Unix timestamp
42
-     *
43
-     * @var string $init_access
44
-     */
45
-    public $init_access;
46
-
47
-    /**
48
-     * Unix timestamp
49
-     *
50
-     * @var string $last_access
51
-     */
52
-    public $last_access;
53
-
54
-    /**
55
-     * The registrations details from the cart
56
-     *
57
-     * @var array $reg_info
58
-     */
59
-    public $reg_info;
60
-
61
-    /**
62
-     * Some data handlers can set what reg status all the registrations are filtered by.
63
-     * The status should match a EEM_Registration status constant.
64
-     *
65
-     * @var string $filtered_reg_status
66
-     */
67
-    public $filtered_reg_status;
68
-
69
-    /**
70
-     * will hold an array of events assembled from $reg_info
71
-     *
72
-     * @var EE_Event[] $events
73
-     */
74
-    public $events;
75
-
76
-    /**
77
-     * holds an array of datetimes assembled from the incoming data.
78
-     *
79
-     * @var EE_Datetime[] $datetimes
80
-     */
81
-    public $datetimes;
82
-
83
-    /**
84
-     * holds an array of tickets assembled from the incoming data.
85
-     *
86
-     * @var EE_Ticket[] $tickets
87
-     */
88
-    public $tickets;
89
-
90
-    /**
91
-     * holds an array with a key of parent line item and values are an array of children of that line item.
92
-     *
93
-     * @since 4.5.0
94
-     * @var EE_Line_Item[] $line_items_with_children
95
-     */
96
-    public $line_items_with_children;
97
-
98
-    /**
99
-     * will hold an array of attendees assembled from the $reg_info
100
-     *
101
-     * @var EE_Attendee[] $attendees
102
-     */
103
-    public $attendees;
104
-
105
-    /**
106
-     * will hold an array of cached registration objects and info assembled from reg_info
107
-     *
108
-     * @var array $registrations
109
-     */
110
-    public $registrations;
111
-
112
-    /**
113
-     * will hold an array of answers assembled from the $reg_info
114
-     *
115
-     * @var EE_Answer[] $answers
116
-     */
117
-    public $answers;
118
-
119
-    /**
120
-     * will hold an array of questions assembled from the $reg_info (indexed by Answer ID);
121
-     *
122
-     * @var EE_Question[] $questions
123
-     */
124
-    public $questions;
125
-
126
-    /**
127
-     * Will hold billing data assembled from $billing_info (if present)
128
-     *
129
-     * @var mixed (array|null) $billing
130
-     */
131
-    public $billing;
132
-
133
-    /**
134
-     * The total amount of tax for the transaction
135
-     *
136
-     * @var float $taxes
137
-     */
138
-    public $taxes;
139
-
140
-    /**
141
-     * Holds the line items related to taxes
142
-     *
143
-     * @since 4.5.0
144
-     * @var EE_Line_Item[] $tax_line_items
145
-     */
146
-    public $tax_line_items;
147
-
148
-    /**
149
-     * Hold the line items which aren't taxes and don't relate
150
-     * to tickets. So: promotions and miscellaneous charges
151
-     *
152
-     * @since 4.5
153
-     * @var EE_Line_Item[] $additional_line_items
154
-     */
155
-    public $additional_line_items;
156
-
157
-    /**
158
-     * Holds the grand total EE_Line_Item
159
-     *
160
-     * @var EE_Line_Item $grand_total_line_item
161
-     */
162
-    public $grand_total_line_item;
163
-
164
-    /**
165
-     * holds the grand total price object
166
-     * currently not used.
167
-     *
168
-     * @var null $grand_total_price_object
169
-     */
170
-    public $grand_total_price_object;
171
-
172
-    /**
173
-     * total number of tickets
174
-     *
175
-     * @var int $total_ticket_count
176
-     */
177
-    public $total_ticket_count;
178
-
179
-    /**
180
-     * Will hold the final transaction object (EE_Transaction)
181
-     *
182
-     * @var EE_Transaction $txn
183
-     */
184
-    public $txn;
185
-
186
-    /**
187
-     * Holds the payments related to a transaction
188
-     *
189
-     * @since 4.5.0
190
-     * @var EE_Payment[] $payments
191
-     */
192
-    public $payments;
193
-
194
-    /**
195
-     * Holds the first related payment related for a transaction
196
-     *
197
-     * @since 4.5.0
198
-     * @var EE_Payment $payment
199
-     */
200
-    public $payment;
201
-
202
-    /**
203
-     * Will hold the label for the txn status
204
-     *
205
-     * @var string $txn_status
206
-     */
207
-    public $txn_status;
208
-
209
-    /**
210
-     * Will hold the final registration object (EE_Registration)
211
-     *
212
-     * @var EE_Registration[] $reg_objs
213
-     */
214
-    public $reg_objs;
215
-
216
-    /**
217
-     * Will hold an array of primary attendee data (if present)
218
-     *
219
-     * @var array $primary_attendee_data
220
-     */
221
-    public $primary_attendee_data;
222
-
223
-    /**
224
-     * This is just an internal object used for passing around the incoming data.
225
-     *
226
-     * @var mixed $_data
227
-     */
228
-    protected $_data;
229
-
230
-    /**
231
-     * This is just an internal object used for passing around the incoming data.
232
-     *
233
-     * @var mixed $incoming_data
234
-     */
235
-    public $incoming_data;
236
-
237
-    /**
238
-     * hold objects that might be created
239
-     *
240
-     * @type EE_Registration $reg_obj
241
-     */
242
-    public $reg_obj;
243
-
244
-
245
-    /**
246
-     * constructor
247
-     *
248
-     * @param mixed $data incoming data object|array.  Suggested that child classes use type hinting for expected
249
-     *                    data object.  But here parent will be generic because we don't know what's coming in.
250
-     */
251
-    public function __construct($data)
252
-    {
253
-        $this->_data = $data;
254
-        $this->_setup_data();
255
-    }
256
-
257
-
258
-    /**
259
-     * Every child class has to setup the data object !
260
-     *
261
-     * @return void
262
-     */
263
-    abstract protected function _setup_data();
264
-
265
-
266
-    /**
267
-     * Returns database safe representation of the data later used to when instantiating this object.
268
-     *
269
-     * @param mixed $data The incoming data to be prepped.
270
-     * @return mixed   The prepped data for db
271
-     */
272
-    public static function convert_data_for_persistent_storage($data)
273
-    {
274
-        return $data;
275
-    }
276
-
277
-
278
-    /**
279
-     * Data that has been stored in persistent storage that was prepped by _convert_data_for_persistent_storage
280
-     * can be sent into this method and converted back into the format used for instantiating with this data handler.
281
-     *
282
-     * @param $data
283
-     * @return mixed
284
-     */
285
-    public static function convert_data_from_persistent_storage($data)
286
-    {
287
-        return $data;
288
-    }
289
-
290
-
291
-    /**
292
-     * only purpose is to return the data
293
-     *
294
-     * @access public
295
-     * @return mixed the formatted data object!
296
-     */
297
-    public function data()
298
-    {
299
-        return $this->_data;
300
-    }
301
-
302
-
303
-    /**
304
-     * This helper method can be used by any incoming data handlers to setup the data correctly.  All that is required
305
-     * is that $this->reg_objs be set.
306
-     *
307
-     * @throws EE_Error
308
-     * @throws InvalidDataTypeException
309
-     * @throws InvalidInterfaceException
310
-     * @throws InvalidArgumentException
311
-     * @throws EntityNotFoundException
312
-     */
313
-    protected function _assemble_data()
314
-    {
315
-        // verify that reg_objs is set
316
-        if (
317
-            ! is_array($this->reg_objs)
318
-            && ! reset($this->reg_objs) instanceof EE_Registration
319
-        ) {
320
-            throw new EE_Error(
321
-                esc_html__(
322
-                    'In order to assemble the data correctly, the "reg_objs" property must be an array of EE_Registration objects',
323
-                    'event_espresso'
324
-                )
325
-            );
326
-        }
327
-
328
-        // get all attendee and events associated with the registrations in this transaction
329
-        $events             = $event_setup = $evtcache = $tickets = $datetimes = array();
330
-        $answers            = $questions = $attendees = $line_items = $registrations = array();
331
-        $total_ticket_count = 0;
332
-
333
-        if (! empty($this->reg_objs)) {
334
-            $event_attendee_count = array();
335
-            /** @var EE_Registration $reg */
336
-            foreach ($this->reg_objs as $reg) {
337
-                if (
338
-                    $this->_skip_registration_for_processing($reg)
339
-                ) {
340
-                    continue;
341
-                }
342
-
343
-                $evt_id = $reg->event_ID();
344
-                /** @type EE_Ticket $ticket */
345
-                $ticket          = $reg->get_first_related('Ticket');
346
-                $attendee = $reg->attendee();
347
-                $event = $reg->event();
348
-                // if none of the following entities are available, then we can't setup other data reliably,
349
-                // so let's just skip.
350
-                if (
351
-                    ! $ticket instanceof EE_Ticket
352
-                    || ! $attendee instanceof EE_Attendee
353
-                    || ! $event instanceof EE_Event
354
-                ) {
355
-                    continue;
356
-                }
357
-                $relateddatetime = $ticket->datetimes();
358
-                $total_ticket_count++;
359
-                $tickets[ $ticket->ID() ]['ticket']                        = $ticket;
360
-                $tickets[ $ticket->ID() ]['count']                         = is_array($tickets[ $ticket->ID() ])
361
-                                                                           && isset($tickets[ $ticket->ID() ]['count'])
362
-                    ? $tickets[ $ticket->ID() ]['count'] + 1
363
-                    : 1;
364
-                $tickets[ $ticket->ID() ]['att_objs'][ $attendee->ID() ] = $attendee;
365
-                $tickets[ $ticket->ID() ]['dtt_objs']                      = $relateddatetime;
366
-                $tickets[ $ticket->ID() ]['reg_objs'][ $reg->ID() ]          = $reg;
367
-                $tickets[ $ticket->ID() ]['EE_Event']                      = $event;
368
-                $evtcache[ $evt_id ]                                       = $event;
369
-                $eventsetup[ $evt_id ]['reg_objs'][ $reg->ID() ]             = $reg;
370
-                $eventsetup[ $evt_id ]['tkt_objs'][ $ticket->ID() ]          = $ticket;
371
-                $eventsetup[ $evt_id ]['att_objs'][ $attendee->ID() ]    = $attendee;
372
-                $event_attendee_count[ $evt_id ]                           = isset($event_attendee_count[ $evt_id ])
373
-                    ? $event_attendee_count[ $evt_id ] + 1
374
-                    : 0;
375
-                $attendees[ $reg->attendee_ID() ]['line_ref'][]            = $evt_id;
376
-                $attendees[ $reg->attendee_ID() ]['att_obj']               = $attendee;
377
-                $attendees[ $reg->attendee_ID() ]['reg_objs'][ $reg->ID() ]  = $reg;
378
-                // $attendees[ $reg->attendee_ID() ]['registration_id'] = $reg->ID();
379
-                $attendees[ $reg->attendee_ID() ]['attendee_email']          = $attendee->email();
380
-                $attendees[ $reg->attendee_ID() ]['tkt_objs'][ $ticket->ID() ] = $ticket;
381
-                $attendees[ $reg->attendee_ID() ]['evt_objs'][ $evt_id ]       = $event;
382
-
383
-                // registrations
384
-                $registrations[ $reg->ID() ]['tkt_obj'] = $ticket;
385
-                $registrations[ $reg->ID() ]['evt_obj'] = $event;
386
-                $registrations[ $reg->ID() ]['reg_obj'] = $reg;
387
-                $registrations[ $reg->ID() ]['att_obj'] = $attendee;
388
-
389
-                // set up answer objects
390
-                $rel_ans = $reg->get_many_related('Answer');
391
-                foreach ($rel_ans as $ansid => $answer) {
392
-                    if (! isset($questions[ $ansid ])) {
393
-                        $questions[ $ansid ] = $answer->get_first_related('Question');
394
-                    }
395
-                    $answers[ $ansid ]                               = $answer;
396
-                    $registrations[ $reg->ID() ]['ans_objs'][ $ansid ] = $answer;
397
-                }
398
-                /**
399
-                 * @var int $dtt_id
400
-                 * @var EE_Datetime $datetime
401
-                 */
402
-                foreach ($relateddatetime as $dtt_id => $datetime) {
403
-                    $eventsetup[ $evt_id ]['dtt_objs'][ $dtt_id ]       = $datetime;
404
-                    $registrations[ $reg->ID() ]['dtt_objs'][ $dtt_id ] = $datetime;
405
-
406
-                    if (isset($datetimes[ $dtt_id ])) {
407
-                        continue; // already have this info in the datetimes array.
408
-                    }
409
-
410
-                    $datetimes[ $dtt_id ]['tkt_objs'][]           = $ticket;
411
-                    $datetimes[ $dtt_id ]['datetime']             = $datetime;
412
-                    $datetimes[ $dtt_id ]['evt_objs'][ $evt_id ]    = $event;
413
-                    $datetimes[ $dtt_id ]['reg_objs'][ $reg->ID() ] = $reg;
414
-                }
415
-            }
416
-
417
-            // let's loop through the unique event=>reg items and setup data on them
418
-
419
-            if (! empty($eventsetup)) {
420
-                foreach ($eventsetup as $evt_id => $items) {
421
-                    $ticket_line_items_for_event = array();
422
-                    if ($this->txn instanceof EE_Transaction) {
423
-                        $ticket_line_items_for_event = EEM_Line_Item::instance()->get_all(
424
-                            array(
425
-                                array(
426
-                                    'Ticket.Datetime.EVT_ID' => $evt_id,
427
-                                    'TXN_ID'                 => $this->txn->ID(),
428
-                                ),
429
-                                'default_where_conditions' => 'none',
430
-                            )
431
-                        );
432
-                    }
433
-                    $events[ $evt_id ] = array(
434
-                        'ID'              => $evt_id,
435
-                        'event'           => $evtcache[ $evt_id ],
436
-                        'name'            => $evtcache[ $evt_id ] instanceof EE_Event ? $evtcache[ $evt_id ]->name() : '',
437
-                        'total_attendees' => $event_attendee_count[ $evt_id ],
438
-                        'reg_objs'        => $items['reg_objs'],
439
-                        'tkt_objs'        => $items['tkt_objs'],
440
-                        'att_objs'        => $items['att_objs'],
441
-                        'dtt_objs'        => isset($items['dtt_objs']) ? $items['dtt_objs'] : array(),
442
-                        'line_items'      => $ticket_line_items_for_event,
443
-                    );
444
-
445
-                    // make sure the tickets have the line items setup for them.
446
-                    foreach ($ticket_line_items_for_event as $line_id => $line_item) {
447
-                        // only add the ticket line items if we already have this ticket in the $tickets array.
448
-                        if ($line_item instanceof EE_Line_Item && isset($tickets[ $line_item->ticket()->ID() ])) {
449
-                            $tickets[ $line_item->ticket()->ID() ]['line_item']      = $line_item;
450
-                            $tickets[ $line_item->ticket()->ID() ]['sub_line_items'] = $line_item->children();
451
-                            $line_items[ $line_item->ID() ]['children']              = $line_item->children();
452
-                            $line_items[ $line_item->ID() ]['EE_Ticket']             = $line_item->ticket();
453
-                        }
454
-                    }
455
-                }
456
-            }
457
-
458
-            $this->grand_total_line_item = $this->txn instanceof EE_Transaction
459
-                ? $this->txn->total_line_item()
460
-                : null;
461
-        }
462
-
463
-        // lets set the attendees and events properties
464
-        $this->attendees                = $attendees;
465
-        $this->events                   = $events;
466
-        $this->tickets                  = $tickets;
467
-        $this->line_items_with_children = $line_items;
468
-        $this->datetimes                = $datetimes;
469
-        $this->questions                = $questions;
470
-        $this->answers                  = $answers;
471
-        $this->total_ticket_count       = $total_ticket_count;
472
-        $this->registrations            = $registrations;
473
-
474
-        if ($this->txn instanceof EE_Transaction) {
475
-            $this->tax_line_items        = $this->txn->tax_items();
476
-            $this->additional_line_items = $this->txn->non_ticket_line_items();
477
-            $this->payments              = $this->txn->payments();
478
-
479
-            // setup primary registration if we have a single transaction object to work with
480
-
481
-            // let's get just the primary_attendee_data!  First we get the primary registration object.
482
-            $primary_reg = $this->txn->primary_registration();
483
-            // verify
484
-            if ($primary_reg instanceof EE_Registration) {
485
-                // get attendee object
486
-                if ($primary_reg->attendee() instanceof EE_Attendee) {
487
-                    // now we can setup the primary_attendee_data array
488
-                    $this->primary_attendee_data = array(
489
-                        'registration_id' => $primary_reg->ID(),
490
-                        'att_obj'         => $primary_reg->attendee(),
491
-                        'reg_obj'         => $primary_reg,
492
-                        'primary_att_obj' => $primary_reg->attendee(),
493
-                        'primary_reg_obj' => $primary_reg,
494
-                    );
495
-                } else {
496
-                    EE_Error::add_error(
497
-                        esc_html__(
498
-                            'Incoming data does not have a valid Attendee object for the primary registrant.',
499
-                            'event_espresso'
500
-                        ),
501
-                        __FILE__,
502
-                        __FUNCTION__,
503
-                        __LINE__
504
-                    );
505
-                }
506
-            } else {
507
-                EE_Error::add_error(
508
-                    esc_html__(
509
-                        'Incoming data does not have a valid Registration object for the primary registrant.',
510
-                        'event_espresso'
511
-                    ),
512
-                    __FILE__,
513
-                    __FUNCTION__,
514
-                    __LINE__
515
-                );
516
-            }
517
-        }
518
-    }
519
-
520
-    /**
521
-     * This simply considers whether the given registration should be processed or not based on comparison with the
522
-     * filtered_reg_status property.
523
-     *
524
-     * @param EE_Registration $registration
525
-     * @return bool  returning true means we DO want to skip processing.  returning false means we DON'T want to skip
526
-     *               processing
527
-     */
528
-    protected function _skip_registration_for_processing(EE_Registration $registration)
529
-    {
530
-        if (empty($this->filtered_reg_status)) {
531
-            return false;
532
-        }
533
-
534
-        // if we made it here then we just compare the filtered_reg_status with the registration status and return that
535
-        return $this->filtered_reg_status !== $registration->status_ID();
536
-    }
19
+	/**
20
+	 * user id for logged in user when data collected
21
+	 *
22
+	 * @var string $user_id
23
+	 */
24
+	public $user_id;
25
+
26
+	/**
27
+	 * IP Address of browser used
28
+	 *
29
+	 * @var string $ip_address
30
+	 */
31
+	public $ip_address;
32
+
33
+	/**
34
+	 * browser
35
+	 *
36
+	 * @var string $user_agent
37
+	 */
38
+	public $user_agent;
39
+
40
+	/**
41
+	 * Unix timestamp
42
+	 *
43
+	 * @var string $init_access
44
+	 */
45
+	public $init_access;
46
+
47
+	/**
48
+	 * Unix timestamp
49
+	 *
50
+	 * @var string $last_access
51
+	 */
52
+	public $last_access;
53
+
54
+	/**
55
+	 * The registrations details from the cart
56
+	 *
57
+	 * @var array $reg_info
58
+	 */
59
+	public $reg_info;
60
+
61
+	/**
62
+	 * Some data handlers can set what reg status all the registrations are filtered by.
63
+	 * The status should match a EEM_Registration status constant.
64
+	 *
65
+	 * @var string $filtered_reg_status
66
+	 */
67
+	public $filtered_reg_status;
68
+
69
+	/**
70
+	 * will hold an array of events assembled from $reg_info
71
+	 *
72
+	 * @var EE_Event[] $events
73
+	 */
74
+	public $events;
75
+
76
+	/**
77
+	 * holds an array of datetimes assembled from the incoming data.
78
+	 *
79
+	 * @var EE_Datetime[] $datetimes
80
+	 */
81
+	public $datetimes;
82
+
83
+	/**
84
+	 * holds an array of tickets assembled from the incoming data.
85
+	 *
86
+	 * @var EE_Ticket[] $tickets
87
+	 */
88
+	public $tickets;
89
+
90
+	/**
91
+	 * holds an array with a key of parent line item and values are an array of children of that line item.
92
+	 *
93
+	 * @since 4.5.0
94
+	 * @var EE_Line_Item[] $line_items_with_children
95
+	 */
96
+	public $line_items_with_children;
97
+
98
+	/**
99
+	 * will hold an array of attendees assembled from the $reg_info
100
+	 *
101
+	 * @var EE_Attendee[] $attendees
102
+	 */
103
+	public $attendees;
104
+
105
+	/**
106
+	 * will hold an array of cached registration objects and info assembled from reg_info
107
+	 *
108
+	 * @var array $registrations
109
+	 */
110
+	public $registrations;
111
+
112
+	/**
113
+	 * will hold an array of answers assembled from the $reg_info
114
+	 *
115
+	 * @var EE_Answer[] $answers
116
+	 */
117
+	public $answers;
118
+
119
+	/**
120
+	 * will hold an array of questions assembled from the $reg_info (indexed by Answer ID);
121
+	 *
122
+	 * @var EE_Question[] $questions
123
+	 */
124
+	public $questions;
125
+
126
+	/**
127
+	 * Will hold billing data assembled from $billing_info (if present)
128
+	 *
129
+	 * @var mixed (array|null) $billing
130
+	 */
131
+	public $billing;
132
+
133
+	/**
134
+	 * The total amount of tax for the transaction
135
+	 *
136
+	 * @var float $taxes
137
+	 */
138
+	public $taxes;
139
+
140
+	/**
141
+	 * Holds the line items related to taxes
142
+	 *
143
+	 * @since 4.5.0
144
+	 * @var EE_Line_Item[] $tax_line_items
145
+	 */
146
+	public $tax_line_items;
147
+
148
+	/**
149
+	 * Hold the line items which aren't taxes and don't relate
150
+	 * to tickets. So: promotions and miscellaneous charges
151
+	 *
152
+	 * @since 4.5
153
+	 * @var EE_Line_Item[] $additional_line_items
154
+	 */
155
+	public $additional_line_items;
156
+
157
+	/**
158
+	 * Holds the grand total EE_Line_Item
159
+	 *
160
+	 * @var EE_Line_Item $grand_total_line_item
161
+	 */
162
+	public $grand_total_line_item;
163
+
164
+	/**
165
+	 * holds the grand total price object
166
+	 * currently not used.
167
+	 *
168
+	 * @var null $grand_total_price_object
169
+	 */
170
+	public $grand_total_price_object;
171
+
172
+	/**
173
+	 * total number of tickets
174
+	 *
175
+	 * @var int $total_ticket_count
176
+	 */
177
+	public $total_ticket_count;
178
+
179
+	/**
180
+	 * Will hold the final transaction object (EE_Transaction)
181
+	 *
182
+	 * @var EE_Transaction $txn
183
+	 */
184
+	public $txn;
185
+
186
+	/**
187
+	 * Holds the payments related to a transaction
188
+	 *
189
+	 * @since 4.5.0
190
+	 * @var EE_Payment[] $payments
191
+	 */
192
+	public $payments;
193
+
194
+	/**
195
+	 * Holds the first related payment related for a transaction
196
+	 *
197
+	 * @since 4.5.0
198
+	 * @var EE_Payment $payment
199
+	 */
200
+	public $payment;
201
+
202
+	/**
203
+	 * Will hold the label for the txn status
204
+	 *
205
+	 * @var string $txn_status
206
+	 */
207
+	public $txn_status;
208
+
209
+	/**
210
+	 * Will hold the final registration object (EE_Registration)
211
+	 *
212
+	 * @var EE_Registration[] $reg_objs
213
+	 */
214
+	public $reg_objs;
215
+
216
+	/**
217
+	 * Will hold an array of primary attendee data (if present)
218
+	 *
219
+	 * @var array $primary_attendee_data
220
+	 */
221
+	public $primary_attendee_data;
222
+
223
+	/**
224
+	 * This is just an internal object used for passing around the incoming data.
225
+	 *
226
+	 * @var mixed $_data
227
+	 */
228
+	protected $_data;
229
+
230
+	/**
231
+	 * This is just an internal object used for passing around the incoming data.
232
+	 *
233
+	 * @var mixed $incoming_data
234
+	 */
235
+	public $incoming_data;
236
+
237
+	/**
238
+	 * hold objects that might be created
239
+	 *
240
+	 * @type EE_Registration $reg_obj
241
+	 */
242
+	public $reg_obj;
243
+
244
+
245
+	/**
246
+	 * constructor
247
+	 *
248
+	 * @param mixed $data incoming data object|array.  Suggested that child classes use type hinting for expected
249
+	 *                    data object.  But here parent will be generic because we don't know what's coming in.
250
+	 */
251
+	public function __construct($data)
252
+	{
253
+		$this->_data = $data;
254
+		$this->_setup_data();
255
+	}
256
+
257
+
258
+	/**
259
+	 * Every child class has to setup the data object !
260
+	 *
261
+	 * @return void
262
+	 */
263
+	abstract protected function _setup_data();
264
+
265
+
266
+	/**
267
+	 * Returns database safe representation of the data later used to when instantiating this object.
268
+	 *
269
+	 * @param mixed $data The incoming data to be prepped.
270
+	 * @return mixed   The prepped data for db
271
+	 */
272
+	public static function convert_data_for_persistent_storage($data)
273
+	{
274
+		return $data;
275
+	}
276
+
277
+
278
+	/**
279
+	 * Data that has been stored in persistent storage that was prepped by _convert_data_for_persistent_storage
280
+	 * can be sent into this method and converted back into the format used for instantiating with this data handler.
281
+	 *
282
+	 * @param $data
283
+	 * @return mixed
284
+	 */
285
+	public static function convert_data_from_persistent_storage($data)
286
+	{
287
+		return $data;
288
+	}
289
+
290
+
291
+	/**
292
+	 * only purpose is to return the data
293
+	 *
294
+	 * @access public
295
+	 * @return mixed the formatted data object!
296
+	 */
297
+	public function data()
298
+	{
299
+		return $this->_data;
300
+	}
301
+
302
+
303
+	/**
304
+	 * This helper method can be used by any incoming data handlers to setup the data correctly.  All that is required
305
+	 * is that $this->reg_objs be set.
306
+	 *
307
+	 * @throws EE_Error
308
+	 * @throws InvalidDataTypeException
309
+	 * @throws InvalidInterfaceException
310
+	 * @throws InvalidArgumentException
311
+	 * @throws EntityNotFoundException
312
+	 */
313
+	protected function _assemble_data()
314
+	{
315
+		// verify that reg_objs is set
316
+		if (
317
+			! is_array($this->reg_objs)
318
+			&& ! reset($this->reg_objs) instanceof EE_Registration
319
+		) {
320
+			throw new EE_Error(
321
+				esc_html__(
322
+					'In order to assemble the data correctly, the "reg_objs" property must be an array of EE_Registration objects',
323
+					'event_espresso'
324
+				)
325
+			);
326
+		}
327
+
328
+		// get all attendee and events associated with the registrations in this transaction
329
+		$events             = $event_setup = $evtcache = $tickets = $datetimes = array();
330
+		$answers            = $questions = $attendees = $line_items = $registrations = array();
331
+		$total_ticket_count = 0;
332
+
333
+		if (! empty($this->reg_objs)) {
334
+			$event_attendee_count = array();
335
+			/** @var EE_Registration $reg */
336
+			foreach ($this->reg_objs as $reg) {
337
+				if (
338
+					$this->_skip_registration_for_processing($reg)
339
+				) {
340
+					continue;
341
+				}
342
+
343
+				$evt_id = $reg->event_ID();
344
+				/** @type EE_Ticket $ticket */
345
+				$ticket          = $reg->get_first_related('Ticket');
346
+				$attendee = $reg->attendee();
347
+				$event = $reg->event();
348
+				// if none of the following entities are available, then we can't setup other data reliably,
349
+				// so let's just skip.
350
+				if (
351
+					! $ticket instanceof EE_Ticket
352
+					|| ! $attendee instanceof EE_Attendee
353
+					|| ! $event instanceof EE_Event
354
+				) {
355
+					continue;
356
+				}
357
+				$relateddatetime = $ticket->datetimes();
358
+				$total_ticket_count++;
359
+				$tickets[ $ticket->ID() ]['ticket']                        = $ticket;
360
+				$tickets[ $ticket->ID() ]['count']                         = is_array($tickets[ $ticket->ID() ])
361
+																		   && isset($tickets[ $ticket->ID() ]['count'])
362
+					? $tickets[ $ticket->ID() ]['count'] + 1
363
+					: 1;
364
+				$tickets[ $ticket->ID() ]['att_objs'][ $attendee->ID() ] = $attendee;
365
+				$tickets[ $ticket->ID() ]['dtt_objs']                      = $relateddatetime;
366
+				$tickets[ $ticket->ID() ]['reg_objs'][ $reg->ID() ]          = $reg;
367
+				$tickets[ $ticket->ID() ]['EE_Event']                      = $event;
368
+				$evtcache[ $evt_id ]                                       = $event;
369
+				$eventsetup[ $evt_id ]['reg_objs'][ $reg->ID() ]             = $reg;
370
+				$eventsetup[ $evt_id ]['tkt_objs'][ $ticket->ID() ]          = $ticket;
371
+				$eventsetup[ $evt_id ]['att_objs'][ $attendee->ID() ]    = $attendee;
372
+				$event_attendee_count[ $evt_id ]                           = isset($event_attendee_count[ $evt_id ])
373
+					? $event_attendee_count[ $evt_id ] + 1
374
+					: 0;
375
+				$attendees[ $reg->attendee_ID() ]['line_ref'][]            = $evt_id;
376
+				$attendees[ $reg->attendee_ID() ]['att_obj']               = $attendee;
377
+				$attendees[ $reg->attendee_ID() ]['reg_objs'][ $reg->ID() ]  = $reg;
378
+				// $attendees[ $reg->attendee_ID() ]['registration_id'] = $reg->ID();
379
+				$attendees[ $reg->attendee_ID() ]['attendee_email']          = $attendee->email();
380
+				$attendees[ $reg->attendee_ID() ]['tkt_objs'][ $ticket->ID() ] = $ticket;
381
+				$attendees[ $reg->attendee_ID() ]['evt_objs'][ $evt_id ]       = $event;
382
+
383
+				// registrations
384
+				$registrations[ $reg->ID() ]['tkt_obj'] = $ticket;
385
+				$registrations[ $reg->ID() ]['evt_obj'] = $event;
386
+				$registrations[ $reg->ID() ]['reg_obj'] = $reg;
387
+				$registrations[ $reg->ID() ]['att_obj'] = $attendee;
388
+
389
+				// set up answer objects
390
+				$rel_ans = $reg->get_many_related('Answer');
391
+				foreach ($rel_ans as $ansid => $answer) {
392
+					if (! isset($questions[ $ansid ])) {
393
+						$questions[ $ansid ] = $answer->get_first_related('Question');
394
+					}
395
+					$answers[ $ansid ]                               = $answer;
396
+					$registrations[ $reg->ID() ]['ans_objs'][ $ansid ] = $answer;
397
+				}
398
+				/**
399
+				 * @var int $dtt_id
400
+				 * @var EE_Datetime $datetime
401
+				 */
402
+				foreach ($relateddatetime as $dtt_id => $datetime) {
403
+					$eventsetup[ $evt_id ]['dtt_objs'][ $dtt_id ]       = $datetime;
404
+					$registrations[ $reg->ID() ]['dtt_objs'][ $dtt_id ] = $datetime;
405
+
406
+					if (isset($datetimes[ $dtt_id ])) {
407
+						continue; // already have this info in the datetimes array.
408
+					}
409
+
410
+					$datetimes[ $dtt_id ]['tkt_objs'][]           = $ticket;
411
+					$datetimes[ $dtt_id ]['datetime']             = $datetime;
412
+					$datetimes[ $dtt_id ]['evt_objs'][ $evt_id ]    = $event;
413
+					$datetimes[ $dtt_id ]['reg_objs'][ $reg->ID() ] = $reg;
414
+				}
415
+			}
416
+
417
+			// let's loop through the unique event=>reg items and setup data on them
418
+
419
+			if (! empty($eventsetup)) {
420
+				foreach ($eventsetup as $evt_id => $items) {
421
+					$ticket_line_items_for_event = array();
422
+					if ($this->txn instanceof EE_Transaction) {
423
+						$ticket_line_items_for_event = EEM_Line_Item::instance()->get_all(
424
+							array(
425
+								array(
426
+									'Ticket.Datetime.EVT_ID' => $evt_id,
427
+									'TXN_ID'                 => $this->txn->ID(),
428
+								),
429
+								'default_where_conditions' => 'none',
430
+							)
431
+						);
432
+					}
433
+					$events[ $evt_id ] = array(
434
+						'ID'              => $evt_id,
435
+						'event'           => $evtcache[ $evt_id ],
436
+						'name'            => $evtcache[ $evt_id ] instanceof EE_Event ? $evtcache[ $evt_id ]->name() : '',
437
+						'total_attendees' => $event_attendee_count[ $evt_id ],
438
+						'reg_objs'        => $items['reg_objs'],
439
+						'tkt_objs'        => $items['tkt_objs'],
440
+						'att_objs'        => $items['att_objs'],
441
+						'dtt_objs'        => isset($items['dtt_objs']) ? $items['dtt_objs'] : array(),
442
+						'line_items'      => $ticket_line_items_for_event,
443
+					);
444
+
445
+					// make sure the tickets have the line items setup for them.
446
+					foreach ($ticket_line_items_for_event as $line_id => $line_item) {
447
+						// only add the ticket line items if we already have this ticket in the $tickets array.
448
+						if ($line_item instanceof EE_Line_Item && isset($tickets[ $line_item->ticket()->ID() ])) {
449
+							$tickets[ $line_item->ticket()->ID() ]['line_item']      = $line_item;
450
+							$tickets[ $line_item->ticket()->ID() ]['sub_line_items'] = $line_item->children();
451
+							$line_items[ $line_item->ID() ]['children']              = $line_item->children();
452
+							$line_items[ $line_item->ID() ]['EE_Ticket']             = $line_item->ticket();
453
+						}
454
+					}
455
+				}
456
+			}
457
+
458
+			$this->grand_total_line_item = $this->txn instanceof EE_Transaction
459
+				? $this->txn->total_line_item()
460
+				: null;
461
+		}
462
+
463
+		// lets set the attendees and events properties
464
+		$this->attendees                = $attendees;
465
+		$this->events                   = $events;
466
+		$this->tickets                  = $tickets;
467
+		$this->line_items_with_children = $line_items;
468
+		$this->datetimes                = $datetimes;
469
+		$this->questions                = $questions;
470
+		$this->answers                  = $answers;
471
+		$this->total_ticket_count       = $total_ticket_count;
472
+		$this->registrations            = $registrations;
473
+
474
+		if ($this->txn instanceof EE_Transaction) {
475
+			$this->tax_line_items        = $this->txn->tax_items();
476
+			$this->additional_line_items = $this->txn->non_ticket_line_items();
477
+			$this->payments              = $this->txn->payments();
478
+
479
+			// setup primary registration if we have a single transaction object to work with
480
+
481
+			// let's get just the primary_attendee_data!  First we get the primary registration object.
482
+			$primary_reg = $this->txn->primary_registration();
483
+			// verify
484
+			if ($primary_reg instanceof EE_Registration) {
485
+				// get attendee object
486
+				if ($primary_reg->attendee() instanceof EE_Attendee) {
487
+					// now we can setup the primary_attendee_data array
488
+					$this->primary_attendee_data = array(
489
+						'registration_id' => $primary_reg->ID(),
490
+						'att_obj'         => $primary_reg->attendee(),
491
+						'reg_obj'         => $primary_reg,
492
+						'primary_att_obj' => $primary_reg->attendee(),
493
+						'primary_reg_obj' => $primary_reg,
494
+					);
495
+				} else {
496
+					EE_Error::add_error(
497
+						esc_html__(
498
+							'Incoming data does not have a valid Attendee object for the primary registrant.',
499
+							'event_espresso'
500
+						),
501
+						__FILE__,
502
+						__FUNCTION__,
503
+						__LINE__
504
+					);
505
+				}
506
+			} else {
507
+				EE_Error::add_error(
508
+					esc_html__(
509
+						'Incoming data does not have a valid Registration object for the primary registrant.',
510
+						'event_espresso'
511
+					),
512
+					__FILE__,
513
+					__FUNCTION__,
514
+					__LINE__
515
+				);
516
+			}
517
+		}
518
+	}
519
+
520
+	/**
521
+	 * This simply considers whether the given registration should be processed or not based on comparison with the
522
+	 * filtered_reg_status property.
523
+	 *
524
+	 * @param EE_Registration $registration
525
+	 * @return bool  returning true means we DO want to skip processing.  returning false means we DON'T want to skip
526
+	 *               processing
527
+	 */
528
+	protected function _skip_registration_for_processing(EE_Registration $registration)
529
+	{
530
+		if (empty($this->filtered_reg_status)) {
531
+			return false;
532
+		}
533
+
534
+		// if we made it here then we just compare the filtered_reg_status with the registration status and return that
535
+		return $this->filtered_reg_status !== $registration->status_ID();
536
+	}
537 537
 }
Please login to merge, or discard this patch.
core/libraries/payment_methods/EE_Payment_Method_Manager.lib.php 2 patches
Spacing   +26 added lines, -26 removed lines patch added patch discarded remove patch
@@ -74,7 +74,7 @@  discard block
 block discarded – undo
74 74
     public static function instance()
75 75
     {
76 76
         // check if class object is instantiated, and instantiated properly
77
-        if (! self::$_instance instanceof EE_Payment_Method_Manager) {
77
+        if ( ! self::$_instance instanceof EE_Payment_Method_Manager) {
78 78
             EE_Registry::instance()->load_lib('PMT_Base');
79 79
             self::$_instance = new self();
80 80
         }
@@ -105,7 +105,7 @@  discard block
 block discarded – undo
105 105
      */
106 106
     public function maybe_register_payment_methods($force_recheck = false)
107 107
     {
108
-        if (! $this->_payment_method_types || $force_recheck) {
108
+        if ( ! $this->_payment_method_types || $force_recheck) {
109 109
             $this->_register_payment_methods();
110 110
         }
111 111
     }
@@ -119,7 +119,7 @@  discard block
 block discarded – undo
119 119
     protected function _register_payment_methods()
120 120
     {
121 121
         // grab list of installed modules
122
-        $pm_to_register = glob(EE_PAYMENT_METHODS . '*', GLOB_ONLYDIR);
122
+        $pm_to_register = glob(EE_PAYMENT_METHODS.'*', GLOB_ONLYDIR);
123 123
         // filter list of modules to register
124 124
         $pm_to_register = apply_filters(
125 125
             'FHEE__EE_Payment_Method_Manager__register_payment_methods__payment_methods_to_register',
@@ -159,9 +159,9 @@  discard block
 block discarded – undo
159 159
         // create class name from module directory name
160 160
         $module = str_replace(array('_', ' '), array(' ', '_'), $module_dir);
161 161
         // add class prefix
162
-        $module_class = 'EE_PMT_' . $module;
162
+        $module_class = 'EE_PMT_'.$module;
163 163
         // does the module exist ?
164
-        if (! is_readable($payment_method_path . '/' . $module_class . $module_ext)) {
164
+        if ( ! is_readable($payment_method_path.'/'.$module_class.$module_ext)) {
165 165
             $msg = sprintf(
166 166
                 esc_html__(
167 167
                     'The requested %s payment method file could not be found or is not readable due to file permissions.',
@@ -169,22 +169,22 @@  discard block
 block discarded – undo
169 169
                 ),
170 170
                 $module
171 171
             );
172
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
172
+            EE_Error::add_error($msg.'||'.$msg, __FILE__, __FUNCTION__, __LINE__);
173 173
             return false;
174 174
         }
175 175
         // load the module class file
176
-        require_once($payment_method_path . '/' . $module_class . $module_ext);
176
+        require_once($payment_method_path.'/'.$module_class.$module_ext);
177 177
         // verify that class exists
178
-        if (! class_exists($module_class)) {
178
+        if ( ! class_exists($module_class)) {
179 179
             $msg = sprintf(
180 180
                 esc_html__('The requested %s module class does not exist.', 'event_espresso'),
181 181
                 $module_class
182 182
             );
183
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
183
+            EE_Error::add_error($msg.'||'.$msg, __FILE__, __FUNCTION__, __LINE__);
184 184
             return false;
185 185
         }
186 186
         // add to array of registered modules
187
-        $this->_payment_method_types[ $module ] = $payment_method_path . '/' . $module_class . $module_ext;
187
+        $this->_payment_method_types[$module] = $payment_method_path.'/'.$module_class.$module_ext;
188 188
         ksort($this->_payment_method_types);
189 189
         return true;
190 190
     }
@@ -202,12 +202,12 @@  discard block
 block discarded – undo
202 202
         if (
203 203
             $force_recheck
204 204
             || ! is_array($this->_payment_method_types)
205
-            || ! isset($this->_payment_method_types[ $payment_method_name ])
205
+            || ! isset($this->_payment_method_types[$payment_method_name])
206 206
         ) {
207 207
             $this->maybe_register_payment_methods($force_recheck);
208 208
         }
209
-        if (isset($this->_payment_method_types[ $payment_method_name ])) {
210
-            require_once($this->_payment_method_types[ $payment_method_name ]);
209
+        if (isset($this->_payment_method_types[$payment_method_name])) {
210
+            require_once($this->_payment_method_types[$payment_method_name]);
211 211
             return true;
212 212
         }
213 213
         return false;
@@ -249,8 +249,8 @@  discard block
 block discarded – undo
249 249
         if ($force_recheck || empty($this->payment_method_objects)) {
250 250
             $this->maybe_register_payment_methods($force_recheck);
251 251
             foreach ($this->payment_method_type_names(true) as $classname) {
252
-                if (! isset($this->payment_method_objects[ $classname ])) {
253
-                    $this->payment_method_objects[ $classname ] = new $classname();
252
+                if ( ! isset($this->payment_method_objects[$classname])) {
253
+                    $this->payment_method_objects[$classname] = new $classname();
254 254
                 }
255 255
             }
256 256
         }
@@ -279,7 +279,7 @@  discard block
 block discarded – undo
279 279
      */
280 280
     public function payment_method_class_from_type($type)
281 281
     {
282
-        return 'EE_PMT_' . $type;
282
+        return 'EE_PMT_'.$type;
283 283
     }
284 284
 
285 285
 
@@ -295,13 +295,13 @@  discard block
 block discarded – undo
295 295
     {
296 296
         $this->maybe_register_payment_methods();
297 297
         $payment_method = EEM_Payment_Method::instance()->get_one_of_type($payment_method_type);
298
-        if (! $payment_method instanceof EE_Payment_Method) {
298
+        if ( ! $payment_method instanceof EE_Payment_Method) {
299 299
             $pm_type_class = $this->payment_method_class_from_type($payment_method_type);
300 300
             if (class_exists($pm_type_class)) {
301 301
                 /** @var $pm_type_obj EE_PMT_Base */
302 302
                 $pm_type_obj = new $pm_type_class();
303 303
                 $payment_method = EEM_Payment_Method::instance()->get_one_by_slug($pm_type_obj->system_name());
304
-                if (! $payment_method) {
304
+                if ( ! $payment_method) {
305 305
                     $payment_method = $this->create_payment_method_of_type($pm_type_obj);
306 306
                 }
307 307
                 $payment_method->set_type($payment_method_type);
@@ -338,7 +338,7 @@  discard block
 block discarded – undo
338 338
                         'The Invoice payment method has been activated. It requires the %1$sinvoice message%2$s type to be active, so it was automatically activated for you.',
339 339
                         'event_espresso'
340 340
                     ),
341
-                    '<a href="' . admin_url('admin.php?page=espresso_messages&action=settings') . '">',
341
+                    '<a href="'.admin_url('admin.php?page=espresso_messages&action=settings').'">',
342 342
                     '</a>'
343 343
                 ),
344 344
                 true
@@ -364,7 +364,7 @@  discard block
 block discarded – undo
364 364
                 'PMD_type'       => $pm_type_obj->system_name(),
365 365
                 'PMD_name'       => $pm_type_obj->defaultFrontendName(),
366 366
                 'PMD_admin_name' => $pm_type_obj->pretty_name(),
367
-                'PMD_slug'       => $pm_type_obj->system_name(),// automatically converted to slug
367
+                'PMD_slug'       => $pm_type_obj->system_name(), // automatically converted to slug
368 368
                 'PMD_wp_user'    => $current_user->ID,
369 369
                 'PMD_order'      => EEM_Payment_Method::instance()->count(
370 370
                     array(array('PMD_type' => array('!=', 'Admin_Only')))
@@ -386,14 +386,14 @@  discard block
 block discarded – undo
386 386
     {
387 387
         $pm_type_obj = $payment_method->type_obj();
388 388
         $payment_method->set_description($pm_type_obj->default_description());
389
-        if (! $payment_method->button_url()) {
389
+        if ( ! $payment_method->button_url()) {
390 390
             $payment_method->set_button_url($pm_type_obj->default_button_url());
391 391
         }
392 392
         // now add setup its default extra meta properties
393 393
         $extra_metas = $pm_type_obj->settings_form()->extra_meta_inputs();
394
-        if (! empty($extra_metas)) {
394
+        if ( ! empty($extra_metas)) {
395 395
             // verify the payment method has an ID before adding extra meta
396
-            if (! $payment_method->ID()) {
396
+            if ( ! $payment_method->ID()) {
397 397
                 $payment_method->save();
398 398
             }
399 399
             foreach ($extra_metas as $meta_name => $input) {
@@ -536,10 +536,10 @@  discard block
 block discarded – undo
536 536
                 )
537 537
             );
538 538
         }
539
-        if (! isset($payment_method_caps[ $role ])) {
540
-            $payment_method_caps[ $role ] = array();
539
+        if ( ! isset($payment_method_caps[$role])) {
540
+            $payment_method_caps[$role] = array();
541 541
         }
542
-        $payment_method_caps[ $role ][] = EE_Payment_Method_Manager::CAPABILITIES_PREFIX
542
+        $payment_method_caps[$role][] = EE_Payment_Method_Manager::CAPABILITIES_PREFIX
543 543
                                           . strtolower($payment_method_name);
544 544
         return $payment_method_caps;
545 545
     }
Please login to merge, or discard this patch.
Indentation   +557 added lines, -557 removed lines patch added patch discarded remove patch
@@ -16,561 +16,561 @@
 block discarded – undo
16 16
  */
17 17
 class EE_Payment_Method_Manager implements ResettableInterface
18 18
 {
19
-    /**
20
-     * prefix added to all payment method capabilities names
21
-     */
22
-    const   CAPABILITIES_PREFIX = 'ee_payment_method_';
23
-
24
-    /**
25
-     * @var EE_Payment_Method_Manager $_instance
26
-     */
27
-    private static $_instance;
28
-
29
-    /**
30
-     * @var boolean
31
-     */
32
-    protected $payment_method_caps_initialized = false;
33
-
34
-    /**
35
-     * @var array keys are class names without 'EE_PMT_', values are their filepaths
36
-     */
37
-    protected $_payment_method_types = array();
38
-
39
-    /**
40
-     * @var EE_PMT_Base[]
41
-     */
42
-    protected $payment_method_objects = array();
43
-
44
-
45
-    /**
46
-     * EE_Payment_Method_Manager constructor.
47
-     *
48
-     * @throws EE_Error
49
-     * @throws DomainException
50
-     */
51
-    public function __construct()
52
-    {
53
-        // if in admin lets ensure caps are set.
54
-        if (is_admin()) {
55
-            $this->_register_payment_methods();
56
-            // set them immediately
57
-            $this->initializePaymentMethodCaps();
58
-            // plus any time they get reset
59
-            add_filter(
60
-                'FHEE__EE_Capabilities__addCaps__capabilities_to_add',
61
-                array($this, 'addPaymentMethodCapsDuringReset')
62
-            );
63
-        }
64
-    }
65
-
66
-
67
-    /**
68
-     * @singleton method used to instantiate class object
69
-     * @return EE_Payment_Method_Manager instance
70
-     * @throws DomainException
71
-     * @throws EE_Error
72
-     */
73
-    public static function instance()
74
-    {
75
-        // check if class object is instantiated, and instantiated properly
76
-        if (! self::$_instance instanceof EE_Payment_Method_Manager) {
77
-            EE_Registry::instance()->load_lib('PMT_Base');
78
-            self::$_instance = new self();
79
-        }
80
-        return self::$_instance;
81
-    }
82
-
83
-
84
-    /**
85
-     * Resets the instance and returns a new one
86
-     *
87
-     * @return EE_Payment_Method_Manager
88
-     * @throws DomainException
89
-     * @throws EE_Error
90
-     */
91
-    public static function reset()
92
-    {
93
-        self::$_instance = null;
94
-        return self::instance();
95
-    }
96
-
97
-
98
-    /**
99
-     * If necessary, re-register payment methods
100
-     *
101
-     * @param boolean $force_recheck whether to recheck for payment method types,
102
-     *                               or just re-use the PMTs we found last time we checked during this request (if
103
-     *                               we have not yet checked during this request, then we need to check anyways)
104
-     */
105
-    public function maybe_register_payment_methods($force_recheck = false)
106
-    {
107
-        if (! $this->_payment_method_types || $force_recheck) {
108
-            $this->_register_payment_methods();
109
-        }
110
-    }
111
-
112
-
113
-    /**
114
-     * register_payment_methods
115
-     *
116
-     * @return array
117
-     */
118
-    protected function _register_payment_methods()
119
-    {
120
-        // grab list of installed modules
121
-        $pm_to_register = glob(EE_PAYMENT_METHODS . '*', GLOB_ONLYDIR);
122
-        // filter list of modules to register
123
-        $pm_to_register = apply_filters(
124
-            'FHEE__EE_Payment_Method_Manager__register_payment_methods__payment_methods_to_register',
125
-            $pm_to_register
126
-        );
127
-        // remove any duplicates if that should happen for some reason
128
-        $pm_to_register = array_unique($pm_to_register);
129
-        // loop through folders
130
-        foreach ($pm_to_register as $pm_path) {
131
-            $this->register_payment_method($pm_path);
132
-        }
133
-        do_action('FHEE__EE_Payment_Method_Manager__register_payment_methods__registered_payment_methods');
134
-        // filter list of installed modules
135
-        // keep them organized alphabetically by the payment method type's name
136
-        ksort($this->_payment_method_types);
137
-        return apply_filters(
138
-            'FHEE__EE_Payment_Method_Manager__register_payment_methods__installed_payment_methods',
139
-            $this->_payment_method_types
140
-        );
141
-    }
142
-
143
-
144
-    /**
145
-     * register_payment_method- makes core aware of this payment method
146
-     *
147
-     * @param string $payment_method_path - full path up to and including payment method folder
148
-     * @return boolean
149
-     */
150
-    public function register_payment_method($payment_method_path = '')
151
-    {
152
-        do_action('AHEE__EE_Payment_Method_Manager__register_payment_method__begin', $payment_method_path);
153
-        $module_ext = '.pm.php';
154
-        // make all separators match
155
-        $payment_method_path = rtrim(str_replace('/\\', '/', $payment_method_path), '/');
156
-        // grab and sanitize module name
157
-        $module_dir = basename($payment_method_path);
158
-        // create class name from module directory name
159
-        $module = str_replace(array('_', ' '), array(' ', '_'), $module_dir);
160
-        // add class prefix
161
-        $module_class = 'EE_PMT_' . $module;
162
-        // does the module exist ?
163
-        if (! is_readable($payment_method_path . '/' . $module_class . $module_ext)) {
164
-            $msg = sprintf(
165
-                esc_html__(
166
-                    'The requested %s payment method file could not be found or is not readable due to file permissions.',
167
-                    'event_espresso'
168
-                ),
169
-                $module
170
-            );
171
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
172
-            return false;
173
-        }
174
-        // load the module class file
175
-        require_once($payment_method_path . '/' . $module_class . $module_ext);
176
-        // verify that class exists
177
-        if (! class_exists($module_class)) {
178
-            $msg = sprintf(
179
-                esc_html__('The requested %s module class does not exist.', 'event_espresso'),
180
-                $module_class
181
-            );
182
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
183
-            return false;
184
-        }
185
-        // add to array of registered modules
186
-        $this->_payment_method_types[ $module ] = $payment_method_path . '/' . $module_class . $module_ext;
187
-        ksort($this->_payment_method_types);
188
-        return true;
189
-    }
190
-
191
-
192
-    /**
193
-     * Checks if a payment method has been registered, and if so includes it
194
-     *
195
-     * @param string  $payment_method_name like 'PayPal_Pro', (ie class name without the prefix 'EEPM_')
196
-     * @param boolean $force_recheck       whether to force re-checking for new payment method types
197
-     * @return boolean
198
-     */
199
-    public function payment_method_type_exists($payment_method_name, $force_recheck = false)
200
-    {
201
-        if (
202
-            $force_recheck
203
-            || ! is_array($this->_payment_method_types)
204
-            || ! isset($this->_payment_method_types[ $payment_method_name ])
205
-        ) {
206
-            $this->maybe_register_payment_methods($force_recheck);
207
-        }
208
-        if (isset($this->_payment_method_types[ $payment_method_name ])) {
209
-            require_once($this->_payment_method_types[ $payment_method_name ]);
210
-            return true;
211
-        }
212
-        return false;
213
-    }
214
-
215
-
216
-    /**
217
-     * Returns all the class names of the various payment method types
218
-     *
219
-     * @param boolean $with_prefixes TRUE: get payment method type class names; false just their 'names'
220
-     *                               (what you'd find in wp_esp_payment_method.PMD_type)
221
-     * @param boolean $force_recheck whether to force re-checking for new payment method types
222
-     * @return array
223
-     */
224
-    public function payment_method_type_names($with_prefixes = false, $force_recheck = false)
225
-    {
226
-        $this->maybe_register_payment_methods($force_recheck);
227
-        if ($with_prefixes) {
228
-            $classnames = array_keys($this->_payment_method_types);
229
-            $payment_methods = array();
230
-            foreach ($classnames as $classname) {
231
-                $payment_methods[] = $this->payment_method_class_from_type($classname);
232
-            }
233
-            return $payment_methods;
234
-        }
235
-        return array_keys($this->_payment_method_types);
236
-    }
237
-
238
-
239
-    /**
240
-     * Gets an object of each payment method type, none of which are bound to a
241
-     * payment method instance
242
-     *
243
-     * @param boolean $force_recheck whether to force re-checking for new payment method types
244
-     * @return EE_PMT_Base[]
245
-     */
246
-    public function payment_method_types($force_recheck = false)
247
-    {
248
-        if ($force_recheck || empty($this->payment_method_objects)) {
249
-            $this->maybe_register_payment_methods($force_recheck);
250
-            foreach ($this->payment_method_type_names(true) as $classname) {
251
-                if (! isset($this->payment_method_objects[ $classname ])) {
252
-                    $this->payment_method_objects[ $classname ] = new $classname();
253
-                }
254
-            }
255
-        }
256
-        return $this->payment_method_objects;
257
-    }
258
-
259
-
260
-    /**
261
-     * Changes the payment method's class name into the payment method type's name
262
-     * (as used on the payment method's table's PMD_type field)
263
-     *
264
-     * @param string $classname
265
-     * @return string
266
-     */
267
-    public function payment_method_type_sans_class_prefix($classname)
268
-    {
269
-        return str_replace('EE_PMT_', '', $classname);
270
-    }
271
-
272
-
273
-    /**
274
-     * Does the opposite of payment-method_type_sans_prefix
275
-     *
276
-     * @param string $type
277
-     * @return string
278
-     */
279
-    public function payment_method_class_from_type($type)
280
-    {
281
-        return 'EE_PMT_' . $type;
282
-    }
283
-
284
-
285
-    /**
286
-     * Activates a payment method of the given type.
287
-     *
288
-     * @param string $payment_method_type the PMT_type; for EE_PMT_Invoice this would be 'Invoice'
289
-     * @return EE_Payment_Method
290
-     * @throws InvalidDataTypeException
291
-     * @throws EE_Error
292
-     */
293
-    public function activate_a_payment_method_of_type($payment_method_type)
294
-    {
295
-        $this->maybe_register_payment_methods();
296
-        $payment_method = EEM_Payment_Method::instance()->get_one_of_type($payment_method_type);
297
-        if (! $payment_method instanceof EE_Payment_Method) {
298
-            $pm_type_class = $this->payment_method_class_from_type($payment_method_type);
299
-            if (class_exists($pm_type_class)) {
300
-                /** @var $pm_type_obj EE_PMT_Base */
301
-                $pm_type_obj = new $pm_type_class();
302
-                $payment_method = EEM_Payment_Method::instance()->get_one_by_slug($pm_type_obj->system_name());
303
-                if (! $payment_method) {
304
-                    $payment_method = $this->create_payment_method_of_type($pm_type_obj);
305
-                }
306
-                $payment_method->set_type($payment_method_type);
307
-                $this->initialize_payment_method($payment_method);
308
-            } else {
309
-                throw new EE_Error(
310
-                    sprintf(
311
-                        esc_html__(
312
-                            'There is no payment method of type %1$s, so it could not be activated',
313
-                            'event_espresso'
314
-                        ),
315
-                        $pm_type_class
316
-                    )
317
-                );
318
-            }
319
-        }
320
-        $payment_method->set_active();
321
-        $payment_method->save();
322
-        /** @type EE_Message_Resource_Manager $message_resource_manager */
323
-        // if this was the invoice message type, make sure users can view their invoices
324
-        if (
325
-            $payment_method->type() === 'Invoice'
326
-            && (
327
-            ! EEH_MSG_Template::is_mt_active('invoice')
328
-            )
329
-        ) {
330
-            $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
331
-            /** @type EE_Message_Resource_Manager $message_resource_manager */
332
-            $message_resource_manager->ensure_message_type_is_active('invoice', 'html');
333
-            new PersistentAdminNotice(
334
-                'invoice_pm_requirements_notice',
335
-                sprintf(
336
-                    esc_html__(
337
-                        'The Invoice payment method has been activated. It requires the %1$sinvoice message%2$s type to be active, so it was automatically activated for you.',
338
-                        'event_espresso'
339
-                    ),
340
-                    '<a href="' . admin_url('admin.php?page=espresso_messages&action=settings') . '">',
341
-                    '</a>'
342
-                ),
343
-                true
344
-            );
345
-        }
346
-        return $payment_method;
347
-    }
348
-
349
-
350
-    /**
351
-     * Creates a payment method of the specified type. Does not save it.
352
-     *
353
-     * @global WP_User    $current_user
354
-     * @param EE_PMT_Base $pm_type_obj
355
-     * @return EE_Payment_Method
356
-     * @throws EE_Error
357
-     */
358
-    public function create_payment_method_of_type($pm_type_obj)
359
-    {
360
-        global $current_user;
361
-        $payment_method = EE_Payment_Method::new_instance(
362
-            array(
363
-                'PMD_type'       => $pm_type_obj->system_name(),
364
-                'PMD_name'       => $pm_type_obj->defaultFrontendName(),
365
-                'PMD_admin_name' => $pm_type_obj->pretty_name(),
366
-                'PMD_slug'       => $pm_type_obj->system_name(),// automatically converted to slug
367
-                'PMD_wp_user'    => $current_user->ID,
368
-                'PMD_order'      => EEM_Payment_Method::instance()->count(
369
-                    array(array('PMD_type' => array('!=', 'Admin_Only')))
370
-                ) * 10,
371
-            )
372
-        );
373
-        return $payment_method;
374
-    }
375
-
376
-
377
-    /**
378
-     * Sets the initial payment method properties (including extra meta)
379
-     *
380
-     * @param EE_Payment_Method $payment_method
381
-     * @return EE_Payment_Method
382
-     * @throws EE_Error
383
-     */
384
-    public function initialize_payment_method($payment_method)
385
-    {
386
-        $pm_type_obj = $payment_method->type_obj();
387
-        $payment_method->set_description($pm_type_obj->default_description());
388
-        if (! $payment_method->button_url()) {
389
-            $payment_method->set_button_url($pm_type_obj->default_button_url());
390
-        }
391
-        // now add setup its default extra meta properties
392
-        $extra_metas = $pm_type_obj->settings_form()->extra_meta_inputs();
393
-        if (! empty($extra_metas)) {
394
-            // verify the payment method has an ID before adding extra meta
395
-            if (! $payment_method->ID()) {
396
-                $payment_method->save();
397
-            }
398
-            foreach ($extra_metas as $meta_name => $input) {
399
-                $payment_method->update_extra_meta($meta_name, $input->raw_value());
400
-            }
401
-        }
402
-        return $payment_method;
403
-    }
404
-
405
-
406
-    /**
407
-     * Makes sure the payment method is related to the specified payment method
408
-     *
409
-     * @deprecated in 4.9.40 because the currency payment method table is being deprecated
410
-     * @param EE_Payment_Method $payment_method
411
-     * @return EE_Payment_Method
412
-     * @throws EE_Error
413
-     */
414
-    public function set_usable_currencies_on_payment_method($payment_method)
415
-    {
416
-        EE_Error::doing_it_wrong(
417
-            'EE_Payment_Method_Manager::set_usable_currencies_on_payment_method',
418
-            esc_html__(
419
-                'We no longer define what currencies are usable by payment methods. Its not used nor efficient.',
420
-                'event_espresso'
421
-            ),
422
-            '4.9.40'
423
-        );
424
-        return $payment_method;
425
-    }
426
-
427
-
428
-    /**
429
-     * Deactivates a payment method of the given payment method slug.
430
-     *
431
-     * @param string $payment_method_slug The slug for the payment method to deactivate.
432
-     * @return int count of rows updated.
433
-     * @throws EE_Error
434
-     */
435
-    public function deactivate_payment_method($payment_method_slug)
436
-    {
437
-        EE_Log::instance()->log(
438
-            __FILE__,
439
-            __FUNCTION__,
440
-            sprintf(
441
-                esc_html__(
442
-                    'Payment method with slug %1$s is being deactivated by site admin',
443
-                    'event_espresso'
444
-                ),
445
-                $payment_method_slug
446
-            ),
447
-            'payment_method_change'
448
-        );
449
-        $count_updated = EEM_Payment_Method::instance()->update(
450
-            array('PMD_scope' => array()),
451
-            array(array('PMD_slug' => $payment_method_slug))
452
-        );
453
-        do_action(
454
-            'AHEE__EE_Payment_Method_Manager__deactivate_payment_method__after_deactivating_payment_method',
455
-            $payment_method_slug,
456
-            $count_updated
457
-        );
458
-        return $count_updated;
459
-    }
460
-
461
-
462
-    /**
463
-     * initializes payment method access caps via EE_Capabilities::init_role_caps()
464
-     * upon EE_Payment_Method_Manager construction
465
-     *
466
-     * @throws EE_Error
467
-     * @throws DomainException
468
-     */
469
-    protected function initializePaymentMethodCaps()
470
-    {
471
-        // don't do this twice
472
-        if ($this->payment_method_caps_initialized) {
473
-            return;
474
-        }
475
-        EE_Capabilities::instance()->addCaps(
476
-            $this->getPaymentMethodCaps()
477
-        );
478
-        $this->payment_method_caps_initialized = true;
479
-    }
480
-
481
-
482
-    /**
483
-     * array  of dynamic payment method access caps.
484
-     * at the time of writing, october 20 2014, these are the caps added:
485
-     *  ee_payment_method_admin_only
486
-     *  ee_payment_method_aim
487
-     *  ee_payment_method_bank
488
-     *  ee_payment_method_check
489
-     *  ee_payment_method_invoice
490
-     *  ee_payment_method_mijireh
491
-     *  ee_payment_method_paypal_pro
492
-     *  ee_payment_method_paypal_standard
493
-     * Any other payment methods added to core or via addons will also get
494
-     * their related capability automatically added too, so long as they are
495
-     * registered properly using EE_Register_Payment_Method::register()
496
-     *
497
-     * @return array
498
-     * @throws DomainException
499
-     */
500
-    protected function getPaymentMethodCaps()
501
-    {
502
-        $caps = array();
503
-        foreach ($this->payment_method_type_names() as $payment_method_name) {
504
-            $caps = $this->addPaymentMethodCap($payment_method_name, $caps);
505
-        }
506
-        return $caps;
507
-    }
508
-
509
-
510
-    /**
511
-     * @param string $payment_method_name
512
-     * @param array  $payment_method_caps
513
-     * @param string $role
514
-     * @return array
515
-     * @throws DomainException
516
-     */
517
-    public function addPaymentMethodCap($payment_method_name, array $payment_method_caps, $role = 'administrator')
518
-    {
519
-        if (empty($payment_method_name)) {
520
-            throw new DomainException(
521
-                esc_html__(
522
-                    'The name of a payment method must be specified to add capabilities.',
523
-                    'event_espresso'
524
-                )
525
-            );
526
-        }
527
-        if (empty($role)) {
528
-            throw new DomainException(
529
-                sprintf(
530
-                    esc_html__(
531
-                        'No role was supplied while trying to add capabilities for the %1$s payment method.',
532
-                        'event_espresso'
533
-                    ),
534
-                    $payment_method_name
535
-                )
536
-            );
537
-        }
538
-        if (! isset($payment_method_caps[ $role ])) {
539
-            $payment_method_caps[ $role ] = array();
540
-        }
541
-        $payment_method_caps[ $role ][] = EE_Payment_Method_Manager::CAPABILITIES_PREFIX
542
-                                          . strtolower($payment_method_name);
543
-        return $payment_method_caps;
544
-    }
545
-
546
-
547
-    /**
548
-     * callback for FHEE__EE_Capabilities__init_role_caps__caps_map filter
549
-     * to add dynamic payment method access caps when capabilities are reset
550
-     * (or if that filter is called and PM caps are not already set)
551
-     *
552
-     * @param array $caps capabilities being filtered
553
-     * @param bool  $reset
554
-     * @return array
555
-     * @throws DomainException
556
-     */
557
-    public function addPaymentMethodCapsDuringReset(array $caps, $reset = false)
558
-    {
559
-        if ($reset || ! $this->payment_method_caps_initialized) {
560
-            $this->payment_method_caps_initialized = true;
561
-            $caps = array_merge_recursive($caps, $this->getPaymentMethodCaps());
562
-        }
563
-        return $caps;
564
-    }
565
-
566
-
567
-    /**
568
-     * @deprecated 4.9.42
569
-     * @param $caps
570
-     * @return mixed
571
-     */
572
-    public function add_payment_method_caps($caps)
573
-    {
574
-        return $caps;
575
-    }
19
+	/**
20
+	 * prefix added to all payment method capabilities names
21
+	 */
22
+	const   CAPABILITIES_PREFIX = 'ee_payment_method_';
23
+
24
+	/**
25
+	 * @var EE_Payment_Method_Manager $_instance
26
+	 */
27
+	private static $_instance;
28
+
29
+	/**
30
+	 * @var boolean
31
+	 */
32
+	protected $payment_method_caps_initialized = false;
33
+
34
+	/**
35
+	 * @var array keys are class names without 'EE_PMT_', values are their filepaths
36
+	 */
37
+	protected $_payment_method_types = array();
38
+
39
+	/**
40
+	 * @var EE_PMT_Base[]
41
+	 */
42
+	protected $payment_method_objects = array();
43
+
44
+
45
+	/**
46
+	 * EE_Payment_Method_Manager constructor.
47
+	 *
48
+	 * @throws EE_Error
49
+	 * @throws DomainException
50
+	 */
51
+	public function __construct()
52
+	{
53
+		// if in admin lets ensure caps are set.
54
+		if (is_admin()) {
55
+			$this->_register_payment_methods();
56
+			// set them immediately
57
+			$this->initializePaymentMethodCaps();
58
+			// plus any time they get reset
59
+			add_filter(
60
+				'FHEE__EE_Capabilities__addCaps__capabilities_to_add',
61
+				array($this, 'addPaymentMethodCapsDuringReset')
62
+			);
63
+		}
64
+	}
65
+
66
+
67
+	/**
68
+	 * @singleton method used to instantiate class object
69
+	 * @return EE_Payment_Method_Manager instance
70
+	 * @throws DomainException
71
+	 * @throws EE_Error
72
+	 */
73
+	public static function instance()
74
+	{
75
+		// check if class object is instantiated, and instantiated properly
76
+		if (! self::$_instance instanceof EE_Payment_Method_Manager) {
77
+			EE_Registry::instance()->load_lib('PMT_Base');
78
+			self::$_instance = new self();
79
+		}
80
+		return self::$_instance;
81
+	}
82
+
83
+
84
+	/**
85
+	 * Resets the instance and returns a new one
86
+	 *
87
+	 * @return EE_Payment_Method_Manager
88
+	 * @throws DomainException
89
+	 * @throws EE_Error
90
+	 */
91
+	public static function reset()
92
+	{
93
+		self::$_instance = null;
94
+		return self::instance();
95
+	}
96
+
97
+
98
+	/**
99
+	 * If necessary, re-register payment methods
100
+	 *
101
+	 * @param boolean $force_recheck whether to recheck for payment method types,
102
+	 *                               or just re-use the PMTs we found last time we checked during this request (if
103
+	 *                               we have not yet checked during this request, then we need to check anyways)
104
+	 */
105
+	public function maybe_register_payment_methods($force_recheck = false)
106
+	{
107
+		if (! $this->_payment_method_types || $force_recheck) {
108
+			$this->_register_payment_methods();
109
+		}
110
+	}
111
+
112
+
113
+	/**
114
+	 * register_payment_methods
115
+	 *
116
+	 * @return array
117
+	 */
118
+	protected function _register_payment_methods()
119
+	{
120
+		// grab list of installed modules
121
+		$pm_to_register = glob(EE_PAYMENT_METHODS . '*', GLOB_ONLYDIR);
122
+		// filter list of modules to register
123
+		$pm_to_register = apply_filters(
124
+			'FHEE__EE_Payment_Method_Manager__register_payment_methods__payment_methods_to_register',
125
+			$pm_to_register
126
+		);
127
+		// remove any duplicates if that should happen for some reason
128
+		$pm_to_register = array_unique($pm_to_register);
129
+		// loop through folders
130
+		foreach ($pm_to_register as $pm_path) {
131
+			$this->register_payment_method($pm_path);
132
+		}
133
+		do_action('FHEE__EE_Payment_Method_Manager__register_payment_methods__registered_payment_methods');
134
+		// filter list of installed modules
135
+		// keep them organized alphabetically by the payment method type's name
136
+		ksort($this->_payment_method_types);
137
+		return apply_filters(
138
+			'FHEE__EE_Payment_Method_Manager__register_payment_methods__installed_payment_methods',
139
+			$this->_payment_method_types
140
+		);
141
+	}
142
+
143
+
144
+	/**
145
+	 * register_payment_method- makes core aware of this payment method
146
+	 *
147
+	 * @param string $payment_method_path - full path up to and including payment method folder
148
+	 * @return boolean
149
+	 */
150
+	public function register_payment_method($payment_method_path = '')
151
+	{
152
+		do_action('AHEE__EE_Payment_Method_Manager__register_payment_method__begin', $payment_method_path);
153
+		$module_ext = '.pm.php';
154
+		// make all separators match
155
+		$payment_method_path = rtrim(str_replace('/\\', '/', $payment_method_path), '/');
156
+		// grab and sanitize module name
157
+		$module_dir = basename($payment_method_path);
158
+		// create class name from module directory name
159
+		$module = str_replace(array('_', ' '), array(' ', '_'), $module_dir);
160
+		// add class prefix
161
+		$module_class = 'EE_PMT_' . $module;
162
+		// does the module exist ?
163
+		if (! is_readable($payment_method_path . '/' . $module_class . $module_ext)) {
164
+			$msg = sprintf(
165
+				esc_html__(
166
+					'The requested %s payment method file could not be found or is not readable due to file permissions.',
167
+					'event_espresso'
168
+				),
169
+				$module
170
+			);
171
+			EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
172
+			return false;
173
+		}
174
+		// load the module class file
175
+		require_once($payment_method_path . '/' . $module_class . $module_ext);
176
+		// verify that class exists
177
+		if (! class_exists($module_class)) {
178
+			$msg = sprintf(
179
+				esc_html__('The requested %s module class does not exist.', 'event_espresso'),
180
+				$module_class
181
+			);
182
+			EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
183
+			return false;
184
+		}
185
+		// add to array of registered modules
186
+		$this->_payment_method_types[ $module ] = $payment_method_path . '/' . $module_class . $module_ext;
187
+		ksort($this->_payment_method_types);
188
+		return true;
189
+	}
190
+
191
+
192
+	/**
193
+	 * Checks if a payment method has been registered, and if so includes it
194
+	 *
195
+	 * @param string  $payment_method_name like 'PayPal_Pro', (ie class name without the prefix 'EEPM_')
196
+	 * @param boolean $force_recheck       whether to force re-checking for new payment method types
197
+	 * @return boolean
198
+	 */
199
+	public function payment_method_type_exists($payment_method_name, $force_recheck = false)
200
+	{
201
+		if (
202
+			$force_recheck
203
+			|| ! is_array($this->_payment_method_types)
204
+			|| ! isset($this->_payment_method_types[ $payment_method_name ])
205
+		) {
206
+			$this->maybe_register_payment_methods($force_recheck);
207
+		}
208
+		if (isset($this->_payment_method_types[ $payment_method_name ])) {
209
+			require_once($this->_payment_method_types[ $payment_method_name ]);
210
+			return true;
211
+		}
212
+		return false;
213
+	}
214
+
215
+
216
+	/**
217
+	 * Returns all the class names of the various payment method types
218
+	 *
219
+	 * @param boolean $with_prefixes TRUE: get payment method type class names; false just their 'names'
220
+	 *                               (what you'd find in wp_esp_payment_method.PMD_type)
221
+	 * @param boolean $force_recheck whether to force re-checking for new payment method types
222
+	 * @return array
223
+	 */
224
+	public function payment_method_type_names($with_prefixes = false, $force_recheck = false)
225
+	{
226
+		$this->maybe_register_payment_methods($force_recheck);
227
+		if ($with_prefixes) {
228
+			$classnames = array_keys($this->_payment_method_types);
229
+			$payment_methods = array();
230
+			foreach ($classnames as $classname) {
231
+				$payment_methods[] = $this->payment_method_class_from_type($classname);
232
+			}
233
+			return $payment_methods;
234
+		}
235
+		return array_keys($this->_payment_method_types);
236
+	}
237
+
238
+
239
+	/**
240
+	 * Gets an object of each payment method type, none of which are bound to a
241
+	 * payment method instance
242
+	 *
243
+	 * @param boolean $force_recheck whether to force re-checking for new payment method types
244
+	 * @return EE_PMT_Base[]
245
+	 */
246
+	public function payment_method_types($force_recheck = false)
247
+	{
248
+		if ($force_recheck || empty($this->payment_method_objects)) {
249
+			$this->maybe_register_payment_methods($force_recheck);
250
+			foreach ($this->payment_method_type_names(true) as $classname) {
251
+				if (! isset($this->payment_method_objects[ $classname ])) {
252
+					$this->payment_method_objects[ $classname ] = new $classname();
253
+				}
254
+			}
255
+		}
256
+		return $this->payment_method_objects;
257
+	}
258
+
259
+
260
+	/**
261
+	 * Changes the payment method's class name into the payment method type's name
262
+	 * (as used on the payment method's table's PMD_type field)
263
+	 *
264
+	 * @param string $classname
265
+	 * @return string
266
+	 */
267
+	public function payment_method_type_sans_class_prefix($classname)
268
+	{
269
+		return str_replace('EE_PMT_', '', $classname);
270
+	}
271
+
272
+
273
+	/**
274
+	 * Does the opposite of payment-method_type_sans_prefix
275
+	 *
276
+	 * @param string $type
277
+	 * @return string
278
+	 */
279
+	public function payment_method_class_from_type($type)
280
+	{
281
+		return 'EE_PMT_' . $type;
282
+	}
283
+
284
+
285
+	/**
286
+	 * Activates a payment method of the given type.
287
+	 *
288
+	 * @param string $payment_method_type the PMT_type; for EE_PMT_Invoice this would be 'Invoice'
289
+	 * @return EE_Payment_Method
290
+	 * @throws InvalidDataTypeException
291
+	 * @throws EE_Error
292
+	 */
293
+	public function activate_a_payment_method_of_type($payment_method_type)
294
+	{
295
+		$this->maybe_register_payment_methods();
296
+		$payment_method = EEM_Payment_Method::instance()->get_one_of_type($payment_method_type);
297
+		if (! $payment_method instanceof EE_Payment_Method) {
298
+			$pm_type_class = $this->payment_method_class_from_type($payment_method_type);
299
+			if (class_exists($pm_type_class)) {
300
+				/** @var $pm_type_obj EE_PMT_Base */
301
+				$pm_type_obj = new $pm_type_class();
302
+				$payment_method = EEM_Payment_Method::instance()->get_one_by_slug($pm_type_obj->system_name());
303
+				if (! $payment_method) {
304
+					$payment_method = $this->create_payment_method_of_type($pm_type_obj);
305
+				}
306
+				$payment_method->set_type($payment_method_type);
307
+				$this->initialize_payment_method($payment_method);
308
+			} else {
309
+				throw new EE_Error(
310
+					sprintf(
311
+						esc_html__(
312
+							'There is no payment method of type %1$s, so it could not be activated',
313
+							'event_espresso'
314
+						),
315
+						$pm_type_class
316
+					)
317
+				);
318
+			}
319
+		}
320
+		$payment_method->set_active();
321
+		$payment_method->save();
322
+		/** @type EE_Message_Resource_Manager $message_resource_manager */
323
+		// if this was the invoice message type, make sure users can view their invoices
324
+		if (
325
+			$payment_method->type() === 'Invoice'
326
+			&& (
327
+			! EEH_MSG_Template::is_mt_active('invoice')
328
+			)
329
+		) {
330
+			$message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
331
+			/** @type EE_Message_Resource_Manager $message_resource_manager */
332
+			$message_resource_manager->ensure_message_type_is_active('invoice', 'html');
333
+			new PersistentAdminNotice(
334
+				'invoice_pm_requirements_notice',
335
+				sprintf(
336
+					esc_html__(
337
+						'The Invoice payment method has been activated. It requires the %1$sinvoice message%2$s type to be active, so it was automatically activated for you.',
338
+						'event_espresso'
339
+					),
340
+					'<a href="' . admin_url('admin.php?page=espresso_messages&action=settings') . '">',
341
+					'</a>'
342
+				),
343
+				true
344
+			);
345
+		}
346
+		return $payment_method;
347
+	}
348
+
349
+
350
+	/**
351
+	 * Creates a payment method of the specified type. Does not save it.
352
+	 *
353
+	 * @global WP_User    $current_user
354
+	 * @param EE_PMT_Base $pm_type_obj
355
+	 * @return EE_Payment_Method
356
+	 * @throws EE_Error
357
+	 */
358
+	public function create_payment_method_of_type($pm_type_obj)
359
+	{
360
+		global $current_user;
361
+		$payment_method = EE_Payment_Method::new_instance(
362
+			array(
363
+				'PMD_type'       => $pm_type_obj->system_name(),
364
+				'PMD_name'       => $pm_type_obj->defaultFrontendName(),
365
+				'PMD_admin_name' => $pm_type_obj->pretty_name(),
366
+				'PMD_slug'       => $pm_type_obj->system_name(),// automatically converted to slug
367
+				'PMD_wp_user'    => $current_user->ID,
368
+				'PMD_order'      => EEM_Payment_Method::instance()->count(
369
+					array(array('PMD_type' => array('!=', 'Admin_Only')))
370
+				) * 10,
371
+			)
372
+		);
373
+		return $payment_method;
374
+	}
375
+
376
+
377
+	/**
378
+	 * Sets the initial payment method properties (including extra meta)
379
+	 *
380
+	 * @param EE_Payment_Method $payment_method
381
+	 * @return EE_Payment_Method
382
+	 * @throws EE_Error
383
+	 */
384
+	public function initialize_payment_method($payment_method)
385
+	{
386
+		$pm_type_obj = $payment_method->type_obj();
387
+		$payment_method->set_description($pm_type_obj->default_description());
388
+		if (! $payment_method->button_url()) {
389
+			$payment_method->set_button_url($pm_type_obj->default_button_url());
390
+		}
391
+		// now add setup its default extra meta properties
392
+		$extra_metas = $pm_type_obj->settings_form()->extra_meta_inputs();
393
+		if (! empty($extra_metas)) {
394
+			// verify the payment method has an ID before adding extra meta
395
+			if (! $payment_method->ID()) {
396
+				$payment_method->save();
397
+			}
398
+			foreach ($extra_metas as $meta_name => $input) {
399
+				$payment_method->update_extra_meta($meta_name, $input->raw_value());
400
+			}
401
+		}
402
+		return $payment_method;
403
+	}
404
+
405
+
406
+	/**
407
+	 * Makes sure the payment method is related to the specified payment method
408
+	 *
409
+	 * @deprecated in 4.9.40 because the currency payment method table is being deprecated
410
+	 * @param EE_Payment_Method $payment_method
411
+	 * @return EE_Payment_Method
412
+	 * @throws EE_Error
413
+	 */
414
+	public function set_usable_currencies_on_payment_method($payment_method)
415
+	{
416
+		EE_Error::doing_it_wrong(
417
+			'EE_Payment_Method_Manager::set_usable_currencies_on_payment_method',
418
+			esc_html__(
419
+				'We no longer define what currencies are usable by payment methods. Its not used nor efficient.',
420
+				'event_espresso'
421
+			),
422
+			'4.9.40'
423
+		);
424
+		return $payment_method;
425
+	}
426
+
427
+
428
+	/**
429
+	 * Deactivates a payment method of the given payment method slug.
430
+	 *
431
+	 * @param string $payment_method_slug The slug for the payment method to deactivate.
432
+	 * @return int count of rows updated.
433
+	 * @throws EE_Error
434
+	 */
435
+	public function deactivate_payment_method($payment_method_slug)
436
+	{
437
+		EE_Log::instance()->log(
438
+			__FILE__,
439
+			__FUNCTION__,
440
+			sprintf(
441
+				esc_html__(
442
+					'Payment method with slug %1$s is being deactivated by site admin',
443
+					'event_espresso'
444
+				),
445
+				$payment_method_slug
446
+			),
447
+			'payment_method_change'
448
+		);
449
+		$count_updated = EEM_Payment_Method::instance()->update(
450
+			array('PMD_scope' => array()),
451
+			array(array('PMD_slug' => $payment_method_slug))
452
+		);
453
+		do_action(
454
+			'AHEE__EE_Payment_Method_Manager__deactivate_payment_method__after_deactivating_payment_method',
455
+			$payment_method_slug,
456
+			$count_updated
457
+		);
458
+		return $count_updated;
459
+	}
460
+
461
+
462
+	/**
463
+	 * initializes payment method access caps via EE_Capabilities::init_role_caps()
464
+	 * upon EE_Payment_Method_Manager construction
465
+	 *
466
+	 * @throws EE_Error
467
+	 * @throws DomainException
468
+	 */
469
+	protected function initializePaymentMethodCaps()
470
+	{
471
+		// don't do this twice
472
+		if ($this->payment_method_caps_initialized) {
473
+			return;
474
+		}
475
+		EE_Capabilities::instance()->addCaps(
476
+			$this->getPaymentMethodCaps()
477
+		);
478
+		$this->payment_method_caps_initialized = true;
479
+	}
480
+
481
+
482
+	/**
483
+	 * array  of dynamic payment method access caps.
484
+	 * at the time of writing, october 20 2014, these are the caps added:
485
+	 *  ee_payment_method_admin_only
486
+	 *  ee_payment_method_aim
487
+	 *  ee_payment_method_bank
488
+	 *  ee_payment_method_check
489
+	 *  ee_payment_method_invoice
490
+	 *  ee_payment_method_mijireh
491
+	 *  ee_payment_method_paypal_pro
492
+	 *  ee_payment_method_paypal_standard
493
+	 * Any other payment methods added to core or via addons will also get
494
+	 * their related capability automatically added too, so long as they are
495
+	 * registered properly using EE_Register_Payment_Method::register()
496
+	 *
497
+	 * @return array
498
+	 * @throws DomainException
499
+	 */
500
+	protected function getPaymentMethodCaps()
501
+	{
502
+		$caps = array();
503
+		foreach ($this->payment_method_type_names() as $payment_method_name) {
504
+			$caps = $this->addPaymentMethodCap($payment_method_name, $caps);
505
+		}
506
+		return $caps;
507
+	}
508
+
509
+
510
+	/**
511
+	 * @param string $payment_method_name
512
+	 * @param array  $payment_method_caps
513
+	 * @param string $role
514
+	 * @return array
515
+	 * @throws DomainException
516
+	 */
517
+	public function addPaymentMethodCap($payment_method_name, array $payment_method_caps, $role = 'administrator')
518
+	{
519
+		if (empty($payment_method_name)) {
520
+			throw new DomainException(
521
+				esc_html__(
522
+					'The name of a payment method must be specified to add capabilities.',
523
+					'event_espresso'
524
+				)
525
+			);
526
+		}
527
+		if (empty($role)) {
528
+			throw new DomainException(
529
+				sprintf(
530
+					esc_html__(
531
+						'No role was supplied while trying to add capabilities for the %1$s payment method.',
532
+						'event_espresso'
533
+					),
534
+					$payment_method_name
535
+				)
536
+			);
537
+		}
538
+		if (! isset($payment_method_caps[ $role ])) {
539
+			$payment_method_caps[ $role ] = array();
540
+		}
541
+		$payment_method_caps[ $role ][] = EE_Payment_Method_Manager::CAPABILITIES_PREFIX
542
+										  . strtolower($payment_method_name);
543
+		return $payment_method_caps;
544
+	}
545
+
546
+
547
+	/**
548
+	 * callback for FHEE__EE_Capabilities__init_role_caps__caps_map filter
549
+	 * to add dynamic payment method access caps when capabilities are reset
550
+	 * (or if that filter is called and PM caps are not already set)
551
+	 *
552
+	 * @param array $caps capabilities being filtered
553
+	 * @param bool  $reset
554
+	 * @return array
555
+	 * @throws DomainException
556
+	 */
557
+	public function addPaymentMethodCapsDuringReset(array $caps, $reset = false)
558
+	{
559
+		if ($reset || ! $this->payment_method_caps_initialized) {
560
+			$this->payment_method_caps_initialized = true;
561
+			$caps = array_merge_recursive($caps, $this->getPaymentMethodCaps());
562
+		}
563
+		return $caps;
564
+	}
565
+
566
+
567
+	/**
568
+	 * @deprecated 4.9.42
569
+	 * @param $caps
570
+	 * @return mixed
571
+	 */
572
+	public function add_payment_method_caps($caps)
573
+	{
574
+		return $caps;
575
+	}
576 576
 }
Please login to merge, or discard this patch.