Completed
Branch dev (143a30)
by
unknown
08:42 queued 06:17
created
caffeinated/modules/events_archive_caff/EED_Events_Archive_Caff.module.php 1 patch
Indentation   +249 added lines, -249 removed lines patch added patch discarded remove patch
@@ -14,268 +14,268 @@
 block discarded – undo
14 14
 class EED_Events_Archive_Caff extends EED_Events_Archive
15 15
 {
16 16
 
17
-    /**
18
-     * @return EED_Events_Archive_Caff|EED_Module
19
-     */
20
-    public static function instance()
21
-    {
22
-        return parent::get_instance(__CLASS__);
23
-    }
17
+	/**
18
+	 * @return EED_Events_Archive_Caff|EED_Module
19
+	 */
20
+	public static function instance()
21
+	{
22
+		return parent::get_instance(__CLASS__);
23
+	}
24 24
 
25 25
 
26
-    /**
27
-     * set_hooks - for hooking into EE Core, other modules, etc
28
-     *
29
-     * @return    void
30
-     */
31
-    public static function set_hooks()
32
-    {
33
-    }
26
+	/**
27
+	 * set_hooks - for hooking into EE Core, other modules, etc
28
+	 *
29
+	 * @return    void
30
+	 */
31
+	public static function set_hooks()
32
+	{
33
+	}
34 34
 
35
-    /**
36
-     *    set_hooks_admin - for hooking into EE Admin Core, other modules, etc
37
-     *
38
-     * @access    public
39
-     * @return    void
40
-     */
41
-    public static function set_hooks_admin()
42
-    {
43
-        self::setDefinitions();
44
-        add_action(
45
-            'AHEE__template_settings__template__before_settings_form',
46
-            array('EED_Events_Archive_Caff', 'template_settings_form'),
47
-            10
48
-        );
49
-        add_filter(
50
-            'FHEE__General_Settings_Admin_Page__update_template_settings__data',
51
-            array('EED_Events_Archive_Caff', 'update_template_settings'),
52
-            10,
53
-            2
54
-        );
55
-        // AJAX
56
-        add_action(
57
-            'wp_ajax_espresso_update_event_archive_order',
58
-            array('EED_Events_Archive_Caff', 'update_event_archive_order')
59
-        );
60
-        add_action(
61
-            'wp_ajax_nopriv_espresso_update_event_archive_order',
62
-            array('EED_Events_Archive_Caff', 'update_event_archive_order')
63
-        );
64
-    }
35
+	/**
36
+	 *    set_hooks_admin - for hooking into EE Admin Core, other modules, etc
37
+	 *
38
+	 * @access    public
39
+	 * @return    void
40
+	 */
41
+	public static function set_hooks_admin()
42
+	{
43
+		self::setDefinitions();
44
+		add_action(
45
+			'AHEE__template_settings__template__before_settings_form',
46
+			array('EED_Events_Archive_Caff', 'template_settings_form'),
47
+			10
48
+		);
49
+		add_filter(
50
+			'FHEE__General_Settings_Admin_Page__update_template_settings__data',
51
+			array('EED_Events_Archive_Caff', 'update_template_settings'),
52
+			10,
53
+			2
54
+		);
55
+		// AJAX
56
+		add_action(
57
+			'wp_ajax_espresso_update_event_archive_order',
58
+			array('EED_Events_Archive_Caff', 'update_event_archive_order')
59
+		);
60
+		add_action(
61
+			'wp_ajax_nopriv_espresso_update_event_archive_order',
62
+			array('EED_Events_Archive_Caff', 'update_event_archive_order')
63
+		);
64
+	}
65 65
 
66 66
 
67
-    /**
68
-     * run - initial module setup
69
-     *
70
-     * @param    WP $WP
71
-     * @return    void
72
-     */
73
-    public function run($WP)
74
-    {
75
-    }
67
+	/**
68
+	 * run - initial module setup
69
+	 *
70
+	 * @param    WP $WP
71
+	 * @return    void
72
+	 */
73
+	public function run($WP)
74
+	{
75
+	}
76 76
 
77 77
 
78
-    /**
79
-     * Conditionally set constants if they haven't been defined yet.
80
-     */
81
-    public static function setDefinitions()
82
-    {
83
-        if (! defined('EVENTS_ARCHIVE_CAFF_TEMPLATES_PATH')) {
84
-            define(
85
-                'EVENTS_ARCHIVE_CAFF_TEMPLATES_PATH',
86
-                str_replace('\\', DS, plugin_dir_path(__FILE__)) . 'templates/'
87
-            );
88
-            define('EVENT_ARCHIVE_CAFF_ASSETS_URL', plugin_dir_url(__FILE__) . 'assets/');
89
-        }
90
-    }
78
+	/**
79
+	 * Conditionally set constants if they haven't been defined yet.
80
+	 */
81
+	public static function setDefinitions()
82
+	{
83
+		if (! defined('EVENTS_ARCHIVE_CAFF_TEMPLATES_PATH')) {
84
+			define(
85
+				'EVENTS_ARCHIVE_CAFF_TEMPLATES_PATH',
86
+				str_replace('\\', DS, plugin_dir_path(__FILE__)) . 'templates/'
87
+			);
88
+			define('EVENT_ARCHIVE_CAFF_ASSETS_URL', plugin_dir_url(__FILE__) . 'assets/');
89
+		}
90
+	}
91 91
 
92 92
 
93
-    /**
94
-     * @return void
95
-     * @throws DomainException
96
-     * @throws InvalidArgumentException
97
-     * @throws InvalidDataTypeException
98
-     * @throws InvalidInterfaceException
99
-     */
100
-    public static function template_settings_form()
101
-    {
102
-        /** @var EE_Admin_Page_Loader $admin_page_loader */
103
-        $admin_page_loader = LoaderFactory::getLoader()->getShared('EE_Admin_Page_Loader');
104
-        // grab general settings admin page and remove the existing hook callback
105
-        $gen_set_admin = $admin_page_loader->get_admin_page_object('general_settings');
106
-        if ($gen_set_admin instanceof General_Settings_Admin_Page) {
107
-            remove_action(
108
-                'AHEE__template_settings__template__before_settings_form',
109
-                array($gen_set_admin, 'template_settings_caff_features'),
110
-                100
111
-            );
112
-        }
113
-        // first just grab the template settings
114
-        $config = EE_Registry::instance()->CFG->template_settings;
115
-        // then if the Event Archive config is valid, use that, else create a new one
116
-        $config = $config instanceof EE_Template_Config
117
-                  && $config->EED_Events_Archive instanceof EE_Events_Archive_Config
118
-            ? $config->EED_Events_Archive
119
-            : new EE_Events_Archive_Config();
120
-        $config = apply_filters(
121
-            'FHEE__EED_Events_Archive__template_settings_form__event_list_config',
122
-            $config
123
-        );
124
-        $config->display_status_banner = isset($config->display_status_banner)
125
-            ? $config->display_status_banner
126
-            : 0;
127
-        $config->display_description = isset($config->display_description)
128
-            ? $config->display_description
129
-            : 1;
130
-        $config->display_ticket_selector = isset($config->display_ticket_selector)
131
-            ? $config->display_ticket_selector
132
-            : 0;
133
-        $config->display_datetimes = isset($config->display_datetimes)
134
-            ? $config->display_datetimes
135
-            : 1;
136
-        $config->display_venue = isset($config->display_venue)
137
-            ? $config->display_venue
138
-            : 0;
139
-        $config->display_expired_events = isset($config->display_expired_events)
140
-            ? $config->display_expired_events
141
-            : 0;
142
-        // display order options
143
-        $config->use_sortable_display_order = isset($config->use_sortable_display_order)
144
-            ? $config->use_sortable_display_order
145
-            : false;
146
-        $config->display_order_tickets = isset($config->display_order_tickets)
147
-            ? $config->display_order_tickets
148
-            : 120;
149
-        $config->display_order_datetimes = isset($config->display_order_datetimes)
150
-            ? $config->display_order_datetimes
151
-            : 110;
152
-        $config->display_order_event = isset($config->display_order_event)
153
-            ? $config->display_order_event
154
-            : 100;
155
-        $config->display_order_venue = isset($config->display_order_venue)
156
-            ? $config->display_order_venue
157
-            : 130;
158
-        // get template parts
159
-        $template_parts = EED_Events_Archive::instance()->initialize_template_parts($config);
160
-        // convert to array so that we can add more properties
161
-        $config = get_object_vars($config);
162
-        $config['event_archive_display_order'] = $template_parts->generate_sortable_list_of_template_parts(
163
-            'event-archive-sortable-js',
164
-            '',
165
-            'archive-sortable-li archive-sortable-js'
166
-        );
167
-        EEH_Template::display_template(
168
-            EVENTS_ARCHIVE_CAFF_TEMPLATES_PATH . 'admin-event-list-settings.template.php',
169
-            $config
170
-        );
171
-    }
93
+	/**
94
+	 * @return void
95
+	 * @throws DomainException
96
+	 * @throws InvalidArgumentException
97
+	 * @throws InvalidDataTypeException
98
+	 * @throws InvalidInterfaceException
99
+	 */
100
+	public static function template_settings_form()
101
+	{
102
+		/** @var EE_Admin_Page_Loader $admin_page_loader */
103
+		$admin_page_loader = LoaderFactory::getLoader()->getShared('EE_Admin_Page_Loader');
104
+		// grab general settings admin page and remove the existing hook callback
105
+		$gen_set_admin = $admin_page_loader->get_admin_page_object('general_settings');
106
+		if ($gen_set_admin instanceof General_Settings_Admin_Page) {
107
+			remove_action(
108
+				'AHEE__template_settings__template__before_settings_form',
109
+				array($gen_set_admin, 'template_settings_caff_features'),
110
+				100
111
+			);
112
+		}
113
+		// first just grab the template settings
114
+		$config = EE_Registry::instance()->CFG->template_settings;
115
+		// then if the Event Archive config is valid, use that, else create a new one
116
+		$config = $config instanceof EE_Template_Config
117
+				  && $config->EED_Events_Archive instanceof EE_Events_Archive_Config
118
+			? $config->EED_Events_Archive
119
+			: new EE_Events_Archive_Config();
120
+		$config = apply_filters(
121
+			'FHEE__EED_Events_Archive__template_settings_form__event_list_config',
122
+			$config
123
+		);
124
+		$config->display_status_banner = isset($config->display_status_banner)
125
+			? $config->display_status_banner
126
+			: 0;
127
+		$config->display_description = isset($config->display_description)
128
+			? $config->display_description
129
+			: 1;
130
+		$config->display_ticket_selector = isset($config->display_ticket_selector)
131
+			? $config->display_ticket_selector
132
+			: 0;
133
+		$config->display_datetimes = isset($config->display_datetimes)
134
+			? $config->display_datetimes
135
+			: 1;
136
+		$config->display_venue = isset($config->display_venue)
137
+			? $config->display_venue
138
+			: 0;
139
+		$config->display_expired_events = isset($config->display_expired_events)
140
+			? $config->display_expired_events
141
+			: 0;
142
+		// display order options
143
+		$config->use_sortable_display_order = isset($config->use_sortable_display_order)
144
+			? $config->use_sortable_display_order
145
+			: false;
146
+		$config->display_order_tickets = isset($config->display_order_tickets)
147
+			? $config->display_order_tickets
148
+			: 120;
149
+		$config->display_order_datetimes = isset($config->display_order_datetimes)
150
+			? $config->display_order_datetimes
151
+			: 110;
152
+		$config->display_order_event = isset($config->display_order_event)
153
+			? $config->display_order_event
154
+			: 100;
155
+		$config->display_order_venue = isset($config->display_order_venue)
156
+			? $config->display_order_venue
157
+			: 130;
158
+		// get template parts
159
+		$template_parts = EED_Events_Archive::instance()->initialize_template_parts($config);
160
+		// convert to array so that we can add more properties
161
+		$config = get_object_vars($config);
162
+		$config['event_archive_display_order'] = $template_parts->generate_sortable_list_of_template_parts(
163
+			'event-archive-sortable-js',
164
+			'',
165
+			'archive-sortable-li archive-sortable-js'
166
+		);
167
+		EEH_Template::display_template(
168
+			EVENTS_ARCHIVE_CAFF_TEMPLATES_PATH . 'admin-event-list-settings.template.php',
169
+			$config
170
+		);
171
+	}
172 172
 
173 173
 
174
-    /**
175
-     * @param EE_Template_Config $CFG
176
-     * @param array              $REQ
177
-     * @return EE_Template_Config
178
-     */
179
-    public static function update_template_settings($CFG, $REQ)
180
-    {
181
-        // unless we are resetting the config...
182
-        if (
183
-            ! isset($REQ['EED_Events_Archive_reset_event_list_settings'])
184
-            || absint($REQ['EED_Events_Archive_reset_event_list_settings']) !== 1
185
-        ) {
186
-            /** @var EE_Events_Archive_Config $config */
187
-            $config = $CFG->EED_Events_Archive instanceof EE_Events_Archive_Config
188
-                ? $CFG->EED_Events_Archive
189
-                : new EE_Events_Archive_Config();
174
+	/**
175
+	 * @param EE_Template_Config $CFG
176
+	 * @param array              $REQ
177
+	 * @return EE_Template_Config
178
+	 */
179
+	public static function update_template_settings($CFG, $REQ)
180
+	{
181
+		// unless we are resetting the config...
182
+		if (
183
+			! isset($REQ['EED_Events_Archive_reset_event_list_settings'])
184
+			|| absint($REQ['EED_Events_Archive_reset_event_list_settings']) !== 1
185
+		) {
186
+			/** @var EE_Events_Archive_Config $config */
187
+			$config = $CFG->EED_Events_Archive instanceof EE_Events_Archive_Config
188
+				? $CFG->EED_Events_Archive
189
+				: new EE_Events_Archive_Config();
190 190
 
191
-            $config->display_status_banner = isset($REQ['EED_Events_Archive_display_status_banner'])
192
-                ? absint($REQ['EED_Events_Archive_display_status_banner'])
193
-                : 0;
194
-            $config->display_description = isset($REQ['EED_Events_Archive_display_description'])
195
-                ? absint($REQ['EED_Events_Archive_display_description'])
196
-                : 1;
197
-            $config->display_ticket_selector = isset($REQ['EED_Events_Archive_display_ticket_selector'])
198
-                ? absint($REQ['EED_Events_Archive_display_ticket_selector'])
199
-                : 0;
200
-            $config->display_datetimes = isset($REQ['EED_Events_Archive_display_datetimes'])
201
-                ? absint($REQ['EED_Events_Archive_display_datetimes'])
202
-                : 1;
203
-            $config->display_venue = isset($REQ['EED_Events_Archive_display_venue'])
204
-                ? absint($REQ['EED_Events_Archive_display_venue'])
205
-                : 0;
206
-            $config->display_expired_events = isset($REQ['EED_Events_Archive_display_expired_events'])
207
-                ? absint($REQ['EED_Events_Archive_display_expired_events'])
208
-                : 0;
209
-            $config->use_sortable_display_order = isset($REQ['EED_Events_Archive_use_sortable_display_order'])
210
-                ? absint($REQ['EED_Events_Archive_use_sortable_display_order'])
211
-                : 0;
212
-            $config->display_order_event = $config->display_order_event !== null
213
-                                           && $config->use_sortable_display_order
214
-                ? $config->display_order_event
215
-                : EED_Events_Archive::EVENT_DETAILS_PRIORITY;
216
-            $config->display_order_datetimes = $config->display_order_datetimes !== null
217
-                                               && $config->use_sortable_display_order
218
-                ? $config->display_order_datetimes
219
-                : EED_Events_Archive::EVENT_DATETIMES_PRIORITY;
220
-            $config->display_order_tickets = $config->display_order_tickets !== null
221
-                                             && $config->use_sortable_display_order
222
-                ? $config->display_order_tickets
223
-                : EED_Events_Archive::EVENT_TICKETS_PRIORITY;
224
-            $config->display_order_venue = $config->display_order_venue !== null
225
-                                           && $config->use_sortable_display_order
226
-                ? $config->display_order_venue
227
-                : EED_Events_Archive::EVENT_VENUES_PRIORITY;
228
-        } else {
229
-            $config = new EE_Events_Archive_Config();
230
-        }
191
+			$config->display_status_banner = isset($REQ['EED_Events_Archive_display_status_banner'])
192
+				? absint($REQ['EED_Events_Archive_display_status_banner'])
193
+				: 0;
194
+			$config->display_description = isset($REQ['EED_Events_Archive_display_description'])
195
+				? absint($REQ['EED_Events_Archive_display_description'])
196
+				: 1;
197
+			$config->display_ticket_selector = isset($REQ['EED_Events_Archive_display_ticket_selector'])
198
+				? absint($REQ['EED_Events_Archive_display_ticket_selector'])
199
+				: 0;
200
+			$config->display_datetimes = isset($REQ['EED_Events_Archive_display_datetimes'])
201
+				? absint($REQ['EED_Events_Archive_display_datetimes'])
202
+				: 1;
203
+			$config->display_venue = isset($REQ['EED_Events_Archive_display_venue'])
204
+				? absint($REQ['EED_Events_Archive_display_venue'])
205
+				: 0;
206
+			$config->display_expired_events = isset($REQ['EED_Events_Archive_display_expired_events'])
207
+				? absint($REQ['EED_Events_Archive_display_expired_events'])
208
+				: 0;
209
+			$config->use_sortable_display_order = isset($REQ['EED_Events_Archive_use_sortable_display_order'])
210
+				? absint($REQ['EED_Events_Archive_use_sortable_display_order'])
211
+				: 0;
212
+			$config->display_order_event = $config->display_order_event !== null
213
+										   && $config->use_sortable_display_order
214
+				? $config->display_order_event
215
+				: EED_Events_Archive::EVENT_DETAILS_PRIORITY;
216
+			$config->display_order_datetimes = $config->display_order_datetimes !== null
217
+											   && $config->use_sortable_display_order
218
+				? $config->display_order_datetimes
219
+				: EED_Events_Archive::EVENT_DATETIMES_PRIORITY;
220
+			$config->display_order_tickets = $config->display_order_tickets !== null
221
+											 && $config->use_sortable_display_order
222
+				? $config->display_order_tickets
223
+				: EED_Events_Archive::EVENT_TICKETS_PRIORITY;
224
+			$config->display_order_venue = $config->display_order_venue !== null
225
+										   && $config->use_sortable_display_order
226
+				? $config->display_order_venue
227
+				: EED_Events_Archive::EVENT_VENUES_PRIORITY;
228
+		} else {
229
+			$config = new EE_Events_Archive_Config();
230
+		}
231 231
 
232
-        $CFG->EED_Events_Archive = $config;
233
-        do_action('AHEE__EED_Events_Archive__update_template_settings__after_update', $CFG, $REQ);
234
-        return $CFG;
235
-    }
232
+		$CFG->EED_Events_Archive = $config;
233
+		do_action('AHEE__EED_Events_Archive__update_template_settings__after_update', $CFG, $REQ);
234
+		return $CFG;
235
+	}
236 236
 
237 237
 
238
-    /**
239
-     * @return void
240
-     * @throws InvalidArgumentException
241
-     * @throws InvalidDataTypeException
242
-     * @throws InvalidInterfaceException
243
-     */
244
-    public static function update_event_archive_order()
245
-    {
246
-        /** @var EE_Config $config */
247
-        $config = EE_Registry::instance()->CFG;
248
-        $config_saved = false;
249
-        $template_parts = EED_Events_Archive_Caff::getRequest()->getRequestParam('elements');
250
-        if (! empty($template_parts)) {
251
-            $template_parts = explode(',', trim($template_parts, ','));
252
-            foreach ($template_parts as $key => $template_part) {
253
-                $template_part = "display_order_$template_part";
254
-                $priority = ($key * 10) + EED_Events_Archive::EVENT_DETAILS_PRIORITY;
255
-                if (
256
-                    $config->template_settings->EED_Events_Archive instanceof EE_Events_Archive_Config
257
-                    && property_exists(
258
-                        $config->template_settings->EED_Events_Archive,
259
-                        $template_part
260
-                    )
261
-                ) {
262
-                    $config->template_settings->EED_Events_Archive->{$template_part} = $priority;
263
-                }
264
-                do_action("AHEE__EED_Events_Archive__update_event_archive_order__$template_part", $priority);
265
-            }
266
-            $config_saved = $config->update_espresso_config(false, false);
267
-        }
268
-        if ($config_saved) {
269
-            EE_Error::add_success(esc_html__('Display Order has been successfully updated.', 'event_espresso'));
270
-        } else {
271
-            EE_Error::add_error(
272
-                esc_html__('Display Order was not updated.', 'event_espresso'),
273
-                __FILE__,
274
-                __FUNCTION__,
275
-                __LINE__
276
-            );
277
-        }
278
-        echo wp_json_encode(EE_Error::get_notices(false));
279
-        exit();
280
-    }
238
+	/**
239
+	 * @return void
240
+	 * @throws InvalidArgumentException
241
+	 * @throws InvalidDataTypeException
242
+	 * @throws InvalidInterfaceException
243
+	 */
244
+	public static function update_event_archive_order()
245
+	{
246
+		/** @var EE_Config $config */
247
+		$config = EE_Registry::instance()->CFG;
248
+		$config_saved = false;
249
+		$template_parts = EED_Events_Archive_Caff::getRequest()->getRequestParam('elements');
250
+		if (! empty($template_parts)) {
251
+			$template_parts = explode(',', trim($template_parts, ','));
252
+			foreach ($template_parts as $key => $template_part) {
253
+				$template_part = "display_order_$template_part";
254
+				$priority = ($key * 10) + EED_Events_Archive::EVENT_DETAILS_PRIORITY;
255
+				if (
256
+					$config->template_settings->EED_Events_Archive instanceof EE_Events_Archive_Config
257
+					&& property_exists(
258
+						$config->template_settings->EED_Events_Archive,
259
+						$template_part
260
+					)
261
+				) {
262
+					$config->template_settings->EED_Events_Archive->{$template_part} = $priority;
263
+				}
264
+				do_action("AHEE__EED_Events_Archive__update_event_archive_order__$template_part", $priority);
265
+			}
266
+			$config_saved = $config->update_espresso_config(false, false);
267
+		}
268
+		if ($config_saved) {
269
+			EE_Error::add_success(esc_html__('Display Order has been successfully updated.', 'event_espresso'));
270
+		} else {
271
+			EE_Error::add_error(
272
+				esc_html__('Display Order was not updated.', 'event_espresso'),
273
+				__FILE__,
274
+				__FUNCTION__,
275
+				__LINE__
276
+			);
277
+		}
278
+		echo wp_json_encode(EE_Error::get_notices(false));
279
+		exit();
280
+	}
281 281
 }
Please login to merge, or discard this patch.
core/services/request/RequestParams.php 1 patch
Indentation   +323 added lines, -323 removed lines patch added patch discarded remove patch
@@ -14,327 +14,327 @@
 block discarded – undo
14 14
 class RequestParams
15 15
 {
16 16
 
17
-    /**
18
-     * $_GET parameters
19
-     *
20
-     * @var array
21
-     */
22
-    protected $get;
23
-
24
-    /**
25
-     * $_POST parameters
26
-     *
27
-     * @var array
28
-     */
29
-    protected $post;
30
-
31
-    /**
32
-     * $_REQUEST parameters
33
-     *
34
-     * @var array
35
-     */
36
-    protected $request;
37
-
38
-    /**
39
-     * @var RequestSanitizer
40
-     */
41
-    protected $sanitizer;
42
-
43
-
44
-    /**
45
-     * RequestParams constructor.
46
-     *
47
-     * @param RequestSanitizer $sanitizer
48
-     * @param array            $get
49
-     * @param array            $post
50
-     */
51
-    public function __construct(RequestSanitizer $sanitizer, array $get = [], array $post = [])
52
-    {
53
-        $this->sanitizer = $sanitizer;
54
-        $this->get       = ! empty($get) ? $get : $_GET;
55
-        $this->post      = ! empty($post) ? $post : $_POST;
56
-        $this->request   = array_merge($this->get, $this->post);
57
-    }
58
-
59
-
60
-    /**
61
-     * @return array
62
-     */
63
-    public function getParams()
64
-    {
65
-        return $this->get;
66
-    }
67
-
68
-
69
-    /**
70
-     * @return array
71
-     */
72
-    public function postParams()
73
-    {
74
-        return $this->post;
75
-    }
76
-
77
-
78
-    /**
79
-     * returns contents of $_REQUEST
80
-     *
81
-     * @return array
82
-     */
83
-    public function requestParams()
84
-    {
85
-        return $this->request;
86
-    }
87
-
88
-
89
-    /**
90
-     * @param string     $key
91
-     * @param mixed|null $value
92
-     * @param bool       $override_ee
93
-     * @return    void
94
-     */
95
-    public function setRequestParam($key, $value, $override_ee = false)
96
-    {
97
-        // don't allow "ee" to be overwritten unless explicitly instructed to do so
98
-        if ($override_ee || $key !== 'ee' || empty($this->request['ee'])) {
99
-            $this->request[ $key ] = $value;
100
-        }
101
-    }
102
-
103
-
104
-    /**
105
-     * merges the incoming array of parameters into the existing request parameters
106
-     *
107
-     * @param array $request_params
108
-     * @return void
109
-     * @since   4.10.24.p
110
-     */
111
-    public function mergeRequestParams(array $request_params)
112
-    {
113
-        $this->request = array_merge($this->request, $request_params);
114
-    }
115
-
116
-
117
-    /**
118
-     * returns   the value for a request param if the given key exists
119
-     *
120
-     * @param string     $key
121
-     * @param mixed|null $default
122
-     * @param string     $type      the expected data type for the parameter's value, ie: string, int, bool, etc
123
-     * @param bool       $is_array  if true, then parameter value will be treated as an array of $type
124
-     * @param string     $delimiter for CSV type strings that should be returned as an array
125
-     * @return array|bool|float|int|string
126
-     */
127
-    public function getRequestParam($key, $default = null, $type = 'string', $is_array = false, $delimiter = '')
128
-    {
129
-        return $this->sanitizer->clean(
130
-            $this->parameterDrillDown($key, $default, 'get'),
131
-            $type,
132
-            $is_array,
133
-            $delimiter
134
-        );
135
-    }
136
-
137
-
138
-    /**
139
-     * check if param exists
140
-     *
141
-     * @param string $key
142
-     * @return bool
143
-     */
144
-    public function requestParamIsSet($key)
145
-    {
146
-        return (bool) $this->parameterDrillDown($key);
147
-    }
148
-
149
-
150
-    /**
151
-     * check if a request parameter exists whose key that matches the supplied wildcard pattern
152
-     * and return the value for the first match found
153
-     * wildcards can be either of the following:
154
-     *      ? to represent a single character of any type
155
-     *      * to represent one or more characters of any type
156
-     *
157
-     * @param string     $pattern
158
-     * @param mixed|null $default
159
-     * @param string     $type      the expected data type for the parameter's value, ie: string, int, bool, etc
160
-     * @param bool       $is_array  if true, then parameter value will be treated as an array of $type
161
-     * @param string     $delimiter for CSV type strings that should be returned as an array
162
-     * @return array|bool|float|int|string
163
-     */
164
-    public function getMatch($pattern, $default = null, $type = 'string', $is_array = false, $delimiter = '')
165
-    {
166
-        return $this->sanitizer->clean(
167
-            $this->parameterDrillDown($pattern, $default, 'match'),
168
-            $type,
169
-            $is_array,
170
-            $delimiter
171
-        );
172
-    }
173
-
174
-
175
-    /**
176
-     * check if a request parameter exists whose key matches the supplied wildcard pattern
177
-     * wildcards can be either of the following:
178
-     *      ? to represent a single character of any type
179
-     *      * to represent one or more characters of any type
180
-     * returns true if a match is found or false if not
181
-     *
182
-     * @param string $pattern
183
-     * @return bool
184
-     */
185
-    public function matches($pattern)
186
-    {
187
-        return (bool) $this->parameterDrillDown($pattern, false, 'match', 'bool');
188
-    }
189
-
190
-
191
-    /**
192
-     * @see https://stackoverflow.com/questions/6163055/php-string-matching-with-wildcard
193
-     * @param string $pattern               A string including wildcards to be converted to a regex pattern
194
-     *                                      and used to search through the current request's parameter keys
195
-     * @param array  $request_params        The array of request parameters to search through
196
-     * @param mixed  $default               [optional] The value to be returned if no match is found.
197
-     *                                      Default is null
198
-     * @param string $return                [optional] Controls what kind of value is returned.
199
-     *                                      Options are:
200
-     *                                      'bool' will return true or false if match is found or not
201
-     *                                      'key' will return the first key found that matches the supplied pattern
202
-     *                                      'value' will return the value for the first request parameter
203
-     *                                      whose key matches the supplied pattern
204
-     *                                      Default is 'value'
205
-     * @return boolean|string
206
-     */
207
-    private function match($pattern, array $request_params, $default = null, $return = 'value')
208
-    {
209
-        $return = in_array($return, ['bool', 'key', 'value'], true)
210
-            ? $return
211
-            : 'is_set';
212
-        // replace wildcard chars with regex chars
213
-        $pattern = str_replace(
214
-            ['\*', '\?'],
215
-            ['.*', '.'],
216
-            preg_quote($pattern, '/')
217
-        );
218
-        foreach ($request_params as $key => $request_param) {
219
-            if (preg_match('/^' . $pattern . '$/is', $key)) {
220
-                // return value for request param
221
-                if ($return === 'value') {
222
-                    return $request_param;
223
-                }
224
-                // or actual key or true just to indicate it was found
225
-                return $return === 'key' ? $key : true;
226
-            }
227
-        }
228
-        // match not found so return default value or false
229
-        return $return === 'value' ? $default : false;
230
-    }
231
-
232
-
233
-    /**
234
-     * the supplied key can be a simple string to represent a "top-level" request parameter
235
-     * or represent a key for a request parameter that is nested deeper within the request parameter array,
236
-     * by using square brackets to surround keys for deeper array elements.
237
-     * For example :
238
-     * if the supplied $key was: "first[second][third]"
239
-     * then this will attempt to drill down into the request parameter array to find a value.
240
-     * Given the following request parameters:
241
-     *  array(
242
-     *      'first' => array(
243
-     *          'second' => array(
244
-     *              'third' => 'has a value'
245
-     *          )
246
-     *      )
247
-     *  )
248
-     * would return true if default parameters were set
249
-     *
250
-     * @param string $callback
251
-     * @param        $key
252
-     * @param null   $default
253
-     * @param string $return
254
-     * @param mixed  $request_params
255
-     * @return bool|mixed|null
256
-     */
257
-    private function parameterDrillDown(
258
-        $key,
259
-        $default = null,
260
-        $callback = 'is_set',
261
-        $return = 'value',
262
-        $request_params = []
263
-    ) {
264
-        $callback       = in_array($callback, ['is_set', 'get', 'match'], true)
265
-            ? $callback
266
-            : 'is_set';
267
-        $request_params = ! empty($request_params)
268
-            ? $request_params
269
-            : $this->request;
270
-        // does incoming key represent an array like 'first[second][third]'  ?
271
-        if (strpos($key, '[') !== false) {
272
-            // turn it into an actual array
273
-            $key  = str_replace(']', '', $key);
274
-            $keys = explode('[', $key);
275
-            $key  = array_shift($keys);
276
-            if ($callback === 'match') {
277
-                $real_key = $this->match($key, $request_params, $default, 'key');
278
-                $key      = $real_key ?: $key;
279
-            }
280
-            // check if top level key exists
281
-            if (isset($request_params[ $key ])) {
282
-                // build a new key to pass along like: 'second[third]'
283
-                // or just 'second' depending on depth of keys
284
-                $key_string = array_shift($keys);
285
-                if (! empty($keys)) {
286
-                    $key_string .= '[' . implode('][', $keys) . ']';
287
-                }
288
-                return $this->parameterDrillDown(
289
-                    $key_string,
290
-                    $default,
291
-                    $callback,
292
-                    $return,
293
-                    $request_params[ $key ]
294
-                );
295
-            }
296
-        }
297
-        if ($callback === 'is_set') {
298
-            return isset($request_params[ $key ]);
299
-        }
300
-        if ($callback === 'match') {
301
-            return $this->match($key, $request_params, $default, $return);
302
-        }
303
-        return isset($request_params[ $key ])
304
-            ? $request_params[ $key ]
305
-            : $default;
306
-    }
307
-
308
-
309
-    /**
310
-     * remove param
311
-     *
312
-     * @param      $key
313
-     * @param bool $unset_from_global_too
314
-     */
315
-    public function unSetRequestParam($key, $unset_from_global_too = false)
316
-    {
317
-        // because unset may not actually remove var
318
-        $this->get[ $key ]     = null;
319
-        $this->post[ $key ]    = null;
320
-        $this->request[ $key ] = null;
321
-        unset($this->get[ $key ], $this->post[ $key ], $this->request[ $key ]);
322
-        if ($unset_from_global_too) {
323
-            unset($_GET[ $key ], $_POST[ $key ], $_REQUEST[ $key ]);
324
-        }
325
-    }
326
-
327
-
328
-    /**
329
-     * remove params
330
-     *
331
-     * @param array $keys
332
-     * @param bool  $unset_from_global_too
333
-     */
334
-    public function unSetRequestParams(array $keys, $unset_from_global_too = false)
335
-    {
336
-        foreach ($keys as $key) {
337
-            $this->unSetRequestParam($key, $unset_from_global_too);
338
-        }
339
-    }
17
+	/**
18
+	 * $_GET parameters
19
+	 *
20
+	 * @var array
21
+	 */
22
+	protected $get;
23
+
24
+	/**
25
+	 * $_POST parameters
26
+	 *
27
+	 * @var array
28
+	 */
29
+	protected $post;
30
+
31
+	/**
32
+	 * $_REQUEST parameters
33
+	 *
34
+	 * @var array
35
+	 */
36
+	protected $request;
37
+
38
+	/**
39
+	 * @var RequestSanitizer
40
+	 */
41
+	protected $sanitizer;
42
+
43
+
44
+	/**
45
+	 * RequestParams constructor.
46
+	 *
47
+	 * @param RequestSanitizer $sanitizer
48
+	 * @param array            $get
49
+	 * @param array            $post
50
+	 */
51
+	public function __construct(RequestSanitizer $sanitizer, array $get = [], array $post = [])
52
+	{
53
+		$this->sanitizer = $sanitizer;
54
+		$this->get       = ! empty($get) ? $get : $_GET;
55
+		$this->post      = ! empty($post) ? $post : $_POST;
56
+		$this->request   = array_merge($this->get, $this->post);
57
+	}
58
+
59
+
60
+	/**
61
+	 * @return array
62
+	 */
63
+	public function getParams()
64
+	{
65
+		return $this->get;
66
+	}
67
+
68
+
69
+	/**
70
+	 * @return array
71
+	 */
72
+	public function postParams()
73
+	{
74
+		return $this->post;
75
+	}
76
+
77
+
78
+	/**
79
+	 * returns contents of $_REQUEST
80
+	 *
81
+	 * @return array
82
+	 */
83
+	public function requestParams()
84
+	{
85
+		return $this->request;
86
+	}
87
+
88
+
89
+	/**
90
+	 * @param string     $key
91
+	 * @param mixed|null $value
92
+	 * @param bool       $override_ee
93
+	 * @return    void
94
+	 */
95
+	public function setRequestParam($key, $value, $override_ee = false)
96
+	{
97
+		// don't allow "ee" to be overwritten unless explicitly instructed to do so
98
+		if ($override_ee || $key !== 'ee' || empty($this->request['ee'])) {
99
+			$this->request[ $key ] = $value;
100
+		}
101
+	}
102
+
103
+
104
+	/**
105
+	 * merges the incoming array of parameters into the existing request parameters
106
+	 *
107
+	 * @param array $request_params
108
+	 * @return void
109
+	 * @since   4.10.24.p
110
+	 */
111
+	public function mergeRequestParams(array $request_params)
112
+	{
113
+		$this->request = array_merge($this->request, $request_params);
114
+	}
115
+
116
+
117
+	/**
118
+	 * returns   the value for a request param if the given key exists
119
+	 *
120
+	 * @param string     $key
121
+	 * @param mixed|null $default
122
+	 * @param string     $type      the expected data type for the parameter's value, ie: string, int, bool, etc
123
+	 * @param bool       $is_array  if true, then parameter value will be treated as an array of $type
124
+	 * @param string     $delimiter for CSV type strings that should be returned as an array
125
+	 * @return array|bool|float|int|string
126
+	 */
127
+	public function getRequestParam($key, $default = null, $type = 'string', $is_array = false, $delimiter = '')
128
+	{
129
+		return $this->sanitizer->clean(
130
+			$this->parameterDrillDown($key, $default, 'get'),
131
+			$type,
132
+			$is_array,
133
+			$delimiter
134
+		);
135
+	}
136
+
137
+
138
+	/**
139
+	 * check if param exists
140
+	 *
141
+	 * @param string $key
142
+	 * @return bool
143
+	 */
144
+	public function requestParamIsSet($key)
145
+	{
146
+		return (bool) $this->parameterDrillDown($key);
147
+	}
148
+
149
+
150
+	/**
151
+	 * check if a request parameter exists whose key that matches the supplied wildcard pattern
152
+	 * and return the value for the first match found
153
+	 * wildcards can be either of the following:
154
+	 *      ? to represent a single character of any type
155
+	 *      * to represent one or more characters of any type
156
+	 *
157
+	 * @param string     $pattern
158
+	 * @param mixed|null $default
159
+	 * @param string     $type      the expected data type for the parameter's value, ie: string, int, bool, etc
160
+	 * @param bool       $is_array  if true, then parameter value will be treated as an array of $type
161
+	 * @param string     $delimiter for CSV type strings that should be returned as an array
162
+	 * @return array|bool|float|int|string
163
+	 */
164
+	public function getMatch($pattern, $default = null, $type = 'string', $is_array = false, $delimiter = '')
165
+	{
166
+		return $this->sanitizer->clean(
167
+			$this->parameterDrillDown($pattern, $default, 'match'),
168
+			$type,
169
+			$is_array,
170
+			$delimiter
171
+		);
172
+	}
173
+
174
+
175
+	/**
176
+	 * check if a request parameter exists whose key matches the supplied wildcard pattern
177
+	 * wildcards can be either of the following:
178
+	 *      ? to represent a single character of any type
179
+	 *      * to represent one or more characters of any type
180
+	 * returns true if a match is found or false if not
181
+	 *
182
+	 * @param string $pattern
183
+	 * @return bool
184
+	 */
185
+	public function matches($pattern)
186
+	{
187
+		return (bool) $this->parameterDrillDown($pattern, false, 'match', 'bool');
188
+	}
189
+
190
+
191
+	/**
192
+	 * @see https://stackoverflow.com/questions/6163055/php-string-matching-with-wildcard
193
+	 * @param string $pattern               A string including wildcards to be converted to a regex pattern
194
+	 *                                      and used to search through the current request's parameter keys
195
+	 * @param array  $request_params        The array of request parameters to search through
196
+	 * @param mixed  $default               [optional] The value to be returned if no match is found.
197
+	 *                                      Default is null
198
+	 * @param string $return                [optional] Controls what kind of value is returned.
199
+	 *                                      Options are:
200
+	 *                                      'bool' will return true or false if match is found or not
201
+	 *                                      'key' will return the first key found that matches the supplied pattern
202
+	 *                                      'value' will return the value for the first request parameter
203
+	 *                                      whose key matches the supplied pattern
204
+	 *                                      Default is 'value'
205
+	 * @return boolean|string
206
+	 */
207
+	private function match($pattern, array $request_params, $default = null, $return = 'value')
208
+	{
209
+		$return = in_array($return, ['bool', 'key', 'value'], true)
210
+			? $return
211
+			: 'is_set';
212
+		// replace wildcard chars with regex chars
213
+		$pattern = str_replace(
214
+			['\*', '\?'],
215
+			['.*', '.'],
216
+			preg_quote($pattern, '/')
217
+		);
218
+		foreach ($request_params as $key => $request_param) {
219
+			if (preg_match('/^' . $pattern . '$/is', $key)) {
220
+				// return value for request param
221
+				if ($return === 'value') {
222
+					return $request_param;
223
+				}
224
+				// or actual key or true just to indicate it was found
225
+				return $return === 'key' ? $key : true;
226
+			}
227
+		}
228
+		// match not found so return default value or false
229
+		return $return === 'value' ? $default : false;
230
+	}
231
+
232
+
233
+	/**
234
+	 * the supplied key can be a simple string to represent a "top-level" request parameter
235
+	 * or represent a key for a request parameter that is nested deeper within the request parameter array,
236
+	 * by using square brackets to surround keys for deeper array elements.
237
+	 * For example :
238
+	 * if the supplied $key was: "first[second][third]"
239
+	 * then this will attempt to drill down into the request parameter array to find a value.
240
+	 * Given the following request parameters:
241
+	 *  array(
242
+	 *      'first' => array(
243
+	 *          'second' => array(
244
+	 *              'third' => 'has a value'
245
+	 *          )
246
+	 *      )
247
+	 *  )
248
+	 * would return true if default parameters were set
249
+	 *
250
+	 * @param string $callback
251
+	 * @param        $key
252
+	 * @param null   $default
253
+	 * @param string $return
254
+	 * @param mixed  $request_params
255
+	 * @return bool|mixed|null
256
+	 */
257
+	private function parameterDrillDown(
258
+		$key,
259
+		$default = null,
260
+		$callback = 'is_set',
261
+		$return = 'value',
262
+		$request_params = []
263
+	) {
264
+		$callback       = in_array($callback, ['is_set', 'get', 'match'], true)
265
+			? $callback
266
+			: 'is_set';
267
+		$request_params = ! empty($request_params)
268
+			? $request_params
269
+			: $this->request;
270
+		// does incoming key represent an array like 'first[second][third]'  ?
271
+		if (strpos($key, '[') !== false) {
272
+			// turn it into an actual array
273
+			$key  = str_replace(']', '', $key);
274
+			$keys = explode('[', $key);
275
+			$key  = array_shift($keys);
276
+			if ($callback === 'match') {
277
+				$real_key = $this->match($key, $request_params, $default, 'key');
278
+				$key      = $real_key ?: $key;
279
+			}
280
+			// check if top level key exists
281
+			if (isset($request_params[ $key ])) {
282
+				// build a new key to pass along like: 'second[third]'
283
+				// or just 'second' depending on depth of keys
284
+				$key_string = array_shift($keys);
285
+				if (! empty($keys)) {
286
+					$key_string .= '[' . implode('][', $keys) . ']';
287
+				}
288
+				return $this->parameterDrillDown(
289
+					$key_string,
290
+					$default,
291
+					$callback,
292
+					$return,
293
+					$request_params[ $key ]
294
+				);
295
+			}
296
+		}
297
+		if ($callback === 'is_set') {
298
+			return isset($request_params[ $key ]);
299
+		}
300
+		if ($callback === 'match') {
301
+			return $this->match($key, $request_params, $default, $return);
302
+		}
303
+		return isset($request_params[ $key ])
304
+			? $request_params[ $key ]
305
+			: $default;
306
+	}
307
+
308
+
309
+	/**
310
+	 * remove param
311
+	 *
312
+	 * @param      $key
313
+	 * @param bool $unset_from_global_too
314
+	 */
315
+	public function unSetRequestParam($key, $unset_from_global_too = false)
316
+	{
317
+		// because unset may not actually remove var
318
+		$this->get[ $key ]     = null;
319
+		$this->post[ $key ]    = null;
320
+		$this->request[ $key ] = null;
321
+		unset($this->get[ $key ], $this->post[ $key ], $this->request[ $key ]);
322
+		if ($unset_from_global_too) {
323
+			unset($_GET[ $key ], $_POST[ $key ], $_REQUEST[ $key ]);
324
+		}
325
+	}
326
+
327
+
328
+	/**
329
+	 * remove params
330
+	 *
331
+	 * @param array $keys
332
+	 * @param bool  $unset_from_global_too
333
+	 */
334
+	public function unSetRequestParams(array $keys, $unset_from_global_too = false)
335
+	{
336
+		foreach ($keys as $key) {
337
+			$this->unSetRequestParam($key, $unset_from_global_too);
338
+		}
339
+	}
340 340
 }
Please login to merge, or discard this patch.
core/business/EE_Registration_Processor.class.php 2 patches
Indentation   +773 added lines, -773 removed lines patch added patch discarded remove patch
@@ -26,778 +26,778 @@
 block discarded – undo
26 26
 class EE_Registration_Processor extends EE_Processor_Base
27 27
 {
28 28
 
29
-    /**
30
-     * @var EE_Registration_Processor $_instance
31
-     * @access    private
32
-     */
33
-    private static $_instance;
34
-
35
-    /**
36
-     * initial reg status at the beginning of this request.
37
-     * indexed by registration ID
38
-     *
39
-     * @var array
40
-     */
41
-    protected $_old_reg_status = [];
42
-
43
-    /**
44
-     * reg status at the end of the request after all processing.
45
-     * indexed by registration ID
46
-     *
47
-     * @var array
48
-     */
49
-    protected $_new_reg_status = [];
50
-
51
-    /**
52
-     * amounts paid at the end of the request after all processing.
53
-     * indexed by registration ID
54
-     *
55
-     * @var array
56
-     */
57
-    protected static $_amount_paid = [];
58
-
59
-    /**
60
-     * Cache of the reg final price for registrations corresponding to a ticket line item
61
-     *
62
-     * @deprecated
63
-     * @var array @see EEH_Line_Item::calculate_reg_final_prices_per_line_item()'s return value
64
-     */
65
-    protected $_reg_final_price_per_tkt_line_item;
66
-
67
-    /**
68
-     * @var RequestInterface $request
69
-     */
70
-    protected $request;
71
-
72
-
73
-    /**
74
-     * @singleton method used to instantiate class object
75
-     * @param RequestInterface|null $request
76
-     * @return EE_Registration_Processor instance
77
-     * @throws InvalidArgumentException
78
-     * @throws InvalidInterfaceException
79
-     * @throws InvalidDataTypeException
80
-     */
81
-    public static function instance(RequestInterface $request = null)
82
-    {
83
-        // check if class object is instantiated
84
-        if (! self::$_instance instanceof EE_Registration_Processor) {
85
-            if (! $request instanceof RequestInterface) {
86
-                $request = LoaderFactory::getLoader()->getShared('EventEspresso\core\services\request\Request');
87
-            }
88
-            self::$_instance = new self($request);
89
-        }
90
-        return self::$_instance;
91
-    }
92
-
93
-
94
-    /**
95
-     * EE_Registration_Processor constructor.
96
-     *
97
-     * @param RequestInterface $request
98
-     */
99
-    public function __construct(RequestInterface $request)
100
-    {
101
-        $this->request = $request;
102
-    }
103
-
104
-
105
-    /**
106
-     * @param int $REG_ID
107
-     * @return string
108
-     */
109
-    public function old_reg_status($REG_ID)
110
-    {
111
-        return isset($this->_old_reg_status[ $REG_ID ]) ? $this->_old_reg_status[ $REG_ID ] : null;
112
-    }
113
-
114
-
115
-    /**
116
-     * @param int    $REG_ID
117
-     * @param string $old_reg_status
118
-     */
119
-    public function set_old_reg_status($REG_ID, $old_reg_status)
120
-    {
121
-        // only set the first time
122
-        if (! isset($this->_old_reg_status[ $REG_ID ])) {
123
-            $this->_old_reg_status[ $REG_ID ] = $old_reg_status;
124
-        }
125
-    }
126
-
127
-
128
-    /**
129
-     * @param int $REG_ID
130
-     * @return string
131
-     */
132
-    public function new_reg_status($REG_ID)
133
-    {
134
-        return isset($this->_new_reg_status[ $REG_ID ]) ? $this->_new_reg_status[ $REG_ID ] : null;
135
-    }
136
-
137
-
138
-    /**
139
-     * @param int    $REG_ID
140
-     * @param string $new_reg_status
141
-     */
142
-    public function set_new_reg_status($REG_ID, $new_reg_status)
143
-    {
144
-        $this->_new_reg_status[ $REG_ID ] = $new_reg_status;
145
-    }
146
-
147
-
148
-    /**
149
-     * reg_status_updated
150
-     *
151
-     * @param int $REG_ID
152
-     * @return bool
153
-     */
154
-    public function reg_status_updated($REG_ID)
155
-    {
156
-        return $this->new_reg_status($REG_ID) !== $this->old_reg_status($REG_ID);
157
-    }
158
-
159
-
160
-    /**
161
-     * @param EE_Registration $registration
162
-     * @throws EE_Error
163
-     * @throws EntityNotFoundException
164
-     * @throws InvalidArgumentException
165
-     * @throws InvalidDataTypeException
166
-     * @throws InvalidInterfaceException
167
-     * @throws ReflectionException
168
-     * @throws RuntimeException
169
-     */
170
-    public function update_registration_status_and_trigger_notifications(EE_Registration $registration)
171
-    {
172
-        $this->toggle_incomplete_registration_status_to_default($registration, false);
173
-        $this->toggle_registration_status_for_default_approved_events($registration, false);
174
-        $this->toggle_registration_status_if_no_monies_owing($registration, false);
175
-        $registration->save();
176
-        // trigger notifications
177
-        $this->trigger_registration_update_notifications($registration);
178
-    }
179
-
180
-
181
-    /**
182
-     *    manually_update_registration_status
183
-     *
184
-     * @access public
185
-     * @param EE_Registration $registration
186
-     * @param string          $new_reg_status
187
-     * @param bool            $save TRUE will save the registration if the status is updated, FALSE will leave that up
188
-     *                              to client code
189
-     * @return bool
190
-     * @throws EE_Error
191
-     * @throws EntityNotFoundException
192
-     * @throws InvalidArgumentException
193
-     * @throws InvalidDataTypeException
194
-     * @throws InvalidInterfaceException
195
-     * @throws ReflectionException
196
-     * @throws RuntimeException
197
-     */
198
-    public function manually_update_registration_status(
199
-        EE_Registration $registration,
200
-        $new_reg_status = '',
201
-        $save = true
202
-    ) {
203
-        // set initial REG_Status
204
-        $this->set_old_reg_status($registration->ID(), $registration->status_ID());
205
-        // set incoming REG_Status
206
-        $this->set_new_reg_status($registration->ID(), $new_reg_status);
207
-        // toggle reg status but only if it has changed and the user can do so
208
-        if (
209
-            $this->reg_status_updated($registration->ID())
210
-            && (
211
-                (! $this->request->isAdmin() || $this->request->isFrontAjax())
212
-                || EE_Registry::instance()->CAP->current_user_can(
213
-                    'ee_edit_registration',
214
-                    'toggle_registration_status',
215
-                    $registration->ID()
216
-                )
217
-            )
218
-        ) {
219
-            // change status to new value
220
-            $updated = $registration->set_status($this->new_reg_status($registration->ID()));
221
-            if ($updated && $save) {
222
-                $registration->save();
223
-            }
224
-            return true;
225
-        }
226
-        return false;
227
-    }
228
-
229
-
230
-    /**
231
-     *    toggle_incomplete_registration_status_to_default
232
-     *        changes any incomplete registrations to either the event or global default registration status
233
-     *
234
-     * @access public
235
-     * @param EE_Registration       $registration
236
-     * @param bool                  $save TRUE will save the registration if the status is updated, FALSE will leave
237
-     *                                    that up to client code
238
-     * @param ContextInterface|null $context
239
-     * @return void
240
-     * @throws EE_Error
241
-     * @throws InvalidArgumentException
242
-     * @throws ReflectionException
243
-     * @throws RuntimeException
244
-     * @throws EntityNotFoundException
245
-     * @throws InvalidDataTypeException
246
-     * @throws InvalidInterfaceException
247
-     */
248
-    public function toggle_incomplete_registration_status_to_default(
249
-        EE_Registration $registration,
250
-        $save = true,
251
-        ContextInterface $context = null
252
-    ) {
253
-        $existing_reg_status = $registration->status_ID();
254
-        // set initial REG_Status
255
-        $this->set_old_reg_status($registration->ID(), $existing_reg_status);
256
-        // is the registration currently incomplete ?
257
-        if ($registration->status_ID() === EEM_Registration::status_id_incomplete) {
258
-            // grab default reg status for the event, if set
259
-            $event_default_registration_status = $registration->event()->default_registration_status();
260
-            // if no default reg status is set for the event, then use the global value
261
-            $STS_ID = ! empty($event_default_registration_status)
262
-                ? $event_default_registration_status
263
-                : EE_Registry::instance()->CFG->registration->default_STS_ID;
264
-            // if the event default reg status is approved, then downgrade temporarily to payment pending to ensure that payments are triggered
265
-            $STS_ID = $STS_ID === EEM_Registration::status_id_approved ? EEM_Registration::status_id_pending_payment
266
-                : $STS_ID;
267
-            // set incoming REG_Status
268
-            $this->set_new_reg_status($registration->ID(), $STS_ID);
269
-            $registration->set_status($STS_ID, false, $context);
270
-            if ($save) {
271
-                $registration->save();
272
-            }
273
-            // don't trigger notifications during IPNs because they will get triggered by EE_Payment_Processor
274
-            if (! EE_Processor_Base::$IPN) {
275
-                // otherwise, send out notifications
276
-                add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true', 10);
277
-            }
278
-            // DEBUG LOG
279
-            // $this->log(
280
-            //     __CLASS__,
281
-            //     __FUNCTION__,
282
-            //     __LINE__,
283
-            //     $registration->transaction(),
284
-            //     array(
285
-            //         'IPN' => EE_Processor_Base::$IPN,
286
-            //         'deliver_notifications' => has_filter(
287
-            //             'FHEE__EED_Messages___maybe_registration__deliver_notifications'
288
-            //         ),
289
-            //     )
290
-            // );
291
-        }
292
-    }
293
-
294
-
295
-    /**
296
-     *    toggle_registration_status_for_default_approved_events
297
-     *
298
-     * @access public
299
-     * @param EE_Registration $registration
300
-     * @param bool            $save TRUE will save the registration if the status is updated, FALSE will leave that up
301
-     *                              to client code
302
-     * @return bool
303
-     * @throws EE_Error
304
-     * @throws EntityNotFoundException
305
-     * @throws InvalidArgumentException
306
-     * @throws InvalidDataTypeException
307
-     * @throws InvalidInterfaceException
308
-     * @throws ReflectionException
309
-     * @throws RuntimeException
310
-     */
311
-    public function toggle_registration_status_for_default_approved_events(EE_Registration $registration, $save = true)
312
-    {
313
-        $reg_status = $registration->status_ID();
314
-        // set initial REG_Status
315
-        $this->set_old_reg_status($registration->ID(), $reg_status);
316
-        // if not already, toggle reg status to approved IF the event default reg status is approved
317
-        // ( as long as the registration wasn't cancelled or declined at some point )
318
-        if (
319
-            $reg_status !== EEM_Registration::status_id_cancelled
320
-            && $reg_status
321
-               !== EEM_Registration::status_id_declined
322
-            && $reg_status !== EEM_Registration::status_id_approved
323
-            && $registration->event()->default_registration_status() === EEM_Registration::status_id_approved
324
-        ) {
325
-            // set incoming REG_Status
326
-            $this->set_new_reg_status($registration->ID(), EEM_Registration::status_id_approved);
327
-            // toggle status to approved
328
-            $registration->set_status(EEM_Registration::status_id_approved);
329
-            if ($save) {
330
-                $registration->save();
331
-            }
332
-            // don't trigger notifications during IPNs because they will get triggered by EE_Payment_Processor
333
-            if (! EE_Processor_Base::$IPN) {
334
-                // otherwise, send out notifications
335
-                add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true', 10);
336
-            }
337
-            // DEBUG LOG
338
-            // $this->log(
339
-            //     __CLASS__,
340
-            //     __FUNCTION__,
341
-            //     __LINE__,
342
-            //     $registration->transaction(),
343
-            //     array(
344
-            //         'IPN' => EE_Processor_Base::$IPN,
345
-            //         'deliver_notifications' => has_filter(
346
-            //             'FHEE__EED_Messages___maybe_registration__deliver_notifications'
347
-            //         ),
348
-            //     )
349
-            // );
350
-            return true;
351
-        }
352
-        return false;
353
-    }
354
-
355
-
356
-    /**
357
-     *    toggle_registration_statuses_if_no_monies_owing
358
-     *
359
-     * @access public
360
-     * @param EE_Registration $registration
361
-     * @param bool            $save TRUE will save the registration if the status is updated, FALSE will leave that up
362
-     *                              to client code
363
-     * @param array           $additional_details
364
-     * @return bool
365
-     * @throws EE_Error
366
-     * @throws EntityNotFoundException
367
-     * @throws InvalidArgumentException
368
-     * @throws InvalidDataTypeException
369
-     * @throws InvalidInterfaceException
370
-     * @throws ReflectionException
371
-     * @throws RuntimeException
372
-     */
373
-    public function toggle_registration_status_if_no_monies_owing(
374
-        EE_Registration $registration,
375
-        $save = true,
376
-        array $additional_details = []
377
-    ) {
378
-        // set initial REG_Status
379
-        $this->set_old_reg_status($registration->ID(), $registration->status_ID());
380
-        // was a payment just made ?
381
-        $payment    = isset($additional_details['payment_updates'], $additional_details['last_payment'])
382
-                      && $additional_details['payment_updates']
383
-                      && $additional_details['last_payment'] instanceof EE_Payment
384
-            ? $additional_details['last_payment']
385
-            : null;
386
-        $total_paid = array_sum(self::$_amount_paid);
387
-        // toggle reg status to approved IF
388
-        if (
29
+	/**
30
+	 * @var EE_Registration_Processor $_instance
31
+	 * @access    private
32
+	 */
33
+	private static $_instance;
34
+
35
+	/**
36
+	 * initial reg status at the beginning of this request.
37
+	 * indexed by registration ID
38
+	 *
39
+	 * @var array
40
+	 */
41
+	protected $_old_reg_status = [];
42
+
43
+	/**
44
+	 * reg status at the end of the request after all processing.
45
+	 * indexed by registration ID
46
+	 *
47
+	 * @var array
48
+	 */
49
+	protected $_new_reg_status = [];
50
+
51
+	/**
52
+	 * amounts paid at the end of the request after all processing.
53
+	 * indexed by registration ID
54
+	 *
55
+	 * @var array
56
+	 */
57
+	protected static $_amount_paid = [];
58
+
59
+	/**
60
+	 * Cache of the reg final price for registrations corresponding to a ticket line item
61
+	 *
62
+	 * @deprecated
63
+	 * @var array @see EEH_Line_Item::calculate_reg_final_prices_per_line_item()'s return value
64
+	 */
65
+	protected $_reg_final_price_per_tkt_line_item;
66
+
67
+	/**
68
+	 * @var RequestInterface $request
69
+	 */
70
+	protected $request;
71
+
72
+
73
+	/**
74
+	 * @singleton method used to instantiate class object
75
+	 * @param RequestInterface|null $request
76
+	 * @return EE_Registration_Processor instance
77
+	 * @throws InvalidArgumentException
78
+	 * @throws InvalidInterfaceException
79
+	 * @throws InvalidDataTypeException
80
+	 */
81
+	public static function instance(RequestInterface $request = null)
82
+	{
83
+		// check if class object is instantiated
84
+		if (! self::$_instance instanceof EE_Registration_Processor) {
85
+			if (! $request instanceof RequestInterface) {
86
+				$request = LoaderFactory::getLoader()->getShared('EventEspresso\core\services\request\Request');
87
+			}
88
+			self::$_instance = new self($request);
89
+		}
90
+		return self::$_instance;
91
+	}
92
+
93
+
94
+	/**
95
+	 * EE_Registration_Processor constructor.
96
+	 *
97
+	 * @param RequestInterface $request
98
+	 */
99
+	public function __construct(RequestInterface $request)
100
+	{
101
+		$this->request = $request;
102
+	}
103
+
104
+
105
+	/**
106
+	 * @param int $REG_ID
107
+	 * @return string
108
+	 */
109
+	public function old_reg_status($REG_ID)
110
+	{
111
+		return isset($this->_old_reg_status[ $REG_ID ]) ? $this->_old_reg_status[ $REG_ID ] : null;
112
+	}
113
+
114
+
115
+	/**
116
+	 * @param int    $REG_ID
117
+	 * @param string $old_reg_status
118
+	 */
119
+	public function set_old_reg_status($REG_ID, $old_reg_status)
120
+	{
121
+		// only set the first time
122
+		if (! isset($this->_old_reg_status[ $REG_ID ])) {
123
+			$this->_old_reg_status[ $REG_ID ] = $old_reg_status;
124
+		}
125
+	}
126
+
127
+
128
+	/**
129
+	 * @param int $REG_ID
130
+	 * @return string
131
+	 */
132
+	public function new_reg_status($REG_ID)
133
+	{
134
+		return isset($this->_new_reg_status[ $REG_ID ]) ? $this->_new_reg_status[ $REG_ID ] : null;
135
+	}
136
+
137
+
138
+	/**
139
+	 * @param int    $REG_ID
140
+	 * @param string $new_reg_status
141
+	 */
142
+	public function set_new_reg_status($REG_ID, $new_reg_status)
143
+	{
144
+		$this->_new_reg_status[ $REG_ID ] = $new_reg_status;
145
+	}
146
+
147
+
148
+	/**
149
+	 * reg_status_updated
150
+	 *
151
+	 * @param int $REG_ID
152
+	 * @return bool
153
+	 */
154
+	public function reg_status_updated($REG_ID)
155
+	{
156
+		return $this->new_reg_status($REG_ID) !== $this->old_reg_status($REG_ID);
157
+	}
158
+
159
+
160
+	/**
161
+	 * @param EE_Registration $registration
162
+	 * @throws EE_Error
163
+	 * @throws EntityNotFoundException
164
+	 * @throws InvalidArgumentException
165
+	 * @throws InvalidDataTypeException
166
+	 * @throws InvalidInterfaceException
167
+	 * @throws ReflectionException
168
+	 * @throws RuntimeException
169
+	 */
170
+	public function update_registration_status_and_trigger_notifications(EE_Registration $registration)
171
+	{
172
+		$this->toggle_incomplete_registration_status_to_default($registration, false);
173
+		$this->toggle_registration_status_for_default_approved_events($registration, false);
174
+		$this->toggle_registration_status_if_no_monies_owing($registration, false);
175
+		$registration->save();
176
+		// trigger notifications
177
+		$this->trigger_registration_update_notifications($registration);
178
+	}
179
+
180
+
181
+	/**
182
+	 *    manually_update_registration_status
183
+	 *
184
+	 * @access public
185
+	 * @param EE_Registration $registration
186
+	 * @param string          $new_reg_status
187
+	 * @param bool            $save TRUE will save the registration if the status is updated, FALSE will leave that up
188
+	 *                              to client code
189
+	 * @return bool
190
+	 * @throws EE_Error
191
+	 * @throws EntityNotFoundException
192
+	 * @throws InvalidArgumentException
193
+	 * @throws InvalidDataTypeException
194
+	 * @throws InvalidInterfaceException
195
+	 * @throws ReflectionException
196
+	 * @throws RuntimeException
197
+	 */
198
+	public function manually_update_registration_status(
199
+		EE_Registration $registration,
200
+		$new_reg_status = '',
201
+		$save = true
202
+	) {
203
+		// set initial REG_Status
204
+		$this->set_old_reg_status($registration->ID(), $registration->status_ID());
205
+		// set incoming REG_Status
206
+		$this->set_new_reg_status($registration->ID(), $new_reg_status);
207
+		// toggle reg status but only if it has changed and the user can do so
208
+		if (
209
+			$this->reg_status_updated($registration->ID())
210
+			&& (
211
+				(! $this->request->isAdmin() || $this->request->isFrontAjax())
212
+				|| EE_Registry::instance()->CAP->current_user_can(
213
+					'ee_edit_registration',
214
+					'toggle_registration_status',
215
+					$registration->ID()
216
+				)
217
+			)
218
+		) {
219
+			// change status to new value
220
+			$updated = $registration->set_status($this->new_reg_status($registration->ID()));
221
+			if ($updated && $save) {
222
+				$registration->save();
223
+			}
224
+			return true;
225
+		}
226
+		return false;
227
+	}
228
+
229
+
230
+	/**
231
+	 *    toggle_incomplete_registration_status_to_default
232
+	 *        changes any incomplete registrations to either the event or global default registration status
233
+	 *
234
+	 * @access public
235
+	 * @param EE_Registration       $registration
236
+	 * @param bool                  $save TRUE will save the registration if the status is updated, FALSE will leave
237
+	 *                                    that up to client code
238
+	 * @param ContextInterface|null $context
239
+	 * @return void
240
+	 * @throws EE_Error
241
+	 * @throws InvalidArgumentException
242
+	 * @throws ReflectionException
243
+	 * @throws RuntimeException
244
+	 * @throws EntityNotFoundException
245
+	 * @throws InvalidDataTypeException
246
+	 * @throws InvalidInterfaceException
247
+	 */
248
+	public function toggle_incomplete_registration_status_to_default(
249
+		EE_Registration $registration,
250
+		$save = true,
251
+		ContextInterface $context = null
252
+	) {
253
+		$existing_reg_status = $registration->status_ID();
254
+		// set initial REG_Status
255
+		$this->set_old_reg_status($registration->ID(), $existing_reg_status);
256
+		// is the registration currently incomplete ?
257
+		if ($registration->status_ID() === EEM_Registration::status_id_incomplete) {
258
+			// grab default reg status for the event, if set
259
+			$event_default_registration_status = $registration->event()->default_registration_status();
260
+			// if no default reg status is set for the event, then use the global value
261
+			$STS_ID = ! empty($event_default_registration_status)
262
+				? $event_default_registration_status
263
+				: EE_Registry::instance()->CFG->registration->default_STS_ID;
264
+			// if the event default reg status is approved, then downgrade temporarily to payment pending to ensure that payments are triggered
265
+			$STS_ID = $STS_ID === EEM_Registration::status_id_approved ? EEM_Registration::status_id_pending_payment
266
+				: $STS_ID;
267
+			// set incoming REG_Status
268
+			$this->set_new_reg_status($registration->ID(), $STS_ID);
269
+			$registration->set_status($STS_ID, false, $context);
270
+			if ($save) {
271
+				$registration->save();
272
+			}
273
+			// don't trigger notifications during IPNs because they will get triggered by EE_Payment_Processor
274
+			if (! EE_Processor_Base::$IPN) {
275
+				// otherwise, send out notifications
276
+				add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true', 10);
277
+			}
278
+			// DEBUG LOG
279
+			// $this->log(
280
+			//     __CLASS__,
281
+			//     __FUNCTION__,
282
+			//     __LINE__,
283
+			//     $registration->transaction(),
284
+			//     array(
285
+			//         'IPN' => EE_Processor_Base::$IPN,
286
+			//         'deliver_notifications' => has_filter(
287
+			//             'FHEE__EED_Messages___maybe_registration__deliver_notifications'
288
+			//         ),
289
+			//     )
290
+			// );
291
+		}
292
+	}
293
+
294
+
295
+	/**
296
+	 *    toggle_registration_status_for_default_approved_events
297
+	 *
298
+	 * @access public
299
+	 * @param EE_Registration $registration
300
+	 * @param bool            $save TRUE will save the registration if the status is updated, FALSE will leave that up
301
+	 *                              to client code
302
+	 * @return bool
303
+	 * @throws EE_Error
304
+	 * @throws EntityNotFoundException
305
+	 * @throws InvalidArgumentException
306
+	 * @throws InvalidDataTypeException
307
+	 * @throws InvalidInterfaceException
308
+	 * @throws ReflectionException
309
+	 * @throws RuntimeException
310
+	 */
311
+	public function toggle_registration_status_for_default_approved_events(EE_Registration $registration, $save = true)
312
+	{
313
+		$reg_status = $registration->status_ID();
314
+		// set initial REG_Status
315
+		$this->set_old_reg_status($registration->ID(), $reg_status);
316
+		// if not already, toggle reg status to approved IF the event default reg status is approved
317
+		// ( as long as the registration wasn't cancelled or declined at some point )
318
+		if (
319
+			$reg_status !== EEM_Registration::status_id_cancelled
320
+			&& $reg_status
321
+			   !== EEM_Registration::status_id_declined
322
+			&& $reg_status !== EEM_Registration::status_id_approved
323
+			&& $registration->event()->default_registration_status() === EEM_Registration::status_id_approved
324
+		) {
325
+			// set incoming REG_Status
326
+			$this->set_new_reg_status($registration->ID(), EEM_Registration::status_id_approved);
327
+			// toggle status to approved
328
+			$registration->set_status(EEM_Registration::status_id_approved);
329
+			if ($save) {
330
+				$registration->save();
331
+			}
332
+			// don't trigger notifications during IPNs because they will get triggered by EE_Payment_Processor
333
+			if (! EE_Processor_Base::$IPN) {
334
+				// otherwise, send out notifications
335
+				add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true', 10);
336
+			}
337
+			// DEBUG LOG
338
+			// $this->log(
339
+			//     __CLASS__,
340
+			//     __FUNCTION__,
341
+			//     __LINE__,
342
+			//     $registration->transaction(),
343
+			//     array(
344
+			//         'IPN' => EE_Processor_Base::$IPN,
345
+			//         'deliver_notifications' => has_filter(
346
+			//             'FHEE__EED_Messages___maybe_registration__deliver_notifications'
347
+			//         ),
348
+			//     )
349
+			// );
350
+			return true;
351
+		}
352
+		return false;
353
+	}
354
+
355
+
356
+	/**
357
+	 *    toggle_registration_statuses_if_no_monies_owing
358
+	 *
359
+	 * @access public
360
+	 * @param EE_Registration $registration
361
+	 * @param bool            $save TRUE will save the registration if the status is updated, FALSE will leave that up
362
+	 *                              to client code
363
+	 * @param array           $additional_details
364
+	 * @return bool
365
+	 * @throws EE_Error
366
+	 * @throws EntityNotFoundException
367
+	 * @throws InvalidArgumentException
368
+	 * @throws InvalidDataTypeException
369
+	 * @throws InvalidInterfaceException
370
+	 * @throws ReflectionException
371
+	 * @throws RuntimeException
372
+	 */
373
+	public function toggle_registration_status_if_no_monies_owing(
374
+		EE_Registration $registration,
375
+		$save = true,
376
+		array $additional_details = []
377
+	) {
378
+		// set initial REG_Status
379
+		$this->set_old_reg_status($registration->ID(), $registration->status_ID());
380
+		// was a payment just made ?
381
+		$payment    = isset($additional_details['payment_updates'], $additional_details['last_payment'])
382
+					  && $additional_details['payment_updates']
383
+					  && $additional_details['last_payment'] instanceof EE_Payment
384
+			? $additional_details['last_payment']
385
+			: null;
386
+		$total_paid = array_sum(self::$_amount_paid);
387
+		// toggle reg status to approved IF
388
+		if (
389 389
 // REG status is pending payment
390
-            $registration->status_ID() === EEM_Registration::status_id_pending_payment
391
-            // AND no monies are owing
392
-            && (
393
-                (
394
-                    $registration->transaction()->is_completed()
395
-                    || $registration->transaction()->is_overpaid()
396
-                    || $registration->transaction()->is_free()
397
-                    || apply_filters(
398
-                        'FHEE__EE_Registration_Processor__toggle_registration_status_if_no_monies_owing',
399
-                        false,
400
-                        $registration
401
-                    )
402
-                )
403
-                || (
404
-                    $payment instanceof EE_Payment && $payment->is_approved()
405
-                    && // this specific registration has not yet been paid for
406
-                    ! isset(self::$_amount_paid[ $registration->ID() ])
407
-                    && // payment amount, less what we have already attributed to other registrations, is greater than this reg's final price
408
-                    $payment->amount() - $total_paid >= $registration->final_price()
409
-                )
410
-            )
411
-        ) {
412
-            // mark as paid
413
-            self::$_amount_paid[ $registration->ID() ] = $registration->final_price();
414
-            // track new REG_Status
415
-            $this->set_new_reg_status($registration->ID(), EEM_Registration::status_id_approved);
416
-            // toggle status to approved
417
-            $registration->set_status(EEM_Registration::status_id_approved);
418
-            if ($save) {
419
-                $registration->save();
420
-            }
421
-            // don't trigger notifications during IPNs because they will get triggered by EE_Payment_Processor
422
-            if (! EE_Processor_Base::$IPN) {
423
-                // otherwise, send out notifications
424
-                add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true', 10);
425
-            }
426
-            // DEBUG LOG
427
-            // $this->log(
428
-            //     __CLASS__,
429
-            //     __FUNCTION__,
430
-            //     __LINE__,
431
-            //     $registration->transaction(),
432
-            //     array(
433
-            //         'IPN' => EE_Processor_Base::$IPN,
434
-            //         'deliver_notifications' => has_filter(
435
-            //             'FHEE__EED_Messages___maybe_registration__deliver_notifications'
436
-            //         ),
437
-            //     )
438
-            // );
439
-            return true;
440
-        }
441
-        return false;
442
-    }
443
-
444
-
445
-    /**
446
-     *    registration_status_changed
447
-     *
448
-     * @access public
449
-     * @param EE_Registration $registration
450
-     * @param array           $additional_details
451
-     * @return void
452
-     */
453
-    public function trigger_registration_update_notifications($registration, array $additional_details = [])
454
-    {
455
-        try {
456
-            if (! $registration instanceof EE_Registration) {
457
-                throw new EE_Error(
458
-                    esc_html__('An invalid registration was received.', 'event_espresso')
459
-                );
460
-            }
461
-            // EE_Registry::instance()->load_helper('Debug_Tools');
462
-            // EEH_Debug_Tools::log(
463
-            //     __CLASS__,
464
-            //     __FUNCTION__,
465
-            //     __LINE__,
466
-            //     array($registration->transaction(), $additional_details),
467
-            //     false,
468
-            //     'EE_Transaction: ' . $registration->transaction()->ID()
469
-            // );
470
-            if (
471
-                ! $this->request->getRequestParam('non_primary_reg_notification', 0, 'int')
472
-                && ! $registration->is_primary_registrant()
473
-            ) {
474
-                return;
475
-            }
476
-            do_action(
477
-                'AHEE__EE_Registration_Processor__trigger_registration_update_notifications',
478
-                $registration,
479
-                $additional_details
480
-            );
481
-        } catch (Exception $e) {
482
-            EE_Error::add_error($e->getMessage(), $e->getFile(), 'unknown_function_from_exception', $e->getLine());
483
-        }
484
-    }
485
-
486
-
487
-    /**
488
-     * sets reg status based either on passed param or on transaction status and event pre-approval setting
489
-     *
490
-     * @param EE_Registration $registration
491
-     * @param array           $additional_details
492
-     * @return bool
493
-     * @throws EE_Error
494
-     * @throws EntityNotFoundException
495
-     * @throws InvalidArgumentException
496
-     * @throws InvalidDataTypeException
497
-     * @throws InvalidInterfaceException
498
-     * @throws ReflectionException
499
-     * @throws RuntimeException
500
-     */
501
-    public function update_registration_after_checkout_or_payment(
502
-        EE_Registration $registration,
503
-        array $additional_details = []
504
-    ) {
505
-        // set initial REG_Status
506
-        $this->set_old_reg_status($registration->ID(), $registration->status_ID());
507
-        // if the registration status gets updated, then save the registration
508
-        if (
509
-            $this->toggle_registration_status_for_default_approved_events($registration, false)
510
-            || $this->toggle_registration_status_if_no_monies_owing(
511
-                $registration,
512
-                false,
513
-                $additional_details
514
-            )
515
-        ) {
516
-            $registration->save();
517
-        }
518
-        // set new  REG_Status
519
-        $this->set_new_reg_status($registration->ID(), $registration->status_ID());
520
-        return $this->reg_status_updated($registration->ID())
521
-               && $this->new_reg_status($registration->ID()) === EEM_Registration::status_id_approved;
522
-    }
523
-
524
-
525
-    /**
526
-     * Updates the registration' final prices based on the current line item tree (taking into account
527
-     * discounts, taxes, and other line items unrelated to tickets.)
528
-     *
529
-     * @param EE_Transaction $transaction
530
-     * @param boolean        $save_regs whether to immediately save registrations in this function or not
531
-     * @return void
532
-     * @throws EE_Error
533
-     * @throws InvalidArgumentException
534
-     * @throws InvalidDataTypeException
535
-     * @throws InvalidInterfaceException
536
-     * @throws RuntimeException
537
-     * @throws ReflectionException
538
-     */
539
-    public function update_registration_final_prices($transaction, $save_regs = true)
540
-    {
541
-        $reg_final_price_per_ticket_line_item = EEH_Line_Item::calculate_reg_final_prices_per_line_item(
542
-            $transaction->total_line_item()
543
-        );
544
-        foreach ($transaction->registrations() as $registration) {
545
-            /** @var EE_Line_Item $line_item */
546
-            $line_item = EEM_Line_Item::instance()->get_line_item_for_registration($registration);
547
-            if (isset($reg_final_price_per_ticket_line_item[ $line_item->ID() ])) {
548
-                $registration->set_final_price($reg_final_price_per_ticket_line_item[ $line_item->ID() ]);
549
-                if ($save_regs) {
550
-                    $registration->save();
551
-                }
552
-            }
553
-        }
554
-        // and make sure there's no rounding problem
555
-        $this->fix_reg_final_price_rounding_issue($transaction);
556
-    }
557
-
558
-
559
-    /**
560
-     * Makes sure there is no rounding errors for the REG_final_prices.
561
-     * Eg, if we have 3 registrations for $1, and there is a $0.01 discount between the three of them,
562
-     * they will each be for $0.99333333, which gets rounded to $1 again.
563
-     * So the transaction total will be $2.99, but each registration will be for $1,
564
-     * so if each registrant paid individually they will have overpaid by $0.01.
565
-     * So in order to overcome this, we check for any difference, and if there is a difference
566
-     * we just grab one registrant at random and make them responsible for it.
567
-     * This should be used after setting REG_final_prices (it's done automatically as part of
568
-     * EE_Registration_Processor::update_registration_final_prices())
569
-     *
570
-     * @param EE_Transaction $transaction
571
-     * @return bool success verifying that there is NO difference after this method is done
572
-     * @throws EE_Error
573
-     * @throws InvalidArgumentException
574
-     * @throws InvalidDataTypeException
575
-     * @throws InvalidInterfaceException
576
-     * @throws ReflectionException
577
-     */
578
-    public function fix_reg_final_price_rounding_issue($transaction)
579
-    {
580
-        $reg_final_price_sum = EEM_Registration::instance()->sum(
581
-            [
582
-                [
583
-                    'TXN_ID' => $transaction->ID(),
584
-                ],
585
-            ],
586
-            'REG_final_price'
587
-        );
588
-        $diff                = $transaction->total() - $reg_final_price_sum;
589
-        // ok then, just grab one of the registrations
590
-        if ($diff !== (float) 0) {
591
-            $a_reg = EEM_Registration::instance()->get_one(
592
-                [
593
-                    [
594
-                        'TXN_ID' => $transaction->ID(),
595
-                    ],
596
-                ]
597
-            );
598
-            return $a_reg instanceof EE_Registration
599
-                   && $a_reg->save(['REG_final_price' => $a_reg->final_price() + $diff]);
600
-        }
601
-        return true;
602
-    }
603
-
604
-
605
-    /**
606
-     * update_registration_after_being_canceled_or_declined
607
-     *
608
-     * @param EE_Registration $registration
609
-     * @param array           $closed_reg_statuses
610
-     * @param bool            $update_reg
611
-     * @return bool
612
-     * @throws EE_Error
613
-     * @throws RuntimeException
614
-     * @throws ReflectionException
615
-     */
616
-    public function update_registration_after_being_canceled_or_declined(
617
-        EE_Registration $registration,
618
-        array $closed_reg_statuses = [],
619
-        $update_reg = true
620
-    ) {
621
-        // these reg statuses should not be considered in any calculations involving monies owing
622
-        $closed_reg_statuses = ! empty($closed_reg_statuses)
623
-            ? $closed_reg_statuses
624
-            : EEM_Registration::closed_reg_statuses();
625
-        if (! in_array($registration->status_ID(), $closed_reg_statuses, true)) {
626
-            return false;
627
-        }
628
-        // release a reserved ticket by decrementing ticket and datetime reserved values
629
-        $registration->release_reserved_ticket(true, 'RegProcessor:' . __LINE__);
630
-        $registration->set_final_price(0);
631
-        if ($update_reg) {
632
-            $registration->save();
633
-        }
634
-        return true;
635
-    }
636
-
637
-
638
-    /**
639
-     * update_canceled_or_declined_registration_after_being_reinstated
640
-     *
641
-     * @param EE_Registration $registration
642
-     * @param array           $closed_reg_statuses
643
-     * @param bool            $update_reg
644
-     * @return bool
645
-     * @throws EE_Error
646
-     * @throws RuntimeException
647
-     * @throws ReflectionException
648
-     */
649
-    public function update_canceled_or_declined_registration_after_being_reinstated(
650
-        EE_Registration $registration,
651
-        array $closed_reg_statuses = [],
652
-        $update_reg = true
653
-    ) {
654
-        // these reg statuses should not be considered in any calculations involving monies owing
655
-        $closed_reg_statuses = ! empty($closed_reg_statuses) ? $closed_reg_statuses
656
-            : EEM_Registration::closed_reg_statuses();
657
-        if (in_array($registration->status_ID(), $closed_reg_statuses, true)) {
658
-            return false;
659
-        }
660
-        $ticket = $registration->ticket();
661
-        if (! $ticket instanceof EE_Ticket) {
662
-            throw new EE_Error(
663
-                sprintf(
664
-                    esc_html__(
665
-                        'The Ticket for Registration %1$d was not found or is invalid.',
666
-                        'event_espresso'
667
-                    ),
668
-                    $registration->ticket_ID()
669
-                )
670
-            );
671
-        }
672
-        $registration->set_final_price($ticket->price());
673
-        if ($update_reg) {
674
-            $registration->save();
675
-        }
676
-        return true;
677
-    }
678
-
679
-
680
-    /**
681
-     * generate_ONE_registration_from_line_item
682
-     * Although a ticket line item may have a quantity greater than 1,
683
-     * this method will ONLY CREATE ONE REGISTRATION !!!
684
-     * Regardless of the ticket line item quantity.
685
-     * This means that any code calling this method is responsible for ensuring
686
-     * that the final registration count matches the ticket line item quantity.
687
-     * This was done to make it easier to match the number of registrations
688
-     * to the number of tickets in the cart, when the cart has been edited
689
-     * after SPCO has already been initialized. So if an additional ticket was added to the cart, you can simply pass
690
-     * the line item to this method to add a second ticket, and in this case, you would not want to add 2 tickets.
691
-     *
692
-     * @param EE_Line_Item   $line_item
693
-     * @param EE_Transaction $transaction
694
-     * @param int            $att_nmbr
695
-     * @param int            $total_ticket_count
696
-     * @return EE_Registration | null
697
-     * @throws OutOfRangeException
698
-     * @throws UnexpectedEntityException
699
-     * @throws EE_Error
700
-     * @throws ReflectionException
701
-     * @deprecated
702
-     * @since 4.9.1
703
-     */
704
-    public function generate_ONE_registration_from_line_item(
705
-        EE_Line_Item $line_item,
706
-        EE_Transaction $transaction,
707
-        $att_nmbr = 1,
708
-        $total_ticket_count = 1
709
-    ) {
710
-        EE_Error::doing_it_wrong(
711
-            __CLASS__ . '::' . __FUNCTION__,
712
-            sprintf(
713
-                esc_html__('This method is deprecated. Please use "%s" instead', 'event_espresso'),
714
-                '\EventEspresso\core\domain\services\registration\CreateRegistrationService::create()'
715
-            ),
716
-            '4.9.1',
717
-            '5.0.0'
718
-        );
719
-        // grab the related ticket object for this line_item
720
-        $ticket = $line_item->ticket();
721
-        if (! $ticket instanceof EE_Ticket) {
722
-            EE_Error::add_error(
723
-                sprintf(
724
-                    esc_html__('Line item %s did not contain a valid ticket', 'event_espresso'),
725
-                    $line_item->ID()
726
-                ),
727
-                __FILE__,
728
-                __FUNCTION__,
729
-                __LINE__
730
-            );
731
-            return null;
732
-        }
733
-        $registration_service = new CreateRegistrationService();
734
-        // then generate a new registration from that
735
-        return $registration_service->create(
736
-            $ticket->get_related_event(),
737
-            $transaction,
738
-            $ticket,
739
-            $line_item,
740
-            $att_nmbr,
741
-            $total_ticket_count
742
-        );
743
-    }
744
-
745
-
746
-    /**
747
-     * generates reg_url_link
748
-     *
749
-     * @param int                   $att_nmbr
750
-     * @param EE_Line_Item | string $item
751
-     * @return RegUrlLink
752
-     * @throws InvalidArgumentException
753
-     * @deprecated
754
-     * @since 4.9.1
755
-     */
756
-    public function generate_reg_url_link($att_nmbr, $item)
757
-    {
758
-        EE_Error::doing_it_wrong(
759
-            __CLASS__ . '::' . __FUNCTION__,
760
-            sprintf(
761
-                esc_html__('This method is deprecated. Please use "%s" instead', 'event_espresso'),
762
-                'EventEspresso\core\domain\entities\RegUrlLink'
763
-            ),
764
-            '4.9.1',
765
-            '5.0.0'
766
-        );
767
-        return new RegUrlLink($att_nmbr, $item);
768
-    }
769
-
770
-
771
-    /**
772
-     * generates reg code
773
-     *
774
-     * @param EE_Registration $registration
775
-     * @return RegCode
776
-     * @throws EE_Error
777
-     * @throws EntityNotFoundException
778
-     * @throws InvalidArgumentException
779
-     * @since 4.9.1
780
-     * @deprecated
781
-     */
782
-    public function generate_reg_code(EE_Registration $registration)
783
-    {
784
-        EE_Error::doing_it_wrong(
785
-            __CLASS__ . '::' . __FUNCTION__,
786
-            sprintf(
787
-                esc_html__('This method is deprecated. Please use "%s" instead', 'event_espresso'),
788
-                'EventEspresso\core\domain\entities\RegCode'
789
-            ),
790
-            '4.9.1',
791
-            '5.0.0'
792
-        );
793
-        return apply_filters(
794
-            'FHEE__EE_Registration_Processor___generate_reg_code__new_reg_code',
795
-            new RegCode(
796
-                RegUrlLink::fromRegistration($registration),
797
-                $registration->transaction(),
798
-                $registration->ticket()
799
-            ),
800
-            $registration
801
-        );
802
-    }
390
+			$registration->status_ID() === EEM_Registration::status_id_pending_payment
391
+			// AND no monies are owing
392
+			&& (
393
+				(
394
+					$registration->transaction()->is_completed()
395
+					|| $registration->transaction()->is_overpaid()
396
+					|| $registration->transaction()->is_free()
397
+					|| apply_filters(
398
+						'FHEE__EE_Registration_Processor__toggle_registration_status_if_no_monies_owing',
399
+						false,
400
+						$registration
401
+					)
402
+				)
403
+				|| (
404
+					$payment instanceof EE_Payment && $payment->is_approved()
405
+					&& // this specific registration has not yet been paid for
406
+					! isset(self::$_amount_paid[ $registration->ID() ])
407
+					&& // payment amount, less what we have already attributed to other registrations, is greater than this reg's final price
408
+					$payment->amount() - $total_paid >= $registration->final_price()
409
+				)
410
+			)
411
+		) {
412
+			// mark as paid
413
+			self::$_amount_paid[ $registration->ID() ] = $registration->final_price();
414
+			// track new REG_Status
415
+			$this->set_new_reg_status($registration->ID(), EEM_Registration::status_id_approved);
416
+			// toggle status to approved
417
+			$registration->set_status(EEM_Registration::status_id_approved);
418
+			if ($save) {
419
+				$registration->save();
420
+			}
421
+			// don't trigger notifications during IPNs because they will get triggered by EE_Payment_Processor
422
+			if (! EE_Processor_Base::$IPN) {
423
+				// otherwise, send out notifications
424
+				add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true', 10);
425
+			}
426
+			// DEBUG LOG
427
+			// $this->log(
428
+			//     __CLASS__,
429
+			//     __FUNCTION__,
430
+			//     __LINE__,
431
+			//     $registration->transaction(),
432
+			//     array(
433
+			//         'IPN' => EE_Processor_Base::$IPN,
434
+			//         'deliver_notifications' => has_filter(
435
+			//             'FHEE__EED_Messages___maybe_registration__deliver_notifications'
436
+			//         ),
437
+			//     )
438
+			// );
439
+			return true;
440
+		}
441
+		return false;
442
+	}
443
+
444
+
445
+	/**
446
+	 *    registration_status_changed
447
+	 *
448
+	 * @access public
449
+	 * @param EE_Registration $registration
450
+	 * @param array           $additional_details
451
+	 * @return void
452
+	 */
453
+	public function trigger_registration_update_notifications($registration, array $additional_details = [])
454
+	{
455
+		try {
456
+			if (! $registration instanceof EE_Registration) {
457
+				throw new EE_Error(
458
+					esc_html__('An invalid registration was received.', 'event_espresso')
459
+				);
460
+			}
461
+			// EE_Registry::instance()->load_helper('Debug_Tools');
462
+			// EEH_Debug_Tools::log(
463
+			//     __CLASS__,
464
+			//     __FUNCTION__,
465
+			//     __LINE__,
466
+			//     array($registration->transaction(), $additional_details),
467
+			//     false,
468
+			//     'EE_Transaction: ' . $registration->transaction()->ID()
469
+			// );
470
+			if (
471
+				! $this->request->getRequestParam('non_primary_reg_notification', 0, 'int')
472
+				&& ! $registration->is_primary_registrant()
473
+			) {
474
+				return;
475
+			}
476
+			do_action(
477
+				'AHEE__EE_Registration_Processor__trigger_registration_update_notifications',
478
+				$registration,
479
+				$additional_details
480
+			);
481
+		} catch (Exception $e) {
482
+			EE_Error::add_error($e->getMessage(), $e->getFile(), 'unknown_function_from_exception', $e->getLine());
483
+		}
484
+	}
485
+
486
+
487
+	/**
488
+	 * sets reg status based either on passed param or on transaction status and event pre-approval setting
489
+	 *
490
+	 * @param EE_Registration $registration
491
+	 * @param array           $additional_details
492
+	 * @return bool
493
+	 * @throws EE_Error
494
+	 * @throws EntityNotFoundException
495
+	 * @throws InvalidArgumentException
496
+	 * @throws InvalidDataTypeException
497
+	 * @throws InvalidInterfaceException
498
+	 * @throws ReflectionException
499
+	 * @throws RuntimeException
500
+	 */
501
+	public function update_registration_after_checkout_or_payment(
502
+		EE_Registration $registration,
503
+		array $additional_details = []
504
+	) {
505
+		// set initial REG_Status
506
+		$this->set_old_reg_status($registration->ID(), $registration->status_ID());
507
+		// if the registration status gets updated, then save the registration
508
+		if (
509
+			$this->toggle_registration_status_for_default_approved_events($registration, false)
510
+			|| $this->toggle_registration_status_if_no_monies_owing(
511
+				$registration,
512
+				false,
513
+				$additional_details
514
+			)
515
+		) {
516
+			$registration->save();
517
+		}
518
+		// set new  REG_Status
519
+		$this->set_new_reg_status($registration->ID(), $registration->status_ID());
520
+		return $this->reg_status_updated($registration->ID())
521
+			   && $this->new_reg_status($registration->ID()) === EEM_Registration::status_id_approved;
522
+	}
523
+
524
+
525
+	/**
526
+	 * Updates the registration' final prices based on the current line item tree (taking into account
527
+	 * discounts, taxes, and other line items unrelated to tickets.)
528
+	 *
529
+	 * @param EE_Transaction $transaction
530
+	 * @param boolean        $save_regs whether to immediately save registrations in this function or not
531
+	 * @return void
532
+	 * @throws EE_Error
533
+	 * @throws InvalidArgumentException
534
+	 * @throws InvalidDataTypeException
535
+	 * @throws InvalidInterfaceException
536
+	 * @throws RuntimeException
537
+	 * @throws ReflectionException
538
+	 */
539
+	public function update_registration_final_prices($transaction, $save_regs = true)
540
+	{
541
+		$reg_final_price_per_ticket_line_item = EEH_Line_Item::calculate_reg_final_prices_per_line_item(
542
+			$transaction->total_line_item()
543
+		);
544
+		foreach ($transaction->registrations() as $registration) {
545
+			/** @var EE_Line_Item $line_item */
546
+			$line_item = EEM_Line_Item::instance()->get_line_item_for_registration($registration);
547
+			if (isset($reg_final_price_per_ticket_line_item[ $line_item->ID() ])) {
548
+				$registration->set_final_price($reg_final_price_per_ticket_line_item[ $line_item->ID() ]);
549
+				if ($save_regs) {
550
+					$registration->save();
551
+				}
552
+			}
553
+		}
554
+		// and make sure there's no rounding problem
555
+		$this->fix_reg_final_price_rounding_issue($transaction);
556
+	}
557
+
558
+
559
+	/**
560
+	 * Makes sure there is no rounding errors for the REG_final_prices.
561
+	 * Eg, if we have 3 registrations for $1, and there is a $0.01 discount between the three of them,
562
+	 * they will each be for $0.99333333, which gets rounded to $1 again.
563
+	 * So the transaction total will be $2.99, but each registration will be for $1,
564
+	 * so if each registrant paid individually they will have overpaid by $0.01.
565
+	 * So in order to overcome this, we check for any difference, and if there is a difference
566
+	 * we just grab one registrant at random and make them responsible for it.
567
+	 * This should be used after setting REG_final_prices (it's done automatically as part of
568
+	 * EE_Registration_Processor::update_registration_final_prices())
569
+	 *
570
+	 * @param EE_Transaction $transaction
571
+	 * @return bool success verifying that there is NO difference after this method is done
572
+	 * @throws EE_Error
573
+	 * @throws InvalidArgumentException
574
+	 * @throws InvalidDataTypeException
575
+	 * @throws InvalidInterfaceException
576
+	 * @throws ReflectionException
577
+	 */
578
+	public function fix_reg_final_price_rounding_issue($transaction)
579
+	{
580
+		$reg_final_price_sum = EEM_Registration::instance()->sum(
581
+			[
582
+				[
583
+					'TXN_ID' => $transaction->ID(),
584
+				],
585
+			],
586
+			'REG_final_price'
587
+		);
588
+		$diff                = $transaction->total() - $reg_final_price_sum;
589
+		// ok then, just grab one of the registrations
590
+		if ($diff !== (float) 0) {
591
+			$a_reg = EEM_Registration::instance()->get_one(
592
+				[
593
+					[
594
+						'TXN_ID' => $transaction->ID(),
595
+					],
596
+				]
597
+			);
598
+			return $a_reg instanceof EE_Registration
599
+				   && $a_reg->save(['REG_final_price' => $a_reg->final_price() + $diff]);
600
+		}
601
+		return true;
602
+	}
603
+
604
+
605
+	/**
606
+	 * update_registration_after_being_canceled_or_declined
607
+	 *
608
+	 * @param EE_Registration $registration
609
+	 * @param array           $closed_reg_statuses
610
+	 * @param bool            $update_reg
611
+	 * @return bool
612
+	 * @throws EE_Error
613
+	 * @throws RuntimeException
614
+	 * @throws ReflectionException
615
+	 */
616
+	public function update_registration_after_being_canceled_or_declined(
617
+		EE_Registration $registration,
618
+		array $closed_reg_statuses = [],
619
+		$update_reg = true
620
+	) {
621
+		// these reg statuses should not be considered in any calculations involving monies owing
622
+		$closed_reg_statuses = ! empty($closed_reg_statuses)
623
+			? $closed_reg_statuses
624
+			: EEM_Registration::closed_reg_statuses();
625
+		if (! in_array($registration->status_ID(), $closed_reg_statuses, true)) {
626
+			return false;
627
+		}
628
+		// release a reserved ticket by decrementing ticket and datetime reserved values
629
+		$registration->release_reserved_ticket(true, 'RegProcessor:' . __LINE__);
630
+		$registration->set_final_price(0);
631
+		if ($update_reg) {
632
+			$registration->save();
633
+		}
634
+		return true;
635
+	}
636
+
637
+
638
+	/**
639
+	 * update_canceled_or_declined_registration_after_being_reinstated
640
+	 *
641
+	 * @param EE_Registration $registration
642
+	 * @param array           $closed_reg_statuses
643
+	 * @param bool            $update_reg
644
+	 * @return bool
645
+	 * @throws EE_Error
646
+	 * @throws RuntimeException
647
+	 * @throws ReflectionException
648
+	 */
649
+	public function update_canceled_or_declined_registration_after_being_reinstated(
650
+		EE_Registration $registration,
651
+		array $closed_reg_statuses = [],
652
+		$update_reg = true
653
+	) {
654
+		// these reg statuses should not be considered in any calculations involving monies owing
655
+		$closed_reg_statuses = ! empty($closed_reg_statuses) ? $closed_reg_statuses
656
+			: EEM_Registration::closed_reg_statuses();
657
+		if (in_array($registration->status_ID(), $closed_reg_statuses, true)) {
658
+			return false;
659
+		}
660
+		$ticket = $registration->ticket();
661
+		if (! $ticket instanceof EE_Ticket) {
662
+			throw new EE_Error(
663
+				sprintf(
664
+					esc_html__(
665
+						'The Ticket for Registration %1$d was not found or is invalid.',
666
+						'event_espresso'
667
+					),
668
+					$registration->ticket_ID()
669
+				)
670
+			);
671
+		}
672
+		$registration->set_final_price($ticket->price());
673
+		if ($update_reg) {
674
+			$registration->save();
675
+		}
676
+		return true;
677
+	}
678
+
679
+
680
+	/**
681
+	 * generate_ONE_registration_from_line_item
682
+	 * Although a ticket line item may have a quantity greater than 1,
683
+	 * this method will ONLY CREATE ONE REGISTRATION !!!
684
+	 * Regardless of the ticket line item quantity.
685
+	 * This means that any code calling this method is responsible for ensuring
686
+	 * that the final registration count matches the ticket line item quantity.
687
+	 * This was done to make it easier to match the number of registrations
688
+	 * to the number of tickets in the cart, when the cart has been edited
689
+	 * after SPCO has already been initialized. So if an additional ticket was added to the cart, you can simply pass
690
+	 * the line item to this method to add a second ticket, and in this case, you would not want to add 2 tickets.
691
+	 *
692
+	 * @param EE_Line_Item   $line_item
693
+	 * @param EE_Transaction $transaction
694
+	 * @param int            $att_nmbr
695
+	 * @param int            $total_ticket_count
696
+	 * @return EE_Registration | null
697
+	 * @throws OutOfRangeException
698
+	 * @throws UnexpectedEntityException
699
+	 * @throws EE_Error
700
+	 * @throws ReflectionException
701
+	 * @deprecated
702
+	 * @since 4.9.1
703
+	 */
704
+	public function generate_ONE_registration_from_line_item(
705
+		EE_Line_Item $line_item,
706
+		EE_Transaction $transaction,
707
+		$att_nmbr = 1,
708
+		$total_ticket_count = 1
709
+	) {
710
+		EE_Error::doing_it_wrong(
711
+			__CLASS__ . '::' . __FUNCTION__,
712
+			sprintf(
713
+				esc_html__('This method is deprecated. Please use "%s" instead', 'event_espresso'),
714
+				'\EventEspresso\core\domain\services\registration\CreateRegistrationService::create()'
715
+			),
716
+			'4.9.1',
717
+			'5.0.0'
718
+		);
719
+		// grab the related ticket object for this line_item
720
+		$ticket = $line_item->ticket();
721
+		if (! $ticket instanceof EE_Ticket) {
722
+			EE_Error::add_error(
723
+				sprintf(
724
+					esc_html__('Line item %s did not contain a valid ticket', 'event_espresso'),
725
+					$line_item->ID()
726
+				),
727
+				__FILE__,
728
+				__FUNCTION__,
729
+				__LINE__
730
+			);
731
+			return null;
732
+		}
733
+		$registration_service = new CreateRegistrationService();
734
+		// then generate a new registration from that
735
+		return $registration_service->create(
736
+			$ticket->get_related_event(),
737
+			$transaction,
738
+			$ticket,
739
+			$line_item,
740
+			$att_nmbr,
741
+			$total_ticket_count
742
+		);
743
+	}
744
+
745
+
746
+	/**
747
+	 * generates reg_url_link
748
+	 *
749
+	 * @param int                   $att_nmbr
750
+	 * @param EE_Line_Item | string $item
751
+	 * @return RegUrlLink
752
+	 * @throws InvalidArgumentException
753
+	 * @deprecated
754
+	 * @since 4.9.1
755
+	 */
756
+	public function generate_reg_url_link($att_nmbr, $item)
757
+	{
758
+		EE_Error::doing_it_wrong(
759
+			__CLASS__ . '::' . __FUNCTION__,
760
+			sprintf(
761
+				esc_html__('This method is deprecated. Please use "%s" instead', 'event_espresso'),
762
+				'EventEspresso\core\domain\entities\RegUrlLink'
763
+			),
764
+			'4.9.1',
765
+			'5.0.0'
766
+		);
767
+		return new RegUrlLink($att_nmbr, $item);
768
+	}
769
+
770
+
771
+	/**
772
+	 * generates reg code
773
+	 *
774
+	 * @param EE_Registration $registration
775
+	 * @return RegCode
776
+	 * @throws EE_Error
777
+	 * @throws EntityNotFoundException
778
+	 * @throws InvalidArgumentException
779
+	 * @since 4.9.1
780
+	 * @deprecated
781
+	 */
782
+	public function generate_reg_code(EE_Registration $registration)
783
+	{
784
+		EE_Error::doing_it_wrong(
785
+			__CLASS__ . '::' . __FUNCTION__,
786
+			sprintf(
787
+				esc_html__('This method is deprecated. Please use "%s" instead', 'event_espresso'),
788
+				'EventEspresso\core\domain\entities\RegCode'
789
+			),
790
+			'4.9.1',
791
+			'5.0.0'
792
+		);
793
+		return apply_filters(
794
+			'FHEE__EE_Registration_Processor___generate_reg_code__new_reg_code',
795
+			new RegCode(
796
+				RegUrlLink::fromRegistration($registration),
797
+				$registration->transaction(),
798
+				$registration->ticket()
799
+			),
800
+			$registration
801
+		);
802
+	}
803 803
 }
Please login to merge, or discard this patch.
Spacing   +25 added lines, -25 removed lines patch added patch discarded remove patch
@@ -81,8 +81,8 @@  discard block
 block discarded – undo
81 81
     public static function instance(RequestInterface $request = null)
82 82
     {
83 83
         // check if class object is instantiated
84
-        if (! self::$_instance instanceof EE_Registration_Processor) {
85
-            if (! $request instanceof RequestInterface) {
84
+        if ( ! self::$_instance instanceof EE_Registration_Processor) {
85
+            if ( ! $request instanceof RequestInterface) {
86 86
                 $request = LoaderFactory::getLoader()->getShared('EventEspresso\core\services\request\Request');
87 87
             }
88 88
             self::$_instance = new self($request);
@@ -108,7 +108,7 @@  discard block
 block discarded – undo
108 108
      */
109 109
     public function old_reg_status($REG_ID)
110 110
     {
111
-        return isset($this->_old_reg_status[ $REG_ID ]) ? $this->_old_reg_status[ $REG_ID ] : null;
111
+        return isset($this->_old_reg_status[$REG_ID]) ? $this->_old_reg_status[$REG_ID] : null;
112 112
     }
113 113
 
114 114
 
@@ -119,8 +119,8 @@  discard block
 block discarded – undo
119 119
     public function set_old_reg_status($REG_ID, $old_reg_status)
120 120
     {
121 121
         // only set the first time
122
-        if (! isset($this->_old_reg_status[ $REG_ID ])) {
123
-            $this->_old_reg_status[ $REG_ID ] = $old_reg_status;
122
+        if ( ! isset($this->_old_reg_status[$REG_ID])) {
123
+            $this->_old_reg_status[$REG_ID] = $old_reg_status;
124 124
         }
125 125
     }
126 126
 
@@ -131,7 +131,7 @@  discard block
 block discarded – undo
131 131
      */
132 132
     public function new_reg_status($REG_ID)
133 133
     {
134
-        return isset($this->_new_reg_status[ $REG_ID ]) ? $this->_new_reg_status[ $REG_ID ] : null;
134
+        return isset($this->_new_reg_status[$REG_ID]) ? $this->_new_reg_status[$REG_ID] : null;
135 135
     }
136 136
 
137 137
 
@@ -141,7 +141,7 @@  discard block
 block discarded – undo
141 141
      */
142 142
     public function set_new_reg_status($REG_ID, $new_reg_status)
143 143
     {
144
-        $this->_new_reg_status[ $REG_ID ] = $new_reg_status;
144
+        $this->_new_reg_status[$REG_ID] = $new_reg_status;
145 145
     }
146 146
 
147 147
 
@@ -208,7 +208,7 @@  discard block
 block discarded – undo
208 208
         if (
209 209
             $this->reg_status_updated($registration->ID())
210 210
             && (
211
-                (! $this->request->isAdmin() || $this->request->isFrontAjax())
211
+                ( ! $this->request->isAdmin() || $this->request->isFrontAjax())
212 212
                 || EE_Registry::instance()->CAP->current_user_can(
213 213
                     'ee_edit_registration',
214 214
                     'toggle_registration_status',
@@ -271,7 +271,7 @@  discard block
 block discarded – undo
271 271
                 $registration->save();
272 272
             }
273 273
             // don't trigger notifications during IPNs because they will get triggered by EE_Payment_Processor
274
-            if (! EE_Processor_Base::$IPN) {
274
+            if ( ! EE_Processor_Base::$IPN) {
275 275
                 // otherwise, send out notifications
276 276
                 add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true', 10);
277 277
             }
@@ -330,7 +330,7 @@  discard block
 block discarded – undo
330 330
                 $registration->save();
331 331
             }
332 332
             // don't trigger notifications during IPNs because they will get triggered by EE_Payment_Processor
333
-            if (! EE_Processor_Base::$IPN) {
333
+            if ( ! EE_Processor_Base::$IPN) {
334 334
                 // otherwise, send out notifications
335 335
                 add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true', 10);
336 336
             }
@@ -378,7 +378,7 @@  discard block
 block discarded – undo
378 378
         // set initial REG_Status
379 379
         $this->set_old_reg_status($registration->ID(), $registration->status_ID());
380 380
         // was a payment just made ?
381
-        $payment    = isset($additional_details['payment_updates'], $additional_details['last_payment'])
381
+        $payment = isset($additional_details['payment_updates'], $additional_details['last_payment'])
382 382
                       && $additional_details['payment_updates']
383 383
                       && $additional_details['last_payment'] instanceof EE_Payment
384 384
             ? $additional_details['last_payment']
@@ -403,14 +403,14 @@  discard block
 block discarded – undo
403 403
                 || (
404 404
                     $payment instanceof EE_Payment && $payment->is_approved()
405 405
                     && // this specific registration has not yet been paid for
406
-                    ! isset(self::$_amount_paid[ $registration->ID() ])
406
+                    ! isset(self::$_amount_paid[$registration->ID()])
407 407
                     && // payment amount, less what we have already attributed to other registrations, is greater than this reg's final price
408 408
                     $payment->amount() - $total_paid >= $registration->final_price()
409 409
                 )
410 410
             )
411 411
         ) {
412 412
             // mark as paid
413
-            self::$_amount_paid[ $registration->ID() ] = $registration->final_price();
413
+            self::$_amount_paid[$registration->ID()] = $registration->final_price();
414 414
             // track new REG_Status
415 415
             $this->set_new_reg_status($registration->ID(), EEM_Registration::status_id_approved);
416 416
             // toggle status to approved
@@ -419,7 +419,7 @@  discard block
 block discarded – undo
419 419
                 $registration->save();
420 420
             }
421 421
             // don't trigger notifications during IPNs because they will get triggered by EE_Payment_Processor
422
-            if (! EE_Processor_Base::$IPN) {
422
+            if ( ! EE_Processor_Base::$IPN) {
423 423
                 // otherwise, send out notifications
424 424
                 add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true', 10);
425 425
             }
@@ -453,7 +453,7 @@  discard block
 block discarded – undo
453 453
     public function trigger_registration_update_notifications($registration, array $additional_details = [])
454 454
     {
455 455
         try {
456
-            if (! $registration instanceof EE_Registration) {
456
+            if ( ! $registration instanceof EE_Registration) {
457 457
                 throw new EE_Error(
458 458
                     esc_html__('An invalid registration was received.', 'event_espresso')
459 459
                 );
@@ -544,8 +544,8 @@  discard block
 block discarded – undo
544 544
         foreach ($transaction->registrations() as $registration) {
545 545
             /** @var EE_Line_Item $line_item */
546 546
             $line_item = EEM_Line_Item::instance()->get_line_item_for_registration($registration);
547
-            if (isset($reg_final_price_per_ticket_line_item[ $line_item->ID() ])) {
548
-                $registration->set_final_price($reg_final_price_per_ticket_line_item[ $line_item->ID() ]);
547
+            if (isset($reg_final_price_per_ticket_line_item[$line_item->ID()])) {
548
+                $registration->set_final_price($reg_final_price_per_ticket_line_item[$line_item->ID()]);
549 549
                 if ($save_regs) {
550 550
                     $registration->save();
551 551
                 }
@@ -585,7 +585,7 @@  discard block
 block discarded – undo
585 585
             ],
586 586
             'REG_final_price'
587 587
         );
588
-        $diff                = $transaction->total() - $reg_final_price_sum;
588
+        $diff = $transaction->total() - $reg_final_price_sum;
589 589
         // ok then, just grab one of the registrations
590 590
         if ($diff !== (float) 0) {
591 591
             $a_reg = EEM_Registration::instance()->get_one(
@@ -622,11 +622,11 @@  discard block
 block discarded – undo
622 622
         $closed_reg_statuses = ! empty($closed_reg_statuses)
623 623
             ? $closed_reg_statuses
624 624
             : EEM_Registration::closed_reg_statuses();
625
-        if (! in_array($registration->status_ID(), $closed_reg_statuses, true)) {
625
+        if ( ! in_array($registration->status_ID(), $closed_reg_statuses, true)) {
626 626
             return false;
627 627
         }
628 628
         // release a reserved ticket by decrementing ticket and datetime reserved values
629
-        $registration->release_reserved_ticket(true, 'RegProcessor:' . __LINE__);
629
+        $registration->release_reserved_ticket(true, 'RegProcessor:'.__LINE__);
630 630
         $registration->set_final_price(0);
631 631
         if ($update_reg) {
632 632
             $registration->save();
@@ -658,7 +658,7 @@  discard block
 block discarded – undo
658 658
             return false;
659 659
         }
660 660
         $ticket = $registration->ticket();
661
-        if (! $ticket instanceof EE_Ticket) {
661
+        if ( ! $ticket instanceof EE_Ticket) {
662 662
             throw new EE_Error(
663 663
                 sprintf(
664 664
                     esc_html__(
@@ -708,7 +708,7 @@  discard block
 block discarded – undo
708 708
         $total_ticket_count = 1
709 709
     ) {
710 710
         EE_Error::doing_it_wrong(
711
-            __CLASS__ . '::' . __FUNCTION__,
711
+            __CLASS__.'::'.__FUNCTION__,
712 712
             sprintf(
713 713
                 esc_html__('This method is deprecated. Please use "%s" instead', 'event_espresso'),
714 714
                 '\EventEspresso\core\domain\services\registration\CreateRegistrationService::create()'
@@ -718,7 +718,7 @@  discard block
 block discarded – undo
718 718
         );
719 719
         // grab the related ticket object for this line_item
720 720
         $ticket = $line_item->ticket();
721
-        if (! $ticket instanceof EE_Ticket) {
721
+        if ( ! $ticket instanceof EE_Ticket) {
722 722
             EE_Error::add_error(
723 723
                 sprintf(
724 724
                     esc_html__('Line item %s did not contain a valid ticket', 'event_espresso'),
@@ -756,7 +756,7 @@  discard block
 block discarded – undo
756 756
     public function generate_reg_url_link($att_nmbr, $item)
757 757
     {
758 758
         EE_Error::doing_it_wrong(
759
-            __CLASS__ . '::' . __FUNCTION__,
759
+            __CLASS__.'::'.__FUNCTION__,
760 760
             sprintf(
761 761
                 esc_html__('This method is deprecated. Please use "%s" instead', 'event_espresso'),
762 762
                 'EventEspresso\core\domain\entities\RegUrlLink'
@@ -782,7 +782,7 @@  discard block
 block discarded – undo
782 782
     public function generate_reg_code(EE_Registration $registration)
783 783
     {
784 784
         EE_Error::doing_it_wrong(
785
-            __CLASS__ . '::' . __FUNCTION__,
785
+            __CLASS__.'::'.__FUNCTION__,
786 786
             sprintf(
787 787
                 esc_html__('This method is deprecated. Please use "%s" instead', 'event_espresso'),
788 788
                 'EventEspresso\core\domain\entities\RegCode'
Please login to merge, or discard this patch.
modules/messages/EED_Messages.module.php 2 patches
Indentation   +1338 added lines, -1338 removed lines patch added patch discarded remove patch
@@ -16,1351 +16,1351 @@
 block discarded – undo
16 16
 class EED_Messages extends EED_Module
17 17
 {
18 18
 
19
-    /**
20
-     * This holds the EE_messages controller
21
-     *
22
-     * @deprecated 4.9.0
23
-     * @var EE_messages $_EEMSG
24
-     */
25
-    protected static $_EEMSG;
26
-
27
-    /**
28
-     * @type EE_Message_Resource_Manager $_message_resource_manager
29
-     */
30
-    protected static $_message_resource_manager;
31
-
32
-    /**
33
-     * This holds the EE_Messages_Processor business class.
34
-     *
35
-     * @type EE_Messages_Processor
36
-     */
37
-    protected static $_MSG_PROCESSOR;
38
-
39
-    /**
40
-     * holds all the paths for various messages components.
41
-     * Utilized by autoloader registry
42
-     *
43
-     * @var array
44
-     */
45
-    protected static $_MSG_PATHS;
46
-
47
-
48
-    /**
49
-     * This will hold an array of messages template packs that are registered in the messages system.
50
-     * Format is:
51
-     * array(
52
-     *    'template_pack_dbref' => EE_Messages_Template_Pack (instance)
53
-     * )
54
-     *
55
-     * @var EE_Messages_Template_Pack[]
56
-     */
57
-    protected static $_TMP_PACKS = array();
58
-
59
-
60
-    /**
61
-     * @return EED_Messages|EED_Module
62
-     * @throws EE_Error
63
-     * @throws ReflectionException
64
-     */
65
-    public static function instance()
66
-    {
67
-        return parent::get_instance(__CLASS__);
68
-    }
69
-
70
-
71
-    /**
72
-     *  set_hooks - for hooking into EE Core, other modules, etc
73
-     *
74
-     * @since 4.5.0
75
-     * @return    void
76
-     */
77
-    public static function set_hooks()
78
-    {
79
-        // actions
80
-        add_action('AHEE__EE_Payment_Processor__update_txn_based_on_payment', array('EED_Messages', 'payment'), 10, 2);
81
-        add_action(
82
-            'AHEE__EE_Registration_Processor__trigger_registration_update_notifications',
83
-            array('EED_Messages', 'maybe_registration'),
84
-            10,
85
-            2
86
-        );
87
-        // filters
88
-        add_filter(
89
-            'FHEE__EE_Registration__receipt_url__receipt_url',
90
-            array('EED_Messages', 'registration_message_trigger_url'),
91
-            10,
92
-            4
93
-        );
94
-        add_filter(
95
-            'FHEE__EE_Registration__invoice_url__invoice_url',
96
-            array('EED_Messages', 'registration_message_trigger_url'),
97
-            10,
98
-            4
99
-        );
100
-        // register routes
101
-        self::_register_routes();
102
-    }
103
-
104
-    /**
105
-     *    set_hooks_admin - for hooking into EE Admin Core, other modules, etc
106
-     *
107
-     * @access    public
108
-     * @return    void
109
-     */
110
-    public static function set_hooks_admin()
111
-    {
112
-        // actions
113
-        add_action('AHEE__EE_Payment_Processor__update_txn_based_on_payment', array('EED_Messages', 'payment'), 10, 2);
114
-        add_action(
115
-            'AHEE__Transactions_Admin_Page___send_payment_reminder__process_admin_payment_reminder',
116
-            array('EED_Messages', 'payment_reminder'),
117
-            10
118
-        );
119
-        add_action(
120
-            'AHEE__EE_Registration_Processor__trigger_registration_update_notifications',
121
-            array('EED_Messages', 'maybe_registration'),
122
-            10,
123
-            3
124
-        );
125
-        add_action(
126
-            'AHEE__Extend_Registrations_Admin_Page___newsletter_selected_send__with_registrations',
127
-            array('EED_Messages', 'send_newsletter_message'),
128
-            10,
129
-            2
130
-        );
131
-        add_action(
132
-            'AHEE__EES_Espresso_Cancelled__process_shortcode__transaction',
133
-            array('EED_Messages', 'cancelled_registration'),
134
-            10
135
-        );
136
-        add_action(
137
-            'AHEE__EE_Admin_Page___process_admin_payment_notification',
138
-            array('EED_Messages', 'process_admin_payment'),
139
-            10,
140
-            1
141
-        );
142
-        // filters
143
-        add_filter(
144
-            'FHEE__EE_Admin_Page___process_resend_registration__success',
145
-            array('EED_Messages', 'process_resend'),
146
-            10,
147
-            2
148
-        );
149
-        add_filter(
150
-            'FHEE__EE_Registration__receipt_url__receipt_url',
151
-            array('EED_Messages', 'registration_message_trigger_url'),
152
-            10,
153
-            4
154
-        );
155
-        add_filter(
156
-            'FHEE__EE_Registration__invoice_url__invoice_url',
157
-            array('EED_Messages', 'registration_message_trigger_url'),
158
-            10,
159
-            4
160
-        );
161
-    }
162
-
163
-
164
-    /**
165
-     * All the message triggers done by route go in here.
166
-     *
167
-     * @since 4.5.0
168
-     * @return void
169
-     */
170
-    protected static function _register_routes()
171
-    {
172
-        EE_Config::register_route('msg_url_trigger', 'Messages', 'run');
173
-        EE_Config::register_route('msg_cron_trigger', 'Messages', 'execute_batch_request');
174
-        EE_Config::register_route('msg_browser_trigger', 'Messages', 'browser_trigger');
175
-        EE_Config::register_route('msg_browser_error_trigger', 'Messages', 'browser_error_trigger');
176
-        do_action('AHEE__EED_Messages___register_routes');
177
-    }
178
-
179
-
180
-    /**
181
-     * This is called when a browser display trigger is executed.
182
-     * The browser display trigger is typically used when a already generated message is displayed directly in the
183
-     * browser.
184
-     *
185
-     * @since 4.9.0
186
-     * @param WP $WP
187
-     * @throws EE_Error
188
-     * @throws InvalidArgumentException
189
-     * @throws ReflectionException
190
-     * @throws InvalidDataTypeException
191
-     * @throws InvalidInterfaceException
192
-     */
193
-    public function browser_trigger($WP)
194
-    {
195
-        // ensure controller is loaded
196
-        self::_load_controller();
197
-        $token = self::getRequest()->getRequestParam('token');
198
-        try {
199
-            $mtg = new EE_Message_Generated_From_Token($token, 'html', self::$_message_resource_manager);
200
-            self::$_MSG_PROCESSOR->generate_and_send_now($mtg);
201
-        } catch (EE_Error $e) {
202
-            $error_msg = esc_html__(
203
-                'Please note that a system message failed to send due to a technical issue.',
204
-                'event_espresso'
205
-            );
206
-            // add specific message for developers if WP_DEBUG in on
207
-            $error_msg .= '||' . $e->getMessage();
208
-            EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__);
209
-        }
210
-    }
211
-
212
-
213
-    /**
214
-     * This is called when a browser error trigger is executed.
215
-     * When triggered this will grab the EE_Message matching the token in the request and use that to get the error
216
-     * message and display it.
217
-     *
218
-     * @since 4.9.0
219
-     * @param $WP
220
-     * @throws EE_Error
221
-     * @throws InvalidArgumentException
222
-     * @throws InvalidDataTypeException
223
-     * @throws InvalidInterfaceException
224
-     */
225
-    public function browser_error_trigger($WP)
226
-    {
227
-        $token = self::getRequest()->getRequestParam('token');
228
-        if ($token) {
229
-            $message = EEM_Message::instance()->get_one_by_token($token);
230
-            if ($message instanceof EE_Message) {
231
-                header('HTTP/1.1 200 OK');
232
-                $error_msg = nl2br($message->error_message());
233
-                ?>
19
+	/**
20
+	 * This holds the EE_messages controller
21
+	 *
22
+	 * @deprecated 4.9.0
23
+	 * @var EE_messages $_EEMSG
24
+	 */
25
+	protected static $_EEMSG;
26
+
27
+	/**
28
+	 * @type EE_Message_Resource_Manager $_message_resource_manager
29
+	 */
30
+	protected static $_message_resource_manager;
31
+
32
+	/**
33
+	 * This holds the EE_Messages_Processor business class.
34
+	 *
35
+	 * @type EE_Messages_Processor
36
+	 */
37
+	protected static $_MSG_PROCESSOR;
38
+
39
+	/**
40
+	 * holds all the paths for various messages components.
41
+	 * Utilized by autoloader registry
42
+	 *
43
+	 * @var array
44
+	 */
45
+	protected static $_MSG_PATHS;
46
+
47
+
48
+	/**
49
+	 * This will hold an array of messages template packs that are registered in the messages system.
50
+	 * Format is:
51
+	 * array(
52
+	 *    'template_pack_dbref' => EE_Messages_Template_Pack (instance)
53
+	 * )
54
+	 *
55
+	 * @var EE_Messages_Template_Pack[]
56
+	 */
57
+	protected static $_TMP_PACKS = array();
58
+
59
+
60
+	/**
61
+	 * @return EED_Messages|EED_Module
62
+	 * @throws EE_Error
63
+	 * @throws ReflectionException
64
+	 */
65
+	public static function instance()
66
+	{
67
+		return parent::get_instance(__CLASS__);
68
+	}
69
+
70
+
71
+	/**
72
+	 *  set_hooks - for hooking into EE Core, other modules, etc
73
+	 *
74
+	 * @since 4.5.0
75
+	 * @return    void
76
+	 */
77
+	public static function set_hooks()
78
+	{
79
+		// actions
80
+		add_action('AHEE__EE_Payment_Processor__update_txn_based_on_payment', array('EED_Messages', 'payment'), 10, 2);
81
+		add_action(
82
+			'AHEE__EE_Registration_Processor__trigger_registration_update_notifications',
83
+			array('EED_Messages', 'maybe_registration'),
84
+			10,
85
+			2
86
+		);
87
+		// filters
88
+		add_filter(
89
+			'FHEE__EE_Registration__receipt_url__receipt_url',
90
+			array('EED_Messages', 'registration_message_trigger_url'),
91
+			10,
92
+			4
93
+		);
94
+		add_filter(
95
+			'FHEE__EE_Registration__invoice_url__invoice_url',
96
+			array('EED_Messages', 'registration_message_trigger_url'),
97
+			10,
98
+			4
99
+		);
100
+		// register routes
101
+		self::_register_routes();
102
+	}
103
+
104
+	/**
105
+	 *    set_hooks_admin - for hooking into EE Admin Core, other modules, etc
106
+	 *
107
+	 * @access    public
108
+	 * @return    void
109
+	 */
110
+	public static function set_hooks_admin()
111
+	{
112
+		// actions
113
+		add_action('AHEE__EE_Payment_Processor__update_txn_based_on_payment', array('EED_Messages', 'payment'), 10, 2);
114
+		add_action(
115
+			'AHEE__Transactions_Admin_Page___send_payment_reminder__process_admin_payment_reminder',
116
+			array('EED_Messages', 'payment_reminder'),
117
+			10
118
+		);
119
+		add_action(
120
+			'AHEE__EE_Registration_Processor__trigger_registration_update_notifications',
121
+			array('EED_Messages', 'maybe_registration'),
122
+			10,
123
+			3
124
+		);
125
+		add_action(
126
+			'AHEE__Extend_Registrations_Admin_Page___newsletter_selected_send__with_registrations',
127
+			array('EED_Messages', 'send_newsletter_message'),
128
+			10,
129
+			2
130
+		);
131
+		add_action(
132
+			'AHEE__EES_Espresso_Cancelled__process_shortcode__transaction',
133
+			array('EED_Messages', 'cancelled_registration'),
134
+			10
135
+		);
136
+		add_action(
137
+			'AHEE__EE_Admin_Page___process_admin_payment_notification',
138
+			array('EED_Messages', 'process_admin_payment'),
139
+			10,
140
+			1
141
+		);
142
+		// filters
143
+		add_filter(
144
+			'FHEE__EE_Admin_Page___process_resend_registration__success',
145
+			array('EED_Messages', 'process_resend'),
146
+			10,
147
+			2
148
+		);
149
+		add_filter(
150
+			'FHEE__EE_Registration__receipt_url__receipt_url',
151
+			array('EED_Messages', 'registration_message_trigger_url'),
152
+			10,
153
+			4
154
+		);
155
+		add_filter(
156
+			'FHEE__EE_Registration__invoice_url__invoice_url',
157
+			array('EED_Messages', 'registration_message_trigger_url'),
158
+			10,
159
+			4
160
+		);
161
+	}
162
+
163
+
164
+	/**
165
+	 * All the message triggers done by route go in here.
166
+	 *
167
+	 * @since 4.5.0
168
+	 * @return void
169
+	 */
170
+	protected static function _register_routes()
171
+	{
172
+		EE_Config::register_route('msg_url_trigger', 'Messages', 'run');
173
+		EE_Config::register_route('msg_cron_trigger', 'Messages', 'execute_batch_request');
174
+		EE_Config::register_route('msg_browser_trigger', 'Messages', 'browser_trigger');
175
+		EE_Config::register_route('msg_browser_error_trigger', 'Messages', 'browser_error_trigger');
176
+		do_action('AHEE__EED_Messages___register_routes');
177
+	}
178
+
179
+
180
+	/**
181
+	 * This is called when a browser display trigger is executed.
182
+	 * The browser display trigger is typically used when a already generated message is displayed directly in the
183
+	 * browser.
184
+	 *
185
+	 * @since 4.9.0
186
+	 * @param WP $WP
187
+	 * @throws EE_Error
188
+	 * @throws InvalidArgumentException
189
+	 * @throws ReflectionException
190
+	 * @throws InvalidDataTypeException
191
+	 * @throws InvalidInterfaceException
192
+	 */
193
+	public function browser_trigger($WP)
194
+	{
195
+		// ensure controller is loaded
196
+		self::_load_controller();
197
+		$token = self::getRequest()->getRequestParam('token');
198
+		try {
199
+			$mtg = new EE_Message_Generated_From_Token($token, 'html', self::$_message_resource_manager);
200
+			self::$_MSG_PROCESSOR->generate_and_send_now($mtg);
201
+		} catch (EE_Error $e) {
202
+			$error_msg = esc_html__(
203
+				'Please note that a system message failed to send due to a technical issue.',
204
+				'event_espresso'
205
+			);
206
+			// add specific message for developers if WP_DEBUG in on
207
+			$error_msg .= '||' . $e->getMessage();
208
+			EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__);
209
+		}
210
+	}
211
+
212
+
213
+	/**
214
+	 * This is called when a browser error trigger is executed.
215
+	 * When triggered this will grab the EE_Message matching the token in the request and use that to get the error
216
+	 * message and display it.
217
+	 *
218
+	 * @since 4.9.0
219
+	 * @param $WP
220
+	 * @throws EE_Error
221
+	 * @throws InvalidArgumentException
222
+	 * @throws InvalidDataTypeException
223
+	 * @throws InvalidInterfaceException
224
+	 */
225
+	public function browser_error_trigger($WP)
226
+	{
227
+		$token = self::getRequest()->getRequestParam('token');
228
+		if ($token) {
229
+			$message = EEM_Message::instance()->get_one_by_token($token);
230
+			if ($message instanceof EE_Message) {
231
+				header('HTTP/1.1 200 OK');
232
+				$error_msg = nl2br($message->error_message());
233
+				?>
234 234
                 <!DOCTYPE html>
235 235
                 <html>
236 236
                 <head></head>
237 237
                 <body>
238 238
                 <?php echo empty($error_msg)
239
-                    ? esc_html__(
240
-                        'Unfortunately, we were unable to capture the error message for this message.',
241
-                        'event_espresso'
242
-                    )
243
-                    : wp_kses(
244
-                        $error_msg,
245
-                        array(
246
-                            'a'      => array(
247
-                                'href'  => array(),
248
-                                'title' => array(),
249
-                            ),
250
-                            'span'   => array(),
251
-                            'div'    => array(),
252
-                            'p'      => array(),
253
-                            'strong' => array(),
254
-                            'em'     => array(),
255
-                            'br'     => array(),
256
-                        )
257
-                    ); ?>
239
+					? esc_html__(
240
+						'Unfortunately, we were unable to capture the error message for this message.',
241
+						'event_espresso'
242
+					)
243
+					: wp_kses(
244
+						$error_msg,
245
+						array(
246
+							'a'      => array(
247
+								'href'  => array(),
248
+								'title' => array(),
249
+							),
250
+							'span'   => array(),
251
+							'div'    => array(),
252
+							'p'      => array(),
253
+							'strong' => array(),
254
+							'em'     => array(),
255
+							'br'     => array(),
256
+						)
257
+					); ?>
258 258
                 </body>
259 259
                 </html>
260 260
                 <?php
261
-                exit;
262
-            }
263
-        }
264
-    }
265
-
266
-
267
-    /**
268
-     *  This runs when the msg_url_trigger route has initiated.
269
-     *
270
-     * @since 4.5.0
271
-     * @param WP $WP
272
-     * @throws EE_Error
273
-     * @throws InvalidArgumentException
274
-     * @throws ReflectionException
275
-     * @throws InvalidDataTypeException
276
-     * @throws InvalidInterfaceException
277
-     */
278
-    public function run($WP)
279
-    {
280
-        // ensure controller is loaded
281
-        self::_load_controller();
282
-        // attempt to process message
283
-        try {
284
-            /** @type EE_Message_To_Generate_From_Request $message_to_generate */
285
-            $message_to_generate = EE_Registry::instance()->load_lib('Message_To_Generate_From_Request');
286
-            self::$_MSG_PROCESSOR->generate_and_send_now($message_to_generate);
287
-        } catch (EE_Error $e) {
288
-            $error_msg = esc_html__(
289
-                'Please note that a system message failed to send due to a technical issue.',
290
-                'event_espresso'
291
-            );
292
-            // add specific message for developers if WP_DEBUG in on
293
-            $error_msg .= '||' . $e->getMessage();
294
-            EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__);
295
-        }
296
-    }
297
-
298
-
299
-    /**
300
-     * This is triggered by the 'msg_cron_trigger' route.
301
-     *
302
-     * @param WP $WP
303
-     */
304
-    public function execute_batch_request($WP)
305
-    {
306
-        $this->run_cron();
307
-        header('HTTP/1.1 200 OK');
308
-        exit();
309
-    }
310
-
311
-
312
-    /**
313
-     * This gets executed on wp_cron jobs or when a batch request is initiated on its own separate non regular wp
314
-     * request.
315
-     */
316
-    public function run_cron()
317
-    {
318
-        self::_load_controller();
319
-        $request = self::getRequest();
320
-        // get required vars
321
-        $cron_type = $request->getRequestParam('type');
322
-        $transient_key = $request->getRequestParam('key');
323
-
324
-        // now let's verify transient, if not valid exit immediately
325
-        if (! get_transient($transient_key)) {
326
-            /**
327
-             * trigger error so this gets in the error logs.  This is important because it happens on a non-user
328
-             * request.
329
-             */
330
-            trigger_error(esc_attr__('Invalid Request (Transient does not exist)', 'event_espresso'));
331
-        }
332
-
333
-        // if made it here, lets' delete the transient to keep the db clean
334
-        delete_transient($transient_key);
335
-
336
-        if (apply_filters('FHEE__EED_Messages__run_cron__use_wp_cron', true)) {
337
-            $method = 'batch_' . $cron_type . '_from_queue';
338
-            if (method_exists(self::$_MSG_PROCESSOR, $method)) {
339
-                self::$_MSG_PROCESSOR->$method();
340
-            } else {
341
-                // no matching task
342
-                /**
343
-                 * trigger error so this gets in the error logs.  This is important because it happens on a non user
344
-                 * request.
345
-                 */
346
-                trigger_error(
347
-                    esc_attr(
348
-                        sprintf(
349
-                            esc_html__('There is no task corresponding to this route %s', 'event_espresso'),
350
-                            $cron_type
351
-                        )
352
-                    )
353
-                );
354
-            }
355
-        }
356
-
357
-        do_action('FHEE__EED_Messages__run_cron__end');
358
-    }
359
-
360
-
361
-    /**
362
-     * This is used to retrieve the template pack for the given name.
363
-     * Retrieved packs are cached on the static $_TMP_PACKS array.  If there is no class matching the given name then
364
-     * the default template pack is returned.
365
-     *
366
-     * @deprecated 4.9.0  @see EEH_MSG_Template::get_template_pack()
367
-     * @param string $template_pack_name This should correspond to the dbref of the template pack (which is also used
368
-     *                                   in generating the Pack class name).
369
-     * @return EE_Messages_Template_Pack
370
-     * @throws EE_Error
371
-     * @throws InvalidArgumentException
372
-     * @throws ReflectionException
373
-     * @throws InvalidDataTypeException
374
-     * @throws InvalidInterfaceException
375
-     */
376
-    public static function get_template_pack($template_pack_name)
377
-    {
378
-        EE_Registry::instance()->load_helper('MSG_Template');
379
-        return EEH_MSG_Template::get_template_pack($template_pack_name);
380
-    }
381
-
382
-
383
-    /**
384
-     * Retrieves an array of all template packs.
385
-     * Array is in the format array( 'dbref' => EE_Messages_Template_Pack )
386
-     *
387
-     * @deprecated 4.9.0  @see EEH_MSG_Template_Pack::get_template_pack_collection
388
-     * @return EE_Messages_Template_Pack[]
389
-     * @throws EE_Error
390
-     * @throws InvalidArgumentException
391
-     * @throws ReflectionException
392
-     * @throws InvalidDataTypeException
393
-     * @throws InvalidInterfaceException
394
-     */
395
-    public static function get_template_packs()
396
-    {
397
-        EE_Registry::instance()->load_helper('MSG_Template');
398
-
399
-        // for backward compat, let's make sure this returns in the same format as originally.
400
-        $template_pack_collection = EEH_MSG_Template::get_template_pack_collection();
401
-        $template_pack_collection->rewind();
402
-        $template_packs = array();
403
-        while ($template_pack_collection->valid()) {
404
-            $template_packs[ $template_pack_collection->current()->dbref ] = $template_pack_collection->current();
405
-            $template_pack_collection->next();
406
-        }
407
-        return $template_packs;
408
-    }
409
-
410
-
411
-    /**
412
-     * This simply makes sure the autoloaders are registered for the EE_messages system.
413
-     *
414
-     * @since 4.5.0
415
-     * @return void
416
-     * @throws EE_Error
417
-     */
418
-    public static function set_autoloaders()
419
-    {
420
-        if (empty(self::$_MSG_PATHS)) {
421
-            self::_set_messages_paths();
422
-            foreach (self::$_MSG_PATHS as $path) {
423
-                EEH_Autoloader::register_autoloaders_for_each_file_in_folder($path);
424
-            }
425
-            // add aliases
426
-            EEH_Autoloader::add_alias('EE_messages', 'EE_messages');
427
-            EEH_Autoloader::add_alias('EE_messenger', 'EE_messenger');
428
-        }
429
-    }
430
-
431
-
432
-    /**
433
-     * Take care of adding all the paths for the messages components to the $_MSG_PATHS property
434
-     * for use by the Messages Autoloaders
435
-     *
436
-     * @since 4.5.0
437
-     * @return void.
438
-     */
439
-    protected static function _set_messages_paths()
440
-    {
441
-        self::$_MSG_PATHS = apply_filters(
442
-            'FHEE__EED_Messages___set_messages_paths___MSG_PATHS',
443
-            [
444
-                EE_LIBRARIES . 'messages/message_type',
445
-                EE_LIBRARIES . 'messages/messenger',
446
-                EE_LIBRARIES . 'messages/defaults',
447
-                EE_LIBRARIES . 'messages/defaults/email',
448
-                EE_LIBRARIES . 'messages/data_class',
449
-                EE_LIBRARIES . 'messages/validators',
450
-                EE_LIBRARIES . 'messages/validators/email',
451
-                EE_LIBRARIES . 'messages/validators/html',
452
-                EE_LIBRARIES . 'shortcodes',
453
-            ]
454
-        );
455
-    }
456
-
457
-
458
-    /**
459
-     * Takes care of loading dependencies
460
-     *
461
-     * @since 4.5.0
462
-     * @return void
463
-     * @throws EE_Error
464
-     * @throws InvalidArgumentException
465
-     * @throws ReflectionException
466
-     * @throws InvalidDataTypeException
467
-     * @throws InvalidInterfaceException
468
-     */
469
-    protected static function _load_controller()
470
-    {
471
-        if (! self::$_MSG_PROCESSOR instanceof EE_Messages_Processor) {
472
-            EE_Registry::instance()->load_core('Request_Handler');
473
-            self::set_autoloaders();
474
-            self::$_EEMSG = EE_Registry::instance()->load_lib('messages');
475
-            self::$_MSG_PROCESSOR = EE_Registry::instance()->load_lib('Messages_Processor');
476
-            self::$_message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
477
-        }
478
-    }
479
-
480
-
481
-    /**
482
-     * @param EE_Transaction $transaction
483
-     * @throws EE_Error
484
-     * @throws InvalidArgumentException
485
-     * @throws InvalidDataTypeException
486
-     * @throws InvalidInterfaceException
487
-     * @throws ReflectionException
488
-     */
489
-    public static function payment_reminder(EE_Transaction $transaction)
490
-    {
491
-        self::_load_controller();
492
-        $data = array($transaction, null);
493
-        self::$_MSG_PROCESSOR->generate_for_all_active_messengers('payment_reminder', $data);
494
-    }
495
-
496
-
497
-    /**
498
-     * Any messages triggers for after successful gateway payments should go in here.
499
-     *
500
-     * @param EE_Transaction  $transaction object
501
-     * @param EE_Payment|null $payment     object
502
-     * @return void
503
-     * @throws EE_Error
504
-     * @throws InvalidArgumentException
505
-     * @throws ReflectionException
506
-     * @throws InvalidDataTypeException
507
-     * @throws InvalidInterfaceException
508
-     */
509
-    public static function payment(EE_Transaction $transaction, EE_Payment $payment = null)
510
-    {
511
-        // if there's no payment object, then we cannot do a payment type message!
512
-        if (! $payment instanceof EE_Payment) {
513
-            return;
514
-        }
515
-        self::_load_controller();
516
-        $data = array($transaction, $payment);
517
-        EE_Registry::instance()->load_helper('MSG_Template');
518
-        $message_type = EEH_MSG_Template::convert_payment_status_to_message_type($payment->STS_ID());
519
-        // if payment amount is less than 0 then switch to payment_refund message type.
520
-        $message_type = $payment->amount() < 0 ? 'payment_refund' : $message_type;
521
-        self::$_MSG_PROCESSOR->generate_for_all_active_messengers($message_type, $data);
522
-    }
523
-
524
-
525
-    /**
526
-     * @param EE_Transaction $transaction
527
-     * @throws EE_Error
528
-     * @throws InvalidArgumentException
529
-     * @throws InvalidDataTypeException
530
-     * @throws InvalidInterfaceException
531
-     * @throws ReflectionException
532
-     */
533
-    public static function cancelled_registration(EE_Transaction $transaction)
534
-    {
535
-        self::_load_controller();
536
-        $data = array($transaction, null);
537
-        self::$_MSG_PROCESSOR->generate_for_all_active_messengers('cancelled_registration', $data);
538
-    }
539
-
540
-
541
-    /**
542
-     * Trigger for Registration messages
543
-     * Note that what registration message type is sent depends on what the reg status is for the registrations on the
544
-     * incoming transaction.
545
-     *
546
-     * @param EE_Registration $registration
547
-     * @param array           $extra_details
548
-     * @return void
549
-     * @throws EE_Error
550
-     * @throws InvalidArgumentException
551
-     * @throws InvalidDataTypeException
552
-     * @throws InvalidInterfaceException
553
-     * @throws ReflectionException
554
-     * @throws EntityNotFoundException
555
-     */
556
-    public static function maybe_registration(EE_Registration $registration, $extra_details = array())
557
-    {
558
-
559
-        if (! self::_verify_registration_notification_send($registration, $extra_details)) {
560
-            // no messages please
561
-            return;
562
-        }
563
-
564
-        // get all non-trashed registrations so we make sure we send messages for the right status.
565
-        $all_registrations = $registration->transaction()->registrations(
566
-            array(
567
-                array('REG_deleted' => false),
568
-                'order_by' => array(
569
-                    'Event.EVT_name'     => 'ASC',
570
-                    'Attendee.ATT_lname' => 'ASC',
571
-                    'Attendee.ATT_fname' => 'ASC',
572
-                ),
573
-            )
574
-        );
575
-        // cached array of statuses so we only trigger messages once per status.
576
-        $statuses_sent = array();
577
-        self::_load_controller();
578
-        $mtgs = array();
579
-
580
-        // loop through registrations and trigger messages once per status.
581
-        foreach ($all_registrations as $reg) {
582
-            // already triggered?
583
-            if (in_array($reg->status_ID(), $statuses_sent)) {
584
-                continue;
585
-            }
586
-
587
-            $message_type = EEH_MSG_Template::convert_reg_status_to_message_type($reg->status_ID());
588
-            $mtgs = array_merge(
589
-                $mtgs,
590
-                self::$_MSG_PROCESSOR->setup_mtgs_for_all_active_messengers(
591
-                    $message_type,
592
-                    array($registration->transaction(), null, $reg->status_ID())
593
-                )
594
-            );
595
-            $statuses_sent[] = $reg->status_ID();
596
-        }
597
-
598
-        if (count($statuses_sent) > 1) {
599
-            $mtgs = array_merge(
600
-                $mtgs,
601
-                self::$_MSG_PROCESSOR->setup_mtgs_for_all_active_messengers(
602
-                    'registration_summary',
603
-                    array($registration->transaction(), null)
604
-                )
605
-            );
606
-        }
607
-
608
-        // batch queue and initiate request
609
-        self::$_MSG_PROCESSOR->batch_queue_for_generation_and_persist($mtgs);
610
-        self::$_MSG_PROCESSOR->get_queue()->initiate_request_by_priority();
611
-    }
612
-
613
-
614
-    /**
615
-     * This is a helper method used to very whether a registration notification should be sent or
616
-     * not.  Prevents duplicate notifications going out for registration context notifications.
617
-     *
618
-     * @param EE_Registration $registration  [description]
619
-     * @param array           $extra_details [description]
620
-     * @return bool          true = send away, false = nope halt the presses.
621
-     */
622
-    protected static function _verify_registration_notification_send(
623
-        EE_Registration $registration,
624
-        $extra_details = array()
625
-    ) {
626
-        $request = self::getRequest();
627
-        if (
628
-            ! $request->getRequestParam('non_primary_reg_notification', 0, 'int')
629
-            && ! $registration->is_primary_registrant()
630
-        ) {
631
-            return false;
632
-        }
633
-        // first we check if we're in admin and not doing front ajax
634
-        if (
635
-            ($request->isAdmin() || $request->isAdminAjax())
636
-            && ! $request->isFrontAjax()
637
-        ) {
638
-            $status_change = $request->getRequestParam('txn_reg_status_change', [], 'int', true);
639
-            // make sure appropriate admin params are set for sending messages
640
-            if (
641
-                ! isset($status_change['send_notifications'])
642
-                || (isset($status_change['send_notifications']) && ! $status_change['send_notifications'])
643
-            ) {
644
-                // no messages sent please.
645
-                return false;
646
-            }
647
-        } else {
648
-            // frontend request (either regular or via AJAX)
649
-            // TXN is NOT finalized ?
650
-            if (! isset($extra_details['finalized']) || $extra_details['finalized'] === false) {
651
-                return false;
652
-            }
653
-            // return visit but nothing changed ???
654
-            if (
655
-                isset($extra_details['revisit'], $extra_details['status_updates']) &&
656
-                $extra_details['revisit'] && ! $extra_details['status_updates']
657
-            ) {
658
-                return false;
659
-            }
660
-            // NOT sending messages && reg status is something other than "Not-Approved"
661
-            if (
662
-                ! apply_filters('FHEE__EED_Messages___maybe_registration__deliver_notifications', false) &&
663
-                $registration->status_ID() !== EEM_Registration::status_id_not_approved
664
-            ) {
665
-                return false;
666
-            }
667
-        }
668
-        // release the kraken
669
-        return true;
670
-    }
671
-
672
-
673
-    /**
674
-     * Simply returns an array indexed by Registration Status ID and the related message_type name associated with that
675
-     * status id.
676
-     *
677
-     * @deprecated 4.9.0  Use EEH_MSG_Template::reg_status_to_message_type_array()
678
-     *                    or EEH_MSG_Template::convert_reg_status_to_message_type
679
-     * @param string $reg_status
680
-     * @return array
681
-     * @throws EE_Error
682
-     * @throws InvalidArgumentException
683
-     * @throws ReflectionException
684
-     * @throws InvalidDataTypeException
685
-     * @throws InvalidInterfaceException
686
-     */
687
-    protected static function _get_reg_status_array($reg_status = '')
688
-    {
689
-        EE_Registry::instance()->load_helper('MSG_Template');
690
-        return EEH_MSG_Template::convert_reg_status_to_message_type($reg_status)
691
-            ? EEH_MSG_Template::convert_reg_status_to_message_type($reg_status)
692
-            : EEH_MSG_Template::reg_status_to_message_type_array();
693
-    }
694
-
695
-
696
-    /**
697
-     * Simply returns the payment message type for the given payment status.
698
-     *
699
-     * @deprecated 4.9.0 Use EEH_MSG_Template::payment_status_to_message_type_array
700
-     *                   or EEH_MSG_Template::convert_payment_status_to_message_type
701
-     * @param string $payment_status The payment status being matched.
702
-     * @return bool|string The payment message type slug matching the status or false if no match.
703
-     * @throws EE_Error
704
-     * @throws InvalidArgumentException
705
-     * @throws ReflectionException
706
-     * @throws InvalidDataTypeException
707
-     * @throws InvalidInterfaceException
708
-     */
709
-    protected static function _get_payment_message_type($payment_status)
710
-    {
711
-        EE_Registry::instance()->load_helper('MSG_Template');
712
-        return EEH_MSG_Template::convert_payment_status_to_message_type($payment_status)
713
-            ? EEH_MSG_Template::convert_payment_status_to_message_type($payment_status)
714
-            : false;
715
-    }
716
-
717
-
718
-    /**
719
-     * Message triggers for a resending already sent message(s) (via EE_Message list table)
720
-     *
721
-     * @access public
722
-     * @param array $req_data This is the $_POST & $_GET data sent from EE_Admin Pages
723
-     * @return bool success/fail
724
-     * @throws EE_Error
725
-     * @throws InvalidArgumentException
726
-     * @throws InvalidDataTypeException
727
-     * @throws InvalidInterfaceException
728
-     * @throws ReflectionException
729
-     */
730
-    public static function process_resend(array $req_data = [])
731
-    {
732
-        self::_load_controller();
733
-        $request = self::getRequest();
734
-        // if $msgID in this request then skip to the new resend_message
735
-        if ($request->getRequestParam('MSG_ID')) {
736
-            return self::resend_message();
737
-        }
738
-
739
-        // make sure any incoming request data is set on the request so that it gets picked up later.
740
-        foreach ((array) $req_data as $request_key => $request_value) {
741
-            if (! $request->requestParamIsSet($request_key)) {
742
-                $request->setRequestParam($request_key, $request_value);
743
-            }
744
-        }
745
-
746
-        if (
747
-            ! $messages_to_send = self::$_MSG_PROCESSOR->setup_messages_to_generate_from_registration_ids_in_request()
748
-        ) {
749
-            return false;
750
-        }
751
-
752
-        try {
753
-            self::$_MSG_PROCESSOR->batch_queue_for_generation_and_persist($messages_to_send);
754
-            self::$_MSG_PROCESSOR->get_queue()->initiate_request_by_priority();
755
-        } catch (EE_Error $e) {
756
-            EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
757
-            return false;
758
-        }
759
-        EE_Error::add_success(
760
-            esc_html__('Messages have been successfully queued for generation and sending.', 'event_espresso')
761
-        );
762
-        return true; // everything got queued.
763
-    }
764
-
765
-
766
-    /**
767
-     * Message triggers for a resending already sent message(s) (via EE_Message list table)
768
-     *
769
-     * @return bool
770
-     * @throws EE_Error
771
-     * @throws InvalidArgumentException
772
-     * @throws InvalidDataTypeException
773
-     * @throws InvalidInterfaceException
774
-     * @throws ReflectionException
775
-     */
776
-    public static function resend_message()
777
-    {
778
-        self::_load_controller();
779
-
780
-        $msgID = self::getRequest()->getRequestParam('MSG_ID', 0, 'int');
781
-        if (! $msgID) {
782
-            EE_Error::add_error(
783
-                esc_html__(
784
-                    'Something went wrong because there is no "MSG_ID" value in the request',
785
-                    'event_espresso'
786
-                ),
787
-                __FILE__,
788
-                __FUNCTION__,
789
-                __LINE__
790
-            );
791
-            return false;
792
-        }
793
-
794
-        self::$_MSG_PROCESSOR->setup_messages_from_ids_and_send((array) $msgID);
795
-
796
-        // setup success message.
797
-        $count_ready_for_resend = self::$_MSG_PROCESSOR->get_queue()->count_STS_in_queue(EEM_Message::status_resend);
798
-        EE_Error::add_success(
799
-            sprintf(
800
-                _n(
801
-                    'There was %d message queued for resending.',
802
-                    'There were %d messages queued for resending.',
803
-                    $count_ready_for_resend,
804
-                    'event_espresso'
805
-                ),
806
-                $count_ready_for_resend
807
-            )
808
-        );
809
-        return true;
810
-    }
811
-
812
-
813
-    /**
814
-     * Message triggers for manual payment applied by admin
815
-     *
816
-     * @param  EE_Payment $payment EE_payment object
817
-     * @return bool success/fail
818
-     * @throws EE_Error
819
-     * @throws InvalidArgumentException
820
-     * @throws ReflectionException
821
-     * @throws InvalidDataTypeException
822
-     * @throws InvalidInterfaceException
823
-     */
824
-    public static function process_admin_payment(EE_Payment $payment)
825
-    {
826
-        EE_Registry::instance()->load_helper('MSG_Template');
827
-        // we need to get the transaction object
828
-        $transaction = $payment->transaction();
829
-        if ($transaction instanceof EE_Transaction) {
830
-            $data = array($transaction, $payment);
831
-            $message_type = EEH_MSG_Template::convert_payment_status_to_message_type($payment->STS_ID());
832
-
833
-            // if payment amount is less than 0 then switch to payment_refund message type.
834
-            $message_type = $payment->amount() < 0 ? 'payment_refund' : $message_type;
835
-
836
-            // if payment_refund is selected, but the status is NOT accepted.  Then change message type to false so NO message notification goes out.
837
-            $message_type = $message_type == 'payment_refund' && $payment->STS_ID() != EEM_Payment::status_id_approved
838
-                ? false : $message_type;
839
-
840
-            self::_load_controller();
841
-
842
-            self::$_MSG_PROCESSOR->generate_for_all_active_messengers($message_type, $data);
843
-
844
-            // get count of queued for generation
845
-            $count_to_generate = self::$_MSG_PROCESSOR->get_queue()->count_STS_in_queue(
846
-                array(
847
-                    EEM_Message::status_incomplete,
848
-                    EEM_Message::status_idle,
849
-                )
850
-            );
851
-
852
-            if ($count_to_generate > 0 && self::$_MSG_PROCESSOR->get_queue()->get_message_repository()->count() !== 0) {
853
-                add_filter('FHEE__EE_Admin_Page___process_admin_payment_notification__success', '__return_true');
854
-                return true;
855
-            } else {
856
-                $count_failed = self::$_MSG_PROCESSOR->get_queue()->count_STS_in_queue(
857
-                    EEM_Message::instance()->stati_indicating_failed_sending()
858
-                );
859
-                /**
860
-                 * Verify that there are actually errors.  If not then we return a success message because the queue might have been emptied due to successful
861
-                 * IMMEDIATE generation.
862
-                 */
863
-                if ($count_failed > 0) {
864
-                    EE_Error::add_error(
865
-                        sprintf(
866
-                            _n(
867
-                                'The payment notification generation failed.',
868
-                                '%d payment notifications failed being sent.',
869
-                                $count_failed,
870
-                                'event_espresso'
871
-                            ),
872
-                            $count_failed
873
-                        ),
874
-                        __FILE__,
875
-                        __FUNCTION__,
876
-                        __LINE__
877
-                    );
878
-
879
-                    return false;
880
-                } else {
881
-                    add_filter('FHEE__EE_Admin_Page___process_admin_payment_notification__success', '__return_true');
882
-                    return true;
883
-                }
884
-            }
885
-        } else {
886
-            EE_Error::add_error(
887
-                'Unable to generate the payment notification because the given value for the transaction is invalid.',
888
-                'event_espresso'
889
-            );
890
-            return false;
891
-        }
892
-    }
893
-
894
-
895
-    /**
896
-     * Callback for AHEE__Extend_Registrations_Admin_Page___newsletter_selected_send_with_registrations trigger
897
-     *
898
-     * @since   4.3.0
899
-     * @param  EE_Registration[] $registrations an array of EE_Registration objects
900
-     * @param  int               $grp_id        a specific message template group id.
901
-     * @return void
902
-     * @throws EE_Error
903
-     * @throws InvalidArgumentException
904
-     * @throws InvalidDataTypeException
905
-     * @throws InvalidInterfaceException
906
-     * @throws ReflectionException
907
-     */
908
-    public static function send_newsletter_message($registrations, $grp_id)
909
-    {
910
-        // make sure mtp is id and set it in the request later messages setup.
911
-        self::getRequest()->setRequestParam('GRP_ID', (int) $grp_id);
912
-        self::_load_controller();
913
-        self::$_MSG_PROCESSOR->generate_for_all_active_messengers('newsletter', $registrations);
914
-    }
915
-
916
-
917
-    /**
918
-     * Callback for FHEE__EE_Registration__invoice_url__invoice_url or FHEE__EE_Registration__receipt_url__receipt_url
919
-     *
920
-     * @since   4.3.0
921
-     * @param    string          $registration_message_trigger_url
922
-     * @param    EE_Registration $registration
923
-     * @param string             $messenger
924
-     * @param string             $message_type
925
-     * @return string
926
-     * @throws EE_Error
927
-     * @throws InvalidArgumentException
928
-     * @throws InvalidDataTypeException
929
-     * @throws InvalidInterfaceException
930
-     */
931
-    public static function registration_message_trigger_url(
932
-        $registration_message_trigger_url,
933
-        EE_Registration $registration,
934
-        $messenger = 'html',
935
-        $message_type = 'invoice'
936
-    ) {
937
-        // whitelist $messenger
938
-        switch ($messenger) {
939
-            case 'pdf':
940
-                $sending_messenger = 'pdf';
941
-                $generating_messenger = 'html';
942
-                break;
943
-            case 'html':
944
-            default:
945
-                $sending_messenger = 'html';
946
-                $generating_messenger = 'html';
947
-                break;
948
-        }
949
-        // whitelist $message_type
950
-        switch ($message_type) {
951
-            case 'receipt':
952
-                $message_type = 'receipt';
953
-                break;
954
-            case 'invoice':
955
-            default:
956
-                $message_type = 'invoice';
957
-                break;
958
-        }
959
-        // verify that both the messenger AND the message type are active
960
-        if (
961
-            EEH_MSG_Template::is_messenger_active($sending_messenger)
962
-            && EEH_MSG_Template::is_mt_active($message_type)
963
-        ) {
964
-            // need to get the correct message template group for this (i.e. is there a custom invoice for the event this registration is registered for?)
965
-            $template_query_params = array(
966
-                'MTP_is_active'    => true,
967
-                'MTP_messenger'    => $generating_messenger,
968
-                'MTP_message_type' => $message_type,
969
-                'Event.EVT_ID'     => $registration->event_ID(),
970
-            );
971
-            // get the message template group.
972
-            $msg_template_group = EEM_Message_Template_Group::instance()->get_one(array($template_query_params));
973
-            // if we don't have an EE_Message_Template_Group then return
974
-            if (! $msg_template_group instanceof EE_Message_Template_Group) {
975
-                // remove EVT_ID from query params so that global templates get picked up
976
-                unset($template_query_params['Event.EVT_ID']);
977
-                // get global template as the fallback
978
-                $msg_template_group = EEM_Message_Template_Group::instance()->get_one(array($template_query_params));
979
-            }
980
-            // if we don't have an EE_Message_Template_Group then return
981
-            if (! $msg_template_group instanceof EE_Message_Template_Group) {
982
-                return '';
983
-            }
984
-            // generate the URL
985
-            $registration_message_trigger_url = EEH_MSG_Template::generate_url_trigger(
986
-                $sending_messenger,
987
-                $generating_messenger,
988
-                'purchaser',
989
-                $message_type,
990
-                $registration,
991
-                $msg_template_group->ID(),
992
-                $registration->transaction_ID()
993
-            );
994
-        }
995
-        return $registration_message_trigger_url;
996
-    }
997
-
998
-
999
-    /**
1000
-     * Use to generate and return a message preview!
1001
-     *
1002
-     * @param  string $type      This should correspond with a valid message type
1003
-     * @param  string $context   This should correspond with a valid context for the message type
1004
-     * @param  string $messenger This should correspond with a valid messenger.
1005
-     * @param bool    $send      true we will do a test send using the messenger delivery, false we just do a regular
1006
-     *                           preview
1007
-     * @return bool|string The body of the message or if send is requested, sends.
1008
-     * @throws EE_Error
1009
-     * @throws InvalidArgumentException
1010
-     * @throws InvalidDataTypeException
1011
-     * @throws InvalidInterfaceException
1012
-     * @throws ReflectionException
1013
-     */
1014
-    public static function preview_message($type, $context, $messenger, $send = false)
1015
-    {
1016
-        self::_load_controller();
1017
-        $mtg = new EE_Message_To_Generate(
1018
-            $messenger,
1019
-            $type,
1020
-            array(),
1021
-            $context,
1022
-            true
1023
-        );
1024
-        $generated_preview_queue = self::$_MSG_PROCESSOR->generate_for_preview($mtg, $send);
1025
-        if ($generated_preview_queue instanceof EE_Messages_Queue) {
1026
-            // loop through all content for the preview and remove any persisted records.
1027
-            $content = '';
1028
-            foreach ($generated_preview_queue->get_message_repository() as $message) {
1029
-                $content = $message->content();
1030
-                if ($message->ID() > 0 && $message->STS_ID() !== EEM_Message::status_failed) {
1031
-                    $message->delete();
1032
-                }
1033
-            }
1034
-            return $content;
1035
-        } else {
1036
-            return $generated_preview_queue;
1037
-        }
1038
-    }
1039
-
1040
-
1041
-    /**
1042
-     * This is a method that allows for sending a message using a messenger matching the string given and the provided
1043
-     * EE_Message_Queue object.  The EE_Message_Queue object is used to create a single aggregate EE_Message via the
1044
-     * content found in the EE_Message objects in the queue.
1045
-     *
1046
-     * @since 4.9.0
1047
-     * @param string            $messenger            a string matching a valid active messenger in the system
1048
-     * @param string            $message_type         Although it seems contrary to the name of the method, a message
1049
-     *                                                type name is still required to send along the message type to the
1050
-     *                                                messenger because this is used for determining what specific
1051
-     *                                                variations might be loaded for the generated message.
1052
-     * @param EE_Messages_Queue $queue
1053
-     * @param string            $custom_subject       Can be used to set what the custom subject string will be on the
1054
-     *                                                aggregate EE_Message object.
1055
-     * @return bool success or fail.
1056
-     * @throws EE_Error
1057
-     * @throws InvalidArgumentException
1058
-     * @throws ReflectionException
1059
-     * @throws InvalidDataTypeException
1060
-     * @throws InvalidInterfaceException
1061
-     */
1062
-    public static function send_message_with_messenger_only(
1063
-        $messenger,
1064
-        $message_type,
1065
-        EE_Messages_Queue $queue,
1066
-        $custom_subject = ''
1067
-    ) {
1068
-        self::_load_controller();
1069
-        /** @type EE_Message_To_Generate_From_Queue $message_to_generate */
1070
-        $message_to_generate = EE_Registry::instance()->load_lib(
1071
-            'Message_To_Generate_From_Queue',
1072
-            array(
1073
-                $messenger,
1074
-                $message_type,
1075
-                $queue,
1076
-                $custom_subject,
1077
-            )
1078
-        );
1079
-        return self::$_MSG_PROCESSOR->queue_for_sending($message_to_generate);
1080
-    }
1081
-
1082
-
1083
-    /**
1084
-     * Generates Messages immediately for EE_Message IDs (but only for the correct status for generation)
1085
-     *
1086
-     * @since 4.9.0
1087
-     * @param array $message_ids An array of message ids
1088
-     * @return bool|EE_Messages_Queue false if nothing was generated, EE_Messages_Queue containing generated
1089
-     *                           messages.
1090
-     * @throws EE_Error
1091
-     * @throws InvalidArgumentException
1092
-     * @throws InvalidDataTypeException
1093
-     * @throws InvalidInterfaceException
1094
-     * @throws ReflectionException
1095
-     */
1096
-    public static function generate_now($message_ids)
1097
-    {
1098
-        self::_load_controller();
1099
-        $messages = EEM_Message::instance()->get_all(
1100
-            array(
1101
-                0 => array(
1102
-                    'MSG_ID' => array('IN', $message_ids),
1103
-                    'STS_ID' => EEM_Message::status_incomplete,
1104
-                ),
1105
-            )
1106
-        );
1107
-        $generated_queue = false;
1108
-        if ($messages) {
1109
-            $generated_queue = self::$_MSG_PROCESSOR->batch_generate_from_queue($messages);
1110
-        }
1111
-
1112
-        if (! $generated_queue instanceof EE_Messages_Queue) {
1113
-            EE_Error::add_error(
1114
-                esc_html__(
1115
-                    'The messages were not generated. This could mean there is already a batch being generated on a separate request, or because the selected messages are not ready for generation. Please wait a minute or two and try again.',
1116
-                    'event_espresso'
1117
-                ),
1118
-                __FILE__,
1119
-                __FUNCTION__,
1120
-                __LINE__
1121
-            );
1122
-        }
1123
-        return $generated_queue;
1124
-    }
1125
-
1126
-
1127
-    /**
1128
-     * Sends messages immediately for the incoming message_ids that have the status of EEM_Message::status_resend or,
1129
-     * EEM_Message::status_idle
1130
-     *
1131
-     * @since 4.9.0
1132
-     * @param $message_ids
1133
-     * @return bool|EE_Messages_Queue false if no messages sent.
1134
-     * @throws EE_Error
1135
-     * @throws InvalidArgumentException
1136
-     * @throws InvalidDataTypeException
1137
-     * @throws InvalidInterfaceException
1138
-     * @throws ReflectionException
1139
-     */
1140
-    public static function send_now($message_ids)
1141
-    {
1142
-        self::_load_controller();
1143
-        $messages = EEM_Message::instance()->get_all(
1144
-            array(
1145
-                0 => array(
1146
-                    'MSG_ID' => array('IN', $message_ids),
1147
-                    'STS_ID' => array(
1148
-                        'IN',
1149
-                        array(EEM_Message::status_idle, EEM_Message::status_resend, EEM_Message::status_retry),
1150
-                    ),
1151
-                ),
1152
-            )
1153
-        );
1154
-        $sent_queue = false;
1155
-        if ($messages) {
1156
-            $sent_queue = self::$_MSG_PROCESSOR->batch_send_from_queue($messages);
1157
-        }
1158
-
1159
-        if (! $sent_queue instanceof EE_Messages_Queue) {
1160
-            EE_Error::add_error(
1161
-                esc_html__(
1162
-                    'The messages were not sent. This could mean there is already a batch being sent on a separate request, or because the selected messages are not sendable. Please wait a minute or two and try again.',
1163
-                    'event_espresso'
1164
-                ),
1165
-                __FILE__,
1166
-                __FUNCTION__,
1167
-                __LINE__
1168
-            );
1169
-        } else {
1170
-            // can count how many sent by using the messages in the queue
1171
-            $sent_count = $sent_queue->count_STS_in_queue(EEM_Message::instance()->stati_indicating_sent());
1172
-            if ($sent_count > 0) {
1173
-                EE_Error::add_success(
1174
-                    sprintf(
1175
-                        _n(
1176
-                            'There was %d message successfully sent.',
1177
-                            'There were %d messages successfully sent.',
1178
-                            $sent_count,
1179
-                            'event_espresso'
1180
-                        ),
1181
-                        $sent_count
1182
-                    )
1183
-                );
1184
-            } else {
1185
-                EE_Error::overwrite_errors();
1186
-                EE_Error::add_error(
1187
-                    esc_html__(
1188
-                        'No message was sent because of problems with sending. Either all the messages you selected were not a sendable message, they were ALREADY sent on a different scheduled task, or there was an error.
261
+				exit;
262
+			}
263
+		}
264
+	}
265
+
266
+
267
+	/**
268
+	 *  This runs when the msg_url_trigger route has initiated.
269
+	 *
270
+	 * @since 4.5.0
271
+	 * @param WP $WP
272
+	 * @throws EE_Error
273
+	 * @throws InvalidArgumentException
274
+	 * @throws ReflectionException
275
+	 * @throws InvalidDataTypeException
276
+	 * @throws InvalidInterfaceException
277
+	 */
278
+	public function run($WP)
279
+	{
280
+		// ensure controller is loaded
281
+		self::_load_controller();
282
+		// attempt to process message
283
+		try {
284
+			/** @type EE_Message_To_Generate_From_Request $message_to_generate */
285
+			$message_to_generate = EE_Registry::instance()->load_lib('Message_To_Generate_From_Request');
286
+			self::$_MSG_PROCESSOR->generate_and_send_now($message_to_generate);
287
+		} catch (EE_Error $e) {
288
+			$error_msg = esc_html__(
289
+				'Please note that a system message failed to send due to a technical issue.',
290
+				'event_espresso'
291
+			);
292
+			// add specific message for developers if WP_DEBUG in on
293
+			$error_msg .= '||' . $e->getMessage();
294
+			EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__);
295
+		}
296
+	}
297
+
298
+
299
+	/**
300
+	 * This is triggered by the 'msg_cron_trigger' route.
301
+	 *
302
+	 * @param WP $WP
303
+	 */
304
+	public function execute_batch_request($WP)
305
+	{
306
+		$this->run_cron();
307
+		header('HTTP/1.1 200 OK');
308
+		exit();
309
+	}
310
+
311
+
312
+	/**
313
+	 * This gets executed on wp_cron jobs or when a batch request is initiated on its own separate non regular wp
314
+	 * request.
315
+	 */
316
+	public function run_cron()
317
+	{
318
+		self::_load_controller();
319
+		$request = self::getRequest();
320
+		// get required vars
321
+		$cron_type = $request->getRequestParam('type');
322
+		$transient_key = $request->getRequestParam('key');
323
+
324
+		// now let's verify transient, if not valid exit immediately
325
+		if (! get_transient($transient_key)) {
326
+			/**
327
+			 * trigger error so this gets in the error logs.  This is important because it happens on a non-user
328
+			 * request.
329
+			 */
330
+			trigger_error(esc_attr__('Invalid Request (Transient does not exist)', 'event_espresso'));
331
+		}
332
+
333
+		// if made it here, lets' delete the transient to keep the db clean
334
+		delete_transient($transient_key);
335
+
336
+		if (apply_filters('FHEE__EED_Messages__run_cron__use_wp_cron', true)) {
337
+			$method = 'batch_' . $cron_type . '_from_queue';
338
+			if (method_exists(self::$_MSG_PROCESSOR, $method)) {
339
+				self::$_MSG_PROCESSOR->$method();
340
+			} else {
341
+				// no matching task
342
+				/**
343
+				 * trigger error so this gets in the error logs.  This is important because it happens on a non user
344
+				 * request.
345
+				 */
346
+				trigger_error(
347
+					esc_attr(
348
+						sprintf(
349
+							esc_html__('There is no task corresponding to this route %s', 'event_espresso'),
350
+							$cron_type
351
+						)
352
+					)
353
+				);
354
+			}
355
+		}
356
+
357
+		do_action('FHEE__EED_Messages__run_cron__end');
358
+	}
359
+
360
+
361
+	/**
362
+	 * This is used to retrieve the template pack for the given name.
363
+	 * Retrieved packs are cached on the static $_TMP_PACKS array.  If there is no class matching the given name then
364
+	 * the default template pack is returned.
365
+	 *
366
+	 * @deprecated 4.9.0  @see EEH_MSG_Template::get_template_pack()
367
+	 * @param string $template_pack_name This should correspond to the dbref of the template pack (which is also used
368
+	 *                                   in generating the Pack class name).
369
+	 * @return EE_Messages_Template_Pack
370
+	 * @throws EE_Error
371
+	 * @throws InvalidArgumentException
372
+	 * @throws ReflectionException
373
+	 * @throws InvalidDataTypeException
374
+	 * @throws InvalidInterfaceException
375
+	 */
376
+	public static function get_template_pack($template_pack_name)
377
+	{
378
+		EE_Registry::instance()->load_helper('MSG_Template');
379
+		return EEH_MSG_Template::get_template_pack($template_pack_name);
380
+	}
381
+
382
+
383
+	/**
384
+	 * Retrieves an array of all template packs.
385
+	 * Array is in the format array( 'dbref' => EE_Messages_Template_Pack )
386
+	 *
387
+	 * @deprecated 4.9.0  @see EEH_MSG_Template_Pack::get_template_pack_collection
388
+	 * @return EE_Messages_Template_Pack[]
389
+	 * @throws EE_Error
390
+	 * @throws InvalidArgumentException
391
+	 * @throws ReflectionException
392
+	 * @throws InvalidDataTypeException
393
+	 * @throws InvalidInterfaceException
394
+	 */
395
+	public static function get_template_packs()
396
+	{
397
+		EE_Registry::instance()->load_helper('MSG_Template');
398
+
399
+		// for backward compat, let's make sure this returns in the same format as originally.
400
+		$template_pack_collection = EEH_MSG_Template::get_template_pack_collection();
401
+		$template_pack_collection->rewind();
402
+		$template_packs = array();
403
+		while ($template_pack_collection->valid()) {
404
+			$template_packs[ $template_pack_collection->current()->dbref ] = $template_pack_collection->current();
405
+			$template_pack_collection->next();
406
+		}
407
+		return $template_packs;
408
+	}
409
+
410
+
411
+	/**
412
+	 * This simply makes sure the autoloaders are registered for the EE_messages system.
413
+	 *
414
+	 * @since 4.5.0
415
+	 * @return void
416
+	 * @throws EE_Error
417
+	 */
418
+	public static function set_autoloaders()
419
+	{
420
+		if (empty(self::$_MSG_PATHS)) {
421
+			self::_set_messages_paths();
422
+			foreach (self::$_MSG_PATHS as $path) {
423
+				EEH_Autoloader::register_autoloaders_for_each_file_in_folder($path);
424
+			}
425
+			// add aliases
426
+			EEH_Autoloader::add_alias('EE_messages', 'EE_messages');
427
+			EEH_Autoloader::add_alias('EE_messenger', 'EE_messenger');
428
+		}
429
+	}
430
+
431
+
432
+	/**
433
+	 * Take care of adding all the paths for the messages components to the $_MSG_PATHS property
434
+	 * for use by the Messages Autoloaders
435
+	 *
436
+	 * @since 4.5.0
437
+	 * @return void.
438
+	 */
439
+	protected static function _set_messages_paths()
440
+	{
441
+		self::$_MSG_PATHS = apply_filters(
442
+			'FHEE__EED_Messages___set_messages_paths___MSG_PATHS',
443
+			[
444
+				EE_LIBRARIES . 'messages/message_type',
445
+				EE_LIBRARIES . 'messages/messenger',
446
+				EE_LIBRARIES . 'messages/defaults',
447
+				EE_LIBRARIES . 'messages/defaults/email',
448
+				EE_LIBRARIES . 'messages/data_class',
449
+				EE_LIBRARIES . 'messages/validators',
450
+				EE_LIBRARIES . 'messages/validators/email',
451
+				EE_LIBRARIES . 'messages/validators/html',
452
+				EE_LIBRARIES . 'shortcodes',
453
+			]
454
+		);
455
+	}
456
+
457
+
458
+	/**
459
+	 * Takes care of loading dependencies
460
+	 *
461
+	 * @since 4.5.0
462
+	 * @return void
463
+	 * @throws EE_Error
464
+	 * @throws InvalidArgumentException
465
+	 * @throws ReflectionException
466
+	 * @throws InvalidDataTypeException
467
+	 * @throws InvalidInterfaceException
468
+	 */
469
+	protected static function _load_controller()
470
+	{
471
+		if (! self::$_MSG_PROCESSOR instanceof EE_Messages_Processor) {
472
+			EE_Registry::instance()->load_core('Request_Handler');
473
+			self::set_autoloaders();
474
+			self::$_EEMSG = EE_Registry::instance()->load_lib('messages');
475
+			self::$_MSG_PROCESSOR = EE_Registry::instance()->load_lib('Messages_Processor');
476
+			self::$_message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
477
+		}
478
+	}
479
+
480
+
481
+	/**
482
+	 * @param EE_Transaction $transaction
483
+	 * @throws EE_Error
484
+	 * @throws InvalidArgumentException
485
+	 * @throws InvalidDataTypeException
486
+	 * @throws InvalidInterfaceException
487
+	 * @throws ReflectionException
488
+	 */
489
+	public static function payment_reminder(EE_Transaction $transaction)
490
+	{
491
+		self::_load_controller();
492
+		$data = array($transaction, null);
493
+		self::$_MSG_PROCESSOR->generate_for_all_active_messengers('payment_reminder', $data);
494
+	}
495
+
496
+
497
+	/**
498
+	 * Any messages triggers for after successful gateway payments should go in here.
499
+	 *
500
+	 * @param EE_Transaction  $transaction object
501
+	 * @param EE_Payment|null $payment     object
502
+	 * @return void
503
+	 * @throws EE_Error
504
+	 * @throws InvalidArgumentException
505
+	 * @throws ReflectionException
506
+	 * @throws InvalidDataTypeException
507
+	 * @throws InvalidInterfaceException
508
+	 */
509
+	public static function payment(EE_Transaction $transaction, EE_Payment $payment = null)
510
+	{
511
+		// if there's no payment object, then we cannot do a payment type message!
512
+		if (! $payment instanceof EE_Payment) {
513
+			return;
514
+		}
515
+		self::_load_controller();
516
+		$data = array($transaction, $payment);
517
+		EE_Registry::instance()->load_helper('MSG_Template');
518
+		$message_type = EEH_MSG_Template::convert_payment_status_to_message_type($payment->STS_ID());
519
+		// if payment amount is less than 0 then switch to payment_refund message type.
520
+		$message_type = $payment->amount() < 0 ? 'payment_refund' : $message_type;
521
+		self::$_MSG_PROCESSOR->generate_for_all_active_messengers($message_type, $data);
522
+	}
523
+
524
+
525
+	/**
526
+	 * @param EE_Transaction $transaction
527
+	 * @throws EE_Error
528
+	 * @throws InvalidArgumentException
529
+	 * @throws InvalidDataTypeException
530
+	 * @throws InvalidInterfaceException
531
+	 * @throws ReflectionException
532
+	 */
533
+	public static function cancelled_registration(EE_Transaction $transaction)
534
+	{
535
+		self::_load_controller();
536
+		$data = array($transaction, null);
537
+		self::$_MSG_PROCESSOR->generate_for_all_active_messengers('cancelled_registration', $data);
538
+	}
539
+
540
+
541
+	/**
542
+	 * Trigger for Registration messages
543
+	 * Note that what registration message type is sent depends on what the reg status is for the registrations on the
544
+	 * incoming transaction.
545
+	 *
546
+	 * @param EE_Registration $registration
547
+	 * @param array           $extra_details
548
+	 * @return void
549
+	 * @throws EE_Error
550
+	 * @throws InvalidArgumentException
551
+	 * @throws InvalidDataTypeException
552
+	 * @throws InvalidInterfaceException
553
+	 * @throws ReflectionException
554
+	 * @throws EntityNotFoundException
555
+	 */
556
+	public static function maybe_registration(EE_Registration $registration, $extra_details = array())
557
+	{
558
+
559
+		if (! self::_verify_registration_notification_send($registration, $extra_details)) {
560
+			// no messages please
561
+			return;
562
+		}
563
+
564
+		// get all non-trashed registrations so we make sure we send messages for the right status.
565
+		$all_registrations = $registration->transaction()->registrations(
566
+			array(
567
+				array('REG_deleted' => false),
568
+				'order_by' => array(
569
+					'Event.EVT_name'     => 'ASC',
570
+					'Attendee.ATT_lname' => 'ASC',
571
+					'Attendee.ATT_fname' => 'ASC',
572
+				),
573
+			)
574
+		);
575
+		// cached array of statuses so we only trigger messages once per status.
576
+		$statuses_sent = array();
577
+		self::_load_controller();
578
+		$mtgs = array();
579
+
580
+		// loop through registrations and trigger messages once per status.
581
+		foreach ($all_registrations as $reg) {
582
+			// already triggered?
583
+			if (in_array($reg->status_ID(), $statuses_sent)) {
584
+				continue;
585
+			}
586
+
587
+			$message_type = EEH_MSG_Template::convert_reg_status_to_message_type($reg->status_ID());
588
+			$mtgs = array_merge(
589
+				$mtgs,
590
+				self::$_MSG_PROCESSOR->setup_mtgs_for_all_active_messengers(
591
+					$message_type,
592
+					array($registration->transaction(), null, $reg->status_ID())
593
+				)
594
+			);
595
+			$statuses_sent[] = $reg->status_ID();
596
+		}
597
+
598
+		if (count($statuses_sent) > 1) {
599
+			$mtgs = array_merge(
600
+				$mtgs,
601
+				self::$_MSG_PROCESSOR->setup_mtgs_for_all_active_messengers(
602
+					'registration_summary',
603
+					array($registration->transaction(), null)
604
+				)
605
+			);
606
+		}
607
+
608
+		// batch queue and initiate request
609
+		self::$_MSG_PROCESSOR->batch_queue_for_generation_and_persist($mtgs);
610
+		self::$_MSG_PROCESSOR->get_queue()->initiate_request_by_priority();
611
+	}
612
+
613
+
614
+	/**
615
+	 * This is a helper method used to very whether a registration notification should be sent or
616
+	 * not.  Prevents duplicate notifications going out for registration context notifications.
617
+	 *
618
+	 * @param EE_Registration $registration  [description]
619
+	 * @param array           $extra_details [description]
620
+	 * @return bool          true = send away, false = nope halt the presses.
621
+	 */
622
+	protected static function _verify_registration_notification_send(
623
+		EE_Registration $registration,
624
+		$extra_details = array()
625
+	) {
626
+		$request = self::getRequest();
627
+		if (
628
+			! $request->getRequestParam('non_primary_reg_notification', 0, 'int')
629
+			&& ! $registration->is_primary_registrant()
630
+		) {
631
+			return false;
632
+		}
633
+		// first we check if we're in admin and not doing front ajax
634
+		if (
635
+			($request->isAdmin() || $request->isAdminAjax())
636
+			&& ! $request->isFrontAjax()
637
+		) {
638
+			$status_change = $request->getRequestParam('txn_reg_status_change', [], 'int', true);
639
+			// make sure appropriate admin params are set for sending messages
640
+			if (
641
+				! isset($status_change['send_notifications'])
642
+				|| (isset($status_change['send_notifications']) && ! $status_change['send_notifications'])
643
+			) {
644
+				// no messages sent please.
645
+				return false;
646
+			}
647
+		} else {
648
+			// frontend request (either regular or via AJAX)
649
+			// TXN is NOT finalized ?
650
+			if (! isset($extra_details['finalized']) || $extra_details['finalized'] === false) {
651
+				return false;
652
+			}
653
+			// return visit but nothing changed ???
654
+			if (
655
+				isset($extra_details['revisit'], $extra_details['status_updates']) &&
656
+				$extra_details['revisit'] && ! $extra_details['status_updates']
657
+			) {
658
+				return false;
659
+			}
660
+			// NOT sending messages && reg status is something other than "Not-Approved"
661
+			if (
662
+				! apply_filters('FHEE__EED_Messages___maybe_registration__deliver_notifications', false) &&
663
+				$registration->status_ID() !== EEM_Registration::status_id_not_approved
664
+			) {
665
+				return false;
666
+			}
667
+		}
668
+		// release the kraken
669
+		return true;
670
+	}
671
+
672
+
673
+	/**
674
+	 * Simply returns an array indexed by Registration Status ID and the related message_type name associated with that
675
+	 * status id.
676
+	 *
677
+	 * @deprecated 4.9.0  Use EEH_MSG_Template::reg_status_to_message_type_array()
678
+	 *                    or EEH_MSG_Template::convert_reg_status_to_message_type
679
+	 * @param string $reg_status
680
+	 * @return array
681
+	 * @throws EE_Error
682
+	 * @throws InvalidArgumentException
683
+	 * @throws ReflectionException
684
+	 * @throws InvalidDataTypeException
685
+	 * @throws InvalidInterfaceException
686
+	 */
687
+	protected static function _get_reg_status_array($reg_status = '')
688
+	{
689
+		EE_Registry::instance()->load_helper('MSG_Template');
690
+		return EEH_MSG_Template::convert_reg_status_to_message_type($reg_status)
691
+			? EEH_MSG_Template::convert_reg_status_to_message_type($reg_status)
692
+			: EEH_MSG_Template::reg_status_to_message_type_array();
693
+	}
694
+
695
+
696
+	/**
697
+	 * Simply returns the payment message type for the given payment status.
698
+	 *
699
+	 * @deprecated 4.9.0 Use EEH_MSG_Template::payment_status_to_message_type_array
700
+	 *                   or EEH_MSG_Template::convert_payment_status_to_message_type
701
+	 * @param string $payment_status The payment status being matched.
702
+	 * @return bool|string The payment message type slug matching the status or false if no match.
703
+	 * @throws EE_Error
704
+	 * @throws InvalidArgumentException
705
+	 * @throws ReflectionException
706
+	 * @throws InvalidDataTypeException
707
+	 * @throws InvalidInterfaceException
708
+	 */
709
+	protected static function _get_payment_message_type($payment_status)
710
+	{
711
+		EE_Registry::instance()->load_helper('MSG_Template');
712
+		return EEH_MSG_Template::convert_payment_status_to_message_type($payment_status)
713
+			? EEH_MSG_Template::convert_payment_status_to_message_type($payment_status)
714
+			: false;
715
+	}
716
+
717
+
718
+	/**
719
+	 * Message triggers for a resending already sent message(s) (via EE_Message list table)
720
+	 *
721
+	 * @access public
722
+	 * @param array $req_data This is the $_POST & $_GET data sent from EE_Admin Pages
723
+	 * @return bool success/fail
724
+	 * @throws EE_Error
725
+	 * @throws InvalidArgumentException
726
+	 * @throws InvalidDataTypeException
727
+	 * @throws InvalidInterfaceException
728
+	 * @throws ReflectionException
729
+	 */
730
+	public static function process_resend(array $req_data = [])
731
+	{
732
+		self::_load_controller();
733
+		$request = self::getRequest();
734
+		// if $msgID in this request then skip to the new resend_message
735
+		if ($request->getRequestParam('MSG_ID')) {
736
+			return self::resend_message();
737
+		}
738
+
739
+		// make sure any incoming request data is set on the request so that it gets picked up later.
740
+		foreach ((array) $req_data as $request_key => $request_value) {
741
+			if (! $request->requestParamIsSet($request_key)) {
742
+				$request->setRequestParam($request_key, $request_value);
743
+			}
744
+		}
745
+
746
+		if (
747
+			! $messages_to_send = self::$_MSG_PROCESSOR->setup_messages_to_generate_from_registration_ids_in_request()
748
+		) {
749
+			return false;
750
+		}
751
+
752
+		try {
753
+			self::$_MSG_PROCESSOR->batch_queue_for_generation_and_persist($messages_to_send);
754
+			self::$_MSG_PROCESSOR->get_queue()->initiate_request_by_priority();
755
+		} catch (EE_Error $e) {
756
+			EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
757
+			return false;
758
+		}
759
+		EE_Error::add_success(
760
+			esc_html__('Messages have been successfully queued for generation and sending.', 'event_espresso')
761
+		);
762
+		return true; // everything got queued.
763
+	}
764
+
765
+
766
+	/**
767
+	 * Message triggers for a resending already sent message(s) (via EE_Message list table)
768
+	 *
769
+	 * @return bool
770
+	 * @throws EE_Error
771
+	 * @throws InvalidArgumentException
772
+	 * @throws InvalidDataTypeException
773
+	 * @throws InvalidInterfaceException
774
+	 * @throws ReflectionException
775
+	 */
776
+	public static function resend_message()
777
+	{
778
+		self::_load_controller();
779
+
780
+		$msgID = self::getRequest()->getRequestParam('MSG_ID', 0, 'int');
781
+		if (! $msgID) {
782
+			EE_Error::add_error(
783
+				esc_html__(
784
+					'Something went wrong because there is no "MSG_ID" value in the request',
785
+					'event_espresso'
786
+				),
787
+				__FILE__,
788
+				__FUNCTION__,
789
+				__LINE__
790
+			);
791
+			return false;
792
+		}
793
+
794
+		self::$_MSG_PROCESSOR->setup_messages_from_ids_and_send((array) $msgID);
795
+
796
+		// setup success message.
797
+		$count_ready_for_resend = self::$_MSG_PROCESSOR->get_queue()->count_STS_in_queue(EEM_Message::status_resend);
798
+		EE_Error::add_success(
799
+			sprintf(
800
+				_n(
801
+					'There was %d message queued for resending.',
802
+					'There were %d messages queued for resending.',
803
+					$count_ready_for_resend,
804
+					'event_espresso'
805
+				),
806
+				$count_ready_for_resend
807
+			)
808
+		);
809
+		return true;
810
+	}
811
+
812
+
813
+	/**
814
+	 * Message triggers for manual payment applied by admin
815
+	 *
816
+	 * @param  EE_Payment $payment EE_payment object
817
+	 * @return bool success/fail
818
+	 * @throws EE_Error
819
+	 * @throws InvalidArgumentException
820
+	 * @throws ReflectionException
821
+	 * @throws InvalidDataTypeException
822
+	 * @throws InvalidInterfaceException
823
+	 */
824
+	public static function process_admin_payment(EE_Payment $payment)
825
+	{
826
+		EE_Registry::instance()->load_helper('MSG_Template');
827
+		// we need to get the transaction object
828
+		$transaction = $payment->transaction();
829
+		if ($transaction instanceof EE_Transaction) {
830
+			$data = array($transaction, $payment);
831
+			$message_type = EEH_MSG_Template::convert_payment_status_to_message_type($payment->STS_ID());
832
+
833
+			// if payment amount is less than 0 then switch to payment_refund message type.
834
+			$message_type = $payment->amount() < 0 ? 'payment_refund' : $message_type;
835
+
836
+			// if payment_refund is selected, but the status is NOT accepted.  Then change message type to false so NO message notification goes out.
837
+			$message_type = $message_type == 'payment_refund' && $payment->STS_ID() != EEM_Payment::status_id_approved
838
+				? false : $message_type;
839
+
840
+			self::_load_controller();
841
+
842
+			self::$_MSG_PROCESSOR->generate_for_all_active_messengers($message_type, $data);
843
+
844
+			// get count of queued for generation
845
+			$count_to_generate = self::$_MSG_PROCESSOR->get_queue()->count_STS_in_queue(
846
+				array(
847
+					EEM_Message::status_incomplete,
848
+					EEM_Message::status_idle,
849
+				)
850
+			);
851
+
852
+			if ($count_to_generate > 0 && self::$_MSG_PROCESSOR->get_queue()->get_message_repository()->count() !== 0) {
853
+				add_filter('FHEE__EE_Admin_Page___process_admin_payment_notification__success', '__return_true');
854
+				return true;
855
+			} else {
856
+				$count_failed = self::$_MSG_PROCESSOR->get_queue()->count_STS_in_queue(
857
+					EEM_Message::instance()->stati_indicating_failed_sending()
858
+				);
859
+				/**
860
+				 * Verify that there are actually errors.  If not then we return a success message because the queue might have been emptied due to successful
861
+				 * IMMEDIATE generation.
862
+				 */
863
+				if ($count_failed > 0) {
864
+					EE_Error::add_error(
865
+						sprintf(
866
+							_n(
867
+								'The payment notification generation failed.',
868
+								'%d payment notifications failed being sent.',
869
+								$count_failed,
870
+								'event_espresso'
871
+							),
872
+							$count_failed
873
+						),
874
+						__FILE__,
875
+						__FUNCTION__,
876
+						__LINE__
877
+					);
878
+
879
+					return false;
880
+				} else {
881
+					add_filter('FHEE__EE_Admin_Page___process_admin_payment_notification__success', '__return_true');
882
+					return true;
883
+				}
884
+			}
885
+		} else {
886
+			EE_Error::add_error(
887
+				'Unable to generate the payment notification because the given value for the transaction is invalid.',
888
+				'event_espresso'
889
+			);
890
+			return false;
891
+		}
892
+	}
893
+
894
+
895
+	/**
896
+	 * Callback for AHEE__Extend_Registrations_Admin_Page___newsletter_selected_send_with_registrations trigger
897
+	 *
898
+	 * @since   4.3.0
899
+	 * @param  EE_Registration[] $registrations an array of EE_Registration objects
900
+	 * @param  int               $grp_id        a specific message template group id.
901
+	 * @return void
902
+	 * @throws EE_Error
903
+	 * @throws InvalidArgumentException
904
+	 * @throws InvalidDataTypeException
905
+	 * @throws InvalidInterfaceException
906
+	 * @throws ReflectionException
907
+	 */
908
+	public static function send_newsletter_message($registrations, $grp_id)
909
+	{
910
+		// make sure mtp is id and set it in the request later messages setup.
911
+		self::getRequest()->setRequestParam('GRP_ID', (int) $grp_id);
912
+		self::_load_controller();
913
+		self::$_MSG_PROCESSOR->generate_for_all_active_messengers('newsletter', $registrations);
914
+	}
915
+
916
+
917
+	/**
918
+	 * Callback for FHEE__EE_Registration__invoice_url__invoice_url or FHEE__EE_Registration__receipt_url__receipt_url
919
+	 *
920
+	 * @since   4.3.0
921
+	 * @param    string          $registration_message_trigger_url
922
+	 * @param    EE_Registration $registration
923
+	 * @param string             $messenger
924
+	 * @param string             $message_type
925
+	 * @return string
926
+	 * @throws EE_Error
927
+	 * @throws InvalidArgumentException
928
+	 * @throws InvalidDataTypeException
929
+	 * @throws InvalidInterfaceException
930
+	 */
931
+	public static function registration_message_trigger_url(
932
+		$registration_message_trigger_url,
933
+		EE_Registration $registration,
934
+		$messenger = 'html',
935
+		$message_type = 'invoice'
936
+	) {
937
+		// whitelist $messenger
938
+		switch ($messenger) {
939
+			case 'pdf':
940
+				$sending_messenger = 'pdf';
941
+				$generating_messenger = 'html';
942
+				break;
943
+			case 'html':
944
+			default:
945
+				$sending_messenger = 'html';
946
+				$generating_messenger = 'html';
947
+				break;
948
+		}
949
+		// whitelist $message_type
950
+		switch ($message_type) {
951
+			case 'receipt':
952
+				$message_type = 'receipt';
953
+				break;
954
+			case 'invoice':
955
+			default:
956
+				$message_type = 'invoice';
957
+				break;
958
+		}
959
+		// verify that both the messenger AND the message type are active
960
+		if (
961
+			EEH_MSG_Template::is_messenger_active($sending_messenger)
962
+			&& EEH_MSG_Template::is_mt_active($message_type)
963
+		) {
964
+			// need to get the correct message template group for this (i.e. is there a custom invoice for the event this registration is registered for?)
965
+			$template_query_params = array(
966
+				'MTP_is_active'    => true,
967
+				'MTP_messenger'    => $generating_messenger,
968
+				'MTP_message_type' => $message_type,
969
+				'Event.EVT_ID'     => $registration->event_ID(),
970
+			);
971
+			// get the message template group.
972
+			$msg_template_group = EEM_Message_Template_Group::instance()->get_one(array($template_query_params));
973
+			// if we don't have an EE_Message_Template_Group then return
974
+			if (! $msg_template_group instanceof EE_Message_Template_Group) {
975
+				// remove EVT_ID from query params so that global templates get picked up
976
+				unset($template_query_params['Event.EVT_ID']);
977
+				// get global template as the fallback
978
+				$msg_template_group = EEM_Message_Template_Group::instance()->get_one(array($template_query_params));
979
+			}
980
+			// if we don't have an EE_Message_Template_Group then return
981
+			if (! $msg_template_group instanceof EE_Message_Template_Group) {
982
+				return '';
983
+			}
984
+			// generate the URL
985
+			$registration_message_trigger_url = EEH_MSG_Template::generate_url_trigger(
986
+				$sending_messenger,
987
+				$generating_messenger,
988
+				'purchaser',
989
+				$message_type,
990
+				$registration,
991
+				$msg_template_group->ID(),
992
+				$registration->transaction_ID()
993
+			);
994
+		}
995
+		return $registration_message_trigger_url;
996
+	}
997
+
998
+
999
+	/**
1000
+	 * Use to generate and return a message preview!
1001
+	 *
1002
+	 * @param  string $type      This should correspond with a valid message type
1003
+	 * @param  string $context   This should correspond with a valid context for the message type
1004
+	 * @param  string $messenger This should correspond with a valid messenger.
1005
+	 * @param bool    $send      true we will do a test send using the messenger delivery, false we just do a regular
1006
+	 *                           preview
1007
+	 * @return bool|string The body of the message or if send is requested, sends.
1008
+	 * @throws EE_Error
1009
+	 * @throws InvalidArgumentException
1010
+	 * @throws InvalidDataTypeException
1011
+	 * @throws InvalidInterfaceException
1012
+	 * @throws ReflectionException
1013
+	 */
1014
+	public static function preview_message($type, $context, $messenger, $send = false)
1015
+	{
1016
+		self::_load_controller();
1017
+		$mtg = new EE_Message_To_Generate(
1018
+			$messenger,
1019
+			$type,
1020
+			array(),
1021
+			$context,
1022
+			true
1023
+		);
1024
+		$generated_preview_queue = self::$_MSG_PROCESSOR->generate_for_preview($mtg, $send);
1025
+		if ($generated_preview_queue instanceof EE_Messages_Queue) {
1026
+			// loop through all content for the preview and remove any persisted records.
1027
+			$content = '';
1028
+			foreach ($generated_preview_queue->get_message_repository() as $message) {
1029
+				$content = $message->content();
1030
+				if ($message->ID() > 0 && $message->STS_ID() !== EEM_Message::status_failed) {
1031
+					$message->delete();
1032
+				}
1033
+			}
1034
+			return $content;
1035
+		} else {
1036
+			return $generated_preview_queue;
1037
+		}
1038
+	}
1039
+
1040
+
1041
+	/**
1042
+	 * This is a method that allows for sending a message using a messenger matching the string given and the provided
1043
+	 * EE_Message_Queue object.  The EE_Message_Queue object is used to create a single aggregate EE_Message via the
1044
+	 * content found in the EE_Message objects in the queue.
1045
+	 *
1046
+	 * @since 4.9.0
1047
+	 * @param string            $messenger            a string matching a valid active messenger in the system
1048
+	 * @param string            $message_type         Although it seems contrary to the name of the method, a message
1049
+	 *                                                type name is still required to send along the message type to the
1050
+	 *                                                messenger because this is used for determining what specific
1051
+	 *                                                variations might be loaded for the generated message.
1052
+	 * @param EE_Messages_Queue $queue
1053
+	 * @param string            $custom_subject       Can be used to set what the custom subject string will be on the
1054
+	 *                                                aggregate EE_Message object.
1055
+	 * @return bool success or fail.
1056
+	 * @throws EE_Error
1057
+	 * @throws InvalidArgumentException
1058
+	 * @throws ReflectionException
1059
+	 * @throws InvalidDataTypeException
1060
+	 * @throws InvalidInterfaceException
1061
+	 */
1062
+	public static function send_message_with_messenger_only(
1063
+		$messenger,
1064
+		$message_type,
1065
+		EE_Messages_Queue $queue,
1066
+		$custom_subject = ''
1067
+	) {
1068
+		self::_load_controller();
1069
+		/** @type EE_Message_To_Generate_From_Queue $message_to_generate */
1070
+		$message_to_generate = EE_Registry::instance()->load_lib(
1071
+			'Message_To_Generate_From_Queue',
1072
+			array(
1073
+				$messenger,
1074
+				$message_type,
1075
+				$queue,
1076
+				$custom_subject,
1077
+			)
1078
+		);
1079
+		return self::$_MSG_PROCESSOR->queue_for_sending($message_to_generate);
1080
+	}
1081
+
1082
+
1083
+	/**
1084
+	 * Generates Messages immediately for EE_Message IDs (but only for the correct status for generation)
1085
+	 *
1086
+	 * @since 4.9.0
1087
+	 * @param array $message_ids An array of message ids
1088
+	 * @return bool|EE_Messages_Queue false if nothing was generated, EE_Messages_Queue containing generated
1089
+	 *                           messages.
1090
+	 * @throws EE_Error
1091
+	 * @throws InvalidArgumentException
1092
+	 * @throws InvalidDataTypeException
1093
+	 * @throws InvalidInterfaceException
1094
+	 * @throws ReflectionException
1095
+	 */
1096
+	public static function generate_now($message_ids)
1097
+	{
1098
+		self::_load_controller();
1099
+		$messages = EEM_Message::instance()->get_all(
1100
+			array(
1101
+				0 => array(
1102
+					'MSG_ID' => array('IN', $message_ids),
1103
+					'STS_ID' => EEM_Message::status_incomplete,
1104
+				),
1105
+			)
1106
+		);
1107
+		$generated_queue = false;
1108
+		if ($messages) {
1109
+			$generated_queue = self::$_MSG_PROCESSOR->batch_generate_from_queue($messages);
1110
+		}
1111
+
1112
+		if (! $generated_queue instanceof EE_Messages_Queue) {
1113
+			EE_Error::add_error(
1114
+				esc_html__(
1115
+					'The messages were not generated. This could mean there is already a batch being generated on a separate request, or because the selected messages are not ready for generation. Please wait a minute or two and try again.',
1116
+					'event_espresso'
1117
+				),
1118
+				__FILE__,
1119
+				__FUNCTION__,
1120
+				__LINE__
1121
+			);
1122
+		}
1123
+		return $generated_queue;
1124
+	}
1125
+
1126
+
1127
+	/**
1128
+	 * Sends messages immediately for the incoming message_ids that have the status of EEM_Message::status_resend or,
1129
+	 * EEM_Message::status_idle
1130
+	 *
1131
+	 * @since 4.9.0
1132
+	 * @param $message_ids
1133
+	 * @return bool|EE_Messages_Queue false if no messages sent.
1134
+	 * @throws EE_Error
1135
+	 * @throws InvalidArgumentException
1136
+	 * @throws InvalidDataTypeException
1137
+	 * @throws InvalidInterfaceException
1138
+	 * @throws ReflectionException
1139
+	 */
1140
+	public static function send_now($message_ids)
1141
+	{
1142
+		self::_load_controller();
1143
+		$messages = EEM_Message::instance()->get_all(
1144
+			array(
1145
+				0 => array(
1146
+					'MSG_ID' => array('IN', $message_ids),
1147
+					'STS_ID' => array(
1148
+						'IN',
1149
+						array(EEM_Message::status_idle, EEM_Message::status_resend, EEM_Message::status_retry),
1150
+					),
1151
+				),
1152
+			)
1153
+		);
1154
+		$sent_queue = false;
1155
+		if ($messages) {
1156
+			$sent_queue = self::$_MSG_PROCESSOR->batch_send_from_queue($messages);
1157
+		}
1158
+
1159
+		if (! $sent_queue instanceof EE_Messages_Queue) {
1160
+			EE_Error::add_error(
1161
+				esc_html__(
1162
+					'The messages were not sent. This could mean there is already a batch being sent on a separate request, or because the selected messages are not sendable. Please wait a minute or two and try again.',
1163
+					'event_espresso'
1164
+				),
1165
+				__FILE__,
1166
+				__FUNCTION__,
1167
+				__LINE__
1168
+			);
1169
+		} else {
1170
+			// can count how many sent by using the messages in the queue
1171
+			$sent_count = $sent_queue->count_STS_in_queue(EEM_Message::instance()->stati_indicating_sent());
1172
+			if ($sent_count > 0) {
1173
+				EE_Error::add_success(
1174
+					sprintf(
1175
+						_n(
1176
+							'There was %d message successfully sent.',
1177
+							'There were %d messages successfully sent.',
1178
+							$sent_count,
1179
+							'event_espresso'
1180
+						),
1181
+						$sent_count
1182
+					)
1183
+				);
1184
+			} else {
1185
+				EE_Error::overwrite_errors();
1186
+				EE_Error::add_error(
1187
+					esc_html__(
1188
+						'No message was sent because of problems with sending. Either all the messages you selected were not a sendable message, they were ALREADY sent on a different scheduled task, or there was an error.
1189 1189
 					If there was an error, you can look at the messages in the message activity list table for any error messages.',
1190
-                        'event_espresso'
1191
-                    ),
1192
-                    __FILE__,
1193
-                    __FUNCTION__,
1194
-                    __LINE__
1195
-                );
1196
-            }
1197
-        }
1198
-        return $sent_queue;
1199
-    }
1200
-
1201
-
1202
-    /**
1203
-     * Generate and send immediately from the given $message_ids
1204
-     *
1205
-     * @param array $message_ids EE_Message entity ids.
1206
-     * @throws EE_Error
1207
-     * @throws InvalidArgumentException
1208
-     * @throws InvalidDataTypeException
1209
-     * @throws InvalidInterfaceException
1210
-     * @throws ReflectionException
1211
-     */
1212
-    public static function generate_and_send_now(array $message_ids)
1213
-    {
1214
-        $generated_queue = self::generate_now($message_ids);
1215
-        // now let's just trigger sending immediately from this queue.
1216
-        $messages_sent = $generated_queue instanceof EE_Messages_Queue
1217
-            ? $generated_queue->execute()
1218
-            : 0;
1219
-        if ($messages_sent) {
1220
-            EE_Error::add_success(
1221
-                esc_html(
1222
-                    sprintf(
1223
-                        _n(
1224
-                            'There was %d message successfully generated and sent.',
1225
-                            'There were %d messages successfully generated and sent.',
1226
-                            $messages_sent,
1227
-                            'event_espresso'
1228
-                        ),
1229
-                        $messages_sent
1230
-                    )
1231
-                )
1232
-            );
1233
-            // errors would be added via the generate_now method.
1234
-        }
1235
-    }
1236
-
1237
-
1238
-    /**
1239
-     * This will queue the incoming message ids for resending.
1240
-     * Note, only message_ids corresponding to messages with the status of EEM_Message::sent will be queued.
1241
-     *
1242
-     * @since 4.9.0
1243
-     * @param array $message_ids An array of EE_Message IDs
1244
-     * @return bool true means messages were successfully queued for resending, false means none were queued for
1245
-     *                           resending.
1246
-     * @throws EE_Error
1247
-     * @throws InvalidArgumentException
1248
-     * @throws InvalidDataTypeException
1249
-     * @throws InvalidInterfaceException
1250
-     * @throws ReflectionException
1251
-     */
1252
-    public static function queue_for_resending($message_ids)
1253
-    {
1254
-        self::_load_controller();
1255
-        self::$_MSG_PROCESSOR->setup_messages_from_ids_and_send($message_ids);
1256
-
1257
-        // get queue and count
1258
-        $queue_count = self::$_MSG_PROCESSOR->get_queue()->count_STS_in_queue(EEM_Message::status_resend);
1259
-
1260
-        if (
1261
-            $queue_count > 0
1262
-        ) {
1263
-            EE_Error::add_success(
1264
-                sprintf(
1265
-                    _n(
1266
-                        '%d message successfully queued for resending.',
1267
-                        '%d messages successfully queued for resending.',
1268
-                        $queue_count,
1269
-                        'event_espresso'
1270
-                    ),
1271
-                    $queue_count
1272
-                )
1273
-            );
1274
-            /**
1275
-             * @see filter usage in EE_Messages_Queue::initiate_request_by_priority
1276
-             */
1277
-        } elseif (
1278
-            apply_filters('FHEE__EE_Messages_Processor__initiate_request_by_priority__do_immediate_processing', true)
1279
-            || EE_Registry::instance()->NET_CFG->core->do_messages_on_same_request
1280
-        ) {
1281
-            $queue_count = self::$_MSG_PROCESSOR->get_queue()->count_STS_in_queue(EEM_Message::status_sent);
1282
-            if ($queue_count > 0) {
1283
-                EE_Error::add_success(
1284
-                    sprintf(
1285
-                        _n(
1286
-                            '%d message successfully sent.',
1287
-                            '%d messages successfully sent.',
1288
-                            $queue_count,
1289
-                            'event_espresso'
1290
-                        ),
1291
-                        $queue_count
1292
-                    )
1293
-                );
1294
-            } else {
1295
-                EE_Error::add_error(
1296
-                    esc_html__(
1297
-                        'No messages were queued for resending. This usually only happens when all the messages flagged for resending are not a status that can be resent.',
1298
-                        'event_espresso'
1299
-                    ),
1300
-                    __FILE__,
1301
-                    __FUNCTION__,
1302
-                    __LINE__
1303
-                );
1304
-            }
1305
-        } else {
1306
-            EE_Error::add_error(
1307
-                esc_html__(
1308
-                    'No messages were queued for resending. This usually only happens when all the messages flagged for resending are not a status that can be resent.',
1309
-                    'event_espresso'
1310
-                ),
1311
-                __FILE__,
1312
-                __FUNCTION__,
1313
-                __LINE__
1314
-            );
1315
-        }
1316
-        return (bool) $queue_count;
1317
-    }
1318
-
1319
-
1320
-    /**
1321
-     * debug
1322
-     *
1323
-     * @param string          $class
1324
-     * @param string          $func
1325
-     * @param string          $line
1326
-     * @param \EE_Transaction $transaction
1327
-     * @param array           $info
1328
-     * @param bool            $display_request
1329
-     * @throws EE_Error
1330
-     * @throws \EventEspresso\core\exceptions\InvalidSessionDataException
1331
-     */
1332
-    protected static function log(
1333
-        $class = '',
1334
-        $func = '',
1335
-        $line = '',
1336
-        EE_Transaction $transaction,
1337
-        $info = array(),
1338
-        $display_request = false
1339
-    ) {
1340
-        if (defined('EE_DEBUG') && EE_DEBUG) {
1341
-            if ($transaction instanceof EE_Transaction) {
1342
-                // don't serialize objects
1343
-                $info = EEH_Debug_Tools::strip_objects($info);
1344
-                $info['TXN_status'] = $transaction->status_ID();
1345
-                $info['TXN_reg_steps'] = $transaction->reg_steps();
1346
-                if ($transaction->ID()) {
1347
-                    $index = 'EE_Transaction: ' . $transaction->ID();
1348
-                    EEH_Debug_Tools::log($class, $func, $line, $info, $display_request, $index);
1349
-                }
1350
-            }
1351
-        }
1352
-    }
1353
-
1354
-
1355
-    /**
1356
-     *  Resets all the static properties in this class when called.
1357
-     */
1358
-    public static function reset()
1359
-    {
1360
-        self::$_EEMSG = null;
1361
-        self::$_message_resource_manager = null;
1362
-        self::$_MSG_PROCESSOR = null;
1363
-        self::$_MSG_PATHS = null;
1364
-        self::$_TMP_PACKS = array();
1365
-    }
1190
+						'event_espresso'
1191
+					),
1192
+					__FILE__,
1193
+					__FUNCTION__,
1194
+					__LINE__
1195
+				);
1196
+			}
1197
+		}
1198
+		return $sent_queue;
1199
+	}
1200
+
1201
+
1202
+	/**
1203
+	 * Generate and send immediately from the given $message_ids
1204
+	 *
1205
+	 * @param array $message_ids EE_Message entity ids.
1206
+	 * @throws EE_Error
1207
+	 * @throws InvalidArgumentException
1208
+	 * @throws InvalidDataTypeException
1209
+	 * @throws InvalidInterfaceException
1210
+	 * @throws ReflectionException
1211
+	 */
1212
+	public static function generate_and_send_now(array $message_ids)
1213
+	{
1214
+		$generated_queue = self::generate_now($message_ids);
1215
+		// now let's just trigger sending immediately from this queue.
1216
+		$messages_sent = $generated_queue instanceof EE_Messages_Queue
1217
+			? $generated_queue->execute()
1218
+			: 0;
1219
+		if ($messages_sent) {
1220
+			EE_Error::add_success(
1221
+				esc_html(
1222
+					sprintf(
1223
+						_n(
1224
+							'There was %d message successfully generated and sent.',
1225
+							'There were %d messages successfully generated and sent.',
1226
+							$messages_sent,
1227
+							'event_espresso'
1228
+						),
1229
+						$messages_sent
1230
+					)
1231
+				)
1232
+			);
1233
+			// errors would be added via the generate_now method.
1234
+		}
1235
+	}
1236
+
1237
+
1238
+	/**
1239
+	 * This will queue the incoming message ids for resending.
1240
+	 * Note, only message_ids corresponding to messages with the status of EEM_Message::sent will be queued.
1241
+	 *
1242
+	 * @since 4.9.0
1243
+	 * @param array $message_ids An array of EE_Message IDs
1244
+	 * @return bool true means messages were successfully queued for resending, false means none were queued for
1245
+	 *                           resending.
1246
+	 * @throws EE_Error
1247
+	 * @throws InvalidArgumentException
1248
+	 * @throws InvalidDataTypeException
1249
+	 * @throws InvalidInterfaceException
1250
+	 * @throws ReflectionException
1251
+	 */
1252
+	public static function queue_for_resending($message_ids)
1253
+	{
1254
+		self::_load_controller();
1255
+		self::$_MSG_PROCESSOR->setup_messages_from_ids_and_send($message_ids);
1256
+
1257
+		// get queue and count
1258
+		$queue_count = self::$_MSG_PROCESSOR->get_queue()->count_STS_in_queue(EEM_Message::status_resend);
1259
+
1260
+		if (
1261
+			$queue_count > 0
1262
+		) {
1263
+			EE_Error::add_success(
1264
+				sprintf(
1265
+					_n(
1266
+						'%d message successfully queued for resending.',
1267
+						'%d messages successfully queued for resending.',
1268
+						$queue_count,
1269
+						'event_espresso'
1270
+					),
1271
+					$queue_count
1272
+				)
1273
+			);
1274
+			/**
1275
+			 * @see filter usage in EE_Messages_Queue::initiate_request_by_priority
1276
+			 */
1277
+		} elseif (
1278
+			apply_filters('FHEE__EE_Messages_Processor__initiate_request_by_priority__do_immediate_processing', true)
1279
+			|| EE_Registry::instance()->NET_CFG->core->do_messages_on_same_request
1280
+		) {
1281
+			$queue_count = self::$_MSG_PROCESSOR->get_queue()->count_STS_in_queue(EEM_Message::status_sent);
1282
+			if ($queue_count > 0) {
1283
+				EE_Error::add_success(
1284
+					sprintf(
1285
+						_n(
1286
+							'%d message successfully sent.',
1287
+							'%d messages successfully sent.',
1288
+							$queue_count,
1289
+							'event_espresso'
1290
+						),
1291
+						$queue_count
1292
+					)
1293
+				);
1294
+			} else {
1295
+				EE_Error::add_error(
1296
+					esc_html__(
1297
+						'No messages were queued for resending. This usually only happens when all the messages flagged for resending are not a status that can be resent.',
1298
+						'event_espresso'
1299
+					),
1300
+					__FILE__,
1301
+					__FUNCTION__,
1302
+					__LINE__
1303
+				);
1304
+			}
1305
+		} else {
1306
+			EE_Error::add_error(
1307
+				esc_html__(
1308
+					'No messages were queued for resending. This usually only happens when all the messages flagged for resending are not a status that can be resent.',
1309
+					'event_espresso'
1310
+				),
1311
+				__FILE__,
1312
+				__FUNCTION__,
1313
+				__LINE__
1314
+			);
1315
+		}
1316
+		return (bool) $queue_count;
1317
+	}
1318
+
1319
+
1320
+	/**
1321
+	 * debug
1322
+	 *
1323
+	 * @param string          $class
1324
+	 * @param string          $func
1325
+	 * @param string          $line
1326
+	 * @param \EE_Transaction $transaction
1327
+	 * @param array           $info
1328
+	 * @param bool            $display_request
1329
+	 * @throws EE_Error
1330
+	 * @throws \EventEspresso\core\exceptions\InvalidSessionDataException
1331
+	 */
1332
+	protected static function log(
1333
+		$class = '',
1334
+		$func = '',
1335
+		$line = '',
1336
+		EE_Transaction $transaction,
1337
+		$info = array(),
1338
+		$display_request = false
1339
+	) {
1340
+		if (defined('EE_DEBUG') && EE_DEBUG) {
1341
+			if ($transaction instanceof EE_Transaction) {
1342
+				// don't serialize objects
1343
+				$info = EEH_Debug_Tools::strip_objects($info);
1344
+				$info['TXN_status'] = $transaction->status_ID();
1345
+				$info['TXN_reg_steps'] = $transaction->reg_steps();
1346
+				if ($transaction->ID()) {
1347
+					$index = 'EE_Transaction: ' . $transaction->ID();
1348
+					EEH_Debug_Tools::log($class, $func, $line, $info, $display_request, $index);
1349
+				}
1350
+			}
1351
+		}
1352
+	}
1353
+
1354
+
1355
+	/**
1356
+	 *  Resets all the static properties in this class when called.
1357
+	 */
1358
+	public static function reset()
1359
+	{
1360
+		self::$_EEMSG = null;
1361
+		self::$_message_resource_manager = null;
1362
+		self::$_MSG_PROCESSOR = null;
1363
+		self::$_MSG_PATHS = null;
1364
+		self::$_TMP_PACKS = array();
1365
+	}
1366 1366
 }
Please login to merge, or discard this patch.
Spacing   +25 added lines, -25 removed lines patch added patch discarded remove patch
@@ -204,7 +204,7 @@  discard block
 block discarded – undo
204 204
                 'event_espresso'
205 205
             );
206 206
             // add specific message for developers if WP_DEBUG in on
207
-            $error_msg .= '||' . $e->getMessage();
207
+            $error_msg .= '||'.$e->getMessage();
208 208
             EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__);
209 209
         }
210 210
     }
@@ -290,7 +290,7 @@  discard block
 block discarded – undo
290 290
                 'event_espresso'
291 291
             );
292 292
             // add specific message for developers if WP_DEBUG in on
293
-            $error_msg .= '||' . $e->getMessage();
293
+            $error_msg .= '||'.$e->getMessage();
294 294
             EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__);
295 295
         }
296 296
     }
@@ -322,7 +322,7 @@  discard block
 block discarded – undo
322 322
         $transient_key = $request->getRequestParam('key');
323 323
 
324 324
         // now let's verify transient, if not valid exit immediately
325
-        if (! get_transient($transient_key)) {
325
+        if ( ! get_transient($transient_key)) {
326 326
             /**
327 327
              * trigger error so this gets in the error logs.  This is important because it happens on a non-user
328 328
              * request.
@@ -334,7 +334,7 @@  discard block
 block discarded – undo
334 334
         delete_transient($transient_key);
335 335
 
336 336
         if (apply_filters('FHEE__EED_Messages__run_cron__use_wp_cron', true)) {
337
-            $method = 'batch_' . $cron_type . '_from_queue';
337
+            $method = 'batch_'.$cron_type.'_from_queue';
338 338
             if (method_exists(self::$_MSG_PROCESSOR, $method)) {
339 339
                 self::$_MSG_PROCESSOR->$method();
340 340
             } else {
@@ -401,7 +401,7 @@  discard block
 block discarded – undo
401 401
         $template_pack_collection->rewind();
402 402
         $template_packs = array();
403 403
         while ($template_pack_collection->valid()) {
404
-            $template_packs[ $template_pack_collection->current()->dbref ] = $template_pack_collection->current();
404
+            $template_packs[$template_pack_collection->current()->dbref] = $template_pack_collection->current();
405 405
             $template_pack_collection->next();
406 406
         }
407 407
         return $template_packs;
@@ -441,15 +441,15 @@  discard block
 block discarded – undo
441 441
         self::$_MSG_PATHS = apply_filters(
442 442
             'FHEE__EED_Messages___set_messages_paths___MSG_PATHS',
443 443
             [
444
-                EE_LIBRARIES . 'messages/message_type',
445
-                EE_LIBRARIES . 'messages/messenger',
446
-                EE_LIBRARIES . 'messages/defaults',
447
-                EE_LIBRARIES . 'messages/defaults/email',
448
-                EE_LIBRARIES . 'messages/data_class',
449
-                EE_LIBRARIES . 'messages/validators',
450
-                EE_LIBRARIES . 'messages/validators/email',
451
-                EE_LIBRARIES . 'messages/validators/html',
452
-                EE_LIBRARIES . 'shortcodes',
444
+                EE_LIBRARIES.'messages/message_type',
445
+                EE_LIBRARIES.'messages/messenger',
446
+                EE_LIBRARIES.'messages/defaults',
447
+                EE_LIBRARIES.'messages/defaults/email',
448
+                EE_LIBRARIES.'messages/data_class',
449
+                EE_LIBRARIES.'messages/validators',
450
+                EE_LIBRARIES.'messages/validators/email',
451
+                EE_LIBRARIES.'messages/validators/html',
452
+                EE_LIBRARIES.'shortcodes',
453 453
             ]
454 454
         );
455 455
     }
@@ -468,7 +468,7 @@  discard block
 block discarded – undo
468 468
      */
469 469
     protected static function _load_controller()
470 470
     {
471
-        if (! self::$_MSG_PROCESSOR instanceof EE_Messages_Processor) {
471
+        if ( ! self::$_MSG_PROCESSOR instanceof EE_Messages_Processor) {
472 472
             EE_Registry::instance()->load_core('Request_Handler');
473 473
             self::set_autoloaders();
474 474
             self::$_EEMSG = EE_Registry::instance()->load_lib('messages');
@@ -509,7 +509,7 @@  discard block
 block discarded – undo
509 509
     public static function payment(EE_Transaction $transaction, EE_Payment $payment = null)
510 510
     {
511 511
         // if there's no payment object, then we cannot do a payment type message!
512
-        if (! $payment instanceof EE_Payment) {
512
+        if ( ! $payment instanceof EE_Payment) {
513 513
             return;
514 514
         }
515 515
         self::_load_controller();
@@ -556,7 +556,7 @@  discard block
 block discarded – undo
556 556
     public static function maybe_registration(EE_Registration $registration, $extra_details = array())
557 557
     {
558 558
 
559
-        if (! self::_verify_registration_notification_send($registration, $extra_details)) {
559
+        if ( ! self::_verify_registration_notification_send($registration, $extra_details)) {
560 560
             // no messages please
561 561
             return;
562 562
         }
@@ -647,7 +647,7 @@  discard block
 block discarded – undo
647 647
         } else {
648 648
             // frontend request (either regular or via AJAX)
649 649
             // TXN is NOT finalized ?
650
-            if (! isset($extra_details['finalized']) || $extra_details['finalized'] === false) {
650
+            if ( ! isset($extra_details['finalized']) || $extra_details['finalized'] === false) {
651 651
                 return false;
652 652
             }
653 653
             // return visit but nothing changed ???
@@ -738,7 +738,7 @@  discard block
 block discarded – undo
738 738
 
739 739
         // make sure any incoming request data is set on the request so that it gets picked up later.
740 740
         foreach ((array) $req_data as $request_key => $request_value) {
741
-            if (! $request->requestParamIsSet($request_key)) {
741
+            if ( ! $request->requestParamIsSet($request_key)) {
742 742
                 $request->setRequestParam($request_key, $request_value);
743 743
             }
744 744
         }
@@ -778,7 +778,7 @@  discard block
 block discarded – undo
778 778
         self::_load_controller();
779 779
 
780 780
         $msgID = self::getRequest()->getRequestParam('MSG_ID', 0, 'int');
781
-        if (! $msgID) {
781
+        if ( ! $msgID) {
782 782
             EE_Error::add_error(
783 783
                 esc_html__(
784 784
                     'Something went wrong because there is no "MSG_ID" value in the request',
@@ -971,14 +971,14 @@  discard block
 block discarded – undo
971 971
             // get the message template group.
972 972
             $msg_template_group = EEM_Message_Template_Group::instance()->get_one(array($template_query_params));
973 973
             // if we don't have an EE_Message_Template_Group then return
974
-            if (! $msg_template_group instanceof EE_Message_Template_Group) {
974
+            if ( ! $msg_template_group instanceof EE_Message_Template_Group) {
975 975
                 // remove EVT_ID from query params so that global templates get picked up
976 976
                 unset($template_query_params['Event.EVT_ID']);
977 977
                 // get global template as the fallback
978 978
                 $msg_template_group = EEM_Message_Template_Group::instance()->get_one(array($template_query_params));
979 979
             }
980 980
             // if we don't have an EE_Message_Template_Group then return
981
-            if (! $msg_template_group instanceof EE_Message_Template_Group) {
981
+            if ( ! $msg_template_group instanceof EE_Message_Template_Group) {
982 982
                 return '';
983 983
             }
984 984
             // generate the URL
@@ -1109,7 +1109,7 @@  discard block
 block discarded – undo
1109 1109
             $generated_queue = self::$_MSG_PROCESSOR->batch_generate_from_queue($messages);
1110 1110
         }
1111 1111
 
1112
-        if (! $generated_queue instanceof EE_Messages_Queue) {
1112
+        if ( ! $generated_queue instanceof EE_Messages_Queue) {
1113 1113
             EE_Error::add_error(
1114 1114
                 esc_html__(
1115 1115
                     'The messages were not generated. This could mean there is already a batch being generated on a separate request, or because the selected messages are not ready for generation. Please wait a minute or two and try again.',
@@ -1156,7 +1156,7 @@  discard block
 block discarded – undo
1156 1156
             $sent_queue = self::$_MSG_PROCESSOR->batch_send_from_queue($messages);
1157 1157
         }
1158 1158
 
1159
-        if (! $sent_queue instanceof EE_Messages_Queue) {
1159
+        if ( ! $sent_queue instanceof EE_Messages_Queue) {
1160 1160
             EE_Error::add_error(
1161 1161
                 esc_html__(
1162 1162
                     'The messages were not sent. This could mean there is already a batch being sent on a separate request, or because the selected messages are not sendable. Please wait a minute or two and try again.',
@@ -1344,7 +1344,7 @@  discard block
 block discarded – undo
1344 1344
                 $info['TXN_status'] = $transaction->status_ID();
1345 1345
                 $info['TXN_reg_steps'] = $transaction->reg_steps();
1346 1346
                 if ($transaction->ID()) {
1347
-                    $index = 'EE_Transaction: ' . $transaction->ID();
1347
+                    $index = 'EE_Transaction: '.$transaction->ID();
1348 1348
                     EEH_Debug_Tools::log($class, $func, $line, $info, $display_request, $index);
1349 1349
                 }
1350 1350
             }
Please login to merge, or discard this patch.
caffeinated/admin/extend/events/Extend_Events_Admin_Page.core.php 3 patches
Indentation   +1083 added lines, -1083 removed lines patch added patch discarded remove patch
@@ -16,223 +16,223 @@  discard block
 block discarded – undo
16 16
 class Extend_Events_Admin_Page extends Events_Admin_Page
17 17
 {
18 18
 
19
-    /**
20
-     * @var EE_Admin_Config
21
-     */
22
-    protected $admin_config;
23
-
24
-    /**
25
-     * @var AdvancedEditorAdminFormSection
26
-     */
27
-    protected $advanced_editor_admin_form;
28
-
29
-
30
-    /**
31
-     * Extend_Events_Admin_Page constructor.
32
-     *
33
-     * @param bool $routing
34
-     * @throws EE_Error
35
-     * @throws ReflectionException
36
-     */
37
-    public function __construct($routing = true)
38
-    {
39
-        if (! defined('EVENTS_CAF_TEMPLATE_PATH')) {
40
-            define('EVENTS_CAF_TEMPLATE_PATH', EE_CORE_CAF_ADMIN_EXTEND . 'events/templates/');
41
-            define('EVENTS_CAF_ASSETS', EE_CORE_CAF_ADMIN_EXTEND . 'events/assets/');
42
-            define('EVENTS_CAF_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL . 'events/assets/');
43
-        }
44
-        parent::__construct($routing);
45
-        $this->admin_config = $this->loader->getShared('EE_Admin_Config');
46
-    }
47
-
48
-
49
-    /**
50
-     * Sets routes.
51
-     *
52
-     * @throws EE_Error
53
-     */
54
-    protected function _extend_page_config()
55
-    {
56
-        $this->_admin_base_path = EE_CORE_CAF_ADMIN_EXTEND . 'events';
57
-        // is there a evt_id in the request?
58
-        $EVT_ID             = $this->request->getRequestParam('EVT_ID', 0, 'int');
59
-        $EVT_ID             = $this->request->getRequestParam('post', $EVT_ID, 'int');
60
-        $TKT_ID             = $this->request->getRequestParam('TKT_ID', 0, 'int');
61
-        $new_page_routes    = [
62
-            'duplicate_event'          => [
63
-                'func'       => '_duplicate_event',
64
-                'capability' => 'ee_edit_event',
65
-                'obj_id'     => $EVT_ID,
66
-                'noheader'   => true,
67
-            ],
68
-            'import_page'              => [
69
-                'func'       => '_import_page',
70
-                'capability' => 'import',
71
-            ],
72
-            'import'                   => [
73
-                'func'       => '_import_events',
74
-                'capability' => 'import',
75
-                'noheader'   => true,
76
-            ],
77
-            'import_events'            => [
78
-                'func'       => '_import_events',
79
-                'capability' => 'import',
80
-                'noheader'   => true,
81
-            ],
82
-            'export_events'            => [
83
-                'func'       => '_events_export',
84
-                'capability' => 'export',
85
-                'noheader'   => true,
86
-            ],
87
-            'export_categories'        => [
88
-                'func'       => '_categories_export',
89
-                'capability' => 'export',
90
-                'noheader'   => true,
91
-            ],
92
-            'sample_export_file'       => [
93
-                'func'       => '_sample_export_file',
94
-                'capability' => 'export',
95
-                'noheader'   => true,
96
-            ],
97
-            'update_template_settings' => [
98
-                'func'       => '_update_template_settings',
99
-                'capability' => 'manage_options',
100
-                'noheader'   => true,
101
-            ],
102
-            'ticket_list_table'        => [
103
-                'func'       => '_tickets_overview_list_table',
104
-                'capability' => 'ee_read_default_tickets',
105
-            ],
106
-        ];
107
-        $this->_page_config['create_new']['metaboxes'][] = '_premium_event_editor_meta_boxes';
108
-        $this->_page_config['edit']['metaboxes'][]       = '_premium_event_editor_meta_boxes';
109
-        // don't load these meta boxes if using the advanced editor
110
-        if (
111
-            ! $this->admin_config->useAdvancedEditor()
112
-            || ! $this->feature->allowed('use_default_ticket_manager')
113
-        ) {
114
-            $this->_page_config['create_new']['qtips'][] = 'EE_Event_Editor_Tips';
115
-            $this->_page_config['edit']['qtips'][]       = 'EE_Event_Editor_Tips';
116
-
117
-            $legacy_editor_page_routes = [
118
-                'trash_ticket'    => [
119
-                    'func'       => '_trash_or_restore_ticket',
120
-                    'capability' => 'ee_delete_default_ticket',
121
-                    'obj_id'     => $TKT_ID,
122
-                    'noheader'   => true,
123
-                    'args'       => ['trash' => true],
124
-                ],
125
-                'trash_tickets'   => [
126
-                    'func'       => '_trash_or_restore_ticket',
127
-                    'capability' => 'ee_delete_default_tickets',
128
-                    'noheader'   => true,
129
-                    'args'       => ['trash' => true],
130
-                ],
131
-                'restore_ticket'  => [
132
-                    'func'       => '_trash_or_restore_ticket',
133
-                    'capability' => 'ee_delete_default_ticket',
134
-                    'obj_id'     => $TKT_ID,
135
-                    'noheader'   => true,
136
-                ],
137
-                'restore_tickets' => [
138
-                    'func'       => '_trash_or_restore_ticket',
139
-                    'capability' => 'ee_delete_default_tickets',
140
-                    'noheader'   => true,
141
-                ],
142
-                'delete_ticket'   => [
143
-                    'func'       => '_delete_ticket',
144
-                    'capability' => 'ee_delete_default_ticket',
145
-                    'obj_id'     => $TKT_ID,
146
-                    'noheader'   => true,
147
-                ],
148
-                'delete_tickets'  => [
149
-                    'func'       => '_delete_ticket',
150
-                    'capability' => 'ee_delete_default_tickets',
151
-                    'noheader'   => true,
152
-                ],
153
-            ];
154
-            $new_page_routes           = array_merge($new_page_routes, $legacy_editor_page_routes);
155
-        }
156
-
157
-        $this->_page_routes = array_merge($this->_page_routes, $new_page_routes);
158
-        // partial route/config override
159
-        $this->_page_config['import_events']['metaboxes'] = $this->_default_espresso_metaboxes;
160
-        $this->_page_config['default']['list_table']      = 'Extend_Events_Admin_List_Table';
161
-        // add tickets tab but only if there are more than one default ticket!
162
-        $ticket_count = EEM_Ticket::instance()->count_deleted_and_undeleted(
163
-            [['TKT_is_default' => 1]],
164
-            'TKT_ID',
165
-            true
166
-        );
167
-        if ($ticket_count > 1) {
168
-            $new_page_config = [
169
-                'ticket_list_table' => [
170
-                    'nav'           => [
171
-                        'label' => esc_html__('Default Tickets', 'event_espresso'),
172
-                        'order' => 60,
173
-                    ],
174
-                    'list_table'    => 'Tickets_List_Table',
175
-                    'require_nonce' => false,
176
-                ],
177
-            ];
178
-        }
179
-        // template settings
180
-        $new_page_config['template_settings'] = [
181
-            'nav'           => [
182
-                'label' => esc_html__('Templates', 'event_espresso'),
183
-                'order' => 30,
184
-            ],
185
-            'metaboxes'     => array_merge($this->_default_espresso_metaboxes, ['_publish_post_box']),
186
-            'help_tabs'     => [
187
-                'general_settings_templates_help_tab' => [
188
-                    'title'    => esc_html__('Templates', 'event_espresso'),
189
-                    'filename' => 'general_settings_templates',
190
-                ],
191
-            ],
192
-            // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
193
-            // 'help_tour'     => ['Templates_Help_Tour'],
194
-            'require_nonce' => false,
195
-        ];
196
-        $this->_page_config                   = array_merge($this->_page_config, $new_page_config);
197
-        // add filters and actions
198
-        // modifying _views
199
-        add_filter(
200
-            'FHEE_event_datetime_metabox_add_additional_date_time_template',
201
-            [$this, 'add_additional_datetime_button'],
202
-            10,
203
-            2
204
-        );
205
-        add_filter(
206
-            'FHEE_event_datetime_metabox_clone_button_template',
207
-            [$this, 'add_datetime_clone_button'],
208
-            10,
209
-            2
210
-        );
211
-        add_filter(
212
-            'FHEE_event_datetime_metabox_timezones_template',
213
-            [$this, 'datetime_timezones_template'],
214
-            10,
215
-            2
216
-        );
217
-        // filters for event list table
218
-        add_filter('FHEE__Extend_Events_Admin_List_Table__filters', [$this, 'list_table_filters'], 10, 2);
219
-        add_filter(
220
-            'FHEE__Events_Admin_List_Table__column_actions__action_links',
221
-            [$this, 'extra_list_table_actions'],
222
-            10,
223
-            2
224
-        );
225
-        // legend item
226
-        add_filter('FHEE__Events_Admin_Page___event_legend_items__items', [$this, 'additional_legend_items']);
227
-        add_action('admin_init', [$this, 'admin_init']);
228
-        // load additional handlers
229
-        $this->handleActionRequest();
230
-    }
231
-
232
-
233
-    private function getRequestAction()
234
-    {
235
-        return $this->request->getRequestParam('action);
19
+	/**
20
+	 * @var EE_Admin_Config
21
+	 */
22
+	protected $admin_config;
23
+
24
+	/**
25
+	 * @var AdvancedEditorAdminFormSection
26
+	 */
27
+	protected $advanced_editor_admin_form;
28
+
29
+
30
+	/**
31
+	 * Extend_Events_Admin_Page constructor.
32
+	 *
33
+	 * @param bool $routing
34
+	 * @throws EE_Error
35
+	 * @throws ReflectionException
36
+	 */
37
+	public function __construct($routing = true)
38
+	{
39
+		if (! defined('EVENTS_CAF_TEMPLATE_PATH')) {
40
+			define('EVENTS_CAF_TEMPLATE_PATH', EE_CORE_CAF_ADMIN_EXTEND . 'events/templates/');
41
+			define('EVENTS_CAF_ASSETS', EE_CORE_CAF_ADMIN_EXTEND . 'events/assets/');
42
+			define('EVENTS_CAF_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL . 'events/assets/');
43
+		}
44
+		parent::__construct($routing);
45
+		$this->admin_config = $this->loader->getShared('EE_Admin_Config');
46
+	}
47
+
48
+
49
+	/**
50
+	 * Sets routes.
51
+	 *
52
+	 * @throws EE_Error
53
+	 */
54
+	protected function _extend_page_config()
55
+	{
56
+		$this->_admin_base_path = EE_CORE_CAF_ADMIN_EXTEND . 'events';
57
+		// is there a evt_id in the request?
58
+		$EVT_ID             = $this->request->getRequestParam('EVT_ID', 0, 'int');
59
+		$EVT_ID             = $this->request->getRequestParam('post', $EVT_ID, 'int');
60
+		$TKT_ID             = $this->request->getRequestParam('TKT_ID', 0, 'int');
61
+		$new_page_routes    = [
62
+			'duplicate_event'          => [
63
+				'func'       => '_duplicate_event',
64
+				'capability' => 'ee_edit_event',
65
+				'obj_id'     => $EVT_ID,
66
+				'noheader'   => true,
67
+			],
68
+			'import_page'              => [
69
+				'func'       => '_import_page',
70
+				'capability' => 'import',
71
+			],
72
+			'import'                   => [
73
+				'func'       => '_import_events',
74
+				'capability' => 'import',
75
+				'noheader'   => true,
76
+			],
77
+			'import_events'            => [
78
+				'func'       => '_import_events',
79
+				'capability' => 'import',
80
+				'noheader'   => true,
81
+			],
82
+			'export_events'            => [
83
+				'func'       => '_events_export',
84
+				'capability' => 'export',
85
+				'noheader'   => true,
86
+			],
87
+			'export_categories'        => [
88
+				'func'       => '_categories_export',
89
+				'capability' => 'export',
90
+				'noheader'   => true,
91
+			],
92
+			'sample_export_file'       => [
93
+				'func'       => '_sample_export_file',
94
+				'capability' => 'export',
95
+				'noheader'   => true,
96
+			],
97
+			'update_template_settings' => [
98
+				'func'       => '_update_template_settings',
99
+				'capability' => 'manage_options',
100
+				'noheader'   => true,
101
+			],
102
+			'ticket_list_table'        => [
103
+				'func'       => '_tickets_overview_list_table',
104
+				'capability' => 'ee_read_default_tickets',
105
+			],
106
+		];
107
+		$this->_page_config['create_new']['metaboxes'][] = '_premium_event_editor_meta_boxes';
108
+		$this->_page_config['edit']['metaboxes'][]       = '_premium_event_editor_meta_boxes';
109
+		// don't load these meta boxes if using the advanced editor
110
+		if (
111
+			! $this->admin_config->useAdvancedEditor()
112
+			|| ! $this->feature->allowed('use_default_ticket_manager')
113
+		) {
114
+			$this->_page_config['create_new']['qtips'][] = 'EE_Event_Editor_Tips';
115
+			$this->_page_config['edit']['qtips'][]       = 'EE_Event_Editor_Tips';
116
+
117
+			$legacy_editor_page_routes = [
118
+				'trash_ticket'    => [
119
+					'func'       => '_trash_or_restore_ticket',
120
+					'capability' => 'ee_delete_default_ticket',
121
+					'obj_id'     => $TKT_ID,
122
+					'noheader'   => true,
123
+					'args'       => ['trash' => true],
124
+				],
125
+				'trash_tickets'   => [
126
+					'func'       => '_trash_or_restore_ticket',
127
+					'capability' => 'ee_delete_default_tickets',
128
+					'noheader'   => true,
129
+					'args'       => ['trash' => true],
130
+				],
131
+				'restore_ticket'  => [
132
+					'func'       => '_trash_or_restore_ticket',
133
+					'capability' => 'ee_delete_default_ticket',
134
+					'obj_id'     => $TKT_ID,
135
+					'noheader'   => true,
136
+				],
137
+				'restore_tickets' => [
138
+					'func'       => '_trash_or_restore_ticket',
139
+					'capability' => 'ee_delete_default_tickets',
140
+					'noheader'   => true,
141
+				],
142
+				'delete_ticket'   => [
143
+					'func'       => '_delete_ticket',
144
+					'capability' => 'ee_delete_default_ticket',
145
+					'obj_id'     => $TKT_ID,
146
+					'noheader'   => true,
147
+				],
148
+				'delete_tickets'  => [
149
+					'func'       => '_delete_ticket',
150
+					'capability' => 'ee_delete_default_tickets',
151
+					'noheader'   => true,
152
+				],
153
+			];
154
+			$new_page_routes           = array_merge($new_page_routes, $legacy_editor_page_routes);
155
+		}
156
+
157
+		$this->_page_routes = array_merge($this->_page_routes, $new_page_routes);
158
+		// partial route/config override
159
+		$this->_page_config['import_events']['metaboxes'] = $this->_default_espresso_metaboxes;
160
+		$this->_page_config['default']['list_table']      = 'Extend_Events_Admin_List_Table';
161
+		// add tickets tab but only if there are more than one default ticket!
162
+		$ticket_count = EEM_Ticket::instance()->count_deleted_and_undeleted(
163
+			[['TKT_is_default' => 1]],
164
+			'TKT_ID',
165
+			true
166
+		);
167
+		if ($ticket_count > 1) {
168
+			$new_page_config = [
169
+				'ticket_list_table' => [
170
+					'nav'           => [
171
+						'label' => esc_html__('Default Tickets', 'event_espresso'),
172
+						'order' => 60,
173
+					],
174
+					'list_table'    => 'Tickets_List_Table',
175
+					'require_nonce' => false,
176
+				],
177
+			];
178
+		}
179
+		// template settings
180
+		$new_page_config['template_settings'] = [
181
+			'nav'           => [
182
+				'label' => esc_html__('Templates', 'event_espresso'),
183
+				'order' => 30,
184
+			],
185
+			'metaboxes'     => array_merge($this->_default_espresso_metaboxes, ['_publish_post_box']),
186
+			'help_tabs'     => [
187
+				'general_settings_templates_help_tab' => [
188
+					'title'    => esc_html__('Templates', 'event_espresso'),
189
+					'filename' => 'general_settings_templates',
190
+				],
191
+			],
192
+			// disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
193
+			// 'help_tour'     => ['Templates_Help_Tour'],
194
+			'require_nonce' => false,
195
+		];
196
+		$this->_page_config                   = array_merge($this->_page_config, $new_page_config);
197
+		// add filters and actions
198
+		// modifying _views
199
+		add_filter(
200
+			'FHEE_event_datetime_metabox_add_additional_date_time_template',
201
+			[$this, 'add_additional_datetime_button'],
202
+			10,
203
+			2
204
+		);
205
+		add_filter(
206
+			'FHEE_event_datetime_metabox_clone_button_template',
207
+			[$this, 'add_datetime_clone_button'],
208
+			10,
209
+			2
210
+		);
211
+		add_filter(
212
+			'FHEE_event_datetime_metabox_timezones_template',
213
+			[$this, 'datetime_timezones_template'],
214
+			10,
215
+			2
216
+		);
217
+		// filters for event list table
218
+		add_filter('FHEE__Extend_Events_Admin_List_Table__filters', [$this, 'list_table_filters'], 10, 2);
219
+		add_filter(
220
+			'FHEE__Events_Admin_List_Table__column_actions__action_links',
221
+			[$this, 'extra_list_table_actions'],
222
+			10,
223
+			2
224
+		);
225
+		// legend item
226
+		add_filter('FHEE__Events_Admin_Page___event_legend_items__items', [$this, 'additional_legend_items']);
227
+		add_action('admin_init', [$this, 'admin_init']);
228
+		// load additional handlers
229
+		$this->handleActionRequest();
230
+	}
231
+
232
+
233
+	private function getRequestAction()
234
+	{
235
+		return $this->request->getRequestParam('action);
236 236
     }
237 237
 
238 238
 
@@ -540,870 +540,870 @@  discard block
 block discarded – undo
540 540
     {
541 541
         // first make sure the ID for the event is in the request.
542 542
         //  If it isn't then we need to bail and redirect back to overview list table (cause how did we get here?)
543
-        $EVT_ID = $this->request->getRequestParam('EVT_ID', 0, 'int');
544
-        if (! $EVT_ID) {
545
-            EE_Error::add_error(
546
-                esc_html__(
547
-                    'In order to duplicate an event an Event ID is required.  None was given.',
548
-                    'event_espresso'
549
-                ),
550
-                __FILE__,
551
-                __FUNCTION__,
552
-                __LINE__
553
-            );
554
-            $this->_redirect_after_action(false, '', '', [], true);
555
-            return;
556
-        }
557
-        // k we've got EVT_ID so let's use that to get the event we'll duplicate
558
-        $orig_event = EEM_Event::instance()->get_one_by_ID($EVT_ID);
559
-        if (! $orig_event instanceof EE_Event) {
560
-            throw new EE_Error(
561
-                sprintf(
562
-                    esc_html__('An EE_Event object could not be retrieved for the given ID (%s)', 'event_espresso'),
563
-                    $EVT_ID
564
-                )
565
-            );
566
-        }
567
-        // k now let's clone the $orig_event before getting relations
568
-        $new_event = clone $orig_event;
569
-        // original datetimes
570
-        $orig_datetimes = $orig_event->get_many_related('Datetime');
571
-        // other original relations
572
-        $orig_ven = $orig_event->get_many_related('Venue');
573
-        // reset the ID and modify other details to make it clear this is a dupe
574
-        $new_event->set('EVT_ID', 0);
575
-        $new_name = $new_event->name() . ' ' . esc_html__('**DUPLICATE**', 'event_espresso');
576
-        $new_event->set('EVT_name', $new_name);
577
-        $new_event->set(
578
-            'EVT_slug',
579
-            wp_unique_post_slug(
580
-                sanitize_title($orig_event->name()),
581
-                0,
582
-                'publish',
583
-                'espresso_events',
584
-                0
585
-            )
586
-        );
587
-        $new_event->set('status', 'draft');
588
-        // duplicate discussion settings
589
-        $new_event->set('comment_status', $orig_event->get('comment_status'));
590
-        $new_event->set('ping_status', $orig_event->get('ping_status'));
591
-        // save the new event
592
-        $new_event->save();
593
-        // venues
594
-        foreach ($orig_ven as $ven) {
595
-            $new_event->_add_relation_to($ven, 'Venue');
596
-        }
597
-        $new_event->save();
598
-        // now we need to get the question group relations and handle that
599
-        // first primary question groups
600
-        $orig_primary_qgs = $orig_event->get_many_related(
601
-            'Question_Group',
602
-            [['Event_Question_Group.EQG_primary' => true]]
603
-        );
604
-        if (! empty($orig_primary_qgs)) {
605
-            foreach ($orig_primary_qgs as $obj) {
606
-                if ($obj instanceof EE_Question_Group) {
607
-                    $new_event->_add_relation_to($obj, 'Question_Group', ['EQG_primary' => true]);
608
-                }
609
-            }
610
-        }
611
-        // next additional attendee question groups
612
-        $orig_additional_qgs = $orig_event->get_many_related(
613
-            'Question_Group',
614
-            [['Event_Question_Group.EQG_additional' => true]]
615
-        );
616
-        if (! empty($orig_additional_qgs)) {
617
-            foreach ($orig_additional_qgs as $obj) {
618
-                if ($obj instanceof EE_Question_Group) {
619
-                    $new_event->_add_relation_to($obj, 'Question_Group', ['EQG_additional' => true]);
620
-                }
621
-            }
622
-        }
623
-
624
-        $new_event->save();
625
-
626
-        // k now that we have the new event saved we can loop through the datetimes and start adding relations.
627
-        $cloned_tickets = [];
628
-        foreach ($orig_datetimes as $orig_dtt) {
629
-            if (! $orig_dtt instanceof EE_Datetime) {
630
-                continue;
631
-            }
632
-            $new_dtt      = clone $orig_dtt;
633
-            $orig_tickets = $orig_dtt->tickets();
634
-            // save new dtt then add to event
635
-            $new_dtt->set('DTT_ID', 0);
636
-            $new_dtt->set('DTT_sold', 0);
637
-            $new_dtt->set_reserved(0);
638
-            $new_dtt->save();
639
-            $new_event->_add_relation_to($new_dtt, 'Datetime');
640
-            $new_event->save();
641
-            // now let's get the ticket relations setup.
642
-            foreach ((array) $orig_tickets as $orig_ticket) {
643
-                // it's possible a datetime will have no tickets so let's verify we HAVE a ticket first.
644
-                if (! $orig_ticket instanceof EE_Ticket) {
645
-                    continue;
646
-                }
647
-                // is this ticket archived?  If it is then let's skip
648
-                if ($orig_ticket->get('TKT_deleted')) {
649
-                    continue;
650
-                }
651
-                // does this original ticket already exist in the clone_tickets cache?
652
-                //  If so we'll just use the new ticket from it.
653
-                if (isset($cloned_tickets[ $orig_ticket->ID() ])) {
654
-                    $new_ticket = $cloned_tickets[ $orig_ticket->ID() ];
655
-                } else {
656
-                    $new_ticket = clone $orig_ticket;
657
-                    // get relations on the $orig_ticket that we need to setup.
658
-                    $orig_prices = $orig_ticket->prices();
659
-                    $new_ticket->set('TKT_ID', 0);
660
-                    $new_ticket->set('TKT_sold', 0);
661
-                    $new_ticket->set('TKT_reserved', 0);
662
-                    $new_ticket->save(); // make sure new ticket has ID.
663
-                    // price relations on new ticket need to be setup.
664
-                    foreach ($orig_prices as $orig_price) {
665
-                        $new_price = clone $orig_price;
666
-                        $new_price->set('PRC_ID', 0);
667
-                        $new_price->save();
668
-                        $new_ticket->_add_relation_to($new_price, 'Price');
669
-                        $new_ticket->save();
670
-                    }
671
-
672
-                    do_action(
673
-                        'AHEE__Extend_Events_Admin_Page___duplicate_event__duplicate_ticket__after',
674
-                        $orig_ticket,
675
-                        $new_ticket,
676
-                        $orig_prices,
677
-                        $orig_event,
678
-                        $orig_dtt,
679
-                        $new_dtt
680
-                    );
681
-                }
682
-                // k now we can add the new ticket as a relation to the new datetime
683
-                // and make sure its added to our cached $cloned_tickets array
684
-                // for use with later datetimes that have the same ticket.
685
-                $new_dtt->_add_relation_to($new_ticket, 'Ticket');
686
-                $new_dtt->save();
687
-                $cloned_tickets[ $orig_ticket->ID() ] = $new_ticket;
688
-            }
689
-        }
690
-        // clone taxonomy information
691
-        $taxonomies_to_clone_with = apply_filters(
692
-            'FHEE__Extend_Events_Admin_Page___duplicate_event__taxonomies_to_clone',
693
-            ['espresso_event_categories', 'espresso_event_type', 'post_tag']
694
-        );
695
-        // get terms for original event (notice)
696
-        $orig_terms = wp_get_object_terms($orig_event->ID(), $taxonomies_to_clone_with);
697
-        // loop through terms and add them to new event.
698
-        foreach ($orig_terms as $term) {
699
-            wp_set_object_terms($new_event->ID(), $term->term_id, $term->taxonomy, true);
700
-        }
701
-
702
-        // duplicate other core WP_Post items for this event.
703
-        // post thumbnail (feature image).
704
-        $feature_image_id = get_post_thumbnail_id($orig_event->ID());
705
-        if ($feature_image_id) {
706
-            update_post_meta($new_event->ID(), '_thumbnail_id', $feature_image_id);
707
-        }
708
-
709
-        // duplicate page_template setting
710
-        $page_template = get_post_meta($orig_event->ID(), '_wp_page_template', true);
711
-        if ($page_template) {
712
-            update_post_meta($new_event->ID(), '_wp_page_template', $page_template);
713
-        }
714
-
715
-        do_action('AHEE__Extend_Events_Admin_Page___duplicate_event__after', $new_event, $orig_event);
716
-        // now let's redirect to the edit page for this duplicated event if we have a new event id.
717
-        if ($new_event->ID()) {
718
-            $redirect_args = [
719
-                'post'   => $new_event->ID(),
720
-                'action' => 'edit',
721
-            ];
722
-            EE_Error::add_success(
723
-                esc_html__(
724
-                    'Event successfully duplicated.  Please review the details below and make any necessary edits',
725
-                    'event_espresso'
726
-                )
727
-            );
728
-        } else {
729
-            $redirect_args = [
730
-                'action' => 'default',
731
-            ];
732
-            EE_Error::add_error(
733
-                esc_html__('Not able to duplicate event.  Something went wrong.', 'event_espresso'),
734
-                __FILE__,
735
-                __FUNCTION__,
736
-                __LINE__
737
-            );
738
-        }
739
-        $this->_redirect_after_action(false, '', '', $redirect_args, true);
740
-    }
741
-
742
-
743
-    /**
744
-     * Generates output for the import page.
745
-     *
746
-     * @throws EE_Error
747
-     */
748
-    protected function _import_page()
749
-    {
750
-        $title                                      = esc_html__('Import', 'event_espresso');
751
-        $intro                                      = esc_html__(
752
-            'If you have a previously exported Event Espresso 4 information in a Comma Separated Value (CSV) file format, you can upload the file here: ',
753
-            'event_espresso'
754
-        );
755
-
756
-        $form_url = EVENTS_ADMIN_URL;
757
-        $action   = 'import_events';
758
-        $type     = 'csv';
759
-
760
-        $this->_template_args['form'] = EE_Import::instance()->upload_form(
761
-            $title,
762
-            $intro,
763
-            $form_url,
764
-            $action,
765
-            $type
766
-        );
767
-
768
-        $this->_template_args['sample_file_link']   = EE_Admin_Page::add_query_args_and_nonce(
769
-            ['action' => 'sample_export_file'],
770
-            $this->_admin_base_url
771
-        );
772
-        $this->_template_args['admin_page_content'] = EEH_Template::display_template(
773
-            EVENTS_CAF_TEMPLATE_PATH . 'import_page.template.php',
774
-            $this->_template_args,
775
-            true
776
-        );
777
-        $this->display_admin_page_with_sidebar();
778
-    }
779
-
780
-
781
-    /**
782
-     * _import_events
783
-     * This handles displaying the screen and running imports for importing events.
784
-     *
785
-     * @return void
786
-     * @throws EE_Error
787
-     */
788
-    protected function _import_events()
789
-    {
790
-        require_once(EE_CLASSES . 'EE_Import.class.php');
791
-        $success = EE_Import::instance()->import();
792
-        $this->_redirect_after_action(
793
-            $success,
794
-            esc_html__('Import File', 'event_espresso'),
795
-            'ran',
796
-            ['action' => 'import_page'],
797
-            true
798
-        );
799
-    }
800
-
801
-
802
-    /**
803
-     * _events_export
804
-     * Will export all (or just the given event) to a Excel compatible file.
805
-     *
806
-     * @access protected
807
-     * @return void
808
-     */
809
-    protected function _events_export()
810
-    {
811
-        $EVT_ID = $this->request->getRequestParam('EVT_ID', 0, 'int');
812
-        $EVT_ID = $this->request->getRequestParam('EVT_IDs', $EVT_ID, 'int');
813
-        $this->request->mergeRequestParams(
814
-            [
815
-                'export' => 'report',
816
-                'action' => 'all_event_data',
817
-                'EVT_ID' => $EVT_ID,
818
-            ]
819
-        );
820
-        if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
821
-            require_once(EE_CLASSES . 'EE_Export.class.php');
822
-            $EE_Export = EE_Export::instance($this->request->requestParams());
823
-            $EE_Export->export();
824
-        }
825
-    }
826
-
827
-
828
-    /**
829
-     * handle category exports()
830
-     *
831
-     * @return void
832
-     */
833
-    protected function _categories_export()
834
-    {
835
-        $EVT_ID = $this->request->getRequestParam('EVT_CAT_ID', 0, 'int');
836
-        $this->request->mergeRequestParams(
837
-            [
838
-                'export' => 'report',
839
-                'action' => 'categories',
840
-                'EVT_ID' => $EVT_ID,
841
-            ]
842
-        );
843
-        if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
844
-            require_once(EE_CLASSES . 'EE_Export.class.php');
845
-            $EE_Export = EE_Export::instance($this->request->requestParams());
846
-            $EE_Export->export();
847
-        }
848
-    }
849
-
850
-
851
-    /**
852
-     * Creates a sample CSV file for importing
853
-     */
854
-    protected function _sample_export_file()
855
-    {
856
-        $EE_Export = EE_Export::instance();
857
-        if ($EE_Export instanceof EE_Export) {
858
-            $EE_Export->export();
859
-        }
860
-    }
861
-
862
-
863
-    /*************        Template Settings        *************/
864
-    /**
865
-     * Generates template settings page output
866
-     *
867
-     * @throws DomainException
868
-     * @throws EE_Error
869
-     * @throws InvalidArgumentException
870
-     * @throws InvalidDataTypeException
871
-     * @throws InvalidInterfaceException
872
-     */
873
-    protected function _template_settings()
874
-    {
875
-        $this->_template_args['values'] = $this->_yes_no_values;
876
-        /**
877
-         * Note leaving this filter in for backward compatibility this was moved in 4.6.x
878
-         * from General_Settings_Admin_Page to here.
879
-         */
880
-        $this->_template_args = apply_filters(
881
-            'FHEE__General_Settings_Admin_Page__template_settings__template_args',
882
-            $this->_template_args
883
-        );
884
-        $this->_set_add_edit_form_tags('update_template_settings');
885
-        $this->_set_publish_post_box_vars(null, false, false, null, false);
886
-        $this->_template_args['admin_page_content'] = EEH_Template::display_template(
887
-            EVENTS_CAF_TEMPLATE_PATH . 'template_settings.template.php',
888
-            $this->_template_args,
889
-            true
890
-        );
891
-        $this->display_admin_page_with_sidebar();
892
-    }
893
-
894
-
895
-    /**
896
-     * Handler for updating template settings.
897
-     *
898
-     * @throws EE_Error
899
-     */
900
-    protected function _update_template_settings()
901
-    {
902
-        /**
903
-         * Note leaving this filter in for backward compatibility this was moved in 4.6.x
904
-         * from General_Settings_Admin_Page to here.
905
-         */
906
-        EE_Registry::instance()->CFG->template_settings = apply_filters(
907
-            'FHEE__General_Settings_Admin_Page__update_template_settings__data',
908
-            EE_Registry::instance()->CFG->template_settings,
909
-            $this->request->requestParams()
910
-        );
911
-        // update custom post type slugs and detect if we need to flush rewrite rules
912
-        $old_slug = EE_Registry::instance()->CFG->core->event_cpt_slug;
913
-
914
-        $event_cpt_slug = $this->request->getRequestParam('event_cpt_slug');
915
-
916
-        EE_Registry::instance()->CFG->core->event_cpt_slug = $event_cpt_slug
917
-            ? EE_Registry::instance()->CFG->core->event_cpt_slug
918
-            : EEH_URL::slugify($event_cpt_slug, 'events');
919
-
920
-        $what    = esc_html__('Template Settings', 'event_espresso');
921
-        $success = $this->_update_espresso_configuration(
922
-            $what,
923
-            EE_Registry::instance()->CFG->template_settings,
924
-            __FILE__,
925
-            __FUNCTION__,
926
-            __LINE__
927
-        );
928
-        if (EE_Registry::instance()->CFG->core->event_cpt_slug !== $old_slug) {
929
-            /** @var EventEspresso\core\domain\services\custom_post_types\RewriteRules $rewrite_rules */
930
-            $rewrite_rules = LoaderFactory::getLoader()->getShared(
931
-                'EventEspresso\core\domain\services\custom_post_types\RewriteRules'
932
-            );
933
-            $rewrite_rules->flush();
934
-        }
935
-        $this->_redirect_after_action($success, $what, 'updated', ['action' => 'template_settings']);
936
-    }
937
-
938
-
939
-    /**
940
-     * _premium_event_editor_meta_boxes
941
-     * add all metaboxes related to the event_editor
942
-     *
943
-     * @access protected
944
-     * @return void
945
-     * @throws EE_Error
946
-     * @throws ReflectionException
947
-     */
948
-    protected function _premium_event_editor_meta_boxes()
949
-    {
950
-        $this->verify_cpt_object();
951
-        // check if the new EDTR reg options meta box is being used, and if so, don't load the legacy version
952
-        if (
953
-            ! $this->admin_config->useAdvancedEditor()
954
-            || ! $this->feature->allowed('use_reg_options_meta_box')
955
-        ) {
956
-            add_meta_box(
957
-                'espresso_event_editor_event_options',
958
-                esc_html__('Event Registration Options', 'event_espresso'),
959
-                [$this, 'registration_options_meta_box'],
960
-                $this->page_slug,
961
-                'side',
962
-                'core'
963
-            );
964
-        }
965
-    }
966
-
967
-
968
-    /**
969
-     * override caf metabox
970
-     *
971
-     * @return void
972
-     * @throws EE_Error
973
-     * @throws ReflectionException
974
-     */
975
-    public function registration_options_meta_box()
976
-    {
977
-        $yes_no_values = [
978
-            ['id' => true, 'text' => esc_html__('Yes', 'event_espresso')],
979
-            ['id' => false, 'text' => esc_html__('No', 'event_espresso')],
980
-        ];
981
-
982
-        $default_reg_status_values = EEM_Registration::reg_status_array(
983
-            [
984
-                EEM_Registration::status_id_cancelled,
985
-                EEM_Registration::status_id_declined,
986
-                EEM_Registration::status_id_incomplete,
987
-                EEM_Registration::status_id_wait_list,
988
-            ],
989
-            true
990
-        );
991
-
992
-        $template_args['active_status']    = $this->_cpt_model_obj->pretty_active_status(false);
993
-        $template_args['_event']           = $this->_cpt_model_obj;
994
-        $template_args['additional_limit'] = $this->_cpt_model_obj->additional_limit();
995
-
996
-        $template_args['default_registration_status']     = EEH_Form_Fields::select_input(
997
-            'default_reg_status',
998
-            $default_reg_status_values,
999
-            $this->_cpt_model_obj->default_registration_status()
1000
-        );
1001
-        $template_args['display_description']             = EEH_Form_Fields::select_input(
1002
-            'display_desc',
1003
-            $yes_no_values,
1004
-            $this->_cpt_model_obj->display_description()
1005
-        );
1006
-        $template_args['display_ticket_selector']         = EEH_Form_Fields::select_input(
1007
-            'display_ticket_selector',
1008
-            $yes_no_values,
1009
-            $this->_cpt_model_obj->display_ticket_selector(),
1010
-            '',
1011
-            '',
1012
-            false
1013
-        );
1014
-        $template_args['EVT_default_registration_status'] = EEH_Form_Fields::select_input(
1015
-            'EVT_default_registration_status',
1016
-            $default_reg_status_values,
1017
-            $this->_cpt_model_obj->default_registration_status()
1018
-        );
1019
-        $template_args['additional_registration_options'] = apply_filters(
1020
-            'FHEE__Events_Admin_Page__registration_options_meta_box__additional_registration_options',
1021
-            '',
1022
-            $template_args,
1023
-            $yes_no_values,
1024
-            $default_reg_status_values
1025
-        );
1026
-        EEH_Template::display_template(
1027
-            EVENTS_CAF_TEMPLATE_PATH . 'event_registration_options.template.php',
1028
-            $template_args
1029
-        );
1030
-    }
1031
-
1032
-
1033
-
1034
-    /**
1035
-     * wp_list_table_mods for caf
1036
-     * ============================
1037
-     */
1038
-    /**
1039
-     * hook into list table filters and provide filters for caffeinated list table
1040
-     *
1041
-     * @param array $old_filters    any existing filters present
1042
-     * @param array $list_table_obj the list table object
1043
-     * @return array                  new filters
1044
-     * @throws EE_Error
1045
-     * @throws ReflectionException
1046
-     */
1047
-    public function list_table_filters($old_filters, $list_table_obj)
1048
-    {
1049
-        $filters = [];
1050
-        // first month/year filters
1051
-        $filters[] = $this->espresso_event_months_dropdown();
1052
-        $status    = $this->request->getRequestParam('status');
1053
-        // active status dropdown
1054
-        if ($status !== 'draft') {
1055
-            $filters[] = $this->active_status_dropdown($this->request->getRequestParam('active_status'));
1056
-            $filters[] = $this->venuesDropdown($this->request->getRequestParam('venue'));
1057
-        }
1058
-        // category filter
1059
-        $filters[] = $this->category_dropdown();
1060
-        return array_merge($old_filters, $filters);
1061
-    }
1062
-
1063
-
1064
-    /**
1065
-     * espresso_event_months_dropdown
1066
-     *
1067
-     * @access public
1068
-     * @return string                dropdown listing month/year selections for events.
1069
-     * @throws EE_Error
1070
-     */
1071
-    public function espresso_event_months_dropdown()
1072
-    {
1073
-        // what we need to do is get all PRIMARY datetimes for all events to filter on.
1074
-        // Note we need to include any other filters that are set!
1075
-        return EEH_Form_Fields::generate_event_months_dropdown(
1076
-            $this->request->getRequestParam('month_range'),
1077
-            $this->request->getRequestParam('status'),
1078
-            $this->request->getRequestParam('EVT_CAT', 0, 'int'),
1079
-            $this->request->getRequestParam('active_status')
1080
-        );
1081
-    }
1082
-
1083
-
1084
-    /**
1085
-     * returns a list of "active" statuses on the event
1086
-     *
1087
-     * @param string $current_value whatever the current active status is
1088
-     * @return string
1089
-     */
1090
-    public function active_status_dropdown($current_value = '')
1091
-    {
1092
-        $select_name = 'active_status';
1093
-        $values      = [
1094
-            'none'     => esc_html__('Show Active/Inactive', 'event_espresso'),
1095
-            'active'   => esc_html__('Active', 'event_espresso'),
1096
-            'upcoming' => esc_html__('Upcoming', 'event_espresso'),
1097
-            'expired'  => esc_html__('Expired', 'event_espresso'),
1098
-            'inactive' => esc_html__('Inactive', 'event_espresso'),
1099
-        ];
1100
-
1101
-        return EEH_Form_Fields::select_input($select_name, $values, $current_value, '', 'wide');
1102
-    }
1103
-
1104
-
1105
-    /**
1106
-     * returns a list of "venues"
1107
-     *
1108
-     * @param string $current_value whatever the current active status is
1109
-     * @return string
1110
-     * @throws EE_Error
1111
-     * @throws ReflectionException
1112
-     */
1113
-    protected function venuesDropdown($current_value = '')
1114
-    {
1115
-        $values = ['' => esc_html__('All Venues', 'event_espresso')];
1116
-        // populate the list of venues.
1117
-        $venues = EEM_Venue::instance()->get_all(['order_by' => ['VNU_name' => 'ASC']]);
1118
-
1119
-        foreach ($venues as $venue) {
1120
-            $values[ $venue->ID() ] = $venue->name();
1121
-        }
1122
-
1123
-        return EEH_Form_Fields::select_input('venue', $values, $current_value, '', 'wide');
1124
-    }
1125
-
1126
-
1127
-    /**
1128
-     * output a dropdown of the categories for the category filter on the event admin list table
1129
-     *
1130
-     * @access  public
1131
-     * @return string html
1132
-     * @throws EE_Error
1133
-     * @throws ReflectionException
1134
-     */
1135
-    public function category_dropdown()
1136
-    {
1137
-        return EEH_Form_Fields::generate_event_category_dropdown(
1138
-            $this->request->getRequestParam('EVT_CAT', -1, 'int')
1139
-        );
1140
-    }
1141
-
1142
-
1143
-    /**
1144
-     * get total number of events today
1145
-     *
1146
-     * @access public
1147
-     * @return int
1148
-     * @throws EE_Error
1149
-     * @throws InvalidArgumentException
1150
-     * @throws InvalidDataTypeException
1151
-     * @throws InvalidInterfaceException
1152
-     */
1153
-    public function total_events_today()
1154
-    {
1155
-        $start = EEM_Datetime::instance()->convert_datetime_for_query(
1156
-            'DTT_EVT_start',
1157
-            date('Y-m-d') . ' 00:00:00',
1158
-            'Y-m-d H:i:s',
1159
-            'UTC'
1160
-        );
1161
-        $end   = EEM_Datetime::instance()->convert_datetime_for_query(
1162
-            'DTT_EVT_start',
1163
-            date('Y-m-d') . ' 23:59:59',
1164
-            'Y-m-d H:i:s',
1165
-            'UTC'
1166
-        );
1167
-        $where = [
1168
-            'Datetime.DTT_EVT_start' => ['BETWEEN', [$start, $end]],
1169
-        ];
1170
-        return EEM_Event::instance()->count([$where, 'caps' => 'read_admin'], 'EVT_ID', true);
1171
-    }
1172
-
1173
-
1174
-    /**
1175
-     * get total number of events this month
1176
-     *
1177
-     * @access public
1178
-     * @return int
1179
-     * @throws EE_Error
1180
-     * @throws InvalidArgumentException
1181
-     * @throws InvalidDataTypeException
1182
-     * @throws InvalidInterfaceException
1183
-     */
1184
-    public function total_events_this_month()
1185
-    {
1186
-        // Dates
1187
-        $this_year_r     = date('Y');
1188
-        $this_month_r    = date('m');
1189
-        $days_this_month = date('t');
1190
-        $start           = EEM_Datetime::instance()->convert_datetime_for_query(
1191
-            'DTT_EVT_start',
1192
-            $this_year_r . '-' . $this_month_r . '-01 00:00:00',
1193
-            'Y-m-d H:i:s',
1194
-            'UTC'
1195
-        );
1196
-        $end             = EEM_Datetime::instance()->convert_datetime_for_query(
1197
-            'DTT_EVT_start',
1198
-            $this_year_r . '-' . $this_month_r . '-' . $days_this_month . ' 23:59:59',
1199
-            'Y-m-d H:i:s',
1200
-            'UTC'
1201
-        );
1202
-        $where           = [
1203
-            'Datetime.DTT_EVT_start' => ['BETWEEN', [$start, $end]],
1204
-        ];
1205
-        return EEM_Event::instance()->count([$where, 'caps' => 'read_admin'], 'EVT_ID', true);
1206
-    }
1207
-
1208
-
1209
-    /** DEFAULT TICKETS STUFF **/
1210
-
1211
-    /**
1212
-     * Output default tickets list table view.
1213
-     *
1214
-     * @throws EE_Error
1215
-     */
1216
-    public function _tickets_overview_list_table()
1217
-    {
1218
-        if (
1219
-            $this->admin_config->useAdvancedEditor()
1220
-            && $this->feature->allowed('use_default_ticket_manager')
1221
-        ) {
1222
-            // check if the new EDTR reg options meta box is being used, and if so, don't load the legacy version
1223
-            $this->_template_args['admin_page_content'] = EEH_Template::display_template(
1224
-                EVENTS_CAF_TEMPLATE_PATH . 'default_tickets_moved_notice.template.php',
1225
-                [],
1226
-                true
1227
-            );
1228
-            $this->display_admin_page_with_no_sidebar();
1229
-        } else {
1230
-            $this->_search_btn_label = esc_html__('Tickets', 'event_espresso');
1231
-            $this->display_admin_list_table_page_with_no_sidebar();
1232
-        }
1233
-    }
1234
-
1235
-
1236
-    /**
1237
-     * @param int  $per_page
1238
-     * @param bool $count
1239
-     * @param bool $trashed
1240
-     * @return EE_Soft_Delete_Base_Class[]|int
1241
-     * @throws EE_Error
1242
-     */
1243
-    public function get_default_tickets($per_page = 10, $count = false, $trashed = false)
1244
-    {
1245
-        $orderby = $this->request->getRequestParam('orderby', 'TKT_name');
1246
-        $order   = $this->request->getRequestParam('order', 'ASC');
1247
-        switch ($orderby) {
1248
-            case 'TKT_name':
1249
-                $orderby = ['TKT_name' => $order];
1250
-                break;
1251
-            case 'TKT_price':
1252
-                $orderby = ['TKT_price' => $order];
1253
-                break;
1254
-            case 'TKT_uses':
1255
-                $orderby = ['TKT_uses' => $order];
1256
-                break;
1257
-            case 'TKT_min':
1258
-                $orderby = ['TKT_min' => $order];
1259
-                break;
1260
-            case 'TKT_max':
1261
-                $orderby = ['TKT_max' => $order];
1262
-                break;
1263
-            case 'TKT_qty':
1264
-                $orderby = ['TKT_qty' => $order];
1265
-                break;
1266
-        }
1267
-
1268
-        $current_page = $this->request->getRequestParam('paged', 1, 'int');
1269
-        $per_page     = $this->request->getRequestParam('perpage', $per_page, 'int');
1270
-        $offset       = ($current_page - 1) * $per_page;
1271
-
1272
-        $where = [
1273
-            'TKT_is_default' => 1,
1274
-            'TKT_deleted'    => $trashed,
1275
-        ];
1276
-
1277
-        $search_term = $this->request->getRequestParam('s');
1278
-        if ($search_term) {
1279
-            $search_term = '%' . $search_term . '%';
1280
-            $where['OR'] = [
1281
-                'TKT_name'        => ['LIKE', $search_term],
1282
-                'TKT_description' => ['LIKE', $search_term],
1283
-            ];
1284
-        }
1285
-
1286
-        return $count
1287
-            ? EEM_Ticket::instance()->count_deleted_and_undeleted([$where])
1288
-            : EEM_Ticket::instance()->get_all_deleted_and_undeleted(
1289
-                [
1290
-                    $where,
1291
-                    'order_by' => $orderby,
1292
-                    'limit'    => [$offset, $per_page],
1293
-                    'group_by' => 'TKT_ID',
1294
-                ]
1295
-            );
1296
-    }
1297
-
1298
-
1299
-    /**
1300
-     * @param bool $trash
1301
-     * @throws EE_Error
1302
-     * @throws InvalidArgumentException
1303
-     * @throws InvalidDataTypeException
1304
-     * @throws InvalidInterfaceException
1305
-     */
1306
-    protected function _trash_or_restore_ticket($trash = false)
1307
-    {
1308
-        $success = 1;
1309
-        $TKT     = EEM_Ticket::instance();
1310
-        // checkboxes?
1311
-        $checkboxes = $this->request->getRequestParam('checkbox', [], 'int', true);
1312
-        if (! empty($checkboxes)) {
1313
-            // if array has more than one element then success message should be plural
1314
-            $success = count($checkboxes) > 1 ? 2 : 1;
1315
-            // cycle thru the boxes
1316
-            while (list($TKT_ID, $value) = each($checkboxes)) {
1317
-                if ($trash) {
1318
-                    if (! $TKT->delete_by_ID($TKT_ID)) {
1319
-                        $success = 0;
1320
-                    }
1321
-                } elseif (! $TKT->restore_by_ID($TKT_ID)) {
1322
-                    $success = 0;
1323
-                }
1324
-            }
1325
-        } else {
1326
-            // grab single id and trash
1327
-            $TKT_ID = $this->request->getRequestParam('TKT_ID', 0, 'int');
1328
-            if ($trash) {
1329
-                if (! $TKT->delete_by_ID($TKT_ID)) {
1330
-                    $success = 0;
1331
-                }
1332
-            } elseif (! $TKT->restore_by_ID($TKT_ID)) {
1333
-                $success = 0;
1334
-            }
1335
-        }
1336
-        $action_desc = $trash ? 'moved to the trash' : 'restored';
1337
-        $query_args  = [
1338
-            'action' => 'ticket_list_table',
1339
-            'status' => $trash ? '' : 'trashed',
1340
-        ];
1341
-        $this->_redirect_after_action($success, esc_html__('Tickets', 'event_espresso'), $action_desc, $query_args);
1342
-    }
1343
-
1344
-
1345
-    /**
1346
-     * Handles trashing default ticket.
1347
-     *
1348
-     * @throws EE_Error
1349
-     * @throws ReflectionException
1350
-     */
1351
-    protected function _delete_ticket()
1352
-    {
1353
-        $success = 1;
1354
-        // checkboxes?
1355
-        $checkboxes = $this->request->getRequestParam('checkbox', [], 'int', true);
1356
-        if (! empty($checkboxes)) {
1357
-            // if array has more than one element then success message should be plural
1358
-            $success = count($checkboxes) > 1 ? 2 : 1;
1359
-            // cycle thru the boxes
1360
-            while (list($TKT_ID, $value) = each($checkboxes)) {
1361
-                // delete
1362
-                if (! $this->_delete_the_ticket($TKT_ID)) {
1363
-                    $success = 0;
1364
-                }
1365
-            }
1366
-        } else {
1367
-            // grab single id and trash
1368
-            $TKT_ID = $this->request->getRequestParam('TKT_ID', 0, 'int');
1369
-            if (! $this->_delete_the_ticket($TKT_ID)) {
1370
-                $success = 0;
1371
-            }
1372
-        }
1373
-        $action_desc = 'deleted';
1374
-        $query_args  = [
1375
-            'action' => 'ticket_list_table',
1376
-            'status' => 'trashed',
1377
-        ];
1378
-        // fail safe.  If the default ticket count === 1 then we need to redirect to event overview.
1379
-        if (
1380
-            EEM_Ticket::instance()->count_deleted_and_undeleted(
1381
-                [['TKT_is_default' => 1]],
1382
-                'TKT_ID',
1383
-                true
1384
-            )
1385
-        ) {
1386
-            $query_args = [];
1387
-        }
1388
-        $this->_redirect_after_action($success, esc_html__('Tickets', 'event_espresso'), $action_desc, $query_args);
1389
-    }
1390
-
1391
-
1392
-    /**
1393
-     * @param int $TKT_ID
1394
-     * @return bool|int
1395
-     * @throws EE_Error
1396
-     * @throws ReflectionException
1397
-     */
1398
-    protected function _delete_the_ticket($TKT_ID)
1399
-    {
1400
-        $ticket = EEM_Ticket::instance()->get_one_by_ID($TKT_ID);
1401
-        if (! $ticket instanceof EE_Ticket) {
1402
-            return false;
1403
-        }
1404
-        $ticket->_remove_relations('Datetime');
1405
-        // delete all related prices first
1406
-        $ticket->delete_related_permanently('Price');
1407
-        return $ticket->delete_permanently();
1408
-    }
543
+		$EVT_ID = $this->request->getRequestParam('EVT_ID', 0, 'int');
544
+		if (! $EVT_ID) {
545
+			EE_Error::add_error(
546
+				esc_html__(
547
+					'In order to duplicate an event an Event ID is required.  None was given.',
548
+					'event_espresso'
549
+				),
550
+				__FILE__,
551
+				__FUNCTION__,
552
+				__LINE__
553
+			);
554
+			$this->_redirect_after_action(false, '', '', [], true);
555
+			return;
556
+		}
557
+		// k we've got EVT_ID so let's use that to get the event we'll duplicate
558
+		$orig_event = EEM_Event::instance()->get_one_by_ID($EVT_ID);
559
+		if (! $orig_event instanceof EE_Event) {
560
+			throw new EE_Error(
561
+				sprintf(
562
+					esc_html__('An EE_Event object could not be retrieved for the given ID (%s)', 'event_espresso'),
563
+					$EVT_ID
564
+				)
565
+			);
566
+		}
567
+		// k now let's clone the $orig_event before getting relations
568
+		$new_event = clone $orig_event;
569
+		// original datetimes
570
+		$orig_datetimes = $orig_event->get_many_related('Datetime');
571
+		// other original relations
572
+		$orig_ven = $orig_event->get_many_related('Venue');
573
+		// reset the ID and modify other details to make it clear this is a dupe
574
+		$new_event->set('EVT_ID', 0);
575
+		$new_name = $new_event->name() . ' ' . esc_html__('**DUPLICATE**', 'event_espresso');
576
+		$new_event->set('EVT_name', $new_name);
577
+		$new_event->set(
578
+			'EVT_slug',
579
+			wp_unique_post_slug(
580
+				sanitize_title($orig_event->name()),
581
+				0,
582
+				'publish',
583
+				'espresso_events',
584
+				0
585
+			)
586
+		);
587
+		$new_event->set('status', 'draft');
588
+		// duplicate discussion settings
589
+		$new_event->set('comment_status', $orig_event->get('comment_status'));
590
+		$new_event->set('ping_status', $orig_event->get('ping_status'));
591
+		// save the new event
592
+		$new_event->save();
593
+		// venues
594
+		foreach ($orig_ven as $ven) {
595
+			$new_event->_add_relation_to($ven, 'Venue');
596
+		}
597
+		$new_event->save();
598
+		// now we need to get the question group relations and handle that
599
+		// first primary question groups
600
+		$orig_primary_qgs = $orig_event->get_many_related(
601
+			'Question_Group',
602
+			[['Event_Question_Group.EQG_primary' => true]]
603
+		);
604
+		if (! empty($orig_primary_qgs)) {
605
+			foreach ($orig_primary_qgs as $obj) {
606
+				if ($obj instanceof EE_Question_Group) {
607
+					$new_event->_add_relation_to($obj, 'Question_Group', ['EQG_primary' => true]);
608
+				}
609
+			}
610
+		}
611
+		// next additional attendee question groups
612
+		$orig_additional_qgs = $orig_event->get_many_related(
613
+			'Question_Group',
614
+			[['Event_Question_Group.EQG_additional' => true]]
615
+		);
616
+		if (! empty($orig_additional_qgs)) {
617
+			foreach ($orig_additional_qgs as $obj) {
618
+				if ($obj instanceof EE_Question_Group) {
619
+					$new_event->_add_relation_to($obj, 'Question_Group', ['EQG_additional' => true]);
620
+				}
621
+			}
622
+		}
623
+
624
+		$new_event->save();
625
+
626
+		// k now that we have the new event saved we can loop through the datetimes and start adding relations.
627
+		$cloned_tickets = [];
628
+		foreach ($orig_datetimes as $orig_dtt) {
629
+			if (! $orig_dtt instanceof EE_Datetime) {
630
+				continue;
631
+			}
632
+			$new_dtt      = clone $orig_dtt;
633
+			$orig_tickets = $orig_dtt->tickets();
634
+			// save new dtt then add to event
635
+			$new_dtt->set('DTT_ID', 0);
636
+			$new_dtt->set('DTT_sold', 0);
637
+			$new_dtt->set_reserved(0);
638
+			$new_dtt->save();
639
+			$new_event->_add_relation_to($new_dtt, 'Datetime');
640
+			$new_event->save();
641
+			// now let's get the ticket relations setup.
642
+			foreach ((array) $orig_tickets as $orig_ticket) {
643
+				// it's possible a datetime will have no tickets so let's verify we HAVE a ticket first.
644
+				if (! $orig_ticket instanceof EE_Ticket) {
645
+					continue;
646
+				}
647
+				// is this ticket archived?  If it is then let's skip
648
+				if ($orig_ticket->get('TKT_deleted')) {
649
+					continue;
650
+				}
651
+				// does this original ticket already exist in the clone_tickets cache?
652
+				//  If so we'll just use the new ticket from it.
653
+				if (isset($cloned_tickets[ $orig_ticket->ID() ])) {
654
+					$new_ticket = $cloned_tickets[ $orig_ticket->ID() ];
655
+				} else {
656
+					$new_ticket = clone $orig_ticket;
657
+					// get relations on the $orig_ticket that we need to setup.
658
+					$orig_prices = $orig_ticket->prices();
659
+					$new_ticket->set('TKT_ID', 0);
660
+					$new_ticket->set('TKT_sold', 0);
661
+					$new_ticket->set('TKT_reserved', 0);
662
+					$new_ticket->save(); // make sure new ticket has ID.
663
+					// price relations on new ticket need to be setup.
664
+					foreach ($orig_prices as $orig_price) {
665
+						$new_price = clone $orig_price;
666
+						$new_price->set('PRC_ID', 0);
667
+						$new_price->save();
668
+						$new_ticket->_add_relation_to($new_price, 'Price');
669
+						$new_ticket->save();
670
+					}
671
+
672
+					do_action(
673
+						'AHEE__Extend_Events_Admin_Page___duplicate_event__duplicate_ticket__after',
674
+						$orig_ticket,
675
+						$new_ticket,
676
+						$orig_prices,
677
+						$orig_event,
678
+						$orig_dtt,
679
+						$new_dtt
680
+					);
681
+				}
682
+				// k now we can add the new ticket as a relation to the new datetime
683
+				// and make sure its added to our cached $cloned_tickets array
684
+				// for use with later datetimes that have the same ticket.
685
+				$new_dtt->_add_relation_to($new_ticket, 'Ticket');
686
+				$new_dtt->save();
687
+				$cloned_tickets[ $orig_ticket->ID() ] = $new_ticket;
688
+			}
689
+		}
690
+		// clone taxonomy information
691
+		$taxonomies_to_clone_with = apply_filters(
692
+			'FHEE__Extend_Events_Admin_Page___duplicate_event__taxonomies_to_clone',
693
+			['espresso_event_categories', 'espresso_event_type', 'post_tag']
694
+		);
695
+		// get terms for original event (notice)
696
+		$orig_terms = wp_get_object_terms($orig_event->ID(), $taxonomies_to_clone_with);
697
+		// loop through terms and add them to new event.
698
+		foreach ($orig_terms as $term) {
699
+			wp_set_object_terms($new_event->ID(), $term->term_id, $term->taxonomy, true);
700
+		}
701
+
702
+		// duplicate other core WP_Post items for this event.
703
+		// post thumbnail (feature image).
704
+		$feature_image_id = get_post_thumbnail_id($orig_event->ID());
705
+		if ($feature_image_id) {
706
+			update_post_meta($new_event->ID(), '_thumbnail_id', $feature_image_id);
707
+		}
708
+
709
+		// duplicate page_template setting
710
+		$page_template = get_post_meta($orig_event->ID(), '_wp_page_template', true);
711
+		if ($page_template) {
712
+			update_post_meta($new_event->ID(), '_wp_page_template', $page_template);
713
+		}
714
+
715
+		do_action('AHEE__Extend_Events_Admin_Page___duplicate_event__after', $new_event, $orig_event);
716
+		// now let's redirect to the edit page for this duplicated event if we have a new event id.
717
+		if ($new_event->ID()) {
718
+			$redirect_args = [
719
+				'post'   => $new_event->ID(),
720
+				'action' => 'edit',
721
+			];
722
+			EE_Error::add_success(
723
+				esc_html__(
724
+					'Event successfully duplicated.  Please review the details below and make any necessary edits',
725
+					'event_espresso'
726
+				)
727
+			);
728
+		} else {
729
+			$redirect_args = [
730
+				'action' => 'default',
731
+			];
732
+			EE_Error::add_error(
733
+				esc_html__('Not able to duplicate event.  Something went wrong.', 'event_espresso'),
734
+				__FILE__,
735
+				__FUNCTION__,
736
+				__LINE__
737
+			);
738
+		}
739
+		$this->_redirect_after_action(false, '', '', $redirect_args, true);
740
+	}
741
+
742
+
743
+	/**
744
+	 * Generates output for the import page.
745
+	 *
746
+	 * @throws EE_Error
747
+	 */
748
+	protected function _import_page()
749
+	{
750
+		$title                                      = esc_html__('Import', 'event_espresso');
751
+		$intro                                      = esc_html__(
752
+			'If you have a previously exported Event Espresso 4 information in a Comma Separated Value (CSV) file format, you can upload the file here: ',
753
+			'event_espresso'
754
+		);
755
+
756
+		$form_url = EVENTS_ADMIN_URL;
757
+		$action   = 'import_events';
758
+		$type     = 'csv';
759
+
760
+		$this->_template_args['form'] = EE_Import::instance()->upload_form(
761
+			$title,
762
+			$intro,
763
+			$form_url,
764
+			$action,
765
+			$type
766
+		);
767
+
768
+		$this->_template_args['sample_file_link']   = EE_Admin_Page::add_query_args_and_nonce(
769
+			['action' => 'sample_export_file'],
770
+			$this->_admin_base_url
771
+		);
772
+		$this->_template_args['admin_page_content'] = EEH_Template::display_template(
773
+			EVENTS_CAF_TEMPLATE_PATH . 'import_page.template.php',
774
+			$this->_template_args,
775
+			true
776
+		);
777
+		$this->display_admin_page_with_sidebar();
778
+	}
779
+
780
+
781
+	/**
782
+	 * _import_events
783
+	 * This handles displaying the screen and running imports for importing events.
784
+	 *
785
+	 * @return void
786
+	 * @throws EE_Error
787
+	 */
788
+	protected function _import_events()
789
+	{
790
+		require_once(EE_CLASSES . 'EE_Import.class.php');
791
+		$success = EE_Import::instance()->import();
792
+		$this->_redirect_after_action(
793
+			$success,
794
+			esc_html__('Import File', 'event_espresso'),
795
+			'ran',
796
+			['action' => 'import_page'],
797
+			true
798
+		);
799
+	}
800
+
801
+
802
+	/**
803
+	 * _events_export
804
+	 * Will export all (or just the given event) to a Excel compatible file.
805
+	 *
806
+	 * @access protected
807
+	 * @return void
808
+	 */
809
+	protected function _events_export()
810
+	{
811
+		$EVT_ID = $this->request->getRequestParam('EVT_ID', 0, 'int');
812
+		$EVT_ID = $this->request->getRequestParam('EVT_IDs', $EVT_ID, 'int');
813
+		$this->request->mergeRequestParams(
814
+			[
815
+				'export' => 'report',
816
+				'action' => 'all_event_data',
817
+				'EVT_ID' => $EVT_ID,
818
+			]
819
+		);
820
+		if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
821
+			require_once(EE_CLASSES . 'EE_Export.class.php');
822
+			$EE_Export = EE_Export::instance($this->request->requestParams());
823
+			$EE_Export->export();
824
+		}
825
+	}
826
+
827
+
828
+	/**
829
+	 * handle category exports()
830
+	 *
831
+	 * @return void
832
+	 */
833
+	protected function _categories_export()
834
+	{
835
+		$EVT_ID = $this->request->getRequestParam('EVT_CAT_ID', 0, 'int');
836
+		$this->request->mergeRequestParams(
837
+			[
838
+				'export' => 'report',
839
+				'action' => 'categories',
840
+				'EVT_ID' => $EVT_ID,
841
+			]
842
+		);
843
+		if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
844
+			require_once(EE_CLASSES . 'EE_Export.class.php');
845
+			$EE_Export = EE_Export::instance($this->request->requestParams());
846
+			$EE_Export->export();
847
+		}
848
+	}
849
+
850
+
851
+	/**
852
+	 * Creates a sample CSV file for importing
853
+	 */
854
+	protected function _sample_export_file()
855
+	{
856
+		$EE_Export = EE_Export::instance();
857
+		if ($EE_Export instanceof EE_Export) {
858
+			$EE_Export->export();
859
+		}
860
+	}
861
+
862
+
863
+	/*************        Template Settings        *************/
864
+	/**
865
+	 * Generates template settings page output
866
+	 *
867
+	 * @throws DomainException
868
+	 * @throws EE_Error
869
+	 * @throws InvalidArgumentException
870
+	 * @throws InvalidDataTypeException
871
+	 * @throws InvalidInterfaceException
872
+	 */
873
+	protected function _template_settings()
874
+	{
875
+		$this->_template_args['values'] = $this->_yes_no_values;
876
+		/**
877
+		 * Note leaving this filter in for backward compatibility this was moved in 4.6.x
878
+		 * from General_Settings_Admin_Page to here.
879
+		 */
880
+		$this->_template_args = apply_filters(
881
+			'FHEE__General_Settings_Admin_Page__template_settings__template_args',
882
+			$this->_template_args
883
+		);
884
+		$this->_set_add_edit_form_tags('update_template_settings');
885
+		$this->_set_publish_post_box_vars(null, false, false, null, false);
886
+		$this->_template_args['admin_page_content'] = EEH_Template::display_template(
887
+			EVENTS_CAF_TEMPLATE_PATH . 'template_settings.template.php',
888
+			$this->_template_args,
889
+			true
890
+		);
891
+		$this->display_admin_page_with_sidebar();
892
+	}
893
+
894
+
895
+	/**
896
+	 * Handler for updating template settings.
897
+	 *
898
+	 * @throws EE_Error
899
+	 */
900
+	protected function _update_template_settings()
901
+	{
902
+		/**
903
+		 * Note leaving this filter in for backward compatibility this was moved in 4.6.x
904
+		 * from General_Settings_Admin_Page to here.
905
+		 */
906
+		EE_Registry::instance()->CFG->template_settings = apply_filters(
907
+			'FHEE__General_Settings_Admin_Page__update_template_settings__data',
908
+			EE_Registry::instance()->CFG->template_settings,
909
+			$this->request->requestParams()
910
+		);
911
+		// update custom post type slugs and detect if we need to flush rewrite rules
912
+		$old_slug = EE_Registry::instance()->CFG->core->event_cpt_slug;
913
+
914
+		$event_cpt_slug = $this->request->getRequestParam('event_cpt_slug');
915
+
916
+		EE_Registry::instance()->CFG->core->event_cpt_slug = $event_cpt_slug
917
+			? EE_Registry::instance()->CFG->core->event_cpt_slug
918
+			: EEH_URL::slugify($event_cpt_slug, 'events');
919
+
920
+		$what    = esc_html__('Template Settings', 'event_espresso');
921
+		$success = $this->_update_espresso_configuration(
922
+			$what,
923
+			EE_Registry::instance()->CFG->template_settings,
924
+			__FILE__,
925
+			__FUNCTION__,
926
+			__LINE__
927
+		);
928
+		if (EE_Registry::instance()->CFG->core->event_cpt_slug !== $old_slug) {
929
+			/** @var EventEspresso\core\domain\services\custom_post_types\RewriteRules $rewrite_rules */
930
+			$rewrite_rules = LoaderFactory::getLoader()->getShared(
931
+				'EventEspresso\core\domain\services\custom_post_types\RewriteRules'
932
+			);
933
+			$rewrite_rules->flush();
934
+		}
935
+		$this->_redirect_after_action($success, $what, 'updated', ['action' => 'template_settings']);
936
+	}
937
+
938
+
939
+	/**
940
+	 * _premium_event_editor_meta_boxes
941
+	 * add all metaboxes related to the event_editor
942
+	 *
943
+	 * @access protected
944
+	 * @return void
945
+	 * @throws EE_Error
946
+	 * @throws ReflectionException
947
+	 */
948
+	protected function _premium_event_editor_meta_boxes()
949
+	{
950
+		$this->verify_cpt_object();
951
+		// check if the new EDTR reg options meta box is being used, and if so, don't load the legacy version
952
+		if (
953
+			! $this->admin_config->useAdvancedEditor()
954
+			|| ! $this->feature->allowed('use_reg_options_meta_box')
955
+		) {
956
+			add_meta_box(
957
+				'espresso_event_editor_event_options',
958
+				esc_html__('Event Registration Options', 'event_espresso'),
959
+				[$this, 'registration_options_meta_box'],
960
+				$this->page_slug,
961
+				'side',
962
+				'core'
963
+			);
964
+		}
965
+	}
966
+
967
+
968
+	/**
969
+	 * override caf metabox
970
+	 *
971
+	 * @return void
972
+	 * @throws EE_Error
973
+	 * @throws ReflectionException
974
+	 */
975
+	public function registration_options_meta_box()
976
+	{
977
+		$yes_no_values = [
978
+			['id' => true, 'text' => esc_html__('Yes', 'event_espresso')],
979
+			['id' => false, 'text' => esc_html__('No', 'event_espresso')],
980
+		];
981
+
982
+		$default_reg_status_values = EEM_Registration::reg_status_array(
983
+			[
984
+				EEM_Registration::status_id_cancelled,
985
+				EEM_Registration::status_id_declined,
986
+				EEM_Registration::status_id_incomplete,
987
+				EEM_Registration::status_id_wait_list,
988
+			],
989
+			true
990
+		);
991
+
992
+		$template_args['active_status']    = $this->_cpt_model_obj->pretty_active_status(false);
993
+		$template_args['_event']           = $this->_cpt_model_obj;
994
+		$template_args['additional_limit'] = $this->_cpt_model_obj->additional_limit();
995
+
996
+		$template_args['default_registration_status']     = EEH_Form_Fields::select_input(
997
+			'default_reg_status',
998
+			$default_reg_status_values,
999
+			$this->_cpt_model_obj->default_registration_status()
1000
+		);
1001
+		$template_args['display_description']             = EEH_Form_Fields::select_input(
1002
+			'display_desc',
1003
+			$yes_no_values,
1004
+			$this->_cpt_model_obj->display_description()
1005
+		);
1006
+		$template_args['display_ticket_selector']         = EEH_Form_Fields::select_input(
1007
+			'display_ticket_selector',
1008
+			$yes_no_values,
1009
+			$this->_cpt_model_obj->display_ticket_selector(),
1010
+			'',
1011
+			'',
1012
+			false
1013
+		);
1014
+		$template_args['EVT_default_registration_status'] = EEH_Form_Fields::select_input(
1015
+			'EVT_default_registration_status',
1016
+			$default_reg_status_values,
1017
+			$this->_cpt_model_obj->default_registration_status()
1018
+		);
1019
+		$template_args['additional_registration_options'] = apply_filters(
1020
+			'FHEE__Events_Admin_Page__registration_options_meta_box__additional_registration_options',
1021
+			'',
1022
+			$template_args,
1023
+			$yes_no_values,
1024
+			$default_reg_status_values
1025
+		);
1026
+		EEH_Template::display_template(
1027
+			EVENTS_CAF_TEMPLATE_PATH . 'event_registration_options.template.php',
1028
+			$template_args
1029
+		);
1030
+	}
1031
+
1032
+
1033
+
1034
+	/**
1035
+	 * wp_list_table_mods for caf
1036
+	 * ============================
1037
+	 */
1038
+	/**
1039
+	 * hook into list table filters and provide filters for caffeinated list table
1040
+	 *
1041
+	 * @param array $old_filters    any existing filters present
1042
+	 * @param array $list_table_obj the list table object
1043
+	 * @return array                  new filters
1044
+	 * @throws EE_Error
1045
+	 * @throws ReflectionException
1046
+	 */
1047
+	public function list_table_filters($old_filters, $list_table_obj)
1048
+	{
1049
+		$filters = [];
1050
+		// first month/year filters
1051
+		$filters[] = $this->espresso_event_months_dropdown();
1052
+		$status    = $this->request->getRequestParam('status');
1053
+		// active status dropdown
1054
+		if ($status !== 'draft') {
1055
+			$filters[] = $this->active_status_dropdown($this->request->getRequestParam('active_status'));
1056
+			$filters[] = $this->venuesDropdown($this->request->getRequestParam('venue'));
1057
+		}
1058
+		// category filter
1059
+		$filters[] = $this->category_dropdown();
1060
+		return array_merge($old_filters, $filters);
1061
+	}
1062
+
1063
+
1064
+	/**
1065
+	 * espresso_event_months_dropdown
1066
+	 *
1067
+	 * @access public
1068
+	 * @return string                dropdown listing month/year selections for events.
1069
+	 * @throws EE_Error
1070
+	 */
1071
+	public function espresso_event_months_dropdown()
1072
+	{
1073
+		// what we need to do is get all PRIMARY datetimes for all events to filter on.
1074
+		// Note we need to include any other filters that are set!
1075
+		return EEH_Form_Fields::generate_event_months_dropdown(
1076
+			$this->request->getRequestParam('month_range'),
1077
+			$this->request->getRequestParam('status'),
1078
+			$this->request->getRequestParam('EVT_CAT', 0, 'int'),
1079
+			$this->request->getRequestParam('active_status')
1080
+		);
1081
+	}
1082
+
1083
+
1084
+	/**
1085
+	 * returns a list of "active" statuses on the event
1086
+	 *
1087
+	 * @param string $current_value whatever the current active status is
1088
+	 * @return string
1089
+	 */
1090
+	public function active_status_dropdown($current_value = '')
1091
+	{
1092
+		$select_name = 'active_status';
1093
+		$values      = [
1094
+			'none'     => esc_html__('Show Active/Inactive', 'event_espresso'),
1095
+			'active'   => esc_html__('Active', 'event_espresso'),
1096
+			'upcoming' => esc_html__('Upcoming', 'event_espresso'),
1097
+			'expired'  => esc_html__('Expired', 'event_espresso'),
1098
+			'inactive' => esc_html__('Inactive', 'event_espresso'),
1099
+		];
1100
+
1101
+		return EEH_Form_Fields::select_input($select_name, $values, $current_value, '', 'wide');
1102
+	}
1103
+
1104
+
1105
+	/**
1106
+	 * returns a list of "venues"
1107
+	 *
1108
+	 * @param string $current_value whatever the current active status is
1109
+	 * @return string
1110
+	 * @throws EE_Error
1111
+	 * @throws ReflectionException
1112
+	 */
1113
+	protected function venuesDropdown($current_value = '')
1114
+	{
1115
+		$values = ['' => esc_html__('All Venues', 'event_espresso')];
1116
+		// populate the list of venues.
1117
+		$venues = EEM_Venue::instance()->get_all(['order_by' => ['VNU_name' => 'ASC']]);
1118
+
1119
+		foreach ($venues as $venue) {
1120
+			$values[ $venue->ID() ] = $venue->name();
1121
+		}
1122
+
1123
+		return EEH_Form_Fields::select_input('venue', $values, $current_value, '', 'wide');
1124
+	}
1125
+
1126
+
1127
+	/**
1128
+	 * output a dropdown of the categories for the category filter on the event admin list table
1129
+	 *
1130
+	 * @access  public
1131
+	 * @return string html
1132
+	 * @throws EE_Error
1133
+	 * @throws ReflectionException
1134
+	 */
1135
+	public function category_dropdown()
1136
+	{
1137
+		return EEH_Form_Fields::generate_event_category_dropdown(
1138
+			$this->request->getRequestParam('EVT_CAT', -1, 'int')
1139
+		);
1140
+	}
1141
+
1142
+
1143
+	/**
1144
+	 * get total number of events today
1145
+	 *
1146
+	 * @access public
1147
+	 * @return int
1148
+	 * @throws EE_Error
1149
+	 * @throws InvalidArgumentException
1150
+	 * @throws InvalidDataTypeException
1151
+	 * @throws InvalidInterfaceException
1152
+	 */
1153
+	public function total_events_today()
1154
+	{
1155
+		$start = EEM_Datetime::instance()->convert_datetime_for_query(
1156
+			'DTT_EVT_start',
1157
+			date('Y-m-d') . ' 00:00:00',
1158
+			'Y-m-d H:i:s',
1159
+			'UTC'
1160
+		);
1161
+		$end   = EEM_Datetime::instance()->convert_datetime_for_query(
1162
+			'DTT_EVT_start',
1163
+			date('Y-m-d') . ' 23:59:59',
1164
+			'Y-m-d H:i:s',
1165
+			'UTC'
1166
+		);
1167
+		$where = [
1168
+			'Datetime.DTT_EVT_start' => ['BETWEEN', [$start, $end]],
1169
+		];
1170
+		return EEM_Event::instance()->count([$where, 'caps' => 'read_admin'], 'EVT_ID', true);
1171
+	}
1172
+
1173
+
1174
+	/**
1175
+	 * get total number of events this month
1176
+	 *
1177
+	 * @access public
1178
+	 * @return int
1179
+	 * @throws EE_Error
1180
+	 * @throws InvalidArgumentException
1181
+	 * @throws InvalidDataTypeException
1182
+	 * @throws InvalidInterfaceException
1183
+	 */
1184
+	public function total_events_this_month()
1185
+	{
1186
+		// Dates
1187
+		$this_year_r     = date('Y');
1188
+		$this_month_r    = date('m');
1189
+		$days_this_month = date('t');
1190
+		$start           = EEM_Datetime::instance()->convert_datetime_for_query(
1191
+			'DTT_EVT_start',
1192
+			$this_year_r . '-' . $this_month_r . '-01 00:00:00',
1193
+			'Y-m-d H:i:s',
1194
+			'UTC'
1195
+		);
1196
+		$end             = EEM_Datetime::instance()->convert_datetime_for_query(
1197
+			'DTT_EVT_start',
1198
+			$this_year_r . '-' . $this_month_r . '-' . $days_this_month . ' 23:59:59',
1199
+			'Y-m-d H:i:s',
1200
+			'UTC'
1201
+		);
1202
+		$where           = [
1203
+			'Datetime.DTT_EVT_start' => ['BETWEEN', [$start, $end]],
1204
+		];
1205
+		return EEM_Event::instance()->count([$where, 'caps' => 'read_admin'], 'EVT_ID', true);
1206
+	}
1207
+
1208
+
1209
+	/** DEFAULT TICKETS STUFF **/
1210
+
1211
+	/**
1212
+	 * Output default tickets list table view.
1213
+	 *
1214
+	 * @throws EE_Error
1215
+	 */
1216
+	public function _tickets_overview_list_table()
1217
+	{
1218
+		if (
1219
+			$this->admin_config->useAdvancedEditor()
1220
+			&& $this->feature->allowed('use_default_ticket_manager')
1221
+		) {
1222
+			// check if the new EDTR reg options meta box is being used, and if so, don't load the legacy version
1223
+			$this->_template_args['admin_page_content'] = EEH_Template::display_template(
1224
+				EVENTS_CAF_TEMPLATE_PATH . 'default_tickets_moved_notice.template.php',
1225
+				[],
1226
+				true
1227
+			);
1228
+			$this->display_admin_page_with_no_sidebar();
1229
+		} else {
1230
+			$this->_search_btn_label = esc_html__('Tickets', 'event_espresso');
1231
+			$this->display_admin_list_table_page_with_no_sidebar();
1232
+		}
1233
+	}
1234
+
1235
+
1236
+	/**
1237
+	 * @param int  $per_page
1238
+	 * @param bool $count
1239
+	 * @param bool $trashed
1240
+	 * @return EE_Soft_Delete_Base_Class[]|int
1241
+	 * @throws EE_Error
1242
+	 */
1243
+	public function get_default_tickets($per_page = 10, $count = false, $trashed = false)
1244
+	{
1245
+		$orderby = $this->request->getRequestParam('orderby', 'TKT_name');
1246
+		$order   = $this->request->getRequestParam('order', 'ASC');
1247
+		switch ($orderby) {
1248
+			case 'TKT_name':
1249
+				$orderby = ['TKT_name' => $order];
1250
+				break;
1251
+			case 'TKT_price':
1252
+				$orderby = ['TKT_price' => $order];
1253
+				break;
1254
+			case 'TKT_uses':
1255
+				$orderby = ['TKT_uses' => $order];
1256
+				break;
1257
+			case 'TKT_min':
1258
+				$orderby = ['TKT_min' => $order];
1259
+				break;
1260
+			case 'TKT_max':
1261
+				$orderby = ['TKT_max' => $order];
1262
+				break;
1263
+			case 'TKT_qty':
1264
+				$orderby = ['TKT_qty' => $order];
1265
+				break;
1266
+		}
1267
+
1268
+		$current_page = $this->request->getRequestParam('paged', 1, 'int');
1269
+		$per_page     = $this->request->getRequestParam('perpage', $per_page, 'int');
1270
+		$offset       = ($current_page - 1) * $per_page;
1271
+
1272
+		$where = [
1273
+			'TKT_is_default' => 1,
1274
+			'TKT_deleted'    => $trashed,
1275
+		];
1276
+
1277
+		$search_term = $this->request->getRequestParam('s');
1278
+		if ($search_term) {
1279
+			$search_term = '%' . $search_term . '%';
1280
+			$where['OR'] = [
1281
+				'TKT_name'        => ['LIKE', $search_term],
1282
+				'TKT_description' => ['LIKE', $search_term],
1283
+			];
1284
+		}
1285
+
1286
+		return $count
1287
+			? EEM_Ticket::instance()->count_deleted_and_undeleted([$where])
1288
+			: EEM_Ticket::instance()->get_all_deleted_and_undeleted(
1289
+				[
1290
+					$where,
1291
+					'order_by' => $orderby,
1292
+					'limit'    => [$offset, $per_page],
1293
+					'group_by' => 'TKT_ID',
1294
+				]
1295
+			);
1296
+	}
1297
+
1298
+
1299
+	/**
1300
+	 * @param bool $trash
1301
+	 * @throws EE_Error
1302
+	 * @throws InvalidArgumentException
1303
+	 * @throws InvalidDataTypeException
1304
+	 * @throws InvalidInterfaceException
1305
+	 */
1306
+	protected function _trash_or_restore_ticket($trash = false)
1307
+	{
1308
+		$success = 1;
1309
+		$TKT     = EEM_Ticket::instance();
1310
+		// checkboxes?
1311
+		$checkboxes = $this->request->getRequestParam('checkbox', [], 'int', true);
1312
+		if (! empty($checkboxes)) {
1313
+			// if array has more than one element then success message should be plural
1314
+			$success = count($checkboxes) > 1 ? 2 : 1;
1315
+			// cycle thru the boxes
1316
+			while (list($TKT_ID, $value) = each($checkboxes)) {
1317
+				if ($trash) {
1318
+					if (! $TKT->delete_by_ID($TKT_ID)) {
1319
+						$success = 0;
1320
+					}
1321
+				} elseif (! $TKT->restore_by_ID($TKT_ID)) {
1322
+					$success = 0;
1323
+				}
1324
+			}
1325
+		} else {
1326
+			// grab single id and trash
1327
+			$TKT_ID = $this->request->getRequestParam('TKT_ID', 0, 'int');
1328
+			if ($trash) {
1329
+				if (! $TKT->delete_by_ID($TKT_ID)) {
1330
+					$success = 0;
1331
+				}
1332
+			} elseif (! $TKT->restore_by_ID($TKT_ID)) {
1333
+				$success = 0;
1334
+			}
1335
+		}
1336
+		$action_desc = $trash ? 'moved to the trash' : 'restored';
1337
+		$query_args  = [
1338
+			'action' => 'ticket_list_table',
1339
+			'status' => $trash ? '' : 'trashed',
1340
+		];
1341
+		$this->_redirect_after_action($success, esc_html__('Tickets', 'event_espresso'), $action_desc, $query_args);
1342
+	}
1343
+
1344
+
1345
+	/**
1346
+	 * Handles trashing default ticket.
1347
+	 *
1348
+	 * @throws EE_Error
1349
+	 * @throws ReflectionException
1350
+	 */
1351
+	protected function _delete_ticket()
1352
+	{
1353
+		$success = 1;
1354
+		// checkboxes?
1355
+		$checkboxes = $this->request->getRequestParam('checkbox', [], 'int', true);
1356
+		if (! empty($checkboxes)) {
1357
+			// if array has more than one element then success message should be plural
1358
+			$success = count($checkboxes) > 1 ? 2 : 1;
1359
+			// cycle thru the boxes
1360
+			while (list($TKT_ID, $value) = each($checkboxes)) {
1361
+				// delete
1362
+				if (! $this->_delete_the_ticket($TKT_ID)) {
1363
+					$success = 0;
1364
+				}
1365
+			}
1366
+		} else {
1367
+			// grab single id and trash
1368
+			$TKT_ID = $this->request->getRequestParam('TKT_ID', 0, 'int');
1369
+			if (! $this->_delete_the_ticket($TKT_ID)) {
1370
+				$success = 0;
1371
+			}
1372
+		}
1373
+		$action_desc = 'deleted';
1374
+		$query_args  = [
1375
+			'action' => 'ticket_list_table',
1376
+			'status' => 'trashed',
1377
+		];
1378
+		// fail safe.  If the default ticket count === 1 then we need to redirect to event overview.
1379
+		if (
1380
+			EEM_Ticket::instance()->count_deleted_and_undeleted(
1381
+				[['TKT_is_default' => 1]],
1382
+				'TKT_ID',
1383
+				true
1384
+			)
1385
+		) {
1386
+			$query_args = [];
1387
+		}
1388
+		$this->_redirect_after_action($success, esc_html__('Tickets', 'event_espresso'), $action_desc, $query_args);
1389
+	}
1390
+
1391
+
1392
+	/**
1393
+	 * @param int $TKT_ID
1394
+	 * @return bool|int
1395
+	 * @throws EE_Error
1396
+	 * @throws ReflectionException
1397
+	 */
1398
+	protected function _delete_the_ticket($TKT_ID)
1399
+	{
1400
+		$ticket = EEM_Ticket::instance()->get_one_by_ID($TKT_ID);
1401
+		if (! $ticket instanceof EE_Ticket) {
1402
+			return false;
1403
+		}
1404
+		$ticket->_remove_relations('Datetime');
1405
+		// delete all related prices first
1406
+		$ticket->delete_related_permanently('Price');
1407
+		return $ticket->delete_permanently();
1408
+	}
1409 1409
 }
Please login to merge, or discard this patch.
Spacing   +63 added lines, -63 removed lines patch added patch discarded remove patch
@@ -36,10 +36,10 @@  discard block
 block discarded – undo
36 36
      */
37 37
     public function __construct($routing = true)
38 38
     {
39
-        if (! defined('EVENTS_CAF_TEMPLATE_PATH')) {
40
-            define('EVENTS_CAF_TEMPLATE_PATH', EE_CORE_CAF_ADMIN_EXTEND . 'events/templates/');
41
-            define('EVENTS_CAF_ASSETS', EE_CORE_CAF_ADMIN_EXTEND . 'events/assets/');
42
-            define('EVENTS_CAF_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL . 'events/assets/');
39
+        if ( ! defined('EVENTS_CAF_TEMPLATE_PATH')) {
40
+            define('EVENTS_CAF_TEMPLATE_PATH', EE_CORE_CAF_ADMIN_EXTEND.'events/templates/');
41
+            define('EVENTS_CAF_ASSETS', EE_CORE_CAF_ADMIN_EXTEND.'events/assets/');
42
+            define('EVENTS_CAF_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL.'events/assets/');
43 43
         }
44 44
         parent::__construct($routing);
45 45
         $this->admin_config = $this->loader->getShared('EE_Admin_Config');
@@ -53,7 +53,7 @@  discard block
 block discarded – undo
53 53
      */
54 54
     protected function _extend_page_config()
55 55
     {
56
-        $this->_admin_base_path = EE_CORE_CAF_ADMIN_EXTEND . 'events';
56
+        $this->_admin_base_path = EE_CORE_CAF_ADMIN_EXTEND.'events';
57 57
         // is there a evt_id in the request?
58 58
         $EVT_ID             = $this->request->getRequestParam('EVT_ID', 0, 'int');
59 59
         $EVT_ID             = $this->request->getRequestParam('post', $EVT_ID, 'int');
@@ -151,7 +151,7 @@  discard block
 block discarded – undo
151 151
                     'noheader'   => true,
152 152
                 ],
153 153
             ];
154
-            $new_page_routes           = array_merge($new_page_routes, $legacy_editor_page_routes);
154
+            $new_page_routes = array_merge($new_page_routes, $legacy_editor_page_routes);
155 155
         }
156 156
 
157 157
         $this->_page_routes = array_merge($this->_page_routes, $new_page_routes);
@@ -193,7 +193,7 @@  discard block
 block discarded – undo
193 193
             // 'help_tour'     => ['Templates_Help_Tour'],
194 194
             'require_nonce' => false,
195 195
         ];
196
-        $this->_page_config                   = array_merge($this->_page_config, $new_page_config);
196
+        $this->_page_config = array_merge($this->_page_config, $new_page_config);
197 197
         // add filters and actions
198 198
         // modifying _views
199 199
         add_filter(
@@ -262,7 +262,7 @@  discard block
 block discarded – undo
262 262
             EE_Registry::$i18n_js_strings,
263 263
             [
264 264
                 'image_confirm'          => esc_html__(
265
-                    'Do you really want to delete this image? Please remember to update your event to complete the removal.',
265
+                    'Do you really want to delete this image ? Please remember to update your event to complete the removal.',
266 266
                     'event_espresso'
267 267
                 ),
268 268
                 'event_starts_on'        => esc_html__('Event Starts on', 'event_espresso'),
@@ -305,13 +305,13 @@  discard block
 block discarded – undo
305 305
                 $this->_admin_base_url
306 306
             );
307 307
             $title  = esc_attr__('Duplicate Event', 'event_espresso');
308
-            $return .= '<a href="'
308
+            $return .= '<a href = "'
309 309
                        . $href
310
-                       . '" title="'
310
+                       . '" title = "'
311 311
                        . $title
312
-                       . '" id="ee-duplicate-event-button" class="button button-small"  value="duplicate_event">'
312
+                       . '" id = "ee-duplicate-event-button" class = "button button-small"  value = "duplicate_event" > '
313 313
                        . $title
314
-                       . '</a>';
314
+                       . '< / a > ';
315 315
         }
316 316
         return $return;
317 317
     }
@@ -351,18 +351,18 @@  discard block
 block discarded – undo
351 351
     {
352 352
         if (! $this->admin_config->useAdvancedEditor()) {
353 353
             wp_register_script(
354
-                'ee-event-editor-heartbeat',
355
-                EVENTS_CAF_ASSETS_URL . 'event-editor-heartbeat.js',
354
+                'ee - event - editor - heartbeat',
355
+                EVENTS_CAF_ASSETS_URL . 'event - editor - heartbeat.js',
356 356
                 ['ee_admin_js', 'heartbeat'],
357 357
                 EVENT_ESPRESSO_VERSION,
358 358
                 true
359 359
             );
360
-            wp_enqueue_script('ee-accounting');
361
-            wp_enqueue_script('ee-event-editor-heartbeat');
360
+            wp_enqueue_script('ee - accounting');
361
+            wp_enqueue_script('ee - event - editor - heartbeat');
362 362
         }
363 363
         wp_enqueue_script('event_editor_js');
364 364
         // styles
365
-        wp_enqueue_style('espresso-ui-theme');
365
+        wp_enqueue_style('espresso - ui - theme');
366 366
     }
367 367
 
368 368
 
@@ -473,11 +473,11 @@  discard block
 block discarded – undo
473 473
                 'EVT_ID' => $event->ID(),
474 474
             ];
475 475
             $reports_link       = EE_Admin_Page::add_query_args_and_nonce($reports_query_args, REG_ADMIN_URL);
476
-            $action_links[]     = '<a href="'
476
+            $action_links[]     = '<a href = "'
477 477
                                   . $reports_link
478
-                                  . '" title="'
478
+                                  . '" title = "'
479 479
                                   . esc_attr__('View Report', 'event_espresso')
480
-                                  . '"><div class="dashicons dashicons-chart-bar"></div></a>'
480
+                                  . '"> < div class = "dashicons dashicons-chart-bar" > < / div > < / a > '
481 481
                                   . "\n\t";
482 482
         }
483 483
         if (EE_Registry::instance()->CAP->current_user_can('ee_read_global_messages', 'view_filtered_messages')) {
@@ -505,7 +505,7 @@  discard block
 block discarded – undo
505 505
             )
506 506
         ) {
507 507
             $items['reports'] = [
508
-                'class' => 'dashicons dashicons-chart-bar',
508
+                'class' => 'dashicons dashicons - chart - bar',
509 509
                 'desc'  => esc_html__('Event Reports', 'event_espresso'),
510 510
             ];
511 511
         }
@@ -539,9 +539,9 @@  discard block
 block discarded – undo
539 539
     protected function _duplicate_event()
540 540
     {
541 541
         // first make sure the ID for the event is in the request.
542
-        //  If it isn't then we need to bail and redirect back to overview list table (cause how did we get here?)
542
+        //  If it isn't then we need to bail and redirect back to overview list table(cause how did we get here ?)
543 543
         $EVT_ID = $this->request->getRequestParam('EVT_ID', 0, 'int');
544
-        if (! $EVT_ID) {
544
+        if ( ! $EVT_ID) {
545 545
             EE_Error::add_error(
546 546
                 esc_html__(
547 547
                     'In order to duplicate an event an Event ID is required.  None was given.',
@@ -556,7 +556,7 @@  discard block
 block discarded – undo
556 556
         }
557 557
         // k we've got EVT_ID so let's use that to get the event we'll duplicate
558 558
         $orig_event = EEM_Event::instance()->get_one_by_ID($EVT_ID);
559
-        if (! $orig_event instanceof EE_Event) {
559
+        if ( ! $orig_event instanceof EE_Event) {
560 560
             throw new EE_Error(
561 561
                 sprintf(
562 562
                     esc_html__('An EE_Event object could not be retrieved for the given ID (%s)', 'event_espresso'),
@@ -572,7 +572,7 @@  discard block
 block discarded – undo
572 572
         $orig_ven = $orig_event->get_many_related('Venue');
573 573
         // reset the ID and modify other details to make it clear this is a dupe
574 574
         $new_event->set('EVT_ID', 0);
575
-        $new_name = $new_event->name() . ' ' . esc_html__('**DUPLICATE**', 'event_espresso');
575
+        $new_name = $new_event->name().' '.esc_html__('**DUPLICATE**', 'event_espresso');
576 576
         $new_event->set('EVT_name', $new_name);
577 577
         $new_event->set(
578 578
             'EVT_slug',
@@ -601,7 +601,7 @@  discard block
 block discarded – undo
601 601
             'Question_Group',
602 602
             [['Event_Question_Group.EQG_primary' => true]]
603 603
         );
604
-        if (! empty($orig_primary_qgs)) {
604
+        if ( ! empty($orig_primary_qgs)) {
605 605
             foreach ($orig_primary_qgs as $obj) {
606 606
                 if ($obj instanceof EE_Question_Group) {
607 607
                     $new_event->_add_relation_to($obj, 'Question_Group', ['EQG_primary' => true]);
@@ -613,7 +613,7 @@  discard block
 block discarded – undo
613 613
             'Question_Group',
614 614
             [['Event_Question_Group.EQG_additional' => true]]
615 615
         );
616
-        if (! empty($orig_additional_qgs)) {
616
+        if ( ! empty($orig_additional_qgs)) {
617 617
             foreach ($orig_additional_qgs as $obj) {
618 618
                 if ($obj instanceof EE_Question_Group) {
619 619
                     $new_event->_add_relation_to($obj, 'Question_Group', ['EQG_additional' => true]);
@@ -626,7 +626,7 @@  discard block
 block discarded – undo
626 626
         // k now that we have the new event saved we can loop through the datetimes and start adding relations.
627 627
         $cloned_tickets = [];
628 628
         foreach ($orig_datetimes as $orig_dtt) {
629
-            if (! $orig_dtt instanceof EE_Datetime) {
629
+            if ( ! $orig_dtt instanceof EE_Datetime) {
630 630
                 continue;
631 631
             }
632 632
             $new_dtt      = clone $orig_dtt;
@@ -641,7 +641,7 @@  discard block
 block discarded – undo
641 641
             // now let's get the ticket relations setup.
642 642
             foreach ((array) $orig_tickets as $orig_ticket) {
643 643
                 // it's possible a datetime will have no tickets so let's verify we HAVE a ticket first.
644
-                if (! $orig_ticket instanceof EE_Ticket) {
644
+                if ( ! $orig_ticket instanceof EE_Ticket) {
645 645
                     continue;
646 646
                 }
647 647
                 // is this ticket archived?  If it is then let's skip
@@ -650,8 +650,8 @@  discard block
 block discarded – undo
650 650
                 }
651 651
                 // does this original ticket already exist in the clone_tickets cache?
652 652
                 //  If so we'll just use the new ticket from it.
653
-                if (isset($cloned_tickets[ $orig_ticket->ID() ])) {
654
-                    $new_ticket = $cloned_tickets[ $orig_ticket->ID() ];
653
+                if (isset($cloned_tickets[$orig_ticket->ID()])) {
654
+                    $new_ticket = $cloned_tickets[$orig_ticket->ID()];
655 655
                 } else {
656 656
                     $new_ticket = clone $orig_ticket;
657 657
                     // get relations on the $orig_ticket that we need to setup.
@@ -684,7 +684,7 @@  discard block
 block discarded – undo
684 684
                 // for use with later datetimes that have the same ticket.
685 685
                 $new_dtt->_add_relation_to($new_ticket, 'Ticket');
686 686
                 $new_dtt->save();
687
-                $cloned_tickets[ $orig_ticket->ID() ] = $new_ticket;
687
+                $cloned_tickets[$orig_ticket->ID()] = $new_ticket;
688 688
             }
689 689
         }
690 690
         // clone taxonomy information
@@ -765,12 +765,12 @@  discard block
 block discarded – undo
765 765
             $type
766 766
         );
767 767
 
768
-        $this->_template_args['sample_file_link']   = EE_Admin_Page::add_query_args_and_nonce(
768
+        $this->_template_args['sample_file_link'] = EE_Admin_Page::add_query_args_and_nonce(
769 769
             ['action' => 'sample_export_file'],
770 770
             $this->_admin_base_url
771 771
         );
772 772
         $this->_template_args['admin_page_content'] = EEH_Template::display_template(
773
-            EVENTS_CAF_TEMPLATE_PATH . 'import_page.template.php',
773
+            EVENTS_CAF_TEMPLATE_PATH.'import_page.template.php',
774 774
             $this->_template_args,
775 775
             true
776 776
         );
@@ -787,7 +787,7 @@  discard block
 block discarded – undo
787 787
      */
788 788
     protected function _import_events()
789 789
     {
790
-        require_once(EE_CLASSES . 'EE_Import.class.php');
790
+        require_once(EE_CLASSES.'EE_Import.class.php');
791 791
         $success = EE_Import::instance()->import();
792 792
         $this->_redirect_after_action(
793 793
             $success,
@@ -817,8 +817,8 @@  discard block
 block discarded – undo
817 817
                 'EVT_ID' => $EVT_ID,
818 818
             ]
819 819
         );
820
-        if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
821
-            require_once(EE_CLASSES . 'EE_Export.class.php');
820
+        if (is_readable(EE_CLASSES.'EE_Export.class.php')) {
821
+            require_once(EE_CLASSES.'EE_Export.class.php');
822 822
             $EE_Export = EE_Export::instance($this->request->requestParams());
823 823
             $EE_Export->export();
824 824
         }
@@ -840,8 +840,8 @@  discard block
 block discarded – undo
840 840
                 'EVT_ID' => $EVT_ID,
841 841
             ]
842 842
         );
843
-        if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
844
-            require_once(EE_CLASSES . 'EE_Export.class.php');
843
+        if (is_readable(EE_CLASSES.'EE_Export.class.php')) {
844
+            require_once(EE_CLASSES.'EE_Export.class.php');
845 845
             $EE_Export = EE_Export::instance($this->request->requestParams());
846 846
             $EE_Export->export();
847 847
         }
@@ -884,7 +884,7 @@  discard block
 block discarded – undo
884 884
         $this->_set_add_edit_form_tags('update_template_settings');
885 885
         $this->_set_publish_post_box_vars(null, false, false, null, false);
886 886
         $this->_template_args['admin_page_content'] = EEH_Template::display_template(
887
-            EVENTS_CAF_TEMPLATE_PATH . 'template_settings.template.php',
887
+            EVENTS_CAF_TEMPLATE_PATH.'template_settings.template.php',
888 888
             $this->_template_args,
889 889
             true
890 890
         );
@@ -993,17 +993,17 @@  discard block
 block discarded – undo
993 993
         $template_args['_event']           = $this->_cpt_model_obj;
994 994
         $template_args['additional_limit'] = $this->_cpt_model_obj->additional_limit();
995 995
 
996
-        $template_args['default_registration_status']     = EEH_Form_Fields::select_input(
996
+        $template_args['default_registration_status'] = EEH_Form_Fields::select_input(
997 997
             'default_reg_status',
998 998
             $default_reg_status_values,
999 999
             $this->_cpt_model_obj->default_registration_status()
1000 1000
         );
1001
-        $template_args['display_description']             = EEH_Form_Fields::select_input(
1001
+        $template_args['display_description'] = EEH_Form_Fields::select_input(
1002 1002
             'display_desc',
1003 1003
             $yes_no_values,
1004 1004
             $this->_cpt_model_obj->display_description()
1005 1005
         );
1006
-        $template_args['display_ticket_selector']         = EEH_Form_Fields::select_input(
1006
+        $template_args['display_ticket_selector'] = EEH_Form_Fields::select_input(
1007 1007
             'display_ticket_selector',
1008 1008
             $yes_no_values,
1009 1009
             $this->_cpt_model_obj->display_ticket_selector(),
@@ -1024,7 +1024,7 @@  discard block
 block discarded – undo
1024 1024
             $default_reg_status_values
1025 1025
         );
1026 1026
         EEH_Template::display_template(
1027
-            EVENTS_CAF_TEMPLATE_PATH . 'event_registration_options.template.php',
1027
+            EVENTS_CAF_TEMPLATE_PATH.'event_registration_options.template.php',
1028 1028
             $template_args
1029 1029
         );
1030 1030
     }
@@ -1117,7 +1117,7 @@  discard block
 block discarded – undo
1117 1117
         $venues = EEM_Venue::instance()->get_all(['order_by' => ['VNU_name' => 'ASC']]);
1118 1118
 
1119 1119
         foreach ($venues as $venue) {
1120
-            $values[ $venue->ID() ] = $venue->name();
1120
+            $values[$venue->ID()] = $venue->name();
1121 1121
         }
1122 1122
 
1123 1123
         return EEH_Form_Fields::select_input('venue', $values, $current_value, '', 'wide');
@@ -1154,13 +1154,13 @@  discard block
 block discarded – undo
1154 1154
     {
1155 1155
         $start = EEM_Datetime::instance()->convert_datetime_for_query(
1156 1156
             'DTT_EVT_start',
1157
-            date('Y-m-d') . ' 00:00:00',
1157
+            date('Y-m-d').' 00:00:00',
1158 1158
             'Y-m-d H:i:s',
1159 1159
             'UTC'
1160 1160
         );
1161
-        $end   = EEM_Datetime::instance()->convert_datetime_for_query(
1161
+        $end = EEM_Datetime::instance()->convert_datetime_for_query(
1162 1162
             'DTT_EVT_start',
1163
-            date('Y-m-d') . ' 23:59:59',
1163
+            date('Y-m-d').' 23:59:59',
1164 1164
             'Y-m-d H:i:s',
1165 1165
             'UTC'
1166 1166
         );
@@ -1189,17 +1189,17 @@  discard block
 block discarded – undo
1189 1189
         $days_this_month = date('t');
1190 1190
         $start           = EEM_Datetime::instance()->convert_datetime_for_query(
1191 1191
             'DTT_EVT_start',
1192
-            $this_year_r . '-' . $this_month_r . '-01 00:00:00',
1192
+            $this_year_r.'-'.$this_month_r.'-01 00:00:00',
1193 1193
             'Y-m-d H:i:s',
1194 1194
             'UTC'
1195 1195
         );
1196
-        $end             = EEM_Datetime::instance()->convert_datetime_for_query(
1196
+        $end = EEM_Datetime::instance()->convert_datetime_for_query(
1197 1197
             'DTT_EVT_start',
1198
-            $this_year_r . '-' . $this_month_r . '-' . $days_this_month . ' 23:59:59',
1198
+            $this_year_r.'-'.$this_month_r.'-'.$days_this_month.' 23:59:59',
1199 1199
             'Y-m-d H:i:s',
1200 1200
             'UTC'
1201 1201
         );
1202
-        $where           = [
1202
+        $where = [
1203 1203
             'Datetime.DTT_EVT_start' => ['BETWEEN', [$start, $end]],
1204 1204
         ];
1205 1205
         return EEM_Event::instance()->count([$where, 'caps' => 'read_admin'], 'EVT_ID', true);
@@ -1221,7 +1221,7 @@  discard block
 block discarded – undo
1221 1221
         ) {
1222 1222
             // check if the new EDTR reg options meta box is being used, and if so, don't load the legacy version
1223 1223
             $this->_template_args['admin_page_content'] = EEH_Template::display_template(
1224
-                EVENTS_CAF_TEMPLATE_PATH . 'default_tickets_moved_notice.template.php',
1224
+                EVENTS_CAF_TEMPLATE_PATH.'default_tickets_moved_notice.template.php',
1225 1225
                 [],
1226 1226
                 true
1227 1227
             );
@@ -1276,7 +1276,7 @@  discard block
 block discarded – undo
1276 1276
 
1277 1277
         $search_term = $this->request->getRequestParam('s');
1278 1278
         if ($search_term) {
1279
-            $search_term = '%' . $search_term . '%';
1279
+            $search_term = '%'.$search_term.'%';
1280 1280
             $where['OR'] = [
1281 1281
                 'TKT_name'        => ['LIKE', $search_term],
1282 1282
                 'TKT_description' => ['LIKE', $search_term],
@@ -1309,16 +1309,16 @@  discard block
 block discarded – undo
1309 1309
         $TKT     = EEM_Ticket::instance();
1310 1310
         // checkboxes?
1311 1311
         $checkboxes = $this->request->getRequestParam('checkbox', [], 'int', true);
1312
-        if (! empty($checkboxes)) {
1312
+        if ( ! empty($checkboxes)) {
1313 1313
             // if array has more than one element then success message should be plural
1314 1314
             $success = count($checkboxes) > 1 ? 2 : 1;
1315 1315
             // cycle thru the boxes
1316 1316
             while (list($TKT_ID, $value) = each($checkboxes)) {
1317 1317
                 if ($trash) {
1318
-                    if (! $TKT->delete_by_ID($TKT_ID)) {
1318
+                    if ( ! $TKT->delete_by_ID($TKT_ID)) {
1319 1319
                         $success = 0;
1320 1320
                     }
1321
-                } elseif (! $TKT->restore_by_ID($TKT_ID)) {
1321
+                } elseif ( ! $TKT->restore_by_ID($TKT_ID)) {
1322 1322
                     $success = 0;
1323 1323
                 }
1324 1324
             }
@@ -1326,10 +1326,10 @@  discard block
 block discarded – undo
1326 1326
             // grab single id and trash
1327 1327
             $TKT_ID = $this->request->getRequestParam('TKT_ID', 0, 'int');
1328 1328
             if ($trash) {
1329
-                if (! $TKT->delete_by_ID($TKT_ID)) {
1329
+                if ( ! $TKT->delete_by_ID($TKT_ID)) {
1330 1330
                     $success = 0;
1331 1331
                 }
1332
-            } elseif (! $TKT->restore_by_ID($TKT_ID)) {
1332
+            } elseif ( ! $TKT->restore_by_ID($TKT_ID)) {
1333 1333
                 $success = 0;
1334 1334
             }
1335 1335
         }
@@ -1353,20 +1353,20 @@  discard block
 block discarded – undo
1353 1353
         $success = 1;
1354 1354
         // checkboxes?
1355 1355
         $checkboxes = $this->request->getRequestParam('checkbox', [], 'int', true);
1356
-        if (! empty($checkboxes)) {
1356
+        if ( ! empty($checkboxes)) {
1357 1357
             // if array has more than one element then success message should be plural
1358 1358
             $success = count($checkboxes) > 1 ? 2 : 1;
1359 1359
             // cycle thru the boxes
1360 1360
             while (list($TKT_ID, $value) = each($checkboxes)) {
1361 1361
                 // delete
1362
-                if (! $this->_delete_the_ticket($TKT_ID)) {
1362
+                if ( ! $this->_delete_the_ticket($TKT_ID)) {
1363 1363
                     $success = 0;
1364 1364
                 }
1365 1365
             }
1366 1366
         } else {
1367 1367
             // grab single id and trash
1368 1368
             $TKT_ID = $this->request->getRequestParam('TKT_ID', 0, 'int');
1369
-            if (! $this->_delete_the_ticket($TKT_ID)) {
1369
+            if ( ! $this->_delete_the_ticket($TKT_ID)) {
1370 1370
                 $success = 0;
1371 1371
             }
1372 1372
         }
@@ -1398,7 +1398,7 @@  discard block
 block discarded – undo
1398 1398
     protected function _delete_the_ticket($TKT_ID)
1399 1399
     {
1400 1400
         $ticket = EEM_Ticket::instance()->get_one_by_ID($TKT_ID);
1401
-        if (! $ticket instanceof EE_Ticket) {
1401
+        if ( ! $ticket instanceof EE_Ticket) {
1402 1402
             return false;
1403 1403
         }
1404 1404
         $ticket->_remove_relations('Datetime');
Please login to merge, or discard this patch.
Braces   +3 added lines, -1 removed lines patch added patch discarded remove patch
@@ -262,7 +262,8 @@  discard block
 block discarded – undo
262 262
             EE_Registry::$i18n_js_strings,
263 263
             [
264 264
                 'image_confirm'          => esc_html__(
265
-                    'Do you really want to delete this image? Please remember to update your event to complete the removal.',
265
+                    'Do {
266
+	you really want to delete this image? Please remember to update your event to complete the removal.',
266 267
                     'event_espresso'
267 268
                 ),
268 269
                 'event_starts_on'        => esc_html__('Event Starts on', 'event_espresso'),
@@ -541,6 +542,7 @@  discard block
 block discarded – undo
541 542
         // first make sure the ID for the event is in the request.
542 543
         //  If it isn't then we need to bail and redirect back to overview list table (cause how did we get here?)
543 544
         $EVT_ID = $this->request->getRequestParam('EVT_ID', 0, 'int');
545
+}
544 546
         if (! $EVT_ID) {
545 547
             EE_Error::add_error(
546 548
                 esc_html__(
Please login to merge, or discard this patch.