Completed
Branch EDTR/master (50dd13)
by
unknown
25:34 queued 17:04
created
core/domain/entities/routing/handlers/admin/EspressoEventEditor.php 1 patch
Indentation   +108 added lines, -108 removed lines patch added patch discarded remove patch
@@ -19,116 +19,116 @@
 block discarded – undo
19 19
 class EspressoEventEditor extends EspressoEventsAdmin
20 20
 {
21 21
 
22
-    /**
23
-     * returns true if the current request matches this route
24
-     *
25
-     * @return bool
26
-     * @since   $VID:$
27
-     */
28
-    public function matchesCurrentRequest()
29
-    {
30
-        return parent::matchesCurrentRequest()
31
-               && $this->admin_config->useAdvancedEditor()
32
-               && (
33
-                $this->request->getRequestParam('action') === 'create_new'
34
-                || $this->request->getRequestParam('action') === 'edit'
35
-            );
36
-    }
22
+	/**
23
+	 * returns true if the current request matches this route
24
+	 *
25
+	 * @return bool
26
+	 * @since   $VID:$
27
+	 */
28
+	public function matchesCurrentRequest()
29
+	{
30
+		return parent::matchesCurrentRequest()
31
+			   && $this->admin_config->useAdvancedEditor()
32
+			   && (
33
+				$this->request->getRequestParam('action') === 'create_new'
34
+				|| $this->request->getRequestParam('action') === 'edit'
35
+			);
36
+	}
37 37
 
38 38
 
39
-    /**
40
-     * @since $VID:$
41
-     */
42
-    protected function registerDependencies()
43
-    {
44
-        $this->dependency_map->registerDependencies(
45
-            'EventEspresso\core\domain\services\admin\events\editor\EventEditorGraphQLData',
46
-            [
47
-                'EventEspresso\core\domain\entities\admin\GraphQLData\Datetimes'                 => EE_Dependency_Map::load_from_cache,
48
-                'EventEspresso\core\domain\entities\admin\GraphQLData\Prices'                    => EE_Dependency_Map::load_from_cache,
49
-                'EventEspresso\core\domain\entities\admin\GraphQLData\PriceTypes'                => EE_Dependency_Map::load_from_cache,
50
-                'EventEspresso\core\domain\entities\admin\GraphQLData\Tickets'                   => EE_Dependency_Map::load_from_cache,
51
-                'EventEspresso\core\domain\services\admin\events\editor\NewEventDefaultEntities' => EE_Dependency_Map::load_from_cache,
52
-                'EventEspresso\core\domain\services\admin\events\editor\EventEntityRelations'    => EE_Dependency_Map::load_from_cache,
53
-            ]
54
-        );
55
-        $this->dependency_map->registerDependencies(
56
-            'EventEspresso\core\domain\services\admin\events\editor\EventEntityRelations',
57
-            [
58
-                'EEM_Datetime'   => EE_Dependency_Map::load_from_cache,
59
-                'EEM_Event'      => EE_Dependency_Map::load_from_cache,
60
-                'EEM_Price'      => EE_Dependency_Map::load_from_cache,
61
-                'EEM_Price_Type' => EE_Dependency_Map::load_from_cache,
62
-                'EEM_Ticket'     => EE_Dependency_Map::load_from_cache,
63
-            ]
64
-        );
65
-        $this->dependency_map->registerDependencies(
66
-            'EventEspresso\core\domain\services\admin\events\editor\NewEventDefaultEntities',
67
-            [
68
-                'EEM_Datetime'                                                       => EE_Dependency_Map::load_from_cache,
69
-                'EEM_Event'                                                          => EE_Dependency_Map::load_from_cache,
70
-                'EEM_Price'                                                          => EE_Dependency_Map::load_from_cache,
71
-                'EEM_Price_Type'                                                     => EE_Dependency_Map::load_from_cache,
72
-                'EEM_Ticket'                                                         => EE_Dependency_Map::load_from_cache,
73
-                'EventEspresso\core\domain\services\admin\entities\DefaultDatetimes' => EE_Dependency_Map::load_from_cache,
74
-            ]
75
-        );
76
-        $this->dependency_map->registerDependencies(
77
-            'EventEspresso\core\domain\services\admin\entities\DefaultDatetimes',
78
-            [
79
-                'EventEspresso\core\domain\services\admin\entities\DefaultTickets' => EE_Dependency_Map::load_from_cache,
80
-                'EEM_Datetime'                                                     => EE_Dependency_Map::load_from_cache,
81
-            ]
82
-        );
83
-        $this->dependency_map->registerDependencies(
84
-            'EventEspresso\core\domain\services\admin\entities\DefaultTickets',
85
-            [
86
-                'EventEspresso\core\domain\services\admin\entities\DefaultPrices' => EE_Dependency_Map::load_from_cache,
87
-                'EEM_Ticket'                                                      => EE_Dependency_Map::load_from_cache,
88
-            ]
89
-        );
90
-        $this->dependency_map->registerDependencies(
91
-            'EventEspresso\core\domain\services\admin\entities\DefaultPrices',
92
-            [
93
-                'EEM_Price'      => EE_Dependency_Map::load_from_cache,
94
-                'EEM_Price_Type' => EE_Dependency_Map::load_from_cache,
95
-            ]
96
-        );
97
-        $this->dependency_map->registerDependencies(
98
-            'EventEspresso\core\domain\entities\routing\data_nodes\domains\EventEditor',
99
-            [
100
-                'EventEspresso\core\domain\services\admin\events\editor\EventEditorGraphQLData' => EE_Dependency_Map::load_from_cache,
101
-                'EventEspresso\core\services\json\JsonDataNodeValidator'                        => EE_Dependency_Map::load_from_cache,
102
-            ]
103
-        );
104
-        /** @var EventEspressoData $primary_data_node */
105
-        $primary_data_node = $this->loader->getShared(
106
-            'EventEspresso\core\domain\entities\routing\data_nodes\EventEspressoData'
107
-        );
108
-        $primary_data_node->setTargetScript(EspressoCoreAppAssetManager::JS_HANDLE_EDITOR);
109
-        /** @var EventEditor $data_node */
110
-        $data_node = $this->loader->getShared(
111
-            'EventEspresso\core\domain\entities\routing\data_nodes\domains\EventEditor'
112
-        );
113
-        $this->setDataNode($data_node);
114
-    }
39
+	/**
40
+	 * @since $VID:$
41
+	 */
42
+	protected function registerDependencies()
43
+	{
44
+		$this->dependency_map->registerDependencies(
45
+			'EventEspresso\core\domain\services\admin\events\editor\EventEditorGraphQLData',
46
+			[
47
+				'EventEspresso\core\domain\entities\admin\GraphQLData\Datetimes'                 => EE_Dependency_Map::load_from_cache,
48
+				'EventEspresso\core\domain\entities\admin\GraphQLData\Prices'                    => EE_Dependency_Map::load_from_cache,
49
+				'EventEspresso\core\domain\entities\admin\GraphQLData\PriceTypes'                => EE_Dependency_Map::load_from_cache,
50
+				'EventEspresso\core\domain\entities\admin\GraphQLData\Tickets'                   => EE_Dependency_Map::load_from_cache,
51
+				'EventEspresso\core\domain\services\admin\events\editor\NewEventDefaultEntities' => EE_Dependency_Map::load_from_cache,
52
+				'EventEspresso\core\domain\services\admin\events\editor\EventEntityRelations'    => EE_Dependency_Map::load_from_cache,
53
+			]
54
+		);
55
+		$this->dependency_map->registerDependencies(
56
+			'EventEspresso\core\domain\services\admin\events\editor\EventEntityRelations',
57
+			[
58
+				'EEM_Datetime'   => EE_Dependency_Map::load_from_cache,
59
+				'EEM_Event'      => EE_Dependency_Map::load_from_cache,
60
+				'EEM_Price'      => EE_Dependency_Map::load_from_cache,
61
+				'EEM_Price_Type' => EE_Dependency_Map::load_from_cache,
62
+				'EEM_Ticket'     => EE_Dependency_Map::load_from_cache,
63
+			]
64
+		);
65
+		$this->dependency_map->registerDependencies(
66
+			'EventEspresso\core\domain\services\admin\events\editor\NewEventDefaultEntities',
67
+			[
68
+				'EEM_Datetime'                                                       => EE_Dependency_Map::load_from_cache,
69
+				'EEM_Event'                                                          => EE_Dependency_Map::load_from_cache,
70
+				'EEM_Price'                                                          => EE_Dependency_Map::load_from_cache,
71
+				'EEM_Price_Type'                                                     => EE_Dependency_Map::load_from_cache,
72
+				'EEM_Ticket'                                                         => EE_Dependency_Map::load_from_cache,
73
+				'EventEspresso\core\domain\services\admin\entities\DefaultDatetimes' => EE_Dependency_Map::load_from_cache,
74
+			]
75
+		);
76
+		$this->dependency_map->registerDependencies(
77
+			'EventEspresso\core\domain\services\admin\entities\DefaultDatetimes',
78
+			[
79
+				'EventEspresso\core\domain\services\admin\entities\DefaultTickets' => EE_Dependency_Map::load_from_cache,
80
+				'EEM_Datetime'                                                     => EE_Dependency_Map::load_from_cache,
81
+			]
82
+		);
83
+		$this->dependency_map->registerDependencies(
84
+			'EventEspresso\core\domain\services\admin\entities\DefaultTickets',
85
+			[
86
+				'EventEspresso\core\domain\services\admin\entities\DefaultPrices' => EE_Dependency_Map::load_from_cache,
87
+				'EEM_Ticket'                                                      => EE_Dependency_Map::load_from_cache,
88
+			]
89
+		);
90
+		$this->dependency_map->registerDependencies(
91
+			'EventEspresso\core\domain\services\admin\entities\DefaultPrices',
92
+			[
93
+				'EEM_Price'      => EE_Dependency_Map::load_from_cache,
94
+				'EEM_Price_Type' => EE_Dependency_Map::load_from_cache,
95
+			]
96
+		);
97
+		$this->dependency_map->registerDependencies(
98
+			'EventEspresso\core\domain\entities\routing\data_nodes\domains\EventEditor',
99
+			[
100
+				'EventEspresso\core\domain\services\admin\events\editor\EventEditorGraphQLData' => EE_Dependency_Map::load_from_cache,
101
+				'EventEspresso\core\services\json\JsonDataNodeValidator'                        => EE_Dependency_Map::load_from_cache,
102
+			]
103
+		);
104
+		/** @var EventEspressoData $primary_data_node */
105
+		$primary_data_node = $this->loader->getShared(
106
+			'EventEspresso\core\domain\entities\routing\data_nodes\EventEspressoData'
107
+		);
108
+		$primary_data_node->setTargetScript(EspressoCoreAppAssetManager::JS_HANDLE_EDITOR);
109
+		/** @var EventEditor $data_node */
110
+		$data_node = $this->loader->getShared(
111
+			'EventEspresso\core\domain\entities\routing\data_nodes\domains\EventEditor'
112
+		);
113
+		$this->setDataNode($data_node);
114
+	}
115 115
 
116 116
 
117
-    /**
118
-     * implements logic required to run during request
119
-     *
120
-     * @return bool
121
-     * @since   $VID:$
122
-     */
123
-    protected function requestHandler()
124
-    {
125
-        /** @var GraphQLManager $graphQL_manager */
126
-        $graphQL_manager = $this->loader->getShared('EventEspresso\core\services\graphql\GraphQLManager');
127
-        $graphQL_manager->init();
128
-        $this->asset_manager = $this->loader->getShared(
129
-            'EventEspresso\core\domain\services\assets\EspressoCoreAppAssetManager'
130
-        );
131
-        add_action('admin_enqueue_scripts', [$this->asset_manager, 'enqueueBrowserAssets'], 100);
132
-        return true;
133
-    }
117
+	/**
118
+	 * implements logic required to run during request
119
+	 *
120
+	 * @return bool
121
+	 * @since   $VID:$
122
+	 */
123
+	protected function requestHandler()
124
+	{
125
+		/** @var GraphQLManager $graphQL_manager */
126
+		$graphQL_manager = $this->loader->getShared('EventEspresso\core\services\graphql\GraphQLManager');
127
+		$graphQL_manager->init();
128
+		$this->asset_manager = $this->loader->getShared(
129
+			'EventEspresso\core\domain\services\assets\EspressoCoreAppAssetManager'
130
+		);
131
+		add_action('admin_enqueue_scripts', [$this->asset_manager, 'enqueueBrowserAssets'], 100);
132
+		return true;
133
+	}
134 134
 }
Please login to merge, or discard this patch.
core/helpers/EEH_Qtip_Loader.helper.php 2 patches
Indentation   +278 added lines, -278 removed lines patch added patch discarded remove patch
@@ -16,282 +16,282 @@
 block discarded – undo
16 16
 class EEH_Qtip_Loader extends EEH_Base
17 17
 {
18 18
 
19
-    /**
20
-     * @var LoaderInterface $loader
21
-     */
22
-    protected $loader;
23
-
24
-    /**
25
-     * @var EEH_Qtip_Loader
26
-     */
27
-    private static $_instance;
28
-
29
-    /**
30
-     * array of qtip config objects
31
-     * @var EE_Qtip_Config[]
32
-     */
33
-    private $_qtips = array();
34
-
35
-
36
-
37
-    /**
38
-     *@singleton method used to instantiate class object
39
-     *@access public
40
-     *@return EEH_Qtip_Loader instance
41
-     */
42
-    public static function instance()
43
-    {
44
-        // check if class object is instantiated
45
-        if (! EEH_Qtip_Loader::$_instance instanceof EEH_Qtip_Loader) {
46
-            EEH_Qtip_Loader::$_instance = new EEH_Qtip_Loader();
47
-        }
48
-        return EEH_Qtip_Loader::$_instance;
49
-    }
50
-
51
-
52
-
53
-    /**
54
-     * private constructor to prevent direct creation
55
-     */
56
-    private function __construct()
57
-    {
58
-        // let's just make sure this is instantiated in the right place.
59
-        if (did_action('wp_print_styles') || did_action('admin_head')) {
60
-            EE_Error::doing_it_wrong(
61
-                'EEH_Qtip_Loader',
62
-                __(
63
-                    'This helper must be instantiated before or within a callback for the WordPress wp_enqueue_scripts hook action hook.',
64
-                    'event_espresso'
65
-                ),
66
-                '4.1'
67
-            );
68
-        }
69
-        $this->loader = LoaderFactory::getLoader();
70
-    }
71
-
72
-
73
-    /**
74
-     * Call this from wp_enqueue_scripts or admin_enqueue_scripts to setup and enqueue the qtip library
75
-     *
76
-     * @access public
77
-     * @return void
78
-     */
79
-    public function register_and_enqueue()
80
-    {
81
-        $qtips_js = !defined('SCRIPT_DEBUG')
82
-            ? EE_THIRD_PARTY_URL . 'qtip/jquery.qtip.min.js'
83
-            : EE_THIRD_PARTY_URL . 'qtip/jquery.qtip.js';
84
-        $qtip_map = EE_THIRD_PARTY_URL . 'qtip/jquery.qtip.min.map';
85
-        $qtip_css = !defined('SCRIPT_DEBUG')
86
-            ? EE_THIRD_PARTY_URL . 'qtip/jquery.qtip.min.css'
87
-            : EE_THIRD_PARTY_URL . 'qtip/jquery.qtip.css';
88
-
89
-        wp_register_script('qtip-map', $qtip_map, array(), '3', true);
90
-        wp_register_script('qtip', $qtips_js, array('jquery'), '3.0.3', true);
91
-        wp_register_script(
92
-            'ee-qtip-helper',
93
-            EE_HELPERS_ASSETS . 'ee-qtip-helper.js',
94
-            array('qtip', JqueryAssetManager::JS_HANDLE_JQUERY_COOKIE),
95
-            EVENT_ESPRESSO_VERSION,
96
-            true
97
-        );
98
-
99
-        wp_register_style('qtip-css', $qtip_css, array(), '2.2');
100
-
101
-        // k now let's see if there are any registered qtips.
102
-        // If there are, then we need to setup the localized script for ee-qtip-helper.js
103
-        // (and enqueue ee-qtip-helper.js of course!)
104
-        if (!empty($this->_qtips)) {
105
-            wp_enqueue_script('ee-qtip-helper');
106
-            wp_enqueue_style('qtip-css');
107
-            $qtips = array();
108
-            foreach ($this->_qtips as $qtip) {
109
-                $qts = $qtip->get_tips();
110
-                foreach ($qts as $qt) {
111
-                    if (! $qt instanceof EE_Qtip) {
112
-                        continue;
113
-                    }
114
-                    $qtips[] = array(
115
-                        'content_id' => $qt->content_id,
116
-                        'options' => $qt->options,
117
-                        'target' => $qt->target,
118
-                        );
119
-                }
120
-            }
121
-            if (!empty($qtips)) {
122
-                wp_localize_script('ee-qtip-helper', 'EE_QTIP_HELPER', array( 'qtips' => $qtips ));
123
-            }
124
-        } else {
125
-            // qtips has been requested without any registration (so assuming its just directly used in the admin).
126
-            wp_enqueue_script('qtip');
127
-            wp_enqueue_style('qtip-css');
128
-        }
129
-    }
130
-
131
-
132
-    /**
133
-     * This simply registers the given qtip config and:
134
-     * - adds it to the $_qtips property array.
135
-     * - sets up the content containers for all qtips in the config,
136
-     * - registers and enqueues the qtip scripts and styles.
137
-     *
138
-     * @access public
139
-     * @param array        $paths      Array of paths to check for the EE_Qtip class. If present we check these path(s)
140
-     *                                 first.  If not present (empty array), then it's assumed it's either in
141
-     *                                 core/libraries/qtips OR the file is already loaded.
142
-     * @param string|array $qtips      name of the Qtip class (full class name is expected and will be used for looking
143
-     *                                 for file, Qtip config classes must extend EE_Qtip_Config) [if this is an array,
144
-     *                                 then we loop through the array to instantiate and setup the qtips]
145
-     * @return void
146
-     * @throws DomainException
147
-     * @throws EE_Error
148
-     * @throws ReflectionException
149
-     */
150
-    public function register($qtips, $paths = array())
151
-    {
152
-        // let's just make sure this is instantiated in the right place.
153
-        if (did_action('wp_enqueue_scripts') || did_action('admin_enqueue_scripts')) {
154
-            EE_Error::doing_it_wrong(
155
-                'EEH_Qtip_Loader->register()',
156
-                __(
157
-                    'EE_Qtip_Config objects must be registered before wp_enqueue_scripts is called.',
158
-                    'event_espresso'
159
-                ),
160
-                '4.1'
161
-            );
162
-        }
163
-
164
-        $qtips = (array) $qtips; // typecast to array
165
-        foreach ($qtips as $qtip) {
166
-            $this->_qtips[] = $this->_register($qtip, $paths);
167
-        }
168
-
169
-        // hook into appropriate footer
170
-        $footer_action = is_admin() ? 'admin_footer' : 'wp_footer';
171
-        add_action($footer_action, array($this, 'setup_qtip'), 10);
172
-
173
-        // make sure we "turn on" qtip js.
174
-        add_filter('FHEE_load_qtip', '__return_true');
175
-    }
176
-
177
-
178
-    /**
179
-     * private utility for registering and setting up qtip config objects
180
-     *
181
-     * @access private
182
-     * @param string $qtip  the short name of the class (will be used to generate the expected classname)
183
-     * @param array  $paths array of paths to check (or if empty we check core/libraries/qtips or assume its loaded)
184
-     * @return EE_Qtip_Config
185
-     * @throws DomainException
186
-     * @throws EE_Error
187
-     * @throws ReflectionException
188
-     */
189
-    private function _register($qtip, $paths)
190
-    {
191
-        // before doing anything we have to make sure that EE_Qtip_Config parent is required.
192
-        EE_Registry::instance()->load_lib('Qtip_Config', array(), true);
193
-        if (!empty($paths)) {
194
-            $paths = (array) $paths;
195
-            foreach ($paths as $path) {
196
-                $path .= $qtip . '.lib.php';
197
-                if (is_readable($path)) {
198
-                    require_once $path;
199
-                }
200
-            }
201
-        }
202
-
203
-        // does class exist at this point?  If it does then let's instantiate.  If it doesn't then let's continue with other paths.
204
-        if (! class_exists($qtip)) {
205
-            $path = EE_LIBRARIES . 'qtips/' . $qtip . '.lib.php';
206
-            if (! is_readable($path)) {
207
-                throw new DomainException(
208
-                    sprintf(
209
-                        __(
210
-                            'Unable to load the Qtip Config registered for this page (%s) because none of the file paths attempted are readable.  Please check the spelling of the paths you\'ve used in the registration',
211
-                            'event_espresso'
212
-                        ),
213
-                        $qtip
214
-                    )
215
-                );
216
-            }
217
-            require_once $path;
218
-        }
219
-
220
-        // now we attempt a class_exists one more time.
221
-        if (! class_exists($qtip)) {
222
-            throw new DomainException(
223
-                sprintf(
224
-                    __(
225
-                        'The Qtip_Config class being registered (%s) does not exist, please check the spelling.',
226
-                        'event_espresso'
227
-                    ),
228
-                    $qtip
229
-                )
230
-            );
231
-        }
232
-
233
-        // made it HERE?  FINALLY, let's get things setup.
234
-        $qtip_config = $this->loader->getShared($qtip);
235
-
236
-        // verify that $qtip is a valid object
237
-        if (! $qtip_config instanceof EE_Qtip_Config) {
238
-            throw new DomainException(
239
-                sprintf(
240
-                    esc_html__(
241
-                        'The class given for the Qtip loader (%1$s) is not a child of the %2$sEE_Qtip_Config%3$s class. Please make sure you are extending EE_Qtip_Config.',
242
-                        'event_espresso'
243
-                    ),
244
-                    $qtip,
245
-                    '<strong>',
246
-                    '</strong>'
247
-                )
248
-            );
249
-        }
250
-
251
-        return $qtip_config;
252
-    }
253
-
254
-
255
-
256
-    /**
257
-     * This takes care of generating the qtip content containers.
258
-     * Output gets put in the appropriate page footer (depending on context (either admin_footer or wp_footer) )
259
-     *
260
-     * @return void
261
-     */
262
-    public function setup_qtip()
263
-    {
264
-        if (empty($this->_qtips)) {
265
-            return; // no qtips!
266
-        }
267
-
268
-        $content = array();
269
-
270
-        foreach ($this->_qtips as $qtip) {
271
-            $content[] = $this->_generate_content_container($qtip);
272
-        }
273
-
274
-        echo implode('<br />', $content);
275
-    }
276
-
277
-
278
-    /**
279
-     * Generates a content container from a given EE_Qtip_Config object.
280
-     *
281
-     * @param  EE_Qtip_Config $qtip
282
-     * @return string  (html content container for qtip);
283
-     */
284
-    private function _generate_content_container($qtip)
285
-    {
286
-        $qts = $qtip->get_tips();
287
-        $content = array();
288
-        foreach ($qts as $qt) {
289
-            if (! $qt instanceof EE_Qtip) {
290
-                continue;
291
-            }
292
-            $content[] = '<div class="ee-qtip-helper-content hidden" id="' . $qt->content_id . '">' . $qt->content . '</div>';
293
-        }
294
-
295
-        return implode('<br />', $content);
296
-    }
19
+	/**
20
+	 * @var LoaderInterface $loader
21
+	 */
22
+	protected $loader;
23
+
24
+	/**
25
+	 * @var EEH_Qtip_Loader
26
+	 */
27
+	private static $_instance;
28
+
29
+	/**
30
+	 * array of qtip config objects
31
+	 * @var EE_Qtip_Config[]
32
+	 */
33
+	private $_qtips = array();
34
+
35
+
36
+
37
+	/**
38
+	 *@singleton method used to instantiate class object
39
+	 *@access public
40
+	 *@return EEH_Qtip_Loader instance
41
+	 */
42
+	public static function instance()
43
+	{
44
+		// check if class object is instantiated
45
+		if (! EEH_Qtip_Loader::$_instance instanceof EEH_Qtip_Loader) {
46
+			EEH_Qtip_Loader::$_instance = new EEH_Qtip_Loader();
47
+		}
48
+		return EEH_Qtip_Loader::$_instance;
49
+	}
50
+
51
+
52
+
53
+	/**
54
+	 * private constructor to prevent direct creation
55
+	 */
56
+	private function __construct()
57
+	{
58
+		// let's just make sure this is instantiated in the right place.
59
+		if (did_action('wp_print_styles') || did_action('admin_head')) {
60
+			EE_Error::doing_it_wrong(
61
+				'EEH_Qtip_Loader',
62
+				__(
63
+					'This helper must be instantiated before or within a callback for the WordPress wp_enqueue_scripts hook action hook.',
64
+					'event_espresso'
65
+				),
66
+				'4.1'
67
+			);
68
+		}
69
+		$this->loader = LoaderFactory::getLoader();
70
+	}
71
+
72
+
73
+	/**
74
+	 * Call this from wp_enqueue_scripts or admin_enqueue_scripts to setup and enqueue the qtip library
75
+	 *
76
+	 * @access public
77
+	 * @return void
78
+	 */
79
+	public function register_and_enqueue()
80
+	{
81
+		$qtips_js = !defined('SCRIPT_DEBUG')
82
+			? EE_THIRD_PARTY_URL . 'qtip/jquery.qtip.min.js'
83
+			: EE_THIRD_PARTY_URL . 'qtip/jquery.qtip.js';
84
+		$qtip_map = EE_THIRD_PARTY_URL . 'qtip/jquery.qtip.min.map';
85
+		$qtip_css = !defined('SCRIPT_DEBUG')
86
+			? EE_THIRD_PARTY_URL . 'qtip/jquery.qtip.min.css'
87
+			: EE_THIRD_PARTY_URL . 'qtip/jquery.qtip.css';
88
+
89
+		wp_register_script('qtip-map', $qtip_map, array(), '3', true);
90
+		wp_register_script('qtip', $qtips_js, array('jquery'), '3.0.3', true);
91
+		wp_register_script(
92
+			'ee-qtip-helper',
93
+			EE_HELPERS_ASSETS . 'ee-qtip-helper.js',
94
+			array('qtip', JqueryAssetManager::JS_HANDLE_JQUERY_COOKIE),
95
+			EVENT_ESPRESSO_VERSION,
96
+			true
97
+		);
98
+
99
+		wp_register_style('qtip-css', $qtip_css, array(), '2.2');
100
+
101
+		// k now let's see if there are any registered qtips.
102
+		// If there are, then we need to setup the localized script for ee-qtip-helper.js
103
+		// (and enqueue ee-qtip-helper.js of course!)
104
+		if (!empty($this->_qtips)) {
105
+			wp_enqueue_script('ee-qtip-helper');
106
+			wp_enqueue_style('qtip-css');
107
+			$qtips = array();
108
+			foreach ($this->_qtips as $qtip) {
109
+				$qts = $qtip->get_tips();
110
+				foreach ($qts as $qt) {
111
+					if (! $qt instanceof EE_Qtip) {
112
+						continue;
113
+					}
114
+					$qtips[] = array(
115
+						'content_id' => $qt->content_id,
116
+						'options' => $qt->options,
117
+						'target' => $qt->target,
118
+						);
119
+				}
120
+			}
121
+			if (!empty($qtips)) {
122
+				wp_localize_script('ee-qtip-helper', 'EE_QTIP_HELPER', array( 'qtips' => $qtips ));
123
+			}
124
+		} else {
125
+			// qtips has been requested without any registration (so assuming its just directly used in the admin).
126
+			wp_enqueue_script('qtip');
127
+			wp_enqueue_style('qtip-css');
128
+		}
129
+	}
130
+
131
+
132
+	/**
133
+	 * This simply registers the given qtip config and:
134
+	 * - adds it to the $_qtips property array.
135
+	 * - sets up the content containers for all qtips in the config,
136
+	 * - registers and enqueues the qtip scripts and styles.
137
+	 *
138
+	 * @access public
139
+	 * @param array        $paths      Array of paths to check for the EE_Qtip class. If present we check these path(s)
140
+	 *                                 first.  If not present (empty array), then it's assumed it's either in
141
+	 *                                 core/libraries/qtips OR the file is already loaded.
142
+	 * @param string|array $qtips      name of the Qtip class (full class name is expected and will be used for looking
143
+	 *                                 for file, Qtip config classes must extend EE_Qtip_Config) [if this is an array,
144
+	 *                                 then we loop through the array to instantiate and setup the qtips]
145
+	 * @return void
146
+	 * @throws DomainException
147
+	 * @throws EE_Error
148
+	 * @throws ReflectionException
149
+	 */
150
+	public function register($qtips, $paths = array())
151
+	{
152
+		// let's just make sure this is instantiated in the right place.
153
+		if (did_action('wp_enqueue_scripts') || did_action('admin_enqueue_scripts')) {
154
+			EE_Error::doing_it_wrong(
155
+				'EEH_Qtip_Loader->register()',
156
+				__(
157
+					'EE_Qtip_Config objects must be registered before wp_enqueue_scripts is called.',
158
+					'event_espresso'
159
+				),
160
+				'4.1'
161
+			);
162
+		}
163
+
164
+		$qtips = (array) $qtips; // typecast to array
165
+		foreach ($qtips as $qtip) {
166
+			$this->_qtips[] = $this->_register($qtip, $paths);
167
+		}
168
+
169
+		// hook into appropriate footer
170
+		$footer_action = is_admin() ? 'admin_footer' : 'wp_footer';
171
+		add_action($footer_action, array($this, 'setup_qtip'), 10);
172
+
173
+		// make sure we "turn on" qtip js.
174
+		add_filter('FHEE_load_qtip', '__return_true');
175
+	}
176
+
177
+
178
+	/**
179
+	 * private utility for registering and setting up qtip config objects
180
+	 *
181
+	 * @access private
182
+	 * @param string $qtip  the short name of the class (will be used to generate the expected classname)
183
+	 * @param array  $paths array of paths to check (or if empty we check core/libraries/qtips or assume its loaded)
184
+	 * @return EE_Qtip_Config
185
+	 * @throws DomainException
186
+	 * @throws EE_Error
187
+	 * @throws ReflectionException
188
+	 */
189
+	private function _register($qtip, $paths)
190
+	{
191
+		// before doing anything we have to make sure that EE_Qtip_Config parent is required.
192
+		EE_Registry::instance()->load_lib('Qtip_Config', array(), true);
193
+		if (!empty($paths)) {
194
+			$paths = (array) $paths;
195
+			foreach ($paths as $path) {
196
+				$path .= $qtip . '.lib.php';
197
+				if (is_readable($path)) {
198
+					require_once $path;
199
+				}
200
+			}
201
+		}
202
+
203
+		// does class exist at this point?  If it does then let's instantiate.  If it doesn't then let's continue with other paths.
204
+		if (! class_exists($qtip)) {
205
+			$path = EE_LIBRARIES . 'qtips/' . $qtip . '.lib.php';
206
+			if (! is_readable($path)) {
207
+				throw new DomainException(
208
+					sprintf(
209
+						__(
210
+							'Unable to load the Qtip Config registered for this page (%s) because none of the file paths attempted are readable.  Please check the spelling of the paths you\'ve used in the registration',
211
+							'event_espresso'
212
+						),
213
+						$qtip
214
+					)
215
+				);
216
+			}
217
+			require_once $path;
218
+		}
219
+
220
+		// now we attempt a class_exists one more time.
221
+		if (! class_exists($qtip)) {
222
+			throw new DomainException(
223
+				sprintf(
224
+					__(
225
+						'The Qtip_Config class being registered (%s) does not exist, please check the spelling.',
226
+						'event_espresso'
227
+					),
228
+					$qtip
229
+				)
230
+			);
231
+		}
232
+
233
+		// made it HERE?  FINALLY, let's get things setup.
234
+		$qtip_config = $this->loader->getShared($qtip);
235
+
236
+		// verify that $qtip is a valid object
237
+		if (! $qtip_config instanceof EE_Qtip_Config) {
238
+			throw new DomainException(
239
+				sprintf(
240
+					esc_html__(
241
+						'The class given for the Qtip loader (%1$s) is not a child of the %2$sEE_Qtip_Config%3$s class. Please make sure you are extending EE_Qtip_Config.',
242
+						'event_espresso'
243
+					),
244
+					$qtip,
245
+					'<strong>',
246
+					'</strong>'
247
+				)
248
+			);
249
+		}
250
+
251
+		return $qtip_config;
252
+	}
253
+
254
+
255
+
256
+	/**
257
+	 * This takes care of generating the qtip content containers.
258
+	 * Output gets put in the appropriate page footer (depending on context (either admin_footer or wp_footer) )
259
+	 *
260
+	 * @return void
261
+	 */
262
+	public function setup_qtip()
263
+	{
264
+		if (empty($this->_qtips)) {
265
+			return; // no qtips!
266
+		}
267
+
268
+		$content = array();
269
+
270
+		foreach ($this->_qtips as $qtip) {
271
+			$content[] = $this->_generate_content_container($qtip);
272
+		}
273
+
274
+		echo implode('<br />', $content);
275
+	}
276
+
277
+
278
+	/**
279
+	 * Generates a content container from a given EE_Qtip_Config object.
280
+	 *
281
+	 * @param  EE_Qtip_Config $qtip
282
+	 * @return string  (html content container for qtip);
283
+	 */
284
+	private function _generate_content_container($qtip)
285
+	{
286
+		$qts = $qtip->get_tips();
287
+		$content = array();
288
+		foreach ($qts as $qt) {
289
+			if (! $qt instanceof EE_Qtip) {
290
+				continue;
291
+			}
292
+			$content[] = '<div class="ee-qtip-helper-content hidden" id="' . $qt->content_id . '">' . $qt->content . '</div>';
293
+		}
294
+
295
+		return implode('<br />', $content);
296
+	}
297 297
 }
Please login to merge, or discard this patch.
Spacing   +20 added lines, -20 removed lines patch added patch discarded remove patch
@@ -42,7 +42,7 @@  discard block
 block discarded – undo
42 42
     public static function instance()
43 43
     {
44 44
         // check if class object is instantiated
45
-        if (! EEH_Qtip_Loader::$_instance instanceof EEH_Qtip_Loader) {
45
+        if ( ! EEH_Qtip_Loader::$_instance instanceof EEH_Qtip_Loader) {
46 46
             EEH_Qtip_Loader::$_instance = new EEH_Qtip_Loader();
47 47
         }
48 48
         return EEH_Qtip_Loader::$_instance;
@@ -78,19 +78,19 @@  discard block
 block discarded – undo
78 78
      */
79 79
     public function register_and_enqueue()
80 80
     {
81
-        $qtips_js = !defined('SCRIPT_DEBUG')
81
+        $qtips_js = ! defined('SCRIPT_DEBUG')
82 82
             ? EE_THIRD_PARTY_URL . 'qtip/jquery.qtip.min.js'
83
-            : EE_THIRD_PARTY_URL . 'qtip/jquery.qtip.js';
84
-        $qtip_map = EE_THIRD_PARTY_URL . 'qtip/jquery.qtip.min.map';
85
-        $qtip_css = !defined('SCRIPT_DEBUG')
83
+            : EE_THIRD_PARTY_URL.'qtip/jquery.qtip.js';
84
+        $qtip_map = EE_THIRD_PARTY_URL.'qtip/jquery.qtip.min.map';
85
+        $qtip_css = ! defined('SCRIPT_DEBUG')
86 86
             ? EE_THIRD_PARTY_URL . 'qtip/jquery.qtip.min.css'
87
-            : EE_THIRD_PARTY_URL . 'qtip/jquery.qtip.css';
87
+            : EE_THIRD_PARTY_URL.'qtip/jquery.qtip.css';
88 88
 
89 89
         wp_register_script('qtip-map', $qtip_map, array(), '3', true);
90 90
         wp_register_script('qtip', $qtips_js, array('jquery'), '3.0.3', true);
91 91
         wp_register_script(
92 92
             'ee-qtip-helper',
93
-            EE_HELPERS_ASSETS . 'ee-qtip-helper.js',
93
+            EE_HELPERS_ASSETS.'ee-qtip-helper.js',
94 94
             array('qtip', JqueryAssetManager::JS_HANDLE_JQUERY_COOKIE),
95 95
             EVENT_ESPRESSO_VERSION,
96 96
             true
@@ -101,14 +101,14 @@  discard block
 block discarded – undo
101 101
         // k now let's see if there are any registered qtips.
102 102
         // If there are, then we need to setup the localized script for ee-qtip-helper.js
103 103
         // (and enqueue ee-qtip-helper.js of course!)
104
-        if (!empty($this->_qtips)) {
104
+        if ( ! empty($this->_qtips)) {
105 105
             wp_enqueue_script('ee-qtip-helper');
106 106
             wp_enqueue_style('qtip-css');
107 107
             $qtips = array();
108 108
             foreach ($this->_qtips as $qtip) {
109 109
                 $qts = $qtip->get_tips();
110 110
                 foreach ($qts as $qt) {
111
-                    if (! $qt instanceof EE_Qtip) {
111
+                    if ( ! $qt instanceof EE_Qtip) {
112 112
                         continue;
113 113
                     }
114 114
                     $qtips[] = array(
@@ -118,8 +118,8 @@  discard block
 block discarded – undo
118 118
                         );
119 119
                 }
120 120
             }
121
-            if (!empty($qtips)) {
122
-                wp_localize_script('ee-qtip-helper', 'EE_QTIP_HELPER', array( 'qtips' => $qtips ));
121
+            if ( ! empty($qtips)) {
122
+                wp_localize_script('ee-qtip-helper', 'EE_QTIP_HELPER', array('qtips' => $qtips));
123 123
             }
124 124
         } else {
125 125
             // qtips has been requested without any registration (so assuming its just directly used in the admin).
@@ -190,10 +190,10 @@  discard block
 block discarded – undo
190 190
     {
191 191
         // before doing anything we have to make sure that EE_Qtip_Config parent is required.
192 192
         EE_Registry::instance()->load_lib('Qtip_Config', array(), true);
193
-        if (!empty($paths)) {
193
+        if ( ! empty($paths)) {
194 194
             $paths = (array) $paths;
195 195
             foreach ($paths as $path) {
196
-                $path .= $qtip . '.lib.php';
196
+                $path .= $qtip.'.lib.php';
197 197
                 if (is_readable($path)) {
198 198
                     require_once $path;
199 199
                 }
@@ -201,9 +201,9 @@  discard block
 block discarded – undo
201 201
         }
202 202
 
203 203
         // does class exist at this point?  If it does then let's instantiate.  If it doesn't then let's continue with other paths.
204
-        if (! class_exists($qtip)) {
205
-            $path = EE_LIBRARIES . 'qtips/' . $qtip . '.lib.php';
206
-            if (! is_readable($path)) {
204
+        if ( ! class_exists($qtip)) {
205
+            $path = EE_LIBRARIES.'qtips/'.$qtip.'.lib.php';
206
+            if ( ! is_readable($path)) {
207 207
                 throw new DomainException(
208 208
                     sprintf(
209 209
                         __(
@@ -218,7 +218,7 @@  discard block
 block discarded – undo
218 218
         }
219 219
 
220 220
         // now we attempt a class_exists one more time.
221
-        if (! class_exists($qtip)) {
221
+        if ( ! class_exists($qtip)) {
222 222
             throw new DomainException(
223 223
                 sprintf(
224 224
                     __(
@@ -234,7 +234,7 @@  discard block
 block discarded – undo
234 234
         $qtip_config = $this->loader->getShared($qtip);
235 235
 
236 236
         // verify that $qtip is a valid object
237
-        if (! $qtip_config instanceof EE_Qtip_Config) {
237
+        if ( ! $qtip_config instanceof EE_Qtip_Config) {
238 238
             throw new DomainException(
239 239
                 sprintf(
240 240
                     esc_html__(
@@ -286,10 +286,10 @@  discard block
 block discarded – undo
286 286
         $qts = $qtip->get_tips();
287 287
         $content = array();
288 288
         foreach ($qts as $qt) {
289
-            if (! $qt instanceof EE_Qtip) {
289
+            if ( ! $qt instanceof EE_Qtip) {
290 290
                 continue;
291 291
             }
292
-            $content[] = '<div class="ee-qtip-helper-content hidden" id="' . $qt->content_id . '">' . $qt->content . '</div>';
292
+            $content[] = '<div class="ee-qtip-helper-content hidden" id="'.$qt->content_id.'">'.$qt->content.'</div>';
293 293
         }
294 294
 
295 295
         return implode('<br />', $content);
Please login to merge, or discard this patch.
core/services/assets/AssetManager.php 1 patch
Indentation   +305 added lines, -305 removed lines patch added patch discarded remove patch
@@ -24,309 +24,309 @@
 block discarded – undo
24 24
 abstract class AssetManager implements AssetManagerInterface
25 25
 {
26 26
 
27
-    /**
28
-     * @var AssetCollection|Asset[] $assets
29
-     */
30
-    protected $assets;
31
-
32
-    /**
33
-     * @var DomainInterface
34
-     */
35
-    protected $domain;
36
-
37
-    /**
38
-     * @var Registry $registry
39
-     */
40
-    protected $registry;
41
-
42
-
43
-    /**
44
-     * AssetRegister constructor.
45
-     *
46
-     * @param DomainInterface $domain
47
-     * @param AssetCollection $assets
48
-     * @param Registry        $registry
49
-     */
50
-    public function __construct(DomainInterface $domain, AssetCollection $assets, Registry $registry)
51
-    {
52
-        $this->domain = $domain;
53
-        $this->assets = $assets;
54
-        $this->registry = $registry;
55
-        add_action('wp_enqueue_scripts', array($this, 'addManifestFile'), 0);
56
-        add_action('admin_enqueue_scripts', array($this, 'addManifestFile'), 0);
57
-        add_action('wp_enqueue_scripts', array($this, 'addAssets'), 2);
58
-        add_action('admin_enqueue_scripts', array($this, 'addAssets'), 2);
59
-    }
60
-
61
-
62
-    /**
63
-     * @return AssetCollection
64
-     */
65
-    public function getAssets()
66
-    {
67
-        return $this->assets;
68
-    }
69
-
70
-
71
-    /**
72
-     * @since 4.9.71.p
73
-     * @return string
74
-     */
75
-    public function assetNamespace()
76
-    {
77
-        return $this->domain->assetNamespace();
78
-    }
79
-
80
-
81
-    /**
82
-     * @return void
83
-     * @throws DuplicateCollectionIdentifierException
84
-     * @throws InvalidDataTypeException
85
-     * @throws InvalidEntityException
86
-     * @since 4.9.62.p
87
-     */
88
-    public function addManifestFile()
89
-    {
90
-        // if a manifest file has already been added for this domain, then just return
91
-        if ($this->assets->has($this->domain->assetNamespace())) {
92
-            return;
93
-        }
94
-        $asset = new ManifestFile($this->domain);
95
-        $this->assets->add($asset, $this->domain->assetNamespace());
96
-    }
97
-
98
-
99
-    /**
100
-     * @return ManifestFile[]
101
-     * @since 4.9.62.p
102
-     */
103
-    public function getManifestFile()
104
-    {
105
-        return $this->assets->getManifestFiles();
106
-    }
107
-
108
-
109
-    /**
110
-     * @param string $handle
111
-     * @param string $source
112
-     * @param array  $dependencies
113
-     * @param bool   $load_in_footer
114
-     * @param string $version
115
-     * @return JavascriptAsset
116
-     * @throws DuplicateCollectionIdentifierException
117
-     * @throws InvalidDataTypeException
118
-     * @throws InvalidEntityException
119
-     * @throws DomainException
120
-     * @since 4.9.62.p
121
-     */
122
-    public function addJavascript(
123
-        $handle,
124
-        $source,
125
-        array $dependencies = array(),
126
-        $load_in_footer = true,
127
-        $version = ''
128
-    ) {
129
-        $asset = new JavascriptAsset(
130
-            $handle,
131
-            $source,
132
-            array_unique($dependencies),
133
-            $load_in_footer,
134
-            $this->domain,
135
-            $version
136
-        );
137
-        $this->assets->add($asset, $handle);
138
-        return $asset;
139
-    }
140
-
141
-
142
-    /**
143
-     * Used to register a javascript asset where everything is dynamically derived from the given handle.
144
-     *
145
-     * @param string       $handle
146
-     * @param string|array $extra_dependencies
147
-     * @return JavascriptAsset
148
-     * @throws DuplicateCollectionIdentifierException
149
-     * @throws InvalidDataTypeException
150
-     * @throws InvalidEntityException
151
-     * @throws DomainException
152
-     */
153
-    public function addJs($handle, $extra_dependencies = [])
154
-    {
155
-        $details = $this->getAssetDetails(
156
-            Asset::TYPE_JS,
157
-            $handle,
158
-            $extra_dependencies
159
-        );
160
-        $source = $this->registry->getJsUrl($this->domain->assetNamespace(), $handle);
161
-        return $this->addJavascript(
162
-            $handle,
163
-            $source,
164
-            $details['dependencies'],
165
-            true,
166
-            $details['version']
167
-        );
168
-    }
169
-
170
-
171
-    /**
172
-     * @param string $handle
173
-     * @param array  $dependencies
174
-     * @param bool   $load_in_footer
175
-     * @param string $version
176
-     * @return JavascriptAsset
177
-     * @throws DomainException
178
-     * @throws DuplicateCollectionIdentifierException
179
-     * @throws InvalidDataTypeException
180
-     * @throws InvalidEntityException
181
-     * @since 4.9.71.p
182
-     */
183
-    public function addVendorJavascript(
184
-        $handle,
185
-        array $dependencies = array(),
186
-        $load_in_footer = true,
187
-        $version = ''
188
-    ) {
189
-        $dev_suffix = wp_scripts_get_suffix('dev');
190
-        $vendor_path = $this->domain->pluginUrl() . 'assets/vendor/';
191
-        return $this->addJavascript(
192
-            $handle,
193
-            "{$vendor_path}{$handle}{$dev_suffix}.js",
194
-            $dependencies,
195
-            $load_in_footer,
196
-            $version
197
-        );
198
-    }
199
-
200
-
201
-    /**
202
-     * @param string $handle
203
-     * @param string $source
204
-     * @param array  $dependencies
205
-     * @param string $media
206
-     * @param string $version
207
-     * @return StylesheetAsset
208
-     * @throws DomainException
209
-     * @throws DuplicateCollectionIdentifierException
210
-     * @throws InvalidDataTypeException
211
-     * @throws InvalidEntityException
212
-     * @since 4.9.62.p
213
-     */
214
-    public function addStylesheet(
215
-        $handle,
216
-        $source,
217
-        array $dependencies = array(),
218
-        $media = 'all',
219
-        $version = ''
220
-    ) {
221
-        $asset = new StylesheetAsset(
222
-            $handle,
223
-            $source,
224
-            array_unique($dependencies),
225
-            $this->domain,
226
-            $media,
227
-            $version
228
-        );
229
-        $this->assets->add($asset, $handle);
230
-        return $asset;
231
-    }
232
-
233
-
234
-    /**
235
-     * Used to register a css asset where everything is dynamically derived from the given handle.
236
-     *
237
-     * @param string       $handle
238
-     * @param string|array $extra_dependencies
239
-     * @return StylesheetAsset
240
-     * @throws DuplicateCollectionIdentifierException
241
-     * @throws InvalidDataTypeException
242
-     * @throws InvalidEntityException
243
-     * @throws DomainException
244
-     */
245
-    public function addCss($handle, $extra_dependencies = [])
246
-    {
247
-        $details = $this->getAssetDetails(
248
-            Asset::TYPE_CSS,
249
-            $handle,
250
-            $extra_dependencies
251
-        );
252
-        return $this->addStylesheet(
253
-            $handle,
254
-            $this->registry->getCssUrl($this->domain->assetNamespace(), $handle),
255
-            $details['dependencies'],
256
-            'all',
257
-            $details['version']
258
-        );
259
-    }
260
-
261
-
262
-    /**
263
-     * @param string $handle
264
-     * @return bool
265
-     * @since 4.9.62.p
266
-     */
267
-    public function enqueueAsset($handle)
268
-    {
269
-        if ($this->assets->has($handle)) {
270
-            /** @var Asset $asset */
271
-            $asset = $this->assets->get($handle);
272
-            if ($asset instanceof BrowserAsset && $asset->isRegistered()) {
273
-                $asset->enqueueAsset();
274
-                return true;
275
-            }
276
-        }
277
-        return false;
278
-    }
279
-
280
-
281
-    /**
282
-     * @return  void
283
-     * @since   $VID:$
284
-     */
285
-    public function enqueueBrowserAssets()
286
-    {
287
-        foreach ($this->assets as $asset) {
288
-            if ($asset instanceof BrowserAsset && $asset->isRegistered()) {
289
-                $asset->enqueueAsset();
290
-            }
291
-        }
292
-    }
293
-
294
-
295
-    /**
296
-     * @param string $asset_type
297
-     * @param string $handle
298
-     * @param array  $extra_dependencies
299
-     * @return array
300
-     * @since 4.10.2.p
301
-     */
302
-    private function getAssetDetails($asset_type, $handle, $extra_dependencies = [])
303
-    {
304
-        $getAssetDetails = '';
305
-        switch ($asset_type) {
306
-            case Asset::TYPE_JS :
307
-                $getAssetDetails = 'getJsAssetDetails';
308
-                break;
309
-            case Asset::TYPE_CSS :
310
-                $getAssetDetails = 'getCssAssetDetails';
311
-                break;
312
-        }
313
-        if ($getAssetDetails === '') {
314
-            return ['dependencies' => [], 'version' => ''];
315
-        }
316
-        $details = $this->registry->$getAssetDetails(
317
-            $this->domain->assetNamespace(),
318
-            $handle
319
-        );
320
-        $details['dependencies'] = isset($details['dependencies'])
321
-            ? $details['dependencies']
322
-            : [];
323
-        $details['version'] = isset($details['version'])
324
-            ? $details['version']
325
-            : '';
326
-        $details['dependencies'] = ! empty($extra_dependencies)
327
-            ? array_merge($details['dependencies'], (array) $extra_dependencies)
328
-            : $details['dependencies'];
329
-        return $details;
330
-
331
-    }
27
+	/**
28
+	 * @var AssetCollection|Asset[] $assets
29
+	 */
30
+	protected $assets;
31
+
32
+	/**
33
+	 * @var DomainInterface
34
+	 */
35
+	protected $domain;
36
+
37
+	/**
38
+	 * @var Registry $registry
39
+	 */
40
+	protected $registry;
41
+
42
+
43
+	/**
44
+	 * AssetRegister constructor.
45
+	 *
46
+	 * @param DomainInterface $domain
47
+	 * @param AssetCollection $assets
48
+	 * @param Registry        $registry
49
+	 */
50
+	public function __construct(DomainInterface $domain, AssetCollection $assets, Registry $registry)
51
+	{
52
+		$this->domain = $domain;
53
+		$this->assets = $assets;
54
+		$this->registry = $registry;
55
+		add_action('wp_enqueue_scripts', array($this, 'addManifestFile'), 0);
56
+		add_action('admin_enqueue_scripts', array($this, 'addManifestFile'), 0);
57
+		add_action('wp_enqueue_scripts', array($this, 'addAssets'), 2);
58
+		add_action('admin_enqueue_scripts', array($this, 'addAssets'), 2);
59
+	}
60
+
61
+
62
+	/**
63
+	 * @return AssetCollection
64
+	 */
65
+	public function getAssets()
66
+	{
67
+		return $this->assets;
68
+	}
69
+
70
+
71
+	/**
72
+	 * @since 4.9.71.p
73
+	 * @return string
74
+	 */
75
+	public function assetNamespace()
76
+	{
77
+		return $this->domain->assetNamespace();
78
+	}
79
+
80
+
81
+	/**
82
+	 * @return void
83
+	 * @throws DuplicateCollectionIdentifierException
84
+	 * @throws InvalidDataTypeException
85
+	 * @throws InvalidEntityException
86
+	 * @since 4.9.62.p
87
+	 */
88
+	public function addManifestFile()
89
+	{
90
+		// if a manifest file has already been added for this domain, then just return
91
+		if ($this->assets->has($this->domain->assetNamespace())) {
92
+			return;
93
+		}
94
+		$asset = new ManifestFile($this->domain);
95
+		$this->assets->add($asset, $this->domain->assetNamespace());
96
+	}
97
+
98
+
99
+	/**
100
+	 * @return ManifestFile[]
101
+	 * @since 4.9.62.p
102
+	 */
103
+	public function getManifestFile()
104
+	{
105
+		return $this->assets->getManifestFiles();
106
+	}
107
+
108
+
109
+	/**
110
+	 * @param string $handle
111
+	 * @param string $source
112
+	 * @param array  $dependencies
113
+	 * @param bool   $load_in_footer
114
+	 * @param string $version
115
+	 * @return JavascriptAsset
116
+	 * @throws DuplicateCollectionIdentifierException
117
+	 * @throws InvalidDataTypeException
118
+	 * @throws InvalidEntityException
119
+	 * @throws DomainException
120
+	 * @since 4.9.62.p
121
+	 */
122
+	public function addJavascript(
123
+		$handle,
124
+		$source,
125
+		array $dependencies = array(),
126
+		$load_in_footer = true,
127
+		$version = ''
128
+	) {
129
+		$asset = new JavascriptAsset(
130
+			$handle,
131
+			$source,
132
+			array_unique($dependencies),
133
+			$load_in_footer,
134
+			$this->domain,
135
+			$version
136
+		);
137
+		$this->assets->add($asset, $handle);
138
+		return $asset;
139
+	}
140
+
141
+
142
+	/**
143
+	 * Used to register a javascript asset where everything is dynamically derived from the given handle.
144
+	 *
145
+	 * @param string       $handle
146
+	 * @param string|array $extra_dependencies
147
+	 * @return JavascriptAsset
148
+	 * @throws DuplicateCollectionIdentifierException
149
+	 * @throws InvalidDataTypeException
150
+	 * @throws InvalidEntityException
151
+	 * @throws DomainException
152
+	 */
153
+	public function addJs($handle, $extra_dependencies = [])
154
+	{
155
+		$details = $this->getAssetDetails(
156
+			Asset::TYPE_JS,
157
+			$handle,
158
+			$extra_dependencies
159
+		);
160
+		$source = $this->registry->getJsUrl($this->domain->assetNamespace(), $handle);
161
+		return $this->addJavascript(
162
+			$handle,
163
+			$source,
164
+			$details['dependencies'],
165
+			true,
166
+			$details['version']
167
+		);
168
+	}
169
+
170
+
171
+	/**
172
+	 * @param string $handle
173
+	 * @param array  $dependencies
174
+	 * @param bool   $load_in_footer
175
+	 * @param string $version
176
+	 * @return JavascriptAsset
177
+	 * @throws DomainException
178
+	 * @throws DuplicateCollectionIdentifierException
179
+	 * @throws InvalidDataTypeException
180
+	 * @throws InvalidEntityException
181
+	 * @since 4.9.71.p
182
+	 */
183
+	public function addVendorJavascript(
184
+		$handle,
185
+		array $dependencies = array(),
186
+		$load_in_footer = true,
187
+		$version = ''
188
+	) {
189
+		$dev_suffix = wp_scripts_get_suffix('dev');
190
+		$vendor_path = $this->domain->pluginUrl() . 'assets/vendor/';
191
+		return $this->addJavascript(
192
+			$handle,
193
+			"{$vendor_path}{$handle}{$dev_suffix}.js",
194
+			$dependencies,
195
+			$load_in_footer,
196
+			$version
197
+		);
198
+	}
199
+
200
+
201
+	/**
202
+	 * @param string $handle
203
+	 * @param string $source
204
+	 * @param array  $dependencies
205
+	 * @param string $media
206
+	 * @param string $version
207
+	 * @return StylesheetAsset
208
+	 * @throws DomainException
209
+	 * @throws DuplicateCollectionIdentifierException
210
+	 * @throws InvalidDataTypeException
211
+	 * @throws InvalidEntityException
212
+	 * @since 4.9.62.p
213
+	 */
214
+	public function addStylesheet(
215
+		$handle,
216
+		$source,
217
+		array $dependencies = array(),
218
+		$media = 'all',
219
+		$version = ''
220
+	) {
221
+		$asset = new StylesheetAsset(
222
+			$handle,
223
+			$source,
224
+			array_unique($dependencies),
225
+			$this->domain,
226
+			$media,
227
+			$version
228
+		);
229
+		$this->assets->add($asset, $handle);
230
+		return $asset;
231
+	}
232
+
233
+
234
+	/**
235
+	 * Used to register a css asset where everything is dynamically derived from the given handle.
236
+	 *
237
+	 * @param string       $handle
238
+	 * @param string|array $extra_dependencies
239
+	 * @return StylesheetAsset
240
+	 * @throws DuplicateCollectionIdentifierException
241
+	 * @throws InvalidDataTypeException
242
+	 * @throws InvalidEntityException
243
+	 * @throws DomainException
244
+	 */
245
+	public function addCss($handle, $extra_dependencies = [])
246
+	{
247
+		$details = $this->getAssetDetails(
248
+			Asset::TYPE_CSS,
249
+			$handle,
250
+			$extra_dependencies
251
+		);
252
+		return $this->addStylesheet(
253
+			$handle,
254
+			$this->registry->getCssUrl($this->domain->assetNamespace(), $handle),
255
+			$details['dependencies'],
256
+			'all',
257
+			$details['version']
258
+		);
259
+	}
260
+
261
+
262
+	/**
263
+	 * @param string $handle
264
+	 * @return bool
265
+	 * @since 4.9.62.p
266
+	 */
267
+	public function enqueueAsset($handle)
268
+	{
269
+		if ($this->assets->has($handle)) {
270
+			/** @var Asset $asset */
271
+			$asset = $this->assets->get($handle);
272
+			if ($asset instanceof BrowserAsset && $asset->isRegistered()) {
273
+				$asset->enqueueAsset();
274
+				return true;
275
+			}
276
+		}
277
+		return false;
278
+	}
279
+
280
+
281
+	/**
282
+	 * @return  void
283
+	 * @since   $VID:$
284
+	 */
285
+	public function enqueueBrowserAssets()
286
+	{
287
+		foreach ($this->assets as $asset) {
288
+			if ($asset instanceof BrowserAsset && $asset->isRegistered()) {
289
+				$asset->enqueueAsset();
290
+			}
291
+		}
292
+	}
293
+
294
+
295
+	/**
296
+	 * @param string $asset_type
297
+	 * @param string $handle
298
+	 * @param array  $extra_dependencies
299
+	 * @return array
300
+	 * @since 4.10.2.p
301
+	 */
302
+	private function getAssetDetails($asset_type, $handle, $extra_dependencies = [])
303
+	{
304
+		$getAssetDetails = '';
305
+		switch ($asset_type) {
306
+			case Asset::TYPE_JS :
307
+				$getAssetDetails = 'getJsAssetDetails';
308
+				break;
309
+			case Asset::TYPE_CSS :
310
+				$getAssetDetails = 'getCssAssetDetails';
311
+				break;
312
+		}
313
+		if ($getAssetDetails === '') {
314
+			return ['dependencies' => [], 'version' => ''];
315
+		}
316
+		$details = $this->registry->$getAssetDetails(
317
+			$this->domain->assetNamespace(),
318
+			$handle
319
+		);
320
+		$details['dependencies'] = isset($details['dependencies'])
321
+			? $details['dependencies']
322
+			: [];
323
+		$details['version'] = isset($details['version'])
324
+			? $details['version']
325
+			: '';
326
+		$details['dependencies'] = ! empty($extra_dependencies)
327
+			? array_merge($details['dependencies'], (array) $extra_dependencies)
328
+			: $details['dependencies'];
329
+		return $details;
330
+
331
+	}
332 332
 }
Please login to merge, or discard this patch.
core/services/assets/Registry.php 1 patch
Indentation   +791 added lines, -791 removed lines patch added patch discarded remove patch
@@ -26,802 +26,802 @@
 block discarded – undo
26 26
 class Registry
27 27
 {
28 28
 
29
-    const FILE_NAME_BUILD_MANIFEST = 'build-manifest.json';
30
-
31
-    /**
32
-     * @var AssetCollection $assets
33
-     */
34
-    protected $assets;
35
-
36
-    /**
37
-     * @var I18nRegistry
38
-     */
39
-    private $i18n_registry;
40
-
41
-    /**
42
-     * This holds the jsdata data object that will be exposed on pages that enqueue the `eejs-core` script.
43
-     *
44
-     * @var array
45
-     */
46
-    protected $jsdata = array();
47
-
48
-    /**
49
-     * This keeps track of all scripts with registered data.  It is used to prevent duplicate data objects setup in the
50
-     * page source.
51
-     *
52
-     * @var array
53
-     */
54
-    private $script_handles_with_data = array();
55
-
56
-
57
-    /**
58
-     * Holds the manifest data obtained from registered manifest files.
59
-     * Manifests are maps of asset chunk name to actual built asset file names.
60
-     * Shape of this array is:
61
-     * array(
62
-     *  'some_namespace_slug' => array(
63
-     *      'some_chunk_name' => array(
64
-     *          'js' => 'filename.js'
65
-     *          'css' => 'filename.js'
66
-     *      ),
67
-     *      'url_base' => 'https://baseurl.com/to/assets
68
-     *  )
69
-     * )
70
-     *
71
-     * @var array
72
-     */
73
-    private $manifest_data = array();
74
-
75
-
76
-    /**
77
-     * Holds any dependency data obtained from registered dependency map json.
78
-     * Dependency map json is generated via the @wordpress/dependency-extraction-webpack-plugin via the webpack config.
79
-     * @see https://github.com/WordPress/gutenberg/tree/master/packages/dependency-extraction-webpack-plugin
80
-     *
81
-     * @var array
82
-     */
83
-    private $dependencies_data = [];
84
-
85
-
86
-    /**
87
-     * This is a known array of possible wp css handles that correspond to what may be exposed as dependencies in our
88
-     * build process.  Currently the dependency export process in webpack does not consider css imports, so we derive
89
-     * them via the js dependencies (WP uses the same handle for both js and css). This is a list of known handles that
90
-     * are used for both js and css.
91
-     * @var array
92
-     */
93
-    private $wp_css_handle_dependencies = [
94
-        'wp-components',
95
-        'wp-block-editor',
96
-        'wp-block-library',
97
-        'wp-edit-post',
98
-        'wp-edit-widgets',
99
-        'wp-editor',
100
-        'wp-format-library',
101
-        'wp-list-reusable-blocks',
102
-        'wp-nux',
103
-    ];
104
-
105
-
106
-    /**
107
-     * Registry constructor.
108
-     * Hooking into WP actions for script registry.
109
-     *
110
-     * @param AssetCollection      $assets
111
-     * @param I18nRegistry         $i18n_registry
112
-     * @throws InvalidArgumentException
113
-     * @throws InvalidDataTypeException
114
-     * @throws InvalidInterfaceException
115
-     */
116
-    public function __construct(AssetCollection $assets, I18nRegistry $i18n_registry)
117
-    {
118
-        $this->assets = $assets;
119
-        $this->i18n_registry = $i18n_registry;
120
-        add_action('wp_enqueue_scripts', array($this, 'registerManifestFiles'), 1);
121
-        add_action('admin_enqueue_scripts', array($this, 'registerManifestFiles'), 1);
122
-        add_action('wp_enqueue_scripts', array($this, 'registerScriptsAndStyles'), 4);
123
-        add_action('admin_enqueue_scripts', array($this, 'registerScriptsAndStyles'), 4);
124
-        add_action('wp_enqueue_scripts', array($this, 'enqueueData'), 5);
125
-        add_action('admin_enqueue_scripts', array($this, 'enqueueData'), 5);
126
-        add_action('wp_print_footer_scripts', array($this, 'enqueueData'), 1);
127
-        add_action('admin_print_footer_scripts', array($this, 'enqueueData'), 1);
128
-    }
129
-
130
-
131
-    /**
132
-     * For classes that have Registry as a dependency, this provides a handy way to register script handles for i18n
133
-     * translation handling.
134
-     *
135
-     * @return I18nRegistry
136
-     */
137
-    public function getI18nRegistry()
138
-    {
139
-        return $this->i18n_registry;
140
-    }
141
-
142
-
143
-    /**
144
-     * Callback for the wp_enqueue_scripts actions used to register assets.
145
-     *
146
-     * @since 4.9.62.p
147
-     * @throws Exception
148
-     */
149
-    public function registerScriptsAndStyles()
150
-    {
151
-        try {
152
-            $this->registerScripts($this->assets->getJavascriptAssets());
153
-            $this->registerStyles($this->assets->getStylesheetAssets());
154
-        } catch (Exception $exception) {
155
-            new ExceptionStackTraceDisplay($exception);
156
-        }
157
-    }
158
-
159
-
160
-    /**
161
-     * Registers JS assets with WP core
162
-     *
163
-     * @param JavascriptAsset[] $scripts
164
-     * @throws AssetRegistrationException
165
-     * @throws InvalidDataTypeException
166
-     * @throws DomainException
167
-     * @since 4.9.62.p
168
-     */
169
-    public function registerScripts(array $scripts)
170
-    {
171
-        foreach ($scripts as $script) {
172
-            // skip to next script if this has already been done
173
-            if ($script->isRegistered()) {
174
-                continue;
175
-            }
176
-            do_action(
177
-                'AHEE__EventEspresso_core_services_assets_Registry__registerScripts__before_script',
178
-                $script
179
-            );
180
-            $registered = wp_register_script(
181
-                $script->handle(),
182
-                $script->source(),
183
-                $script->dependencies(),
184
-                $script->version(),
185
-                $script->loadInFooter()
186
-            );
187
-            if (! $registered && $this->debug()) {
188
-                throw new AssetRegistrationException($script->handle());
189
-            }
190
-            $script->setRegistered($registered);
191
-            if ($script->requiresTranslation()) {
192
-                $this->registerTranslation($script->handle());
193
-            }
194
-            if ($script->enqueueImmediately()) {
195
-                wp_enqueue_script($script->handle());
196
-            }
197
-            do_action(
198
-                'AHEE__EventEspresso_core_services_assets_Registry__registerScripts__after_script',
199
-                $script
200
-            );
201
-        }
202
-    }
203
-
204
-
205
-    /**
206
-     * Registers CSS assets with WP core
207
-     *
208
-     * @param StylesheetAsset[] $styles
209
-     * @throws InvalidDataTypeException
210
-     * @throws DomainException
211
-     * @since 4.9.62.p
212
-     */
213
-    public function registerStyles(array $styles)
214
-    {
215
-        foreach ($styles as $style) {
216
-            // skip to next style if this has already been done
217
-            if ($style->isRegistered()) {
218
-                continue;
219
-            }
220
-            do_action(
221
-                'AHEE__EventEspresso_core_services_assets_Registry__registerStyles__before_style',
222
-                $style
223
-            );
224
-            wp_register_style(
225
-                $style->handle(),
226
-                $style->source(),
227
-                $style->dependencies(),
228
-                $style->version(),
229
-                $style->media()
230
-            );
231
-            $style->setRegistered();
232
-            if ($style->enqueueImmediately()) {
233
-                wp_enqueue_style($style->handle());
234
-            }
235
-            do_action(
236
-                'AHEE__EventEspresso_core_services_assets_Registry__registerStyles__after_style',
237
-                $style
238
-            );
239
-        }
240
-    }
241
-
242
-
243
-    /**
244
-     * Call back for the script print in frontend and backend.
245
-     * Used to call wp_localize_scripts so that data can be added throughout the runtime until this later hook point.
246
-     *
247
-     * @throws Exception
248
-     * @since 4.9.31.rc.015
249
-     */
250
-    public function enqueueData()
251
-    {
252
-        try {
253
-            $this->removeAlreadyRegisteredDataForScriptHandles();
254
-            wp_add_inline_script(
255
-                'eejs-core',
256
-                'var eejsdata=' . wp_json_encode(['data' => $this->jsdata]),
257
-                'before'
258
-            );
259
-            $scripts = $this->assets->getJavascriptAssetsWithData();
260
-            foreach ($scripts as $script) {
261
-                $this->addRegisteredScriptHandlesWithData($script->handle());
262
-                if ($script->hasInlineDataCallback()) {
263
-                    $localize = $script->inlineDataCallback();
264
-                    $localize();
265
-                }
266
-            }
267
-        } catch (Exception $exception) {
268
-            EE_Error::add_error($exception->getMessage(), __FILE__, __FUNCTION__, __LINE__);
269
-            new ExceptionStackTraceDisplay($exception);
270
-        }
271
-    }
272
-
273
-
274
-    /**
275
-     * Used to add data to eejs.data object.
276
-     * Note:  Overriding existing data is not allowed.
277
-     * Data will be accessible as a javascript object when you list `eejs-core` as a dependency for your javascript.
278
-     * If the data you add is something like this:
279
-     *  $this->addData( 'my_plugin_data', array( 'foo' => 'gar' ) );
280
-     * It will be exposed in the page source as:
281
-     *  eejs.data.my_plugin_data.foo == gar
282
-     *
283
-     * @param string       $key   Key used to access your data
284
-     * @param string|array $value Value to attach to key
285
-     * @throws InvalidArgumentException
286
-     */
287
-    public function addData($key, $value)
288
-    {
289
-        if ($this->verifyDataNotExisting($key)) {
290
-            $this->jsdata[ $key ] = $value;
291
-        }
292
-    }
293
-
294
-
295
-    /**
296
-     * Similar to addData except this allows for users to push values to an existing key where the values on key are
297
-     * elements in an array.
298
-     *
299
-     * When you use this method, the value you include will be merged with the array on $key.
300
-     * So if the $key was 'test' and you added a value of ['my_data'] then it would be represented in the javascript
301
-     * object like this, eejs.data.test = [ my_data,
302
-     * ]
303
-     * If there has already been a scalar value attached to the data object given key (via addData for instance), then
304
-     * this will throw an exception.
305
-     *
306
-     * Caution: Only add data using this method if you are okay with the potential for additional data added on the same
307
-     * key potentially overriding the existing data on merge (specifically with associative arrays).
308
-     *
309
-     * @param string       $key   Key to attach data to.
310
-     * @param string|array $value Value being registered.
311
-     * @throws InvalidArgumentException
312
-     */
313
-    public function pushData($key, $value)
314
-    {
315
-        if (isset($this->jsdata[ $key ])
316
-            && ! is_array($this->jsdata[ $key ])
317
-        ) {
318
-            if (! $this->debug()) {
319
-                return;
320
-            }
321
-            throw new InvalidArgumentException(
322
-                sprintf(
323
-                    __(
324
-                        'The value for %1$s is already set and it is not an array. The %2$s method can only be used to
29
+	const FILE_NAME_BUILD_MANIFEST = 'build-manifest.json';
30
+
31
+	/**
32
+	 * @var AssetCollection $assets
33
+	 */
34
+	protected $assets;
35
+
36
+	/**
37
+	 * @var I18nRegistry
38
+	 */
39
+	private $i18n_registry;
40
+
41
+	/**
42
+	 * This holds the jsdata data object that will be exposed on pages that enqueue the `eejs-core` script.
43
+	 *
44
+	 * @var array
45
+	 */
46
+	protected $jsdata = array();
47
+
48
+	/**
49
+	 * This keeps track of all scripts with registered data.  It is used to prevent duplicate data objects setup in the
50
+	 * page source.
51
+	 *
52
+	 * @var array
53
+	 */
54
+	private $script_handles_with_data = array();
55
+
56
+
57
+	/**
58
+	 * Holds the manifest data obtained from registered manifest files.
59
+	 * Manifests are maps of asset chunk name to actual built asset file names.
60
+	 * Shape of this array is:
61
+	 * array(
62
+	 *  'some_namespace_slug' => array(
63
+	 *      'some_chunk_name' => array(
64
+	 *          'js' => 'filename.js'
65
+	 *          'css' => 'filename.js'
66
+	 *      ),
67
+	 *      'url_base' => 'https://baseurl.com/to/assets
68
+	 *  )
69
+	 * )
70
+	 *
71
+	 * @var array
72
+	 */
73
+	private $manifest_data = array();
74
+
75
+
76
+	/**
77
+	 * Holds any dependency data obtained from registered dependency map json.
78
+	 * Dependency map json is generated via the @wordpress/dependency-extraction-webpack-plugin via the webpack config.
79
+	 * @see https://github.com/WordPress/gutenberg/tree/master/packages/dependency-extraction-webpack-plugin
80
+	 *
81
+	 * @var array
82
+	 */
83
+	private $dependencies_data = [];
84
+
85
+
86
+	/**
87
+	 * This is a known array of possible wp css handles that correspond to what may be exposed as dependencies in our
88
+	 * build process.  Currently the dependency export process in webpack does not consider css imports, so we derive
89
+	 * them via the js dependencies (WP uses the same handle for both js and css). This is a list of known handles that
90
+	 * are used for both js and css.
91
+	 * @var array
92
+	 */
93
+	private $wp_css_handle_dependencies = [
94
+		'wp-components',
95
+		'wp-block-editor',
96
+		'wp-block-library',
97
+		'wp-edit-post',
98
+		'wp-edit-widgets',
99
+		'wp-editor',
100
+		'wp-format-library',
101
+		'wp-list-reusable-blocks',
102
+		'wp-nux',
103
+	];
104
+
105
+
106
+	/**
107
+	 * Registry constructor.
108
+	 * Hooking into WP actions for script registry.
109
+	 *
110
+	 * @param AssetCollection      $assets
111
+	 * @param I18nRegistry         $i18n_registry
112
+	 * @throws InvalidArgumentException
113
+	 * @throws InvalidDataTypeException
114
+	 * @throws InvalidInterfaceException
115
+	 */
116
+	public function __construct(AssetCollection $assets, I18nRegistry $i18n_registry)
117
+	{
118
+		$this->assets = $assets;
119
+		$this->i18n_registry = $i18n_registry;
120
+		add_action('wp_enqueue_scripts', array($this, 'registerManifestFiles'), 1);
121
+		add_action('admin_enqueue_scripts', array($this, 'registerManifestFiles'), 1);
122
+		add_action('wp_enqueue_scripts', array($this, 'registerScriptsAndStyles'), 4);
123
+		add_action('admin_enqueue_scripts', array($this, 'registerScriptsAndStyles'), 4);
124
+		add_action('wp_enqueue_scripts', array($this, 'enqueueData'), 5);
125
+		add_action('admin_enqueue_scripts', array($this, 'enqueueData'), 5);
126
+		add_action('wp_print_footer_scripts', array($this, 'enqueueData'), 1);
127
+		add_action('admin_print_footer_scripts', array($this, 'enqueueData'), 1);
128
+	}
129
+
130
+
131
+	/**
132
+	 * For classes that have Registry as a dependency, this provides a handy way to register script handles for i18n
133
+	 * translation handling.
134
+	 *
135
+	 * @return I18nRegistry
136
+	 */
137
+	public function getI18nRegistry()
138
+	{
139
+		return $this->i18n_registry;
140
+	}
141
+
142
+
143
+	/**
144
+	 * Callback for the wp_enqueue_scripts actions used to register assets.
145
+	 *
146
+	 * @since 4.9.62.p
147
+	 * @throws Exception
148
+	 */
149
+	public function registerScriptsAndStyles()
150
+	{
151
+		try {
152
+			$this->registerScripts($this->assets->getJavascriptAssets());
153
+			$this->registerStyles($this->assets->getStylesheetAssets());
154
+		} catch (Exception $exception) {
155
+			new ExceptionStackTraceDisplay($exception);
156
+		}
157
+	}
158
+
159
+
160
+	/**
161
+	 * Registers JS assets with WP core
162
+	 *
163
+	 * @param JavascriptAsset[] $scripts
164
+	 * @throws AssetRegistrationException
165
+	 * @throws InvalidDataTypeException
166
+	 * @throws DomainException
167
+	 * @since 4.9.62.p
168
+	 */
169
+	public function registerScripts(array $scripts)
170
+	{
171
+		foreach ($scripts as $script) {
172
+			// skip to next script if this has already been done
173
+			if ($script->isRegistered()) {
174
+				continue;
175
+			}
176
+			do_action(
177
+				'AHEE__EventEspresso_core_services_assets_Registry__registerScripts__before_script',
178
+				$script
179
+			);
180
+			$registered = wp_register_script(
181
+				$script->handle(),
182
+				$script->source(),
183
+				$script->dependencies(),
184
+				$script->version(),
185
+				$script->loadInFooter()
186
+			);
187
+			if (! $registered && $this->debug()) {
188
+				throw new AssetRegistrationException($script->handle());
189
+			}
190
+			$script->setRegistered($registered);
191
+			if ($script->requiresTranslation()) {
192
+				$this->registerTranslation($script->handle());
193
+			}
194
+			if ($script->enqueueImmediately()) {
195
+				wp_enqueue_script($script->handle());
196
+			}
197
+			do_action(
198
+				'AHEE__EventEspresso_core_services_assets_Registry__registerScripts__after_script',
199
+				$script
200
+			);
201
+		}
202
+	}
203
+
204
+
205
+	/**
206
+	 * Registers CSS assets with WP core
207
+	 *
208
+	 * @param StylesheetAsset[] $styles
209
+	 * @throws InvalidDataTypeException
210
+	 * @throws DomainException
211
+	 * @since 4.9.62.p
212
+	 */
213
+	public function registerStyles(array $styles)
214
+	{
215
+		foreach ($styles as $style) {
216
+			// skip to next style if this has already been done
217
+			if ($style->isRegistered()) {
218
+				continue;
219
+			}
220
+			do_action(
221
+				'AHEE__EventEspresso_core_services_assets_Registry__registerStyles__before_style',
222
+				$style
223
+			);
224
+			wp_register_style(
225
+				$style->handle(),
226
+				$style->source(),
227
+				$style->dependencies(),
228
+				$style->version(),
229
+				$style->media()
230
+			);
231
+			$style->setRegistered();
232
+			if ($style->enqueueImmediately()) {
233
+				wp_enqueue_style($style->handle());
234
+			}
235
+			do_action(
236
+				'AHEE__EventEspresso_core_services_assets_Registry__registerStyles__after_style',
237
+				$style
238
+			);
239
+		}
240
+	}
241
+
242
+
243
+	/**
244
+	 * Call back for the script print in frontend and backend.
245
+	 * Used to call wp_localize_scripts so that data can be added throughout the runtime until this later hook point.
246
+	 *
247
+	 * @throws Exception
248
+	 * @since 4.9.31.rc.015
249
+	 */
250
+	public function enqueueData()
251
+	{
252
+		try {
253
+			$this->removeAlreadyRegisteredDataForScriptHandles();
254
+			wp_add_inline_script(
255
+				'eejs-core',
256
+				'var eejsdata=' . wp_json_encode(['data' => $this->jsdata]),
257
+				'before'
258
+			);
259
+			$scripts = $this->assets->getJavascriptAssetsWithData();
260
+			foreach ($scripts as $script) {
261
+				$this->addRegisteredScriptHandlesWithData($script->handle());
262
+				if ($script->hasInlineDataCallback()) {
263
+					$localize = $script->inlineDataCallback();
264
+					$localize();
265
+				}
266
+			}
267
+		} catch (Exception $exception) {
268
+			EE_Error::add_error($exception->getMessage(), __FILE__, __FUNCTION__, __LINE__);
269
+			new ExceptionStackTraceDisplay($exception);
270
+		}
271
+	}
272
+
273
+
274
+	/**
275
+	 * Used to add data to eejs.data object.
276
+	 * Note:  Overriding existing data is not allowed.
277
+	 * Data will be accessible as a javascript object when you list `eejs-core` as a dependency for your javascript.
278
+	 * If the data you add is something like this:
279
+	 *  $this->addData( 'my_plugin_data', array( 'foo' => 'gar' ) );
280
+	 * It will be exposed in the page source as:
281
+	 *  eejs.data.my_plugin_data.foo == gar
282
+	 *
283
+	 * @param string       $key   Key used to access your data
284
+	 * @param string|array $value Value to attach to key
285
+	 * @throws InvalidArgumentException
286
+	 */
287
+	public function addData($key, $value)
288
+	{
289
+		if ($this->verifyDataNotExisting($key)) {
290
+			$this->jsdata[ $key ] = $value;
291
+		}
292
+	}
293
+
294
+
295
+	/**
296
+	 * Similar to addData except this allows for users to push values to an existing key where the values on key are
297
+	 * elements in an array.
298
+	 *
299
+	 * When you use this method, the value you include will be merged with the array on $key.
300
+	 * So if the $key was 'test' and you added a value of ['my_data'] then it would be represented in the javascript
301
+	 * object like this, eejs.data.test = [ my_data,
302
+	 * ]
303
+	 * If there has already been a scalar value attached to the data object given key (via addData for instance), then
304
+	 * this will throw an exception.
305
+	 *
306
+	 * Caution: Only add data using this method if you are okay with the potential for additional data added on the same
307
+	 * key potentially overriding the existing data on merge (specifically with associative arrays).
308
+	 *
309
+	 * @param string       $key   Key to attach data to.
310
+	 * @param string|array $value Value being registered.
311
+	 * @throws InvalidArgumentException
312
+	 */
313
+	public function pushData($key, $value)
314
+	{
315
+		if (isset($this->jsdata[ $key ])
316
+			&& ! is_array($this->jsdata[ $key ])
317
+		) {
318
+			if (! $this->debug()) {
319
+				return;
320
+			}
321
+			throw new InvalidArgumentException(
322
+				sprintf(
323
+					__(
324
+						'The value for %1$s is already set and it is not an array. The %2$s method can only be used to
325 325
                          push values to this data element when it is an array.',
326
-                        'event_espresso'
327
-                    ),
328
-                    $key,
329
-                    __METHOD__
330
-                )
331
-            );
332
-        }
333
-        if ( ! isset( $this->jsdata[ $key ] ) ) {
334
-            $this->jsdata[ $key ] = is_array($value) ? $value : [$value];
335
-        } else {
336
-            $this->jsdata[ $key ] = array_merge( $this->jsdata[$key], (array) $value);
337
-        }
338
-    }
339
-
340
-
341
-    /**
342
-     * Used to set content used by javascript for a template.
343
-     * Note: Overrides of existing registered templates are not allowed.
344
-     *
345
-     * @param string $template_reference
346
-     * @param string $template_content
347
-     * @throws InvalidArgumentException
348
-     */
349
-    public function addTemplate($template_reference, $template_content)
350
-    {
351
-        if (! isset($this->jsdata['templates'])) {
352
-            $this->jsdata['templates'] = array();
353
-        }
354
-        //no overrides allowed.
355
-        if (isset($this->jsdata['templates'][ $template_reference ])) {
356
-            if (! $this->debug()) {
357
-                return;
358
-            }
359
-            throw new InvalidArgumentException(
360
-                sprintf(
361
-                    __(
362
-                        'The %1$s key already exists for the templates array in the js data array.  No overrides are allowed.',
363
-                        'event_espresso'
364
-                    ),
365
-                    $template_reference
366
-                )
367
-            );
368
-        }
369
-        $this->jsdata['templates'][ $template_reference ] = $template_content;
370
-    }
371
-
372
-
373
-    /**
374
-     * Retrieve the template content already registered for the given reference.
375
-     *
376
-     * @param string $template_reference
377
-     * @return string
378
-     */
379
-    public function getTemplate($template_reference)
380
-    {
381
-        return isset($this->jsdata['templates'][ $template_reference ])
382
-            ? $this->jsdata['templates'][ $template_reference ]
383
-            : '';
384
-    }
385
-
386
-
387
-    /**
388
-     * Retrieve registered data.
389
-     *
390
-     * @param string $key Name of key to attach data to.
391
-     * @return mixed                If there is no for the given key, then false is returned.
392
-     */
393
-    public function getData($key)
394
-    {
395
-        return isset($this->jsdata[ $key ])
396
-            ? $this->jsdata[ $key ]
397
-            : false;
398
-    }
399
-
400
-
401
-    /**
402
-     * Verifies whether the given data exists already on the jsdata array.
403
-     * Overriding data is not allowed.
404
-     *
405
-     * @param string $key Index for data.
406
-     * @return bool        If valid then return true.
407
-     * @throws InvalidArgumentException if data already exists.
408
-     */
409
-    protected function verifyDataNotExisting($key)
410
-    {
411
-        if (isset($this->jsdata[ $key ])) {
412
-            if (! $this->debug()) {
413
-                return false;
414
-            }
415
-            if (is_array($this->jsdata[ $key ])) {
416
-                throw new InvalidArgumentException(
417
-                    sprintf(
418
-                        __(
419
-                            'The value for %1$s already exists in the Registry::eejs object.
326
+						'event_espresso'
327
+					),
328
+					$key,
329
+					__METHOD__
330
+				)
331
+			);
332
+		}
333
+		if ( ! isset( $this->jsdata[ $key ] ) ) {
334
+			$this->jsdata[ $key ] = is_array($value) ? $value : [$value];
335
+		} else {
336
+			$this->jsdata[ $key ] = array_merge( $this->jsdata[$key], (array) $value);
337
+		}
338
+	}
339
+
340
+
341
+	/**
342
+	 * Used to set content used by javascript for a template.
343
+	 * Note: Overrides of existing registered templates are not allowed.
344
+	 *
345
+	 * @param string $template_reference
346
+	 * @param string $template_content
347
+	 * @throws InvalidArgumentException
348
+	 */
349
+	public function addTemplate($template_reference, $template_content)
350
+	{
351
+		if (! isset($this->jsdata['templates'])) {
352
+			$this->jsdata['templates'] = array();
353
+		}
354
+		//no overrides allowed.
355
+		if (isset($this->jsdata['templates'][ $template_reference ])) {
356
+			if (! $this->debug()) {
357
+				return;
358
+			}
359
+			throw new InvalidArgumentException(
360
+				sprintf(
361
+					__(
362
+						'The %1$s key already exists for the templates array in the js data array.  No overrides are allowed.',
363
+						'event_espresso'
364
+					),
365
+					$template_reference
366
+				)
367
+			);
368
+		}
369
+		$this->jsdata['templates'][ $template_reference ] = $template_content;
370
+	}
371
+
372
+
373
+	/**
374
+	 * Retrieve the template content already registered for the given reference.
375
+	 *
376
+	 * @param string $template_reference
377
+	 * @return string
378
+	 */
379
+	public function getTemplate($template_reference)
380
+	{
381
+		return isset($this->jsdata['templates'][ $template_reference ])
382
+			? $this->jsdata['templates'][ $template_reference ]
383
+			: '';
384
+	}
385
+
386
+
387
+	/**
388
+	 * Retrieve registered data.
389
+	 *
390
+	 * @param string $key Name of key to attach data to.
391
+	 * @return mixed                If there is no for the given key, then false is returned.
392
+	 */
393
+	public function getData($key)
394
+	{
395
+		return isset($this->jsdata[ $key ])
396
+			? $this->jsdata[ $key ]
397
+			: false;
398
+	}
399
+
400
+
401
+	/**
402
+	 * Verifies whether the given data exists already on the jsdata array.
403
+	 * Overriding data is not allowed.
404
+	 *
405
+	 * @param string $key Index for data.
406
+	 * @return bool        If valid then return true.
407
+	 * @throws InvalidArgumentException if data already exists.
408
+	 */
409
+	protected function verifyDataNotExisting($key)
410
+	{
411
+		if (isset($this->jsdata[ $key ])) {
412
+			if (! $this->debug()) {
413
+				return false;
414
+			}
415
+			if (is_array($this->jsdata[ $key ])) {
416
+				throw new InvalidArgumentException(
417
+					sprintf(
418
+						__(
419
+							'The value for %1$s already exists in the Registry::eejs object.
420 420
                             Overrides are not allowed. Since the value of this data is an array, you may want to use the
421 421
                             %2$s method to push your value to the array.',
422
-                            'event_espresso'
423
-                        ),
424
-                        $key,
425
-                        'pushData()'
426
-                    )
427
-                );
428
-            }
429
-            throw new InvalidArgumentException(
430
-                sprintf(
431
-                    __(
432
-                        'The value for %1$s already exists in the Registry::eejs object. Overrides are not
422
+							'event_espresso'
423
+						),
424
+						$key,
425
+						'pushData()'
426
+					)
427
+				);
428
+			}
429
+			throw new InvalidArgumentException(
430
+				sprintf(
431
+					__(
432
+						'The value for %1$s already exists in the Registry::eejs object. Overrides are not
433 433
                         allowed.  Consider attaching your value to a different key',
434
-                        'event_espresso'
435
-                    ),
436
-                    $key
437
-                )
438
-            );
439
-        }
440
-        return true;
441
-    }
442
-
443
-
444
-    /**
445
-     * Get the actual asset path for asset manifests.
446
-     * If there is no asset path found for the given $chunk_name, then the $chunk_name is returned.
447
-     *
448
-     * @param string $namespace  The namespace associated with the manifest file hosting the map of chunk_name to actual
449
-     *                           asset file location.
450
-     * @param string $chunk_name
451
-     * @param string $asset_type
452
-     * @return string
453
-     * @since 4.9.59.p
454
-     */
455
-    public function getAssetUrl($namespace, $chunk_name, $asset_type)
456
-    {
457
-        $asset_index = $chunk_name . '.' . $asset_type;
458
-        $url = isset(
459
-            $this->manifest_data[ $namespace ][ $asset_index ],
460
-            $this->manifest_data[ $namespace ]['url_base']
461
-        )
462
-            ? $this->manifest_data[ $namespace ]['url_base']
463
-              . $this->manifest_data[ $namespace ][ $asset_index ]
464
-            : '';
465
-        return apply_filters(
466
-            'FHEE__EventEspresso_core_services_assets_Registry__getAssetUrl',
467
-            $url,
468
-            $namespace,
469
-            $chunk_name,
470
-            $asset_type
471
-        );
472
-    }
473
-
474
-
475
-
476
-    /**
477
-     * Return the url to a js file for the given namespace and chunk name.
478
-     *
479
-     * @param string $namespace
480
-     * @param string $chunk_name
481
-     * @return string
482
-     */
483
-    public function getJsUrl($namespace, $chunk_name)
484
-    {
485
-        return $this->getAssetUrl($namespace, $chunk_name, Asset::TYPE_JS);
486
-    }
487
-
488
-
489
-    /**
490
-     * Return the url to a css file for the given namespace and chunk name.
491
-     *
492
-     * @param string $namespace
493
-     * @param string $chunk_name
494
-     * @return string
495
-     */
496
-    public function getCssUrl($namespace, $chunk_name)
497
-    {
498
-        return $this->getAssetUrl($namespace, $chunk_name, Asset::TYPE_CSS);
499
-    }
500
-
501
-
502
-    /**
503
-     * Return the dependencies array and version string for a given asset $chunk_name
504
-     *
505
-     * @param string $namespace
506
-     * @param string $chunk_name
507
-     * @param string $asset_type
508
-     * @return array
509
-     * @since 4.9.82.p
510
-     */
511
-    private function getDetailsForAsset($namespace, $chunk_name, $asset_type)
512
-    {
513
-        $asset_index = $chunk_name . '.' . $asset_type;
514
-        if (! isset( $this->dependencies_data[ $namespace ][ $asset_index ])) {
515
-            $path = isset($this->manifest_data[ $namespace ]['path'])
516
-                ? $this->manifest_data[ $namespace ]['path']
517
-                : '';
518
-            $dependencies_index = $chunk_name . '.' . Asset::TYPE_PHP;
519
-            $file_path = isset($this->manifest_data[ $namespace ][ $dependencies_index ])
520
-                ? $path . $this->manifest_data[ $namespace ][ $dependencies_index ]
521
-                :
522
-                '';
523
-            $this->dependencies_data[ $namespace ][ $asset_index ] = $file_path !== '' && file_exists($file_path)
524
-                ? $this->getDetailsForAssetType($namespace, $asset_type, $file_path, $chunk_name)
525
-                : [];
526
-        }
527
-        return $this->dependencies_data[ $namespace ][ $asset_index ];
528
-    }
529
-
530
-
531
-    /**
532
-     * Return dependencies array and version string according to asset type.
533
-     * For css assets, this filters the auto generated dependencies by css type.
534
-     *
535
-     * @param string $namespace
536
-     * @param string $asset_type
537
-     * @param string $file_path
538
-     * @param string $chunk_name
539
-     * @return array
540
-     * @since 4.9.82.p
541
-     */
542
-    private function getDetailsForAssetType($namespace, $asset_type, $file_path, $chunk_name)
543
-    {
544
-        // $asset_dependencies = json_decode(file_get_contents($file_path), true);
545
-        $asset_details = require($file_path);
546
-        $asset_details['dependencies'] = isset($asset_details['dependencies'])
547
-            ? $asset_details['dependencies']
548
-            : [];
549
-        $asset_details['version'] = isset($asset_details['version'])
550
-            ? $asset_details['version']
551
-            : '';
552
-        if ($asset_type === Asset::TYPE_JS) {
553
-            $asset_details['dependencies'] =  $chunk_name === 'eejs-core'
554
-                ? $asset_details['dependencies']
555
-                : $asset_details['dependencies'] + [ CoreAssetManager::JS_HANDLE_JS_CORE ];
556
-            return $asset_details;
557
-        }
558
-        // for css we need to make sure there is actually a css file related to this chunk.
559
-        if (isset($this->manifest_data[ $namespace ])) {
560
-            // array of css chunk files for ee.
561
-            $css_chunks = array_map(
562
-                static function ($value) {
563
-                    return str_replace('.css', '', $value);
564
-                },
565
-                array_filter(
566
-                    array_keys($this->manifest_data[ $namespace ]),
567
-                    static function ($value) {
568
-                        return strpos($value, '.css') !== false;
569
-                    }
570
-                )
571
-            );
572
-            // add known wp chunks with css
573
-            $css_chunks = array_merge( $css_chunks, $this->wp_css_handle_dependencies);
574
-            // flip for easier search
575
-            $css_chunks = array_flip($css_chunks);
576
-
577
-            // now let's filter the dependencies for the incoming chunk to actual chunks that have styles
578
-            $asset_details['dependencies'] = array_filter(
579
-                $asset_details['dependencies'],
580
-                static function ($chunk_name) use ($css_chunks) {
581
-                    return isset($css_chunks[ $chunk_name ]);
582
-                }
583
-            );
584
-            return $asset_details;
585
-        }
586
-        return ['dependencies' => [], 'version' => ''];
587
-    }
588
-
589
-
590
-    /**
591
-     * Get the dependencies array and version string for the given js asset chunk name
592
-     *
593
-     * @param string $namespace
594
-     * @param string $chunk_name
595
-     * @return array
596
-     * @since 4.10.2.p
597
-     */
598
-    public function getJsAssetDetails($namespace, $chunk_name)
599
-    {
600
-        return $this->getDetailsForAsset($namespace, $chunk_name, Asset::TYPE_JS);
601
-    }
602
-
603
-
604
-    /**
605
-     * Get the dependencies array and version string for the given css asset chunk name
606
-     *
607
-     * @param string $namespace
608
-     * @param string $chunk_name
609
-     * @return array
610
-     * @since 4.10.2.p
611
-     */
612
-    public function getCssAssetDetails($namespace, $chunk_name)
613
-    {
614
-        return $this->getDetailsForAsset($namespace, $chunk_name, Asset::TYPE_CSS);
615
-    }
616
-
617
-
618
-    /**
619
-     * @throws Exception
620
-     * @throws InvalidArgumentException
621
-     * @throws InvalidFilePathException
622
-     * @since 4.9.62.p
623
-     */
624
-    public function registerManifestFiles()
625
-    {
626
-        try {
627
-            $manifest_files = $this->assets->getManifestFiles();
628
-            foreach ($manifest_files as $manifest_file) {
629
-                $this->registerManifestFile(
630
-                    $manifest_file->assetNamespace(),
631
-                    $manifest_file->urlBase(),
632
-                    $manifest_file->filepath() . Registry::FILE_NAME_BUILD_MANIFEST,
633
-                    $manifest_file->filepath()
634
-                );
635
-            }
636
-        } catch (Exception $exception) {
637
-            EE_Error::add_error($exception->getMessage(), __FILE__, __FUNCTION__, __LINE__);
638
-            new ExceptionStackTraceDisplay($exception);
639
-        }
640
-    }
641
-
642
-
643
-    /**
644
-     * Used to register a js/css manifest file with the registered_manifest_files property.
645
-     *
646
-     * @param string $namespace     Provided to associate the manifest file with a specific namespace.
647
-     * @param string $url_base      The url base for the manifest file location.
648
-     * @param string $manifest_file The absolute path to the manifest file.
649
-     * @param string $manifest_file_path  The path to the folder containing the manifest file. If not provided will be
650
-     *                                    default to `plugin_root/assets/dist`.
651
-     * @throws InvalidArgumentException
652
-     * @throws InvalidFilePathException
653
-     * @since 4.9.59.p
654
-     */
655
-    public function registerManifestFile($namespace, $url_base, $manifest_file, $manifest_file_path = '')
656
-    {
657
-        if (isset($this->manifest_data[ $namespace ])) {
658
-            if (! $this->debug()) {
659
-                return;
660
-            }
661
-            throw new InvalidArgumentException(
662
-                sprintf(
663
-                    esc_html__(
664
-                        'The namespace for this manifest file has already been registered, choose a namespace other than %s',
665
-                        'event_espresso'
666
-                    ),
667
-                    $namespace
668
-                )
669
-            );
670
-        }
671
-        if (filter_var($url_base, FILTER_VALIDATE_URL) === false) {
672
-            if (is_admin()) {
673
-                EE_Error::add_error(
674
-                    sprintf(
675
-                        esc_html__(
676
-                            'The url given for %1$s assets is invalid.  The url provided was: "%2$s". This usually happens when another plugin or theme on a site is using the "%3$s" filter or has an invalid url set for the "%4$s" constant',
677
-                            'event_espresso'
678
-                        ),
679
-                        'Event Espresso',
680
-                        $url_base,
681
-                        'plugins_url',
682
-                        'WP_PLUGIN_URL'
683
-                    ),
684
-                    __FILE__,
685
-                    __FUNCTION__,
686
-                    __LINE__
687
-                );
688
-            }
689
-            return;
690
-        }
691
-        $this->manifest_data[ $namespace ] = $this->decodeManifestFile($manifest_file);
692
-        if (! isset($this->manifest_data[ $namespace ]['url_base'])) {
693
-            $this->manifest_data[ $namespace ]['url_base'] = untrailingslashit($url_base);
694
-        }
695
-        if (! isset($this->manifest_data[ $namespace ]['path'])) {
696
-            $this->manifest_data[ $namespace ]['path'] = untrailingslashit($manifest_file_path);
697
-        }
698
-    }
699
-
700
-
701
-    /**
702
-     * Decodes json from the provided manifest file.
703
-     *
704
-     * @since 4.9.59.p
705
-     * @param string $manifest_file Path to manifest file.
706
-     * @return array
707
-     * @throws InvalidFilePathException
708
-     */
709
-    private function decodeManifestFile($manifest_file)
710
-    {
711
-        if (! file_exists($manifest_file)) {
712
-            throw new InvalidFilePathException($manifest_file);
713
-        }
714
-        return json_decode(file_get_contents($manifest_file), true);
715
-    }
716
-
717
-
718
-    /**
719
-     * This is used to set registered script handles that have data.
720
-     *
721
-     * @param string $script_handle
722
-     */
723
-    private function addRegisteredScriptHandlesWithData($script_handle)
724
-    {
725
-        $this->script_handles_with_data[ $script_handle ] = $script_handle;
726
-    }
727
-
728
-
729
-    /**i
434
+						'event_espresso'
435
+					),
436
+					$key
437
+				)
438
+			);
439
+		}
440
+		return true;
441
+	}
442
+
443
+
444
+	/**
445
+	 * Get the actual asset path for asset manifests.
446
+	 * If there is no asset path found for the given $chunk_name, then the $chunk_name is returned.
447
+	 *
448
+	 * @param string $namespace  The namespace associated with the manifest file hosting the map of chunk_name to actual
449
+	 *                           asset file location.
450
+	 * @param string $chunk_name
451
+	 * @param string $asset_type
452
+	 * @return string
453
+	 * @since 4.9.59.p
454
+	 */
455
+	public function getAssetUrl($namespace, $chunk_name, $asset_type)
456
+	{
457
+		$asset_index = $chunk_name . '.' . $asset_type;
458
+		$url = isset(
459
+			$this->manifest_data[ $namespace ][ $asset_index ],
460
+			$this->manifest_data[ $namespace ]['url_base']
461
+		)
462
+			? $this->manifest_data[ $namespace ]['url_base']
463
+			  . $this->manifest_data[ $namespace ][ $asset_index ]
464
+			: '';
465
+		return apply_filters(
466
+			'FHEE__EventEspresso_core_services_assets_Registry__getAssetUrl',
467
+			$url,
468
+			$namespace,
469
+			$chunk_name,
470
+			$asset_type
471
+		);
472
+	}
473
+
474
+
475
+
476
+	/**
477
+	 * Return the url to a js file for the given namespace and chunk name.
478
+	 *
479
+	 * @param string $namespace
480
+	 * @param string $chunk_name
481
+	 * @return string
482
+	 */
483
+	public function getJsUrl($namespace, $chunk_name)
484
+	{
485
+		return $this->getAssetUrl($namespace, $chunk_name, Asset::TYPE_JS);
486
+	}
487
+
488
+
489
+	/**
490
+	 * Return the url to a css file for the given namespace and chunk name.
491
+	 *
492
+	 * @param string $namespace
493
+	 * @param string $chunk_name
494
+	 * @return string
495
+	 */
496
+	public function getCssUrl($namespace, $chunk_name)
497
+	{
498
+		return $this->getAssetUrl($namespace, $chunk_name, Asset::TYPE_CSS);
499
+	}
500
+
501
+
502
+	/**
503
+	 * Return the dependencies array and version string for a given asset $chunk_name
504
+	 *
505
+	 * @param string $namespace
506
+	 * @param string $chunk_name
507
+	 * @param string $asset_type
508
+	 * @return array
509
+	 * @since 4.9.82.p
510
+	 */
511
+	private function getDetailsForAsset($namespace, $chunk_name, $asset_type)
512
+	{
513
+		$asset_index = $chunk_name . '.' . $asset_type;
514
+		if (! isset( $this->dependencies_data[ $namespace ][ $asset_index ])) {
515
+			$path = isset($this->manifest_data[ $namespace ]['path'])
516
+				? $this->manifest_data[ $namespace ]['path']
517
+				: '';
518
+			$dependencies_index = $chunk_name . '.' . Asset::TYPE_PHP;
519
+			$file_path = isset($this->manifest_data[ $namespace ][ $dependencies_index ])
520
+				? $path . $this->manifest_data[ $namespace ][ $dependencies_index ]
521
+				:
522
+				'';
523
+			$this->dependencies_data[ $namespace ][ $asset_index ] = $file_path !== '' && file_exists($file_path)
524
+				? $this->getDetailsForAssetType($namespace, $asset_type, $file_path, $chunk_name)
525
+				: [];
526
+		}
527
+		return $this->dependencies_data[ $namespace ][ $asset_index ];
528
+	}
529
+
530
+
531
+	/**
532
+	 * Return dependencies array and version string according to asset type.
533
+	 * For css assets, this filters the auto generated dependencies by css type.
534
+	 *
535
+	 * @param string $namespace
536
+	 * @param string $asset_type
537
+	 * @param string $file_path
538
+	 * @param string $chunk_name
539
+	 * @return array
540
+	 * @since 4.9.82.p
541
+	 */
542
+	private function getDetailsForAssetType($namespace, $asset_type, $file_path, $chunk_name)
543
+	{
544
+		// $asset_dependencies = json_decode(file_get_contents($file_path), true);
545
+		$asset_details = require($file_path);
546
+		$asset_details['dependencies'] = isset($asset_details['dependencies'])
547
+			? $asset_details['dependencies']
548
+			: [];
549
+		$asset_details['version'] = isset($asset_details['version'])
550
+			? $asset_details['version']
551
+			: '';
552
+		if ($asset_type === Asset::TYPE_JS) {
553
+			$asset_details['dependencies'] =  $chunk_name === 'eejs-core'
554
+				? $asset_details['dependencies']
555
+				: $asset_details['dependencies'] + [ CoreAssetManager::JS_HANDLE_JS_CORE ];
556
+			return $asset_details;
557
+		}
558
+		// for css we need to make sure there is actually a css file related to this chunk.
559
+		if (isset($this->manifest_data[ $namespace ])) {
560
+			// array of css chunk files for ee.
561
+			$css_chunks = array_map(
562
+				static function ($value) {
563
+					return str_replace('.css', '', $value);
564
+				},
565
+				array_filter(
566
+					array_keys($this->manifest_data[ $namespace ]),
567
+					static function ($value) {
568
+						return strpos($value, '.css') !== false;
569
+					}
570
+				)
571
+			);
572
+			// add known wp chunks with css
573
+			$css_chunks = array_merge( $css_chunks, $this->wp_css_handle_dependencies);
574
+			// flip for easier search
575
+			$css_chunks = array_flip($css_chunks);
576
+
577
+			// now let's filter the dependencies for the incoming chunk to actual chunks that have styles
578
+			$asset_details['dependencies'] = array_filter(
579
+				$asset_details['dependencies'],
580
+				static function ($chunk_name) use ($css_chunks) {
581
+					return isset($css_chunks[ $chunk_name ]);
582
+				}
583
+			);
584
+			return $asset_details;
585
+		}
586
+		return ['dependencies' => [], 'version' => ''];
587
+	}
588
+
589
+
590
+	/**
591
+	 * Get the dependencies array and version string for the given js asset chunk name
592
+	 *
593
+	 * @param string $namespace
594
+	 * @param string $chunk_name
595
+	 * @return array
596
+	 * @since 4.10.2.p
597
+	 */
598
+	public function getJsAssetDetails($namespace, $chunk_name)
599
+	{
600
+		return $this->getDetailsForAsset($namespace, $chunk_name, Asset::TYPE_JS);
601
+	}
602
+
603
+
604
+	/**
605
+	 * Get the dependencies array and version string for the given css asset chunk name
606
+	 *
607
+	 * @param string $namespace
608
+	 * @param string $chunk_name
609
+	 * @return array
610
+	 * @since 4.10.2.p
611
+	 */
612
+	public function getCssAssetDetails($namespace, $chunk_name)
613
+	{
614
+		return $this->getDetailsForAsset($namespace, $chunk_name, Asset::TYPE_CSS);
615
+	}
616
+
617
+
618
+	/**
619
+	 * @throws Exception
620
+	 * @throws InvalidArgumentException
621
+	 * @throws InvalidFilePathException
622
+	 * @since 4.9.62.p
623
+	 */
624
+	public function registerManifestFiles()
625
+	{
626
+		try {
627
+			$manifest_files = $this->assets->getManifestFiles();
628
+			foreach ($manifest_files as $manifest_file) {
629
+				$this->registerManifestFile(
630
+					$manifest_file->assetNamespace(),
631
+					$manifest_file->urlBase(),
632
+					$manifest_file->filepath() . Registry::FILE_NAME_BUILD_MANIFEST,
633
+					$manifest_file->filepath()
634
+				);
635
+			}
636
+		} catch (Exception $exception) {
637
+			EE_Error::add_error($exception->getMessage(), __FILE__, __FUNCTION__, __LINE__);
638
+			new ExceptionStackTraceDisplay($exception);
639
+		}
640
+	}
641
+
642
+
643
+	/**
644
+	 * Used to register a js/css manifest file with the registered_manifest_files property.
645
+	 *
646
+	 * @param string $namespace     Provided to associate the manifest file with a specific namespace.
647
+	 * @param string $url_base      The url base for the manifest file location.
648
+	 * @param string $manifest_file The absolute path to the manifest file.
649
+	 * @param string $manifest_file_path  The path to the folder containing the manifest file. If not provided will be
650
+	 *                                    default to `plugin_root/assets/dist`.
651
+	 * @throws InvalidArgumentException
652
+	 * @throws InvalidFilePathException
653
+	 * @since 4.9.59.p
654
+	 */
655
+	public function registerManifestFile($namespace, $url_base, $manifest_file, $manifest_file_path = '')
656
+	{
657
+		if (isset($this->manifest_data[ $namespace ])) {
658
+			if (! $this->debug()) {
659
+				return;
660
+			}
661
+			throw new InvalidArgumentException(
662
+				sprintf(
663
+					esc_html__(
664
+						'The namespace for this manifest file has already been registered, choose a namespace other than %s',
665
+						'event_espresso'
666
+					),
667
+					$namespace
668
+				)
669
+			);
670
+		}
671
+		if (filter_var($url_base, FILTER_VALIDATE_URL) === false) {
672
+			if (is_admin()) {
673
+				EE_Error::add_error(
674
+					sprintf(
675
+						esc_html__(
676
+							'The url given for %1$s assets is invalid.  The url provided was: "%2$s". This usually happens when another plugin or theme on a site is using the "%3$s" filter or has an invalid url set for the "%4$s" constant',
677
+							'event_espresso'
678
+						),
679
+						'Event Espresso',
680
+						$url_base,
681
+						'plugins_url',
682
+						'WP_PLUGIN_URL'
683
+					),
684
+					__FILE__,
685
+					__FUNCTION__,
686
+					__LINE__
687
+				);
688
+			}
689
+			return;
690
+		}
691
+		$this->manifest_data[ $namespace ] = $this->decodeManifestFile($manifest_file);
692
+		if (! isset($this->manifest_data[ $namespace ]['url_base'])) {
693
+			$this->manifest_data[ $namespace ]['url_base'] = untrailingslashit($url_base);
694
+		}
695
+		if (! isset($this->manifest_data[ $namespace ]['path'])) {
696
+			$this->manifest_data[ $namespace ]['path'] = untrailingslashit($manifest_file_path);
697
+		}
698
+	}
699
+
700
+
701
+	/**
702
+	 * Decodes json from the provided manifest file.
703
+	 *
704
+	 * @since 4.9.59.p
705
+	 * @param string $manifest_file Path to manifest file.
706
+	 * @return array
707
+	 * @throws InvalidFilePathException
708
+	 */
709
+	private function decodeManifestFile($manifest_file)
710
+	{
711
+		if (! file_exists($manifest_file)) {
712
+			throw new InvalidFilePathException($manifest_file);
713
+		}
714
+		return json_decode(file_get_contents($manifest_file), true);
715
+	}
716
+
717
+
718
+	/**
719
+	 * This is used to set registered script handles that have data.
720
+	 *
721
+	 * @param string $script_handle
722
+	 */
723
+	private function addRegisteredScriptHandlesWithData($script_handle)
724
+	{
725
+		$this->script_handles_with_data[ $script_handle ] = $script_handle;
726
+	}
727
+
728
+
729
+	/**i
730 730
      * Checks WP_Scripts for all of each script handle registered internally as having data and unsets from the
731 731
      * Dependency stored in WP_Scripts if its set.
732 732
      */
733
-    private function removeAlreadyRegisteredDataForScriptHandles()
734
-    {
735
-        if (empty($this->script_handles_with_data)) {
736
-            return;
737
-        }
738
-        foreach ($this->script_handles_with_data as $script_handle) {
739
-            $this->removeAlreadyRegisteredDataForScriptHandle($script_handle);
740
-        }
741
-    }
742
-
743
-
744
-    /**
745
-     * Removes any data dependency registered in WP_Scripts if its set.
746
-     *
747
-     * @param string $script_handle
748
-     */
749
-    private function removeAlreadyRegisteredDataForScriptHandle($script_handle)
750
-    {
751
-        if (isset($this->script_handles_with_data[ $script_handle ])) {
752
-            global $wp_scripts;
753
-            $unset_handle = false;
754
-            if ($wp_scripts->get_data($script_handle, 'data')) {
755
-                unset($wp_scripts->registered[ $script_handle ]->extra['data']);
756
-                $unset_handle = true;
757
-            }
758
-            //deal with inline_scripts
759
-            if ($wp_scripts->get_data($script_handle, 'before')) {
760
-                unset($wp_scripts->registered[ $script_handle ]->extra['before']);
761
-                $unset_handle = true;
762
-            }
763
-            if ($wp_scripts->get_data($script_handle, 'after')) {
764
-                unset($wp_scripts->registered[ $script_handle ]->extra['after']);
765
-            }
766
-            if ($unset_handle) {
767
-                unset($this->script_handles_with_data[ $script_handle ]);
768
-            }
769
-        }
770
-    }
771
-
772
-
773
-    /**
774
-     * register translations for a registered script
775
-     *
776
-     * @param string $handle
777
-     */
778
-    public function registerTranslation($handle)
779
-    {
780
-        $this->i18n_registry->registerScriptI18n($handle);
781
-    }
782
-
783
-
784
-    /**
785
-     * @since 4.9.63.p
786
-     * @return bool
787
-     */
788
-    private function debug()
789
-    {
790
-        return apply_filters(
791
-            'FHEE__EventEspresso_core_services_assets_Registry__debug',
792
-            defined('EE_DEBUG') && EE_DEBUG
793
-        );
794
-    }
795
-
796
-
797
-    /**
798
-     * Get the dependencies array for the given js asset chunk name
799
-     *
800
-     * @param string $namespace
801
-     * @param string $chunk_name
802
-     * @return array
803
-     * @deprecated 4.10.2.p
804
-     * @since 4.9.82.p
805
-     */
806
-    public function getJsDependencies($namespace, $chunk_name)
807
-    {
808
-        $details = $this->getJsAssetDetails($namespace, $chunk_name);
809
-        return isset($details['dependencies']) ? $details['dependencies'] : [];
810
-    }
811
-
812
-
813
-    /**
814
-     * Get the dependencies array for the given css asset chunk name
815
-     *
816
-     * @param string $namespace
817
-     * @param string $chunk_name
818
-     * @return array
819
-     * @deprecated 4.10.2.p
820
-     * @since      4.9.82.p
821
-     */
822
-    public function getCssDependencies($namespace, $chunk_name)
823
-    {
824
-        $details = $this->getCssAssetDetails($namespace, $chunk_name);
825
-        return isset($details['dependencies']) ? $details['dependencies'] : [];
826
-    }
733
+	private function removeAlreadyRegisteredDataForScriptHandles()
734
+	{
735
+		if (empty($this->script_handles_with_data)) {
736
+			return;
737
+		}
738
+		foreach ($this->script_handles_with_data as $script_handle) {
739
+			$this->removeAlreadyRegisteredDataForScriptHandle($script_handle);
740
+		}
741
+	}
742
+
743
+
744
+	/**
745
+	 * Removes any data dependency registered in WP_Scripts if its set.
746
+	 *
747
+	 * @param string $script_handle
748
+	 */
749
+	private function removeAlreadyRegisteredDataForScriptHandle($script_handle)
750
+	{
751
+		if (isset($this->script_handles_with_data[ $script_handle ])) {
752
+			global $wp_scripts;
753
+			$unset_handle = false;
754
+			if ($wp_scripts->get_data($script_handle, 'data')) {
755
+				unset($wp_scripts->registered[ $script_handle ]->extra['data']);
756
+				$unset_handle = true;
757
+			}
758
+			//deal with inline_scripts
759
+			if ($wp_scripts->get_data($script_handle, 'before')) {
760
+				unset($wp_scripts->registered[ $script_handle ]->extra['before']);
761
+				$unset_handle = true;
762
+			}
763
+			if ($wp_scripts->get_data($script_handle, 'after')) {
764
+				unset($wp_scripts->registered[ $script_handle ]->extra['after']);
765
+			}
766
+			if ($unset_handle) {
767
+				unset($this->script_handles_with_data[ $script_handle ]);
768
+			}
769
+		}
770
+	}
771
+
772
+
773
+	/**
774
+	 * register translations for a registered script
775
+	 *
776
+	 * @param string $handle
777
+	 */
778
+	public function registerTranslation($handle)
779
+	{
780
+		$this->i18n_registry->registerScriptI18n($handle);
781
+	}
782
+
783
+
784
+	/**
785
+	 * @since 4.9.63.p
786
+	 * @return bool
787
+	 */
788
+	private function debug()
789
+	{
790
+		return apply_filters(
791
+			'FHEE__EventEspresso_core_services_assets_Registry__debug',
792
+			defined('EE_DEBUG') && EE_DEBUG
793
+		);
794
+	}
795
+
796
+
797
+	/**
798
+	 * Get the dependencies array for the given js asset chunk name
799
+	 *
800
+	 * @param string $namespace
801
+	 * @param string $chunk_name
802
+	 * @return array
803
+	 * @deprecated 4.10.2.p
804
+	 * @since 4.9.82.p
805
+	 */
806
+	public function getJsDependencies($namespace, $chunk_name)
807
+	{
808
+		$details = $this->getJsAssetDetails($namespace, $chunk_name);
809
+		return isset($details['dependencies']) ? $details['dependencies'] : [];
810
+	}
811
+
812
+
813
+	/**
814
+	 * Get the dependencies array for the given css asset chunk name
815
+	 *
816
+	 * @param string $namespace
817
+	 * @param string $chunk_name
818
+	 * @return array
819
+	 * @deprecated 4.10.2.p
820
+	 * @since      4.9.82.p
821
+	 */
822
+	public function getCssDependencies($namespace, $chunk_name)
823
+	{
824
+		$details = $this->getCssAssetDetails($namespace, $chunk_name);
825
+		return isset($details['dependencies']) ? $details['dependencies'] : [];
826
+	}
827 827
 }
Please login to merge, or discard this patch.
admin_pages/transactions/Transactions_Admin_Page.core.php 1 patch
Indentation   +2549 added lines, -2549 removed lines patch added patch discarded remove patch
@@ -13,2553 +13,2553 @@
 block discarded – undo
13 13
 class Transactions_Admin_Page extends EE_Admin_Page
14 14
 {
15 15
 
16
-    /**
17
-     * @var EE_Transaction
18
-     */
19
-    private $_transaction;
20
-
21
-    /**
22
-     * @var EE_Session
23
-     */
24
-    private $_session;
25
-
26
-    /**
27
-     * @var array $_txn_status
28
-     */
29
-    private static $_txn_status;
30
-
31
-    /**
32
-     * @var array $_pay_status
33
-     */
34
-    private static $_pay_status;
35
-
36
-    /**
37
-     * @var array $_existing_reg_payment_REG_IDs
38
-     */
39
-    protected $_existing_reg_payment_REG_IDs;
40
-
41
-
42
-    /**
43
-     *    _init_page_props
44
-     *
45
-     * @return void
46
-     */
47
-    protected function _init_page_props()
48
-    {
49
-        $this->page_slug = TXN_PG_SLUG;
50
-        $this->page_label = esc_html__('Transactions', 'event_espresso');
51
-        $this->_admin_base_url = TXN_ADMIN_URL;
52
-        $this->_admin_base_path = TXN_ADMIN;
53
-    }
54
-
55
-
56
-    /**
57
-     *    _ajax_hooks
58
-     *
59
-     * @return void
60
-     */
61
-    protected function _ajax_hooks()
62
-    {
63
-        add_action('wp_ajax_espresso_apply_payment', array($this, 'apply_payments_or_refunds'));
64
-        add_action('wp_ajax_espresso_apply_refund', array($this, 'apply_payments_or_refunds'));
65
-        add_action('wp_ajax_espresso_delete_payment', array($this, 'delete_payment'));
66
-    }
67
-
68
-
69
-    /**
70
-     *    _define_page_props
71
-     *
72
-     * @return void
73
-     */
74
-    protected function _define_page_props()
75
-    {
76
-        $this->_admin_page_title = $this->page_label;
77
-        $this->_labels = array(
78
-            'buttons' => array(
79
-                'add'    => esc_html__('Add New Transaction', 'event_espresso'),
80
-                'edit'   => esc_html__('Edit Transaction', 'event_espresso'),
81
-                'delete' => esc_html__('Delete Transaction', 'event_espresso'),
82
-            ),
83
-        );
84
-    }
85
-
86
-
87
-    /**
88
-     *        grab url requests and route them
89
-     *
90
-     * @access private
91
-     * @return void
92
-     * @throws EE_Error
93
-     * @throws InvalidArgumentException
94
-     * @throws InvalidDataTypeException
95
-     * @throws InvalidInterfaceException
96
-     */
97
-    public function _set_page_routes()
98
-    {
99
-
100
-        $this->_set_transaction_status_array();
101
-
102
-        $txn_id = ! empty($this->_req_data['TXN_ID'])
103
-                  && ! is_array($this->_req_data['TXN_ID'])
104
-            ? $this->_req_data['TXN_ID']
105
-            : 0;
106
-
107
-        $this->_page_routes = array(
108
-
109
-            'default' => array(
110
-                'func'       => '_transactions_overview_list_table',
111
-                'capability' => 'ee_read_transactions',
112
-            ),
113
-
114
-            'view_transaction' => array(
115
-                'func'       => '_transaction_details',
116
-                'capability' => 'ee_read_transaction',
117
-                'obj_id'     => $txn_id,
118
-            ),
119
-
120
-            'send_payment_reminder' => array(
121
-                'func'       => '_send_payment_reminder',
122
-                'noheader'   => true,
123
-                'capability' => 'ee_send_message',
124
-            ),
125
-
126
-            'espresso_apply_payment' => array(
127
-                'func'       => 'apply_payments_or_refunds',
128
-                'noheader'   => true,
129
-                'capability' => 'ee_edit_payments',
130
-            ),
131
-
132
-            'espresso_apply_refund' => array(
133
-                'func'       => 'apply_payments_or_refunds',
134
-                'noheader'   => true,
135
-                'capability' => 'ee_edit_payments',
136
-            ),
137
-
138
-            'espresso_delete_payment' => array(
139
-                'func'       => 'delete_payment',
140
-                'noheader'   => true,
141
-                'capability' => 'ee_delete_payments',
142
-            ),
143
-
144
-            'espresso_recalculate_line_items' => array(
145
-                'func'       => 'recalculateLineItems',
146
-                'noheader'   => true,
147
-                'capability' => 'ee_edit_payments',
148
-            ),
149
-
150
-        );
151
-    }
152
-
153
-
154
-    protected function _set_page_config()
155
-    {
156
-        $this->_page_config = array(
157
-            'default'          => array(
158
-                'nav'           => array(
159
-                    'label' => esc_html__('Overview', 'event_espresso'),
160
-                    'order' => 10,
161
-                ),
162
-                'list_table'    => 'EE_Admin_Transactions_List_Table',
163
-                'help_tabs'     => array(
164
-                    'transactions_overview_help_tab'                       => array(
165
-                        'title'    => esc_html__('Transactions Overview', 'event_espresso'),
166
-                        'filename' => 'transactions_overview',
167
-                    ),
168
-                    'transactions_overview_table_column_headings_help_tab' => array(
169
-                        'title'    => esc_html__('Transactions Table Column Headings', 'event_espresso'),
170
-                        'filename' => 'transactions_overview_table_column_headings',
171
-                    ),
172
-                    'transactions_overview_views_filters_help_tab'         => array(
173
-                        'title'    => esc_html__('Transaction Views & Filters & Search', 'event_espresso'),
174
-                        'filename' => 'transactions_overview_views_filters_search',
175
-                    ),
176
-                ),
177
-                'help_tour'     => array('Transactions_Overview_Help_Tour'),
178
-                /**
179
-                 * commented out because currently we are not displaying tips for transaction list table status but this
180
-                 * may change in a later iteration so want to keep the code for then.
181
-                 */
182
-                // 'qtips' => array( 'Transactions_List_Table_Tips' ),
183
-                'require_nonce' => false,
184
-            ),
185
-            'view_transaction' => array(
186
-                'nav'       => array(
187
-                    'label'      => esc_html__('View Transaction', 'event_espresso'),
188
-                    'order'      => 5,
189
-                    'url'        => isset($this->_req_data['TXN_ID'])
190
-                        ? add_query_arg(array('TXN_ID' => $this->_req_data['TXN_ID']), $this->_current_page_view_url)
191
-                        : $this->_admin_base_url,
192
-                    'persistent' => false,
193
-                ),
194
-                'help_tabs' => array(
195
-                    'transactions_view_transaction_help_tab'                                              => array(
196
-                        'title'    => esc_html__('View Transaction', 'event_espresso'),
197
-                        'filename' => 'transactions_view_transaction',
198
-                    ),
199
-                    'transactions_view_transaction_transaction_details_table_help_tab'                    => array(
200
-                        'title'    => esc_html__('Transaction Details Table', 'event_espresso'),
201
-                        'filename' => 'transactions_view_transaction_transaction_details_table',
202
-                    ),
203
-                    'transactions_view_transaction_attendees_registered_help_tab'                         => array(
204
-                        'title'    => esc_html__('Attendees Registered', 'event_espresso'),
205
-                        'filename' => 'transactions_view_transaction_attendees_registered',
206
-                    ),
207
-                    'transactions_view_transaction_views_primary_registrant_billing_information_help_tab' => array(
208
-                        'title'    => esc_html__('Primary Registrant & Billing Information', 'event_espresso'),
209
-                        'filename' => 'transactions_view_transaction_primary_registrant_billing_information',
210
-                    ),
211
-                ),
212
-                'qtips'     => array('Transaction_Details_Tips'),
213
-                'help_tour' => array('Transaction_Details_Help_Tour'),
214
-                'metaboxes' => array('_transaction_details_metaboxes'),
215
-
216
-                'require_nonce' => false,
217
-            ),
218
-        );
219
-    }
220
-
221
-
222
-    /**
223
-     * The below methods aren't used by this class currently
224
-     */
225
-    protected function _add_screen_options()
226
-    {
227
-        // noop
228
-    }
229
-
230
-
231
-    protected function _add_feature_pointers()
232
-    {
233
-        // noop
234
-    }
235
-
236
-
237
-    public function admin_init()
238
-    {
239
-        // IF a registration was JUST added via the admin...
240
-        if (isset(
241
-            $this->_req_data['redirect_from'],
242
-            $this->_req_data['EVT_ID'],
243
-            $this->_req_data['event_name']
244
-        )) {
245
-            // then set a cookie so that we can block any attempts to use
246
-            // the back button as a way to enter another registration.
247
-            setcookie(
248
-                'ee_registration_added',
249
-                $this->_req_data['EVT_ID'],
250
-                time() + WEEK_IN_SECONDS,
251
-                '/'
252
-            );
253
-            // and update the global
254
-            $_COOKIE['ee_registration_added'] = $this->_req_data['EVT_ID'];
255
-        }
256
-        EE_Registry::$i18n_js_strings['invalid_server_response'] = esc_html__(
257
-            'An error occurred! Your request may have been processed, but a valid response from the server was not received. Please refresh the page and try again.',
258
-            'event_espresso'
259
-        );
260
-        EE_Registry::$i18n_js_strings['error_occurred'] = esc_html__(
261
-            'An error occurred! Please refresh the page and try again.',
262
-            'event_espresso'
263
-        );
264
-        EE_Registry::$i18n_js_strings['txn_status_array'] = self::$_txn_status;
265
-        EE_Registry::$i18n_js_strings['pay_status_array'] = self::$_pay_status;
266
-        EE_Registry::$i18n_js_strings['payments_total'] = esc_html__('Payments Total', 'event_espresso');
267
-        EE_Registry::$i18n_js_strings['transaction_overpaid'] = esc_html__(
268
-            'This transaction has been overpaid ! Payments Total',
269
-            'event_espresso'
270
-        );
271
-    }
272
-
273
-
274
-    public function admin_notices()
275
-    {
276
-        // noop
277
-    }
278
-
279
-
280
-    public function admin_footer_scripts()
281
-    {
282
-        // noop
283
-    }
284
-
285
-
286
-    /**
287
-     * _set_transaction_status_array
288
-     * sets list of transaction statuses
289
-     *
290
-     * @access private
291
-     * @return void
292
-     * @throws EE_Error
293
-     * @throws InvalidArgumentException
294
-     * @throws InvalidDataTypeException
295
-     * @throws InvalidInterfaceException
296
-     */
297
-    private function _set_transaction_status_array()
298
-    {
299
-        self::$_txn_status = EEM_Transaction::instance()->status_array(true);
300
-    }
301
-
302
-
303
-    /**
304
-     * get_transaction_status_array
305
-     * return the transaction status array for wp_list_table
306
-     *
307
-     * @access public
308
-     * @return array
309
-     */
310
-    public function get_transaction_status_array()
311
-    {
312
-        return self::$_txn_status;
313
-    }
314
-
315
-
316
-    /**
317
-     *    get list of payment statuses
318
-     *
319
-     * @access private
320
-     * @return void
321
-     * @throws EE_Error
322
-     * @throws InvalidArgumentException
323
-     * @throws InvalidDataTypeException
324
-     * @throws InvalidInterfaceException
325
-     */
326
-    private function _get_payment_status_array()
327
-    {
328
-        self::$_pay_status = EEM_Payment::instance()->status_array(true);
329
-        $this->_template_args['payment_status'] = self::$_pay_status;
330
-    }
331
-
332
-
333
-    /**
334
-     *    _add_screen_options_default
335
-     *
336
-     * @access protected
337
-     * @return void
338
-     * @throws InvalidArgumentException
339
-     * @throws InvalidDataTypeException
340
-     * @throws InvalidInterfaceException
341
-     */
342
-    protected function _add_screen_options_default()
343
-    {
344
-        $this->_per_page_screen_option();
345
-    }
346
-
347
-
348
-    /**
349
-     * load_scripts_styles
350
-     *
351
-     * @access public
352
-     * @return void
353
-     */
354
-    public function load_scripts_styles()
355
-    {
356
-        // enqueue style
357
-        wp_register_style(
358
-            'espresso_txn',
359
-            TXN_ASSETS_URL . 'espresso_transactions_admin.css',
360
-            array(),
361
-            EVENT_ESPRESSO_VERSION
362
-        );
363
-        wp_enqueue_style('espresso_txn');
364
-        // scripts
365
-        wp_register_script(
366
-            'espresso_txn',
367
-            TXN_ASSETS_URL . 'espresso_transactions_admin.js',
368
-            array(
369
-                'ee_admin_js',
370
-                'ee-datepicker',
371
-                'jquery-ui-datepicker',
372
-                'jquery-ui-draggable',
373
-                'ee-dialog',
374
-                'ee-accounting',
375
-                'ee-serialize-full-array',
376
-            ),
377
-            EVENT_ESPRESSO_VERSION,
378
-            true
379
-        );
380
-        wp_enqueue_script('espresso_txn');
381
-    }
382
-
383
-
384
-    /**
385
-     *    load_scripts_styles_view_transaction
386
-     *
387
-     * @access public
388
-     * @return void
389
-     */
390
-    public function load_scripts_styles_view_transaction()
391
-    {
392
-        // styles
393
-        wp_enqueue_style('espresso-ui-theme');
394
-    }
395
-
396
-
397
-    /**
398
-     *    load_scripts_styles_default
399
-     *
400
-     * @access public
401
-     * @return void
402
-     */
403
-    public function load_scripts_styles_default()
404
-    {
405
-        // styles
406
-        wp_enqueue_style('espresso-ui-theme');
407
-    }
408
-
409
-
410
-    /**
411
-     *    _set_list_table_views_default
412
-     *
413
-     * @access protected
414
-     * @return void
415
-     */
416
-    protected function _set_list_table_views_default()
417
-    {
418
-        $this->_views = array(
419
-            'all'        => array(
420
-                'slug'  => 'all',
421
-                'label' => esc_html__('View All Transactions', 'event_espresso'),
422
-                'count' => 0,
423
-            ),
424
-            'abandoned'  => array(
425
-                'slug'  => 'abandoned',
426
-                'label' => esc_html__('Abandoned Transactions', 'event_espresso'),
427
-                'count' => 0,
428
-            ),
429
-            'incomplete' => array(
430
-                'slug'  => 'incomplete',
431
-                'label' => esc_html__('Incomplete Transactions', 'event_espresso'),
432
-                'count' => 0,
433
-            ),
434
-        );
435
-        if (/**
436
-         * Filters whether a link to the "Failed Transactions" list table
437
-         * appears on the Transactions Admin Page list table.
438
-         * List display can be turned back on via the following:
439
-         * add_filter(
440
-         *     'FHEE__Transactions_Admin_Page___set_list_table_views_default__display_failed_txns_list',
441
-         *     '__return_true'
442
-         * );
443
-         *
444
-         * @since 4.9.70.p
445
-         * @param boolean                 $display_failed_txns_list
446
-         * @param Transactions_Admin_Page $this
447
-         */
448
-        apply_filters(
449
-            'FHEE__Transactions_Admin_Page___set_list_table_views_default__display_failed_txns_list',
450
-            false,
451
-            $this
452
-        )
453
-        ) {
454
-            $this->_views['failed'] = array(
455
-                'slug'  => 'failed',
456
-                'label' => esc_html__('Failed Transactions', 'event_espresso'),
457
-                'count' => 0,
458
-            );
459
-        }
460
-    }
461
-
462
-
463
-    /**
464
-     * _set_transaction_object
465
-     * This sets the _transaction property for the transaction details screen
466
-     *
467
-     * @access private
468
-     * @return void
469
-     * @throws EE_Error
470
-     * @throws InvalidArgumentException
471
-     * @throws RuntimeException
472
-     * @throws InvalidDataTypeException
473
-     * @throws InvalidInterfaceException
474
-     * @throws ReflectionException
475
-     */
476
-    private function _set_transaction_object()
477
-    {
478
-        if ($this->_transaction instanceof EE_Transaction) {
479
-            return;
480
-        } //get out we've already set the object
481
-
482
-        $TXN_ID = ! empty($this->_req_data['TXN_ID'])
483
-            ? absint($this->_req_data['TXN_ID'])
484
-            : false;
485
-
486
-        // get transaction object
487
-        $this->_transaction = EEM_Transaction::instance()->get_one_by_ID($TXN_ID);
488
-        $this->_session = $this->_transaction instanceof EE_Transaction
489
-            ? $this->_transaction->session_data()
490
-            : null;
491
-        if ($this->_transaction instanceof EE_Transaction) {
492
-            $this->_transaction->verify_abandoned_transaction_status();
493
-        }
494
-
495
-        if (! $this->_transaction instanceof EE_Transaction) {
496
-            $error_msg = sprintf(
497
-                esc_html__(
498
-                    'An error occurred and the details for the transaction with the ID # %d could not be retrieved.',
499
-                    'event_espresso'
500
-                ),
501
-                $TXN_ID
502
-            );
503
-            EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__);
504
-        }
505
-    }
506
-
507
-
508
-    /**
509
-     *    _transaction_legend_items
510
-     *
511
-     * @access protected
512
-     * @return array
513
-     * @throws EE_Error
514
-     * @throws InvalidArgumentException
515
-     * @throws ReflectionException
516
-     * @throws InvalidDataTypeException
517
-     * @throws InvalidInterfaceException
518
-     */
519
-    protected function _transaction_legend_items()
520
-    {
521
-        EE_Registry::instance()->load_helper('MSG_Template');
522
-        $items = array();
523
-
524
-        if (EE_Registry::instance()->CAP->current_user_can(
525
-            'ee_read_global_messages',
526
-            'view_filtered_messages'
527
-        )) {
528
-            $related_for_icon = EEH_MSG_Template::get_message_action_icon('see_notifications_for');
529
-            if (is_array($related_for_icon)
530
-                && isset($related_for_icon['css_class'], $related_for_icon['label'])
531
-            ) {
532
-                $items['view_related_messages'] = array(
533
-                    'class' => $related_for_icon['css_class'],
534
-                    'desc'  => $related_for_icon['label'],
535
-                );
536
-            }
537
-        }
538
-
539
-        $items = apply_filters(
540
-            'FHEE__Transactions_Admin_Page___transaction_legend_items__items',
541
-            array_merge(
542
-                $items,
543
-                array(
544
-                    'view_details'          => array(
545
-                        'class' => 'dashicons dashicons-cart',
546
-                        'desc'  => esc_html__('View Transaction Details', 'event_espresso'),
547
-                    ),
548
-                    'view_invoice'          => array(
549
-                        'class' => 'dashicons dashicons-media-spreadsheet',
550
-                        'desc'  => esc_html__('View Transaction Invoice', 'event_espresso'),
551
-                    ),
552
-                    'view_receipt'          => array(
553
-                        'class' => 'dashicons dashicons-media-default',
554
-                        'desc'  => esc_html__('View Transaction Receipt', 'event_espresso'),
555
-                    ),
556
-                    'view_registration'     => array(
557
-                        'class' => 'dashicons dashicons-clipboard',
558
-                        'desc'  => esc_html__('View Registration Details', 'event_espresso'),
559
-                    ),
560
-                    'payment_overview_link' => array(
561
-                        'class' => 'dashicons dashicons-money',
562
-                        'desc'  => esc_html__('Make Payment on Frontend', 'event_espresso'),
563
-                    ),
564
-                )
565
-            )
566
-        );
567
-
568
-        if (EEH_MSG_Template::is_mt_active('payment_reminder')
569
-            && EE_Registry::instance()->CAP->current_user_can(
570
-                'ee_send_message',
571
-                'espresso_transactions_send_payment_reminder'
572
-            )
573
-        ) {
574
-            $items['send_payment_reminder'] = array(
575
-                'class' => 'dashicons dashicons-email-alt',
576
-                'desc'  => esc_html__('Send Payment Reminder', 'event_espresso'),
577
-            );
578
-        }
579
-        $more_items = apply_filters(
580
-            'FHEE__Transactions_Admin_Page___transaction_legend_items__more_items',
581
-            array(
582
-                'overpaid'   => array(
583
-                    'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::overpaid_status_code,
584
-                    'desc'  => EEH_Template::pretty_status(
585
-                        EEM_Transaction::overpaid_status_code,
586
-                        false,
587
-                        'sentence'
588
-                    ),
589
-                ),
590
-                'complete'   => array(
591
-                    'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::complete_status_code,
592
-                    'desc'  => EEH_Template::pretty_status(
593
-                        EEM_Transaction::complete_status_code,
594
-                        false,
595
-                        'sentence'
596
-                    ),
597
-                ),
598
-                'incomplete' => array(
599
-                    'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::incomplete_status_code,
600
-                    'desc'  => EEH_Template::pretty_status(
601
-                        EEM_Transaction::incomplete_status_code,
602
-                        false,
603
-                        'sentence'
604
-                    ),
605
-                ),
606
-                'abandoned'  => array(
607
-                    'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::abandoned_status_code,
608
-                    'desc'  => EEH_Template::pretty_status(
609
-                        EEM_Transaction::abandoned_status_code,
610
-                        false,
611
-                        'sentence'
612
-                    ),
613
-                ),
614
-                'failed'     => array(
615
-                    'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::failed_status_code,
616
-                    'desc'  => EEH_Template::pretty_status(
617
-                        EEM_Transaction::failed_status_code,
618
-                        false,
619
-                        'sentence'
620
-                    ),
621
-                ),
622
-            )
623
-        );
624
-
625
-        return array_merge($items, $more_items);
626
-    }
627
-
628
-
629
-    /**
630
-     *    _transactions_overview_list_table
631
-     *
632
-     * @access protected
633
-     * @return void
634
-     * @throws DomainException
635
-     * @throws EE_Error
636
-     * @throws InvalidArgumentException
637
-     * @throws InvalidDataTypeException
638
-     * @throws InvalidInterfaceException
639
-     * @throws ReflectionException
640
-     */
641
-    protected function _transactions_overview_list_table()
642
-    {
643
-        $this->_admin_page_title = esc_html__('Transactions', 'event_espresso');
644
-        $event = isset($this->_req_data['EVT_ID'])
645
-            ? EEM_Event::instance()->get_one_by_ID($this->_req_data['EVT_ID'])
646
-            : null;
647
-        $this->_template_args['admin_page_header'] = $event instanceof EE_Event
648
-            ? sprintf(
649
-                esc_html__(
650
-                    '%sViewing Transactions for the Event: %s%s',
651
-                    'event_espresso'
652
-                ),
653
-                '<h3>',
654
-                '<a href="'
655
-                . EE_Admin_Page::add_query_args_and_nonce(
656
-                    array('action' => 'edit', 'post' => $event->ID()),
657
-                    EVENTS_ADMIN_URL
658
-                )
659
-                . '" title="'
660
-                . esc_attr__(
661
-                    'Click to Edit event',
662
-                    'event_espresso'
663
-                )
664
-                . '">' . $event->name() . '</a>',
665
-                '</h3>'
666
-            )
667
-            : '';
668
-        $this->_template_args['after_list_table'] = $this->_display_legend($this->_transaction_legend_items());
669
-        $this->display_admin_list_table_page_with_no_sidebar();
670
-    }
671
-
672
-
673
-    /**
674
-     *    _transaction_details
675
-     * generates HTML for the View Transaction Details Admin page
676
-     *
677
-     * @access protected
678
-     * @return void
679
-     * @throws DomainException
680
-     * @throws EE_Error
681
-     * @throws InvalidArgumentException
682
-     * @throws InvalidDataTypeException
683
-     * @throws InvalidInterfaceException
684
-     * @throws RuntimeException
685
-     * @throws ReflectionException
686
-     */
687
-    protected function _transaction_details()
688
-    {
689
-        do_action('AHEE__Transactions_Admin_Page__transaction_details__start', $this->_transaction);
690
-
691
-        $this->_set_transaction_status_array();
692
-
693
-        $this->_template_args = array();
694
-        $this->_template_args['transactions_page'] = $this->_wp_page_slug;
695
-
696
-        $this->_set_transaction_object();
697
-
698
-        if (! $this->_transaction instanceof EE_Transaction) {
699
-            return;
700
-        }
701
-        $primary_registration = $this->_transaction->primary_registration();
702
-        $attendee = $primary_registration instanceof EE_Registration
703
-            ? $primary_registration->attendee()
704
-            : null;
705
-
706
-        $this->_template_args['txn_nmbr']['value'] = $this->_transaction->ID();
707
-        $this->_template_args['txn_nmbr']['label'] = esc_html__('Transaction Number', 'event_espresso');
708
-
709
-        $this->_template_args['txn_datetime']['value'] = $this->_transaction->get_i18n_datetime('TXN_timestamp');
710
-        $this->_template_args['txn_datetime']['label'] = esc_html__('Date', 'event_espresso');
711
-
712
-        $this->_template_args['txn_status']['value'] = self::$_txn_status[ $this->_transaction->status_ID() ];
713
-        $this->_template_args['txn_status']['label'] = esc_html__('Transaction Status', 'event_espresso');
714
-        $this->_template_args['txn_status']['class'] = 'status-' . $this->_transaction->status_ID();
715
-
716
-        $this->_template_args['grand_total'] = $this->_transaction->total();
717
-        $this->_template_args['total_paid'] = $this->_transaction->paid();
718
-
719
-        $amount_due = $this->_transaction->total() - $this->_transaction->paid();
720
-        $this->_template_args['amount_due'] = EEH_Template::format_currency(
721
-            $amount_due,
722
-            true
723
-        );
724
-        if (EE_Registry::instance()->CFG->currency->sign_b4) {
725
-            $this->_template_args['amount_due'] = EE_Registry::instance()->CFG->currency->sign
726
-                                                  . $this->_template_args['amount_due'];
727
-        } else {
728
-            $this->_template_args['amount_due'] .= EE_Registry::instance()->CFG->currency->sign;
729
-        }
730
-        $this->_template_args['amount_due_class'] = '';
731
-
732
-        if ($this->_transaction->paid() === $this->_transaction->total()) {
733
-            // paid in full
734
-            $this->_template_args['amount_due'] = false;
735
-        } elseif ($this->_transaction->paid() > $this->_transaction->total()) {
736
-            // overpaid
737
-            $this->_template_args['amount_due_class'] = 'txn-overview-no-payment-spn';
738
-        } elseif ($this->_transaction->total() > (float) 0) {
739
-            if ($this->_transaction->paid() > (float) 0) {
740
-                // monies owing
741
-                $this->_template_args['amount_due_class'] = 'txn-overview-part-payment-spn';
742
-            } elseif ($this->_transaction->paid() === (float) 0) {
743
-                // no payments made yet
744
-                $this->_template_args['amount_due_class'] = 'txn-overview-no-payment-spn';
745
-            }
746
-        } elseif ($this->_transaction->total() === (float) 0) {
747
-            // free event
748
-            $this->_template_args['amount_due'] = false;
749
-        }
750
-
751
-        $payment_method = $this->_transaction->payment_method();
752
-
753
-        $this->_template_args['method_of_payment_name'] = $payment_method instanceof EE_Payment_Method
754
-            ? $payment_method->admin_name()
755
-            : esc_html__('Unknown', 'event_espresso');
756
-
757
-        $this->_template_args['currency_sign'] = EE_Registry::instance()->CFG->currency->sign;
758
-        // link back to overview
759
-        $this->_template_args['txn_overview_url'] = ! empty($_SERVER['HTTP_REFERER'])
760
-            ? $_SERVER['HTTP_REFERER']
761
-            : TXN_ADMIN_URL;
762
-
763
-
764
-        // next link
765
-        $next_txn = $this->_transaction->next(
766
-            null,
767
-            array(array('STS_ID' => array('!=', EEM_Transaction::failed_status_code))),
768
-            'TXN_ID'
769
-        );
770
-        $this->_template_args['next_transaction'] = $next_txn
771
-            ? $this->_next_link(
772
-                EE_Admin_Page::add_query_args_and_nonce(
773
-                    array('action' => 'view_transaction', 'TXN_ID' => $next_txn['TXN_ID']),
774
-                    TXN_ADMIN_URL
775
-                ),
776
-                'dashicons dashicons-arrow-right ee-icon-size-22'
777
-            )
778
-            : '';
779
-        // previous link
780
-        $previous_txn = $this->_transaction->previous(
781
-            null,
782
-            array(array('STS_ID' => array('!=', EEM_Transaction::failed_status_code))),
783
-            'TXN_ID'
784
-        );
785
-        $this->_template_args['previous_transaction'] = $previous_txn
786
-            ? $this->_previous_link(
787
-                EE_Admin_Page::add_query_args_and_nonce(
788
-                    array('action' => 'view_transaction', 'TXN_ID' => $previous_txn['TXN_ID']),
789
-                    TXN_ADMIN_URL
790
-                ),
791
-                'dashicons dashicons-arrow-left ee-icon-size-22'
792
-            )
793
-            : '';
794
-
795
-        // were we just redirected here after adding a new registration ???
796
-        if (isset(
797
-            $this->_req_data['redirect_from'],
798
-            $this->_req_data['EVT_ID'],
799
-            $this->_req_data['event_name']
800
-        )) {
801
-            if (EE_Registry::instance()->CAP->current_user_can(
802
-                'ee_edit_registrations',
803
-                'espresso_registrations_new_registration',
804
-                $this->_req_data['EVT_ID']
805
-            )) {
806
-                $this->_admin_page_title .= '<a id="add-new-registration" class="add-new-h2 button-primary" href="';
807
-                $this->_admin_page_title .= EE_Admin_Page::add_query_args_and_nonce(
808
-                    array(
809
-                        'page'     => 'espresso_registrations',
810
-                        'action'   => 'new_registration',
811
-                        'return'   => 'default',
812
-                        'TXN_ID'   => $this->_transaction->ID(),
813
-                        'event_id' => $this->_req_data['EVT_ID'],
814
-                    ),
815
-                    REG_ADMIN_URL
816
-                );
817
-                $this->_admin_page_title .= '">';
818
-
819
-                $this->_admin_page_title .= sprintf(
820
-                    esc_html__('Add Another New Registration to Event: "%1$s" ?', 'event_espresso'),
821
-                    htmlentities(urldecode($this->_req_data['event_name']), ENT_QUOTES, 'UTF-8')
822
-                );
823
-                $this->_admin_page_title .= '</a>';
824
-            }
825
-            EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
826
-        }
827
-        // grab messages at the last second
828
-        $this->_template_args['notices'] = EE_Error::get_notices();
829
-        // path to template
830
-        $template_path = TXN_TEMPLATE_PATH . 'txn_admin_details_header.template.php';
831
-        $this->_template_args['admin_page_header'] = EEH_Template::display_template(
832
-            $template_path,
833
-            $this->_template_args,
834
-            true
835
-        );
836
-
837
-        // the details template wrapper
838
-        $this->display_admin_page_with_sidebar();
839
-    }
840
-
841
-
842
-    /**
843
-     *        _transaction_details_metaboxes
844
-     *
845
-     * @access protected
846
-     * @return void
847
-     * @throws EE_Error
848
-     * @throws InvalidArgumentException
849
-     * @throws InvalidDataTypeException
850
-     * @throws InvalidInterfaceException
851
-     * @throws RuntimeException
852
-     * @throws ReflectionException
853
-     */
854
-    protected function _transaction_details_metaboxes()
855
-    {
856
-
857
-        $this->_set_transaction_object();
858
-
859
-        if (! $this->_transaction instanceof EE_Transaction) {
860
-            return;
861
-        }
862
-        add_meta_box(
863
-            'edit-txn-details-mbox',
864
-            esc_html__('Transaction Details', 'event_espresso'),
865
-            array($this, 'txn_details_meta_box'),
866
-            $this->_wp_page_slug,
867
-            'normal',
868
-            'high'
869
-        );
870
-        add_meta_box(
871
-            'edit-txn-attendees-mbox',
872
-            esc_html__('Attendees Registered in this Transaction', 'event_espresso'),
873
-            array($this, 'txn_attendees_meta_box'),
874
-            $this->_wp_page_slug,
875
-            'normal',
876
-            'high',
877
-            array('TXN_ID' => $this->_transaction->ID())
878
-        );
879
-        add_meta_box(
880
-            'edit-txn-registrant-mbox',
881
-            esc_html__('Primary Contact', 'event_espresso'),
882
-            array($this, 'txn_registrant_side_meta_box'),
883
-            $this->_wp_page_slug,
884
-            'side',
885
-            'high'
886
-        );
887
-        add_meta_box(
888
-            'edit-txn-billing-info-mbox',
889
-            esc_html__('Billing Information', 'event_espresso'),
890
-            array($this, 'txn_billing_info_side_meta_box'),
891
-            $this->_wp_page_slug,
892
-            'side',
893
-            'high'
894
-        );
895
-    }
896
-
897
-
898
-    /**
899
-     * Callback for transaction actions metabox.
900
-     *
901
-     * @param EE_Transaction|null $transaction
902
-     * @return string
903
-     * @throws DomainException
904
-     * @throws EE_Error
905
-     * @throws InvalidArgumentException
906
-     * @throws InvalidDataTypeException
907
-     * @throws InvalidInterfaceException
908
-     * @throws ReflectionException
909
-     * @throws RuntimeException
910
-     */
911
-    public function getActionButtons(EE_Transaction $transaction = null)
912
-    {
913
-        $content = '';
914
-        $actions = array();
915
-        if (! $transaction instanceof EE_Transaction) {
916
-            return $content;
917
-        }
918
-        /** @var EE_Registration $primary_registration */
919
-        $primary_registration = $transaction->primary_registration();
920
-        $attendee = $primary_registration instanceof EE_Registration
921
-            ? $primary_registration->attendee()
922
-            : null;
923
-
924
-        if ($attendee instanceof EE_Attendee
925
-            && EE_Registry::instance()->CAP->current_user_can(
926
-                'ee_send_message',
927
-                'espresso_transactions_send_payment_reminder'
928
-            )
929
-        ) {
930
-            $actions['payment_reminder'] =
931
-                EEH_MSG_Template::is_mt_active('payment_reminder')
932
-                && $this->_transaction->status_ID() !== EEM_Transaction::complete_status_code
933
-                && $this->_transaction->status_ID() !== EEM_Transaction::overpaid_status_code
934
-                    ? EEH_Template::get_button_or_link(
935
-                        EE_Admin_Page::add_query_args_and_nonce(
936
-                            array(
937
-                                'action'      => 'send_payment_reminder',
938
-                                'TXN_ID'      => $this->_transaction->ID(),
939
-                                'redirect_to' => 'view_transaction',
940
-                            ),
941
-                            TXN_ADMIN_URL
942
-                        ),
943
-                        esc_html__(' Send Payment Reminder', 'event_espresso'),
944
-                        'button secondary-button',
945
-                        'dashicons dashicons-email-alt'
946
-                    )
947
-                    : '';
948
-        }
949
-
950
-        if (EE_Registry::instance()->CAP->current_user_can(
951
-            'ee_edit_payments',
952
-            'espresso_transactions_recalculate_line_items'
953
-        )
954
-        ) {
955
-            $actions['recalculate_line_items'] = EEH_Template::get_button_or_link(
956
-                EE_Admin_Page::add_query_args_and_nonce(
957
-                    array(
958
-                        'action'      => 'espresso_recalculate_line_items',
959
-                        'TXN_ID'      => $this->_transaction->ID(),
960
-                        'redirect_to' => 'view_transaction',
961
-                    ),
962
-                    TXN_ADMIN_URL
963
-                ),
964
-                esc_html__(' Recalculate Taxes and Total', 'event_espresso'),
965
-                'button secondary-button',
966
-                'dashicons dashicons-update'
967
-            );
968
-        }
969
-
970
-        if ($primary_registration instanceof EE_Registration
971
-            && EEH_MSG_Template::is_mt_active('receipt')
972
-        ) {
973
-            $actions['receipt'] = EEH_Template::get_button_or_link(
974
-                $primary_registration->receipt_url(),
975
-                esc_html__('View Receipt', 'event_espresso'),
976
-                'button secondary-button',
977
-                'dashicons dashicons-media-default'
978
-            );
979
-        }
980
-
981
-        if ($primary_registration instanceof EE_Registration
982
-            && EEH_MSG_Template::is_mt_active('invoice')
983
-        ) {
984
-            $actions['invoice'] = EEH_Template::get_button_or_link(
985
-                $primary_registration->invoice_url(),
986
-                esc_html__('View Invoice', 'event_espresso'),
987
-                'button secondary-button',
988
-                'dashicons dashicons-media-spreadsheet'
989
-            );
990
-        }
991
-        $actions = array_filter(
992
-            apply_filters('FHEE__Transactions_Admin_Page__getActionButtons__actions', $actions, $transaction)
993
-        );
994
-        if ($actions) {
995
-            $content = '<ul>';
996
-            $content .= '<li>' . implode('</li><li>', $actions) . '</li>';
997
-            $content .= '</uL>';
998
-        }
999
-        return $content;
1000
-    }
1001
-
1002
-
1003
-    /**
1004
-     * txn_details_meta_box
1005
-     * generates HTML for the Transaction main meta box
1006
-     *
1007
-     * @return void
1008
-     * @throws DomainException
1009
-     * @throws EE_Error
1010
-     * @throws InvalidArgumentException
1011
-     * @throws InvalidDataTypeException
1012
-     * @throws InvalidInterfaceException
1013
-     * @throws RuntimeException
1014
-     * @throws ReflectionException
1015
-     */
1016
-    public function txn_details_meta_box()
1017
-    {
1018
-        $this->_set_transaction_object();
1019
-        $this->_template_args['TXN_ID'] = $this->_transaction->ID();
1020
-        $this->_template_args['attendee'] = $this->_transaction->primary_registration() instanceof EE_Registration
1021
-            ? $this->_transaction->primary_registration()->attendee()
1022
-            : null;
1023
-        $this->_template_args['can_edit_payments'] = EE_Registry::instance()->CAP->current_user_can(
1024
-            'ee_edit_payments',
1025
-            'apply_payment_or_refund_from_registration_details'
1026
-        );
1027
-        $this->_template_args['can_delete_payments'] = EE_Registry::instance()->CAP->current_user_can(
1028
-            'ee_delete_payments',
1029
-            'delete_payment_from_registration_details'
1030
-        );
1031
-
1032
-        // get line table
1033
-        EEH_Autoloader::register_line_item_display_autoloaders();
1034
-        $Line_Item_Display = new EE_Line_Item_Display(
1035
-            'admin_table',
1036
-            'EE_Admin_Table_Line_Item_Display_Strategy'
1037
-        );
1038
-        $this->_template_args['line_item_table'] = $Line_Item_Display->display_line_item(
1039
-            $this->_transaction->total_line_item()
1040
-        );
1041
-        $this->_template_args['REG_code'] = $this->_transaction->primary_registration()->reg_code();
1042
-
1043
-        // process taxes
1044
-        $taxes = $this->_transaction->line_items(array(array('LIN_type' => EEM_Line_Item::type_tax)));
1045
-        $this->_template_args['taxes'] = ! empty($taxes) ? $taxes : false;
1046
-
1047
-        $this->_template_args['grand_total'] = EEH_Template::format_currency(
1048
-            $this->_transaction->total(),
1049
-            false,
1050
-            false
1051
-        );
1052
-        $this->_template_args['grand_raw_total'] = $this->_transaction->total();
1053
-        $this->_template_args['TXN_status'] = $this->_transaction->status_ID();
1054
-
1055
-        // process payment details
1056
-        $payments = $this->_transaction->payments();
1057
-        if (! empty($payments)) {
1058
-            $this->_template_args['payments'] = $payments;
1059
-            $this->_template_args['existing_reg_payments'] = $this->_get_registration_payment_IDs($payments);
1060
-        } else {
1061
-            $this->_template_args['payments'] = false;
1062
-            $this->_template_args['existing_reg_payments'] = array();
1063
-        }
1064
-
1065
-        $this->_template_args['edit_payment_url'] = add_query_arg(array('action' => 'edit_payment'), TXN_ADMIN_URL);
1066
-        $this->_template_args['delete_payment_url'] = add_query_arg(
1067
-            array('action' => 'espresso_delete_payment'),
1068
-            TXN_ADMIN_URL
1069
-        );
1070
-
1071
-        if (isset($txn_details['invoice_number'])) {
1072
-            $this->_template_args['txn_details']['invoice_number']['value'] = $this->_template_args['REG_code'];
1073
-            $this->_template_args['txn_details']['invoice_number']['label'] = esc_html__(
1074
-                'Invoice Number',
1075
-                'event_espresso'
1076
-            );
1077
-        }
1078
-
1079
-        $this->_template_args['txn_details']['registration_session']['value'] = $this->_transaction
1080
-            ->primary_registration()
1081
-            ->session_ID();
1082
-        $this->_template_args['txn_details']['registration_session']['label'] = esc_html__(
1083
-            'Registration Session',
1084
-            'event_espresso'
1085
-        );
1086
-
1087
-        $this->_template_args['txn_details']['ip_address']['value'] = isset($this->_session['ip_address'])
1088
-            ? $this->_session['ip_address']
1089
-            : '';
1090
-        $this->_template_args['txn_details']['ip_address']['label'] = esc_html__(
1091
-            'Transaction placed from IP',
1092
-            'event_espresso'
1093
-        );
1094
-
1095
-        $this->_template_args['txn_details']['user_agent']['value'] = isset($this->_session['user_agent'])
1096
-            ? $this->_session['user_agent']
1097
-            : '';
1098
-        $this->_template_args['txn_details']['user_agent']['label'] = esc_html__(
1099
-            'Registrant User Agent',
1100
-            'event_espresso'
1101
-        );
1102
-
1103
-        $reg_steps = '<ul>';
1104
-        foreach ($this->_transaction->reg_steps() as $reg_step => $reg_step_status) {
1105
-            if ($reg_step_status === true) {
1106
-                $reg_steps .= '<li style="color:#70cc50">'
1107
-                              . sprintf(
1108
-                                  esc_html__('%1$s : Completed', 'event_espresso'),
1109
-                                  ucwords(str_replace('_', ' ', $reg_step))
1110
-                              )
1111
-                              . '</li>';
1112
-            } elseif (is_numeric($reg_step_status) && $reg_step_status !== false) {
1113
-                $reg_steps .= '<li style="color:#2EA2CC">'
1114
-                              . sprintf(
1115
-                                  esc_html__('%1$s : Initiated %2$s', 'event_espresso'),
1116
-                                  ucwords(str_replace('_', ' ', $reg_step)),
1117
-                                  date(
1118
-                                      get_option('date_format') . ' ' . get_option('time_format'),
1119
-                                      $reg_step_status + (get_option('gmt_offset') * HOUR_IN_SECONDS)
1120
-                                  )
1121
-                              )
1122
-                              . '</li>';
1123
-            } else {
1124
-                $reg_steps .= '<li style="color:#E76700">'
1125
-                              . sprintf(
1126
-                                  esc_html__('%1$s : Never Initiated', 'event_espresso'),
1127
-                                  ucwords(str_replace('_', ' ', $reg_step))
1128
-                              )
1129
-                              . '</li>';
1130
-            }
1131
-        }
1132
-        $reg_steps .= '</ul>';
1133
-        $this->_template_args['txn_details']['reg_steps']['value'] = $reg_steps;
1134
-        $this->_template_args['txn_details']['reg_steps']['label'] = esc_html__(
1135
-            'Registration Step Progress',
1136
-            'event_espresso'
1137
-        );
1138
-
1139
-
1140
-        $this->_get_registrations_to_apply_payment_to();
1141
-        $this->_get_payment_methods($payments);
1142
-        $this->_get_payment_status_array();
1143
-        $this->_get_reg_status_selection(); // sets up the template args for the reg status array for the transaction.
1144
-
1145
-        $this->_template_args['transaction_form_url'] = add_query_arg(
1146
-            array(
1147
-                'action'  => 'edit_transaction',
1148
-                'process' => 'transaction',
1149
-            ),
1150
-            TXN_ADMIN_URL
1151
-        );
1152
-        $this->_template_args['apply_payment_form_url'] = add_query_arg(
1153
-            array(
1154
-                'page'   => 'espresso_transactions',
1155
-                'action' => 'espresso_apply_payment',
1156
-            ),
1157
-            WP_AJAX_URL
1158
-        );
1159
-        $this->_template_args['delete_payment_form_url'] = add_query_arg(
1160
-            array(
1161
-                'page'   => 'espresso_transactions',
1162
-                'action' => 'espresso_delete_payment',
1163
-            ),
1164
-            WP_AJAX_URL
1165
-        );
1166
-
1167
-        $this->_template_args['action_buttons'] = $this->getActionButtons($this->_transaction);
1168
-
1169
-        // 'espresso_delete_payment_nonce'
1170
-
1171
-        $template_path = TXN_TEMPLATE_PATH . 'txn_admin_details_main_meta_box_txn_details.template.php';
1172
-        echo EEH_Template::display_template($template_path, $this->_template_args, true);
1173
-    }
1174
-
1175
-
1176
-    /**
1177
-     * _get_registration_payment_IDs
1178
-     *    generates an array of Payment IDs and their corresponding Registration IDs
1179
-     *
1180
-     * @access protected
1181
-     * @param EE_Payment[] $payments
1182
-     * @return array
1183
-     * @throws EE_Error
1184
-     * @throws InvalidArgumentException
1185
-     * @throws InvalidDataTypeException
1186
-     * @throws InvalidInterfaceException
1187
-     * @throws ReflectionException
1188
-     */
1189
-    protected function _get_registration_payment_IDs($payments = array())
1190
-    {
1191
-        $existing_reg_payments = array();
1192
-        // get all reg payments for these payments
1193
-        $reg_payments = EEM_Registration_Payment::instance()->get_all(
1194
-            array(
1195
-                array(
1196
-                    'PAY_ID' => array(
1197
-                        'IN',
1198
-                        array_keys($payments),
1199
-                    ),
1200
-                ),
1201
-            )
1202
-        );
1203
-        if (! empty($reg_payments)) {
1204
-            foreach ($payments as $payment) {
1205
-                if (! $payment instanceof EE_Payment) {
1206
-                    continue;
1207
-                } elseif (! isset($existing_reg_payments[ $payment->ID() ])) {
1208
-                    $existing_reg_payments[ $payment->ID() ] = array();
1209
-                }
1210
-                foreach ($reg_payments as $reg_payment) {
1211
-                    if ($reg_payment instanceof EE_Registration_Payment
1212
-                        && $reg_payment->payment_ID() === $payment->ID()
1213
-                    ) {
1214
-                        $existing_reg_payments[ $payment->ID() ][] = $reg_payment->registration_ID();
1215
-                    }
1216
-                }
1217
-            }
1218
-        }
1219
-
1220
-        return $existing_reg_payments;
1221
-    }
1222
-
1223
-
1224
-    /**
1225
-     * _get_registrations_to_apply_payment_to
1226
-     *    generates HTML for displaying a series of checkboxes in the admin payment modal window
1227
-     * which allows the admin to only apply the payment to the specific registrations
1228
-     *
1229
-     * @access protected
1230
-     * @return void
1231
-     * @throws EE_Error
1232
-     * @throws InvalidArgumentException
1233
-     * @throws InvalidDataTypeException
1234
-     * @throws InvalidInterfaceException
1235
-     * @throws ReflectionException
1236
-     */
1237
-    protected function _get_registrations_to_apply_payment_to()
1238
-    {
1239
-        // we want any registration with an active status (ie: not deleted or cancelled)
1240
-        $query_params = array(
1241
-            array(
1242
-                'STS_ID' => array(
1243
-                    'IN',
1244
-                    array(
1245
-                        EEM_Registration::status_id_approved,
1246
-                        EEM_Registration::status_id_pending_payment,
1247
-                        EEM_Registration::status_id_not_approved,
1248
-                    ),
1249
-                ),
1250
-            ),
1251
-        );
1252
-        $registrations_to_apply_payment_to = EEH_HTML::br() . EEH_HTML::div(
1253
-            '',
1254
-            'txn-admin-apply-payment-to-registrations-dv',
1255
-            '',
1256
-            'clear: both; margin: 1.5em 0 0; display: none;'
1257
-        );
1258
-        $registrations_to_apply_payment_to .= EEH_HTML::br() . EEH_HTML::div('', '', 'admin-primary-mbox-tbl-wrap');
1259
-        $registrations_to_apply_payment_to .= EEH_HTML::table('', '', 'admin-primary-mbox-tbl');
1260
-        $registrations_to_apply_payment_to .= EEH_HTML::thead(
1261
-            EEH_HTML::tr(
1262
-                EEH_HTML::th(esc_html__('ID', 'event_espresso')) .
1263
-                EEH_HTML::th(esc_html__('Registrant', 'event_espresso')) .
1264
-                EEH_HTML::th(esc_html__('Ticket', 'event_espresso')) .
1265
-                EEH_HTML::th(esc_html__('Event', 'event_espresso')) .
1266
-                EEH_HTML::th(esc_html__('Paid', 'event_espresso'), '', 'txn-admin-payment-paid-td jst-cntr') .
1267
-                EEH_HTML::th(esc_html__('Owing', 'event_espresso'), '', 'txn-admin-payment-owing-td jst-cntr') .
1268
-                EEH_HTML::th(esc_html__('Apply', 'event_espresso'), '', 'jst-cntr')
1269
-            )
1270
-        );
1271
-        $registrations_to_apply_payment_to .= EEH_HTML::tbody();
1272
-        // get registrations for TXN
1273
-        $registrations = $this->_transaction->registrations($query_params);
1274
-        $existing_reg_payments = $this->_template_args['existing_reg_payments'];
1275
-        foreach ($registrations as $registration) {
1276
-            if ($registration instanceof EE_Registration) {
1277
-                $attendee_name = $registration->attendee() instanceof EE_Attendee
1278
-                    ? $registration->attendee()->full_name()
1279
-                    : esc_html__('Unknown Attendee', 'event_espresso');
1280
-                $owing = $registration->final_price() - $registration->paid();
1281
-                $taxable = $registration->ticket()->taxable()
1282
-                    ? ' <span class="smaller-text lt-grey-text"> ' . esc_html__('+ tax', 'event_espresso') . '</span>'
1283
-                    : '';
1284
-                $checked = empty($existing_reg_payments)
1285
-                           || in_array($registration->ID(), $existing_reg_payments, true)
1286
-                    ? ' checked="checked"'
1287
-                    : '';
1288
-                $disabled = $registration->final_price() > 0 ? '' : ' disabled';
1289
-                $registrations_to_apply_payment_to .= EEH_HTML::tr(
1290
-                    EEH_HTML::td($registration->ID()) .
1291
-                    EEH_HTML::td($attendee_name) .
1292
-                    EEH_HTML::td(
1293
-                        $registration->ticket()->name() . ' : ' . $registration->ticket()->pretty_price() . $taxable
1294
-                    ) .
1295
-                    EEH_HTML::td($registration->event_name()) .
1296
-                    EEH_HTML::td($registration->pretty_paid(), '', 'txn-admin-payment-paid-td jst-cntr') .
1297
-                    EEH_HTML::td(
1298
-                        EEH_Template::format_currency($owing),
1299
-                        '',
1300
-                        'txn-admin-payment-owing-td jst-cntr'
1301
-                    ) .
1302
-                    EEH_HTML::td(
1303
-                        '<input type="checkbox" value="' . $registration->ID()
1304
-                        . '" name="txn_admin_payment[registrations]"'
1305
-                        . $checked . $disabled . '>',
1306
-                        '',
1307
-                        'jst-cntr'
1308
-                    ),
1309
-                    'apply-payment-registration-row-' . $registration->ID()
1310
-                );
1311
-            }
1312
-        }
1313
-        $registrations_to_apply_payment_to .= EEH_HTML::tbodyx();
1314
-        $registrations_to_apply_payment_to .= EEH_HTML::tablex();
1315
-        $registrations_to_apply_payment_to .= EEH_HTML::divx();
1316
-        $registrations_to_apply_payment_to .= EEH_HTML::p(
1317
-            esc_html__(
1318
-                'The payment will only be applied to the registrations that have a check mark in their corresponding check box. Checkboxes for free registrations have been disabled.',
1319
-                'event_espresso'
1320
-            ),
1321
-            '',
1322
-            'clear description'
1323
-        );
1324
-        $registrations_to_apply_payment_to .= EEH_HTML::divx();
1325
-        $this->_template_args['registrations_to_apply_payment_to'] = $registrations_to_apply_payment_to;
1326
-    }
1327
-
1328
-
1329
-    /**
1330
-     * _get_reg_status_selection
1331
-     *
1332
-     * @todo   this will need to be adjusted either once MER comes along OR we move default reg status to tickets
1333
-     *         instead of events.
1334
-     * @access protected
1335
-     * @return void
1336
-     * @throws EE_Error
1337
-     */
1338
-    protected function _get_reg_status_selection()
1339
-    {
1340
-        // first get all possible statuses
1341
-        $statuses = EEM_Registration::reg_status_array(array(), true);
1342
-        // let's add a "don't change" option.
1343
-        $status_array['NAN'] = esc_html__('Leave the Same', 'event_espresso');
1344
-        $status_array = array_merge($status_array, $statuses);
1345
-        $this->_template_args['status_change_select'] = EEH_Form_Fields::select_input(
1346
-            'txn_reg_status_change[reg_status]',
1347
-            $status_array,
1348
-            'NAN',
1349
-            'id="txn-admin-payment-reg-status-inp"',
1350
-            'txn-reg-status-change-reg-status'
1351
-        );
1352
-        $this->_template_args['delete_status_change_select'] = EEH_Form_Fields::select_input(
1353
-            'delete_txn_reg_status_change[reg_status]',
1354
-            $status_array,
1355
-            'NAN',
1356
-            'delete-txn-admin-payment-reg-status-inp',
1357
-            'delete-txn-reg-status-change-reg-status'
1358
-        );
1359
-    }
1360
-
1361
-
1362
-    /**
1363
-     *    _get_payment_methods
1364
-     * Gets all the payment methods available generally, or the ones that are already
1365
-     * selected on these payments (in case their payment methods are no longer active).
1366
-     * Has the side-effect of updating the template args' payment_methods item
1367
-     *
1368
-     * @access private
1369
-     * @param EE_Payment[] to show on this page
1370
-     * @return void
1371
-     * @throws EE_Error
1372
-     * @throws InvalidArgumentException
1373
-     * @throws InvalidDataTypeException
1374
-     * @throws InvalidInterfaceException
1375
-     * @throws ReflectionException
1376
-     */
1377
-    private function _get_payment_methods($payments = array())
1378
-    {
1379
-        $payment_methods_of_payments = array();
1380
-        foreach ($payments as $payment) {
1381
-            if ($payment instanceof EE_Payment) {
1382
-                $payment_methods_of_payments[] = $payment->ID();
1383
-            }
1384
-        }
1385
-        if ($payment_methods_of_payments) {
1386
-            $query_args = array(
1387
-                array(
1388
-                    'OR*payment_method_for_payment' => array(
1389
-                        'PMD_ID'    => array('IN', $payment_methods_of_payments),
1390
-                        'PMD_scope' => array('LIKE', '%' . EEM_Payment_Method::scope_admin . '%'),
1391
-                    ),
1392
-                ),
1393
-            );
1394
-        } else {
1395
-            $query_args = array(array('PMD_scope' => array('LIKE', '%' . EEM_Payment_Method::scope_admin . '%')));
1396
-        }
1397
-        $this->_template_args['payment_methods'] = EEM_Payment_Method::instance()->get_all($query_args);
1398
-    }
1399
-
1400
-
1401
-    /**
1402
-     * txn_attendees_meta_box
1403
-     *    generates HTML for the Attendees Transaction main meta box
1404
-     *
1405
-     * @access public
1406
-     * @param WP_Post $post
1407
-     * @param array   $metabox
1408
-     * @return void
1409
-     * @throws DomainException
1410
-     * @throws EE_Error
1411
-     * @throws InvalidArgumentException
1412
-     * @throws InvalidDataTypeException
1413
-     * @throws InvalidInterfaceException
1414
-     * @throws ReflectionException
1415
-     */
1416
-    public function txn_attendees_meta_box($post, $metabox = array('args' => array()))
1417
-    {
1418
-
1419
-        /** @noinspection NonSecureExtractUsageInspection */
1420
-        extract($metabox['args']);
1421
-        $this->_template_args['post'] = $post;
1422
-        $this->_template_args['event_attendees'] = array();
1423
-        // process items in cart
1424
-        $line_items = $this->_transaction->get_many_related(
1425
-            'Line_Item',
1426
-            array(array('LIN_type' => 'line-item'))
1427
-        );
1428
-        if (! empty($line_items)) {
1429
-            foreach ($line_items as $item) {
1430
-                if ($item instanceof EE_Line_Item) {
1431
-                    switch ($item->OBJ_type()) {
1432
-                        case 'Event':
1433
-                            break;
1434
-                        case 'Ticket':
1435
-                            $ticket = $item->ticket();
1436
-                            // right now we're only handling tickets here.
1437
-                            // Cause its expected that only tickets will have attendees right?
1438
-                            if (! $ticket instanceof EE_Ticket) {
1439
-                                break;
1440
-                            }
1441
-                            try {
1442
-                                $event_name = $ticket->get_event_name();
1443
-                            } catch (Exception $e) {
1444
-                                EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
1445
-                                $event_name = esc_html__('Unknown Event', 'event_espresso');
1446
-                            }
1447
-                            $event_name .= ' - ' . $item->name();
1448
-                            $ticket_price = EEH_Template::format_currency($item->unit_price());
1449
-                            // now get all of the registrations for this transaction that use this ticket
1450
-                            $registrations = $ticket->registrations(
1451
-                                array(array('TXN_ID' => $this->_transaction->ID()))
1452
-                            );
1453
-                            foreach ($registrations as $registration) {
1454
-                                if (! $registration instanceof EE_Registration) {
1455
-                                    break;
1456
-                                }
1457
-                                $this->_template_args['event_attendees'][ $registration->ID() ]['STS_ID']
1458
-                                    = $registration->status_ID();
1459
-                                $this->_template_args['event_attendees'][ $registration->ID() ]['att_num']
1460
-                                    = $registration->count();
1461
-                                $this->_template_args['event_attendees'][ $registration->ID() ]['event_ticket_name']
1462
-                                    = $event_name;
1463
-                                $this->_template_args['event_attendees'][ $registration->ID() ]['ticket_price']
1464
-                                    = $ticket_price;
1465
-                                // attendee info
1466
-                                $attendee = $registration->get_first_related('Attendee');
1467
-                                if ($attendee instanceof EE_Attendee) {
1468
-                                    $this->_template_args['event_attendees'][ $registration->ID() ]['att_id']
1469
-                                        = $attendee->ID();
1470
-                                    $this->_template_args['event_attendees'][ $registration->ID() ]['attendee']
1471
-                                        = $attendee->full_name();
1472
-                                    $this->_template_args['event_attendees'][ $registration->ID() ]['email']
1473
-                                        = '<a href="mailto:' . $attendee->email() . '?subject=' . $event_name
1474
-                                          . esc_html__(
1475
-                                              ' Event',
1476
-                                              'event_espresso'
1477
-                                          )
1478
-                                          . '">' . $attendee->email() . '</a>';
1479
-                                    $this->_template_args['event_attendees'][ $registration->ID() ]['address']
1480
-                                        = EEH_Address::format($attendee, 'inline', false, false);
1481
-                                } else {
1482
-                                    $this->_template_args['event_attendees'][ $registration->ID() ]['att_id'] = '';
1483
-                                    $this->_template_args['event_attendees'][ $registration->ID() ]['attendee'] = '';
1484
-                                    $this->_template_args['event_attendees'][ $registration->ID() ]['email'] = '';
1485
-                                    $this->_template_args['event_attendees'][ $registration->ID() ]['address'] = '';
1486
-                                }
1487
-                            }
1488
-                            break;
1489
-                    }
1490
-                }
1491
-            }
1492
-
1493
-            $this->_template_args['transaction_form_url'] = add_query_arg(
1494
-                array(
1495
-                    'action'  => 'edit_transaction',
1496
-                    'process' => 'attendees',
1497
-                ),
1498
-                TXN_ADMIN_URL
1499
-            );
1500
-            echo EEH_Template::display_template(
1501
-                TXN_TEMPLATE_PATH . 'txn_admin_details_main_meta_box_attendees.template.php',
1502
-                $this->_template_args,
1503
-                true
1504
-            );
1505
-        } else {
1506
-            echo sprintf(
1507
-                esc_html__(
1508
-                    '%1$sFor some reason, there are no attendees registered for this transaction. Likely the registration was abandoned in process.%2$s',
1509
-                    'event_espresso'
1510
-                ),
1511
-                '<p class="important-notice">',
1512
-                '</p>'
1513
-            );
1514
-        }
1515
-    }
1516
-
1517
-
1518
-    /**
1519
-     * txn_registrant_side_meta_box
1520
-     * generates HTML for the Edit Transaction side meta box
1521
-     *
1522
-     * @access public
1523
-     * @return void
1524
-     * @throws DomainException
1525
-     * @throws EE_Error
1526
-     * @throws InvalidArgumentException
1527
-     * @throws InvalidDataTypeException
1528
-     * @throws InvalidInterfaceException
1529
-     * @throws ReflectionException
1530
-     */
1531
-    public function txn_registrant_side_meta_box()
1532
-    {
1533
-        $primary_att = $this->_transaction->primary_registration() instanceof EE_Registration
1534
-            ? $this->_transaction->primary_registration()->get_first_related('Attendee')
1535
-            : null;
1536
-        if (! $primary_att instanceof EE_Attendee) {
1537
-            $this->_template_args['no_attendee_message'] = esc_html__(
1538
-                'There is no attached contact for this transaction.  The transaction either failed due to an error or was abandoned.',
1539
-                'event_espresso'
1540
-            );
1541
-            $primary_att = EEM_Attendee::instance()->create_default_object();
1542
-        }
1543
-        $this->_template_args['ATT_ID'] = $primary_att->ID();
1544
-        $this->_template_args['prime_reg_fname'] = $primary_att->fname();
1545
-        $this->_template_args['prime_reg_lname'] = $primary_att->lname();
1546
-        $this->_template_args['prime_reg_email'] = $primary_att->email();
1547
-        $this->_template_args['prime_reg_phone'] = $primary_att->phone();
1548
-        $this->_template_args['edit_attendee_url'] = EE_Admin_Page::add_query_args_and_nonce(
1549
-            array(
1550
-                'action' => 'edit_attendee',
1551
-                'post'   => $primary_att->ID(),
1552
-            ),
1553
-            REG_ADMIN_URL
1554
-        );
1555
-        // get formatted address for registrant
1556
-        $this->_template_args['formatted_address'] = EEH_Address::format($primary_att);
1557
-        echo EEH_Template::display_template(
1558
-            TXN_TEMPLATE_PATH . 'txn_admin_details_side_meta_box_registrant.template.php',
1559
-            $this->_template_args,
1560
-            true
1561
-        );
1562
-    }
1563
-
1564
-
1565
-    /**
1566
-     * txn_billing_info_side_meta_box
1567
-     *    generates HTML for the Edit Transaction side meta box
1568
-     *
1569
-     * @access public
1570
-     * @return void
1571
-     * @throws DomainException
1572
-     * @throws EE_Error
1573
-     */
1574
-    public function txn_billing_info_side_meta_box()
1575
-    {
1576
-
1577
-        $this->_template_args['billing_form'] = $this->_transaction->billing_info();
1578
-        $this->_template_args['billing_form_url'] = add_query_arg(
1579
-            array('action' => 'edit_transaction', 'process' => 'billing'),
1580
-            TXN_ADMIN_URL
1581
-        );
1582
-
1583
-        $template_path = TXN_TEMPLATE_PATH . 'txn_admin_details_side_meta_box_billing_info.template.php';
1584
-        echo EEH_Template::display_template($template_path, $this->_template_args, true);
1585
-    }
1586
-
1587
-
1588
-    /**
1589
-     * apply_payments_or_refunds
1590
-     *    registers a payment or refund made towards a transaction
1591
-     *
1592
-     * @access public
1593
-     * @return void
1594
-     * @throws EE_Error
1595
-     * @throws InvalidArgumentException
1596
-     * @throws ReflectionException
1597
-     * @throws RuntimeException
1598
-     * @throws InvalidDataTypeException
1599
-     * @throws InvalidInterfaceException
1600
-     */
1601
-    public function apply_payments_or_refunds()
1602
-    {
1603
-        $json_response_data = array('return_data' => false);
1604
-        $valid_data = $this->_validate_payment_request_data();
1605
-        $has_access = EE_Registry::instance()->CAP->current_user_can(
1606
-            'ee_edit_payments',
1607
-            'apply_payment_or_refund_from_registration_details'
1608
-        );
1609
-        if (! empty($valid_data) && $has_access) {
1610
-            $PAY_ID = $valid_data['PAY_ID'];
1611
-            // save  the new payment
1612
-            $payment = $this->_create_payment_from_request_data($valid_data);
1613
-            // get the TXN for this payment
1614
-            $transaction = $payment->transaction();
1615
-            // verify transaction
1616
-            if ($transaction instanceof EE_Transaction) {
1617
-                // calculate_total_payments_and_update_status
1618
-                $this->_process_transaction_payments($transaction);
1619
-                $REG_IDs = $this->_get_REG_IDs_to_apply_payment_to($payment);
1620
-                $this->_remove_existing_registration_payments($payment, $PAY_ID);
1621
-                // apply payment to registrations (if applicable)
1622
-                if (! empty($REG_IDs)) {
1623
-                    $this->_update_registration_payments($transaction, $payment, $REG_IDs);
1624
-                    $this->_maybe_send_notifications();
1625
-                    // now process status changes for the same registrations
1626
-                    $this->_process_registration_status_change($transaction, $REG_IDs);
1627
-                }
1628
-                $this->_maybe_send_notifications($payment);
1629
-                // prepare to render page
1630
-                $json_response_data['return_data'] = $this->_build_payment_json_response($payment, $REG_IDs);
1631
-                do_action(
1632
-                    'AHEE__Transactions_Admin_Page__apply_payments_or_refund__after_recording',
1633
-                    $transaction,
1634
-                    $payment
1635
-                );
1636
-            } else {
1637
-                EE_Error::add_error(
1638
-                    esc_html__(
1639
-                        'A valid Transaction for this payment could not be retrieved.',
1640
-                        'event_espresso'
1641
-                    ),
1642
-                    __FILE__,
1643
-                    __FUNCTION__,
1644
-                    __LINE__
1645
-                );
1646
-            }
1647
-        } elseif ($has_access) {
1648
-            EE_Error::add_error(
1649
-                esc_html__(
1650
-                    'The payment form data could not be processed. Please try again.',
1651
-                    'event_espresso'
1652
-                ),
1653
-                __FILE__,
1654
-                __FUNCTION__,
1655
-                __LINE__
1656
-            );
1657
-        } else {
1658
-            EE_Error::add_error(
1659
-                esc_html__(
1660
-                    'You do not have access to apply payments or refunds to a registration.',
1661
-                    'event_espresso'
1662
-                ),
1663
-                __FILE__,
1664
-                __FUNCTION__,
1665
-                __LINE__
1666
-            );
1667
-        }
1668
-        $notices = EE_Error::get_notices(
1669
-            false,
1670
-            false,
1671
-            false
1672
-        );
1673
-        $this->_template_args = array(
1674
-            'data'    => $json_response_data,
1675
-            'error'   => $notices['errors'],
1676
-            'success' => $notices['success'],
1677
-        );
1678
-        $this->_return_json();
1679
-    }
1680
-
1681
-
1682
-    /**
1683
-     * _validate_payment_request_data
1684
-     *
1685
-     * @return array
1686
-     * @throws EE_Error
1687
-     * @throws InvalidArgumentException
1688
-     * @throws InvalidDataTypeException
1689
-     * @throws InvalidInterfaceException
1690
-     */
1691
-    protected function _validate_payment_request_data()
1692
-    {
1693
-        if (! isset($this->_req_data['txn_admin_payment'])) {
1694
-            return array();
1695
-        }
1696
-        $payment_form = $this->_generate_payment_form_section();
1697
-        try {
1698
-            if ($payment_form->was_submitted()) {
1699
-                $payment_form->receive_form_submission();
1700
-                if (! $payment_form->is_valid()) {
1701
-                    $submission_error_messages = array();
1702
-                    foreach ($payment_form->get_validation_errors_accumulated() as $validation_error) {
1703
-                        if ($validation_error instanceof EE_Validation_Error) {
1704
-                            $submission_error_messages[] = sprintf(
1705
-                                _x('%s : %s', 'Form Section Name : Form Validation Error', 'event_espresso'),
1706
-                                $validation_error->get_form_section()->html_label_text(),
1707
-                                $validation_error->getMessage()
1708
-                            );
1709
-                        }
1710
-                    }
1711
-                    EE_Error::add_error(
1712
-                        implode('<br />', $submission_error_messages),
1713
-                        __FILE__,
1714
-                        __FUNCTION__,
1715
-                        __LINE__
1716
-                    );
1717
-                    return array();
1718
-                }
1719
-            }
1720
-        } catch (EE_Error $e) {
1721
-            EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
1722
-            return array();
1723
-        }
1724
-
1725
-        return $payment_form->valid_data();
1726
-    }
1727
-
1728
-
1729
-    /**
1730
-     * _generate_payment_form_section
1731
-     *
1732
-     * @return EE_Form_Section_Proper
1733
-     * @throws EE_Error
1734
-     */
1735
-    protected function _generate_payment_form_section()
1736
-    {
1737
-        return new EE_Form_Section_Proper(
1738
-            array(
1739
-                'name'        => 'txn_admin_payment',
1740
-                'subsections' => array(
1741
-                    'PAY_ID'          => new EE_Text_Input(
1742
-                        array(
1743
-                            'default'               => 0,
1744
-                            'required'              => false,
1745
-                            'html_label_text'       => esc_html__('Payment ID', 'event_espresso'),
1746
-                            'validation_strategies' => array(new EE_Int_Normalization()),
1747
-                        )
1748
-                    ),
1749
-                    'TXN_ID'          => new EE_Text_Input(
1750
-                        array(
1751
-                            'default'               => 0,
1752
-                            'required'              => true,
1753
-                            'html_label_text'       => esc_html__('Transaction ID', 'event_espresso'),
1754
-                            'validation_strategies' => array(new EE_Int_Normalization()),
1755
-                        )
1756
-                    ),
1757
-                    'type'            => new EE_Text_Input(
1758
-                        array(
1759
-                            'default'               => 1,
1760
-                            'required'              => true,
1761
-                            'html_label_text'       => esc_html__('Payment or Refund', 'event_espresso'),
1762
-                            'validation_strategies' => array(new EE_Int_Normalization()),
1763
-                        )
1764
-                    ),
1765
-                    'amount'          => new EE_Text_Input(
1766
-                        array(
1767
-                            'default'               => 0,
1768
-                            'required'              => true,
1769
-                            'html_label_text'       => esc_html__('Payment amount', 'event_espresso'),
1770
-                            'validation_strategies' => array(new EE_Float_Normalization()),
1771
-                        )
1772
-                    ),
1773
-                    'status'          => new EE_Text_Input(
1774
-                        array(
1775
-                            'default'         => EEM_Payment::status_id_approved,
1776
-                            'required'        => true,
1777
-                            'html_label_text' => esc_html__('Payment status', 'event_espresso'),
1778
-                        )
1779
-                    ),
1780
-                    'PMD_ID'          => new EE_Text_Input(
1781
-                        array(
1782
-                            'default'               => 2,
1783
-                            'required'              => true,
1784
-                            'html_label_text'       => esc_html__('Payment Method', 'event_espresso'),
1785
-                            'validation_strategies' => array(new EE_Int_Normalization()),
1786
-                        )
1787
-                    ),
1788
-                    'date'            => new EE_Text_Input(
1789
-                        array(
1790
-                            'default'         => time(),
1791
-                            'required'        => true,
1792
-                            'html_label_text' => esc_html__('Payment date', 'event_espresso'),
1793
-                        )
1794
-                    ),
1795
-                    'txn_id_chq_nmbr' => new EE_Text_Input(
1796
-                        array(
1797
-                            'default'               => '',
1798
-                            'required'              => false,
1799
-                            'html_label_text'       => esc_html__('Transaction or Cheque Number', 'event_espresso'),
1800
-                            'validation_strategies' => array(
1801
-                                new EE_Max_Length_Validation_Strategy(
1802
-                                    esc_html__('Input too long', 'event_espresso'),
1803
-                                    100
1804
-                                ),
1805
-                            ),
1806
-                        )
1807
-                    ),
1808
-                    'po_number'       => new EE_Text_Input(
1809
-                        array(
1810
-                            'default'               => '',
1811
-                            'required'              => false,
1812
-                            'html_label_text'       => esc_html__('Purchase Order Number', 'event_espresso'),
1813
-                            'validation_strategies' => array(
1814
-                                new EE_Max_Length_Validation_Strategy(
1815
-                                    esc_html__('Input too long', 'event_espresso'),
1816
-                                    100
1817
-                                ),
1818
-                            ),
1819
-                        )
1820
-                    ),
1821
-                    'accounting'      => new EE_Text_Input(
1822
-                        array(
1823
-                            'default'               => '',
1824
-                            'required'              => false,
1825
-                            'html_label_text'       => esc_html__('Extra Field for Accounting', 'event_espresso'),
1826
-                            'validation_strategies' => array(
1827
-                                new EE_Max_Length_Validation_Strategy(
1828
-                                    esc_html__('Input too long', 'event_espresso'),
1829
-                                    100
1830
-                                ),
1831
-                            ),
1832
-                        )
1833
-                    ),
1834
-                ),
1835
-            )
1836
-        );
1837
-    }
1838
-
1839
-
1840
-    /**
1841
-     * _create_payment_from_request_data
1842
-     *
1843
-     * @param array $valid_data
1844
-     * @return EE_Payment
1845
-     * @throws EE_Error
1846
-     * @throws InvalidArgumentException
1847
-     * @throws InvalidDataTypeException
1848
-     * @throws InvalidInterfaceException
1849
-     * @throws ReflectionException
1850
-     */
1851
-    protected function _create_payment_from_request_data($valid_data)
1852
-    {
1853
-        $PAY_ID = $valid_data['PAY_ID'];
1854
-        // get payment amount
1855
-        $amount = $valid_data['amount'] ? abs($valid_data['amount']) : 0;
1856
-        // payments have a type value of 1 and refunds have a type value of -1
1857
-        // so multiplying amount by type will give a positive value for payments, and negative values for refunds
1858
-        $amount = $valid_data['type'] < 0 ? $amount * -1 : $amount;
1859
-        // for some reason the date string coming in has extra spaces between the date and time.  This fixes that.
1860
-        $date = $valid_data['date']
1861
-            ? preg_replace('/\s+/', ' ', $valid_data['date'])
1862
-            : date('Y-m-d g:i a', current_time('timestamp'));
1863
-        $payment = EE_Payment::new_instance(
1864
-            array(
1865
-                'TXN_ID'              => $valid_data['TXN_ID'],
1866
-                'STS_ID'              => $valid_data['status'],
1867
-                'PAY_timestamp'       => $date,
1868
-                'PAY_source'          => EEM_Payment_Method::scope_admin,
1869
-                'PMD_ID'              => $valid_data['PMD_ID'],
1870
-                'PAY_amount'          => $amount,
1871
-                'PAY_txn_id_chq_nmbr' => $valid_data['txn_id_chq_nmbr'],
1872
-                'PAY_po_number'       => $valid_data['po_number'],
1873
-                'PAY_extra_accntng'   => $valid_data['accounting'],
1874
-                'PAY_details'         => $valid_data,
1875
-                'PAY_ID'              => $PAY_ID,
1876
-            ),
1877
-            '',
1878
-            array('Y-m-d', 'g:i a')
1879
-        );
1880
-
1881
-        if (! $payment->save()) {
1882
-            EE_Error::add_error(
1883
-                sprintf(
1884
-                    esc_html__('Payment %1$d has not been successfully saved to the database.', 'event_espresso'),
1885
-                    $payment->ID()
1886
-                ),
1887
-                __FILE__,
1888
-                __FUNCTION__,
1889
-                __LINE__
1890
-            );
1891
-        }
1892
-
1893
-        return $payment;
1894
-    }
1895
-
1896
-
1897
-    /**
1898
-     * _process_transaction_payments
1899
-     *
1900
-     * @param \EE_Transaction $transaction
1901
-     * @return void
1902
-     * @throws EE_Error
1903
-     * @throws InvalidArgumentException
1904
-     * @throws ReflectionException
1905
-     * @throws InvalidDataTypeException
1906
-     * @throws InvalidInterfaceException
1907
-     */
1908
-    protected function _process_transaction_payments(EE_Transaction $transaction)
1909
-    {
1910
-        /** @type EE_Transaction_Payments $transaction_payments */
1911
-        $transaction_payments = EE_Registry::instance()->load_class('Transaction_Payments');
1912
-        // update the transaction with this payment
1913
-        if ($transaction_payments->calculate_total_payments_and_update_status($transaction)) {
1914
-            EE_Error::add_success(
1915
-                esc_html__(
1916
-                    'The payment has been processed successfully.',
1917
-                    'event_espresso'
1918
-                ),
1919
-                __FILE__,
1920
-                __FUNCTION__,
1921
-                __LINE__
1922
-            );
1923
-        } else {
1924
-            EE_Error::add_error(
1925
-                esc_html__(
1926
-                    'The payment was processed successfully but the amount paid for the transaction was not updated.',
1927
-                    'event_espresso'
1928
-                ),
1929
-                __FILE__,
1930
-                __FUNCTION__,
1931
-                __LINE__
1932
-            );
1933
-        }
1934
-    }
1935
-
1936
-
1937
-    /**
1938
-     * _get_REG_IDs_to_apply_payment_to
1939
-     * returns a list of registration IDs that the payment will apply to
1940
-     *
1941
-     * @param \EE_Payment $payment
1942
-     * @return array
1943
-     * @throws EE_Error
1944
-     * @throws InvalidArgumentException
1945
-     * @throws InvalidDataTypeException
1946
-     * @throws InvalidInterfaceException
1947
-     * @throws ReflectionException
1948
-     */
1949
-    protected function _get_REG_IDs_to_apply_payment_to(EE_Payment $payment)
1950
-    {
1951
-        $REG_IDs = array();
1952
-        // grab array of IDs for specific registrations to apply changes to
1953
-        if (isset($this->_req_data['txn_admin_payment']['registrations'])) {
1954
-            $REG_IDs = (array) $this->_req_data['txn_admin_payment']['registrations'];
1955
-        }
1956
-        // nothing specified ? then get all reg IDs
1957
-        if (empty($REG_IDs)) {
1958
-            $registrations = $payment->transaction()->registrations();
1959
-            $REG_IDs = ! empty($registrations)
1960
-                ? array_keys($registrations)
1961
-                : $this->_get_existing_reg_payment_REG_IDs($payment);
1962
-        }
1963
-
1964
-        // ensure that REG_IDs are integers and NOT strings
1965
-        return array_map('intval', $REG_IDs);
1966
-    }
1967
-
1968
-
1969
-    /**
1970
-     * @return array
1971
-     */
1972
-    public function existing_reg_payment_REG_IDs()
1973
-    {
1974
-        return $this->_existing_reg_payment_REG_IDs;
1975
-    }
1976
-
1977
-
1978
-    /**
1979
-     * @param array $existing_reg_payment_REG_IDs
1980
-     */
1981
-    public function set_existing_reg_payment_REG_IDs($existing_reg_payment_REG_IDs = null)
1982
-    {
1983
-        $this->_existing_reg_payment_REG_IDs = $existing_reg_payment_REG_IDs;
1984
-    }
1985
-
1986
-
1987
-    /**
1988
-     * _get_existing_reg_payment_REG_IDs
1989
-     * returns a list of registration IDs that the payment is currently related to
1990
-     * as recorded in the database
1991
-     *
1992
-     * @param \EE_Payment $payment
1993
-     * @return array
1994
-     * @throws EE_Error
1995
-     * @throws InvalidArgumentException
1996
-     * @throws InvalidDataTypeException
1997
-     * @throws InvalidInterfaceException
1998
-     * @throws ReflectionException
1999
-     */
2000
-    protected function _get_existing_reg_payment_REG_IDs(EE_Payment $payment)
2001
-    {
2002
-        if ($this->existing_reg_payment_REG_IDs() === null) {
2003
-            // let's get any existing reg payment records for this payment
2004
-            $existing_reg_payment_REG_IDs = $payment->get_many_related('Registration');
2005
-            // but we only want the REG IDs, so grab the array keys
2006
-            $existing_reg_payment_REG_IDs = ! empty($existing_reg_payment_REG_IDs)
2007
-                ? array_keys($existing_reg_payment_REG_IDs)
2008
-                : array();
2009
-            $this->set_existing_reg_payment_REG_IDs($existing_reg_payment_REG_IDs);
2010
-        }
2011
-
2012
-        return $this->existing_reg_payment_REG_IDs();
2013
-    }
2014
-
2015
-
2016
-    /**
2017
-     * _remove_existing_registration_payments
2018
-     * this calculates the difference between existing relations
2019
-     * to the supplied payment and the new list registration IDs,
2020
-     * removes any related registrations that no longer apply,
2021
-     * and then updates the registration paid fields
2022
-     *
2023
-     * @param \EE_Payment $payment
2024
-     * @param int         $PAY_ID
2025
-     * @return bool;
2026
-     * @throws EE_Error
2027
-     * @throws InvalidArgumentException
2028
-     * @throws ReflectionException
2029
-     * @throws InvalidDataTypeException
2030
-     * @throws InvalidInterfaceException
2031
-     */
2032
-    protected function _remove_existing_registration_payments(EE_Payment $payment, $PAY_ID = 0)
2033
-    {
2034
-        // newly created payments will have nothing recorded for $PAY_ID
2035
-        if (absint($PAY_ID) === 0) {
2036
-            return false;
2037
-        }
2038
-        $existing_reg_payment_REG_IDs = $this->_get_existing_reg_payment_REG_IDs($payment);
2039
-        if (empty($existing_reg_payment_REG_IDs)) {
2040
-            return false;
2041
-        }
2042
-        /** @type EE_Transaction_Payments $transaction_payments */
2043
-        $transaction_payments = EE_Registry::instance()->load_class('Transaction_Payments');
2044
-
2045
-        return $transaction_payments->delete_registration_payments_and_update_registrations(
2046
-            $payment,
2047
-            array(
2048
-                array(
2049
-                    'PAY_ID' => $payment->ID(),
2050
-                    'REG_ID' => array('IN', $existing_reg_payment_REG_IDs),
2051
-                ),
2052
-            )
2053
-        );
2054
-    }
2055
-
2056
-
2057
-    /**
2058
-     * _update_registration_payments
2059
-     * this applies the payments to the selected registrations
2060
-     * but only if they have not already been paid for
2061
-     *
2062
-     * @param  EE_Transaction $transaction
2063
-     * @param \EE_Payment     $payment
2064
-     * @param array           $REG_IDs
2065
-     * @return void
2066
-     * @throws EE_Error
2067
-     * @throws InvalidArgumentException
2068
-     * @throws ReflectionException
2069
-     * @throws RuntimeException
2070
-     * @throws InvalidDataTypeException
2071
-     * @throws InvalidInterfaceException
2072
-     */
2073
-    protected function _update_registration_payments(
2074
-        EE_Transaction $transaction,
2075
-        EE_Payment $payment,
2076
-        $REG_IDs = array()
2077
-    ) {
2078
-        // we can pass our own custom set of registrations to EE_Payment_Processor::process_registration_payments()
2079
-        // so let's do that using our set of REG_IDs from the form
2080
-        $registration_query_where_params = array(
2081
-            'REG_ID' => array('IN', $REG_IDs),
2082
-        );
2083
-        // but add in some conditions regarding payment,
2084
-        // so that we don't apply payments to registrations that are free or have already been paid for
2085
-        // but ONLY if the payment is NOT a refund ( ie: the payment amount is not negative )
2086
-        if (! $payment->is_a_refund()) {
2087
-            $registration_query_where_params['REG_final_price'] = array('!=', 0);
2088
-            $registration_query_where_params['REG_final_price*'] = array('!=', 'REG_paid', true);
2089
-        }
2090
-        $registrations = $transaction->registrations(array($registration_query_where_params));
2091
-        if (! empty($registrations)) {
2092
-            /** @type EE_Payment_Processor $payment_processor */
2093
-            $payment_processor = EE_Registry::instance()->load_core('Payment_Processor');
2094
-            $payment_processor->process_registration_payments($transaction, $payment, $registrations);
2095
-        }
2096
-    }
2097
-
2098
-
2099
-    /**
2100
-     * _process_registration_status_change
2101
-     * This processes requested registration status changes for all the registrations
2102
-     * on a given transaction and (optionally) sends out notifications for the changes.
2103
-     *
2104
-     * @param  EE_Transaction $transaction
2105
-     * @param array           $REG_IDs
2106
-     * @return bool
2107
-     * @throws EE_Error
2108
-     * @throws InvalidArgumentException
2109
-     * @throws ReflectionException
2110
-     * @throws InvalidDataTypeException
2111
-     * @throws InvalidInterfaceException
2112
-     */
2113
-    protected function _process_registration_status_change(EE_Transaction $transaction, $REG_IDs = array())
2114
-    {
2115
-        // first if there is no change in status then we get out.
2116
-        if (! isset($this->_req_data['txn_reg_status_change']['reg_status'])
2117
-            || $this->_req_data['txn_reg_status_change']['reg_status'] === 'NAN'
2118
-        ) {
2119
-            // no error message, no change requested, just nothing to do man.
2120
-            return false;
2121
-        }
2122
-        /** @type EE_Transaction_Processor $transaction_processor */
2123
-        $transaction_processor = EE_Registry::instance()->load_class('Transaction_Processor');
2124
-
2125
-        // made it here dude?  Oh WOW.  K, let's take care of changing the statuses
2126
-        return $transaction_processor->manually_update_registration_statuses(
2127
-            $transaction,
2128
-            sanitize_text_field($this->_req_data['txn_reg_status_change']['reg_status']),
2129
-            array(array('REG_ID' => array('IN', $REG_IDs)))
2130
-        );
2131
-    }
2132
-
2133
-
2134
-    /**
2135
-     * _build_payment_json_response
2136
-     *
2137
-     * @access public
2138
-     * @param \EE_Payment $payment
2139
-     * @param array       $REG_IDs
2140
-     * @param bool | null $delete_txn_reg_status_change
2141
-     * @return array
2142
-     * @throws EE_Error
2143
-     * @throws InvalidArgumentException
2144
-     * @throws InvalidDataTypeException
2145
-     * @throws InvalidInterfaceException
2146
-     * @throws ReflectionException
2147
-     */
2148
-    protected function _build_payment_json_response(
2149
-        EE_Payment $payment,
2150
-        $REG_IDs = array(),
2151
-        $delete_txn_reg_status_change = null
2152
-    ) {
2153
-        // was the payment deleted ?
2154
-        if (is_bool($delete_txn_reg_status_change)) {
2155
-            return array(
2156
-                'PAY_ID'                       => $payment->ID(),
2157
-                'amount'                       => $payment->amount(),
2158
-                'total_paid'                   => $payment->transaction()->paid(),
2159
-                'txn_status'                   => $payment->transaction()->status_ID(),
2160
-                'pay_status'                   => $payment->STS_ID(),
2161
-                'registrations'                => $this->_registration_payment_data_array($REG_IDs),
2162
-                'delete_txn_reg_status_change' => $delete_txn_reg_status_change,
2163
-            );
2164
-        } else {
2165
-            $this->_get_payment_status_array();
2166
-
2167
-            return array(
2168
-                'amount'           => $payment->amount(),
2169
-                'total_paid'       => $payment->transaction()->paid(),
2170
-                'txn_status'       => $payment->transaction()->status_ID(),
2171
-                'pay_status'       => $payment->STS_ID(),
2172
-                'PAY_ID'           => $payment->ID(),
2173
-                'STS_ID'           => $payment->STS_ID(),
2174
-                'status'           => self::$_pay_status[ $payment->STS_ID() ],
2175
-                'date'             => $payment->timestamp('Y-m-d', 'h:i a'),
2176
-                'method'           => strtoupper($payment->source()),
2177
-                'PM_ID'            => $payment->payment_method() ? $payment->payment_method()->ID() : 1,
2178
-                'gateway'          => $payment->payment_method()
2179
-                    ? $payment->payment_method()->admin_name()
2180
-                    : esc_html__('Unknown', 'event_espresso'),
2181
-                'gateway_response' => $payment->gateway_response(),
2182
-                'txn_id_chq_nmbr'  => $payment->txn_id_chq_nmbr(),
2183
-                'po_number'        => $payment->po_number(),
2184
-                'extra_accntng'    => $payment->extra_accntng(),
2185
-                'registrations'    => $this->_registration_payment_data_array($REG_IDs),
2186
-            );
2187
-        }
2188
-    }
2189
-
2190
-
2191
-    /**
2192
-     * delete_payment
2193
-     *    delete a payment or refund made towards a transaction
2194
-     *
2195
-     * @access public
2196
-     * @return void
2197
-     * @throws EE_Error
2198
-     * @throws InvalidArgumentException
2199
-     * @throws ReflectionException
2200
-     * @throws InvalidDataTypeException
2201
-     * @throws InvalidInterfaceException
2202
-     */
2203
-    public function delete_payment()
2204
-    {
2205
-        $json_response_data = array('return_data' => false);
2206
-        $PAY_ID = isset($this->_req_data['delete_txn_admin_payment']['PAY_ID'])
2207
-            ? absint($this->_req_data['delete_txn_admin_payment']['PAY_ID'])
2208
-            : 0;
2209
-        $can_delete = EE_Registry::instance()->CAP->current_user_can(
2210
-            'ee_delete_payments',
2211
-            'delete_payment_from_registration_details'
2212
-        );
2213
-        if ($PAY_ID && $can_delete) {
2214
-            $delete_txn_reg_status_change = isset($this->_req_data['delete_txn_reg_status_change'])
2215
-                ? $this->_req_data['delete_txn_reg_status_change']
2216
-                : false;
2217
-            $payment = EEM_Payment::instance()->get_one_by_ID($PAY_ID);
2218
-            if ($payment instanceof EE_Payment) {
2219
-                $REG_IDs = $this->_get_existing_reg_payment_REG_IDs($payment);
2220
-                /** @type EE_Transaction_Payments $transaction_payments */
2221
-                $transaction_payments = EE_Registry::instance()->load_class('Transaction_Payments');
2222
-                if ($transaction_payments->delete_payment_and_update_transaction($payment)) {
2223
-                    $json_response_data['return_data'] = $this->_build_payment_json_response(
2224
-                        $payment,
2225
-                        $REG_IDs,
2226
-                        $delete_txn_reg_status_change
2227
-                    );
2228
-                    if ($delete_txn_reg_status_change) {
2229
-                        $this->_req_data['txn_reg_status_change'] = $delete_txn_reg_status_change;
2230
-                        // MAKE sure we also add the delete_txn_req_status_change to the
2231
-                        // $_REQUEST global because that's how messages will be looking for it.
2232
-                        $_REQUEST['txn_reg_status_change'] = $delete_txn_reg_status_change;
2233
-                        $this->_maybe_send_notifications();
2234
-                        $this->_process_registration_status_change($payment->transaction(), $REG_IDs);
2235
-                    }
2236
-                }
2237
-            } else {
2238
-                EE_Error::add_error(
2239
-                    esc_html__('Valid Payment data could not be retrieved from the database.', 'event_espresso'),
2240
-                    __FILE__,
2241
-                    __FUNCTION__,
2242
-                    __LINE__
2243
-                );
2244
-            }
2245
-        } elseif ($can_delete) {
2246
-            EE_Error::add_error(
2247
-                esc_html__(
2248
-                    'A valid Payment ID was not received, therefore payment form data could not be loaded.',
2249
-                    'event_espresso'
2250
-                ),
2251
-                __FILE__,
2252
-                __FUNCTION__,
2253
-                __LINE__
2254
-            );
2255
-        } else {
2256
-            EE_Error::add_error(
2257
-                esc_html__(
2258
-                    'You do not have access to delete a payment.',
2259
-                    'event_espresso'
2260
-                ),
2261
-                __FILE__,
2262
-                __FUNCTION__,
2263
-                __LINE__
2264
-            );
2265
-        }
2266
-        $notices = EE_Error::get_notices(false, false, false);
2267
-        $this->_template_args = array(
2268
-            'data'      => $json_response_data,
2269
-            'success'   => $notices['success'],
2270
-            'error'     => $notices['errors'],
2271
-            'attention' => $notices['attention'],
2272
-        );
2273
-        $this->_return_json();
2274
-    }
2275
-
2276
-
2277
-    /**
2278
-     * _registration_payment_data_array
2279
-     * adds info for 'owing' and 'paid' for each registration to the json response
2280
-     *
2281
-     * @access protected
2282
-     * @param array $REG_IDs
2283
-     * @return array
2284
-     * @throws EE_Error
2285
-     * @throws InvalidArgumentException
2286
-     * @throws InvalidDataTypeException
2287
-     * @throws InvalidInterfaceException
2288
-     * @throws ReflectionException
2289
-     */
2290
-    protected function _registration_payment_data_array($REG_IDs)
2291
-    {
2292
-        $registration_payment_data = array();
2293
-        // if non empty reg_ids lets get an array of registrations and update the values for the apply_payment/refund rows.
2294
-        if (! empty($REG_IDs)) {
2295
-            $registrations = EEM_Registration::instance()->get_all(array(array('REG_ID' => array('IN', $REG_IDs))));
2296
-            foreach ($registrations as $registration) {
2297
-                if ($registration instanceof EE_Registration) {
2298
-                    $registration_payment_data[ $registration->ID() ] = array(
2299
-                        'paid'  => $registration->pretty_paid(),
2300
-                        'owing' => EEH_Template::format_currency($registration->final_price() - $registration->paid()),
2301
-                    );
2302
-                }
2303
-            }
2304
-        }
2305
-
2306
-        return $registration_payment_data;
2307
-    }
2308
-
2309
-
2310
-    /**
2311
-     * _maybe_send_notifications
2312
-     * determines whether or not the admin has indicated that notifications should be sent.
2313
-     * If so, will toggle a filter switch for delivering registration notices.
2314
-     * If passed an EE_Payment object, then it will trigger payment notifications instead.
2315
-     *
2316
-     * @access protected
2317
-     * @param \EE_Payment | null $payment
2318
-     */
2319
-    protected function _maybe_send_notifications($payment = null)
2320
-    {
2321
-        switch ($payment instanceof EE_Payment) {
2322
-            // payment notifications
2323
-            case true:
2324
-                if (isset($this->_req_data['txn_payments']['send_notifications'])
2325
-                    && filter_var(
2326
-                        $this->_req_data['txn_payments']['send_notifications'],
2327
-                        FILTER_VALIDATE_BOOLEAN
2328
-                    )
2329
-                ) {
2330
-                    $this->_process_payment_notification($payment);
2331
-                }
2332
-                break;
2333
-            // registration notifications
2334
-            case false:
2335
-                if (isset($this->_req_data['txn_reg_status_change']['send_notifications'])
2336
-                    && filter_var(
2337
-                        $this->_req_data['txn_reg_status_change']['send_notifications'],
2338
-                        FILTER_VALIDATE_BOOLEAN
2339
-                    )
2340
-                ) {
2341
-                    add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true');
2342
-                }
2343
-                break;
2344
-        }
2345
-    }
2346
-
2347
-
2348
-    /**
2349
-     * _send_payment_reminder
2350
-     *    generates HTML for the View Transaction Details Admin page
2351
-     *
2352
-     * @access protected
2353
-     * @return void
2354
-     * @throws EE_Error
2355
-     * @throws InvalidArgumentException
2356
-     * @throws InvalidDataTypeException
2357
-     * @throws InvalidInterfaceException
2358
-     */
2359
-    protected function _send_payment_reminder()
2360
-    {
2361
-        $TXN_ID = ! empty($this->_req_data['TXN_ID']) ? absint($this->_req_data['TXN_ID']) : false;
2362
-        $transaction = EEM_Transaction::instance()->get_one_by_ID($TXN_ID);
2363
-        $query_args = isset($this->_req_data['redirect_to']) ? array(
2364
-            'action' => $this->_req_data['redirect_to'],
2365
-            'TXN_ID' => $this->_req_data['TXN_ID'],
2366
-        ) : array();
2367
-        do_action(
2368
-            'AHEE__Transactions_Admin_Page___send_payment_reminder__process_admin_payment_reminder',
2369
-            $transaction
2370
-        );
2371
-        $this->_redirect_after_action(
2372
-            false,
2373
-            esc_html__('payment reminder', 'event_espresso'),
2374
-            esc_html__('sent', 'event_espresso'),
2375
-            $query_args,
2376
-            true
2377
-        );
2378
-    }
2379
-
2380
-
2381
-    /**
2382
-     *  get_transactions
2383
-     *    get transactions for given parameters (used by list table)
2384
-     *
2385
-     * @param  int     $perpage how many transactions displayed per page
2386
-     * @param  boolean $count   return the count or objects
2387
-     * @param string   $view
2388
-     * @return mixed int = count || array of transaction objects
2389
-     * @throws EE_Error
2390
-     * @throws InvalidArgumentException
2391
-     * @throws InvalidDataTypeException
2392
-     * @throws InvalidInterfaceException
2393
-     */
2394
-    public function get_transactions($perpage, $count = false, $view = '')
2395
-    {
2396
-
2397
-        $TXN = EEM_Transaction::instance();
2398
-
2399
-        $start_date = isset($this->_req_data['txn-filter-start-date'])
2400
-            ? wp_strip_all_tags($this->_req_data['txn-filter-start-date'])
2401
-            : date(
2402
-                'm/d/Y',
2403
-                strtotime('-10 year')
2404
-            );
2405
-        $end_date = isset($this->_req_data['txn-filter-end-date'])
2406
-            ? wp_strip_all_tags($this->_req_data['txn-filter-end-date'])
2407
-            : date('m/d/Y');
2408
-
2409
-        // make sure our timestamps start and end right at the boundaries for each day
2410
-        $start_date = date('Y-m-d', strtotime($start_date)) . ' 00:00:00';
2411
-        $end_date = date('Y-m-d', strtotime($end_date)) . ' 23:59:59';
2412
-
2413
-
2414
-        // convert to timestamps
2415
-        $start_date = strtotime($start_date);
2416
-        $end_date = strtotime($end_date);
2417
-
2418
-        // makes sure start date is the lowest value and vice versa
2419
-        $start_date = min($start_date, $end_date);
2420
-        $end_date = max($start_date, $end_date);
2421
-
2422
-        // convert to correct format for query
2423
-        $start_date = EEM_Transaction::instance()->convert_datetime_for_query(
2424
-            'TXN_timestamp',
2425
-            date('Y-m-d H:i:s', $start_date),
2426
-            'Y-m-d H:i:s'
2427
-        );
2428
-        $end_date = EEM_Transaction::instance()->convert_datetime_for_query(
2429
-            'TXN_timestamp',
2430
-            date('Y-m-d H:i:s', $end_date),
2431
-            'Y-m-d H:i:s'
2432
-        );
2433
-
2434
-
2435
-        // set orderby
2436
-        $this->_req_data['orderby'] = ! empty($this->_req_data['orderby']) ? $this->_req_data['orderby'] : '';
2437
-
2438
-        switch ($this->_req_data['orderby']) {
2439
-            case 'TXN_ID':
2440
-                $orderby = 'TXN_ID';
2441
-                break;
2442
-            case 'ATT_fname':
2443
-                $orderby = 'Registration.Attendee.ATT_fname';
2444
-                break;
2445
-            case 'event_name':
2446
-                $orderby = 'Registration.Event.EVT_name';
2447
-                break;
2448
-            default: // 'TXN_timestamp'
2449
-                $orderby = 'TXN_timestamp';
2450
-        }
2451
-
2452
-        $sort = ! empty($this->_req_data['order']) ? $this->_req_data['order'] : 'DESC';
2453
-        $current_page = ! empty($this->_req_data['paged']) ? $this->_req_data['paged'] : 1;
2454
-        $per_page = ! empty($perpage) ? $perpage : 10;
2455
-        $per_page = ! empty($this->_req_data['perpage']) ? $this->_req_data['perpage'] : $per_page;
2456
-
2457
-        $offset = ($current_page - 1) * $per_page;
2458
-        $limit = array($offset, $per_page);
2459
-
2460
-        $_where = array(
2461
-            'TXN_timestamp'          => array('BETWEEN', array($start_date, $end_date)),
2462
-            'Registration.REG_count' => 1,
2463
-        );
2464
-
2465
-        if (isset($this->_req_data['EVT_ID'])) {
2466
-            $_where['Registration.EVT_ID'] = $this->_req_data['EVT_ID'];
2467
-        }
2468
-
2469
-        if (isset($this->_req_data['s'])) {
2470
-            $search_string = '%' . $this->_req_data['s'] . '%';
2471
-            $_where['OR'] = array(
2472
-                'Registration.Event.EVT_name'         => array('LIKE', $search_string),
2473
-                'Registration.Event.EVT_desc'         => array('LIKE', $search_string),
2474
-                'Registration.Event.EVT_short_desc'   => array('LIKE', $search_string),
2475
-                'Registration.Attendee.ATT_full_name' => array('LIKE', $search_string),
2476
-                'Registration.Attendee.ATT_fname'     => array('LIKE', $search_string),
2477
-                'Registration.Attendee.ATT_lname'     => array('LIKE', $search_string),
2478
-                'Registration.Attendee.ATT_short_bio' => array('LIKE', $search_string),
2479
-                'Registration.Attendee.ATT_email'     => array('LIKE', $search_string),
2480
-                'Registration.Attendee.ATT_address'   => array('LIKE', $search_string),
2481
-                'Registration.Attendee.ATT_address2'  => array('LIKE', $search_string),
2482
-                'Registration.Attendee.ATT_city'      => array('LIKE', $search_string),
2483
-                'Registration.REG_final_price'        => array('LIKE', $search_string),
2484
-                'Registration.REG_code'               => array('LIKE', $search_string),
2485
-                'Registration.REG_count'              => array('LIKE', $search_string),
2486
-                'Registration.REG_group_size'         => array('LIKE', $search_string),
2487
-                'Registration.Ticket.TKT_name'        => array('LIKE', $search_string),
2488
-                'Registration.Ticket.TKT_description' => array('LIKE', $search_string),
2489
-                'Payment.PAY_source'                  => array('LIKE', $search_string),
2490
-                'Payment.Payment_Method.PMD_name'     => array('LIKE', $search_string),
2491
-                'TXN_session_data'                    => array('LIKE', $search_string),
2492
-                'Payment.PAY_txn_id_chq_nmbr'         => array('LIKE', $search_string),
2493
-            );
2494
-        }
2495
-
2496
-        // failed transactions
2497
-        $failed = (! empty($this->_req_data['status']) && $this->_req_data['status'] === 'failed' && ! $count)
2498
-                  || ($count && $view === 'failed');
2499
-        $abandoned = (! empty($this->_req_data['status']) && $this->_req_data['status'] === 'abandoned' && ! $count)
2500
-                     || ($count && $view === 'abandoned');
2501
-        $incomplete = (! empty($this->_req_data['status']) && $this->_req_data['status'] === 'incomplete' && ! $count)
2502
-                      || ($count && $view === 'incomplete');
2503
-
2504
-        if ($failed) {
2505
-            $_where['STS_ID'] = EEM_Transaction::failed_status_code;
2506
-        } elseif ($abandoned) {
2507
-            $_where['STS_ID'] = EEM_Transaction::abandoned_status_code;
2508
-        } elseif ($incomplete) {
2509
-            $_where['STS_ID'] = EEM_Transaction::incomplete_status_code;
2510
-        } else {
2511
-            $_where['STS_ID'] = array('!=', EEM_Transaction::failed_status_code);
2512
-            $_where['STS_ID*'] = array('!=', EEM_Transaction::abandoned_status_code);
2513
-        }
2514
-
2515
-        $query_params = apply_filters(
2516
-            'FHEE__Transactions_Admin_Page___get_transactions_query_params',
2517
-            array(
2518
-                $_where,
2519
-                'order_by'                 => array($orderby => $sort),
2520
-                'limit'                    => $limit,
2521
-                'default_where_conditions' => EEM_Base::default_where_conditions_this_only,
2522
-            ),
2523
-            $this->_req_data,
2524
-            $view,
2525
-            $count
2526
-        );
2527
-
2528
-        $transactions = $count
2529
-            ? $TXN->count(array($query_params[0]), 'TXN_ID', true)
2530
-            : $TXN->get_all($query_params);
2531
-
2532
-        return $transactions;
2533
-    }
2534
-
2535
-
2536
-    /**
2537
-     * @since 4.9.79.p
2538
-     * @throws EE_Error
2539
-     * @throws InvalidArgumentException
2540
-     * @throws InvalidDataTypeException
2541
-     * @throws InvalidInterfaceException
2542
-     * @throws ReflectionException
2543
-     * @throws RuntimeException
2544
-     */
2545
-    public function recalculateLineItems()
2546
-    {
2547
-        $TXN_ID = ! empty($this->_req_data['TXN_ID']) ? absint($this->_req_data['TXN_ID']) : false;
2548
-        /** @var EE_Transaction $transaction */
2549
-        $transaction = EEM_Transaction::instance()->get_one_by_ID($TXN_ID);
2550
-        $total_line_item = $transaction->total_line_item(false);
2551
-        $success = $transaction->recalculateLineItems();
2552
-        $this->_redirect_after_action(
2553
-            (bool) $success,
2554
-            esc_html__('Transaction taxes and totals', 'event_espresso'),
2555
-            esc_html__('recalculated', 'event_espresso'),
2556
-            isset($this->_req_data['redirect_to'])
2557
-                ? array(
2558
-                'action' => $this->_req_data['redirect_to'],
2559
-                'TXN_ID' => $this->_req_data['TXN_ID'],
2560
-            )
2561
-                : array(),
2562
-            true
2563
-        );
2564
-    }
16
+	/**
17
+	 * @var EE_Transaction
18
+	 */
19
+	private $_transaction;
20
+
21
+	/**
22
+	 * @var EE_Session
23
+	 */
24
+	private $_session;
25
+
26
+	/**
27
+	 * @var array $_txn_status
28
+	 */
29
+	private static $_txn_status;
30
+
31
+	/**
32
+	 * @var array $_pay_status
33
+	 */
34
+	private static $_pay_status;
35
+
36
+	/**
37
+	 * @var array $_existing_reg_payment_REG_IDs
38
+	 */
39
+	protected $_existing_reg_payment_REG_IDs;
40
+
41
+
42
+	/**
43
+	 *    _init_page_props
44
+	 *
45
+	 * @return void
46
+	 */
47
+	protected function _init_page_props()
48
+	{
49
+		$this->page_slug = TXN_PG_SLUG;
50
+		$this->page_label = esc_html__('Transactions', 'event_espresso');
51
+		$this->_admin_base_url = TXN_ADMIN_URL;
52
+		$this->_admin_base_path = TXN_ADMIN;
53
+	}
54
+
55
+
56
+	/**
57
+	 *    _ajax_hooks
58
+	 *
59
+	 * @return void
60
+	 */
61
+	protected function _ajax_hooks()
62
+	{
63
+		add_action('wp_ajax_espresso_apply_payment', array($this, 'apply_payments_or_refunds'));
64
+		add_action('wp_ajax_espresso_apply_refund', array($this, 'apply_payments_or_refunds'));
65
+		add_action('wp_ajax_espresso_delete_payment', array($this, 'delete_payment'));
66
+	}
67
+
68
+
69
+	/**
70
+	 *    _define_page_props
71
+	 *
72
+	 * @return void
73
+	 */
74
+	protected function _define_page_props()
75
+	{
76
+		$this->_admin_page_title = $this->page_label;
77
+		$this->_labels = array(
78
+			'buttons' => array(
79
+				'add'    => esc_html__('Add New Transaction', 'event_espresso'),
80
+				'edit'   => esc_html__('Edit Transaction', 'event_espresso'),
81
+				'delete' => esc_html__('Delete Transaction', 'event_espresso'),
82
+			),
83
+		);
84
+	}
85
+
86
+
87
+	/**
88
+	 *        grab url requests and route them
89
+	 *
90
+	 * @access private
91
+	 * @return void
92
+	 * @throws EE_Error
93
+	 * @throws InvalidArgumentException
94
+	 * @throws InvalidDataTypeException
95
+	 * @throws InvalidInterfaceException
96
+	 */
97
+	public function _set_page_routes()
98
+	{
99
+
100
+		$this->_set_transaction_status_array();
101
+
102
+		$txn_id = ! empty($this->_req_data['TXN_ID'])
103
+				  && ! is_array($this->_req_data['TXN_ID'])
104
+			? $this->_req_data['TXN_ID']
105
+			: 0;
106
+
107
+		$this->_page_routes = array(
108
+
109
+			'default' => array(
110
+				'func'       => '_transactions_overview_list_table',
111
+				'capability' => 'ee_read_transactions',
112
+			),
113
+
114
+			'view_transaction' => array(
115
+				'func'       => '_transaction_details',
116
+				'capability' => 'ee_read_transaction',
117
+				'obj_id'     => $txn_id,
118
+			),
119
+
120
+			'send_payment_reminder' => array(
121
+				'func'       => '_send_payment_reminder',
122
+				'noheader'   => true,
123
+				'capability' => 'ee_send_message',
124
+			),
125
+
126
+			'espresso_apply_payment' => array(
127
+				'func'       => 'apply_payments_or_refunds',
128
+				'noheader'   => true,
129
+				'capability' => 'ee_edit_payments',
130
+			),
131
+
132
+			'espresso_apply_refund' => array(
133
+				'func'       => 'apply_payments_or_refunds',
134
+				'noheader'   => true,
135
+				'capability' => 'ee_edit_payments',
136
+			),
137
+
138
+			'espresso_delete_payment' => array(
139
+				'func'       => 'delete_payment',
140
+				'noheader'   => true,
141
+				'capability' => 'ee_delete_payments',
142
+			),
143
+
144
+			'espresso_recalculate_line_items' => array(
145
+				'func'       => 'recalculateLineItems',
146
+				'noheader'   => true,
147
+				'capability' => 'ee_edit_payments',
148
+			),
149
+
150
+		);
151
+	}
152
+
153
+
154
+	protected function _set_page_config()
155
+	{
156
+		$this->_page_config = array(
157
+			'default'          => array(
158
+				'nav'           => array(
159
+					'label' => esc_html__('Overview', 'event_espresso'),
160
+					'order' => 10,
161
+				),
162
+				'list_table'    => 'EE_Admin_Transactions_List_Table',
163
+				'help_tabs'     => array(
164
+					'transactions_overview_help_tab'                       => array(
165
+						'title'    => esc_html__('Transactions Overview', 'event_espresso'),
166
+						'filename' => 'transactions_overview',
167
+					),
168
+					'transactions_overview_table_column_headings_help_tab' => array(
169
+						'title'    => esc_html__('Transactions Table Column Headings', 'event_espresso'),
170
+						'filename' => 'transactions_overview_table_column_headings',
171
+					),
172
+					'transactions_overview_views_filters_help_tab'         => array(
173
+						'title'    => esc_html__('Transaction Views & Filters & Search', 'event_espresso'),
174
+						'filename' => 'transactions_overview_views_filters_search',
175
+					),
176
+				),
177
+				'help_tour'     => array('Transactions_Overview_Help_Tour'),
178
+				/**
179
+				 * commented out because currently we are not displaying tips for transaction list table status but this
180
+				 * may change in a later iteration so want to keep the code for then.
181
+				 */
182
+				// 'qtips' => array( 'Transactions_List_Table_Tips' ),
183
+				'require_nonce' => false,
184
+			),
185
+			'view_transaction' => array(
186
+				'nav'       => array(
187
+					'label'      => esc_html__('View Transaction', 'event_espresso'),
188
+					'order'      => 5,
189
+					'url'        => isset($this->_req_data['TXN_ID'])
190
+						? add_query_arg(array('TXN_ID' => $this->_req_data['TXN_ID']), $this->_current_page_view_url)
191
+						: $this->_admin_base_url,
192
+					'persistent' => false,
193
+				),
194
+				'help_tabs' => array(
195
+					'transactions_view_transaction_help_tab'                                              => array(
196
+						'title'    => esc_html__('View Transaction', 'event_espresso'),
197
+						'filename' => 'transactions_view_transaction',
198
+					),
199
+					'transactions_view_transaction_transaction_details_table_help_tab'                    => array(
200
+						'title'    => esc_html__('Transaction Details Table', 'event_espresso'),
201
+						'filename' => 'transactions_view_transaction_transaction_details_table',
202
+					),
203
+					'transactions_view_transaction_attendees_registered_help_tab'                         => array(
204
+						'title'    => esc_html__('Attendees Registered', 'event_espresso'),
205
+						'filename' => 'transactions_view_transaction_attendees_registered',
206
+					),
207
+					'transactions_view_transaction_views_primary_registrant_billing_information_help_tab' => array(
208
+						'title'    => esc_html__('Primary Registrant & Billing Information', 'event_espresso'),
209
+						'filename' => 'transactions_view_transaction_primary_registrant_billing_information',
210
+					),
211
+				),
212
+				'qtips'     => array('Transaction_Details_Tips'),
213
+				'help_tour' => array('Transaction_Details_Help_Tour'),
214
+				'metaboxes' => array('_transaction_details_metaboxes'),
215
+
216
+				'require_nonce' => false,
217
+			),
218
+		);
219
+	}
220
+
221
+
222
+	/**
223
+	 * The below methods aren't used by this class currently
224
+	 */
225
+	protected function _add_screen_options()
226
+	{
227
+		// noop
228
+	}
229
+
230
+
231
+	protected function _add_feature_pointers()
232
+	{
233
+		// noop
234
+	}
235
+
236
+
237
+	public function admin_init()
238
+	{
239
+		// IF a registration was JUST added via the admin...
240
+		if (isset(
241
+			$this->_req_data['redirect_from'],
242
+			$this->_req_data['EVT_ID'],
243
+			$this->_req_data['event_name']
244
+		)) {
245
+			// then set a cookie so that we can block any attempts to use
246
+			// the back button as a way to enter another registration.
247
+			setcookie(
248
+				'ee_registration_added',
249
+				$this->_req_data['EVT_ID'],
250
+				time() + WEEK_IN_SECONDS,
251
+				'/'
252
+			);
253
+			// and update the global
254
+			$_COOKIE['ee_registration_added'] = $this->_req_data['EVT_ID'];
255
+		}
256
+		EE_Registry::$i18n_js_strings['invalid_server_response'] = esc_html__(
257
+			'An error occurred! Your request may have been processed, but a valid response from the server was not received. Please refresh the page and try again.',
258
+			'event_espresso'
259
+		);
260
+		EE_Registry::$i18n_js_strings['error_occurred'] = esc_html__(
261
+			'An error occurred! Please refresh the page and try again.',
262
+			'event_espresso'
263
+		);
264
+		EE_Registry::$i18n_js_strings['txn_status_array'] = self::$_txn_status;
265
+		EE_Registry::$i18n_js_strings['pay_status_array'] = self::$_pay_status;
266
+		EE_Registry::$i18n_js_strings['payments_total'] = esc_html__('Payments Total', 'event_espresso');
267
+		EE_Registry::$i18n_js_strings['transaction_overpaid'] = esc_html__(
268
+			'This transaction has been overpaid ! Payments Total',
269
+			'event_espresso'
270
+		);
271
+	}
272
+
273
+
274
+	public function admin_notices()
275
+	{
276
+		// noop
277
+	}
278
+
279
+
280
+	public function admin_footer_scripts()
281
+	{
282
+		// noop
283
+	}
284
+
285
+
286
+	/**
287
+	 * _set_transaction_status_array
288
+	 * sets list of transaction statuses
289
+	 *
290
+	 * @access private
291
+	 * @return void
292
+	 * @throws EE_Error
293
+	 * @throws InvalidArgumentException
294
+	 * @throws InvalidDataTypeException
295
+	 * @throws InvalidInterfaceException
296
+	 */
297
+	private function _set_transaction_status_array()
298
+	{
299
+		self::$_txn_status = EEM_Transaction::instance()->status_array(true);
300
+	}
301
+
302
+
303
+	/**
304
+	 * get_transaction_status_array
305
+	 * return the transaction status array for wp_list_table
306
+	 *
307
+	 * @access public
308
+	 * @return array
309
+	 */
310
+	public function get_transaction_status_array()
311
+	{
312
+		return self::$_txn_status;
313
+	}
314
+
315
+
316
+	/**
317
+	 *    get list of payment statuses
318
+	 *
319
+	 * @access private
320
+	 * @return void
321
+	 * @throws EE_Error
322
+	 * @throws InvalidArgumentException
323
+	 * @throws InvalidDataTypeException
324
+	 * @throws InvalidInterfaceException
325
+	 */
326
+	private function _get_payment_status_array()
327
+	{
328
+		self::$_pay_status = EEM_Payment::instance()->status_array(true);
329
+		$this->_template_args['payment_status'] = self::$_pay_status;
330
+	}
331
+
332
+
333
+	/**
334
+	 *    _add_screen_options_default
335
+	 *
336
+	 * @access protected
337
+	 * @return void
338
+	 * @throws InvalidArgumentException
339
+	 * @throws InvalidDataTypeException
340
+	 * @throws InvalidInterfaceException
341
+	 */
342
+	protected function _add_screen_options_default()
343
+	{
344
+		$this->_per_page_screen_option();
345
+	}
346
+
347
+
348
+	/**
349
+	 * load_scripts_styles
350
+	 *
351
+	 * @access public
352
+	 * @return void
353
+	 */
354
+	public function load_scripts_styles()
355
+	{
356
+		// enqueue style
357
+		wp_register_style(
358
+			'espresso_txn',
359
+			TXN_ASSETS_URL . 'espresso_transactions_admin.css',
360
+			array(),
361
+			EVENT_ESPRESSO_VERSION
362
+		);
363
+		wp_enqueue_style('espresso_txn');
364
+		// scripts
365
+		wp_register_script(
366
+			'espresso_txn',
367
+			TXN_ASSETS_URL . 'espresso_transactions_admin.js',
368
+			array(
369
+				'ee_admin_js',
370
+				'ee-datepicker',
371
+				'jquery-ui-datepicker',
372
+				'jquery-ui-draggable',
373
+				'ee-dialog',
374
+				'ee-accounting',
375
+				'ee-serialize-full-array',
376
+			),
377
+			EVENT_ESPRESSO_VERSION,
378
+			true
379
+		);
380
+		wp_enqueue_script('espresso_txn');
381
+	}
382
+
383
+
384
+	/**
385
+	 *    load_scripts_styles_view_transaction
386
+	 *
387
+	 * @access public
388
+	 * @return void
389
+	 */
390
+	public function load_scripts_styles_view_transaction()
391
+	{
392
+		// styles
393
+		wp_enqueue_style('espresso-ui-theme');
394
+	}
395
+
396
+
397
+	/**
398
+	 *    load_scripts_styles_default
399
+	 *
400
+	 * @access public
401
+	 * @return void
402
+	 */
403
+	public function load_scripts_styles_default()
404
+	{
405
+		// styles
406
+		wp_enqueue_style('espresso-ui-theme');
407
+	}
408
+
409
+
410
+	/**
411
+	 *    _set_list_table_views_default
412
+	 *
413
+	 * @access protected
414
+	 * @return void
415
+	 */
416
+	protected function _set_list_table_views_default()
417
+	{
418
+		$this->_views = array(
419
+			'all'        => array(
420
+				'slug'  => 'all',
421
+				'label' => esc_html__('View All Transactions', 'event_espresso'),
422
+				'count' => 0,
423
+			),
424
+			'abandoned'  => array(
425
+				'slug'  => 'abandoned',
426
+				'label' => esc_html__('Abandoned Transactions', 'event_espresso'),
427
+				'count' => 0,
428
+			),
429
+			'incomplete' => array(
430
+				'slug'  => 'incomplete',
431
+				'label' => esc_html__('Incomplete Transactions', 'event_espresso'),
432
+				'count' => 0,
433
+			),
434
+		);
435
+		if (/**
436
+		 * Filters whether a link to the "Failed Transactions" list table
437
+		 * appears on the Transactions Admin Page list table.
438
+		 * List display can be turned back on via the following:
439
+		 * add_filter(
440
+		 *     'FHEE__Transactions_Admin_Page___set_list_table_views_default__display_failed_txns_list',
441
+		 *     '__return_true'
442
+		 * );
443
+		 *
444
+		 * @since 4.9.70.p
445
+		 * @param boolean                 $display_failed_txns_list
446
+		 * @param Transactions_Admin_Page $this
447
+		 */
448
+		apply_filters(
449
+			'FHEE__Transactions_Admin_Page___set_list_table_views_default__display_failed_txns_list',
450
+			false,
451
+			$this
452
+		)
453
+		) {
454
+			$this->_views['failed'] = array(
455
+				'slug'  => 'failed',
456
+				'label' => esc_html__('Failed Transactions', 'event_espresso'),
457
+				'count' => 0,
458
+			);
459
+		}
460
+	}
461
+
462
+
463
+	/**
464
+	 * _set_transaction_object
465
+	 * This sets the _transaction property for the transaction details screen
466
+	 *
467
+	 * @access private
468
+	 * @return void
469
+	 * @throws EE_Error
470
+	 * @throws InvalidArgumentException
471
+	 * @throws RuntimeException
472
+	 * @throws InvalidDataTypeException
473
+	 * @throws InvalidInterfaceException
474
+	 * @throws ReflectionException
475
+	 */
476
+	private function _set_transaction_object()
477
+	{
478
+		if ($this->_transaction instanceof EE_Transaction) {
479
+			return;
480
+		} //get out we've already set the object
481
+
482
+		$TXN_ID = ! empty($this->_req_data['TXN_ID'])
483
+			? absint($this->_req_data['TXN_ID'])
484
+			: false;
485
+
486
+		// get transaction object
487
+		$this->_transaction = EEM_Transaction::instance()->get_one_by_ID($TXN_ID);
488
+		$this->_session = $this->_transaction instanceof EE_Transaction
489
+			? $this->_transaction->session_data()
490
+			: null;
491
+		if ($this->_transaction instanceof EE_Transaction) {
492
+			$this->_transaction->verify_abandoned_transaction_status();
493
+		}
494
+
495
+		if (! $this->_transaction instanceof EE_Transaction) {
496
+			$error_msg = sprintf(
497
+				esc_html__(
498
+					'An error occurred and the details for the transaction with the ID # %d could not be retrieved.',
499
+					'event_espresso'
500
+				),
501
+				$TXN_ID
502
+			);
503
+			EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__);
504
+		}
505
+	}
506
+
507
+
508
+	/**
509
+	 *    _transaction_legend_items
510
+	 *
511
+	 * @access protected
512
+	 * @return array
513
+	 * @throws EE_Error
514
+	 * @throws InvalidArgumentException
515
+	 * @throws ReflectionException
516
+	 * @throws InvalidDataTypeException
517
+	 * @throws InvalidInterfaceException
518
+	 */
519
+	protected function _transaction_legend_items()
520
+	{
521
+		EE_Registry::instance()->load_helper('MSG_Template');
522
+		$items = array();
523
+
524
+		if (EE_Registry::instance()->CAP->current_user_can(
525
+			'ee_read_global_messages',
526
+			'view_filtered_messages'
527
+		)) {
528
+			$related_for_icon = EEH_MSG_Template::get_message_action_icon('see_notifications_for');
529
+			if (is_array($related_for_icon)
530
+				&& isset($related_for_icon['css_class'], $related_for_icon['label'])
531
+			) {
532
+				$items['view_related_messages'] = array(
533
+					'class' => $related_for_icon['css_class'],
534
+					'desc'  => $related_for_icon['label'],
535
+				);
536
+			}
537
+		}
538
+
539
+		$items = apply_filters(
540
+			'FHEE__Transactions_Admin_Page___transaction_legend_items__items',
541
+			array_merge(
542
+				$items,
543
+				array(
544
+					'view_details'          => array(
545
+						'class' => 'dashicons dashicons-cart',
546
+						'desc'  => esc_html__('View Transaction Details', 'event_espresso'),
547
+					),
548
+					'view_invoice'          => array(
549
+						'class' => 'dashicons dashicons-media-spreadsheet',
550
+						'desc'  => esc_html__('View Transaction Invoice', 'event_espresso'),
551
+					),
552
+					'view_receipt'          => array(
553
+						'class' => 'dashicons dashicons-media-default',
554
+						'desc'  => esc_html__('View Transaction Receipt', 'event_espresso'),
555
+					),
556
+					'view_registration'     => array(
557
+						'class' => 'dashicons dashicons-clipboard',
558
+						'desc'  => esc_html__('View Registration Details', 'event_espresso'),
559
+					),
560
+					'payment_overview_link' => array(
561
+						'class' => 'dashicons dashicons-money',
562
+						'desc'  => esc_html__('Make Payment on Frontend', 'event_espresso'),
563
+					),
564
+				)
565
+			)
566
+		);
567
+
568
+		if (EEH_MSG_Template::is_mt_active('payment_reminder')
569
+			&& EE_Registry::instance()->CAP->current_user_can(
570
+				'ee_send_message',
571
+				'espresso_transactions_send_payment_reminder'
572
+			)
573
+		) {
574
+			$items['send_payment_reminder'] = array(
575
+				'class' => 'dashicons dashicons-email-alt',
576
+				'desc'  => esc_html__('Send Payment Reminder', 'event_espresso'),
577
+			);
578
+		}
579
+		$more_items = apply_filters(
580
+			'FHEE__Transactions_Admin_Page___transaction_legend_items__more_items',
581
+			array(
582
+				'overpaid'   => array(
583
+					'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::overpaid_status_code,
584
+					'desc'  => EEH_Template::pretty_status(
585
+						EEM_Transaction::overpaid_status_code,
586
+						false,
587
+						'sentence'
588
+					),
589
+				),
590
+				'complete'   => array(
591
+					'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::complete_status_code,
592
+					'desc'  => EEH_Template::pretty_status(
593
+						EEM_Transaction::complete_status_code,
594
+						false,
595
+						'sentence'
596
+					),
597
+				),
598
+				'incomplete' => array(
599
+					'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::incomplete_status_code,
600
+					'desc'  => EEH_Template::pretty_status(
601
+						EEM_Transaction::incomplete_status_code,
602
+						false,
603
+						'sentence'
604
+					),
605
+				),
606
+				'abandoned'  => array(
607
+					'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::abandoned_status_code,
608
+					'desc'  => EEH_Template::pretty_status(
609
+						EEM_Transaction::abandoned_status_code,
610
+						false,
611
+						'sentence'
612
+					),
613
+				),
614
+				'failed'     => array(
615
+					'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::failed_status_code,
616
+					'desc'  => EEH_Template::pretty_status(
617
+						EEM_Transaction::failed_status_code,
618
+						false,
619
+						'sentence'
620
+					),
621
+				),
622
+			)
623
+		);
624
+
625
+		return array_merge($items, $more_items);
626
+	}
627
+
628
+
629
+	/**
630
+	 *    _transactions_overview_list_table
631
+	 *
632
+	 * @access protected
633
+	 * @return void
634
+	 * @throws DomainException
635
+	 * @throws EE_Error
636
+	 * @throws InvalidArgumentException
637
+	 * @throws InvalidDataTypeException
638
+	 * @throws InvalidInterfaceException
639
+	 * @throws ReflectionException
640
+	 */
641
+	protected function _transactions_overview_list_table()
642
+	{
643
+		$this->_admin_page_title = esc_html__('Transactions', 'event_espresso');
644
+		$event = isset($this->_req_data['EVT_ID'])
645
+			? EEM_Event::instance()->get_one_by_ID($this->_req_data['EVT_ID'])
646
+			: null;
647
+		$this->_template_args['admin_page_header'] = $event instanceof EE_Event
648
+			? sprintf(
649
+				esc_html__(
650
+					'%sViewing Transactions for the Event: %s%s',
651
+					'event_espresso'
652
+				),
653
+				'<h3>',
654
+				'<a href="'
655
+				. EE_Admin_Page::add_query_args_and_nonce(
656
+					array('action' => 'edit', 'post' => $event->ID()),
657
+					EVENTS_ADMIN_URL
658
+				)
659
+				. '" title="'
660
+				. esc_attr__(
661
+					'Click to Edit event',
662
+					'event_espresso'
663
+				)
664
+				. '">' . $event->name() . '</a>',
665
+				'</h3>'
666
+			)
667
+			: '';
668
+		$this->_template_args['after_list_table'] = $this->_display_legend($this->_transaction_legend_items());
669
+		$this->display_admin_list_table_page_with_no_sidebar();
670
+	}
671
+
672
+
673
+	/**
674
+	 *    _transaction_details
675
+	 * generates HTML for the View Transaction Details Admin page
676
+	 *
677
+	 * @access protected
678
+	 * @return void
679
+	 * @throws DomainException
680
+	 * @throws EE_Error
681
+	 * @throws InvalidArgumentException
682
+	 * @throws InvalidDataTypeException
683
+	 * @throws InvalidInterfaceException
684
+	 * @throws RuntimeException
685
+	 * @throws ReflectionException
686
+	 */
687
+	protected function _transaction_details()
688
+	{
689
+		do_action('AHEE__Transactions_Admin_Page__transaction_details__start', $this->_transaction);
690
+
691
+		$this->_set_transaction_status_array();
692
+
693
+		$this->_template_args = array();
694
+		$this->_template_args['transactions_page'] = $this->_wp_page_slug;
695
+
696
+		$this->_set_transaction_object();
697
+
698
+		if (! $this->_transaction instanceof EE_Transaction) {
699
+			return;
700
+		}
701
+		$primary_registration = $this->_transaction->primary_registration();
702
+		$attendee = $primary_registration instanceof EE_Registration
703
+			? $primary_registration->attendee()
704
+			: null;
705
+
706
+		$this->_template_args['txn_nmbr']['value'] = $this->_transaction->ID();
707
+		$this->_template_args['txn_nmbr']['label'] = esc_html__('Transaction Number', 'event_espresso');
708
+
709
+		$this->_template_args['txn_datetime']['value'] = $this->_transaction->get_i18n_datetime('TXN_timestamp');
710
+		$this->_template_args['txn_datetime']['label'] = esc_html__('Date', 'event_espresso');
711
+
712
+		$this->_template_args['txn_status']['value'] = self::$_txn_status[ $this->_transaction->status_ID() ];
713
+		$this->_template_args['txn_status']['label'] = esc_html__('Transaction Status', 'event_espresso');
714
+		$this->_template_args['txn_status']['class'] = 'status-' . $this->_transaction->status_ID();
715
+
716
+		$this->_template_args['grand_total'] = $this->_transaction->total();
717
+		$this->_template_args['total_paid'] = $this->_transaction->paid();
718
+
719
+		$amount_due = $this->_transaction->total() - $this->_transaction->paid();
720
+		$this->_template_args['amount_due'] = EEH_Template::format_currency(
721
+			$amount_due,
722
+			true
723
+		);
724
+		if (EE_Registry::instance()->CFG->currency->sign_b4) {
725
+			$this->_template_args['amount_due'] = EE_Registry::instance()->CFG->currency->sign
726
+												  . $this->_template_args['amount_due'];
727
+		} else {
728
+			$this->_template_args['amount_due'] .= EE_Registry::instance()->CFG->currency->sign;
729
+		}
730
+		$this->_template_args['amount_due_class'] = '';
731
+
732
+		if ($this->_transaction->paid() === $this->_transaction->total()) {
733
+			// paid in full
734
+			$this->_template_args['amount_due'] = false;
735
+		} elseif ($this->_transaction->paid() > $this->_transaction->total()) {
736
+			// overpaid
737
+			$this->_template_args['amount_due_class'] = 'txn-overview-no-payment-spn';
738
+		} elseif ($this->_transaction->total() > (float) 0) {
739
+			if ($this->_transaction->paid() > (float) 0) {
740
+				// monies owing
741
+				$this->_template_args['amount_due_class'] = 'txn-overview-part-payment-spn';
742
+			} elseif ($this->_transaction->paid() === (float) 0) {
743
+				// no payments made yet
744
+				$this->_template_args['amount_due_class'] = 'txn-overview-no-payment-spn';
745
+			}
746
+		} elseif ($this->_transaction->total() === (float) 0) {
747
+			// free event
748
+			$this->_template_args['amount_due'] = false;
749
+		}
750
+
751
+		$payment_method = $this->_transaction->payment_method();
752
+
753
+		$this->_template_args['method_of_payment_name'] = $payment_method instanceof EE_Payment_Method
754
+			? $payment_method->admin_name()
755
+			: esc_html__('Unknown', 'event_espresso');
756
+
757
+		$this->_template_args['currency_sign'] = EE_Registry::instance()->CFG->currency->sign;
758
+		// link back to overview
759
+		$this->_template_args['txn_overview_url'] = ! empty($_SERVER['HTTP_REFERER'])
760
+			? $_SERVER['HTTP_REFERER']
761
+			: TXN_ADMIN_URL;
762
+
763
+
764
+		// next link
765
+		$next_txn = $this->_transaction->next(
766
+			null,
767
+			array(array('STS_ID' => array('!=', EEM_Transaction::failed_status_code))),
768
+			'TXN_ID'
769
+		);
770
+		$this->_template_args['next_transaction'] = $next_txn
771
+			? $this->_next_link(
772
+				EE_Admin_Page::add_query_args_and_nonce(
773
+					array('action' => 'view_transaction', 'TXN_ID' => $next_txn['TXN_ID']),
774
+					TXN_ADMIN_URL
775
+				),
776
+				'dashicons dashicons-arrow-right ee-icon-size-22'
777
+			)
778
+			: '';
779
+		// previous link
780
+		$previous_txn = $this->_transaction->previous(
781
+			null,
782
+			array(array('STS_ID' => array('!=', EEM_Transaction::failed_status_code))),
783
+			'TXN_ID'
784
+		);
785
+		$this->_template_args['previous_transaction'] = $previous_txn
786
+			? $this->_previous_link(
787
+				EE_Admin_Page::add_query_args_and_nonce(
788
+					array('action' => 'view_transaction', 'TXN_ID' => $previous_txn['TXN_ID']),
789
+					TXN_ADMIN_URL
790
+				),
791
+				'dashicons dashicons-arrow-left ee-icon-size-22'
792
+			)
793
+			: '';
794
+
795
+		// were we just redirected here after adding a new registration ???
796
+		if (isset(
797
+			$this->_req_data['redirect_from'],
798
+			$this->_req_data['EVT_ID'],
799
+			$this->_req_data['event_name']
800
+		)) {
801
+			if (EE_Registry::instance()->CAP->current_user_can(
802
+				'ee_edit_registrations',
803
+				'espresso_registrations_new_registration',
804
+				$this->_req_data['EVT_ID']
805
+			)) {
806
+				$this->_admin_page_title .= '<a id="add-new-registration" class="add-new-h2 button-primary" href="';
807
+				$this->_admin_page_title .= EE_Admin_Page::add_query_args_and_nonce(
808
+					array(
809
+						'page'     => 'espresso_registrations',
810
+						'action'   => 'new_registration',
811
+						'return'   => 'default',
812
+						'TXN_ID'   => $this->_transaction->ID(),
813
+						'event_id' => $this->_req_data['EVT_ID'],
814
+					),
815
+					REG_ADMIN_URL
816
+				);
817
+				$this->_admin_page_title .= '">';
818
+
819
+				$this->_admin_page_title .= sprintf(
820
+					esc_html__('Add Another New Registration to Event: "%1$s" ?', 'event_espresso'),
821
+					htmlentities(urldecode($this->_req_data['event_name']), ENT_QUOTES, 'UTF-8')
822
+				);
823
+				$this->_admin_page_title .= '</a>';
824
+			}
825
+			EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
826
+		}
827
+		// grab messages at the last second
828
+		$this->_template_args['notices'] = EE_Error::get_notices();
829
+		// path to template
830
+		$template_path = TXN_TEMPLATE_PATH . 'txn_admin_details_header.template.php';
831
+		$this->_template_args['admin_page_header'] = EEH_Template::display_template(
832
+			$template_path,
833
+			$this->_template_args,
834
+			true
835
+		);
836
+
837
+		// the details template wrapper
838
+		$this->display_admin_page_with_sidebar();
839
+	}
840
+
841
+
842
+	/**
843
+	 *        _transaction_details_metaboxes
844
+	 *
845
+	 * @access protected
846
+	 * @return void
847
+	 * @throws EE_Error
848
+	 * @throws InvalidArgumentException
849
+	 * @throws InvalidDataTypeException
850
+	 * @throws InvalidInterfaceException
851
+	 * @throws RuntimeException
852
+	 * @throws ReflectionException
853
+	 */
854
+	protected function _transaction_details_metaboxes()
855
+	{
856
+
857
+		$this->_set_transaction_object();
858
+
859
+		if (! $this->_transaction instanceof EE_Transaction) {
860
+			return;
861
+		}
862
+		add_meta_box(
863
+			'edit-txn-details-mbox',
864
+			esc_html__('Transaction Details', 'event_espresso'),
865
+			array($this, 'txn_details_meta_box'),
866
+			$this->_wp_page_slug,
867
+			'normal',
868
+			'high'
869
+		);
870
+		add_meta_box(
871
+			'edit-txn-attendees-mbox',
872
+			esc_html__('Attendees Registered in this Transaction', 'event_espresso'),
873
+			array($this, 'txn_attendees_meta_box'),
874
+			$this->_wp_page_slug,
875
+			'normal',
876
+			'high',
877
+			array('TXN_ID' => $this->_transaction->ID())
878
+		);
879
+		add_meta_box(
880
+			'edit-txn-registrant-mbox',
881
+			esc_html__('Primary Contact', 'event_espresso'),
882
+			array($this, 'txn_registrant_side_meta_box'),
883
+			$this->_wp_page_slug,
884
+			'side',
885
+			'high'
886
+		);
887
+		add_meta_box(
888
+			'edit-txn-billing-info-mbox',
889
+			esc_html__('Billing Information', 'event_espresso'),
890
+			array($this, 'txn_billing_info_side_meta_box'),
891
+			$this->_wp_page_slug,
892
+			'side',
893
+			'high'
894
+		);
895
+	}
896
+
897
+
898
+	/**
899
+	 * Callback for transaction actions metabox.
900
+	 *
901
+	 * @param EE_Transaction|null $transaction
902
+	 * @return string
903
+	 * @throws DomainException
904
+	 * @throws EE_Error
905
+	 * @throws InvalidArgumentException
906
+	 * @throws InvalidDataTypeException
907
+	 * @throws InvalidInterfaceException
908
+	 * @throws ReflectionException
909
+	 * @throws RuntimeException
910
+	 */
911
+	public function getActionButtons(EE_Transaction $transaction = null)
912
+	{
913
+		$content = '';
914
+		$actions = array();
915
+		if (! $transaction instanceof EE_Transaction) {
916
+			return $content;
917
+		}
918
+		/** @var EE_Registration $primary_registration */
919
+		$primary_registration = $transaction->primary_registration();
920
+		$attendee = $primary_registration instanceof EE_Registration
921
+			? $primary_registration->attendee()
922
+			: null;
923
+
924
+		if ($attendee instanceof EE_Attendee
925
+			&& EE_Registry::instance()->CAP->current_user_can(
926
+				'ee_send_message',
927
+				'espresso_transactions_send_payment_reminder'
928
+			)
929
+		) {
930
+			$actions['payment_reminder'] =
931
+				EEH_MSG_Template::is_mt_active('payment_reminder')
932
+				&& $this->_transaction->status_ID() !== EEM_Transaction::complete_status_code
933
+				&& $this->_transaction->status_ID() !== EEM_Transaction::overpaid_status_code
934
+					? EEH_Template::get_button_or_link(
935
+						EE_Admin_Page::add_query_args_and_nonce(
936
+							array(
937
+								'action'      => 'send_payment_reminder',
938
+								'TXN_ID'      => $this->_transaction->ID(),
939
+								'redirect_to' => 'view_transaction',
940
+							),
941
+							TXN_ADMIN_URL
942
+						),
943
+						esc_html__(' Send Payment Reminder', 'event_espresso'),
944
+						'button secondary-button',
945
+						'dashicons dashicons-email-alt'
946
+					)
947
+					: '';
948
+		}
949
+
950
+		if (EE_Registry::instance()->CAP->current_user_can(
951
+			'ee_edit_payments',
952
+			'espresso_transactions_recalculate_line_items'
953
+		)
954
+		) {
955
+			$actions['recalculate_line_items'] = EEH_Template::get_button_or_link(
956
+				EE_Admin_Page::add_query_args_and_nonce(
957
+					array(
958
+						'action'      => 'espresso_recalculate_line_items',
959
+						'TXN_ID'      => $this->_transaction->ID(),
960
+						'redirect_to' => 'view_transaction',
961
+					),
962
+					TXN_ADMIN_URL
963
+				),
964
+				esc_html__(' Recalculate Taxes and Total', 'event_espresso'),
965
+				'button secondary-button',
966
+				'dashicons dashicons-update'
967
+			);
968
+		}
969
+
970
+		if ($primary_registration instanceof EE_Registration
971
+			&& EEH_MSG_Template::is_mt_active('receipt')
972
+		) {
973
+			$actions['receipt'] = EEH_Template::get_button_or_link(
974
+				$primary_registration->receipt_url(),
975
+				esc_html__('View Receipt', 'event_espresso'),
976
+				'button secondary-button',
977
+				'dashicons dashicons-media-default'
978
+			);
979
+		}
980
+
981
+		if ($primary_registration instanceof EE_Registration
982
+			&& EEH_MSG_Template::is_mt_active('invoice')
983
+		) {
984
+			$actions['invoice'] = EEH_Template::get_button_or_link(
985
+				$primary_registration->invoice_url(),
986
+				esc_html__('View Invoice', 'event_espresso'),
987
+				'button secondary-button',
988
+				'dashicons dashicons-media-spreadsheet'
989
+			);
990
+		}
991
+		$actions = array_filter(
992
+			apply_filters('FHEE__Transactions_Admin_Page__getActionButtons__actions', $actions, $transaction)
993
+		);
994
+		if ($actions) {
995
+			$content = '<ul>';
996
+			$content .= '<li>' . implode('</li><li>', $actions) . '</li>';
997
+			$content .= '</uL>';
998
+		}
999
+		return $content;
1000
+	}
1001
+
1002
+
1003
+	/**
1004
+	 * txn_details_meta_box
1005
+	 * generates HTML for the Transaction main meta box
1006
+	 *
1007
+	 * @return void
1008
+	 * @throws DomainException
1009
+	 * @throws EE_Error
1010
+	 * @throws InvalidArgumentException
1011
+	 * @throws InvalidDataTypeException
1012
+	 * @throws InvalidInterfaceException
1013
+	 * @throws RuntimeException
1014
+	 * @throws ReflectionException
1015
+	 */
1016
+	public function txn_details_meta_box()
1017
+	{
1018
+		$this->_set_transaction_object();
1019
+		$this->_template_args['TXN_ID'] = $this->_transaction->ID();
1020
+		$this->_template_args['attendee'] = $this->_transaction->primary_registration() instanceof EE_Registration
1021
+			? $this->_transaction->primary_registration()->attendee()
1022
+			: null;
1023
+		$this->_template_args['can_edit_payments'] = EE_Registry::instance()->CAP->current_user_can(
1024
+			'ee_edit_payments',
1025
+			'apply_payment_or_refund_from_registration_details'
1026
+		);
1027
+		$this->_template_args['can_delete_payments'] = EE_Registry::instance()->CAP->current_user_can(
1028
+			'ee_delete_payments',
1029
+			'delete_payment_from_registration_details'
1030
+		);
1031
+
1032
+		// get line table
1033
+		EEH_Autoloader::register_line_item_display_autoloaders();
1034
+		$Line_Item_Display = new EE_Line_Item_Display(
1035
+			'admin_table',
1036
+			'EE_Admin_Table_Line_Item_Display_Strategy'
1037
+		);
1038
+		$this->_template_args['line_item_table'] = $Line_Item_Display->display_line_item(
1039
+			$this->_transaction->total_line_item()
1040
+		);
1041
+		$this->_template_args['REG_code'] = $this->_transaction->primary_registration()->reg_code();
1042
+
1043
+		// process taxes
1044
+		$taxes = $this->_transaction->line_items(array(array('LIN_type' => EEM_Line_Item::type_tax)));
1045
+		$this->_template_args['taxes'] = ! empty($taxes) ? $taxes : false;
1046
+
1047
+		$this->_template_args['grand_total'] = EEH_Template::format_currency(
1048
+			$this->_transaction->total(),
1049
+			false,
1050
+			false
1051
+		);
1052
+		$this->_template_args['grand_raw_total'] = $this->_transaction->total();
1053
+		$this->_template_args['TXN_status'] = $this->_transaction->status_ID();
1054
+
1055
+		// process payment details
1056
+		$payments = $this->_transaction->payments();
1057
+		if (! empty($payments)) {
1058
+			$this->_template_args['payments'] = $payments;
1059
+			$this->_template_args['existing_reg_payments'] = $this->_get_registration_payment_IDs($payments);
1060
+		} else {
1061
+			$this->_template_args['payments'] = false;
1062
+			$this->_template_args['existing_reg_payments'] = array();
1063
+		}
1064
+
1065
+		$this->_template_args['edit_payment_url'] = add_query_arg(array('action' => 'edit_payment'), TXN_ADMIN_URL);
1066
+		$this->_template_args['delete_payment_url'] = add_query_arg(
1067
+			array('action' => 'espresso_delete_payment'),
1068
+			TXN_ADMIN_URL
1069
+		);
1070
+
1071
+		if (isset($txn_details['invoice_number'])) {
1072
+			$this->_template_args['txn_details']['invoice_number']['value'] = $this->_template_args['REG_code'];
1073
+			$this->_template_args['txn_details']['invoice_number']['label'] = esc_html__(
1074
+				'Invoice Number',
1075
+				'event_espresso'
1076
+			);
1077
+		}
1078
+
1079
+		$this->_template_args['txn_details']['registration_session']['value'] = $this->_transaction
1080
+			->primary_registration()
1081
+			->session_ID();
1082
+		$this->_template_args['txn_details']['registration_session']['label'] = esc_html__(
1083
+			'Registration Session',
1084
+			'event_espresso'
1085
+		);
1086
+
1087
+		$this->_template_args['txn_details']['ip_address']['value'] = isset($this->_session['ip_address'])
1088
+			? $this->_session['ip_address']
1089
+			: '';
1090
+		$this->_template_args['txn_details']['ip_address']['label'] = esc_html__(
1091
+			'Transaction placed from IP',
1092
+			'event_espresso'
1093
+		);
1094
+
1095
+		$this->_template_args['txn_details']['user_agent']['value'] = isset($this->_session['user_agent'])
1096
+			? $this->_session['user_agent']
1097
+			: '';
1098
+		$this->_template_args['txn_details']['user_agent']['label'] = esc_html__(
1099
+			'Registrant User Agent',
1100
+			'event_espresso'
1101
+		);
1102
+
1103
+		$reg_steps = '<ul>';
1104
+		foreach ($this->_transaction->reg_steps() as $reg_step => $reg_step_status) {
1105
+			if ($reg_step_status === true) {
1106
+				$reg_steps .= '<li style="color:#70cc50">'
1107
+							  . sprintf(
1108
+								  esc_html__('%1$s : Completed', 'event_espresso'),
1109
+								  ucwords(str_replace('_', ' ', $reg_step))
1110
+							  )
1111
+							  . '</li>';
1112
+			} elseif (is_numeric($reg_step_status) && $reg_step_status !== false) {
1113
+				$reg_steps .= '<li style="color:#2EA2CC">'
1114
+							  . sprintf(
1115
+								  esc_html__('%1$s : Initiated %2$s', 'event_espresso'),
1116
+								  ucwords(str_replace('_', ' ', $reg_step)),
1117
+								  date(
1118
+									  get_option('date_format') . ' ' . get_option('time_format'),
1119
+									  $reg_step_status + (get_option('gmt_offset') * HOUR_IN_SECONDS)
1120
+								  )
1121
+							  )
1122
+							  . '</li>';
1123
+			} else {
1124
+				$reg_steps .= '<li style="color:#E76700">'
1125
+							  . sprintf(
1126
+								  esc_html__('%1$s : Never Initiated', 'event_espresso'),
1127
+								  ucwords(str_replace('_', ' ', $reg_step))
1128
+							  )
1129
+							  . '</li>';
1130
+			}
1131
+		}
1132
+		$reg_steps .= '</ul>';
1133
+		$this->_template_args['txn_details']['reg_steps']['value'] = $reg_steps;
1134
+		$this->_template_args['txn_details']['reg_steps']['label'] = esc_html__(
1135
+			'Registration Step Progress',
1136
+			'event_espresso'
1137
+		);
1138
+
1139
+
1140
+		$this->_get_registrations_to_apply_payment_to();
1141
+		$this->_get_payment_methods($payments);
1142
+		$this->_get_payment_status_array();
1143
+		$this->_get_reg_status_selection(); // sets up the template args for the reg status array for the transaction.
1144
+
1145
+		$this->_template_args['transaction_form_url'] = add_query_arg(
1146
+			array(
1147
+				'action'  => 'edit_transaction',
1148
+				'process' => 'transaction',
1149
+			),
1150
+			TXN_ADMIN_URL
1151
+		);
1152
+		$this->_template_args['apply_payment_form_url'] = add_query_arg(
1153
+			array(
1154
+				'page'   => 'espresso_transactions',
1155
+				'action' => 'espresso_apply_payment',
1156
+			),
1157
+			WP_AJAX_URL
1158
+		);
1159
+		$this->_template_args['delete_payment_form_url'] = add_query_arg(
1160
+			array(
1161
+				'page'   => 'espresso_transactions',
1162
+				'action' => 'espresso_delete_payment',
1163
+			),
1164
+			WP_AJAX_URL
1165
+		);
1166
+
1167
+		$this->_template_args['action_buttons'] = $this->getActionButtons($this->_transaction);
1168
+
1169
+		// 'espresso_delete_payment_nonce'
1170
+
1171
+		$template_path = TXN_TEMPLATE_PATH . 'txn_admin_details_main_meta_box_txn_details.template.php';
1172
+		echo EEH_Template::display_template($template_path, $this->_template_args, true);
1173
+	}
1174
+
1175
+
1176
+	/**
1177
+	 * _get_registration_payment_IDs
1178
+	 *    generates an array of Payment IDs and their corresponding Registration IDs
1179
+	 *
1180
+	 * @access protected
1181
+	 * @param EE_Payment[] $payments
1182
+	 * @return array
1183
+	 * @throws EE_Error
1184
+	 * @throws InvalidArgumentException
1185
+	 * @throws InvalidDataTypeException
1186
+	 * @throws InvalidInterfaceException
1187
+	 * @throws ReflectionException
1188
+	 */
1189
+	protected function _get_registration_payment_IDs($payments = array())
1190
+	{
1191
+		$existing_reg_payments = array();
1192
+		// get all reg payments for these payments
1193
+		$reg_payments = EEM_Registration_Payment::instance()->get_all(
1194
+			array(
1195
+				array(
1196
+					'PAY_ID' => array(
1197
+						'IN',
1198
+						array_keys($payments),
1199
+					),
1200
+				),
1201
+			)
1202
+		);
1203
+		if (! empty($reg_payments)) {
1204
+			foreach ($payments as $payment) {
1205
+				if (! $payment instanceof EE_Payment) {
1206
+					continue;
1207
+				} elseif (! isset($existing_reg_payments[ $payment->ID() ])) {
1208
+					$existing_reg_payments[ $payment->ID() ] = array();
1209
+				}
1210
+				foreach ($reg_payments as $reg_payment) {
1211
+					if ($reg_payment instanceof EE_Registration_Payment
1212
+						&& $reg_payment->payment_ID() === $payment->ID()
1213
+					) {
1214
+						$existing_reg_payments[ $payment->ID() ][] = $reg_payment->registration_ID();
1215
+					}
1216
+				}
1217
+			}
1218
+		}
1219
+
1220
+		return $existing_reg_payments;
1221
+	}
1222
+
1223
+
1224
+	/**
1225
+	 * _get_registrations_to_apply_payment_to
1226
+	 *    generates HTML for displaying a series of checkboxes in the admin payment modal window
1227
+	 * which allows the admin to only apply the payment to the specific registrations
1228
+	 *
1229
+	 * @access protected
1230
+	 * @return void
1231
+	 * @throws EE_Error
1232
+	 * @throws InvalidArgumentException
1233
+	 * @throws InvalidDataTypeException
1234
+	 * @throws InvalidInterfaceException
1235
+	 * @throws ReflectionException
1236
+	 */
1237
+	protected function _get_registrations_to_apply_payment_to()
1238
+	{
1239
+		// we want any registration with an active status (ie: not deleted or cancelled)
1240
+		$query_params = array(
1241
+			array(
1242
+				'STS_ID' => array(
1243
+					'IN',
1244
+					array(
1245
+						EEM_Registration::status_id_approved,
1246
+						EEM_Registration::status_id_pending_payment,
1247
+						EEM_Registration::status_id_not_approved,
1248
+					),
1249
+				),
1250
+			),
1251
+		);
1252
+		$registrations_to_apply_payment_to = EEH_HTML::br() . EEH_HTML::div(
1253
+			'',
1254
+			'txn-admin-apply-payment-to-registrations-dv',
1255
+			'',
1256
+			'clear: both; margin: 1.5em 0 0; display: none;'
1257
+		);
1258
+		$registrations_to_apply_payment_to .= EEH_HTML::br() . EEH_HTML::div('', '', 'admin-primary-mbox-tbl-wrap');
1259
+		$registrations_to_apply_payment_to .= EEH_HTML::table('', '', 'admin-primary-mbox-tbl');
1260
+		$registrations_to_apply_payment_to .= EEH_HTML::thead(
1261
+			EEH_HTML::tr(
1262
+				EEH_HTML::th(esc_html__('ID', 'event_espresso')) .
1263
+				EEH_HTML::th(esc_html__('Registrant', 'event_espresso')) .
1264
+				EEH_HTML::th(esc_html__('Ticket', 'event_espresso')) .
1265
+				EEH_HTML::th(esc_html__('Event', 'event_espresso')) .
1266
+				EEH_HTML::th(esc_html__('Paid', 'event_espresso'), '', 'txn-admin-payment-paid-td jst-cntr') .
1267
+				EEH_HTML::th(esc_html__('Owing', 'event_espresso'), '', 'txn-admin-payment-owing-td jst-cntr') .
1268
+				EEH_HTML::th(esc_html__('Apply', 'event_espresso'), '', 'jst-cntr')
1269
+			)
1270
+		);
1271
+		$registrations_to_apply_payment_to .= EEH_HTML::tbody();
1272
+		// get registrations for TXN
1273
+		$registrations = $this->_transaction->registrations($query_params);
1274
+		$existing_reg_payments = $this->_template_args['existing_reg_payments'];
1275
+		foreach ($registrations as $registration) {
1276
+			if ($registration instanceof EE_Registration) {
1277
+				$attendee_name = $registration->attendee() instanceof EE_Attendee
1278
+					? $registration->attendee()->full_name()
1279
+					: esc_html__('Unknown Attendee', 'event_espresso');
1280
+				$owing = $registration->final_price() - $registration->paid();
1281
+				$taxable = $registration->ticket()->taxable()
1282
+					? ' <span class="smaller-text lt-grey-text"> ' . esc_html__('+ tax', 'event_espresso') . '</span>'
1283
+					: '';
1284
+				$checked = empty($existing_reg_payments)
1285
+						   || in_array($registration->ID(), $existing_reg_payments, true)
1286
+					? ' checked="checked"'
1287
+					: '';
1288
+				$disabled = $registration->final_price() > 0 ? '' : ' disabled';
1289
+				$registrations_to_apply_payment_to .= EEH_HTML::tr(
1290
+					EEH_HTML::td($registration->ID()) .
1291
+					EEH_HTML::td($attendee_name) .
1292
+					EEH_HTML::td(
1293
+						$registration->ticket()->name() . ' : ' . $registration->ticket()->pretty_price() . $taxable
1294
+					) .
1295
+					EEH_HTML::td($registration->event_name()) .
1296
+					EEH_HTML::td($registration->pretty_paid(), '', 'txn-admin-payment-paid-td jst-cntr') .
1297
+					EEH_HTML::td(
1298
+						EEH_Template::format_currency($owing),
1299
+						'',
1300
+						'txn-admin-payment-owing-td jst-cntr'
1301
+					) .
1302
+					EEH_HTML::td(
1303
+						'<input type="checkbox" value="' . $registration->ID()
1304
+						. '" name="txn_admin_payment[registrations]"'
1305
+						. $checked . $disabled . '>',
1306
+						'',
1307
+						'jst-cntr'
1308
+					),
1309
+					'apply-payment-registration-row-' . $registration->ID()
1310
+				);
1311
+			}
1312
+		}
1313
+		$registrations_to_apply_payment_to .= EEH_HTML::tbodyx();
1314
+		$registrations_to_apply_payment_to .= EEH_HTML::tablex();
1315
+		$registrations_to_apply_payment_to .= EEH_HTML::divx();
1316
+		$registrations_to_apply_payment_to .= EEH_HTML::p(
1317
+			esc_html__(
1318
+				'The payment will only be applied to the registrations that have a check mark in their corresponding check box. Checkboxes for free registrations have been disabled.',
1319
+				'event_espresso'
1320
+			),
1321
+			'',
1322
+			'clear description'
1323
+		);
1324
+		$registrations_to_apply_payment_to .= EEH_HTML::divx();
1325
+		$this->_template_args['registrations_to_apply_payment_to'] = $registrations_to_apply_payment_to;
1326
+	}
1327
+
1328
+
1329
+	/**
1330
+	 * _get_reg_status_selection
1331
+	 *
1332
+	 * @todo   this will need to be adjusted either once MER comes along OR we move default reg status to tickets
1333
+	 *         instead of events.
1334
+	 * @access protected
1335
+	 * @return void
1336
+	 * @throws EE_Error
1337
+	 */
1338
+	protected function _get_reg_status_selection()
1339
+	{
1340
+		// first get all possible statuses
1341
+		$statuses = EEM_Registration::reg_status_array(array(), true);
1342
+		// let's add a "don't change" option.
1343
+		$status_array['NAN'] = esc_html__('Leave the Same', 'event_espresso');
1344
+		$status_array = array_merge($status_array, $statuses);
1345
+		$this->_template_args['status_change_select'] = EEH_Form_Fields::select_input(
1346
+			'txn_reg_status_change[reg_status]',
1347
+			$status_array,
1348
+			'NAN',
1349
+			'id="txn-admin-payment-reg-status-inp"',
1350
+			'txn-reg-status-change-reg-status'
1351
+		);
1352
+		$this->_template_args['delete_status_change_select'] = EEH_Form_Fields::select_input(
1353
+			'delete_txn_reg_status_change[reg_status]',
1354
+			$status_array,
1355
+			'NAN',
1356
+			'delete-txn-admin-payment-reg-status-inp',
1357
+			'delete-txn-reg-status-change-reg-status'
1358
+		);
1359
+	}
1360
+
1361
+
1362
+	/**
1363
+	 *    _get_payment_methods
1364
+	 * Gets all the payment methods available generally, or the ones that are already
1365
+	 * selected on these payments (in case their payment methods are no longer active).
1366
+	 * Has the side-effect of updating the template args' payment_methods item
1367
+	 *
1368
+	 * @access private
1369
+	 * @param EE_Payment[] to show on this page
1370
+	 * @return void
1371
+	 * @throws EE_Error
1372
+	 * @throws InvalidArgumentException
1373
+	 * @throws InvalidDataTypeException
1374
+	 * @throws InvalidInterfaceException
1375
+	 * @throws ReflectionException
1376
+	 */
1377
+	private function _get_payment_methods($payments = array())
1378
+	{
1379
+		$payment_methods_of_payments = array();
1380
+		foreach ($payments as $payment) {
1381
+			if ($payment instanceof EE_Payment) {
1382
+				$payment_methods_of_payments[] = $payment->ID();
1383
+			}
1384
+		}
1385
+		if ($payment_methods_of_payments) {
1386
+			$query_args = array(
1387
+				array(
1388
+					'OR*payment_method_for_payment' => array(
1389
+						'PMD_ID'    => array('IN', $payment_methods_of_payments),
1390
+						'PMD_scope' => array('LIKE', '%' . EEM_Payment_Method::scope_admin . '%'),
1391
+					),
1392
+				),
1393
+			);
1394
+		} else {
1395
+			$query_args = array(array('PMD_scope' => array('LIKE', '%' . EEM_Payment_Method::scope_admin . '%')));
1396
+		}
1397
+		$this->_template_args['payment_methods'] = EEM_Payment_Method::instance()->get_all($query_args);
1398
+	}
1399
+
1400
+
1401
+	/**
1402
+	 * txn_attendees_meta_box
1403
+	 *    generates HTML for the Attendees Transaction main meta box
1404
+	 *
1405
+	 * @access public
1406
+	 * @param WP_Post $post
1407
+	 * @param array   $metabox
1408
+	 * @return void
1409
+	 * @throws DomainException
1410
+	 * @throws EE_Error
1411
+	 * @throws InvalidArgumentException
1412
+	 * @throws InvalidDataTypeException
1413
+	 * @throws InvalidInterfaceException
1414
+	 * @throws ReflectionException
1415
+	 */
1416
+	public function txn_attendees_meta_box($post, $metabox = array('args' => array()))
1417
+	{
1418
+
1419
+		/** @noinspection NonSecureExtractUsageInspection */
1420
+		extract($metabox['args']);
1421
+		$this->_template_args['post'] = $post;
1422
+		$this->_template_args['event_attendees'] = array();
1423
+		// process items in cart
1424
+		$line_items = $this->_transaction->get_many_related(
1425
+			'Line_Item',
1426
+			array(array('LIN_type' => 'line-item'))
1427
+		);
1428
+		if (! empty($line_items)) {
1429
+			foreach ($line_items as $item) {
1430
+				if ($item instanceof EE_Line_Item) {
1431
+					switch ($item->OBJ_type()) {
1432
+						case 'Event':
1433
+							break;
1434
+						case 'Ticket':
1435
+							$ticket = $item->ticket();
1436
+							// right now we're only handling tickets here.
1437
+							// Cause its expected that only tickets will have attendees right?
1438
+							if (! $ticket instanceof EE_Ticket) {
1439
+								break;
1440
+							}
1441
+							try {
1442
+								$event_name = $ticket->get_event_name();
1443
+							} catch (Exception $e) {
1444
+								EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
1445
+								$event_name = esc_html__('Unknown Event', 'event_espresso');
1446
+							}
1447
+							$event_name .= ' - ' . $item->name();
1448
+							$ticket_price = EEH_Template::format_currency($item->unit_price());
1449
+							// now get all of the registrations for this transaction that use this ticket
1450
+							$registrations = $ticket->registrations(
1451
+								array(array('TXN_ID' => $this->_transaction->ID()))
1452
+							);
1453
+							foreach ($registrations as $registration) {
1454
+								if (! $registration instanceof EE_Registration) {
1455
+									break;
1456
+								}
1457
+								$this->_template_args['event_attendees'][ $registration->ID() ]['STS_ID']
1458
+									= $registration->status_ID();
1459
+								$this->_template_args['event_attendees'][ $registration->ID() ]['att_num']
1460
+									= $registration->count();
1461
+								$this->_template_args['event_attendees'][ $registration->ID() ]['event_ticket_name']
1462
+									= $event_name;
1463
+								$this->_template_args['event_attendees'][ $registration->ID() ]['ticket_price']
1464
+									= $ticket_price;
1465
+								// attendee info
1466
+								$attendee = $registration->get_first_related('Attendee');
1467
+								if ($attendee instanceof EE_Attendee) {
1468
+									$this->_template_args['event_attendees'][ $registration->ID() ]['att_id']
1469
+										= $attendee->ID();
1470
+									$this->_template_args['event_attendees'][ $registration->ID() ]['attendee']
1471
+										= $attendee->full_name();
1472
+									$this->_template_args['event_attendees'][ $registration->ID() ]['email']
1473
+										= '<a href="mailto:' . $attendee->email() . '?subject=' . $event_name
1474
+										  . esc_html__(
1475
+											  ' Event',
1476
+											  'event_espresso'
1477
+										  )
1478
+										  . '">' . $attendee->email() . '</a>';
1479
+									$this->_template_args['event_attendees'][ $registration->ID() ]['address']
1480
+										= EEH_Address::format($attendee, 'inline', false, false);
1481
+								} else {
1482
+									$this->_template_args['event_attendees'][ $registration->ID() ]['att_id'] = '';
1483
+									$this->_template_args['event_attendees'][ $registration->ID() ]['attendee'] = '';
1484
+									$this->_template_args['event_attendees'][ $registration->ID() ]['email'] = '';
1485
+									$this->_template_args['event_attendees'][ $registration->ID() ]['address'] = '';
1486
+								}
1487
+							}
1488
+							break;
1489
+					}
1490
+				}
1491
+			}
1492
+
1493
+			$this->_template_args['transaction_form_url'] = add_query_arg(
1494
+				array(
1495
+					'action'  => 'edit_transaction',
1496
+					'process' => 'attendees',
1497
+				),
1498
+				TXN_ADMIN_URL
1499
+			);
1500
+			echo EEH_Template::display_template(
1501
+				TXN_TEMPLATE_PATH . 'txn_admin_details_main_meta_box_attendees.template.php',
1502
+				$this->_template_args,
1503
+				true
1504
+			);
1505
+		} else {
1506
+			echo sprintf(
1507
+				esc_html__(
1508
+					'%1$sFor some reason, there are no attendees registered for this transaction. Likely the registration was abandoned in process.%2$s',
1509
+					'event_espresso'
1510
+				),
1511
+				'<p class="important-notice">',
1512
+				'</p>'
1513
+			);
1514
+		}
1515
+	}
1516
+
1517
+
1518
+	/**
1519
+	 * txn_registrant_side_meta_box
1520
+	 * generates HTML for the Edit Transaction side meta box
1521
+	 *
1522
+	 * @access public
1523
+	 * @return void
1524
+	 * @throws DomainException
1525
+	 * @throws EE_Error
1526
+	 * @throws InvalidArgumentException
1527
+	 * @throws InvalidDataTypeException
1528
+	 * @throws InvalidInterfaceException
1529
+	 * @throws ReflectionException
1530
+	 */
1531
+	public function txn_registrant_side_meta_box()
1532
+	{
1533
+		$primary_att = $this->_transaction->primary_registration() instanceof EE_Registration
1534
+			? $this->_transaction->primary_registration()->get_first_related('Attendee')
1535
+			: null;
1536
+		if (! $primary_att instanceof EE_Attendee) {
1537
+			$this->_template_args['no_attendee_message'] = esc_html__(
1538
+				'There is no attached contact for this transaction.  The transaction either failed due to an error or was abandoned.',
1539
+				'event_espresso'
1540
+			);
1541
+			$primary_att = EEM_Attendee::instance()->create_default_object();
1542
+		}
1543
+		$this->_template_args['ATT_ID'] = $primary_att->ID();
1544
+		$this->_template_args['prime_reg_fname'] = $primary_att->fname();
1545
+		$this->_template_args['prime_reg_lname'] = $primary_att->lname();
1546
+		$this->_template_args['prime_reg_email'] = $primary_att->email();
1547
+		$this->_template_args['prime_reg_phone'] = $primary_att->phone();
1548
+		$this->_template_args['edit_attendee_url'] = EE_Admin_Page::add_query_args_and_nonce(
1549
+			array(
1550
+				'action' => 'edit_attendee',
1551
+				'post'   => $primary_att->ID(),
1552
+			),
1553
+			REG_ADMIN_URL
1554
+		);
1555
+		// get formatted address for registrant
1556
+		$this->_template_args['formatted_address'] = EEH_Address::format($primary_att);
1557
+		echo EEH_Template::display_template(
1558
+			TXN_TEMPLATE_PATH . 'txn_admin_details_side_meta_box_registrant.template.php',
1559
+			$this->_template_args,
1560
+			true
1561
+		);
1562
+	}
1563
+
1564
+
1565
+	/**
1566
+	 * txn_billing_info_side_meta_box
1567
+	 *    generates HTML for the Edit Transaction side meta box
1568
+	 *
1569
+	 * @access public
1570
+	 * @return void
1571
+	 * @throws DomainException
1572
+	 * @throws EE_Error
1573
+	 */
1574
+	public function txn_billing_info_side_meta_box()
1575
+	{
1576
+
1577
+		$this->_template_args['billing_form'] = $this->_transaction->billing_info();
1578
+		$this->_template_args['billing_form_url'] = add_query_arg(
1579
+			array('action' => 'edit_transaction', 'process' => 'billing'),
1580
+			TXN_ADMIN_URL
1581
+		);
1582
+
1583
+		$template_path = TXN_TEMPLATE_PATH . 'txn_admin_details_side_meta_box_billing_info.template.php';
1584
+		echo EEH_Template::display_template($template_path, $this->_template_args, true);
1585
+	}
1586
+
1587
+
1588
+	/**
1589
+	 * apply_payments_or_refunds
1590
+	 *    registers a payment or refund made towards a transaction
1591
+	 *
1592
+	 * @access public
1593
+	 * @return void
1594
+	 * @throws EE_Error
1595
+	 * @throws InvalidArgumentException
1596
+	 * @throws ReflectionException
1597
+	 * @throws RuntimeException
1598
+	 * @throws InvalidDataTypeException
1599
+	 * @throws InvalidInterfaceException
1600
+	 */
1601
+	public function apply_payments_or_refunds()
1602
+	{
1603
+		$json_response_data = array('return_data' => false);
1604
+		$valid_data = $this->_validate_payment_request_data();
1605
+		$has_access = EE_Registry::instance()->CAP->current_user_can(
1606
+			'ee_edit_payments',
1607
+			'apply_payment_or_refund_from_registration_details'
1608
+		);
1609
+		if (! empty($valid_data) && $has_access) {
1610
+			$PAY_ID = $valid_data['PAY_ID'];
1611
+			// save  the new payment
1612
+			$payment = $this->_create_payment_from_request_data($valid_data);
1613
+			// get the TXN for this payment
1614
+			$transaction = $payment->transaction();
1615
+			// verify transaction
1616
+			if ($transaction instanceof EE_Transaction) {
1617
+				// calculate_total_payments_and_update_status
1618
+				$this->_process_transaction_payments($transaction);
1619
+				$REG_IDs = $this->_get_REG_IDs_to_apply_payment_to($payment);
1620
+				$this->_remove_existing_registration_payments($payment, $PAY_ID);
1621
+				// apply payment to registrations (if applicable)
1622
+				if (! empty($REG_IDs)) {
1623
+					$this->_update_registration_payments($transaction, $payment, $REG_IDs);
1624
+					$this->_maybe_send_notifications();
1625
+					// now process status changes for the same registrations
1626
+					$this->_process_registration_status_change($transaction, $REG_IDs);
1627
+				}
1628
+				$this->_maybe_send_notifications($payment);
1629
+				// prepare to render page
1630
+				$json_response_data['return_data'] = $this->_build_payment_json_response($payment, $REG_IDs);
1631
+				do_action(
1632
+					'AHEE__Transactions_Admin_Page__apply_payments_or_refund__after_recording',
1633
+					$transaction,
1634
+					$payment
1635
+				);
1636
+			} else {
1637
+				EE_Error::add_error(
1638
+					esc_html__(
1639
+						'A valid Transaction for this payment could not be retrieved.',
1640
+						'event_espresso'
1641
+					),
1642
+					__FILE__,
1643
+					__FUNCTION__,
1644
+					__LINE__
1645
+				);
1646
+			}
1647
+		} elseif ($has_access) {
1648
+			EE_Error::add_error(
1649
+				esc_html__(
1650
+					'The payment form data could not be processed. Please try again.',
1651
+					'event_espresso'
1652
+				),
1653
+				__FILE__,
1654
+				__FUNCTION__,
1655
+				__LINE__
1656
+			);
1657
+		} else {
1658
+			EE_Error::add_error(
1659
+				esc_html__(
1660
+					'You do not have access to apply payments or refunds to a registration.',
1661
+					'event_espresso'
1662
+				),
1663
+				__FILE__,
1664
+				__FUNCTION__,
1665
+				__LINE__
1666
+			);
1667
+		}
1668
+		$notices = EE_Error::get_notices(
1669
+			false,
1670
+			false,
1671
+			false
1672
+		);
1673
+		$this->_template_args = array(
1674
+			'data'    => $json_response_data,
1675
+			'error'   => $notices['errors'],
1676
+			'success' => $notices['success'],
1677
+		);
1678
+		$this->_return_json();
1679
+	}
1680
+
1681
+
1682
+	/**
1683
+	 * _validate_payment_request_data
1684
+	 *
1685
+	 * @return array
1686
+	 * @throws EE_Error
1687
+	 * @throws InvalidArgumentException
1688
+	 * @throws InvalidDataTypeException
1689
+	 * @throws InvalidInterfaceException
1690
+	 */
1691
+	protected function _validate_payment_request_data()
1692
+	{
1693
+		if (! isset($this->_req_data['txn_admin_payment'])) {
1694
+			return array();
1695
+		}
1696
+		$payment_form = $this->_generate_payment_form_section();
1697
+		try {
1698
+			if ($payment_form->was_submitted()) {
1699
+				$payment_form->receive_form_submission();
1700
+				if (! $payment_form->is_valid()) {
1701
+					$submission_error_messages = array();
1702
+					foreach ($payment_form->get_validation_errors_accumulated() as $validation_error) {
1703
+						if ($validation_error instanceof EE_Validation_Error) {
1704
+							$submission_error_messages[] = sprintf(
1705
+								_x('%s : %s', 'Form Section Name : Form Validation Error', 'event_espresso'),
1706
+								$validation_error->get_form_section()->html_label_text(),
1707
+								$validation_error->getMessage()
1708
+							);
1709
+						}
1710
+					}
1711
+					EE_Error::add_error(
1712
+						implode('<br />', $submission_error_messages),
1713
+						__FILE__,
1714
+						__FUNCTION__,
1715
+						__LINE__
1716
+					);
1717
+					return array();
1718
+				}
1719
+			}
1720
+		} catch (EE_Error $e) {
1721
+			EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
1722
+			return array();
1723
+		}
1724
+
1725
+		return $payment_form->valid_data();
1726
+	}
1727
+
1728
+
1729
+	/**
1730
+	 * _generate_payment_form_section
1731
+	 *
1732
+	 * @return EE_Form_Section_Proper
1733
+	 * @throws EE_Error
1734
+	 */
1735
+	protected function _generate_payment_form_section()
1736
+	{
1737
+		return new EE_Form_Section_Proper(
1738
+			array(
1739
+				'name'        => 'txn_admin_payment',
1740
+				'subsections' => array(
1741
+					'PAY_ID'          => new EE_Text_Input(
1742
+						array(
1743
+							'default'               => 0,
1744
+							'required'              => false,
1745
+							'html_label_text'       => esc_html__('Payment ID', 'event_espresso'),
1746
+							'validation_strategies' => array(new EE_Int_Normalization()),
1747
+						)
1748
+					),
1749
+					'TXN_ID'          => new EE_Text_Input(
1750
+						array(
1751
+							'default'               => 0,
1752
+							'required'              => true,
1753
+							'html_label_text'       => esc_html__('Transaction ID', 'event_espresso'),
1754
+							'validation_strategies' => array(new EE_Int_Normalization()),
1755
+						)
1756
+					),
1757
+					'type'            => new EE_Text_Input(
1758
+						array(
1759
+							'default'               => 1,
1760
+							'required'              => true,
1761
+							'html_label_text'       => esc_html__('Payment or Refund', 'event_espresso'),
1762
+							'validation_strategies' => array(new EE_Int_Normalization()),
1763
+						)
1764
+					),
1765
+					'amount'          => new EE_Text_Input(
1766
+						array(
1767
+							'default'               => 0,
1768
+							'required'              => true,
1769
+							'html_label_text'       => esc_html__('Payment amount', 'event_espresso'),
1770
+							'validation_strategies' => array(new EE_Float_Normalization()),
1771
+						)
1772
+					),
1773
+					'status'          => new EE_Text_Input(
1774
+						array(
1775
+							'default'         => EEM_Payment::status_id_approved,
1776
+							'required'        => true,
1777
+							'html_label_text' => esc_html__('Payment status', 'event_espresso'),
1778
+						)
1779
+					),
1780
+					'PMD_ID'          => new EE_Text_Input(
1781
+						array(
1782
+							'default'               => 2,
1783
+							'required'              => true,
1784
+							'html_label_text'       => esc_html__('Payment Method', 'event_espresso'),
1785
+							'validation_strategies' => array(new EE_Int_Normalization()),
1786
+						)
1787
+					),
1788
+					'date'            => new EE_Text_Input(
1789
+						array(
1790
+							'default'         => time(),
1791
+							'required'        => true,
1792
+							'html_label_text' => esc_html__('Payment date', 'event_espresso'),
1793
+						)
1794
+					),
1795
+					'txn_id_chq_nmbr' => new EE_Text_Input(
1796
+						array(
1797
+							'default'               => '',
1798
+							'required'              => false,
1799
+							'html_label_text'       => esc_html__('Transaction or Cheque Number', 'event_espresso'),
1800
+							'validation_strategies' => array(
1801
+								new EE_Max_Length_Validation_Strategy(
1802
+									esc_html__('Input too long', 'event_espresso'),
1803
+									100
1804
+								),
1805
+							),
1806
+						)
1807
+					),
1808
+					'po_number'       => new EE_Text_Input(
1809
+						array(
1810
+							'default'               => '',
1811
+							'required'              => false,
1812
+							'html_label_text'       => esc_html__('Purchase Order Number', 'event_espresso'),
1813
+							'validation_strategies' => array(
1814
+								new EE_Max_Length_Validation_Strategy(
1815
+									esc_html__('Input too long', 'event_espresso'),
1816
+									100
1817
+								),
1818
+							),
1819
+						)
1820
+					),
1821
+					'accounting'      => new EE_Text_Input(
1822
+						array(
1823
+							'default'               => '',
1824
+							'required'              => false,
1825
+							'html_label_text'       => esc_html__('Extra Field for Accounting', 'event_espresso'),
1826
+							'validation_strategies' => array(
1827
+								new EE_Max_Length_Validation_Strategy(
1828
+									esc_html__('Input too long', 'event_espresso'),
1829
+									100
1830
+								),
1831
+							),
1832
+						)
1833
+					),
1834
+				),
1835
+			)
1836
+		);
1837
+	}
1838
+
1839
+
1840
+	/**
1841
+	 * _create_payment_from_request_data
1842
+	 *
1843
+	 * @param array $valid_data
1844
+	 * @return EE_Payment
1845
+	 * @throws EE_Error
1846
+	 * @throws InvalidArgumentException
1847
+	 * @throws InvalidDataTypeException
1848
+	 * @throws InvalidInterfaceException
1849
+	 * @throws ReflectionException
1850
+	 */
1851
+	protected function _create_payment_from_request_data($valid_data)
1852
+	{
1853
+		$PAY_ID = $valid_data['PAY_ID'];
1854
+		// get payment amount
1855
+		$amount = $valid_data['amount'] ? abs($valid_data['amount']) : 0;
1856
+		// payments have a type value of 1 and refunds have a type value of -1
1857
+		// so multiplying amount by type will give a positive value for payments, and negative values for refunds
1858
+		$amount = $valid_data['type'] < 0 ? $amount * -1 : $amount;
1859
+		// for some reason the date string coming in has extra spaces between the date and time.  This fixes that.
1860
+		$date = $valid_data['date']
1861
+			? preg_replace('/\s+/', ' ', $valid_data['date'])
1862
+			: date('Y-m-d g:i a', current_time('timestamp'));
1863
+		$payment = EE_Payment::new_instance(
1864
+			array(
1865
+				'TXN_ID'              => $valid_data['TXN_ID'],
1866
+				'STS_ID'              => $valid_data['status'],
1867
+				'PAY_timestamp'       => $date,
1868
+				'PAY_source'          => EEM_Payment_Method::scope_admin,
1869
+				'PMD_ID'              => $valid_data['PMD_ID'],
1870
+				'PAY_amount'          => $amount,
1871
+				'PAY_txn_id_chq_nmbr' => $valid_data['txn_id_chq_nmbr'],
1872
+				'PAY_po_number'       => $valid_data['po_number'],
1873
+				'PAY_extra_accntng'   => $valid_data['accounting'],
1874
+				'PAY_details'         => $valid_data,
1875
+				'PAY_ID'              => $PAY_ID,
1876
+			),
1877
+			'',
1878
+			array('Y-m-d', 'g:i a')
1879
+		);
1880
+
1881
+		if (! $payment->save()) {
1882
+			EE_Error::add_error(
1883
+				sprintf(
1884
+					esc_html__('Payment %1$d has not been successfully saved to the database.', 'event_espresso'),
1885
+					$payment->ID()
1886
+				),
1887
+				__FILE__,
1888
+				__FUNCTION__,
1889
+				__LINE__
1890
+			);
1891
+		}
1892
+
1893
+		return $payment;
1894
+	}
1895
+
1896
+
1897
+	/**
1898
+	 * _process_transaction_payments
1899
+	 *
1900
+	 * @param \EE_Transaction $transaction
1901
+	 * @return void
1902
+	 * @throws EE_Error
1903
+	 * @throws InvalidArgumentException
1904
+	 * @throws ReflectionException
1905
+	 * @throws InvalidDataTypeException
1906
+	 * @throws InvalidInterfaceException
1907
+	 */
1908
+	protected function _process_transaction_payments(EE_Transaction $transaction)
1909
+	{
1910
+		/** @type EE_Transaction_Payments $transaction_payments */
1911
+		$transaction_payments = EE_Registry::instance()->load_class('Transaction_Payments');
1912
+		// update the transaction with this payment
1913
+		if ($transaction_payments->calculate_total_payments_and_update_status($transaction)) {
1914
+			EE_Error::add_success(
1915
+				esc_html__(
1916
+					'The payment has been processed successfully.',
1917
+					'event_espresso'
1918
+				),
1919
+				__FILE__,
1920
+				__FUNCTION__,
1921
+				__LINE__
1922
+			);
1923
+		} else {
1924
+			EE_Error::add_error(
1925
+				esc_html__(
1926
+					'The payment was processed successfully but the amount paid for the transaction was not updated.',
1927
+					'event_espresso'
1928
+				),
1929
+				__FILE__,
1930
+				__FUNCTION__,
1931
+				__LINE__
1932
+			);
1933
+		}
1934
+	}
1935
+
1936
+
1937
+	/**
1938
+	 * _get_REG_IDs_to_apply_payment_to
1939
+	 * returns a list of registration IDs that the payment will apply to
1940
+	 *
1941
+	 * @param \EE_Payment $payment
1942
+	 * @return array
1943
+	 * @throws EE_Error
1944
+	 * @throws InvalidArgumentException
1945
+	 * @throws InvalidDataTypeException
1946
+	 * @throws InvalidInterfaceException
1947
+	 * @throws ReflectionException
1948
+	 */
1949
+	protected function _get_REG_IDs_to_apply_payment_to(EE_Payment $payment)
1950
+	{
1951
+		$REG_IDs = array();
1952
+		// grab array of IDs for specific registrations to apply changes to
1953
+		if (isset($this->_req_data['txn_admin_payment']['registrations'])) {
1954
+			$REG_IDs = (array) $this->_req_data['txn_admin_payment']['registrations'];
1955
+		}
1956
+		// nothing specified ? then get all reg IDs
1957
+		if (empty($REG_IDs)) {
1958
+			$registrations = $payment->transaction()->registrations();
1959
+			$REG_IDs = ! empty($registrations)
1960
+				? array_keys($registrations)
1961
+				: $this->_get_existing_reg_payment_REG_IDs($payment);
1962
+		}
1963
+
1964
+		// ensure that REG_IDs are integers and NOT strings
1965
+		return array_map('intval', $REG_IDs);
1966
+	}
1967
+
1968
+
1969
+	/**
1970
+	 * @return array
1971
+	 */
1972
+	public function existing_reg_payment_REG_IDs()
1973
+	{
1974
+		return $this->_existing_reg_payment_REG_IDs;
1975
+	}
1976
+
1977
+
1978
+	/**
1979
+	 * @param array $existing_reg_payment_REG_IDs
1980
+	 */
1981
+	public function set_existing_reg_payment_REG_IDs($existing_reg_payment_REG_IDs = null)
1982
+	{
1983
+		$this->_existing_reg_payment_REG_IDs = $existing_reg_payment_REG_IDs;
1984
+	}
1985
+
1986
+
1987
+	/**
1988
+	 * _get_existing_reg_payment_REG_IDs
1989
+	 * returns a list of registration IDs that the payment is currently related to
1990
+	 * as recorded in the database
1991
+	 *
1992
+	 * @param \EE_Payment $payment
1993
+	 * @return array
1994
+	 * @throws EE_Error
1995
+	 * @throws InvalidArgumentException
1996
+	 * @throws InvalidDataTypeException
1997
+	 * @throws InvalidInterfaceException
1998
+	 * @throws ReflectionException
1999
+	 */
2000
+	protected function _get_existing_reg_payment_REG_IDs(EE_Payment $payment)
2001
+	{
2002
+		if ($this->existing_reg_payment_REG_IDs() === null) {
2003
+			// let's get any existing reg payment records for this payment
2004
+			$existing_reg_payment_REG_IDs = $payment->get_many_related('Registration');
2005
+			// but we only want the REG IDs, so grab the array keys
2006
+			$existing_reg_payment_REG_IDs = ! empty($existing_reg_payment_REG_IDs)
2007
+				? array_keys($existing_reg_payment_REG_IDs)
2008
+				: array();
2009
+			$this->set_existing_reg_payment_REG_IDs($existing_reg_payment_REG_IDs);
2010
+		}
2011
+
2012
+		return $this->existing_reg_payment_REG_IDs();
2013
+	}
2014
+
2015
+
2016
+	/**
2017
+	 * _remove_existing_registration_payments
2018
+	 * this calculates the difference between existing relations
2019
+	 * to the supplied payment and the new list registration IDs,
2020
+	 * removes any related registrations that no longer apply,
2021
+	 * and then updates the registration paid fields
2022
+	 *
2023
+	 * @param \EE_Payment $payment
2024
+	 * @param int         $PAY_ID
2025
+	 * @return bool;
2026
+	 * @throws EE_Error
2027
+	 * @throws InvalidArgumentException
2028
+	 * @throws ReflectionException
2029
+	 * @throws InvalidDataTypeException
2030
+	 * @throws InvalidInterfaceException
2031
+	 */
2032
+	protected function _remove_existing_registration_payments(EE_Payment $payment, $PAY_ID = 0)
2033
+	{
2034
+		// newly created payments will have nothing recorded for $PAY_ID
2035
+		if (absint($PAY_ID) === 0) {
2036
+			return false;
2037
+		}
2038
+		$existing_reg_payment_REG_IDs = $this->_get_existing_reg_payment_REG_IDs($payment);
2039
+		if (empty($existing_reg_payment_REG_IDs)) {
2040
+			return false;
2041
+		}
2042
+		/** @type EE_Transaction_Payments $transaction_payments */
2043
+		$transaction_payments = EE_Registry::instance()->load_class('Transaction_Payments');
2044
+
2045
+		return $transaction_payments->delete_registration_payments_and_update_registrations(
2046
+			$payment,
2047
+			array(
2048
+				array(
2049
+					'PAY_ID' => $payment->ID(),
2050
+					'REG_ID' => array('IN', $existing_reg_payment_REG_IDs),
2051
+				),
2052
+			)
2053
+		);
2054
+	}
2055
+
2056
+
2057
+	/**
2058
+	 * _update_registration_payments
2059
+	 * this applies the payments to the selected registrations
2060
+	 * but only if they have not already been paid for
2061
+	 *
2062
+	 * @param  EE_Transaction $transaction
2063
+	 * @param \EE_Payment     $payment
2064
+	 * @param array           $REG_IDs
2065
+	 * @return void
2066
+	 * @throws EE_Error
2067
+	 * @throws InvalidArgumentException
2068
+	 * @throws ReflectionException
2069
+	 * @throws RuntimeException
2070
+	 * @throws InvalidDataTypeException
2071
+	 * @throws InvalidInterfaceException
2072
+	 */
2073
+	protected function _update_registration_payments(
2074
+		EE_Transaction $transaction,
2075
+		EE_Payment $payment,
2076
+		$REG_IDs = array()
2077
+	) {
2078
+		// we can pass our own custom set of registrations to EE_Payment_Processor::process_registration_payments()
2079
+		// so let's do that using our set of REG_IDs from the form
2080
+		$registration_query_where_params = array(
2081
+			'REG_ID' => array('IN', $REG_IDs),
2082
+		);
2083
+		// but add in some conditions regarding payment,
2084
+		// so that we don't apply payments to registrations that are free or have already been paid for
2085
+		// but ONLY if the payment is NOT a refund ( ie: the payment amount is not negative )
2086
+		if (! $payment->is_a_refund()) {
2087
+			$registration_query_where_params['REG_final_price'] = array('!=', 0);
2088
+			$registration_query_where_params['REG_final_price*'] = array('!=', 'REG_paid', true);
2089
+		}
2090
+		$registrations = $transaction->registrations(array($registration_query_where_params));
2091
+		if (! empty($registrations)) {
2092
+			/** @type EE_Payment_Processor $payment_processor */
2093
+			$payment_processor = EE_Registry::instance()->load_core('Payment_Processor');
2094
+			$payment_processor->process_registration_payments($transaction, $payment, $registrations);
2095
+		}
2096
+	}
2097
+
2098
+
2099
+	/**
2100
+	 * _process_registration_status_change
2101
+	 * This processes requested registration status changes for all the registrations
2102
+	 * on a given transaction and (optionally) sends out notifications for the changes.
2103
+	 *
2104
+	 * @param  EE_Transaction $transaction
2105
+	 * @param array           $REG_IDs
2106
+	 * @return bool
2107
+	 * @throws EE_Error
2108
+	 * @throws InvalidArgumentException
2109
+	 * @throws ReflectionException
2110
+	 * @throws InvalidDataTypeException
2111
+	 * @throws InvalidInterfaceException
2112
+	 */
2113
+	protected function _process_registration_status_change(EE_Transaction $transaction, $REG_IDs = array())
2114
+	{
2115
+		// first if there is no change in status then we get out.
2116
+		if (! isset($this->_req_data['txn_reg_status_change']['reg_status'])
2117
+			|| $this->_req_data['txn_reg_status_change']['reg_status'] === 'NAN'
2118
+		) {
2119
+			// no error message, no change requested, just nothing to do man.
2120
+			return false;
2121
+		}
2122
+		/** @type EE_Transaction_Processor $transaction_processor */
2123
+		$transaction_processor = EE_Registry::instance()->load_class('Transaction_Processor');
2124
+
2125
+		// made it here dude?  Oh WOW.  K, let's take care of changing the statuses
2126
+		return $transaction_processor->manually_update_registration_statuses(
2127
+			$transaction,
2128
+			sanitize_text_field($this->_req_data['txn_reg_status_change']['reg_status']),
2129
+			array(array('REG_ID' => array('IN', $REG_IDs)))
2130
+		);
2131
+	}
2132
+
2133
+
2134
+	/**
2135
+	 * _build_payment_json_response
2136
+	 *
2137
+	 * @access public
2138
+	 * @param \EE_Payment $payment
2139
+	 * @param array       $REG_IDs
2140
+	 * @param bool | null $delete_txn_reg_status_change
2141
+	 * @return array
2142
+	 * @throws EE_Error
2143
+	 * @throws InvalidArgumentException
2144
+	 * @throws InvalidDataTypeException
2145
+	 * @throws InvalidInterfaceException
2146
+	 * @throws ReflectionException
2147
+	 */
2148
+	protected function _build_payment_json_response(
2149
+		EE_Payment $payment,
2150
+		$REG_IDs = array(),
2151
+		$delete_txn_reg_status_change = null
2152
+	) {
2153
+		// was the payment deleted ?
2154
+		if (is_bool($delete_txn_reg_status_change)) {
2155
+			return array(
2156
+				'PAY_ID'                       => $payment->ID(),
2157
+				'amount'                       => $payment->amount(),
2158
+				'total_paid'                   => $payment->transaction()->paid(),
2159
+				'txn_status'                   => $payment->transaction()->status_ID(),
2160
+				'pay_status'                   => $payment->STS_ID(),
2161
+				'registrations'                => $this->_registration_payment_data_array($REG_IDs),
2162
+				'delete_txn_reg_status_change' => $delete_txn_reg_status_change,
2163
+			);
2164
+		} else {
2165
+			$this->_get_payment_status_array();
2166
+
2167
+			return array(
2168
+				'amount'           => $payment->amount(),
2169
+				'total_paid'       => $payment->transaction()->paid(),
2170
+				'txn_status'       => $payment->transaction()->status_ID(),
2171
+				'pay_status'       => $payment->STS_ID(),
2172
+				'PAY_ID'           => $payment->ID(),
2173
+				'STS_ID'           => $payment->STS_ID(),
2174
+				'status'           => self::$_pay_status[ $payment->STS_ID() ],
2175
+				'date'             => $payment->timestamp('Y-m-d', 'h:i a'),
2176
+				'method'           => strtoupper($payment->source()),
2177
+				'PM_ID'            => $payment->payment_method() ? $payment->payment_method()->ID() : 1,
2178
+				'gateway'          => $payment->payment_method()
2179
+					? $payment->payment_method()->admin_name()
2180
+					: esc_html__('Unknown', 'event_espresso'),
2181
+				'gateway_response' => $payment->gateway_response(),
2182
+				'txn_id_chq_nmbr'  => $payment->txn_id_chq_nmbr(),
2183
+				'po_number'        => $payment->po_number(),
2184
+				'extra_accntng'    => $payment->extra_accntng(),
2185
+				'registrations'    => $this->_registration_payment_data_array($REG_IDs),
2186
+			);
2187
+		}
2188
+	}
2189
+
2190
+
2191
+	/**
2192
+	 * delete_payment
2193
+	 *    delete a payment or refund made towards a transaction
2194
+	 *
2195
+	 * @access public
2196
+	 * @return void
2197
+	 * @throws EE_Error
2198
+	 * @throws InvalidArgumentException
2199
+	 * @throws ReflectionException
2200
+	 * @throws InvalidDataTypeException
2201
+	 * @throws InvalidInterfaceException
2202
+	 */
2203
+	public function delete_payment()
2204
+	{
2205
+		$json_response_data = array('return_data' => false);
2206
+		$PAY_ID = isset($this->_req_data['delete_txn_admin_payment']['PAY_ID'])
2207
+			? absint($this->_req_data['delete_txn_admin_payment']['PAY_ID'])
2208
+			: 0;
2209
+		$can_delete = EE_Registry::instance()->CAP->current_user_can(
2210
+			'ee_delete_payments',
2211
+			'delete_payment_from_registration_details'
2212
+		);
2213
+		if ($PAY_ID && $can_delete) {
2214
+			$delete_txn_reg_status_change = isset($this->_req_data['delete_txn_reg_status_change'])
2215
+				? $this->_req_data['delete_txn_reg_status_change']
2216
+				: false;
2217
+			$payment = EEM_Payment::instance()->get_one_by_ID($PAY_ID);
2218
+			if ($payment instanceof EE_Payment) {
2219
+				$REG_IDs = $this->_get_existing_reg_payment_REG_IDs($payment);
2220
+				/** @type EE_Transaction_Payments $transaction_payments */
2221
+				$transaction_payments = EE_Registry::instance()->load_class('Transaction_Payments');
2222
+				if ($transaction_payments->delete_payment_and_update_transaction($payment)) {
2223
+					$json_response_data['return_data'] = $this->_build_payment_json_response(
2224
+						$payment,
2225
+						$REG_IDs,
2226
+						$delete_txn_reg_status_change
2227
+					);
2228
+					if ($delete_txn_reg_status_change) {
2229
+						$this->_req_data['txn_reg_status_change'] = $delete_txn_reg_status_change;
2230
+						// MAKE sure we also add the delete_txn_req_status_change to the
2231
+						// $_REQUEST global because that's how messages will be looking for it.
2232
+						$_REQUEST['txn_reg_status_change'] = $delete_txn_reg_status_change;
2233
+						$this->_maybe_send_notifications();
2234
+						$this->_process_registration_status_change($payment->transaction(), $REG_IDs);
2235
+					}
2236
+				}
2237
+			} else {
2238
+				EE_Error::add_error(
2239
+					esc_html__('Valid Payment data could not be retrieved from the database.', 'event_espresso'),
2240
+					__FILE__,
2241
+					__FUNCTION__,
2242
+					__LINE__
2243
+				);
2244
+			}
2245
+		} elseif ($can_delete) {
2246
+			EE_Error::add_error(
2247
+				esc_html__(
2248
+					'A valid Payment ID was not received, therefore payment form data could not be loaded.',
2249
+					'event_espresso'
2250
+				),
2251
+				__FILE__,
2252
+				__FUNCTION__,
2253
+				__LINE__
2254
+			);
2255
+		} else {
2256
+			EE_Error::add_error(
2257
+				esc_html__(
2258
+					'You do not have access to delete a payment.',
2259
+					'event_espresso'
2260
+				),
2261
+				__FILE__,
2262
+				__FUNCTION__,
2263
+				__LINE__
2264
+			);
2265
+		}
2266
+		$notices = EE_Error::get_notices(false, false, false);
2267
+		$this->_template_args = array(
2268
+			'data'      => $json_response_data,
2269
+			'success'   => $notices['success'],
2270
+			'error'     => $notices['errors'],
2271
+			'attention' => $notices['attention'],
2272
+		);
2273
+		$this->_return_json();
2274
+	}
2275
+
2276
+
2277
+	/**
2278
+	 * _registration_payment_data_array
2279
+	 * adds info for 'owing' and 'paid' for each registration to the json response
2280
+	 *
2281
+	 * @access protected
2282
+	 * @param array $REG_IDs
2283
+	 * @return array
2284
+	 * @throws EE_Error
2285
+	 * @throws InvalidArgumentException
2286
+	 * @throws InvalidDataTypeException
2287
+	 * @throws InvalidInterfaceException
2288
+	 * @throws ReflectionException
2289
+	 */
2290
+	protected function _registration_payment_data_array($REG_IDs)
2291
+	{
2292
+		$registration_payment_data = array();
2293
+		// if non empty reg_ids lets get an array of registrations and update the values for the apply_payment/refund rows.
2294
+		if (! empty($REG_IDs)) {
2295
+			$registrations = EEM_Registration::instance()->get_all(array(array('REG_ID' => array('IN', $REG_IDs))));
2296
+			foreach ($registrations as $registration) {
2297
+				if ($registration instanceof EE_Registration) {
2298
+					$registration_payment_data[ $registration->ID() ] = array(
2299
+						'paid'  => $registration->pretty_paid(),
2300
+						'owing' => EEH_Template::format_currency($registration->final_price() - $registration->paid()),
2301
+					);
2302
+				}
2303
+			}
2304
+		}
2305
+
2306
+		return $registration_payment_data;
2307
+	}
2308
+
2309
+
2310
+	/**
2311
+	 * _maybe_send_notifications
2312
+	 * determines whether or not the admin has indicated that notifications should be sent.
2313
+	 * If so, will toggle a filter switch for delivering registration notices.
2314
+	 * If passed an EE_Payment object, then it will trigger payment notifications instead.
2315
+	 *
2316
+	 * @access protected
2317
+	 * @param \EE_Payment | null $payment
2318
+	 */
2319
+	protected function _maybe_send_notifications($payment = null)
2320
+	{
2321
+		switch ($payment instanceof EE_Payment) {
2322
+			// payment notifications
2323
+			case true:
2324
+				if (isset($this->_req_data['txn_payments']['send_notifications'])
2325
+					&& filter_var(
2326
+						$this->_req_data['txn_payments']['send_notifications'],
2327
+						FILTER_VALIDATE_BOOLEAN
2328
+					)
2329
+				) {
2330
+					$this->_process_payment_notification($payment);
2331
+				}
2332
+				break;
2333
+			// registration notifications
2334
+			case false:
2335
+				if (isset($this->_req_data['txn_reg_status_change']['send_notifications'])
2336
+					&& filter_var(
2337
+						$this->_req_data['txn_reg_status_change']['send_notifications'],
2338
+						FILTER_VALIDATE_BOOLEAN
2339
+					)
2340
+				) {
2341
+					add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true');
2342
+				}
2343
+				break;
2344
+		}
2345
+	}
2346
+
2347
+
2348
+	/**
2349
+	 * _send_payment_reminder
2350
+	 *    generates HTML for the View Transaction Details Admin page
2351
+	 *
2352
+	 * @access protected
2353
+	 * @return void
2354
+	 * @throws EE_Error
2355
+	 * @throws InvalidArgumentException
2356
+	 * @throws InvalidDataTypeException
2357
+	 * @throws InvalidInterfaceException
2358
+	 */
2359
+	protected function _send_payment_reminder()
2360
+	{
2361
+		$TXN_ID = ! empty($this->_req_data['TXN_ID']) ? absint($this->_req_data['TXN_ID']) : false;
2362
+		$transaction = EEM_Transaction::instance()->get_one_by_ID($TXN_ID);
2363
+		$query_args = isset($this->_req_data['redirect_to']) ? array(
2364
+			'action' => $this->_req_data['redirect_to'],
2365
+			'TXN_ID' => $this->_req_data['TXN_ID'],
2366
+		) : array();
2367
+		do_action(
2368
+			'AHEE__Transactions_Admin_Page___send_payment_reminder__process_admin_payment_reminder',
2369
+			$transaction
2370
+		);
2371
+		$this->_redirect_after_action(
2372
+			false,
2373
+			esc_html__('payment reminder', 'event_espresso'),
2374
+			esc_html__('sent', 'event_espresso'),
2375
+			$query_args,
2376
+			true
2377
+		);
2378
+	}
2379
+
2380
+
2381
+	/**
2382
+	 *  get_transactions
2383
+	 *    get transactions for given parameters (used by list table)
2384
+	 *
2385
+	 * @param  int     $perpage how many transactions displayed per page
2386
+	 * @param  boolean $count   return the count or objects
2387
+	 * @param string   $view
2388
+	 * @return mixed int = count || array of transaction objects
2389
+	 * @throws EE_Error
2390
+	 * @throws InvalidArgumentException
2391
+	 * @throws InvalidDataTypeException
2392
+	 * @throws InvalidInterfaceException
2393
+	 */
2394
+	public function get_transactions($perpage, $count = false, $view = '')
2395
+	{
2396
+
2397
+		$TXN = EEM_Transaction::instance();
2398
+
2399
+		$start_date = isset($this->_req_data['txn-filter-start-date'])
2400
+			? wp_strip_all_tags($this->_req_data['txn-filter-start-date'])
2401
+			: date(
2402
+				'm/d/Y',
2403
+				strtotime('-10 year')
2404
+			);
2405
+		$end_date = isset($this->_req_data['txn-filter-end-date'])
2406
+			? wp_strip_all_tags($this->_req_data['txn-filter-end-date'])
2407
+			: date('m/d/Y');
2408
+
2409
+		// make sure our timestamps start and end right at the boundaries for each day
2410
+		$start_date = date('Y-m-d', strtotime($start_date)) . ' 00:00:00';
2411
+		$end_date = date('Y-m-d', strtotime($end_date)) . ' 23:59:59';
2412
+
2413
+
2414
+		// convert to timestamps
2415
+		$start_date = strtotime($start_date);
2416
+		$end_date = strtotime($end_date);
2417
+
2418
+		// makes sure start date is the lowest value and vice versa
2419
+		$start_date = min($start_date, $end_date);
2420
+		$end_date = max($start_date, $end_date);
2421
+
2422
+		// convert to correct format for query
2423
+		$start_date = EEM_Transaction::instance()->convert_datetime_for_query(
2424
+			'TXN_timestamp',
2425
+			date('Y-m-d H:i:s', $start_date),
2426
+			'Y-m-d H:i:s'
2427
+		);
2428
+		$end_date = EEM_Transaction::instance()->convert_datetime_for_query(
2429
+			'TXN_timestamp',
2430
+			date('Y-m-d H:i:s', $end_date),
2431
+			'Y-m-d H:i:s'
2432
+		);
2433
+
2434
+
2435
+		// set orderby
2436
+		$this->_req_data['orderby'] = ! empty($this->_req_data['orderby']) ? $this->_req_data['orderby'] : '';
2437
+
2438
+		switch ($this->_req_data['orderby']) {
2439
+			case 'TXN_ID':
2440
+				$orderby = 'TXN_ID';
2441
+				break;
2442
+			case 'ATT_fname':
2443
+				$orderby = 'Registration.Attendee.ATT_fname';
2444
+				break;
2445
+			case 'event_name':
2446
+				$orderby = 'Registration.Event.EVT_name';
2447
+				break;
2448
+			default: // 'TXN_timestamp'
2449
+				$orderby = 'TXN_timestamp';
2450
+		}
2451
+
2452
+		$sort = ! empty($this->_req_data['order']) ? $this->_req_data['order'] : 'DESC';
2453
+		$current_page = ! empty($this->_req_data['paged']) ? $this->_req_data['paged'] : 1;
2454
+		$per_page = ! empty($perpage) ? $perpage : 10;
2455
+		$per_page = ! empty($this->_req_data['perpage']) ? $this->_req_data['perpage'] : $per_page;
2456
+
2457
+		$offset = ($current_page - 1) * $per_page;
2458
+		$limit = array($offset, $per_page);
2459
+
2460
+		$_where = array(
2461
+			'TXN_timestamp'          => array('BETWEEN', array($start_date, $end_date)),
2462
+			'Registration.REG_count' => 1,
2463
+		);
2464
+
2465
+		if (isset($this->_req_data['EVT_ID'])) {
2466
+			$_where['Registration.EVT_ID'] = $this->_req_data['EVT_ID'];
2467
+		}
2468
+
2469
+		if (isset($this->_req_data['s'])) {
2470
+			$search_string = '%' . $this->_req_data['s'] . '%';
2471
+			$_where['OR'] = array(
2472
+				'Registration.Event.EVT_name'         => array('LIKE', $search_string),
2473
+				'Registration.Event.EVT_desc'         => array('LIKE', $search_string),
2474
+				'Registration.Event.EVT_short_desc'   => array('LIKE', $search_string),
2475
+				'Registration.Attendee.ATT_full_name' => array('LIKE', $search_string),
2476
+				'Registration.Attendee.ATT_fname'     => array('LIKE', $search_string),
2477
+				'Registration.Attendee.ATT_lname'     => array('LIKE', $search_string),
2478
+				'Registration.Attendee.ATT_short_bio' => array('LIKE', $search_string),
2479
+				'Registration.Attendee.ATT_email'     => array('LIKE', $search_string),
2480
+				'Registration.Attendee.ATT_address'   => array('LIKE', $search_string),
2481
+				'Registration.Attendee.ATT_address2'  => array('LIKE', $search_string),
2482
+				'Registration.Attendee.ATT_city'      => array('LIKE', $search_string),
2483
+				'Registration.REG_final_price'        => array('LIKE', $search_string),
2484
+				'Registration.REG_code'               => array('LIKE', $search_string),
2485
+				'Registration.REG_count'              => array('LIKE', $search_string),
2486
+				'Registration.REG_group_size'         => array('LIKE', $search_string),
2487
+				'Registration.Ticket.TKT_name'        => array('LIKE', $search_string),
2488
+				'Registration.Ticket.TKT_description' => array('LIKE', $search_string),
2489
+				'Payment.PAY_source'                  => array('LIKE', $search_string),
2490
+				'Payment.Payment_Method.PMD_name'     => array('LIKE', $search_string),
2491
+				'TXN_session_data'                    => array('LIKE', $search_string),
2492
+				'Payment.PAY_txn_id_chq_nmbr'         => array('LIKE', $search_string),
2493
+			);
2494
+		}
2495
+
2496
+		// failed transactions
2497
+		$failed = (! empty($this->_req_data['status']) && $this->_req_data['status'] === 'failed' && ! $count)
2498
+				  || ($count && $view === 'failed');
2499
+		$abandoned = (! empty($this->_req_data['status']) && $this->_req_data['status'] === 'abandoned' && ! $count)
2500
+					 || ($count && $view === 'abandoned');
2501
+		$incomplete = (! empty($this->_req_data['status']) && $this->_req_data['status'] === 'incomplete' && ! $count)
2502
+					  || ($count && $view === 'incomplete');
2503
+
2504
+		if ($failed) {
2505
+			$_where['STS_ID'] = EEM_Transaction::failed_status_code;
2506
+		} elseif ($abandoned) {
2507
+			$_where['STS_ID'] = EEM_Transaction::abandoned_status_code;
2508
+		} elseif ($incomplete) {
2509
+			$_where['STS_ID'] = EEM_Transaction::incomplete_status_code;
2510
+		} else {
2511
+			$_where['STS_ID'] = array('!=', EEM_Transaction::failed_status_code);
2512
+			$_where['STS_ID*'] = array('!=', EEM_Transaction::abandoned_status_code);
2513
+		}
2514
+
2515
+		$query_params = apply_filters(
2516
+			'FHEE__Transactions_Admin_Page___get_transactions_query_params',
2517
+			array(
2518
+				$_where,
2519
+				'order_by'                 => array($orderby => $sort),
2520
+				'limit'                    => $limit,
2521
+				'default_where_conditions' => EEM_Base::default_where_conditions_this_only,
2522
+			),
2523
+			$this->_req_data,
2524
+			$view,
2525
+			$count
2526
+		);
2527
+
2528
+		$transactions = $count
2529
+			? $TXN->count(array($query_params[0]), 'TXN_ID', true)
2530
+			: $TXN->get_all($query_params);
2531
+
2532
+		return $transactions;
2533
+	}
2534
+
2535
+
2536
+	/**
2537
+	 * @since 4.9.79.p
2538
+	 * @throws EE_Error
2539
+	 * @throws InvalidArgumentException
2540
+	 * @throws InvalidDataTypeException
2541
+	 * @throws InvalidInterfaceException
2542
+	 * @throws ReflectionException
2543
+	 * @throws RuntimeException
2544
+	 */
2545
+	public function recalculateLineItems()
2546
+	{
2547
+		$TXN_ID = ! empty($this->_req_data['TXN_ID']) ? absint($this->_req_data['TXN_ID']) : false;
2548
+		/** @var EE_Transaction $transaction */
2549
+		$transaction = EEM_Transaction::instance()->get_one_by_ID($TXN_ID);
2550
+		$total_line_item = $transaction->total_line_item(false);
2551
+		$success = $transaction->recalculateLineItems();
2552
+		$this->_redirect_after_action(
2553
+			(bool) $success,
2554
+			esc_html__('Transaction taxes and totals', 'event_espresso'),
2555
+			esc_html__('recalculated', 'event_espresso'),
2556
+			isset($this->_req_data['redirect_to'])
2557
+				? array(
2558
+				'action' => $this->_req_data['redirect_to'],
2559
+				'TXN_ID' => $this->_req_data['TXN_ID'],
2560
+			)
2561
+				: array(),
2562
+			true
2563
+		);
2564
+	}
2565 2565
 }
Please login to merge, or discard this patch.
admin_pages/registrations/EE_Registrations_List_Table.class.php 1 patch
Indentation   +965 added lines, -965 removed lines patch added patch discarded remove patch
@@ -24,1046 +24,1046 @@
 block discarded – undo
24 24
 {
25 25
 
26 26
 
27
-    /**
28
-     * @var array
29
-     */
30
-    private $_status;
27
+	/**
28
+	 * @var array
29
+	 */
30
+	private $_status;
31 31
 
32 32
 
33
-    /**
34
-     * An array of transaction details for the related transaction to the registration being processed.
35
-     * This is set via the _set_related_details method.
36
-     *
37
-     * @var array
38
-     */
39
-    protected $_transaction_details = array();
33
+	/**
34
+	 * An array of transaction details for the related transaction to the registration being processed.
35
+	 * This is set via the _set_related_details method.
36
+	 *
37
+	 * @var array
38
+	 */
39
+	protected $_transaction_details = array();
40 40
 
41 41
 
42
-    /**
43
-     * An array of event details for the related event to the registration being processed.
44
-     * This is set via the _set_related_details method.
45
-     *
46
-     * @var array
47
-     */
48
-    protected $_event_details = array();
42
+	/**
43
+	 * An array of event details for the related event to the registration being processed.
44
+	 * This is set via the _set_related_details method.
45
+	 *
46
+	 * @var array
47
+	 */
48
+	protected $_event_details = array();
49 49
 
50 50
 
51
-    /**
52
-     * @param \Registrations_Admin_Page $admin_page
53
-     */
54
-    public function __construct(Registrations_Admin_Page $admin_page)
55
-    {
56
-        if (! empty($_GET['event_id'])) {
57
-            $extra_query_args = array();
58
-            foreach ($admin_page->get_views() as $key => $view_details) {
59
-                $extra_query_args[ $view_details['slug'] ] = array('event_id' => $_GET['event_id']);
60
-            }
61
-            $this->_views = $admin_page->get_list_table_view_RLs($extra_query_args);
62
-        }
63
-        parent::__construct($admin_page);
64
-        $this->_status = $this->_admin_page->get_registration_status_array();
65
-    }
51
+	/**
52
+	 * @param \Registrations_Admin_Page $admin_page
53
+	 */
54
+	public function __construct(Registrations_Admin_Page $admin_page)
55
+	{
56
+		if (! empty($_GET['event_id'])) {
57
+			$extra_query_args = array();
58
+			foreach ($admin_page->get_views() as $key => $view_details) {
59
+				$extra_query_args[ $view_details['slug'] ] = array('event_id' => $_GET['event_id']);
60
+			}
61
+			$this->_views = $admin_page->get_list_table_view_RLs($extra_query_args);
62
+		}
63
+		parent::__construct($admin_page);
64
+		$this->_status = $this->_admin_page->get_registration_status_array();
65
+	}
66 66
 
67 67
 
68
-    /**
69
-     *    _setup_data
70
-     *
71
-     * @access protected
72
-     * @return void
73
-     */
74
-    protected function _setup_data()
75
-    {
76
-        $this->_data = $this->_admin_page->get_registrations($this->_per_page);
77
-        $this->_all_data_count = $this->_admin_page->get_registrations($this->_per_page, true, false, false);
78
-    }
68
+	/**
69
+	 *    _setup_data
70
+	 *
71
+	 * @access protected
72
+	 * @return void
73
+	 */
74
+	protected function _setup_data()
75
+	{
76
+		$this->_data = $this->_admin_page->get_registrations($this->_per_page);
77
+		$this->_all_data_count = $this->_admin_page->get_registrations($this->_per_page, true, false, false);
78
+	}
79 79
 
80 80
 
81
-    /**
82
-     *    _set_properties
83
-     *
84
-     * @access protected
85
-     * @return void
86
-     */
87
-    protected function _set_properties()
88
-    {
89
-        $this->_wp_list_args = array(
90
-            'singular' => __('registration', 'event_espresso'),
91
-            'plural'   => __('registrations', 'event_espresso'),
92
-            'ajax'     => true,
93
-            'screen'   => $this->_admin_page->get_current_screen()->id,
94
-        );
95
-        $ID_column_name = __('ID', 'event_espresso');
96
-        $ID_column_name .= ' : <span class="show-on-mobile-view-only" style="float:none">';
97
-        $ID_column_name .= __('Registrant Name', 'event_espresso');
98
-        $ID_column_name .= '</span> ';
99
-        if (isset($_GET['event_id'])) {
100
-            $this->_columns = array(
101
-                'cb'               => '<input type="checkbox" />', // Render a checkbox instead of text
102
-                '_REG_ID'          => $ID_column_name,
103
-                'ATT_fname'        => __('Name', 'event_espresso'),
104
-                'ATT_email'        => __('Email', 'event_espresso'),
105
-                '_REG_date'        => __('Reg Date', 'event_espresso'),
106
-                'PRC_amount'       => __('TKT Price', 'event_espresso'),
107
-                '_REG_final_price' => __('Final Price', 'event_espresso'),
108
-                'TXN_total'        => __('Total Txn', 'event_espresso'),
109
-                'TXN_paid'         => __('Paid', 'event_espresso'),
110
-                'actions'          => __('Actions', 'event_espresso'),
111
-            );
112
-            $this->_bottom_buttons = array(
113
-                'report' => array(
114
-                    'route'         => 'registrations_report',
115
-                    'extra_request' => array(
116
-                        'EVT_ID'     => isset($this->_req_data['event_id']) ? $this->_req_data['event_id'] : null,
117
-                        'return_url' => urlencode("//{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}"),
118
-                    ),
119
-                ),
120
-            );
121
-        } else {
122
-            $this->_columns = array(
123
-                'cb'               => '<input type="checkbox" />', // Render a checkbox instead of text
124
-                '_REG_ID'          => $ID_column_name,
125
-                'ATT_fname'        => __('Name', 'event_espresso'),
126
-                '_REG_date'        => __('TXN Date', 'event_espresso'),
127
-                'event_name'       => __('Event', 'event_espresso'),
128
-                'DTT_EVT_start'    => __('Event Date', 'event_espresso'),
129
-                '_REG_final_price' => __('Price', 'event_espresso'),
130
-                '_REG_paid'        => __('Paid', 'event_espresso'),
131
-                'actions'          => __('Actions', 'event_espresso'),
132
-            );
133
-            $this->_bottom_buttons = array(
134
-                'report_all' => array(
135
-                    'route'         => 'registrations_report',
136
-                    'extra_request' => array(
137
-                        'return_url' => urlencode("//{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}"),
138
-                    ),
139
-                ),
140
-            );
141
-        }
142
-        $this->_bottom_buttons['report_filtered'] = array(
143
-            'route'         => 'registrations_report',
144
-            'extra_request' => array(
145
-                'use_filters' => true,
146
-                'return_url'  => urlencode("//{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}"),
147
-            ),
148
-        );
149
-        $filters = array_diff_key(
150
-            $this->_req_data,
151
-            array_flip(
152
-                array(
153
-                    'page',
154
-                    'action',
155
-                    'default_nonce',
156
-                )
157
-            )
158
-        );
159
-        if (!empty($filters)) {
160
-            $this->_bottom_buttons['report_filtered']['extra_request']['filters'] = $filters;
161
-        }
162
-        $this->_primary_column = '_REG_ID';
163
-        $this->_sortable_columns = array(
164
-            '_REG_date'     => array('_REG_date' => true),   // true means its already sorted
165
-            /**
166
-             * Allows users to change the default sort if they wish.
167
-             * Returning a falsey on this filter will result in the default sort to be by firstname rather than last
168
-             * name.
169
-             */
170
-            'ATT_fname'     => array(
171
-                'FHEE__EE_Registrations_List_Table___set_properties__default_sort_by_registration_last_name',
172
-                true,
173
-                $this,
174
-            )
175
-                ? array('ATT_lname' => false)
176
-                : array('ATT_fname' => false),
177
-            'event_name'    => array('event_name' => false),
178
-            'DTT_EVT_start' => array('DTT_EVT_start' => false),
179
-            '_REG_ID'       => array('_REG_ID' => false),
180
-        );
181
-        $this->_hidden_columns = array();
182
-    }
81
+	/**
82
+	 *    _set_properties
83
+	 *
84
+	 * @access protected
85
+	 * @return void
86
+	 */
87
+	protected function _set_properties()
88
+	{
89
+		$this->_wp_list_args = array(
90
+			'singular' => __('registration', 'event_espresso'),
91
+			'plural'   => __('registrations', 'event_espresso'),
92
+			'ajax'     => true,
93
+			'screen'   => $this->_admin_page->get_current_screen()->id,
94
+		);
95
+		$ID_column_name = __('ID', 'event_espresso');
96
+		$ID_column_name .= ' : <span class="show-on-mobile-view-only" style="float:none">';
97
+		$ID_column_name .= __('Registrant Name', 'event_espresso');
98
+		$ID_column_name .= '</span> ';
99
+		if (isset($_GET['event_id'])) {
100
+			$this->_columns = array(
101
+				'cb'               => '<input type="checkbox" />', // Render a checkbox instead of text
102
+				'_REG_ID'          => $ID_column_name,
103
+				'ATT_fname'        => __('Name', 'event_espresso'),
104
+				'ATT_email'        => __('Email', 'event_espresso'),
105
+				'_REG_date'        => __('Reg Date', 'event_espresso'),
106
+				'PRC_amount'       => __('TKT Price', 'event_espresso'),
107
+				'_REG_final_price' => __('Final Price', 'event_espresso'),
108
+				'TXN_total'        => __('Total Txn', 'event_espresso'),
109
+				'TXN_paid'         => __('Paid', 'event_espresso'),
110
+				'actions'          => __('Actions', 'event_espresso'),
111
+			);
112
+			$this->_bottom_buttons = array(
113
+				'report' => array(
114
+					'route'         => 'registrations_report',
115
+					'extra_request' => array(
116
+						'EVT_ID'     => isset($this->_req_data['event_id']) ? $this->_req_data['event_id'] : null,
117
+						'return_url' => urlencode("//{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}"),
118
+					),
119
+				),
120
+			);
121
+		} else {
122
+			$this->_columns = array(
123
+				'cb'               => '<input type="checkbox" />', // Render a checkbox instead of text
124
+				'_REG_ID'          => $ID_column_name,
125
+				'ATT_fname'        => __('Name', 'event_espresso'),
126
+				'_REG_date'        => __('TXN Date', 'event_espresso'),
127
+				'event_name'       => __('Event', 'event_espresso'),
128
+				'DTT_EVT_start'    => __('Event Date', 'event_espresso'),
129
+				'_REG_final_price' => __('Price', 'event_espresso'),
130
+				'_REG_paid'        => __('Paid', 'event_espresso'),
131
+				'actions'          => __('Actions', 'event_espresso'),
132
+			);
133
+			$this->_bottom_buttons = array(
134
+				'report_all' => array(
135
+					'route'         => 'registrations_report',
136
+					'extra_request' => array(
137
+						'return_url' => urlencode("//{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}"),
138
+					),
139
+				),
140
+			);
141
+		}
142
+		$this->_bottom_buttons['report_filtered'] = array(
143
+			'route'         => 'registrations_report',
144
+			'extra_request' => array(
145
+				'use_filters' => true,
146
+				'return_url'  => urlencode("//{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}"),
147
+			),
148
+		);
149
+		$filters = array_diff_key(
150
+			$this->_req_data,
151
+			array_flip(
152
+				array(
153
+					'page',
154
+					'action',
155
+					'default_nonce',
156
+				)
157
+			)
158
+		);
159
+		if (!empty($filters)) {
160
+			$this->_bottom_buttons['report_filtered']['extra_request']['filters'] = $filters;
161
+		}
162
+		$this->_primary_column = '_REG_ID';
163
+		$this->_sortable_columns = array(
164
+			'_REG_date'     => array('_REG_date' => true),   // true means its already sorted
165
+			/**
166
+			 * Allows users to change the default sort if they wish.
167
+			 * Returning a falsey on this filter will result in the default sort to be by firstname rather than last
168
+			 * name.
169
+			 */
170
+			'ATT_fname'     => array(
171
+				'FHEE__EE_Registrations_List_Table___set_properties__default_sort_by_registration_last_name',
172
+				true,
173
+				$this,
174
+			)
175
+				? array('ATT_lname' => false)
176
+				: array('ATT_fname' => false),
177
+			'event_name'    => array('event_name' => false),
178
+			'DTT_EVT_start' => array('DTT_EVT_start' => false),
179
+			'_REG_ID'       => array('_REG_ID' => false),
180
+		);
181
+		$this->_hidden_columns = array();
182
+	}
183 183
 
184 184
 
185
-    /**
186
-     * This simply sets up the row class for the table rows.
187
-     * Allows for easier overriding of child methods for setting up sorting.
188
-     *
189
-     * @param  EE_Registration $item the current item
190
-     * @return string
191
-     */
192
-    protected function _get_row_class($item)
193
-    {
194
-        $class = parent::_get_row_class($item);
195
-        // add status class
196
-        $class .= ' ee-status-strip reg-status-' . $item->status_ID();
197
-        if ($this->_has_checkbox_column) {
198
-            $class .= ' has-checkbox-column';
199
-        }
200
-        return $class;
201
-    }
185
+	/**
186
+	 * This simply sets up the row class for the table rows.
187
+	 * Allows for easier overriding of child methods for setting up sorting.
188
+	 *
189
+	 * @param  EE_Registration $item the current item
190
+	 * @return string
191
+	 */
192
+	protected function _get_row_class($item)
193
+	{
194
+		$class = parent::_get_row_class($item);
195
+		// add status class
196
+		$class .= ' ee-status-strip reg-status-' . $item->status_ID();
197
+		if ($this->_has_checkbox_column) {
198
+			$class .= ' has-checkbox-column';
199
+		}
200
+		return $class;
201
+	}
202 202
 
203 203
 
204
-    /**
205
-     * Set the $_transaction_details property if not set yet.
206
-     *
207
-     * @param EE_Registration $registration
208
-     * @throws EE_Error
209
-     * @throws InvalidArgumentException
210
-     * @throws ReflectionException
211
-     * @throws InvalidDataTypeException
212
-     * @throws InvalidInterfaceException
213
-     */
214
-    protected function _set_related_details(EE_Registration $registration)
215
-    {
216
-        $transaction = $registration->get_first_related('Transaction');
217
-        $status = $transaction instanceof EE_Transaction ? $transaction->status_ID()
218
-            : EEM_Transaction::failed_status_code;
219
-        $this->_transaction_details = array(
220
-            'transaction' => $transaction,
221
-            'status'      => $status,
222
-            'id'          => $transaction instanceof EE_Transaction ? $transaction->ID() : 0,
223
-            'title_attr'  => sprintf(
224
-                __('View Transaction Details (%s)', 'event_espresso'),
225
-                EEH_Template::pretty_status($status, false, 'sentence')
226
-            ),
227
-        );
228
-        try {
229
-            $event = $registration->event();
230
-        } catch (EntityNotFoundException $e) {
231
-            $event = null;
232
-        }
233
-        $status = $event instanceof EE_Event ? $event->get_active_status() : EE_Datetime::inactive;
234
-        $this->_event_details = array(
235
-            'event'      => $event,
236
-            'status'     => $status,
237
-            'id'         => $event instanceof EE_Event ? $event->ID() : 0,
238
-            'title_attr' => sprintf(
239
-                __('Edit Event (%s)', 'event_espresso'),
240
-                EEH_Template::pretty_status($status, false, 'sentence')
241
-            ),
242
-        );
243
-    }
204
+	/**
205
+	 * Set the $_transaction_details property if not set yet.
206
+	 *
207
+	 * @param EE_Registration $registration
208
+	 * @throws EE_Error
209
+	 * @throws InvalidArgumentException
210
+	 * @throws ReflectionException
211
+	 * @throws InvalidDataTypeException
212
+	 * @throws InvalidInterfaceException
213
+	 */
214
+	protected function _set_related_details(EE_Registration $registration)
215
+	{
216
+		$transaction = $registration->get_first_related('Transaction');
217
+		$status = $transaction instanceof EE_Transaction ? $transaction->status_ID()
218
+			: EEM_Transaction::failed_status_code;
219
+		$this->_transaction_details = array(
220
+			'transaction' => $transaction,
221
+			'status'      => $status,
222
+			'id'          => $transaction instanceof EE_Transaction ? $transaction->ID() : 0,
223
+			'title_attr'  => sprintf(
224
+				__('View Transaction Details (%s)', 'event_espresso'),
225
+				EEH_Template::pretty_status($status, false, 'sentence')
226
+			),
227
+		);
228
+		try {
229
+			$event = $registration->event();
230
+		} catch (EntityNotFoundException $e) {
231
+			$event = null;
232
+		}
233
+		$status = $event instanceof EE_Event ? $event->get_active_status() : EE_Datetime::inactive;
234
+		$this->_event_details = array(
235
+			'event'      => $event,
236
+			'status'     => $status,
237
+			'id'         => $event instanceof EE_Event ? $event->ID() : 0,
238
+			'title_attr' => sprintf(
239
+				__('Edit Event (%s)', 'event_espresso'),
240
+				EEH_Template::pretty_status($status, false, 'sentence')
241
+			),
242
+		);
243
+	}
244 244
 
245 245
 
246
-    /**
247
-     *    _get_table_filters
248
-     *
249
-     * @access protected
250
-     * @return array
251
-     */
252
-    protected function _get_table_filters()
253
-    {
254
-        $filters = array();
255
-        // todo we're currently using old functions here. We need to move things into the Events_Admin_Page() class as
256
-        // methods.
257
-        $cur_date = isset($this->_req_data['month_range']) ? $this->_req_data['month_range'] : '';
258
-        $cur_category = isset($this->_req_data['EVT_CAT']) ? $this->_req_data['EVT_CAT'] : -1;
259
-        $reg_status = isset($this->_req_data['_reg_status']) ? $this->_req_data['_reg_status'] : '';
260
-        $filters[] = EEH_Form_Fields::generate_registration_months_dropdown($cur_date, $reg_status, $cur_category);
261
-        $filters[] = EEH_Form_Fields::generate_event_category_dropdown($cur_category);
262
-        $status = array();
263
-        $status[] = array('id' => 0, 'text' => __('Select Status', 'event_espresso'));
264
-        foreach ($this->_status as $key => $value) {
265
-            $status[] = array('id' => $key, 'text' => $value);
266
-        }
267
-        if ($this->_view !== 'incomplete') {
268
-            $filters[] = EEH_Form_Fields::select_input(
269
-                '_reg_status',
270
-                $status,
271
-                isset($this->_req_data['_reg_status']) ? strtoupper(sanitize_key($this->_req_data['_reg_status']))
272
-                    : ''
273
-            );
274
-        }
275
-        if (isset($this->_req_data['event_id'])) {
276
-            $filters[] = EEH_Form_Fields::hidden_input('event_id', $this->_req_data['event_id'], 'reg_event_id');
277
-        }
278
-        return $filters;
279
-    }
246
+	/**
247
+	 *    _get_table_filters
248
+	 *
249
+	 * @access protected
250
+	 * @return array
251
+	 */
252
+	protected function _get_table_filters()
253
+	{
254
+		$filters = array();
255
+		// todo we're currently using old functions here. We need to move things into the Events_Admin_Page() class as
256
+		// methods.
257
+		$cur_date = isset($this->_req_data['month_range']) ? $this->_req_data['month_range'] : '';
258
+		$cur_category = isset($this->_req_data['EVT_CAT']) ? $this->_req_data['EVT_CAT'] : -1;
259
+		$reg_status = isset($this->_req_data['_reg_status']) ? $this->_req_data['_reg_status'] : '';
260
+		$filters[] = EEH_Form_Fields::generate_registration_months_dropdown($cur_date, $reg_status, $cur_category);
261
+		$filters[] = EEH_Form_Fields::generate_event_category_dropdown($cur_category);
262
+		$status = array();
263
+		$status[] = array('id' => 0, 'text' => __('Select Status', 'event_espresso'));
264
+		foreach ($this->_status as $key => $value) {
265
+			$status[] = array('id' => $key, 'text' => $value);
266
+		}
267
+		if ($this->_view !== 'incomplete') {
268
+			$filters[] = EEH_Form_Fields::select_input(
269
+				'_reg_status',
270
+				$status,
271
+				isset($this->_req_data['_reg_status']) ? strtoupper(sanitize_key($this->_req_data['_reg_status']))
272
+					: ''
273
+			);
274
+		}
275
+		if (isset($this->_req_data['event_id'])) {
276
+			$filters[] = EEH_Form_Fields::hidden_input('event_id', $this->_req_data['event_id'], 'reg_event_id');
277
+		}
278
+		return $filters;
279
+	}
280 280
 
281 281
 
282
-    /**
283
-     *    _add_view_counts
284
-     *
285
-     * @access protected
286
-     * @return void
287
-     * @throws EE_Error
288
-     * @throws InvalidArgumentException
289
-     * @throws InvalidDataTypeException
290
-     * @throws InvalidInterfaceException
291
-     */
292
-    protected function _add_view_counts()
293
-    {
294
-        $this->_views['all']['count'] = $this->_total_registrations();
295
-        $this->_views['month']['count'] = $this->_total_registrations_this_month();
296
-        $this->_views['today']['count'] = $this->_total_registrations_today();
297
-        if (EE_Registry::instance()->CAP->current_user_can(
298
-            'ee_delete_registrations',
299
-            'espresso_registrations_trash_registrations'
300
-        )) {
301
-            $this->_views['incomplete']['count'] = $this->_total_registrations('incomplete');
302
-            $this->_views['trash']['count'] = $this->_total_registrations('trash');
303
-        }
304
-    }
282
+	/**
283
+	 *    _add_view_counts
284
+	 *
285
+	 * @access protected
286
+	 * @return void
287
+	 * @throws EE_Error
288
+	 * @throws InvalidArgumentException
289
+	 * @throws InvalidDataTypeException
290
+	 * @throws InvalidInterfaceException
291
+	 */
292
+	protected function _add_view_counts()
293
+	{
294
+		$this->_views['all']['count'] = $this->_total_registrations();
295
+		$this->_views['month']['count'] = $this->_total_registrations_this_month();
296
+		$this->_views['today']['count'] = $this->_total_registrations_today();
297
+		if (EE_Registry::instance()->CAP->current_user_can(
298
+			'ee_delete_registrations',
299
+			'espresso_registrations_trash_registrations'
300
+		)) {
301
+			$this->_views['incomplete']['count'] = $this->_total_registrations('incomplete');
302
+			$this->_views['trash']['count'] = $this->_total_registrations('trash');
303
+		}
304
+	}
305 305
 
306 306
 
307
-    /**
308
-     * _total_registrations
309
-     *
310
-     * @access protected
311
-     * @param string $view
312
-     * @return int
313
-     * @throws EE_Error
314
-     * @throws InvalidArgumentException
315
-     * @throws InvalidDataTypeException
316
-     * @throws InvalidInterfaceException
317
-     */
318
-    protected function _total_registrations($view = '')
319
-    {
320
-        $_where = array();
321
-        $EVT_ID = isset($this->_req_data['event_id']) ? absint($this->_req_data['event_id']) : false;
322
-        if ($EVT_ID) {
323
-            $_where['EVT_ID'] = $EVT_ID;
324
-        }
325
-        switch ($view) {
326
-            case 'trash':
327
-                return EEM_Registration::instance()->count_deleted(array($_where));
328
-                break;
329
-            case 'incomplete':
330
-                $_where['STS_ID'] = EEM_Registration::status_id_incomplete;
331
-                break;
332
-            default:
333
-                $_where['STS_ID'] = array('!=', EEM_Registration::status_id_incomplete);
334
-        }
335
-        return EEM_Registration::instance()->count(array($_where));
336
-    }
307
+	/**
308
+	 * _total_registrations
309
+	 *
310
+	 * @access protected
311
+	 * @param string $view
312
+	 * @return int
313
+	 * @throws EE_Error
314
+	 * @throws InvalidArgumentException
315
+	 * @throws InvalidDataTypeException
316
+	 * @throws InvalidInterfaceException
317
+	 */
318
+	protected function _total_registrations($view = '')
319
+	{
320
+		$_where = array();
321
+		$EVT_ID = isset($this->_req_data['event_id']) ? absint($this->_req_data['event_id']) : false;
322
+		if ($EVT_ID) {
323
+			$_where['EVT_ID'] = $EVT_ID;
324
+		}
325
+		switch ($view) {
326
+			case 'trash':
327
+				return EEM_Registration::instance()->count_deleted(array($_where));
328
+				break;
329
+			case 'incomplete':
330
+				$_where['STS_ID'] = EEM_Registration::status_id_incomplete;
331
+				break;
332
+			default:
333
+				$_where['STS_ID'] = array('!=', EEM_Registration::status_id_incomplete);
334
+		}
335
+		return EEM_Registration::instance()->count(array($_where));
336
+	}
337 337
 
338 338
 
339
-    /**
340
-     * _total_registrations_this_month
341
-     *
342
-     * @access protected
343
-     * @return int
344
-     * @throws EE_Error
345
-     * @throws InvalidArgumentException
346
-     * @throws InvalidDataTypeException
347
-     * @throws InvalidInterfaceException
348
-     */
349
-    protected function _total_registrations_this_month()
350
-    {
351
-        $EVT_ID = isset($this->_req_data['event_id']) ? absint($this->_req_data['event_id']) : false;
352
-        $_where = $EVT_ID ? array('EVT_ID' => $EVT_ID) : array();
353
-        $this_year_r = date('Y', current_time('timestamp'));
354
-        $time_start = ' 00:00:00';
355
-        $time_end = ' 23:59:59';
356
-        $this_month_r = date('m', current_time('timestamp'));
357
-        $days_this_month = date('t', current_time('timestamp'));
358
-        // setup date query.
359
-        $beginning_string = EEM_Registration::instance()->convert_datetime_for_query(
360
-            'REG_date',
361
-            $this_year_r . '-' . $this_month_r . '-01' . ' ' . $time_start,
362
-            'Y-m-d H:i:s'
363
-        );
364
-        $end_string = EEM_Registration::instance()->convert_datetime_for_query(
365
-            'REG_date',
366
-            $this_year_r . '-' . $this_month_r . '-' . $days_this_month . ' ' . $time_end,
367
-            'Y-m-d H:i:s'
368
-        );
369
-        $_where['REG_date'] = array(
370
-            'BETWEEN',
371
-            array(
372
-                $beginning_string,
373
-                $end_string,
374
-            ),
375
-        );
376
-        $_where['STS_ID'] = array('!=', EEM_Registration::status_id_incomplete);
377
-        return EEM_Registration::instance()->count(array($_where));
378
-    }
339
+	/**
340
+	 * _total_registrations_this_month
341
+	 *
342
+	 * @access protected
343
+	 * @return int
344
+	 * @throws EE_Error
345
+	 * @throws InvalidArgumentException
346
+	 * @throws InvalidDataTypeException
347
+	 * @throws InvalidInterfaceException
348
+	 */
349
+	protected function _total_registrations_this_month()
350
+	{
351
+		$EVT_ID = isset($this->_req_data['event_id']) ? absint($this->_req_data['event_id']) : false;
352
+		$_where = $EVT_ID ? array('EVT_ID' => $EVT_ID) : array();
353
+		$this_year_r = date('Y', current_time('timestamp'));
354
+		$time_start = ' 00:00:00';
355
+		$time_end = ' 23:59:59';
356
+		$this_month_r = date('m', current_time('timestamp'));
357
+		$days_this_month = date('t', current_time('timestamp'));
358
+		// setup date query.
359
+		$beginning_string = EEM_Registration::instance()->convert_datetime_for_query(
360
+			'REG_date',
361
+			$this_year_r . '-' . $this_month_r . '-01' . ' ' . $time_start,
362
+			'Y-m-d H:i:s'
363
+		);
364
+		$end_string = EEM_Registration::instance()->convert_datetime_for_query(
365
+			'REG_date',
366
+			$this_year_r . '-' . $this_month_r . '-' . $days_this_month . ' ' . $time_end,
367
+			'Y-m-d H:i:s'
368
+		);
369
+		$_where['REG_date'] = array(
370
+			'BETWEEN',
371
+			array(
372
+				$beginning_string,
373
+				$end_string,
374
+			),
375
+		);
376
+		$_where['STS_ID'] = array('!=', EEM_Registration::status_id_incomplete);
377
+		return EEM_Registration::instance()->count(array($_where));
378
+	}
379 379
 
380 380
 
381
-    /**
382
-     * _total_registrations_today
383
-     *
384
-     * @access protected
385
-     * @return int
386
-     * @throws EE_Error
387
-     * @throws InvalidArgumentException
388
-     * @throws InvalidDataTypeException
389
-     * @throws InvalidInterfaceException
390
-     */
391
-    protected function _total_registrations_today()
392
-    {
393
-        $EVT_ID = isset($this->_req_data['event_id']) ? absint($this->_req_data['event_id']) : false;
394
-        $_where = $EVT_ID ? array('EVT_ID' => $EVT_ID) : array();
395
-        $current_date = date('Y-m-d', current_time('timestamp'));
396
-        $time_start = ' 00:00:00';
397
-        $time_end = ' 23:59:59';
398
-        $_where['REG_date'] = array(
399
-            'BETWEEN',
400
-            array(
401
-                EEM_Registration::instance()->convert_datetime_for_query(
402
-                    'REG_date',
403
-                    $current_date . $time_start,
404
-                    'Y-m-d H:i:s'
405
-                ),
406
-                EEM_Registration::instance()->convert_datetime_for_query(
407
-                    'REG_date',
408
-                    $current_date . $time_end,
409
-                    'Y-m-d H:i:s'
410
-                ),
411
-            ),
412
-        );
413
-        $_where['STS_ID'] = array('!=', EEM_Registration::status_id_incomplete);
414
-        return EEM_Registration::instance()->count(array($_where));
415
-    }
381
+	/**
382
+	 * _total_registrations_today
383
+	 *
384
+	 * @access protected
385
+	 * @return int
386
+	 * @throws EE_Error
387
+	 * @throws InvalidArgumentException
388
+	 * @throws InvalidDataTypeException
389
+	 * @throws InvalidInterfaceException
390
+	 */
391
+	protected function _total_registrations_today()
392
+	{
393
+		$EVT_ID = isset($this->_req_data['event_id']) ? absint($this->_req_data['event_id']) : false;
394
+		$_where = $EVT_ID ? array('EVT_ID' => $EVT_ID) : array();
395
+		$current_date = date('Y-m-d', current_time('timestamp'));
396
+		$time_start = ' 00:00:00';
397
+		$time_end = ' 23:59:59';
398
+		$_where['REG_date'] = array(
399
+			'BETWEEN',
400
+			array(
401
+				EEM_Registration::instance()->convert_datetime_for_query(
402
+					'REG_date',
403
+					$current_date . $time_start,
404
+					'Y-m-d H:i:s'
405
+				),
406
+				EEM_Registration::instance()->convert_datetime_for_query(
407
+					'REG_date',
408
+					$current_date . $time_end,
409
+					'Y-m-d H:i:s'
410
+				),
411
+			),
412
+		);
413
+		$_where['STS_ID'] = array('!=', EEM_Registration::status_id_incomplete);
414
+		return EEM_Registration::instance()->count(array($_where));
415
+	}
416 416
 
417 417
 
418
-    /**
419
-     * column_cb
420
-     *
421
-     * @access public
422
-     * @param \EE_Registration $item
423
-     * @return string
424
-     * @throws EE_Error
425
-     * @throws InvalidArgumentException
426
-     * @throws InvalidDataTypeException
427
-     * @throws InvalidInterfaceException
428
-     * @throws ReflectionException
429
-     */
430
-    public function column_cb($item)
431
-    {
432
-        /** checkbox/lock **/
433
-        $transaction = $item->get_first_related('Transaction');
434
-        $payment_count = $transaction instanceof EE_Transaction
435
-            ? $transaction->count_related('Payment')
436
-            : 0;
437
-        return $payment_count > 0
438
-               || ! EE_Registry::instance()->CAP->current_user_can(
439
-                   'ee_edit_registration',
440
-                   'registration_list_table_checkbox_input',
441
-                   $item->ID()
442
-               )
443
-            ? sprintf('<input type="checkbox" name="_REG_ID[]" value="%1$d" />', $item->ID())
444
-              . '<span class="ee-lock-icon"></span>'
445
-            : sprintf('<input type="checkbox" name="_REG_ID[]" value="%1$d" />', $item->ID());
446
-    }
418
+	/**
419
+	 * column_cb
420
+	 *
421
+	 * @access public
422
+	 * @param \EE_Registration $item
423
+	 * @return string
424
+	 * @throws EE_Error
425
+	 * @throws InvalidArgumentException
426
+	 * @throws InvalidDataTypeException
427
+	 * @throws InvalidInterfaceException
428
+	 * @throws ReflectionException
429
+	 */
430
+	public function column_cb($item)
431
+	{
432
+		/** checkbox/lock **/
433
+		$transaction = $item->get_first_related('Transaction');
434
+		$payment_count = $transaction instanceof EE_Transaction
435
+			? $transaction->count_related('Payment')
436
+			: 0;
437
+		return $payment_count > 0
438
+			   || ! EE_Registry::instance()->CAP->current_user_can(
439
+				   'ee_edit_registration',
440
+				   'registration_list_table_checkbox_input',
441
+				   $item->ID()
442
+			   )
443
+			? sprintf('<input type="checkbox" name="_REG_ID[]" value="%1$d" />', $item->ID())
444
+			  . '<span class="ee-lock-icon"></span>'
445
+			: sprintf('<input type="checkbox" name="_REG_ID[]" value="%1$d" />', $item->ID());
446
+	}
447 447
 
448 448
 
449
-    /**
450
-     * column__REG_ID
451
-     *
452
-     * @access public
453
-     * @param \EE_Registration $item
454
-     * @return string
455
-     * @throws EE_Error
456
-     * @throws InvalidArgumentException
457
-     * @throws InvalidDataTypeException
458
-     * @throws InvalidInterfaceException
459
-     * @throws ReflectionException
460
-     */
461
-    public function column__REG_ID(EE_Registration $item)
462
-    {
463
-        $attendee = $item->attendee();
464
-        $content = $item->ID();
465
-        $content .= '<div class="show-on-mobile-view-only">';
466
-        $content .= '<br>';
467
-        $content .= $attendee instanceof EE_Attendee ? $attendee->full_name() : '';
468
-        $content .= '&nbsp;' . sprintf(__('(%1$s / %2$s)', 'event_espresso'), $item->count(), $item->group_size());
469
-        $content .= '<br>' . sprintf(__('Reg Code: %s', 'event_espresso'), $item->get('REG_code'));
470
-        $content .= '</div>';
471
-        return $content;
472
-    }
449
+	/**
450
+	 * column__REG_ID
451
+	 *
452
+	 * @access public
453
+	 * @param \EE_Registration $item
454
+	 * @return string
455
+	 * @throws EE_Error
456
+	 * @throws InvalidArgumentException
457
+	 * @throws InvalidDataTypeException
458
+	 * @throws InvalidInterfaceException
459
+	 * @throws ReflectionException
460
+	 */
461
+	public function column__REG_ID(EE_Registration $item)
462
+	{
463
+		$attendee = $item->attendee();
464
+		$content = $item->ID();
465
+		$content .= '<div class="show-on-mobile-view-only">';
466
+		$content .= '<br>';
467
+		$content .= $attendee instanceof EE_Attendee ? $attendee->full_name() : '';
468
+		$content .= '&nbsp;' . sprintf(__('(%1$s / %2$s)', 'event_espresso'), $item->count(), $item->group_size());
469
+		$content .= '<br>' . sprintf(__('Reg Code: %s', 'event_espresso'), $item->get('REG_code'));
470
+		$content .= '</div>';
471
+		return $content;
472
+	}
473 473
 
474 474
 
475
-    /**
476
-     * column__REG_date
477
-     *
478
-     * @access public
479
-     * @param \EE_Registration $item
480
-     * @return string
481
-     * @throws EE_Error
482
-     * @throws InvalidArgumentException
483
-     * @throws InvalidDataTypeException
484
-     * @throws InvalidInterfaceException
485
-     * @throws ReflectionException
486
-     */
487
-    public function column__REG_date(EE_Registration $item)
488
-    {
489
-        $this->_set_related_details($item);
490
-        // Build row actions
491
-        $view_lnk_url = EE_Admin_Page::add_query_args_and_nonce(
492
-            array(
493
-                'action' => 'view_transaction',
494
-                'TXN_ID' => $this->_transaction_details['id'],
495
-            ),
496
-            TXN_ADMIN_URL
497
-        );
498
-        $view_link = EE_Registry::instance()->CAP->current_user_can(
499
-            'ee_read_transaction',
500
-            'espresso_transactions_view_transaction'
501
-        )
502
-            ? '<a class="ee-status-color-'
503
-              . $this->_transaction_details['status']
504
-              . '" href="'
505
-              . $view_lnk_url
506
-              . '" title="'
507
-              . esc_attr($this->_transaction_details['title_attr'])
508
-              . '">'
509
-              . $item->get_i18n_datetime('REG_date')
510
-              . '</a>' : $item->get_i18n_datetime('REG_date');
511
-        $view_link .= '<br><span class="ee-status-text-small">'
512
-                      . EEH_Template::pretty_status($this->_transaction_details['status'], false, 'sentence')
513
-                      . '</span>';
514
-        return $view_link;
515
-    }
475
+	/**
476
+	 * column__REG_date
477
+	 *
478
+	 * @access public
479
+	 * @param \EE_Registration $item
480
+	 * @return string
481
+	 * @throws EE_Error
482
+	 * @throws InvalidArgumentException
483
+	 * @throws InvalidDataTypeException
484
+	 * @throws InvalidInterfaceException
485
+	 * @throws ReflectionException
486
+	 */
487
+	public function column__REG_date(EE_Registration $item)
488
+	{
489
+		$this->_set_related_details($item);
490
+		// Build row actions
491
+		$view_lnk_url = EE_Admin_Page::add_query_args_and_nonce(
492
+			array(
493
+				'action' => 'view_transaction',
494
+				'TXN_ID' => $this->_transaction_details['id'],
495
+			),
496
+			TXN_ADMIN_URL
497
+		);
498
+		$view_link = EE_Registry::instance()->CAP->current_user_can(
499
+			'ee_read_transaction',
500
+			'espresso_transactions_view_transaction'
501
+		)
502
+			? '<a class="ee-status-color-'
503
+			  . $this->_transaction_details['status']
504
+			  . '" href="'
505
+			  . $view_lnk_url
506
+			  . '" title="'
507
+			  . esc_attr($this->_transaction_details['title_attr'])
508
+			  . '">'
509
+			  . $item->get_i18n_datetime('REG_date')
510
+			  . '</a>' : $item->get_i18n_datetime('REG_date');
511
+		$view_link .= '<br><span class="ee-status-text-small">'
512
+					  . EEH_Template::pretty_status($this->_transaction_details['status'], false, 'sentence')
513
+					  . '</span>';
514
+		return $view_link;
515
+	}
516 516
 
517 517
 
518
-    /**
519
-     * column_event_name
520
-     *
521
-     * @access public
522
-     * @param \EE_Registration $item
523
-     * @return string
524
-     * @throws EE_Error
525
-     * @throws InvalidArgumentException
526
-     * @throws InvalidDataTypeException
527
-     * @throws InvalidInterfaceException
528
-     * @throws ReflectionException
529
-     */
530
-    public function column_event_name(EE_Registration $item)
531
-    {
532
-        $this->_set_related_details($item);
533
-        // page=espresso_events&action=edit_event&EVT_ID=2&edit_event_nonce=cf3a7e5b62
534
-        $EVT_ID = $item->event_ID();
535
-        $event_name = $item->event_name();
536
-        $event_name = $event_name ? $event_name : __("No Associated Event", 'event_espresso');
537
-        $event_name = wp_trim_words($event_name, 30, '...');
538
-        if ($EVT_ID) {
539
-            $edit_event_url = EE_Admin_Page::add_query_args_and_nonce(
540
-                array('action' => 'edit', 'post' => $EVT_ID),
541
-                EVENTS_ADMIN_URL
542
-            );
543
-            $edit_event = EE_Registry::instance()->CAP->current_user_can('ee_edit_event', 'edit_event', $EVT_ID)
544
-                ? '<a class="ee-status-color-'
545
-                  . $this->_event_details['status']
546
-                  . '" href="'
547
-                  . $edit_event_url
548
-                  . '" title="'
549
-                  . esc_attr($this->_event_details['title_attr'])
550
-                  . '">'
551
-                  . $event_name
552
-                  . '</a>' : $event_name;
553
-            $edit_event_url = EE_Admin_Page::add_query_args_and_nonce(array('event_id' => $EVT_ID), REG_ADMIN_URL);
554
-            $actions['event_filter'] = '<a href="' . $edit_event_url . '" title="';
555
-            $actions['event_filter'] .= sprintf(
556
-                esc_attr__('Filter this list to only show registrations for %s', 'event_espresso'),
557
-                $event_name
558
-            );
559
-            $actions['event_filter'] .= '">' . __('View Registrations', 'event_espresso') . '</a>';
560
-        } else {
561
-            $edit_event = $event_name;
562
-            $actions['event_filter'] = '';
563
-        }
564
-        return sprintf('%1$s %2$s', $edit_event, $this->row_actions($actions));
565
-    }
518
+	/**
519
+	 * column_event_name
520
+	 *
521
+	 * @access public
522
+	 * @param \EE_Registration $item
523
+	 * @return string
524
+	 * @throws EE_Error
525
+	 * @throws InvalidArgumentException
526
+	 * @throws InvalidDataTypeException
527
+	 * @throws InvalidInterfaceException
528
+	 * @throws ReflectionException
529
+	 */
530
+	public function column_event_name(EE_Registration $item)
531
+	{
532
+		$this->_set_related_details($item);
533
+		// page=espresso_events&action=edit_event&EVT_ID=2&edit_event_nonce=cf3a7e5b62
534
+		$EVT_ID = $item->event_ID();
535
+		$event_name = $item->event_name();
536
+		$event_name = $event_name ? $event_name : __("No Associated Event", 'event_espresso');
537
+		$event_name = wp_trim_words($event_name, 30, '...');
538
+		if ($EVT_ID) {
539
+			$edit_event_url = EE_Admin_Page::add_query_args_and_nonce(
540
+				array('action' => 'edit', 'post' => $EVT_ID),
541
+				EVENTS_ADMIN_URL
542
+			);
543
+			$edit_event = EE_Registry::instance()->CAP->current_user_can('ee_edit_event', 'edit_event', $EVT_ID)
544
+				? '<a class="ee-status-color-'
545
+				  . $this->_event_details['status']
546
+				  . '" href="'
547
+				  . $edit_event_url
548
+				  . '" title="'
549
+				  . esc_attr($this->_event_details['title_attr'])
550
+				  . '">'
551
+				  . $event_name
552
+				  . '</a>' : $event_name;
553
+			$edit_event_url = EE_Admin_Page::add_query_args_and_nonce(array('event_id' => $EVT_ID), REG_ADMIN_URL);
554
+			$actions['event_filter'] = '<a href="' . $edit_event_url . '" title="';
555
+			$actions['event_filter'] .= sprintf(
556
+				esc_attr__('Filter this list to only show registrations for %s', 'event_espresso'),
557
+				$event_name
558
+			);
559
+			$actions['event_filter'] .= '">' . __('View Registrations', 'event_espresso') . '</a>';
560
+		} else {
561
+			$edit_event = $event_name;
562
+			$actions['event_filter'] = '';
563
+		}
564
+		return sprintf('%1$s %2$s', $edit_event, $this->row_actions($actions));
565
+	}
566 566
 
567 567
 
568
-    /**
569
-     * column_DTT_EVT_start
570
-     *
571
-     * @access public
572
-     * @param \EE_Registration $item
573
-     * @return string
574
-     * @throws EE_Error
575
-     * @throws InvalidArgumentException
576
-     * @throws InvalidDataTypeException
577
-     * @throws InvalidInterfaceException
578
-     * @throws ReflectionException
579
-     */
580
-    public function column_DTT_EVT_start(EE_Registration $item)
581
-    {
582
-        $datetime_strings = array();
583
-        $ticket = $item->ticket(true);
584
-        if ($ticket instanceof EE_Ticket) {
585
-            $remove_defaults = array('default_where_conditions' => 'none');
586
-            $datetimes = $ticket->datetimes($remove_defaults);
587
-            foreach ($datetimes as $datetime) {
588
-                $datetime_strings[] = $datetime->get_i18n_datetime('DTT_EVT_start');
589
-            }
590
-            return $this->generateDisplayForDatetimes($datetime_strings);
591
-        }
592
-        return __('There is no ticket on this registration', 'event_espresso');
593
-    }
568
+	/**
569
+	 * column_DTT_EVT_start
570
+	 *
571
+	 * @access public
572
+	 * @param \EE_Registration $item
573
+	 * @return string
574
+	 * @throws EE_Error
575
+	 * @throws InvalidArgumentException
576
+	 * @throws InvalidDataTypeException
577
+	 * @throws InvalidInterfaceException
578
+	 * @throws ReflectionException
579
+	 */
580
+	public function column_DTT_EVT_start(EE_Registration $item)
581
+	{
582
+		$datetime_strings = array();
583
+		$ticket = $item->ticket(true);
584
+		if ($ticket instanceof EE_Ticket) {
585
+			$remove_defaults = array('default_where_conditions' => 'none');
586
+			$datetimes = $ticket->datetimes($remove_defaults);
587
+			foreach ($datetimes as $datetime) {
588
+				$datetime_strings[] = $datetime->get_i18n_datetime('DTT_EVT_start');
589
+			}
590
+			return $this->generateDisplayForDatetimes($datetime_strings);
591
+		}
592
+		return __('There is no ticket on this registration', 'event_espresso');
593
+	}
594 594
 
595 595
 
596
-    /**
597
-     * Receives an array of datetime strings to display and converts them to the html container for the column.
598
-     *
599
-     * @param array $datetime_strings
600
-     * @return string
601
-     */
602
-    public function generateDisplayForDateTimes(array $datetime_strings)
603
-    {
604
-        $content = '<div class="ee-registration-event-datetimes-container">';
605
-        $expand_toggle = count($datetime_strings) > 1
606
-            ? ' <span title="' . esc_attr__('Click to view all dates', 'event_espresso')
607
-              . '" class="ee-js ee-more-datetimes-toggle dashicons dashicons-plus"></span>'
608
-            : '';
609
-        // get first item for initial visibility
610
-        $content .= '<div class="left">' . array_shift($datetime_strings) . '</div>';
611
-        $content .= $expand_toggle;
612
-        if ($datetime_strings) {
613
-            $content .= '<div style="clear:both"></div>';
614
-            $content .= '<div class="ee-registration-event-datetimes-container more-items hidden">';
615
-            $content .= implode("<br />", $datetime_strings);
616
-            $content .= '</div>';
617
-        }
618
-        $content .= '</div>';
619
-        return $content;
620
-    }
596
+	/**
597
+	 * Receives an array of datetime strings to display and converts them to the html container for the column.
598
+	 *
599
+	 * @param array $datetime_strings
600
+	 * @return string
601
+	 */
602
+	public function generateDisplayForDateTimes(array $datetime_strings)
603
+	{
604
+		$content = '<div class="ee-registration-event-datetimes-container">';
605
+		$expand_toggle = count($datetime_strings) > 1
606
+			? ' <span title="' . esc_attr__('Click to view all dates', 'event_espresso')
607
+			  . '" class="ee-js ee-more-datetimes-toggle dashicons dashicons-plus"></span>'
608
+			: '';
609
+		// get first item for initial visibility
610
+		$content .= '<div class="left">' . array_shift($datetime_strings) . '</div>';
611
+		$content .= $expand_toggle;
612
+		if ($datetime_strings) {
613
+			$content .= '<div style="clear:both"></div>';
614
+			$content .= '<div class="ee-registration-event-datetimes-container more-items hidden">';
615
+			$content .= implode("<br />", $datetime_strings);
616
+			$content .= '</div>';
617
+		}
618
+		$content .= '</div>';
619
+		return $content;
620
+	}
621 621
 
622 622
 
623
-    /**
624
-     * column_ATT_fname
625
-     *
626
-     * @access public
627
-     * @param \EE_Registration $item
628
-     * @return string
629
-     * @throws EE_Error
630
-     * @throws InvalidArgumentException
631
-     * @throws InvalidDataTypeException
632
-     * @throws InvalidInterfaceException
633
-     * @throws ReflectionException
634
-     */
635
-    public function column_ATT_fname(EE_Registration $item)
636
-    {
637
-        $attendee = $item->attendee();
638
-        $edit_lnk_url = EE_Admin_Page::add_query_args_and_nonce(
639
-            array(
640
-                'action'  => 'view_registration',
641
-                '_REG_ID' => $item->ID(),
642
-            ),
643
-            REG_ADMIN_URL
644
-        );
645
-        $attendee_name = $attendee instanceof EE_Attendee ? $attendee->full_name() : '';
646
-        $link = EE_Registry::instance()->CAP->current_user_can(
647
-            'ee_read_registration',
648
-            'espresso_registrations_view_registration',
649
-            $item->ID()
650
-        )
651
-            ? '<a href="'
652
-              . $edit_lnk_url
653
-              . '" title="'
654
-              . esc_attr__('View Registration Details', 'event_espresso')
655
-              . '">'
656
-              . $attendee_name
657
-              . '</a>' : $attendee_name;
658
-        $link .= $item->count() === 1
659
-            ? '&nbsp;<sup><div class="dashicons dashicons-star-filled yellow-icon ee-icon-size-8"></div></sup>' : '';
660
-        $t = $item->get_first_related('Transaction');
661
-        $payment_count = $t instanceof EE_Transaction ? $t->count_related('Payment') : 0;
662
-        // append group count to name
663
-        $link .= '&nbsp;' . sprintf(__('(%1$s / %2$s)', 'event_espresso'), $item->count(), $item->group_size());
664
-        // append reg_code
665
-        $link .= '<br>' . sprintf(__('Reg Code: %s', 'event_espresso'), $item->get('REG_code'));
666
-        // reg status text for accessibility
667
-        $link .= '<br><span class="ee-status-text-small">'
668
-                 . EEH_Template::pretty_status($item->status_ID(), false, 'sentence')
669
-                 . '</span>';
670
-        $action = [ '_REG_ID' => $item->ID() ];
671
-        if (isset($this->_req_data['event_id'])) {
672
-            $action['event_id'] = $item->event_ID();
673
-        }
674
-        // trash/restore/delete actions
675
-        $actions = array();
676
-        if ($this->_view !== 'trash'
677
-            && $payment_count === 0
678
-            && EE_Registry::instance()->CAP->current_user_can(
679
-                'ee_delete_registration',
680
-                'espresso_registrations_trash_registrations',
681
-                $item->ID()
682
-            )) {
683
-            $action['action'] = 'trash_registrations';
684
-            $trash_lnk_url = EE_Admin_Page::add_query_args_and_nonce(
685
-                $action,
686
-                REG_ADMIN_URL
687
-            );
688
-            $actions['trash'] = '<a href="'
689
-                                . $trash_lnk_url
690
-                                . '" title="'
691
-                                . esc_attr__('Trash Registration', 'event_espresso')
692
-                                . '">' . __('Trash', 'event_espresso') . '</a>';
693
-        } elseif ($this->_view === 'trash') {
694
-            // restore registration link
695
-            if (EE_Registry::instance()->CAP->current_user_can(
696
-                'ee_delete_registration',
697
-                'espresso_registrations_restore_registrations',
698
-                $item->ID()
699
-            )) {
700
-                $action['action'] = 'restore_registrations';
701
-                $restore_lnk_url = EE_Admin_Page::add_query_args_and_nonce(
702
-                    $action,
703
-                    REG_ADMIN_URL
704
-                );
705
-                $actions['restore'] = '<a href="'
706
-                                      . $restore_lnk_url
707
-                                      . '" title="'
708
-                                      . esc_attr__('Restore Registration', 'event_espresso') . '">'
709
-                                      . __('Restore', 'event_espresso') . '</a>';
710
-            }
711
-            if (EE_Registry::instance()->CAP->current_user_can(
712
-                'ee_delete_registration',
713
-                'espresso_registrations_ee_delete_registrations',
714
-                $item->ID()
715
-            )) {
716
-                $action['action'] = 'delete_registrations';
717
-                $delete_lnk_url = EE_Admin_Page::add_query_args_and_nonce(
718
-                    $action,
719
-                    REG_ADMIN_URL
720
-                );
721
-                $actions['delete'] = '<a href="'
722
-                                     . $delete_lnk_url
723
-                                     . '" title="'
724
-                                     . esc_attr__('Delete Registration Permanently', 'event_espresso')
725
-                                     . '">'
726
-                                     . __('Delete', 'event_espresso')
727
-                                     . '</a>';
728
-            }
729
-        }
730
-        return sprintf('%1$s %2$s', $link, $this->row_actions($actions));
731
-    }
623
+	/**
624
+	 * column_ATT_fname
625
+	 *
626
+	 * @access public
627
+	 * @param \EE_Registration $item
628
+	 * @return string
629
+	 * @throws EE_Error
630
+	 * @throws InvalidArgumentException
631
+	 * @throws InvalidDataTypeException
632
+	 * @throws InvalidInterfaceException
633
+	 * @throws ReflectionException
634
+	 */
635
+	public function column_ATT_fname(EE_Registration $item)
636
+	{
637
+		$attendee = $item->attendee();
638
+		$edit_lnk_url = EE_Admin_Page::add_query_args_and_nonce(
639
+			array(
640
+				'action'  => 'view_registration',
641
+				'_REG_ID' => $item->ID(),
642
+			),
643
+			REG_ADMIN_URL
644
+		);
645
+		$attendee_name = $attendee instanceof EE_Attendee ? $attendee->full_name() : '';
646
+		$link = EE_Registry::instance()->CAP->current_user_can(
647
+			'ee_read_registration',
648
+			'espresso_registrations_view_registration',
649
+			$item->ID()
650
+		)
651
+			? '<a href="'
652
+			  . $edit_lnk_url
653
+			  . '" title="'
654
+			  . esc_attr__('View Registration Details', 'event_espresso')
655
+			  . '">'
656
+			  . $attendee_name
657
+			  . '</a>' : $attendee_name;
658
+		$link .= $item->count() === 1
659
+			? '&nbsp;<sup><div class="dashicons dashicons-star-filled yellow-icon ee-icon-size-8"></div></sup>' : '';
660
+		$t = $item->get_first_related('Transaction');
661
+		$payment_count = $t instanceof EE_Transaction ? $t->count_related('Payment') : 0;
662
+		// append group count to name
663
+		$link .= '&nbsp;' . sprintf(__('(%1$s / %2$s)', 'event_espresso'), $item->count(), $item->group_size());
664
+		// append reg_code
665
+		$link .= '<br>' . sprintf(__('Reg Code: %s', 'event_espresso'), $item->get('REG_code'));
666
+		// reg status text for accessibility
667
+		$link .= '<br><span class="ee-status-text-small">'
668
+				 . EEH_Template::pretty_status($item->status_ID(), false, 'sentence')
669
+				 . '</span>';
670
+		$action = [ '_REG_ID' => $item->ID() ];
671
+		if (isset($this->_req_data['event_id'])) {
672
+			$action['event_id'] = $item->event_ID();
673
+		}
674
+		// trash/restore/delete actions
675
+		$actions = array();
676
+		if ($this->_view !== 'trash'
677
+			&& $payment_count === 0
678
+			&& EE_Registry::instance()->CAP->current_user_can(
679
+				'ee_delete_registration',
680
+				'espresso_registrations_trash_registrations',
681
+				$item->ID()
682
+			)) {
683
+			$action['action'] = 'trash_registrations';
684
+			$trash_lnk_url = EE_Admin_Page::add_query_args_and_nonce(
685
+				$action,
686
+				REG_ADMIN_URL
687
+			);
688
+			$actions['trash'] = '<a href="'
689
+								. $trash_lnk_url
690
+								. '" title="'
691
+								. esc_attr__('Trash Registration', 'event_espresso')
692
+								. '">' . __('Trash', 'event_espresso') . '</a>';
693
+		} elseif ($this->_view === 'trash') {
694
+			// restore registration link
695
+			if (EE_Registry::instance()->CAP->current_user_can(
696
+				'ee_delete_registration',
697
+				'espresso_registrations_restore_registrations',
698
+				$item->ID()
699
+			)) {
700
+				$action['action'] = 'restore_registrations';
701
+				$restore_lnk_url = EE_Admin_Page::add_query_args_and_nonce(
702
+					$action,
703
+					REG_ADMIN_URL
704
+				);
705
+				$actions['restore'] = '<a href="'
706
+									  . $restore_lnk_url
707
+									  . '" title="'
708
+									  . esc_attr__('Restore Registration', 'event_espresso') . '">'
709
+									  . __('Restore', 'event_espresso') . '</a>';
710
+			}
711
+			if (EE_Registry::instance()->CAP->current_user_can(
712
+				'ee_delete_registration',
713
+				'espresso_registrations_ee_delete_registrations',
714
+				$item->ID()
715
+			)) {
716
+				$action['action'] = 'delete_registrations';
717
+				$delete_lnk_url = EE_Admin_Page::add_query_args_and_nonce(
718
+					$action,
719
+					REG_ADMIN_URL
720
+				);
721
+				$actions['delete'] = '<a href="'
722
+									 . $delete_lnk_url
723
+									 . '" title="'
724
+									 . esc_attr__('Delete Registration Permanently', 'event_espresso')
725
+									 . '">'
726
+									 . __('Delete', 'event_espresso')
727
+									 . '</a>';
728
+			}
729
+		}
730
+		return sprintf('%1$s %2$s', $link, $this->row_actions($actions));
731
+	}
732 732
 
733 733
 
734
-    /**
735
-     * column_ATT_email
736
-     *
737
-     * @access public
738
-     * @param \EE_Registration $item
739
-     * @return string
740
-     * @throws EE_Error
741
-     * @throws InvalidArgumentException
742
-     * @throws InvalidDataTypeException
743
-     * @throws InvalidInterfaceException
744
-     * @throws ReflectionException
745
-     */
746
-    public function column_ATT_email(EE_Registration $item)
747
-    {
748
-        $attendee = $item->get_first_related('Attendee');
749
-        return ! $attendee instanceof EE_Attendee ? __('No attached contact record.', 'event_espresso')
750
-            : $attendee->email();
751
-    }
734
+	/**
735
+	 * column_ATT_email
736
+	 *
737
+	 * @access public
738
+	 * @param \EE_Registration $item
739
+	 * @return string
740
+	 * @throws EE_Error
741
+	 * @throws InvalidArgumentException
742
+	 * @throws InvalidDataTypeException
743
+	 * @throws InvalidInterfaceException
744
+	 * @throws ReflectionException
745
+	 */
746
+	public function column_ATT_email(EE_Registration $item)
747
+	{
748
+		$attendee = $item->get_first_related('Attendee');
749
+		return ! $attendee instanceof EE_Attendee ? __('No attached contact record.', 'event_espresso')
750
+			: $attendee->email();
751
+	}
752 752
 
753 753
 
754
-    /**
755
-     * column__REG_count
756
-     *
757
-     * @access public
758
-     * @param \EE_Registration $item
759
-     * @return string
760
-     */
761
-    public function column__REG_count(EE_Registration $item)
762
-    {
763
-        return sprintf(__('%1$s / %2$s', 'event_espresso'), $item->count(), $item->group_size());
764
-    }
754
+	/**
755
+	 * column__REG_count
756
+	 *
757
+	 * @access public
758
+	 * @param \EE_Registration $item
759
+	 * @return string
760
+	 */
761
+	public function column__REG_count(EE_Registration $item)
762
+	{
763
+		return sprintf(__('%1$s / %2$s', 'event_espresso'), $item->count(), $item->group_size());
764
+	}
765 765
 
766 766
 
767
-    /**
768
-     * column_PRC_amount
769
-     *
770
-     * @access public
771
-     * @param \EE_Registration $item
772
-     * @return string
773
-     * @throws EE_Error
774
-     */
775
-    public function column_PRC_amount(EE_Registration $item)
776
-    {
777
-        $ticket = $item->ticket();
778
-        $content = isset($_GET['event_id']) && $ticket instanceof EE_Ticket ? '<span class="TKT_name">'
779
-                                                                              . $ticket->name()
780
-                                                                              . '</span><br />' : '';
781
-        if ($item->final_price() > 0) {
782
-            $content .= '<span class="reg-pad-rght">' . $item->pretty_final_price() . '</span>';
783
-        } else {
784
-            // free event
785
-            $content .= '<span class="reg-overview-free-event-spn reg-pad-rght">'
786
-                        . __('free', 'event_espresso')
787
-                        . '</span>';
788
-        }
789
-        return $content;
790
-    }
767
+	/**
768
+	 * column_PRC_amount
769
+	 *
770
+	 * @access public
771
+	 * @param \EE_Registration $item
772
+	 * @return string
773
+	 * @throws EE_Error
774
+	 */
775
+	public function column_PRC_amount(EE_Registration $item)
776
+	{
777
+		$ticket = $item->ticket();
778
+		$content = isset($_GET['event_id']) && $ticket instanceof EE_Ticket ? '<span class="TKT_name">'
779
+																			  . $ticket->name()
780
+																			  . '</span><br />' : '';
781
+		if ($item->final_price() > 0) {
782
+			$content .= '<span class="reg-pad-rght">' . $item->pretty_final_price() . '</span>';
783
+		} else {
784
+			// free event
785
+			$content .= '<span class="reg-overview-free-event-spn reg-pad-rght">'
786
+						. __('free', 'event_espresso')
787
+						. '</span>';
788
+		}
789
+		return $content;
790
+	}
791 791
 
792 792
 
793
-    /**
794
-     * column__REG_final_price
795
-     *
796
-     * @access public
797
-     * @param \EE_Registration $item
798
-     * @return string
799
-     * @throws EE_Error
800
-     */
801
-    public function column__REG_final_price(EE_Registration $item)
802
-    {
803
-        $ticket = $item->ticket();
804
-        $content = isset($_GET['event_id']) || ! $ticket instanceof EE_Ticket
805
-            ? ''
806
-            : '<span class="TKT_name">'
807
-              . $ticket->name()
808
-              . '</span><br />';
809
-        $content .= '<span class="reg-pad-rght">' . $item->pretty_final_price() . '</span>';
810
-        return $content;
811
-    }
793
+	/**
794
+	 * column__REG_final_price
795
+	 *
796
+	 * @access public
797
+	 * @param \EE_Registration $item
798
+	 * @return string
799
+	 * @throws EE_Error
800
+	 */
801
+	public function column__REG_final_price(EE_Registration $item)
802
+	{
803
+		$ticket = $item->ticket();
804
+		$content = isset($_GET['event_id']) || ! $ticket instanceof EE_Ticket
805
+			? ''
806
+			: '<span class="TKT_name">'
807
+			  . $ticket->name()
808
+			  . '</span><br />';
809
+		$content .= '<span class="reg-pad-rght">' . $item->pretty_final_price() . '</span>';
810
+		return $content;
811
+	}
812 812
 
813 813
 
814
-    /**
815
-     * column__REG_paid
816
-     *
817
-     * @access public
818
-     * @param \EE_Registration $item
819
-     * @return string
820
-     * @throws EE_Error
821
-     */
822
-    public function column__REG_paid(EE_Registration $item)
823
-    {
824
-        $payment_method = $item->payment_method();
825
-        $payment_method_name = $payment_method instanceof EE_Payment_Method ? $payment_method->admin_name()
826
-            : __('Unknown', 'event_espresso');
827
-        $content = '<span class="reg-pad-rght">' . $item->pretty_paid() . '</span>';
828
-        if ($item->paid() > 0) {
829
-            $content .= '<br><span class="ee-status-text-small">'
830
-                        . sprintf(
831
-                            __('...via %s', 'event_espresso'),
832
-                            $payment_method_name
833
-                        )
834
-                        . '</span>';
835
-        }
836
-        return $content;
837
-    }
814
+	/**
815
+	 * column__REG_paid
816
+	 *
817
+	 * @access public
818
+	 * @param \EE_Registration $item
819
+	 * @return string
820
+	 * @throws EE_Error
821
+	 */
822
+	public function column__REG_paid(EE_Registration $item)
823
+	{
824
+		$payment_method = $item->payment_method();
825
+		$payment_method_name = $payment_method instanceof EE_Payment_Method ? $payment_method->admin_name()
826
+			: __('Unknown', 'event_espresso');
827
+		$content = '<span class="reg-pad-rght">' . $item->pretty_paid() . '</span>';
828
+		if ($item->paid() > 0) {
829
+			$content .= '<br><span class="ee-status-text-small">'
830
+						. sprintf(
831
+							__('...via %s', 'event_espresso'),
832
+							$payment_method_name
833
+						)
834
+						. '</span>';
835
+		}
836
+		return $content;
837
+	}
838 838
 
839 839
 
840
-    /**
841
-     * column_TXN_total
842
-     *
843
-     * @access public
844
-     * @param \EE_Registration $item
845
-     * @return string
846
-     * @throws EE_Error
847
-     * @throws EntityNotFoundException
848
-     * @throws InvalidArgumentException
849
-     * @throws InvalidDataTypeException
850
-     * @throws InvalidInterfaceException
851
-     */
852
-    public function column_TXN_total(EE_Registration $item)
853
-    {
854
-        if ($item->transaction()) {
855
-            $view_txn_lnk_url = EE_Admin_Page::add_query_args_and_nonce(
856
-                array(
857
-                    'action' => 'view_transaction',
858
-                    'TXN_ID' => $item->transaction_ID(),
859
-                ),
860
-                TXN_ADMIN_URL
861
-            );
862
-            return EE_Registry::instance()->CAP->current_user_can(
863
-                'ee_read_transaction',
864
-                'espresso_transactions_view_transaction',
865
-                $item->transaction_ID()
866
-            )
867
-                ? '<span class="reg-pad-rght"><a class="status-'
868
-                  . $item->transaction()->status_ID()
869
-                  . '" href="'
870
-                  . $view_txn_lnk_url
871
-                  . '"  title="'
872
-                  . esc_attr__('View Transaction', 'event_espresso')
873
-                  . '">'
874
-                  . $item->transaction()->pretty_total()
875
-                  . '</a></span>' : '<span class="reg-pad-rght">' . $item->transaction()->pretty_total() . '</span>';
876
-        } else {
877
-            return __("None", "event_espresso");
878
-        }
879
-    }
840
+	/**
841
+	 * column_TXN_total
842
+	 *
843
+	 * @access public
844
+	 * @param \EE_Registration $item
845
+	 * @return string
846
+	 * @throws EE_Error
847
+	 * @throws EntityNotFoundException
848
+	 * @throws InvalidArgumentException
849
+	 * @throws InvalidDataTypeException
850
+	 * @throws InvalidInterfaceException
851
+	 */
852
+	public function column_TXN_total(EE_Registration $item)
853
+	{
854
+		if ($item->transaction()) {
855
+			$view_txn_lnk_url = EE_Admin_Page::add_query_args_and_nonce(
856
+				array(
857
+					'action' => 'view_transaction',
858
+					'TXN_ID' => $item->transaction_ID(),
859
+				),
860
+				TXN_ADMIN_URL
861
+			);
862
+			return EE_Registry::instance()->CAP->current_user_can(
863
+				'ee_read_transaction',
864
+				'espresso_transactions_view_transaction',
865
+				$item->transaction_ID()
866
+			)
867
+				? '<span class="reg-pad-rght"><a class="status-'
868
+				  . $item->transaction()->status_ID()
869
+				  . '" href="'
870
+				  . $view_txn_lnk_url
871
+				  . '"  title="'
872
+				  . esc_attr__('View Transaction', 'event_espresso')
873
+				  . '">'
874
+				  . $item->transaction()->pretty_total()
875
+				  . '</a></span>' : '<span class="reg-pad-rght">' . $item->transaction()->pretty_total() . '</span>';
876
+		} else {
877
+			return __("None", "event_espresso");
878
+		}
879
+	}
880 880
 
881 881
 
882
-    /**
883
-     * column_TXN_paid
884
-     *
885
-     * @access public
886
-     * @param \EE_Registration $item
887
-     * @return string
888
-     * @throws EE_Error
889
-     * @throws EntityNotFoundException
890
-     * @throws InvalidArgumentException
891
-     * @throws InvalidDataTypeException
892
-     * @throws InvalidInterfaceException
893
-     */
894
-    public function column_TXN_paid(EE_Registration $item)
895
-    {
896
-        if ($item->count() === 1) {
897
-            $transaction = $item->transaction() ? $item->transaction() : EE_Transaction::new_instance();
898
-            if ($transaction->paid() >= $transaction->total()) {
899
-                return '<span class="reg-pad-rght"><div class="dashicons dashicons-yes green-icon"></div></span>';
900
-            } else {
901
-                $view_txn_lnk_url = EE_Admin_Page::add_query_args_and_nonce(
902
-                    array(
903
-                        'action' => 'view_transaction',
904
-                        'TXN_ID' => $item->transaction_ID(),
905
-                    ),
906
-                    TXN_ADMIN_URL
907
-                );
908
-                return EE_Registry::instance()->CAP->current_user_can(
909
-                    'ee_read_transaction',
910
-                    'espresso_transactions_view_transaction',
911
-                    $item->transaction_ID()
912
-                )
913
-                    ? '<span class="reg-pad-rght"><a class="status-'
914
-                      . $transaction->status_ID()
915
-                      . '" href="'
916
-                      . $view_txn_lnk_url
917
-                      . '"  title="'
918
-                      . esc_attr__('View Transaction', 'event_espresso')
919
-                      . '">'
920
-                      . $item->transaction()->pretty_paid()
921
-                      . '</a><span>' : '<span class="reg-pad-rght">' . $item->transaction()->pretty_paid() . '</span>';
922
-            }
923
-        }
924
-        return '&nbsp;';
925
-    }
882
+	/**
883
+	 * column_TXN_paid
884
+	 *
885
+	 * @access public
886
+	 * @param \EE_Registration $item
887
+	 * @return string
888
+	 * @throws EE_Error
889
+	 * @throws EntityNotFoundException
890
+	 * @throws InvalidArgumentException
891
+	 * @throws InvalidDataTypeException
892
+	 * @throws InvalidInterfaceException
893
+	 */
894
+	public function column_TXN_paid(EE_Registration $item)
895
+	{
896
+		if ($item->count() === 1) {
897
+			$transaction = $item->transaction() ? $item->transaction() : EE_Transaction::new_instance();
898
+			if ($transaction->paid() >= $transaction->total()) {
899
+				return '<span class="reg-pad-rght"><div class="dashicons dashicons-yes green-icon"></div></span>';
900
+			} else {
901
+				$view_txn_lnk_url = EE_Admin_Page::add_query_args_and_nonce(
902
+					array(
903
+						'action' => 'view_transaction',
904
+						'TXN_ID' => $item->transaction_ID(),
905
+					),
906
+					TXN_ADMIN_URL
907
+				);
908
+				return EE_Registry::instance()->CAP->current_user_can(
909
+					'ee_read_transaction',
910
+					'espresso_transactions_view_transaction',
911
+					$item->transaction_ID()
912
+				)
913
+					? '<span class="reg-pad-rght"><a class="status-'
914
+					  . $transaction->status_ID()
915
+					  . '" href="'
916
+					  . $view_txn_lnk_url
917
+					  . '"  title="'
918
+					  . esc_attr__('View Transaction', 'event_espresso')
919
+					  . '">'
920
+					  . $item->transaction()->pretty_paid()
921
+					  . '</a><span>' : '<span class="reg-pad-rght">' . $item->transaction()->pretty_paid() . '</span>';
922
+			}
923
+		}
924
+		return '&nbsp;';
925
+	}
926 926
 
927 927
 
928
-    /**
929
-     * column_actions
930
-     *
931
-     * @access public
932
-     * @param \EE_Registration $item
933
-     * @return string
934
-     * @throws EE_Error
935
-     * @throws InvalidArgumentException
936
-     * @throws InvalidDataTypeException
937
-     * @throws InvalidInterfaceException
938
-     * @throws ReflectionException
939
-     */
940
-    public function column_actions(EE_Registration $item)
941
-    {
942
-        $actions = array();
943
-        $attendee = $item->attendee();
944
-        $this->_set_related_details($item);
945
-        // Build row actions
946
-        $view_lnk_url = EE_Admin_Page::add_query_args_and_nonce(
947
-            array(
948
-                'action'  => 'view_registration',
949
-                '_REG_ID' => $item->ID(),
950
-            ),
951
-            REG_ADMIN_URL
952
-        );
953
-        $edit_lnk_url = EE_Admin_Page::add_query_args_and_nonce(
954
-            array(
955
-                'action' => 'edit_attendee',
956
-                'post'   => $item->attendee_ID(),
957
-            ),
958
-            REG_ADMIN_URL
959
-        );
960
-        // page=attendees&event_admin_reports=resend_email&registration_id=43653465634&event_id=2&form_action=resend_email
961
-        // $resend_reg_lnk_url_params = array( 'action'=>'resend_registration', '_REG_ID'=>$item->REG_ID );
962
-        $resend_reg_lnk_url = EE_Admin_Page::add_query_args_and_nonce(
963
-            array(
964
-                'action'  => 'resend_registration',
965
-                '_REG_ID' => $item->ID(),
966
-            ),
967
-            REG_ADMIN_URL,
968
-            true
969
-        );
970
-        // Build row actions
971
-        $actions['view_lnk'] = EE_Registry::instance()->CAP->current_user_can(
972
-            'ee_read_registration',
973
-            'espresso_registrations_view_registration',
974
-            $item->ID()
975
-        ) ? '<li><a href="'
976
-            . $view_lnk_url
977
-            . '" title="'
978
-            . esc_attr__('View Registration Details', 'event_espresso')
979
-            . '" class="tiny-text">
928
+	/**
929
+	 * column_actions
930
+	 *
931
+	 * @access public
932
+	 * @param \EE_Registration $item
933
+	 * @return string
934
+	 * @throws EE_Error
935
+	 * @throws InvalidArgumentException
936
+	 * @throws InvalidDataTypeException
937
+	 * @throws InvalidInterfaceException
938
+	 * @throws ReflectionException
939
+	 */
940
+	public function column_actions(EE_Registration $item)
941
+	{
942
+		$actions = array();
943
+		$attendee = $item->attendee();
944
+		$this->_set_related_details($item);
945
+		// Build row actions
946
+		$view_lnk_url = EE_Admin_Page::add_query_args_and_nonce(
947
+			array(
948
+				'action'  => 'view_registration',
949
+				'_REG_ID' => $item->ID(),
950
+			),
951
+			REG_ADMIN_URL
952
+		);
953
+		$edit_lnk_url = EE_Admin_Page::add_query_args_and_nonce(
954
+			array(
955
+				'action' => 'edit_attendee',
956
+				'post'   => $item->attendee_ID(),
957
+			),
958
+			REG_ADMIN_URL
959
+		);
960
+		// page=attendees&event_admin_reports=resend_email&registration_id=43653465634&event_id=2&form_action=resend_email
961
+		// $resend_reg_lnk_url_params = array( 'action'=>'resend_registration', '_REG_ID'=>$item->REG_ID );
962
+		$resend_reg_lnk_url = EE_Admin_Page::add_query_args_and_nonce(
963
+			array(
964
+				'action'  => 'resend_registration',
965
+				'_REG_ID' => $item->ID(),
966
+			),
967
+			REG_ADMIN_URL,
968
+			true
969
+		);
970
+		// Build row actions
971
+		$actions['view_lnk'] = EE_Registry::instance()->CAP->current_user_can(
972
+			'ee_read_registration',
973
+			'espresso_registrations_view_registration',
974
+			$item->ID()
975
+		) ? '<li><a href="'
976
+			. $view_lnk_url
977
+			. '" title="'
978
+			. esc_attr__('View Registration Details', 'event_espresso')
979
+			. '" class="tiny-text">
980 980
 				<div class="dashicons dashicons-clipboard"></div>
981 981
 			</a>
982 982
 			</li>'
983
-            : '';
984
-        $actions['edit_lnk'] = EE_Registry::instance()->CAP->current_user_can(
985
-            'ee_edit_contacts',
986
-            'espresso_registrations_edit_attendee'
987
-        )
988
-                               && $attendee instanceof EE_Attendee
989
-            ? '
983
+			: '';
984
+		$actions['edit_lnk'] = EE_Registry::instance()->CAP->current_user_can(
985
+			'ee_edit_contacts',
986
+			'espresso_registrations_edit_attendee'
987
+		)
988
+							   && $attendee instanceof EE_Attendee
989
+			? '
990 990
 			<li>
991 991
 			<a href="' . $edit_lnk_url . '" title="'
992
-              . esc_attr__('Edit Contact Details', 'event_espresso') . '" class="tiny-text">
992
+			  . esc_attr__('Edit Contact Details', 'event_espresso') . '" class="tiny-text">
993 993
 				<div class="ee-icon ee-icon-user-edit ee-icon-size-16"></div>
994 994
 			</a>
995 995
 			</li>' : '';
996
-        $actions['resend_reg_lnk'] = $attendee instanceof EE_Attendee
997
-                                     && EE_Registry::instance()->CAP->current_user_can(
998
-                                         'ee_send_message',
999
-                                         'espresso_registrations_resend_registration',
1000
-                                         $item->ID()
1001
-                                     )
1002
-            ? '
996
+		$actions['resend_reg_lnk'] = $attendee instanceof EE_Attendee
997
+									 && EE_Registry::instance()->CAP->current_user_can(
998
+										 'ee_send_message',
999
+										 'espresso_registrations_resend_registration',
1000
+										 $item->ID()
1001
+									 )
1002
+			? '
1003 1003
 			<li>
1004 1004
 			<a href="'
1005
-              . $resend_reg_lnk_url
1006
-              . '" title="'
1007
-              . esc_attr__('Resend Registration Details', 'event_espresso')
1008
-              . '" class="tiny-text">
1005
+			  . $resend_reg_lnk_url
1006
+			  . '" title="'
1007
+			  . esc_attr__('Resend Registration Details', 'event_espresso')
1008
+			  . '" class="tiny-text">
1009 1009
 				<div class="dashicons dashicons-email-alt"></div>
1010 1010
 			</a>
1011 1011
 			</li>' : '';
1012
-        // page=transactions&action=view_transaction&txn=256&_wpnonce=6414da4dbb
1013
-        $view_txn_lnk_url = EE_Admin_Page::add_query_args_and_nonce(
1014
-            array(
1015
-                'action' => 'view_transaction',
1016
-                'TXN_ID' => $this->_transaction_details['id'],
1017
-            ),
1018
-            TXN_ADMIN_URL
1019
-        );
1020
-        $actions['view_txn_lnk'] = EE_Registry::instance()->CAP->current_user_can(
1021
-            'ee_read_transaction',
1022
-            'espresso_transactions_view_transaction',
1023
-            $this->_transaction_details['id']
1024
-        )
1025
-            ? '
1012
+		// page=transactions&action=view_transaction&txn=256&_wpnonce=6414da4dbb
1013
+		$view_txn_lnk_url = EE_Admin_Page::add_query_args_and_nonce(
1014
+			array(
1015
+				'action' => 'view_transaction',
1016
+				'TXN_ID' => $this->_transaction_details['id'],
1017
+			),
1018
+			TXN_ADMIN_URL
1019
+		);
1020
+		$actions['view_txn_lnk'] = EE_Registry::instance()->CAP->current_user_can(
1021
+			'ee_read_transaction',
1022
+			'espresso_transactions_view_transaction',
1023
+			$this->_transaction_details['id']
1024
+		)
1025
+			? '
1026 1026
 			<li>
1027 1027
 			<a class="ee-status-color-'
1028
-              . $this->_transaction_details['status']
1029
-              . ' tiny-text" href="'
1030
-              . $view_txn_lnk_url
1031
-              . '"  title="'
1032
-              . $this->_transaction_details['title_attr']
1033
-              . '">
1028
+			  . $this->_transaction_details['status']
1029
+			  . ' tiny-text" href="'
1030
+			  . $view_txn_lnk_url
1031
+			  . '"  title="'
1032
+			  . $this->_transaction_details['title_attr']
1033
+			  . '">
1034 1034
 				<div class="dashicons dashicons-cart"></div>
1035 1035
 			</a>
1036 1036
 			</li>' : '';
1037
-        // invoice link
1038
-        $actions['dl_invoice_lnk'] = '';
1039
-        $dl_invoice_lnk_url = $item->invoice_url();
1040
-        // only show invoice link if message type is active.
1041
-        if ($attendee instanceof EE_Attendee
1042
-            && $item->is_primary_registrant()
1043
-            && EEH_MSG_Template::is_mt_active('invoice')
1044
-        ) {
1045
-            $actions['dl_invoice_lnk'] = '
1037
+		// invoice link
1038
+		$actions['dl_invoice_lnk'] = '';
1039
+		$dl_invoice_lnk_url = $item->invoice_url();
1040
+		// only show invoice link if message type is active.
1041
+		if ($attendee instanceof EE_Attendee
1042
+			&& $item->is_primary_registrant()
1043
+			&& EEH_MSG_Template::is_mt_active('invoice')
1044
+		) {
1045
+			$actions['dl_invoice_lnk'] = '
1046 1046
 		<li>
1047 1047
 			<a title="'
1048
-                                         . esc_attr__('View Transaction Invoice', 'event_espresso')
1049
-                                         . '" target="_blank" href="'
1050
-                                         . $dl_invoice_lnk_url
1051
-                                         . '" class="tiny-text">
1048
+										 . esc_attr__('View Transaction Invoice', 'event_espresso')
1049
+										 . '" target="_blank" href="'
1050
+										 . $dl_invoice_lnk_url
1051
+										 . '" class="tiny-text">
1052 1052
 				<span class="dashicons dashicons-media-spreadsheet ee-icon-size-18"></span>
1053 1053
 			</a>
1054 1054
 		</li>';
1055
-        }
1056
-        $actions['filtered_messages_link'] = '';
1057
-        // message list table link (filtered by REG_ID
1058
-        if (EE_Registry::instance()->CAP->current_user_can('ee_read_global_messages', 'view_filtered_messages')) {
1059
-            $actions['filtered_messages_link'] = '<li>'
1060
-                                                 . EEH_MSG_Template::get_message_action_link(
1061
-                                                     'see_notifications_for',
1062
-                                                     null,
1063
-                                                     array('_REG_ID' => $item->ID())
1064
-                                                 ) . '</li>';
1065
-        }
1066
-        $actions = apply_filters('FHEE__EE_Registrations_List_Table__column_actions__actions', $actions, $item, $this);
1067
-        return $this->_action_string(implode('', $actions), $item, 'ul', 'reg-overview-actions-ul');
1068
-    }
1055
+		}
1056
+		$actions['filtered_messages_link'] = '';
1057
+		// message list table link (filtered by REG_ID
1058
+		if (EE_Registry::instance()->CAP->current_user_can('ee_read_global_messages', 'view_filtered_messages')) {
1059
+			$actions['filtered_messages_link'] = '<li>'
1060
+												 . EEH_MSG_Template::get_message_action_link(
1061
+													 'see_notifications_for',
1062
+													 null,
1063
+													 array('_REG_ID' => $item->ID())
1064
+												 ) . '</li>';
1065
+		}
1066
+		$actions = apply_filters('FHEE__EE_Registrations_List_Table__column_actions__actions', $actions, $item, $this);
1067
+		return $this->_action_string(implode('', $actions), $item, 'ul', 'reg-overview-actions-ul');
1068
+	}
1069 1069
 }
Please login to merge, or discard this patch.
admin_pages/registrations/Registrations_Admin_Page.core.php 1 patch
Indentation   +3705 added lines, -3705 removed lines patch added patch discarded remove patch
@@ -18,2227 +18,2227 @@  discard block
 block discarded – undo
18 18
 class Registrations_Admin_Page extends EE_Admin_Page_CPT
19 19
 {
20 20
 
21
-    /**
22
-     * @var EE_Registration
23
-     */
24
-    private $_registration;
25
-
26
-    /**
27
-     * @var EE_Event
28
-     */
29
-    private $_reg_event;
30
-
31
-    /**
32
-     * @var EE_Session
33
-     */
34
-    private $_session;
35
-
36
-    private static $_reg_status;
37
-
38
-    /**
39
-     * Form for displaying the custom questions for this registration.
40
-     * This gets used a few times throughout the request so its best to cache it
41
-     *
42
-     * @var EE_Registration_Custom_Questions_Form
43
-     */
44
-    protected $_reg_custom_questions_form;
45
-
46
-    /**
47
-     * @var EEM_Registration $registration_model
48
-     */
49
-    private $registration_model;
50
-
51
-    /**
52
-     * @var EEM_Attendee $attendee_model
53
-     */
54
-    private $attendee_model;
55
-
56
-    /**
57
-     * @var EEM_Event $event_model
58
-     */
59
-    private $event_model;
60
-
61
-    /**
62
-     * @var EEM_Status $status_model
63
-     */
64
-    private $status_model;
65
-
66
-
67
-    /**
68
-     * @param bool $routing
69
-     * @throws EE_Error
70
-     * @throws InvalidArgumentException
71
-     * @throws InvalidDataTypeException
72
-     * @throws InvalidInterfaceException
73
-     * @throws ReflectionException
74
-     */
75
-    public function __construct($routing = true)
76
-    {
77
-        parent::__construct($routing);
78
-        add_action('wp_loaded', array($this, 'wp_loaded'));
79
-    }
80
-
81
-    /**
82
-     * @return EEM_Registration
83
-     * @throws InvalidArgumentException
84
-     * @throws InvalidDataTypeException
85
-     * @throws InvalidInterfaceException
86
-     * @since 4.10.2.p
87
-     */
88
-    protected function getRegistrationModel()
89
-    {
90
-        if (! $this->registration_model instanceof EEM_Registration) {
91
-            $this->registration_model = $this->loader->getShared('EEM_Registration');
92
-        }
93
-        return $this->registration_model;
94
-    }
95
-
96
-    /**
97
-     * @return EEM_Attendee
98
-     * @throws InvalidArgumentException
99
-     * @throws InvalidDataTypeException
100
-     * @throws InvalidInterfaceException
101
-     * @since 4.10.2.p
102
-     */
103
-    protected function getAttendeeModel()
104
-    {
105
-        if (! $this->attendee_model instanceof EEM_Attendee) {
106
-            $this->attendee_model = $this->loader->getShared('EEM_Attendee');
107
-        }
108
-        return $this->attendee_model;
109
-    }
110
-
111
-
112
-    /**
113
-     * @return EEM_Event
114
-     * @throws InvalidArgumentException
115
-     * @throws InvalidDataTypeException
116
-     * @throws InvalidInterfaceException
117
-     * @since 4.10.2.p
118
-     */
119
-    protected function getEventModel()
120
-    {
121
-        if (! $this->event_model instanceof EEM_Event) {
122
-            $this->event_model = $this->loader->getShared('EEM_Event');
123
-        }
124
-        return $this->event_model;
125
-    }
126
-
127
-    /**
128
-     * @return EEM_Status
129
-     * @throws InvalidArgumentException
130
-     * @throws InvalidDataTypeException
131
-     * @throws InvalidInterfaceException
132
-     * @since 4.10.2.p
133
-     */
134
-    protected function getStatusModel()
135
-    {
136
-        if (! $this->status_model instanceof EEM_Status) {
137
-            $this->status_model = $this->loader->getShared('EEM_Status');
138
-        }
139
-        return $this->status_model;
140
-    }
141
-
142
-
143
-    public function wp_loaded()
144
-    {
145
-        // when adding a new registration...
146
-        if (isset($this->_req_data['action']) && $this->_req_data['action'] === 'new_registration') {
147
-            EE_System::do_not_cache();
148
-            if (! isset($this->_req_data['processing_registration'])
149
-                || absint($this->_req_data['processing_registration']) !== 1
150
-            ) {
151
-                // and it's NOT the attendee information reg step
152
-                // force cookie expiration by setting time to last week
153
-                setcookie('ee_registration_added', 0, time() - WEEK_IN_SECONDS, '/');
154
-                // and update the global
155
-                $_COOKIE['ee_registration_added'] = 0;
156
-            }
157
-        }
158
-    }
159
-
160
-
161
-    protected function _init_page_props()
162
-    {
163
-        $this->page_slug = REG_PG_SLUG;
164
-        $this->_admin_base_url = REG_ADMIN_URL;
165
-        $this->_admin_base_path = REG_ADMIN;
166
-        $this->page_label = esc_html__('Registrations', 'event_espresso');
167
-        $this->_cpt_routes = array(
168
-            'add_new_attendee' => 'espresso_attendees',
169
-            'edit_attendee'    => 'espresso_attendees',
170
-            'insert_attendee'  => 'espresso_attendees',
171
-            'update_attendee'  => 'espresso_attendees',
172
-        );
173
-        $this->_cpt_model_names = array(
174
-            'add_new_attendee' => 'EEM_Attendee',
175
-            'edit_attendee'    => 'EEM_Attendee',
176
-        );
177
-        $this->_cpt_edit_routes = array(
178
-            'espresso_attendees' => 'edit_attendee',
179
-        );
180
-        $this->_pagenow_map = array(
181
-            'add_new_attendee' => 'post-new.php',
182
-            'edit_attendee'    => 'post.php',
183
-            'trash'            => 'post.php',
184
-        );
185
-        add_action('edit_form_after_title', array($this, 'after_title_form_fields'), 10);
186
-        // add filters so that the comment urls don't take users to a confusing 404 page
187
-        add_filter('get_comment_link', array($this, 'clear_comment_link'), 10, 3);
188
-    }
189
-
190
-
191
-    public function clear_comment_link($link, $comment, $args)
192
-    {
193
-        // gotta make sure this only happens on this route
194
-        $post_type = get_post_type($comment->comment_post_ID);
195
-        if ($post_type === 'espresso_attendees') {
196
-            return '#commentsdiv';
197
-        }
198
-        return $link;
199
-    }
200
-
201
-
202
-    protected function _ajax_hooks()
203
-    {
204
-        // todo: all hooks for registrations ajax goes in here
205
-        add_action('wp_ajax_toggle_checkin_status', array($this, 'toggle_checkin_status'));
206
-    }
207
-
208
-
209
-    protected function _define_page_props()
210
-    {
211
-        $this->_admin_page_title = $this->page_label;
212
-        $this->_labels = array(
213
-            'buttons'                      => array(
214
-                'add-registrant'      => esc_html__('Add New Registration', 'event_espresso'),
215
-                'add-attendee'        => esc_html__('Add Contact', 'event_espresso'),
216
-                'edit'                => esc_html__('Edit Contact', 'event_espresso'),
217
-                'report'              => esc_html__('Event Registrations CSV Report', 'event_espresso'),
218
-                'report_all'          => esc_html__('All Registrations CSV Report', 'event_espresso'),
219
-                'report_filtered'     => esc_html__('Filtered CSV Report', 'event_espresso'),
220
-                'contact_list_report' => esc_html__('Contact List Report', 'event_espresso'),
221
-                'contact_list_export' => esc_html__('Export Data', 'event_espresso'),
222
-            ),
223
-            'publishbox'                   => array(
224
-                'add_new_attendee' => esc_html__('Add Contact Record', 'event_espresso'),
225
-                'edit_attendee'    => esc_html__('Update Contact Record', 'event_espresso'),
226
-            ),
227
-            'hide_add_button_on_cpt_route' => array(
228
-                'edit_attendee' => true,
229
-            ),
230
-        );
231
-    }
232
-
233
-
234
-    /**
235
-     *        grab url requests and route them
236
-     *
237
-     * @access private
238
-     * @return void
239
-     * @throws EE_Error
240
-     */
241
-    public function _set_page_routes()
242
-    {
243
-        $this->_get_registration_status_array();
244
-        $reg_id = ! empty($this->_req_data['_REG_ID']) && ! is_array($this->_req_data['_REG_ID'])
245
-            ? $this->_req_data['_REG_ID'] : 0;
246
-        $reg_id = empty($reg_id) && ! empty($this->_req_data['reg_status_change_form']['REG_ID'])
247
-            ? $this->_req_data['reg_status_change_form']['REG_ID']
248
-            : $reg_id;
249
-        $att_id = ! empty($this->_req_data['ATT_ID']) && ! is_array($this->_req_data['ATT_ID'])
250
-            ? $this->_req_data['ATT_ID'] : 0;
251
-        $att_id = ! empty($this->_req_data['post']) && ! is_array($this->_req_data['post'])
252
-            ? $this->_req_data['post']
253
-            : $att_id;
254
-        $this->_page_routes = array(
255
-            'default'                             => array(
256
-                'func'       => '_registrations_overview_list_table',
257
-                'capability' => 'ee_read_registrations',
258
-            ),
259
-            'view_registration'                   => array(
260
-                'func'       => '_registration_details',
261
-                'capability' => 'ee_read_registration',
262
-                'obj_id'     => $reg_id,
263
-            ),
264
-            'edit_registration'                   => array(
265
-                'func'               => '_update_attendee_registration_form',
266
-                'noheader'           => true,
267
-                'headers_sent_route' => 'view_registration',
268
-                'capability'         => 'ee_edit_registration',
269
-                'obj_id'             => $reg_id,
270
-                '_REG_ID'            => $reg_id,
271
-            ),
272
-            'trash_registrations'                 => array(
273
-                'func'       => '_trash_or_restore_registrations',
274
-                'args'       => array('trash' => true),
275
-                'noheader'   => true,
276
-                'capability' => 'ee_delete_registrations',
277
-            ),
278
-            'restore_registrations'               => array(
279
-                'func'       => '_trash_or_restore_registrations',
280
-                'args'       => array('trash' => false),
281
-                'noheader'   => true,
282
-                'capability' => 'ee_delete_registrations',
283
-            ),
284
-            'delete_registrations'                => array(
285
-                'func'       => '_delete_registrations',
286
-                'noheader'   => true,
287
-                'capability' => 'ee_delete_registrations',
288
-            ),
289
-            'new_registration'                    => array(
290
-                'func'       => 'new_registration',
291
-                'capability' => 'ee_edit_registrations',
292
-            ),
293
-            'process_reg_step'                    => array(
294
-                'func'       => 'process_reg_step',
295
-                'noheader'   => true,
296
-                'capability' => 'ee_edit_registrations',
297
-            ),
298
-            'redirect_to_txn'                     => array(
299
-                'func'       => 'redirect_to_txn',
300
-                'noheader'   => true,
301
-                'capability' => 'ee_edit_registrations',
302
-            ),
303
-            'change_reg_status'                   => array(
304
-                'func'       => '_change_reg_status',
305
-                'noheader'   => true,
306
-                'capability' => 'ee_edit_registration',
307
-                'obj_id'     => $reg_id,
308
-            ),
309
-            'approve_registration'                => array(
310
-                'func'       => 'approve_registration',
311
-                'noheader'   => true,
312
-                'capability' => 'ee_edit_registration',
313
-                'obj_id'     => $reg_id,
314
-            ),
315
-            'approve_and_notify_registration'     => array(
316
-                'func'       => 'approve_registration',
317
-                'noheader'   => true,
318
-                'args'       => array(true),
319
-                'capability' => 'ee_edit_registration',
320
-                'obj_id'     => $reg_id,
321
-            ),
322
-            'approve_registrations'               => array(
323
-                'func'       => 'bulk_action_on_registrations',
324
-                'noheader'   => true,
325
-                'capability' => 'ee_edit_registrations',
326
-                'args'       => array('approve'),
327
-            ),
328
-            'approve_and_notify_registrations'    => array(
329
-                'func'       => 'bulk_action_on_registrations',
330
-                'noheader'   => true,
331
-                'capability' => 'ee_edit_registrations',
332
-                'args'       => array('approve', true),
333
-            ),
334
-            'decline_registration'                => array(
335
-                'func'       => 'decline_registration',
336
-                'noheader'   => true,
337
-                'capability' => 'ee_edit_registration',
338
-                'obj_id'     => $reg_id,
339
-            ),
340
-            'decline_and_notify_registration'     => array(
341
-                'func'       => 'decline_registration',
342
-                'noheader'   => true,
343
-                'args'       => array(true),
344
-                'capability' => 'ee_edit_registration',
345
-                'obj_id'     => $reg_id,
346
-            ),
347
-            'decline_registrations'               => array(
348
-                'func'       => 'bulk_action_on_registrations',
349
-                'noheader'   => true,
350
-                'capability' => 'ee_edit_registrations',
351
-                'args'       => array('decline'),
352
-            ),
353
-            'decline_and_notify_registrations'    => array(
354
-                'func'       => 'bulk_action_on_registrations',
355
-                'noheader'   => true,
356
-                'capability' => 'ee_edit_registrations',
357
-                'args'       => array('decline', true),
358
-            ),
359
-            'pending_registration'                => array(
360
-                'func'       => 'pending_registration',
361
-                'noheader'   => true,
362
-                'capability' => 'ee_edit_registration',
363
-                'obj_id'     => $reg_id,
364
-            ),
365
-            'pending_and_notify_registration'     => array(
366
-                'func'       => 'pending_registration',
367
-                'noheader'   => true,
368
-                'args'       => array(true),
369
-                'capability' => 'ee_edit_registration',
370
-                'obj_id'     => $reg_id,
371
-            ),
372
-            'pending_registrations'               => array(
373
-                'func'       => 'bulk_action_on_registrations',
374
-                'noheader'   => true,
375
-                'capability' => 'ee_edit_registrations',
376
-                'args'       => array('pending'),
377
-            ),
378
-            'pending_and_notify_registrations'    => array(
379
-                'func'       => 'bulk_action_on_registrations',
380
-                'noheader'   => true,
381
-                'capability' => 'ee_edit_registrations',
382
-                'args'       => array('pending', true),
383
-            ),
384
-            'no_approve_registration'             => array(
385
-                'func'       => 'not_approve_registration',
386
-                'noheader'   => true,
387
-                'capability' => 'ee_edit_registration',
388
-                'obj_id'     => $reg_id,
389
-            ),
390
-            'no_approve_and_notify_registration'  => array(
391
-                'func'       => 'not_approve_registration',
392
-                'noheader'   => true,
393
-                'args'       => array(true),
394
-                'capability' => 'ee_edit_registration',
395
-                'obj_id'     => $reg_id,
396
-            ),
397
-            'no_approve_registrations'            => array(
398
-                'func'       => 'bulk_action_on_registrations',
399
-                'noheader'   => true,
400
-                'capability' => 'ee_edit_registrations',
401
-                'args'       => array('not_approve'),
402
-            ),
403
-            'no_approve_and_notify_registrations' => array(
404
-                'func'       => 'bulk_action_on_registrations',
405
-                'noheader'   => true,
406
-                'capability' => 'ee_edit_registrations',
407
-                'args'       => array('not_approve', true),
408
-            ),
409
-            'cancel_registration'                 => array(
410
-                'func'       => 'cancel_registration',
411
-                'noheader'   => true,
412
-                'capability' => 'ee_edit_registration',
413
-                'obj_id'     => $reg_id,
414
-            ),
415
-            'cancel_and_notify_registration'      => array(
416
-                'func'       => 'cancel_registration',
417
-                'noheader'   => true,
418
-                'args'       => array(true),
419
-                'capability' => 'ee_edit_registration',
420
-                'obj_id'     => $reg_id,
421
-            ),
422
-            'cancel_registrations'                => array(
423
-                'func'       => 'bulk_action_on_registrations',
424
-                'noheader'   => true,
425
-                'capability' => 'ee_edit_registrations',
426
-                'args'       => array('cancel'),
427
-            ),
428
-            'cancel_and_notify_registrations'     => array(
429
-                'func'       => 'bulk_action_on_registrations',
430
-                'noheader'   => true,
431
-                'capability' => 'ee_edit_registrations',
432
-                'args'       => array('cancel', true),
433
-            ),
434
-            'wait_list_registration'              => array(
435
-                'func'       => 'wait_list_registration',
436
-                'noheader'   => true,
437
-                'capability' => 'ee_edit_registration',
438
-                'obj_id'     => $reg_id,
439
-            ),
440
-            'wait_list_and_notify_registration'   => array(
441
-                'func'       => 'wait_list_registration',
442
-                'noheader'   => true,
443
-                'args'       => array(true),
444
-                'capability' => 'ee_edit_registration',
445
-                'obj_id'     => $reg_id,
446
-            ),
447
-            'contact_list'                        => array(
448
-                'func'       => '_attendee_contact_list_table',
449
-                'capability' => 'ee_read_contacts',
450
-            ),
451
-            'add_new_attendee'                    => array(
452
-                'func' => '_create_new_cpt_item',
453
-                'args' => array(
454
-                    'new_attendee' => true,
455
-                    'capability'   => 'ee_edit_contacts',
456
-                ),
457
-            ),
458
-            'edit_attendee'                       => array(
459
-                'func'       => '_edit_cpt_item',
460
-                'capability' => 'ee_edit_contacts',
461
-                'obj_id'     => $att_id,
462
-            ),
463
-            'duplicate_attendee'                  => array(
464
-                'func'       => '_duplicate_attendee',
465
-                'noheader'   => true,
466
-                'capability' => 'ee_edit_contacts',
467
-                'obj_id'     => $att_id,
468
-            ),
469
-            'insert_attendee'                     => array(
470
-                'func'       => '_insert_or_update_attendee',
471
-                'args'       => array(
472
-                    'new_attendee' => true,
473
-                ),
474
-                'noheader'   => true,
475
-                'capability' => 'ee_edit_contacts',
476
-            ),
477
-            'update_attendee'                     => array(
478
-                'func'       => '_insert_or_update_attendee',
479
-                'args'       => array(
480
-                    'new_attendee' => false,
481
-                ),
482
-                'noheader'   => true,
483
-                'capability' => 'ee_edit_contacts',
484
-                'obj_id'     => $att_id,
485
-            ),
486
-            'trash_attendees'                     => array(
487
-                'func'       => '_trash_or_restore_attendees',
488
-                'args'       => array(
489
-                    'trash' => 'true',
490
-                ),
491
-                'noheader'   => true,
492
-                'capability' => 'ee_delete_contacts',
493
-            ),
494
-            'trash_attendee'                      => array(
495
-                'func'       => '_trash_or_restore_attendees',
496
-                'args'       => array(
497
-                    'trash' => true,
498
-                ),
499
-                'noheader'   => true,
500
-                'capability' => 'ee_delete_contacts',
501
-                'obj_id'     => $att_id,
502
-            ),
503
-            'restore_attendees'                   => array(
504
-                'func'       => '_trash_or_restore_attendees',
505
-                'args'       => array(
506
-                    'trash' => false,
507
-                ),
508
-                'noheader'   => true,
509
-                'capability' => 'ee_delete_contacts',
510
-                'obj_id'     => $att_id,
511
-            ),
512
-            'resend_registration'                 => array(
513
-                'func'       => '_resend_registration',
514
-                'noheader'   => true,
515
-                'capability' => 'ee_send_message',
516
-            ),
517
-            'registrations_report'                => array(
518
-                'func'       => '_registrations_report',
519
-                'noheader'   => true,
520
-                'capability' => 'ee_read_registrations',
521
-            ),
522
-            'contact_list_export'                 => array(
523
-                'func'       => '_contact_list_export',
524
-                'noheader'   => true,
525
-                'capability' => 'export',
526
-            ),
527
-            'contact_list_report'                 => array(
528
-                'func'       => '_contact_list_report',
529
-                'noheader'   => true,
530
-                'capability' => 'ee_read_contacts',
531
-            ),
532
-        );
533
-    }
534
-
535
-
536
-    protected function _set_page_config()
537
-    {
538
-        $this->_page_config = array(
539
-            'default'           => array(
540
-                'nav'           => array(
541
-                    'label' => esc_html__('Overview', 'event_espresso'),
542
-                    'order' => 5,
543
-                ),
544
-                'help_tabs'     => array(
545
-                    'registrations_overview_help_tab'                       => array(
546
-                        'title'    => esc_html__('Registrations Overview', 'event_espresso'),
547
-                        'filename' => 'registrations_overview',
548
-                    ),
549
-                    'registrations_overview_table_column_headings_help_tab' => array(
550
-                        'title'    => esc_html__('Registrations Table Column Headings', 'event_espresso'),
551
-                        'filename' => 'registrations_overview_table_column_headings',
552
-                    ),
553
-                    'registrations_overview_filters_help_tab'               => array(
554
-                        'title'    => esc_html__('Registration Filters', 'event_espresso'),
555
-                        'filename' => 'registrations_overview_filters',
556
-                    ),
557
-                    'registrations_overview_views_help_tab'                 => array(
558
-                        'title'    => esc_html__('Registration Views', 'event_espresso'),
559
-                        'filename' => 'registrations_overview_views',
560
-                    ),
561
-                    'registrations_regoverview_other_help_tab'              => array(
562
-                        'title'    => esc_html__('Registrations Other', 'event_espresso'),
563
-                        'filename' => 'registrations_overview_other',
564
-                    ),
565
-                ),
566
-                'help_tour'     => array('Registration_Overview_Help_Tour'),
567
-                'qtips'         => array('Registration_List_Table_Tips'),
568
-                'list_table'    => 'EE_Registrations_List_Table',
569
-                'require_nonce' => false,
570
-            ),
571
-            'view_registration' => array(
572
-                'nav'           => array(
573
-                    'label'      => esc_html__('REG Details', 'event_espresso'),
574
-                    'order'      => 15,
575
-                    'url'        => isset($this->_req_data['_REG_ID'])
576
-                        ? add_query_arg(array('_REG_ID' => $this->_req_data['_REG_ID']), $this->_current_page_view_url)
577
-                        : $this->_admin_base_url,
578
-                    'persistent' => false,
579
-                ),
580
-                'help_tabs'     => array(
581
-                    'registrations_details_help_tab'                    => array(
582
-                        'title'    => esc_html__('Registration Details', 'event_espresso'),
583
-                        'filename' => 'registrations_details',
584
-                    ),
585
-                    'registrations_details_table_help_tab'              => array(
586
-                        'title'    => esc_html__('Registration Details Table', 'event_espresso'),
587
-                        'filename' => 'registrations_details_table',
588
-                    ),
589
-                    'registrations_details_form_answers_help_tab'       => array(
590
-                        'title'    => esc_html__('Registration Form Answers', 'event_espresso'),
591
-                        'filename' => 'registrations_details_form_answers',
592
-                    ),
593
-                    'registrations_details_registrant_details_help_tab' => array(
594
-                        'title'    => esc_html__('Contact Details', 'event_espresso'),
595
-                        'filename' => 'registrations_details_registrant_details',
596
-                    ),
597
-                ),
598
-                'help_tour'     => array('Registration_Details_Help_Tour'),
599
-                'metaboxes'     => array_merge(
600
-                    $this->_default_espresso_metaboxes,
601
-                    array('_registration_details_metaboxes')
602
-                ),
603
-                'require_nonce' => false,
604
-            ),
605
-            'new_registration'  => array(
606
-                'nav'           => array(
607
-                    'label'      => esc_html__('Add New Registration', 'event_espresso'),
608
-                    'url'        => '#',
609
-                    'order'      => 15,
610
-                    'persistent' => false,
611
-                ),
612
-                'metaboxes'     => $this->_default_espresso_metaboxes,
613
-                'labels'        => array(
614
-                    'publishbox' => esc_html__('Save Registration', 'event_espresso'),
615
-                ),
616
-                'require_nonce' => false,
617
-            ),
618
-            'add_new_attendee'  => array(
619
-                'nav'           => array(
620
-                    'label'      => esc_html__('Add Contact', 'event_espresso'),
621
-                    'order'      => 15,
622
-                    'persistent' => false,
623
-                ),
624
-                'metaboxes'     => array_merge(
625
-                    $this->_default_espresso_metaboxes,
626
-                    array('_publish_post_box', 'attendee_editor_metaboxes')
627
-                ),
628
-                'require_nonce' => false,
629
-            ),
630
-            'edit_attendee'     => array(
631
-                'nav'           => array(
632
-                    'label'      => esc_html__('Edit Contact', 'event_espresso'),
633
-                    'order'      => 15,
634
-                    'persistent' => false,
635
-                    'url'        => isset($this->_req_data['ATT_ID'])
636
-                        ? add_query_arg(array('ATT_ID' => $this->_req_data['ATT_ID']), $this->_current_page_view_url)
637
-                        : $this->_admin_base_url,
638
-                ),
639
-                'metaboxes'     => array('attendee_editor_metaboxes'),
640
-                'require_nonce' => false,
641
-            ),
642
-            'contact_list'      => array(
643
-                'nav'           => array(
644
-                    'label' => esc_html__('Contact List', 'event_espresso'),
645
-                    'order' => 20,
646
-                ),
647
-                'list_table'    => 'EE_Attendee_Contact_List_Table',
648
-                'help_tabs'     => array(
649
-                    'registrations_contact_list_help_tab'                       => array(
650
-                        'title'    => esc_html__('Registrations Contact List', 'event_espresso'),
651
-                        'filename' => 'registrations_contact_list',
652
-                    ),
653
-                    'registrations_contact-list_table_column_headings_help_tab' => array(
654
-                        'title'    => esc_html__('Contact List Table Column Headings', 'event_espresso'),
655
-                        'filename' => 'registrations_contact_list_table_column_headings',
656
-                    ),
657
-                    'registrations_contact_list_views_help_tab'                 => array(
658
-                        'title'    => esc_html__('Contact List Views', 'event_espresso'),
659
-                        'filename' => 'registrations_contact_list_views',
660
-                    ),
661
-                    'registrations_contact_list_other_help_tab'                 => array(
662
-                        'title'    => esc_html__('Contact List Other', 'event_espresso'),
663
-                        'filename' => 'registrations_contact_list_other',
664
-                    ),
665
-                ),
666
-                'help_tour'     => array('Contact_List_Help_Tour'),
667
-                'metaboxes'     => array(),
668
-                'require_nonce' => false,
669
-            ),
670
-            // override default cpt routes
671
-            'create_new'        => '',
672
-            'edit'              => '',
673
-        );
674
-    }
675
-
676
-
677
-    /**
678
-     * The below methods aren't used by this class currently
679
-     */
680
-    protected function _add_screen_options()
681
-    {
682
-    }
683
-
684
-
685
-    protected function _add_feature_pointers()
686
-    {
687
-    }
688
-
689
-
690
-    public function admin_init()
691
-    {
692
-        EE_Registry::$i18n_js_strings['update_att_qstns'] = esc_html__(
693
-            'click "Update Registration Questions" to save your changes',
694
-            'event_espresso'
695
-        );
696
-    }
697
-
698
-
699
-    public function admin_notices()
700
-    {
701
-    }
702
-
703
-
704
-    public function admin_footer_scripts()
705
-    {
706
-    }
707
-
708
-
709
-    /**
710
-     *        get list of registration statuses
711
-     *
712
-     * @access private
713
-     * @return void
714
-     * @throws EE_Error
715
-     */
716
-    private function _get_registration_status_array()
717
-    {
718
-        self::$_reg_status = EEM_Registration::reg_status_array(array(), true);
719
-    }
720
-
721
-
722
-    /**
723
-     * @throws InvalidArgumentException
724
-     * @throws InvalidDataTypeException
725
-     * @throws InvalidInterfaceException
726
-     * @since 4.10.2.p
727
-     */
728
-    protected function _add_screen_options_default()
729
-    {
730
-        $this->_per_page_screen_option();
731
-    }
732
-
733
-
734
-    /**
735
-     * @throws InvalidArgumentException
736
-     * @throws InvalidDataTypeException
737
-     * @throws InvalidInterfaceException
738
-     * @since 4.10.2.p
739
-     */
740
-    protected function _add_screen_options_contact_list()
741
-    {
742
-        $page_title = $this->_admin_page_title;
743
-        $this->_admin_page_title = esc_html__('Contacts', 'event_espresso');
744
-        $this->_per_page_screen_option();
745
-        $this->_admin_page_title = $page_title;
746
-    }
747
-
748
-
749
-    public function load_scripts_styles()
750
-    {
751
-        // style
752
-        wp_register_style(
753
-            'espresso_reg',
754
-            REG_ASSETS_URL . 'espresso_registrations_admin.css',
755
-            array('ee-admin-css'),
756
-            EVENT_ESPRESSO_VERSION
757
-        );
758
-        wp_enqueue_style('espresso_reg');
759
-        // script
760
-        wp_register_script(
761
-            'espresso_reg',
762
-            REG_ASSETS_URL . 'espresso_registrations_admin.js',
763
-            array('jquery-ui-datepicker', 'jquery-ui-draggable', 'ee_admin_js'),
764
-            EVENT_ESPRESSO_VERSION,
765
-            true
766
-        );
767
-        wp_enqueue_script('espresso_reg');
768
-    }
769
-
770
-
771
-    /**
772
-     * @throws EE_Error
773
-     * @throws InvalidArgumentException
774
-     * @throws InvalidDataTypeException
775
-     * @throws InvalidInterfaceException
776
-     * @throws ReflectionException
777
-     * @since 4.10.2.p
778
-     */
779
-    public function load_scripts_styles_edit_attendee()
780
-    {
781
-        // stuff to only show up on our attendee edit details page.
782
-        $attendee_details_translations = array(
783
-            'att_publish_text' => sprintf(
784
-                /* translators: The date and time */
785
-                wp_strip_all_tags(__('Created on: %s', 'event_espresso')),
786
-                '<b>' . $this->_cpt_model_obj->get_datetime('ATT_created') . '</b>'
787
-            ),
788
-        );
789
-        wp_localize_script('espresso_reg', 'ATTENDEE_DETAILS', $attendee_details_translations);
790
-        wp_enqueue_script('jquery-validate');
791
-    }
792
-
793
-
794
-    /**
795
-     * @throws EE_Error
796
-     * @throws InvalidArgumentException
797
-     * @throws InvalidDataTypeException
798
-     * @throws InvalidInterfaceException
799
-     * @throws ReflectionException
800
-     * @since 4.10.2.p
801
-     */
802
-    public function load_scripts_styles_view_registration()
803
-    {
804
-        // styles
805
-        wp_enqueue_style('espresso-ui-theme');
806
-        // scripts
807
-        $this->_get_reg_custom_questions_form($this->_registration->ID());
808
-        $this->_reg_custom_questions_form->wp_enqueue_scripts(true);
809
-    }
810
-
811
-
812
-    public function load_scripts_styles_contact_list()
813
-    {
814
-        wp_dequeue_style('espresso_reg');
815
-        wp_register_style(
816
-            'espresso_att',
817
-            REG_ASSETS_URL . 'espresso_attendees_admin.css',
818
-            array('ee-admin-css'),
819
-            EVENT_ESPRESSO_VERSION
820
-        );
821
-        wp_enqueue_style('espresso_att');
822
-    }
823
-
824
-
825
-    public function load_scripts_styles_new_registration()
826
-    {
827
-        wp_register_script(
828
-            'ee-spco-for-admin',
829
-            REG_ASSETS_URL . 'spco_for_admin.js',
830
-            array('underscore', 'jquery'),
831
-            EVENT_ESPRESSO_VERSION,
832
-            true
833
-        );
834
-        wp_enqueue_script('ee-spco-for-admin');
835
-        add_filter('FHEE__EED_Ticket_Selector__load_tckt_slctr_assets', '__return_true');
836
-        EE_Form_Section_Proper::wp_enqueue_scripts();
837
-        EED_Ticket_Selector::load_tckt_slctr_assets();
838
-        EE_Datepicker_Input::enqueue_styles_and_scripts();
839
-    }
840
-
841
-
842
-    public function AHEE__EE_Admin_Page__route_admin_request_resend_registration()
843
-    {
844
-        add_filter('FHEE_load_EE_messages', '__return_true');
845
-    }
846
-
847
-
848
-    public function AHEE__EE_Admin_Page__route_admin_request_approve_registration()
849
-    {
850
-        add_filter('FHEE_load_EE_messages', '__return_true');
851
-    }
852
-
853
-
854
-    /**
855
-     * @throws EE_Error
856
-     * @throws InvalidArgumentException
857
-     * @throws InvalidDataTypeException
858
-     * @throws InvalidInterfaceException
859
-     * @throws ReflectionException
860
-     * @since 4.10.2.p
861
-     */
862
-    protected function _set_list_table_views_default()
863
-    {
864
-        // for notification related bulk actions we need to make sure only active messengers have an option.
865
-        EED_Messages::set_autoloaders();
866
-        /** @type EE_Message_Resource_Manager $message_resource_manager */
867
-        $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
868
-        $active_mts = $message_resource_manager->list_of_active_message_types();
869
-        // key= bulk_action_slug, value= message type.
870
-        $match_array = array(
871
-            'approve_registrations'    => 'registration',
872
-            'decline_registrations'    => 'declined_registration',
873
-            'pending_registrations'    => 'pending_approval',
874
-            'no_approve_registrations' => 'not_approved_registration',
875
-            'cancel_registrations'     => 'cancelled_registration',
876
-        );
877
-        $can_send = EE_Registry::instance()->CAP->current_user_can(
878
-            'ee_send_message',
879
-            'batch_send_messages'
880
-        );
881
-        /** setup reg status bulk actions **/
882
-        $def_reg_status_actions['approve_registrations'] = esc_html__('Approve Registrations', 'event_espresso');
883
-        if ($can_send && in_array($match_array['approve_registrations'], $active_mts, true)) {
884
-            $def_reg_status_actions['approve_and_notify_registrations'] = esc_html__(
885
-                'Approve and Notify Registrations',
886
-                'event_espresso'
887
-            );
888
-        }
889
-        $def_reg_status_actions['decline_registrations'] = esc_html__('Decline Registrations', 'event_espresso');
890
-        if ($can_send && in_array($match_array['decline_registrations'], $active_mts, true)) {
891
-            $def_reg_status_actions['decline_and_notify_registrations'] = esc_html__(
892
-                'Decline and Notify Registrations',
893
-                'event_espresso'
894
-            );
895
-        }
896
-        $def_reg_status_actions['pending_registrations'] = esc_html__(
897
-            'Set Registrations to Pending Payment',
898
-            'event_espresso'
899
-        );
900
-        if ($can_send && in_array($match_array['pending_registrations'], $active_mts, true)) {
901
-            $def_reg_status_actions['pending_and_notify_registrations'] = esc_html__(
902
-                'Set Registrations to Pending Payment and Notify',
903
-                'event_espresso'
904
-            );
905
-        }
906
-        $def_reg_status_actions['no_approve_registrations'] = esc_html__(
907
-            'Set Registrations to Not Approved',
908
-            'event_espresso'
909
-        );
910
-        if ($can_send && in_array($match_array['no_approve_registrations'], $active_mts, true)) {
911
-            $def_reg_status_actions['no_approve_and_notify_registrations'] = esc_html__(
912
-                'Set Registrations to Not Approved and Notify',
913
-                'event_espresso'
914
-            );
915
-        }
916
-        $def_reg_status_actions['cancel_registrations'] = esc_html__('Cancel Registrations', 'event_espresso');
917
-        if ($can_send && in_array($match_array['cancel_registrations'], $active_mts, true)) {
918
-            $def_reg_status_actions['cancel_and_notify_registrations'] = esc_html__(
919
-                'Cancel Registrations and Notify',
920
-                'event_espresso'
921
-            );
922
-        }
923
-        $def_reg_status_actions = apply_filters(
924
-            'FHEE__Registrations_Admin_Page___set_list_table_views_default__def_reg_status_actions_array',
925
-            $def_reg_status_actions,
926
-            $active_mts,
927
-            $can_send
928
-        );
929
-
930
-        $this->_views = array(
931
-            'all'   => array(
932
-                'slug'        => 'all',
933
-                'label'       => esc_html__('View All Registrations', 'event_espresso'),
934
-                'count'       => 0,
935
-                'bulk_action' => array_merge(
936
-                    $def_reg_status_actions,
937
-                    array(
938
-                        'trash_registrations' => esc_html__('Trash Registrations', 'event_espresso'),
939
-                    )
940
-                ),
941
-            ),
942
-            'month' => array(
943
-                'slug'        => 'month',
944
-                'label'       => esc_html__('This Month', 'event_espresso'),
945
-                'count'       => 0,
946
-                'bulk_action' => array_merge(
947
-                    $def_reg_status_actions,
948
-                    array(
949
-                        'trash_registrations' => esc_html__('Trash Registrations', 'event_espresso'),
950
-                    )
951
-                ),
952
-            ),
953
-            'today' => array(
954
-                'slug'        => 'today',
955
-                'label'       => sprintf(
956
-                    esc_html__('Today - %s', 'event_espresso'),
957
-                    date('M d, Y', current_time('timestamp'))
958
-                ),
959
-                'count'       => 0,
960
-                'bulk_action' => array_merge(
961
-                    $def_reg_status_actions,
962
-                    array(
963
-                        'trash_registrations' => esc_html__('Trash Registrations', 'event_espresso'),
964
-                    )
965
-                ),
966
-            ),
967
-        );
968
-        if (EE_Registry::instance()->CAP->current_user_can(
969
-            'ee_delete_registrations',
970
-            'espresso_registrations_delete_registration'
971
-        )) {
972
-            $this->_views['incomplete'] = array(
973
-                'slug'        => 'incomplete',
974
-                'label'       => esc_html__('Incomplete', 'event_espresso'),
975
-                'count'       => 0,
976
-                'bulk_action' => array(
977
-                    'trash_registrations' => esc_html__('Trash Registrations', 'event_espresso'),
978
-                ),
979
-            );
980
-            $this->_views['trash'] = array(
981
-                'slug'        => 'trash',
982
-                'label'       => esc_html__('Trash', 'event_espresso'),
983
-                'count'       => 0,
984
-                'bulk_action' => array(
985
-                    'restore_registrations' => esc_html__('Restore Registrations', 'event_espresso'),
986
-                    'delete_registrations'  => esc_html__('Delete Registrations Permanently', 'event_espresso'),
987
-                ),
988
-            );
989
-        }
990
-    }
991
-
992
-
993
-    protected function _set_list_table_views_contact_list()
994
-    {
995
-        $this->_views = array(
996
-            'in_use' => array(
997
-                'slug'        => 'in_use',
998
-                'label'       => esc_html__('In Use', 'event_espresso'),
999
-                'count'       => 0,
1000
-                'bulk_action' => array(
1001
-                    'trash_attendees' => esc_html__('Move to Trash', 'event_espresso'),
1002
-                ),
1003
-            ),
1004
-        );
1005
-        if (EE_Registry::instance()->CAP->current_user_can(
1006
-            'ee_delete_contacts',
1007
-            'espresso_registrations_trash_attendees'
1008
-        )
1009
-        ) {
1010
-            $this->_views['trash'] = array(
1011
-                'slug'        => 'trash',
1012
-                'label'       => esc_html__('Trash', 'event_espresso'),
1013
-                'count'       => 0,
1014
-                'bulk_action' => array(
1015
-                    'restore_attendees' => esc_html__('Restore from Trash', 'event_espresso'),
1016
-                ),
1017
-            );
1018
-        }
1019
-    }
1020
-
1021
-
1022
-    protected function _registration_legend_items()
1023
-    {
1024
-        $fc_items = array(
1025
-            'star-icon'        => array(
1026
-                'class' => 'dashicons dashicons-star-filled yellow-icon ee-icon-size-8',
1027
-                'desc'  => esc_html__('This is the Primary Registrant', 'event_espresso'),
1028
-            ),
1029
-            'view_details'     => array(
1030
-                'class' => 'dashicons dashicons-clipboard',
1031
-                'desc'  => esc_html__('View Registration Details', 'event_espresso'),
1032
-            ),
1033
-            'edit_attendee'    => array(
1034
-                'class' => 'ee-icon ee-icon-user-edit ee-icon-size-16',
1035
-                'desc'  => esc_html__('Edit Contact Details', 'event_espresso'),
1036
-            ),
1037
-            'view_transaction' => array(
1038
-                'class' => 'dashicons dashicons-cart',
1039
-                'desc'  => esc_html__('View Transaction Details', 'event_espresso'),
1040
-            ),
1041
-            'view_invoice'     => array(
1042
-                'class' => 'dashicons dashicons-media-spreadsheet',
1043
-                'desc'  => esc_html__('View Transaction Invoice', 'event_espresso'),
1044
-            ),
1045
-        );
1046
-        if (EE_Registry::instance()->CAP->current_user_can(
1047
-            'ee_send_message',
1048
-            'espresso_registrations_resend_registration'
1049
-        )) {
1050
-            $fc_items['resend_registration'] = array(
1051
-                'class' => 'dashicons dashicons-email-alt',
1052
-                'desc'  => esc_html__('Resend Registration Details', 'event_espresso'),
1053
-            );
1054
-        } else {
1055
-            $fc_items['blank'] = array('class' => 'blank', 'desc' => '');
1056
-        }
1057
-        if (EE_Registry::instance()->CAP->current_user_can(
1058
-            'ee_read_global_messages',
1059
-            'view_filtered_messages'
1060
-        )) {
1061
-            $related_for_icon = EEH_MSG_Template::get_message_action_icon('see_notifications_for');
1062
-            if (is_array($related_for_icon) && isset($related_for_icon['css_class'], $related_for_icon['label'])) {
1063
-                $fc_items['view_related_messages'] = array(
1064
-                    'class' => $related_for_icon['css_class'],
1065
-                    'desc'  => $related_for_icon['label'],
1066
-                );
1067
-            }
1068
-        }
1069
-        $sc_items = array(
1070
-            'approved_status'   => array(
1071
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_approved,
1072
-                'desc'  => EEH_Template::pretty_status(
1073
-                    EEM_Registration::status_id_approved,
1074
-                    false,
1075
-                    'sentence'
1076
-                ),
1077
-            ),
1078
-            'pending_status'    => array(
1079
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_pending_payment,
1080
-                'desc'  => EEH_Template::pretty_status(
1081
-                    EEM_Registration::status_id_pending_payment,
1082
-                    false,
1083
-                    'sentence'
1084
-                ),
1085
-            ),
1086
-            'wait_list'         => array(
1087
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_wait_list,
1088
-                'desc'  => EEH_Template::pretty_status(
1089
-                    EEM_Registration::status_id_wait_list,
1090
-                    false,
1091
-                    'sentence'
1092
-                ),
1093
-            ),
1094
-            'incomplete_status' => array(
1095
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_incomplete,
1096
-                'desc'  => EEH_Template::pretty_status(
1097
-                    EEM_Registration::status_id_incomplete,
1098
-                    false,
1099
-                    'sentence'
1100
-                ),
1101
-            ),
1102
-            'not_approved'      => array(
1103
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_not_approved,
1104
-                'desc'  => EEH_Template::pretty_status(
1105
-                    EEM_Registration::status_id_not_approved,
1106
-                    false,
1107
-                    'sentence'
1108
-                ),
1109
-            ),
1110
-            'declined_status'   => array(
1111
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_declined,
1112
-                'desc'  => EEH_Template::pretty_status(
1113
-                    EEM_Registration::status_id_declined,
1114
-                    false,
1115
-                    'sentence'
1116
-                ),
1117
-            ),
1118
-            'cancelled_status'  => array(
1119
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_cancelled,
1120
-                'desc'  => EEH_Template::pretty_status(
1121
-                    EEM_Registration::status_id_cancelled,
1122
-                    false,
1123
-                    'sentence'
1124
-                ),
1125
-            ),
1126
-        );
1127
-        return array_merge($fc_items, $sc_items);
1128
-    }
1129
-
1130
-
1131
-
1132
-    /***************************************        REGISTRATION OVERVIEW        **************************************/
1133
-
1134
-
1135
-
1136
-    /**
1137
-     * @throws DomainException
1138
-     * @throws EE_Error
1139
-     * @throws InvalidArgumentException
1140
-     * @throws InvalidDataTypeException
1141
-     * @throws InvalidInterfaceException
1142
-     * @throws ReflectionException
1143
-     */
1144
-    protected function _registrations_overview_list_table()
1145
-    {
1146
-        $this->appendAddNewRegistrationButtonToPageTitle();
1147
-        $header_text = '';
1148
-        $admin_page_header_decorators = [
1149
-            'EventEspresso\core\domain\services\admin\registrations\list_table\page_header\AttendeeFilterHeader',
1150
-            'EventEspresso\core\domain\services\admin\registrations\list_table\page_header\EventFilterHeader',
1151
-            'EventEspresso\core\domain\services\admin\registrations\list_table\page_header\DateFilterHeader',
1152
-            'EventEspresso\core\domain\services\admin\registrations\list_table\page_header\TicketFilterHeader',
1153
-        ];
1154
-        foreach ($admin_page_header_decorators as $admin_page_header_decorator) {
1155
-            $filter_header_decorator = $this->loader->getNew($admin_page_header_decorator);
1156
-            $header_text = $filter_header_decorator->getHeaderText($header_text);
1157
-        }
1158
-        $this->_template_args['admin_page_header'] = $header_text;
1159
-        $this->_template_args['after_list_table'] = $this->_display_legend($this->_registration_legend_items());
1160
-        $this->display_admin_list_table_page_with_no_sidebar();
1161
-    }
1162
-
1163
-
1164
-    /**
1165
-     * @throws EE_Error
1166
-     * @throws InvalidArgumentException
1167
-     * @throws InvalidDataTypeException
1168
-     * @throws InvalidInterfaceException
1169
-     */
1170
-    private function appendAddNewRegistrationButtonToPageTitle()
1171
-    {
1172
-        $EVT_ID = ! empty($this->_req_data['event_id'])
1173
-            ? absint($this->_req_data['event_id'])
1174
-            : 0;
1175
-        if ($EVT_ID
1176
-            && EE_Registry::instance()->CAP->current_user_can(
1177
-                'ee_edit_registrations',
1178
-                'espresso_registrations_new_registration',
1179
-                $EVT_ID
1180
-            )
1181
-        ) {
1182
-            $this->_admin_page_title .= ' ' . $this->get_action_link_or_button(
1183
-                'new_registration',
1184
-                'add-registrant',
1185
-                array('event_id' => $EVT_ID),
1186
-                'add-new-h2'
1187
-            );
1188
-        }
1189
-    }
1190
-
1191
-
1192
-    /**
1193
-     * This sets the _registration property for the registration details screen
1194
-     *
1195
-     * @access private
1196
-     * @return bool
1197
-     * @throws EE_Error
1198
-     * @throws InvalidArgumentException
1199
-     * @throws InvalidDataTypeException
1200
-     * @throws InvalidInterfaceException
1201
-     */
1202
-    private function _set_registration_object()
1203
-    {
1204
-        // get out if we've already set the object
1205
-        if ($this->_registration instanceof EE_Registration) {
1206
-            return true;
1207
-        }
1208
-        $REG_ID = (! empty($this->_req_data['_REG_ID'])) ? absint($this->_req_data['_REG_ID']) : false;
1209
-        if ($this->_registration = $this->getRegistrationModel()->get_one_by_ID($REG_ID)) {
1210
-            return true;
1211
-        }
1212
-        $error_msg = sprintf(
1213
-            esc_html__(
1214
-                'An error occurred and the details for Registration ID #%s could not be retrieved.',
1215
-                'event_espresso'
1216
-            ),
1217
-            $REG_ID
1218
-        );
1219
-        EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__);
1220
-        $this->_registration = null;
1221
-        return false;
1222
-    }
1223
-
1224
-
1225
-    /**
1226
-     * Used to retrieve registrations for the list table.
1227
-     *
1228
-     * @param int  $per_page
1229
-     * @param bool $count
1230
-     * @param bool $this_month
1231
-     * @param bool $today
1232
-     * @return EE_Registration[]|int
1233
-     * @throws EE_Error
1234
-     * @throws InvalidArgumentException
1235
-     * @throws InvalidDataTypeException
1236
-     * @throws InvalidInterfaceException
1237
-     */
1238
-    public function get_registrations(
1239
-        $per_page = 10,
1240
-        $count = false,
1241
-        $this_month = false,
1242
-        $today = false
1243
-    ) {
1244
-        if ($this_month) {
1245
-            $this->_req_data['status'] = 'month';
1246
-        }
1247
-        if ($today) {
1248
-            $this->_req_data['status'] = 'today';
1249
-        }
1250
-        $query_params = $this->_get_registration_query_parameters($this->_req_data, $per_page, $count);
1251
-        /**
1252
-         * Override the default groupby added by EEM_Base so that sorts with multiple order bys work as expected
1253
-         *
1254
-         * @link https://events.codebasehq.com/projects/event-espresso/tickets/10093
1255
-         * @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
1256
-         *                             or if you have the development copy of EE you can view this at the path:
1257
-         *                             /docs/G--Model-System/model-query-params.md
1258
-         */
1259
-        $query_params['group_by'] = '';
1260
-
1261
-        return $count
1262
-            ? $this->getRegistrationModel()->count($query_params)
1263
-            /** @type EE_Registration[] */
1264
-            : $this->getRegistrationModel()->get_all($query_params);
1265
-    }
1266
-
1267
-
1268
-    /**
1269
-     * Retrieves the query parameters to be used by the Registration model for getting registrations.
1270
-     * Note: this listens to values on the request for some of the query parameters.
1271
-     *
1272
-     * @param array $request
1273
-     * @param int   $per_page
1274
-     * @param bool  $count
1275
-     * @return array
1276
-     * @throws EE_Error
1277
-     * @throws InvalidArgumentException
1278
-     * @throws InvalidDataTypeException
1279
-     * @throws InvalidInterfaceException
1280
-     */
1281
-    protected function _get_registration_query_parameters(
1282
-        $request = array(),
1283
-        $per_page = 10,
1284
-        $count = false
1285
-    ) {
1286
-        /** @var EventEspresso\core\domain\services\admin\registrations\list_table\QueryBuilder $list_table_query_builder */
1287
-        $list_table_query_builder = $this->loader->getNew(
1288
-            'EventEspresso\core\domain\services\admin\registrations\list_table\QueryBuilder',
1289
-            [ $request ]
1290
-        );
1291
-        return $list_table_query_builder->getQueryParams($per_page, $count);
1292
-    }
1293
-
1294
-
1295
-    public function get_registration_status_array()
1296
-    {
1297
-        return self::$_reg_status;
1298
-    }
1299
-
1300
-
1301
-
1302
-
1303
-    /***************************************        REGISTRATION DETAILS        ***************************************/
1304
-    /**
1305
-     *        generates HTML for the View Registration Details Admin page
1306
-     *
1307
-     * @access protected
1308
-     * @return void
1309
-     * @throws DomainException
1310
-     * @throws EE_Error
1311
-     * @throws InvalidArgumentException
1312
-     * @throws InvalidDataTypeException
1313
-     * @throws InvalidInterfaceException
1314
-     * @throws EntityNotFoundException
1315
-     * @throws ReflectionException
1316
-     */
1317
-    protected function _registration_details()
1318
-    {
1319
-        $this->_template_args = array();
1320
-        $this->_set_registration_object();
1321
-        if (is_object($this->_registration)) {
1322
-            $transaction = $this->_registration->transaction()
1323
-                ? $this->_registration->transaction()
1324
-                : EE_Transaction::new_instance();
1325
-            $this->_session = $transaction->session_data();
1326
-            $event_id = $this->_registration->event_ID();
1327
-            $this->_template_args['reg_nmbr']['value'] = $this->_registration->ID();
1328
-            $this->_template_args['reg_nmbr']['label'] = esc_html__('Registration Number', 'event_espresso');
1329
-            $this->_template_args['reg_datetime']['value'] = $this->_registration->get_i18n_datetime('REG_date');
1330
-            $this->_template_args['reg_datetime']['label'] = esc_html__('Date', 'event_espresso');
1331
-            $this->_template_args['grand_total'] = $transaction->total();
1332
-            $this->_template_args['currency_sign'] = EE_Registry::instance()->CFG->currency->sign;
1333
-            // link back to overview
1334
-            $this->_template_args['reg_overview_url'] = REG_ADMIN_URL;
1335
-            $this->_template_args['registration'] = $this->_registration;
1336
-            $this->_template_args['filtered_registrations_link'] = EE_Admin_Page::add_query_args_and_nonce(
1337
-                array(
1338
-                    'action'   => 'default',
1339
-                    'event_id' => $event_id,
1340
-                ),
1341
-                REG_ADMIN_URL
1342
-            );
1343
-            $this->_template_args['filtered_transactions_link'] = EE_Admin_Page::add_query_args_and_nonce(
1344
-                array(
1345
-                    'action' => 'default',
1346
-                    'EVT_ID' => $event_id,
1347
-                    'page'   => 'espresso_transactions',
1348
-                ),
1349
-                admin_url('admin.php')
1350
-            );
1351
-            $this->_template_args['event_link'] = EE_Admin_Page::add_query_args_and_nonce(
1352
-                array(
1353
-                    'page'   => 'espresso_events',
1354
-                    'action' => 'edit',
1355
-                    'post'   => $event_id,
1356
-                ),
1357
-                admin_url('admin.php')
1358
-            );
1359
-            // next and previous links
1360
-            $next_reg = $this->_registration->next(
1361
-                null,
1362
-                array(),
1363
-                'REG_ID'
1364
-            );
1365
-            $this->_template_args['next_registration'] = $next_reg
1366
-                ? $this->_next_link(
1367
-                    EE_Admin_Page::add_query_args_and_nonce(
1368
-                        array(
1369
-                            'action'  => 'view_registration',
1370
-                            '_REG_ID' => $next_reg['REG_ID'],
1371
-                        ),
1372
-                        REG_ADMIN_URL
1373
-                    ),
1374
-                    'dashicons dashicons-arrow-right ee-icon-size-22'
1375
-                )
1376
-                : '';
1377
-            $previous_reg = $this->_registration->previous(
1378
-                null,
1379
-                array(),
1380
-                'REG_ID'
1381
-            );
1382
-            $this->_template_args['previous_registration'] = $previous_reg
1383
-                ? $this->_previous_link(
1384
-                    EE_Admin_Page::add_query_args_and_nonce(
1385
-                        array(
1386
-                            'action'  => 'view_registration',
1387
-                            '_REG_ID' => $previous_reg['REG_ID'],
1388
-                        ),
1389
-                        REG_ADMIN_URL
1390
-                    ),
1391
-                    'dashicons dashicons-arrow-left ee-icon-size-22'
1392
-                )
1393
-                : '';
1394
-            // grab header
1395
-            $template_path = REG_TEMPLATE_PATH . 'reg_admin_details_header.template.php';
1396
-            $this->_template_args['REG_ID'] = $this->_registration->ID();
1397
-            $this->_template_args['admin_page_header'] = EEH_Template::display_template(
1398
-                $template_path,
1399
-                $this->_template_args,
1400
-                true
1401
-            );
1402
-        } else {
1403
-            $this->_template_args['admin_page_header'] = $this->display_espresso_notices();
1404
-        }
1405
-        // the details template wrapper
1406
-        $this->display_admin_page_with_sidebar();
1407
-    }
1408
-
1409
-
1410
-    /**
1411
-     * @throws EE_Error
1412
-     * @throws InvalidArgumentException
1413
-     * @throws InvalidDataTypeException
1414
-     * @throws InvalidInterfaceException
1415
-     * @throws ReflectionException
1416
-     * @since 4.10.2.p
1417
-     */
1418
-    protected function _registration_details_metaboxes()
1419
-    {
1420
-        do_action('AHEE__Registrations_Admin_Page___registration_details_metabox__start', $this);
1421
-        $this->_set_registration_object();
1422
-        $attendee = $this->_registration instanceof EE_Registration ? $this->_registration->attendee() : null;
1423
-        add_meta_box(
1424
-            'edit-reg-status-mbox',
1425
-            esc_html__('Registration Status', 'event_espresso'),
1426
-            array($this, 'set_reg_status_buttons_metabox'),
1427
-            $this->wp_page_slug,
1428
-            'normal',
1429
-            'high'
1430
-        );
1431
-        add_meta_box(
1432
-            'edit-reg-details-mbox',
1433
-            esc_html__('Registration Details', 'event_espresso'),
1434
-            array($this, '_reg_details_meta_box'),
1435
-            $this->wp_page_slug,
1436
-            'normal',
1437
-            'high'
1438
-        );
1439
-        if ($attendee instanceof EE_Attendee
1440
-            && EE_Registry::instance()->CAP->current_user_can(
1441
-                'ee_read_registration',
1442
-                'edit-reg-questions-mbox',
1443
-                $this->_registration->ID()
1444
-            )
1445
-        ) {
1446
-            add_meta_box(
1447
-                'edit-reg-questions-mbox',
1448
-                esc_html__('Registration Form Answers', 'event_espresso'),
1449
-                array($this, '_reg_questions_meta_box'),
1450
-                $this->wp_page_slug,
1451
-                'normal',
1452
-                'high'
1453
-            );
1454
-        }
1455
-        add_meta_box(
1456
-            'edit-reg-registrant-mbox',
1457
-            esc_html__('Contact Details', 'event_espresso'),
1458
-            array($this, '_reg_registrant_side_meta_box'),
1459
-            $this->wp_page_slug,
1460
-            'side',
1461
-            'high'
1462
-        );
1463
-        if ($this->_registration->group_size() > 1) {
1464
-            add_meta_box(
1465
-                'edit-reg-attendees-mbox',
1466
-                esc_html__('Other Registrations in this Transaction', 'event_espresso'),
1467
-                array($this, '_reg_attendees_meta_box'),
1468
-                $this->wp_page_slug,
1469
-                'normal',
1470
-                'high'
1471
-            );
1472
-        }
1473
-    }
1474
-
1475
-
1476
-    /**
1477
-     * set_reg_status_buttons_metabox
1478
-     *
1479
-     * @access protected
1480
-     * @return string
1481
-     * @throws EE_Error
1482
-     * @throws EntityNotFoundException
1483
-     * @throws InvalidArgumentException
1484
-     * @throws InvalidDataTypeException
1485
-     * @throws InvalidInterfaceException
1486
-     * @throws ReflectionException
1487
-     */
1488
-    public function set_reg_status_buttons_metabox()
1489
-    {
1490
-        $this->_set_registration_object();
1491
-        $change_reg_status_form = $this->_generate_reg_status_change_form();
1492
-        echo $change_reg_status_form->form_open(
1493
-            self::add_query_args_and_nonce(
1494
-                array(
1495
-                    'action' => 'change_reg_status',
1496
-                ),
1497
-                REG_ADMIN_URL
1498
-            )
1499
-        );
1500
-        echo $change_reg_status_form->get_html();
1501
-        echo $change_reg_status_form->form_close();
1502
-    }
1503
-
1504
-
1505
-    /**
1506
-     * @return EE_Form_Section_Proper
1507
-     * @throws EE_Error
1508
-     * @throws InvalidArgumentException
1509
-     * @throws InvalidDataTypeException
1510
-     * @throws InvalidInterfaceException
1511
-     * @throws EntityNotFoundException
1512
-     * @throws ReflectionException
1513
-     */
1514
-    protected function _generate_reg_status_change_form()
1515
-    {
1516
-        $reg_status_change_form_array = array(
1517
-            'name'            => 'reg_status_change_form',
1518
-            'html_id'         => 'reg-status-change-form',
1519
-            'layout_strategy' => new EE_Admin_Two_Column_Layout(),
1520
-            'subsections'     => array(
1521
-                'return'             => new EE_Hidden_Input(
1522
-                    array(
1523
-                        'name'    => 'return',
1524
-                        'default' => 'view_registration',
1525
-                    )
1526
-                ),
1527
-                'REG_ID'             => new EE_Hidden_Input(
1528
-                    array(
1529
-                        'name'    => 'REG_ID',
1530
-                        'default' => $this->_registration->ID(),
1531
-                    )
1532
-                ),
1533
-                'current_status'     => new EE_Form_Section_HTML(
1534
-                    EEH_HTML::table(
1535
-                        EEH_HTML::tr(
1536
-                            EEH_HTML::th(
1537
-                                EEH_HTML::label(
1538
-                                    EEH_HTML::strong(
1539
-                                        esc_html__('Current Registration Status', 'event_espresso')
1540
-                                    )
1541
-                                )
1542
-                            )
1543
-                            . EEH_HTML::td(
1544
-                                EEH_HTML::strong(
1545
-                                    $this->_registration->pretty_status(),
1546
-                                    '',
1547
-                                    'status-' . $this->_registration->status_ID(),
1548
-                                    'line-height: 1em; font-size: 1.5em; font-weight: bold;'
1549
-                                )
1550
-                            )
1551
-                        )
1552
-                    )
1553
-                )
1554
-            )
1555
-        );
1556
-        if (EE_Registry::instance()->CAP->current_user_can(
1557
-            'ee_edit_registration',
1558
-            'toggle_registration_status',
1559
-            $this->_registration->ID()
1560
-        )) {
1561
-            $reg_status_change_form_array['subsections']['reg_status'] = new EE_Select_Input(
1562
-                $this->_get_reg_statuses(),
1563
-                array(
1564
-                    'html_label_text' => esc_html__('Change Registration Status to', 'event_espresso'),
1565
-                    'default'         => $this->_registration->status_ID(),
1566
-                )
1567
-            );
1568
-            $reg_status_change_form_array['subsections']['send_notifications'] = new EE_Yes_No_Input(
1569
-                array(
1570
-                    'html_label_text' => esc_html__('Send Related Messages', 'event_espresso'),
1571
-                    'default'         => false,
1572
-                    'html_help_text'  => esc_html__(
1573
-                        'If set to "Yes", then the related messages will be sent to the registrant.',
1574
-                        'event_espresso'
1575
-                    )
1576
-                )
1577
-            );
1578
-            $reg_status_change_form_array['subsections']['submit'] = new EE_Submit_Input(
1579
-                array(
1580
-                    'html_class'      => 'button-primary',
1581
-                    'html_label_text' => '&nbsp;',
1582
-                    'default'         => esc_html__('Update Registration Status', 'event_espresso'),
1583
-                )
1584
-            );
1585
-        }
1586
-        return new EE_Form_Section_Proper($reg_status_change_form_array);
1587
-    }
1588
-
1589
-
1590
-    /**
1591
-     * Returns an array of all the buttons for the various statuses and switch status actions
1592
-     *
1593
-     * @return array
1594
-     * @throws EE_Error
1595
-     * @throws InvalidArgumentException
1596
-     * @throws InvalidDataTypeException
1597
-     * @throws InvalidInterfaceException
1598
-     * @throws EntityNotFoundException
1599
-     */
1600
-    protected function _get_reg_statuses()
1601
-    {
1602
-        $reg_status_array = $this->getRegistrationModel()->reg_status_array();
1603
-        unset($reg_status_array[ EEM_Registration::status_id_incomplete ]);
1604
-        // get current reg status
1605
-        $current_status = $this->_registration->status_ID();
1606
-        // is registration for free event? This will determine whether to display the pending payment option
1607
-        if ($current_status !== EEM_Registration::status_id_pending_payment
1608
-            && EEH_Money::compare_floats($this->_registration->ticket()->price(), 0.00)
1609
-        ) {
1610
-            unset($reg_status_array[ EEM_Registration::status_id_pending_payment ]);
1611
-        }
1612
-        return $this->getStatusModel()->localized_status($reg_status_array, false, 'sentence');
1613
-    }
1614
-
1615
-
1616
-    /**
1617
-     * This method is used when using _REG_ID from request which may or may not be an array of reg_ids.
1618
-     *
1619
-     * @param bool $status REG status given for changing registrations to.
1620
-     * @param bool $notify Whether to send messages notifications or not.
1621
-     * @return array (array with reg_id(s) updated and whether update was successful.
1622
-     * @throws DomainException
1623
-     * @throws EE_Error
1624
-     * @throws EntityNotFoundException
1625
-     * @throws InvalidArgumentException
1626
-     * @throws InvalidDataTypeException
1627
-     * @throws InvalidInterfaceException
1628
-     * @throws ReflectionException
1629
-     * @throws RuntimeException
1630
-     */
1631
-    protected function _set_registration_status_from_request($status = false, $notify = false)
1632
-    {
1633
-        if (isset($this->_req_data['reg_status_change_form'])) {
1634
-            $REG_IDs = isset($this->_req_data['reg_status_change_form']['REG_ID'])
1635
-                ? (array) $this->_req_data['reg_status_change_form']['REG_ID']
1636
-                : array();
1637
-        } else {
1638
-            $REG_IDs = isset($this->_req_data['_REG_ID'])
1639
-                ? (array) $this->_req_data['_REG_ID']
1640
-                : array();
1641
-        }
1642
-        // sanitize $REG_IDs
1643
-        $REG_IDs = array_map('absint', $REG_IDs);
1644
-        // and remove empty entries
1645
-        $REG_IDs = array_filter($REG_IDs);
1646
-
1647
-        $result = $this->_set_registration_status($REG_IDs, $status, $notify);
1648
-
1649
-        /**
1650
-         * Set and filter $_req_data['_REG_ID'] for any potential future messages notifications.
1651
-         * Currently this value is used downstream by the _process_resend_registration method.
1652
-         *
1653
-         * @param int|array                $registration_ids The registration ids that have had their status changed successfully.
1654
-         * @param bool                     $status           The status registrations were changed to.
1655
-         * @param bool                     $success          If the status was changed successfully for all registrations.
1656
-         * @param Registrations_Admin_Page $admin_page_object
1657
-         */
1658
-        $this->_req_data['_REG_ID'] = apply_filters(
1659
-            'FHEE__Registrations_Admin_Page___set_registration_status_from_request__REG_IDs',
1660
-            $result['REG_ID'],
1661
-            $status,
1662
-            $result['success'],
1663
-            $this
1664
-        );
1665
-
1666
-        // notify?
1667
-        if ($notify
1668
-            && $result['success']
1669
-            && ! empty($this->_req_data['_REG_ID'])
1670
-            && EE_Registry::instance()->CAP->current_user_can(
1671
-                'ee_send_message',
1672
-                'espresso_registrations_resend_registration'
1673
-            )
1674
-        ) {
1675
-            $this->_process_resend_registration();
1676
-        }
1677
-        return $result;
1678
-    }
1679
-
1680
-
1681
-    /**
1682
-     * Set the registration status for the given reg_id (which may or may not be an array, it gets typecast to an
1683
-     * array). Note, this method does NOT take care of possible notifications.  That is required by calling code.
1684
-     *
1685
-     * @param array  $REG_IDs
1686
-     * @param string $status
1687
-     * @param bool   $notify  Used to indicate whether notification was requested or not.  This determines the context
1688
-     *                        slug sent with setting the registration status.
1689
-     * @return array (an array with 'success' key representing whether status change was successful, and 'REG_ID' as
1690
-     * @throws EE_Error
1691
-     * @throws InvalidArgumentException
1692
-     * @throws InvalidDataTypeException
1693
-     * @throws InvalidInterfaceException
1694
-     * @throws ReflectionException
1695
-     * @throws RuntimeException
1696
-     * @throws EntityNotFoundException
1697
-     * @throws DomainException
1698
-     */
1699
-    protected function _set_registration_status($REG_IDs = array(), $status = '', $notify = false)
1700
-    {
1701
-        $success = false;
1702
-        // typecast $REG_IDs
1703
-        $REG_IDs = (array) $REG_IDs;
1704
-        if (! empty($REG_IDs)) {
1705
-            $success = true;
1706
-            // set default status if none is passed
1707
-            $status = $status ? $status : EEM_Registration::status_id_pending_payment;
1708
-            $status_context = $notify
1709
-                ? Domain::CONTEXT_REGISTRATION_STATUS_CHANGE_REGISTRATION_ADMIN_NOTIFY
1710
-                : Domain::CONTEXT_REGISTRATION_STATUS_CHANGE_REGISTRATION_ADMIN;
1711
-            // loop through REG_ID's and change status
1712
-            foreach ($REG_IDs as $REG_ID) {
1713
-                $registration = $this->getRegistrationModel()->get_one_by_ID($REG_ID);
1714
-                if ($registration instanceof EE_Registration) {
1715
-                    $registration->set_status(
1716
-                        $status,
1717
-                        false,
1718
-                        new Context(
1719
-                            $status_context,
1720
-                            esc_html__(
1721
-                                'Manually triggered status change on a Registration Admin Page route.',
1722
-                                'event_espresso'
1723
-                            )
1724
-                        )
1725
-                    );
1726
-                    $result = $registration->save();
1727
-                    // verifying explicit fails because update *may* just return 0 for 0 rows affected
1728
-                    $success = $result !== false ? $success : false;
1729
-                }
1730
-            }
1731
-        }
1732
-
1733
-        // return $success and processed registrations
1734
-        return array('REG_ID' => $REG_IDs, 'success' => $success);
1735
-    }
1736
-
1737
-
1738
-    /**
1739
-     * Common logic for setting up success message and redirecting to appropriate route
1740
-     *
1741
-     * @param string $STS_ID status id for the registration changed to
1742
-     * @param bool   $notify indicates whether the _set_registration_status_from_request does notifications or not.
1743
-     * @return void
1744
-     * @throws DomainException
1745
-     * @throws EE_Error
1746
-     * @throws EntityNotFoundException
1747
-     * @throws InvalidArgumentException
1748
-     * @throws InvalidDataTypeException
1749
-     * @throws InvalidInterfaceException
1750
-     * @throws ReflectionException
1751
-     * @throws RuntimeException
1752
-     */
1753
-    protected function _reg_status_change_return($STS_ID, $notify = false)
1754
-    {
1755
-        $result = ! empty($STS_ID) ? $this->_set_registration_status_from_request($STS_ID, $notify)
1756
-            : array('success' => false);
1757
-        $success = isset($result['success']) && $result['success'];
1758
-        // setup success message
1759
-        if ($success) {
1760
-            if (is_array($result['REG_ID']) && count($result['REG_ID']) === 1) {
1761
-                $msg = sprintf(
1762
-                    esc_html__('Registration status has been set to %s', 'event_espresso'),
1763
-                    EEH_Template::pretty_status($STS_ID, false, 'lower')
1764
-                );
1765
-            } else {
1766
-                $msg = sprintf(
1767
-                    esc_html__('Registrations have been set to %s.', 'event_espresso'),
1768
-                    EEH_Template::pretty_status($STS_ID, false, 'lower')
1769
-                );
1770
-            }
1771
-            EE_Error::add_success($msg);
1772
-        } else {
1773
-            EE_Error::add_error(
1774
-                esc_html__(
1775
-                    'Something went wrong, and the status was not changed',
1776
-                    'event_espresso'
1777
-                ),
1778
-                __FILE__,
1779
-                __LINE__,
1780
-                __FUNCTION__
1781
-            );
1782
-        }
1783
-        if (isset($this->_req_data['return']) && $this->_req_data['return'] === 'view_registration') {
1784
-            $route = array('action' => 'view_registration', '_REG_ID' => reset($result['REG_ID']));
1785
-        } else {
1786
-            $route = array('action' => 'default');
1787
-        }
1788
-        $route = $this->mergeExistingRequestParamsWithRedirectArgs($route);
1789
-        $this->_redirect_after_action($success, '', '', $route, true);
1790
-    }
1791
-
1792
-
1793
-    /**
1794
-     * incoming reg status change from reg details page.
1795
-     *
1796
-     * @return void
1797
-     * @throws EE_Error
1798
-     * @throws EntityNotFoundException
1799
-     * @throws InvalidArgumentException
1800
-     * @throws InvalidDataTypeException
1801
-     * @throws InvalidInterfaceException
1802
-     * @throws ReflectionException
1803
-     * @throws RuntimeException
1804
-     * @throws DomainException
1805
-     */
1806
-    protected function _change_reg_status()
1807
-    {
1808
-        $this->_req_data['return'] = 'view_registration';
1809
-        // set notify based on whether the send notifications toggle is set or not
1810
-        $notify = ! empty($this->_req_data['reg_status_change_form']['send_notifications']);
1811
-        // $notify = ! empty( $this->_req_data['txn_reg_status_change']['send_notifications'] );
1812
-        $this->_req_data['reg_status_change_form']['reg_status'] = isset($this->_req_data['reg_status_change_form']['reg_status'])
1813
-            ? $this->_req_data['reg_status_change_form']['reg_status'] : '';
1814
-        switch ($this->_req_data['reg_status_change_form']['reg_status']) {
1815
-            case EEM_Registration::status_id_approved:
1816
-            case EEH_Template::pretty_status(EEM_Registration::status_id_approved, false, 'sentence'):
1817
-                $this->approve_registration($notify);
1818
-                break;
1819
-            case EEM_Registration::status_id_pending_payment:
1820
-            case EEH_Template::pretty_status(EEM_Registration::status_id_pending_payment, false, 'sentence'):
1821
-                $this->pending_registration($notify);
1822
-                break;
1823
-            case EEM_Registration::status_id_not_approved:
1824
-            case EEH_Template::pretty_status(EEM_Registration::status_id_not_approved, false, 'sentence'):
1825
-                $this->not_approve_registration($notify);
1826
-                break;
1827
-            case EEM_Registration::status_id_declined:
1828
-            case EEH_Template::pretty_status(EEM_Registration::status_id_declined, false, 'sentence'):
1829
-                $this->decline_registration($notify);
1830
-                break;
1831
-            case EEM_Registration::status_id_cancelled:
1832
-            case EEH_Template::pretty_status(EEM_Registration::status_id_cancelled, false, 'sentence'):
1833
-                $this->cancel_registration($notify);
1834
-                break;
1835
-            case EEM_Registration::status_id_wait_list:
1836
-            case EEH_Template::pretty_status(EEM_Registration::status_id_wait_list, false, 'sentence'):
1837
-                $this->wait_list_registration($notify);
1838
-                break;
1839
-            case EEM_Registration::status_id_incomplete:
1840
-            default:
1841
-                $result['success'] = false;
1842
-                unset($this->_req_data['return']);
1843
-                $this->_reg_status_change_return('', false);
1844
-                break;
1845
-        }
1846
-    }
1847
-
1848
-
1849
-    /**
1850
-     * Callback for bulk action routes.
1851
-     * Note: although we could just register the singular route callbacks for each bulk action route as well, this
1852
-     * method was chosen so there is one central place all the registration status bulk actions are going through.
1853
-     * Potentially, this provides an easier place to locate logic that is specific to these bulk actions (as opposed to
1854
-     * when an action is happening on just a single registration).
1855
-     *
1856
-     * @param      $action
1857
-     * @param bool $notify
1858
-     */
1859
-    protected function bulk_action_on_registrations($action, $notify = false)
1860
-    {
1861
-        do_action(
1862
-            'AHEE__Registrations_Admin_Page__bulk_action_on_registrations__before_execution',
1863
-            $this,
1864
-            $action,
1865
-            $notify
1866
-        );
1867
-        $method = $action . '_registration';
1868
-        if (method_exists($this, $method)) {
1869
-            $this->$method($notify);
1870
-        }
1871
-    }
1872
-
1873
-
1874
-    /**
1875
-     * approve_registration
1876
-     *
1877
-     * @access protected
1878
-     * @param bool $notify whether or not to notify the registrant about their approval.
1879
-     * @return void
1880
-     * @throws EE_Error
1881
-     * @throws EntityNotFoundException
1882
-     * @throws InvalidArgumentException
1883
-     * @throws InvalidDataTypeException
1884
-     * @throws InvalidInterfaceException
1885
-     * @throws ReflectionException
1886
-     * @throws RuntimeException
1887
-     * @throws DomainException
1888
-     */
1889
-    protected function approve_registration($notify = false)
1890
-    {
1891
-        $this->_reg_status_change_return(EEM_Registration::status_id_approved, $notify);
1892
-    }
1893
-
1894
-
1895
-    /**
1896
-     *        decline_registration
1897
-     *
1898
-     * @access protected
1899
-     * @param bool $notify whether or not to notify the registrant about their status change.
1900
-     * @return void
1901
-     * @throws EE_Error
1902
-     * @throws EntityNotFoundException
1903
-     * @throws InvalidArgumentException
1904
-     * @throws InvalidDataTypeException
1905
-     * @throws InvalidInterfaceException
1906
-     * @throws ReflectionException
1907
-     * @throws RuntimeException
1908
-     * @throws DomainException
1909
-     */
1910
-    protected function decline_registration($notify = false)
1911
-    {
1912
-        $this->_reg_status_change_return(EEM_Registration::status_id_declined, $notify);
1913
-    }
1914
-
1915
-
1916
-    /**
1917
-     *        cancel_registration
1918
-     *
1919
-     * @access protected
1920
-     * @param bool $notify whether or not to notify the registrant about their status change.
1921
-     * @return void
1922
-     * @throws EE_Error
1923
-     * @throws EntityNotFoundException
1924
-     * @throws InvalidArgumentException
1925
-     * @throws InvalidDataTypeException
1926
-     * @throws InvalidInterfaceException
1927
-     * @throws ReflectionException
1928
-     * @throws RuntimeException
1929
-     * @throws DomainException
1930
-     */
1931
-    protected function cancel_registration($notify = false)
1932
-    {
1933
-        $this->_reg_status_change_return(EEM_Registration::status_id_cancelled, $notify);
1934
-    }
1935
-
1936
-
1937
-    /**
1938
-     *        not_approve_registration
1939
-     *
1940
-     * @access protected
1941
-     * @param bool $notify whether or not to notify the registrant about their status change.
1942
-     * @return void
1943
-     * @throws EE_Error
1944
-     * @throws EntityNotFoundException
1945
-     * @throws InvalidArgumentException
1946
-     * @throws InvalidDataTypeException
1947
-     * @throws InvalidInterfaceException
1948
-     * @throws ReflectionException
1949
-     * @throws RuntimeException
1950
-     * @throws DomainException
1951
-     */
1952
-    protected function not_approve_registration($notify = false)
1953
-    {
1954
-        $this->_reg_status_change_return(EEM_Registration::status_id_not_approved, $notify);
1955
-    }
1956
-
1957
-
1958
-    /**
1959
-     *        decline_registration
1960
-     *
1961
-     * @access protected
1962
-     * @param bool $notify whether or not to notify the registrant about their status change.
1963
-     * @return void
1964
-     * @throws EE_Error
1965
-     * @throws EntityNotFoundException
1966
-     * @throws InvalidArgumentException
1967
-     * @throws InvalidDataTypeException
1968
-     * @throws InvalidInterfaceException
1969
-     * @throws ReflectionException
1970
-     * @throws RuntimeException
1971
-     * @throws DomainException
1972
-     */
1973
-    protected function pending_registration($notify = false)
1974
-    {
1975
-        $this->_reg_status_change_return(EEM_Registration::status_id_pending_payment, $notify);
1976
-    }
1977
-
1978
-
1979
-    /**
1980
-     * waitlist_registration
1981
-     *
1982
-     * @access protected
1983
-     * @param bool $notify whether or not to notify the registrant about their status change.
1984
-     * @return void
1985
-     * @throws EE_Error
1986
-     * @throws EntityNotFoundException
1987
-     * @throws InvalidArgumentException
1988
-     * @throws InvalidDataTypeException
1989
-     * @throws InvalidInterfaceException
1990
-     * @throws ReflectionException
1991
-     * @throws RuntimeException
1992
-     * @throws DomainException
1993
-     */
1994
-    protected function wait_list_registration($notify = false)
1995
-    {
1996
-        $this->_reg_status_change_return(EEM_Registration::status_id_wait_list, $notify);
1997
-    }
1998
-
1999
-
2000
-    /**
2001
-     *        generates HTML for the Registration main meta box
2002
-     *
2003
-     * @access public
2004
-     * @return void
2005
-     * @throws DomainException
2006
-     * @throws EE_Error
2007
-     * @throws InvalidArgumentException
2008
-     * @throws InvalidDataTypeException
2009
-     * @throws InvalidInterfaceException
2010
-     * @throws ReflectionException
2011
-     * @throws EntityNotFoundException
2012
-     */
2013
-    public function _reg_details_meta_box()
2014
-    {
2015
-        EEH_Autoloader::register_line_item_display_autoloaders();
2016
-        EEH_Autoloader::register_line_item_filter_autoloaders();
2017
-        EE_Registry::instance()->load_helper('Line_Item');
2018
-        $transaction = $this->_registration->transaction() ? $this->_registration->transaction()
2019
-            : EE_Transaction::new_instance();
2020
-        $this->_session = $transaction->session_data();
2021
-        $filters = new EE_Line_Item_Filter_Collection();
2022
-        $filters->add(new EE_Single_Registration_Line_Item_Filter($this->_registration));
2023
-        $filters->add(new EE_Non_Zero_Line_Item_Filter());
2024
-        $line_item_filter_processor = new EE_Line_Item_Filter_Processor(
2025
-            $filters,
2026
-            $transaction->total_line_item()
2027
-        );
2028
-        $filtered_line_item_tree = $line_item_filter_processor->process();
2029
-        $line_item_display = new EE_Line_Item_Display(
2030
-            'reg_admin_table',
2031
-            'EE_Admin_Table_Registration_Line_Item_Display_Strategy'
2032
-        );
2033
-        $this->_template_args['line_item_table'] = $line_item_display->display_line_item(
2034
-            $filtered_line_item_tree,
2035
-            array('EE_Registration' => $this->_registration)
2036
-        );
2037
-        $attendee = $this->_registration->attendee();
2038
-        if (EE_Registry::instance()->CAP->current_user_can(
2039
-            'ee_read_transaction',
2040
-            'espresso_transactions_view_transaction'
2041
-        )) {
2042
-            $this->_template_args['view_transaction_button'] = EEH_Template::get_button_or_link(
2043
-                EE_Admin_Page::add_query_args_and_nonce(
2044
-                    array(
2045
-                        'action' => 'view_transaction',
2046
-                        'TXN_ID' => $transaction->ID(),
2047
-                    ),
2048
-                    TXN_ADMIN_URL
2049
-                ),
2050
-                esc_html__(' View Transaction', 'event_espresso'),
2051
-                'button secondary-button right',
2052
-                'dashicons dashicons-cart'
2053
-            );
2054
-        } else {
2055
-            $this->_template_args['view_transaction_button'] = '';
2056
-        }
2057
-        if ($attendee instanceof EE_Attendee
2058
-            && EE_Registry::instance()->CAP->current_user_can(
2059
-                'ee_send_message',
2060
-                'espresso_registrations_resend_registration'
2061
-            )
2062
-        ) {
2063
-            $this->_template_args['resend_registration_button'] = EEH_Template::get_button_or_link(
2064
-                EE_Admin_Page::add_query_args_and_nonce(
2065
-                    array(
2066
-                        'action'      => 'resend_registration',
2067
-                        '_REG_ID'     => $this->_registration->ID(),
2068
-                        'redirect_to' => 'view_registration',
2069
-                    ),
2070
-                    REG_ADMIN_URL
2071
-                ),
2072
-                esc_html__(' Resend Registration', 'event_espresso'),
2073
-                'button secondary-button right',
2074
-                'dashicons dashicons-email-alt'
2075
-            );
2076
-        } else {
2077
-            $this->_template_args['resend_registration_button'] = '';
2078
-        }
2079
-        $this->_template_args['currency_sign'] = EE_Registry::instance()->CFG->currency->sign;
2080
-        $payment = $transaction->get_first_related('Payment');
2081
-        $payment = ! $payment instanceof EE_Payment
2082
-            ? EE_Payment::new_instance()
2083
-            : $payment;
2084
-        $payment_method = $payment->get_first_related('Payment_Method');
2085
-        $payment_method = ! $payment_method instanceof EE_Payment_Method
2086
-            ? EE_Payment_Method::new_instance()
2087
-            : $payment_method;
2088
-        $reg_details = array(
2089
-            'payment_method'       => $payment_method->name(),
2090
-            'response_msg'         => $payment->gateway_response(),
2091
-            'registration_id'      => $this->_registration->get('REG_code'),
2092
-            'registration_session' => $this->_registration->session_ID(),
2093
-            'ip_address'           => isset($this->_session['ip_address']) ? $this->_session['ip_address'] : '',
2094
-            'user_agent'           => isset($this->_session['user_agent']) ? $this->_session['user_agent'] : '',
2095
-        );
2096
-        if (isset($reg_details['registration_id'])) {
2097
-            $this->_template_args['reg_details']['registration_id']['value'] = $reg_details['registration_id'];
2098
-            $this->_template_args['reg_details']['registration_id']['label'] = esc_html__(
2099
-                'Registration ID',
2100
-                'event_espresso'
2101
-            );
2102
-            $this->_template_args['reg_details']['registration_id']['class'] = 'regular-text';
2103
-        }
2104
-        if (isset($reg_details['payment_method'])) {
2105
-            $this->_template_args['reg_details']['payment_method']['value'] = $reg_details['payment_method'];
2106
-            $this->_template_args['reg_details']['payment_method']['label'] = esc_html__(
2107
-                'Most Recent Payment Method',
2108
-                'event_espresso'
2109
-            );
2110
-            $this->_template_args['reg_details']['payment_method']['class'] = 'regular-text';
2111
-            $this->_template_args['reg_details']['response_msg']['value'] = $reg_details['response_msg'];
2112
-            $this->_template_args['reg_details']['response_msg']['label'] = esc_html__(
2113
-                'Payment method response',
2114
-                'event_espresso'
2115
-            );
2116
-            $this->_template_args['reg_details']['response_msg']['class'] = 'regular-text';
2117
-        }
2118
-        $this->_template_args['reg_details']['registration_session']['value'] = $reg_details['registration_session'];
2119
-        $this->_template_args['reg_details']['registration_session']['label'] = esc_html__(
2120
-            'Registration Session',
2121
-            'event_espresso'
2122
-        );
2123
-        $this->_template_args['reg_details']['registration_session']['class'] = 'regular-text';
2124
-        $this->_template_args['reg_details']['ip_address']['value'] = $reg_details['ip_address'];
2125
-        $this->_template_args['reg_details']['ip_address']['label'] = esc_html__(
2126
-            'Registration placed from IP',
2127
-            'event_espresso'
2128
-        );
2129
-        $this->_template_args['reg_details']['ip_address']['class'] = 'regular-text';
2130
-        $this->_template_args['reg_details']['user_agent']['value'] = $reg_details['user_agent'];
2131
-        $this->_template_args['reg_details']['user_agent']['label'] = esc_html__(
2132
-            'Registrant User Agent',
2133
-            'event_espresso'
2134
-        );
2135
-        $this->_template_args['reg_details']['user_agent']['class'] = 'large-text';
2136
-        $this->_template_args['event_link'] = EE_Admin_Page::add_query_args_and_nonce(
2137
-            array(
2138
-                'action'   => 'default',
2139
-                'event_id' => $this->_registration->event_ID(),
2140
-            ),
2141
-            REG_ADMIN_URL
2142
-        );
2143
-        $this->_template_args['REG_ID'] = $this->_registration->ID();
2144
-        $this->_template_args['event_id'] = $this->_registration->event_ID();
2145
-        $template_path =
2146
-            REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_reg_details.template.php';
2147
-        echo EEH_Template::display_template($template_path, $this->_template_args, true);
2148
-    }
2149
-
2150
-
2151
-    /**
2152
-     * generates HTML for the Registration Questions meta box.
2153
-     * If pre-4.8.32.rc.000 hooks are used, uses old methods (with its filters),
2154
-     * otherwise uses new forms system
2155
-     *
2156
-     * @access public
2157
-     * @return void
2158
-     * @throws DomainException
2159
-     * @throws EE_Error
2160
-     * @throws InvalidArgumentException
2161
-     * @throws InvalidDataTypeException
2162
-     * @throws InvalidInterfaceException
2163
-     * @throws ReflectionException
2164
-     */
2165
-    public function _reg_questions_meta_box()
2166
-    {
2167
-        // allow someone to override this method entirely
2168
-        if (apply_filters(
2169
-            'FHEE__Registrations_Admin_Page___reg_questions_meta_box__do_default',
2170
-            true,
2171
-            $this,
2172
-            $this->_registration
2173
-        )) {
2174
-            $form = $this->_get_reg_custom_questions_form(
2175
-                $this->_registration->ID()
2176
-            );
2177
-            $this->_template_args['att_questions'] = count($form->subforms()) > 0
2178
-                ? $form->get_html_and_js()
2179
-                : '';
2180
-            $this->_template_args['reg_questions_form_action'] = 'edit_registration';
2181
-            $this->_template_args['REG_ID'] = $this->_registration->ID();
2182
-            $template_path =
2183
-                REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_reg_questions.template.php';
2184
-            echo EEH_Template::display_template($template_path, $this->_template_args, true);
2185
-        }
2186
-    }
2187
-
2188
-
2189
-    /**
2190
-     * form_before_question_group
2191
-     *
2192
-     * @deprecated    as of 4.8.32.rc.000
2193
-     * @access        public
2194
-     * @param        string $output
2195
-     * @return        string
2196
-     */
2197
-    public function form_before_question_group($output)
2198
-    {
2199
-        EE_Error::doing_it_wrong(
2200
-            __CLASS__ . '::' . __FUNCTION__,
2201
-            esc_html__(
2202
-                'This method would have been protected but was used on a filter callback so needed to be public. Please discontinue usage as it will be removed soon.',
2203
-                'event_espresso'
2204
-            ),
2205
-            '4.8.32.rc.000'
2206
-        );
2207
-        return '
21
+	/**
22
+	 * @var EE_Registration
23
+	 */
24
+	private $_registration;
25
+
26
+	/**
27
+	 * @var EE_Event
28
+	 */
29
+	private $_reg_event;
30
+
31
+	/**
32
+	 * @var EE_Session
33
+	 */
34
+	private $_session;
35
+
36
+	private static $_reg_status;
37
+
38
+	/**
39
+	 * Form for displaying the custom questions for this registration.
40
+	 * This gets used a few times throughout the request so its best to cache it
41
+	 *
42
+	 * @var EE_Registration_Custom_Questions_Form
43
+	 */
44
+	protected $_reg_custom_questions_form;
45
+
46
+	/**
47
+	 * @var EEM_Registration $registration_model
48
+	 */
49
+	private $registration_model;
50
+
51
+	/**
52
+	 * @var EEM_Attendee $attendee_model
53
+	 */
54
+	private $attendee_model;
55
+
56
+	/**
57
+	 * @var EEM_Event $event_model
58
+	 */
59
+	private $event_model;
60
+
61
+	/**
62
+	 * @var EEM_Status $status_model
63
+	 */
64
+	private $status_model;
65
+
66
+
67
+	/**
68
+	 * @param bool $routing
69
+	 * @throws EE_Error
70
+	 * @throws InvalidArgumentException
71
+	 * @throws InvalidDataTypeException
72
+	 * @throws InvalidInterfaceException
73
+	 * @throws ReflectionException
74
+	 */
75
+	public function __construct($routing = true)
76
+	{
77
+		parent::__construct($routing);
78
+		add_action('wp_loaded', array($this, 'wp_loaded'));
79
+	}
80
+
81
+	/**
82
+	 * @return EEM_Registration
83
+	 * @throws InvalidArgumentException
84
+	 * @throws InvalidDataTypeException
85
+	 * @throws InvalidInterfaceException
86
+	 * @since 4.10.2.p
87
+	 */
88
+	protected function getRegistrationModel()
89
+	{
90
+		if (! $this->registration_model instanceof EEM_Registration) {
91
+			$this->registration_model = $this->loader->getShared('EEM_Registration');
92
+		}
93
+		return $this->registration_model;
94
+	}
95
+
96
+	/**
97
+	 * @return EEM_Attendee
98
+	 * @throws InvalidArgumentException
99
+	 * @throws InvalidDataTypeException
100
+	 * @throws InvalidInterfaceException
101
+	 * @since 4.10.2.p
102
+	 */
103
+	protected function getAttendeeModel()
104
+	{
105
+		if (! $this->attendee_model instanceof EEM_Attendee) {
106
+			$this->attendee_model = $this->loader->getShared('EEM_Attendee');
107
+		}
108
+		return $this->attendee_model;
109
+	}
110
+
111
+
112
+	/**
113
+	 * @return EEM_Event
114
+	 * @throws InvalidArgumentException
115
+	 * @throws InvalidDataTypeException
116
+	 * @throws InvalidInterfaceException
117
+	 * @since 4.10.2.p
118
+	 */
119
+	protected function getEventModel()
120
+	{
121
+		if (! $this->event_model instanceof EEM_Event) {
122
+			$this->event_model = $this->loader->getShared('EEM_Event');
123
+		}
124
+		return $this->event_model;
125
+	}
126
+
127
+	/**
128
+	 * @return EEM_Status
129
+	 * @throws InvalidArgumentException
130
+	 * @throws InvalidDataTypeException
131
+	 * @throws InvalidInterfaceException
132
+	 * @since 4.10.2.p
133
+	 */
134
+	protected function getStatusModel()
135
+	{
136
+		if (! $this->status_model instanceof EEM_Status) {
137
+			$this->status_model = $this->loader->getShared('EEM_Status');
138
+		}
139
+		return $this->status_model;
140
+	}
141
+
142
+
143
+	public function wp_loaded()
144
+	{
145
+		// when adding a new registration...
146
+		if (isset($this->_req_data['action']) && $this->_req_data['action'] === 'new_registration') {
147
+			EE_System::do_not_cache();
148
+			if (! isset($this->_req_data['processing_registration'])
149
+				|| absint($this->_req_data['processing_registration']) !== 1
150
+			) {
151
+				// and it's NOT the attendee information reg step
152
+				// force cookie expiration by setting time to last week
153
+				setcookie('ee_registration_added', 0, time() - WEEK_IN_SECONDS, '/');
154
+				// and update the global
155
+				$_COOKIE['ee_registration_added'] = 0;
156
+			}
157
+		}
158
+	}
159
+
160
+
161
+	protected function _init_page_props()
162
+	{
163
+		$this->page_slug = REG_PG_SLUG;
164
+		$this->_admin_base_url = REG_ADMIN_URL;
165
+		$this->_admin_base_path = REG_ADMIN;
166
+		$this->page_label = esc_html__('Registrations', 'event_espresso');
167
+		$this->_cpt_routes = array(
168
+			'add_new_attendee' => 'espresso_attendees',
169
+			'edit_attendee'    => 'espresso_attendees',
170
+			'insert_attendee'  => 'espresso_attendees',
171
+			'update_attendee'  => 'espresso_attendees',
172
+		);
173
+		$this->_cpt_model_names = array(
174
+			'add_new_attendee' => 'EEM_Attendee',
175
+			'edit_attendee'    => 'EEM_Attendee',
176
+		);
177
+		$this->_cpt_edit_routes = array(
178
+			'espresso_attendees' => 'edit_attendee',
179
+		);
180
+		$this->_pagenow_map = array(
181
+			'add_new_attendee' => 'post-new.php',
182
+			'edit_attendee'    => 'post.php',
183
+			'trash'            => 'post.php',
184
+		);
185
+		add_action('edit_form_after_title', array($this, 'after_title_form_fields'), 10);
186
+		// add filters so that the comment urls don't take users to a confusing 404 page
187
+		add_filter('get_comment_link', array($this, 'clear_comment_link'), 10, 3);
188
+	}
189
+
190
+
191
+	public function clear_comment_link($link, $comment, $args)
192
+	{
193
+		// gotta make sure this only happens on this route
194
+		$post_type = get_post_type($comment->comment_post_ID);
195
+		if ($post_type === 'espresso_attendees') {
196
+			return '#commentsdiv';
197
+		}
198
+		return $link;
199
+	}
200
+
201
+
202
+	protected function _ajax_hooks()
203
+	{
204
+		// todo: all hooks for registrations ajax goes in here
205
+		add_action('wp_ajax_toggle_checkin_status', array($this, 'toggle_checkin_status'));
206
+	}
207
+
208
+
209
+	protected function _define_page_props()
210
+	{
211
+		$this->_admin_page_title = $this->page_label;
212
+		$this->_labels = array(
213
+			'buttons'                      => array(
214
+				'add-registrant'      => esc_html__('Add New Registration', 'event_espresso'),
215
+				'add-attendee'        => esc_html__('Add Contact', 'event_espresso'),
216
+				'edit'                => esc_html__('Edit Contact', 'event_espresso'),
217
+				'report'              => esc_html__('Event Registrations CSV Report', 'event_espresso'),
218
+				'report_all'          => esc_html__('All Registrations CSV Report', 'event_espresso'),
219
+				'report_filtered'     => esc_html__('Filtered CSV Report', 'event_espresso'),
220
+				'contact_list_report' => esc_html__('Contact List Report', 'event_espresso'),
221
+				'contact_list_export' => esc_html__('Export Data', 'event_espresso'),
222
+			),
223
+			'publishbox'                   => array(
224
+				'add_new_attendee' => esc_html__('Add Contact Record', 'event_espresso'),
225
+				'edit_attendee'    => esc_html__('Update Contact Record', 'event_espresso'),
226
+			),
227
+			'hide_add_button_on_cpt_route' => array(
228
+				'edit_attendee' => true,
229
+			),
230
+		);
231
+	}
232
+
233
+
234
+	/**
235
+	 *        grab url requests and route them
236
+	 *
237
+	 * @access private
238
+	 * @return void
239
+	 * @throws EE_Error
240
+	 */
241
+	public function _set_page_routes()
242
+	{
243
+		$this->_get_registration_status_array();
244
+		$reg_id = ! empty($this->_req_data['_REG_ID']) && ! is_array($this->_req_data['_REG_ID'])
245
+			? $this->_req_data['_REG_ID'] : 0;
246
+		$reg_id = empty($reg_id) && ! empty($this->_req_data['reg_status_change_form']['REG_ID'])
247
+			? $this->_req_data['reg_status_change_form']['REG_ID']
248
+			: $reg_id;
249
+		$att_id = ! empty($this->_req_data['ATT_ID']) && ! is_array($this->_req_data['ATT_ID'])
250
+			? $this->_req_data['ATT_ID'] : 0;
251
+		$att_id = ! empty($this->_req_data['post']) && ! is_array($this->_req_data['post'])
252
+			? $this->_req_data['post']
253
+			: $att_id;
254
+		$this->_page_routes = array(
255
+			'default'                             => array(
256
+				'func'       => '_registrations_overview_list_table',
257
+				'capability' => 'ee_read_registrations',
258
+			),
259
+			'view_registration'                   => array(
260
+				'func'       => '_registration_details',
261
+				'capability' => 'ee_read_registration',
262
+				'obj_id'     => $reg_id,
263
+			),
264
+			'edit_registration'                   => array(
265
+				'func'               => '_update_attendee_registration_form',
266
+				'noheader'           => true,
267
+				'headers_sent_route' => 'view_registration',
268
+				'capability'         => 'ee_edit_registration',
269
+				'obj_id'             => $reg_id,
270
+				'_REG_ID'            => $reg_id,
271
+			),
272
+			'trash_registrations'                 => array(
273
+				'func'       => '_trash_or_restore_registrations',
274
+				'args'       => array('trash' => true),
275
+				'noheader'   => true,
276
+				'capability' => 'ee_delete_registrations',
277
+			),
278
+			'restore_registrations'               => array(
279
+				'func'       => '_trash_or_restore_registrations',
280
+				'args'       => array('trash' => false),
281
+				'noheader'   => true,
282
+				'capability' => 'ee_delete_registrations',
283
+			),
284
+			'delete_registrations'                => array(
285
+				'func'       => '_delete_registrations',
286
+				'noheader'   => true,
287
+				'capability' => 'ee_delete_registrations',
288
+			),
289
+			'new_registration'                    => array(
290
+				'func'       => 'new_registration',
291
+				'capability' => 'ee_edit_registrations',
292
+			),
293
+			'process_reg_step'                    => array(
294
+				'func'       => 'process_reg_step',
295
+				'noheader'   => true,
296
+				'capability' => 'ee_edit_registrations',
297
+			),
298
+			'redirect_to_txn'                     => array(
299
+				'func'       => 'redirect_to_txn',
300
+				'noheader'   => true,
301
+				'capability' => 'ee_edit_registrations',
302
+			),
303
+			'change_reg_status'                   => array(
304
+				'func'       => '_change_reg_status',
305
+				'noheader'   => true,
306
+				'capability' => 'ee_edit_registration',
307
+				'obj_id'     => $reg_id,
308
+			),
309
+			'approve_registration'                => array(
310
+				'func'       => 'approve_registration',
311
+				'noheader'   => true,
312
+				'capability' => 'ee_edit_registration',
313
+				'obj_id'     => $reg_id,
314
+			),
315
+			'approve_and_notify_registration'     => array(
316
+				'func'       => 'approve_registration',
317
+				'noheader'   => true,
318
+				'args'       => array(true),
319
+				'capability' => 'ee_edit_registration',
320
+				'obj_id'     => $reg_id,
321
+			),
322
+			'approve_registrations'               => array(
323
+				'func'       => 'bulk_action_on_registrations',
324
+				'noheader'   => true,
325
+				'capability' => 'ee_edit_registrations',
326
+				'args'       => array('approve'),
327
+			),
328
+			'approve_and_notify_registrations'    => array(
329
+				'func'       => 'bulk_action_on_registrations',
330
+				'noheader'   => true,
331
+				'capability' => 'ee_edit_registrations',
332
+				'args'       => array('approve', true),
333
+			),
334
+			'decline_registration'                => array(
335
+				'func'       => 'decline_registration',
336
+				'noheader'   => true,
337
+				'capability' => 'ee_edit_registration',
338
+				'obj_id'     => $reg_id,
339
+			),
340
+			'decline_and_notify_registration'     => array(
341
+				'func'       => 'decline_registration',
342
+				'noheader'   => true,
343
+				'args'       => array(true),
344
+				'capability' => 'ee_edit_registration',
345
+				'obj_id'     => $reg_id,
346
+			),
347
+			'decline_registrations'               => array(
348
+				'func'       => 'bulk_action_on_registrations',
349
+				'noheader'   => true,
350
+				'capability' => 'ee_edit_registrations',
351
+				'args'       => array('decline'),
352
+			),
353
+			'decline_and_notify_registrations'    => array(
354
+				'func'       => 'bulk_action_on_registrations',
355
+				'noheader'   => true,
356
+				'capability' => 'ee_edit_registrations',
357
+				'args'       => array('decline', true),
358
+			),
359
+			'pending_registration'                => array(
360
+				'func'       => 'pending_registration',
361
+				'noheader'   => true,
362
+				'capability' => 'ee_edit_registration',
363
+				'obj_id'     => $reg_id,
364
+			),
365
+			'pending_and_notify_registration'     => array(
366
+				'func'       => 'pending_registration',
367
+				'noheader'   => true,
368
+				'args'       => array(true),
369
+				'capability' => 'ee_edit_registration',
370
+				'obj_id'     => $reg_id,
371
+			),
372
+			'pending_registrations'               => array(
373
+				'func'       => 'bulk_action_on_registrations',
374
+				'noheader'   => true,
375
+				'capability' => 'ee_edit_registrations',
376
+				'args'       => array('pending'),
377
+			),
378
+			'pending_and_notify_registrations'    => array(
379
+				'func'       => 'bulk_action_on_registrations',
380
+				'noheader'   => true,
381
+				'capability' => 'ee_edit_registrations',
382
+				'args'       => array('pending', true),
383
+			),
384
+			'no_approve_registration'             => array(
385
+				'func'       => 'not_approve_registration',
386
+				'noheader'   => true,
387
+				'capability' => 'ee_edit_registration',
388
+				'obj_id'     => $reg_id,
389
+			),
390
+			'no_approve_and_notify_registration'  => array(
391
+				'func'       => 'not_approve_registration',
392
+				'noheader'   => true,
393
+				'args'       => array(true),
394
+				'capability' => 'ee_edit_registration',
395
+				'obj_id'     => $reg_id,
396
+			),
397
+			'no_approve_registrations'            => array(
398
+				'func'       => 'bulk_action_on_registrations',
399
+				'noheader'   => true,
400
+				'capability' => 'ee_edit_registrations',
401
+				'args'       => array('not_approve'),
402
+			),
403
+			'no_approve_and_notify_registrations' => array(
404
+				'func'       => 'bulk_action_on_registrations',
405
+				'noheader'   => true,
406
+				'capability' => 'ee_edit_registrations',
407
+				'args'       => array('not_approve', true),
408
+			),
409
+			'cancel_registration'                 => array(
410
+				'func'       => 'cancel_registration',
411
+				'noheader'   => true,
412
+				'capability' => 'ee_edit_registration',
413
+				'obj_id'     => $reg_id,
414
+			),
415
+			'cancel_and_notify_registration'      => array(
416
+				'func'       => 'cancel_registration',
417
+				'noheader'   => true,
418
+				'args'       => array(true),
419
+				'capability' => 'ee_edit_registration',
420
+				'obj_id'     => $reg_id,
421
+			),
422
+			'cancel_registrations'                => array(
423
+				'func'       => 'bulk_action_on_registrations',
424
+				'noheader'   => true,
425
+				'capability' => 'ee_edit_registrations',
426
+				'args'       => array('cancel'),
427
+			),
428
+			'cancel_and_notify_registrations'     => array(
429
+				'func'       => 'bulk_action_on_registrations',
430
+				'noheader'   => true,
431
+				'capability' => 'ee_edit_registrations',
432
+				'args'       => array('cancel', true),
433
+			),
434
+			'wait_list_registration'              => array(
435
+				'func'       => 'wait_list_registration',
436
+				'noheader'   => true,
437
+				'capability' => 'ee_edit_registration',
438
+				'obj_id'     => $reg_id,
439
+			),
440
+			'wait_list_and_notify_registration'   => array(
441
+				'func'       => 'wait_list_registration',
442
+				'noheader'   => true,
443
+				'args'       => array(true),
444
+				'capability' => 'ee_edit_registration',
445
+				'obj_id'     => $reg_id,
446
+			),
447
+			'contact_list'                        => array(
448
+				'func'       => '_attendee_contact_list_table',
449
+				'capability' => 'ee_read_contacts',
450
+			),
451
+			'add_new_attendee'                    => array(
452
+				'func' => '_create_new_cpt_item',
453
+				'args' => array(
454
+					'new_attendee' => true,
455
+					'capability'   => 'ee_edit_contacts',
456
+				),
457
+			),
458
+			'edit_attendee'                       => array(
459
+				'func'       => '_edit_cpt_item',
460
+				'capability' => 'ee_edit_contacts',
461
+				'obj_id'     => $att_id,
462
+			),
463
+			'duplicate_attendee'                  => array(
464
+				'func'       => '_duplicate_attendee',
465
+				'noheader'   => true,
466
+				'capability' => 'ee_edit_contacts',
467
+				'obj_id'     => $att_id,
468
+			),
469
+			'insert_attendee'                     => array(
470
+				'func'       => '_insert_or_update_attendee',
471
+				'args'       => array(
472
+					'new_attendee' => true,
473
+				),
474
+				'noheader'   => true,
475
+				'capability' => 'ee_edit_contacts',
476
+			),
477
+			'update_attendee'                     => array(
478
+				'func'       => '_insert_or_update_attendee',
479
+				'args'       => array(
480
+					'new_attendee' => false,
481
+				),
482
+				'noheader'   => true,
483
+				'capability' => 'ee_edit_contacts',
484
+				'obj_id'     => $att_id,
485
+			),
486
+			'trash_attendees'                     => array(
487
+				'func'       => '_trash_or_restore_attendees',
488
+				'args'       => array(
489
+					'trash' => 'true',
490
+				),
491
+				'noheader'   => true,
492
+				'capability' => 'ee_delete_contacts',
493
+			),
494
+			'trash_attendee'                      => array(
495
+				'func'       => '_trash_or_restore_attendees',
496
+				'args'       => array(
497
+					'trash' => true,
498
+				),
499
+				'noheader'   => true,
500
+				'capability' => 'ee_delete_contacts',
501
+				'obj_id'     => $att_id,
502
+			),
503
+			'restore_attendees'                   => array(
504
+				'func'       => '_trash_or_restore_attendees',
505
+				'args'       => array(
506
+					'trash' => false,
507
+				),
508
+				'noheader'   => true,
509
+				'capability' => 'ee_delete_contacts',
510
+				'obj_id'     => $att_id,
511
+			),
512
+			'resend_registration'                 => array(
513
+				'func'       => '_resend_registration',
514
+				'noheader'   => true,
515
+				'capability' => 'ee_send_message',
516
+			),
517
+			'registrations_report'                => array(
518
+				'func'       => '_registrations_report',
519
+				'noheader'   => true,
520
+				'capability' => 'ee_read_registrations',
521
+			),
522
+			'contact_list_export'                 => array(
523
+				'func'       => '_contact_list_export',
524
+				'noheader'   => true,
525
+				'capability' => 'export',
526
+			),
527
+			'contact_list_report'                 => array(
528
+				'func'       => '_contact_list_report',
529
+				'noheader'   => true,
530
+				'capability' => 'ee_read_contacts',
531
+			),
532
+		);
533
+	}
534
+
535
+
536
+	protected function _set_page_config()
537
+	{
538
+		$this->_page_config = array(
539
+			'default'           => array(
540
+				'nav'           => array(
541
+					'label' => esc_html__('Overview', 'event_espresso'),
542
+					'order' => 5,
543
+				),
544
+				'help_tabs'     => array(
545
+					'registrations_overview_help_tab'                       => array(
546
+						'title'    => esc_html__('Registrations Overview', 'event_espresso'),
547
+						'filename' => 'registrations_overview',
548
+					),
549
+					'registrations_overview_table_column_headings_help_tab' => array(
550
+						'title'    => esc_html__('Registrations Table Column Headings', 'event_espresso'),
551
+						'filename' => 'registrations_overview_table_column_headings',
552
+					),
553
+					'registrations_overview_filters_help_tab'               => array(
554
+						'title'    => esc_html__('Registration Filters', 'event_espresso'),
555
+						'filename' => 'registrations_overview_filters',
556
+					),
557
+					'registrations_overview_views_help_tab'                 => array(
558
+						'title'    => esc_html__('Registration Views', 'event_espresso'),
559
+						'filename' => 'registrations_overview_views',
560
+					),
561
+					'registrations_regoverview_other_help_tab'              => array(
562
+						'title'    => esc_html__('Registrations Other', 'event_espresso'),
563
+						'filename' => 'registrations_overview_other',
564
+					),
565
+				),
566
+				'help_tour'     => array('Registration_Overview_Help_Tour'),
567
+				'qtips'         => array('Registration_List_Table_Tips'),
568
+				'list_table'    => 'EE_Registrations_List_Table',
569
+				'require_nonce' => false,
570
+			),
571
+			'view_registration' => array(
572
+				'nav'           => array(
573
+					'label'      => esc_html__('REG Details', 'event_espresso'),
574
+					'order'      => 15,
575
+					'url'        => isset($this->_req_data['_REG_ID'])
576
+						? add_query_arg(array('_REG_ID' => $this->_req_data['_REG_ID']), $this->_current_page_view_url)
577
+						: $this->_admin_base_url,
578
+					'persistent' => false,
579
+				),
580
+				'help_tabs'     => array(
581
+					'registrations_details_help_tab'                    => array(
582
+						'title'    => esc_html__('Registration Details', 'event_espresso'),
583
+						'filename' => 'registrations_details',
584
+					),
585
+					'registrations_details_table_help_tab'              => array(
586
+						'title'    => esc_html__('Registration Details Table', 'event_espresso'),
587
+						'filename' => 'registrations_details_table',
588
+					),
589
+					'registrations_details_form_answers_help_tab'       => array(
590
+						'title'    => esc_html__('Registration Form Answers', 'event_espresso'),
591
+						'filename' => 'registrations_details_form_answers',
592
+					),
593
+					'registrations_details_registrant_details_help_tab' => array(
594
+						'title'    => esc_html__('Contact Details', 'event_espresso'),
595
+						'filename' => 'registrations_details_registrant_details',
596
+					),
597
+				),
598
+				'help_tour'     => array('Registration_Details_Help_Tour'),
599
+				'metaboxes'     => array_merge(
600
+					$this->_default_espresso_metaboxes,
601
+					array('_registration_details_metaboxes')
602
+				),
603
+				'require_nonce' => false,
604
+			),
605
+			'new_registration'  => array(
606
+				'nav'           => array(
607
+					'label'      => esc_html__('Add New Registration', 'event_espresso'),
608
+					'url'        => '#',
609
+					'order'      => 15,
610
+					'persistent' => false,
611
+				),
612
+				'metaboxes'     => $this->_default_espresso_metaboxes,
613
+				'labels'        => array(
614
+					'publishbox' => esc_html__('Save Registration', 'event_espresso'),
615
+				),
616
+				'require_nonce' => false,
617
+			),
618
+			'add_new_attendee'  => array(
619
+				'nav'           => array(
620
+					'label'      => esc_html__('Add Contact', 'event_espresso'),
621
+					'order'      => 15,
622
+					'persistent' => false,
623
+				),
624
+				'metaboxes'     => array_merge(
625
+					$this->_default_espresso_metaboxes,
626
+					array('_publish_post_box', 'attendee_editor_metaboxes')
627
+				),
628
+				'require_nonce' => false,
629
+			),
630
+			'edit_attendee'     => array(
631
+				'nav'           => array(
632
+					'label'      => esc_html__('Edit Contact', 'event_espresso'),
633
+					'order'      => 15,
634
+					'persistent' => false,
635
+					'url'        => isset($this->_req_data['ATT_ID'])
636
+						? add_query_arg(array('ATT_ID' => $this->_req_data['ATT_ID']), $this->_current_page_view_url)
637
+						: $this->_admin_base_url,
638
+				),
639
+				'metaboxes'     => array('attendee_editor_metaboxes'),
640
+				'require_nonce' => false,
641
+			),
642
+			'contact_list'      => array(
643
+				'nav'           => array(
644
+					'label' => esc_html__('Contact List', 'event_espresso'),
645
+					'order' => 20,
646
+				),
647
+				'list_table'    => 'EE_Attendee_Contact_List_Table',
648
+				'help_tabs'     => array(
649
+					'registrations_contact_list_help_tab'                       => array(
650
+						'title'    => esc_html__('Registrations Contact List', 'event_espresso'),
651
+						'filename' => 'registrations_contact_list',
652
+					),
653
+					'registrations_contact-list_table_column_headings_help_tab' => array(
654
+						'title'    => esc_html__('Contact List Table Column Headings', 'event_espresso'),
655
+						'filename' => 'registrations_contact_list_table_column_headings',
656
+					),
657
+					'registrations_contact_list_views_help_tab'                 => array(
658
+						'title'    => esc_html__('Contact List Views', 'event_espresso'),
659
+						'filename' => 'registrations_contact_list_views',
660
+					),
661
+					'registrations_contact_list_other_help_tab'                 => array(
662
+						'title'    => esc_html__('Contact List Other', 'event_espresso'),
663
+						'filename' => 'registrations_contact_list_other',
664
+					),
665
+				),
666
+				'help_tour'     => array('Contact_List_Help_Tour'),
667
+				'metaboxes'     => array(),
668
+				'require_nonce' => false,
669
+			),
670
+			// override default cpt routes
671
+			'create_new'        => '',
672
+			'edit'              => '',
673
+		);
674
+	}
675
+
676
+
677
+	/**
678
+	 * The below methods aren't used by this class currently
679
+	 */
680
+	protected function _add_screen_options()
681
+	{
682
+	}
683
+
684
+
685
+	protected function _add_feature_pointers()
686
+	{
687
+	}
688
+
689
+
690
+	public function admin_init()
691
+	{
692
+		EE_Registry::$i18n_js_strings['update_att_qstns'] = esc_html__(
693
+			'click "Update Registration Questions" to save your changes',
694
+			'event_espresso'
695
+		);
696
+	}
697
+
698
+
699
+	public function admin_notices()
700
+	{
701
+	}
702
+
703
+
704
+	public function admin_footer_scripts()
705
+	{
706
+	}
707
+
708
+
709
+	/**
710
+	 *        get list of registration statuses
711
+	 *
712
+	 * @access private
713
+	 * @return void
714
+	 * @throws EE_Error
715
+	 */
716
+	private function _get_registration_status_array()
717
+	{
718
+		self::$_reg_status = EEM_Registration::reg_status_array(array(), true);
719
+	}
720
+
721
+
722
+	/**
723
+	 * @throws InvalidArgumentException
724
+	 * @throws InvalidDataTypeException
725
+	 * @throws InvalidInterfaceException
726
+	 * @since 4.10.2.p
727
+	 */
728
+	protected function _add_screen_options_default()
729
+	{
730
+		$this->_per_page_screen_option();
731
+	}
732
+
733
+
734
+	/**
735
+	 * @throws InvalidArgumentException
736
+	 * @throws InvalidDataTypeException
737
+	 * @throws InvalidInterfaceException
738
+	 * @since 4.10.2.p
739
+	 */
740
+	protected function _add_screen_options_contact_list()
741
+	{
742
+		$page_title = $this->_admin_page_title;
743
+		$this->_admin_page_title = esc_html__('Contacts', 'event_espresso');
744
+		$this->_per_page_screen_option();
745
+		$this->_admin_page_title = $page_title;
746
+	}
747
+
748
+
749
+	public function load_scripts_styles()
750
+	{
751
+		// style
752
+		wp_register_style(
753
+			'espresso_reg',
754
+			REG_ASSETS_URL . 'espresso_registrations_admin.css',
755
+			array('ee-admin-css'),
756
+			EVENT_ESPRESSO_VERSION
757
+		);
758
+		wp_enqueue_style('espresso_reg');
759
+		// script
760
+		wp_register_script(
761
+			'espresso_reg',
762
+			REG_ASSETS_URL . 'espresso_registrations_admin.js',
763
+			array('jquery-ui-datepicker', 'jquery-ui-draggable', 'ee_admin_js'),
764
+			EVENT_ESPRESSO_VERSION,
765
+			true
766
+		);
767
+		wp_enqueue_script('espresso_reg');
768
+	}
769
+
770
+
771
+	/**
772
+	 * @throws EE_Error
773
+	 * @throws InvalidArgumentException
774
+	 * @throws InvalidDataTypeException
775
+	 * @throws InvalidInterfaceException
776
+	 * @throws ReflectionException
777
+	 * @since 4.10.2.p
778
+	 */
779
+	public function load_scripts_styles_edit_attendee()
780
+	{
781
+		// stuff to only show up on our attendee edit details page.
782
+		$attendee_details_translations = array(
783
+			'att_publish_text' => sprintf(
784
+				/* translators: The date and time */
785
+				wp_strip_all_tags(__('Created on: %s', 'event_espresso')),
786
+				'<b>' . $this->_cpt_model_obj->get_datetime('ATT_created') . '</b>'
787
+			),
788
+		);
789
+		wp_localize_script('espresso_reg', 'ATTENDEE_DETAILS', $attendee_details_translations);
790
+		wp_enqueue_script('jquery-validate');
791
+	}
792
+
793
+
794
+	/**
795
+	 * @throws EE_Error
796
+	 * @throws InvalidArgumentException
797
+	 * @throws InvalidDataTypeException
798
+	 * @throws InvalidInterfaceException
799
+	 * @throws ReflectionException
800
+	 * @since 4.10.2.p
801
+	 */
802
+	public function load_scripts_styles_view_registration()
803
+	{
804
+		// styles
805
+		wp_enqueue_style('espresso-ui-theme');
806
+		// scripts
807
+		$this->_get_reg_custom_questions_form($this->_registration->ID());
808
+		$this->_reg_custom_questions_form->wp_enqueue_scripts(true);
809
+	}
810
+
811
+
812
+	public function load_scripts_styles_contact_list()
813
+	{
814
+		wp_dequeue_style('espresso_reg');
815
+		wp_register_style(
816
+			'espresso_att',
817
+			REG_ASSETS_URL . 'espresso_attendees_admin.css',
818
+			array('ee-admin-css'),
819
+			EVENT_ESPRESSO_VERSION
820
+		);
821
+		wp_enqueue_style('espresso_att');
822
+	}
823
+
824
+
825
+	public function load_scripts_styles_new_registration()
826
+	{
827
+		wp_register_script(
828
+			'ee-spco-for-admin',
829
+			REG_ASSETS_URL . 'spco_for_admin.js',
830
+			array('underscore', 'jquery'),
831
+			EVENT_ESPRESSO_VERSION,
832
+			true
833
+		);
834
+		wp_enqueue_script('ee-spco-for-admin');
835
+		add_filter('FHEE__EED_Ticket_Selector__load_tckt_slctr_assets', '__return_true');
836
+		EE_Form_Section_Proper::wp_enqueue_scripts();
837
+		EED_Ticket_Selector::load_tckt_slctr_assets();
838
+		EE_Datepicker_Input::enqueue_styles_and_scripts();
839
+	}
840
+
841
+
842
+	public function AHEE__EE_Admin_Page__route_admin_request_resend_registration()
843
+	{
844
+		add_filter('FHEE_load_EE_messages', '__return_true');
845
+	}
846
+
847
+
848
+	public function AHEE__EE_Admin_Page__route_admin_request_approve_registration()
849
+	{
850
+		add_filter('FHEE_load_EE_messages', '__return_true');
851
+	}
852
+
853
+
854
+	/**
855
+	 * @throws EE_Error
856
+	 * @throws InvalidArgumentException
857
+	 * @throws InvalidDataTypeException
858
+	 * @throws InvalidInterfaceException
859
+	 * @throws ReflectionException
860
+	 * @since 4.10.2.p
861
+	 */
862
+	protected function _set_list_table_views_default()
863
+	{
864
+		// for notification related bulk actions we need to make sure only active messengers have an option.
865
+		EED_Messages::set_autoloaders();
866
+		/** @type EE_Message_Resource_Manager $message_resource_manager */
867
+		$message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
868
+		$active_mts = $message_resource_manager->list_of_active_message_types();
869
+		// key= bulk_action_slug, value= message type.
870
+		$match_array = array(
871
+			'approve_registrations'    => 'registration',
872
+			'decline_registrations'    => 'declined_registration',
873
+			'pending_registrations'    => 'pending_approval',
874
+			'no_approve_registrations' => 'not_approved_registration',
875
+			'cancel_registrations'     => 'cancelled_registration',
876
+		);
877
+		$can_send = EE_Registry::instance()->CAP->current_user_can(
878
+			'ee_send_message',
879
+			'batch_send_messages'
880
+		);
881
+		/** setup reg status bulk actions **/
882
+		$def_reg_status_actions['approve_registrations'] = esc_html__('Approve Registrations', 'event_espresso');
883
+		if ($can_send && in_array($match_array['approve_registrations'], $active_mts, true)) {
884
+			$def_reg_status_actions['approve_and_notify_registrations'] = esc_html__(
885
+				'Approve and Notify Registrations',
886
+				'event_espresso'
887
+			);
888
+		}
889
+		$def_reg_status_actions['decline_registrations'] = esc_html__('Decline Registrations', 'event_espresso');
890
+		if ($can_send && in_array($match_array['decline_registrations'], $active_mts, true)) {
891
+			$def_reg_status_actions['decline_and_notify_registrations'] = esc_html__(
892
+				'Decline and Notify Registrations',
893
+				'event_espresso'
894
+			);
895
+		}
896
+		$def_reg_status_actions['pending_registrations'] = esc_html__(
897
+			'Set Registrations to Pending Payment',
898
+			'event_espresso'
899
+		);
900
+		if ($can_send && in_array($match_array['pending_registrations'], $active_mts, true)) {
901
+			$def_reg_status_actions['pending_and_notify_registrations'] = esc_html__(
902
+				'Set Registrations to Pending Payment and Notify',
903
+				'event_espresso'
904
+			);
905
+		}
906
+		$def_reg_status_actions['no_approve_registrations'] = esc_html__(
907
+			'Set Registrations to Not Approved',
908
+			'event_espresso'
909
+		);
910
+		if ($can_send && in_array($match_array['no_approve_registrations'], $active_mts, true)) {
911
+			$def_reg_status_actions['no_approve_and_notify_registrations'] = esc_html__(
912
+				'Set Registrations to Not Approved and Notify',
913
+				'event_espresso'
914
+			);
915
+		}
916
+		$def_reg_status_actions['cancel_registrations'] = esc_html__('Cancel Registrations', 'event_espresso');
917
+		if ($can_send && in_array($match_array['cancel_registrations'], $active_mts, true)) {
918
+			$def_reg_status_actions['cancel_and_notify_registrations'] = esc_html__(
919
+				'Cancel Registrations and Notify',
920
+				'event_espresso'
921
+			);
922
+		}
923
+		$def_reg_status_actions = apply_filters(
924
+			'FHEE__Registrations_Admin_Page___set_list_table_views_default__def_reg_status_actions_array',
925
+			$def_reg_status_actions,
926
+			$active_mts,
927
+			$can_send
928
+		);
929
+
930
+		$this->_views = array(
931
+			'all'   => array(
932
+				'slug'        => 'all',
933
+				'label'       => esc_html__('View All Registrations', 'event_espresso'),
934
+				'count'       => 0,
935
+				'bulk_action' => array_merge(
936
+					$def_reg_status_actions,
937
+					array(
938
+						'trash_registrations' => esc_html__('Trash Registrations', 'event_espresso'),
939
+					)
940
+				),
941
+			),
942
+			'month' => array(
943
+				'slug'        => 'month',
944
+				'label'       => esc_html__('This Month', 'event_espresso'),
945
+				'count'       => 0,
946
+				'bulk_action' => array_merge(
947
+					$def_reg_status_actions,
948
+					array(
949
+						'trash_registrations' => esc_html__('Trash Registrations', 'event_espresso'),
950
+					)
951
+				),
952
+			),
953
+			'today' => array(
954
+				'slug'        => 'today',
955
+				'label'       => sprintf(
956
+					esc_html__('Today - %s', 'event_espresso'),
957
+					date('M d, Y', current_time('timestamp'))
958
+				),
959
+				'count'       => 0,
960
+				'bulk_action' => array_merge(
961
+					$def_reg_status_actions,
962
+					array(
963
+						'trash_registrations' => esc_html__('Trash Registrations', 'event_espresso'),
964
+					)
965
+				),
966
+			),
967
+		);
968
+		if (EE_Registry::instance()->CAP->current_user_can(
969
+			'ee_delete_registrations',
970
+			'espresso_registrations_delete_registration'
971
+		)) {
972
+			$this->_views['incomplete'] = array(
973
+				'slug'        => 'incomplete',
974
+				'label'       => esc_html__('Incomplete', 'event_espresso'),
975
+				'count'       => 0,
976
+				'bulk_action' => array(
977
+					'trash_registrations' => esc_html__('Trash Registrations', 'event_espresso'),
978
+				),
979
+			);
980
+			$this->_views['trash'] = array(
981
+				'slug'        => 'trash',
982
+				'label'       => esc_html__('Trash', 'event_espresso'),
983
+				'count'       => 0,
984
+				'bulk_action' => array(
985
+					'restore_registrations' => esc_html__('Restore Registrations', 'event_espresso'),
986
+					'delete_registrations'  => esc_html__('Delete Registrations Permanently', 'event_espresso'),
987
+				),
988
+			);
989
+		}
990
+	}
991
+
992
+
993
+	protected function _set_list_table_views_contact_list()
994
+	{
995
+		$this->_views = array(
996
+			'in_use' => array(
997
+				'slug'        => 'in_use',
998
+				'label'       => esc_html__('In Use', 'event_espresso'),
999
+				'count'       => 0,
1000
+				'bulk_action' => array(
1001
+					'trash_attendees' => esc_html__('Move to Trash', 'event_espresso'),
1002
+				),
1003
+			),
1004
+		);
1005
+		if (EE_Registry::instance()->CAP->current_user_can(
1006
+			'ee_delete_contacts',
1007
+			'espresso_registrations_trash_attendees'
1008
+		)
1009
+		) {
1010
+			$this->_views['trash'] = array(
1011
+				'slug'        => 'trash',
1012
+				'label'       => esc_html__('Trash', 'event_espresso'),
1013
+				'count'       => 0,
1014
+				'bulk_action' => array(
1015
+					'restore_attendees' => esc_html__('Restore from Trash', 'event_espresso'),
1016
+				),
1017
+			);
1018
+		}
1019
+	}
1020
+
1021
+
1022
+	protected function _registration_legend_items()
1023
+	{
1024
+		$fc_items = array(
1025
+			'star-icon'        => array(
1026
+				'class' => 'dashicons dashicons-star-filled yellow-icon ee-icon-size-8',
1027
+				'desc'  => esc_html__('This is the Primary Registrant', 'event_espresso'),
1028
+			),
1029
+			'view_details'     => array(
1030
+				'class' => 'dashicons dashicons-clipboard',
1031
+				'desc'  => esc_html__('View Registration Details', 'event_espresso'),
1032
+			),
1033
+			'edit_attendee'    => array(
1034
+				'class' => 'ee-icon ee-icon-user-edit ee-icon-size-16',
1035
+				'desc'  => esc_html__('Edit Contact Details', 'event_espresso'),
1036
+			),
1037
+			'view_transaction' => array(
1038
+				'class' => 'dashicons dashicons-cart',
1039
+				'desc'  => esc_html__('View Transaction Details', 'event_espresso'),
1040
+			),
1041
+			'view_invoice'     => array(
1042
+				'class' => 'dashicons dashicons-media-spreadsheet',
1043
+				'desc'  => esc_html__('View Transaction Invoice', 'event_espresso'),
1044
+			),
1045
+		);
1046
+		if (EE_Registry::instance()->CAP->current_user_can(
1047
+			'ee_send_message',
1048
+			'espresso_registrations_resend_registration'
1049
+		)) {
1050
+			$fc_items['resend_registration'] = array(
1051
+				'class' => 'dashicons dashicons-email-alt',
1052
+				'desc'  => esc_html__('Resend Registration Details', 'event_espresso'),
1053
+			);
1054
+		} else {
1055
+			$fc_items['blank'] = array('class' => 'blank', 'desc' => '');
1056
+		}
1057
+		if (EE_Registry::instance()->CAP->current_user_can(
1058
+			'ee_read_global_messages',
1059
+			'view_filtered_messages'
1060
+		)) {
1061
+			$related_for_icon = EEH_MSG_Template::get_message_action_icon('see_notifications_for');
1062
+			if (is_array($related_for_icon) && isset($related_for_icon['css_class'], $related_for_icon['label'])) {
1063
+				$fc_items['view_related_messages'] = array(
1064
+					'class' => $related_for_icon['css_class'],
1065
+					'desc'  => $related_for_icon['label'],
1066
+				);
1067
+			}
1068
+		}
1069
+		$sc_items = array(
1070
+			'approved_status'   => array(
1071
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_approved,
1072
+				'desc'  => EEH_Template::pretty_status(
1073
+					EEM_Registration::status_id_approved,
1074
+					false,
1075
+					'sentence'
1076
+				),
1077
+			),
1078
+			'pending_status'    => array(
1079
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_pending_payment,
1080
+				'desc'  => EEH_Template::pretty_status(
1081
+					EEM_Registration::status_id_pending_payment,
1082
+					false,
1083
+					'sentence'
1084
+				),
1085
+			),
1086
+			'wait_list'         => array(
1087
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_wait_list,
1088
+				'desc'  => EEH_Template::pretty_status(
1089
+					EEM_Registration::status_id_wait_list,
1090
+					false,
1091
+					'sentence'
1092
+				),
1093
+			),
1094
+			'incomplete_status' => array(
1095
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_incomplete,
1096
+				'desc'  => EEH_Template::pretty_status(
1097
+					EEM_Registration::status_id_incomplete,
1098
+					false,
1099
+					'sentence'
1100
+				),
1101
+			),
1102
+			'not_approved'      => array(
1103
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_not_approved,
1104
+				'desc'  => EEH_Template::pretty_status(
1105
+					EEM_Registration::status_id_not_approved,
1106
+					false,
1107
+					'sentence'
1108
+				),
1109
+			),
1110
+			'declined_status'   => array(
1111
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_declined,
1112
+				'desc'  => EEH_Template::pretty_status(
1113
+					EEM_Registration::status_id_declined,
1114
+					false,
1115
+					'sentence'
1116
+				),
1117
+			),
1118
+			'cancelled_status'  => array(
1119
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_cancelled,
1120
+				'desc'  => EEH_Template::pretty_status(
1121
+					EEM_Registration::status_id_cancelled,
1122
+					false,
1123
+					'sentence'
1124
+				),
1125
+			),
1126
+		);
1127
+		return array_merge($fc_items, $sc_items);
1128
+	}
1129
+
1130
+
1131
+
1132
+	/***************************************        REGISTRATION OVERVIEW        **************************************/
1133
+
1134
+
1135
+
1136
+	/**
1137
+	 * @throws DomainException
1138
+	 * @throws EE_Error
1139
+	 * @throws InvalidArgumentException
1140
+	 * @throws InvalidDataTypeException
1141
+	 * @throws InvalidInterfaceException
1142
+	 * @throws ReflectionException
1143
+	 */
1144
+	protected function _registrations_overview_list_table()
1145
+	{
1146
+		$this->appendAddNewRegistrationButtonToPageTitle();
1147
+		$header_text = '';
1148
+		$admin_page_header_decorators = [
1149
+			'EventEspresso\core\domain\services\admin\registrations\list_table\page_header\AttendeeFilterHeader',
1150
+			'EventEspresso\core\domain\services\admin\registrations\list_table\page_header\EventFilterHeader',
1151
+			'EventEspresso\core\domain\services\admin\registrations\list_table\page_header\DateFilterHeader',
1152
+			'EventEspresso\core\domain\services\admin\registrations\list_table\page_header\TicketFilterHeader',
1153
+		];
1154
+		foreach ($admin_page_header_decorators as $admin_page_header_decorator) {
1155
+			$filter_header_decorator = $this->loader->getNew($admin_page_header_decorator);
1156
+			$header_text = $filter_header_decorator->getHeaderText($header_text);
1157
+		}
1158
+		$this->_template_args['admin_page_header'] = $header_text;
1159
+		$this->_template_args['after_list_table'] = $this->_display_legend($this->_registration_legend_items());
1160
+		$this->display_admin_list_table_page_with_no_sidebar();
1161
+	}
1162
+
1163
+
1164
+	/**
1165
+	 * @throws EE_Error
1166
+	 * @throws InvalidArgumentException
1167
+	 * @throws InvalidDataTypeException
1168
+	 * @throws InvalidInterfaceException
1169
+	 */
1170
+	private function appendAddNewRegistrationButtonToPageTitle()
1171
+	{
1172
+		$EVT_ID = ! empty($this->_req_data['event_id'])
1173
+			? absint($this->_req_data['event_id'])
1174
+			: 0;
1175
+		if ($EVT_ID
1176
+			&& EE_Registry::instance()->CAP->current_user_can(
1177
+				'ee_edit_registrations',
1178
+				'espresso_registrations_new_registration',
1179
+				$EVT_ID
1180
+			)
1181
+		) {
1182
+			$this->_admin_page_title .= ' ' . $this->get_action_link_or_button(
1183
+				'new_registration',
1184
+				'add-registrant',
1185
+				array('event_id' => $EVT_ID),
1186
+				'add-new-h2'
1187
+			);
1188
+		}
1189
+	}
1190
+
1191
+
1192
+	/**
1193
+	 * This sets the _registration property for the registration details screen
1194
+	 *
1195
+	 * @access private
1196
+	 * @return bool
1197
+	 * @throws EE_Error
1198
+	 * @throws InvalidArgumentException
1199
+	 * @throws InvalidDataTypeException
1200
+	 * @throws InvalidInterfaceException
1201
+	 */
1202
+	private function _set_registration_object()
1203
+	{
1204
+		// get out if we've already set the object
1205
+		if ($this->_registration instanceof EE_Registration) {
1206
+			return true;
1207
+		}
1208
+		$REG_ID = (! empty($this->_req_data['_REG_ID'])) ? absint($this->_req_data['_REG_ID']) : false;
1209
+		if ($this->_registration = $this->getRegistrationModel()->get_one_by_ID($REG_ID)) {
1210
+			return true;
1211
+		}
1212
+		$error_msg = sprintf(
1213
+			esc_html__(
1214
+				'An error occurred and the details for Registration ID #%s could not be retrieved.',
1215
+				'event_espresso'
1216
+			),
1217
+			$REG_ID
1218
+		);
1219
+		EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__);
1220
+		$this->_registration = null;
1221
+		return false;
1222
+	}
1223
+
1224
+
1225
+	/**
1226
+	 * Used to retrieve registrations for the list table.
1227
+	 *
1228
+	 * @param int  $per_page
1229
+	 * @param bool $count
1230
+	 * @param bool $this_month
1231
+	 * @param bool $today
1232
+	 * @return EE_Registration[]|int
1233
+	 * @throws EE_Error
1234
+	 * @throws InvalidArgumentException
1235
+	 * @throws InvalidDataTypeException
1236
+	 * @throws InvalidInterfaceException
1237
+	 */
1238
+	public function get_registrations(
1239
+		$per_page = 10,
1240
+		$count = false,
1241
+		$this_month = false,
1242
+		$today = false
1243
+	) {
1244
+		if ($this_month) {
1245
+			$this->_req_data['status'] = 'month';
1246
+		}
1247
+		if ($today) {
1248
+			$this->_req_data['status'] = 'today';
1249
+		}
1250
+		$query_params = $this->_get_registration_query_parameters($this->_req_data, $per_page, $count);
1251
+		/**
1252
+		 * Override the default groupby added by EEM_Base so that sorts with multiple order bys work as expected
1253
+		 *
1254
+		 * @link https://events.codebasehq.com/projects/event-espresso/tickets/10093
1255
+		 * @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
1256
+		 *                             or if you have the development copy of EE you can view this at the path:
1257
+		 *                             /docs/G--Model-System/model-query-params.md
1258
+		 */
1259
+		$query_params['group_by'] = '';
1260
+
1261
+		return $count
1262
+			? $this->getRegistrationModel()->count($query_params)
1263
+			/** @type EE_Registration[] */
1264
+			: $this->getRegistrationModel()->get_all($query_params);
1265
+	}
1266
+
1267
+
1268
+	/**
1269
+	 * Retrieves the query parameters to be used by the Registration model for getting registrations.
1270
+	 * Note: this listens to values on the request for some of the query parameters.
1271
+	 *
1272
+	 * @param array $request
1273
+	 * @param int   $per_page
1274
+	 * @param bool  $count
1275
+	 * @return array
1276
+	 * @throws EE_Error
1277
+	 * @throws InvalidArgumentException
1278
+	 * @throws InvalidDataTypeException
1279
+	 * @throws InvalidInterfaceException
1280
+	 */
1281
+	protected function _get_registration_query_parameters(
1282
+		$request = array(),
1283
+		$per_page = 10,
1284
+		$count = false
1285
+	) {
1286
+		/** @var EventEspresso\core\domain\services\admin\registrations\list_table\QueryBuilder $list_table_query_builder */
1287
+		$list_table_query_builder = $this->loader->getNew(
1288
+			'EventEspresso\core\domain\services\admin\registrations\list_table\QueryBuilder',
1289
+			[ $request ]
1290
+		);
1291
+		return $list_table_query_builder->getQueryParams($per_page, $count);
1292
+	}
1293
+
1294
+
1295
+	public function get_registration_status_array()
1296
+	{
1297
+		return self::$_reg_status;
1298
+	}
1299
+
1300
+
1301
+
1302
+
1303
+	/***************************************        REGISTRATION DETAILS        ***************************************/
1304
+	/**
1305
+	 *        generates HTML for the View Registration Details Admin page
1306
+	 *
1307
+	 * @access protected
1308
+	 * @return void
1309
+	 * @throws DomainException
1310
+	 * @throws EE_Error
1311
+	 * @throws InvalidArgumentException
1312
+	 * @throws InvalidDataTypeException
1313
+	 * @throws InvalidInterfaceException
1314
+	 * @throws EntityNotFoundException
1315
+	 * @throws ReflectionException
1316
+	 */
1317
+	protected function _registration_details()
1318
+	{
1319
+		$this->_template_args = array();
1320
+		$this->_set_registration_object();
1321
+		if (is_object($this->_registration)) {
1322
+			$transaction = $this->_registration->transaction()
1323
+				? $this->_registration->transaction()
1324
+				: EE_Transaction::new_instance();
1325
+			$this->_session = $transaction->session_data();
1326
+			$event_id = $this->_registration->event_ID();
1327
+			$this->_template_args['reg_nmbr']['value'] = $this->_registration->ID();
1328
+			$this->_template_args['reg_nmbr']['label'] = esc_html__('Registration Number', 'event_espresso');
1329
+			$this->_template_args['reg_datetime']['value'] = $this->_registration->get_i18n_datetime('REG_date');
1330
+			$this->_template_args['reg_datetime']['label'] = esc_html__('Date', 'event_espresso');
1331
+			$this->_template_args['grand_total'] = $transaction->total();
1332
+			$this->_template_args['currency_sign'] = EE_Registry::instance()->CFG->currency->sign;
1333
+			// link back to overview
1334
+			$this->_template_args['reg_overview_url'] = REG_ADMIN_URL;
1335
+			$this->_template_args['registration'] = $this->_registration;
1336
+			$this->_template_args['filtered_registrations_link'] = EE_Admin_Page::add_query_args_and_nonce(
1337
+				array(
1338
+					'action'   => 'default',
1339
+					'event_id' => $event_id,
1340
+				),
1341
+				REG_ADMIN_URL
1342
+			);
1343
+			$this->_template_args['filtered_transactions_link'] = EE_Admin_Page::add_query_args_and_nonce(
1344
+				array(
1345
+					'action' => 'default',
1346
+					'EVT_ID' => $event_id,
1347
+					'page'   => 'espresso_transactions',
1348
+				),
1349
+				admin_url('admin.php')
1350
+			);
1351
+			$this->_template_args['event_link'] = EE_Admin_Page::add_query_args_and_nonce(
1352
+				array(
1353
+					'page'   => 'espresso_events',
1354
+					'action' => 'edit',
1355
+					'post'   => $event_id,
1356
+				),
1357
+				admin_url('admin.php')
1358
+			);
1359
+			// next and previous links
1360
+			$next_reg = $this->_registration->next(
1361
+				null,
1362
+				array(),
1363
+				'REG_ID'
1364
+			);
1365
+			$this->_template_args['next_registration'] = $next_reg
1366
+				? $this->_next_link(
1367
+					EE_Admin_Page::add_query_args_and_nonce(
1368
+						array(
1369
+							'action'  => 'view_registration',
1370
+							'_REG_ID' => $next_reg['REG_ID'],
1371
+						),
1372
+						REG_ADMIN_URL
1373
+					),
1374
+					'dashicons dashicons-arrow-right ee-icon-size-22'
1375
+				)
1376
+				: '';
1377
+			$previous_reg = $this->_registration->previous(
1378
+				null,
1379
+				array(),
1380
+				'REG_ID'
1381
+			);
1382
+			$this->_template_args['previous_registration'] = $previous_reg
1383
+				? $this->_previous_link(
1384
+					EE_Admin_Page::add_query_args_and_nonce(
1385
+						array(
1386
+							'action'  => 'view_registration',
1387
+							'_REG_ID' => $previous_reg['REG_ID'],
1388
+						),
1389
+						REG_ADMIN_URL
1390
+					),
1391
+					'dashicons dashicons-arrow-left ee-icon-size-22'
1392
+				)
1393
+				: '';
1394
+			// grab header
1395
+			$template_path = REG_TEMPLATE_PATH . 'reg_admin_details_header.template.php';
1396
+			$this->_template_args['REG_ID'] = $this->_registration->ID();
1397
+			$this->_template_args['admin_page_header'] = EEH_Template::display_template(
1398
+				$template_path,
1399
+				$this->_template_args,
1400
+				true
1401
+			);
1402
+		} else {
1403
+			$this->_template_args['admin_page_header'] = $this->display_espresso_notices();
1404
+		}
1405
+		// the details template wrapper
1406
+		$this->display_admin_page_with_sidebar();
1407
+	}
1408
+
1409
+
1410
+	/**
1411
+	 * @throws EE_Error
1412
+	 * @throws InvalidArgumentException
1413
+	 * @throws InvalidDataTypeException
1414
+	 * @throws InvalidInterfaceException
1415
+	 * @throws ReflectionException
1416
+	 * @since 4.10.2.p
1417
+	 */
1418
+	protected function _registration_details_metaboxes()
1419
+	{
1420
+		do_action('AHEE__Registrations_Admin_Page___registration_details_metabox__start', $this);
1421
+		$this->_set_registration_object();
1422
+		$attendee = $this->_registration instanceof EE_Registration ? $this->_registration->attendee() : null;
1423
+		add_meta_box(
1424
+			'edit-reg-status-mbox',
1425
+			esc_html__('Registration Status', 'event_espresso'),
1426
+			array($this, 'set_reg_status_buttons_metabox'),
1427
+			$this->wp_page_slug,
1428
+			'normal',
1429
+			'high'
1430
+		);
1431
+		add_meta_box(
1432
+			'edit-reg-details-mbox',
1433
+			esc_html__('Registration Details', 'event_espresso'),
1434
+			array($this, '_reg_details_meta_box'),
1435
+			$this->wp_page_slug,
1436
+			'normal',
1437
+			'high'
1438
+		);
1439
+		if ($attendee instanceof EE_Attendee
1440
+			&& EE_Registry::instance()->CAP->current_user_can(
1441
+				'ee_read_registration',
1442
+				'edit-reg-questions-mbox',
1443
+				$this->_registration->ID()
1444
+			)
1445
+		) {
1446
+			add_meta_box(
1447
+				'edit-reg-questions-mbox',
1448
+				esc_html__('Registration Form Answers', 'event_espresso'),
1449
+				array($this, '_reg_questions_meta_box'),
1450
+				$this->wp_page_slug,
1451
+				'normal',
1452
+				'high'
1453
+			);
1454
+		}
1455
+		add_meta_box(
1456
+			'edit-reg-registrant-mbox',
1457
+			esc_html__('Contact Details', 'event_espresso'),
1458
+			array($this, '_reg_registrant_side_meta_box'),
1459
+			$this->wp_page_slug,
1460
+			'side',
1461
+			'high'
1462
+		);
1463
+		if ($this->_registration->group_size() > 1) {
1464
+			add_meta_box(
1465
+				'edit-reg-attendees-mbox',
1466
+				esc_html__('Other Registrations in this Transaction', 'event_espresso'),
1467
+				array($this, '_reg_attendees_meta_box'),
1468
+				$this->wp_page_slug,
1469
+				'normal',
1470
+				'high'
1471
+			);
1472
+		}
1473
+	}
1474
+
1475
+
1476
+	/**
1477
+	 * set_reg_status_buttons_metabox
1478
+	 *
1479
+	 * @access protected
1480
+	 * @return string
1481
+	 * @throws EE_Error
1482
+	 * @throws EntityNotFoundException
1483
+	 * @throws InvalidArgumentException
1484
+	 * @throws InvalidDataTypeException
1485
+	 * @throws InvalidInterfaceException
1486
+	 * @throws ReflectionException
1487
+	 */
1488
+	public function set_reg_status_buttons_metabox()
1489
+	{
1490
+		$this->_set_registration_object();
1491
+		$change_reg_status_form = $this->_generate_reg_status_change_form();
1492
+		echo $change_reg_status_form->form_open(
1493
+			self::add_query_args_and_nonce(
1494
+				array(
1495
+					'action' => 'change_reg_status',
1496
+				),
1497
+				REG_ADMIN_URL
1498
+			)
1499
+		);
1500
+		echo $change_reg_status_form->get_html();
1501
+		echo $change_reg_status_form->form_close();
1502
+	}
1503
+
1504
+
1505
+	/**
1506
+	 * @return EE_Form_Section_Proper
1507
+	 * @throws EE_Error
1508
+	 * @throws InvalidArgumentException
1509
+	 * @throws InvalidDataTypeException
1510
+	 * @throws InvalidInterfaceException
1511
+	 * @throws EntityNotFoundException
1512
+	 * @throws ReflectionException
1513
+	 */
1514
+	protected function _generate_reg_status_change_form()
1515
+	{
1516
+		$reg_status_change_form_array = array(
1517
+			'name'            => 'reg_status_change_form',
1518
+			'html_id'         => 'reg-status-change-form',
1519
+			'layout_strategy' => new EE_Admin_Two_Column_Layout(),
1520
+			'subsections'     => array(
1521
+				'return'             => new EE_Hidden_Input(
1522
+					array(
1523
+						'name'    => 'return',
1524
+						'default' => 'view_registration',
1525
+					)
1526
+				),
1527
+				'REG_ID'             => new EE_Hidden_Input(
1528
+					array(
1529
+						'name'    => 'REG_ID',
1530
+						'default' => $this->_registration->ID(),
1531
+					)
1532
+				),
1533
+				'current_status'     => new EE_Form_Section_HTML(
1534
+					EEH_HTML::table(
1535
+						EEH_HTML::tr(
1536
+							EEH_HTML::th(
1537
+								EEH_HTML::label(
1538
+									EEH_HTML::strong(
1539
+										esc_html__('Current Registration Status', 'event_espresso')
1540
+									)
1541
+								)
1542
+							)
1543
+							. EEH_HTML::td(
1544
+								EEH_HTML::strong(
1545
+									$this->_registration->pretty_status(),
1546
+									'',
1547
+									'status-' . $this->_registration->status_ID(),
1548
+									'line-height: 1em; font-size: 1.5em; font-weight: bold;'
1549
+								)
1550
+							)
1551
+						)
1552
+					)
1553
+				)
1554
+			)
1555
+		);
1556
+		if (EE_Registry::instance()->CAP->current_user_can(
1557
+			'ee_edit_registration',
1558
+			'toggle_registration_status',
1559
+			$this->_registration->ID()
1560
+		)) {
1561
+			$reg_status_change_form_array['subsections']['reg_status'] = new EE_Select_Input(
1562
+				$this->_get_reg_statuses(),
1563
+				array(
1564
+					'html_label_text' => esc_html__('Change Registration Status to', 'event_espresso'),
1565
+					'default'         => $this->_registration->status_ID(),
1566
+				)
1567
+			);
1568
+			$reg_status_change_form_array['subsections']['send_notifications'] = new EE_Yes_No_Input(
1569
+				array(
1570
+					'html_label_text' => esc_html__('Send Related Messages', 'event_espresso'),
1571
+					'default'         => false,
1572
+					'html_help_text'  => esc_html__(
1573
+						'If set to "Yes", then the related messages will be sent to the registrant.',
1574
+						'event_espresso'
1575
+					)
1576
+				)
1577
+			);
1578
+			$reg_status_change_form_array['subsections']['submit'] = new EE_Submit_Input(
1579
+				array(
1580
+					'html_class'      => 'button-primary',
1581
+					'html_label_text' => '&nbsp;',
1582
+					'default'         => esc_html__('Update Registration Status', 'event_espresso'),
1583
+				)
1584
+			);
1585
+		}
1586
+		return new EE_Form_Section_Proper($reg_status_change_form_array);
1587
+	}
1588
+
1589
+
1590
+	/**
1591
+	 * Returns an array of all the buttons for the various statuses and switch status actions
1592
+	 *
1593
+	 * @return array
1594
+	 * @throws EE_Error
1595
+	 * @throws InvalidArgumentException
1596
+	 * @throws InvalidDataTypeException
1597
+	 * @throws InvalidInterfaceException
1598
+	 * @throws EntityNotFoundException
1599
+	 */
1600
+	protected function _get_reg_statuses()
1601
+	{
1602
+		$reg_status_array = $this->getRegistrationModel()->reg_status_array();
1603
+		unset($reg_status_array[ EEM_Registration::status_id_incomplete ]);
1604
+		// get current reg status
1605
+		$current_status = $this->_registration->status_ID();
1606
+		// is registration for free event? This will determine whether to display the pending payment option
1607
+		if ($current_status !== EEM_Registration::status_id_pending_payment
1608
+			&& EEH_Money::compare_floats($this->_registration->ticket()->price(), 0.00)
1609
+		) {
1610
+			unset($reg_status_array[ EEM_Registration::status_id_pending_payment ]);
1611
+		}
1612
+		return $this->getStatusModel()->localized_status($reg_status_array, false, 'sentence');
1613
+	}
1614
+
1615
+
1616
+	/**
1617
+	 * This method is used when using _REG_ID from request which may or may not be an array of reg_ids.
1618
+	 *
1619
+	 * @param bool $status REG status given for changing registrations to.
1620
+	 * @param bool $notify Whether to send messages notifications or not.
1621
+	 * @return array (array with reg_id(s) updated and whether update was successful.
1622
+	 * @throws DomainException
1623
+	 * @throws EE_Error
1624
+	 * @throws EntityNotFoundException
1625
+	 * @throws InvalidArgumentException
1626
+	 * @throws InvalidDataTypeException
1627
+	 * @throws InvalidInterfaceException
1628
+	 * @throws ReflectionException
1629
+	 * @throws RuntimeException
1630
+	 */
1631
+	protected function _set_registration_status_from_request($status = false, $notify = false)
1632
+	{
1633
+		if (isset($this->_req_data['reg_status_change_form'])) {
1634
+			$REG_IDs = isset($this->_req_data['reg_status_change_form']['REG_ID'])
1635
+				? (array) $this->_req_data['reg_status_change_form']['REG_ID']
1636
+				: array();
1637
+		} else {
1638
+			$REG_IDs = isset($this->_req_data['_REG_ID'])
1639
+				? (array) $this->_req_data['_REG_ID']
1640
+				: array();
1641
+		}
1642
+		// sanitize $REG_IDs
1643
+		$REG_IDs = array_map('absint', $REG_IDs);
1644
+		// and remove empty entries
1645
+		$REG_IDs = array_filter($REG_IDs);
1646
+
1647
+		$result = $this->_set_registration_status($REG_IDs, $status, $notify);
1648
+
1649
+		/**
1650
+		 * Set and filter $_req_data['_REG_ID'] for any potential future messages notifications.
1651
+		 * Currently this value is used downstream by the _process_resend_registration method.
1652
+		 *
1653
+		 * @param int|array                $registration_ids The registration ids that have had their status changed successfully.
1654
+		 * @param bool                     $status           The status registrations were changed to.
1655
+		 * @param bool                     $success          If the status was changed successfully for all registrations.
1656
+		 * @param Registrations_Admin_Page $admin_page_object
1657
+		 */
1658
+		$this->_req_data['_REG_ID'] = apply_filters(
1659
+			'FHEE__Registrations_Admin_Page___set_registration_status_from_request__REG_IDs',
1660
+			$result['REG_ID'],
1661
+			$status,
1662
+			$result['success'],
1663
+			$this
1664
+		);
1665
+
1666
+		// notify?
1667
+		if ($notify
1668
+			&& $result['success']
1669
+			&& ! empty($this->_req_data['_REG_ID'])
1670
+			&& EE_Registry::instance()->CAP->current_user_can(
1671
+				'ee_send_message',
1672
+				'espresso_registrations_resend_registration'
1673
+			)
1674
+		) {
1675
+			$this->_process_resend_registration();
1676
+		}
1677
+		return $result;
1678
+	}
1679
+
1680
+
1681
+	/**
1682
+	 * Set the registration status for the given reg_id (which may or may not be an array, it gets typecast to an
1683
+	 * array). Note, this method does NOT take care of possible notifications.  That is required by calling code.
1684
+	 *
1685
+	 * @param array  $REG_IDs
1686
+	 * @param string $status
1687
+	 * @param bool   $notify  Used to indicate whether notification was requested or not.  This determines the context
1688
+	 *                        slug sent with setting the registration status.
1689
+	 * @return array (an array with 'success' key representing whether status change was successful, and 'REG_ID' as
1690
+	 * @throws EE_Error
1691
+	 * @throws InvalidArgumentException
1692
+	 * @throws InvalidDataTypeException
1693
+	 * @throws InvalidInterfaceException
1694
+	 * @throws ReflectionException
1695
+	 * @throws RuntimeException
1696
+	 * @throws EntityNotFoundException
1697
+	 * @throws DomainException
1698
+	 */
1699
+	protected function _set_registration_status($REG_IDs = array(), $status = '', $notify = false)
1700
+	{
1701
+		$success = false;
1702
+		// typecast $REG_IDs
1703
+		$REG_IDs = (array) $REG_IDs;
1704
+		if (! empty($REG_IDs)) {
1705
+			$success = true;
1706
+			// set default status if none is passed
1707
+			$status = $status ? $status : EEM_Registration::status_id_pending_payment;
1708
+			$status_context = $notify
1709
+				? Domain::CONTEXT_REGISTRATION_STATUS_CHANGE_REGISTRATION_ADMIN_NOTIFY
1710
+				: Domain::CONTEXT_REGISTRATION_STATUS_CHANGE_REGISTRATION_ADMIN;
1711
+			// loop through REG_ID's and change status
1712
+			foreach ($REG_IDs as $REG_ID) {
1713
+				$registration = $this->getRegistrationModel()->get_one_by_ID($REG_ID);
1714
+				if ($registration instanceof EE_Registration) {
1715
+					$registration->set_status(
1716
+						$status,
1717
+						false,
1718
+						new Context(
1719
+							$status_context,
1720
+							esc_html__(
1721
+								'Manually triggered status change on a Registration Admin Page route.',
1722
+								'event_espresso'
1723
+							)
1724
+						)
1725
+					);
1726
+					$result = $registration->save();
1727
+					// verifying explicit fails because update *may* just return 0 for 0 rows affected
1728
+					$success = $result !== false ? $success : false;
1729
+				}
1730
+			}
1731
+		}
1732
+
1733
+		// return $success and processed registrations
1734
+		return array('REG_ID' => $REG_IDs, 'success' => $success);
1735
+	}
1736
+
1737
+
1738
+	/**
1739
+	 * Common logic for setting up success message and redirecting to appropriate route
1740
+	 *
1741
+	 * @param string $STS_ID status id for the registration changed to
1742
+	 * @param bool   $notify indicates whether the _set_registration_status_from_request does notifications or not.
1743
+	 * @return void
1744
+	 * @throws DomainException
1745
+	 * @throws EE_Error
1746
+	 * @throws EntityNotFoundException
1747
+	 * @throws InvalidArgumentException
1748
+	 * @throws InvalidDataTypeException
1749
+	 * @throws InvalidInterfaceException
1750
+	 * @throws ReflectionException
1751
+	 * @throws RuntimeException
1752
+	 */
1753
+	protected function _reg_status_change_return($STS_ID, $notify = false)
1754
+	{
1755
+		$result = ! empty($STS_ID) ? $this->_set_registration_status_from_request($STS_ID, $notify)
1756
+			: array('success' => false);
1757
+		$success = isset($result['success']) && $result['success'];
1758
+		// setup success message
1759
+		if ($success) {
1760
+			if (is_array($result['REG_ID']) && count($result['REG_ID']) === 1) {
1761
+				$msg = sprintf(
1762
+					esc_html__('Registration status has been set to %s', 'event_espresso'),
1763
+					EEH_Template::pretty_status($STS_ID, false, 'lower')
1764
+				);
1765
+			} else {
1766
+				$msg = sprintf(
1767
+					esc_html__('Registrations have been set to %s.', 'event_espresso'),
1768
+					EEH_Template::pretty_status($STS_ID, false, 'lower')
1769
+				);
1770
+			}
1771
+			EE_Error::add_success($msg);
1772
+		} else {
1773
+			EE_Error::add_error(
1774
+				esc_html__(
1775
+					'Something went wrong, and the status was not changed',
1776
+					'event_espresso'
1777
+				),
1778
+				__FILE__,
1779
+				__LINE__,
1780
+				__FUNCTION__
1781
+			);
1782
+		}
1783
+		if (isset($this->_req_data['return']) && $this->_req_data['return'] === 'view_registration') {
1784
+			$route = array('action' => 'view_registration', '_REG_ID' => reset($result['REG_ID']));
1785
+		} else {
1786
+			$route = array('action' => 'default');
1787
+		}
1788
+		$route = $this->mergeExistingRequestParamsWithRedirectArgs($route);
1789
+		$this->_redirect_after_action($success, '', '', $route, true);
1790
+	}
1791
+
1792
+
1793
+	/**
1794
+	 * incoming reg status change from reg details page.
1795
+	 *
1796
+	 * @return void
1797
+	 * @throws EE_Error
1798
+	 * @throws EntityNotFoundException
1799
+	 * @throws InvalidArgumentException
1800
+	 * @throws InvalidDataTypeException
1801
+	 * @throws InvalidInterfaceException
1802
+	 * @throws ReflectionException
1803
+	 * @throws RuntimeException
1804
+	 * @throws DomainException
1805
+	 */
1806
+	protected function _change_reg_status()
1807
+	{
1808
+		$this->_req_data['return'] = 'view_registration';
1809
+		// set notify based on whether the send notifications toggle is set or not
1810
+		$notify = ! empty($this->_req_data['reg_status_change_form']['send_notifications']);
1811
+		// $notify = ! empty( $this->_req_data['txn_reg_status_change']['send_notifications'] );
1812
+		$this->_req_data['reg_status_change_form']['reg_status'] = isset($this->_req_data['reg_status_change_form']['reg_status'])
1813
+			? $this->_req_data['reg_status_change_form']['reg_status'] : '';
1814
+		switch ($this->_req_data['reg_status_change_form']['reg_status']) {
1815
+			case EEM_Registration::status_id_approved:
1816
+			case EEH_Template::pretty_status(EEM_Registration::status_id_approved, false, 'sentence'):
1817
+				$this->approve_registration($notify);
1818
+				break;
1819
+			case EEM_Registration::status_id_pending_payment:
1820
+			case EEH_Template::pretty_status(EEM_Registration::status_id_pending_payment, false, 'sentence'):
1821
+				$this->pending_registration($notify);
1822
+				break;
1823
+			case EEM_Registration::status_id_not_approved:
1824
+			case EEH_Template::pretty_status(EEM_Registration::status_id_not_approved, false, 'sentence'):
1825
+				$this->not_approve_registration($notify);
1826
+				break;
1827
+			case EEM_Registration::status_id_declined:
1828
+			case EEH_Template::pretty_status(EEM_Registration::status_id_declined, false, 'sentence'):
1829
+				$this->decline_registration($notify);
1830
+				break;
1831
+			case EEM_Registration::status_id_cancelled:
1832
+			case EEH_Template::pretty_status(EEM_Registration::status_id_cancelled, false, 'sentence'):
1833
+				$this->cancel_registration($notify);
1834
+				break;
1835
+			case EEM_Registration::status_id_wait_list:
1836
+			case EEH_Template::pretty_status(EEM_Registration::status_id_wait_list, false, 'sentence'):
1837
+				$this->wait_list_registration($notify);
1838
+				break;
1839
+			case EEM_Registration::status_id_incomplete:
1840
+			default:
1841
+				$result['success'] = false;
1842
+				unset($this->_req_data['return']);
1843
+				$this->_reg_status_change_return('', false);
1844
+				break;
1845
+		}
1846
+	}
1847
+
1848
+
1849
+	/**
1850
+	 * Callback for bulk action routes.
1851
+	 * Note: although we could just register the singular route callbacks for each bulk action route as well, this
1852
+	 * method was chosen so there is one central place all the registration status bulk actions are going through.
1853
+	 * Potentially, this provides an easier place to locate logic that is specific to these bulk actions (as opposed to
1854
+	 * when an action is happening on just a single registration).
1855
+	 *
1856
+	 * @param      $action
1857
+	 * @param bool $notify
1858
+	 */
1859
+	protected function bulk_action_on_registrations($action, $notify = false)
1860
+	{
1861
+		do_action(
1862
+			'AHEE__Registrations_Admin_Page__bulk_action_on_registrations__before_execution',
1863
+			$this,
1864
+			$action,
1865
+			$notify
1866
+		);
1867
+		$method = $action . '_registration';
1868
+		if (method_exists($this, $method)) {
1869
+			$this->$method($notify);
1870
+		}
1871
+	}
1872
+
1873
+
1874
+	/**
1875
+	 * approve_registration
1876
+	 *
1877
+	 * @access protected
1878
+	 * @param bool $notify whether or not to notify the registrant about their approval.
1879
+	 * @return void
1880
+	 * @throws EE_Error
1881
+	 * @throws EntityNotFoundException
1882
+	 * @throws InvalidArgumentException
1883
+	 * @throws InvalidDataTypeException
1884
+	 * @throws InvalidInterfaceException
1885
+	 * @throws ReflectionException
1886
+	 * @throws RuntimeException
1887
+	 * @throws DomainException
1888
+	 */
1889
+	protected function approve_registration($notify = false)
1890
+	{
1891
+		$this->_reg_status_change_return(EEM_Registration::status_id_approved, $notify);
1892
+	}
1893
+
1894
+
1895
+	/**
1896
+	 *        decline_registration
1897
+	 *
1898
+	 * @access protected
1899
+	 * @param bool $notify whether or not to notify the registrant about their status change.
1900
+	 * @return void
1901
+	 * @throws EE_Error
1902
+	 * @throws EntityNotFoundException
1903
+	 * @throws InvalidArgumentException
1904
+	 * @throws InvalidDataTypeException
1905
+	 * @throws InvalidInterfaceException
1906
+	 * @throws ReflectionException
1907
+	 * @throws RuntimeException
1908
+	 * @throws DomainException
1909
+	 */
1910
+	protected function decline_registration($notify = false)
1911
+	{
1912
+		$this->_reg_status_change_return(EEM_Registration::status_id_declined, $notify);
1913
+	}
1914
+
1915
+
1916
+	/**
1917
+	 *        cancel_registration
1918
+	 *
1919
+	 * @access protected
1920
+	 * @param bool $notify whether or not to notify the registrant about their status change.
1921
+	 * @return void
1922
+	 * @throws EE_Error
1923
+	 * @throws EntityNotFoundException
1924
+	 * @throws InvalidArgumentException
1925
+	 * @throws InvalidDataTypeException
1926
+	 * @throws InvalidInterfaceException
1927
+	 * @throws ReflectionException
1928
+	 * @throws RuntimeException
1929
+	 * @throws DomainException
1930
+	 */
1931
+	protected function cancel_registration($notify = false)
1932
+	{
1933
+		$this->_reg_status_change_return(EEM_Registration::status_id_cancelled, $notify);
1934
+	}
1935
+
1936
+
1937
+	/**
1938
+	 *        not_approve_registration
1939
+	 *
1940
+	 * @access protected
1941
+	 * @param bool $notify whether or not to notify the registrant about their status change.
1942
+	 * @return void
1943
+	 * @throws EE_Error
1944
+	 * @throws EntityNotFoundException
1945
+	 * @throws InvalidArgumentException
1946
+	 * @throws InvalidDataTypeException
1947
+	 * @throws InvalidInterfaceException
1948
+	 * @throws ReflectionException
1949
+	 * @throws RuntimeException
1950
+	 * @throws DomainException
1951
+	 */
1952
+	protected function not_approve_registration($notify = false)
1953
+	{
1954
+		$this->_reg_status_change_return(EEM_Registration::status_id_not_approved, $notify);
1955
+	}
1956
+
1957
+
1958
+	/**
1959
+	 *        decline_registration
1960
+	 *
1961
+	 * @access protected
1962
+	 * @param bool $notify whether or not to notify the registrant about their status change.
1963
+	 * @return void
1964
+	 * @throws EE_Error
1965
+	 * @throws EntityNotFoundException
1966
+	 * @throws InvalidArgumentException
1967
+	 * @throws InvalidDataTypeException
1968
+	 * @throws InvalidInterfaceException
1969
+	 * @throws ReflectionException
1970
+	 * @throws RuntimeException
1971
+	 * @throws DomainException
1972
+	 */
1973
+	protected function pending_registration($notify = false)
1974
+	{
1975
+		$this->_reg_status_change_return(EEM_Registration::status_id_pending_payment, $notify);
1976
+	}
1977
+
1978
+
1979
+	/**
1980
+	 * waitlist_registration
1981
+	 *
1982
+	 * @access protected
1983
+	 * @param bool $notify whether or not to notify the registrant about their status change.
1984
+	 * @return void
1985
+	 * @throws EE_Error
1986
+	 * @throws EntityNotFoundException
1987
+	 * @throws InvalidArgumentException
1988
+	 * @throws InvalidDataTypeException
1989
+	 * @throws InvalidInterfaceException
1990
+	 * @throws ReflectionException
1991
+	 * @throws RuntimeException
1992
+	 * @throws DomainException
1993
+	 */
1994
+	protected function wait_list_registration($notify = false)
1995
+	{
1996
+		$this->_reg_status_change_return(EEM_Registration::status_id_wait_list, $notify);
1997
+	}
1998
+
1999
+
2000
+	/**
2001
+	 *        generates HTML for the Registration main meta box
2002
+	 *
2003
+	 * @access public
2004
+	 * @return void
2005
+	 * @throws DomainException
2006
+	 * @throws EE_Error
2007
+	 * @throws InvalidArgumentException
2008
+	 * @throws InvalidDataTypeException
2009
+	 * @throws InvalidInterfaceException
2010
+	 * @throws ReflectionException
2011
+	 * @throws EntityNotFoundException
2012
+	 */
2013
+	public function _reg_details_meta_box()
2014
+	{
2015
+		EEH_Autoloader::register_line_item_display_autoloaders();
2016
+		EEH_Autoloader::register_line_item_filter_autoloaders();
2017
+		EE_Registry::instance()->load_helper('Line_Item');
2018
+		$transaction = $this->_registration->transaction() ? $this->_registration->transaction()
2019
+			: EE_Transaction::new_instance();
2020
+		$this->_session = $transaction->session_data();
2021
+		$filters = new EE_Line_Item_Filter_Collection();
2022
+		$filters->add(new EE_Single_Registration_Line_Item_Filter($this->_registration));
2023
+		$filters->add(new EE_Non_Zero_Line_Item_Filter());
2024
+		$line_item_filter_processor = new EE_Line_Item_Filter_Processor(
2025
+			$filters,
2026
+			$transaction->total_line_item()
2027
+		);
2028
+		$filtered_line_item_tree = $line_item_filter_processor->process();
2029
+		$line_item_display = new EE_Line_Item_Display(
2030
+			'reg_admin_table',
2031
+			'EE_Admin_Table_Registration_Line_Item_Display_Strategy'
2032
+		);
2033
+		$this->_template_args['line_item_table'] = $line_item_display->display_line_item(
2034
+			$filtered_line_item_tree,
2035
+			array('EE_Registration' => $this->_registration)
2036
+		);
2037
+		$attendee = $this->_registration->attendee();
2038
+		if (EE_Registry::instance()->CAP->current_user_can(
2039
+			'ee_read_transaction',
2040
+			'espresso_transactions_view_transaction'
2041
+		)) {
2042
+			$this->_template_args['view_transaction_button'] = EEH_Template::get_button_or_link(
2043
+				EE_Admin_Page::add_query_args_and_nonce(
2044
+					array(
2045
+						'action' => 'view_transaction',
2046
+						'TXN_ID' => $transaction->ID(),
2047
+					),
2048
+					TXN_ADMIN_URL
2049
+				),
2050
+				esc_html__(' View Transaction', 'event_espresso'),
2051
+				'button secondary-button right',
2052
+				'dashicons dashicons-cart'
2053
+			);
2054
+		} else {
2055
+			$this->_template_args['view_transaction_button'] = '';
2056
+		}
2057
+		if ($attendee instanceof EE_Attendee
2058
+			&& EE_Registry::instance()->CAP->current_user_can(
2059
+				'ee_send_message',
2060
+				'espresso_registrations_resend_registration'
2061
+			)
2062
+		) {
2063
+			$this->_template_args['resend_registration_button'] = EEH_Template::get_button_or_link(
2064
+				EE_Admin_Page::add_query_args_and_nonce(
2065
+					array(
2066
+						'action'      => 'resend_registration',
2067
+						'_REG_ID'     => $this->_registration->ID(),
2068
+						'redirect_to' => 'view_registration',
2069
+					),
2070
+					REG_ADMIN_URL
2071
+				),
2072
+				esc_html__(' Resend Registration', 'event_espresso'),
2073
+				'button secondary-button right',
2074
+				'dashicons dashicons-email-alt'
2075
+			);
2076
+		} else {
2077
+			$this->_template_args['resend_registration_button'] = '';
2078
+		}
2079
+		$this->_template_args['currency_sign'] = EE_Registry::instance()->CFG->currency->sign;
2080
+		$payment = $transaction->get_first_related('Payment');
2081
+		$payment = ! $payment instanceof EE_Payment
2082
+			? EE_Payment::new_instance()
2083
+			: $payment;
2084
+		$payment_method = $payment->get_first_related('Payment_Method');
2085
+		$payment_method = ! $payment_method instanceof EE_Payment_Method
2086
+			? EE_Payment_Method::new_instance()
2087
+			: $payment_method;
2088
+		$reg_details = array(
2089
+			'payment_method'       => $payment_method->name(),
2090
+			'response_msg'         => $payment->gateway_response(),
2091
+			'registration_id'      => $this->_registration->get('REG_code'),
2092
+			'registration_session' => $this->_registration->session_ID(),
2093
+			'ip_address'           => isset($this->_session['ip_address']) ? $this->_session['ip_address'] : '',
2094
+			'user_agent'           => isset($this->_session['user_agent']) ? $this->_session['user_agent'] : '',
2095
+		);
2096
+		if (isset($reg_details['registration_id'])) {
2097
+			$this->_template_args['reg_details']['registration_id']['value'] = $reg_details['registration_id'];
2098
+			$this->_template_args['reg_details']['registration_id']['label'] = esc_html__(
2099
+				'Registration ID',
2100
+				'event_espresso'
2101
+			);
2102
+			$this->_template_args['reg_details']['registration_id']['class'] = 'regular-text';
2103
+		}
2104
+		if (isset($reg_details['payment_method'])) {
2105
+			$this->_template_args['reg_details']['payment_method']['value'] = $reg_details['payment_method'];
2106
+			$this->_template_args['reg_details']['payment_method']['label'] = esc_html__(
2107
+				'Most Recent Payment Method',
2108
+				'event_espresso'
2109
+			);
2110
+			$this->_template_args['reg_details']['payment_method']['class'] = 'regular-text';
2111
+			$this->_template_args['reg_details']['response_msg']['value'] = $reg_details['response_msg'];
2112
+			$this->_template_args['reg_details']['response_msg']['label'] = esc_html__(
2113
+				'Payment method response',
2114
+				'event_espresso'
2115
+			);
2116
+			$this->_template_args['reg_details']['response_msg']['class'] = 'regular-text';
2117
+		}
2118
+		$this->_template_args['reg_details']['registration_session']['value'] = $reg_details['registration_session'];
2119
+		$this->_template_args['reg_details']['registration_session']['label'] = esc_html__(
2120
+			'Registration Session',
2121
+			'event_espresso'
2122
+		);
2123
+		$this->_template_args['reg_details']['registration_session']['class'] = 'regular-text';
2124
+		$this->_template_args['reg_details']['ip_address']['value'] = $reg_details['ip_address'];
2125
+		$this->_template_args['reg_details']['ip_address']['label'] = esc_html__(
2126
+			'Registration placed from IP',
2127
+			'event_espresso'
2128
+		);
2129
+		$this->_template_args['reg_details']['ip_address']['class'] = 'regular-text';
2130
+		$this->_template_args['reg_details']['user_agent']['value'] = $reg_details['user_agent'];
2131
+		$this->_template_args['reg_details']['user_agent']['label'] = esc_html__(
2132
+			'Registrant User Agent',
2133
+			'event_espresso'
2134
+		);
2135
+		$this->_template_args['reg_details']['user_agent']['class'] = 'large-text';
2136
+		$this->_template_args['event_link'] = EE_Admin_Page::add_query_args_and_nonce(
2137
+			array(
2138
+				'action'   => 'default',
2139
+				'event_id' => $this->_registration->event_ID(),
2140
+			),
2141
+			REG_ADMIN_URL
2142
+		);
2143
+		$this->_template_args['REG_ID'] = $this->_registration->ID();
2144
+		$this->_template_args['event_id'] = $this->_registration->event_ID();
2145
+		$template_path =
2146
+			REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_reg_details.template.php';
2147
+		echo EEH_Template::display_template($template_path, $this->_template_args, true);
2148
+	}
2149
+
2150
+
2151
+	/**
2152
+	 * generates HTML for the Registration Questions meta box.
2153
+	 * If pre-4.8.32.rc.000 hooks are used, uses old methods (with its filters),
2154
+	 * otherwise uses new forms system
2155
+	 *
2156
+	 * @access public
2157
+	 * @return void
2158
+	 * @throws DomainException
2159
+	 * @throws EE_Error
2160
+	 * @throws InvalidArgumentException
2161
+	 * @throws InvalidDataTypeException
2162
+	 * @throws InvalidInterfaceException
2163
+	 * @throws ReflectionException
2164
+	 */
2165
+	public function _reg_questions_meta_box()
2166
+	{
2167
+		// allow someone to override this method entirely
2168
+		if (apply_filters(
2169
+			'FHEE__Registrations_Admin_Page___reg_questions_meta_box__do_default',
2170
+			true,
2171
+			$this,
2172
+			$this->_registration
2173
+		)) {
2174
+			$form = $this->_get_reg_custom_questions_form(
2175
+				$this->_registration->ID()
2176
+			);
2177
+			$this->_template_args['att_questions'] = count($form->subforms()) > 0
2178
+				? $form->get_html_and_js()
2179
+				: '';
2180
+			$this->_template_args['reg_questions_form_action'] = 'edit_registration';
2181
+			$this->_template_args['REG_ID'] = $this->_registration->ID();
2182
+			$template_path =
2183
+				REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_reg_questions.template.php';
2184
+			echo EEH_Template::display_template($template_path, $this->_template_args, true);
2185
+		}
2186
+	}
2187
+
2188
+
2189
+	/**
2190
+	 * form_before_question_group
2191
+	 *
2192
+	 * @deprecated    as of 4.8.32.rc.000
2193
+	 * @access        public
2194
+	 * @param        string $output
2195
+	 * @return        string
2196
+	 */
2197
+	public function form_before_question_group($output)
2198
+	{
2199
+		EE_Error::doing_it_wrong(
2200
+			__CLASS__ . '::' . __FUNCTION__,
2201
+			esc_html__(
2202
+				'This method would have been protected but was used on a filter callback so needed to be public. Please discontinue usage as it will be removed soon.',
2203
+				'event_espresso'
2204
+			),
2205
+			'4.8.32.rc.000'
2206
+		);
2207
+		return '
2208 2208
 	<table class="form-table ee-width-100">
2209 2209
 		<tbody>
2210 2210
 			';
2211
-    }
2212
-
2213
-
2214
-    /**
2215
-     * form_after_question_group
2216
-     *
2217
-     * @deprecated    as of 4.8.32.rc.000
2218
-     * @access        public
2219
-     * @param        string $output
2220
-     * @return        string
2221
-     */
2222
-    public function form_after_question_group($output)
2223
-    {
2224
-        EE_Error::doing_it_wrong(
2225
-            __CLASS__ . '::' . __FUNCTION__,
2226
-            esc_html__(
2227
-                'This method would have been protected but was used on a filter callback so needed to be public. Please discontinue usage as it will be removed soon.',
2228
-                'event_espresso'
2229
-            ),
2230
-            '4.8.32.rc.000'
2231
-        );
2232
-        return '
2211
+	}
2212
+
2213
+
2214
+	/**
2215
+	 * form_after_question_group
2216
+	 *
2217
+	 * @deprecated    as of 4.8.32.rc.000
2218
+	 * @access        public
2219
+	 * @param        string $output
2220
+	 * @return        string
2221
+	 */
2222
+	public function form_after_question_group($output)
2223
+	{
2224
+		EE_Error::doing_it_wrong(
2225
+			__CLASS__ . '::' . __FUNCTION__,
2226
+			esc_html__(
2227
+				'This method would have been protected but was used on a filter callback so needed to be public. Please discontinue usage as it will be removed soon.',
2228
+				'event_espresso'
2229
+			),
2230
+			'4.8.32.rc.000'
2231
+		);
2232
+		return '
2233 2233
 			<tr class="hide-if-no-js">
2234 2234
 				<th> </th>
2235 2235
 				<td class="reg-admin-edit-attendee-question-td">
2236 2236
 					<a class="reg-admin-edit-attendee-question-lnk" href="#" title="'
2237
-               . esc_attr__('click to edit question', 'event_espresso')
2238
-               . '">
2237
+			   . esc_attr__('click to edit question', 'event_espresso')
2238
+			   . '">
2239 2239
 						<span class="reg-admin-edit-question-group-spn lt-grey-txt">'
2240
-               . esc_html__('edit the above question group', 'event_espresso')
2241
-               . '</span>
2240
+			   . esc_html__('edit the above question group', 'event_espresso')
2241
+			   . '</span>
2242 2242
 						<div class="dashicons dashicons-edit"></div>
2243 2243
 					</a>
2244 2244
 				</td>
@@ -2246,642 +2246,642 @@  discard block
 block discarded – undo
2246 2246
 		</tbody>
2247 2247
 	</table>
2248 2248
 ';
2249
-    }
2250
-
2251
-
2252
-    /**
2253
-     * form_form_field_label_wrap
2254
-     *
2255
-     * @deprecated    as of 4.8.32.rc.000
2256
-     * @access        public
2257
-     * @param        string $label
2258
-     * @return        string
2259
-     */
2260
-    public function form_form_field_label_wrap($label)
2261
-    {
2262
-        EE_Error::doing_it_wrong(
2263
-            __CLASS__ . '::' . __FUNCTION__,
2264
-            esc_html__(
2265
-                'This method would have been protected but was used on a filter callback so needed to be public. Please discontinue usage as it will be removed soon.',
2266
-                'event_espresso'
2267
-            ),
2268
-            '4.8.32.rc.000'
2269
-        );
2270
-        return '
2249
+	}
2250
+
2251
+
2252
+	/**
2253
+	 * form_form_field_label_wrap
2254
+	 *
2255
+	 * @deprecated    as of 4.8.32.rc.000
2256
+	 * @access        public
2257
+	 * @param        string $label
2258
+	 * @return        string
2259
+	 */
2260
+	public function form_form_field_label_wrap($label)
2261
+	{
2262
+		EE_Error::doing_it_wrong(
2263
+			__CLASS__ . '::' . __FUNCTION__,
2264
+			esc_html__(
2265
+				'This method would have been protected but was used on a filter callback so needed to be public. Please discontinue usage as it will be removed soon.',
2266
+				'event_espresso'
2267
+			),
2268
+			'4.8.32.rc.000'
2269
+		);
2270
+		return '
2271 2271
 			<tr>
2272 2272
 				<th>
2273 2273
 					' . $label . '
2274 2274
 				</th>';
2275
-    }
2276
-
2277
-
2278
-    /**
2279
-     * form_form_field_input__wrap
2280
-     *
2281
-     * @deprecated    as of 4.8.32.rc.000
2282
-     * @access        public
2283
-     * @param        string $input
2284
-     * @return        string
2285
-     */
2286
-    public function form_form_field_input__wrap($input)
2287
-    {
2288
-        EE_Error::doing_it_wrong(
2289
-            __CLASS__ . '::' . __FUNCTION__,
2290
-            esc_html__(
2291
-                'This method would have been protected but was used on a filter callback so needed to be public. Please discontinue usage as it will be removed soon.',
2292
-                'event_espresso'
2293
-            ),
2294
-            '4.8.32.rc.000'
2295
-        );
2296
-        return '
2275
+	}
2276
+
2277
+
2278
+	/**
2279
+	 * form_form_field_input__wrap
2280
+	 *
2281
+	 * @deprecated    as of 4.8.32.rc.000
2282
+	 * @access        public
2283
+	 * @param        string $input
2284
+	 * @return        string
2285
+	 */
2286
+	public function form_form_field_input__wrap($input)
2287
+	{
2288
+		EE_Error::doing_it_wrong(
2289
+			__CLASS__ . '::' . __FUNCTION__,
2290
+			esc_html__(
2291
+				'This method would have been protected but was used on a filter callback so needed to be public. Please discontinue usage as it will be removed soon.',
2292
+				'event_espresso'
2293
+			),
2294
+			'4.8.32.rc.000'
2295
+		);
2296
+		return '
2297 2297
 				<td class="reg-admin-attendee-questions-input-td disabled-input">
2298 2298
 					' . $input . '
2299 2299
 				</td>
2300 2300
 			</tr>';
2301
-    }
2302
-
2303
-
2304
-    /**
2305
-     * Updates the registration's custom questions according to the form info, if the form is submitted.
2306
-     * If it's not a post, the "view_registrations" route will be called next on the SAME request
2307
-     * to display the page
2308
-     *
2309
-     * @access protected
2310
-     * @return void
2311
-     * @throws EE_Error
2312
-     * @throws InvalidArgumentException
2313
-     * @throws InvalidDataTypeException
2314
-     * @throws InvalidInterfaceException
2315
-     * @throws ReflectionException
2316
-     */
2317
-    protected function _update_attendee_registration_form()
2318
-    {
2319
-        do_action('AHEE__Registrations_Admin_Page___update_attendee_registration_form__start', $this);
2320
-        if ($_SERVER['REQUEST_METHOD'] === 'POST') {
2321
-            $REG_ID = isset($this->_req_data['_REG_ID']) ? absint($this->_req_data['_REG_ID']) : false;
2322
-            $success = $this->_save_reg_custom_questions_form($REG_ID);
2323
-            if ($success) {
2324
-                $what = esc_html__('Registration Form', 'event_espresso');
2325
-                $route = $REG_ID ? array('action' => 'view_registration', '_REG_ID' => $REG_ID)
2326
-                    : array('action' => 'default');
2327
-                $this->_redirect_after_action($success, $what, esc_html__('updated', 'event_espresso'), $route);
2328
-            }
2329
-        }
2330
-    }
2331
-
2332
-
2333
-    /**
2334
-     * Gets the form for saving registrations custom questions (if done
2335
-     * previously retrieves the cached form object, which may have validation errors in it)
2336
-     *
2337
-     * @param int $REG_ID
2338
-     * @return EE_Registration_Custom_Questions_Form
2339
-     * @throws EE_Error
2340
-     * @throws InvalidArgumentException
2341
-     * @throws InvalidDataTypeException
2342
-     * @throws InvalidInterfaceException
2343
-     */
2344
-    protected function _get_reg_custom_questions_form($REG_ID)
2345
-    {
2346
-        if (! $this->_reg_custom_questions_form) {
2347
-            require_once(REG_ADMIN . 'form_sections/EE_Registration_Custom_Questions_Form.form.php');
2348
-            $this->_reg_custom_questions_form = new EE_Registration_Custom_Questions_Form(
2349
-                $this->getRegistrationModel()->get_one_by_ID($REG_ID)
2350
-            );
2351
-            $this->_reg_custom_questions_form->_construct_finalize(null, null);
2352
-        }
2353
-        return $this->_reg_custom_questions_form;
2354
-    }
2355
-
2356
-
2357
-    /**
2358
-     * Saves
2359
-     *
2360
-     * @access private
2361
-     * @param bool $REG_ID
2362
-     * @return bool
2363
-     * @throws EE_Error
2364
-     * @throws InvalidArgumentException
2365
-     * @throws InvalidDataTypeException
2366
-     * @throws InvalidInterfaceException
2367
-     * @throws ReflectionException
2368
-     */
2369
-    private function _save_reg_custom_questions_form($REG_ID = false)
2370
-    {
2371
-        if (! $REG_ID) {
2372
-            EE_Error::add_error(
2373
-                esc_html__(
2374
-                    'An error occurred. No registration ID was received.',
2375
-                    'event_espresso'
2376
-                ),
2377
-                __FILE__,
2378
-                __FUNCTION__,
2379
-                __LINE__
2380
-            );
2381
-        }
2382
-        $form = $this->_get_reg_custom_questions_form($REG_ID);
2383
-        $form->receive_form_submission($this->_req_data);
2384
-        $success = false;
2385
-        if ($form->is_valid()) {
2386
-            foreach ($form->subforms() as $question_group_id => $question_group_form) {
2387
-                foreach ($question_group_form->inputs() as $question_id => $input) {
2388
-                    $where_conditions = array(
2389
-                        'QST_ID' => $question_id,
2390
-                        'REG_ID' => $REG_ID,
2391
-                    );
2392
-                    $possibly_new_values = array(
2393
-                        'ANS_value' => $input->normalized_value(),
2394
-                    );
2395
-                    $answer = EEM_Answer::instance()->get_one(array($where_conditions));
2396
-                    if ($answer instanceof EE_Answer) {
2397
-                        $success = $answer->save($possibly_new_values);
2398
-                    } else {
2399
-                        // insert it then
2400
-                        $cols_n_vals = array_merge($where_conditions, $possibly_new_values);
2401
-                        $answer = EE_Answer::new_instance($cols_n_vals);
2402
-                        $success = $answer->save();
2403
-                    }
2404
-                }
2405
-            }
2406
-        } else {
2407
-            EE_Error::add_error($form->get_validation_error_string(), __FILE__, __FUNCTION__, __LINE__);
2408
-        }
2409
-        return $success;
2410
-    }
2411
-
2412
-
2413
-    /**
2414
-     *        generates HTML for the Registration main meta box
2415
-     *
2416
-     * @access public
2417
-     * @return void
2418
-     * @throws DomainException
2419
-     * @throws EE_Error
2420
-     * @throws InvalidArgumentException
2421
-     * @throws InvalidDataTypeException
2422
-     * @throws InvalidInterfaceException
2423
-     * @throws ReflectionException
2424
-     */
2425
-    public function _reg_attendees_meta_box()
2426
-    {
2427
-        $REG = $this->getRegistrationModel();
2428
-        // get all other registrations on this transaction, and cache
2429
-        // the attendees for them so we don't have to run another query using force_join
2430
-        $registrations = $REG->get_all(
2431
-            array(
2432
-                array(
2433
-                    'TXN_ID' => $this->_registration->transaction_ID(),
2434
-                    'REG_ID' => array('!=', $this->_registration->ID()),
2435
-                ),
2436
-                'force_join' => array('Attendee'),
2437
-                'default_where_conditions' => 'other_models_only',
2438
-            )
2439
-        );
2440
-        $this->_template_args['attendees'] = array();
2441
-        $this->_template_args['attendee_notice'] = '';
2442
-        if (empty($registrations)
2443
-            || (is_array($registrations)
2444
-                && ! EEH_Array::get_one_item_from_array($registrations))
2445
-        ) {
2446
-            EE_Error::add_error(
2447
-                esc_html__(
2448
-                    'There are no records attached to this registration. Something may have gone wrong with the registration',
2449
-                    'event_espresso'
2450
-                ),
2451
-                __FILE__,
2452
-                __FUNCTION__,
2453
-                __LINE__
2454
-            );
2455
-            $this->_template_args['attendee_notice'] = EE_Error::get_notices();
2456
-        } else {
2457
-            $att_nmbr = 1;
2458
-            foreach ($registrations as $registration) {
2459
-                /* @var $registration EE_Registration */
2460
-                $attendee = $registration->attendee()
2461
-                    ? $registration->attendee()
2462
-                    : $this->getAttendeeModel()->create_default_object();
2463
-                $this->_template_args['attendees'][ $att_nmbr ]['STS_ID'] = $registration->status_ID();
2464
-                $this->_template_args['attendees'][ $att_nmbr ]['fname'] = $attendee->fname();
2465
-                $this->_template_args['attendees'][ $att_nmbr ]['lname'] = $attendee->lname();
2466
-                $this->_template_args['attendees'][ $att_nmbr ]['email'] = $attendee->email();
2467
-                $this->_template_args['attendees'][ $att_nmbr ]['final_price'] = $registration->final_price();
2468
-                $this->_template_args['attendees'][ $att_nmbr ]['address'] = implode(
2469
-                    ', ',
2470
-                    $attendee->full_address_as_array()
2471
-                );
2472
-                $this->_template_args['attendees'][ $att_nmbr ]['att_link'] = self::add_query_args_and_nonce(
2473
-                    array(
2474
-                        'action' => 'edit_attendee',
2475
-                        'post'   => $attendee->ID(),
2476
-                    ),
2477
-                    REG_ADMIN_URL
2478
-                );
2479
-                $this->_template_args['attendees'][ $att_nmbr ]['event_name'] = $registration->event_obj() instanceof EE_Event
2480
-                    ? $registration->event_obj()->name()
2481
-                    : '';
2482
-                $att_nmbr++;
2483
-            }
2484
-            $this->_template_args['currency_sign'] = EE_Registry::instance()->CFG->currency->sign;
2485
-        }
2486
-        $template_path = REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_attendees.template.php';
2487
-        echo EEH_Template::display_template($template_path, $this->_template_args, true);
2488
-    }
2489
-
2490
-
2491
-    /**
2492
-     *        generates HTML for the Edit Registration side meta box
2493
-     *
2494
-     * @access public
2495
-     * @return void
2496
-     * @throws DomainException
2497
-     * @throws EE_Error
2498
-     * @throws InvalidArgumentException
2499
-     * @throws InvalidDataTypeException
2500
-     * @throws InvalidInterfaceException
2501
-     * @throws ReflectionException
2502
-     */
2503
-    public function _reg_registrant_side_meta_box()
2504
-    {
2505
-        /*@var $attendee EE_Attendee */
2506
-        $att_check = $this->_registration->attendee();
2507
-        $attendee = $att_check instanceof EE_Attendee
2508
-            ? $att_check
2509
-            : $this->getAttendeeModel()->create_default_object();
2510
-        // now let's determine if this is not the primary registration.  If it isn't then we set the
2511
-        // primary_registration object for reference BUT ONLY if the Attendee object loaded is not the same as the
2512
-        // primary registration object (that way we know if we need to show create button or not)
2513
-        if (! $this->_registration->is_primary_registrant()) {
2514
-            $primary_registration = $this->_registration->get_primary_registration();
2515
-            $primary_attendee = $primary_registration instanceof EE_Registration ? $primary_registration->attendee()
2516
-                : null;
2517
-            if (! $primary_attendee instanceof EE_Attendee || $attendee->ID() !== $primary_attendee->ID()) {
2518
-                // in here?  This means the displayed registration is not the primary registrant but ALREADY HAS its own
2519
-                // custom attendee object so let's not worry about the primary reg.
2520
-                $primary_registration = null;
2521
-            }
2522
-        } else {
2523
-            $primary_registration = null;
2524
-        }
2525
-        $this->_template_args['ATT_ID'] = $attendee->ID();
2526
-        $this->_template_args['fname'] = $attendee->fname();
2527
-        $this->_template_args['lname'] = $attendee->lname();
2528
-        $this->_template_args['email'] = $attendee->email();
2529
-        $this->_template_args['phone'] = $attendee->phone();
2530
-        $this->_template_args['formatted_address'] = EEH_Address::format($attendee);
2531
-        // edit link
2532
-        $this->_template_args['att_edit_link'] = EE_Admin_Page::add_query_args_and_nonce(
2533
-            array(
2534
-                'action' => 'edit_attendee',
2535
-                'post'   => $attendee->ID(),
2536
-            ),
2537
-            REG_ADMIN_URL
2538
-        );
2539
-        $this->_template_args['att_edit_label'] = esc_html__('View/Edit Contact', 'event_espresso');
2540
-        // create link
2541
-        $this->_template_args['create_link'] = $primary_registration instanceof EE_Registration
2542
-            ? EE_Admin_Page::add_query_args_and_nonce(
2543
-                array(
2544
-                    'action'  => 'duplicate_attendee',
2545
-                    '_REG_ID' => $this->_registration->ID(),
2546
-                ),
2547
-                REG_ADMIN_URL
2548
-            ) : '';
2549
-        $this->_template_args['create_label'] = esc_html__('Create Contact', 'event_espresso');
2550
-        $this->_template_args['att_check'] = $att_check;
2551
-        $template_path = REG_TEMPLATE_PATH . 'reg_admin_details_side_meta_box_registrant.template.php';
2552
-        echo EEH_Template::display_template($template_path, $this->_template_args, true);
2553
-    }
2554
-
2555
-
2556
-    /**
2557
-     * trash or restore registrations
2558
-     *
2559
-     * @param  boolean $trash whether to archive or restore
2560
-     * @return void
2561
-     * @throws EE_Error
2562
-     * @throws InvalidArgumentException
2563
-     * @throws InvalidDataTypeException
2564
-     * @throws InvalidInterfaceException
2565
-     * @throws RuntimeException
2566
-     * @access protected
2567
-     */
2568
-    protected function _trash_or_restore_registrations($trash = true)
2569
-    {
2570
-        // if empty _REG_ID then get out because there's nothing to do
2571
-        if (empty($this->_req_data['_REG_ID'])) {
2572
-            EE_Error::add_error(
2573
-                sprintf(
2574
-                    esc_html__(
2575
-                        'In order to %1$s registrations you must select which ones you wish to %1$s by clicking the checkboxes.',
2576
-                        'event_espresso'
2577
-                    ),
2578
-                    $trash ? 'trash' : 'restore'
2579
-                ),
2580
-                __FILE__,
2581
-                __LINE__,
2582
-                __FUNCTION__
2583
-            );
2584
-            $this->_redirect_after_action(false, '', '', array(), true);
2585
-        }
2586
-        $success = 0;
2587
-        $overwrite_msgs = false;
2588
-        // Checkboxes
2589
-        if (! is_array($this->_req_data['_REG_ID'])) {
2590
-            $this->_req_data['_REG_ID'] = array($this->_req_data['_REG_ID']);
2591
-        }
2592
-        $reg_count = count($this->_req_data['_REG_ID']);
2593
-        // cycle thru checkboxes
2594
-        foreach ($this->_req_data['_REG_ID'] as $REG_ID) {
2595
-            /** @var EE_Registration $REG */
2596
-            $REG = $this->getRegistrationModel()->get_one_by_ID($REG_ID);
2597
-            $payments = $REG->registration_payments();
2598
-            if (! empty($payments)) {
2599
-                $name = $REG->attendee() instanceof EE_Attendee
2600
-                    ? $REG->attendee()->full_name()
2601
-                    : esc_html__('Unknown Attendee', 'event_espresso');
2602
-                $overwrite_msgs = true;
2603
-                EE_Error::add_error(
2604
-                    sprintf(
2605
-                        esc_html__(
2606
-                            'The registration for %s could not be trashed because it has payments attached to the related transaction.  If you wish to trash this registration you must first delete the payments on the related transaction.',
2607
-                            'event_espresso'
2608
-                        ),
2609
-                        $name
2610
-                    ),
2611
-                    __FILE__,
2612
-                    __FUNCTION__,
2613
-                    __LINE__
2614
-                );
2615
-                // can't trash this registration because it has payments.
2616
-                continue;
2617
-            }
2618
-            $updated = $trash ? $REG->delete() : $REG->restore();
2619
-            if ($updated) {
2620
-                $success++;
2621
-            }
2622
-        }
2623
-        $this->_redirect_after_action(
2624
-            $success === $reg_count, // were ALL registrations affected?
2625
-            $success > 1
2626
-                ? esc_html__('Registrations', 'event_espresso')
2627
-                : esc_html__('Registration', 'event_espresso'),
2628
-            $trash
2629
-                ? esc_html__('moved to the trash', 'event_espresso')
2630
-                : esc_html__('restored', 'event_espresso'),
2631
-            $this->mergeExistingRequestParamsWithRedirectArgs(array('action' => 'default')),
2632
-            $overwrite_msgs
2633
-        );
2634
-    }
2635
-
2636
-
2637
-    /**
2638
-     * This is used to permanently delete registrations.  Note, this will handle not only deleting permanently the
2639
-     * registration but also.
2640
-     * 1. Removing relations to EE_Attendee
2641
-     * 2. Deleting permanently the related transaction, but ONLY if all related registrations to the transaction are
2642
-     * ALSO trashed.
2643
-     * 3. Deleting permanently any related Line items but only if the above conditions are met.
2644
-     * 4. Removing relationships between all tickets and the related registrations
2645
-     * 5. Deleting permanently any related Answers (and the answers for other related registrations that were deleted.)
2646
-     * 6. Deleting permanently any related Checkins.
2647
-     *
2648
-     * @return void
2649
-     * @throws EE_Error
2650
-     * @throws InvalidArgumentException
2651
-     * @throws InvalidDataTypeException
2652
-     * @throws InvalidInterfaceException
2653
-     * @throws ReflectionException
2654
-     */
2655
-    protected function _delete_registrations()
2656
-    {
2657
-        $REG_MDL = $this->getRegistrationModel();
2658
-        $success = 1;
2659
-        // Checkboxes
2660
-        if (! empty($this->_req_data['_REG_ID']) && is_array($this->_req_data['_REG_ID'])) {
2661
-            // if array has more than one element than success message should be plural
2662
-            $success = count($this->_req_data['_REG_ID']) > 1 ? 2 : 1;
2663
-            // cycle thru checkboxes
2664
-            foreach ($this->_req_data['_REG_ID'] as $REG_ID) {
2665
-                $REG = $REG_MDL->get_one_by_ID($REG_ID);
2666
-                if (! $REG instanceof EE_Registration) {
2667
-                    continue;
2668
-                }
2669
-                $deleted = $this->_delete_registration($REG);
2670
-                if (! $deleted) {
2671
-                    $success = 0;
2672
-                }
2673
-            }
2674
-        } else {
2675
-            // grab single id and delete
2676
-            $REG_ID = $this->_req_data['_REG_ID'];
2677
-            /** @var EE_Registration $REG */
2678
-            $REG = $REG_MDL->get_one_by_ID($REG_ID);
2679
-            $deleted = $this->_delete_registration($REG);
2680
-            if (! $deleted) {
2681
-                $success = 0;
2682
-            }
2683
-        }
2684
-        $what = $success > 1
2685
-            ? esc_html__('Registrations', 'event_espresso')
2686
-            : esc_html__('Registration', 'event_espresso');
2687
-        $action_desc = esc_html__('permanently deleted.', 'event_espresso');
2688
-        $this->_redirect_after_action(
2689
-            $success,
2690
-            $what,
2691
-            $action_desc,
2692
-            $this->mergeExistingRequestParamsWithRedirectArgs(['action' => 'default']),
2693
-            true
2694
-        );
2695
-    }
2696
-
2697
-
2698
-    /**
2699
-     * handles the permanent deletion of a registration.  See comments with _delete_registrations() for details on what
2700
-     * models get affected.
2701
-     *
2702
-     * @param EE_Registration $REG registration to be deleted permanently
2703
-     * @return bool true = successful deletion, false = fail.
2704
-     * @throws EE_Error
2705
-     * @throws InvalidArgumentException
2706
-     * @throws InvalidDataTypeException
2707
-     * @throws InvalidInterfaceException
2708
-     * @throws ReflectionException
2709
-     */
2710
-    protected function _delete_registration(EE_Registration $REG)
2711
-    {
2712
-        // first we start with the transaction... ultimately, we WILL not delete permanently if there are any related
2713
-        // registrations on the transaction that are NOT trashed.
2714
-        $TXN = $REG->get_first_related('Transaction');
2715
-        if (! $TXN instanceof EE_Transaction) {
2716
-            EE_Error::add_error(
2717
-                sprintf(
2718
-                    esc_html__(
2719
-                        'Unable to permanently delete registration %d because its related transaction has already been deleted. If you can restore the related transaction to the database then this registration can be deleted.',
2720
-                        'event_espresso'
2721
-                    ),
2722
-                    $REG->id()
2723
-                ),
2724
-                __FILE__,
2725
-                __FUNCTION__,
2726
-                __LINE__
2727
-            );
2728
-            return false;
2729
-        }
2730
-        $REGS = $TXN->get_many_related('Registration');
2731
-        $all_trashed = true;
2732
-        foreach ($REGS as $registration) {
2733
-            if (! $registration->get('REG_deleted')) {
2734
-                $all_trashed = false;
2735
-            }
2736
-        }
2737
-        if (! $all_trashed) {
2738
-            EE_Error::add_error(
2739
-                esc_html__(
2740
-                    'Unable to permanently delete this registration. Before this registration can be permanently deleted, all registrations made in the same transaction must be trashed as well.  These registrations will be permanently deleted in the same action.',
2741
-                    'event_espresso'
2742
-                ),
2743
-                __FILE__,
2744
-                __FUNCTION__,
2745
-                __LINE__
2746
-            );
2747
-            return false;
2748
-        }
2749
-        // k made it here so that means we can delete all the related transactions and their answers (but let's do them
2750
-        // separately from THIS one).
2751
-        foreach ($REGS as $registration) {
2752
-            // delete related answers
2753
-            $registration->delete_related_permanently('Answer');
2754
-            // remove relationship to EE_Attendee (but we ALWAYS leave the contact record intact)
2755
-            $attendee = $registration->get_first_related('Attendee');
2756
-            if ($attendee instanceof EE_Attendee) {
2757
-                $registration->_remove_relation_to($attendee, 'Attendee');
2758
-            }
2759
-            // now remove relationships to tickets on this registration.
2760
-            $registration->_remove_relations('Ticket');
2761
-            // now delete permanently the checkins related to this registration.
2762
-            $registration->delete_related_permanently('Checkin');
2763
-            if ($registration->ID() === $REG->ID()) {
2764
-                continue;
2765
-            } //we don't want to delete permanently the existing registration just yet.
2766
-            // remove relation to transaction for these registrations if NOT the existing registrations
2767
-            $registration->_remove_relations('Transaction');
2768
-            // delete permanently any related messages.
2769
-            $registration->delete_related_permanently('Message');
2770
-            // now delete this registration permanently
2771
-            $registration->delete_permanently();
2772
-        }
2773
-        // now all related registrations on the transaction are handled.  So let's just handle this registration itself
2774
-        // (the transaction and line items should be all that's left).
2775
-        // delete the line items related to the transaction for this registration.
2776
-        $TXN->delete_related_permanently('Line_Item');
2777
-        // we need to remove all the relationships on the transaction
2778
-        $TXN->delete_related_permanently('Payment');
2779
-        $TXN->delete_related_permanently('Extra_Meta');
2780
-        $TXN->delete_related_permanently('Message');
2781
-        // now we can delete this REG permanently (and the transaction of course)
2782
-        $REG->delete_related_permanently('Transaction');
2783
-        return $REG->delete_permanently();
2784
-    }
2785
-
2786
-
2787
-    /**
2788
-     *    generates HTML for the Register New Attendee Admin page
2789
-     *
2790
-     * @access private
2791
-     * @throws DomainException
2792
-     * @throws EE_Error
2793
-     * @throws InvalidArgumentException
2794
-     * @throws InvalidDataTypeException
2795
-     * @throws InvalidInterfaceException
2796
-     * @throws ReflectionException
2797
-     */
2798
-    public function new_registration()
2799
-    {
2800
-        if (! $this->_set_reg_event()) {
2801
-            throw new EE_Error(
2802
-                esc_html__(
2803
-                    'Unable to continue with registering because there is no Event ID in the request',
2804
-                    'event_espresso'
2805
-                )
2806
-            );
2807
-        }
2808
-        EE_Registry::instance()->REQ->set_espresso_page(true);
2809
-        // gotta start with a clean slate if we're not coming here via ajax
2810
-        if (! defined('DOING_AJAX')
2811
-            && (! isset($this->_req_data['processing_registration']) || isset($this->_req_data['step_error']))
2812
-        ) {
2813
-            EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
2814
-        }
2815
-        $this->_template_args['event_name'] = '';
2816
-        // event name
2817
-        if ($this->_reg_event) {
2818
-            $this->_template_args['event_name'] = $this->_reg_event->name();
2819
-            $edit_event_url = self::add_query_args_and_nonce(
2820
-                array(
2821
-                    'action' => 'edit',
2822
-                    'post'   => $this->_reg_event->ID(),
2823
-                ),
2824
-                EVENTS_ADMIN_URL
2825
-            );
2826
-            $edit_event_lnk = '<a href="'
2827
-                              . $edit_event_url
2828
-                              . '" title="'
2829
-                              . esc_attr__('Edit ', 'event_espresso')
2830
-                              . $this->_reg_event->name()
2831
-                              . '">'
2832
-                              . esc_html__('Edit Event', 'event_espresso')
2833
-                              . '</a>';
2834
-            $this->_template_args['event_name'] .= ' <span class="admin-page-header-edit-lnk not-bold">'
2835
-                                                   . $edit_event_lnk
2836
-                                                   . '</span>';
2837
-        }
2838
-        $this->_template_args['step_content'] = $this->_get_registration_step_content();
2839
-        if (defined('DOING_AJAX')) {
2840
-            $this->_return_json();
2841
-        }
2842
-        // grab header
2843
-        $template_path =
2844
-            REG_TEMPLATE_PATH . 'reg_admin_register_new_attendee.template.php';
2845
-        $this->_template_args['admin_page_content'] = EEH_Template::display_template(
2846
-            $template_path,
2847
-            $this->_template_args,
2848
-            true
2849
-        );
2850
-        // $this->_set_publish_post_box_vars( NULL, FALSE, FALSE, NULL, FALSE );
2851
-        // the details template wrapper
2852
-        $this->display_admin_page_with_sidebar();
2853
-    }
2854
-
2855
-
2856
-    /**
2857
-     * This returns the content for a registration step
2858
-     *
2859
-     * @access protected
2860
-     * @return string html
2861
-     * @throws DomainException
2862
-     * @throws EE_Error
2863
-     * @throws InvalidArgumentException
2864
-     * @throws InvalidDataTypeException
2865
-     * @throws InvalidInterfaceException
2866
-     */
2867
-    protected function _get_registration_step_content()
2868
-    {
2869
-        if (isset($_COOKIE['ee_registration_added']) && $_COOKIE['ee_registration_added']) {
2870
-            $warning_msg = sprintf(
2871
-                esc_html__(
2872
-                    '%2$sWARNING!!!%3$s%1$sPlease do not use the back button to return to this page for the purpose of adding another registration.%1$sThis can result in lost and/or corrupted data.%1$sIf you wish to add another registration, then please click the%1$s%7$s"Add Another New Registration to Event"%8$s button%1$son the Transaction details page, after you are redirected.%1$s%1$s%4$s redirecting in %5$s seconds %6$s',
2873
-                    'event_espresso'
2874
-                ),
2875
-                '<br />',
2876
-                '<h3 class="important-notice">',
2877
-                '</h3>',
2878
-                '<div class="float-right">',
2879
-                '<span id="redirect_timer" class="important-notice">30</span>',
2880
-                '</div>',
2881
-                '<b>',
2882
-                '</b>'
2883
-            );
2884
-            return '
2301
+	}
2302
+
2303
+
2304
+	/**
2305
+	 * Updates the registration's custom questions according to the form info, if the form is submitted.
2306
+	 * If it's not a post, the "view_registrations" route will be called next on the SAME request
2307
+	 * to display the page
2308
+	 *
2309
+	 * @access protected
2310
+	 * @return void
2311
+	 * @throws EE_Error
2312
+	 * @throws InvalidArgumentException
2313
+	 * @throws InvalidDataTypeException
2314
+	 * @throws InvalidInterfaceException
2315
+	 * @throws ReflectionException
2316
+	 */
2317
+	protected function _update_attendee_registration_form()
2318
+	{
2319
+		do_action('AHEE__Registrations_Admin_Page___update_attendee_registration_form__start', $this);
2320
+		if ($_SERVER['REQUEST_METHOD'] === 'POST') {
2321
+			$REG_ID = isset($this->_req_data['_REG_ID']) ? absint($this->_req_data['_REG_ID']) : false;
2322
+			$success = $this->_save_reg_custom_questions_form($REG_ID);
2323
+			if ($success) {
2324
+				$what = esc_html__('Registration Form', 'event_espresso');
2325
+				$route = $REG_ID ? array('action' => 'view_registration', '_REG_ID' => $REG_ID)
2326
+					: array('action' => 'default');
2327
+				$this->_redirect_after_action($success, $what, esc_html__('updated', 'event_espresso'), $route);
2328
+			}
2329
+		}
2330
+	}
2331
+
2332
+
2333
+	/**
2334
+	 * Gets the form for saving registrations custom questions (if done
2335
+	 * previously retrieves the cached form object, which may have validation errors in it)
2336
+	 *
2337
+	 * @param int $REG_ID
2338
+	 * @return EE_Registration_Custom_Questions_Form
2339
+	 * @throws EE_Error
2340
+	 * @throws InvalidArgumentException
2341
+	 * @throws InvalidDataTypeException
2342
+	 * @throws InvalidInterfaceException
2343
+	 */
2344
+	protected function _get_reg_custom_questions_form($REG_ID)
2345
+	{
2346
+		if (! $this->_reg_custom_questions_form) {
2347
+			require_once(REG_ADMIN . 'form_sections/EE_Registration_Custom_Questions_Form.form.php');
2348
+			$this->_reg_custom_questions_form = new EE_Registration_Custom_Questions_Form(
2349
+				$this->getRegistrationModel()->get_one_by_ID($REG_ID)
2350
+			);
2351
+			$this->_reg_custom_questions_form->_construct_finalize(null, null);
2352
+		}
2353
+		return $this->_reg_custom_questions_form;
2354
+	}
2355
+
2356
+
2357
+	/**
2358
+	 * Saves
2359
+	 *
2360
+	 * @access private
2361
+	 * @param bool $REG_ID
2362
+	 * @return bool
2363
+	 * @throws EE_Error
2364
+	 * @throws InvalidArgumentException
2365
+	 * @throws InvalidDataTypeException
2366
+	 * @throws InvalidInterfaceException
2367
+	 * @throws ReflectionException
2368
+	 */
2369
+	private function _save_reg_custom_questions_form($REG_ID = false)
2370
+	{
2371
+		if (! $REG_ID) {
2372
+			EE_Error::add_error(
2373
+				esc_html__(
2374
+					'An error occurred. No registration ID was received.',
2375
+					'event_espresso'
2376
+				),
2377
+				__FILE__,
2378
+				__FUNCTION__,
2379
+				__LINE__
2380
+			);
2381
+		}
2382
+		$form = $this->_get_reg_custom_questions_form($REG_ID);
2383
+		$form->receive_form_submission($this->_req_data);
2384
+		$success = false;
2385
+		if ($form->is_valid()) {
2386
+			foreach ($form->subforms() as $question_group_id => $question_group_form) {
2387
+				foreach ($question_group_form->inputs() as $question_id => $input) {
2388
+					$where_conditions = array(
2389
+						'QST_ID' => $question_id,
2390
+						'REG_ID' => $REG_ID,
2391
+					);
2392
+					$possibly_new_values = array(
2393
+						'ANS_value' => $input->normalized_value(),
2394
+					);
2395
+					$answer = EEM_Answer::instance()->get_one(array($where_conditions));
2396
+					if ($answer instanceof EE_Answer) {
2397
+						$success = $answer->save($possibly_new_values);
2398
+					} else {
2399
+						// insert it then
2400
+						$cols_n_vals = array_merge($where_conditions, $possibly_new_values);
2401
+						$answer = EE_Answer::new_instance($cols_n_vals);
2402
+						$success = $answer->save();
2403
+					}
2404
+				}
2405
+			}
2406
+		} else {
2407
+			EE_Error::add_error($form->get_validation_error_string(), __FILE__, __FUNCTION__, __LINE__);
2408
+		}
2409
+		return $success;
2410
+	}
2411
+
2412
+
2413
+	/**
2414
+	 *        generates HTML for the Registration main meta box
2415
+	 *
2416
+	 * @access public
2417
+	 * @return void
2418
+	 * @throws DomainException
2419
+	 * @throws EE_Error
2420
+	 * @throws InvalidArgumentException
2421
+	 * @throws InvalidDataTypeException
2422
+	 * @throws InvalidInterfaceException
2423
+	 * @throws ReflectionException
2424
+	 */
2425
+	public function _reg_attendees_meta_box()
2426
+	{
2427
+		$REG = $this->getRegistrationModel();
2428
+		// get all other registrations on this transaction, and cache
2429
+		// the attendees for them so we don't have to run another query using force_join
2430
+		$registrations = $REG->get_all(
2431
+			array(
2432
+				array(
2433
+					'TXN_ID' => $this->_registration->transaction_ID(),
2434
+					'REG_ID' => array('!=', $this->_registration->ID()),
2435
+				),
2436
+				'force_join' => array('Attendee'),
2437
+				'default_where_conditions' => 'other_models_only',
2438
+			)
2439
+		);
2440
+		$this->_template_args['attendees'] = array();
2441
+		$this->_template_args['attendee_notice'] = '';
2442
+		if (empty($registrations)
2443
+			|| (is_array($registrations)
2444
+				&& ! EEH_Array::get_one_item_from_array($registrations))
2445
+		) {
2446
+			EE_Error::add_error(
2447
+				esc_html__(
2448
+					'There are no records attached to this registration. Something may have gone wrong with the registration',
2449
+					'event_espresso'
2450
+				),
2451
+				__FILE__,
2452
+				__FUNCTION__,
2453
+				__LINE__
2454
+			);
2455
+			$this->_template_args['attendee_notice'] = EE_Error::get_notices();
2456
+		} else {
2457
+			$att_nmbr = 1;
2458
+			foreach ($registrations as $registration) {
2459
+				/* @var $registration EE_Registration */
2460
+				$attendee = $registration->attendee()
2461
+					? $registration->attendee()
2462
+					: $this->getAttendeeModel()->create_default_object();
2463
+				$this->_template_args['attendees'][ $att_nmbr ]['STS_ID'] = $registration->status_ID();
2464
+				$this->_template_args['attendees'][ $att_nmbr ]['fname'] = $attendee->fname();
2465
+				$this->_template_args['attendees'][ $att_nmbr ]['lname'] = $attendee->lname();
2466
+				$this->_template_args['attendees'][ $att_nmbr ]['email'] = $attendee->email();
2467
+				$this->_template_args['attendees'][ $att_nmbr ]['final_price'] = $registration->final_price();
2468
+				$this->_template_args['attendees'][ $att_nmbr ]['address'] = implode(
2469
+					', ',
2470
+					$attendee->full_address_as_array()
2471
+				);
2472
+				$this->_template_args['attendees'][ $att_nmbr ]['att_link'] = self::add_query_args_and_nonce(
2473
+					array(
2474
+						'action' => 'edit_attendee',
2475
+						'post'   => $attendee->ID(),
2476
+					),
2477
+					REG_ADMIN_URL
2478
+				);
2479
+				$this->_template_args['attendees'][ $att_nmbr ]['event_name'] = $registration->event_obj() instanceof EE_Event
2480
+					? $registration->event_obj()->name()
2481
+					: '';
2482
+				$att_nmbr++;
2483
+			}
2484
+			$this->_template_args['currency_sign'] = EE_Registry::instance()->CFG->currency->sign;
2485
+		}
2486
+		$template_path = REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_attendees.template.php';
2487
+		echo EEH_Template::display_template($template_path, $this->_template_args, true);
2488
+	}
2489
+
2490
+
2491
+	/**
2492
+	 *        generates HTML for the Edit Registration side meta box
2493
+	 *
2494
+	 * @access public
2495
+	 * @return void
2496
+	 * @throws DomainException
2497
+	 * @throws EE_Error
2498
+	 * @throws InvalidArgumentException
2499
+	 * @throws InvalidDataTypeException
2500
+	 * @throws InvalidInterfaceException
2501
+	 * @throws ReflectionException
2502
+	 */
2503
+	public function _reg_registrant_side_meta_box()
2504
+	{
2505
+		/*@var $attendee EE_Attendee */
2506
+		$att_check = $this->_registration->attendee();
2507
+		$attendee = $att_check instanceof EE_Attendee
2508
+			? $att_check
2509
+			: $this->getAttendeeModel()->create_default_object();
2510
+		// now let's determine if this is not the primary registration.  If it isn't then we set the
2511
+		// primary_registration object for reference BUT ONLY if the Attendee object loaded is not the same as the
2512
+		// primary registration object (that way we know if we need to show create button or not)
2513
+		if (! $this->_registration->is_primary_registrant()) {
2514
+			$primary_registration = $this->_registration->get_primary_registration();
2515
+			$primary_attendee = $primary_registration instanceof EE_Registration ? $primary_registration->attendee()
2516
+				: null;
2517
+			if (! $primary_attendee instanceof EE_Attendee || $attendee->ID() !== $primary_attendee->ID()) {
2518
+				// in here?  This means the displayed registration is not the primary registrant but ALREADY HAS its own
2519
+				// custom attendee object so let's not worry about the primary reg.
2520
+				$primary_registration = null;
2521
+			}
2522
+		} else {
2523
+			$primary_registration = null;
2524
+		}
2525
+		$this->_template_args['ATT_ID'] = $attendee->ID();
2526
+		$this->_template_args['fname'] = $attendee->fname();
2527
+		$this->_template_args['lname'] = $attendee->lname();
2528
+		$this->_template_args['email'] = $attendee->email();
2529
+		$this->_template_args['phone'] = $attendee->phone();
2530
+		$this->_template_args['formatted_address'] = EEH_Address::format($attendee);
2531
+		// edit link
2532
+		$this->_template_args['att_edit_link'] = EE_Admin_Page::add_query_args_and_nonce(
2533
+			array(
2534
+				'action' => 'edit_attendee',
2535
+				'post'   => $attendee->ID(),
2536
+			),
2537
+			REG_ADMIN_URL
2538
+		);
2539
+		$this->_template_args['att_edit_label'] = esc_html__('View/Edit Contact', 'event_espresso');
2540
+		// create link
2541
+		$this->_template_args['create_link'] = $primary_registration instanceof EE_Registration
2542
+			? EE_Admin_Page::add_query_args_and_nonce(
2543
+				array(
2544
+					'action'  => 'duplicate_attendee',
2545
+					'_REG_ID' => $this->_registration->ID(),
2546
+				),
2547
+				REG_ADMIN_URL
2548
+			) : '';
2549
+		$this->_template_args['create_label'] = esc_html__('Create Contact', 'event_espresso');
2550
+		$this->_template_args['att_check'] = $att_check;
2551
+		$template_path = REG_TEMPLATE_PATH . 'reg_admin_details_side_meta_box_registrant.template.php';
2552
+		echo EEH_Template::display_template($template_path, $this->_template_args, true);
2553
+	}
2554
+
2555
+
2556
+	/**
2557
+	 * trash or restore registrations
2558
+	 *
2559
+	 * @param  boolean $trash whether to archive or restore
2560
+	 * @return void
2561
+	 * @throws EE_Error
2562
+	 * @throws InvalidArgumentException
2563
+	 * @throws InvalidDataTypeException
2564
+	 * @throws InvalidInterfaceException
2565
+	 * @throws RuntimeException
2566
+	 * @access protected
2567
+	 */
2568
+	protected function _trash_or_restore_registrations($trash = true)
2569
+	{
2570
+		// if empty _REG_ID then get out because there's nothing to do
2571
+		if (empty($this->_req_data['_REG_ID'])) {
2572
+			EE_Error::add_error(
2573
+				sprintf(
2574
+					esc_html__(
2575
+						'In order to %1$s registrations you must select which ones you wish to %1$s by clicking the checkboxes.',
2576
+						'event_espresso'
2577
+					),
2578
+					$trash ? 'trash' : 'restore'
2579
+				),
2580
+				__FILE__,
2581
+				__LINE__,
2582
+				__FUNCTION__
2583
+			);
2584
+			$this->_redirect_after_action(false, '', '', array(), true);
2585
+		}
2586
+		$success = 0;
2587
+		$overwrite_msgs = false;
2588
+		// Checkboxes
2589
+		if (! is_array($this->_req_data['_REG_ID'])) {
2590
+			$this->_req_data['_REG_ID'] = array($this->_req_data['_REG_ID']);
2591
+		}
2592
+		$reg_count = count($this->_req_data['_REG_ID']);
2593
+		// cycle thru checkboxes
2594
+		foreach ($this->_req_data['_REG_ID'] as $REG_ID) {
2595
+			/** @var EE_Registration $REG */
2596
+			$REG = $this->getRegistrationModel()->get_one_by_ID($REG_ID);
2597
+			$payments = $REG->registration_payments();
2598
+			if (! empty($payments)) {
2599
+				$name = $REG->attendee() instanceof EE_Attendee
2600
+					? $REG->attendee()->full_name()
2601
+					: esc_html__('Unknown Attendee', 'event_espresso');
2602
+				$overwrite_msgs = true;
2603
+				EE_Error::add_error(
2604
+					sprintf(
2605
+						esc_html__(
2606
+							'The registration for %s could not be trashed because it has payments attached to the related transaction.  If you wish to trash this registration you must first delete the payments on the related transaction.',
2607
+							'event_espresso'
2608
+						),
2609
+						$name
2610
+					),
2611
+					__FILE__,
2612
+					__FUNCTION__,
2613
+					__LINE__
2614
+				);
2615
+				// can't trash this registration because it has payments.
2616
+				continue;
2617
+			}
2618
+			$updated = $trash ? $REG->delete() : $REG->restore();
2619
+			if ($updated) {
2620
+				$success++;
2621
+			}
2622
+		}
2623
+		$this->_redirect_after_action(
2624
+			$success === $reg_count, // were ALL registrations affected?
2625
+			$success > 1
2626
+				? esc_html__('Registrations', 'event_espresso')
2627
+				: esc_html__('Registration', 'event_espresso'),
2628
+			$trash
2629
+				? esc_html__('moved to the trash', 'event_espresso')
2630
+				: esc_html__('restored', 'event_espresso'),
2631
+			$this->mergeExistingRequestParamsWithRedirectArgs(array('action' => 'default')),
2632
+			$overwrite_msgs
2633
+		);
2634
+	}
2635
+
2636
+
2637
+	/**
2638
+	 * This is used to permanently delete registrations.  Note, this will handle not only deleting permanently the
2639
+	 * registration but also.
2640
+	 * 1. Removing relations to EE_Attendee
2641
+	 * 2. Deleting permanently the related transaction, but ONLY if all related registrations to the transaction are
2642
+	 * ALSO trashed.
2643
+	 * 3. Deleting permanently any related Line items but only if the above conditions are met.
2644
+	 * 4. Removing relationships between all tickets and the related registrations
2645
+	 * 5. Deleting permanently any related Answers (and the answers for other related registrations that were deleted.)
2646
+	 * 6. Deleting permanently any related Checkins.
2647
+	 *
2648
+	 * @return void
2649
+	 * @throws EE_Error
2650
+	 * @throws InvalidArgumentException
2651
+	 * @throws InvalidDataTypeException
2652
+	 * @throws InvalidInterfaceException
2653
+	 * @throws ReflectionException
2654
+	 */
2655
+	protected function _delete_registrations()
2656
+	{
2657
+		$REG_MDL = $this->getRegistrationModel();
2658
+		$success = 1;
2659
+		// Checkboxes
2660
+		if (! empty($this->_req_data['_REG_ID']) && is_array($this->_req_data['_REG_ID'])) {
2661
+			// if array has more than one element than success message should be plural
2662
+			$success = count($this->_req_data['_REG_ID']) > 1 ? 2 : 1;
2663
+			// cycle thru checkboxes
2664
+			foreach ($this->_req_data['_REG_ID'] as $REG_ID) {
2665
+				$REG = $REG_MDL->get_one_by_ID($REG_ID);
2666
+				if (! $REG instanceof EE_Registration) {
2667
+					continue;
2668
+				}
2669
+				$deleted = $this->_delete_registration($REG);
2670
+				if (! $deleted) {
2671
+					$success = 0;
2672
+				}
2673
+			}
2674
+		} else {
2675
+			// grab single id and delete
2676
+			$REG_ID = $this->_req_data['_REG_ID'];
2677
+			/** @var EE_Registration $REG */
2678
+			$REG = $REG_MDL->get_one_by_ID($REG_ID);
2679
+			$deleted = $this->_delete_registration($REG);
2680
+			if (! $deleted) {
2681
+				$success = 0;
2682
+			}
2683
+		}
2684
+		$what = $success > 1
2685
+			? esc_html__('Registrations', 'event_espresso')
2686
+			: esc_html__('Registration', 'event_espresso');
2687
+		$action_desc = esc_html__('permanently deleted.', 'event_espresso');
2688
+		$this->_redirect_after_action(
2689
+			$success,
2690
+			$what,
2691
+			$action_desc,
2692
+			$this->mergeExistingRequestParamsWithRedirectArgs(['action' => 'default']),
2693
+			true
2694
+		);
2695
+	}
2696
+
2697
+
2698
+	/**
2699
+	 * handles the permanent deletion of a registration.  See comments with _delete_registrations() for details on what
2700
+	 * models get affected.
2701
+	 *
2702
+	 * @param EE_Registration $REG registration to be deleted permanently
2703
+	 * @return bool true = successful deletion, false = fail.
2704
+	 * @throws EE_Error
2705
+	 * @throws InvalidArgumentException
2706
+	 * @throws InvalidDataTypeException
2707
+	 * @throws InvalidInterfaceException
2708
+	 * @throws ReflectionException
2709
+	 */
2710
+	protected function _delete_registration(EE_Registration $REG)
2711
+	{
2712
+		// first we start with the transaction... ultimately, we WILL not delete permanently if there are any related
2713
+		// registrations on the transaction that are NOT trashed.
2714
+		$TXN = $REG->get_first_related('Transaction');
2715
+		if (! $TXN instanceof EE_Transaction) {
2716
+			EE_Error::add_error(
2717
+				sprintf(
2718
+					esc_html__(
2719
+						'Unable to permanently delete registration %d because its related transaction has already been deleted. If you can restore the related transaction to the database then this registration can be deleted.',
2720
+						'event_espresso'
2721
+					),
2722
+					$REG->id()
2723
+				),
2724
+				__FILE__,
2725
+				__FUNCTION__,
2726
+				__LINE__
2727
+			);
2728
+			return false;
2729
+		}
2730
+		$REGS = $TXN->get_many_related('Registration');
2731
+		$all_trashed = true;
2732
+		foreach ($REGS as $registration) {
2733
+			if (! $registration->get('REG_deleted')) {
2734
+				$all_trashed = false;
2735
+			}
2736
+		}
2737
+		if (! $all_trashed) {
2738
+			EE_Error::add_error(
2739
+				esc_html__(
2740
+					'Unable to permanently delete this registration. Before this registration can be permanently deleted, all registrations made in the same transaction must be trashed as well.  These registrations will be permanently deleted in the same action.',
2741
+					'event_espresso'
2742
+				),
2743
+				__FILE__,
2744
+				__FUNCTION__,
2745
+				__LINE__
2746
+			);
2747
+			return false;
2748
+		}
2749
+		// k made it here so that means we can delete all the related transactions and their answers (but let's do them
2750
+		// separately from THIS one).
2751
+		foreach ($REGS as $registration) {
2752
+			// delete related answers
2753
+			$registration->delete_related_permanently('Answer');
2754
+			// remove relationship to EE_Attendee (but we ALWAYS leave the contact record intact)
2755
+			$attendee = $registration->get_first_related('Attendee');
2756
+			if ($attendee instanceof EE_Attendee) {
2757
+				$registration->_remove_relation_to($attendee, 'Attendee');
2758
+			}
2759
+			// now remove relationships to tickets on this registration.
2760
+			$registration->_remove_relations('Ticket');
2761
+			// now delete permanently the checkins related to this registration.
2762
+			$registration->delete_related_permanently('Checkin');
2763
+			if ($registration->ID() === $REG->ID()) {
2764
+				continue;
2765
+			} //we don't want to delete permanently the existing registration just yet.
2766
+			// remove relation to transaction for these registrations if NOT the existing registrations
2767
+			$registration->_remove_relations('Transaction');
2768
+			// delete permanently any related messages.
2769
+			$registration->delete_related_permanently('Message');
2770
+			// now delete this registration permanently
2771
+			$registration->delete_permanently();
2772
+		}
2773
+		// now all related registrations on the transaction are handled.  So let's just handle this registration itself
2774
+		// (the transaction and line items should be all that's left).
2775
+		// delete the line items related to the transaction for this registration.
2776
+		$TXN->delete_related_permanently('Line_Item');
2777
+		// we need to remove all the relationships on the transaction
2778
+		$TXN->delete_related_permanently('Payment');
2779
+		$TXN->delete_related_permanently('Extra_Meta');
2780
+		$TXN->delete_related_permanently('Message');
2781
+		// now we can delete this REG permanently (and the transaction of course)
2782
+		$REG->delete_related_permanently('Transaction');
2783
+		return $REG->delete_permanently();
2784
+	}
2785
+
2786
+
2787
+	/**
2788
+	 *    generates HTML for the Register New Attendee Admin page
2789
+	 *
2790
+	 * @access private
2791
+	 * @throws DomainException
2792
+	 * @throws EE_Error
2793
+	 * @throws InvalidArgumentException
2794
+	 * @throws InvalidDataTypeException
2795
+	 * @throws InvalidInterfaceException
2796
+	 * @throws ReflectionException
2797
+	 */
2798
+	public function new_registration()
2799
+	{
2800
+		if (! $this->_set_reg_event()) {
2801
+			throw new EE_Error(
2802
+				esc_html__(
2803
+					'Unable to continue with registering because there is no Event ID in the request',
2804
+					'event_espresso'
2805
+				)
2806
+			);
2807
+		}
2808
+		EE_Registry::instance()->REQ->set_espresso_page(true);
2809
+		// gotta start with a clean slate if we're not coming here via ajax
2810
+		if (! defined('DOING_AJAX')
2811
+			&& (! isset($this->_req_data['processing_registration']) || isset($this->_req_data['step_error']))
2812
+		) {
2813
+			EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
2814
+		}
2815
+		$this->_template_args['event_name'] = '';
2816
+		// event name
2817
+		if ($this->_reg_event) {
2818
+			$this->_template_args['event_name'] = $this->_reg_event->name();
2819
+			$edit_event_url = self::add_query_args_and_nonce(
2820
+				array(
2821
+					'action' => 'edit',
2822
+					'post'   => $this->_reg_event->ID(),
2823
+				),
2824
+				EVENTS_ADMIN_URL
2825
+			);
2826
+			$edit_event_lnk = '<a href="'
2827
+							  . $edit_event_url
2828
+							  . '" title="'
2829
+							  . esc_attr__('Edit ', 'event_espresso')
2830
+							  . $this->_reg_event->name()
2831
+							  . '">'
2832
+							  . esc_html__('Edit Event', 'event_espresso')
2833
+							  . '</a>';
2834
+			$this->_template_args['event_name'] .= ' <span class="admin-page-header-edit-lnk not-bold">'
2835
+												   . $edit_event_lnk
2836
+												   . '</span>';
2837
+		}
2838
+		$this->_template_args['step_content'] = $this->_get_registration_step_content();
2839
+		if (defined('DOING_AJAX')) {
2840
+			$this->_return_json();
2841
+		}
2842
+		// grab header
2843
+		$template_path =
2844
+			REG_TEMPLATE_PATH . 'reg_admin_register_new_attendee.template.php';
2845
+		$this->_template_args['admin_page_content'] = EEH_Template::display_template(
2846
+			$template_path,
2847
+			$this->_template_args,
2848
+			true
2849
+		);
2850
+		// $this->_set_publish_post_box_vars( NULL, FALSE, FALSE, NULL, FALSE );
2851
+		// the details template wrapper
2852
+		$this->display_admin_page_with_sidebar();
2853
+	}
2854
+
2855
+
2856
+	/**
2857
+	 * This returns the content for a registration step
2858
+	 *
2859
+	 * @access protected
2860
+	 * @return string html
2861
+	 * @throws DomainException
2862
+	 * @throws EE_Error
2863
+	 * @throws InvalidArgumentException
2864
+	 * @throws InvalidDataTypeException
2865
+	 * @throws InvalidInterfaceException
2866
+	 */
2867
+	protected function _get_registration_step_content()
2868
+	{
2869
+		if (isset($_COOKIE['ee_registration_added']) && $_COOKIE['ee_registration_added']) {
2870
+			$warning_msg = sprintf(
2871
+				esc_html__(
2872
+					'%2$sWARNING!!!%3$s%1$sPlease do not use the back button to return to this page for the purpose of adding another registration.%1$sThis can result in lost and/or corrupted data.%1$sIf you wish to add another registration, then please click the%1$s%7$s"Add Another New Registration to Event"%8$s button%1$son the Transaction details page, after you are redirected.%1$s%1$s%4$s redirecting in %5$s seconds %6$s',
2873
+					'event_espresso'
2874
+				),
2875
+				'<br />',
2876
+				'<h3 class="important-notice">',
2877
+				'</h3>',
2878
+				'<div class="float-right">',
2879
+				'<span id="redirect_timer" class="important-notice">30</span>',
2880
+				'</div>',
2881
+				'<b>',
2882
+				'</b>'
2883
+			);
2884
+			return '
2885 2885
 	<div id="ee-add-reg-back-button-dv"><p>' . $warning_msg . '</p></div>
2886 2886
 	<script >
2887 2887
 		// WHOAH !!! it appears that someone is using the back button from the Transaction admin page
@@ -2894,868 +2894,868 @@  discard block
 block discarded – undo
2894 2894
 	        }
2895 2895
 	    }, 800 );
2896 2896
 	</script >';
2897
-        }
2898
-        $template_args = array(
2899
-            'title'                    => '',
2900
-            'content'                  => '',
2901
-            'step_button_text'         => '',
2902
-            'show_notification_toggle' => false,
2903
-        );
2904
-        // to indicate we're processing a new registration
2905
-        $hidden_fields = array(
2906
-            'processing_registration' => array(
2907
-                'type'  => 'hidden',
2908
-                'value' => 0,
2909
-            ),
2910
-            'event_id'                => array(
2911
-                'type'  => 'hidden',
2912
-                'value' => $this->_reg_event->ID(),
2913
-            ),
2914
-        );
2915
-        // if the cart is empty then we know we're at step one so we'll display ticket selector
2916
-        $cart = EE_Registry::instance()->SSN->cart();
2917
-        $step = ! $cart instanceof EE_Cart ? 'ticket' : 'questions';
2918
-        switch ($step) {
2919
-            case 'ticket':
2920
-                $hidden_fields['processing_registration']['value'] = 1;
2921
-                $template_args['title'] = esc_html__(
2922
-                    'Step One: Select the Ticket for this registration',
2923
-                    'event_espresso'
2924
-                );
2925
-                $template_args['content'] =
2926
-                    EED_Ticket_Selector::instance()->display_ticket_selector($this->_reg_event);
2927
-                $template_args['content'] .= '</div>';
2928
-                $template_args['step_button_text'] = esc_html__(
2929
-                    'Add Tickets and Continue to Registrant Details',
2930
-                    'event_espresso'
2931
-                );
2932
-                $template_args['show_notification_toggle'] = false;
2933
-                break;
2934
-            case 'questions':
2935
-                $hidden_fields['processing_registration']['value'] = 2;
2936
-                $template_args['title'] = esc_html__(
2937
-                    'Step Two: Add Registrant Details for this Registration',
2938
-                    'event_espresso'
2939
-                );
2940
-                // in theory we should be able to run EED_SPCO at this point because the cart should have been setup
2941
-                // properly by the first process_reg_step run.
2942
-                $template_args['content'] =
2943
-                    EED_Single_Page_Checkout::registration_checkout_for_admin();
2944
-                $template_args['step_button_text'] = esc_html__(
2945
-                    'Save Registration and Continue to Details',
2946
-                    'event_espresso'
2947
-                );
2948
-                $template_args['show_notification_toggle'] = true;
2949
-                break;
2950
-        }
2951
-        // we come back to the process_registration_step route.
2952
-        $this->_set_add_edit_form_tags('process_reg_step', $hidden_fields);
2953
-        return EEH_Template::display_template(
2954
-            REG_TEMPLATE_PATH . 'reg_admin_register_new_attendee_step_content.template.php',
2955
-            $template_args,
2956
-            true
2957
-        );
2958
-    }
2959
-
2960
-
2961
-    /**
2962
-     *        set_reg_event
2963
-     *
2964
-     * @access private
2965
-     * @return bool
2966
-     * @throws EE_Error
2967
-     * @throws InvalidArgumentException
2968
-     * @throws InvalidDataTypeException
2969
-     * @throws InvalidInterfaceException
2970
-     */
2971
-    private function _set_reg_event()
2972
-    {
2973
-        if (is_object($this->_reg_event)) {
2974
-            return true;
2975
-        }
2976
-        $EVT_ID = (! empty($this->_req_data['event_id'])) ? absint($this->_req_data['event_id']) : false;
2977
-        if (! $EVT_ID) {
2978
-            return false;
2979
-        }
2980
-        $this->_reg_event = $this->getEventModel()->get_one_by_ID($EVT_ID);
2981
-        return true;
2982
-    }
2983
-
2984
-
2985
-    /**
2986
-     * process_reg_step
2987
-     *
2988
-     * @access        public
2989
-     * @return string
2990
-     * @throws DomainException
2991
-     * @throws EE_Error
2992
-     * @throws InvalidArgumentException
2993
-     * @throws InvalidDataTypeException
2994
-     * @throws InvalidInterfaceException
2995
-     * @throws ReflectionException
2996
-     * @throws RuntimeException
2997
-     */
2998
-    public function process_reg_step()
2999
-    {
3000
-        EE_System::do_not_cache();
3001
-        $this->_set_reg_event();
3002
-        EE_Registry::instance()->REQ->set_espresso_page(true);
3003
-        EE_Registry::instance()->REQ->set('uts', time());
3004
-        // what step are we on?
3005
-        $cart = EE_Registry::instance()->SSN->cart();
3006
-        $step = ! $cart instanceof EE_Cart ? 'ticket' : 'questions';
3007
-        // if doing ajax then we need to verify the nonce
3008
-        if (defined('DOING_AJAX')) {
3009
-            $nonce = isset($this->_req_data[ $this->_req_nonce ])
3010
-                ? sanitize_text_field($this->_req_data[ $this->_req_nonce ]) : '';
3011
-            $this->_verify_nonce($nonce, $this->_req_nonce);
3012
-        }
3013
-        switch ($step) {
3014
-            case 'ticket':
3015
-                // process ticket selection
3016
-                $success = EED_Ticket_Selector::instance()->process_ticket_selections();
3017
-                if ($success) {
3018
-                    EE_Error::add_success(
3019
-                        esc_html__(
3020
-                            'Tickets Selected. Now complete the registration.',
3021
-                            'event_espresso'
3022
-                        )
3023
-                    );
3024
-                } else {
3025
-                    $query_args['step_error'] = $this->_req_data['step_error'] = true;
3026
-                }
3027
-                if (defined('DOING_AJAX')) {
3028
-                    $this->new_registration(); // display next step
3029
-                } else {
3030
-                    $query_args = array(
3031
-                        'action'                  => 'new_registration',
3032
-                        'processing_registration' => 1,
3033
-                        'event_id'                => $this->_reg_event->ID(),
3034
-                        'uts'                     => time(),
3035
-                    );
3036
-                    $this->_redirect_after_action(
3037
-                        false,
3038
-                        '',
3039
-                        '',
3040
-                        $query_args,
3041
-                        true
3042
-                    );
3043
-                }
3044
-                break;
3045
-            case 'questions':
3046
-                if (! isset(
3047
-                    $this->_req_data['txn_reg_status_change'],
3048
-                    $this->_req_data['txn_reg_status_change']['send_notifications']
3049
-                )
3050
-                ) {
3051
-                    add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_false', 15);
3052
-                }
3053
-                // process registration
3054
-                $transaction = EED_Single_Page_Checkout::instance()->process_registration_from_admin();
3055
-                if ($cart instanceof EE_Cart) {
3056
-                    $grand_total = $cart->get_cart_grand_total();
3057
-                    if ($grand_total instanceof EE_Line_Item) {
3058
-                        $grand_total->save_this_and_descendants_to_txn();
3059
-                    }
3060
-                }
3061
-                if (! $transaction instanceof EE_Transaction) {
3062
-                    $query_args = array(
3063
-                        'action'                  => 'new_registration',
3064
-                        'processing_registration' => 2,
3065
-                        'event_id'                => $this->_reg_event->ID(),
3066
-                        'uts'                     => time(),
3067
-                    );
3068
-                    if (defined('DOING_AJAX')) {
3069
-                        // display registration form again because there are errors (maybe validation?)
3070
-                        $this->new_registration();
3071
-                        return;
3072
-                    }
3073
-                    $this->_redirect_after_action(
3074
-                        false,
3075
-                        '',
3076
-                        '',
3077
-                        $query_args,
3078
-                        true
3079
-                    );
3080
-                    return;
3081
-                }
3082
-                // maybe update status, and make sure to save transaction if not done already
3083
-                if (! $transaction->update_status_based_on_total_paid()) {
3084
-                    $transaction->save();
3085
-                }
3086
-                EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
3087
-                $this->_req_data = array();
3088
-                $query_args = array(
3089
-                    'action'        => 'redirect_to_txn',
3090
-                    'TXN_ID'        => $transaction->ID(),
3091
-                    'EVT_ID'        => $this->_reg_event->ID(),
3092
-                    'event_name'    => urlencode($this->_reg_event->name()),
3093
-                    'redirect_from' => 'new_registration',
3094
-                );
3095
-                $this->_redirect_after_action(false, '', '', $query_args, true);
3096
-                break;
3097
-        }
3098
-        // what are you looking here for?  Should be nothing to do at this point.
3099
-    }
3100
-
3101
-
3102
-    /**
3103
-     * redirect_to_txn
3104
-     *
3105
-     * @access public
3106
-     * @return void
3107
-     * @throws EE_Error
3108
-     * @throws InvalidArgumentException
3109
-     * @throws InvalidDataTypeException
3110
-     * @throws InvalidInterfaceException
3111
-     * @throws ReflectionException
3112
-     */
3113
-    public function redirect_to_txn()
3114
-    {
3115
-        EE_System::do_not_cache();
3116
-        EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
3117
-        $query_args = array(
3118
-            'action' => 'view_transaction',
3119
-            'TXN_ID' => isset($this->_req_data['TXN_ID']) ? absint($this->_req_data['TXN_ID']) : 0,
3120
-            'page'   => 'espresso_transactions',
3121
-        );
3122
-        if (isset($this->_req_data['EVT_ID'], $this->_req_data['redirect_from'])) {
3123
-            $query_args['EVT_ID'] = $this->_req_data['EVT_ID'];
3124
-            $query_args['event_name'] = urlencode($this->_req_data['event_name']);
3125
-            $query_args['redirect_from'] = $this->_req_data['redirect_from'];
3126
-        }
3127
-        EE_Error::add_success(
3128
-            esc_html__(
3129
-                'Registration Created.  Please review the transaction and add any payments as necessary',
3130
-                'event_espresso'
3131
-            )
3132
-        );
3133
-        $this->_redirect_after_action(false, '', '', $query_args, true);
3134
-    }
3135
-
3136
-
3137
-    /**
3138
-     *        generates HTML for the Attendee Contact List
3139
-     *
3140
-     * @access protected
3141
-     * @return void
3142
-     * @throws DomainException
3143
-     * @throws EE_Error
3144
-     */
3145
-    protected function _attendee_contact_list_table()
3146
-    {
3147
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3148
-        $this->_search_btn_label = esc_html__('Contacts', 'event_espresso');
3149
-        $this->display_admin_list_table_page_with_no_sidebar();
3150
-    }
3151
-
3152
-
3153
-    /**
3154
-     *        get_attendees
3155
-     *
3156
-     * @param      $per_page
3157
-     * @param bool $count whether to return count or data.
3158
-     * @param bool $trash
3159
-     * @return array
3160
-     * @throws EE_Error
3161
-     * @throws InvalidArgumentException
3162
-     * @throws InvalidDataTypeException
3163
-     * @throws InvalidInterfaceException
3164
-     * @access public
3165
-     */
3166
-    public function get_attendees($per_page, $count = false, $trash = false)
3167
-    {
3168
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3169
-        require_once(REG_ADMIN . 'EE_Attendee_Contact_List_Table.class.php');
3170
-        $this->_req_data['orderby'] = ! empty($this->_req_data['orderby']) ? $this->_req_data['orderby'] : '';
3171
-        switch ($this->_req_data['orderby']) {
3172
-            case 'ATT_ID':
3173
-                $orderby = 'ATT_ID';
3174
-                break;
3175
-            case 'ATT_fname':
3176
-                $orderby = 'ATT_fname';
3177
-                break;
3178
-            case 'ATT_email':
3179
-                $orderby = 'ATT_email';
3180
-                break;
3181
-            case 'ATT_city':
3182
-                $orderby = 'ATT_city';
3183
-                break;
3184
-            case 'STA_ID':
3185
-                $orderby = 'STA_ID';
3186
-                break;
3187
-            case 'CNT_ID':
3188
-                $orderby = 'CNT_ID';
3189
-                break;
3190
-            case 'Registration_Count':
3191
-                $orderby = 'Registration_Count';
3192
-                break;
3193
-            default:
3194
-                $orderby = 'ATT_lname';
3195
-        }
3196
-        $sort = (isset($this->_req_data['order']) && ! empty($this->_req_data['order']))
3197
-            ? $this->_req_data['order']
3198
-            : 'ASC';
3199
-        $current_page = isset($this->_req_data['paged']) && ! empty($this->_req_data['paged'])
3200
-            ? $this->_req_data['paged']
3201
-            : 1;
3202
-        $per_page = isset($per_page) && ! empty($per_page) ? $per_page : 10;
3203
-        $per_page = isset($this->_req_data['perpage']) && ! empty($this->_req_data['perpage'])
3204
-            ? $this->_req_data['perpage']
3205
-            : $per_page;
3206
-        $_where = array();
3207
-        if (! empty($this->_req_data['s'])) {
3208
-            $sstr = '%' . $this->_req_data['s'] . '%';
3209
-            $_where['OR'] = array(
3210
-                'Registration.Event.EVT_name'       => array('LIKE', $sstr),
3211
-                'Registration.Event.EVT_desc'       => array('LIKE', $sstr),
3212
-                'Registration.Event.EVT_short_desc' => array('LIKE', $sstr),
3213
-                'ATT_fname'                         => array('LIKE', $sstr),
3214
-                'ATT_lname'                         => array('LIKE', $sstr),
3215
-                'ATT_short_bio'                     => array('LIKE', $sstr),
3216
-                'ATT_email'                         => array('LIKE', $sstr),
3217
-                'ATT_address'                       => array('LIKE', $sstr),
3218
-                'ATT_address2'                      => array('LIKE', $sstr),
3219
-                'ATT_city'                          => array('LIKE', $sstr),
3220
-                'Country.CNT_name'                  => array('LIKE', $sstr),
3221
-                'State.STA_name'                    => array('LIKE', $sstr),
3222
-                'ATT_phone'                         => array('LIKE', $sstr),
3223
-                'Registration.REG_final_price'      => array('LIKE', $sstr),
3224
-                'Registration.REG_code'             => array('LIKE', $sstr),
3225
-                'Registration.REG_group_size'       => array('LIKE', $sstr),
3226
-            );
3227
-        }
3228
-        $offset = ($current_page - 1) * $per_page;
3229
-        $limit = $count ? null : array($offset, $per_page);
3230
-        $query_args = array(
3231
-            $_where,
3232
-            'extra_selects' => array('Registration_Count' => array('Registration.REG_ID', 'count', '%d')),
3233
-            'limit'         => $limit,
3234
-        );
3235
-        if (! $count) {
3236
-            $query_args['order_by'] = array($orderby => $sort);
3237
-        }
3238
-        if ($trash) {
3239
-            $query_args[0]['status'] = array('!=', 'publish');
3240
-            $all_attendees = $count
3241
-                ? $this->getAttendeeModel()->count($query_args, 'ATT_ID', true)
3242
-                : $this->getAttendeeModel()->get_all($query_args);
3243
-        } else {
3244
-            $query_args[0]['status'] = array('IN', array('publish'));
3245
-            $all_attendees = $count
3246
-                ? $this->getAttendeeModel()->count($query_args, 'ATT_ID', true)
3247
-                : $this->getAttendeeModel()->get_all($query_args);
3248
-        }
3249
-        return $all_attendees;
3250
-    }
3251
-
3252
-
3253
-    /**
3254
-     * This is just taking care of resending the registration confirmation
3255
-     *
3256
-     * @access protected
3257
-     * @return void
3258
-     * @throws EE_Error
3259
-     * @throws InvalidArgumentException
3260
-     * @throws InvalidDataTypeException
3261
-     * @throws InvalidInterfaceException
3262
-     * @throws ReflectionException
3263
-     */
3264
-    protected function _resend_registration()
3265
-    {
3266
-        $this->_process_resend_registration();
3267
-        $query_args = isset($this->_req_data['redirect_to'])
3268
-            ? array('action' => $this->_req_data['redirect_to'], '_REG_ID' => $this->_req_data['_REG_ID'])
3269
-            : array('action' => 'default');
3270
-        $this->_redirect_after_action(false, '', '', $query_args, true);
3271
-    }
3272
-
3273
-    /**
3274
-     * Creates a registration report, but accepts the name of a method to use for preparing the query parameters
3275
-     * to use when selecting registrations
3276
-     *
3277
-     * @param string $method_name_for_getting_query_params the name of the method (on this class) to use for preparing
3278
-     *                                                     the query parameters from the request
3279
-     * @return void ends the request with a redirect or download
3280
-     */
3281
-    public function _registrations_report_base($method_name_for_getting_query_params)
3282
-    {
3283
-        if (! defined('EE_USE_OLD_CSV_REPORT_CLASS')) {
3284
-            wp_redirect(
3285
-                EE_Admin_Page::add_query_args_and_nonce(
3286
-                    array(
3287
-                        'page'        => 'espresso_batch',
3288
-                        'batch'       => 'file',
3289
-                        'EVT_ID'      => isset($this->_req_data['EVT_ID']) ? $this->_req_data['EVT_ID'] : null,
3290
-                        'filters'     => urlencode(
3291
-                            serialize(
3292
-                                $this->$method_name_for_getting_query_params(
3293
-                                    EEH_Array::is_set(
3294
-                                        $this->_req_data,
3295
-                                        'filters',
3296
-                                        array()
3297
-                                    )
3298
-                                )
3299
-                            )
3300
-                        ),
3301
-                        'use_filters' => EEH_Array::is_set($this->_req_data, 'use_filters', false),
3302
-                        'job_handler' => urlencode('EventEspressoBatchRequest\JobHandlers\RegistrationsReport'),
3303
-                        'return_url'  => urlencode($this->_req_data['return_url']),
3304
-                    )
3305
-                )
3306
-            );
3307
-        } else {
3308
-            $new_request_args = array(
3309
-                'export' => 'report',
3310
-                'action' => 'registrations_report_for_event',
3311
-                'EVT_ID' => isset($this->_req_data['EVT_ID']) ? $this->_req_data['EVT_ID'] : null,
3312
-            );
3313
-            $this->_req_data = array_merge($this->_req_data, $new_request_args);
3314
-            if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
3315
-                require_once(EE_CLASSES . 'EE_Export.class.php');
3316
-                $EE_Export = EE_Export::instance($this->_req_data);
3317
-                $EE_Export->export();
3318
-            }
3319
-        }
3320
-    }
3321
-
3322
-
3323
-    /**
3324
-     * Creates a registration report using only query parameters in the request
3325
-     *
3326
-     * @return void
3327
-     */
3328
-    public function _registrations_report()
3329
-    {
3330
-        $this->_registrations_report_base('_get_registration_query_parameters');
3331
-    }
3332
-
3333
-
3334
-    public function _contact_list_export()
3335
-    {
3336
-        if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
3337
-            require_once(EE_CLASSES . 'EE_Export.class.php');
3338
-            $EE_Export = EE_Export::instance($this->_req_data);
3339
-            $EE_Export->export_attendees();
3340
-        }
3341
-    }
3342
-
3343
-
3344
-    public function _contact_list_report()
3345
-    {
3346
-        if (! defined('EE_USE_OLD_CSV_REPORT_CLASS')) {
3347
-            wp_redirect(
3348
-                EE_Admin_Page::add_query_args_and_nonce(
3349
-                    array(
3350
-                        'page'        => 'espresso_batch',
3351
-                        'batch'       => 'file',
3352
-                        'job_handler' => urlencode('EventEspressoBatchRequest\JobHandlers\AttendeesReport'),
3353
-                        'return_url'  => urlencode($this->_req_data['return_url']),
3354
-                    )
3355
-                )
3356
-            );
3357
-        } else {
3358
-            if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
3359
-                require_once(EE_CLASSES . 'EE_Export.class.php');
3360
-                $EE_Export = EE_Export::instance($this->_req_data);
3361
-                $EE_Export->report_attendees();
3362
-            }
3363
-        }
3364
-    }
3365
-
3366
-
3367
-
3368
-
3369
-
3370
-    /***************************************        ATTENDEE DETAILS        ***************************************/
3371
-    /**
3372
-     * This duplicates the attendee object for the given incoming registration id and attendee_id.
3373
-     *
3374
-     * @return void
3375
-     * @throws EE_Error
3376
-     * @throws InvalidArgumentException
3377
-     * @throws InvalidDataTypeException
3378
-     * @throws InvalidInterfaceException
3379
-     * @throws ReflectionException
3380
-     */
3381
-    protected function _duplicate_attendee()
3382
-    {
3383
-        $action = ! empty($this->_req_data['return']) ? $this->_req_data['return'] : 'default';
3384
-        // verify we have necessary info
3385
-        if (empty($this->_req_data['_REG_ID'])) {
3386
-            EE_Error::add_error(
3387
-                esc_html__(
3388
-                    'Unable to create the contact for the registration because the required parameters are not present (_REG_ID )',
3389
-                    'event_espresso'
3390
-                ),
3391
-                __FILE__,
3392
-                __LINE__,
3393
-                __FUNCTION__
3394
-            );
3395
-            $query_args = array('action' => $action);
3396
-            $this->_redirect_after_action('', '', '', $query_args, true);
3397
-        }
3398
-        // okay necessary deets present... let's dupe the incoming attendee and attach to incoming registration.
3399
-        $registration = $this->getRegistrationModel()->get_one_by_ID($this->_req_data['_REG_ID']);
3400
-        $attendee = $registration->attendee();
3401
-        // remove relation of existing attendee on registration
3402
-        $registration->_remove_relation_to($attendee, 'Attendee');
3403
-        // new attendee
3404
-        $new_attendee = clone $attendee;
3405
-        $new_attendee->set('ATT_ID', 0);
3406
-        $new_attendee->save();
3407
-        // add new attendee to reg
3408
-        $registration->_add_relation_to($new_attendee, 'Attendee');
3409
-        EE_Error::add_success(
3410
-            esc_html__(
3411
-                'New Contact record created.  Now make any edits you wish to make for this contact.',
3412
-                'event_espresso'
3413
-            )
3414
-        );
3415
-        // redirect to edit page for attendee
3416
-        $query_args = array('post' => $new_attendee->ID(), 'action' => 'edit_attendee');
3417
-        $this->_redirect_after_action('', '', '', $query_args, true);
3418
-    }
3419
-
3420
-
3421
-    /**
3422
-     * Callback invoked by parent EE_Admin_CPT class hooked in on `save_post` wp hook.
3423
-     *
3424
-     * @param int     $post_id
3425
-     * @param WP_POST $post
3426
-     * @throws DomainException
3427
-     * @throws EE_Error
3428
-     * @throws InvalidArgumentException
3429
-     * @throws InvalidDataTypeException
3430
-     * @throws InvalidInterfaceException
3431
-     * @throws LogicException
3432
-     * @throws InvalidFormSubmissionException
3433
-     * @throws ReflectionException
3434
-     */
3435
-    protected function _insert_update_cpt_item($post_id, $post)
3436
-    {
3437
-        $success = true;
3438
-        $attendee = $post instanceof WP_Post && $post->post_type === 'espresso_attendees'
3439
-            ? $this->getAttendeeModel()->get_one_by_ID($post_id)
3440
-            : null;
3441
-        // for attendee updates
3442
-        if ($attendee instanceof EE_Attendee) {
3443
-            // note we should only be UPDATING attendees at this point.
3444
-            $updated_fields = array(
3445
-                'ATT_fname'     => $this->_req_data['ATT_fname'],
3446
-                'ATT_lname'     => $this->_req_data['ATT_lname'],
3447
-                'ATT_full_name' => $this->_req_data['ATT_fname'] . ' ' . $this->_req_data['ATT_lname'],
3448
-                'ATT_address'   => isset($this->_req_data['ATT_address']) ? $this->_req_data['ATT_address'] : '',
3449
-                'ATT_address2'  => isset($this->_req_data['ATT_address2']) ? $this->_req_data['ATT_address2'] : '',
3450
-                'ATT_city'      => isset($this->_req_data['ATT_city']) ? $this->_req_data['ATT_city'] : '',
3451
-                'STA_ID'        => isset($this->_req_data['STA_ID']) ? $this->_req_data['STA_ID'] : '',
3452
-                'CNT_ISO'       => isset($this->_req_data['CNT_ISO']) ? $this->_req_data['CNT_ISO'] : '',
3453
-                'ATT_zip'       => isset($this->_req_data['ATT_zip']) ? $this->_req_data['ATT_zip'] : '',
3454
-            );
3455
-            foreach ($updated_fields as $field => $value) {
3456
-                $attendee->set($field, $value);
3457
-            }
3458
-
3459
-            // process contact details metabox form handler (which will also save the attendee)
3460
-            $contact_details_form = $this->getAttendeeContactDetailsMetaboxFormHandler($attendee);
3461
-            $success = $contact_details_form->process($this->_req_data);
3462
-
3463
-            $attendee_update_callbacks = apply_filters(
3464
-                'FHEE__Registrations_Admin_Page__insert_update_cpt_item__attendee_update',
3465
-                array()
3466
-            );
3467
-            foreach ($attendee_update_callbacks as $a_callback) {
3468
-                if (false === call_user_func_array($a_callback, array($attendee, $this->_req_data))) {
3469
-                    throw new EE_Error(
3470
-                        sprintf(
3471
-                            esc_html__(
3472
-                                'The %s callback given for the "FHEE__Registrations_Admin_Page__insert_update_cpt_item__attendee_update" filter is not a valid callback.  Please check the spelling.',
3473
-                                'event_espresso'
3474
-                            ),
3475
-                            $a_callback
3476
-                        )
3477
-                    );
3478
-                }
3479
-            }
3480
-        }
3481
-
3482
-        if ($success === false) {
3483
-            EE_Error::add_error(
3484
-                esc_html__(
3485
-                    'Something went wrong with updating the meta table data for the registration.',
3486
-                    'event_espresso'
3487
-                ),
3488
-                __FILE__,
3489
-                __FUNCTION__,
3490
-                __LINE__
3491
-            );
3492
-        }
3493
-    }
3494
-
3495
-
3496
-    public function trash_cpt_item($post_id)
3497
-    {
3498
-    }
3499
-
3500
-
3501
-    public function delete_cpt_item($post_id)
3502
-    {
3503
-    }
3504
-
3505
-
3506
-    public function restore_cpt_item($post_id)
3507
-    {
3508
-    }
3509
-
3510
-
3511
-    protected function _restore_cpt_item($post_id, $revision_id)
3512
-    {
3513
-    }
3514
-
3515
-
3516
-    /**
3517
-     * @throws EE_Error
3518
-     * @since 4.10.2.p
3519
-     */
3520
-    public function attendee_editor_metaboxes()
3521
-    {
3522
-        $this->verify_cpt_object();
3523
-        remove_meta_box(
3524
-            'postexcerpt',
3525
-            $this->_cpt_routes[ $this->_req_action ],
3526
-            'normal'
3527
-        );
3528
-        remove_meta_box('commentstatusdiv', $this->_cpt_routes[ $this->_req_action ], 'normal', 'core');
3529
-        if (post_type_supports('espresso_attendees', 'excerpt')) {
3530
-            add_meta_box(
3531
-                'postexcerpt',
3532
-                esc_html__('Short Biography', 'event_espresso'),
3533
-                'post_excerpt_meta_box',
3534
-                $this->_cpt_routes[ $this->_req_action ],
3535
-                'normal'
3536
-            );
3537
-        }
3538
-        if (post_type_supports('espresso_attendees', 'comments')) {
3539
-            add_meta_box(
3540
-                'commentsdiv',
3541
-                esc_html__('Notes on the Contact', 'event_espresso'),
3542
-                'post_comment_meta_box',
3543
-                $this->_cpt_routes[ $this->_req_action ],
3544
-                'normal',
3545
-                'core'
3546
-            );
3547
-        }
3548
-        add_meta_box(
3549
-            'attendee_contact_info',
3550
-            esc_html__('Contact Info', 'event_espresso'),
3551
-            array($this, 'attendee_contact_info'),
3552
-            $this->_cpt_routes[ $this->_req_action ],
3553
-            'side',
3554
-            'core'
3555
-        );
3556
-        add_meta_box(
3557
-            'attendee_details_address',
3558
-            esc_html__('Address Details', 'event_espresso'),
3559
-            array($this, 'attendee_address_details'),
3560
-            $this->_cpt_routes[ $this->_req_action ],
3561
-            'normal',
3562
-            'core'
3563
-        );
3564
-        add_meta_box(
3565
-            'attendee_registrations',
3566
-            esc_html__('Registrations for this Contact', 'event_espresso'),
3567
-            array($this, 'attendee_registrations_meta_box'),
3568
-            $this->_cpt_routes[ $this->_req_action ],
3569
-            'normal',
3570
-            'high'
3571
-        );
3572
-    }
3573
-
3574
-
3575
-    /**
3576
-     * Metabox for attendee contact info
3577
-     *
3578
-     * @param  WP_Post $post wp post object
3579
-     * @return string attendee contact info ( and form )
3580
-     * @throws EE_Error
3581
-     * @throws InvalidArgumentException
3582
-     * @throws InvalidDataTypeException
3583
-     * @throws InvalidInterfaceException
3584
-     * @throws LogicException
3585
-     * @throws DomainException
3586
-     */
3587
-    public function attendee_contact_info($post)
3588
-    {
3589
-        // get attendee object ( should already have it )
3590
-        $form = $this->getAttendeeContactDetailsMetaboxFormHandler($this->_cpt_model_obj);
3591
-        $form->enqueueStylesAndScripts();
3592
-        echo $form->display();
3593
-    }
3594
-
3595
-
3596
-    /**
3597
-     * Return form handler for the contact details metabox
3598
-     *
3599
-     * @param EE_Attendee $attendee
3600
-     * @return AttendeeContactDetailsMetaboxFormHandler
3601
-     * @throws DomainException
3602
-     * @throws InvalidArgumentException
3603
-     * @throws InvalidDataTypeException
3604
-     * @throws InvalidInterfaceException
3605
-     */
3606
-    protected function getAttendeeContactDetailsMetaboxFormHandler(EE_Attendee $attendee)
3607
-    {
3608
-        return new AttendeeContactDetailsMetaboxFormHandler($attendee, EE_Registry::instance());
3609
-    }
3610
-
3611
-
3612
-    /**
3613
-     * Metabox for attendee details
3614
-     *
3615
-     * @param  WP_Post $post wp post object
3616
-     * @throws DomainException
3617
-     */
3618
-    public function attendee_address_details($post)
3619
-    {
3620
-        // get attendee object (should already have it)
3621
-        $this->_template_args['attendee'] = $this->_cpt_model_obj;
3622
-        $this->_template_args['state_html'] = EEH_Form_Fields::generate_form_input(
3623
-            new EE_Question_Form_Input(
3624
-                EE_Question::new_instance(
3625
-                    array(
3626
-                        'QST_ID'           => 0,
3627
-                        'QST_display_text' => esc_html__('State/Province', 'event_espresso'),
3628
-                        'QST_system'       => 'admin-state',
3629
-                    )
3630
-                ),
3631
-                EE_Answer::new_instance(
3632
-                    array(
3633
-                        'ANS_ID'    => 0,
3634
-                        'ANS_value' => $this->_cpt_model_obj->state_ID(),
3635
-                    )
3636
-                ),
3637
-                array(
3638
-                    'input_id'       => 'STA_ID',
3639
-                    'input_name'     => 'STA_ID',
3640
-                    'input_prefix'   => '',
3641
-                    'append_qstn_id' => false,
3642
-                )
3643
-            )
3644
-        );
3645
-        $this->_template_args['country_html'] = EEH_Form_Fields::generate_form_input(
3646
-            new EE_Question_Form_Input(
3647
-                EE_Question::new_instance(
3648
-                    array(
3649
-                        'QST_ID'           => 0,
3650
-                        'QST_display_text' => esc_html__('Country', 'event_espresso'),
3651
-                        'QST_system'       => 'admin-country',
3652
-                    )
3653
-                ),
3654
-                EE_Answer::new_instance(
3655
-                    array(
3656
-                        'ANS_ID'    => 0,
3657
-                        'ANS_value' => $this->_cpt_model_obj->country_ID(),
3658
-                    )
3659
-                ),
3660
-                array(
3661
-                    'input_id'       => 'CNT_ISO',
3662
-                    'input_name'     => 'CNT_ISO',
3663
-                    'input_prefix'   => '',
3664
-                    'append_qstn_id' => false,
3665
-                )
3666
-            )
3667
-        );
3668
-        $template =
3669
-            REG_TEMPLATE_PATH . 'attendee_address_details_metabox_content.template.php';
3670
-        EEH_Template::display_template($template, $this->_template_args);
3671
-    }
3672
-
3673
-
3674
-    /**
3675
-     *        _attendee_details
3676
-     *
3677
-     * @access protected
3678
-     * @param $post
3679
-     * @return void
3680
-     * @throws DomainException
3681
-     * @throws EE_Error
3682
-     * @throws InvalidArgumentException
3683
-     * @throws InvalidDataTypeException
3684
-     * @throws InvalidInterfaceException
3685
-     * @throws ReflectionException
3686
-     */
3687
-    public function attendee_registrations_meta_box($post)
3688
-    {
3689
-        $this->_template_args['attendee'] = $this->_cpt_model_obj;
3690
-        $this->_template_args['registrations'] = $this->_cpt_model_obj->get_many_related('Registration');
3691
-        $template =
3692
-            REG_TEMPLATE_PATH . 'attendee_registrations_main_meta_box.template.php';
3693
-        EEH_Template::display_template($template, $this->_template_args);
3694
-    }
3695
-
3696
-
3697
-    /**
3698
-     * add in the form fields for the attendee edit
3699
-     *
3700
-     * @param  WP_Post $post wp post object
3701
-     * @return string html for new form.
3702
-     * @throws DomainException
3703
-     */
3704
-    public function after_title_form_fields($post)
3705
-    {
3706
-        if ($post->post_type === 'espresso_attendees') {
3707
-            $template = REG_TEMPLATE_PATH . 'attendee_details_after_title_form_fields.template.php';
3708
-            $template_args['attendee'] = $this->_cpt_model_obj;
3709
-            EEH_Template::display_template($template, $template_args);
3710
-        }
3711
-    }
3712
-
3713
-
3714
-    /**
3715
-     *        _trash_or_restore_attendee
3716
-     *
3717
-     * @param boolean $trash - whether to move item to trash (TRUE) or restore it (FALSE)
3718
-     * @return void
3719
-     * @throws EE_Error
3720
-     * @throws InvalidArgumentException
3721
-     * @throws InvalidDataTypeException
3722
-     * @throws InvalidInterfaceException
3723
-     * @throws ReflectionException
3724
-     * @access protected
3725
-     */
3726
-    protected function _trash_or_restore_attendees($trash = true)
3727
-    {
3728
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3729
-        $success = 1;
3730
-        // Checkboxes
3731
-        if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
3732
-            // if array has more than one element than success message should be plural
3733
-            $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1;
3734
-            // cycle thru checkboxes
3735
-            foreach ($this->_req_data['checkbox'] as $ATT_ID) {
3736
-                $updated = $trash ? $this->getAttendeeModel()->update_by_ID(array('status' => 'trash'), $ATT_ID)
3737
-                    : $this->getAttendeeModel()->update_by_ID(array('status' => 'publish'), $ATT_ID);
3738
-                if (! $updated) {
3739
-                    $success = 0;
3740
-                }
3741
-            }
3742
-        } else {
3743
-            // grab single id and delete
3744
-            $ATT_ID = absint($this->_req_data['ATT_ID']);
3745
-            // get attendee
3746
-            $att = $this->getAttendeeModel()->get_one_by_ID($ATT_ID);
3747
-            $updated = $trash ? $att->set_status('trash') : $att->set_status('publish');
3748
-            $updated = $att->save() && $updated;
3749
-            if (! $updated) {
3750
-                $success = 0;
3751
-            }
3752
-        }
3753
-        $what = $success > 1
3754
-            ? esc_html__('Contacts', 'event_espresso')
3755
-            : esc_html__('Contact', 'event_espresso');
3756
-        $action_desc = $trash
3757
-            ? esc_html__('moved to the trash', 'event_espresso')
3758
-            : esc_html__('restored', 'event_espresso');
3759
-        $this->_redirect_after_action($success, $what, $action_desc, array('action' => 'contact_list'));
3760
-    }
2897
+		}
2898
+		$template_args = array(
2899
+			'title'                    => '',
2900
+			'content'                  => '',
2901
+			'step_button_text'         => '',
2902
+			'show_notification_toggle' => false,
2903
+		);
2904
+		// to indicate we're processing a new registration
2905
+		$hidden_fields = array(
2906
+			'processing_registration' => array(
2907
+				'type'  => 'hidden',
2908
+				'value' => 0,
2909
+			),
2910
+			'event_id'                => array(
2911
+				'type'  => 'hidden',
2912
+				'value' => $this->_reg_event->ID(),
2913
+			),
2914
+		);
2915
+		// if the cart is empty then we know we're at step one so we'll display ticket selector
2916
+		$cart = EE_Registry::instance()->SSN->cart();
2917
+		$step = ! $cart instanceof EE_Cart ? 'ticket' : 'questions';
2918
+		switch ($step) {
2919
+			case 'ticket':
2920
+				$hidden_fields['processing_registration']['value'] = 1;
2921
+				$template_args['title'] = esc_html__(
2922
+					'Step One: Select the Ticket for this registration',
2923
+					'event_espresso'
2924
+				);
2925
+				$template_args['content'] =
2926
+					EED_Ticket_Selector::instance()->display_ticket_selector($this->_reg_event);
2927
+				$template_args['content'] .= '</div>';
2928
+				$template_args['step_button_text'] = esc_html__(
2929
+					'Add Tickets and Continue to Registrant Details',
2930
+					'event_espresso'
2931
+				);
2932
+				$template_args['show_notification_toggle'] = false;
2933
+				break;
2934
+			case 'questions':
2935
+				$hidden_fields['processing_registration']['value'] = 2;
2936
+				$template_args['title'] = esc_html__(
2937
+					'Step Two: Add Registrant Details for this Registration',
2938
+					'event_espresso'
2939
+				);
2940
+				// in theory we should be able to run EED_SPCO at this point because the cart should have been setup
2941
+				// properly by the first process_reg_step run.
2942
+				$template_args['content'] =
2943
+					EED_Single_Page_Checkout::registration_checkout_for_admin();
2944
+				$template_args['step_button_text'] = esc_html__(
2945
+					'Save Registration and Continue to Details',
2946
+					'event_espresso'
2947
+				);
2948
+				$template_args['show_notification_toggle'] = true;
2949
+				break;
2950
+		}
2951
+		// we come back to the process_registration_step route.
2952
+		$this->_set_add_edit_form_tags('process_reg_step', $hidden_fields);
2953
+		return EEH_Template::display_template(
2954
+			REG_TEMPLATE_PATH . 'reg_admin_register_new_attendee_step_content.template.php',
2955
+			$template_args,
2956
+			true
2957
+		);
2958
+	}
2959
+
2960
+
2961
+	/**
2962
+	 *        set_reg_event
2963
+	 *
2964
+	 * @access private
2965
+	 * @return bool
2966
+	 * @throws EE_Error
2967
+	 * @throws InvalidArgumentException
2968
+	 * @throws InvalidDataTypeException
2969
+	 * @throws InvalidInterfaceException
2970
+	 */
2971
+	private function _set_reg_event()
2972
+	{
2973
+		if (is_object($this->_reg_event)) {
2974
+			return true;
2975
+		}
2976
+		$EVT_ID = (! empty($this->_req_data['event_id'])) ? absint($this->_req_data['event_id']) : false;
2977
+		if (! $EVT_ID) {
2978
+			return false;
2979
+		}
2980
+		$this->_reg_event = $this->getEventModel()->get_one_by_ID($EVT_ID);
2981
+		return true;
2982
+	}
2983
+
2984
+
2985
+	/**
2986
+	 * process_reg_step
2987
+	 *
2988
+	 * @access        public
2989
+	 * @return string
2990
+	 * @throws DomainException
2991
+	 * @throws EE_Error
2992
+	 * @throws InvalidArgumentException
2993
+	 * @throws InvalidDataTypeException
2994
+	 * @throws InvalidInterfaceException
2995
+	 * @throws ReflectionException
2996
+	 * @throws RuntimeException
2997
+	 */
2998
+	public function process_reg_step()
2999
+	{
3000
+		EE_System::do_not_cache();
3001
+		$this->_set_reg_event();
3002
+		EE_Registry::instance()->REQ->set_espresso_page(true);
3003
+		EE_Registry::instance()->REQ->set('uts', time());
3004
+		// what step are we on?
3005
+		$cart = EE_Registry::instance()->SSN->cart();
3006
+		$step = ! $cart instanceof EE_Cart ? 'ticket' : 'questions';
3007
+		// if doing ajax then we need to verify the nonce
3008
+		if (defined('DOING_AJAX')) {
3009
+			$nonce = isset($this->_req_data[ $this->_req_nonce ])
3010
+				? sanitize_text_field($this->_req_data[ $this->_req_nonce ]) : '';
3011
+			$this->_verify_nonce($nonce, $this->_req_nonce);
3012
+		}
3013
+		switch ($step) {
3014
+			case 'ticket':
3015
+				// process ticket selection
3016
+				$success = EED_Ticket_Selector::instance()->process_ticket_selections();
3017
+				if ($success) {
3018
+					EE_Error::add_success(
3019
+						esc_html__(
3020
+							'Tickets Selected. Now complete the registration.',
3021
+							'event_espresso'
3022
+						)
3023
+					);
3024
+				} else {
3025
+					$query_args['step_error'] = $this->_req_data['step_error'] = true;
3026
+				}
3027
+				if (defined('DOING_AJAX')) {
3028
+					$this->new_registration(); // display next step
3029
+				} else {
3030
+					$query_args = array(
3031
+						'action'                  => 'new_registration',
3032
+						'processing_registration' => 1,
3033
+						'event_id'                => $this->_reg_event->ID(),
3034
+						'uts'                     => time(),
3035
+					);
3036
+					$this->_redirect_after_action(
3037
+						false,
3038
+						'',
3039
+						'',
3040
+						$query_args,
3041
+						true
3042
+					);
3043
+				}
3044
+				break;
3045
+			case 'questions':
3046
+				if (! isset(
3047
+					$this->_req_data['txn_reg_status_change'],
3048
+					$this->_req_data['txn_reg_status_change']['send_notifications']
3049
+				)
3050
+				) {
3051
+					add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_false', 15);
3052
+				}
3053
+				// process registration
3054
+				$transaction = EED_Single_Page_Checkout::instance()->process_registration_from_admin();
3055
+				if ($cart instanceof EE_Cart) {
3056
+					$grand_total = $cart->get_cart_grand_total();
3057
+					if ($grand_total instanceof EE_Line_Item) {
3058
+						$grand_total->save_this_and_descendants_to_txn();
3059
+					}
3060
+				}
3061
+				if (! $transaction instanceof EE_Transaction) {
3062
+					$query_args = array(
3063
+						'action'                  => 'new_registration',
3064
+						'processing_registration' => 2,
3065
+						'event_id'                => $this->_reg_event->ID(),
3066
+						'uts'                     => time(),
3067
+					);
3068
+					if (defined('DOING_AJAX')) {
3069
+						// display registration form again because there are errors (maybe validation?)
3070
+						$this->new_registration();
3071
+						return;
3072
+					}
3073
+					$this->_redirect_after_action(
3074
+						false,
3075
+						'',
3076
+						'',
3077
+						$query_args,
3078
+						true
3079
+					);
3080
+					return;
3081
+				}
3082
+				// maybe update status, and make sure to save transaction if not done already
3083
+				if (! $transaction->update_status_based_on_total_paid()) {
3084
+					$transaction->save();
3085
+				}
3086
+				EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
3087
+				$this->_req_data = array();
3088
+				$query_args = array(
3089
+					'action'        => 'redirect_to_txn',
3090
+					'TXN_ID'        => $transaction->ID(),
3091
+					'EVT_ID'        => $this->_reg_event->ID(),
3092
+					'event_name'    => urlencode($this->_reg_event->name()),
3093
+					'redirect_from' => 'new_registration',
3094
+				);
3095
+				$this->_redirect_after_action(false, '', '', $query_args, true);
3096
+				break;
3097
+		}
3098
+		// what are you looking here for?  Should be nothing to do at this point.
3099
+	}
3100
+
3101
+
3102
+	/**
3103
+	 * redirect_to_txn
3104
+	 *
3105
+	 * @access public
3106
+	 * @return void
3107
+	 * @throws EE_Error
3108
+	 * @throws InvalidArgumentException
3109
+	 * @throws InvalidDataTypeException
3110
+	 * @throws InvalidInterfaceException
3111
+	 * @throws ReflectionException
3112
+	 */
3113
+	public function redirect_to_txn()
3114
+	{
3115
+		EE_System::do_not_cache();
3116
+		EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
3117
+		$query_args = array(
3118
+			'action' => 'view_transaction',
3119
+			'TXN_ID' => isset($this->_req_data['TXN_ID']) ? absint($this->_req_data['TXN_ID']) : 0,
3120
+			'page'   => 'espresso_transactions',
3121
+		);
3122
+		if (isset($this->_req_data['EVT_ID'], $this->_req_data['redirect_from'])) {
3123
+			$query_args['EVT_ID'] = $this->_req_data['EVT_ID'];
3124
+			$query_args['event_name'] = urlencode($this->_req_data['event_name']);
3125
+			$query_args['redirect_from'] = $this->_req_data['redirect_from'];
3126
+		}
3127
+		EE_Error::add_success(
3128
+			esc_html__(
3129
+				'Registration Created.  Please review the transaction and add any payments as necessary',
3130
+				'event_espresso'
3131
+			)
3132
+		);
3133
+		$this->_redirect_after_action(false, '', '', $query_args, true);
3134
+	}
3135
+
3136
+
3137
+	/**
3138
+	 *        generates HTML for the Attendee Contact List
3139
+	 *
3140
+	 * @access protected
3141
+	 * @return void
3142
+	 * @throws DomainException
3143
+	 * @throws EE_Error
3144
+	 */
3145
+	protected function _attendee_contact_list_table()
3146
+	{
3147
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3148
+		$this->_search_btn_label = esc_html__('Contacts', 'event_espresso');
3149
+		$this->display_admin_list_table_page_with_no_sidebar();
3150
+	}
3151
+
3152
+
3153
+	/**
3154
+	 *        get_attendees
3155
+	 *
3156
+	 * @param      $per_page
3157
+	 * @param bool $count whether to return count or data.
3158
+	 * @param bool $trash
3159
+	 * @return array
3160
+	 * @throws EE_Error
3161
+	 * @throws InvalidArgumentException
3162
+	 * @throws InvalidDataTypeException
3163
+	 * @throws InvalidInterfaceException
3164
+	 * @access public
3165
+	 */
3166
+	public function get_attendees($per_page, $count = false, $trash = false)
3167
+	{
3168
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3169
+		require_once(REG_ADMIN . 'EE_Attendee_Contact_List_Table.class.php');
3170
+		$this->_req_data['orderby'] = ! empty($this->_req_data['orderby']) ? $this->_req_data['orderby'] : '';
3171
+		switch ($this->_req_data['orderby']) {
3172
+			case 'ATT_ID':
3173
+				$orderby = 'ATT_ID';
3174
+				break;
3175
+			case 'ATT_fname':
3176
+				$orderby = 'ATT_fname';
3177
+				break;
3178
+			case 'ATT_email':
3179
+				$orderby = 'ATT_email';
3180
+				break;
3181
+			case 'ATT_city':
3182
+				$orderby = 'ATT_city';
3183
+				break;
3184
+			case 'STA_ID':
3185
+				$orderby = 'STA_ID';
3186
+				break;
3187
+			case 'CNT_ID':
3188
+				$orderby = 'CNT_ID';
3189
+				break;
3190
+			case 'Registration_Count':
3191
+				$orderby = 'Registration_Count';
3192
+				break;
3193
+			default:
3194
+				$orderby = 'ATT_lname';
3195
+		}
3196
+		$sort = (isset($this->_req_data['order']) && ! empty($this->_req_data['order']))
3197
+			? $this->_req_data['order']
3198
+			: 'ASC';
3199
+		$current_page = isset($this->_req_data['paged']) && ! empty($this->_req_data['paged'])
3200
+			? $this->_req_data['paged']
3201
+			: 1;
3202
+		$per_page = isset($per_page) && ! empty($per_page) ? $per_page : 10;
3203
+		$per_page = isset($this->_req_data['perpage']) && ! empty($this->_req_data['perpage'])
3204
+			? $this->_req_data['perpage']
3205
+			: $per_page;
3206
+		$_where = array();
3207
+		if (! empty($this->_req_data['s'])) {
3208
+			$sstr = '%' . $this->_req_data['s'] . '%';
3209
+			$_where['OR'] = array(
3210
+				'Registration.Event.EVT_name'       => array('LIKE', $sstr),
3211
+				'Registration.Event.EVT_desc'       => array('LIKE', $sstr),
3212
+				'Registration.Event.EVT_short_desc' => array('LIKE', $sstr),
3213
+				'ATT_fname'                         => array('LIKE', $sstr),
3214
+				'ATT_lname'                         => array('LIKE', $sstr),
3215
+				'ATT_short_bio'                     => array('LIKE', $sstr),
3216
+				'ATT_email'                         => array('LIKE', $sstr),
3217
+				'ATT_address'                       => array('LIKE', $sstr),
3218
+				'ATT_address2'                      => array('LIKE', $sstr),
3219
+				'ATT_city'                          => array('LIKE', $sstr),
3220
+				'Country.CNT_name'                  => array('LIKE', $sstr),
3221
+				'State.STA_name'                    => array('LIKE', $sstr),
3222
+				'ATT_phone'                         => array('LIKE', $sstr),
3223
+				'Registration.REG_final_price'      => array('LIKE', $sstr),
3224
+				'Registration.REG_code'             => array('LIKE', $sstr),
3225
+				'Registration.REG_group_size'       => array('LIKE', $sstr),
3226
+			);
3227
+		}
3228
+		$offset = ($current_page - 1) * $per_page;
3229
+		$limit = $count ? null : array($offset, $per_page);
3230
+		$query_args = array(
3231
+			$_where,
3232
+			'extra_selects' => array('Registration_Count' => array('Registration.REG_ID', 'count', '%d')),
3233
+			'limit'         => $limit,
3234
+		);
3235
+		if (! $count) {
3236
+			$query_args['order_by'] = array($orderby => $sort);
3237
+		}
3238
+		if ($trash) {
3239
+			$query_args[0]['status'] = array('!=', 'publish');
3240
+			$all_attendees = $count
3241
+				? $this->getAttendeeModel()->count($query_args, 'ATT_ID', true)
3242
+				: $this->getAttendeeModel()->get_all($query_args);
3243
+		} else {
3244
+			$query_args[0]['status'] = array('IN', array('publish'));
3245
+			$all_attendees = $count
3246
+				? $this->getAttendeeModel()->count($query_args, 'ATT_ID', true)
3247
+				: $this->getAttendeeModel()->get_all($query_args);
3248
+		}
3249
+		return $all_attendees;
3250
+	}
3251
+
3252
+
3253
+	/**
3254
+	 * This is just taking care of resending the registration confirmation
3255
+	 *
3256
+	 * @access protected
3257
+	 * @return void
3258
+	 * @throws EE_Error
3259
+	 * @throws InvalidArgumentException
3260
+	 * @throws InvalidDataTypeException
3261
+	 * @throws InvalidInterfaceException
3262
+	 * @throws ReflectionException
3263
+	 */
3264
+	protected function _resend_registration()
3265
+	{
3266
+		$this->_process_resend_registration();
3267
+		$query_args = isset($this->_req_data['redirect_to'])
3268
+			? array('action' => $this->_req_data['redirect_to'], '_REG_ID' => $this->_req_data['_REG_ID'])
3269
+			: array('action' => 'default');
3270
+		$this->_redirect_after_action(false, '', '', $query_args, true);
3271
+	}
3272
+
3273
+	/**
3274
+	 * Creates a registration report, but accepts the name of a method to use for preparing the query parameters
3275
+	 * to use when selecting registrations
3276
+	 *
3277
+	 * @param string $method_name_for_getting_query_params the name of the method (on this class) to use for preparing
3278
+	 *                                                     the query parameters from the request
3279
+	 * @return void ends the request with a redirect or download
3280
+	 */
3281
+	public function _registrations_report_base($method_name_for_getting_query_params)
3282
+	{
3283
+		if (! defined('EE_USE_OLD_CSV_REPORT_CLASS')) {
3284
+			wp_redirect(
3285
+				EE_Admin_Page::add_query_args_and_nonce(
3286
+					array(
3287
+						'page'        => 'espresso_batch',
3288
+						'batch'       => 'file',
3289
+						'EVT_ID'      => isset($this->_req_data['EVT_ID']) ? $this->_req_data['EVT_ID'] : null,
3290
+						'filters'     => urlencode(
3291
+							serialize(
3292
+								$this->$method_name_for_getting_query_params(
3293
+									EEH_Array::is_set(
3294
+										$this->_req_data,
3295
+										'filters',
3296
+										array()
3297
+									)
3298
+								)
3299
+							)
3300
+						),
3301
+						'use_filters' => EEH_Array::is_set($this->_req_data, 'use_filters', false),
3302
+						'job_handler' => urlencode('EventEspressoBatchRequest\JobHandlers\RegistrationsReport'),
3303
+						'return_url'  => urlencode($this->_req_data['return_url']),
3304
+					)
3305
+				)
3306
+			);
3307
+		} else {
3308
+			$new_request_args = array(
3309
+				'export' => 'report',
3310
+				'action' => 'registrations_report_for_event',
3311
+				'EVT_ID' => isset($this->_req_data['EVT_ID']) ? $this->_req_data['EVT_ID'] : null,
3312
+			);
3313
+			$this->_req_data = array_merge($this->_req_data, $new_request_args);
3314
+			if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
3315
+				require_once(EE_CLASSES . 'EE_Export.class.php');
3316
+				$EE_Export = EE_Export::instance($this->_req_data);
3317
+				$EE_Export->export();
3318
+			}
3319
+		}
3320
+	}
3321
+
3322
+
3323
+	/**
3324
+	 * Creates a registration report using only query parameters in the request
3325
+	 *
3326
+	 * @return void
3327
+	 */
3328
+	public function _registrations_report()
3329
+	{
3330
+		$this->_registrations_report_base('_get_registration_query_parameters');
3331
+	}
3332
+
3333
+
3334
+	public function _contact_list_export()
3335
+	{
3336
+		if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
3337
+			require_once(EE_CLASSES . 'EE_Export.class.php');
3338
+			$EE_Export = EE_Export::instance($this->_req_data);
3339
+			$EE_Export->export_attendees();
3340
+		}
3341
+	}
3342
+
3343
+
3344
+	public function _contact_list_report()
3345
+	{
3346
+		if (! defined('EE_USE_OLD_CSV_REPORT_CLASS')) {
3347
+			wp_redirect(
3348
+				EE_Admin_Page::add_query_args_and_nonce(
3349
+					array(
3350
+						'page'        => 'espresso_batch',
3351
+						'batch'       => 'file',
3352
+						'job_handler' => urlencode('EventEspressoBatchRequest\JobHandlers\AttendeesReport'),
3353
+						'return_url'  => urlencode($this->_req_data['return_url']),
3354
+					)
3355
+				)
3356
+			);
3357
+		} else {
3358
+			if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
3359
+				require_once(EE_CLASSES . 'EE_Export.class.php');
3360
+				$EE_Export = EE_Export::instance($this->_req_data);
3361
+				$EE_Export->report_attendees();
3362
+			}
3363
+		}
3364
+	}
3365
+
3366
+
3367
+
3368
+
3369
+
3370
+	/***************************************        ATTENDEE DETAILS        ***************************************/
3371
+	/**
3372
+	 * This duplicates the attendee object for the given incoming registration id and attendee_id.
3373
+	 *
3374
+	 * @return void
3375
+	 * @throws EE_Error
3376
+	 * @throws InvalidArgumentException
3377
+	 * @throws InvalidDataTypeException
3378
+	 * @throws InvalidInterfaceException
3379
+	 * @throws ReflectionException
3380
+	 */
3381
+	protected function _duplicate_attendee()
3382
+	{
3383
+		$action = ! empty($this->_req_data['return']) ? $this->_req_data['return'] : 'default';
3384
+		// verify we have necessary info
3385
+		if (empty($this->_req_data['_REG_ID'])) {
3386
+			EE_Error::add_error(
3387
+				esc_html__(
3388
+					'Unable to create the contact for the registration because the required parameters are not present (_REG_ID )',
3389
+					'event_espresso'
3390
+				),
3391
+				__FILE__,
3392
+				__LINE__,
3393
+				__FUNCTION__
3394
+			);
3395
+			$query_args = array('action' => $action);
3396
+			$this->_redirect_after_action('', '', '', $query_args, true);
3397
+		}
3398
+		// okay necessary deets present... let's dupe the incoming attendee and attach to incoming registration.
3399
+		$registration = $this->getRegistrationModel()->get_one_by_ID($this->_req_data['_REG_ID']);
3400
+		$attendee = $registration->attendee();
3401
+		// remove relation of existing attendee on registration
3402
+		$registration->_remove_relation_to($attendee, 'Attendee');
3403
+		// new attendee
3404
+		$new_attendee = clone $attendee;
3405
+		$new_attendee->set('ATT_ID', 0);
3406
+		$new_attendee->save();
3407
+		// add new attendee to reg
3408
+		$registration->_add_relation_to($new_attendee, 'Attendee');
3409
+		EE_Error::add_success(
3410
+			esc_html__(
3411
+				'New Contact record created.  Now make any edits you wish to make for this contact.',
3412
+				'event_espresso'
3413
+			)
3414
+		);
3415
+		// redirect to edit page for attendee
3416
+		$query_args = array('post' => $new_attendee->ID(), 'action' => 'edit_attendee');
3417
+		$this->_redirect_after_action('', '', '', $query_args, true);
3418
+	}
3419
+
3420
+
3421
+	/**
3422
+	 * Callback invoked by parent EE_Admin_CPT class hooked in on `save_post` wp hook.
3423
+	 *
3424
+	 * @param int     $post_id
3425
+	 * @param WP_POST $post
3426
+	 * @throws DomainException
3427
+	 * @throws EE_Error
3428
+	 * @throws InvalidArgumentException
3429
+	 * @throws InvalidDataTypeException
3430
+	 * @throws InvalidInterfaceException
3431
+	 * @throws LogicException
3432
+	 * @throws InvalidFormSubmissionException
3433
+	 * @throws ReflectionException
3434
+	 */
3435
+	protected function _insert_update_cpt_item($post_id, $post)
3436
+	{
3437
+		$success = true;
3438
+		$attendee = $post instanceof WP_Post && $post->post_type === 'espresso_attendees'
3439
+			? $this->getAttendeeModel()->get_one_by_ID($post_id)
3440
+			: null;
3441
+		// for attendee updates
3442
+		if ($attendee instanceof EE_Attendee) {
3443
+			// note we should only be UPDATING attendees at this point.
3444
+			$updated_fields = array(
3445
+				'ATT_fname'     => $this->_req_data['ATT_fname'],
3446
+				'ATT_lname'     => $this->_req_data['ATT_lname'],
3447
+				'ATT_full_name' => $this->_req_data['ATT_fname'] . ' ' . $this->_req_data['ATT_lname'],
3448
+				'ATT_address'   => isset($this->_req_data['ATT_address']) ? $this->_req_data['ATT_address'] : '',
3449
+				'ATT_address2'  => isset($this->_req_data['ATT_address2']) ? $this->_req_data['ATT_address2'] : '',
3450
+				'ATT_city'      => isset($this->_req_data['ATT_city']) ? $this->_req_data['ATT_city'] : '',
3451
+				'STA_ID'        => isset($this->_req_data['STA_ID']) ? $this->_req_data['STA_ID'] : '',
3452
+				'CNT_ISO'       => isset($this->_req_data['CNT_ISO']) ? $this->_req_data['CNT_ISO'] : '',
3453
+				'ATT_zip'       => isset($this->_req_data['ATT_zip']) ? $this->_req_data['ATT_zip'] : '',
3454
+			);
3455
+			foreach ($updated_fields as $field => $value) {
3456
+				$attendee->set($field, $value);
3457
+			}
3458
+
3459
+			// process contact details metabox form handler (which will also save the attendee)
3460
+			$contact_details_form = $this->getAttendeeContactDetailsMetaboxFormHandler($attendee);
3461
+			$success = $contact_details_form->process($this->_req_data);
3462
+
3463
+			$attendee_update_callbacks = apply_filters(
3464
+				'FHEE__Registrations_Admin_Page__insert_update_cpt_item__attendee_update',
3465
+				array()
3466
+			);
3467
+			foreach ($attendee_update_callbacks as $a_callback) {
3468
+				if (false === call_user_func_array($a_callback, array($attendee, $this->_req_data))) {
3469
+					throw new EE_Error(
3470
+						sprintf(
3471
+							esc_html__(
3472
+								'The %s callback given for the "FHEE__Registrations_Admin_Page__insert_update_cpt_item__attendee_update" filter is not a valid callback.  Please check the spelling.',
3473
+								'event_espresso'
3474
+							),
3475
+							$a_callback
3476
+						)
3477
+					);
3478
+				}
3479
+			}
3480
+		}
3481
+
3482
+		if ($success === false) {
3483
+			EE_Error::add_error(
3484
+				esc_html__(
3485
+					'Something went wrong with updating the meta table data for the registration.',
3486
+					'event_espresso'
3487
+				),
3488
+				__FILE__,
3489
+				__FUNCTION__,
3490
+				__LINE__
3491
+			);
3492
+		}
3493
+	}
3494
+
3495
+
3496
+	public function trash_cpt_item($post_id)
3497
+	{
3498
+	}
3499
+
3500
+
3501
+	public function delete_cpt_item($post_id)
3502
+	{
3503
+	}
3504
+
3505
+
3506
+	public function restore_cpt_item($post_id)
3507
+	{
3508
+	}
3509
+
3510
+
3511
+	protected function _restore_cpt_item($post_id, $revision_id)
3512
+	{
3513
+	}
3514
+
3515
+
3516
+	/**
3517
+	 * @throws EE_Error
3518
+	 * @since 4.10.2.p
3519
+	 */
3520
+	public function attendee_editor_metaboxes()
3521
+	{
3522
+		$this->verify_cpt_object();
3523
+		remove_meta_box(
3524
+			'postexcerpt',
3525
+			$this->_cpt_routes[ $this->_req_action ],
3526
+			'normal'
3527
+		);
3528
+		remove_meta_box('commentstatusdiv', $this->_cpt_routes[ $this->_req_action ], 'normal', 'core');
3529
+		if (post_type_supports('espresso_attendees', 'excerpt')) {
3530
+			add_meta_box(
3531
+				'postexcerpt',
3532
+				esc_html__('Short Biography', 'event_espresso'),
3533
+				'post_excerpt_meta_box',
3534
+				$this->_cpt_routes[ $this->_req_action ],
3535
+				'normal'
3536
+			);
3537
+		}
3538
+		if (post_type_supports('espresso_attendees', 'comments')) {
3539
+			add_meta_box(
3540
+				'commentsdiv',
3541
+				esc_html__('Notes on the Contact', 'event_espresso'),
3542
+				'post_comment_meta_box',
3543
+				$this->_cpt_routes[ $this->_req_action ],
3544
+				'normal',
3545
+				'core'
3546
+			);
3547
+		}
3548
+		add_meta_box(
3549
+			'attendee_contact_info',
3550
+			esc_html__('Contact Info', 'event_espresso'),
3551
+			array($this, 'attendee_contact_info'),
3552
+			$this->_cpt_routes[ $this->_req_action ],
3553
+			'side',
3554
+			'core'
3555
+		);
3556
+		add_meta_box(
3557
+			'attendee_details_address',
3558
+			esc_html__('Address Details', 'event_espresso'),
3559
+			array($this, 'attendee_address_details'),
3560
+			$this->_cpt_routes[ $this->_req_action ],
3561
+			'normal',
3562
+			'core'
3563
+		);
3564
+		add_meta_box(
3565
+			'attendee_registrations',
3566
+			esc_html__('Registrations for this Contact', 'event_espresso'),
3567
+			array($this, 'attendee_registrations_meta_box'),
3568
+			$this->_cpt_routes[ $this->_req_action ],
3569
+			'normal',
3570
+			'high'
3571
+		);
3572
+	}
3573
+
3574
+
3575
+	/**
3576
+	 * Metabox for attendee contact info
3577
+	 *
3578
+	 * @param  WP_Post $post wp post object
3579
+	 * @return string attendee contact info ( and form )
3580
+	 * @throws EE_Error
3581
+	 * @throws InvalidArgumentException
3582
+	 * @throws InvalidDataTypeException
3583
+	 * @throws InvalidInterfaceException
3584
+	 * @throws LogicException
3585
+	 * @throws DomainException
3586
+	 */
3587
+	public function attendee_contact_info($post)
3588
+	{
3589
+		// get attendee object ( should already have it )
3590
+		$form = $this->getAttendeeContactDetailsMetaboxFormHandler($this->_cpt_model_obj);
3591
+		$form->enqueueStylesAndScripts();
3592
+		echo $form->display();
3593
+	}
3594
+
3595
+
3596
+	/**
3597
+	 * Return form handler for the contact details metabox
3598
+	 *
3599
+	 * @param EE_Attendee $attendee
3600
+	 * @return AttendeeContactDetailsMetaboxFormHandler
3601
+	 * @throws DomainException
3602
+	 * @throws InvalidArgumentException
3603
+	 * @throws InvalidDataTypeException
3604
+	 * @throws InvalidInterfaceException
3605
+	 */
3606
+	protected function getAttendeeContactDetailsMetaboxFormHandler(EE_Attendee $attendee)
3607
+	{
3608
+		return new AttendeeContactDetailsMetaboxFormHandler($attendee, EE_Registry::instance());
3609
+	}
3610
+
3611
+
3612
+	/**
3613
+	 * Metabox for attendee details
3614
+	 *
3615
+	 * @param  WP_Post $post wp post object
3616
+	 * @throws DomainException
3617
+	 */
3618
+	public function attendee_address_details($post)
3619
+	{
3620
+		// get attendee object (should already have it)
3621
+		$this->_template_args['attendee'] = $this->_cpt_model_obj;
3622
+		$this->_template_args['state_html'] = EEH_Form_Fields::generate_form_input(
3623
+			new EE_Question_Form_Input(
3624
+				EE_Question::new_instance(
3625
+					array(
3626
+						'QST_ID'           => 0,
3627
+						'QST_display_text' => esc_html__('State/Province', 'event_espresso'),
3628
+						'QST_system'       => 'admin-state',
3629
+					)
3630
+				),
3631
+				EE_Answer::new_instance(
3632
+					array(
3633
+						'ANS_ID'    => 0,
3634
+						'ANS_value' => $this->_cpt_model_obj->state_ID(),
3635
+					)
3636
+				),
3637
+				array(
3638
+					'input_id'       => 'STA_ID',
3639
+					'input_name'     => 'STA_ID',
3640
+					'input_prefix'   => '',
3641
+					'append_qstn_id' => false,
3642
+				)
3643
+			)
3644
+		);
3645
+		$this->_template_args['country_html'] = EEH_Form_Fields::generate_form_input(
3646
+			new EE_Question_Form_Input(
3647
+				EE_Question::new_instance(
3648
+					array(
3649
+						'QST_ID'           => 0,
3650
+						'QST_display_text' => esc_html__('Country', 'event_espresso'),
3651
+						'QST_system'       => 'admin-country',
3652
+					)
3653
+				),
3654
+				EE_Answer::new_instance(
3655
+					array(
3656
+						'ANS_ID'    => 0,
3657
+						'ANS_value' => $this->_cpt_model_obj->country_ID(),
3658
+					)
3659
+				),
3660
+				array(
3661
+					'input_id'       => 'CNT_ISO',
3662
+					'input_name'     => 'CNT_ISO',
3663
+					'input_prefix'   => '',
3664
+					'append_qstn_id' => false,
3665
+				)
3666
+			)
3667
+		);
3668
+		$template =
3669
+			REG_TEMPLATE_PATH . 'attendee_address_details_metabox_content.template.php';
3670
+		EEH_Template::display_template($template, $this->_template_args);
3671
+	}
3672
+
3673
+
3674
+	/**
3675
+	 *        _attendee_details
3676
+	 *
3677
+	 * @access protected
3678
+	 * @param $post
3679
+	 * @return void
3680
+	 * @throws DomainException
3681
+	 * @throws EE_Error
3682
+	 * @throws InvalidArgumentException
3683
+	 * @throws InvalidDataTypeException
3684
+	 * @throws InvalidInterfaceException
3685
+	 * @throws ReflectionException
3686
+	 */
3687
+	public function attendee_registrations_meta_box($post)
3688
+	{
3689
+		$this->_template_args['attendee'] = $this->_cpt_model_obj;
3690
+		$this->_template_args['registrations'] = $this->_cpt_model_obj->get_many_related('Registration');
3691
+		$template =
3692
+			REG_TEMPLATE_PATH . 'attendee_registrations_main_meta_box.template.php';
3693
+		EEH_Template::display_template($template, $this->_template_args);
3694
+	}
3695
+
3696
+
3697
+	/**
3698
+	 * add in the form fields for the attendee edit
3699
+	 *
3700
+	 * @param  WP_Post $post wp post object
3701
+	 * @return string html for new form.
3702
+	 * @throws DomainException
3703
+	 */
3704
+	public function after_title_form_fields($post)
3705
+	{
3706
+		if ($post->post_type === 'espresso_attendees') {
3707
+			$template = REG_TEMPLATE_PATH . 'attendee_details_after_title_form_fields.template.php';
3708
+			$template_args['attendee'] = $this->_cpt_model_obj;
3709
+			EEH_Template::display_template($template, $template_args);
3710
+		}
3711
+	}
3712
+
3713
+
3714
+	/**
3715
+	 *        _trash_or_restore_attendee
3716
+	 *
3717
+	 * @param boolean $trash - whether to move item to trash (TRUE) or restore it (FALSE)
3718
+	 * @return void
3719
+	 * @throws EE_Error
3720
+	 * @throws InvalidArgumentException
3721
+	 * @throws InvalidDataTypeException
3722
+	 * @throws InvalidInterfaceException
3723
+	 * @throws ReflectionException
3724
+	 * @access protected
3725
+	 */
3726
+	protected function _trash_or_restore_attendees($trash = true)
3727
+	{
3728
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3729
+		$success = 1;
3730
+		// Checkboxes
3731
+		if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
3732
+			// if array has more than one element than success message should be plural
3733
+			$success = count($this->_req_data['checkbox']) > 1 ? 2 : 1;
3734
+			// cycle thru checkboxes
3735
+			foreach ($this->_req_data['checkbox'] as $ATT_ID) {
3736
+				$updated = $trash ? $this->getAttendeeModel()->update_by_ID(array('status' => 'trash'), $ATT_ID)
3737
+					: $this->getAttendeeModel()->update_by_ID(array('status' => 'publish'), $ATT_ID);
3738
+				if (! $updated) {
3739
+					$success = 0;
3740
+				}
3741
+			}
3742
+		} else {
3743
+			// grab single id and delete
3744
+			$ATT_ID = absint($this->_req_data['ATT_ID']);
3745
+			// get attendee
3746
+			$att = $this->getAttendeeModel()->get_one_by_ID($ATT_ID);
3747
+			$updated = $trash ? $att->set_status('trash') : $att->set_status('publish');
3748
+			$updated = $att->save() && $updated;
3749
+			if (! $updated) {
3750
+				$success = 0;
3751
+			}
3752
+		}
3753
+		$what = $success > 1
3754
+			? esc_html__('Contacts', 'event_espresso')
3755
+			: esc_html__('Contact', 'event_espresso');
3756
+		$action_desc = $trash
3757
+			? esc_html__('moved to the trash', 'event_espresso')
3758
+			: esc_html__('restored', 'event_espresso');
3759
+		$this->_redirect_after_action($success, $what, $action_desc, array('action' => 'contact_list'));
3760
+	}
3761 3761
 }
Please login to merge, or discard this patch.
core/domain/entities/routing/handlers/admin/EspressoLegacyAdmin.php 1 patch
Indentation   +111 added lines, -111 removed lines patch added patch discarded remove patch
@@ -18,121 +18,121 @@
 block discarded – undo
18 18
 class EspressoLegacyAdmin extends AdminRoute
19 19
 {
20 20
 
21
-    /**
22
-     * @var LegacyAccountingAssetManager $asset_manager
23
-     */
24
-    protected $asset_manager;
21
+	/**
22
+	 * @var LegacyAccountingAssetManager $asset_manager
23
+	 */
24
+	protected $asset_manager;
25 25
 
26 26
 
27
-    /**
28
-     * returns true if the current request matches this route
29
-     *
30
-     * @return bool
31
-     * @since   $VID:$
32
-     */
33
-    public function matchesCurrentRequest()
34
-    {
35
-        global $pagenow;
36
-        return $this->request->isAdminAjax() || (
37
-            parent::matchesCurrentRequest() && $pagenow && $pagenow === 'admin.php'
38
-        );
39
-    }
27
+	/**
28
+	 * returns true if the current request matches this route
29
+	 *
30
+	 * @return bool
31
+	 * @since   $VID:$
32
+	 */
33
+	public function matchesCurrentRequest()
34
+	{
35
+		global $pagenow;
36
+		return $this->request->isAdminAjax() || (
37
+			parent::matchesCurrentRequest() && $pagenow && $pagenow === 'admin.php'
38
+		);
39
+	}
40 40
 
41 41
 
42
-    /**
43
-     * @since $VID:$
44
-     */
45
-    protected function registerDependencies()
46
-    {
47
-        $asset_manger_dependencies = [
48
-            'EventEspresso\core\domain\Domain'                   => EE_Dependency_Map::load_from_cache,
49
-            'EventEspresso\core\services\assets\AssetCollection' => EE_Dependency_Map::load_from_cache,
50
-            'EventEspresso\core\services\assets\Registry'        => EE_Dependency_Map::load_from_cache,
51
-        ];
52
-        $this->dependency_map->registerDependencies(JqueryAssetManager::class, $asset_manger_dependencies);
53
-        $this->dependency_map->registerDependencies(EspressoLegacyAdminAssetManager::class, $asset_manger_dependencies);
54
-        $this->dependency_map->registerDependencies(
55
-            LegacyAccountingAssetManager::class,
56
-            ['EE_Currency_Config' => EE_Dependency_Map::load_from_cache] + $asset_manger_dependencies
57
-        );
58
-        $this->dependency_map->registerDependencies(
59
-            'EE_Admin_Transactions_List_Table',
60
-            [
61
-                null,
62
-                'EventEspresso\core\domain\values\session\SessionLifespan' => EE_Dependency_Map::load_from_cache,
63
-            ]
64
-        );
65
-        $this->dependency_map->registerDependencies(
66
-            'EventEspresso\caffeinated\modules\recaptcha_invisible\RecaptchaAdminSettings',
67
-            ['EE_Registration_Config' => EE_Dependency_Map::load_from_cache]
68
-        );
69
-        $this->dependency_map->registerDependencies(
70
-            'EventEspresso\admin_pages\general_settings\OrganizationSettings',
71
-            [
72
-                'EE_Registry'                                             => EE_Dependency_Map::load_from_cache,
73
-                'EE_Organization_Config'                                  => EE_Dependency_Map::load_from_cache,
74
-                'EE_Core_Config'                                          => EE_Dependency_Map::load_from_cache,
75
-                'EE_Network_Core_Config'                                  => EE_Dependency_Map::load_from_cache,
76
-                'EventEspresso\core\services\address\CountrySubRegionDao' => EE_Dependency_Map::load_from_cache,
77
-            ]
78
-        );
79
-        $this->dependency_map->registerDependencies(
80
-            'EventEspresso\core\services\address\CountrySubRegionDao',
81
-            [
82
-                'EEM_State'                                            => EE_Dependency_Map::load_from_cache,
83
-                'EventEspresso\core\services\validators\JsonValidator' => EE_Dependency_Map::load_from_cache
84
-            ]
85
-        );
86
-        $this->dependency_map->registerDependencies(
87
-            'EventEspresso\core\domain\services\admin\registrations\list_table\QueryBuilder',
88
-            [
89
-                null,
90
-                'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache,
91
-                'EEM_Registration'                            => EE_Dependency_Map::load_from_cache,
92
-            ]
93
-        );
94
-        $this->dependency_map->registerDependencies(
95
-            'EventEspresso\core\domain\services\admin\registrations\list_table\page_header\AttendeeFilterHeader',
96
-            [
97
-                'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache,
98
-                'EEM_Attendee'                                => EE_Dependency_Map::load_from_cache,
99
-            ]
100
-        );
101
-        $this->dependency_map->registerDependencies(
102
-            'EventEspresso\core\domain\services\admin\registrations\list_table\page_header\DateFilterHeader',
103
-            [
104
-                'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache,
105
-                'EEM_Datetime'                                => EE_Dependency_Map::load_from_cache,
106
-            ]
107
-        );
108
-        $this->dependency_map->registerDependencies(
109
-            'EventEspresso\core\domain\services\admin\registrations\list_table\page_header\EventFilterHeader',
110
-            [
111
-                'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache,
112
-                'EEM_Event'                                   => EE_Dependency_Map::load_from_cache,
113
-            ]
114
-        );
115
-        $this->dependency_map->registerDependencies(
116
-            'EventEspresso\core\domain\services\admin\registrations\list_table\page_header\TicketFilterHeader',
117
-            [
118
-                'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache,
119
-                'EEM_Ticket'                                  => EE_Dependency_Map::load_from_cache,
120
-            ]
121
-        );
122
-    }
42
+	/**
43
+	 * @since $VID:$
44
+	 */
45
+	protected function registerDependencies()
46
+	{
47
+		$asset_manger_dependencies = [
48
+			'EventEspresso\core\domain\Domain'                   => EE_Dependency_Map::load_from_cache,
49
+			'EventEspresso\core\services\assets\AssetCollection' => EE_Dependency_Map::load_from_cache,
50
+			'EventEspresso\core\services\assets\Registry'        => EE_Dependency_Map::load_from_cache,
51
+		];
52
+		$this->dependency_map->registerDependencies(JqueryAssetManager::class, $asset_manger_dependencies);
53
+		$this->dependency_map->registerDependencies(EspressoLegacyAdminAssetManager::class, $asset_manger_dependencies);
54
+		$this->dependency_map->registerDependencies(
55
+			LegacyAccountingAssetManager::class,
56
+			['EE_Currency_Config' => EE_Dependency_Map::load_from_cache] + $asset_manger_dependencies
57
+		);
58
+		$this->dependency_map->registerDependencies(
59
+			'EE_Admin_Transactions_List_Table',
60
+			[
61
+				null,
62
+				'EventEspresso\core\domain\values\session\SessionLifespan' => EE_Dependency_Map::load_from_cache,
63
+			]
64
+		);
65
+		$this->dependency_map->registerDependencies(
66
+			'EventEspresso\caffeinated\modules\recaptcha_invisible\RecaptchaAdminSettings',
67
+			['EE_Registration_Config' => EE_Dependency_Map::load_from_cache]
68
+		);
69
+		$this->dependency_map->registerDependencies(
70
+			'EventEspresso\admin_pages\general_settings\OrganizationSettings',
71
+			[
72
+				'EE_Registry'                                             => EE_Dependency_Map::load_from_cache,
73
+				'EE_Organization_Config'                                  => EE_Dependency_Map::load_from_cache,
74
+				'EE_Core_Config'                                          => EE_Dependency_Map::load_from_cache,
75
+				'EE_Network_Core_Config'                                  => EE_Dependency_Map::load_from_cache,
76
+				'EventEspresso\core\services\address\CountrySubRegionDao' => EE_Dependency_Map::load_from_cache,
77
+			]
78
+		);
79
+		$this->dependency_map->registerDependencies(
80
+			'EventEspresso\core\services\address\CountrySubRegionDao',
81
+			[
82
+				'EEM_State'                                            => EE_Dependency_Map::load_from_cache,
83
+				'EventEspresso\core\services\validators\JsonValidator' => EE_Dependency_Map::load_from_cache
84
+			]
85
+		);
86
+		$this->dependency_map->registerDependencies(
87
+			'EventEspresso\core\domain\services\admin\registrations\list_table\QueryBuilder',
88
+			[
89
+				null,
90
+				'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache,
91
+				'EEM_Registration'                            => EE_Dependency_Map::load_from_cache,
92
+			]
93
+		);
94
+		$this->dependency_map->registerDependencies(
95
+			'EventEspresso\core\domain\services\admin\registrations\list_table\page_header\AttendeeFilterHeader',
96
+			[
97
+				'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache,
98
+				'EEM_Attendee'                                => EE_Dependency_Map::load_from_cache,
99
+			]
100
+		);
101
+		$this->dependency_map->registerDependencies(
102
+			'EventEspresso\core\domain\services\admin\registrations\list_table\page_header\DateFilterHeader',
103
+			[
104
+				'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache,
105
+				'EEM_Datetime'                                => EE_Dependency_Map::load_from_cache,
106
+			]
107
+		);
108
+		$this->dependency_map->registerDependencies(
109
+			'EventEspresso\core\domain\services\admin\registrations\list_table\page_header\EventFilterHeader',
110
+			[
111
+				'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache,
112
+				'EEM_Event'                                   => EE_Dependency_Map::load_from_cache,
113
+			]
114
+		);
115
+		$this->dependency_map->registerDependencies(
116
+			'EventEspresso\core\domain\services\admin\registrations\list_table\page_header\TicketFilterHeader',
117
+			[
118
+				'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache,
119
+				'EEM_Ticket'                                  => EE_Dependency_Map::load_from_cache,
120
+			]
121
+		);
122
+	}
123 123
 
124 124
 
125
-    /**
126
-     * implements logic required to run during request
127
-     *
128
-     * @return bool
129
-     * @since   $VID:$
130
-     */
131
-    protected function requestHandler()
132
-    {
133
-        $this->loader->getShared(JqueryAssetManager::class);
134
-        $this->loader->getShared(EspressoLegacyAdminAssetManager::class);
135
-        $this->loader->getShared(LegacyAccountingAssetManager::class);
136
-        return true;
137
-    }
125
+	/**
126
+	 * implements logic required to run during request
127
+	 *
128
+	 * @return bool
129
+	 * @since   $VID:$
130
+	 */
131
+	protected function requestHandler()
132
+	{
133
+		$this->loader->getShared(JqueryAssetManager::class);
134
+		$this->loader->getShared(EspressoLegacyAdminAssetManager::class);
135
+		$this->loader->getShared(LegacyAccountingAssetManager::class);
136
+		return true;
137
+	}
138 138
 }
Please login to merge, or discard this patch.