Completed
Branch BUG/11268/session-ticket-relea... (393c4a)
by
unknown
40:56 queued 25:34
created
core/domain/entities/custom_post_types/CustomTaxonomyTerm.php 1 patch
Indentation   +56 added lines, -56 removed lines patch added patch discarded remove patch
@@ -17,60 +17,60 @@
 block discarded – undo
17 17
 class CustomTaxonomyTerm
18 18
 {
19 19
 
20
-    /**
21
-     * @var string $taxonomy_slug
22
-     */
23
-    public $taxonomy_slug;
24
-
25
-    /**
26
-     * @var string $term_slug
27
-     */
28
-    public $term_slug;
29
-
30
-    /**
31
-     * @var array $custom_post_type_slugs
32
-     */
33
-    public $custom_post_type_slugs;
34
-
35
-
36
-    /**
37
-     * CustomTaxonomyTerm constructor.
38
-     *
39
-     * @param string $taxonomy_slug
40
-     * @param string $term_slug
41
-     * @param array  $custom_post_type_slugs
42
-     */
43
-    public function __construct($taxonomy_slug, $term_slug, array $custom_post_type_slugs = array())
44
-    {
45
-        $this->taxonomy_slug          = $taxonomy_slug;
46
-        $this->term_slug              = $term_slug;
47
-        $this->custom_post_type_slugs = $custom_post_type_slugs;
48
-    }
49
-
50
-
51
-    /**
52
-     * @return string
53
-     */
54
-    public function taxonomySlug()
55
-    {
56
-        return $this->taxonomy_slug;
57
-    }
58
-
59
-
60
-    /**
61
-     * @return string
62
-     */
63
-    public function termSlug()
64
-    {
65
-        return $this->term_slug;
66
-    }
67
-
68
-
69
-    /**
70
-     * @return array
71
-     */
72
-    public function customPostTypeSlugs()
73
-    {
74
-        return $this->custom_post_type_slugs;
75
-    }
20
+	/**
21
+	 * @var string $taxonomy_slug
22
+	 */
23
+	public $taxonomy_slug;
24
+
25
+	/**
26
+	 * @var string $term_slug
27
+	 */
28
+	public $term_slug;
29
+
30
+	/**
31
+	 * @var array $custom_post_type_slugs
32
+	 */
33
+	public $custom_post_type_slugs;
34
+
35
+
36
+	/**
37
+	 * CustomTaxonomyTerm constructor.
38
+	 *
39
+	 * @param string $taxonomy_slug
40
+	 * @param string $term_slug
41
+	 * @param array  $custom_post_type_slugs
42
+	 */
43
+	public function __construct($taxonomy_slug, $term_slug, array $custom_post_type_slugs = array())
44
+	{
45
+		$this->taxonomy_slug          = $taxonomy_slug;
46
+		$this->term_slug              = $term_slug;
47
+		$this->custom_post_type_slugs = $custom_post_type_slugs;
48
+	}
49
+
50
+
51
+	/**
52
+	 * @return string
53
+	 */
54
+	public function taxonomySlug()
55
+	{
56
+		return $this->taxonomy_slug;
57
+	}
58
+
59
+
60
+	/**
61
+	 * @return string
62
+	 */
63
+	public function termSlug()
64
+	{
65
+		return $this->term_slug;
66
+	}
67
+
68
+
69
+	/**
70
+	 * @return array
71
+	 */
72
+	public function customPostTypeSlugs()
73
+	{
74
+		return $this->custom_post_type_slugs;
75
+	}
76 76
 }
Please login to merge, or discard this patch.
core/domain/entities/custom_post_types/CustomTaxonomyDefinitions.php 1 patch
Indentation   +126 added lines, -126 removed lines patch added patch discarded remove patch
@@ -17,130 +17,130 @@
 block discarded – undo
17 17
 class CustomTaxonomyDefinitions
18 18
 {
19 19
 
20
-    /**
21
-     * @var array $taxonomies
22
-     */
23
-    private $taxonomies;
24
-
25
-
26
-    /**
27
-     * EspressoCustomPostTypeDefinitions constructor.
28
-     */
29
-    public function __construct()
30
-    {
31
-        $this->setTaxonomies();
32
-        add_filter('pre_term_description', array($this, 'filterCustomTermDescription'), 1, 2);
33
-    }
34
-
35
-
36
-    private function setTaxonomies()
37
-    {
38
-        $this->taxonomies = array(
39
-            'espresso_event_categories' => array(
40
-                'singular_name' => esc_html__('Event Category', 'event_espresso'),
41
-                'plural_name'   => esc_html__('Event Categories', 'event_espresso'),
42
-                'args'          => array(
43
-                    'public'            => true,
44
-                    'show_in_nav_menus' => true,
45
-                    'show_in_rest'      => true,
46
-                    'capabilities'      => array(
47
-                        'manage_terms' => 'ee_manage_event_categories',
48
-                        'edit_terms'   => 'ee_edit_event_category',
49
-                        'delete_terms' => 'ee_delete_event_category',
50
-                        'assign_terms' => 'ee_assign_event_category',
51
-                    ),
52
-                    'rewrite'           => array('slug' => esc_html__('event-category', 'event_espresso')),
53
-                ),
54
-            ),
55
-            'espresso_venue_categories' => array(
56
-                'singular_name' => esc_html__('Venue Category', 'event_espresso'),
57
-                'plural_name'   => esc_html__('Venue Categories', 'event_espresso'),
58
-                'args'          => array(
59
-                    'public'            => true,
60
-                    'show_in_nav_menus' => false, //by default this doesn't show for decaf
61
-                    'show_in_rest'      => true,
62
-                    'capabilities'      => array(
63
-                        'manage_terms' => 'ee_manage_venue_categories',
64
-                        'edit_terms'   => 'ee_edit_venue_category',
65
-                        'delete_terms' => 'ee_delete_venue_category',
66
-                        'assign_terms' => 'ee_assign_venue_category',
67
-                    ),
68
-                    'rewrite'           => array('slug' => esc_html__('venue-category', 'event_espresso')),
69
-                ),
70
-            ),
71
-            'espresso_event_type'       => array(
72
-                'singular_name' => esc_html__('Event Type', 'event_espresso'),
73
-                'plural_name'   => esc_html__('Event Types', 'event_espresso'),
74
-                'args'          => array(
75
-                    'public'       => true,
76
-                    'show_ui'      => false,
77
-                    'show_in_rest' => true,
78
-                    'capabilities' => array(
79
-                        'manage_terms' => 'ee_read_event_type',
80
-                        'edit_terms'   => 'ee_edit_event_type',
81
-                        'delete_terms' => 'ee_delete_event_type',
82
-                        'assign_terms' => 'ee_assign_event_type',
83
-                    ),
84
-                    'rewrite'      => array('slug' => esc_html__('event-type', 'event_espresso')),
85
-                    'hierarchical' => true,
86
-                ),
87
-            ),
88
-        );
89
-    }
90
-
91
-
92
-    /**
93
-     * @return array
94
-     */
95
-    public function getCustomTaxonomyDefinitions()
96
-    {
97
-        return (array) apply_filters(
98
-            'FHEE__EventEspresso_core_domain_entities_custom_post_types_TaxonomyDefinitions__getTaxonomies',
99
-            // legacy filter applied for now,
100
-            // later on we'll run a has_filter($tag) check and throw a doing_it_wrong() notice
101
-            apply_filters(
102
-                'FHEE__EE_Register_CPTs__get_taxonomies__taxonomies',
103
-                $this->taxonomies
104
-            )
105
-        );
106
-    }
107
-
108
-
109
-    /**
110
-     * @return array
111
-     */
112
-    public function getCustomTaxonomySlugs()
113
-    {
114
-        return array_keys($this->getCustomTaxonomyDefinitions());
115
-    }
116
-
117
-
118
-    /**
119
-     * By default, WordPress strips all html from term taxonomy description content.
120
-     * The purpose of this method is to remove that restriction
121
-     * and ensure that we still run ee term taxonomy descriptions
122
-     * through some full html sanitization equivalent to the post content field.
123
-     * So first we remove default filter for term description
124
-     * but we have to do this earlier before wp sets their own filter
125
-     * because they just set a global filter on all term descriptions
126
-     * before the custom term description filter.
127
-     * Really sux.
128
-     *
129
-     * @param string $description The description content.
130
-     * @param string $taxonomy    The taxonomy name for the taxonomy being filtered.
131
-     * @return string
132
-     */
133
-    public function filterCustomTermDescription($description, $taxonomy)
134
-    {
135
-        //get a list of EE taxonomies
136
-        $custom_taxonomies = $this->getCustomTaxonomySlugs();
137
-        //only do our own thing if the taxonomy listed is an ee taxonomy.
138
-        if (in_array($taxonomy, $custom_taxonomies, true)) {
139
-            //remove default wp filter
140
-            remove_filter('pre_term_description', 'wp_filter_kses');
141
-            //sanitize THIS content.
142
-            $description = wp_kses($description, wp_kses_allowed_html('post'));
143
-        }
144
-        return $description;
145
-    }
20
+	/**
21
+	 * @var array $taxonomies
22
+	 */
23
+	private $taxonomies;
24
+
25
+
26
+	/**
27
+	 * EspressoCustomPostTypeDefinitions constructor.
28
+	 */
29
+	public function __construct()
30
+	{
31
+		$this->setTaxonomies();
32
+		add_filter('pre_term_description', array($this, 'filterCustomTermDescription'), 1, 2);
33
+	}
34
+
35
+
36
+	private function setTaxonomies()
37
+	{
38
+		$this->taxonomies = array(
39
+			'espresso_event_categories' => array(
40
+				'singular_name' => esc_html__('Event Category', 'event_espresso'),
41
+				'plural_name'   => esc_html__('Event Categories', 'event_espresso'),
42
+				'args'          => array(
43
+					'public'            => true,
44
+					'show_in_nav_menus' => true,
45
+					'show_in_rest'      => true,
46
+					'capabilities'      => array(
47
+						'manage_terms' => 'ee_manage_event_categories',
48
+						'edit_terms'   => 'ee_edit_event_category',
49
+						'delete_terms' => 'ee_delete_event_category',
50
+						'assign_terms' => 'ee_assign_event_category',
51
+					),
52
+					'rewrite'           => array('slug' => esc_html__('event-category', 'event_espresso')),
53
+				),
54
+			),
55
+			'espresso_venue_categories' => array(
56
+				'singular_name' => esc_html__('Venue Category', 'event_espresso'),
57
+				'plural_name'   => esc_html__('Venue Categories', 'event_espresso'),
58
+				'args'          => array(
59
+					'public'            => true,
60
+					'show_in_nav_menus' => false, //by default this doesn't show for decaf
61
+					'show_in_rest'      => true,
62
+					'capabilities'      => array(
63
+						'manage_terms' => 'ee_manage_venue_categories',
64
+						'edit_terms'   => 'ee_edit_venue_category',
65
+						'delete_terms' => 'ee_delete_venue_category',
66
+						'assign_terms' => 'ee_assign_venue_category',
67
+					),
68
+					'rewrite'           => array('slug' => esc_html__('venue-category', 'event_espresso')),
69
+				),
70
+			),
71
+			'espresso_event_type'       => array(
72
+				'singular_name' => esc_html__('Event Type', 'event_espresso'),
73
+				'plural_name'   => esc_html__('Event Types', 'event_espresso'),
74
+				'args'          => array(
75
+					'public'       => true,
76
+					'show_ui'      => false,
77
+					'show_in_rest' => true,
78
+					'capabilities' => array(
79
+						'manage_terms' => 'ee_read_event_type',
80
+						'edit_terms'   => 'ee_edit_event_type',
81
+						'delete_terms' => 'ee_delete_event_type',
82
+						'assign_terms' => 'ee_assign_event_type',
83
+					),
84
+					'rewrite'      => array('slug' => esc_html__('event-type', 'event_espresso')),
85
+					'hierarchical' => true,
86
+				),
87
+			),
88
+		);
89
+	}
90
+
91
+
92
+	/**
93
+	 * @return array
94
+	 */
95
+	public function getCustomTaxonomyDefinitions()
96
+	{
97
+		return (array) apply_filters(
98
+			'FHEE__EventEspresso_core_domain_entities_custom_post_types_TaxonomyDefinitions__getTaxonomies',
99
+			// legacy filter applied for now,
100
+			// later on we'll run a has_filter($tag) check and throw a doing_it_wrong() notice
101
+			apply_filters(
102
+				'FHEE__EE_Register_CPTs__get_taxonomies__taxonomies',
103
+				$this->taxonomies
104
+			)
105
+		);
106
+	}
107
+
108
+
109
+	/**
110
+	 * @return array
111
+	 */
112
+	public function getCustomTaxonomySlugs()
113
+	{
114
+		return array_keys($this->getCustomTaxonomyDefinitions());
115
+	}
116
+
117
+
118
+	/**
119
+	 * By default, WordPress strips all html from term taxonomy description content.
120
+	 * The purpose of this method is to remove that restriction
121
+	 * and ensure that we still run ee term taxonomy descriptions
122
+	 * through some full html sanitization equivalent to the post content field.
123
+	 * So first we remove default filter for term description
124
+	 * but we have to do this earlier before wp sets their own filter
125
+	 * because they just set a global filter on all term descriptions
126
+	 * before the custom term description filter.
127
+	 * Really sux.
128
+	 *
129
+	 * @param string $description The description content.
130
+	 * @param string $taxonomy    The taxonomy name for the taxonomy being filtered.
131
+	 * @return string
132
+	 */
133
+	public function filterCustomTermDescription($description, $taxonomy)
134
+	{
135
+		//get a list of EE taxonomies
136
+		$custom_taxonomies = $this->getCustomTaxonomySlugs();
137
+		//only do our own thing if the taxonomy listed is an ee taxonomy.
138
+		if (in_array($taxonomy, $custom_taxonomies, true)) {
139
+			//remove default wp filter
140
+			remove_filter('pre_term_description', 'wp_filter_kses');
141
+			//sanitize THIS content.
142
+			$description = wp_kses($description, wp_kses_allowed_html('post'));
143
+		}
144
+		return $description;
145
+	}
146 146
 }
Please login to merge, or discard this patch.
caffeinated/admin/extend/events/Extend_Events_Admin_Page.core.php 2 patches
Indentation   +1268 added lines, -1268 removed lines patch added patch discarded remove patch
@@ -19,1272 +19,1272 @@
 block discarded – undo
19 19
 {
20 20
 
21 21
 
22
-    /**
23
-     * Extend_Events_Admin_Page constructor.
24
-     *
25
-     * @param bool $routing
26
-     */
27
-    public function __construct($routing = true)
28
-    {
29
-        parent::__construct($routing);
30
-        if (! defined('EVENTS_CAF_TEMPLATE_PATH')) {
31
-            define('EVENTS_CAF_TEMPLATE_PATH', EE_CORE_CAF_ADMIN_EXTEND . 'events/templates/');
32
-            define('EVENTS_CAF_ASSETS', EE_CORE_CAF_ADMIN_EXTEND . 'events/assets/');
33
-            define('EVENTS_CAF_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL . 'events/assets/');
34
-        }
35
-    }
36
-
37
-
38
-    /**
39
-     * Sets routes.
40
-     */
41
-    protected function _extend_page_config()
42
-    {
43
-        $this->_admin_base_path = EE_CORE_CAF_ADMIN_EXTEND . 'events';
44
-        //is there a evt_id in the request?
45
-        $evt_id = ! empty($this->_req_data['EVT_ID']) && ! is_array($this->_req_data['EVT_ID'])
46
-            ? $this->_req_data['EVT_ID']
47
-            : 0;
48
-        $evt_id = ! empty($this->_req_data['post']) ? $this->_req_data['post'] : $evt_id;
49
-        //tkt_id?
50
-        $tkt_id             = ! empty($this->_req_data['TKT_ID']) && ! is_array($this->_req_data['TKT_ID'])
51
-            ? $this->_req_data['TKT_ID']
52
-            : 0;
53
-        $new_page_routes    = array(
54
-            'duplicate_event'          => array(
55
-                'func'       => '_duplicate_event',
56
-                'capability' => 'ee_edit_event',
57
-                'obj_id'     => $evt_id,
58
-                'noheader'   => true,
59
-            ),
60
-            'ticket_list_table'        => array(
61
-                'func'       => '_tickets_overview_list_table',
62
-                'capability' => 'ee_read_default_tickets',
63
-            ),
64
-            'trash_ticket'             => array(
65
-                'func'       => '_trash_or_restore_ticket',
66
-                'capability' => 'ee_delete_default_ticket',
67
-                'obj_id'     => $tkt_id,
68
-                'noheader'   => true,
69
-                'args'       => array('trash' => true),
70
-            ),
71
-            'trash_tickets'            => array(
72
-                'func'       => '_trash_or_restore_ticket',
73
-                'capability' => 'ee_delete_default_tickets',
74
-                'noheader'   => true,
75
-                'args'       => array('trash' => true),
76
-            ),
77
-            'restore_ticket'           => array(
78
-                'func'       => '_trash_or_restore_ticket',
79
-                'capability' => 'ee_delete_default_ticket',
80
-                'obj_id'     => $tkt_id,
81
-                'noheader'   => true,
82
-            ),
83
-            'restore_tickets'          => array(
84
-                'func'       => '_trash_or_restore_ticket',
85
-                'capability' => 'ee_delete_default_tickets',
86
-                'noheader'   => true,
87
-            ),
88
-            'delete_ticket'            => array(
89
-                'func'       => '_delete_ticket',
90
-                'capability' => 'ee_delete_default_ticket',
91
-                'obj_id'     => $tkt_id,
92
-                'noheader'   => true,
93
-            ),
94
-            'delete_tickets'           => array(
95
-                'func'       => '_delete_ticket',
96
-                'capability' => 'ee_delete_default_tickets',
97
-                'noheader'   => true,
98
-            ),
99
-            'import_page'              => array(
100
-                'func'       => '_import_page',
101
-                'capability' => 'import',
102
-            ),
103
-            'import'                   => array(
104
-                'func'       => '_import_events',
105
-                'capability' => 'import',
106
-                'noheader'   => true,
107
-            ),
108
-            'import_events'            => array(
109
-                'func'       => '_import_events',
110
-                'capability' => 'import',
111
-                'noheader'   => true,
112
-            ),
113
-            'export_events'            => array(
114
-                'func'       => '_events_export',
115
-                'capability' => 'export',
116
-                'noheader'   => true,
117
-            ),
118
-            'export_categories'        => array(
119
-                'func'       => '_categories_export',
120
-                'capability' => 'export',
121
-                'noheader'   => true,
122
-            ),
123
-            'sample_export_file'       => array(
124
-                'func'       => '_sample_export_file',
125
-                'capability' => 'export',
126
-                'noheader'   => true,
127
-            ),
128
-            'update_template_settings' => array(
129
-                'func'       => '_update_template_settings',
130
-                'capability' => 'manage_options',
131
-                'noheader'   => true,
132
-            ),
133
-        );
134
-        $this->_page_routes = array_merge($this->_page_routes, $new_page_routes);
135
-        //partial route/config override
136
-        $this->_page_config['import_events']['metaboxes'] = $this->_default_espresso_metaboxes;
137
-        $this->_page_config['create_new']['metaboxes'][]  = '_premium_event_editor_meta_boxes';
138
-        $this->_page_config['create_new']['qtips'][]      = 'EE_Event_Editor_Tips';
139
-        $this->_page_config['edit']['qtips'][]            = 'EE_Event_Editor_Tips';
140
-        $this->_page_config['edit']['metaboxes'][]        = '_premium_event_editor_meta_boxes';
141
-        $this->_page_config['default']['list_table']      = 'Extend_Events_Admin_List_Table';
142
-        //add tickets tab but only if there are more than one default ticket!
143
-        $tkt_count = EEM_Ticket::instance()->count_deleted_and_undeleted(
144
-            array(array('TKT_is_default' => 1)),
145
-            'TKT_ID',
146
-            true
147
-        );
148
-        if ($tkt_count > 1) {
149
-            $new_page_config = array(
150
-                'ticket_list_table' => array(
151
-                    'nav'           => array(
152
-                        'label' => esc_html__('Default Tickets', 'event_espresso'),
153
-                        'order' => 60,
154
-                    ),
155
-                    'list_table'    => 'Tickets_List_Table',
156
-                    'require_nonce' => false,
157
-                ),
158
-            );
159
-        }
160
-        //template settings
161
-        $new_page_config['template_settings'] = array(
162
-            'nav'           => array(
163
-                'label' => esc_html__('Templates', 'event_espresso'),
164
-                'order' => 30,
165
-            ),
166
-            'metaboxes'     => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')),
167
-            'help_tabs'     => array(
168
-                'general_settings_templates_help_tab' => array(
169
-                    'title'    => esc_html__('Templates', 'event_espresso'),
170
-                    'filename' => 'general_settings_templates',
171
-                ),
172
-            ),
173
-            'help_tour'     => array('Templates_Help_Tour'),
174
-            'require_nonce' => false,
175
-        );
176
-        $this->_page_config                   = array_merge($this->_page_config, $new_page_config);
177
-        //add filters and actions
178
-        //modifying _views
179
-        add_filter(
180
-            'FHEE_event_datetime_metabox_add_additional_date_time_template',
181
-            array($this, 'add_additional_datetime_button'),
182
-            10,
183
-            2
184
-        );
185
-        add_filter(
186
-            'FHEE_event_datetime_metabox_clone_button_template',
187
-            array($this, 'add_datetime_clone_button'),
188
-            10,
189
-            2
190
-        );
191
-        add_filter(
192
-            'FHEE_event_datetime_metabox_timezones_template',
193
-            array($this, 'datetime_timezones_template'),
194
-            10,
195
-            2
196
-        );
197
-        //filters for event list table
198
-        add_filter('FHEE__Extend_Events_Admin_List_Table__filters', array($this, 'list_table_filters'), 10, 2);
199
-        add_filter(
200
-            'FHEE__Events_Admin_List_Table__column_actions__action_links',
201
-            array($this, 'extra_list_table_actions'),
202
-            10,
203
-            2
204
-        );
205
-        //legend item
206
-        add_filter('FHEE__Events_Admin_Page___event_legend_items__items', array($this, 'additional_legend_items'));
207
-        add_action('admin_init', array($this, 'admin_init'));
208
-        //heartbeat stuff
209
-        add_filter('heartbeat_received', array($this, 'heartbeat_response'), 10, 2);
210
-    }
211
-
212
-
213
-    /**
214
-     * admin_init
215
-     */
216
-    public function admin_init()
217
-    {
218
-        EE_Registry::$i18n_js_strings = array_merge(
219
-            EE_Registry::$i18n_js_strings,
220
-            array(
221
-                'image_confirm'          => esc_html__(
222
-                    'Do you really want to delete this image? Please remember to update your event to complete the removal.',
223
-                    'event_espresso'
224
-                ),
225
-                'event_starts_on'        => esc_html__('Event Starts on', 'event_espresso'),
226
-                'event_ends_on'          => esc_html__('Event Ends on', 'event_espresso'),
227
-                'event_datetime_actions' => esc_html__('Actions', 'event_espresso'),
228
-                'event_clone_dt_msg'     => esc_html__('Clone this Event Date and Time', 'event_espresso'),
229
-                'remove_event_dt_msg'    => esc_html__('Remove this Event Time', 'event_espresso'),
230
-            )
231
-        );
232
-    }
233
-
234
-
235
-    /**
236
-     * This will be used to listen for any heartbeat data packages coming via the WordPress heartbeat API and handle
237
-     * accordingly.
238
-     *
239
-     * @param array $response The existing heartbeat response array.
240
-     * @param array $data     The incoming data package.
241
-     * @return array  possibly appended response.
242
-     */
243
-    public function heartbeat_response($response, $data)
244
-    {
245
-        /**
246
-         * check whether count of tickets is approaching the potential
247
-         * limits for the server.
248
-         */
249
-        if (! empty($data['input_count'])) {
250
-            $response['max_input_vars_check'] = EE_Registry::instance()->CFG->environment->max_input_vars_limit_check(
251
-                $data['input_count']
252
-            );
253
-        }
254
-        return $response;
255
-    }
256
-
257
-
258
-    /**
259
-     * Add per page screen options to the default ticket list table view.
260
-     */
261
-    protected function _add_screen_options_ticket_list_table()
262
-    {
263
-        $this->_per_page_screen_option();
264
-    }
265
-
266
-
267
-    /**
268
-     * @param string $return
269
-     * @param int    $id
270
-     * @param string $new_title
271
-     * @param string $new_slug
272
-     * @return string
273
-     */
274
-    public function extra_permalink_field_buttons($return, $id, $new_title, $new_slug)
275
-    {
276
-        $return = parent::extra_permalink_field_buttons($return, $id, $new_title, $new_slug);
277
-        //make sure this is only when editing
278
-        if (! empty($id)) {
279
-            $href   = EE_Admin_Page::add_query_args_and_nonce(
280
-                array('action' => 'duplicate_event', 'EVT_ID' => $id),
281
-                $this->_admin_base_url
282
-            );
283
-            $title  = esc_attr__('Duplicate Event', 'event_espresso');
284
-            $return .= '<a href="'
285
-                       . $href
286
-                       . '" title="'
287
-                       . $title
288
-                       . '" id="ee-duplicate-event-button" class="button button-small"  value="duplicate_event">'
289
-                       . $title
290
-                       . '</a>';
291
-        }
292
-        return $return;
293
-    }
294
-
295
-
296
-    /**
297
-     * Set the list table views for the default ticket list table view.
298
-     */
299
-    public function _set_list_table_views_ticket_list_table()
300
-    {
301
-        $this->_views = array(
302
-            'all'     => array(
303
-                'slug'        => 'all',
304
-                'label'       => esc_html__('All', 'event_espresso'),
305
-                'count'       => 0,
306
-                'bulk_action' => array(
307
-                    'trash_tickets' => esc_html__('Move to Trash', 'event_espresso'),
308
-                ),
309
-            ),
310
-            'trashed' => array(
311
-                'slug'        => 'trashed',
312
-                'label'       => esc_html__('Trash', 'event_espresso'),
313
-                'count'       => 0,
314
-                'bulk_action' => array(
315
-                    'restore_tickets' => esc_html__('Restore from Trash', 'event_espresso'),
316
-                    'delete_tickets'  => esc_html__('Delete Permanently', 'event_espresso'),
317
-                ),
318
-            ),
319
-        );
320
-    }
321
-
322
-
323
-    /**
324
-     * Enqueue scripts and styles for the event editor.
325
-     */
326
-    public function load_scripts_styles_edit()
327
-    {
328
-        wp_register_script(
329
-            'ee-event-editor-heartbeat',
330
-            EVENTS_CAF_ASSETS_URL . 'event-editor-heartbeat.js',
331
-            array('ee_admin_js', 'heartbeat'),
332
-            EVENT_ESPRESSO_VERSION,
333
-            true
334
-        );
335
-        wp_enqueue_script('ee-accounting');
336
-        //styles
337
-        wp_enqueue_style('espresso-ui-theme');
338
-        wp_enqueue_script('event_editor_js');
339
-        wp_enqueue_script('ee-event-editor-heartbeat');
340
-    }
341
-
342
-
343
-    /**
344
-     * Returns template for the additional datetime.
345
-     * @param $template
346
-     * @param $template_args
347
-     * @return mixed
348
-     * @throws DomainException
349
-     */
350
-    public function add_additional_datetime_button($template, $template_args)
351
-    {
352
-        return EEH_Template::display_template(
353
-            EVENTS_CAF_TEMPLATE_PATH . 'event_datetime_add_additional_time.template.php',
354
-            $template_args,
355
-            true
356
-        );
357
-    }
358
-
359
-
360
-    /**
361
-     * Returns the template for cloning a datetime.
362
-     * @param $template
363
-     * @param $template_args
364
-     * @return mixed
365
-     * @throws DomainException
366
-     */
367
-    public function add_datetime_clone_button($template, $template_args)
368
-    {
369
-        return EEH_Template::display_template(
370
-            EVENTS_CAF_TEMPLATE_PATH . 'event_datetime_metabox_clone_button.template.php',
371
-            $template_args,
372
-            true
373
-        );
374
-    }
375
-
376
-
377
-    /**
378
-     * Returns the template for datetime timezones.
379
-     * @param $template
380
-     * @param $template_args
381
-     * @return mixed
382
-     * @throws DomainException
383
-     */
384
-    public function datetime_timezones_template($template, $template_args)
385
-    {
386
-        return EEH_Template::display_template(
387
-            EVENTS_CAF_TEMPLATE_PATH . 'event_datetime_timezones.template.php',
388
-            $template_args,
389
-            true
390
-        );
391
-    }
392
-
393
-
394
-    /**
395
-     * Sets the views for the default list table view.
396
-     */
397
-    protected function _set_list_table_views_default()
398
-    {
399
-        parent::_set_list_table_views_default();
400
-        $new_views    = array(
401
-            'today' => array(
402
-                'slug'        => 'today',
403
-                'label'       => esc_html__('Today', 'event_espresso'),
404
-                'count'       => $this->total_events_today(),
405
-                'bulk_action' => array(
406
-                    'trash_events' => esc_html__('Move to Trash', 'event_espresso'),
407
-                ),
408
-            ),
409
-            'month' => array(
410
-                'slug'        => 'month',
411
-                'label'       => esc_html__('This Month', 'event_espresso'),
412
-                'count'       => $this->total_events_this_month(),
413
-                'bulk_action' => array(
414
-                    'trash_events' => esc_html__('Move to Trash', 'event_espresso'),
415
-                ),
416
-            ),
417
-        );
418
-        $this->_views = array_merge($this->_views, $new_views);
419
-    }
420
-
421
-
422
-    /**
423
-     * Returns the extra action links for the default list table view.
424
-     * @param array     $action_links
425
-     * @param \EE_Event $event
426
-     * @return array
427
-     * @throws EE_Error
428
-     */
429
-    public function extra_list_table_actions(array $action_links, \EE_Event $event)
430
-    {
431
-        if (EE_Registry::instance()->CAP->current_user_can(
432
-            'ee_read_registrations',
433
-            'espresso_registrations_reports',
434
-            $event->ID()
435
-        )
436
-        ) {
437
-            $reports_query_args = array(
438
-                'action' => 'reports',
439
-                'EVT_ID' => $event->ID(),
440
-            );
441
-            $reports_link       = EE_Admin_Page::add_query_args_and_nonce($reports_query_args, REG_ADMIN_URL);
442
-            $action_links[]     = '<a href="'
443
-                                  . $reports_link
444
-                                  . '" title="'
445
-                                  . esc_attr__('View Report', 'event_espresso')
446
-                                  . '"><div class="dashicons dashicons-chart-bar"></div></a>'
447
-                                  . "\n\t";
448
-        }
449
-        if (EE_Registry::instance()->CAP->current_user_can('ee_read_global_messages', 'view_filtered_messages')) {
450
-            EE_Registry::instance()->load_helper('MSG_Template');
451
-            $action_links[] = EEH_MSG_Template::get_message_action_link(
452
-                'see_notifications_for',
453
-                null,
454
-                array('EVT_ID' => $event->ID())
455
-            );
456
-        }
457
-        return $action_links;
458
-    }
459
-
460
-
461
-    /**
462
-     * @param $items
463
-     * @return mixed
464
-     */
465
-    public function additional_legend_items($items)
466
-    {
467
-        if (EE_Registry::instance()->CAP->current_user_can(
468
-            'ee_read_registrations',
469
-            'espresso_registrations_reports'
470
-        )
471
-        ) {
472
-            $items['reports'] = array(
473
-                'class' => 'dashicons dashicons-chart-bar',
474
-                'desc'  => esc_html__('Event Reports', 'event_espresso'),
475
-            );
476
-        }
477
-        if (EE_Registry::instance()->CAP->current_user_can('ee_read_global_messages', 'view_filtered_messages')) {
478
-            $related_for_icon = EEH_MSG_Template::get_message_action_icon('see_notifications_for');
479
-            if (isset($related_for_icon['css_class']) && isset($related_for_icon['label'])) {
480
-                $items['view_related_messages'] = array(
481
-                    'class' => $related_for_icon['css_class'],
482
-                    'desc'  => $related_for_icon['label'],
483
-                );
484
-            }
485
-        }
486
-        return $items;
487
-    }
488
-
489
-
490
-    /**
491
-     * This is the callback method for the duplicate event route
492
-     * Method looks for 'EVT_ID' in the request and retrieves that event and its details and duplicates them
493
-     * into a new event.  We add a hook so that any plugins that add extra event details can hook into this
494
-     * action.  Note that the dupe will have **DUPLICATE** as its title and slug.
495
-     * After duplication the redirect is to the new event edit page.
496
-     *
497
-     * @return void
498
-     * @access protected
499
-     * @throws EE_Error If EE_Event is not available with given ID
500
-     */
501
-    protected function _duplicate_event()
502
-    {
503
-        // first make sure the ID for the event is in the request.
504
-        //  If it isn't then we need to bail and redirect back to overview list table (cause how did we get here?)
505
-        if (! isset($this->_req_data['EVT_ID'])) {
506
-            EE_Error::add_error(
507
-                esc_html__(
508
-                    'In order to duplicate an event an Event ID is required.  None was given.',
509
-                    'event_espresso'
510
-                ),
511
-                __FILE__,
512
-                __FUNCTION__,
513
-                __LINE__
514
-            );
515
-            $this->_redirect_after_action(false, '', '', array(), true);
516
-            return;
517
-        }
518
-        //k we've got EVT_ID so let's use that to get the event we'll duplicate
519
-        $orig_event = EEM_Event::instance()->get_one_by_ID($this->_req_data['EVT_ID']);
520
-        if (! $orig_event instanceof EE_Event) {
521
-            throw new EE_Error(
522
-                sprintf(
523
-                    esc_html__('An EE_Event object could not be retrieved for the given ID (%s)', 'event_espresso'),
524
-                    $this->_req_data['EVT_ID']
525
-                )
526
-            );
527
-        }
528
-        //k now let's clone the $orig_event before getting relations
529
-        $new_event = clone $orig_event;
530
-        //original datetimes
531
-        $orig_datetimes = $orig_event->get_many_related('Datetime');
532
-        //other original relations
533
-        $orig_ven = $orig_event->get_many_related('Venue');
534
-        //reset the ID and modify other details to make it clear this is a dupe
535
-        $new_event->set('EVT_ID', 0);
536
-        $new_name = $new_event->name() . ' ' . esc_html__('**DUPLICATE**', 'event_espresso');
537
-        $new_event->set('EVT_name', $new_name);
538
-        $new_event->set(
539
-            'EVT_slug',
540
-            wp_unique_post_slug(
541
-                sanitize_title($orig_event->name()),
542
-                0,
543
-                'publish',
544
-                'espresso_events',
545
-                0
546
-            )
547
-        );
548
-        $new_event->set('status', 'draft');
549
-        //duplicate discussion settings
550
-        $new_event->set('comment_status', $orig_event->get('comment_status'));
551
-        $new_event->set('ping_status', $orig_event->get('ping_status'));
552
-        //save the new event
553
-        $new_event->save();
554
-        //venues
555
-        foreach ($orig_ven as $ven) {
556
-            $new_event->_add_relation_to($ven, 'Venue');
557
-        }
558
-        $new_event->save();
559
-        //now we need to get the question group relations and handle that
560
-        //first primary question groups
561
-        $orig_primary_qgs = $orig_event->get_many_related(
562
-            'Question_Group',
563
-            array(array('Event_Question_Group.EQG_primary' => 1))
564
-        );
565
-        if (! empty($orig_primary_qgs)) {
566
-            foreach ($orig_primary_qgs as $id => $obj) {
567
-                if ($obj instanceof EE_Question_Group) {
568
-                    $new_event->_add_relation_to($obj, 'Question_Group', array('EQG_primary' => 1));
569
-                }
570
-            }
571
-        }
572
-        //next additional attendee question groups
573
-        $orig_additional_qgs = $orig_event->get_many_related(
574
-            'Question_Group',
575
-            array(array('Event_Question_Group.EQG_primary' => 0))
576
-        );
577
-        if (! empty($orig_additional_qgs)) {
578
-            foreach ($orig_additional_qgs as $id => $obj) {
579
-                if ($obj instanceof EE_Question_Group) {
580
-                    $new_event->_add_relation_to($obj, 'Question_Group', array('EQG_primary' => 0));
581
-                }
582
-            }
583
-        }
584
-
585
-        $new_event->save();
586
-
587
-        //k now that we have the new event saved we can loop through the datetimes and start adding relations.
588
-        $cloned_tickets = array();
589
-        foreach ($orig_datetimes as $orig_dtt) {
590
-            if (! $orig_dtt instanceof EE_Datetime) {
591
-                continue;
592
-            }
593
-            $new_dtt   = clone $orig_dtt;
594
-            $orig_tkts = $orig_dtt->tickets();
595
-            //save new dtt then add to event
596
-            $new_dtt->set('DTT_ID', 0);
597
-            $new_dtt->set('DTT_sold', 0);
598
-            $new_dtt->set_reserved(0);
599
-            $new_dtt->save();
600
-            $new_event->_add_relation_to($new_dtt, 'Datetime');
601
-            $new_event->save();
602
-            //now let's get the ticket relations setup.
603
-            foreach ((array)$orig_tkts as $orig_tkt) {
604
-                //it's possible a datetime will have no tickets so let's verify we HAVE a ticket first.
605
-                if (! $orig_tkt instanceof EE_Ticket) {
606
-                    continue;
607
-                }
608
-                //is this ticket archived?  If it is then let's skip
609
-                if ($orig_tkt->get('TKT_deleted')) {
610
-                    continue;
611
-                }
612
-                // does this original ticket already exist in the clone_tickets cache?
613
-                //  If so we'll just use the new ticket from it.
614
-                if (isset($cloned_tickets[$orig_tkt->ID()])) {
615
-                    $new_tkt = $cloned_tickets[$orig_tkt->ID()];
616
-                } else {
617
-                    $new_tkt = clone $orig_tkt;
618
-                    //get relations on the $orig_tkt that we need to setup.
619
-                    $orig_prices = $orig_tkt->prices();
620
-                    $new_tkt->set('TKT_ID', 0);
621
-                    $new_tkt->set('TKT_sold', 0);
622
-                    $new_tkt->set('TKT_reserved', 0);
623
-                    $new_tkt->save(); //make sure new ticket has ID.
624
-                    //price relations on new ticket need to be setup.
625
-                    foreach ($orig_prices as $orig_price) {
626
-                        $new_price = clone $orig_price;
627
-                        $new_price->set('PRC_ID', 0);
628
-                        $new_price->save();
629
-                        $new_tkt->_add_relation_to($new_price, 'Price');
630
-                        $new_tkt->save();
631
-                    }
632
-
633
-                    do_action(
634
-                        'AHEE__Extend_Events_Admin_Page___duplicate_event__duplicate_ticket__after',
635
-                        $orig_tkt,
636
-                        $new_tkt,
637
-                        $orig_prices,
638
-                        $orig_event,
639
-                        $orig_dtt,
640
-                        $new_dtt
641
-                    );
642
-                }
643
-                // k now we can add the new ticket as a relation to the new datetime
644
-                // and make sure its added to our cached $cloned_tickets array
645
-                // for use with later datetimes that have the same ticket.
646
-                $new_dtt->_add_relation_to($new_tkt, 'Ticket');
647
-                $new_dtt->save();
648
-                $cloned_tickets[$orig_tkt->ID()] = $new_tkt;
649
-            }
650
-        }
651
-        //clone taxonomy information
652
-        $taxonomies_to_clone_with = apply_filters(
653
-            'FHEE__Extend_Events_Admin_Page___duplicate_event__taxonomies_to_clone',
654
-            array('espresso_event_categories', 'espresso_event_type', 'post_tag')
655
-        );
656
-        //get terms for original event (notice)
657
-        $orig_terms = wp_get_object_terms($orig_event->ID(), $taxonomies_to_clone_with);
658
-        //loop through terms and add them to new event.
659
-        foreach ($orig_terms as $term) {
660
-            wp_set_object_terms($new_event->ID(), $term->term_id, $term->taxonomy, true);
661
-        }
662
-
663
-        //duplicate other core WP_Post items for this event.
664
-        //post thumbnail (feature image).
665
-        $feature_image_id = get_post_thumbnail_id($orig_event->ID());
666
-        if ($feature_image_id) {
667
-            update_post_meta($new_event->ID(), '_thumbnail_id', $feature_image_id);
668
-        }
669
-
670
-        //duplicate page_template setting
671
-        $page_template = get_post_meta($orig_event->ID(), '_wp_page_template', true);
672
-        if ($page_template) {
673
-            update_post_meta($new_event->ID(), '_wp_page_template', $page_template);
674
-        }
675
-
676
-        do_action('AHEE__Extend_Events_Admin_Page___duplicate_event__after', $new_event, $orig_event);
677
-        //now let's redirect to the edit page for this duplicated event if we have a new event id.
678
-        if ($new_event->ID()) {
679
-            $redirect_args = array(
680
-                'post'   => $new_event->ID(),
681
-                'action' => 'edit',
682
-            );
683
-            EE_Error::add_success(
684
-                esc_html__(
685
-                    'Event successfully duplicated.  Please review the details below and make any necessary edits',
686
-                    'event_espresso'
687
-                )
688
-            );
689
-        } else {
690
-            $redirect_args = array(
691
-                'action' => 'default',
692
-            );
693
-            EE_Error::add_error(
694
-                esc_html__('Not able to duplicate event.  Something went wrong.', 'event_espresso'),
695
-                __FILE__,
696
-                __FUNCTION__,
697
-                __LINE__
698
-            );
699
-        }
700
-        $this->_redirect_after_action(false, '', '', $redirect_args, true);
701
-    }
702
-
703
-
704
-    /**
705
-     * Generates output for the import page.
706
-     * @throws DomainException
707
-     */
708
-    protected function _import_page()
709
-    {
710
-        $title                                      = esc_html__('Import', 'event_espresso');
711
-        $intro                                      = esc_html__(
712
-            'If you have a previously exported Event Espresso 4 information in a Comma Separated Value (CSV) file format, you can upload the file here: ',
713
-            'event_espresso'
714
-        );
715
-        $form_url                                   = EVENTS_ADMIN_URL;
716
-        $action                                     = 'import_events';
717
-        $type                                       = 'csv';
718
-        $this->_template_args['form']               = EE_Import::instance()->upload_form(
719
-            $title, $intro, $form_url, $action, $type
720
-        );
721
-        $this->_template_args['sample_file_link']   = EE_Admin_Page::add_query_args_and_nonce(
722
-            array('action' => 'sample_export_file'),
723
-            $this->_admin_base_url
724
-        );
725
-        $content                                    = EEH_Template::display_template(
726
-            EVENTS_CAF_TEMPLATE_PATH . 'import_page.template.php',
727
-            $this->_template_args,
728
-            true
729
-        );
730
-        $this->_template_args['admin_page_content'] = $content;
731
-        $this->display_admin_page_with_sidebar();
732
-    }
733
-
734
-
735
-    /**
736
-     * _import_events
737
-     * This handles displaying the screen and running imports for importing events.
738
-     *
739
-     * @return void
740
-     */
741
-    protected function _import_events()
742
-    {
743
-        require_once(EE_CLASSES . 'EE_Import.class.php');
744
-        $success = EE_Import::instance()->import();
745
-        $this->_redirect_after_action($success, 'Import File', 'ran', array('action' => 'import_page'), true);
746
-    }
747
-
748
-
749
-    /**
750
-     * _events_export
751
-     * Will export all (or just the given event) to a Excel compatible file.
752
-     *
753
-     * @access protected
754
-     * @return void
755
-     */
756
-    protected function _events_export()
757
-    {
758
-        if (isset($this->_req_data['EVT_ID'])) {
759
-            $event_ids = $this->_req_data['EVT_ID'];
760
-        } elseif (isset($this->_req_data['EVT_IDs'])) {
761
-            $event_ids = $this->_req_data['EVT_IDs'];
762
-        } else {
763
-            $event_ids = null;
764
-        }
765
-        //todo: I don't like doing this but it'll do until we modify EE_Export Class.
766
-        $new_request_args = array(
767
-            'export' => 'report',
768
-            'action' => 'all_event_data',
769
-            'EVT_ID' => $event_ids,
770
-        );
771
-        $this->_req_data  = array_merge($this->_req_data, $new_request_args);
772
-        if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
773
-            require_once(EE_CLASSES . 'EE_Export.class.php');
774
-            $EE_Export = EE_Export::instance($this->_req_data);
775
-            $EE_Export->export();
776
-        }
777
-    }
778
-
779
-
780
-    /**
781
-     * handle category exports()
782
-     *
783
-     * @return void
784
-     */
785
-    protected function _categories_export()
786
-    {
787
-        //todo: I don't like doing this but it'll do until we modify EE_Export Class.
788
-        $new_request_args = array(
789
-            'export'       => 'report',
790
-            'action'       => 'categories',
791
-            'category_ids' => $this->_req_data['EVT_CAT_ID'],
792
-        );
793
-        $this->_req_data  = array_merge($this->_req_data, $new_request_args);
794
-        if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
795
-            require_once(EE_CLASSES . 'EE_Export.class.php');
796
-            $EE_Export = EE_Export::instance($this->_req_data);
797
-            $EE_Export->export();
798
-        }
799
-    }
800
-
801
-
802
-    /**
803
-     * Creates a sample CSV file for importing
804
-     */
805
-    protected function _sample_export_file()
806
-    {
807
-        //		require_once(EE_CLASSES . 'EE_Export.class.php');
808
-        EE_Export::instance()->export_sample();
809
-    }
810
-
811
-
812
-    /*************        Template Settings        *************/
813
-    /**
814
-     * Generates template settings page output
815
-     * @throws DomainException
816
-     * @throws EE_Error
817
-     */
818
-    protected function _template_settings()
819
-    {
820
-        $this->_template_args['values'] = $this->_yes_no_values;
821
-        /**
822
-         * Note leaving this filter in for backward compatibility this was moved in 4.6.x
823
-         * from General_Settings_Admin_Page to here.
824
-         */
825
-        $this->_template_args = apply_filters(
826
-            'FHEE__General_Settings_Admin_Page__template_settings__template_args',
827
-            $this->_template_args
828
-        );
829
-        $this->_set_add_edit_form_tags('update_template_settings');
830
-        $this->_set_publish_post_box_vars(null, false, false, null, false);
831
-        $this->_template_args['admin_page_content'] = EEH_Template::display_template(
832
-            EVENTS_CAF_TEMPLATE_PATH . 'template_settings.template.php',
833
-            $this->_template_args,
834
-            true
835
-        );
836
-        $this->display_admin_page_with_sidebar();
837
-    }
838
-
839
-
840
-    /**
841
-     * Handler for updating template settings.
842
-     *
843
-     * @throws InvalidInterfaceException
844
-     * @throws InvalidDataTypeException
845
-     * @throws InvalidArgumentException
846
-     */
847
-    protected function _update_template_settings()
848
-    {
849
-        /**
850
-         * Note leaving this filter in for backward compatibility this was moved in 4.6.x
851
-         * from General_Settings_Admin_Page to here.
852
-         */
853
-        EE_Registry::instance()->CFG->template_settings = apply_filters(
854
-            'FHEE__General_Settings_Admin_Page__update_template_settings__data',
855
-            EE_Registry::instance()->CFG->template_settings,
856
-            $this->_req_data
857
-        );
858
-        //update custom post type slugs and detect if we need to flush rewrite rules
859
-        $old_slug                                          = EE_Registry::instance()->CFG->core->event_cpt_slug;
860
-        EE_Registry::instance()->CFG->core->event_cpt_slug = empty($this->_req_data['event_cpt_slug'])
861
-            ? EE_Registry::instance()->CFG->core->event_cpt_slug
862
-            : sanitize_title_with_dashes($this->_req_data['event_cpt_slug']);
863
-        $what                                              = 'Template Settings';
864
-        $success                                           = $this->_update_espresso_configuration(
865
-            $what,
866
-            EE_Registry::instance()->CFG->template_settings,
867
-            __FILE__,
868
-            __FUNCTION__,
869
-            __LINE__
870
-        );
871
-        if (EE_Registry::instance()->CFG->core->event_cpt_slug != $old_slug) {
872
-            /** @var EventEspresso\core\domain\services\custom_post_types\RewriteRules $rewrite_rules */
873
-            $rewrite_rules =  LoaderFactory::getLoader()->getShared(
874
-                'EventEspresso\core\domain\services\custom_post_types\RewriteRules'
875
-            );
876
-            $rewrite_rules->flush();
877
-        }
878
-        $this->_redirect_after_action($success, $what, 'updated', array('action' => 'template_settings'));
879
-    }
880
-
881
-
882
-    /**
883
-     * _premium_event_editor_meta_boxes
884
-     * add all metaboxes related to the event_editor
885
-     *
886
-     * @access protected
887
-     * @return void
888
-     * @throws EE_Error
889
-     */
890
-    protected function _premium_event_editor_meta_boxes()
891
-    {
892
-        $this->verify_cpt_object();
893
-        add_meta_box(
894
-            'espresso_event_editor_event_options',
895
-            esc_html__('Event Registration Options', 'event_espresso'),
896
-            array($this, 'registration_options_meta_box'),
897
-            $this->page_slug,
898
-            'side',
899
-            'core'
900
-        );
901
-    }
902
-
903
-
904
-    /**
905
-     * override caf metabox
906
-     *
907
-     * @return void
908
-     * @throws DomainException
909
-     */
910
-    public function registration_options_meta_box()
911
-    {
912
-        $yes_no_values                                    = array(
913
-            array('id' => true, 'text' => esc_html__('Yes', 'event_espresso')),
914
-            array('id' => false, 'text' => esc_html__('No', 'event_espresso')),
915
-        );
916
-        $default_reg_status_values                        = EEM_Registration::reg_status_array(
917
-            array(
918
-                EEM_Registration::status_id_cancelled,
919
-                EEM_Registration::status_id_declined,
920
-                EEM_Registration::status_id_incomplete,
921
-                EEM_Registration::status_id_wait_list,
922
-            ),
923
-            true
924
-        );
925
-        $template_args['active_status']                   = $this->_cpt_model_obj->pretty_active_status(false);
926
-        $template_args['_event']                          = $this->_cpt_model_obj;
927
-        $template_args['additional_limit']                = $this->_cpt_model_obj->additional_limit();
928
-        $template_args['default_registration_status']     = EEH_Form_Fields::select_input(
929
-            'default_reg_status',
930
-            $default_reg_status_values,
931
-            $this->_cpt_model_obj->default_registration_status()
932
-        );
933
-        $template_args['display_description']             = EEH_Form_Fields::select_input(
934
-            'display_desc',
935
-            $yes_no_values,
936
-            $this->_cpt_model_obj->display_description()
937
-        );
938
-        $template_args['display_ticket_selector']         = EEH_Form_Fields::select_input(
939
-            'display_ticket_selector',
940
-            $yes_no_values,
941
-            $this->_cpt_model_obj->display_ticket_selector(),
942
-            '',
943
-            '',
944
-            false
945
-        );
946
-        $template_args['EVT_default_registration_status'] = EEH_Form_Fields::select_input(
947
-            'EVT_default_registration_status',
948
-            $default_reg_status_values,
949
-            $this->_cpt_model_obj->default_registration_status()
950
-        );
951
-        $template_args['additional_registration_options'] = apply_filters(
952
-            'FHEE__Events_Admin_Page__registration_options_meta_box__additional_registration_options',
953
-            '',
954
-            $template_args,
955
-            $yes_no_values,
956
-            $default_reg_status_values
957
-        );
958
-        EEH_Template::display_template(
959
-            EVENTS_CAF_TEMPLATE_PATH . 'event_registration_options.template.php',
960
-            $template_args
961
-        );
962
-    }
963
-
964
-
965
-
966
-    /**
967
-     * wp_list_table_mods for caf
968
-     * ============================
969
-     */
970
-    /**
971
-     * hook into list table filters and provide filters for caffeinated list table
972
-     *
973
-     * @param  array $old_filters    any existing filters present
974
-     * @param  array $list_table_obj the list table object
975
-     * @return array                  new filters
976
-     */
977
-    public function list_table_filters($old_filters, $list_table_obj)
978
-    {
979
-        $filters = array();
980
-        //first month/year filters
981
-        $filters[] = $this->espresso_event_months_dropdown();
982
-        $status    = isset($this->_req_data['status']) ? $this->_req_data['status'] : null;
983
-        //active status dropdown
984
-        if ($status !== 'draft') {
985
-            $filters[] = $this->active_status_dropdown(
986
-                isset($this->_req_data['active_status']) ? $this->_req_data['active_status'] : ''
987
-            );
988
-        }
989
-        //category filter
990
-        $filters[] = $this->category_dropdown();
991
-        return array_merge($old_filters, $filters);
992
-    }
993
-
994
-
995
-    /**
996
-     * espresso_event_months_dropdown
997
-     *
998
-     * @access public
999
-     * @return string                dropdown listing month/year selections for events.
1000
-     */
1001
-    public function espresso_event_months_dropdown()
1002
-    {
1003
-        // what we need to do is get all PRIMARY datetimes for all events to filter on.
1004
-        // Note we need to include any other filters that are set!
1005
-        $status = isset($this->_req_data['status']) ? $this->_req_data['status'] : null;
1006
-        //categories?
1007
-        $category = isset($this->_req_data['EVT_CAT']) && $this->_req_data['EVT_CAT'] > 0
1008
-            ? $this->_req_data['EVT_CAT']
1009
-            : null;
1010
-        //active status?
1011
-        $active_status = isset($this->_req_data['active_status']) ? $this->_req_data['active_status'] : null;
1012
-        $cur_date      = isset($this->_req_data['month_range']) ? $this->_req_data['month_range'] : '';
1013
-        return EEH_Form_Fields::generate_event_months_dropdown($cur_date, $status, $category, $active_status);
1014
-    }
1015
-
1016
-
1017
-    /**
1018
-     * returns a list of "active" statuses on the event
1019
-     *
1020
-     * @param  string $current_value whatever the current active status is
1021
-     * @return string
1022
-     */
1023
-    public function active_status_dropdown($current_value = '')
1024
-    {
1025
-        $select_name = 'active_status';
1026
-        $values      = array(
1027
-            'none'     => esc_html__('Show Active/Inactive', 'event_espresso'),
1028
-            'active'   => esc_html__('Active', 'event_espresso'),
1029
-            'upcoming' => esc_html__('Upcoming', 'event_espresso'),
1030
-            'expired'  => esc_html__('Expired', 'event_espresso'),
1031
-            'inactive' => esc_html__('Inactive', 'event_espresso'),
1032
-        );
1033
-        $id          = 'id="espresso-active-status-dropdown-filter"';
1034
-        $class       = 'wide';
1035
-        return EEH_Form_Fields::select_input($select_name, $values, $current_value, $id, $class);
1036
-    }
1037
-
1038
-
1039
-    /**
1040
-     * output a dropdown of the categories for the category filter on the event admin list table
1041
-     *
1042
-     * @access  public
1043
-     * @return string html
1044
-     */
1045
-    public function category_dropdown()
1046
-    {
1047
-        $cur_cat = isset($this->_req_data['EVT_CAT']) ? $this->_req_data['EVT_CAT'] : -1;
1048
-        return EEH_Form_Fields::generate_event_category_dropdown($cur_cat);
1049
-    }
1050
-
1051
-
1052
-    /**
1053
-     * get total number of events today
1054
-     *
1055
-     * @access public
1056
-     * @return int
1057
-     * @throws EE_Error
1058
-     */
1059
-    public function total_events_today()
1060
-    {
1061
-        $start = EEM_Datetime::instance()->convert_datetime_for_query(
1062
-            'DTT_EVT_start',
1063
-            date('Y-m-d') . ' 00:00:00',
1064
-            'Y-m-d H:i:s',
1065
-            'UTC'
1066
-        );
1067
-        $end   = EEM_Datetime::instance()->convert_datetime_for_query(
1068
-            'DTT_EVT_start',
1069
-            date('Y-m-d') . ' 23:59:59',
1070
-            'Y-m-d H:i:s',
1071
-            'UTC'
1072
-        );
1073
-        $where = array(
1074
-            'Datetime.DTT_EVT_start' => array('BETWEEN', array($start, $end)),
1075
-        );
1076
-        $count = EEM_Event::instance()->count(array($where, 'caps' => 'read_admin'), 'EVT_ID', true);
1077
-        return $count;
1078
-    }
1079
-
1080
-
1081
-    /**
1082
-     * get total number of events this month
1083
-     *
1084
-     * @access public
1085
-     * @return int
1086
-     * @throws EE_Error
1087
-     */
1088
-    public function total_events_this_month()
1089
-    {
1090
-        //Dates
1091
-        $this_year_r     = date('Y');
1092
-        $this_month_r    = date('m');
1093
-        $days_this_month = date('t');
1094
-        $start           = EEM_Datetime::instance()->convert_datetime_for_query(
1095
-            'DTT_EVT_start',
1096
-            $this_year_r . '-' . $this_month_r . '-01 00:00:00',
1097
-            'Y-m-d H:i:s',
1098
-            'UTC'
1099
-        );
1100
-        $end             = EEM_Datetime::instance()->convert_datetime_for_query(
1101
-            'DTT_EVT_start',
1102
-            $this_year_r . '-' . $this_month_r . '-' . $days_this_month . ' 23:59:59',
1103
-            'Y-m-d H:i:s',
1104
-            'UTC'
1105
-        );
1106
-        $where           = array(
1107
-            'Datetime.DTT_EVT_start' => array('BETWEEN', array($start, $end)),
1108
-        );
1109
-        $count           = EEM_Event::instance()->count(array($where, 'caps' => 'read_admin'), 'EVT_ID', true);
1110
-        return $count;
1111
-    }
1112
-
1113
-
1114
-    /** DEFAULT TICKETS STUFF **/
1115
-
1116
-    /**
1117
-     * Output default tickets list table view.
1118
-     */
1119
-    public function _tickets_overview_list_table()
1120
-    {
1121
-        $this->_search_btn_label = esc_html__('Tickets', 'event_espresso');
1122
-        $this->display_admin_list_table_page_with_no_sidebar();
1123
-    }
1124
-
1125
-
1126
-    /**
1127
-     * @param int  $per_page
1128
-     * @param bool $count
1129
-     * @param bool $trashed
1130
-     * @return \EE_Soft_Delete_Base_Class[]|int
1131
-     */
1132
-    public function get_default_tickets($per_page = 10, $count = false, $trashed = false)
1133
-    {
1134
-        $orderby = empty($this->_req_data['orderby']) ? 'TKT_name' : $this->_req_data['orderby'];
1135
-        $order   = empty($this->_req_data['order']) ? 'ASC' : $this->_req_data['order'];
1136
-        switch ($orderby) {
1137
-            case 'TKT_name':
1138
-                $orderby = array('TKT_name' => $order);
1139
-                break;
1140
-            case 'TKT_price':
1141
-                $orderby = array('TKT_price' => $order);
1142
-                break;
1143
-            case 'TKT_uses':
1144
-                $orderby = array('TKT_uses' => $order);
1145
-                break;
1146
-            case 'TKT_min':
1147
-                $orderby = array('TKT_min' => $order);
1148
-                break;
1149
-            case 'TKT_max':
1150
-                $orderby = array('TKT_max' => $order);
1151
-                break;
1152
-            case 'TKT_qty':
1153
-                $orderby = array('TKT_qty' => $order);
1154
-                break;
1155
-        }
1156
-        $current_page = isset($this->_req_data['paged']) && ! empty($this->_req_data['paged'])
1157
-            ? $this->_req_data['paged']
1158
-            : 1;
1159
-        $per_page     = isset($this->_req_data['perpage']) && ! empty($this->_req_data['perpage'])
1160
-            ? $this->_req_data['perpage']
1161
-            : $per_page;
1162
-        $_where       = array(
1163
-            'TKT_is_default' => 1,
1164
-            'TKT_deleted'    => $trashed,
1165
-        );
1166
-        $offset       = ($current_page - 1) * $per_page;
1167
-        $limit        = array($offset, $per_page);
1168
-        if (isset($this->_req_data['s'])) {
1169
-            $sstr         = '%' . $this->_req_data['s'] . '%';
1170
-            $_where['OR'] = array(
1171
-                'TKT_name'        => array('LIKE', $sstr),
1172
-                'TKT_description' => array('LIKE', $sstr),
1173
-            );
1174
-        }
1175
-        $query_params = array(
1176
-            $_where,
1177
-            'order_by' => $orderby,
1178
-            'limit'    => $limit,
1179
-            'group_by' => 'TKT_ID',
1180
-        );
1181
-        if ($count) {
1182
-            return EEM_Ticket::instance()->count_deleted_and_undeleted(array($_where));
1183
-        } else {
1184
-            return EEM_Ticket::instance()->get_all_deleted_and_undeleted($query_params);
1185
-        }
1186
-    }
1187
-
1188
-
1189
-    /**
1190
-     * @param bool $trash
1191
-     * @throws EE_Error
1192
-     */
1193
-    protected function _trash_or_restore_ticket($trash = false)
1194
-    {
1195
-        $success = 1;
1196
-        $TKT     = EEM_Ticket::instance();
1197
-        //checkboxes?
1198
-        if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
1199
-            //if array has more than one element then success message should be plural
1200
-            $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1;
1201
-            //cycle thru the boxes
1202
-            while (list($TKT_ID, $value) = each($this->_req_data['checkbox'])) {
1203
-                if ($trash) {
1204
-                    if (! $TKT->delete_by_ID($TKT_ID)) {
1205
-                        $success = 0;
1206
-                    }
1207
-                } else {
1208
-                    if (! $TKT->restore_by_ID($TKT_ID)) {
1209
-                        $success = 0;
1210
-                    }
1211
-                }
1212
-            }
1213
-        } else {
1214
-            //grab single id and trash
1215
-            $TKT_ID = absint($this->_req_data['TKT_ID']);
1216
-            if ($trash) {
1217
-                if (! $TKT->delete_by_ID($TKT_ID)) {
1218
-                    $success = 0;
1219
-                }
1220
-            } else {
1221
-                if (! $TKT->restore_by_ID($TKT_ID)) {
1222
-                    $success = 0;
1223
-                }
1224
-            }
1225
-        }
1226
-        $action_desc = $trash ? 'moved to the trash' : 'restored';
1227
-        $query_args  = array(
1228
-            'action' => 'ticket_list_table',
1229
-            'status' => $trash ? '' : 'trashed',
1230
-        );
1231
-        $this->_redirect_after_action($success, 'Tickets', $action_desc, $query_args);
1232
-    }
1233
-
1234
-
1235
-    /**
1236
-     * Handles trashing default ticket.
1237
-     */
1238
-    protected function _delete_ticket()
1239
-    {
1240
-        $success = 1;
1241
-        //checkboxes?
1242
-        if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
1243
-            //if array has more than one element then success message should be plural
1244
-            $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1;
1245
-            //cycle thru the boxes
1246
-            while (list($TKT_ID, $value) = each($this->_req_data['checkbox'])) {
1247
-                //delete
1248
-                if (! $this->_delete_the_ticket($TKT_ID)) {
1249
-                    $success = 0;
1250
-                }
1251
-            }
1252
-        } else {
1253
-            //grab single id and trash
1254
-            $TKT_ID = absint($this->_req_data['TKT_ID']);
1255
-            if (! $this->_delete_the_ticket($TKT_ID)) {
1256
-                $success = 0;
1257
-            }
1258
-        }
1259
-        $action_desc = 'deleted';
1260
-        $query_args  = array(
1261
-            'action' => 'ticket_list_table',
1262
-            'status' => 'trashed',
1263
-        );
1264
-        //fail safe.  If the default ticket count === 1 then we need to redirect to event overview.
1265
-        if (EEM_Ticket::instance()->count_deleted_and_undeleted(
1266
-            array(array('TKT_is_default' => 1)),
1267
-            'TKT_ID',
1268
-            true
1269
-        )
1270
-        ) {
1271
-            $query_args = array();
1272
-        }
1273
-        $this->_redirect_after_action($success, 'Tickets', $action_desc, $query_args);
1274
-    }
1275
-
1276
-
1277
-    /**
1278
-     * @param int $TKT_ID
1279
-     * @return bool|int
1280
-     * @throws EE_Error
1281
-     */
1282
-    protected function _delete_the_ticket($TKT_ID)
1283
-    {
1284
-        $tkt = EEM_Ticket::instance()->get_one_by_ID($TKT_ID);
1285
-        $tkt->_remove_relations('Datetime');
1286
-        //delete all related prices first
1287
-        $tkt->delete_related_permanently('Price');
1288
-        return $tkt->delete_permanently();
1289
-    }
22
+	/**
23
+	 * Extend_Events_Admin_Page constructor.
24
+	 *
25
+	 * @param bool $routing
26
+	 */
27
+	public function __construct($routing = true)
28
+	{
29
+		parent::__construct($routing);
30
+		if (! defined('EVENTS_CAF_TEMPLATE_PATH')) {
31
+			define('EVENTS_CAF_TEMPLATE_PATH', EE_CORE_CAF_ADMIN_EXTEND . 'events/templates/');
32
+			define('EVENTS_CAF_ASSETS', EE_CORE_CAF_ADMIN_EXTEND . 'events/assets/');
33
+			define('EVENTS_CAF_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL . 'events/assets/');
34
+		}
35
+	}
36
+
37
+
38
+	/**
39
+	 * Sets routes.
40
+	 */
41
+	protected function _extend_page_config()
42
+	{
43
+		$this->_admin_base_path = EE_CORE_CAF_ADMIN_EXTEND . 'events';
44
+		//is there a evt_id in the request?
45
+		$evt_id = ! empty($this->_req_data['EVT_ID']) && ! is_array($this->_req_data['EVT_ID'])
46
+			? $this->_req_data['EVT_ID']
47
+			: 0;
48
+		$evt_id = ! empty($this->_req_data['post']) ? $this->_req_data['post'] : $evt_id;
49
+		//tkt_id?
50
+		$tkt_id             = ! empty($this->_req_data['TKT_ID']) && ! is_array($this->_req_data['TKT_ID'])
51
+			? $this->_req_data['TKT_ID']
52
+			: 0;
53
+		$new_page_routes    = array(
54
+			'duplicate_event'          => array(
55
+				'func'       => '_duplicate_event',
56
+				'capability' => 'ee_edit_event',
57
+				'obj_id'     => $evt_id,
58
+				'noheader'   => true,
59
+			),
60
+			'ticket_list_table'        => array(
61
+				'func'       => '_tickets_overview_list_table',
62
+				'capability' => 'ee_read_default_tickets',
63
+			),
64
+			'trash_ticket'             => array(
65
+				'func'       => '_trash_or_restore_ticket',
66
+				'capability' => 'ee_delete_default_ticket',
67
+				'obj_id'     => $tkt_id,
68
+				'noheader'   => true,
69
+				'args'       => array('trash' => true),
70
+			),
71
+			'trash_tickets'            => array(
72
+				'func'       => '_trash_or_restore_ticket',
73
+				'capability' => 'ee_delete_default_tickets',
74
+				'noheader'   => true,
75
+				'args'       => array('trash' => true),
76
+			),
77
+			'restore_ticket'           => array(
78
+				'func'       => '_trash_or_restore_ticket',
79
+				'capability' => 'ee_delete_default_ticket',
80
+				'obj_id'     => $tkt_id,
81
+				'noheader'   => true,
82
+			),
83
+			'restore_tickets'          => array(
84
+				'func'       => '_trash_or_restore_ticket',
85
+				'capability' => 'ee_delete_default_tickets',
86
+				'noheader'   => true,
87
+			),
88
+			'delete_ticket'            => array(
89
+				'func'       => '_delete_ticket',
90
+				'capability' => 'ee_delete_default_ticket',
91
+				'obj_id'     => $tkt_id,
92
+				'noheader'   => true,
93
+			),
94
+			'delete_tickets'           => array(
95
+				'func'       => '_delete_ticket',
96
+				'capability' => 'ee_delete_default_tickets',
97
+				'noheader'   => true,
98
+			),
99
+			'import_page'              => array(
100
+				'func'       => '_import_page',
101
+				'capability' => 'import',
102
+			),
103
+			'import'                   => array(
104
+				'func'       => '_import_events',
105
+				'capability' => 'import',
106
+				'noheader'   => true,
107
+			),
108
+			'import_events'            => array(
109
+				'func'       => '_import_events',
110
+				'capability' => 'import',
111
+				'noheader'   => true,
112
+			),
113
+			'export_events'            => array(
114
+				'func'       => '_events_export',
115
+				'capability' => 'export',
116
+				'noheader'   => true,
117
+			),
118
+			'export_categories'        => array(
119
+				'func'       => '_categories_export',
120
+				'capability' => 'export',
121
+				'noheader'   => true,
122
+			),
123
+			'sample_export_file'       => array(
124
+				'func'       => '_sample_export_file',
125
+				'capability' => 'export',
126
+				'noheader'   => true,
127
+			),
128
+			'update_template_settings' => array(
129
+				'func'       => '_update_template_settings',
130
+				'capability' => 'manage_options',
131
+				'noheader'   => true,
132
+			),
133
+		);
134
+		$this->_page_routes = array_merge($this->_page_routes, $new_page_routes);
135
+		//partial route/config override
136
+		$this->_page_config['import_events']['metaboxes'] = $this->_default_espresso_metaboxes;
137
+		$this->_page_config['create_new']['metaboxes'][]  = '_premium_event_editor_meta_boxes';
138
+		$this->_page_config['create_new']['qtips'][]      = 'EE_Event_Editor_Tips';
139
+		$this->_page_config['edit']['qtips'][]            = 'EE_Event_Editor_Tips';
140
+		$this->_page_config['edit']['metaboxes'][]        = '_premium_event_editor_meta_boxes';
141
+		$this->_page_config['default']['list_table']      = 'Extend_Events_Admin_List_Table';
142
+		//add tickets tab but only if there are more than one default ticket!
143
+		$tkt_count = EEM_Ticket::instance()->count_deleted_and_undeleted(
144
+			array(array('TKT_is_default' => 1)),
145
+			'TKT_ID',
146
+			true
147
+		);
148
+		if ($tkt_count > 1) {
149
+			$new_page_config = array(
150
+				'ticket_list_table' => array(
151
+					'nav'           => array(
152
+						'label' => esc_html__('Default Tickets', 'event_espresso'),
153
+						'order' => 60,
154
+					),
155
+					'list_table'    => 'Tickets_List_Table',
156
+					'require_nonce' => false,
157
+				),
158
+			);
159
+		}
160
+		//template settings
161
+		$new_page_config['template_settings'] = array(
162
+			'nav'           => array(
163
+				'label' => esc_html__('Templates', 'event_espresso'),
164
+				'order' => 30,
165
+			),
166
+			'metaboxes'     => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')),
167
+			'help_tabs'     => array(
168
+				'general_settings_templates_help_tab' => array(
169
+					'title'    => esc_html__('Templates', 'event_espresso'),
170
+					'filename' => 'general_settings_templates',
171
+				),
172
+			),
173
+			'help_tour'     => array('Templates_Help_Tour'),
174
+			'require_nonce' => false,
175
+		);
176
+		$this->_page_config                   = array_merge($this->_page_config, $new_page_config);
177
+		//add filters and actions
178
+		//modifying _views
179
+		add_filter(
180
+			'FHEE_event_datetime_metabox_add_additional_date_time_template',
181
+			array($this, 'add_additional_datetime_button'),
182
+			10,
183
+			2
184
+		);
185
+		add_filter(
186
+			'FHEE_event_datetime_metabox_clone_button_template',
187
+			array($this, 'add_datetime_clone_button'),
188
+			10,
189
+			2
190
+		);
191
+		add_filter(
192
+			'FHEE_event_datetime_metabox_timezones_template',
193
+			array($this, 'datetime_timezones_template'),
194
+			10,
195
+			2
196
+		);
197
+		//filters for event list table
198
+		add_filter('FHEE__Extend_Events_Admin_List_Table__filters', array($this, 'list_table_filters'), 10, 2);
199
+		add_filter(
200
+			'FHEE__Events_Admin_List_Table__column_actions__action_links',
201
+			array($this, 'extra_list_table_actions'),
202
+			10,
203
+			2
204
+		);
205
+		//legend item
206
+		add_filter('FHEE__Events_Admin_Page___event_legend_items__items', array($this, 'additional_legend_items'));
207
+		add_action('admin_init', array($this, 'admin_init'));
208
+		//heartbeat stuff
209
+		add_filter('heartbeat_received', array($this, 'heartbeat_response'), 10, 2);
210
+	}
211
+
212
+
213
+	/**
214
+	 * admin_init
215
+	 */
216
+	public function admin_init()
217
+	{
218
+		EE_Registry::$i18n_js_strings = array_merge(
219
+			EE_Registry::$i18n_js_strings,
220
+			array(
221
+				'image_confirm'          => esc_html__(
222
+					'Do you really want to delete this image? Please remember to update your event to complete the removal.',
223
+					'event_espresso'
224
+				),
225
+				'event_starts_on'        => esc_html__('Event Starts on', 'event_espresso'),
226
+				'event_ends_on'          => esc_html__('Event Ends on', 'event_espresso'),
227
+				'event_datetime_actions' => esc_html__('Actions', 'event_espresso'),
228
+				'event_clone_dt_msg'     => esc_html__('Clone this Event Date and Time', 'event_espresso'),
229
+				'remove_event_dt_msg'    => esc_html__('Remove this Event Time', 'event_espresso'),
230
+			)
231
+		);
232
+	}
233
+
234
+
235
+	/**
236
+	 * This will be used to listen for any heartbeat data packages coming via the WordPress heartbeat API and handle
237
+	 * accordingly.
238
+	 *
239
+	 * @param array $response The existing heartbeat response array.
240
+	 * @param array $data     The incoming data package.
241
+	 * @return array  possibly appended response.
242
+	 */
243
+	public function heartbeat_response($response, $data)
244
+	{
245
+		/**
246
+		 * check whether count of tickets is approaching the potential
247
+		 * limits for the server.
248
+		 */
249
+		if (! empty($data['input_count'])) {
250
+			$response['max_input_vars_check'] = EE_Registry::instance()->CFG->environment->max_input_vars_limit_check(
251
+				$data['input_count']
252
+			);
253
+		}
254
+		return $response;
255
+	}
256
+
257
+
258
+	/**
259
+	 * Add per page screen options to the default ticket list table view.
260
+	 */
261
+	protected function _add_screen_options_ticket_list_table()
262
+	{
263
+		$this->_per_page_screen_option();
264
+	}
265
+
266
+
267
+	/**
268
+	 * @param string $return
269
+	 * @param int    $id
270
+	 * @param string $new_title
271
+	 * @param string $new_slug
272
+	 * @return string
273
+	 */
274
+	public function extra_permalink_field_buttons($return, $id, $new_title, $new_slug)
275
+	{
276
+		$return = parent::extra_permalink_field_buttons($return, $id, $new_title, $new_slug);
277
+		//make sure this is only when editing
278
+		if (! empty($id)) {
279
+			$href   = EE_Admin_Page::add_query_args_and_nonce(
280
+				array('action' => 'duplicate_event', 'EVT_ID' => $id),
281
+				$this->_admin_base_url
282
+			);
283
+			$title  = esc_attr__('Duplicate Event', 'event_espresso');
284
+			$return .= '<a href="'
285
+					   . $href
286
+					   . '" title="'
287
+					   . $title
288
+					   . '" id="ee-duplicate-event-button" class="button button-small"  value="duplicate_event">'
289
+					   . $title
290
+					   . '</a>';
291
+		}
292
+		return $return;
293
+	}
294
+
295
+
296
+	/**
297
+	 * Set the list table views for the default ticket list table view.
298
+	 */
299
+	public function _set_list_table_views_ticket_list_table()
300
+	{
301
+		$this->_views = array(
302
+			'all'     => array(
303
+				'slug'        => 'all',
304
+				'label'       => esc_html__('All', 'event_espresso'),
305
+				'count'       => 0,
306
+				'bulk_action' => array(
307
+					'trash_tickets' => esc_html__('Move to Trash', 'event_espresso'),
308
+				),
309
+			),
310
+			'trashed' => array(
311
+				'slug'        => 'trashed',
312
+				'label'       => esc_html__('Trash', 'event_espresso'),
313
+				'count'       => 0,
314
+				'bulk_action' => array(
315
+					'restore_tickets' => esc_html__('Restore from Trash', 'event_espresso'),
316
+					'delete_tickets'  => esc_html__('Delete Permanently', 'event_espresso'),
317
+				),
318
+			),
319
+		);
320
+	}
321
+
322
+
323
+	/**
324
+	 * Enqueue scripts and styles for the event editor.
325
+	 */
326
+	public function load_scripts_styles_edit()
327
+	{
328
+		wp_register_script(
329
+			'ee-event-editor-heartbeat',
330
+			EVENTS_CAF_ASSETS_URL . 'event-editor-heartbeat.js',
331
+			array('ee_admin_js', 'heartbeat'),
332
+			EVENT_ESPRESSO_VERSION,
333
+			true
334
+		);
335
+		wp_enqueue_script('ee-accounting');
336
+		//styles
337
+		wp_enqueue_style('espresso-ui-theme');
338
+		wp_enqueue_script('event_editor_js');
339
+		wp_enqueue_script('ee-event-editor-heartbeat');
340
+	}
341
+
342
+
343
+	/**
344
+	 * Returns template for the additional datetime.
345
+	 * @param $template
346
+	 * @param $template_args
347
+	 * @return mixed
348
+	 * @throws DomainException
349
+	 */
350
+	public function add_additional_datetime_button($template, $template_args)
351
+	{
352
+		return EEH_Template::display_template(
353
+			EVENTS_CAF_TEMPLATE_PATH . 'event_datetime_add_additional_time.template.php',
354
+			$template_args,
355
+			true
356
+		);
357
+	}
358
+
359
+
360
+	/**
361
+	 * Returns the template for cloning a datetime.
362
+	 * @param $template
363
+	 * @param $template_args
364
+	 * @return mixed
365
+	 * @throws DomainException
366
+	 */
367
+	public function add_datetime_clone_button($template, $template_args)
368
+	{
369
+		return EEH_Template::display_template(
370
+			EVENTS_CAF_TEMPLATE_PATH . 'event_datetime_metabox_clone_button.template.php',
371
+			$template_args,
372
+			true
373
+		);
374
+	}
375
+
376
+
377
+	/**
378
+	 * Returns the template for datetime timezones.
379
+	 * @param $template
380
+	 * @param $template_args
381
+	 * @return mixed
382
+	 * @throws DomainException
383
+	 */
384
+	public function datetime_timezones_template($template, $template_args)
385
+	{
386
+		return EEH_Template::display_template(
387
+			EVENTS_CAF_TEMPLATE_PATH . 'event_datetime_timezones.template.php',
388
+			$template_args,
389
+			true
390
+		);
391
+	}
392
+
393
+
394
+	/**
395
+	 * Sets the views for the default list table view.
396
+	 */
397
+	protected function _set_list_table_views_default()
398
+	{
399
+		parent::_set_list_table_views_default();
400
+		$new_views    = array(
401
+			'today' => array(
402
+				'slug'        => 'today',
403
+				'label'       => esc_html__('Today', 'event_espresso'),
404
+				'count'       => $this->total_events_today(),
405
+				'bulk_action' => array(
406
+					'trash_events' => esc_html__('Move to Trash', 'event_espresso'),
407
+				),
408
+			),
409
+			'month' => array(
410
+				'slug'        => 'month',
411
+				'label'       => esc_html__('This Month', 'event_espresso'),
412
+				'count'       => $this->total_events_this_month(),
413
+				'bulk_action' => array(
414
+					'trash_events' => esc_html__('Move to Trash', 'event_espresso'),
415
+				),
416
+			),
417
+		);
418
+		$this->_views = array_merge($this->_views, $new_views);
419
+	}
420
+
421
+
422
+	/**
423
+	 * Returns the extra action links for the default list table view.
424
+	 * @param array     $action_links
425
+	 * @param \EE_Event $event
426
+	 * @return array
427
+	 * @throws EE_Error
428
+	 */
429
+	public function extra_list_table_actions(array $action_links, \EE_Event $event)
430
+	{
431
+		if (EE_Registry::instance()->CAP->current_user_can(
432
+			'ee_read_registrations',
433
+			'espresso_registrations_reports',
434
+			$event->ID()
435
+		)
436
+		) {
437
+			$reports_query_args = array(
438
+				'action' => 'reports',
439
+				'EVT_ID' => $event->ID(),
440
+			);
441
+			$reports_link       = EE_Admin_Page::add_query_args_and_nonce($reports_query_args, REG_ADMIN_URL);
442
+			$action_links[]     = '<a href="'
443
+								  . $reports_link
444
+								  . '" title="'
445
+								  . esc_attr__('View Report', 'event_espresso')
446
+								  . '"><div class="dashicons dashicons-chart-bar"></div></a>'
447
+								  . "\n\t";
448
+		}
449
+		if (EE_Registry::instance()->CAP->current_user_can('ee_read_global_messages', 'view_filtered_messages')) {
450
+			EE_Registry::instance()->load_helper('MSG_Template');
451
+			$action_links[] = EEH_MSG_Template::get_message_action_link(
452
+				'see_notifications_for',
453
+				null,
454
+				array('EVT_ID' => $event->ID())
455
+			);
456
+		}
457
+		return $action_links;
458
+	}
459
+
460
+
461
+	/**
462
+	 * @param $items
463
+	 * @return mixed
464
+	 */
465
+	public function additional_legend_items($items)
466
+	{
467
+		if (EE_Registry::instance()->CAP->current_user_can(
468
+			'ee_read_registrations',
469
+			'espresso_registrations_reports'
470
+		)
471
+		) {
472
+			$items['reports'] = array(
473
+				'class' => 'dashicons dashicons-chart-bar',
474
+				'desc'  => esc_html__('Event Reports', 'event_espresso'),
475
+			);
476
+		}
477
+		if (EE_Registry::instance()->CAP->current_user_can('ee_read_global_messages', 'view_filtered_messages')) {
478
+			$related_for_icon = EEH_MSG_Template::get_message_action_icon('see_notifications_for');
479
+			if (isset($related_for_icon['css_class']) && isset($related_for_icon['label'])) {
480
+				$items['view_related_messages'] = array(
481
+					'class' => $related_for_icon['css_class'],
482
+					'desc'  => $related_for_icon['label'],
483
+				);
484
+			}
485
+		}
486
+		return $items;
487
+	}
488
+
489
+
490
+	/**
491
+	 * This is the callback method for the duplicate event route
492
+	 * Method looks for 'EVT_ID' in the request and retrieves that event and its details and duplicates them
493
+	 * into a new event.  We add a hook so that any plugins that add extra event details can hook into this
494
+	 * action.  Note that the dupe will have **DUPLICATE** as its title and slug.
495
+	 * After duplication the redirect is to the new event edit page.
496
+	 *
497
+	 * @return void
498
+	 * @access protected
499
+	 * @throws EE_Error If EE_Event is not available with given ID
500
+	 */
501
+	protected function _duplicate_event()
502
+	{
503
+		// first make sure the ID for the event is in the request.
504
+		//  If it isn't then we need to bail and redirect back to overview list table (cause how did we get here?)
505
+		if (! isset($this->_req_data['EVT_ID'])) {
506
+			EE_Error::add_error(
507
+				esc_html__(
508
+					'In order to duplicate an event an Event ID is required.  None was given.',
509
+					'event_espresso'
510
+				),
511
+				__FILE__,
512
+				__FUNCTION__,
513
+				__LINE__
514
+			);
515
+			$this->_redirect_after_action(false, '', '', array(), true);
516
+			return;
517
+		}
518
+		//k we've got EVT_ID so let's use that to get the event we'll duplicate
519
+		$orig_event = EEM_Event::instance()->get_one_by_ID($this->_req_data['EVT_ID']);
520
+		if (! $orig_event instanceof EE_Event) {
521
+			throw new EE_Error(
522
+				sprintf(
523
+					esc_html__('An EE_Event object could not be retrieved for the given ID (%s)', 'event_espresso'),
524
+					$this->_req_data['EVT_ID']
525
+				)
526
+			);
527
+		}
528
+		//k now let's clone the $orig_event before getting relations
529
+		$new_event = clone $orig_event;
530
+		//original datetimes
531
+		$orig_datetimes = $orig_event->get_many_related('Datetime');
532
+		//other original relations
533
+		$orig_ven = $orig_event->get_many_related('Venue');
534
+		//reset the ID and modify other details to make it clear this is a dupe
535
+		$new_event->set('EVT_ID', 0);
536
+		$new_name = $new_event->name() . ' ' . esc_html__('**DUPLICATE**', 'event_espresso');
537
+		$new_event->set('EVT_name', $new_name);
538
+		$new_event->set(
539
+			'EVT_slug',
540
+			wp_unique_post_slug(
541
+				sanitize_title($orig_event->name()),
542
+				0,
543
+				'publish',
544
+				'espresso_events',
545
+				0
546
+			)
547
+		);
548
+		$new_event->set('status', 'draft');
549
+		//duplicate discussion settings
550
+		$new_event->set('comment_status', $orig_event->get('comment_status'));
551
+		$new_event->set('ping_status', $orig_event->get('ping_status'));
552
+		//save the new event
553
+		$new_event->save();
554
+		//venues
555
+		foreach ($orig_ven as $ven) {
556
+			$new_event->_add_relation_to($ven, 'Venue');
557
+		}
558
+		$new_event->save();
559
+		//now we need to get the question group relations and handle that
560
+		//first primary question groups
561
+		$orig_primary_qgs = $orig_event->get_many_related(
562
+			'Question_Group',
563
+			array(array('Event_Question_Group.EQG_primary' => 1))
564
+		);
565
+		if (! empty($orig_primary_qgs)) {
566
+			foreach ($orig_primary_qgs as $id => $obj) {
567
+				if ($obj instanceof EE_Question_Group) {
568
+					$new_event->_add_relation_to($obj, 'Question_Group', array('EQG_primary' => 1));
569
+				}
570
+			}
571
+		}
572
+		//next additional attendee question groups
573
+		$orig_additional_qgs = $orig_event->get_many_related(
574
+			'Question_Group',
575
+			array(array('Event_Question_Group.EQG_primary' => 0))
576
+		);
577
+		if (! empty($orig_additional_qgs)) {
578
+			foreach ($orig_additional_qgs as $id => $obj) {
579
+				if ($obj instanceof EE_Question_Group) {
580
+					$new_event->_add_relation_to($obj, 'Question_Group', array('EQG_primary' => 0));
581
+				}
582
+			}
583
+		}
584
+
585
+		$new_event->save();
586
+
587
+		//k now that we have the new event saved we can loop through the datetimes and start adding relations.
588
+		$cloned_tickets = array();
589
+		foreach ($orig_datetimes as $orig_dtt) {
590
+			if (! $orig_dtt instanceof EE_Datetime) {
591
+				continue;
592
+			}
593
+			$new_dtt   = clone $orig_dtt;
594
+			$orig_tkts = $orig_dtt->tickets();
595
+			//save new dtt then add to event
596
+			$new_dtt->set('DTT_ID', 0);
597
+			$new_dtt->set('DTT_sold', 0);
598
+			$new_dtt->set_reserved(0);
599
+			$new_dtt->save();
600
+			$new_event->_add_relation_to($new_dtt, 'Datetime');
601
+			$new_event->save();
602
+			//now let's get the ticket relations setup.
603
+			foreach ((array)$orig_tkts as $orig_tkt) {
604
+				//it's possible a datetime will have no tickets so let's verify we HAVE a ticket first.
605
+				if (! $orig_tkt instanceof EE_Ticket) {
606
+					continue;
607
+				}
608
+				//is this ticket archived?  If it is then let's skip
609
+				if ($orig_tkt->get('TKT_deleted')) {
610
+					continue;
611
+				}
612
+				// does this original ticket already exist in the clone_tickets cache?
613
+				//  If so we'll just use the new ticket from it.
614
+				if (isset($cloned_tickets[$orig_tkt->ID()])) {
615
+					$new_tkt = $cloned_tickets[$orig_tkt->ID()];
616
+				} else {
617
+					$new_tkt = clone $orig_tkt;
618
+					//get relations on the $orig_tkt that we need to setup.
619
+					$orig_prices = $orig_tkt->prices();
620
+					$new_tkt->set('TKT_ID', 0);
621
+					$new_tkt->set('TKT_sold', 0);
622
+					$new_tkt->set('TKT_reserved', 0);
623
+					$new_tkt->save(); //make sure new ticket has ID.
624
+					//price relations on new ticket need to be setup.
625
+					foreach ($orig_prices as $orig_price) {
626
+						$new_price = clone $orig_price;
627
+						$new_price->set('PRC_ID', 0);
628
+						$new_price->save();
629
+						$new_tkt->_add_relation_to($new_price, 'Price');
630
+						$new_tkt->save();
631
+					}
632
+
633
+					do_action(
634
+						'AHEE__Extend_Events_Admin_Page___duplicate_event__duplicate_ticket__after',
635
+						$orig_tkt,
636
+						$new_tkt,
637
+						$orig_prices,
638
+						$orig_event,
639
+						$orig_dtt,
640
+						$new_dtt
641
+					);
642
+				}
643
+				// k now we can add the new ticket as a relation to the new datetime
644
+				// and make sure its added to our cached $cloned_tickets array
645
+				// for use with later datetimes that have the same ticket.
646
+				$new_dtt->_add_relation_to($new_tkt, 'Ticket');
647
+				$new_dtt->save();
648
+				$cloned_tickets[$orig_tkt->ID()] = $new_tkt;
649
+			}
650
+		}
651
+		//clone taxonomy information
652
+		$taxonomies_to_clone_with = apply_filters(
653
+			'FHEE__Extend_Events_Admin_Page___duplicate_event__taxonomies_to_clone',
654
+			array('espresso_event_categories', 'espresso_event_type', 'post_tag')
655
+		);
656
+		//get terms for original event (notice)
657
+		$orig_terms = wp_get_object_terms($orig_event->ID(), $taxonomies_to_clone_with);
658
+		//loop through terms and add them to new event.
659
+		foreach ($orig_terms as $term) {
660
+			wp_set_object_terms($new_event->ID(), $term->term_id, $term->taxonomy, true);
661
+		}
662
+
663
+		//duplicate other core WP_Post items for this event.
664
+		//post thumbnail (feature image).
665
+		$feature_image_id = get_post_thumbnail_id($orig_event->ID());
666
+		if ($feature_image_id) {
667
+			update_post_meta($new_event->ID(), '_thumbnail_id', $feature_image_id);
668
+		}
669
+
670
+		//duplicate page_template setting
671
+		$page_template = get_post_meta($orig_event->ID(), '_wp_page_template', true);
672
+		if ($page_template) {
673
+			update_post_meta($new_event->ID(), '_wp_page_template', $page_template);
674
+		}
675
+
676
+		do_action('AHEE__Extend_Events_Admin_Page___duplicate_event__after', $new_event, $orig_event);
677
+		//now let's redirect to the edit page for this duplicated event if we have a new event id.
678
+		if ($new_event->ID()) {
679
+			$redirect_args = array(
680
+				'post'   => $new_event->ID(),
681
+				'action' => 'edit',
682
+			);
683
+			EE_Error::add_success(
684
+				esc_html__(
685
+					'Event successfully duplicated.  Please review the details below and make any necessary edits',
686
+					'event_espresso'
687
+				)
688
+			);
689
+		} else {
690
+			$redirect_args = array(
691
+				'action' => 'default',
692
+			);
693
+			EE_Error::add_error(
694
+				esc_html__('Not able to duplicate event.  Something went wrong.', 'event_espresso'),
695
+				__FILE__,
696
+				__FUNCTION__,
697
+				__LINE__
698
+			);
699
+		}
700
+		$this->_redirect_after_action(false, '', '', $redirect_args, true);
701
+	}
702
+
703
+
704
+	/**
705
+	 * Generates output for the import page.
706
+	 * @throws DomainException
707
+	 */
708
+	protected function _import_page()
709
+	{
710
+		$title                                      = esc_html__('Import', 'event_espresso');
711
+		$intro                                      = esc_html__(
712
+			'If you have a previously exported Event Espresso 4 information in a Comma Separated Value (CSV) file format, you can upload the file here: ',
713
+			'event_espresso'
714
+		);
715
+		$form_url                                   = EVENTS_ADMIN_URL;
716
+		$action                                     = 'import_events';
717
+		$type                                       = 'csv';
718
+		$this->_template_args['form']               = EE_Import::instance()->upload_form(
719
+			$title, $intro, $form_url, $action, $type
720
+		);
721
+		$this->_template_args['sample_file_link']   = EE_Admin_Page::add_query_args_and_nonce(
722
+			array('action' => 'sample_export_file'),
723
+			$this->_admin_base_url
724
+		);
725
+		$content                                    = EEH_Template::display_template(
726
+			EVENTS_CAF_TEMPLATE_PATH . 'import_page.template.php',
727
+			$this->_template_args,
728
+			true
729
+		);
730
+		$this->_template_args['admin_page_content'] = $content;
731
+		$this->display_admin_page_with_sidebar();
732
+	}
733
+
734
+
735
+	/**
736
+	 * _import_events
737
+	 * This handles displaying the screen and running imports for importing events.
738
+	 *
739
+	 * @return void
740
+	 */
741
+	protected function _import_events()
742
+	{
743
+		require_once(EE_CLASSES . 'EE_Import.class.php');
744
+		$success = EE_Import::instance()->import();
745
+		$this->_redirect_after_action($success, 'Import File', 'ran', array('action' => 'import_page'), true);
746
+	}
747
+
748
+
749
+	/**
750
+	 * _events_export
751
+	 * Will export all (or just the given event) to a Excel compatible file.
752
+	 *
753
+	 * @access protected
754
+	 * @return void
755
+	 */
756
+	protected function _events_export()
757
+	{
758
+		if (isset($this->_req_data['EVT_ID'])) {
759
+			$event_ids = $this->_req_data['EVT_ID'];
760
+		} elseif (isset($this->_req_data['EVT_IDs'])) {
761
+			$event_ids = $this->_req_data['EVT_IDs'];
762
+		} else {
763
+			$event_ids = null;
764
+		}
765
+		//todo: I don't like doing this but it'll do until we modify EE_Export Class.
766
+		$new_request_args = array(
767
+			'export' => 'report',
768
+			'action' => 'all_event_data',
769
+			'EVT_ID' => $event_ids,
770
+		);
771
+		$this->_req_data  = array_merge($this->_req_data, $new_request_args);
772
+		if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
773
+			require_once(EE_CLASSES . 'EE_Export.class.php');
774
+			$EE_Export = EE_Export::instance($this->_req_data);
775
+			$EE_Export->export();
776
+		}
777
+	}
778
+
779
+
780
+	/**
781
+	 * handle category exports()
782
+	 *
783
+	 * @return void
784
+	 */
785
+	protected function _categories_export()
786
+	{
787
+		//todo: I don't like doing this but it'll do until we modify EE_Export Class.
788
+		$new_request_args = array(
789
+			'export'       => 'report',
790
+			'action'       => 'categories',
791
+			'category_ids' => $this->_req_data['EVT_CAT_ID'],
792
+		);
793
+		$this->_req_data  = array_merge($this->_req_data, $new_request_args);
794
+		if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
795
+			require_once(EE_CLASSES . 'EE_Export.class.php');
796
+			$EE_Export = EE_Export::instance($this->_req_data);
797
+			$EE_Export->export();
798
+		}
799
+	}
800
+
801
+
802
+	/**
803
+	 * Creates a sample CSV file for importing
804
+	 */
805
+	protected function _sample_export_file()
806
+	{
807
+		//		require_once(EE_CLASSES . 'EE_Export.class.php');
808
+		EE_Export::instance()->export_sample();
809
+	}
810
+
811
+
812
+	/*************        Template Settings        *************/
813
+	/**
814
+	 * Generates template settings page output
815
+	 * @throws DomainException
816
+	 * @throws EE_Error
817
+	 */
818
+	protected function _template_settings()
819
+	{
820
+		$this->_template_args['values'] = $this->_yes_no_values;
821
+		/**
822
+		 * Note leaving this filter in for backward compatibility this was moved in 4.6.x
823
+		 * from General_Settings_Admin_Page to here.
824
+		 */
825
+		$this->_template_args = apply_filters(
826
+			'FHEE__General_Settings_Admin_Page__template_settings__template_args',
827
+			$this->_template_args
828
+		);
829
+		$this->_set_add_edit_form_tags('update_template_settings');
830
+		$this->_set_publish_post_box_vars(null, false, false, null, false);
831
+		$this->_template_args['admin_page_content'] = EEH_Template::display_template(
832
+			EVENTS_CAF_TEMPLATE_PATH . 'template_settings.template.php',
833
+			$this->_template_args,
834
+			true
835
+		);
836
+		$this->display_admin_page_with_sidebar();
837
+	}
838
+
839
+
840
+	/**
841
+	 * Handler for updating template settings.
842
+	 *
843
+	 * @throws InvalidInterfaceException
844
+	 * @throws InvalidDataTypeException
845
+	 * @throws InvalidArgumentException
846
+	 */
847
+	protected function _update_template_settings()
848
+	{
849
+		/**
850
+		 * Note leaving this filter in for backward compatibility this was moved in 4.6.x
851
+		 * from General_Settings_Admin_Page to here.
852
+		 */
853
+		EE_Registry::instance()->CFG->template_settings = apply_filters(
854
+			'FHEE__General_Settings_Admin_Page__update_template_settings__data',
855
+			EE_Registry::instance()->CFG->template_settings,
856
+			$this->_req_data
857
+		);
858
+		//update custom post type slugs and detect if we need to flush rewrite rules
859
+		$old_slug                                          = EE_Registry::instance()->CFG->core->event_cpt_slug;
860
+		EE_Registry::instance()->CFG->core->event_cpt_slug = empty($this->_req_data['event_cpt_slug'])
861
+			? EE_Registry::instance()->CFG->core->event_cpt_slug
862
+			: sanitize_title_with_dashes($this->_req_data['event_cpt_slug']);
863
+		$what                                              = 'Template Settings';
864
+		$success                                           = $this->_update_espresso_configuration(
865
+			$what,
866
+			EE_Registry::instance()->CFG->template_settings,
867
+			__FILE__,
868
+			__FUNCTION__,
869
+			__LINE__
870
+		);
871
+		if (EE_Registry::instance()->CFG->core->event_cpt_slug != $old_slug) {
872
+			/** @var EventEspresso\core\domain\services\custom_post_types\RewriteRules $rewrite_rules */
873
+			$rewrite_rules =  LoaderFactory::getLoader()->getShared(
874
+				'EventEspresso\core\domain\services\custom_post_types\RewriteRules'
875
+			);
876
+			$rewrite_rules->flush();
877
+		}
878
+		$this->_redirect_after_action($success, $what, 'updated', array('action' => 'template_settings'));
879
+	}
880
+
881
+
882
+	/**
883
+	 * _premium_event_editor_meta_boxes
884
+	 * add all metaboxes related to the event_editor
885
+	 *
886
+	 * @access protected
887
+	 * @return void
888
+	 * @throws EE_Error
889
+	 */
890
+	protected function _premium_event_editor_meta_boxes()
891
+	{
892
+		$this->verify_cpt_object();
893
+		add_meta_box(
894
+			'espresso_event_editor_event_options',
895
+			esc_html__('Event Registration Options', 'event_espresso'),
896
+			array($this, 'registration_options_meta_box'),
897
+			$this->page_slug,
898
+			'side',
899
+			'core'
900
+		);
901
+	}
902
+
903
+
904
+	/**
905
+	 * override caf metabox
906
+	 *
907
+	 * @return void
908
+	 * @throws DomainException
909
+	 */
910
+	public function registration_options_meta_box()
911
+	{
912
+		$yes_no_values                                    = array(
913
+			array('id' => true, 'text' => esc_html__('Yes', 'event_espresso')),
914
+			array('id' => false, 'text' => esc_html__('No', 'event_espresso')),
915
+		);
916
+		$default_reg_status_values                        = EEM_Registration::reg_status_array(
917
+			array(
918
+				EEM_Registration::status_id_cancelled,
919
+				EEM_Registration::status_id_declined,
920
+				EEM_Registration::status_id_incomplete,
921
+				EEM_Registration::status_id_wait_list,
922
+			),
923
+			true
924
+		);
925
+		$template_args['active_status']                   = $this->_cpt_model_obj->pretty_active_status(false);
926
+		$template_args['_event']                          = $this->_cpt_model_obj;
927
+		$template_args['additional_limit']                = $this->_cpt_model_obj->additional_limit();
928
+		$template_args['default_registration_status']     = EEH_Form_Fields::select_input(
929
+			'default_reg_status',
930
+			$default_reg_status_values,
931
+			$this->_cpt_model_obj->default_registration_status()
932
+		);
933
+		$template_args['display_description']             = EEH_Form_Fields::select_input(
934
+			'display_desc',
935
+			$yes_no_values,
936
+			$this->_cpt_model_obj->display_description()
937
+		);
938
+		$template_args['display_ticket_selector']         = EEH_Form_Fields::select_input(
939
+			'display_ticket_selector',
940
+			$yes_no_values,
941
+			$this->_cpt_model_obj->display_ticket_selector(),
942
+			'',
943
+			'',
944
+			false
945
+		);
946
+		$template_args['EVT_default_registration_status'] = EEH_Form_Fields::select_input(
947
+			'EVT_default_registration_status',
948
+			$default_reg_status_values,
949
+			$this->_cpt_model_obj->default_registration_status()
950
+		);
951
+		$template_args['additional_registration_options'] = apply_filters(
952
+			'FHEE__Events_Admin_Page__registration_options_meta_box__additional_registration_options',
953
+			'',
954
+			$template_args,
955
+			$yes_no_values,
956
+			$default_reg_status_values
957
+		);
958
+		EEH_Template::display_template(
959
+			EVENTS_CAF_TEMPLATE_PATH . 'event_registration_options.template.php',
960
+			$template_args
961
+		);
962
+	}
963
+
964
+
965
+
966
+	/**
967
+	 * wp_list_table_mods for caf
968
+	 * ============================
969
+	 */
970
+	/**
971
+	 * hook into list table filters and provide filters for caffeinated list table
972
+	 *
973
+	 * @param  array $old_filters    any existing filters present
974
+	 * @param  array $list_table_obj the list table object
975
+	 * @return array                  new filters
976
+	 */
977
+	public function list_table_filters($old_filters, $list_table_obj)
978
+	{
979
+		$filters = array();
980
+		//first month/year filters
981
+		$filters[] = $this->espresso_event_months_dropdown();
982
+		$status    = isset($this->_req_data['status']) ? $this->_req_data['status'] : null;
983
+		//active status dropdown
984
+		if ($status !== 'draft') {
985
+			$filters[] = $this->active_status_dropdown(
986
+				isset($this->_req_data['active_status']) ? $this->_req_data['active_status'] : ''
987
+			);
988
+		}
989
+		//category filter
990
+		$filters[] = $this->category_dropdown();
991
+		return array_merge($old_filters, $filters);
992
+	}
993
+
994
+
995
+	/**
996
+	 * espresso_event_months_dropdown
997
+	 *
998
+	 * @access public
999
+	 * @return string                dropdown listing month/year selections for events.
1000
+	 */
1001
+	public function espresso_event_months_dropdown()
1002
+	{
1003
+		// what we need to do is get all PRIMARY datetimes for all events to filter on.
1004
+		// Note we need to include any other filters that are set!
1005
+		$status = isset($this->_req_data['status']) ? $this->_req_data['status'] : null;
1006
+		//categories?
1007
+		$category = isset($this->_req_data['EVT_CAT']) && $this->_req_data['EVT_CAT'] > 0
1008
+			? $this->_req_data['EVT_CAT']
1009
+			: null;
1010
+		//active status?
1011
+		$active_status = isset($this->_req_data['active_status']) ? $this->_req_data['active_status'] : null;
1012
+		$cur_date      = isset($this->_req_data['month_range']) ? $this->_req_data['month_range'] : '';
1013
+		return EEH_Form_Fields::generate_event_months_dropdown($cur_date, $status, $category, $active_status);
1014
+	}
1015
+
1016
+
1017
+	/**
1018
+	 * returns a list of "active" statuses on the event
1019
+	 *
1020
+	 * @param  string $current_value whatever the current active status is
1021
+	 * @return string
1022
+	 */
1023
+	public function active_status_dropdown($current_value = '')
1024
+	{
1025
+		$select_name = 'active_status';
1026
+		$values      = array(
1027
+			'none'     => esc_html__('Show Active/Inactive', 'event_espresso'),
1028
+			'active'   => esc_html__('Active', 'event_espresso'),
1029
+			'upcoming' => esc_html__('Upcoming', 'event_espresso'),
1030
+			'expired'  => esc_html__('Expired', 'event_espresso'),
1031
+			'inactive' => esc_html__('Inactive', 'event_espresso'),
1032
+		);
1033
+		$id          = 'id="espresso-active-status-dropdown-filter"';
1034
+		$class       = 'wide';
1035
+		return EEH_Form_Fields::select_input($select_name, $values, $current_value, $id, $class);
1036
+	}
1037
+
1038
+
1039
+	/**
1040
+	 * output a dropdown of the categories for the category filter on the event admin list table
1041
+	 *
1042
+	 * @access  public
1043
+	 * @return string html
1044
+	 */
1045
+	public function category_dropdown()
1046
+	{
1047
+		$cur_cat = isset($this->_req_data['EVT_CAT']) ? $this->_req_data['EVT_CAT'] : -1;
1048
+		return EEH_Form_Fields::generate_event_category_dropdown($cur_cat);
1049
+	}
1050
+
1051
+
1052
+	/**
1053
+	 * get total number of events today
1054
+	 *
1055
+	 * @access public
1056
+	 * @return int
1057
+	 * @throws EE_Error
1058
+	 */
1059
+	public function total_events_today()
1060
+	{
1061
+		$start = EEM_Datetime::instance()->convert_datetime_for_query(
1062
+			'DTT_EVT_start',
1063
+			date('Y-m-d') . ' 00:00:00',
1064
+			'Y-m-d H:i:s',
1065
+			'UTC'
1066
+		);
1067
+		$end   = EEM_Datetime::instance()->convert_datetime_for_query(
1068
+			'DTT_EVT_start',
1069
+			date('Y-m-d') . ' 23:59:59',
1070
+			'Y-m-d H:i:s',
1071
+			'UTC'
1072
+		);
1073
+		$where = array(
1074
+			'Datetime.DTT_EVT_start' => array('BETWEEN', array($start, $end)),
1075
+		);
1076
+		$count = EEM_Event::instance()->count(array($where, 'caps' => 'read_admin'), 'EVT_ID', true);
1077
+		return $count;
1078
+	}
1079
+
1080
+
1081
+	/**
1082
+	 * get total number of events this month
1083
+	 *
1084
+	 * @access public
1085
+	 * @return int
1086
+	 * @throws EE_Error
1087
+	 */
1088
+	public function total_events_this_month()
1089
+	{
1090
+		//Dates
1091
+		$this_year_r     = date('Y');
1092
+		$this_month_r    = date('m');
1093
+		$days_this_month = date('t');
1094
+		$start           = EEM_Datetime::instance()->convert_datetime_for_query(
1095
+			'DTT_EVT_start',
1096
+			$this_year_r . '-' . $this_month_r . '-01 00:00:00',
1097
+			'Y-m-d H:i:s',
1098
+			'UTC'
1099
+		);
1100
+		$end             = EEM_Datetime::instance()->convert_datetime_for_query(
1101
+			'DTT_EVT_start',
1102
+			$this_year_r . '-' . $this_month_r . '-' . $days_this_month . ' 23:59:59',
1103
+			'Y-m-d H:i:s',
1104
+			'UTC'
1105
+		);
1106
+		$where           = array(
1107
+			'Datetime.DTT_EVT_start' => array('BETWEEN', array($start, $end)),
1108
+		);
1109
+		$count           = EEM_Event::instance()->count(array($where, 'caps' => 'read_admin'), 'EVT_ID', true);
1110
+		return $count;
1111
+	}
1112
+
1113
+
1114
+	/** DEFAULT TICKETS STUFF **/
1115
+
1116
+	/**
1117
+	 * Output default tickets list table view.
1118
+	 */
1119
+	public function _tickets_overview_list_table()
1120
+	{
1121
+		$this->_search_btn_label = esc_html__('Tickets', 'event_espresso');
1122
+		$this->display_admin_list_table_page_with_no_sidebar();
1123
+	}
1124
+
1125
+
1126
+	/**
1127
+	 * @param int  $per_page
1128
+	 * @param bool $count
1129
+	 * @param bool $trashed
1130
+	 * @return \EE_Soft_Delete_Base_Class[]|int
1131
+	 */
1132
+	public function get_default_tickets($per_page = 10, $count = false, $trashed = false)
1133
+	{
1134
+		$orderby = empty($this->_req_data['orderby']) ? 'TKT_name' : $this->_req_data['orderby'];
1135
+		$order   = empty($this->_req_data['order']) ? 'ASC' : $this->_req_data['order'];
1136
+		switch ($orderby) {
1137
+			case 'TKT_name':
1138
+				$orderby = array('TKT_name' => $order);
1139
+				break;
1140
+			case 'TKT_price':
1141
+				$orderby = array('TKT_price' => $order);
1142
+				break;
1143
+			case 'TKT_uses':
1144
+				$orderby = array('TKT_uses' => $order);
1145
+				break;
1146
+			case 'TKT_min':
1147
+				$orderby = array('TKT_min' => $order);
1148
+				break;
1149
+			case 'TKT_max':
1150
+				$orderby = array('TKT_max' => $order);
1151
+				break;
1152
+			case 'TKT_qty':
1153
+				$orderby = array('TKT_qty' => $order);
1154
+				break;
1155
+		}
1156
+		$current_page = isset($this->_req_data['paged']) && ! empty($this->_req_data['paged'])
1157
+			? $this->_req_data['paged']
1158
+			: 1;
1159
+		$per_page     = isset($this->_req_data['perpage']) && ! empty($this->_req_data['perpage'])
1160
+			? $this->_req_data['perpage']
1161
+			: $per_page;
1162
+		$_where       = array(
1163
+			'TKT_is_default' => 1,
1164
+			'TKT_deleted'    => $trashed,
1165
+		);
1166
+		$offset       = ($current_page - 1) * $per_page;
1167
+		$limit        = array($offset, $per_page);
1168
+		if (isset($this->_req_data['s'])) {
1169
+			$sstr         = '%' . $this->_req_data['s'] . '%';
1170
+			$_where['OR'] = array(
1171
+				'TKT_name'        => array('LIKE', $sstr),
1172
+				'TKT_description' => array('LIKE', $sstr),
1173
+			);
1174
+		}
1175
+		$query_params = array(
1176
+			$_where,
1177
+			'order_by' => $orderby,
1178
+			'limit'    => $limit,
1179
+			'group_by' => 'TKT_ID',
1180
+		);
1181
+		if ($count) {
1182
+			return EEM_Ticket::instance()->count_deleted_and_undeleted(array($_where));
1183
+		} else {
1184
+			return EEM_Ticket::instance()->get_all_deleted_and_undeleted($query_params);
1185
+		}
1186
+	}
1187
+
1188
+
1189
+	/**
1190
+	 * @param bool $trash
1191
+	 * @throws EE_Error
1192
+	 */
1193
+	protected function _trash_or_restore_ticket($trash = false)
1194
+	{
1195
+		$success = 1;
1196
+		$TKT     = EEM_Ticket::instance();
1197
+		//checkboxes?
1198
+		if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
1199
+			//if array has more than one element then success message should be plural
1200
+			$success = count($this->_req_data['checkbox']) > 1 ? 2 : 1;
1201
+			//cycle thru the boxes
1202
+			while (list($TKT_ID, $value) = each($this->_req_data['checkbox'])) {
1203
+				if ($trash) {
1204
+					if (! $TKT->delete_by_ID($TKT_ID)) {
1205
+						$success = 0;
1206
+					}
1207
+				} else {
1208
+					if (! $TKT->restore_by_ID($TKT_ID)) {
1209
+						$success = 0;
1210
+					}
1211
+				}
1212
+			}
1213
+		} else {
1214
+			//grab single id and trash
1215
+			$TKT_ID = absint($this->_req_data['TKT_ID']);
1216
+			if ($trash) {
1217
+				if (! $TKT->delete_by_ID($TKT_ID)) {
1218
+					$success = 0;
1219
+				}
1220
+			} else {
1221
+				if (! $TKT->restore_by_ID($TKT_ID)) {
1222
+					$success = 0;
1223
+				}
1224
+			}
1225
+		}
1226
+		$action_desc = $trash ? 'moved to the trash' : 'restored';
1227
+		$query_args  = array(
1228
+			'action' => 'ticket_list_table',
1229
+			'status' => $trash ? '' : 'trashed',
1230
+		);
1231
+		$this->_redirect_after_action($success, 'Tickets', $action_desc, $query_args);
1232
+	}
1233
+
1234
+
1235
+	/**
1236
+	 * Handles trashing default ticket.
1237
+	 */
1238
+	protected function _delete_ticket()
1239
+	{
1240
+		$success = 1;
1241
+		//checkboxes?
1242
+		if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
1243
+			//if array has more than one element then success message should be plural
1244
+			$success = count($this->_req_data['checkbox']) > 1 ? 2 : 1;
1245
+			//cycle thru the boxes
1246
+			while (list($TKT_ID, $value) = each($this->_req_data['checkbox'])) {
1247
+				//delete
1248
+				if (! $this->_delete_the_ticket($TKT_ID)) {
1249
+					$success = 0;
1250
+				}
1251
+			}
1252
+		} else {
1253
+			//grab single id and trash
1254
+			$TKT_ID = absint($this->_req_data['TKT_ID']);
1255
+			if (! $this->_delete_the_ticket($TKT_ID)) {
1256
+				$success = 0;
1257
+			}
1258
+		}
1259
+		$action_desc = 'deleted';
1260
+		$query_args  = array(
1261
+			'action' => 'ticket_list_table',
1262
+			'status' => 'trashed',
1263
+		);
1264
+		//fail safe.  If the default ticket count === 1 then we need to redirect to event overview.
1265
+		if (EEM_Ticket::instance()->count_deleted_and_undeleted(
1266
+			array(array('TKT_is_default' => 1)),
1267
+			'TKT_ID',
1268
+			true
1269
+		)
1270
+		) {
1271
+			$query_args = array();
1272
+		}
1273
+		$this->_redirect_after_action($success, 'Tickets', $action_desc, $query_args);
1274
+	}
1275
+
1276
+
1277
+	/**
1278
+	 * @param int $TKT_ID
1279
+	 * @return bool|int
1280
+	 * @throws EE_Error
1281
+	 */
1282
+	protected function _delete_the_ticket($TKT_ID)
1283
+	{
1284
+		$tkt = EEM_Ticket::instance()->get_one_by_ID($TKT_ID);
1285
+		$tkt->_remove_relations('Datetime');
1286
+		//delete all related prices first
1287
+		$tkt->delete_related_permanently('Price');
1288
+		return $tkt->delete_permanently();
1289
+	}
1290 1290
 }
Please login to merge, or discard this patch.
Spacing   +54 added lines, -54 removed lines patch added patch discarded remove patch
@@ -27,10 +27,10 @@  discard block
 block discarded – undo
27 27
     public function __construct($routing = true)
28 28
     {
29 29
         parent::__construct($routing);
30
-        if (! defined('EVENTS_CAF_TEMPLATE_PATH')) {
31
-            define('EVENTS_CAF_TEMPLATE_PATH', EE_CORE_CAF_ADMIN_EXTEND . 'events/templates/');
32
-            define('EVENTS_CAF_ASSETS', EE_CORE_CAF_ADMIN_EXTEND . 'events/assets/');
33
-            define('EVENTS_CAF_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL . 'events/assets/');
30
+        if ( ! defined('EVENTS_CAF_TEMPLATE_PATH')) {
31
+            define('EVENTS_CAF_TEMPLATE_PATH', EE_CORE_CAF_ADMIN_EXTEND.'events/templates/');
32
+            define('EVENTS_CAF_ASSETS', EE_CORE_CAF_ADMIN_EXTEND.'events/assets/');
33
+            define('EVENTS_CAF_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL.'events/assets/');
34 34
         }
35 35
     }
36 36
 
@@ -40,7 +40,7 @@  discard block
 block discarded – undo
40 40
      */
41 41
     protected function _extend_page_config()
42 42
     {
43
-        $this->_admin_base_path = EE_CORE_CAF_ADMIN_EXTEND . 'events';
43
+        $this->_admin_base_path = EE_CORE_CAF_ADMIN_EXTEND.'events';
44 44
         //is there a evt_id in the request?
45 45
         $evt_id = ! empty($this->_req_data['EVT_ID']) && ! is_array($this->_req_data['EVT_ID'])
46 46
             ? $this->_req_data['EVT_ID']
@@ -173,7 +173,7 @@  discard block
 block discarded – undo
173 173
             'help_tour'     => array('Templates_Help_Tour'),
174 174
             'require_nonce' => false,
175 175
         );
176
-        $this->_page_config                   = array_merge($this->_page_config, $new_page_config);
176
+        $this->_page_config = array_merge($this->_page_config, $new_page_config);
177 177
         //add filters and actions
178 178
         //modifying _views
179 179
         add_filter(
@@ -246,7 +246,7 @@  discard block
 block discarded – undo
246 246
          * check whether count of tickets is approaching the potential
247 247
          * limits for the server.
248 248
          */
249
-        if (! empty($data['input_count'])) {
249
+        if ( ! empty($data['input_count'])) {
250 250
             $response['max_input_vars_check'] = EE_Registry::instance()->CFG->environment->max_input_vars_limit_check(
251 251
                 $data['input_count']
252 252
             );
@@ -275,12 +275,12 @@  discard block
 block discarded – undo
275 275
     {
276 276
         $return = parent::extra_permalink_field_buttons($return, $id, $new_title, $new_slug);
277 277
         //make sure this is only when editing
278
-        if (! empty($id)) {
279
-            $href   = EE_Admin_Page::add_query_args_and_nonce(
278
+        if ( ! empty($id)) {
279
+            $href = EE_Admin_Page::add_query_args_and_nonce(
280 280
                 array('action' => 'duplicate_event', 'EVT_ID' => $id),
281 281
                 $this->_admin_base_url
282 282
             );
283
-            $title  = esc_attr__('Duplicate Event', 'event_espresso');
283
+            $title = esc_attr__('Duplicate Event', 'event_espresso');
284 284
             $return .= '<a href="'
285 285
                        . $href
286 286
                        . '" title="'
@@ -327,7 +327,7 @@  discard block
 block discarded – undo
327 327
     {
328 328
         wp_register_script(
329 329
             'ee-event-editor-heartbeat',
330
-            EVENTS_CAF_ASSETS_URL . 'event-editor-heartbeat.js',
330
+            EVENTS_CAF_ASSETS_URL.'event-editor-heartbeat.js',
331 331
             array('ee_admin_js', 'heartbeat'),
332 332
             EVENT_ESPRESSO_VERSION,
333 333
             true
@@ -350,7 +350,7 @@  discard block
 block discarded – undo
350 350
     public function add_additional_datetime_button($template, $template_args)
351 351
     {
352 352
         return EEH_Template::display_template(
353
-            EVENTS_CAF_TEMPLATE_PATH . 'event_datetime_add_additional_time.template.php',
353
+            EVENTS_CAF_TEMPLATE_PATH.'event_datetime_add_additional_time.template.php',
354 354
             $template_args,
355 355
             true
356 356
         );
@@ -367,7 +367,7 @@  discard block
 block discarded – undo
367 367
     public function add_datetime_clone_button($template, $template_args)
368 368
     {
369 369
         return EEH_Template::display_template(
370
-            EVENTS_CAF_TEMPLATE_PATH . 'event_datetime_metabox_clone_button.template.php',
370
+            EVENTS_CAF_TEMPLATE_PATH.'event_datetime_metabox_clone_button.template.php',
371 371
             $template_args,
372 372
             true
373 373
         );
@@ -384,7 +384,7 @@  discard block
 block discarded – undo
384 384
     public function datetime_timezones_template($template, $template_args)
385 385
     {
386 386
         return EEH_Template::display_template(
387
-            EVENTS_CAF_TEMPLATE_PATH . 'event_datetime_timezones.template.php',
387
+            EVENTS_CAF_TEMPLATE_PATH.'event_datetime_timezones.template.php',
388 388
             $template_args,
389 389
             true
390 390
         );
@@ -397,7 +397,7 @@  discard block
 block discarded – undo
397 397
     protected function _set_list_table_views_default()
398 398
     {
399 399
         parent::_set_list_table_views_default();
400
-        $new_views    = array(
400
+        $new_views = array(
401 401
             'today' => array(
402 402
                 'slug'        => 'today',
403 403
                 'label'       => esc_html__('Today', 'event_espresso'),
@@ -502,7 +502,7 @@  discard block
 block discarded – undo
502 502
     {
503 503
         // first make sure the ID for the event is in the request.
504 504
         //  If it isn't then we need to bail and redirect back to overview list table (cause how did we get here?)
505
-        if (! isset($this->_req_data['EVT_ID'])) {
505
+        if ( ! isset($this->_req_data['EVT_ID'])) {
506 506
             EE_Error::add_error(
507 507
                 esc_html__(
508 508
                     'In order to duplicate an event an Event ID is required.  None was given.',
@@ -517,7 +517,7 @@  discard block
 block discarded – undo
517 517
         }
518 518
         //k we've got EVT_ID so let's use that to get the event we'll duplicate
519 519
         $orig_event = EEM_Event::instance()->get_one_by_ID($this->_req_data['EVT_ID']);
520
-        if (! $orig_event instanceof EE_Event) {
520
+        if ( ! $orig_event instanceof EE_Event) {
521 521
             throw new EE_Error(
522 522
                 sprintf(
523 523
                     esc_html__('An EE_Event object could not be retrieved for the given ID (%s)', 'event_espresso'),
@@ -533,7 +533,7 @@  discard block
 block discarded – undo
533 533
         $orig_ven = $orig_event->get_many_related('Venue');
534 534
         //reset the ID and modify other details to make it clear this is a dupe
535 535
         $new_event->set('EVT_ID', 0);
536
-        $new_name = $new_event->name() . ' ' . esc_html__('**DUPLICATE**', 'event_espresso');
536
+        $new_name = $new_event->name().' '.esc_html__('**DUPLICATE**', 'event_espresso');
537 537
         $new_event->set('EVT_name', $new_name);
538 538
         $new_event->set(
539 539
             'EVT_slug',
@@ -562,7 +562,7 @@  discard block
 block discarded – undo
562 562
             'Question_Group',
563 563
             array(array('Event_Question_Group.EQG_primary' => 1))
564 564
         );
565
-        if (! empty($orig_primary_qgs)) {
565
+        if ( ! empty($orig_primary_qgs)) {
566 566
             foreach ($orig_primary_qgs as $id => $obj) {
567 567
                 if ($obj instanceof EE_Question_Group) {
568 568
                     $new_event->_add_relation_to($obj, 'Question_Group', array('EQG_primary' => 1));
@@ -574,7 +574,7 @@  discard block
 block discarded – undo
574 574
             'Question_Group',
575 575
             array(array('Event_Question_Group.EQG_primary' => 0))
576 576
         );
577
-        if (! empty($orig_additional_qgs)) {
577
+        if ( ! empty($orig_additional_qgs)) {
578 578
             foreach ($orig_additional_qgs as $id => $obj) {
579 579
                 if ($obj instanceof EE_Question_Group) {
580 580
                     $new_event->_add_relation_to($obj, 'Question_Group', array('EQG_primary' => 0));
@@ -587,7 +587,7 @@  discard block
 block discarded – undo
587 587
         //k now that we have the new event saved we can loop through the datetimes and start adding relations.
588 588
         $cloned_tickets = array();
589 589
         foreach ($orig_datetimes as $orig_dtt) {
590
-            if (! $orig_dtt instanceof EE_Datetime) {
590
+            if ( ! $orig_dtt instanceof EE_Datetime) {
591 591
                 continue;
592 592
             }
593 593
             $new_dtt   = clone $orig_dtt;
@@ -600,9 +600,9 @@  discard block
 block discarded – undo
600 600
             $new_event->_add_relation_to($new_dtt, 'Datetime');
601 601
             $new_event->save();
602 602
             //now let's get the ticket relations setup.
603
-            foreach ((array)$orig_tkts as $orig_tkt) {
603
+            foreach ((array) $orig_tkts as $orig_tkt) {
604 604
                 //it's possible a datetime will have no tickets so let's verify we HAVE a ticket first.
605
-                if (! $orig_tkt instanceof EE_Ticket) {
605
+                if ( ! $orig_tkt instanceof EE_Ticket) {
606 606
                     continue;
607 607
                 }
608 608
                 //is this ticket archived?  If it is then let's skip
@@ -722,8 +722,8 @@  discard block
 block discarded – undo
722 722
             array('action' => 'sample_export_file'),
723 723
             $this->_admin_base_url
724 724
         );
725
-        $content                                    = EEH_Template::display_template(
726
-            EVENTS_CAF_TEMPLATE_PATH . 'import_page.template.php',
725
+        $content = EEH_Template::display_template(
726
+            EVENTS_CAF_TEMPLATE_PATH.'import_page.template.php',
727 727
             $this->_template_args,
728 728
             true
729 729
         );
@@ -740,7 +740,7 @@  discard block
 block discarded – undo
740 740
      */
741 741
     protected function _import_events()
742 742
     {
743
-        require_once(EE_CLASSES . 'EE_Import.class.php');
743
+        require_once(EE_CLASSES.'EE_Import.class.php');
744 744
         $success = EE_Import::instance()->import();
745 745
         $this->_redirect_after_action($success, 'Import File', 'ran', array('action' => 'import_page'), true);
746 746
     }
@@ -768,9 +768,9 @@  discard block
 block discarded – undo
768 768
             'action' => 'all_event_data',
769 769
             'EVT_ID' => $event_ids,
770 770
         );
771
-        $this->_req_data  = array_merge($this->_req_data, $new_request_args);
772
-        if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
773
-            require_once(EE_CLASSES . 'EE_Export.class.php');
771
+        $this->_req_data = array_merge($this->_req_data, $new_request_args);
772
+        if (is_readable(EE_CLASSES.'EE_Export.class.php')) {
773
+            require_once(EE_CLASSES.'EE_Export.class.php');
774 774
             $EE_Export = EE_Export::instance($this->_req_data);
775 775
             $EE_Export->export();
776 776
         }
@@ -790,9 +790,9 @@  discard block
 block discarded – undo
790 790
             'action'       => 'categories',
791 791
             'category_ids' => $this->_req_data['EVT_CAT_ID'],
792 792
         );
793
-        $this->_req_data  = array_merge($this->_req_data, $new_request_args);
794
-        if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
795
-            require_once(EE_CLASSES . 'EE_Export.class.php');
793
+        $this->_req_data = array_merge($this->_req_data, $new_request_args);
794
+        if (is_readable(EE_CLASSES.'EE_Export.class.php')) {
795
+            require_once(EE_CLASSES.'EE_Export.class.php');
796 796
             $EE_Export = EE_Export::instance($this->_req_data);
797 797
             $EE_Export->export();
798 798
         }
@@ -829,7 +829,7 @@  discard block
 block discarded – undo
829 829
         $this->_set_add_edit_form_tags('update_template_settings');
830 830
         $this->_set_publish_post_box_vars(null, false, false, null, false);
831 831
         $this->_template_args['admin_page_content'] = EEH_Template::display_template(
832
-            EVENTS_CAF_TEMPLATE_PATH . 'template_settings.template.php',
832
+            EVENTS_CAF_TEMPLATE_PATH.'template_settings.template.php',
833 833
             $this->_template_args,
834 834
             true
835 835
         );
@@ -870,7 +870,7 @@  discard block
 block discarded – undo
870 870
         );
871 871
         if (EE_Registry::instance()->CFG->core->event_cpt_slug != $old_slug) {
872 872
             /** @var EventEspresso\core\domain\services\custom_post_types\RewriteRules $rewrite_rules */
873
-            $rewrite_rules =  LoaderFactory::getLoader()->getShared(
873
+            $rewrite_rules = LoaderFactory::getLoader()->getShared(
874 874
                 'EventEspresso\core\domain\services\custom_post_types\RewriteRules'
875 875
             );
876 876
             $rewrite_rules->flush();
@@ -909,11 +909,11 @@  discard block
 block discarded – undo
909 909
      */
910 910
     public function registration_options_meta_box()
911 911
     {
912
-        $yes_no_values                                    = array(
912
+        $yes_no_values = array(
913 913
             array('id' => true, 'text' => esc_html__('Yes', 'event_espresso')),
914 914
             array('id' => false, 'text' => esc_html__('No', 'event_espresso')),
915 915
         );
916
-        $default_reg_status_values                        = EEM_Registration::reg_status_array(
916
+        $default_reg_status_values = EEM_Registration::reg_status_array(
917 917
             array(
918 918
                 EEM_Registration::status_id_cancelled,
919 919
                 EEM_Registration::status_id_declined,
@@ -930,12 +930,12 @@  discard block
 block discarded – undo
930 930
             $default_reg_status_values,
931 931
             $this->_cpt_model_obj->default_registration_status()
932 932
         );
933
-        $template_args['display_description']             = EEH_Form_Fields::select_input(
933
+        $template_args['display_description'] = EEH_Form_Fields::select_input(
934 934
             'display_desc',
935 935
             $yes_no_values,
936 936
             $this->_cpt_model_obj->display_description()
937 937
         );
938
-        $template_args['display_ticket_selector']         = EEH_Form_Fields::select_input(
938
+        $template_args['display_ticket_selector'] = EEH_Form_Fields::select_input(
939 939
             'display_ticket_selector',
940 940
             $yes_no_values,
941 941
             $this->_cpt_model_obj->display_ticket_selector(),
@@ -956,7 +956,7 @@  discard block
 block discarded – undo
956 956
             $default_reg_status_values
957 957
         );
958 958
         EEH_Template::display_template(
959
-            EVENTS_CAF_TEMPLATE_PATH . 'event_registration_options.template.php',
959
+            EVENTS_CAF_TEMPLATE_PATH.'event_registration_options.template.php',
960 960
             $template_args
961 961
         );
962 962
     }
@@ -1060,13 +1060,13 @@  discard block
 block discarded – undo
1060 1060
     {
1061 1061
         $start = EEM_Datetime::instance()->convert_datetime_for_query(
1062 1062
             'DTT_EVT_start',
1063
-            date('Y-m-d') . ' 00:00:00',
1063
+            date('Y-m-d').' 00:00:00',
1064 1064
             'Y-m-d H:i:s',
1065 1065
             'UTC'
1066 1066
         );
1067
-        $end   = EEM_Datetime::instance()->convert_datetime_for_query(
1067
+        $end = EEM_Datetime::instance()->convert_datetime_for_query(
1068 1068
             'DTT_EVT_start',
1069
-            date('Y-m-d') . ' 23:59:59',
1069
+            date('Y-m-d').' 23:59:59',
1070 1070
             'Y-m-d H:i:s',
1071 1071
             'UTC'
1072 1072
         );
@@ -1093,13 +1093,13 @@  discard block
 block discarded – undo
1093 1093
         $days_this_month = date('t');
1094 1094
         $start           = EEM_Datetime::instance()->convert_datetime_for_query(
1095 1095
             'DTT_EVT_start',
1096
-            $this_year_r . '-' . $this_month_r . '-01 00:00:00',
1096
+            $this_year_r.'-'.$this_month_r.'-01 00:00:00',
1097 1097
             'Y-m-d H:i:s',
1098 1098
             'UTC'
1099 1099
         );
1100
-        $end             = EEM_Datetime::instance()->convert_datetime_for_query(
1100
+        $end = EEM_Datetime::instance()->convert_datetime_for_query(
1101 1101
             'DTT_EVT_start',
1102
-            $this_year_r . '-' . $this_month_r . '-' . $days_this_month . ' 23:59:59',
1102
+            $this_year_r.'-'.$this_month_r.'-'.$days_this_month.' 23:59:59',
1103 1103
             'Y-m-d H:i:s',
1104 1104
             'UTC'
1105 1105
         );
@@ -1166,7 +1166,7 @@  discard block
 block discarded – undo
1166 1166
         $offset       = ($current_page - 1) * $per_page;
1167 1167
         $limit        = array($offset, $per_page);
1168 1168
         if (isset($this->_req_data['s'])) {
1169
-            $sstr         = '%' . $this->_req_data['s'] . '%';
1169
+            $sstr         = '%'.$this->_req_data['s'].'%';
1170 1170
             $_where['OR'] = array(
1171 1171
                 'TKT_name'        => array('LIKE', $sstr),
1172 1172
                 'TKT_description' => array('LIKE', $sstr),
@@ -1195,17 +1195,17 @@  discard block
 block discarded – undo
1195 1195
         $success = 1;
1196 1196
         $TKT     = EEM_Ticket::instance();
1197 1197
         //checkboxes?
1198
-        if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
1198
+        if ( ! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
1199 1199
             //if array has more than one element then success message should be plural
1200 1200
             $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1;
1201 1201
             //cycle thru the boxes
1202 1202
             while (list($TKT_ID, $value) = each($this->_req_data['checkbox'])) {
1203 1203
                 if ($trash) {
1204
-                    if (! $TKT->delete_by_ID($TKT_ID)) {
1204
+                    if ( ! $TKT->delete_by_ID($TKT_ID)) {
1205 1205
                         $success = 0;
1206 1206
                     }
1207 1207
                 } else {
1208
-                    if (! $TKT->restore_by_ID($TKT_ID)) {
1208
+                    if ( ! $TKT->restore_by_ID($TKT_ID)) {
1209 1209
                         $success = 0;
1210 1210
                     }
1211 1211
                 }
@@ -1214,11 +1214,11 @@  discard block
 block discarded – undo
1214 1214
             //grab single id and trash
1215 1215
             $TKT_ID = absint($this->_req_data['TKT_ID']);
1216 1216
             if ($trash) {
1217
-                if (! $TKT->delete_by_ID($TKT_ID)) {
1217
+                if ( ! $TKT->delete_by_ID($TKT_ID)) {
1218 1218
                     $success = 0;
1219 1219
                 }
1220 1220
             } else {
1221
-                if (! $TKT->restore_by_ID($TKT_ID)) {
1221
+                if ( ! $TKT->restore_by_ID($TKT_ID)) {
1222 1222
                     $success = 0;
1223 1223
                 }
1224 1224
             }
@@ -1239,20 +1239,20 @@  discard block
 block discarded – undo
1239 1239
     {
1240 1240
         $success = 1;
1241 1241
         //checkboxes?
1242
-        if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
1242
+        if ( ! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
1243 1243
             //if array has more than one element then success message should be plural
1244 1244
             $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1;
1245 1245
             //cycle thru the boxes
1246 1246
             while (list($TKT_ID, $value) = each($this->_req_data['checkbox'])) {
1247 1247
                 //delete
1248
-                if (! $this->_delete_the_ticket($TKT_ID)) {
1248
+                if ( ! $this->_delete_the_ticket($TKT_ID)) {
1249 1249
                     $success = 0;
1250 1250
                 }
1251 1251
             }
1252 1252
         } else {
1253 1253
             //grab single id and trash
1254 1254
             $TKT_ID = absint($this->_req_data['TKT_ID']);
1255
-            if (! $this->_delete_the_ticket($TKT_ID)) {
1255
+            if ( ! $this->_delete_the_ticket($TKT_ID)) {
1256 1256
                 $success = 0;
1257 1257
             }
1258 1258
         }
Please login to merge, or discard this patch.
widgets/upcoming_events/EEW_Upcoming_Events.widget.php 2 patches
Indentation   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -210,14 +210,14 @@  discard block
 block discarded – undo
210 210
 		        <?php _e('Show on all Pages:', 'event_espresso'); ?>
211 211
 			</label>
212 212
 	 	    <?php
213
-	 	    echo EEH_Form_Fields::select(
214
-	 	        __('Show on all Pages:', 'event_espresso'),
215
-	 	        $instance['show_everywhere'],
216
-	 	        $yes_no_values,
217
-	 	        $this->get_field_name('show_everywhere'),
218
-	 	        $this->get_field_id('show_everywhere')
219
-	 	    );
220
-	 	    ?>
213
+	 		echo EEH_Form_Fields::select(
214
+	 			__('Show on all Pages:', 'event_espresso'),
215
+	 			$instance['show_everywhere'],
216
+	 			$yes_no_values,
217
+	 			$this->get_field_name('show_everywhere'),
218
+	 			$this->get_field_id('show_everywhere')
219
+	 		);
220
+	 		?>
221 221
 	 	</p>
222 222
 		<p>
223 223
 			<label for="<?php echo $this->get_field_id('date_limit'); ?>">
@@ -300,14 +300,14 @@  discard block
 block discarded – undo
300 300
 				extract($args);
301 301
 
302 302
 				// add function to make the title a link
303
-	            add_filter('widget_title', array($this, 'make_the_title_a_link'), 15);
303
+				add_filter('widget_title', array($this, 'make_the_title_a_link'), 15);
304 304
 
305 305
 				$title = isset( $instance['title'] ) && ! empty( $instance['title'] ) ? $instance['title'] : '';
306 306
 				// filter the title
307 307
 				$title = apply_filters('widget_title', $title);
308 308
 
309 309
 				// remove the function from the filter, so it does not affect other widgets
310
-	            remove_filter('widget_title', array($this, 'make_the_title_a_link'), 15);
310
+				remove_filter('widget_title', array($this, 'make_the_title_a_link'), 15);
311 311
 
312 312
 				// Before widget (defined by themes).
313 313
 				echo $before_widget;
@@ -419,7 +419,7 @@  discard block
 block discarded – undo
419 419
 	 * @return string
420 420
 	 */
421 421
 	public function make_the_title_a_link($title) {
422
-	    return '<a href="' . EEH_Event_View::event_archive_url() . '">' . $title . '</a>';
422
+		return '<a href="' . EEH_Event_View::event_archive_url() . '">' . $title . '</a>';
423 423
 	}
424 424
 
425 425
 }
Please login to merge, or discard this patch.
Spacing   +81 added lines, -81 removed lines patch added patch discarded remove patch
@@ -31,8 +31,8 @@  discard block
 block discarded – undo
31 31
 	 */
32 32
 	public function __construct() {
33 33
 		parent::__construct(
34
-			__( 'Event Espresso Upcoming Events', 'event_espresso' ),
35
-			 array( 'description' => __( 'A widget to display your upcoming events.', 'event_espresso' ))
34
+			__('Event Espresso Upcoming Events', 'event_espresso'),
35
+			 array('description' => __('A widget to display your upcoming events.', 'event_espresso'))
36 36
 		);
37 37
 	}
38 38
 
@@ -45,9 +45,9 @@  discard block
 block discarded – undo
45 45
 	 * @param array $instance Previously saved values from database.
46 46
 	 * @return string|void
47 47
 	 */
48
-	public function form( $instance ) {
48
+	public function form($instance) {
49 49
 
50
-		EE_Registry::instance()->load_class( 'Question_Option', array(), FALSE, FALSE, TRUE );
50
+		EE_Registry::instance()->load_class('Question_Option', array(), FALSE, FALSE, TRUE);
51 51
 		// Set up some default widget settings.
52 52
 		$defaults = array(
53 53
 			'title' => __('Upcoming Events', 'event_espresso'),
@@ -63,16 +63,16 @@  discard block
 block discarded – undo
63 63
 			'image_size' => 'medium'
64 64
 		);
65 65
 
66
-		$instance = wp_parse_args( (array) $instance, $defaults );
66
+		$instance = wp_parse_args((array) $instance, $defaults);
67 67
 		// don't add HTML labels for EE_Form_Fields generated inputs
68
-		add_filter( 'FHEE__EEH_Form_Fields__label_html', '__return_empty_string' );
68
+		add_filter('FHEE__EEH_Form_Fields__label_html', '__return_empty_string');
69 69
 		$yes_no_values = array(
70
-			EE_Question_Option::new_instance( array( 'QSO_value' => FALSE, 'QSO_desc' => __('No', 'event_espresso'))),
71
-			EE_Question_Option::new_instance( array( 'QSO_value' => TRUE, 'QSO_desc' => __('Yes', 'event_espresso')))
70
+			EE_Question_Option::new_instance(array('QSO_value' => FALSE, 'QSO_desc' => __('No', 'event_espresso'))),
71
+			EE_Question_Option::new_instance(array('QSO_value' => TRUE, 'QSO_desc' => __('Yes', 'event_espresso')))
72 72
 		);
73 73
 		$sort_values = array(
74
-			EE_Question_Option::new_instance( array( 'QSO_value' => 'ASC', 'QSO_desc' => __('ASC', 'event_espresso'))),
75
-			EE_Question_Option::new_instance( array( 'QSO_value' => 'DESC', 'QSO_desc' => __('DESC', 'event_espresso')))
74
+			EE_Question_Option::new_instance(array('QSO_value' => 'ASC', 'QSO_desc' => __('ASC', 'event_espresso'))),
75
+			EE_Question_Option::new_instance(array('QSO_value' => 'DESC', 'QSO_desc' => __('DESC', 'event_espresso')))
76 76
 		);
77 77
 
78 78
 	?>
@@ -83,7 +83,7 @@  discard block
 block discarded – undo
83 83
 			<label for="<?php echo $this->get_field_id('title'); ?>">
84 84
 				<?php _e('Title:', 'event_espresso'); ?>
85 85
 			</label>
86
-			<input id="<?php echo $this->get_field_id('title'); ?>" class="widefat" name="<?php echo $this->get_field_name('title'); ?>" value="<?php echo esc_attr( $instance['title'] ); ?>" type="text" />
86
+			<input id="<?php echo $this->get_field_id('title'); ?>" class="widefat" name="<?php echo $this->get_field_name('title'); ?>" value="<?php echo esc_attr($instance['title']); ?>" type="text" />
87 87
 		</p>
88 88
 		<p>
89 89
 			<label for="<?php echo $this->get_field_id('category_name'); ?>">
@@ -92,16 +92,16 @@  discard block
 block discarded – undo
92 92
 			<?php
93 93
 			$event_categories = array();
94 94
 			/** @type EEM_Term $EEM_Term */
95
-			$EEM_Term = EE_Registry::instance()->load_model( 'Term' );
96
-			$categories = $EEM_Term->get_all_ee_categories( TRUE );
97
-			if ( $categories ) {
98
-				foreach ( $categories as $category ) {
99
-					if ( $category instanceof EE_Term ) {
100
-						$event_categories[] = EE_Question_Option::new_instance( array( 'QSO_value' => $category->get( 'slug' ), 'QSO_desc' => $category->get( 'name' )));
95
+			$EEM_Term = EE_Registry::instance()->load_model('Term');
96
+			$categories = $EEM_Term->get_all_ee_categories(TRUE);
97
+			if ($categories) {
98
+				foreach ($categories as $category) {
99
+					if ($category instanceof EE_Term) {
100
+						$event_categories[] = EE_Question_Option::new_instance(array('QSO_value' => $category->get('slug'), 'QSO_desc' => $category->get('name')));
101 101
 					}
102 102
 				}
103 103
 			}
104
-			array_unshift( $event_categories, EE_Question_Option::new_instance( array( 'QSO_value' => '', 'QSO_desc' => __(' - display all - ', 'event_espresso'))));
104
+			array_unshift($event_categories, EE_Question_Option::new_instance(array('QSO_value' => '', 'QSO_desc' => __(' - display all - ', 'event_espresso'))));
105 105
 			echo EEH_Form_Fields::select(
106 106
 				 __('Event Category:', 'event_espresso'),
107 107
 				$instance['category_name'],
@@ -126,9 +126,9 @@  discard block
 block discarded – undo
126 126
 				 __('Show Expired Events:', 'event_espresso'),
127 127
 				$instance['show_expired'],
128 128
 				array(
129
-					EE_Question_Option::new_instance( array( 'QSO_value' => 0, 'QSO_desc' => __('No', 'event_espresso'))), 
130
-					EE_Question_Option::new_instance( array( 'QSO_value' => 1, 'QSO_desc' => __('Yes', 'event_espresso'))), 
131
-					EE_Question_Option::new_instance( array( 'QSO_value' => 2, 'QSO_desc' => __('Show Only Expired', 'event_espresso'))), 
129
+					EE_Question_Option::new_instance(array('QSO_value' => 0, 'QSO_desc' => __('No', 'event_espresso'))), 
130
+					EE_Question_Option::new_instance(array('QSO_value' => 1, 'QSO_desc' => __('Yes', 'event_espresso'))), 
131
+					EE_Question_Option::new_instance(array('QSO_value' => 2, 'QSO_desc' => __('Show Only Expired', 'event_espresso'))), 
132 132
 				),
133 133
 				$this->get_field_name('show_expired'),
134 134
 				$this->get_field_id('show_expired')
@@ -156,16 +156,16 @@  discard block
 block discarded – undo
156 156
 			<?php
157 157
 			$image_sizes = array();
158 158
 			$sizes = get_intermediate_image_sizes();
159
-			if ( $sizes ) {
159
+			if ($sizes) {
160 160
 				// loop thru images and create option objects out of them
161
-				foreach ( $sizes as $image_size ) {
162
-					$image_size = trim( $image_size );
161
+				foreach ($sizes as $image_size) {
162
+					$image_size = trim($image_size);
163 163
 					// no big images plz
164
-					if ( ! in_array( $image_size, array( 'large', 'post-thumbnail' ))) {
165
-						$image_sizes[] = EE_Question_Option::new_instance( array( 'QSO_value' => $image_size, 'QSO_desc' => $image_size ));
164
+					if ( ! in_array($image_size, array('large', 'post-thumbnail'))) {
165
+						$image_sizes[] = EE_Question_Option::new_instance(array('QSO_value' => $image_size, 'QSO_desc' => $image_size));
166 166
 					}
167 167
 				}
168
-				$image_sizes[] = EE_Question_Option::new_instance( array( 'QSO_value' => 'none', 'QSO_desc' =>  __('don\'t show images', 'event_espresso') ));
168
+				$image_sizes[] = EE_Question_Option::new_instance(array('QSO_value' => 'none', 'QSO_desc' =>  __('don\'t show images', 'event_espresso')));
169 169
 			}
170 170
 			echo EEH_Form_Fields::select(
171 171
 				 __('Image Size:', 'event_espresso'),
@@ -223,7 +223,7 @@  discard block
 block discarded – undo
223 223
 			<label for="<?php echo $this->get_field_id('date_limit'); ?>">
224 224
 				<?php _e('Number of Dates to Display:', 'event_espresso'); ?>
225 225
 			</label>
226
-			<input id="<?php echo $this->get_field_id('date_limit'); ?>" name="<?php echo $this->get_field_name('date_limit'); ?>" value="<?php echo esc_attr( $instance['date_limit'] ); ?>" size="3" type="text" />
226
+			<input id="<?php echo $this->get_field_id('date_limit'); ?>" name="<?php echo $this->get_field_name('date_limit'); ?>" value="<?php echo esc_attr($instance['date_limit']); ?>" size="3" type="text" />
227 227
 		</p>
228 228
 		<p>
229 229
 			<label for="<?php echo $this->get_field_id('date_range'); ?>">
@@ -255,9 +255,9 @@  discard block
 block discarded – undo
255 255
 	 *
256 256
 	 * @return array Updated safe values to be saved.
257 257
 	 */
258
-	public function update( $new_instance, $old_instance ) {
258
+	public function update($new_instance, $old_instance) {
259 259
 		$instance = $old_instance;
260
-		$instance['title'] = ! empty( $new_instance['title'] ) ? strip_tags( $new_instance['title'] ) : '';
260
+		$instance['title'] = ! empty($new_instance['title']) ? strip_tags($new_instance['title']) : '';
261 261
 		$instance['category_name'] = $new_instance['category_name'];
262 262
 		$instance['show_expired'] = $new_instance['show_expired'];
263 263
 		$instance['limit'] = $new_instance['limit'];
@@ -281,18 +281,18 @@  discard block
 block discarded – undo
281 281
 	 * @param array $args     Widget arguments.
282 282
 	 * @param array $instance Saved values from database.
283 283
 	 */
284
-	public function widget( $args, $instance ) {
284
+	public function widget($args, $instance) {
285 285
 
286 286
 		global $post;
287 287
 		// make sure there is some kinda post object
288
-		if ( $post instanceof WP_Post ) {
288
+		if ($post instanceof WP_Post) {
289 289
 			$before_widget = '';
290 290
 			$before_title = '';
291 291
 			$after_title = '';
292 292
 			$after_widget = '';
293 293
 			// but NOT an events archives page, cuz that would be like two event lists on the same page
294
-			$show_everywhere = isset( $instance['show_everywhere'] ) ? (bool) absint( $instance['show_everywhere'] ) : TRUE;
295
-			if ( $show_everywhere || ! ( $post->post_type == 'espresso_events' && is_archive() )) {
294
+			$show_everywhere = isset($instance['show_everywhere']) ? (bool) absint($instance['show_everywhere']) : TRUE;
295
+			if ($show_everywhere || ! ($post->post_type == 'espresso_events' && is_archive())) {
296 296
 				// let's use some of the event helper functions'
297 297
 				// make separate vars out of attributes
298 298
 
@@ -302,7 +302,7 @@  discard block
 block discarded – undo
302 302
 				// add function to make the title a link
303 303
 	            add_filter('widget_title', array($this, 'make_the_title_a_link'), 15);
304 304
 
305
-				$title = isset( $instance['title'] ) && ! empty( $instance['title'] ) ? $instance['title'] : '';
305
+				$title = isset($instance['title']) && ! empty($instance['title']) ? $instance['title'] : '';
306 306
 				// filter the title
307 307
 				$title = apply_filters('widget_title', $title);
308 308
 
@@ -312,90 +312,90 @@  discard block
 block discarded – undo
312 312
 				// Before widget (defined by themes).
313 313
 				echo $before_widget;
314 314
 				// Display the widget title if one was input (before and after defined by themes).
315
-				if ( ! empty( $title )) {
316
-					echo $before_title . $title . $after_title;
315
+				if ( ! empty($title)) {
316
+					echo $before_title.$title.$after_title;
317 317
 				}
318 318
 				// grab widget settings
319
-				$category = isset( $instance['category_name'] ) && ! empty( $instance['category_name'] ) ? $instance['category_name'] : FALSE;
320
-				$show_expired = isset( $instance['show_expired'] ) ? absint( $instance['show_expired'] ) : 0;
321
-				$image_size = isset( $instance['image_size'] ) && ! empty( $instance['image_size'] ) ? $instance['image_size'] : 'medium';
322
-				$show_desc = isset( $instance['show_desc'] ) ? (bool) absint( $instance['show_desc'] ) : TRUE;
323
-				$show_dates = isset( $instance['show_dates'] ) ? (bool) absint( $instance['show_dates'] ) : TRUE;
324
-				$date_limit = isset( $instance['date_limit'] ) && ! empty( $instance['date_limit'] ) ? $instance['date_limit'] : NULL;
325
-				$date_range = isset( $instance['date_range'] ) && ! empty( $instance['date_range'] ) ? $instance['date_range'] : FALSE;
319
+				$category = isset($instance['category_name']) && ! empty($instance['category_name']) ? $instance['category_name'] : FALSE;
320
+				$show_expired = isset($instance['show_expired']) ? absint($instance['show_expired']) : 0;
321
+				$image_size = isset($instance['image_size']) && ! empty($instance['image_size']) ? $instance['image_size'] : 'medium';
322
+				$show_desc = isset($instance['show_desc']) ? (bool) absint($instance['show_desc']) : TRUE;
323
+				$show_dates = isset($instance['show_dates']) ? (bool) absint($instance['show_dates']) : TRUE;
324
+				$date_limit = isset($instance['date_limit']) && ! empty($instance['date_limit']) ? $instance['date_limit'] : NULL;
325
+				$date_range = isset($instance['date_range']) && ! empty($instance['date_range']) ? $instance['date_range'] : FALSE;
326 326
 				// start to build our where clause
327 327
 				$where = array(
328 328
 //					'Datetime.DTT_is_primary' => 1,
329
-					'status' => array( 'IN', array( 'publish', 'sold_out' ) )
329
+					'status' => array('IN', array('publish', 'sold_out'))
330 330
 				);
331 331
 				// add category
332
-				if ( $category ) {
332
+				if ($category) {
333 333
 					$where['Term_Taxonomy.taxonomy'] = 'espresso_event_categories';
334 334
 					$where['Term_Taxonomy.Term.slug'] = $category;
335 335
 				}
336 336
 				// if NOT expired then we want events that start today or in the future
337 337
 				// if NOT show expired then we want events that start today or in the future 
338
-				if ( $show_expired == 0 ) { 
339
-				 	$where['Datetime.DTT_EVT_end'] = array( '>=', EEM_Datetime::instance()->current_time_for_query( 'DTT_EVT_end' ) ); 
338
+				if ($show_expired == 0) { 
339
+				 	$where['Datetime.DTT_EVT_end'] = array('>=', EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end')); 
340 340
 				} 
341 341
 				// if show ONLY expired we want events that ended prior to today 
342
-				if ( $show_expired == 2 ) { 
343
-					$where['Datetime.DTT_EVT_end'] = array( '<=', EEM_Datetime::instance()->current_time_for_query( 'DTT_EVT_start' ) ); 
342
+				if ($show_expired == 2) { 
343
+					$where['Datetime.DTT_EVT_end'] = array('<=', EEM_Datetime::instance()->current_time_for_query('DTT_EVT_start')); 
344 344
 				}
345 345
 				// allow $where to be filtered
346
-				$where = apply_filters( 'FHEE__EEW_Upcoming_Events__widget__where', $where, $category, $show_expired );
346
+				$where = apply_filters('FHEE__EEW_Upcoming_Events__widget__where', $where, $category, $show_expired);
347 347
 				// run the query
348
-				$events = EE_Registry::instance()->load_model( 'Event' )->get_all( array(
348
+				$events = EE_Registry::instance()->load_model('Event')->get_all(array(
349 349
 					$where,
350 350
 					'limit' => isset($instance['limit']) && $instance['limit'] > 0 
351
-								? '0,' . $instance['limit'] 
351
+								? '0,'.$instance['limit'] 
352 352
 								: '0,10',
353 353
 					'order_by' => 'Datetime.DTT_EVT_start',
354 354
 					'order' => isset($instance['sort']) ? $instance['sort'] : 'ASC',
355 355
 					'group_by' => 'EVT_ID'
356 356
 				));
357 357
 
358
-				if ( ! empty( $events )) {
358
+				if ( ! empty($events)) {
359 359
 					echo '<ul class="ee-upcoming-events-widget-ul">';
360
-					foreach ( $events as $event ) {
361
-						if ( $event instanceof EE_Event && ( !is_single() || $post->ID != $event->ID() ) ) {
360
+					foreach ($events as $event) {
361
+						if ($event instanceof EE_Event && ( ! is_single() || $post->ID != $event->ID())) {
362 362
 							//printr( $event, '$event  <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span>', 'auto' );
363
-							echo '<li id="ee-upcoming-events-widget-li-' . $event->ID() . '" class="ee-upcoming-events-widget-li">';
363
+							echo '<li id="ee-upcoming-events-widget-li-'.$event->ID().'" class="ee-upcoming-events-widget-li">';
364 364
 							// how big is the event name ?
365
-							$name_length = strlen( $event->name() );
366
-							switch( $name_length ) {
365
+							$name_length = strlen($event->name());
366
+							switch ($name_length) {
367 367
 								case $name_length > 70 :
368
-									$len_class =  ' three-line';
368
+									$len_class = ' three-line';
369 369
 									break;
370 370
 								case $name_length > 35 :
371
-									$len_class =  ' two-line';
371
+									$len_class = ' two-line';
372 372
 									break;
373 373
 								default :
374
-									$len_class =  ' one-line';
374
+									$len_class = ' one-line';
375 375
 							}
376
-							$event_url = apply_filters( 'FHEE_EEW_Upcoming_Events__widget__event_url', $event->get_permalink(), $event );
377
-							echo '<h5 class="ee-upcoming-events-widget-title-h5"><a class="ee-widget-event-name-a' . $len_class . '" href="' . $event_url . '">' . $event->name() . '</a></h5>';
378
-							if ( post_password_required( $event->ID() ) ) {
379
-								$pswd_form = apply_filters( 'FHEE_EEW_Upcoming_Events__widget__password_form', get_the_password_form( $event->ID() ), $event );
376
+							$event_url = apply_filters('FHEE_EEW_Upcoming_Events__widget__event_url', $event->get_permalink(), $event);
377
+							echo '<h5 class="ee-upcoming-events-widget-title-h5"><a class="ee-widget-event-name-a'.$len_class.'" href="'.$event_url.'">'.$event->name().'</a></h5>';
378
+							if (post_password_required($event->ID())) {
379
+								$pswd_form = apply_filters('FHEE_EEW_Upcoming_Events__widget__password_form', get_the_password_form($event->ID()), $event);
380 380
 								echo $pswd_form;
381 381
 							} else {
382
-								if ( has_post_thumbnail( $event->ID() ) && $image_size != 'none' ) {
383
-									echo '<div class="ee-upcoming-events-widget-img-dv"><a class="ee-upcoming-events-widget-img" href="' . $event_url . '">' . get_the_post_thumbnail( $event->ID(), $image_size ) . '</a></div>';
382
+								if (has_post_thumbnail($event->ID()) && $image_size != 'none') {
383
+									echo '<div class="ee-upcoming-events-widget-img-dv"><a class="ee-upcoming-events-widget-img" href="'.$event_url.'">'.get_the_post_thumbnail($event->ID(), $image_size).'</a></div>';
384 384
 								}
385
-								$desc = $event->short_description( 25 );
386
-								if ( $show_dates ) {
387
-									$date_format = apply_filters( 'FHEE__espresso_event_date_range__date_format', get_option( 'date_format' ));
388
-									$time_format = apply_filters( 'FHEE__espresso_event_date_range__time_format', get_option( 'time_format' ));
389
-									$single_date_format = apply_filters( 'FHEE__espresso_event_date_range__single_date_format', get_option( 'date_format' ));
390
-									$single_time_format = apply_filters( 'FHEE__espresso_event_date_range__single_time_format', get_option( 'time_format' ));
391
-									if ( $date_range == TRUE ) {
392
-										echo espresso_event_date_range( $date_format, $time_format, $single_date_format, $single_time_format, $event->ID() );
393
-									}else{
394
-										echo espresso_list_of_event_dates( $event->ID(), $date_format, $time_format, FALSE, NULL, TRUE, TRUE, $date_limit );
385
+								$desc = $event->short_description(25);
386
+								if ($show_dates) {
387
+									$date_format = apply_filters('FHEE__espresso_event_date_range__date_format', get_option('date_format'));
388
+									$time_format = apply_filters('FHEE__espresso_event_date_range__time_format', get_option('time_format'));
389
+									$single_date_format = apply_filters('FHEE__espresso_event_date_range__single_date_format', get_option('date_format'));
390
+									$single_time_format = apply_filters('FHEE__espresso_event_date_range__single_time_format', get_option('time_format'));
391
+									if ($date_range == TRUE) {
392
+										echo espresso_event_date_range($date_format, $time_format, $single_date_format, $single_time_format, $event->ID());
393
+									} else {
394
+										echo espresso_list_of_event_dates($event->ID(), $date_format, $time_format, FALSE, NULL, TRUE, TRUE, $date_limit);
395 395
 									}
396 396
 								}
397
-								if ( $show_desc && $desc ) {
398
-									echo '<p style="margin-top: .5em">' . $desc . '</p>';
397
+								if ($show_desc && $desc) {
398
+									echo '<p style="margin-top: .5em">'.$desc.'</p>';
399 399
 								}
400 400
 							}
401 401
 							echo '</li>';
@@ -419,7 +419,7 @@  discard block
 block discarded – undo
419 419
 	 * @return string
420 420
 	 */
421 421
 	public function make_the_title_a_link($title) {
422
-	    return '<a href="' . EEH_Event_View::event_archive_url() . '">' . $title . '</a>';
422
+	    return '<a href="'.EEH_Event_View::event_archive_url().'">'.$title.'</a>';
423 423
 	}
424 424
 
425 425
 }
Please login to merge, or discard this patch.
core/EE_Dependency_Map.core.php 2 patches
Spacing   +27 added lines, -27 removed lines patch added patch discarded remove patch
@@ -7,7 +7,7 @@  discard block
 block discarded – undo
7 7
 use EventEspresso\core\services\request\RequestInterface;
8 8
 use EventEspresso\core\services\request\ResponseInterface;
9 9
 
10
-if (! defined('EVENT_ESPRESSO_VERSION')) {
10
+if ( ! defined('EVENT_ESPRESSO_VERSION')) {
11 11
     exit('No direct script access allowed');
12 12
 }
13 13
 
@@ -129,7 +129,7 @@  discard block
 block discarded – undo
129 129
      */
130 130
     public static function instance() {
131 131
         // check if class object is instantiated, and instantiated properly
132
-        if (! self::$_instance instanceof EE_Dependency_Map) {
132
+        if ( ! self::$_instance instanceof EE_Dependency_Map) {
133 133
             self::$_instance = new EE_Dependency_Map(/*$request, $response, $legacy_request*/);
134 134
         }
135 135
         return self::$_instance;
@@ -211,8 +211,8 @@  discard block
 block discarded – undo
211 211
     ) {
212 212
         $class = trim($class, '\\');
213 213
         $registered = false;
214
-        if (empty(self::$_instance->_dependency_map[ $class ])) {
215
-            self::$_instance->_dependency_map[ $class ] = array();
214
+        if (empty(self::$_instance->_dependency_map[$class])) {
215
+            self::$_instance->_dependency_map[$class] = array();
216 216
         }
217 217
         // we need to make sure that any aliases used when registering a dependency
218 218
         // get resolved to the correct class name
@@ -220,7 +220,7 @@  discard block
 block discarded – undo
220 220
             $alias = self::$_instance->get_alias($dependency);
221 221
             if (
222 222
                 $overwrite === EE_Dependency_Map::OVERWRITE_DEPENDENCIES
223
-                || ! isset(self::$_instance->_dependency_map[ $class ][ $alias ])
223
+                || ! isset(self::$_instance->_dependency_map[$class][$alias])
224 224
             ) {
225 225
                 unset($dependencies[$dependency]);
226 226
                 $dependencies[$alias] = $load_source;
@@ -233,13 +233,13 @@  discard block
 block discarded – undo
233 233
         // ie: with A = B + C, entries in B take precedence over duplicate entries in C
234 234
         // Union is way faster than array_merge() but should be used with caution...
235 235
         // especially with numerically indexed arrays
236
-        $dependencies += self::$_instance->_dependency_map[ $class ];
236
+        $dependencies += self::$_instance->_dependency_map[$class];
237 237
         // now we need to ensure that the resulting dependencies
238 238
         // array only has the entries that are required for the class
239 239
         // so first count how many dependencies were originally registered for the class
240
-        $dependency_count = count(self::$_instance->_dependency_map[ $class ]);
240
+        $dependency_count = count(self::$_instance->_dependency_map[$class]);
241 241
         // if that count is non-zero (meaning dependencies were already registered)
242
-        self::$_instance->_dependency_map[ $class ] = $dependency_count
242
+        self::$_instance->_dependency_map[$class] = $dependency_count
243 243
             // then truncate the  final array to match that count
244 244
             ? array_slice($dependencies, 0, $dependency_count)
245 245
             // otherwise just take the incoming array because nothing previously existed
@@ -257,7 +257,7 @@  discard block
 block discarded – undo
257 257
      */
258 258
     public static function register_class_loader($class_name, $loader = 'load_core')
259 259
     {
260
-        if (! $loader instanceof Closure && strpos($class_name, '\\') !== false) {
260
+        if ( ! $loader instanceof Closure && strpos($class_name, '\\') !== false) {
261 261
             throw new DomainException(
262 262
                 esc_html__('Don\'t use class loaders for FQCNs.', 'event_espresso')
263 263
             );
@@ -281,7 +281,7 @@  discard block
 block discarded – undo
281 281
             );
282 282
         }
283 283
         $class_name = self::$_instance->get_alias($class_name);
284
-        if (! isset(self::$_instance->_class_loaders[$class_name])) {
284
+        if ( ! isset(self::$_instance->_class_loaders[$class_name])) {
285 285
             self::$_instance->_class_loaders[$class_name] = $loader;
286 286
             return true;
287 287
         }
@@ -366,7 +366,7 @@  discard block
 block discarded – undo
366 366
     public function class_loader($class_name)
367 367
     {
368 368
         // all legacy models use load_model()
369
-        if(strpos($class_name, 'EEM_') === 0){
369
+        if (strpos($class_name, 'EEM_') === 0) {
370 370
             return 'load_model';
371 371
         }
372 372
         $class_name = $this->get_alias($class_name);
@@ -395,7 +395,7 @@  discard block
 block discarded – undo
395 395
     public function add_alias($class_name, $alias, $for_class = '')
396 396
     {
397 397
         if ($for_class !== '') {
398
-            if (! isset($this->_aliases[$for_class])) {
398
+            if ( ! isset($this->_aliases[$for_class])) {
399 399
                 $this->_aliases[$for_class] = array();
400 400
             }
401 401
             $this->_aliases[$for_class][$class_name] = $alias;
@@ -441,10 +441,10 @@  discard block
 block discarded – undo
441 441
      */
442 442
     public function get_alias($class_name = '', $for_class = '')
443 443
     {
444
-        if (! $this->has_alias($class_name, $for_class)) {
444
+        if ( ! $this->has_alias($class_name, $for_class)) {
445 445
             return $class_name;
446 446
         }
447
-        if ($for_class !== '' && isset($this->_aliases[ $for_class ][ $class_name ])) {
447
+        if ($for_class !== '' && isset($this->_aliases[$for_class][$class_name])) {
448 448
             return $this->get_alias($this->_aliases[$for_class][$class_name], $for_class);
449 449
         }
450 450
         return $this->get_alias($this->_aliases[$class_name]);
@@ -765,13 +765,13 @@  discard block
 block discarded – undo
765 765
             'EE_Front_Controller'      => 'load_core',
766 766
             'EE_Module_Request_Router' => 'load_core',
767 767
             'EE_Registry'              => 'load_core',
768
-            'EE_Request'               => function () use (&$legacy_request) {
768
+            'EE_Request'               => function() use (&$legacy_request) {
769 769
                 return $legacy_request;
770 770
             },
771
-            'EventEspresso\core\services\request\Request' => function () use (&$request) {
771
+            'EventEspresso\core\services\request\Request' => function() use (&$request) {
772 772
                 return $request;
773 773
             },
774
-            'EventEspresso\core\services\request\Response' => function () use (&$response) {
774
+            'EventEspresso\core\services\request\Response' => function() use (&$response) {
775 775
                 return $response;
776 776
             },
777 777
             'EE_Request_Handler'       => 'load_core',
@@ -793,7 +793,7 @@  discard block
 block discarded – undo
793 793
             'EE_Messages_Data_Handler_Collection'  => 'load_lib',
794 794
             'EE_Message_Template_Group_Collection' => 'load_lib',
795 795
             'EE_Payment_Method_Manager'            => 'load_lib',
796
-            'EE_Messages_Generator'                => function () {
796
+            'EE_Messages_Generator'                => function() {
797 797
                 return EE_Registry::instance()->load_lib(
798 798
                     'Messages_Generator',
799 799
                     array(),
@@ -801,7 +801,7 @@  discard block
 block discarded – undo
801 801
                     false
802 802
                 );
803 803
             },
804
-            'EE_Messages_Template_Defaults'        => function ($arguments = array()) {
804
+            'EE_Messages_Template_Defaults'        => function($arguments = array()) {
805 805
                 return EE_Registry::instance()->load_lib(
806 806
                     'Messages_Template_Defaults',
807 807
                     $arguments,
@@ -810,31 +810,31 @@  discard block
 block discarded – undo
810 810
                 );
811 811
             },
812 812
             //load_helper
813
-            'EEH_Parse_Shortcodes'                 => function () {
813
+            'EEH_Parse_Shortcodes'                 => function() {
814 814
                 if (EE_Registry::instance()->load_helper('Parse_Shortcodes')) {
815 815
                     return new EEH_Parse_Shortcodes();
816 816
                 }
817 817
                 return null;
818 818
             },
819
-            'EE_Template_Config'                   => function () {
819
+            'EE_Template_Config'                   => function() {
820 820
                 return EE_Config::instance()->template_settings;
821 821
             },
822
-            'EE_Currency_Config'                   => function () {
822
+            'EE_Currency_Config'                   => function() {
823 823
                 return EE_Config::instance()->currency;
824 824
             },
825
-            'EE_Registration_Config'                   => function () {
825
+            'EE_Registration_Config'                   => function() {
826 826
                 return EE_Config::instance()->registration;
827 827
             },
828
-            'EE_Core_Config'                   => function () {
828
+            'EE_Core_Config'                   => function() {
829 829
                 return EE_Config::instance()->core;
830 830
             },
831
-            'EventEspresso\core\services\loaders\Loader' => function () {
831
+            'EventEspresso\core\services\loaders\Loader' => function() {
832 832
                 return LoaderFactory::getLoader();
833 833
             },
834 834
             'EE_Network_Config' => function() {
835 835
                 return EE_Network_Config::instance();
836 836
             },
837
-            'EE_Config' => function () {
837
+            'EE_Config' => function() {
838 838
                 return EE_Config::instance();
839 839
             }
840 840
         );
@@ -890,7 +890,7 @@  discard block
 block discarded – undo
890 890
             'EventEspresso\core\services\request\ResponseInterface'               => 'EventEspresso\core\services\request\Response',
891 891
             'EventEspresso\core\domain\DomainInterface'                           => 'EventEspresso\core\domain\Domain',
892 892
         );
893
-        if (! (defined('DOING_AJAX') && DOING_AJAX) && is_admin()) {
893
+        if ( ! (defined('DOING_AJAX') && DOING_AJAX) && is_admin()) {
894 894
             $this->_aliases['EventEspresso\core\services\notices\NoticeConverterInterface'] = 'EventEspresso\core\services\notices\ConvertNoticesToAdminNotices';
895 895
         }
896 896
     }
Please login to merge, or discard this patch.
Indentation   +905 added lines, -905 removed lines patch added patch discarded remove patch
@@ -8,7 +8,7 @@  discard block
 block discarded – undo
8 8
 use EventEspresso\core\services\request\ResponseInterface;
9 9
 
10 10
 if (! defined('EVENT_ESPRESSO_VERSION')) {
11
-    exit('No direct script access allowed');
11
+	exit('No direct script access allowed');
12 12
 }
13 13
 
14 14
 
@@ -25,911 +25,911 @@  discard block
 block discarded – undo
25 25
 class EE_Dependency_Map
26 26
 {
27 27
 
28
-    /**
29
-     * This means that the requested class dependency is not present in the dependency map
30
-     */
31
-    const not_registered = 0;
32
-
33
-    /**
34
-     * This instructs class loaders to ALWAYS return a newly instantiated object for the requested class.
35
-     */
36
-    const load_new_object = 1;
37
-
38
-    /**
39
-     * This instructs class loaders to return a previously instantiated and cached object for the requested class.
40
-     * IF a previously instantiated object does not exist, a new one will be created and added to the cache.
41
-     */
42
-    const load_from_cache = 2;
43
-
44
-    /**
45
-     * When registering a dependency,
46
-     * this indicates to keep any existing dependencies that already exist,
47
-     * and simply discard any new dependencies declared in the incoming data
48
-     */
49
-    const KEEP_EXISTING_DEPENDENCIES = 0;
50
-
51
-    /**
52
-     * When registering a dependency,
53
-     * this indicates to overwrite any existing dependencies that already exist using the incoming data
54
-     */
55
-    const OVERWRITE_DEPENDENCIES = 1;
56
-
57
-
58
-
59
-    /**
60
-     * @type EE_Dependency_Map $_instance
61
-     */
62
-    protected static $_instance;
63
-
64
-    /**
65
-     * @type RequestInterface $request
66
-     */
67
-    protected $request;
68
-
69
-    /**
70
-     * @type LegacyRequestInterface $legacy_request
71
-     */
72
-    protected $legacy_request;
73
-
74
-    /**
75
-     * @type ResponseInterface $response
76
-     */
77
-    protected $response;
78
-
79
-    /**
80
-     * @type LoaderInterface $loader
81
-     */
82
-    protected $loader;
83
-
84
-    /**
85
-     * @type array $_dependency_map
86
-     */
87
-    protected $_dependency_map = array();
88
-
89
-    /**
90
-     * @type array $_class_loaders
91
-     */
92
-    protected $_class_loaders = array();
93
-
94
-    /**
95
-     * @type array $_aliases
96
-     */
97
-    protected $_aliases = array();
98
-
99
-
100
-
101
-    /**
102
-     * EE_Dependency_Map constructor.
103
-     */
104
-    protected function __construct()
105
-    {
106
-        // add_action('EE_Load_Espresso_Core__handle_request__initialize_core_loading', array($this, 'initialize'));
107
-        do_action('EE_Dependency_Map____construct');
108
-    }
109
-
110
-
111
-
112
-    /**
113
-     * @throws InvalidDataTypeException
114
-     * @throws InvalidInterfaceException
115
-     * @throws InvalidArgumentException
116
-     */
117
-    public function initialize()
118
-    {
119
-        $this->_register_core_dependencies();
120
-        $this->_register_core_class_loaders();
121
-        $this->_register_core_aliases();
122
-    }
123
-
124
-
125
-
126
-    /**
127
-     * @singleton method used to instantiate class object
128
-     * @return EE_Dependency_Map
129
-     */
130
-    public static function instance() {
131
-        // check if class object is instantiated, and instantiated properly
132
-        if (! self::$_instance instanceof EE_Dependency_Map) {
133
-            self::$_instance = new EE_Dependency_Map(/*$request, $response, $legacy_request*/);
134
-        }
135
-        return self::$_instance;
136
-    }
137
-
138
-
139
-    /**
140
-     * @param RequestInterface $request
141
-     */
142
-    public function setRequest(RequestInterface $request)
143
-    {
144
-        $this->request = $request;
145
-    }
146
-
147
-
148
-    /**
149
-     * @param LegacyRequestInterface $legacy_request
150
-     */
151
-    public function setLegacyRequest(LegacyRequestInterface $legacy_request)
152
-    {
153
-        $this->legacy_request = $legacy_request;
154
-    }
155
-
156
-
157
-    /**
158
-     * @param ResponseInterface $response
159
-     */
160
-    public function setResponse(ResponseInterface $response)
161
-    {
162
-        $this->response = $response;
163
-    }
164
-
165
-
166
-
167
-    /**
168
-     * @param LoaderInterface $loader
169
-     */
170
-    public function setLoader(LoaderInterface $loader)
171
-    {
172
-        $this->loader = $loader;
173
-    }
174
-
175
-
176
-
177
-    /**
178
-     * @param string $class
179
-     * @param array  $dependencies
180
-     * @param int    $overwrite
181
-     * @return bool
182
-     */
183
-    public static function register_dependencies(
184
-        $class,
185
-        array $dependencies,
186
-        $overwrite = EE_Dependency_Map::KEEP_EXISTING_DEPENDENCIES
187
-    ) {
188
-        return self::$_instance->registerDependencies($class, $dependencies, $overwrite);
189
-    }
190
-
191
-
192
-
193
-    /**
194
-     * Assigns an array of class names and corresponding load sources (new or cached)
195
-     * to the class specified by the first parameter.
196
-     * IMPORTANT !!!
197
-     * The order of elements in the incoming $dependencies array MUST match
198
-     * the order of the constructor parameters for the class in question.
199
-     * This is especially important when overriding any existing dependencies that are registered.
200
-     * the third parameter controls whether any duplicate dependencies are overwritten or not.
201
-     *
202
-     * @param string $class
203
-     * @param array  $dependencies
204
-     * @param int    $overwrite
205
-     * @return bool
206
-     */
207
-    public function registerDependencies(
208
-        $class,
209
-        array $dependencies,
210
-        $overwrite = EE_Dependency_Map::KEEP_EXISTING_DEPENDENCIES
211
-    ) {
212
-        $class = trim($class, '\\');
213
-        $registered = false;
214
-        if (empty(self::$_instance->_dependency_map[ $class ])) {
215
-            self::$_instance->_dependency_map[ $class ] = array();
216
-        }
217
-        // we need to make sure that any aliases used when registering a dependency
218
-        // get resolved to the correct class name
219
-        foreach ($dependencies as $dependency => $load_source) {
220
-            $alias = self::$_instance->get_alias($dependency);
221
-            if (
222
-                $overwrite === EE_Dependency_Map::OVERWRITE_DEPENDENCIES
223
-                || ! isset(self::$_instance->_dependency_map[ $class ][ $alias ])
224
-            ) {
225
-                unset($dependencies[$dependency]);
226
-                $dependencies[$alias] = $load_source;
227
-                $registered = true;
228
-            }
229
-        }
230
-        // now add our two lists of dependencies together.
231
-        // using Union (+=) favours the arrays in precedence from left to right,
232
-        // so $dependencies is NOT overwritten because it is listed first
233
-        // ie: with A = B + C, entries in B take precedence over duplicate entries in C
234
-        // Union is way faster than array_merge() but should be used with caution...
235
-        // especially with numerically indexed arrays
236
-        $dependencies += self::$_instance->_dependency_map[ $class ];
237
-        // now we need to ensure that the resulting dependencies
238
-        // array only has the entries that are required for the class
239
-        // so first count how many dependencies were originally registered for the class
240
-        $dependency_count = count(self::$_instance->_dependency_map[ $class ]);
241
-        // if that count is non-zero (meaning dependencies were already registered)
242
-        self::$_instance->_dependency_map[ $class ] = $dependency_count
243
-            // then truncate the  final array to match that count
244
-            ? array_slice($dependencies, 0, $dependency_count)
245
-            // otherwise just take the incoming array because nothing previously existed
246
-            : $dependencies;
247
-        return $registered;
248
-    }
249
-
250
-
251
-
252
-    /**
253
-     * @param string $class_name
254
-     * @param string $loader
255
-     * @return bool
256
-     * @throws DomainException
257
-     */
258
-    public static function register_class_loader($class_name, $loader = 'load_core')
259
-    {
260
-        if (! $loader instanceof Closure && strpos($class_name, '\\') !== false) {
261
-            throw new DomainException(
262
-                esc_html__('Don\'t use class loaders for FQCNs.', 'event_espresso')
263
-            );
264
-        }
265
-        // check that loader is callable or method starts with "load_" and exists in EE_Registry
266
-        if (
267
-            ! is_callable($loader)
268
-            && (
269
-                strpos($loader, 'load_') !== 0
270
-                || ! method_exists('EE_Registry', $loader)
271
-            )
272
-        ) {
273
-            throw new DomainException(
274
-                sprintf(
275
-                    esc_html__(
276
-                        '"%1$s" is not a valid loader method on EE_Registry.',
277
-                        'event_espresso'
278
-                    ),
279
-                    $loader
280
-                )
281
-            );
282
-        }
283
-        $class_name = self::$_instance->get_alias($class_name);
284
-        if (! isset(self::$_instance->_class_loaders[$class_name])) {
285
-            self::$_instance->_class_loaders[$class_name] = $loader;
286
-            return true;
287
-        }
288
-        return false;
289
-    }
290
-
291
-
292
-
293
-    /**
294
-     * @return array
295
-     */
296
-    public function dependency_map()
297
-    {
298
-        return $this->_dependency_map;
299
-    }
300
-
301
-
302
-
303
-    /**
304
-     * returns TRUE if dependency map contains a listing for the provided class name
305
-     *
306
-     * @param string $class_name
307
-     * @return boolean
308
-     */
309
-    public function has($class_name = '')
310
-    {
311
-        // all legacy models have the same dependencies
312
-        if (strpos($class_name, 'EEM_') === 0) {
313
-            $class_name = 'LEGACY_MODELS';
314
-        }
315
-        return isset($this->_dependency_map[$class_name]) ? true : false;
316
-    }
317
-
318
-
319
-
320
-    /**
321
-     * returns TRUE if dependency map contains a listing for the provided class name AND dependency
322
-     *
323
-     * @param string $class_name
324
-     * @param string $dependency
325
-     * @return bool
326
-     */
327
-    public function has_dependency_for_class($class_name = '', $dependency = '')
328
-    {
329
-        // all legacy models have the same dependencies
330
-        if (strpos($class_name, 'EEM_') === 0) {
331
-            $class_name = 'LEGACY_MODELS';
332
-        }
333
-        $dependency = $this->get_alias($dependency);
334
-        return isset($this->_dependency_map[$class_name][$dependency])
335
-            ? true
336
-            : false;
337
-    }
338
-
339
-
340
-
341
-    /**
342
-     * returns loading strategy for whether a previously cached dependency should be loaded or a new instance returned
343
-     *
344
-     * @param string $class_name
345
-     * @param string $dependency
346
-     * @return int
347
-     */
348
-    public function loading_strategy_for_class_dependency($class_name = '', $dependency = '')
349
-    {
350
-        // all legacy models have the same dependencies
351
-        if (strpos($class_name, 'EEM_') === 0) {
352
-            $class_name = 'LEGACY_MODELS';
353
-        }
354
-        $dependency = $this->get_alias($dependency);
355
-        return $this->has_dependency_for_class($class_name, $dependency)
356
-            ? $this->_dependency_map[$class_name][$dependency]
357
-            : EE_Dependency_Map::not_registered;
358
-    }
359
-
360
-
361
-
362
-    /**
363
-     * @param string $class_name
364
-     * @return string | Closure
365
-     */
366
-    public function class_loader($class_name)
367
-    {
368
-        // all legacy models use load_model()
369
-        if(strpos($class_name, 'EEM_') === 0){
370
-            return 'load_model';
371
-        }
372
-        $class_name = $this->get_alias($class_name);
373
-        return isset($this->_class_loaders[$class_name]) ? $this->_class_loaders[$class_name] : '';
374
-    }
375
-
376
-
377
-
378
-    /**
379
-     * @return array
380
-     */
381
-    public function class_loaders()
382
-    {
383
-        return $this->_class_loaders;
384
-    }
385
-
386
-
387
-
388
-    /**
389
-     * adds an alias for a classname
390
-     *
391
-     * @param string $class_name the class name that should be used (concrete class to replace interface)
392
-     * @param string $alias      the class name that would be type hinted for (abstract parent or interface)
393
-     * @param string $for_class  the class that has the dependency (is type hinting for the interface)
394
-     */
395
-    public function add_alias($class_name, $alias, $for_class = '')
396
-    {
397
-        if ($for_class !== '') {
398
-            if (! isset($this->_aliases[$for_class])) {
399
-                $this->_aliases[$for_class] = array();
400
-            }
401
-            $this->_aliases[$for_class][$class_name] = $alias;
402
-        }
403
-        $this->_aliases[$class_name] = $alias;
404
-    }
405
-
406
-
407
-
408
-    /**
409
-     * returns TRUE if the provided class name has an alias
410
-     *
411
-     * @param string $class_name
412
-     * @param string $for_class
413
-     * @return bool
414
-     */
415
-    public function has_alias($class_name = '', $for_class = '')
416
-    {
417
-        return isset($this->_aliases[$for_class][$class_name])
418
-               || (
419
-                   isset($this->_aliases[$class_name])
420
-                   && ! is_array($this->_aliases[$class_name])
421
-               );
422
-    }
423
-
424
-
425
-
426
-    /**
427
-     * returns alias for class name if one exists, otherwise returns the original classname
428
-     * functions recursively, so that multiple aliases can be used to drill down to a classname
429
-     *  for example:
430
-     *      if the following two entries were added to the _aliases array:
431
-     *          array(
432
-     *              'interface_alias'           => 'some\namespace\interface'
433
-     *              'some\namespace\interface'  => 'some\namespace\classname'
434
-     *          )
435
-     *      then one could use EE_Registry::instance()->create( 'interface_alias' )
436
-     *      to load an instance of 'some\namespace\classname'
437
-     *
438
-     * @param string $class_name
439
-     * @param string $for_class
440
-     * @return string
441
-     */
442
-    public function get_alias($class_name = '', $for_class = '')
443
-    {
444
-        if (! $this->has_alias($class_name, $for_class)) {
445
-            return $class_name;
446
-        }
447
-        if ($for_class !== '' && isset($this->_aliases[ $for_class ][ $class_name ])) {
448
-            return $this->get_alias($this->_aliases[$for_class][$class_name], $for_class);
449
-        }
450
-        return $this->get_alias($this->_aliases[$class_name]);
451
-    }
452
-
453
-
454
-
455
-    /**
456
-     * Registers the core dependencies and whether a previously instantiated object should be loaded from the cache,
457
-     * if one exists, or whether a new object should be generated every time the requested class is loaded.
458
-     * This is done by using the following class constants:
459
-     *        EE_Dependency_Map::load_from_cache - loads previously instantiated object
460
-     *        EE_Dependency_Map::load_new_object - generates a new object every time
461
-     */
462
-    protected function _register_core_dependencies()
463
-    {
464
-        $this->_dependency_map = array(
465
-            'EE_Request_Handler'                                                                                          => array(
466
-                'EE_Request' => EE_Dependency_Map::load_from_cache,
467
-            ),
468
-            'EE_System'                                                                                                   => array(
469
-                'EE_Registry'                                 => EE_Dependency_Map::load_from_cache,
470
-                'EventEspresso\core\services\loaders\Loader'  => EE_Dependency_Map::load_from_cache,
471
-                'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache,
472
-                'EE_Maintenance_Mode'                         => EE_Dependency_Map::load_from_cache,
473
-            ),
474
-            'EE_Session'                                                                                                  => array(
475
-                'EventEspresso\core\services\cache\TransientCacheStorage'  => EE_Dependency_Map::load_from_cache,
476
-                'EventEspresso\core\domain\values\session\SessionLifespan' => EE_Dependency_Map::load_from_cache,
477
-                'EventEspresso\core\services\request\Request'              => EE_Dependency_Map::load_from_cache,
478
-                'EE_Encryption'                                            => EE_Dependency_Map::load_from_cache,
479
-            ),
480
-            'EE_Cart'                                                                                                     => array(
481
-                'EE_Session' => EE_Dependency_Map::load_from_cache,
482
-            ),
483
-            'EE_Front_Controller'                                                                                         => array(
484
-                'EE_Registry'              => EE_Dependency_Map::load_from_cache,
485
-                'EE_Request_Handler'       => EE_Dependency_Map::load_from_cache,
486
-                'EE_Module_Request_Router' => EE_Dependency_Map::load_from_cache,
487
-            ),
488
-            'EE_Messenger_Collection_Loader'                                                                              => array(
489
-                'EE_Messenger_Collection' => EE_Dependency_Map::load_new_object,
490
-            ),
491
-            'EE_Message_Type_Collection_Loader'                                                                           => array(
492
-                'EE_Message_Type_Collection' => EE_Dependency_Map::load_new_object,
493
-            ),
494
-            'EE_Message_Resource_Manager'                                                                                 => array(
495
-                'EE_Messenger_Collection_Loader'    => EE_Dependency_Map::load_new_object,
496
-                'EE_Message_Type_Collection_Loader' => EE_Dependency_Map::load_new_object,
497
-                'EEM_Message_Template_Group'        => EE_Dependency_Map::load_from_cache,
498
-            ),
499
-            'EE_Message_Factory'                                                                                          => array(
500
-                'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache,
501
-            ),
502
-            'EE_messages'                                                                                                 => array(
503
-                'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache,
504
-            ),
505
-            'EE_Messages_Generator'                                                                                       => array(
506
-                'EE_Messages_Queue'                    => EE_Dependency_Map::load_new_object,
507
-                'EE_Messages_Data_Handler_Collection'  => EE_Dependency_Map::load_new_object,
508
-                'EE_Message_Template_Group_Collection' => EE_Dependency_Map::load_new_object,
509
-                'EEH_Parse_Shortcodes'                 => EE_Dependency_Map::load_from_cache,
510
-            ),
511
-            'EE_Messages_Processor'                                                                                       => array(
512
-                'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache,
513
-            ),
514
-            'EE_Messages_Queue'                                                                                           => array(
515
-                'EE_Message_Repository' => EE_Dependency_Map::load_new_object,
516
-            ),
517
-            'EE_Messages_Template_Defaults'                                                                               => array(
518
-                'EEM_Message_Template_Group' => EE_Dependency_Map::load_from_cache,
519
-                'EEM_Message_Template'       => EE_Dependency_Map::load_from_cache,
520
-            ),
521
-            'EE_Message_To_Generate_From_Request'                                                                         => array(
522
-                'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache,
523
-                'EE_Request_Handler'          => EE_Dependency_Map::load_from_cache,
524
-            ),
525
-            'EventEspresso\core\services\commands\CommandBus'                                                             => array(
526
-                'EventEspresso\core\services\commands\CommandHandlerManager' => EE_Dependency_Map::load_from_cache,
527
-            ),
528
-            'EventEspresso\services\commands\CommandHandler'                                                              => array(
529
-                'EE_Registry'         => EE_Dependency_Map::load_from_cache,
530
-                'CommandBusInterface' => EE_Dependency_Map::load_from_cache,
531
-            ),
532
-            'EventEspresso\core\services\commands\CommandHandlerManager'                                                  => array(
533
-                'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache,
534
-            ),
535
-            'EventEspresso\core\services\commands\CompositeCommandHandler'                                                => array(
536
-                'EventEspresso\core\services\commands\CommandBus'     => EE_Dependency_Map::load_from_cache,
537
-                'EventEspresso\core\services\commands\CommandFactory' => EE_Dependency_Map::load_from_cache,
538
-            ),
539
-            'EventEspresso\core\services\commands\CommandFactory'                                                         => array(
540
-                'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache,
541
-            ),
542
-            'EventEspresso\core\services\commands\middleware\CapChecker'                                                  => array(
543
-                'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => EE_Dependency_Map::load_from_cache,
544
-            ),
545
-            'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker'                                         => array(
546
-                'EE_Capabilities' => EE_Dependency_Map::load_from_cache,
547
-            ),
548
-            'EventEspresso\core\domain\services\capabilities\RegistrationsCapChecker'                                     => array(
549
-                'EE_Capabilities' => EE_Dependency_Map::load_from_cache,
550
-            ),
551
-            'EventEspresso\core\services\commands\registration\CreateRegistrationCommandHandler'                          => array(
552
-                'EventEspresso\core\domain\services\registration\CreateRegistrationService' => EE_Dependency_Map::load_from_cache,
553
-            ),
554
-            'EventEspresso\core\services\commands\registration\CopyRegistrationDetailsCommandHandler'                     => array(
555
-                'EventEspresso\core\domain\services\registration\CopyRegistrationService' => EE_Dependency_Map::load_from_cache,
556
-            ),
557
-            'EventEspresso\core\services\commands\registration\CopyRegistrationPaymentsCommandHandler'                    => array(
558
-                'EventEspresso\core\domain\services\registration\CopyRegistrationService' => EE_Dependency_Map::load_from_cache,
559
-            ),
560
-            'EventEspresso\core\services\commands\registration\CancelRegistrationAndTicketLineItemCommandHandler'         => array(
561
-                'EventEspresso\core\domain\services\registration\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache,
562
-            ),
563
-            'EventEspresso\core\services\commands\registration\UpdateRegistrationAndTransactionAfterChangeCommandHandler' => array(
564
-                'EventEspresso\core\domain\services\registration\UpdateRegistrationService' => EE_Dependency_Map::load_from_cache,
565
-            ),
566
-            'EventEspresso\core\services\commands\ticket\CreateTicketLineItemCommandHandler'                              => array(
567
-                'EventEspresso\core\domain\services\ticket\CreateTicketLineItemService' => EE_Dependency_Map::load_from_cache,
568
-            ),
569
-            'EventEspresso\core\services\commands\ticket\CancelTicketLineItemCommandHandler'                              => array(
570
-                'EventEspresso\core\domain\services\ticket\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache,
571
-            ),
572
-            'EventEspresso\core\domain\services\registration\CancelRegistrationService'                                   => array(
573
-                'EventEspresso\core\domain\services\ticket\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache,
574
-            ),
575
-            'EventEspresso\core\services\commands\attendee\CreateAttendeeCommandHandler'                                  => array(
576
-                'EEM_Attendee' => EE_Dependency_Map::load_from_cache,
577
-            ),
578
-            'EventEspresso\core\services\database\TableManager'                                                           => array(
579
-                'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
580
-            ),
581
-            'EE_Data_Migration_Class_Base'                                                                                => array(
582
-                'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
583
-                'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
584
-            ),
585
-            'EE_DMS_Core_4_1_0'                                                                                           => array(
586
-                'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
587
-                'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
588
-            ),
589
-            'EE_DMS_Core_4_2_0'                                                                                           => array(
590
-                'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
591
-                'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
592
-            ),
593
-            'EE_DMS_Core_4_3_0'                                                                                           => array(
594
-                'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
595
-                'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
596
-            ),
597
-            'EE_DMS_Core_4_4_0'                                                                                           => array(
598
-                'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
599
-                'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
600
-            ),
601
-            'EE_DMS_Core_4_5_0'                                                                                           => array(
602
-                'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
603
-                'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
604
-            ),
605
-            'EE_DMS_Core_4_6_0'                                                                                           => array(
606
-                'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
607
-                'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
608
-            ),
609
-            'EE_DMS_Core_4_7_0'                                                                                           => array(
610
-                'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
611
-                'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
612
-            ),
613
-            'EE_DMS_Core_4_8_0'                                                                                           => array(
614
-                'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
615
-                'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
616
-            ),
617
-            'EE_DMS_Core_4_9_0'                                                                                           => array(
618
-                'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
619
-                'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
620
-            ),
621
-            'EventEspresso\core\services\assets\I18nRegistry' => array(
622
-                array(),
623
-                'EventEspresso\core\domain\Domain' => EE_Dependency_Map::load_from_cache
624
-            ),
625
-            'EventEspresso\core\services\assets\Registry'                                                                 => array(
626
-                'EE_Template_Config' => EE_Dependency_Map::load_from_cache,
627
-                'EE_Currency_Config' => EE_Dependency_Map::load_from_cache,
628
-                'EventEspresso\core\services\assets\I18nRegistry' => EE_Dependency_Map::load_from_cache,
629
-                'EventEspresso\core\domain\Domain' => EE_Dependency_Map::load_from_cache
630
-            ),
631
-            'EventEspresso\core\domain\entities\shortcodes\EspressoCancelled'                                             => array(
632
-                'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache,
633
-            ),
634
-            'EventEspresso\core\domain\entities\shortcodes\EspressoCheckout'                                              => array(
635
-                'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache,
636
-            ),
637
-            'EventEspresso\core\domain\entities\shortcodes\EspressoEventAttendees'                                        => array(
638
-                'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache,
639
-            ),
640
-            'EventEspresso\core\domain\entities\shortcodes\EspressoEvents'                                                => array(
641
-                'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache,
642
-            ),
643
-            'EventEspresso\core\domain\entities\shortcodes\EspressoThankYou'                                              => array(
644
-                'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache,
645
-            ),
646
-            'EventEspresso\core\domain\entities\shortcodes\EspressoTicketSelector'                                        => array(
647
-                'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache,
648
-            ),
649
-            'EventEspresso\core\domain\entities\shortcodes\EspressoTxnPage'                                               => array(
650
-                'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache,
651
-            ),
652
-            'EventEspresso\core\services\cache\BasicCacheManager'                        => array(
653
-                'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache,
654
-            ),
655
-            'EventEspresso\core\services\cache\PostRelatedCacheManager'                  => array(
656
-                'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache,
657
-            ),
658
-            'EventEspresso\core\domain\services\validation\email\EmailValidationService' => array(
659
-                'EE_Registration_Config'                                  => EE_Dependency_Map::load_from_cache,
660
-                'EventEspresso\core\services\loaders\Loader'              => EE_Dependency_Map::load_from_cache,
661
-            ),
662
-            'EventEspresso\core\domain\values\EmailAddress'                              => array(
663
-                null,
664
-                'EventEspresso\core\domain\services\validation\email\EmailValidationService' => EE_Dependency_Map::load_from_cache,
665
-            ),
666
-            'EventEspresso\core\services\orm\ModelFieldFactory' => array(
667
-                'EventEspresso\core\services\loaders\Loader'              => EE_Dependency_Map::load_from_cache,
668
-            ),
669
-            'LEGACY_MODELS'                                                   => array(
670
-                null,
671
-                'EventEspresso\core\services\database\ModelFieldFactory' => EE_Dependency_Map::load_from_cache,
672
-            ),
673
-            'EE_Module_Request_Router' => array(
674
-                'EE_Request' => EE_Dependency_Map::load_from_cache,
675
-            ),
676
-            'EE_Registration_Processor' => array(
677
-                'EE_Request' => EE_Dependency_Map::load_from_cache,
678
-            ),
679
-            'EventEspresso\core\services\notifications\PersistentAdminNoticeManager' => array(
680
-                null,
681
-                'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => EE_Dependency_Map::load_from_cache,
682
-                'EE_Request' => EE_Dependency_Map::load_from_cache,
683
-            ),
684
-            'EventEspresso\core\services\licensing\LicenseService' => array(
685
-                'EventEspresso\core\domain\services\pue\Stats' => EE_Dependency_Map::load_from_cache,
686
-                'EventEspresso\core\domain\services\pue\Config' => EE_Dependency_Map::load_from_cache
687
-            ),
28
+	/**
29
+	 * This means that the requested class dependency is not present in the dependency map
30
+	 */
31
+	const not_registered = 0;
32
+
33
+	/**
34
+	 * This instructs class loaders to ALWAYS return a newly instantiated object for the requested class.
35
+	 */
36
+	const load_new_object = 1;
37
+
38
+	/**
39
+	 * This instructs class loaders to return a previously instantiated and cached object for the requested class.
40
+	 * IF a previously instantiated object does not exist, a new one will be created and added to the cache.
41
+	 */
42
+	const load_from_cache = 2;
43
+
44
+	/**
45
+	 * When registering a dependency,
46
+	 * this indicates to keep any existing dependencies that already exist,
47
+	 * and simply discard any new dependencies declared in the incoming data
48
+	 */
49
+	const KEEP_EXISTING_DEPENDENCIES = 0;
50
+
51
+	/**
52
+	 * When registering a dependency,
53
+	 * this indicates to overwrite any existing dependencies that already exist using the incoming data
54
+	 */
55
+	const OVERWRITE_DEPENDENCIES = 1;
56
+
57
+
58
+
59
+	/**
60
+	 * @type EE_Dependency_Map $_instance
61
+	 */
62
+	protected static $_instance;
63
+
64
+	/**
65
+	 * @type RequestInterface $request
66
+	 */
67
+	protected $request;
68
+
69
+	/**
70
+	 * @type LegacyRequestInterface $legacy_request
71
+	 */
72
+	protected $legacy_request;
73
+
74
+	/**
75
+	 * @type ResponseInterface $response
76
+	 */
77
+	protected $response;
78
+
79
+	/**
80
+	 * @type LoaderInterface $loader
81
+	 */
82
+	protected $loader;
83
+
84
+	/**
85
+	 * @type array $_dependency_map
86
+	 */
87
+	protected $_dependency_map = array();
88
+
89
+	/**
90
+	 * @type array $_class_loaders
91
+	 */
92
+	protected $_class_loaders = array();
93
+
94
+	/**
95
+	 * @type array $_aliases
96
+	 */
97
+	protected $_aliases = array();
98
+
99
+
100
+
101
+	/**
102
+	 * EE_Dependency_Map constructor.
103
+	 */
104
+	protected function __construct()
105
+	{
106
+		// add_action('EE_Load_Espresso_Core__handle_request__initialize_core_loading', array($this, 'initialize'));
107
+		do_action('EE_Dependency_Map____construct');
108
+	}
109
+
110
+
111
+
112
+	/**
113
+	 * @throws InvalidDataTypeException
114
+	 * @throws InvalidInterfaceException
115
+	 * @throws InvalidArgumentException
116
+	 */
117
+	public function initialize()
118
+	{
119
+		$this->_register_core_dependencies();
120
+		$this->_register_core_class_loaders();
121
+		$this->_register_core_aliases();
122
+	}
123
+
124
+
125
+
126
+	/**
127
+	 * @singleton method used to instantiate class object
128
+	 * @return EE_Dependency_Map
129
+	 */
130
+	public static function instance() {
131
+		// check if class object is instantiated, and instantiated properly
132
+		if (! self::$_instance instanceof EE_Dependency_Map) {
133
+			self::$_instance = new EE_Dependency_Map(/*$request, $response, $legacy_request*/);
134
+		}
135
+		return self::$_instance;
136
+	}
137
+
138
+
139
+	/**
140
+	 * @param RequestInterface $request
141
+	 */
142
+	public function setRequest(RequestInterface $request)
143
+	{
144
+		$this->request = $request;
145
+	}
146
+
147
+
148
+	/**
149
+	 * @param LegacyRequestInterface $legacy_request
150
+	 */
151
+	public function setLegacyRequest(LegacyRequestInterface $legacy_request)
152
+	{
153
+		$this->legacy_request = $legacy_request;
154
+	}
155
+
156
+
157
+	/**
158
+	 * @param ResponseInterface $response
159
+	 */
160
+	public function setResponse(ResponseInterface $response)
161
+	{
162
+		$this->response = $response;
163
+	}
164
+
165
+
166
+
167
+	/**
168
+	 * @param LoaderInterface $loader
169
+	 */
170
+	public function setLoader(LoaderInterface $loader)
171
+	{
172
+		$this->loader = $loader;
173
+	}
174
+
175
+
176
+
177
+	/**
178
+	 * @param string $class
179
+	 * @param array  $dependencies
180
+	 * @param int    $overwrite
181
+	 * @return bool
182
+	 */
183
+	public static function register_dependencies(
184
+		$class,
185
+		array $dependencies,
186
+		$overwrite = EE_Dependency_Map::KEEP_EXISTING_DEPENDENCIES
187
+	) {
188
+		return self::$_instance->registerDependencies($class, $dependencies, $overwrite);
189
+	}
190
+
191
+
192
+
193
+	/**
194
+	 * Assigns an array of class names and corresponding load sources (new or cached)
195
+	 * to the class specified by the first parameter.
196
+	 * IMPORTANT !!!
197
+	 * The order of elements in the incoming $dependencies array MUST match
198
+	 * the order of the constructor parameters for the class in question.
199
+	 * This is especially important when overriding any existing dependencies that are registered.
200
+	 * the third parameter controls whether any duplicate dependencies are overwritten or not.
201
+	 *
202
+	 * @param string $class
203
+	 * @param array  $dependencies
204
+	 * @param int    $overwrite
205
+	 * @return bool
206
+	 */
207
+	public function registerDependencies(
208
+		$class,
209
+		array $dependencies,
210
+		$overwrite = EE_Dependency_Map::KEEP_EXISTING_DEPENDENCIES
211
+	) {
212
+		$class = trim($class, '\\');
213
+		$registered = false;
214
+		if (empty(self::$_instance->_dependency_map[ $class ])) {
215
+			self::$_instance->_dependency_map[ $class ] = array();
216
+		}
217
+		// we need to make sure that any aliases used when registering a dependency
218
+		// get resolved to the correct class name
219
+		foreach ($dependencies as $dependency => $load_source) {
220
+			$alias = self::$_instance->get_alias($dependency);
221
+			if (
222
+				$overwrite === EE_Dependency_Map::OVERWRITE_DEPENDENCIES
223
+				|| ! isset(self::$_instance->_dependency_map[ $class ][ $alias ])
224
+			) {
225
+				unset($dependencies[$dependency]);
226
+				$dependencies[$alias] = $load_source;
227
+				$registered = true;
228
+			}
229
+		}
230
+		// now add our two lists of dependencies together.
231
+		// using Union (+=) favours the arrays in precedence from left to right,
232
+		// so $dependencies is NOT overwritten because it is listed first
233
+		// ie: with A = B + C, entries in B take precedence over duplicate entries in C
234
+		// Union is way faster than array_merge() but should be used with caution...
235
+		// especially with numerically indexed arrays
236
+		$dependencies += self::$_instance->_dependency_map[ $class ];
237
+		// now we need to ensure that the resulting dependencies
238
+		// array only has the entries that are required for the class
239
+		// so first count how many dependencies were originally registered for the class
240
+		$dependency_count = count(self::$_instance->_dependency_map[ $class ]);
241
+		// if that count is non-zero (meaning dependencies were already registered)
242
+		self::$_instance->_dependency_map[ $class ] = $dependency_count
243
+			// then truncate the  final array to match that count
244
+			? array_slice($dependencies, 0, $dependency_count)
245
+			// otherwise just take the incoming array because nothing previously existed
246
+			: $dependencies;
247
+		return $registered;
248
+	}
249
+
250
+
251
+
252
+	/**
253
+	 * @param string $class_name
254
+	 * @param string $loader
255
+	 * @return bool
256
+	 * @throws DomainException
257
+	 */
258
+	public static function register_class_loader($class_name, $loader = 'load_core')
259
+	{
260
+		if (! $loader instanceof Closure && strpos($class_name, '\\') !== false) {
261
+			throw new DomainException(
262
+				esc_html__('Don\'t use class loaders for FQCNs.', 'event_espresso')
263
+			);
264
+		}
265
+		// check that loader is callable or method starts with "load_" and exists in EE_Registry
266
+		if (
267
+			! is_callable($loader)
268
+			&& (
269
+				strpos($loader, 'load_') !== 0
270
+				|| ! method_exists('EE_Registry', $loader)
271
+			)
272
+		) {
273
+			throw new DomainException(
274
+				sprintf(
275
+					esc_html__(
276
+						'"%1$s" is not a valid loader method on EE_Registry.',
277
+						'event_espresso'
278
+					),
279
+					$loader
280
+				)
281
+			);
282
+		}
283
+		$class_name = self::$_instance->get_alias($class_name);
284
+		if (! isset(self::$_instance->_class_loaders[$class_name])) {
285
+			self::$_instance->_class_loaders[$class_name] = $loader;
286
+			return true;
287
+		}
288
+		return false;
289
+	}
290
+
291
+
292
+
293
+	/**
294
+	 * @return array
295
+	 */
296
+	public function dependency_map()
297
+	{
298
+		return $this->_dependency_map;
299
+	}
300
+
301
+
302
+
303
+	/**
304
+	 * returns TRUE if dependency map contains a listing for the provided class name
305
+	 *
306
+	 * @param string $class_name
307
+	 * @return boolean
308
+	 */
309
+	public function has($class_name = '')
310
+	{
311
+		// all legacy models have the same dependencies
312
+		if (strpos($class_name, 'EEM_') === 0) {
313
+			$class_name = 'LEGACY_MODELS';
314
+		}
315
+		return isset($this->_dependency_map[$class_name]) ? true : false;
316
+	}
317
+
318
+
319
+
320
+	/**
321
+	 * returns TRUE if dependency map contains a listing for the provided class name AND dependency
322
+	 *
323
+	 * @param string $class_name
324
+	 * @param string $dependency
325
+	 * @return bool
326
+	 */
327
+	public function has_dependency_for_class($class_name = '', $dependency = '')
328
+	{
329
+		// all legacy models have the same dependencies
330
+		if (strpos($class_name, 'EEM_') === 0) {
331
+			$class_name = 'LEGACY_MODELS';
332
+		}
333
+		$dependency = $this->get_alias($dependency);
334
+		return isset($this->_dependency_map[$class_name][$dependency])
335
+			? true
336
+			: false;
337
+	}
338
+
339
+
340
+
341
+	/**
342
+	 * returns loading strategy for whether a previously cached dependency should be loaded or a new instance returned
343
+	 *
344
+	 * @param string $class_name
345
+	 * @param string $dependency
346
+	 * @return int
347
+	 */
348
+	public function loading_strategy_for_class_dependency($class_name = '', $dependency = '')
349
+	{
350
+		// all legacy models have the same dependencies
351
+		if (strpos($class_name, 'EEM_') === 0) {
352
+			$class_name = 'LEGACY_MODELS';
353
+		}
354
+		$dependency = $this->get_alias($dependency);
355
+		return $this->has_dependency_for_class($class_name, $dependency)
356
+			? $this->_dependency_map[$class_name][$dependency]
357
+			: EE_Dependency_Map::not_registered;
358
+	}
359
+
360
+
361
+
362
+	/**
363
+	 * @param string $class_name
364
+	 * @return string | Closure
365
+	 */
366
+	public function class_loader($class_name)
367
+	{
368
+		// all legacy models use load_model()
369
+		if(strpos($class_name, 'EEM_') === 0){
370
+			return 'load_model';
371
+		}
372
+		$class_name = $this->get_alias($class_name);
373
+		return isset($this->_class_loaders[$class_name]) ? $this->_class_loaders[$class_name] : '';
374
+	}
375
+
376
+
377
+
378
+	/**
379
+	 * @return array
380
+	 */
381
+	public function class_loaders()
382
+	{
383
+		return $this->_class_loaders;
384
+	}
385
+
386
+
387
+
388
+	/**
389
+	 * adds an alias for a classname
390
+	 *
391
+	 * @param string $class_name the class name that should be used (concrete class to replace interface)
392
+	 * @param string $alias      the class name that would be type hinted for (abstract parent or interface)
393
+	 * @param string $for_class  the class that has the dependency (is type hinting for the interface)
394
+	 */
395
+	public function add_alias($class_name, $alias, $for_class = '')
396
+	{
397
+		if ($for_class !== '') {
398
+			if (! isset($this->_aliases[$for_class])) {
399
+				$this->_aliases[$for_class] = array();
400
+			}
401
+			$this->_aliases[$for_class][$class_name] = $alias;
402
+		}
403
+		$this->_aliases[$class_name] = $alias;
404
+	}
405
+
406
+
407
+
408
+	/**
409
+	 * returns TRUE if the provided class name has an alias
410
+	 *
411
+	 * @param string $class_name
412
+	 * @param string $for_class
413
+	 * @return bool
414
+	 */
415
+	public function has_alias($class_name = '', $for_class = '')
416
+	{
417
+		return isset($this->_aliases[$for_class][$class_name])
418
+			   || (
419
+				   isset($this->_aliases[$class_name])
420
+				   && ! is_array($this->_aliases[$class_name])
421
+			   );
422
+	}
423
+
424
+
425
+
426
+	/**
427
+	 * returns alias for class name if one exists, otherwise returns the original classname
428
+	 * functions recursively, so that multiple aliases can be used to drill down to a classname
429
+	 *  for example:
430
+	 *      if the following two entries were added to the _aliases array:
431
+	 *          array(
432
+	 *              'interface_alias'           => 'some\namespace\interface'
433
+	 *              'some\namespace\interface'  => 'some\namespace\classname'
434
+	 *          )
435
+	 *      then one could use EE_Registry::instance()->create( 'interface_alias' )
436
+	 *      to load an instance of 'some\namespace\classname'
437
+	 *
438
+	 * @param string $class_name
439
+	 * @param string $for_class
440
+	 * @return string
441
+	 */
442
+	public function get_alias($class_name = '', $for_class = '')
443
+	{
444
+		if (! $this->has_alias($class_name, $for_class)) {
445
+			return $class_name;
446
+		}
447
+		if ($for_class !== '' && isset($this->_aliases[ $for_class ][ $class_name ])) {
448
+			return $this->get_alias($this->_aliases[$for_class][$class_name], $for_class);
449
+		}
450
+		return $this->get_alias($this->_aliases[$class_name]);
451
+	}
452
+
453
+
454
+
455
+	/**
456
+	 * Registers the core dependencies and whether a previously instantiated object should be loaded from the cache,
457
+	 * if one exists, or whether a new object should be generated every time the requested class is loaded.
458
+	 * This is done by using the following class constants:
459
+	 *        EE_Dependency_Map::load_from_cache - loads previously instantiated object
460
+	 *        EE_Dependency_Map::load_new_object - generates a new object every time
461
+	 */
462
+	protected function _register_core_dependencies()
463
+	{
464
+		$this->_dependency_map = array(
465
+			'EE_Request_Handler'                                                                                          => array(
466
+				'EE_Request' => EE_Dependency_Map::load_from_cache,
467
+			),
468
+			'EE_System'                                                                                                   => array(
469
+				'EE_Registry'                                 => EE_Dependency_Map::load_from_cache,
470
+				'EventEspresso\core\services\loaders\Loader'  => EE_Dependency_Map::load_from_cache,
471
+				'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache,
472
+				'EE_Maintenance_Mode'                         => EE_Dependency_Map::load_from_cache,
473
+			),
474
+			'EE_Session'                                                                                                  => array(
475
+				'EventEspresso\core\services\cache\TransientCacheStorage'  => EE_Dependency_Map::load_from_cache,
476
+				'EventEspresso\core\domain\values\session\SessionLifespan' => EE_Dependency_Map::load_from_cache,
477
+				'EventEspresso\core\services\request\Request'              => EE_Dependency_Map::load_from_cache,
478
+				'EE_Encryption'                                            => EE_Dependency_Map::load_from_cache,
479
+			),
480
+			'EE_Cart'                                                                                                     => array(
481
+				'EE_Session' => EE_Dependency_Map::load_from_cache,
482
+			),
483
+			'EE_Front_Controller'                                                                                         => array(
484
+				'EE_Registry'              => EE_Dependency_Map::load_from_cache,
485
+				'EE_Request_Handler'       => EE_Dependency_Map::load_from_cache,
486
+				'EE_Module_Request_Router' => EE_Dependency_Map::load_from_cache,
487
+			),
488
+			'EE_Messenger_Collection_Loader'                                                                              => array(
489
+				'EE_Messenger_Collection' => EE_Dependency_Map::load_new_object,
490
+			),
491
+			'EE_Message_Type_Collection_Loader'                                                                           => array(
492
+				'EE_Message_Type_Collection' => EE_Dependency_Map::load_new_object,
493
+			),
494
+			'EE_Message_Resource_Manager'                                                                                 => array(
495
+				'EE_Messenger_Collection_Loader'    => EE_Dependency_Map::load_new_object,
496
+				'EE_Message_Type_Collection_Loader' => EE_Dependency_Map::load_new_object,
497
+				'EEM_Message_Template_Group'        => EE_Dependency_Map::load_from_cache,
498
+			),
499
+			'EE_Message_Factory'                                                                                          => array(
500
+				'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache,
501
+			),
502
+			'EE_messages'                                                                                                 => array(
503
+				'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache,
504
+			),
505
+			'EE_Messages_Generator'                                                                                       => array(
506
+				'EE_Messages_Queue'                    => EE_Dependency_Map::load_new_object,
507
+				'EE_Messages_Data_Handler_Collection'  => EE_Dependency_Map::load_new_object,
508
+				'EE_Message_Template_Group_Collection' => EE_Dependency_Map::load_new_object,
509
+				'EEH_Parse_Shortcodes'                 => EE_Dependency_Map::load_from_cache,
510
+			),
511
+			'EE_Messages_Processor'                                                                                       => array(
512
+				'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache,
513
+			),
514
+			'EE_Messages_Queue'                                                                                           => array(
515
+				'EE_Message_Repository' => EE_Dependency_Map::load_new_object,
516
+			),
517
+			'EE_Messages_Template_Defaults'                                                                               => array(
518
+				'EEM_Message_Template_Group' => EE_Dependency_Map::load_from_cache,
519
+				'EEM_Message_Template'       => EE_Dependency_Map::load_from_cache,
520
+			),
521
+			'EE_Message_To_Generate_From_Request'                                                                         => array(
522
+				'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache,
523
+				'EE_Request_Handler'          => EE_Dependency_Map::load_from_cache,
524
+			),
525
+			'EventEspresso\core\services\commands\CommandBus'                                                             => array(
526
+				'EventEspresso\core\services\commands\CommandHandlerManager' => EE_Dependency_Map::load_from_cache,
527
+			),
528
+			'EventEspresso\services\commands\CommandHandler'                                                              => array(
529
+				'EE_Registry'         => EE_Dependency_Map::load_from_cache,
530
+				'CommandBusInterface' => EE_Dependency_Map::load_from_cache,
531
+			),
532
+			'EventEspresso\core\services\commands\CommandHandlerManager'                                                  => array(
533
+				'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache,
534
+			),
535
+			'EventEspresso\core\services\commands\CompositeCommandHandler'                                                => array(
536
+				'EventEspresso\core\services\commands\CommandBus'     => EE_Dependency_Map::load_from_cache,
537
+				'EventEspresso\core\services\commands\CommandFactory' => EE_Dependency_Map::load_from_cache,
538
+			),
539
+			'EventEspresso\core\services\commands\CommandFactory'                                                         => array(
540
+				'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache,
541
+			),
542
+			'EventEspresso\core\services\commands\middleware\CapChecker'                                                  => array(
543
+				'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => EE_Dependency_Map::load_from_cache,
544
+			),
545
+			'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker'                                         => array(
546
+				'EE_Capabilities' => EE_Dependency_Map::load_from_cache,
547
+			),
548
+			'EventEspresso\core\domain\services\capabilities\RegistrationsCapChecker'                                     => array(
549
+				'EE_Capabilities' => EE_Dependency_Map::load_from_cache,
550
+			),
551
+			'EventEspresso\core\services\commands\registration\CreateRegistrationCommandHandler'                          => array(
552
+				'EventEspresso\core\domain\services\registration\CreateRegistrationService' => EE_Dependency_Map::load_from_cache,
553
+			),
554
+			'EventEspresso\core\services\commands\registration\CopyRegistrationDetailsCommandHandler'                     => array(
555
+				'EventEspresso\core\domain\services\registration\CopyRegistrationService' => EE_Dependency_Map::load_from_cache,
556
+			),
557
+			'EventEspresso\core\services\commands\registration\CopyRegistrationPaymentsCommandHandler'                    => array(
558
+				'EventEspresso\core\domain\services\registration\CopyRegistrationService' => EE_Dependency_Map::load_from_cache,
559
+			),
560
+			'EventEspresso\core\services\commands\registration\CancelRegistrationAndTicketLineItemCommandHandler'         => array(
561
+				'EventEspresso\core\domain\services\registration\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache,
562
+			),
563
+			'EventEspresso\core\services\commands\registration\UpdateRegistrationAndTransactionAfterChangeCommandHandler' => array(
564
+				'EventEspresso\core\domain\services\registration\UpdateRegistrationService' => EE_Dependency_Map::load_from_cache,
565
+			),
566
+			'EventEspresso\core\services\commands\ticket\CreateTicketLineItemCommandHandler'                              => array(
567
+				'EventEspresso\core\domain\services\ticket\CreateTicketLineItemService' => EE_Dependency_Map::load_from_cache,
568
+			),
569
+			'EventEspresso\core\services\commands\ticket\CancelTicketLineItemCommandHandler'                              => array(
570
+				'EventEspresso\core\domain\services\ticket\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache,
571
+			),
572
+			'EventEspresso\core\domain\services\registration\CancelRegistrationService'                                   => array(
573
+				'EventEspresso\core\domain\services\ticket\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache,
574
+			),
575
+			'EventEspresso\core\services\commands\attendee\CreateAttendeeCommandHandler'                                  => array(
576
+				'EEM_Attendee' => EE_Dependency_Map::load_from_cache,
577
+			),
578
+			'EventEspresso\core\services\database\TableManager'                                                           => array(
579
+				'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
580
+			),
581
+			'EE_Data_Migration_Class_Base'                                                                                => array(
582
+				'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
583
+				'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
584
+			),
585
+			'EE_DMS_Core_4_1_0'                                                                                           => array(
586
+				'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
587
+				'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
588
+			),
589
+			'EE_DMS_Core_4_2_0'                                                                                           => array(
590
+				'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
591
+				'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
592
+			),
593
+			'EE_DMS_Core_4_3_0'                                                                                           => array(
594
+				'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
595
+				'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
596
+			),
597
+			'EE_DMS_Core_4_4_0'                                                                                           => array(
598
+				'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
599
+				'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
600
+			),
601
+			'EE_DMS_Core_4_5_0'                                                                                           => array(
602
+				'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
603
+				'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
604
+			),
605
+			'EE_DMS_Core_4_6_0'                                                                                           => array(
606
+				'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
607
+				'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
608
+			),
609
+			'EE_DMS_Core_4_7_0'                                                                                           => array(
610
+				'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
611
+				'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
612
+			),
613
+			'EE_DMS_Core_4_8_0'                                                                                           => array(
614
+				'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
615
+				'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
616
+			),
617
+			'EE_DMS_Core_4_9_0'                                                                                           => array(
618
+				'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
619
+				'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
620
+			),
621
+			'EventEspresso\core\services\assets\I18nRegistry' => array(
622
+				array(),
623
+				'EventEspresso\core\domain\Domain' => EE_Dependency_Map::load_from_cache
624
+			),
625
+			'EventEspresso\core\services\assets\Registry'                                                                 => array(
626
+				'EE_Template_Config' => EE_Dependency_Map::load_from_cache,
627
+				'EE_Currency_Config' => EE_Dependency_Map::load_from_cache,
628
+				'EventEspresso\core\services\assets\I18nRegistry' => EE_Dependency_Map::load_from_cache,
629
+				'EventEspresso\core\domain\Domain' => EE_Dependency_Map::load_from_cache
630
+			),
631
+			'EventEspresso\core\domain\entities\shortcodes\EspressoCancelled'                                             => array(
632
+				'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache,
633
+			),
634
+			'EventEspresso\core\domain\entities\shortcodes\EspressoCheckout'                                              => array(
635
+				'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache,
636
+			),
637
+			'EventEspresso\core\domain\entities\shortcodes\EspressoEventAttendees'                                        => array(
638
+				'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache,
639
+			),
640
+			'EventEspresso\core\domain\entities\shortcodes\EspressoEvents'                                                => array(
641
+				'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache,
642
+			),
643
+			'EventEspresso\core\domain\entities\shortcodes\EspressoThankYou'                                              => array(
644
+				'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache,
645
+			),
646
+			'EventEspresso\core\domain\entities\shortcodes\EspressoTicketSelector'                                        => array(
647
+				'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache,
648
+			),
649
+			'EventEspresso\core\domain\entities\shortcodes\EspressoTxnPage'                                               => array(
650
+				'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache,
651
+			),
652
+			'EventEspresso\core\services\cache\BasicCacheManager'                        => array(
653
+				'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache,
654
+			),
655
+			'EventEspresso\core\services\cache\PostRelatedCacheManager'                  => array(
656
+				'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache,
657
+			),
658
+			'EventEspresso\core\domain\services\validation\email\EmailValidationService' => array(
659
+				'EE_Registration_Config'                                  => EE_Dependency_Map::load_from_cache,
660
+				'EventEspresso\core\services\loaders\Loader'              => EE_Dependency_Map::load_from_cache,
661
+			),
662
+			'EventEspresso\core\domain\values\EmailAddress'                              => array(
663
+				null,
664
+				'EventEspresso\core\domain\services\validation\email\EmailValidationService' => EE_Dependency_Map::load_from_cache,
665
+			),
666
+			'EventEspresso\core\services\orm\ModelFieldFactory' => array(
667
+				'EventEspresso\core\services\loaders\Loader'              => EE_Dependency_Map::load_from_cache,
668
+			),
669
+			'LEGACY_MODELS'                                                   => array(
670
+				null,
671
+				'EventEspresso\core\services\database\ModelFieldFactory' => EE_Dependency_Map::load_from_cache,
672
+			),
673
+			'EE_Module_Request_Router' => array(
674
+				'EE_Request' => EE_Dependency_Map::load_from_cache,
675
+			),
676
+			'EE_Registration_Processor' => array(
677
+				'EE_Request' => EE_Dependency_Map::load_from_cache,
678
+			),
679
+			'EventEspresso\core\services\notifications\PersistentAdminNoticeManager' => array(
680
+				null,
681
+				'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => EE_Dependency_Map::load_from_cache,
682
+				'EE_Request' => EE_Dependency_Map::load_from_cache,
683
+			),
684
+			'EventEspresso\core\services\licensing\LicenseService' => array(
685
+				'EventEspresso\core\domain\services\pue\Stats' => EE_Dependency_Map::load_from_cache,
686
+				'EventEspresso\core\domain\services\pue\Config' => EE_Dependency_Map::load_from_cache
687
+			),
688 688
 			'EE_Admin_Transactions_List_Table' => array(
689
-                null,
690
-                'EventEspresso\core\domain\values\session\SessionLifespan' => EE_Dependency_Map::load_from_cache,
691
-			),
692
-            'EventEspresso\core\domain\services\pue\Stats' => array(
693
-                'EventEspresso\core\domain\services\pue\Config' => EE_Dependency_Map::load_from_cache,
694
-                'EE_Maintenance_Mode' => EE_Dependency_Map::load_from_cache,
695
-                'EventEspresso\core\domain\services\pue\StatsGatherer' => EE_Dependency_Map::load_from_cache
696
-            ),
697
-            'EventEspresso\core\domain\services\pue\Config' => array(
698
-                'EE_Network_Config' => EE_Dependency_Map::load_from_cache,
699
-                'EE_Config' => EE_Dependency_Map::load_from_cache
700
-            ),
701
-            'EventEspresso\core\domain\services\pue\StatsGatherer' => array(
702
-                'EEM_Payment_Method' => EE_Dependency_Map::load_from_cache,
703
-                'EEM_Event' => EE_Dependency_Map::load_from_cache,
704
-                'EEM_Datetime' => EE_Dependency_Map::load_from_cache,
705
-                'EEM_Ticket' => EE_Dependency_Map::load_from_cache,
706
-                'EEM_Registration' => EE_Dependency_Map::load_from_cache,
707
-                'EEM_Transaction' => EE_Dependency_Map::load_from_cache,
708
-                'EE_Config' => EE_Dependency_Map::load_from_cache
709
-            ),
710
-            'EventEspresso\core\domain\services\admin\ExitModal' => array(
711
-                'EventEspresso\core\services\assets\Registry' => EE_Dependency_Map::load_from_cache
712
-            ),
713
-            'EventEspresso\core\domain\services\admin\PluginUpsells' => array(
714
-                'EventEspresso\core\domain\Domain' => EE_Dependency_Map::load_from_cache
715
-            ),
716
-            'EventEspresso\caffeinated\modules\recaptcha_invisible\InvisibleRecaptcha' => array(
717
-                'EE_Registration_Config' => EE_Dependency_Map::load_from_cache,
718
-                'EE_Session'             => EE_Dependency_Map::load_from_cache,
719
-            ),
720
-            'EventEspresso\caffeinated\modules\recaptcha_invisible\RecaptchaAdminSettings' => array(
721
-                'EE_Registration_Config' => EE_Dependency_Map::load_from_cache,
722
-            ),
723
-            'EventEspresso\modules\ticket_selector\ProcessTicketSelector' => array(
724
-                'EE_Core_Config' => EE_Dependency_Map::load_from_cache,
725
-                'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache,
726
-                'EE_Session' => EE_Dependency_Map::load_from_cache,
727
-                'EEM_Ticket' => EE_Dependency_Map::load_from_cache,
728
-                'EventEspresso\modules\ticket_selector\TicketDatetimeAvailabilityTracker' => EE_Dependency_Map::load_from_cache,
729
-            ),
730
-            'EventEspresso\modules\ticket_selector\TicketDatetimeAvailabilityTracker' => array(
731
-                'EEM_Datetime' => EE_Dependency_Map::load_from_cache,
732
-            ),
733
-            'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions' => array(
734
-                'EE_Core_Config' => EE_Dependency_Map::load_from_cache,
735
-                'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache,
736
-            ),
737
-            'EventEspresso\core\domain\services\custom_post_types\RegisterCustomPostTypes'   => array(
738
-                'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions' => EE_Dependency_Map::load_from_cache,
739
-            ),
740
-            'EventEspresso\core\domain\services\custom_post_types\RegisterCustomTaxonomies'   => array(
741
-                'EventEspresso\core\domain\entities\custom_post_types\CustomTaxonomyDefinitions' => EE_Dependency_Map::load_from_cache,
742
-            ),
743
-            'EE_CPT_Strategy'   => array(
744
-                'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions' => EE_Dependency_Map::load_from_cache,
745
-                'EventEspresso\core\domain\entities\custom_post_types\CustomTaxonomyDefinitions' => EE_Dependency_Map::load_from_cache,
746
-            ),
747
-        );
748
-    }
749
-
750
-
751
-
752
-    /**
753
-     * Registers how core classes are loaded.
754
-     * This can either be done by simply providing the name of one of the EE_Registry loader methods such as:
755
-     *        'EE_Request_Handler' => 'load_core'
756
-     *        'EE_Messages_Queue'  => 'load_lib'
757
-     *        'EEH_Debug_Tools'    => 'load_helper'
758
-     * or, if greater control is required, by providing a custom closure. For example:
759
-     *        'Some_Class' => function () {
760
-     *            return new Some_Class();
761
-     *        },
762
-     * This is required for instantiating dependencies
763
-     * where an interface has been type hinted in a class constructor. For example:
764
-     *        'Required_Interface' => function () {
765
-     *            return new A_Class_That_Implements_Required_Interface();
766
-     *        },
767
-     *
768
-     * @throws InvalidInterfaceException
769
-     * @throws InvalidDataTypeException
770
-     * @throws InvalidArgumentException
771
-     */
772
-    protected function _register_core_class_loaders()
773
-    {
774
-        //for PHP5.3 compat, we need to register any properties called here in a variable because `$this` cannot
775
-        //be used in a closure.
776
-        $request = &$this->request;
777
-        $response = &$this->response;
778
-        $legacy_request = &$this->legacy_request;
779
-        // $loader = &$this->loader;
780
-        $this->_class_loaders = array(
781
-            //load_core
782
-            'EE_Capabilities'          => 'load_core',
783
-            'EE_Encryption'            => 'load_core',
784
-            'EE_Front_Controller'      => 'load_core',
785
-            'EE_Module_Request_Router' => 'load_core',
786
-            'EE_Registry'              => 'load_core',
787
-            'EE_Request'               => function () use (&$legacy_request) {
788
-                return $legacy_request;
789
-            },
790
-            'EventEspresso\core\services\request\Request' => function () use (&$request) {
791
-                return $request;
792
-            },
793
-            'EventEspresso\core\services\request\Response' => function () use (&$response) {
794
-                return $response;
795
-            },
796
-            'EE_Request_Handler'       => 'load_core',
797
-            'EE_Session'               => 'load_core',
798
-            'EE_Cron_Tasks'            => 'load_core',
799
-            'EE_System'                => 'load_core',
800
-            'EE_Maintenance_Mode'      => 'load_core',
801
-            'EE_Register_CPTs'         => 'load_core',
802
-            'EE_Admin'                 => 'load_core',
803
-            'EE_CPT_Strategy'          => 'load_core',
804
-            //load_lib
805
-            'EE_Message_Resource_Manager'          => 'load_lib',
806
-            'EE_Message_Type_Collection'           => 'load_lib',
807
-            'EE_Message_Type_Collection_Loader'    => 'load_lib',
808
-            'EE_Messenger_Collection'              => 'load_lib',
809
-            'EE_Messenger_Collection_Loader'       => 'load_lib',
810
-            'EE_Messages_Processor'                => 'load_lib',
811
-            'EE_Message_Repository'                => 'load_lib',
812
-            'EE_Messages_Queue'                    => 'load_lib',
813
-            'EE_Messages_Data_Handler_Collection'  => 'load_lib',
814
-            'EE_Message_Template_Group_Collection' => 'load_lib',
815
-            'EE_Payment_Method_Manager'            => 'load_lib',
816
-            'EE_Messages_Generator'                => function () {
817
-                return EE_Registry::instance()->load_lib(
818
-                    'Messages_Generator',
819
-                    array(),
820
-                    false,
821
-                    false
822
-                );
823
-            },
824
-            'EE_Messages_Template_Defaults'        => function ($arguments = array()) {
825
-                return EE_Registry::instance()->load_lib(
826
-                    'Messages_Template_Defaults',
827
-                    $arguments,
828
-                    false,
829
-                    false
830
-                );
831
-            },
832
-            //load_helper
833
-            'EEH_Parse_Shortcodes'                 => function () {
834
-                if (EE_Registry::instance()->load_helper('Parse_Shortcodes')) {
835
-                    return new EEH_Parse_Shortcodes();
836
-                }
837
-                return null;
838
-            },
839
-            'EE_Template_Config'                   => function () {
840
-                return EE_Config::instance()->template_settings;
841
-            },
842
-            'EE_Currency_Config'                   => function () {
843
-                return EE_Config::instance()->currency;
844
-            },
845
-            'EE_Registration_Config'                   => function () {
846
-                return EE_Config::instance()->registration;
847
-            },
848
-            'EE_Core_Config'                   => function () {
849
-                return EE_Config::instance()->core;
850
-            },
851
-            'EventEspresso\core\services\loaders\Loader' => function () {
852
-                return LoaderFactory::getLoader();
853
-            },
854
-            'EE_Network_Config' => function() {
855
-                return EE_Network_Config::instance();
856
-            },
857
-            'EE_Config' => function () {
858
-                return EE_Config::instance();
859
-            }
860
-        );
861
-    }
862
-
863
-
864
-
865
-    /**
866
-     * can be used for supplying alternate names for classes,
867
-     * or for connecting interface names to instantiable classes
868
-     */
869
-    protected function _register_core_aliases()
870
-    {
871
-        $this->_aliases = array(
872
-            'CommandBusInterface'                                                          => 'EventEspresso\core\services\commands\CommandBusInterface',
873
-            'EventEspresso\core\services\commands\CommandBusInterface'                     => 'EventEspresso\core\services\commands\CommandBus',
874
-            'CommandHandlerManagerInterface'                                               => 'EventEspresso\core\services\commands\CommandHandlerManagerInterface',
875
-            'EventEspresso\core\services\commands\CommandHandlerManagerInterface'          => 'EventEspresso\core\services\commands\CommandHandlerManager',
876
-            'CapChecker'                                                                   => 'EventEspresso\core\services\commands\middleware\CapChecker',
877
-            'AddActionHook'                                                                => 'EventEspresso\core\services\commands\middleware\AddActionHook',
878
-            'CapabilitiesChecker'                                                          => 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker',
879
-            'CapabilitiesCheckerInterface'                                                 => 'EventEspresso\core\domain\services\capabilities\CapabilitiesCheckerInterface',
880
-            'EventEspresso\core\domain\services\capabilities\CapabilitiesCheckerInterface' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker',
881
-            'CreateRegistrationService'                                                    => 'EventEspresso\core\domain\services\registration\CreateRegistrationService',
882
-            'CreateRegCodeCommandHandler'                                                  => 'EventEspresso\core\services\commands\registration\CreateRegCodeCommand',
883
-            'CreateRegUrlLinkCommandHandler'                                               => 'EventEspresso\core\services\commands\registration\CreateRegUrlLinkCommand',
884
-            'CreateRegistrationCommandHandler'                                             => 'EventEspresso\core\services\commands\registration\CreateRegistrationCommand',
885
-            'CopyRegistrationDetailsCommandHandler'                                        => 'EventEspresso\core\services\commands\registration\CopyRegistrationDetailsCommand',
886
-            'CopyRegistrationPaymentsCommandHandler'                                       => 'EventEspresso\core\services\commands\registration\CopyRegistrationPaymentsCommand',
887
-            'CancelRegistrationAndTicketLineItemCommandHandler'                            => 'EventEspresso\core\services\commands\registration\CancelRegistrationAndTicketLineItemCommandHandler',
888
-            'UpdateRegistrationAndTransactionAfterChangeCommandHandler'                    => 'EventEspresso\core\services\commands\registration\UpdateRegistrationAndTransactionAfterChangeCommandHandler',
889
-            'CreateTicketLineItemCommandHandler'                                           => 'EventEspresso\core\services\commands\ticket\CreateTicketLineItemCommand',
890
-            'CreateTransactionCommandHandler'                                     => 'EventEspresso\core\services\commands\transaction\CreateTransactionCommandHandler',
891
-            'CreateAttendeeCommandHandler'                                        => 'EventEspresso\core\services\commands\attendee\CreateAttendeeCommandHandler',
892
-            'TableManager'                                                                 => 'EventEspresso\core\services\database\TableManager',
893
-            'TableAnalysis'                                                                => 'EventEspresso\core\services\database\TableAnalysis',
894
-            'EspressoShortcode'                                                            => 'EventEspresso\core\services\shortcodes\EspressoShortcode',
895
-            'ShortcodeInterface'                                                           => 'EventEspresso\core\services\shortcodes\ShortcodeInterface',
896
-            'EventEspresso\core\services\shortcodes\ShortcodeInterface'                    => 'EventEspresso\core\services\shortcodes\EspressoShortcode',
897
-            'EventEspresso\core\services\cache\CacheStorageInterface'                      => 'EventEspresso\core\services\cache\TransientCacheStorage',
898
-            'LoaderInterface'                                                              => 'EventEspresso\core\services\loaders\LoaderInterface',
899
-            'EventEspresso\core\services\loaders\LoaderInterface'                          => 'EventEspresso\core\services\loaders\Loader',
900
-            'CommandFactoryInterface'                                                     => 'EventEspresso\core\services\commands\CommandFactoryInterface',
901
-            'EventEspresso\core\services\commands\CommandFactoryInterface'                => 'EventEspresso\core\services\commands\CommandFactory',
902
-            'EventEspresso\core\domain\services\session\SessionIdentifierInterface'       => 'EE_Session',
903
-            'EmailValidatorInterface'                                                     => 'EventEspresso\core\domain\services\validation\email\EmailValidatorInterface',
904
-            'EventEspresso\core\domain\services\validation\email\EmailValidatorInterface' => 'EventEspresso\core\domain\services\validation\email\EmailValidationService',
905
-            'NoticeConverterInterface'                                            => 'EventEspresso\core\services\notices\NoticeConverterInterface',
906
-            'EventEspresso\core\services\notices\NoticeConverterInterface'        => 'EventEspresso\core\services\notices\ConvertNoticesToEeErrors',
907
-            'NoticesContainerInterface'                                           => 'EventEspresso\core\services\notices\NoticesContainerInterface',
908
-            'EventEspresso\core\services\notices\NoticesContainerInterface'       => 'EventEspresso\core\services\notices\NoticesContainer',
909
-            'EventEspresso\core\services\request\RequestInterface'                => 'EventEspresso\core\services\request\Request',
910
-            'EventEspresso\core\services\request\ResponseInterface'               => 'EventEspresso\core\services\request\Response',
911
-            'EventEspresso\core\domain\DomainInterface'                           => 'EventEspresso\core\domain\Domain',
912
-        );
913
-        if (! (defined('DOING_AJAX') && DOING_AJAX) && is_admin()) {
914
-            $this->_aliases['EventEspresso\core\services\notices\NoticeConverterInterface'] = 'EventEspresso\core\services\notices\ConvertNoticesToAdminNotices';
915
-        }
916
-    }
917
-
918
-
919
-
920
-    /**
921
-     * This is used to reset the internal map and class_loaders to their original default state at the beginning of the
922
-     * request Primarily used by unit tests.
923
-     *
924
-     * @throws InvalidDataTypeException
925
-     * @throws InvalidInterfaceException
926
-     * @throws InvalidArgumentException
927
-     */
928
-    public function reset()
929
-    {
930
-        $this->_register_core_class_loaders();
931
-        $this->_register_core_dependencies();
932
-    }
689
+				null,
690
+				'EventEspresso\core\domain\values\session\SessionLifespan' => EE_Dependency_Map::load_from_cache,
691
+			),
692
+			'EventEspresso\core\domain\services\pue\Stats' => array(
693
+				'EventEspresso\core\domain\services\pue\Config' => EE_Dependency_Map::load_from_cache,
694
+				'EE_Maintenance_Mode' => EE_Dependency_Map::load_from_cache,
695
+				'EventEspresso\core\domain\services\pue\StatsGatherer' => EE_Dependency_Map::load_from_cache
696
+			),
697
+			'EventEspresso\core\domain\services\pue\Config' => array(
698
+				'EE_Network_Config' => EE_Dependency_Map::load_from_cache,
699
+				'EE_Config' => EE_Dependency_Map::load_from_cache
700
+			),
701
+			'EventEspresso\core\domain\services\pue\StatsGatherer' => array(
702
+				'EEM_Payment_Method' => EE_Dependency_Map::load_from_cache,
703
+				'EEM_Event' => EE_Dependency_Map::load_from_cache,
704
+				'EEM_Datetime' => EE_Dependency_Map::load_from_cache,
705
+				'EEM_Ticket' => EE_Dependency_Map::load_from_cache,
706
+				'EEM_Registration' => EE_Dependency_Map::load_from_cache,
707
+				'EEM_Transaction' => EE_Dependency_Map::load_from_cache,
708
+				'EE_Config' => EE_Dependency_Map::load_from_cache
709
+			),
710
+			'EventEspresso\core\domain\services\admin\ExitModal' => array(
711
+				'EventEspresso\core\services\assets\Registry' => EE_Dependency_Map::load_from_cache
712
+			),
713
+			'EventEspresso\core\domain\services\admin\PluginUpsells' => array(
714
+				'EventEspresso\core\domain\Domain' => EE_Dependency_Map::load_from_cache
715
+			),
716
+			'EventEspresso\caffeinated\modules\recaptcha_invisible\InvisibleRecaptcha' => array(
717
+				'EE_Registration_Config' => EE_Dependency_Map::load_from_cache,
718
+				'EE_Session'             => EE_Dependency_Map::load_from_cache,
719
+			),
720
+			'EventEspresso\caffeinated\modules\recaptcha_invisible\RecaptchaAdminSettings' => array(
721
+				'EE_Registration_Config' => EE_Dependency_Map::load_from_cache,
722
+			),
723
+			'EventEspresso\modules\ticket_selector\ProcessTicketSelector' => array(
724
+				'EE_Core_Config' => EE_Dependency_Map::load_from_cache,
725
+				'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache,
726
+				'EE_Session' => EE_Dependency_Map::load_from_cache,
727
+				'EEM_Ticket' => EE_Dependency_Map::load_from_cache,
728
+				'EventEspresso\modules\ticket_selector\TicketDatetimeAvailabilityTracker' => EE_Dependency_Map::load_from_cache,
729
+			),
730
+			'EventEspresso\modules\ticket_selector\TicketDatetimeAvailabilityTracker' => array(
731
+				'EEM_Datetime' => EE_Dependency_Map::load_from_cache,
732
+			),
733
+			'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions' => array(
734
+				'EE_Core_Config' => EE_Dependency_Map::load_from_cache,
735
+				'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache,
736
+			),
737
+			'EventEspresso\core\domain\services\custom_post_types\RegisterCustomPostTypes'   => array(
738
+				'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions' => EE_Dependency_Map::load_from_cache,
739
+			),
740
+			'EventEspresso\core\domain\services\custom_post_types\RegisterCustomTaxonomies'   => array(
741
+				'EventEspresso\core\domain\entities\custom_post_types\CustomTaxonomyDefinitions' => EE_Dependency_Map::load_from_cache,
742
+			),
743
+			'EE_CPT_Strategy'   => array(
744
+				'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions' => EE_Dependency_Map::load_from_cache,
745
+				'EventEspresso\core\domain\entities\custom_post_types\CustomTaxonomyDefinitions' => EE_Dependency_Map::load_from_cache,
746
+			),
747
+		);
748
+	}
749
+
750
+
751
+
752
+	/**
753
+	 * Registers how core classes are loaded.
754
+	 * This can either be done by simply providing the name of one of the EE_Registry loader methods such as:
755
+	 *        'EE_Request_Handler' => 'load_core'
756
+	 *        'EE_Messages_Queue'  => 'load_lib'
757
+	 *        'EEH_Debug_Tools'    => 'load_helper'
758
+	 * or, if greater control is required, by providing a custom closure. For example:
759
+	 *        'Some_Class' => function () {
760
+	 *            return new Some_Class();
761
+	 *        },
762
+	 * This is required for instantiating dependencies
763
+	 * where an interface has been type hinted in a class constructor. For example:
764
+	 *        'Required_Interface' => function () {
765
+	 *            return new A_Class_That_Implements_Required_Interface();
766
+	 *        },
767
+	 *
768
+	 * @throws InvalidInterfaceException
769
+	 * @throws InvalidDataTypeException
770
+	 * @throws InvalidArgumentException
771
+	 */
772
+	protected function _register_core_class_loaders()
773
+	{
774
+		//for PHP5.3 compat, we need to register any properties called here in a variable because `$this` cannot
775
+		//be used in a closure.
776
+		$request = &$this->request;
777
+		$response = &$this->response;
778
+		$legacy_request = &$this->legacy_request;
779
+		// $loader = &$this->loader;
780
+		$this->_class_loaders = array(
781
+			//load_core
782
+			'EE_Capabilities'          => 'load_core',
783
+			'EE_Encryption'            => 'load_core',
784
+			'EE_Front_Controller'      => 'load_core',
785
+			'EE_Module_Request_Router' => 'load_core',
786
+			'EE_Registry'              => 'load_core',
787
+			'EE_Request'               => function () use (&$legacy_request) {
788
+				return $legacy_request;
789
+			},
790
+			'EventEspresso\core\services\request\Request' => function () use (&$request) {
791
+				return $request;
792
+			},
793
+			'EventEspresso\core\services\request\Response' => function () use (&$response) {
794
+				return $response;
795
+			},
796
+			'EE_Request_Handler'       => 'load_core',
797
+			'EE_Session'               => 'load_core',
798
+			'EE_Cron_Tasks'            => 'load_core',
799
+			'EE_System'                => 'load_core',
800
+			'EE_Maintenance_Mode'      => 'load_core',
801
+			'EE_Register_CPTs'         => 'load_core',
802
+			'EE_Admin'                 => 'load_core',
803
+			'EE_CPT_Strategy'          => 'load_core',
804
+			//load_lib
805
+			'EE_Message_Resource_Manager'          => 'load_lib',
806
+			'EE_Message_Type_Collection'           => 'load_lib',
807
+			'EE_Message_Type_Collection_Loader'    => 'load_lib',
808
+			'EE_Messenger_Collection'              => 'load_lib',
809
+			'EE_Messenger_Collection_Loader'       => 'load_lib',
810
+			'EE_Messages_Processor'                => 'load_lib',
811
+			'EE_Message_Repository'                => 'load_lib',
812
+			'EE_Messages_Queue'                    => 'load_lib',
813
+			'EE_Messages_Data_Handler_Collection'  => 'load_lib',
814
+			'EE_Message_Template_Group_Collection' => 'load_lib',
815
+			'EE_Payment_Method_Manager'            => 'load_lib',
816
+			'EE_Messages_Generator'                => function () {
817
+				return EE_Registry::instance()->load_lib(
818
+					'Messages_Generator',
819
+					array(),
820
+					false,
821
+					false
822
+				);
823
+			},
824
+			'EE_Messages_Template_Defaults'        => function ($arguments = array()) {
825
+				return EE_Registry::instance()->load_lib(
826
+					'Messages_Template_Defaults',
827
+					$arguments,
828
+					false,
829
+					false
830
+				);
831
+			},
832
+			//load_helper
833
+			'EEH_Parse_Shortcodes'                 => function () {
834
+				if (EE_Registry::instance()->load_helper('Parse_Shortcodes')) {
835
+					return new EEH_Parse_Shortcodes();
836
+				}
837
+				return null;
838
+			},
839
+			'EE_Template_Config'                   => function () {
840
+				return EE_Config::instance()->template_settings;
841
+			},
842
+			'EE_Currency_Config'                   => function () {
843
+				return EE_Config::instance()->currency;
844
+			},
845
+			'EE_Registration_Config'                   => function () {
846
+				return EE_Config::instance()->registration;
847
+			},
848
+			'EE_Core_Config'                   => function () {
849
+				return EE_Config::instance()->core;
850
+			},
851
+			'EventEspresso\core\services\loaders\Loader' => function () {
852
+				return LoaderFactory::getLoader();
853
+			},
854
+			'EE_Network_Config' => function() {
855
+				return EE_Network_Config::instance();
856
+			},
857
+			'EE_Config' => function () {
858
+				return EE_Config::instance();
859
+			}
860
+		);
861
+	}
862
+
863
+
864
+
865
+	/**
866
+	 * can be used for supplying alternate names for classes,
867
+	 * or for connecting interface names to instantiable classes
868
+	 */
869
+	protected function _register_core_aliases()
870
+	{
871
+		$this->_aliases = array(
872
+			'CommandBusInterface'                                                          => 'EventEspresso\core\services\commands\CommandBusInterface',
873
+			'EventEspresso\core\services\commands\CommandBusInterface'                     => 'EventEspresso\core\services\commands\CommandBus',
874
+			'CommandHandlerManagerInterface'                                               => 'EventEspresso\core\services\commands\CommandHandlerManagerInterface',
875
+			'EventEspresso\core\services\commands\CommandHandlerManagerInterface'          => 'EventEspresso\core\services\commands\CommandHandlerManager',
876
+			'CapChecker'                                                                   => 'EventEspresso\core\services\commands\middleware\CapChecker',
877
+			'AddActionHook'                                                                => 'EventEspresso\core\services\commands\middleware\AddActionHook',
878
+			'CapabilitiesChecker'                                                          => 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker',
879
+			'CapabilitiesCheckerInterface'                                                 => 'EventEspresso\core\domain\services\capabilities\CapabilitiesCheckerInterface',
880
+			'EventEspresso\core\domain\services\capabilities\CapabilitiesCheckerInterface' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker',
881
+			'CreateRegistrationService'                                                    => 'EventEspresso\core\domain\services\registration\CreateRegistrationService',
882
+			'CreateRegCodeCommandHandler'                                                  => 'EventEspresso\core\services\commands\registration\CreateRegCodeCommand',
883
+			'CreateRegUrlLinkCommandHandler'                                               => 'EventEspresso\core\services\commands\registration\CreateRegUrlLinkCommand',
884
+			'CreateRegistrationCommandHandler'                                             => 'EventEspresso\core\services\commands\registration\CreateRegistrationCommand',
885
+			'CopyRegistrationDetailsCommandHandler'                                        => 'EventEspresso\core\services\commands\registration\CopyRegistrationDetailsCommand',
886
+			'CopyRegistrationPaymentsCommandHandler'                                       => 'EventEspresso\core\services\commands\registration\CopyRegistrationPaymentsCommand',
887
+			'CancelRegistrationAndTicketLineItemCommandHandler'                            => 'EventEspresso\core\services\commands\registration\CancelRegistrationAndTicketLineItemCommandHandler',
888
+			'UpdateRegistrationAndTransactionAfterChangeCommandHandler'                    => 'EventEspresso\core\services\commands\registration\UpdateRegistrationAndTransactionAfterChangeCommandHandler',
889
+			'CreateTicketLineItemCommandHandler'                                           => 'EventEspresso\core\services\commands\ticket\CreateTicketLineItemCommand',
890
+			'CreateTransactionCommandHandler'                                     => 'EventEspresso\core\services\commands\transaction\CreateTransactionCommandHandler',
891
+			'CreateAttendeeCommandHandler'                                        => 'EventEspresso\core\services\commands\attendee\CreateAttendeeCommandHandler',
892
+			'TableManager'                                                                 => 'EventEspresso\core\services\database\TableManager',
893
+			'TableAnalysis'                                                                => 'EventEspresso\core\services\database\TableAnalysis',
894
+			'EspressoShortcode'                                                            => 'EventEspresso\core\services\shortcodes\EspressoShortcode',
895
+			'ShortcodeInterface'                                                           => 'EventEspresso\core\services\shortcodes\ShortcodeInterface',
896
+			'EventEspresso\core\services\shortcodes\ShortcodeInterface'                    => 'EventEspresso\core\services\shortcodes\EspressoShortcode',
897
+			'EventEspresso\core\services\cache\CacheStorageInterface'                      => 'EventEspresso\core\services\cache\TransientCacheStorage',
898
+			'LoaderInterface'                                                              => 'EventEspresso\core\services\loaders\LoaderInterface',
899
+			'EventEspresso\core\services\loaders\LoaderInterface'                          => 'EventEspresso\core\services\loaders\Loader',
900
+			'CommandFactoryInterface'                                                     => 'EventEspresso\core\services\commands\CommandFactoryInterface',
901
+			'EventEspresso\core\services\commands\CommandFactoryInterface'                => 'EventEspresso\core\services\commands\CommandFactory',
902
+			'EventEspresso\core\domain\services\session\SessionIdentifierInterface'       => 'EE_Session',
903
+			'EmailValidatorInterface'                                                     => 'EventEspresso\core\domain\services\validation\email\EmailValidatorInterface',
904
+			'EventEspresso\core\domain\services\validation\email\EmailValidatorInterface' => 'EventEspresso\core\domain\services\validation\email\EmailValidationService',
905
+			'NoticeConverterInterface'                                            => 'EventEspresso\core\services\notices\NoticeConverterInterface',
906
+			'EventEspresso\core\services\notices\NoticeConverterInterface'        => 'EventEspresso\core\services\notices\ConvertNoticesToEeErrors',
907
+			'NoticesContainerInterface'                                           => 'EventEspresso\core\services\notices\NoticesContainerInterface',
908
+			'EventEspresso\core\services\notices\NoticesContainerInterface'       => 'EventEspresso\core\services\notices\NoticesContainer',
909
+			'EventEspresso\core\services\request\RequestInterface'                => 'EventEspresso\core\services\request\Request',
910
+			'EventEspresso\core\services\request\ResponseInterface'               => 'EventEspresso\core\services\request\Response',
911
+			'EventEspresso\core\domain\DomainInterface'                           => 'EventEspresso\core\domain\Domain',
912
+		);
913
+		if (! (defined('DOING_AJAX') && DOING_AJAX) && is_admin()) {
914
+			$this->_aliases['EventEspresso\core\services\notices\NoticeConverterInterface'] = 'EventEspresso\core\services\notices\ConvertNoticesToAdminNotices';
915
+		}
916
+	}
917
+
918
+
919
+
920
+	/**
921
+	 * This is used to reset the internal map and class_loaders to their original default state at the beginning of the
922
+	 * request Primarily used by unit tests.
923
+	 *
924
+	 * @throws InvalidDataTypeException
925
+	 * @throws InvalidInterfaceException
926
+	 * @throws InvalidArgumentException
927
+	 */
928
+	public function reset()
929
+	{
930
+		$this->_register_core_class_loaders();
931
+		$this->_register_core_dependencies();
932
+	}
933 933
 
934 934
 
935 935
 }
Please login to merge, or discard this patch.
caffeinated/admin/new/pricing/espresso_events_Pricing_Hooks.class.php 1 patch
Indentation   +2130 added lines, -2130 removed lines patch added patch discarded remove patch
@@ -19,2190 +19,2190 @@
 block discarded – undo
19 19
 class espresso_events_Pricing_Hooks extends EE_Admin_Hooks
20 20
 {
21 21
 
22
-    /**
23
-     * This property is just used to hold the status of whether an event is currently being
24
-     * created (true) or edited (false)
25
-     *
26
-     * @access protected
27
-     * @var bool
28
-     */
29
-    protected $_is_creating_event;
22
+	/**
23
+	 * This property is just used to hold the status of whether an event is currently being
24
+	 * created (true) or edited (false)
25
+	 *
26
+	 * @access protected
27
+	 * @var bool
28
+	 */
29
+	protected $_is_creating_event;
30 30
 
31
-    /**
32
-     * Used to contain the format strings for date and time that will be used for php date and
33
-     * time.
34
-     * Is set in the _set_hooks_properties() method.
35
-     *
36
-     * @var array
37
-     */
38
-    protected $_date_format_strings;
31
+	/**
32
+	 * Used to contain the format strings for date and time that will be used for php date and
33
+	 * time.
34
+	 * Is set in the _set_hooks_properties() method.
35
+	 *
36
+	 * @var array
37
+	 */
38
+	protected $_date_format_strings;
39 39
 
40
-    /**
41
-     * @var string $_date_time_format
42
-     */
43
-    protected $_date_time_format;
40
+	/**
41
+	 * @var string $_date_time_format
42
+	 */
43
+	protected $_date_time_format;
44 44
 
45 45
 
46
-    /**
47
-     * @throws InvalidArgumentException
48
-     * @throws InvalidInterfaceException
49
-     * @throws InvalidDataTypeException
50
-     */
51
-    protected function _set_hooks_properties()
52
-    {
53
-        $this->_name = 'pricing';
54
-        //capability check
55
-        if (! EE_Registry::instance()->CAP->current_user_can(
56
-            'ee_read_default_prices',
57
-            'advanced_ticket_datetime_metabox'
58
-        )) {
59
-            return;
60
-        }
61
-        $this->_setup_metaboxes();
62
-        $this->_set_date_time_formats();
63
-        $this->_validate_format_strings();
64
-        $this->_set_scripts_styles();
65
-        // commented out temporarily until logic is implemented in callback
66
-        // add_action(
67
-        //     'AHEE__EE_Admin_Page_CPT__do_extra_autosave_stuff__after_Extend_Events_Admin_Page',
68
-        //     array($this, 'autosave_handling')
69
-        // );
70
-        add_filter(
71
-            'FHEE__Events_Admin_Page___insert_update_cpt_item__event_update_callbacks',
72
-            array($this, 'caf_updates')
73
-        );
74
-    }
46
+	/**
47
+	 * @throws InvalidArgumentException
48
+	 * @throws InvalidInterfaceException
49
+	 * @throws InvalidDataTypeException
50
+	 */
51
+	protected function _set_hooks_properties()
52
+	{
53
+		$this->_name = 'pricing';
54
+		//capability check
55
+		if (! EE_Registry::instance()->CAP->current_user_can(
56
+			'ee_read_default_prices',
57
+			'advanced_ticket_datetime_metabox'
58
+		)) {
59
+			return;
60
+		}
61
+		$this->_setup_metaboxes();
62
+		$this->_set_date_time_formats();
63
+		$this->_validate_format_strings();
64
+		$this->_set_scripts_styles();
65
+		// commented out temporarily until logic is implemented in callback
66
+		// add_action(
67
+		//     'AHEE__EE_Admin_Page_CPT__do_extra_autosave_stuff__after_Extend_Events_Admin_Page',
68
+		//     array($this, 'autosave_handling')
69
+		// );
70
+		add_filter(
71
+			'FHEE__Events_Admin_Page___insert_update_cpt_item__event_update_callbacks',
72
+			array($this, 'caf_updates')
73
+		);
74
+	}
75 75
 
76 76
 
77
-    /**
78
-     * @return void
79
-     */
80
-    protected function _setup_metaboxes()
81
-    {
82
-        //if we were going to add our own metaboxes we'd use the below.
83
-        $this->_metaboxes        = array(
84
-            0 => array(
85
-                'page_route' => array('edit', 'create_new'),
86
-                'func'       => 'pricing_metabox',
87
-                'label'      => esc_html__('Event Tickets & Datetimes', 'event_espresso'),
88
-                'priority'   => 'high',
89
-                'context'    => 'normal',
90
-            ),
91
-        );
92
-        $this->_remove_metaboxes = array(
93
-            0 => array(
94
-                'page_route' => array('edit', 'create_new'),
95
-                'id'         => 'espresso_event_editor_tickets',
96
-                'context'    => 'normal',
97
-            ),
98
-        );
99
-    }
77
+	/**
78
+	 * @return void
79
+	 */
80
+	protected function _setup_metaboxes()
81
+	{
82
+		//if we were going to add our own metaboxes we'd use the below.
83
+		$this->_metaboxes        = array(
84
+			0 => array(
85
+				'page_route' => array('edit', 'create_new'),
86
+				'func'       => 'pricing_metabox',
87
+				'label'      => esc_html__('Event Tickets & Datetimes', 'event_espresso'),
88
+				'priority'   => 'high',
89
+				'context'    => 'normal',
90
+			),
91
+		);
92
+		$this->_remove_metaboxes = array(
93
+			0 => array(
94
+				'page_route' => array('edit', 'create_new'),
95
+				'id'         => 'espresso_event_editor_tickets',
96
+				'context'    => 'normal',
97
+			),
98
+		);
99
+	}
100 100
 
101 101
 
102
-    /**
103
-     * @return void
104
-     */
105
-    protected function _set_date_time_formats()
106
-    {
107
-        /**
108
-         * Format strings for date and time.  Defaults are existing behaviour from 4.1.
109
-         * Note, that if you return null as the value for 'date', and 'time' in the array, then
110
-         * EE will automatically use the set wp_options, 'date_format', and 'time_format'.
111
-         *
112
-         * @since 4.6.7
113
-         * @var array  Expected an array returned with 'date' and 'time' keys.
114
-         */
115
-        $this->_date_format_strings = apply_filters(
116
-            'FHEE__espresso_events_Pricing_Hooks___set_hooks_properties__date_format_strings',
117
-            array(
118
-                'date' => 'Y-m-d',
119
-                'time' => 'h:i a',
120
-            )
121
-        );
122
-        //validate
123
-        $this->_date_format_strings['date'] = isset($this->_date_format_strings['date'])
124
-            ? $this->_date_format_strings['date']
125
-            : null;
126
-        $this->_date_format_strings['time'] = isset($this->_date_format_strings['time'])
127
-            ? $this->_date_format_strings['time']
128
-            : null;
129
-        $this->_date_time_format            = $this->_date_format_strings['date']
130
-                                              . ' '
131
-                                              . $this->_date_format_strings['time'];
132
-    }
102
+	/**
103
+	 * @return void
104
+	 */
105
+	protected function _set_date_time_formats()
106
+	{
107
+		/**
108
+		 * Format strings for date and time.  Defaults are existing behaviour from 4.1.
109
+		 * Note, that if you return null as the value for 'date', and 'time' in the array, then
110
+		 * EE will automatically use the set wp_options, 'date_format', and 'time_format'.
111
+		 *
112
+		 * @since 4.6.7
113
+		 * @var array  Expected an array returned with 'date' and 'time' keys.
114
+		 */
115
+		$this->_date_format_strings = apply_filters(
116
+			'FHEE__espresso_events_Pricing_Hooks___set_hooks_properties__date_format_strings',
117
+			array(
118
+				'date' => 'Y-m-d',
119
+				'time' => 'h:i a',
120
+			)
121
+		);
122
+		//validate
123
+		$this->_date_format_strings['date'] = isset($this->_date_format_strings['date'])
124
+			? $this->_date_format_strings['date']
125
+			: null;
126
+		$this->_date_format_strings['time'] = isset($this->_date_format_strings['time'])
127
+			? $this->_date_format_strings['time']
128
+			: null;
129
+		$this->_date_time_format            = $this->_date_format_strings['date']
130
+											  . ' '
131
+											  . $this->_date_format_strings['time'];
132
+	}
133 133
 
134 134
 
135
-    /**
136
-     * @return void
137
-     */
138
-    protected function _validate_format_strings()
139
-    {
140
-        //validate format strings
141
-        $format_validation = EEH_DTT_Helper::validate_format_string(
142
-            $this->_date_time_format
143
-        );
144
-        if (is_array($format_validation)) {
145
-            $msg = '<p>';
146
-            $msg .= sprintf(
147
-                esc_html__(
148
-                    'The format "%s" was likely added via a filter and is invalid for the following reasons:',
149
-                    'event_espresso'
150
-                ),
151
-                $this->_date_time_format
152
-            );
153
-            $msg .= '</p><ul>';
154
-            foreach ($format_validation as $error) {
155
-                $msg .= '<li>' . $error . '</li>';
156
-            }
157
-            $msg .= '</ul><p>';
158
-            $msg .= sprintf(
159
-                esc_html__(
160
-                    '%sPlease note that your date and time formats have been reset to "Y-m-d" and "h:i a" respectively.%s',
161
-                    'event_espresso'
162
-                ),
163
-                '<span style="color:#D54E21;">',
164
-                '</span>'
165
-            );
166
-            $msg .= '</p>';
167
-            EE_Error::add_attention($msg, __FILE__, __FUNCTION__, __LINE__);
168
-            $this->_date_format_strings = array(
169
-                'date' => 'Y-m-d',
170
-                'time' => 'h:i a',
171
-            );
172
-        }
173
-    }
135
+	/**
136
+	 * @return void
137
+	 */
138
+	protected function _validate_format_strings()
139
+	{
140
+		//validate format strings
141
+		$format_validation = EEH_DTT_Helper::validate_format_string(
142
+			$this->_date_time_format
143
+		);
144
+		if (is_array($format_validation)) {
145
+			$msg = '<p>';
146
+			$msg .= sprintf(
147
+				esc_html__(
148
+					'The format "%s" was likely added via a filter and is invalid for the following reasons:',
149
+					'event_espresso'
150
+				),
151
+				$this->_date_time_format
152
+			);
153
+			$msg .= '</p><ul>';
154
+			foreach ($format_validation as $error) {
155
+				$msg .= '<li>' . $error . '</li>';
156
+			}
157
+			$msg .= '</ul><p>';
158
+			$msg .= sprintf(
159
+				esc_html__(
160
+					'%sPlease note that your date and time formats have been reset to "Y-m-d" and "h:i a" respectively.%s',
161
+					'event_espresso'
162
+				),
163
+				'<span style="color:#D54E21;">',
164
+				'</span>'
165
+			);
166
+			$msg .= '</p>';
167
+			EE_Error::add_attention($msg, __FILE__, __FUNCTION__, __LINE__);
168
+			$this->_date_format_strings = array(
169
+				'date' => 'Y-m-d',
170
+				'time' => 'h:i a',
171
+			);
172
+		}
173
+	}
174 174
 
175 175
 
176
-    /**
177
-     * @return void
178
-     */
179
-    protected function _set_scripts_styles()
180
-    {
181
-        $this->_scripts_styles = array(
182
-            'registers'   => array(
183
-                'ee-tickets-datetimes-css' => array(
184
-                    'url'  => PRICING_ASSETS_URL . 'event-tickets-datetimes.css',
185
-                    'type' => 'css',
186
-                ),
187
-                'ee-dtt-ticket-metabox'    => array(
188
-                    'url'     => PRICING_ASSETS_URL . 'ee-datetime-ticket-metabox.js',
189
-                    'depends' => array('ee-datepicker', 'ee-dialog', 'underscore'),
190
-                ),
191
-            ),
192
-            'deregisters' => array(
193
-                'event-editor-css'       => array('type' => 'css'),
194
-                'event-datetime-metabox' => array('type' => 'js'),
195
-            ),
196
-            'enqueues'    => array(
197
-                'ee-tickets-datetimes-css' => array('edit', 'create_new'),
198
-                'ee-dtt-ticket-metabox'    => array('edit', 'create_new'),
199
-            ),
200
-            'localize'    => array(
201
-                'ee-dtt-ticket-metabox' => array(
202
-                    'DTT_TRASH_BLOCK'       => array(
203
-                        'main_warning'            => esc_html__(
204
-                            'The Datetime you are attempting to trash is the only datetime selected for the following ticket(s):',
205
-                            'event_espresso'
206
-                        ),
207
-                        'after_warning'           => esc_html__(
208
-                            'In order to trash this datetime you must first make sure the above ticket(s) are assigned to other datetimes.',
209
-                            'event_espresso'
210
-                        ),
211
-                        'cancel_button'           => '<button class="button-secondary ee-modal-cancel">'
212
-                                                     . esc_html__('Cancel', 'event_espresso') . '</button>',
213
-                        'close_button'            => '<button class="button-secondary ee-modal-cancel">'
214
-                                                     . esc_html__('Close', 'event_espresso') . '</button>',
215
-                        'single_warning_from_tkt' => esc_html__(
216
-                            'The Datetime you are attempting to unassign from this ticket is the only remaining datetime for this ticket. Tickets must always have at least one datetime assigned to them.',
217
-                            'event_espresso'
218
-                        ),
219
-                        'single_warning_from_dtt' => esc_html__(
220
-                            'The ticket you are attempting to unassign from this datetime cannot be unassigned because the datetime is the only remaining datetime for the ticket.  Tickets must always have at least one datetime assigned to them.',
221
-                            'event_espresso'
222
-                        ),
223
-                        'dismiss_button'          => '<button class="button-secondary ee-modal-cancel">'
224
-                                                     . esc_html__('Dismiss', 'event_espresso') . '</button>',
225
-                    ),
226
-                    'DTT_ERROR_MSG'         => array(
227
-                        'no_ticket_name' => esc_html__('General Admission', 'event_espresso'),
228
-                        'dismiss_button' => '<div class="save-cancel-button-container">'
229
-                                            . '<button class="button-secondary ee-modal-cancel">'
230
-                                            . esc_html__('Dismiss', 'event_espresso')
231
-                                            . '</button></div>',
232
-                    ),
233
-                    'DTT_OVERSELL_WARNING'  => array(
234
-                        'datetime_ticket' => esc_html__(
235
-                            'You cannot add this ticket to this datetime because it has a sold amount that is greater than the amount of spots remaining for this datetime.',
236
-                            'event_espresso'
237
-                        ),
238
-                        'ticket_datetime' => esc_html__(
239
-                            'You cannot add this datetime to this ticket because the ticket has a sold amount that is greater than the amount of spots remaining on the datetime.',
240
-                            'event_espresso'
241
-                        ),
242
-                    ),
243
-                    'DTT_CONVERTED_FORMATS' => EEH_DTT_Helper::convert_php_to_js_and_moment_date_formats(
244
-                        $this->_date_format_strings['date'],
245
-                        $this->_date_format_strings['time']
246
-                    ),
247
-                    'DTT_START_OF_WEEK'     => array('dayValue' => (int) get_option('start_of_week')),
248
-                ),
249
-            ),
250
-        );
251
-    }
176
+	/**
177
+	 * @return void
178
+	 */
179
+	protected function _set_scripts_styles()
180
+	{
181
+		$this->_scripts_styles = array(
182
+			'registers'   => array(
183
+				'ee-tickets-datetimes-css' => array(
184
+					'url'  => PRICING_ASSETS_URL . 'event-tickets-datetimes.css',
185
+					'type' => 'css',
186
+				),
187
+				'ee-dtt-ticket-metabox'    => array(
188
+					'url'     => PRICING_ASSETS_URL . 'ee-datetime-ticket-metabox.js',
189
+					'depends' => array('ee-datepicker', 'ee-dialog', 'underscore'),
190
+				),
191
+			),
192
+			'deregisters' => array(
193
+				'event-editor-css'       => array('type' => 'css'),
194
+				'event-datetime-metabox' => array('type' => 'js'),
195
+			),
196
+			'enqueues'    => array(
197
+				'ee-tickets-datetimes-css' => array('edit', 'create_new'),
198
+				'ee-dtt-ticket-metabox'    => array('edit', 'create_new'),
199
+			),
200
+			'localize'    => array(
201
+				'ee-dtt-ticket-metabox' => array(
202
+					'DTT_TRASH_BLOCK'       => array(
203
+						'main_warning'            => esc_html__(
204
+							'The Datetime you are attempting to trash is the only datetime selected for the following ticket(s):',
205
+							'event_espresso'
206
+						),
207
+						'after_warning'           => esc_html__(
208
+							'In order to trash this datetime you must first make sure the above ticket(s) are assigned to other datetimes.',
209
+							'event_espresso'
210
+						),
211
+						'cancel_button'           => '<button class="button-secondary ee-modal-cancel">'
212
+													 . esc_html__('Cancel', 'event_espresso') . '</button>',
213
+						'close_button'            => '<button class="button-secondary ee-modal-cancel">'
214
+													 . esc_html__('Close', 'event_espresso') . '</button>',
215
+						'single_warning_from_tkt' => esc_html__(
216
+							'The Datetime you are attempting to unassign from this ticket is the only remaining datetime for this ticket. Tickets must always have at least one datetime assigned to them.',
217
+							'event_espresso'
218
+						),
219
+						'single_warning_from_dtt' => esc_html__(
220
+							'The ticket you are attempting to unassign from this datetime cannot be unassigned because the datetime is the only remaining datetime for the ticket.  Tickets must always have at least one datetime assigned to them.',
221
+							'event_espresso'
222
+						),
223
+						'dismiss_button'          => '<button class="button-secondary ee-modal-cancel">'
224
+													 . esc_html__('Dismiss', 'event_espresso') . '</button>',
225
+					),
226
+					'DTT_ERROR_MSG'         => array(
227
+						'no_ticket_name' => esc_html__('General Admission', 'event_espresso'),
228
+						'dismiss_button' => '<div class="save-cancel-button-container">'
229
+											. '<button class="button-secondary ee-modal-cancel">'
230
+											. esc_html__('Dismiss', 'event_espresso')
231
+											. '</button></div>',
232
+					),
233
+					'DTT_OVERSELL_WARNING'  => array(
234
+						'datetime_ticket' => esc_html__(
235
+							'You cannot add this ticket to this datetime because it has a sold amount that is greater than the amount of spots remaining for this datetime.',
236
+							'event_espresso'
237
+						),
238
+						'ticket_datetime' => esc_html__(
239
+							'You cannot add this datetime to this ticket because the ticket has a sold amount that is greater than the amount of spots remaining on the datetime.',
240
+							'event_espresso'
241
+						),
242
+					),
243
+					'DTT_CONVERTED_FORMATS' => EEH_DTT_Helper::convert_php_to_js_and_moment_date_formats(
244
+						$this->_date_format_strings['date'],
245
+						$this->_date_format_strings['time']
246
+					),
247
+					'DTT_START_OF_WEEK'     => array('dayValue' => (int) get_option('start_of_week')),
248
+				),
249
+			),
250
+		);
251
+	}
252 252
 
253 253
 
254
-    /**
255
-     * @param array $update_callbacks
256
-     * @return array
257
-     */
258
-    public function caf_updates(array $update_callbacks)
259
-    {
260
-        foreach ($update_callbacks as $key => $callback) {
261
-            if ($callback[1] === '_default_tickets_update') {
262
-                unset($update_callbacks[ $key ]);
263
-            }
264
-        }
265
-        $update_callbacks[] = array($this, 'datetime_and_tickets_caf_update');
266
-        return $update_callbacks;
267
-    }
254
+	/**
255
+	 * @param array $update_callbacks
256
+	 * @return array
257
+	 */
258
+	public function caf_updates(array $update_callbacks)
259
+	{
260
+		foreach ($update_callbacks as $key => $callback) {
261
+			if ($callback[1] === '_default_tickets_update') {
262
+				unset($update_callbacks[ $key ]);
263
+			}
264
+		}
265
+		$update_callbacks[] = array($this, 'datetime_and_tickets_caf_update');
266
+		return $update_callbacks;
267
+	}
268 268
 
269 269
 
270
-    /**
271
-     * Handles saving everything related to Tickets (datetimes, tickets, prices)
272
-     *
273
-     * @param  EE_Event $event The Event object we're attaching data to
274
-     * @param  array    $data  The request data from the form
275
-     * @throws ReflectionException
276
-     * @throws Exception
277
-     * @throws InvalidInterfaceException
278
-     * @throws InvalidDataTypeException
279
-     * @throws EE_Error
280
-     * @throws InvalidArgumentException
281
-     */
282
-    public function datetime_and_tickets_caf_update($event, $data)
283
-    {
284
-        //first we need to start with datetimes cause they are the "root" items attached to events.
285
-        $saved_datetimes = $this->_update_datetimes($event, $data);
286
-        //next tackle the tickets (and prices?)
287
-        $this->_update_tickets($event, $saved_datetimes, $data);
288
-    }
270
+	/**
271
+	 * Handles saving everything related to Tickets (datetimes, tickets, prices)
272
+	 *
273
+	 * @param  EE_Event $event The Event object we're attaching data to
274
+	 * @param  array    $data  The request data from the form
275
+	 * @throws ReflectionException
276
+	 * @throws Exception
277
+	 * @throws InvalidInterfaceException
278
+	 * @throws InvalidDataTypeException
279
+	 * @throws EE_Error
280
+	 * @throws InvalidArgumentException
281
+	 */
282
+	public function datetime_and_tickets_caf_update($event, $data)
283
+	{
284
+		//first we need to start with datetimes cause they are the "root" items attached to events.
285
+		$saved_datetimes = $this->_update_datetimes($event, $data);
286
+		//next tackle the tickets (and prices?)
287
+		$this->_update_tickets($event, $saved_datetimes, $data);
288
+	}
289 289
 
290 290
 
291
-    /**
292
-     * update event_datetimes
293
-     *
294
-     * @param  EE_Event $event Event being updated
295
-     * @param  array    $data  the request data from the form
296
-     * @return EE_Datetime[]
297
-     * @throws Exception
298
-     * @throws ReflectionException
299
-     * @throws InvalidInterfaceException
300
-     * @throws InvalidDataTypeException
301
-     * @throws InvalidArgumentException
302
-     * @throws EE_Error
303
-     */
304
-    protected function _update_datetimes($event, $data)
305
-    {
306
-        $timezone       = isset($data['timezone_string']) ? $data['timezone_string'] : null;
307
-        $saved_dtt_ids  = array();
308
-        $saved_dtt_objs = array();
309
-        if (empty($data['edit_event_datetimes']) || ! is_array($data['edit_event_datetimes'])) {
310
-            throw new InvalidArgumentException(
311
-                esc_html__(
312
-                    'The "edit_event_datetimes" array is invalid therefore the event can not be updated.',
313
-                    'event_espresso'
314
-                )
315
-            );
316
-        }
317
-        foreach ($data['edit_event_datetimes'] as $row => $datetime_data) {
318
-            //trim all values to ensure any excess whitespace is removed.
319
-            $datetime_data                = array_map(
320
-                function ($datetime_data)
321
-                {
322
-                    return is_array($datetime_data) ? $datetime_data : trim($datetime_data);
323
-                },
324
-                $datetime_data
325
-            );
326
-            $datetime_data['DTT_EVT_end'] = isset($datetime_data['DTT_EVT_end'])
327
-                                            && ! empty($datetime_data['DTT_EVT_end'])
328
-                ? $datetime_data['DTT_EVT_end']
329
-                : $datetime_data['DTT_EVT_start'];
330
-            $datetime_values              = array(
331
-                'DTT_ID'          => ! empty($datetime_data['DTT_ID'])
332
-                    ? $datetime_data['DTT_ID']
333
-                    : null,
334
-                'DTT_name'        => ! empty($datetime_data['DTT_name'])
335
-                    ? $datetime_data['DTT_name']
336
-                    : '',
337
-                'DTT_description' => ! empty($datetime_data['DTT_description'])
338
-                    ? $datetime_data['DTT_description']
339
-                    : '',
340
-                'DTT_EVT_start'   => $datetime_data['DTT_EVT_start'],
341
-                'DTT_EVT_end'     => $datetime_data['DTT_EVT_end'],
342
-                'DTT_reg_limit'   => empty($datetime_data['DTT_reg_limit'])
343
-                    ? EE_INF
344
-                    : $datetime_data['DTT_reg_limit'],
345
-                'DTT_order'       => ! isset($datetime_data['DTT_order'])
346
-                    ? $row
347
-                    : $datetime_data['DTT_order'],
348
-            );
349
-            // if we have an id then let's get existing object first and then set the new values.
350
-            // Otherwise we instantiate a new object for save.
351
-            if (! empty($datetime_data['DTT_ID'])) {
352
-                $datetime = EE_Registry::instance()
353
-                                       ->load_model('Datetime', array($timezone))
354
-                                       ->get_one_by_ID($datetime_data['DTT_ID']);
355
-                //set date and time format according to what is set in this class.
356
-                $datetime->set_date_format($this->_date_format_strings['date']);
357
-                $datetime->set_time_format($this->_date_format_strings['time']);
358
-                foreach ($datetime_values as $field => $value) {
359
-                    $datetime->set($field, $value);
360
-                }
361
-                // make sure the $dtt_id here is saved just in case
362
-                // after the add_relation_to() the autosave replaces it.
363
-                // We need to do this so we dont' TRASH the parent DTT.
364
-                // (save the ID for both key and value to avoid duplications)
365
-                $saved_dtt_ids[ $datetime->ID() ] = $datetime->ID();
366
-            } else {
367
-                $datetime = EE_Registry::instance()->load_class(
368
-                    'Datetime',
369
-                    array(
370
-                        $datetime_values,
371
-                        $timezone,
372
-                        array($this->_date_format_strings['date'], $this->_date_format_strings['time']),
373
-                    ),
374
-                    false,
375
-                    false
376
-                );
377
-                foreach ($datetime_values as $field => $value) {
378
-                    $datetime->set($field, $value);
379
-                }
380
-            }
381
-            $datetime->save();
382
-            $datetime = $event->_add_relation_to($datetime, 'Datetime');
383
-            // before going any further make sure our dates are setup correctly
384
-            // so that the end date is always equal or greater than the start date.
385
-            if ($datetime->get_raw('DTT_EVT_start') > $datetime->get_raw('DTT_EVT_end')) {
386
-                $datetime->set('DTT_EVT_end', $datetime->get('DTT_EVT_start'));
387
-                $datetime = EEH_DTT_Helper::date_time_add($datetime, 'DTT_EVT_end', 'days');
388
-                $datetime->save();
389
-            }
390
-            //	now we have to make sure we add the new DTT_ID to the $saved_dtt_ids array
391
-            // because it is possible there was a new one created for the autosave.
392
-            // (save the ID for both key and value to avoid duplications)
393
-            $DTT_ID                   = $datetime->ID();
394
-            $saved_dtt_ids[ $DTT_ID ] = $DTT_ID;
395
-            $saved_dtt_objs[ $row ]   = $datetime;
396
-            //todo if ANY of these updates fail then we want the appropriate global error message.
397
-        }
398
-        $event->save();
399
-        // now we need to REMOVE any datetimes that got deleted.
400
-        // Keep in mind that this process will only kick in for datetimes that don't have any DTT_sold on them.
401
-        // So its safe to permanently delete at this point.
402
-        $old_datetimes = explode(',', $data['datetime_IDs']);
403
-        $old_datetimes = $old_datetimes[0] === '' ? array() : $old_datetimes;
404
-        if (is_array($old_datetimes)) {
405
-            $datetimes_to_delete = array_diff($old_datetimes, $saved_dtt_ids);
406
-            foreach ($datetimes_to_delete as $id) {
407
-                $id = absint($id);
408
-                if (empty($id)) {
409
-                    continue;
410
-                }
411
-                $dtt_to_remove = EE_Registry::instance()->load_model('Datetime')->get_one_by_ID($id);
412
-                //remove tkt relationships.
413
-                $related_tickets = $dtt_to_remove->get_many_related('Ticket');
414
-                foreach ($related_tickets as $tkt) {
415
-                    $dtt_to_remove->_remove_relation_to($tkt, 'Ticket');
416
-                }
417
-                $event->_remove_relation_to($id, 'Datetime');
418
-                $dtt_to_remove->refresh_cache_of_related_objects();
419
-            }
420
-        }
421
-        return $saved_dtt_objs;
422
-    }
291
+	/**
292
+	 * update event_datetimes
293
+	 *
294
+	 * @param  EE_Event $event Event being updated
295
+	 * @param  array    $data  the request data from the form
296
+	 * @return EE_Datetime[]
297
+	 * @throws Exception
298
+	 * @throws ReflectionException
299
+	 * @throws InvalidInterfaceException
300
+	 * @throws InvalidDataTypeException
301
+	 * @throws InvalidArgumentException
302
+	 * @throws EE_Error
303
+	 */
304
+	protected function _update_datetimes($event, $data)
305
+	{
306
+		$timezone       = isset($data['timezone_string']) ? $data['timezone_string'] : null;
307
+		$saved_dtt_ids  = array();
308
+		$saved_dtt_objs = array();
309
+		if (empty($data['edit_event_datetimes']) || ! is_array($data['edit_event_datetimes'])) {
310
+			throw new InvalidArgumentException(
311
+				esc_html__(
312
+					'The "edit_event_datetimes" array is invalid therefore the event can not be updated.',
313
+					'event_espresso'
314
+				)
315
+			);
316
+		}
317
+		foreach ($data['edit_event_datetimes'] as $row => $datetime_data) {
318
+			//trim all values to ensure any excess whitespace is removed.
319
+			$datetime_data                = array_map(
320
+				function ($datetime_data)
321
+				{
322
+					return is_array($datetime_data) ? $datetime_data : trim($datetime_data);
323
+				},
324
+				$datetime_data
325
+			);
326
+			$datetime_data['DTT_EVT_end'] = isset($datetime_data['DTT_EVT_end'])
327
+											&& ! empty($datetime_data['DTT_EVT_end'])
328
+				? $datetime_data['DTT_EVT_end']
329
+				: $datetime_data['DTT_EVT_start'];
330
+			$datetime_values              = array(
331
+				'DTT_ID'          => ! empty($datetime_data['DTT_ID'])
332
+					? $datetime_data['DTT_ID']
333
+					: null,
334
+				'DTT_name'        => ! empty($datetime_data['DTT_name'])
335
+					? $datetime_data['DTT_name']
336
+					: '',
337
+				'DTT_description' => ! empty($datetime_data['DTT_description'])
338
+					? $datetime_data['DTT_description']
339
+					: '',
340
+				'DTT_EVT_start'   => $datetime_data['DTT_EVT_start'],
341
+				'DTT_EVT_end'     => $datetime_data['DTT_EVT_end'],
342
+				'DTT_reg_limit'   => empty($datetime_data['DTT_reg_limit'])
343
+					? EE_INF
344
+					: $datetime_data['DTT_reg_limit'],
345
+				'DTT_order'       => ! isset($datetime_data['DTT_order'])
346
+					? $row
347
+					: $datetime_data['DTT_order'],
348
+			);
349
+			// if we have an id then let's get existing object first and then set the new values.
350
+			// Otherwise we instantiate a new object for save.
351
+			if (! empty($datetime_data['DTT_ID'])) {
352
+				$datetime = EE_Registry::instance()
353
+									   ->load_model('Datetime', array($timezone))
354
+									   ->get_one_by_ID($datetime_data['DTT_ID']);
355
+				//set date and time format according to what is set in this class.
356
+				$datetime->set_date_format($this->_date_format_strings['date']);
357
+				$datetime->set_time_format($this->_date_format_strings['time']);
358
+				foreach ($datetime_values as $field => $value) {
359
+					$datetime->set($field, $value);
360
+				}
361
+				// make sure the $dtt_id here is saved just in case
362
+				// after the add_relation_to() the autosave replaces it.
363
+				// We need to do this so we dont' TRASH the parent DTT.
364
+				// (save the ID for both key and value to avoid duplications)
365
+				$saved_dtt_ids[ $datetime->ID() ] = $datetime->ID();
366
+			} else {
367
+				$datetime = EE_Registry::instance()->load_class(
368
+					'Datetime',
369
+					array(
370
+						$datetime_values,
371
+						$timezone,
372
+						array($this->_date_format_strings['date'], $this->_date_format_strings['time']),
373
+					),
374
+					false,
375
+					false
376
+				);
377
+				foreach ($datetime_values as $field => $value) {
378
+					$datetime->set($field, $value);
379
+				}
380
+			}
381
+			$datetime->save();
382
+			$datetime = $event->_add_relation_to($datetime, 'Datetime');
383
+			// before going any further make sure our dates are setup correctly
384
+			// so that the end date is always equal or greater than the start date.
385
+			if ($datetime->get_raw('DTT_EVT_start') > $datetime->get_raw('DTT_EVT_end')) {
386
+				$datetime->set('DTT_EVT_end', $datetime->get('DTT_EVT_start'));
387
+				$datetime = EEH_DTT_Helper::date_time_add($datetime, 'DTT_EVT_end', 'days');
388
+				$datetime->save();
389
+			}
390
+			//	now we have to make sure we add the new DTT_ID to the $saved_dtt_ids array
391
+			// because it is possible there was a new one created for the autosave.
392
+			// (save the ID for both key and value to avoid duplications)
393
+			$DTT_ID                   = $datetime->ID();
394
+			$saved_dtt_ids[ $DTT_ID ] = $DTT_ID;
395
+			$saved_dtt_objs[ $row ]   = $datetime;
396
+			//todo if ANY of these updates fail then we want the appropriate global error message.
397
+		}
398
+		$event->save();
399
+		// now we need to REMOVE any datetimes that got deleted.
400
+		// Keep in mind that this process will only kick in for datetimes that don't have any DTT_sold on them.
401
+		// So its safe to permanently delete at this point.
402
+		$old_datetimes = explode(',', $data['datetime_IDs']);
403
+		$old_datetimes = $old_datetimes[0] === '' ? array() : $old_datetimes;
404
+		if (is_array($old_datetimes)) {
405
+			$datetimes_to_delete = array_diff($old_datetimes, $saved_dtt_ids);
406
+			foreach ($datetimes_to_delete as $id) {
407
+				$id = absint($id);
408
+				if (empty($id)) {
409
+					continue;
410
+				}
411
+				$dtt_to_remove = EE_Registry::instance()->load_model('Datetime')->get_one_by_ID($id);
412
+				//remove tkt relationships.
413
+				$related_tickets = $dtt_to_remove->get_many_related('Ticket');
414
+				foreach ($related_tickets as $tkt) {
415
+					$dtt_to_remove->_remove_relation_to($tkt, 'Ticket');
416
+				}
417
+				$event->_remove_relation_to($id, 'Datetime');
418
+				$dtt_to_remove->refresh_cache_of_related_objects();
419
+			}
420
+		}
421
+		return $saved_dtt_objs;
422
+	}
423 423
 
424 424
 
425
-    /**
426
-     * update tickets
427
-     *
428
-     * @param  EE_Event      $event           Event object being updated
429
-     * @param  EE_Datetime[] $saved_datetimes an array of datetime ids being updated
430
-     * @param  array         $data            incoming request data
431
-     * @return EE_Ticket[]
432
-     * @throws Exception
433
-     * @throws ReflectionException
434
-     * @throws InvalidInterfaceException
435
-     * @throws InvalidDataTypeException
436
-     * @throws InvalidArgumentException
437
-     * @throws EE_Error
438
-     */
439
-    protected function _update_tickets($event, $saved_datetimes, $data)
440
-    {
441
-        $new_tkt     = null;
442
-        $new_default = null;
443
-        //stripslashes because WP filtered the $_POST ($data) array to add slashes
444
-        $data          = stripslashes_deep($data);
445
-        $timezone      = isset($data['timezone_string']) ? $data['timezone_string'] : null;
446
-        $saved_tickets = $datetimes_on_existing = array();
447
-        $old_tickets   = isset($data['ticket_IDs']) ? explode(',', $data['ticket_IDs']) : array();
448
-        if (empty($data['edit_tickets']) || ! is_array($data['edit_tickets'])) {
449
-            throw new InvalidArgumentException(
450
-                esc_html__(
451
-                    'The "edit_tickets" array is invalid therefore the event can not be updated.',
452
-                    'event_espresso'
453
-                )
454
-            );
455
-        }
456
-        foreach ($data['edit_tickets'] as $row => $tkt) {
457
-            $update_prices = $create_new_TKT = false;
458
-            // figure out what datetimes were added to the ticket
459
-            // and what datetimes were removed from the ticket in the session.
460
-            $starting_tkt_dtt_rows = explode(',', $data['starting_ticket_datetime_rows'][ $row ]);
461
-            $tkt_dtt_rows          = explode(',', $data['ticket_datetime_rows'][ $row ]);
462
-            $datetimes_added       = array_diff($tkt_dtt_rows, $starting_tkt_dtt_rows);
463
-            $datetimes_removed     = array_diff($starting_tkt_dtt_rows, $tkt_dtt_rows);
464
-            // trim inputs to ensure any excess whitespace is removed.
465
-            $tkt = array_map(
466
-                function ($ticket_data)
467
-                {
468
-                    return is_array($ticket_data) ? $ticket_data : trim($ticket_data);
469
-                },
470
-                $tkt
471
-            );
472
-            // note we are doing conversions to floats here instead of allowing EE_Money_Field to handle
473
-            // because we're doing calculations prior to using the models.
474
-            // note incoming ['TKT_price'] value is already in standard notation (via js).
475
-            $ticket_price = isset($tkt['TKT_price'])
476
-                ? round((float) $tkt['TKT_price'], 3)
477
-                : 0;
478
-            //note incoming base price needs converted from localized value.
479
-            $base_price = isset($tkt['TKT_base_price'])
480
-                ? EEH_Money::convert_to_float_from_localized_money($tkt['TKT_base_price'])
481
-                : 0;
482
-            //if ticket price == 0 and $base_price != 0 then ticket price == base_price
483
-            $ticket_price  = $ticket_price === 0 && $base_price !== 0
484
-                ? $base_price
485
-                : $ticket_price;
486
-            $base_price_id = isset($tkt['TKT_base_price_ID'])
487
-                ? $tkt['TKT_base_price_ID']
488
-                : 0;
489
-            $price_rows    = is_array($data['edit_prices']) && isset($data['edit_prices'][ $row ])
490
-                ? $data['edit_prices'][ $row ]
491
-                : array();
492
-            $now           = null;
493
-            if (empty($tkt['TKT_start_date'])) {
494
-                //lets' use now in the set timezone.
495
-                $now                   = new DateTime('now', new DateTimeZone($event->get_timezone()));
496
-                $tkt['TKT_start_date'] = $now->format($this->_date_time_format);
497
-            }
498
-            if (empty($tkt['TKT_end_date'])) {
499
-                /**
500
-                 * set the TKT_end_date to the first datetime attached to the ticket.
501
-                 */
502
-                $first_dtt           = $saved_datetimes[ reset($tkt_dtt_rows) ];
503
-                $tkt['TKT_end_date'] = $first_dtt->start_date_and_time($this->_date_time_format);
504
-            }
505
-            $TKT_values = array(
506
-                'TKT_ID'          => ! empty($tkt['TKT_ID']) ? $tkt['TKT_ID'] : null,
507
-                'TTM_ID'          => ! empty($tkt['TTM_ID']) ? $tkt['TTM_ID'] : 0,
508
-                'TKT_name'        => ! empty($tkt['TKT_name']) ? $tkt['TKT_name'] : '',
509
-                'TKT_description' => ! empty($tkt['TKT_description'])
510
-                                     && $tkt['TKT_description'] !== esc_html__(
511
-                    'You can modify this description',
512
-                    'event_espresso'
513
-                )
514
-                    ? $tkt['TKT_description']
515
-                    : '',
516
-                'TKT_start_date'  => $tkt['TKT_start_date'],
517
-                'TKT_end_date'    => $tkt['TKT_end_date'],
518
-                'TKT_qty'         => ! isset($tkt['TKT_qty']) || $tkt['TKT_qty'] === ''
519
-                    ? EE_INF
520
-                    : $tkt['TKT_qty'],
521
-                'TKT_uses'        => ! isset($tkt['TKT_uses']) || $tkt['TKT_uses'] === ''
522
-                    ? EE_INF
523
-                    : $tkt['TKT_uses'],
524
-                'TKT_min'         => empty($tkt['TKT_min']) ? 0 : $tkt['TKT_min'],
525
-                'TKT_max'         => empty($tkt['TKT_max']) ? EE_INF : $tkt['TKT_max'],
526
-                'TKT_row'         => $row,
527
-                'TKT_order'       => isset($tkt['TKT_order']) ? $tkt['TKT_order'] : 0,
528
-                'TKT_taxable'     => ! empty($tkt['TKT_taxable']) ? 1 : 0,
529
-                'TKT_required'    => ! empty($tkt['TKT_required']) ? 1 : 0,
530
-                'TKT_price'       => $ticket_price,
531
-            );
532
-            // if this is a default TKT, then we need to set the TKT_ID to 0 and update accordingly,
533
-            // which means in turn that the prices will become new prices as well.
534
-            if (isset($tkt['TKT_is_default']) && $tkt['TKT_is_default']) {
535
-                $TKT_values['TKT_ID']         = 0;
536
-                $TKT_values['TKT_is_default'] = 0;
537
-                $update_prices                = true;
538
-            }
539
-            // if we have a TKT_ID then we need to get that existing TKT_obj and update it
540
-            // we actually do our saves ahead of doing any add_relations to
541
-            // because its entirely possible that this ticket wasn't removed or added to any datetime in the session
542
-            // but DID have it's items modified.
543
-            // keep in mind that if the TKT has been sold (and we have changed pricing information),
544
-            // then we won't be updating the tkt but instead a new tkt will be created and the old one archived.
545
-            if (absint($TKT_values['TKT_ID'])) {
546
-                $ticket = EE_Registry::instance()
547
-                                     ->load_model('Ticket', array($timezone))
548
-                                     ->get_one_by_ID($tkt['TKT_ID']);
549
-                if ($ticket instanceof EE_Ticket) {
550
-                    $ticket = $this->_update_ticket_datetimes(
551
-                        $ticket,
552
-                        $saved_datetimes,
553
-                        $datetimes_added,
554
-                        $datetimes_removed
555
-                    );
556
-                    // are there any registrations using this ticket ?
557
-                    $tickets_sold = $ticket->count_related(
558
-                        'Registration',
559
-                        array(
560
-                            array(
561
-                                'STS_ID' => array('NOT IN', array(EEM_Registration::status_id_incomplete)),
562
-                            ),
563
-                        )
564
-                    );
565
-                    //set ticket formats
566
-                    $ticket->set_date_format($this->_date_format_strings['date']);
567
-                    $ticket->set_time_format($this->_date_format_strings['time']);
568
-                    // let's just check the total price for the existing ticket
569
-                    // and determine if it matches the new total price.
570
-                    // if they are different then we create a new ticket (if tickets sold)
571
-                    // if they aren't different then we go ahead and modify existing ticket.
572
-                    $create_new_TKT = $tickets_sold > 0 && $ticket_price !== $ticket->price() && ! $ticket->deleted();
573
-                    //set new values
574
-                    foreach ($TKT_values as $field => $value) {
575
-                        if ($field === 'TKT_qty') {
576
-                            $ticket->set_qty($value);
577
-                        } else {
578
-                            $ticket->set($field, $value);
579
-                        }
580
-                    }
581
-                    // if $create_new_TKT is false then we can safely update the existing ticket.
582
-                    // Otherwise we have to create a new ticket.
583
-                    if ($create_new_TKT) {
584
-                        $new_tkt = $this->_duplicate_ticket(
585
-                            $ticket,
586
-                            $price_rows,
587
-                            $ticket_price,
588
-                            $base_price,
589
-                            $base_price_id
590
-                        );
591
-                    }
592
-                }
593
-            } else {
594
-                // no TKT_id so a new TKT
595
-                $ticket = EE_Ticket::new_instance(
596
-                    $TKT_values,
597
-                    $timezone,
598
-                    array($this->_date_format_strings['date'], $this->_date_format_strings['time'])
599
-                );
600
-                if ($ticket instanceof EE_Ticket) {
601
-                    // make sure ticket has an ID of setting relations won't work
602
-                    $ticket->save();
603
-                    $ticket        = $this->_update_ticket_datetimes(
604
-                        $ticket,
605
-                        $saved_datetimes,
606
-                        $datetimes_added,
607
-                        $datetimes_removed
608
-                    );
609
-                    $update_prices = true;
610
-                }
611
-            }
612
-            //make sure any current values have been saved.
613
-            //$ticket->save();
614
-            // before going any further make sure our dates are setup correctly
615
-            // so that the end date is always equal or greater than the start date.
616
-            if ($ticket->get_raw('TKT_start_date') > $ticket->get_raw('TKT_end_date')) {
617
-                $ticket->set('TKT_end_date', $ticket->get('TKT_start_date'));
618
-                $ticket = EEH_DTT_Helper::date_time_add($ticket, 'TKT_end_date', 'days');
619
-            }
620
-            //let's make sure the base price is handled
621
-            $ticket = ! $create_new_TKT
622
-                ? $this->_add_prices_to_ticket(
623
-                    array(),
624
-                    $ticket,
625
-                    $update_prices,
626
-                    $base_price,
627
-                    $base_price_id
628
-                )
629
-                : $ticket;
630
-            //add/update price_modifiers
631
-            $ticket = ! $create_new_TKT
632
-                ? $this->_add_prices_to_ticket($price_rows, $ticket, $update_prices)
633
-                : $ticket;
634
-            //need to make sue that the TKT_price is accurate after saving the prices.
635
-            $ticket->ensure_TKT_Price_correct();
636
-            //handle CREATING a default tkt from the incoming tkt but ONLY if this isn't an autosave.
637
-            if (! defined('DOING_AUTOSAVE') && ! empty($tkt['TKT_is_default_selector'])) {
638
-                $update_prices = true;
639
-                $new_default   = clone $ticket;
640
-                $new_default->set('TKT_ID', 0);
641
-                $new_default->set('TKT_is_default', 1);
642
-                $new_default->set('TKT_row', 1);
643
-                $new_default->set('TKT_price', $ticket_price);
644
-                // remove any dtt relations cause we DON'T want dtt relations attached
645
-                // (note this is just removing the cached relations in the object)
646
-                $new_default->_remove_relations('Datetime');
647
-                //todo we need to add the current attached prices as new prices to the new default ticket.
648
-                $new_default = $this->_add_prices_to_ticket(
649
-                    $price_rows,
650
-                    $new_default,
651
-                    $update_prices
652
-                );
653
-                //don't forget the base price!
654
-                $new_default = $this->_add_prices_to_ticket(
655
-                    array(),
656
-                    $new_default,
657
-                    $update_prices,
658
-                    $base_price,
659
-                    $base_price_id
660
-                );
661
-                $new_default->save();
662
-                do_action(
663
-                    'AHEE__espresso_events_Pricing_Hooks___update_tkts_new_default_ticket',
664
-                    $new_default,
665
-                    $row,
666
-                    $ticket,
667
-                    $data
668
-                );
669
-            }
670
-            // DO ALL dtt relationships for both current tickets and any archived tickets
671
-            // for the given dtt that are related to the current ticket.
672
-            // TODO... not sure exactly how we're going to do this considering we don't know
673
-            // what current ticket the archived tickets are related to
674
-            // (and TKT_parent is used for autosaves so that's not a field we can reliably use).
675
-            //let's assign any tickets that have been setup to the saved_tickets tracker
676
-            //save existing TKT
677
-            $ticket->save();
678
-            if ($create_new_TKT && $new_tkt instanceof EE_Ticket) {
679
-                //save new TKT
680
-                $new_tkt->save();
681
-                //add new ticket to array
682
-                $saved_tickets[ $new_tkt->ID() ] = $new_tkt;
683
-                do_action(
684
-                    'AHEE__espresso_events_Pricing_Hooks___update_tkts_new_ticket',
685
-                    $new_tkt,
686
-                    $row,
687
-                    $tkt,
688
-                    $data
689
-                );
690
-            } else {
691
-                //add tkt to saved tkts
692
-                $saved_tickets[ $ticket->ID() ] = $ticket;
693
-                do_action(
694
-                    'AHEE__espresso_events_Pricing_Hooks___update_tkts_update_ticket',
695
-                    $ticket,
696
-                    $row,
697
-                    $tkt,
698
-                    $data
699
-                );
700
-            }
701
-        }
702
-        // now we need to handle tickets actually "deleted permanently".
703
-        // There are cases where we'd want this to happen
704
-        // (i.e. autosaves are happening and then in between autosaves the user trashes a ticket).
705
-        // Or a draft event was saved and in the process of editing a ticket is trashed.
706
-        // No sense in keeping all the related data in the db!
707
-        $old_tickets     = isset($old_tickets[0]) && $old_tickets[0] === '' ? array() : $old_tickets;
708
-        $tickets_removed = array_diff($old_tickets, array_keys($saved_tickets));
709
-        foreach ($tickets_removed as $id) {
710
-            $id = absint($id);
711
-            //get the ticket for this id
712
-            $tkt_to_remove = EE_Registry::instance()->load_model('Ticket')->get_one_by_ID($id);
713
-            //if this tkt is a default tkt we leave it alone cause it won't be attached to the datetime
714
-            if ($tkt_to_remove->get('TKT_is_default')) {
715
-                continue;
716
-            }
717
-            // if this tkt has any registrations attached so then we just ARCHIVE
718
-            // because we don't actually permanently delete these tickets.
719
-            if ($tkt_to_remove->count_related('Registration') > 0) {
720
-                $tkt_to_remove->delete();
721
-                continue;
722
-            }
723
-            // need to get all the related datetimes on this ticket and remove from every single one of them
724
-            // (remember this process can ONLY kick off if there are NO tkts_sold)
725
-            $datetimes = $tkt_to_remove->get_many_related('Datetime');
726
-            foreach ($datetimes as $datetime) {
727
-                $tkt_to_remove->_remove_relation_to($datetime, 'Datetime');
728
-            }
729
-            // need to do the same for prices (except these prices can also be deleted because again,
730
-            // tickets can only be trashed if they don't have any TKTs sold (otherwise they are just archived))
731
-            $tkt_to_remove->delete_related_permanently('Price');
732
-            do_action('AHEE__espresso_events_Pricing_Hooks___update_tkts_delete_ticket', $tkt_to_remove);
733
-            // finally let's delete this ticket
734
-            // (which should not be blocked at this point b/c we've removed all our relationships)
735
-            $tkt_to_remove->delete_permanently();
736
-        }
737
-        return $saved_tickets;
738
-    }
425
+	/**
426
+	 * update tickets
427
+	 *
428
+	 * @param  EE_Event      $event           Event object being updated
429
+	 * @param  EE_Datetime[] $saved_datetimes an array of datetime ids being updated
430
+	 * @param  array         $data            incoming request data
431
+	 * @return EE_Ticket[]
432
+	 * @throws Exception
433
+	 * @throws ReflectionException
434
+	 * @throws InvalidInterfaceException
435
+	 * @throws InvalidDataTypeException
436
+	 * @throws InvalidArgumentException
437
+	 * @throws EE_Error
438
+	 */
439
+	protected function _update_tickets($event, $saved_datetimes, $data)
440
+	{
441
+		$new_tkt     = null;
442
+		$new_default = null;
443
+		//stripslashes because WP filtered the $_POST ($data) array to add slashes
444
+		$data          = stripslashes_deep($data);
445
+		$timezone      = isset($data['timezone_string']) ? $data['timezone_string'] : null;
446
+		$saved_tickets = $datetimes_on_existing = array();
447
+		$old_tickets   = isset($data['ticket_IDs']) ? explode(',', $data['ticket_IDs']) : array();
448
+		if (empty($data['edit_tickets']) || ! is_array($data['edit_tickets'])) {
449
+			throw new InvalidArgumentException(
450
+				esc_html__(
451
+					'The "edit_tickets" array is invalid therefore the event can not be updated.',
452
+					'event_espresso'
453
+				)
454
+			);
455
+		}
456
+		foreach ($data['edit_tickets'] as $row => $tkt) {
457
+			$update_prices = $create_new_TKT = false;
458
+			// figure out what datetimes were added to the ticket
459
+			// and what datetimes were removed from the ticket in the session.
460
+			$starting_tkt_dtt_rows = explode(',', $data['starting_ticket_datetime_rows'][ $row ]);
461
+			$tkt_dtt_rows          = explode(',', $data['ticket_datetime_rows'][ $row ]);
462
+			$datetimes_added       = array_diff($tkt_dtt_rows, $starting_tkt_dtt_rows);
463
+			$datetimes_removed     = array_diff($starting_tkt_dtt_rows, $tkt_dtt_rows);
464
+			// trim inputs to ensure any excess whitespace is removed.
465
+			$tkt = array_map(
466
+				function ($ticket_data)
467
+				{
468
+					return is_array($ticket_data) ? $ticket_data : trim($ticket_data);
469
+				},
470
+				$tkt
471
+			);
472
+			// note we are doing conversions to floats here instead of allowing EE_Money_Field to handle
473
+			// because we're doing calculations prior to using the models.
474
+			// note incoming ['TKT_price'] value is already in standard notation (via js).
475
+			$ticket_price = isset($tkt['TKT_price'])
476
+				? round((float) $tkt['TKT_price'], 3)
477
+				: 0;
478
+			//note incoming base price needs converted from localized value.
479
+			$base_price = isset($tkt['TKT_base_price'])
480
+				? EEH_Money::convert_to_float_from_localized_money($tkt['TKT_base_price'])
481
+				: 0;
482
+			//if ticket price == 0 and $base_price != 0 then ticket price == base_price
483
+			$ticket_price  = $ticket_price === 0 && $base_price !== 0
484
+				? $base_price
485
+				: $ticket_price;
486
+			$base_price_id = isset($tkt['TKT_base_price_ID'])
487
+				? $tkt['TKT_base_price_ID']
488
+				: 0;
489
+			$price_rows    = is_array($data['edit_prices']) && isset($data['edit_prices'][ $row ])
490
+				? $data['edit_prices'][ $row ]
491
+				: array();
492
+			$now           = null;
493
+			if (empty($tkt['TKT_start_date'])) {
494
+				//lets' use now in the set timezone.
495
+				$now                   = new DateTime('now', new DateTimeZone($event->get_timezone()));
496
+				$tkt['TKT_start_date'] = $now->format($this->_date_time_format);
497
+			}
498
+			if (empty($tkt['TKT_end_date'])) {
499
+				/**
500
+				 * set the TKT_end_date to the first datetime attached to the ticket.
501
+				 */
502
+				$first_dtt           = $saved_datetimes[ reset($tkt_dtt_rows) ];
503
+				$tkt['TKT_end_date'] = $first_dtt->start_date_and_time($this->_date_time_format);
504
+			}
505
+			$TKT_values = array(
506
+				'TKT_ID'          => ! empty($tkt['TKT_ID']) ? $tkt['TKT_ID'] : null,
507
+				'TTM_ID'          => ! empty($tkt['TTM_ID']) ? $tkt['TTM_ID'] : 0,
508
+				'TKT_name'        => ! empty($tkt['TKT_name']) ? $tkt['TKT_name'] : '',
509
+				'TKT_description' => ! empty($tkt['TKT_description'])
510
+									 && $tkt['TKT_description'] !== esc_html__(
511
+					'You can modify this description',
512
+					'event_espresso'
513
+				)
514
+					? $tkt['TKT_description']
515
+					: '',
516
+				'TKT_start_date'  => $tkt['TKT_start_date'],
517
+				'TKT_end_date'    => $tkt['TKT_end_date'],
518
+				'TKT_qty'         => ! isset($tkt['TKT_qty']) || $tkt['TKT_qty'] === ''
519
+					? EE_INF
520
+					: $tkt['TKT_qty'],
521
+				'TKT_uses'        => ! isset($tkt['TKT_uses']) || $tkt['TKT_uses'] === ''
522
+					? EE_INF
523
+					: $tkt['TKT_uses'],
524
+				'TKT_min'         => empty($tkt['TKT_min']) ? 0 : $tkt['TKT_min'],
525
+				'TKT_max'         => empty($tkt['TKT_max']) ? EE_INF : $tkt['TKT_max'],
526
+				'TKT_row'         => $row,
527
+				'TKT_order'       => isset($tkt['TKT_order']) ? $tkt['TKT_order'] : 0,
528
+				'TKT_taxable'     => ! empty($tkt['TKT_taxable']) ? 1 : 0,
529
+				'TKT_required'    => ! empty($tkt['TKT_required']) ? 1 : 0,
530
+				'TKT_price'       => $ticket_price,
531
+			);
532
+			// if this is a default TKT, then we need to set the TKT_ID to 0 and update accordingly,
533
+			// which means in turn that the prices will become new prices as well.
534
+			if (isset($tkt['TKT_is_default']) && $tkt['TKT_is_default']) {
535
+				$TKT_values['TKT_ID']         = 0;
536
+				$TKT_values['TKT_is_default'] = 0;
537
+				$update_prices                = true;
538
+			}
539
+			// if we have a TKT_ID then we need to get that existing TKT_obj and update it
540
+			// we actually do our saves ahead of doing any add_relations to
541
+			// because its entirely possible that this ticket wasn't removed or added to any datetime in the session
542
+			// but DID have it's items modified.
543
+			// keep in mind that if the TKT has been sold (and we have changed pricing information),
544
+			// then we won't be updating the tkt but instead a new tkt will be created and the old one archived.
545
+			if (absint($TKT_values['TKT_ID'])) {
546
+				$ticket = EE_Registry::instance()
547
+									 ->load_model('Ticket', array($timezone))
548
+									 ->get_one_by_ID($tkt['TKT_ID']);
549
+				if ($ticket instanceof EE_Ticket) {
550
+					$ticket = $this->_update_ticket_datetimes(
551
+						$ticket,
552
+						$saved_datetimes,
553
+						$datetimes_added,
554
+						$datetimes_removed
555
+					);
556
+					// are there any registrations using this ticket ?
557
+					$tickets_sold = $ticket->count_related(
558
+						'Registration',
559
+						array(
560
+							array(
561
+								'STS_ID' => array('NOT IN', array(EEM_Registration::status_id_incomplete)),
562
+							),
563
+						)
564
+					);
565
+					//set ticket formats
566
+					$ticket->set_date_format($this->_date_format_strings['date']);
567
+					$ticket->set_time_format($this->_date_format_strings['time']);
568
+					// let's just check the total price for the existing ticket
569
+					// and determine if it matches the new total price.
570
+					// if they are different then we create a new ticket (if tickets sold)
571
+					// if they aren't different then we go ahead and modify existing ticket.
572
+					$create_new_TKT = $tickets_sold > 0 && $ticket_price !== $ticket->price() && ! $ticket->deleted();
573
+					//set new values
574
+					foreach ($TKT_values as $field => $value) {
575
+						if ($field === 'TKT_qty') {
576
+							$ticket->set_qty($value);
577
+						} else {
578
+							$ticket->set($field, $value);
579
+						}
580
+					}
581
+					// if $create_new_TKT is false then we can safely update the existing ticket.
582
+					// Otherwise we have to create a new ticket.
583
+					if ($create_new_TKT) {
584
+						$new_tkt = $this->_duplicate_ticket(
585
+							$ticket,
586
+							$price_rows,
587
+							$ticket_price,
588
+							$base_price,
589
+							$base_price_id
590
+						);
591
+					}
592
+				}
593
+			} else {
594
+				// no TKT_id so a new TKT
595
+				$ticket = EE_Ticket::new_instance(
596
+					$TKT_values,
597
+					$timezone,
598
+					array($this->_date_format_strings['date'], $this->_date_format_strings['time'])
599
+				);
600
+				if ($ticket instanceof EE_Ticket) {
601
+					// make sure ticket has an ID of setting relations won't work
602
+					$ticket->save();
603
+					$ticket        = $this->_update_ticket_datetimes(
604
+						$ticket,
605
+						$saved_datetimes,
606
+						$datetimes_added,
607
+						$datetimes_removed
608
+					);
609
+					$update_prices = true;
610
+				}
611
+			}
612
+			//make sure any current values have been saved.
613
+			//$ticket->save();
614
+			// before going any further make sure our dates are setup correctly
615
+			// so that the end date is always equal or greater than the start date.
616
+			if ($ticket->get_raw('TKT_start_date') > $ticket->get_raw('TKT_end_date')) {
617
+				$ticket->set('TKT_end_date', $ticket->get('TKT_start_date'));
618
+				$ticket = EEH_DTT_Helper::date_time_add($ticket, 'TKT_end_date', 'days');
619
+			}
620
+			//let's make sure the base price is handled
621
+			$ticket = ! $create_new_TKT
622
+				? $this->_add_prices_to_ticket(
623
+					array(),
624
+					$ticket,
625
+					$update_prices,
626
+					$base_price,
627
+					$base_price_id
628
+				)
629
+				: $ticket;
630
+			//add/update price_modifiers
631
+			$ticket = ! $create_new_TKT
632
+				? $this->_add_prices_to_ticket($price_rows, $ticket, $update_prices)
633
+				: $ticket;
634
+			//need to make sue that the TKT_price is accurate after saving the prices.
635
+			$ticket->ensure_TKT_Price_correct();
636
+			//handle CREATING a default tkt from the incoming tkt but ONLY if this isn't an autosave.
637
+			if (! defined('DOING_AUTOSAVE') && ! empty($tkt['TKT_is_default_selector'])) {
638
+				$update_prices = true;
639
+				$new_default   = clone $ticket;
640
+				$new_default->set('TKT_ID', 0);
641
+				$new_default->set('TKT_is_default', 1);
642
+				$new_default->set('TKT_row', 1);
643
+				$new_default->set('TKT_price', $ticket_price);
644
+				// remove any dtt relations cause we DON'T want dtt relations attached
645
+				// (note this is just removing the cached relations in the object)
646
+				$new_default->_remove_relations('Datetime');
647
+				//todo we need to add the current attached prices as new prices to the new default ticket.
648
+				$new_default = $this->_add_prices_to_ticket(
649
+					$price_rows,
650
+					$new_default,
651
+					$update_prices
652
+				);
653
+				//don't forget the base price!
654
+				$new_default = $this->_add_prices_to_ticket(
655
+					array(),
656
+					$new_default,
657
+					$update_prices,
658
+					$base_price,
659
+					$base_price_id
660
+				);
661
+				$new_default->save();
662
+				do_action(
663
+					'AHEE__espresso_events_Pricing_Hooks___update_tkts_new_default_ticket',
664
+					$new_default,
665
+					$row,
666
+					$ticket,
667
+					$data
668
+				);
669
+			}
670
+			// DO ALL dtt relationships for both current tickets and any archived tickets
671
+			// for the given dtt that are related to the current ticket.
672
+			// TODO... not sure exactly how we're going to do this considering we don't know
673
+			// what current ticket the archived tickets are related to
674
+			// (and TKT_parent is used for autosaves so that's not a field we can reliably use).
675
+			//let's assign any tickets that have been setup to the saved_tickets tracker
676
+			//save existing TKT
677
+			$ticket->save();
678
+			if ($create_new_TKT && $new_tkt instanceof EE_Ticket) {
679
+				//save new TKT
680
+				$new_tkt->save();
681
+				//add new ticket to array
682
+				$saved_tickets[ $new_tkt->ID() ] = $new_tkt;
683
+				do_action(
684
+					'AHEE__espresso_events_Pricing_Hooks___update_tkts_new_ticket',
685
+					$new_tkt,
686
+					$row,
687
+					$tkt,
688
+					$data
689
+				);
690
+			} else {
691
+				//add tkt to saved tkts
692
+				$saved_tickets[ $ticket->ID() ] = $ticket;
693
+				do_action(
694
+					'AHEE__espresso_events_Pricing_Hooks___update_tkts_update_ticket',
695
+					$ticket,
696
+					$row,
697
+					$tkt,
698
+					$data
699
+				);
700
+			}
701
+		}
702
+		// now we need to handle tickets actually "deleted permanently".
703
+		// There are cases where we'd want this to happen
704
+		// (i.e. autosaves are happening and then in between autosaves the user trashes a ticket).
705
+		// Or a draft event was saved and in the process of editing a ticket is trashed.
706
+		// No sense in keeping all the related data in the db!
707
+		$old_tickets     = isset($old_tickets[0]) && $old_tickets[0] === '' ? array() : $old_tickets;
708
+		$tickets_removed = array_diff($old_tickets, array_keys($saved_tickets));
709
+		foreach ($tickets_removed as $id) {
710
+			$id = absint($id);
711
+			//get the ticket for this id
712
+			$tkt_to_remove = EE_Registry::instance()->load_model('Ticket')->get_one_by_ID($id);
713
+			//if this tkt is a default tkt we leave it alone cause it won't be attached to the datetime
714
+			if ($tkt_to_remove->get('TKT_is_default')) {
715
+				continue;
716
+			}
717
+			// if this tkt has any registrations attached so then we just ARCHIVE
718
+			// because we don't actually permanently delete these tickets.
719
+			if ($tkt_to_remove->count_related('Registration') > 0) {
720
+				$tkt_to_remove->delete();
721
+				continue;
722
+			}
723
+			// need to get all the related datetimes on this ticket and remove from every single one of them
724
+			// (remember this process can ONLY kick off if there are NO tkts_sold)
725
+			$datetimes = $tkt_to_remove->get_many_related('Datetime');
726
+			foreach ($datetimes as $datetime) {
727
+				$tkt_to_remove->_remove_relation_to($datetime, 'Datetime');
728
+			}
729
+			// need to do the same for prices (except these prices can also be deleted because again,
730
+			// tickets can only be trashed if they don't have any TKTs sold (otherwise they are just archived))
731
+			$tkt_to_remove->delete_related_permanently('Price');
732
+			do_action('AHEE__espresso_events_Pricing_Hooks___update_tkts_delete_ticket', $tkt_to_remove);
733
+			// finally let's delete this ticket
734
+			// (which should not be blocked at this point b/c we've removed all our relationships)
735
+			$tkt_to_remove->delete_permanently();
736
+		}
737
+		return $saved_tickets;
738
+	}
739 739
 
740 740
 
741
-    /**
742
-     * @access  protected
743
-     * @param EE_Ticket      $ticket
744
-     * @param \EE_Datetime[] $saved_datetimes
745
-     * @param \EE_Datetime[] $added_datetimes
746
-     * @param \EE_Datetime[] $removed_datetimes
747
-     * @return EE_Ticket
748
-     * @throws EE_Error
749
-     */
750
-    protected function _update_ticket_datetimes(
751
-        EE_Ticket $ticket,
752
-        $saved_datetimes = array(),
753
-        $added_datetimes = array(),
754
-        $removed_datetimes = array()
755
-    ) {
756
-        // to start we have to add the ticket to all the datetimes its supposed to be with,
757
-        // and removing the ticket from datetimes it got removed from.
758
-        // first let's add datetimes
759
-        if (! empty($added_datetimes) && is_array($added_datetimes)) {
760
-            foreach ($added_datetimes as $row_id) {
761
-                $row_id = (int) $row_id;
762
-                if (isset($saved_datetimes[ $row_id ]) && $saved_datetimes[ $row_id ] instanceof EE_Datetime) {
763
-                    $ticket->_add_relation_to($saved_datetimes[ $row_id ], 'Datetime');
764
-                    // Is this an existing ticket (has an ID) and does it have any sold?
765
-                    // If so, then we need to add that to the DTT sold because this DTT is getting added.
766
-                    if ($ticket->ID() && $ticket->sold() > 0) {
767
-                        $saved_datetimes[ $row_id ]->increase_sold($ticket->sold());
768
-                        $saved_datetimes[ $row_id ]->save();
769
-                    }
770
-                }
771
-            }
772
-        }
773
-        // then remove datetimes
774
-        if (! empty($removed_datetimes) && is_array($removed_datetimes)) {
775
-            foreach ($removed_datetimes as $row_id) {
776
-                $row_id = (int) $row_id;
777
-                // its entirely possible that a datetime got deleted (instead of just removed from relationship.
778
-                // So make sure we skip over this if the dtt isn't in the $saved_datetimes array)
779
-                if (isset($saved_datetimes[ $row_id ]) && $saved_datetimes[ $row_id ] instanceof EE_Datetime) {
780
-                    $ticket->_remove_relation_to($saved_datetimes[ $row_id ], 'Datetime');
781
-                    // Is this an existing ticket (has an ID) and does it have any sold?
782
-                    // If so, then we need to remove it's sold from the DTT_sold.
783
-                    if ($ticket->ID() && $ticket->sold() > 0) {
784
-                        $saved_datetimes[ $row_id ]->decrease_sold($ticket->sold());
785
-                        $saved_datetimes[ $row_id ]->save();
786
-                    }
787
-                }
788
-            }
789
-        }
790
-        // cap ticket qty by datetime reg limits
791
-        $ticket->set_qty(min($ticket->qty(), $ticket->qty('reg_limit')));
792
-        return $ticket;
793
-    }
741
+	/**
742
+	 * @access  protected
743
+	 * @param EE_Ticket      $ticket
744
+	 * @param \EE_Datetime[] $saved_datetimes
745
+	 * @param \EE_Datetime[] $added_datetimes
746
+	 * @param \EE_Datetime[] $removed_datetimes
747
+	 * @return EE_Ticket
748
+	 * @throws EE_Error
749
+	 */
750
+	protected function _update_ticket_datetimes(
751
+		EE_Ticket $ticket,
752
+		$saved_datetimes = array(),
753
+		$added_datetimes = array(),
754
+		$removed_datetimes = array()
755
+	) {
756
+		// to start we have to add the ticket to all the datetimes its supposed to be with,
757
+		// and removing the ticket from datetimes it got removed from.
758
+		// first let's add datetimes
759
+		if (! empty($added_datetimes) && is_array($added_datetimes)) {
760
+			foreach ($added_datetimes as $row_id) {
761
+				$row_id = (int) $row_id;
762
+				if (isset($saved_datetimes[ $row_id ]) && $saved_datetimes[ $row_id ] instanceof EE_Datetime) {
763
+					$ticket->_add_relation_to($saved_datetimes[ $row_id ], 'Datetime');
764
+					// Is this an existing ticket (has an ID) and does it have any sold?
765
+					// If so, then we need to add that to the DTT sold because this DTT is getting added.
766
+					if ($ticket->ID() && $ticket->sold() > 0) {
767
+						$saved_datetimes[ $row_id ]->increase_sold($ticket->sold());
768
+						$saved_datetimes[ $row_id ]->save();
769
+					}
770
+				}
771
+			}
772
+		}
773
+		// then remove datetimes
774
+		if (! empty($removed_datetimes) && is_array($removed_datetimes)) {
775
+			foreach ($removed_datetimes as $row_id) {
776
+				$row_id = (int) $row_id;
777
+				// its entirely possible that a datetime got deleted (instead of just removed from relationship.
778
+				// So make sure we skip over this if the dtt isn't in the $saved_datetimes array)
779
+				if (isset($saved_datetimes[ $row_id ]) && $saved_datetimes[ $row_id ] instanceof EE_Datetime) {
780
+					$ticket->_remove_relation_to($saved_datetimes[ $row_id ], 'Datetime');
781
+					// Is this an existing ticket (has an ID) and does it have any sold?
782
+					// If so, then we need to remove it's sold from the DTT_sold.
783
+					if ($ticket->ID() && $ticket->sold() > 0) {
784
+						$saved_datetimes[ $row_id ]->decrease_sold($ticket->sold());
785
+						$saved_datetimes[ $row_id ]->save();
786
+					}
787
+				}
788
+			}
789
+		}
790
+		// cap ticket qty by datetime reg limits
791
+		$ticket->set_qty(min($ticket->qty(), $ticket->qty('reg_limit')));
792
+		return $ticket;
793
+	}
794 794
 
795 795
 
796
-    /**
797
-     * @access  protected
798
-     * @param EE_Ticket $ticket
799
-     * @param array     $price_rows
800
-     * @param int       $ticket_price
801
-     * @param int       $base_price
802
-     * @param int       $base_price_id
803
-     * @return EE_Ticket
804
-     * @throws ReflectionException
805
-     * @throws InvalidArgumentException
806
-     * @throws InvalidInterfaceException
807
-     * @throws InvalidDataTypeException
808
-     * @throws EE_Error
809
-     */
810
-    protected function _duplicate_ticket(
811
-        EE_Ticket $ticket,
812
-        $price_rows = array(),
813
-        $ticket_price = 0,
814
-        $base_price = 0,
815
-        $base_price_id = 0
816
-    ) {
817
-        // create new ticket that's a copy of the existing
818
-        // except a new id of course (and not archived)
819
-        // AND has the new TKT_price associated with it.
820
-        $new_ticket = clone $ticket;
821
-        $new_ticket->set('TKT_ID', 0);
822
-        $new_ticket->set_deleted(0);
823
-        $new_ticket->set_price($ticket_price);
824
-        $new_ticket->set_sold(0);
825
-        // let's get a new ID for this ticket
826
-        $new_ticket->save();
827
-        // we also need to make sure this new ticket gets the same datetime attachments as the archived ticket
828
-        $datetimes_on_existing = $ticket->datetimes();
829
-        $new_ticket            = $this->_update_ticket_datetimes(
830
-            $new_ticket,
831
-            $datetimes_on_existing,
832
-            array_keys($datetimes_on_existing)
833
-        );
834
-        // $ticket will get archived later b/c we are NOT adding it to the saved_tickets array.
835
-        // if existing $ticket has sold amount, then we need to adjust the qty for the new TKT to = the remaining
836
-        // available.
837
-        if ($ticket->sold() > 0) {
838
-            $new_qty = $ticket->qty() - $ticket->sold();
839
-            $new_ticket->set_qty($new_qty);
840
-        }
841
-        //now we update the prices just for this ticket
842
-        $new_ticket = $this->_add_prices_to_ticket($price_rows, $new_ticket, true);
843
-        //and we update the base price
844
-        $new_ticket = $this->_add_prices_to_ticket(
845
-            array(),
846
-            $new_ticket,
847
-            true,
848
-            $base_price,
849
-            $base_price_id
850
-        );
851
-        return $new_ticket;
852
-    }
796
+	/**
797
+	 * @access  protected
798
+	 * @param EE_Ticket $ticket
799
+	 * @param array     $price_rows
800
+	 * @param int       $ticket_price
801
+	 * @param int       $base_price
802
+	 * @param int       $base_price_id
803
+	 * @return EE_Ticket
804
+	 * @throws ReflectionException
805
+	 * @throws InvalidArgumentException
806
+	 * @throws InvalidInterfaceException
807
+	 * @throws InvalidDataTypeException
808
+	 * @throws EE_Error
809
+	 */
810
+	protected function _duplicate_ticket(
811
+		EE_Ticket $ticket,
812
+		$price_rows = array(),
813
+		$ticket_price = 0,
814
+		$base_price = 0,
815
+		$base_price_id = 0
816
+	) {
817
+		// create new ticket that's a copy of the existing
818
+		// except a new id of course (and not archived)
819
+		// AND has the new TKT_price associated with it.
820
+		$new_ticket = clone $ticket;
821
+		$new_ticket->set('TKT_ID', 0);
822
+		$new_ticket->set_deleted(0);
823
+		$new_ticket->set_price($ticket_price);
824
+		$new_ticket->set_sold(0);
825
+		// let's get a new ID for this ticket
826
+		$new_ticket->save();
827
+		// we also need to make sure this new ticket gets the same datetime attachments as the archived ticket
828
+		$datetimes_on_existing = $ticket->datetimes();
829
+		$new_ticket            = $this->_update_ticket_datetimes(
830
+			$new_ticket,
831
+			$datetimes_on_existing,
832
+			array_keys($datetimes_on_existing)
833
+		);
834
+		// $ticket will get archived later b/c we are NOT adding it to the saved_tickets array.
835
+		// if existing $ticket has sold amount, then we need to adjust the qty for the new TKT to = the remaining
836
+		// available.
837
+		if ($ticket->sold() > 0) {
838
+			$new_qty = $ticket->qty() - $ticket->sold();
839
+			$new_ticket->set_qty($new_qty);
840
+		}
841
+		//now we update the prices just for this ticket
842
+		$new_ticket = $this->_add_prices_to_ticket($price_rows, $new_ticket, true);
843
+		//and we update the base price
844
+		$new_ticket = $this->_add_prices_to_ticket(
845
+			array(),
846
+			$new_ticket,
847
+			true,
848
+			$base_price,
849
+			$base_price_id
850
+		);
851
+		return $new_ticket;
852
+	}
853 853
 
854 854
 
855
-    /**
856
-     * This attaches a list of given prices to a ticket.
857
-     * Note we dont' have to worry about ever removing relationships (or archiving prices) because if there is a change
858
-     * in price information on a ticket, a new ticket is created anyways so the archived ticket will retain the old
859
-     * price info and prices are automatically "archived" via the ticket.
860
-     *
861
-     * @access  private
862
-     * @param array     $prices        Array of prices from the form.
863
-     * @param EE_Ticket $ticket        EE_Ticket object that prices are being attached to.
864
-     * @param bool      $new_prices    Whether attach existing incoming prices or create new ones.
865
-     * @param int|bool  $base_price    if FALSE then NOT doing a base price add.
866
-     * @param int|bool  $base_price_id if present then this is the base_price_id being updated.
867
-     * @return EE_Ticket
868
-     * @throws ReflectionException
869
-     * @throws InvalidArgumentException
870
-     * @throws InvalidInterfaceException
871
-     * @throws InvalidDataTypeException
872
-     * @throws EE_Error
873
-     */
874
-    protected function _add_prices_to_ticket(
875
-        $prices = array(),
876
-        EE_Ticket $ticket,
877
-        $new_prices = false,
878
-        $base_price = false,
879
-        $base_price_id = false
880
-    ) {
881
-        // let's just get any current prices that may exist on the given ticket
882
-        // so we can remove any prices that got trashed in this session.
883
-        $current_prices_on_ticket = $base_price !== false
884
-            ? $ticket->base_price(true)
885
-            : $ticket->price_modifiers();
886
-        $updated_prices           = array();
887
-        // if $base_price ! FALSE then updating a base price.
888
-        if ($base_price !== false) {
889
-            $prices[1] = array(
890
-                'PRC_ID'     => $new_prices || $base_price_id === 1 ? null : $base_price_id,
891
-                'PRT_ID'     => 1,
892
-                'PRC_amount' => $base_price,
893
-                'PRC_name'   => $ticket->get('TKT_name'),
894
-                'PRC_desc'   => $ticket->get('TKT_description'),
895
-            );
896
-        }
897
-        //possibly need to save tkt
898
-        if (! $ticket->ID()) {
899
-            $ticket->save();
900
-        }
901
-        foreach ($prices as $row => $prc) {
902
-            $prt_id = ! empty($prc['PRT_ID']) ? $prc['PRT_ID'] : null;
903
-            if (empty($prt_id)) {
904
-                continue;
905
-            } //prices MUST have a price type id.
906
-            $PRC_values = array(
907
-                'PRC_ID'         => ! empty($prc['PRC_ID']) ? $prc['PRC_ID'] : null,
908
-                'PRT_ID'         => $prt_id,
909
-                'PRC_amount'     => ! empty($prc['PRC_amount']) ? $prc['PRC_amount'] : 0,
910
-                'PRC_name'       => ! empty($prc['PRC_name']) ? $prc['PRC_name'] : '',
911
-                'PRC_desc'       => ! empty($prc['PRC_desc']) ? $prc['PRC_desc'] : '',
912
-                'PRC_is_default' => false,
913
-                //make sure we set PRC_is_default to false for all ticket saves from event_editor
914
-                'PRC_order'      => $row,
915
-            );
916
-            if ($new_prices || empty($PRC_values['PRC_ID'])) {
917
-                $PRC_values['PRC_ID'] = 0;
918
-                $price                = EE_Registry::instance()->load_class(
919
-                    'Price',
920
-                    array($PRC_values),
921
-                    false,
922
-                    false
923
-                );
924
-            } else {
925
-                $price = EE_Registry::instance()->load_model('Price')->get_one_by_ID($prc['PRC_ID']);
926
-                //update this price with new values
927
-                foreach ($PRC_values as $field => $value) {
928
-                    $price->set($field, $value);
929
-                }
930
-            }
931
-            $price->save();
932
-            $updated_prices[ $price->ID() ] = $price;
933
-            $ticket->_add_relation_to($price, 'Price');
934
-        }
935
-        //now let's remove any prices that got removed from the ticket
936
-        if (! empty ($current_prices_on_ticket)) {
937
-            $current          = array_keys($current_prices_on_ticket);
938
-            $updated          = array_keys($updated_prices);
939
-            $prices_to_remove = array_diff($current, $updated);
940
-            if (! empty($prices_to_remove)) {
941
-                foreach ($prices_to_remove as $prc_id) {
942
-                    $p = $current_prices_on_ticket[ $prc_id ];
943
-                    $ticket->_remove_relation_to($p, 'Price');
944
-                    //delete permanently the price
945
-                    $p->delete_permanently();
946
-                }
947
-            }
948
-        }
949
-        return $ticket;
950
-    }
855
+	/**
856
+	 * This attaches a list of given prices to a ticket.
857
+	 * Note we dont' have to worry about ever removing relationships (or archiving prices) because if there is a change
858
+	 * in price information on a ticket, a new ticket is created anyways so the archived ticket will retain the old
859
+	 * price info and prices are automatically "archived" via the ticket.
860
+	 *
861
+	 * @access  private
862
+	 * @param array     $prices        Array of prices from the form.
863
+	 * @param EE_Ticket $ticket        EE_Ticket object that prices are being attached to.
864
+	 * @param bool      $new_prices    Whether attach existing incoming prices or create new ones.
865
+	 * @param int|bool  $base_price    if FALSE then NOT doing a base price add.
866
+	 * @param int|bool  $base_price_id if present then this is the base_price_id being updated.
867
+	 * @return EE_Ticket
868
+	 * @throws ReflectionException
869
+	 * @throws InvalidArgumentException
870
+	 * @throws InvalidInterfaceException
871
+	 * @throws InvalidDataTypeException
872
+	 * @throws EE_Error
873
+	 */
874
+	protected function _add_prices_to_ticket(
875
+		$prices = array(),
876
+		EE_Ticket $ticket,
877
+		$new_prices = false,
878
+		$base_price = false,
879
+		$base_price_id = false
880
+	) {
881
+		// let's just get any current prices that may exist on the given ticket
882
+		// so we can remove any prices that got trashed in this session.
883
+		$current_prices_on_ticket = $base_price !== false
884
+			? $ticket->base_price(true)
885
+			: $ticket->price_modifiers();
886
+		$updated_prices           = array();
887
+		// if $base_price ! FALSE then updating a base price.
888
+		if ($base_price !== false) {
889
+			$prices[1] = array(
890
+				'PRC_ID'     => $new_prices || $base_price_id === 1 ? null : $base_price_id,
891
+				'PRT_ID'     => 1,
892
+				'PRC_amount' => $base_price,
893
+				'PRC_name'   => $ticket->get('TKT_name'),
894
+				'PRC_desc'   => $ticket->get('TKT_description'),
895
+			);
896
+		}
897
+		//possibly need to save tkt
898
+		if (! $ticket->ID()) {
899
+			$ticket->save();
900
+		}
901
+		foreach ($prices as $row => $prc) {
902
+			$prt_id = ! empty($prc['PRT_ID']) ? $prc['PRT_ID'] : null;
903
+			if (empty($prt_id)) {
904
+				continue;
905
+			} //prices MUST have a price type id.
906
+			$PRC_values = array(
907
+				'PRC_ID'         => ! empty($prc['PRC_ID']) ? $prc['PRC_ID'] : null,
908
+				'PRT_ID'         => $prt_id,
909
+				'PRC_amount'     => ! empty($prc['PRC_amount']) ? $prc['PRC_amount'] : 0,
910
+				'PRC_name'       => ! empty($prc['PRC_name']) ? $prc['PRC_name'] : '',
911
+				'PRC_desc'       => ! empty($prc['PRC_desc']) ? $prc['PRC_desc'] : '',
912
+				'PRC_is_default' => false,
913
+				//make sure we set PRC_is_default to false for all ticket saves from event_editor
914
+				'PRC_order'      => $row,
915
+			);
916
+			if ($new_prices || empty($PRC_values['PRC_ID'])) {
917
+				$PRC_values['PRC_ID'] = 0;
918
+				$price                = EE_Registry::instance()->load_class(
919
+					'Price',
920
+					array($PRC_values),
921
+					false,
922
+					false
923
+				);
924
+			} else {
925
+				$price = EE_Registry::instance()->load_model('Price')->get_one_by_ID($prc['PRC_ID']);
926
+				//update this price with new values
927
+				foreach ($PRC_values as $field => $value) {
928
+					$price->set($field, $value);
929
+				}
930
+			}
931
+			$price->save();
932
+			$updated_prices[ $price->ID() ] = $price;
933
+			$ticket->_add_relation_to($price, 'Price');
934
+		}
935
+		//now let's remove any prices that got removed from the ticket
936
+		if (! empty ($current_prices_on_ticket)) {
937
+			$current          = array_keys($current_prices_on_ticket);
938
+			$updated          = array_keys($updated_prices);
939
+			$prices_to_remove = array_diff($current, $updated);
940
+			if (! empty($prices_to_remove)) {
941
+				foreach ($prices_to_remove as $prc_id) {
942
+					$p = $current_prices_on_ticket[ $prc_id ];
943
+					$ticket->_remove_relation_to($p, 'Price');
944
+					//delete permanently the price
945
+					$p->delete_permanently();
946
+				}
947
+			}
948
+		}
949
+		return $ticket;
950
+	}
951 951
 
952 952
 
953
-    /**
954
-     * @param Events_Admin_Page $event_admin_obj
955
-     * @return Events_Admin_Page
956
-     */
957
-    public function autosave_handling(Events_Admin_Page $event_admin_obj)
958
-    {
959
-        return $event_admin_obj;
960
-        //doing nothing for the moment.
961
-        // todo when I get to this remember that I need to set the template args on the $event_admin_obj
962
-        // (use the set_template_args() method)
963
-        /**
964
-         * need to remember to handle TICKET DEFAULT saves correctly:  I've got two input fields in the dom:
965
-         * 1. TKT_is_default_selector (visible)
966
-         * 2. TKT_is_default (hidden)
967
-         * I think we'll use the TKT_is_default for recording whether the ticket displayed IS a default ticket
968
-         * (on new event creations). Whereas the TKT_is_default_selector is for the user to indicate they want
969
-         * this ticket to be saved as a default.
970
-         * The tricky part is, on an initial display on create or edit (or after manually updating),
971
-         * the TKT_is_default_selector will always be unselected and the TKT_is_default will only be true
972
-         * if this is a create.  However, after an autosave, users will want some sort of indicator that
973
-         * the TKT HAS been saved as a default..
974
-         * in other words we don't want to remove the check on TKT_is_default_selector. So here's what I'm thinking.
975
-         * On Autosave:
976
-         * 1. If TKT_is_default is true: we create a new TKT, send back the new id and add id to related elements,
977
-         * then set the TKT_is_default to false.
978
-         * 2. If TKT_is_default_selector is true: we create/edit existing ticket (following conditions above as well).
979
-         *  We do NOT create a new default ticket.  The checkbox stays selected after autosave.
980
-         * 3. only on MANUAL update do we check for the selection and if selected create the new default ticket.
981
-         */
982
-    }
953
+	/**
954
+	 * @param Events_Admin_Page $event_admin_obj
955
+	 * @return Events_Admin_Page
956
+	 */
957
+	public function autosave_handling(Events_Admin_Page $event_admin_obj)
958
+	{
959
+		return $event_admin_obj;
960
+		//doing nothing for the moment.
961
+		// todo when I get to this remember that I need to set the template args on the $event_admin_obj
962
+		// (use the set_template_args() method)
963
+		/**
964
+		 * need to remember to handle TICKET DEFAULT saves correctly:  I've got two input fields in the dom:
965
+		 * 1. TKT_is_default_selector (visible)
966
+		 * 2. TKT_is_default (hidden)
967
+		 * I think we'll use the TKT_is_default for recording whether the ticket displayed IS a default ticket
968
+		 * (on new event creations). Whereas the TKT_is_default_selector is for the user to indicate they want
969
+		 * this ticket to be saved as a default.
970
+		 * The tricky part is, on an initial display on create or edit (or after manually updating),
971
+		 * the TKT_is_default_selector will always be unselected and the TKT_is_default will only be true
972
+		 * if this is a create.  However, after an autosave, users will want some sort of indicator that
973
+		 * the TKT HAS been saved as a default..
974
+		 * in other words we don't want to remove the check on TKT_is_default_selector. So here's what I'm thinking.
975
+		 * On Autosave:
976
+		 * 1. If TKT_is_default is true: we create a new TKT, send back the new id and add id to related elements,
977
+		 * then set the TKT_is_default to false.
978
+		 * 2. If TKT_is_default_selector is true: we create/edit existing ticket (following conditions above as well).
979
+		 *  We do NOT create a new default ticket.  The checkbox stays selected after autosave.
980
+		 * 3. only on MANUAL update do we check for the selection and if selected create the new default ticket.
981
+		 */
982
+	}
983 983
 
984 984
 
985
-    /**
986
-     * @throws ReflectionException
987
-     * @throws InvalidArgumentException
988
-     * @throws InvalidInterfaceException
989
-     * @throws InvalidDataTypeException
990
-     * @throws DomainException
991
-     * @throws EE_Error
992
-     */
993
-    public function pricing_metabox()
994
-    {
995
-        $existing_datetime_ids = $existing_ticket_ids = $datetime_tickets = $ticket_datetimes = array();
996
-        $event                 = $this->_adminpage_obj->get_cpt_model_obj();
997
-        //set is_creating_event property.
998
-        $EVT_ID                   = $event->ID();
999
-        $this->_is_creating_event = empty($this->_req_data['post']);
1000
-        //default main template args
1001
-        $main_template_args = array(
1002
-            'event_datetime_help_link' => EEH_Template::get_help_tab_link(
1003
-                'event_editor_event_datetimes_help_tab',
1004
-                $this->_adminpage_obj->page_slug,
1005
-                $this->_adminpage_obj->get_req_action(),
1006
-                false,
1007
-                false
1008
-            ),
1009
-            // todo need to add a filter to the template for the help text
1010
-            // in the Events_Admin_Page core file so we can add further help
1011
-            'existing_datetime_ids'    => '',
1012
-            'total_dtt_rows'           => 1,
1013
-            'add_new_dtt_help_link'    => EEH_Template::get_help_tab_link(
1014
-                'add_new_dtt_info',
1015
-                $this->_adminpage_obj->page_slug,
1016
-                $this->_adminpage_obj->get_req_action(),
1017
-                false,
1018
-                false
1019
-            ),
1020
-            //todo need to add this help info id to the Events_Admin_Page core file so we can access it here.
1021
-            'datetime_rows'            => '',
1022
-            'show_tickets_container'   => '',
1023
-            //$this->_adminpage_obj->get_cpt_model_obj()->ID() > 1 ? ' style="display:none;"' : '',
1024
-            'ticket_rows'              => '',
1025
-            'existing_ticket_ids'      => '',
1026
-            'total_ticket_rows'        => 1,
1027
-            'ticket_js_structure'      => '',
1028
-            'ee_collapsible_status'    => ' ee-collapsible-open'
1029
-            //$this->_adminpage_obj->get_cpt_model_obj()->ID() > 0 ? ' ee-collapsible-closed' : ' ee-collapsible-open'
1030
-        );
1031
-        $timezone           = $event instanceof EE_Event ? $event->timezone_string() : null;
1032
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1033
-        /**
1034
-         * 1. Start with retrieving Datetimes
1035
-         * 2. For each datetime get related tickets
1036
-         * 3. For each ticket get related prices
1037
-         */
1038
-        /** @var EEM_Datetime $datetime_model */
1039
-        $datetime_model                       = EE_Registry::instance()->load_model('Datetime', array($timezone));
1040
-        $datetimes                            = $datetime_model->get_all_event_dates($EVT_ID);
1041
-        $main_template_args['total_dtt_rows'] = count($datetimes);
1042
-        /**
1043
-         * @see https://events.codebasehq.com/projects/event-espresso/tickets/9486
1044
-         * for why we are counting $datetime_row and then setting that on the Datetime object
1045
-         */
1046
-        $datetime_row = 1;
1047
-        foreach ($datetimes as $datetime) {
1048
-            $DTT_ID = $datetime->get('DTT_ID');
1049
-            $datetime->set('DTT_order', $datetime_row);
1050
-            $existing_datetime_ids[] = $DTT_ID;
1051
-            //tickets attached
1052
-            $related_tickets = $datetime->ID() > 0
1053
-                ? $datetime->get_many_related(
1054
-                    'Ticket',
1055
-                    array(
1056
-                        array(
1057
-                            'OR' => array('TKT_deleted' => 1, 'TKT_deleted*' => 0),
1058
-                        ),
1059
-                        'default_where_conditions' => 'none',
1060
-                        'order_by'                 => array('TKT_order' => 'ASC'),
1061
-                    )
1062
-                )
1063
-                : array();
1064
-            //if there are no related tickets this is likely a new event OR autodraft
1065
-            // event so we need to generate the default tickets because datetimes
1066
-            // ALWAYS have at least one related ticket!!.  EXCEPT, we dont' do this if there is already more than one
1067
-            // datetime on the event.
1068
-            if (empty ($related_tickets) && count($datetimes) < 2) {
1069
-                /** @var EEM_Ticket $ticket_model */
1070
-                $ticket_model    = EE_Registry::instance()->load_model('Ticket');
1071
-                $related_tickets = $ticket_model->get_all_default_tickets();
1072
-                // this should be ordered by TKT_ID, so let's grab the first default ticket
1073
-                // (which will be the main default) and ensure it has any default prices added to it (but do NOT save).
1074
-                $default_prices      = EEM_Price::instance()->get_all_default_prices();
1075
-                $main_default_ticket = reset($related_tickets);
1076
-                if ($main_default_ticket instanceof EE_Ticket) {
1077
-                    foreach ($default_prices as $default_price) {
1078
-                        if ($default_price instanceof EE_Price && $default_price->is_base_price()) {
1079
-                            continue;
1080
-                        }
1081
-                        $main_default_ticket->cache('Price', $default_price);
1082
-                    }
1083
-                }
1084
-            }
1085
-            // we can't actually setup rows in this loop yet cause we don't know all
1086
-            // the unique tickets for this event yet (tickets are linked through all datetimes).
1087
-            // So we're going to temporarily cache some of that information.
1088
-            //loop through and setup the ticket rows and make sure the order is set.
1089
-            foreach ($related_tickets as $ticket) {
1090
-                $TKT_ID     = $ticket->get('TKT_ID');
1091
-                $ticket_row = $ticket->get('TKT_row');
1092
-                //we only want unique tickets in our final display!!
1093
-                if (! in_array($TKT_ID, $existing_ticket_ids, true)) {
1094
-                    $existing_ticket_ids[] = $TKT_ID;
1095
-                    $all_tickets[]         = $ticket;
1096
-                }
1097
-                //temporary cache of this ticket info for this datetime for later processing of datetime rows.
1098
-                $datetime_tickets[ $DTT_ID ][] = $ticket_row;
1099
-                //temporary cache of this datetime info for this ticket for later processing of ticket rows.
1100
-                if (
1101
-                    ! isset($ticket_datetimes[ $TKT_ID ])
1102
-                    || ! in_array($datetime_row, $ticket_datetimes[ $TKT_ID ], true)
1103
-                ) {
1104
-                    $ticket_datetimes[ $TKT_ID ][] = $datetime_row;
1105
-                }
1106
-            }
1107
-            $datetime_row++;
1108
-        }
1109
-        $main_template_args['total_ticket_rows']     = count($existing_ticket_ids);
1110
-        $main_template_args['existing_ticket_ids']   = implode(',', $existing_ticket_ids);
1111
-        $main_template_args['existing_datetime_ids'] = implode(',', $existing_datetime_ids);
1112
-        //sort $all_tickets by order
1113
-        usort(
1114
-            $all_tickets,
1115
-            function (EE_Ticket $a, EE_Ticket $b)
1116
-            {
1117
-                $a_order = (int) $a->get('TKT_order');
1118
-                $b_order = (int) $b->get('TKT_order');
1119
-                if ($a_order === $b_order) {
1120
-                    return 0;
1121
-                }
1122
-                return ($a_order < $b_order) ? -1 : 1;
1123
-            }
1124
-        );
1125
-        // k NOW we have all the data we need for setting up the dtt rows
1126
-        // and ticket rows so we start our dtt loop again.
1127
-        $datetime_row = 1;
1128
-        foreach ($datetimes as $datetime) {
1129
-            $main_template_args['datetime_rows'] .= $this->_get_datetime_row(
1130
-                $datetime_row,
1131
-                $datetime,
1132
-                $datetime_tickets,
1133
-                $all_tickets,
1134
-                false,
1135
-                $datetimes
1136
-            );
1137
-            $datetime_row++;
1138
-        }
1139
-        //then loop through all tickets for the ticket rows.
1140
-        $ticket_row = 1;
1141
-        foreach ($all_tickets as $ticket) {
1142
-            $main_template_args['ticket_rows'] .= $this->_get_ticket_row(
1143
-                $ticket_row,
1144
-                $ticket,
1145
-                $ticket_datetimes,
1146
-                $datetimes,
1147
-                false,
1148
-                $all_tickets
1149
-            );
1150
-            $ticket_row++;
1151
-        }
1152
-        $main_template_args['ticket_js_structure'] = $this->_get_ticket_js_structure($datetimes, $all_tickets);
1153
-        EEH_Template::display_template(
1154
-            PRICING_TEMPLATE_PATH . 'event_tickets_metabox_main.template.php',
1155
-            $main_template_args
1156
-        );
1157
-    }
985
+	/**
986
+	 * @throws ReflectionException
987
+	 * @throws InvalidArgumentException
988
+	 * @throws InvalidInterfaceException
989
+	 * @throws InvalidDataTypeException
990
+	 * @throws DomainException
991
+	 * @throws EE_Error
992
+	 */
993
+	public function pricing_metabox()
994
+	{
995
+		$existing_datetime_ids = $existing_ticket_ids = $datetime_tickets = $ticket_datetimes = array();
996
+		$event                 = $this->_adminpage_obj->get_cpt_model_obj();
997
+		//set is_creating_event property.
998
+		$EVT_ID                   = $event->ID();
999
+		$this->_is_creating_event = empty($this->_req_data['post']);
1000
+		//default main template args
1001
+		$main_template_args = array(
1002
+			'event_datetime_help_link' => EEH_Template::get_help_tab_link(
1003
+				'event_editor_event_datetimes_help_tab',
1004
+				$this->_adminpage_obj->page_slug,
1005
+				$this->_adminpage_obj->get_req_action(),
1006
+				false,
1007
+				false
1008
+			),
1009
+			// todo need to add a filter to the template for the help text
1010
+			// in the Events_Admin_Page core file so we can add further help
1011
+			'existing_datetime_ids'    => '',
1012
+			'total_dtt_rows'           => 1,
1013
+			'add_new_dtt_help_link'    => EEH_Template::get_help_tab_link(
1014
+				'add_new_dtt_info',
1015
+				$this->_adminpage_obj->page_slug,
1016
+				$this->_adminpage_obj->get_req_action(),
1017
+				false,
1018
+				false
1019
+			),
1020
+			//todo need to add this help info id to the Events_Admin_Page core file so we can access it here.
1021
+			'datetime_rows'            => '',
1022
+			'show_tickets_container'   => '',
1023
+			//$this->_adminpage_obj->get_cpt_model_obj()->ID() > 1 ? ' style="display:none;"' : '',
1024
+			'ticket_rows'              => '',
1025
+			'existing_ticket_ids'      => '',
1026
+			'total_ticket_rows'        => 1,
1027
+			'ticket_js_structure'      => '',
1028
+			'ee_collapsible_status'    => ' ee-collapsible-open'
1029
+			//$this->_adminpage_obj->get_cpt_model_obj()->ID() > 0 ? ' ee-collapsible-closed' : ' ee-collapsible-open'
1030
+		);
1031
+		$timezone           = $event instanceof EE_Event ? $event->timezone_string() : null;
1032
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1033
+		/**
1034
+		 * 1. Start with retrieving Datetimes
1035
+		 * 2. For each datetime get related tickets
1036
+		 * 3. For each ticket get related prices
1037
+		 */
1038
+		/** @var EEM_Datetime $datetime_model */
1039
+		$datetime_model                       = EE_Registry::instance()->load_model('Datetime', array($timezone));
1040
+		$datetimes                            = $datetime_model->get_all_event_dates($EVT_ID);
1041
+		$main_template_args['total_dtt_rows'] = count($datetimes);
1042
+		/**
1043
+		 * @see https://events.codebasehq.com/projects/event-espresso/tickets/9486
1044
+		 * for why we are counting $datetime_row and then setting that on the Datetime object
1045
+		 */
1046
+		$datetime_row = 1;
1047
+		foreach ($datetimes as $datetime) {
1048
+			$DTT_ID = $datetime->get('DTT_ID');
1049
+			$datetime->set('DTT_order', $datetime_row);
1050
+			$existing_datetime_ids[] = $DTT_ID;
1051
+			//tickets attached
1052
+			$related_tickets = $datetime->ID() > 0
1053
+				? $datetime->get_many_related(
1054
+					'Ticket',
1055
+					array(
1056
+						array(
1057
+							'OR' => array('TKT_deleted' => 1, 'TKT_deleted*' => 0),
1058
+						),
1059
+						'default_where_conditions' => 'none',
1060
+						'order_by'                 => array('TKT_order' => 'ASC'),
1061
+					)
1062
+				)
1063
+				: array();
1064
+			//if there are no related tickets this is likely a new event OR autodraft
1065
+			// event so we need to generate the default tickets because datetimes
1066
+			// ALWAYS have at least one related ticket!!.  EXCEPT, we dont' do this if there is already more than one
1067
+			// datetime on the event.
1068
+			if (empty ($related_tickets) && count($datetimes) < 2) {
1069
+				/** @var EEM_Ticket $ticket_model */
1070
+				$ticket_model    = EE_Registry::instance()->load_model('Ticket');
1071
+				$related_tickets = $ticket_model->get_all_default_tickets();
1072
+				// this should be ordered by TKT_ID, so let's grab the first default ticket
1073
+				// (which will be the main default) and ensure it has any default prices added to it (but do NOT save).
1074
+				$default_prices      = EEM_Price::instance()->get_all_default_prices();
1075
+				$main_default_ticket = reset($related_tickets);
1076
+				if ($main_default_ticket instanceof EE_Ticket) {
1077
+					foreach ($default_prices as $default_price) {
1078
+						if ($default_price instanceof EE_Price && $default_price->is_base_price()) {
1079
+							continue;
1080
+						}
1081
+						$main_default_ticket->cache('Price', $default_price);
1082
+					}
1083
+				}
1084
+			}
1085
+			// we can't actually setup rows in this loop yet cause we don't know all
1086
+			// the unique tickets for this event yet (tickets are linked through all datetimes).
1087
+			// So we're going to temporarily cache some of that information.
1088
+			//loop through and setup the ticket rows and make sure the order is set.
1089
+			foreach ($related_tickets as $ticket) {
1090
+				$TKT_ID     = $ticket->get('TKT_ID');
1091
+				$ticket_row = $ticket->get('TKT_row');
1092
+				//we only want unique tickets in our final display!!
1093
+				if (! in_array($TKT_ID, $existing_ticket_ids, true)) {
1094
+					$existing_ticket_ids[] = $TKT_ID;
1095
+					$all_tickets[]         = $ticket;
1096
+				}
1097
+				//temporary cache of this ticket info for this datetime for later processing of datetime rows.
1098
+				$datetime_tickets[ $DTT_ID ][] = $ticket_row;
1099
+				//temporary cache of this datetime info for this ticket for later processing of ticket rows.
1100
+				if (
1101
+					! isset($ticket_datetimes[ $TKT_ID ])
1102
+					|| ! in_array($datetime_row, $ticket_datetimes[ $TKT_ID ], true)
1103
+				) {
1104
+					$ticket_datetimes[ $TKT_ID ][] = $datetime_row;
1105
+				}
1106
+			}
1107
+			$datetime_row++;
1108
+		}
1109
+		$main_template_args['total_ticket_rows']     = count($existing_ticket_ids);
1110
+		$main_template_args['existing_ticket_ids']   = implode(',', $existing_ticket_ids);
1111
+		$main_template_args['existing_datetime_ids'] = implode(',', $existing_datetime_ids);
1112
+		//sort $all_tickets by order
1113
+		usort(
1114
+			$all_tickets,
1115
+			function (EE_Ticket $a, EE_Ticket $b)
1116
+			{
1117
+				$a_order = (int) $a->get('TKT_order');
1118
+				$b_order = (int) $b->get('TKT_order');
1119
+				if ($a_order === $b_order) {
1120
+					return 0;
1121
+				}
1122
+				return ($a_order < $b_order) ? -1 : 1;
1123
+			}
1124
+		);
1125
+		// k NOW we have all the data we need for setting up the dtt rows
1126
+		// and ticket rows so we start our dtt loop again.
1127
+		$datetime_row = 1;
1128
+		foreach ($datetimes as $datetime) {
1129
+			$main_template_args['datetime_rows'] .= $this->_get_datetime_row(
1130
+				$datetime_row,
1131
+				$datetime,
1132
+				$datetime_tickets,
1133
+				$all_tickets,
1134
+				false,
1135
+				$datetimes
1136
+			);
1137
+			$datetime_row++;
1138
+		}
1139
+		//then loop through all tickets for the ticket rows.
1140
+		$ticket_row = 1;
1141
+		foreach ($all_tickets as $ticket) {
1142
+			$main_template_args['ticket_rows'] .= $this->_get_ticket_row(
1143
+				$ticket_row,
1144
+				$ticket,
1145
+				$ticket_datetimes,
1146
+				$datetimes,
1147
+				false,
1148
+				$all_tickets
1149
+			);
1150
+			$ticket_row++;
1151
+		}
1152
+		$main_template_args['ticket_js_structure'] = $this->_get_ticket_js_structure($datetimes, $all_tickets);
1153
+		EEH_Template::display_template(
1154
+			PRICING_TEMPLATE_PATH . 'event_tickets_metabox_main.template.php',
1155
+			$main_template_args
1156
+		);
1157
+	}
1158 1158
 
1159 1159
 
1160
-    /**
1161
-     * @param int         $datetime_row
1162
-     * @param EE_Datetime $datetime
1163
-     * @param array       $datetime_tickets
1164
-     * @param array       $all_tickets
1165
-     * @param bool        $default
1166
-     * @param array       $all_datetimes
1167
-     * @return mixed
1168
-     * @throws DomainException
1169
-     * @throws EE_Error
1170
-     */
1171
-    protected function _get_datetime_row(
1172
-        $datetime_row,
1173
-        EE_Datetime $datetime,
1174
-        $datetime_tickets = array(),
1175
-        $all_tickets = array(),
1176
-        $default = false,
1177
-        $all_datetimes = array()
1178
-    ) {
1179
-        $dtt_display_template_args = array(
1180
-            'dtt_edit_row'             => $this->_get_dtt_edit_row(
1181
-                $datetime_row,
1182
-                $datetime,
1183
-                $default,
1184
-                $all_datetimes
1185
-            ),
1186
-            'dtt_attached_tickets_row' => $this->_get_dtt_attached_tickets_row(
1187
-                $datetime_row,
1188
-                $datetime,
1189
-                $datetime_tickets,
1190
-                $all_tickets,
1191
-                $default
1192
-            ),
1193
-            'dtt_row'                  => $default ? 'DTTNUM' : $datetime_row,
1194
-        );
1195
-        return EEH_Template::display_template(
1196
-            PRICING_TEMPLATE_PATH . 'event_tickets_datetime_row_wrapper.template.php',
1197
-            $dtt_display_template_args,
1198
-            true
1199
-        );
1200
-    }
1160
+	/**
1161
+	 * @param int         $datetime_row
1162
+	 * @param EE_Datetime $datetime
1163
+	 * @param array       $datetime_tickets
1164
+	 * @param array       $all_tickets
1165
+	 * @param bool        $default
1166
+	 * @param array       $all_datetimes
1167
+	 * @return mixed
1168
+	 * @throws DomainException
1169
+	 * @throws EE_Error
1170
+	 */
1171
+	protected function _get_datetime_row(
1172
+		$datetime_row,
1173
+		EE_Datetime $datetime,
1174
+		$datetime_tickets = array(),
1175
+		$all_tickets = array(),
1176
+		$default = false,
1177
+		$all_datetimes = array()
1178
+	) {
1179
+		$dtt_display_template_args = array(
1180
+			'dtt_edit_row'             => $this->_get_dtt_edit_row(
1181
+				$datetime_row,
1182
+				$datetime,
1183
+				$default,
1184
+				$all_datetimes
1185
+			),
1186
+			'dtt_attached_tickets_row' => $this->_get_dtt_attached_tickets_row(
1187
+				$datetime_row,
1188
+				$datetime,
1189
+				$datetime_tickets,
1190
+				$all_tickets,
1191
+				$default
1192
+			),
1193
+			'dtt_row'                  => $default ? 'DTTNUM' : $datetime_row,
1194
+		);
1195
+		return EEH_Template::display_template(
1196
+			PRICING_TEMPLATE_PATH . 'event_tickets_datetime_row_wrapper.template.php',
1197
+			$dtt_display_template_args,
1198
+			true
1199
+		);
1200
+	}
1201 1201
 
1202 1202
 
1203
-    /**
1204
-     * This method is used to generate a dtt fields  edit row.
1205
-     * The same row is used to generate a row with valid DTT objects
1206
-     * and the default row that is used as the skeleton by the js.
1207
-     *
1208
-     * @param int           $datetime_row  The row number for the row being generated.
1209
-     * @param EE_Datetime   $datetime
1210
-     * @param bool          $default       Whether a default row is being generated or not.
1211
-     * @param EE_Datetime[] $all_datetimes This is the array of all datetimes used in the editor.
1212
-     * @return string
1213
-     * @throws DomainException
1214
-     * @throws EE_Error
1215
-     */
1216
-    protected function _get_dtt_edit_row($datetime_row, $datetime, $default, $all_datetimes)
1217
-    {
1218
-        // if the incoming $datetime object is NOT an instance of EE_Datetime then force default to true.
1219
-        $default                     = ! $datetime instanceof EE_Datetime ? true : $default;
1220
-        $template_args               = array(
1221
-            'dtt_row'              => $default ? 'DTTNUM' : $datetime_row,
1222
-            'event_datetimes_name' => $default ? 'DTTNAMEATTR' : 'edit_event_datetimes',
1223
-            'edit_dtt_expanded'    => '',
1224
-            'DTT_ID'               => $default ? '' : $datetime->ID(),
1225
-            'DTT_name'             => $default ? '' : $datetime->get_f('DTT_name'),
1226
-            'DTT_description'      => $default ? '' : $datetime->get_f('DTT_description'),
1227
-            'DTT_EVT_start'        => $default ? '' : $datetime->start_date($this->_date_time_format),
1228
-            'DTT_EVT_end'          => $default ? '' : $datetime->end_date($this->_date_time_format),
1229
-            'DTT_reg_limit'        => $default
1230
-                ? ''
1231
-                : $datetime->get_pretty(
1232
-                    'DTT_reg_limit',
1233
-                    'input'
1234
-                ),
1235
-            'DTT_order'            => $default ? 'DTTNUM' : $datetime_row,
1236
-            'dtt_sold'             => $default ? '0' : $datetime->get('DTT_sold'),
1237
-            'dtt_reserved'         => $default ? '0' : $datetime->reserved(),
1238
-            'clone_icon'           => ! empty($datetime) && $datetime->get('DTT_sold') > 0
1239
-                ? ''
1240
-                : 'clone-icon ee-icon ee-icon-clone clickable',
1241
-            'trash_icon'           => ! empty($datetime) && $datetime->get('DTT_sold') > 0
1242
-                ? 'ee-lock-icon'
1243
-                : 'trash-icon dashicons dashicons-post-trash clickable',
1244
-            'reg_list_url'         => $default || ! $datetime->event() instanceof \EE_Event
1245
-                ? ''
1246
-                : EE_Admin_Page::add_query_args_and_nonce(
1247
-                    array('event_id' => $datetime->event()->ID(), 'datetime_id' => $datetime->ID()),
1248
-                    REG_ADMIN_URL
1249
-                ),
1250
-        );
1251
-        $template_args['show_trash'] = count($all_datetimes) === 1 && $template_args['trash_icon'] !== 'ee-lock-icon'
1252
-            ? ' style="display:none"'
1253
-            : '';
1254
-        //allow filtering of template args at this point.
1255
-        $template_args = apply_filters(
1256
-            'FHEE__espresso_events_Pricing_Hooks___get_dtt_edit_row__template_args',
1257
-            $template_args,
1258
-            $datetime_row,
1259
-            $datetime,
1260
-            $default,
1261
-            $all_datetimes,
1262
-            $this->_is_creating_event
1263
-        );
1264
-        return EEH_Template::display_template(
1265
-            PRICING_TEMPLATE_PATH . 'event_tickets_datetime_edit_row.template.php',
1266
-            $template_args,
1267
-            true
1268
-        );
1269
-    }
1203
+	/**
1204
+	 * This method is used to generate a dtt fields  edit row.
1205
+	 * The same row is used to generate a row with valid DTT objects
1206
+	 * and the default row that is used as the skeleton by the js.
1207
+	 *
1208
+	 * @param int           $datetime_row  The row number for the row being generated.
1209
+	 * @param EE_Datetime   $datetime
1210
+	 * @param bool          $default       Whether a default row is being generated or not.
1211
+	 * @param EE_Datetime[] $all_datetimes This is the array of all datetimes used in the editor.
1212
+	 * @return string
1213
+	 * @throws DomainException
1214
+	 * @throws EE_Error
1215
+	 */
1216
+	protected function _get_dtt_edit_row($datetime_row, $datetime, $default, $all_datetimes)
1217
+	{
1218
+		// if the incoming $datetime object is NOT an instance of EE_Datetime then force default to true.
1219
+		$default                     = ! $datetime instanceof EE_Datetime ? true : $default;
1220
+		$template_args               = array(
1221
+			'dtt_row'              => $default ? 'DTTNUM' : $datetime_row,
1222
+			'event_datetimes_name' => $default ? 'DTTNAMEATTR' : 'edit_event_datetimes',
1223
+			'edit_dtt_expanded'    => '',
1224
+			'DTT_ID'               => $default ? '' : $datetime->ID(),
1225
+			'DTT_name'             => $default ? '' : $datetime->get_f('DTT_name'),
1226
+			'DTT_description'      => $default ? '' : $datetime->get_f('DTT_description'),
1227
+			'DTT_EVT_start'        => $default ? '' : $datetime->start_date($this->_date_time_format),
1228
+			'DTT_EVT_end'          => $default ? '' : $datetime->end_date($this->_date_time_format),
1229
+			'DTT_reg_limit'        => $default
1230
+				? ''
1231
+				: $datetime->get_pretty(
1232
+					'DTT_reg_limit',
1233
+					'input'
1234
+				),
1235
+			'DTT_order'            => $default ? 'DTTNUM' : $datetime_row,
1236
+			'dtt_sold'             => $default ? '0' : $datetime->get('DTT_sold'),
1237
+			'dtt_reserved'         => $default ? '0' : $datetime->reserved(),
1238
+			'clone_icon'           => ! empty($datetime) && $datetime->get('DTT_sold') > 0
1239
+				? ''
1240
+				: 'clone-icon ee-icon ee-icon-clone clickable',
1241
+			'trash_icon'           => ! empty($datetime) && $datetime->get('DTT_sold') > 0
1242
+				? 'ee-lock-icon'
1243
+				: 'trash-icon dashicons dashicons-post-trash clickable',
1244
+			'reg_list_url'         => $default || ! $datetime->event() instanceof \EE_Event
1245
+				? ''
1246
+				: EE_Admin_Page::add_query_args_and_nonce(
1247
+					array('event_id' => $datetime->event()->ID(), 'datetime_id' => $datetime->ID()),
1248
+					REG_ADMIN_URL
1249
+				),
1250
+		);
1251
+		$template_args['show_trash'] = count($all_datetimes) === 1 && $template_args['trash_icon'] !== 'ee-lock-icon'
1252
+			? ' style="display:none"'
1253
+			: '';
1254
+		//allow filtering of template args at this point.
1255
+		$template_args = apply_filters(
1256
+			'FHEE__espresso_events_Pricing_Hooks___get_dtt_edit_row__template_args',
1257
+			$template_args,
1258
+			$datetime_row,
1259
+			$datetime,
1260
+			$default,
1261
+			$all_datetimes,
1262
+			$this->_is_creating_event
1263
+		);
1264
+		return EEH_Template::display_template(
1265
+			PRICING_TEMPLATE_PATH . 'event_tickets_datetime_edit_row.template.php',
1266
+			$template_args,
1267
+			true
1268
+		);
1269
+	}
1270 1270
 
1271 1271
 
1272
-    /**
1273
-     * @param int         $datetime_row
1274
-     * @param EE_Datetime $datetime
1275
-     * @param array       $datetime_tickets
1276
-     * @param array       $all_tickets
1277
-     * @param bool        $default
1278
-     * @return mixed
1279
-     * @throws DomainException
1280
-     * @throws EE_Error
1281
-     */
1282
-    protected function _get_dtt_attached_tickets_row(
1283
-        $datetime_row,
1284
-        $datetime,
1285
-        $datetime_tickets = array(),
1286
-        $all_tickets = array(),
1287
-        $default
1288
-    ) {
1289
-        $template_args = array(
1290
-            'dtt_row'                           => $default ? 'DTTNUM' : $datetime_row,
1291
-            'event_datetimes_name'              => $default ? 'DTTNAMEATTR' : 'edit_event_datetimes',
1292
-            'DTT_description'                   => $default ? '' : $datetime->get_f('DTT_description'),
1293
-            'datetime_tickets_list'             => $default ? '<li class="hidden"></li>' : '',
1294
-            'show_tickets_row'                  => ' style="display:none;"',
1295
-            'add_new_datetime_ticket_help_link' => EEH_Template::get_help_tab_link(
1296
-                'add_new_ticket_via_datetime',
1297
-                $this->_adminpage_obj->page_slug,
1298
-                $this->_adminpage_obj->get_req_action(),
1299
-                false,
1300
-                false
1301
-            ),
1302
-            //todo need to add this help info id to the Events_Admin_Page core file so we can access it here.
1303
-            'DTT_ID'                            => $default ? '' : $datetime->ID(),
1304
-        );
1305
-        //need to setup the list items (but only if this isn't a default skeleton setup)
1306
-        if (! $default) {
1307
-            $ticket_row = 1;
1308
-            foreach ($all_tickets as $ticket) {
1309
-                $template_args['datetime_tickets_list'] .= $this->_get_datetime_tickets_list_item(
1310
-                    $datetime_row,
1311
-                    $ticket_row,
1312
-                    $datetime,
1313
-                    $ticket,
1314
-                    $datetime_tickets,
1315
-                    $default
1316
-                );
1317
-                $ticket_row++;
1318
-            }
1319
-        }
1320
-        //filter template args at this point
1321
-        $template_args = apply_filters(
1322
-            'FHEE__espresso_events_Pricing_Hooks___get_dtt_attached_ticket_row__template_args',
1323
-            $template_args,
1324
-            $datetime_row,
1325
-            $datetime,
1326
-            $datetime_tickets,
1327
-            $all_tickets,
1328
-            $default,
1329
-            $this->_is_creating_event
1330
-        );
1331
-        return EEH_Template::display_template(
1332
-            PRICING_TEMPLATE_PATH . 'event_tickets_datetime_attached_tickets_row.template.php',
1333
-            $template_args,
1334
-            true
1335
-        );
1336
-    }
1272
+	/**
1273
+	 * @param int         $datetime_row
1274
+	 * @param EE_Datetime $datetime
1275
+	 * @param array       $datetime_tickets
1276
+	 * @param array       $all_tickets
1277
+	 * @param bool        $default
1278
+	 * @return mixed
1279
+	 * @throws DomainException
1280
+	 * @throws EE_Error
1281
+	 */
1282
+	protected function _get_dtt_attached_tickets_row(
1283
+		$datetime_row,
1284
+		$datetime,
1285
+		$datetime_tickets = array(),
1286
+		$all_tickets = array(),
1287
+		$default
1288
+	) {
1289
+		$template_args = array(
1290
+			'dtt_row'                           => $default ? 'DTTNUM' : $datetime_row,
1291
+			'event_datetimes_name'              => $default ? 'DTTNAMEATTR' : 'edit_event_datetimes',
1292
+			'DTT_description'                   => $default ? '' : $datetime->get_f('DTT_description'),
1293
+			'datetime_tickets_list'             => $default ? '<li class="hidden"></li>' : '',
1294
+			'show_tickets_row'                  => ' style="display:none;"',
1295
+			'add_new_datetime_ticket_help_link' => EEH_Template::get_help_tab_link(
1296
+				'add_new_ticket_via_datetime',
1297
+				$this->_adminpage_obj->page_slug,
1298
+				$this->_adminpage_obj->get_req_action(),
1299
+				false,
1300
+				false
1301
+			),
1302
+			//todo need to add this help info id to the Events_Admin_Page core file so we can access it here.
1303
+			'DTT_ID'                            => $default ? '' : $datetime->ID(),
1304
+		);
1305
+		//need to setup the list items (but only if this isn't a default skeleton setup)
1306
+		if (! $default) {
1307
+			$ticket_row = 1;
1308
+			foreach ($all_tickets as $ticket) {
1309
+				$template_args['datetime_tickets_list'] .= $this->_get_datetime_tickets_list_item(
1310
+					$datetime_row,
1311
+					$ticket_row,
1312
+					$datetime,
1313
+					$ticket,
1314
+					$datetime_tickets,
1315
+					$default
1316
+				);
1317
+				$ticket_row++;
1318
+			}
1319
+		}
1320
+		//filter template args at this point
1321
+		$template_args = apply_filters(
1322
+			'FHEE__espresso_events_Pricing_Hooks___get_dtt_attached_ticket_row__template_args',
1323
+			$template_args,
1324
+			$datetime_row,
1325
+			$datetime,
1326
+			$datetime_tickets,
1327
+			$all_tickets,
1328
+			$default,
1329
+			$this->_is_creating_event
1330
+		);
1331
+		return EEH_Template::display_template(
1332
+			PRICING_TEMPLATE_PATH . 'event_tickets_datetime_attached_tickets_row.template.php',
1333
+			$template_args,
1334
+			true
1335
+		);
1336
+	}
1337 1337
 
1338 1338
 
1339
-    /**
1340
-     * @param int         $datetime_row
1341
-     * @param int         $ticket_row
1342
-     * @param EE_Datetime $datetime
1343
-     * @param EE_Ticket   $ticket
1344
-     * @param array       $datetime_tickets
1345
-     * @param bool        $default
1346
-     * @return mixed
1347
-     * @throws DomainException
1348
-     * @throws EE_Error
1349
-     */
1350
-    protected function _get_datetime_tickets_list_item(
1351
-        $datetime_row,
1352
-        $ticket_row,
1353
-        $datetime,
1354
-        $ticket,
1355
-        $datetime_tickets = array(),
1356
-        $default
1357
-    ) {
1358
-        $dtt_tkts      = $datetime instanceof EE_Datetime && isset($datetime_tickets[ $datetime->ID() ])
1359
-            ? $datetime_tickets[ $datetime->ID() ]
1360
-            : array();
1361
-        $display_row   = $ticket instanceof EE_Ticket ? $ticket->get('TKT_row') : 0;
1362
-        $no_ticket     = $default && empty($ticket);
1363
-        $template_args = array(
1364
-            'dtt_row'                 => $default
1365
-                ? 'DTTNUM'
1366
-                : $datetime_row,
1367
-            'tkt_row'                 => $no_ticket
1368
-                ? 'TICKETNUM'
1369
-                : $ticket_row,
1370
-            'datetime_ticket_checked' => in_array($display_row, $dtt_tkts, true)
1371
-                ? ' checked="checked"'
1372
-                : '',
1373
-            'ticket_selected'         => in_array($display_row, $dtt_tkts, true)
1374
-                ? ' ticket-selected'
1375
-                : '',
1376
-            'TKT_name'                => $no_ticket
1377
-                ? 'TKTNAME'
1378
-                : $ticket->get('TKT_name'),
1379
-            'tkt_status_class'        => $no_ticket || $this->_is_creating_event
1380
-                ? ' tkt-status-' . EE_Ticket::onsale
1381
-                : ' tkt-status-' . $ticket->ticket_status(),
1382
-        );
1383
-        //filter template args
1384
-        $template_args = apply_filters(
1385
-            'FHEE__espresso_events_Pricing_Hooks___get_datetime_tickets_list_item__template_args',
1386
-            $template_args,
1387
-            $datetime_row,
1388
-            $ticket_row,
1389
-            $datetime,
1390
-            $ticket,
1391
-            $datetime_tickets,
1392
-            $default,
1393
-            $this->_is_creating_event
1394
-        );
1395
-        return EEH_Template::display_template(
1396
-            PRICING_TEMPLATE_PATH . 'event_tickets_datetime_dtt_tickets_list.template.php',
1397
-            $template_args,
1398
-            true
1399
-        );
1400
-    }
1339
+	/**
1340
+	 * @param int         $datetime_row
1341
+	 * @param int         $ticket_row
1342
+	 * @param EE_Datetime $datetime
1343
+	 * @param EE_Ticket   $ticket
1344
+	 * @param array       $datetime_tickets
1345
+	 * @param bool        $default
1346
+	 * @return mixed
1347
+	 * @throws DomainException
1348
+	 * @throws EE_Error
1349
+	 */
1350
+	protected function _get_datetime_tickets_list_item(
1351
+		$datetime_row,
1352
+		$ticket_row,
1353
+		$datetime,
1354
+		$ticket,
1355
+		$datetime_tickets = array(),
1356
+		$default
1357
+	) {
1358
+		$dtt_tkts      = $datetime instanceof EE_Datetime && isset($datetime_tickets[ $datetime->ID() ])
1359
+			? $datetime_tickets[ $datetime->ID() ]
1360
+			: array();
1361
+		$display_row   = $ticket instanceof EE_Ticket ? $ticket->get('TKT_row') : 0;
1362
+		$no_ticket     = $default && empty($ticket);
1363
+		$template_args = array(
1364
+			'dtt_row'                 => $default
1365
+				? 'DTTNUM'
1366
+				: $datetime_row,
1367
+			'tkt_row'                 => $no_ticket
1368
+				? 'TICKETNUM'
1369
+				: $ticket_row,
1370
+			'datetime_ticket_checked' => in_array($display_row, $dtt_tkts, true)
1371
+				? ' checked="checked"'
1372
+				: '',
1373
+			'ticket_selected'         => in_array($display_row, $dtt_tkts, true)
1374
+				? ' ticket-selected'
1375
+				: '',
1376
+			'TKT_name'                => $no_ticket
1377
+				? 'TKTNAME'
1378
+				: $ticket->get('TKT_name'),
1379
+			'tkt_status_class'        => $no_ticket || $this->_is_creating_event
1380
+				? ' tkt-status-' . EE_Ticket::onsale
1381
+				: ' tkt-status-' . $ticket->ticket_status(),
1382
+		);
1383
+		//filter template args
1384
+		$template_args = apply_filters(
1385
+			'FHEE__espresso_events_Pricing_Hooks___get_datetime_tickets_list_item__template_args',
1386
+			$template_args,
1387
+			$datetime_row,
1388
+			$ticket_row,
1389
+			$datetime,
1390
+			$ticket,
1391
+			$datetime_tickets,
1392
+			$default,
1393
+			$this->_is_creating_event
1394
+		);
1395
+		return EEH_Template::display_template(
1396
+			PRICING_TEMPLATE_PATH . 'event_tickets_datetime_dtt_tickets_list.template.php',
1397
+			$template_args,
1398
+			true
1399
+		);
1400
+	}
1401 1401
 
1402 1402
 
1403
-    /**
1404
-     * This generates the ticket row for tickets.
1405
-     * This same method is used to generate both the actual rows and the js skeleton row
1406
-     * (when default === true)
1407
-     *
1408
-     * @param int           $ticket_row       Represents the row number being generated.
1409
-     * @param               $ticket
1410
-     * @param EE_Datetime[] $ticket_datetimes Either an array of all datetimes on all tickets indexed by each ticket
1411
-     *                                        or empty for default
1412
-     * @param EE_Datetime[] $all_datetimes    All Datetimes on the event or empty for default.
1413
-     * @param bool          $default          Whether default row being generated or not.
1414
-     * @param EE_Ticket[]   $all_tickets      This is an array of all tickets attached to the event
1415
-     *                                        (or empty in the case of defaults)
1416
-     * @return mixed
1417
-     * @throws InvalidArgumentException
1418
-     * @throws InvalidInterfaceException
1419
-     * @throws InvalidDataTypeException
1420
-     * @throws DomainException
1421
-     * @throws EE_Error
1422
-     * @throws ReflectionException
1423
-     */
1424
-    protected function _get_ticket_row(
1425
-        $ticket_row,
1426
-        $ticket,
1427
-        $ticket_datetimes,
1428
-        $all_datetimes,
1429
-        $default = false,
1430
-        $all_tickets = array()
1431
-    ) {
1432
-        // if $ticket is not an instance of EE_Ticket then force default to true.
1433
-        $default = ! $ticket instanceof EE_Ticket ? true : $default;
1434
-        $prices  = ! empty($ticket) && ! $default ? $ticket->get_many_related('Price',
1435
-            array('default_where_conditions' => 'none', 'order_by' => array('PRC_order' => 'ASC'))) : array();
1436
-        // if there is only one price (which would be the base price)
1437
-        // or NO prices and this ticket is a default ticket,
1438
-        // let's just make sure there are no cached default prices on the object.
1439
-        // This is done by not including any query_params.
1440
-        if ($ticket instanceof EE_Ticket && $ticket->is_default() && (count($prices) === 1 || empty($prices))) {
1441
-            $prices = $ticket->prices();
1442
-        }
1443
-        // check if we're dealing with a default ticket in which case
1444
-        // we don't want any starting_ticket_datetime_row values set
1445
-        // (otherwise there won't be any new relationships created for tickets based off of the default ticket).
1446
-        // This will future proof in case there is ever any behaviour change between what the primary_key defaults to.
1447
-        $default_dtt      = $default || ($ticket instanceof EE_Ticket && $ticket->is_default());
1448
-        $tkt_datetimes    = $ticket instanceof EE_Ticket && isset($ticket_datetimes[ $ticket->ID() ])
1449
-            ? $ticket_datetimes[ $ticket->ID() ]
1450
-            : array();
1451
-        $ticket_subtotal  = $default ? 0 : $ticket->get_ticket_subtotal();
1452
-        $base_price       = $default ? null : $ticket->base_price();
1453
-        $count_price_mods = EEM_Price::instance()->get_all_default_prices(true);
1454
-        //breaking out complicated condition for ticket_status
1455
-        if ($default) {
1456
-            $ticket_status_class = ' tkt-status-' . EE_Ticket::onsale;
1457
-        } else {
1458
-            $ticket_status_class = $ticket->is_default()
1459
-                ? ' tkt-status-' . EE_Ticket::onsale
1460
-                : ' tkt-status-' . $ticket->ticket_status();
1461
-        }
1462
-        //breaking out complicated condition for TKT_taxable
1463
-        if ($default) {
1464
-            $TKT_taxable = '';
1465
-        } else {
1466
-            $TKT_taxable = $ticket->taxable()
1467
-                ? ' checked="checked"'
1468
-                : '';
1469
-        }
1470
-        if ($default) {
1471
-            $TKT_status = EEH_Template::pretty_status(EE_Ticket::onsale, false, 'sentence');
1472
-        } elseif ($ticket->is_default()) {
1473
-            $TKT_status = EEH_Template::pretty_status(EE_Ticket::onsale, false, 'sentence');
1474
-        } else {
1475
-            $TKT_status = $ticket->ticket_status(true);
1476
-        }
1477
-        if ($default) {
1478
-            $TKT_min = '';
1479
-        } else {
1480
-            $TKT_min = $ticket->min();
1481
-            if ($TKT_min === -1 || $TKT_min === 0) {
1482
-                $TKT_min = '';
1483
-            }
1484
-        }
1485
-        $template_args                 = array(
1486
-            'tkt_row'                       => $default ? 'TICKETNUM' : $ticket_row,
1487
-            'TKT_order'                     => $default ? 'TICKETNUM' : $ticket_row,
1488
-            //on initial page load this will always be the correct order.
1489
-            'tkt_status_class'              => $ticket_status_class,
1490
-            'display_edit_tkt_row'          => ' style="display:none;"',
1491
-            'edit_tkt_expanded'             => '',
1492
-            'edit_tickets_name'             => $default ? 'TICKETNAMEATTR' : 'edit_tickets',
1493
-            'TKT_name'                      => $default ? '' : $ticket->get_f('TKT_name'),
1494
-            'TKT_start_date'                => $default
1495
-                ? ''
1496
-                : $ticket->get_date('TKT_start_date', $this->_date_time_format),
1497
-            'TKT_end_date'                  => $default
1498
-                ? ''
1499
-                : $ticket->get_date('TKT_end_date', $this->_date_time_format),
1500
-            'TKT_status'                    => $TKT_status,
1501
-            'TKT_price'                     => $default
1502
-                ? ''
1503
-                : EEH_Template::format_currency(
1504
-                    $ticket->get_ticket_total_with_taxes(),
1505
-                    false,
1506
-                    false
1507
-                ),
1508
-            'TKT_price_code'                => EE_Registry::instance()->CFG->currency->code,
1509
-            'TKT_price_amount'              => $default ? 0 : $ticket_subtotal,
1510
-            'TKT_qty'                       => $default
1511
-                ? ''
1512
-                : $ticket->get_pretty('TKT_qty', 'symbol'),
1513
-            'TKT_qty_for_input'             => $default
1514
-                ? ''
1515
-                : $ticket->get_pretty('TKT_qty', 'input'),
1516
-            'TKT_uses'                      => $default
1517
-                ? ''
1518
-                : $ticket->get_pretty('TKT_uses', 'input'),
1519
-            'TKT_min'                       => $TKT_min,
1520
-            'TKT_max'                       => $default
1521
-                ? ''
1522
-                : $ticket->get_pretty('TKT_max', 'input'),
1523
-            'TKT_sold'                      => $default ? 0 : $ticket->tickets_sold('ticket'),
1524
-            'TKT_reserved'                  => $default ? 0 : $ticket->reserved(),
1525
-            'TKT_registrations'             => $default
1526
-                ? 0
1527
-                : $ticket->count_registrations(
1528
-                    array(
1529
-                        array(
1530
-                            'STS_ID' => array(
1531
-                                '!=',
1532
-                                EEM_Registration::status_id_incomplete,
1533
-                            ),
1534
-                        ),
1535
-                    )
1536
-                ),
1537
-            'TKT_ID'                        => $default ? 0 : $ticket->ID(),
1538
-            'TKT_description'               => $default ? '' : $ticket->get_f('TKT_description'),
1539
-            'TKT_is_default'                => $default ? 0 : $ticket->is_default(),
1540
-            'TKT_required'                  => $default ? 0 : $ticket->required(),
1541
-            'TKT_is_default_selector'       => '',
1542
-            'ticket_price_rows'             => '',
1543
-            'TKT_base_price'                => $default || ! $base_price instanceof EE_Price
1544
-                ? ''
1545
-                : $base_price->get_pretty('PRC_amount', 'localized_float'),
1546
-            'TKT_base_price_ID'             => $default || ! $base_price instanceof EE_Price ? 0 : $base_price->ID(),
1547
-            'show_price_modifier'           => count($prices) > 1 || ($default && $count_price_mods > 0)
1548
-                ? ''
1549
-                : ' style="display:none;"',
1550
-            'show_price_mod_button'         => count($prices) > 1
1551
-                                               || ($default && $count_price_mods > 0)
1552
-                                               || (! $default && $ticket->deleted())
1553
-                ? ' style="display:none;"'
1554
-                : '',
1555
-            'total_price_rows'              => count($prices) > 1 ? count($prices) : 1,
1556
-            'ticket_datetimes_list'         => $default ? '<li class="hidden"></li>' : '',
1557
-            'starting_ticket_datetime_rows' => $default || $default_dtt ? '' : implode(',', $tkt_datetimes),
1558
-            'ticket_datetime_rows'          => $default ? '' : implode(',', $tkt_datetimes),
1559
-            'existing_ticket_price_ids'     => $default ? '' : implode(',', array_keys($prices)),
1560
-            'ticket_template_id'            => $default ? 0 : $ticket->get('TTM_ID'),
1561
-            'TKT_taxable'                   => $TKT_taxable,
1562
-            'display_subtotal'              => $ticket instanceof EE_Ticket && $ticket->taxable()
1563
-                ? ''
1564
-                : ' style="display:none"',
1565
-            'price_currency_symbol'         => EE_Registry::instance()->CFG->currency->sign,
1566
-            'TKT_subtotal_amount_display'   => EEH_Template::format_currency(
1567
-                $ticket_subtotal,
1568
-                false,
1569
-                false
1570
-            ),
1571
-            'TKT_subtotal_amount'           => $ticket_subtotal,
1572
-            'tax_rows'                      => $this->_get_tax_rows($ticket_row, $ticket),
1573
-            'disabled'                      => $ticket instanceof EE_Ticket && $ticket->deleted(),
1574
-            'ticket_archive_class'          => $ticket instanceof EE_Ticket && $ticket->deleted()
1575
-                ? ' ticket-archived'
1576
-                : '',
1577
-            'trash_icon'                    => $ticket instanceof EE_Ticket
1578
-                                               && $ticket->deleted()
1579
-                                               && ! $ticket->is_permanently_deleteable()
1580
-                ? 'ee-lock-icon '
1581
-                : 'trash-icon dashicons dashicons-post-trash clickable',
1582
-            'clone_icon'                    => $ticket instanceof EE_Ticket && $ticket->deleted()
1583
-                ? ''
1584
-                : 'clone-icon ee-icon ee-icon-clone clickable',
1585
-        );
1586
-        $template_args['trash_hidden'] = count($all_tickets) === 1 && $template_args['trash_icon'] !== 'ee-lock-icon'
1587
-            ? ' style="display:none"'
1588
-            : '';
1589
-        //handle rows that should NOT be empty
1590
-        if (empty($template_args['TKT_start_date'])) {
1591
-            //if empty then the start date will be now.
1592
-            $template_args['TKT_start_date']   = date($this->_date_time_format,
1593
-                current_time('timestamp'));
1594
-            $template_args['tkt_status_class'] = ' tkt-status-' . EE_Ticket::onsale;
1595
-        }
1596
-        if (empty($template_args['TKT_end_date'])) {
1597
-            //get the earliest datetime (if present);
1598
-            $earliest_dtt = $this->_adminpage_obj->get_cpt_model_obj()->ID() > 0
1599
-                ? $this->_adminpage_obj->get_cpt_model_obj()->get_first_related(
1600
-                    'Datetime',
1601
-                    array('order_by' => array('DTT_EVT_start' => 'ASC'))
1602
-                )
1603
-                : null;
1604
-            if (! empty($earliest_dtt)) {
1605
-                $template_args['TKT_end_date'] = $earliest_dtt->get_datetime(
1606
-                    'DTT_EVT_start',
1607
-                    $this->_date_time_format
1608
-                );
1609
-            } else {
1610
-                //default so let's just use what's been set for the default date-time which is 30 days from now.
1611
-                $template_args['TKT_end_date'] = date(
1612
-                    $this->_date_time_format,
1613
-                    mktime(
1614
-                        24, 0, 0, date('m'), date('d') + 29, date('Y')
1615
-                    )
1616
-                );
1617
-            }
1618
-            $template_args['tkt_status_class'] = ' tkt-status-' . EE_Ticket::onsale;
1619
-        }
1620
-        //generate ticket_datetime items
1621
-        if (! $default) {
1622
-            $datetime_row = 1;
1623
-            foreach ($all_datetimes as $datetime) {
1624
-                $template_args['ticket_datetimes_list'] .= $this->_get_ticket_datetime_list_item(
1625
-                    $datetime_row,
1626
-                    $ticket_row,
1627
-                    $datetime,
1628
-                    $ticket,
1629
-                    $ticket_datetimes,
1630
-                    $default
1631
-                );
1632
-                $datetime_row++;
1633
-            }
1634
-        }
1635
-        $price_row = 1;
1636
-        foreach ($prices as $price) {
1637
-            if (! $price instanceof EE_Price) {
1638
-                continue;
1639
-            }
1640
-            if ($price->is_base_price()) {
1641
-                $price_row++;
1642
-                continue;
1643
-            }
1644
-            $show_trash                         = ! ((count($prices) > 1 && $price_row === 1) || count($prices) === 1);
1645
-            $show_create                        = ! (count($prices) > 1 && count($prices) !== $price_row);
1646
-            $template_args['ticket_price_rows'] .= $this->_get_ticket_price_row(
1647
-                $ticket_row,
1648
-                $price_row,
1649
-                $price,
1650
-                $default,
1651
-                $ticket,
1652
-                $show_trash,
1653
-                $show_create
1654
-            );
1655
-            $price_row++;
1656
-        }
1657
-        //filter $template_args
1658
-        $template_args = apply_filters(
1659
-            'FHEE__espresso_events_Pricing_Hooks___get_ticket_row__template_args',
1660
-            $template_args,
1661
-            $ticket_row,
1662
-            $ticket,
1663
-            $ticket_datetimes,
1664
-            $all_datetimes,
1665
-            $default,
1666
-            $all_tickets,
1667
-            $this->_is_creating_event
1668
-        );
1669
-        return EEH_Template::display_template(
1670
-            PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_row.template.php',
1671
-            $template_args,
1672
-            true
1673
-        );
1674
-    }
1403
+	/**
1404
+	 * This generates the ticket row for tickets.
1405
+	 * This same method is used to generate both the actual rows and the js skeleton row
1406
+	 * (when default === true)
1407
+	 *
1408
+	 * @param int           $ticket_row       Represents the row number being generated.
1409
+	 * @param               $ticket
1410
+	 * @param EE_Datetime[] $ticket_datetimes Either an array of all datetimes on all tickets indexed by each ticket
1411
+	 *                                        or empty for default
1412
+	 * @param EE_Datetime[] $all_datetimes    All Datetimes on the event or empty for default.
1413
+	 * @param bool          $default          Whether default row being generated or not.
1414
+	 * @param EE_Ticket[]   $all_tickets      This is an array of all tickets attached to the event
1415
+	 *                                        (or empty in the case of defaults)
1416
+	 * @return mixed
1417
+	 * @throws InvalidArgumentException
1418
+	 * @throws InvalidInterfaceException
1419
+	 * @throws InvalidDataTypeException
1420
+	 * @throws DomainException
1421
+	 * @throws EE_Error
1422
+	 * @throws ReflectionException
1423
+	 */
1424
+	protected function _get_ticket_row(
1425
+		$ticket_row,
1426
+		$ticket,
1427
+		$ticket_datetimes,
1428
+		$all_datetimes,
1429
+		$default = false,
1430
+		$all_tickets = array()
1431
+	) {
1432
+		// if $ticket is not an instance of EE_Ticket then force default to true.
1433
+		$default = ! $ticket instanceof EE_Ticket ? true : $default;
1434
+		$prices  = ! empty($ticket) && ! $default ? $ticket->get_many_related('Price',
1435
+			array('default_where_conditions' => 'none', 'order_by' => array('PRC_order' => 'ASC'))) : array();
1436
+		// if there is only one price (which would be the base price)
1437
+		// or NO prices and this ticket is a default ticket,
1438
+		// let's just make sure there are no cached default prices on the object.
1439
+		// This is done by not including any query_params.
1440
+		if ($ticket instanceof EE_Ticket && $ticket->is_default() && (count($prices) === 1 || empty($prices))) {
1441
+			$prices = $ticket->prices();
1442
+		}
1443
+		// check if we're dealing with a default ticket in which case
1444
+		// we don't want any starting_ticket_datetime_row values set
1445
+		// (otherwise there won't be any new relationships created for tickets based off of the default ticket).
1446
+		// This will future proof in case there is ever any behaviour change between what the primary_key defaults to.
1447
+		$default_dtt      = $default || ($ticket instanceof EE_Ticket && $ticket->is_default());
1448
+		$tkt_datetimes    = $ticket instanceof EE_Ticket && isset($ticket_datetimes[ $ticket->ID() ])
1449
+			? $ticket_datetimes[ $ticket->ID() ]
1450
+			: array();
1451
+		$ticket_subtotal  = $default ? 0 : $ticket->get_ticket_subtotal();
1452
+		$base_price       = $default ? null : $ticket->base_price();
1453
+		$count_price_mods = EEM_Price::instance()->get_all_default_prices(true);
1454
+		//breaking out complicated condition for ticket_status
1455
+		if ($default) {
1456
+			$ticket_status_class = ' tkt-status-' . EE_Ticket::onsale;
1457
+		} else {
1458
+			$ticket_status_class = $ticket->is_default()
1459
+				? ' tkt-status-' . EE_Ticket::onsale
1460
+				: ' tkt-status-' . $ticket->ticket_status();
1461
+		}
1462
+		//breaking out complicated condition for TKT_taxable
1463
+		if ($default) {
1464
+			$TKT_taxable = '';
1465
+		} else {
1466
+			$TKT_taxable = $ticket->taxable()
1467
+				? ' checked="checked"'
1468
+				: '';
1469
+		}
1470
+		if ($default) {
1471
+			$TKT_status = EEH_Template::pretty_status(EE_Ticket::onsale, false, 'sentence');
1472
+		} elseif ($ticket->is_default()) {
1473
+			$TKT_status = EEH_Template::pretty_status(EE_Ticket::onsale, false, 'sentence');
1474
+		} else {
1475
+			$TKT_status = $ticket->ticket_status(true);
1476
+		}
1477
+		if ($default) {
1478
+			$TKT_min = '';
1479
+		} else {
1480
+			$TKT_min = $ticket->min();
1481
+			if ($TKT_min === -1 || $TKT_min === 0) {
1482
+				$TKT_min = '';
1483
+			}
1484
+		}
1485
+		$template_args                 = array(
1486
+			'tkt_row'                       => $default ? 'TICKETNUM' : $ticket_row,
1487
+			'TKT_order'                     => $default ? 'TICKETNUM' : $ticket_row,
1488
+			//on initial page load this will always be the correct order.
1489
+			'tkt_status_class'              => $ticket_status_class,
1490
+			'display_edit_tkt_row'          => ' style="display:none;"',
1491
+			'edit_tkt_expanded'             => '',
1492
+			'edit_tickets_name'             => $default ? 'TICKETNAMEATTR' : 'edit_tickets',
1493
+			'TKT_name'                      => $default ? '' : $ticket->get_f('TKT_name'),
1494
+			'TKT_start_date'                => $default
1495
+				? ''
1496
+				: $ticket->get_date('TKT_start_date', $this->_date_time_format),
1497
+			'TKT_end_date'                  => $default
1498
+				? ''
1499
+				: $ticket->get_date('TKT_end_date', $this->_date_time_format),
1500
+			'TKT_status'                    => $TKT_status,
1501
+			'TKT_price'                     => $default
1502
+				? ''
1503
+				: EEH_Template::format_currency(
1504
+					$ticket->get_ticket_total_with_taxes(),
1505
+					false,
1506
+					false
1507
+				),
1508
+			'TKT_price_code'                => EE_Registry::instance()->CFG->currency->code,
1509
+			'TKT_price_amount'              => $default ? 0 : $ticket_subtotal,
1510
+			'TKT_qty'                       => $default
1511
+				? ''
1512
+				: $ticket->get_pretty('TKT_qty', 'symbol'),
1513
+			'TKT_qty_for_input'             => $default
1514
+				? ''
1515
+				: $ticket->get_pretty('TKT_qty', 'input'),
1516
+			'TKT_uses'                      => $default
1517
+				? ''
1518
+				: $ticket->get_pretty('TKT_uses', 'input'),
1519
+			'TKT_min'                       => $TKT_min,
1520
+			'TKT_max'                       => $default
1521
+				? ''
1522
+				: $ticket->get_pretty('TKT_max', 'input'),
1523
+			'TKT_sold'                      => $default ? 0 : $ticket->tickets_sold('ticket'),
1524
+			'TKT_reserved'                  => $default ? 0 : $ticket->reserved(),
1525
+			'TKT_registrations'             => $default
1526
+				? 0
1527
+				: $ticket->count_registrations(
1528
+					array(
1529
+						array(
1530
+							'STS_ID' => array(
1531
+								'!=',
1532
+								EEM_Registration::status_id_incomplete,
1533
+							),
1534
+						),
1535
+					)
1536
+				),
1537
+			'TKT_ID'                        => $default ? 0 : $ticket->ID(),
1538
+			'TKT_description'               => $default ? '' : $ticket->get_f('TKT_description'),
1539
+			'TKT_is_default'                => $default ? 0 : $ticket->is_default(),
1540
+			'TKT_required'                  => $default ? 0 : $ticket->required(),
1541
+			'TKT_is_default_selector'       => '',
1542
+			'ticket_price_rows'             => '',
1543
+			'TKT_base_price'                => $default || ! $base_price instanceof EE_Price
1544
+				? ''
1545
+				: $base_price->get_pretty('PRC_amount', 'localized_float'),
1546
+			'TKT_base_price_ID'             => $default || ! $base_price instanceof EE_Price ? 0 : $base_price->ID(),
1547
+			'show_price_modifier'           => count($prices) > 1 || ($default && $count_price_mods > 0)
1548
+				? ''
1549
+				: ' style="display:none;"',
1550
+			'show_price_mod_button'         => count($prices) > 1
1551
+											   || ($default && $count_price_mods > 0)
1552
+											   || (! $default && $ticket->deleted())
1553
+				? ' style="display:none;"'
1554
+				: '',
1555
+			'total_price_rows'              => count($prices) > 1 ? count($prices) : 1,
1556
+			'ticket_datetimes_list'         => $default ? '<li class="hidden"></li>' : '',
1557
+			'starting_ticket_datetime_rows' => $default || $default_dtt ? '' : implode(',', $tkt_datetimes),
1558
+			'ticket_datetime_rows'          => $default ? '' : implode(',', $tkt_datetimes),
1559
+			'existing_ticket_price_ids'     => $default ? '' : implode(',', array_keys($prices)),
1560
+			'ticket_template_id'            => $default ? 0 : $ticket->get('TTM_ID'),
1561
+			'TKT_taxable'                   => $TKT_taxable,
1562
+			'display_subtotal'              => $ticket instanceof EE_Ticket && $ticket->taxable()
1563
+				? ''
1564
+				: ' style="display:none"',
1565
+			'price_currency_symbol'         => EE_Registry::instance()->CFG->currency->sign,
1566
+			'TKT_subtotal_amount_display'   => EEH_Template::format_currency(
1567
+				$ticket_subtotal,
1568
+				false,
1569
+				false
1570
+			),
1571
+			'TKT_subtotal_amount'           => $ticket_subtotal,
1572
+			'tax_rows'                      => $this->_get_tax_rows($ticket_row, $ticket),
1573
+			'disabled'                      => $ticket instanceof EE_Ticket && $ticket->deleted(),
1574
+			'ticket_archive_class'          => $ticket instanceof EE_Ticket && $ticket->deleted()
1575
+				? ' ticket-archived'
1576
+				: '',
1577
+			'trash_icon'                    => $ticket instanceof EE_Ticket
1578
+											   && $ticket->deleted()
1579
+											   && ! $ticket->is_permanently_deleteable()
1580
+				? 'ee-lock-icon '
1581
+				: 'trash-icon dashicons dashicons-post-trash clickable',
1582
+			'clone_icon'                    => $ticket instanceof EE_Ticket && $ticket->deleted()
1583
+				? ''
1584
+				: 'clone-icon ee-icon ee-icon-clone clickable',
1585
+		);
1586
+		$template_args['trash_hidden'] = count($all_tickets) === 1 && $template_args['trash_icon'] !== 'ee-lock-icon'
1587
+			? ' style="display:none"'
1588
+			: '';
1589
+		//handle rows that should NOT be empty
1590
+		if (empty($template_args['TKT_start_date'])) {
1591
+			//if empty then the start date will be now.
1592
+			$template_args['TKT_start_date']   = date($this->_date_time_format,
1593
+				current_time('timestamp'));
1594
+			$template_args['tkt_status_class'] = ' tkt-status-' . EE_Ticket::onsale;
1595
+		}
1596
+		if (empty($template_args['TKT_end_date'])) {
1597
+			//get the earliest datetime (if present);
1598
+			$earliest_dtt = $this->_adminpage_obj->get_cpt_model_obj()->ID() > 0
1599
+				? $this->_adminpage_obj->get_cpt_model_obj()->get_first_related(
1600
+					'Datetime',
1601
+					array('order_by' => array('DTT_EVT_start' => 'ASC'))
1602
+				)
1603
+				: null;
1604
+			if (! empty($earliest_dtt)) {
1605
+				$template_args['TKT_end_date'] = $earliest_dtt->get_datetime(
1606
+					'DTT_EVT_start',
1607
+					$this->_date_time_format
1608
+				);
1609
+			} else {
1610
+				//default so let's just use what's been set for the default date-time which is 30 days from now.
1611
+				$template_args['TKT_end_date'] = date(
1612
+					$this->_date_time_format,
1613
+					mktime(
1614
+						24, 0, 0, date('m'), date('d') + 29, date('Y')
1615
+					)
1616
+				);
1617
+			}
1618
+			$template_args['tkt_status_class'] = ' tkt-status-' . EE_Ticket::onsale;
1619
+		}
1620
+		//generate ticket_datetime items
1621
+		if (! $default) {
1622
+			$datetime_row = 1;
1623
+			foreach ($all_datetimes as $datetime) {
1624
+				$template_args['ticket_datetimes_list'] .= $this->_get_ticket_datetime_list_item(
1625
+					$datetime_row,
1626
+					$ticket_row,
1627
+					$datetime,
1628
+					$ticket,
1629
+					$ticket_datetimes,
1630
+					$default
1631
+				);
1632
+				$datetime_row++;
1633
+			}
1634
+		}
1635
+		$price_row = 1;
1636
+		foreach ($prices as $price) {
1637
+			if (! $price instanceof EE_Price) {
1638
+				continue;
1639
+			}
1640
+			if ($price->is_base_price()) {
1641
+				$price_row++;
1642
+				continue;
1643
+			}
1644
+			$show_trash                         = ! ((count($prices) > 1 && $price_row === 1) || count($prices) === 1);
1645
+			$show_create                        = ! (count($prices) > 1 && count($prices) !== $price_row);
1646
+			$template_args['ticket_price_rows'] .= $this->_get_ticket_price_row(
1647
+				$ticket_row,
1648
+				$price_row,
1649
+				$price,
1650
+				$default,
1651
+				$ticket,
1652
+				$show_trash,
1653
+				$show_create
1654
+			);
1655
+			$price_row++;
1656
+		}
1657
+		//filter $template_args
1658
+		$template_args = apply_filters(
1659
+			'FHEE__espresso_events_Pricing_Hooks___get_ticket_row__template_args',
1660
+			$template_args,
1661
+			$ticket_row,
1662
+			$ticket,
1663
+			$ticket_datetimes,
1664
+			$all_datetimes,
1665
+			$default,
1666
+			$all_tickets,
1667
+			$this->_is_creating_event
1668
+		);
1669
+		return EEH_Template::display_template(
1670
+			PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_row.template.php',
1671
+			$template_args,
1672
+			true
1673
+		);
1674
+	}
1675 1675
 
1676 1676
 
1677
-    /**
1678
-     * @param int            $ticket_row
1679
-     * @param EE_Ticket|null $ticket
1680
-     * @return string
1681
-     * @throws DomainException
1682
-     * @throws EE_Error
1683
-     */
1684
-    protected function _get_tax_rows($ticket_row, $ticket)
1685
-    {
1686
-        $tax_rows = '';
1687
-        /** @var EE_Price[] $taxes */
1688
-        $taxes = empty($ticket) ? EE_Taxes::get_taxes_for_admin() : $ticket->get_ticket_taxes_for_admin();
1689
-        foreach ($taxes as $tax) {
1690
-            $tax_added     = $this->_get_tax_added($tax, $ticket);
1691
-            $template_args = array(
1692
-                'display_tax'       => ! empty($ticket) && $ticket->get('TKT_taxable')
1693
-                    ? ''
1694
-                    : ' style="display:none;"',
1695
-                'tax_id'            => $tax->ID(),
1696
-                'tkt_row'           => $ticket_row,
1697
-                'tax_label'         => $tax->get('PRC_name'),
1698
-                'tax_added'         => $tax_added,
1699
-                'tax_added_display' => EEH_Template::format_currency($tax_added, false, false),
1700
-                'tax_amount'        => $tax->get('PRC_amount'),
1701
-            );
1702
-            $template_args = apply_filters(
1703
-                'FHEE__espresso_events_Pricing_Hooks___get_tax_rows__template_args',
1704
-                $template_args,
1705
-                $ticket_row,
1706
-                $ticket,
1707
-                $this->_is_creating_event
1708
-            );
1709
-            $tax_rows      .= EEH_Template::display_template(
1710
-                PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_tax_row.template.php',
1711
-                $template_args,
1712
-                true
1713
-            );
1714
-        }
1715
-        return $tax_rows;
1716
-    }
1677
+	/**
1678
+	 * @param int            $ticket_row
1679
+	 * @param EE_Ticket|null $ticket
1680
+	 * @return string
1681
+	 * @throws DomainException
1682
+	 * @throws EE_Error
1683
+	 */
1684
+	protected function _get_tax_rows($ticket_row, $ticket)
1685
+	{
1686
+		$tax_rows = '';
1687
+		/** @var EE_Price[] $taxes */
1688
+		$taxes = empty($ticket) ? EE_Taxes::get_taxes_for_admin() : $ticket->get_ticket_taxes_for_admin();
1689
+		foreach ($taxes as $tax) {
1690
+			$tax_added     = $this->_get_tax_added($tax, $ticket);
1691
+			$template_args = array(
1692
+				'display_tax'       => ! empty($ticket) && $ticket->get('TKT_taxable')
1693
+					? ''
1694
+					: ' style="display:none;"',
1695
+				'tax_id'            => $tax->ID(),
1696
+				'tkt_row'           => $ticket_row,
1697
+				'tax_label'         => $tax->get('PRC_name'),
1698
+				'tax_added'         => $tax_added,
1699
+				'tax_added_display' => EEH_Template::format_currency($tax_added, false, false),
1700
+				'tax_amount'        => $tax->get('PRC_amount'),
1701
+			);
1702
+			$template_args = apply_filters(
1703
+				'FHEE__espresso_events_Pricing_Hooks___get_tax_rows__template_args',
1704
+				$template_args,
1705
+				$ticket_row,
1706
+				$ticket,
1707
+				$this->_is_creating_event
1708
+			);
1709
+			$tax_rows      .= EEH_Template::display_template(
1710
+				PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_tax_row.template.php',
1711
+				$template_args,
1712
+				true
1713
+			);
1714
+		}
1715
+		return $tax_rows;
1716
+	}
1717 1717
 
1718 1718
 
1719
-    /**
1720
-     * @param EE_Price       $tax
1721
-     * @param EE_Ticket|null $ticket
1722
-     * @return float|int
1723
-     * @throws EE_Error
1724
-     */
1725
-    protected function _get_tax_added(EE_Price $tax, $ticket)
1726
-    {
1727
-        $subtotal = empty($ticket) ? 0 : $ticket->get_ticket_subtotal();
1728
-        return $subtotal * $tax->get('PRC_amount') / 100;
1729
-    }
1719
+	/**
1720
+	 * @param EE_Price       $tax
1721
+	 * @param EE_Ticket|null $ticket
1722
+	 * @return float|int
1723
+	 * @throws EE_Error
1724
+	 */
1725
+	protected function _get_tax_added(EE_Price $tax, $ticket)
1726
+	{
1727
+		$subtotal = empty($ticket) ? 0 : $ticket->get_ticket_subtotal();
1728
+		return $subtotal * $tax->get('PRC_amount') / 100;
1729
+	}
1730 1730
 
1731 1731
 
1732
-    /**
1733
-     * @param int            $ticket_row
1734
-     * @param int            $price_row
1735
-     * @param EE_Price|null  $price
1736
-     * @param bool           $default
1737
-     * @param EE_Ticket|null $ticket
1738
-     * @param bool           $show_trash
1739
-     * @param bool           $show_create
1740
-     * @return mixed
1741
-     * @throws InvalidArgumentException
1742
-     * @throws InvalidInterfaceException
1743
-     * @throws InvalidDataTypeException
1744
-     * @throws DomainException
1745
-     * @throws EE_Error
1746
-     * @throws ReflectionException
1747
-     */
1748
-    protected function _get_ticket_price_row(
1749
-        $ticket_row,
1750
-        $price_row,
1751
-        $price,
1752
-        $default,
1753
-        $ticket,
1754
-        $show_trash = true,
1755
-        $show_create = true
1756
-    ) {
1757
-        $send_disabled = ! empty($ticket) && $ticket->get('TKT_deleted');
1758
-        $template_args = array(
1759
-            'tkt_row'               => $default && empty($ticket)
1760
-                ? 'TICKETNUM'
1761
-                : $ticket_row,
1762
-            'PRC_order'             => $default && empty($price)
1763
-                ? 'PRICENUM'
1764
-                : $price_row,
1765
-            'edit_prices_name'      => $default && empty($price)
1766
-                ? 'PRICENAMEATTR'
1767
-                : 'edit_prices',
1768
-            'price_type_selector'   => $default && empty($price)
1769
-                ? $this->_get_base_price_template($ticket_row, $price_row, $price, $default)
1770
-                : $this->_get_price_type_selector(
1771
-                    $ticket_row,
1772
-                    $price_row,
1773
-                    $price,
1774
-                    $default,
1775
-                    $send_disabled
1776
-                ),
1777
-            'PRC_ID'                => $default && empty($price)
1778
-                ? 0
1779
-                : $price->ID(),
1780
-            'PRC_is_default'        => $default && empty($price)
1781
-                ? 0
1782
-                : $price->get('PRC_is_default'),
1783
-            'PRC_name'              => $default && empty($price)
1784
-                ? ''
1785
-                : $price->get('PRC_name'),
1786
-            'price_currency_symbol' => EE_Registry::instance()->CFG->currency->sign,
1787
-            'show_plus_or_minus'    => $default && empty($price)
1788
-                ? ''
1789
-                : ' style="display:none;"',
1790
-            'show_plus'             => ($default && empty($price)) || ($price->is_discount() || $price->is_base_price())
1791
-                ? ' style="display:none;"'
1792
-                : '',
1793
-            'show_minus'            => ($default && empty($price)) || ! $price->is_discount()
1794
-                ? ' style="display:none;"'
1795
-                : '',
1796
-            'show_currency_symbol'  => ($default && empty($price)) || $price->is_percent()
1797
-                ? ' style="display:none"'
1798
-                : '',
1799
-            'PRC_amount'            => $default && empty($price)
1800
-                ? 0
1801
-                : $price->get_pretty('PRC_amount',
1802
-                    'localized_float'),
1803
-            'show_percentage'       => ($default && empty($price)) || ! $price->is_percent()
1804
-                ? ' style="display:none;"'
1805
-                : '',
1806
-            'show_trash_icon'       => $show_trash
1807
-                ? ''
1808
-                : ' style="display:none;"',
1809
-            'show_create_button'    => $show_create
1810
-                ? ''
1811
-                : ' style="display:none;"',
1812
-            'PRC_desc'              => $default && empty($price)
1813
-                ? ''
1814
-                : $price->get('PRC_desc'),
1815
-            'disabled'              => ! empty($ticket) && $ticket->get('TKT_deleted'),
1816
-        );
1817
-        $template_args = apply_filters(
1818
-            'FHEE__espresso_events_Pricing_Hooks___get_ticket_price_row__template_args',
1819
-            $template_args,
1820
-            $ticket_row,
1821
-            $price_row,
1822
-            $price,
1823
-            $default,
1824
-            $ticket,
1825
-            $show_trash,
1826
-            $show_create,
1827
-            $this->_is_creating_event
1828
-        );
1829
-        return EEH_Template::display_template(
1830
-            PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_price_row.template.php',
1831
-            $template_args,
1832
-            true
1833
-        );
1834
-    }
1732
+	/**
1733
+	 * @param int            $ticket_row
1734
+	 * @param int            $price_row
1735
+	 * @param EE_Price|null  $price
1736
+	 * @param bool           $default
1737
+	 * @param EE_Ticket|null $ticket
1738
+	 * @param bool           $show_trash
1739
+	 * @param bool           $show_create
1740
+	 * @return mixed
1741
+	 * @throws InvalidArgumentException
1742
+	 * @throws InvalidInterfaceException
1743
+	 * @throws InvalidDataTypeException
1744
+	 * @throws DomainException
1745
+	 * @throws EE_Error
1746
+	 * @throws ReflectionException
1747
+	 */
1748
+	protected function _get_ticket_price_row(
1749
+		$ticket_row,
1750
+		$price_row,
1751
+		$price,
1752
+		$default,
1753
+		$ticket,
1754
+		$show_trash = true,
1755
+		$show_create = true
1756
+	) {
1757
+		$send_disabled = ! empty($ticket) && $ticket->get('TKT_deleted');
1758
+		$template_args = array(
1759
+			'tkt_row'               => $default && empty($ticket)
1760
+				? 'TICKETNUM'
1761
+				: $ticket_row,
1762
+			'PRC_order'             => $default && empty($price)
1763
+				? 'PRICENUM'
1764
+				: $price_row,
1765
+			'edit_prices_name'      => $default && empty($price)
1766
+				? 'PRICENAMEATTR'
1767
+				: 'edit_prices',
1768
+			'price_type_selector'   => $default && empty($price)
1769
+				? $this->_get_base_price_template($ticket_row, $price_row, $price, $default)
1770
+				: $this->_get_price_type_selector(
1771
+					$ticket_row,
1772
+					$price_row,
1773
+					$price,
1774
+					$default,
1775
+					$send_disabled
1776
+				),
1777
+			'PRC_ID'                => $default && empty($price)
1778
+				? 0
1779
+				: $price->ID(),
1780
+			'PRC_is_default'        => $default && empty($price)
1781
+				? 0
1782
+				: $price->get('PRC_is_default'),
1783
+			'PRC_name'              => $default && empty($price)
1784
+				? ''
1785
+				: $price->get('PRC_name'),
1786
+			'price_currency_symbol' => EE_Registry::instance()->CFG->currency->sign,
1787
+			'show_plus_or_minus'    => $default && empty($price)
1788
+				? ''
1789
+				: ' style="display:none;"',
1790
+			'show_plus'             => ($default && empty($price)) || ($price->is_discount() || $price->is_base_price())
1791
+				? ' style="display:none;"'
1792
+				: '',
1793
+			'show_minus'            => ($default && empty($price)) || ! $price->is_discount()
1794
+				? ' style="display:none;"'
1795
+				: '',
1796
+			'show_currency_symbol'  => ($default && empty($price)) || $price->is_percent()
1797
+				? ' style="display:none"'
1798
+				: '',
1799
+			'PRC_amount'            => $default && empty($price)
1800
+				? 0
1801
+				: $price->get_pretty('PRC_amount',
1802
+					'localized_float'),
1803
+			'show_percentage'       => ($default && empty($price)) || ! $price->is_percent()
1804
+				? ' style="display:none;"'
1805
+				: '',
1806
+			'show_trash_icon'       => $show_trash
1807
+				? ''
1808
+				: ' style="display:none;"',
1809
+			'show_create_button'    => $show_create
1810
+				? ''
1811
+				: ' style="display:none;"',
1812
+			'PRC_desc'              => $default && empty($price)
1813
+				? ''
1814
+				: $price->get('PRC_desc'),
1815
+			'disabled'              => ! empty($ticket) && $ticket->get('TKT_deleted'),
1816
+		);
1817
+		$template_args = apply_filters(
1818
+			'FHEE__espresso_events_Pricing_Hooks___get_ticket_price_row__template_args',
1819
+			$template_args,
1820
+			$ticket_row,
1821
+			$price_row,
1822
+			$price,
1823
+			$default,
1824
+			$ticket,
1825
+			$show_trash,
1826
+			$show_create,
1827
+			$this->_is_creating_event
1828
+		);
1829
+		return EEH_Template::display_template(
1830
+			PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_price_row.template.php',
1831
+			$template_args,
1832
+			true
1833
+		);
1834
+	}
1835 1835
 
1836 1836
 
1837
-    /**
1838
-     * @param int      $ticket_row
1839
-     * @param int      $price_row
1840
-     * @param EE_Price $price
1841
-     * @param bool     $default
1842
-     * @param bool     $disabled
1843
-     * @return mixed
1844
-     * @throws ReflectionException
1845
-     * @throws InvalidArgumentException
1846
-     * @throws InvalidInterfaceException
1847
-     * @throws InvalidDataTypeException
1848
-     * @throws DomainException
1849
-     * @throws EE_Error
1850
-     */
1851
-    protected function _get_price_type_selector($ticket_row, $price_row, $price, $default, $disabled = false)
1852
-    {
1853
-        if ($price->is_base_price()) {
1854
-            return $this->_get_base_price_template(
1855
-                $ticket_row,
1856
-                $price_row,
1857
-                $price,
1858
-                $default
1859
-            );
1860
-        }
1861
-        return $this->_get_price_modifier_template(
1862
-            $ticket_row,
1863
-            $price_row,
1864
-            $price,
1865
-            $default,
1866
-            $disabled
1867
-        );
1868
-    }
1837
+	/**
1838
+	 * @param int      $ticket_row
1839
+	 * @param int      $price_row
1840
+	 * @param EE_Price $price
1841
+	 * @param bool     $default
1842
+	 * @param bool     $disabled
1843
+	 * @return mixed
1844
+	 * @throws ReflectionException
1845
+	 * @throws InvalidArgumentException
1846
+	 * @throws InvalidInterfaceException
1847
+	 * @throws InvalidDataTypeException
1848
+	 * @throws DomainException
1849
+	 * @throws EE_Error
1850
+	 */
1851
+	protected function _get_price_type_selector($ticket_row, $price_row, $price, $default, $disabled = false)
1852
+	{
1853
+		if ($price->is_base_price()) {
1854
+			return $this->_get_base_price_template(
1855
+				$ticket_row,
1856
+				$price_row,
1857
+				$price,
1858
+				$default
1859
+			);
1860
+		}
1861
+		return $this->_get_price_modifier_template(
1862
+			$ticket_row,
1863
+			$price_row,
1864
+			$price,
1865
+			$default,
1866
+			$disabled
1867
+		);
1868
+	}
1869 1869
 
1870 1870
 
1871
-    /**
1872
-     * @param int      $ticket_row
1873
-     * @param int      $price_row
1874
-     * @param EE_Price $price
1875
-     * @param bool     $default
1876
-     * @return mixed
1877
-     * @throws DomainException
1878
-     * @throws EE_Error
1879
-     */
1880
-    protected function _get_base_price_template($ticket_row, $price_row, $price, $default)
1881
-    {
1882
-        $template_args = array(
1883
-            'tkt_row'                   => $default ? 'TICKETNUM' : $ticket_row,
1884
-            'PRC_order'                 => $default && empty($price) ? 'PRICENUM' : $price_row,
1885
-            'PRT_ID'                    => $default && empty($price) ? 1 : $price->get('PRT_ID'),
1886
-            'PRT_name'                  => esc_html__('Price', 'event_espresso'),
1887
-            'price_selected_operator'   => '+',
1888
-            'price_selected_is_percent' => 0,
1889
-        );
1890
-        $template_args = apply_filters(
1891
-            'FHEE__espresso_events_Pricing_Hooks___get_base_price_template__template_args',
1892
-            $template_args,
1893
-            $ticket_row,
1894
-            $price_row,
1895
-            $price,
1896
-            $default,
1897
-            $this->_is_creating_event
1898
-        );
1899
-        return EEH_Template::display_template(
1900
-            PRICING_TEMPLATE_PATH . 'event_tickets_datetime_price_type_base.template.php',
1901
-            $template_args,
1902
-            true
1903
-        );
1904
-    }
1871
+	/**
1872
+	 * @param int      $ticket_row
1873
+	 * @param int      $price_row
1874
+	 * @param EE_Price $price
1875
+	 * @param bool     $default
1876
+	 * @return mixed
1877
+	 * @throws DomainException
1878
+	 * @throws EE_Error
1879
+	 */
1880
+	protected function _get_base_price_template($ticket_row, $price_row, $price, $default)
1881
+	{
1882
+		$template_args = array(
1883
+			'tkt_row'                   => $default ? 'TICKETNUM' : $ticket_row,
1884
+			'PRC_order'                 => $default && empty($price) ? 'PRICENUM' : $price_row,
1885
+			'PRT_ID'                    => $default && empty($price) ? 1 : $price->get('PRT_ID'),
1886
+			'PRT_name'                  => esc_html__('Price', 'event_espresso'),
1887
+			'price_selected_operator'   => '+',
1888
+			'price_selected_is_percent' => 0,
1889
+		);
1890
+		$template_args = apply_filters(
1891
+			'FHEE__espresso_events_Pricing_Hooks___get_base_price_template__template_args',
1892
+			$template_args,
1893
+			$ticket_row,
1894
+			$price_row,
1895
+			$price,
1896
+			$default,
1897
+			$this->_is_creating_event
1898
+		);
1899
+		return EEH_Template::display_template(
1900
+			PRICING_TEMPLATE_PATH . 'event_tickets_datetime_price_type_base.template.php',
1901
+			$template_args,
1902
+			true
1903
+		);
1904
+	}
1905 1905
 
1906 1906
 
1907
-    /**
1908
-     * @param int      $ticket_row
1909
-     * @param int      $price_row
1910
-     * @param EE_Price $price
1911
-     * @param bool     $default
1912
-     * @param bool     $disabled
1913
-     * @return mixed
1914
-     * @throws ReflectionException
1915
-     * @throws InvalidArgumentException
1916
-     * @throws InvalidInterfaceException
1917
-     * @throws InvalidDataTypeException
1918
-     * @throws DomainException
1919
-     * @throws EE_Error
1920
-     */
1921
-    protected function _get_price_modifier_template(
1922
-        $ticket_row,
1923
-        $price_row,
1924
-        $price,
1925
-        $default,
1926
-        $disabled = false
1927
-    ) {
1928
-        $select_name = $default && ! $price instanceof EE_Price
1929
-            ? 'edit_prices[TICKETNUM][PRICENUM][PRT_ID]'
1930
-            : 'edit_prices[' . $ticket_row . '][' . $price_row . '][PRT_ID]';
1931
-        /** @var EEM_Price_Type $price_type_model */
1932
-        $price_type_model       = EE_Registry::instance()->load_model('Price_Type');
1933
-        $price_types            = $price_type_model->get_all(array(
1934
-            array(
1935
-                'OR' => array(
1936
-                    'PBT_ID'  => '2',
1937
-                    'PBT_ID*' => '3',
1938
-                ),
1939
-            ),
1940
-        ));
1941
-        $all_price_types        = $default && ! $price instanceof EE_Price
1942
-            ? array(esc_html__('Select Modifier', 'event_espresso'))
1943
-            : array();
1944
-        $selected_price_type_id = $default && ! $price instanceof EE_Price ? 0 : $price->type();
1945
-        $price_option_spans     = '';
1946
-        //setup price types for selector
1947
-        foreach ($price_types as $price_type) {
1948
-            if (! $price_type instanceof EE_Price_Type) {
1949
-                continue;
1950
-            }
1951
-            $all_price_types[ $price_type->ID() ] = $price_type->get('PRT_name');
1952
-            //while we're in the loop let's setup the option spans used by js
1953
-            $span_args          = array(
1954
-                'PRT_ID'         => $price_type->ID(),
1955
-                'PRT_operator'   => $price_type->is_discount() ? '-' : '+',
1956
-                'PRT_is_percent' => $price_type->get('PRT_is_percent') ? 1 : 0,
1957
-            );
1958
-            $price_option_spans .= EEH_Template::display_template(
1959
-                PRICING_TEMPLATE_PATH . 'event_tickets_datetime_price_option_span.template.php',
1960
-                $span_args,
1961
-                true
1962
-            );
1963
-        }
1964
-        $select_name               = $disabled ? 'archive_price[' . $ticket_row . '][' . $price_row . '][PRT_ID]'
1965
-            : $select_name;
1966
-        $select_input              = new EE_Select_Input(
1967
-            $all_price_types,
1968
-            array(
1969
-                'default'               => $selected_price_type_id,
1970
-                'html_name'             => $select_name,
1971
-                'html_class'            => 'edit-price-PRT_ID',
1972
-                'html_other_attributes' => $disabled ? 'style="width:auto;" disabled' : 'style="width:auto;"',
1973
-            )
1974
-        );
1975
-        $price_selected_operator   = $price instanceof EE_Price && $price->is_discount() ? '-' : '+';
1976
-        $price_selected_operator   = $default && ! $price instanceof EE_Price ? '' : $price_selected_operator;
1977
-        $price_selected_is_percent = $price instanceof EE_Price && $price->is_percent() ? 1 : 0;
1978
-        $price_selected_is_percent = $default && ! $price instanceof EE_Price ? '' : $price_selected_is_percent;
1979
-        $template_args             = array(
1980
-            'tkt_row'                   => $default ? 'TICKETNUM' : $ticket_row,
1981
-            'PRC_order'                 => $default && ! $price instanceof EE_Price ? 'PRICENUM' : $price_row,
1982
-            'price_modifier_selector'   => $select_input->get_html_for_input(),
1983
-            'main_name'                 => $select_name,
1984
-            'selected_price_type_id'    => $selected_price_type_id,
1985
-            'price_option_spans'        => $price_option_spans,
1986
-            'price_selected_operator'   => $price_selected_operator,
1987
-            'price_selected_is_percent' => $price_selected_is_percent,
1988
-            'disabled'                  => $disabled,
1989
-        );
1990
-        $template_args             = apply_filters(
1991
-            'FHEE__espresso_events_Pricing_Hooks___get_price_modifier_template__template_args',
1992
-            $template_args,
1993
-            $ticket_row,
1994
-            $price_row,
1995
-            $price,
1996
-            $default,
1997
-            $disabled,
1998
-            $this->_is_creating_event
1999
-        );
2000
-        return EEH_Template::display_template(
2001
-            PRICING_TEMPLATE_PATH . 'event_tickets_datetime_price_modifier_selector.template.php',
2002
-            $template_args,
2003
-            true
2004
-        );
2005
-    }
1907
+	/**
1908
+	 * @param int      $ticket_row
1909
+	 * @param int      $price_row
1910
+	 * @param EE_Price $price
1911
+	 * @param bool     $default
1912
+	 * @param bool     $disabled
1913
+	 * @return mixed
1914
+	 * @throws ReflectionException
1915
+	 * @throws InvalidArgumentException
1916
+	 * @throws InvalidInterfaceException
1917
+	 * @throws InvalidDataTypeException
1918
+	 * @throws DomainException
1919
+	 * @throws EE_Error
1920
+	 */
1921
+	protected function _get_price_modifier_template(
1922
+		$ticket_row,
1923
+		$price_row,
1924
+		$price,
1925
+		$default,
1926
+		$disabled = false
1927
+	) {
1928
+		$select_name = $default && ! $price instanceof EE_Price
1929
+			? 'edit_prices[TICKETNUM][PRICENUM][PRT_ID]'
1930
+			: 'edit_prices[' . $ticket_row . '][' . $price_row . '][PRT_ID]';
1931
+		/** @var EEM_Price_Type $price_type_model */
1932
+		$price_type_model       = EE_Registry::instance()->load_model('Price_Type');
1933
+		$price_types            = $price_type_model->get_all(array(
1934
+			array(
1935
+				'OR' => array(
1936
+					'PBT_ID'  => '2',
1937
+					'PBT_ID*' => '3',
1938
+				),
1939
+			),
1940
+		));
1941
+		$all_price_types        = $default && ! $price instanceof EE_Price
1942
+			? array(esc_html__('Select Modifier', 'event_espresso'))
1943
+			: array();
1944
+		$selected_price_type_id = $default && ! $price instanceof EE_Price ? 0 : $price->type();
1945
+		$price_option_spans     = '';
1946
+		//setup price types for selector
1947
+		foreach ($price_types as $price_type) {
1948
+			if (! $price_type instanceof EE_Price_Type) {
1949
+				continue;
1950
+			}
1951
+			$all_price_types[ $price_type->ID() ] = $price_type->get('PRT_name');
1952
+			//while we're in the loop let's setup the option spans used by js
1953
+			$span_args          = array(
1954
+				'PRT_ID'         => $price_type->ID(),
1955
+				'PRT_operator'   => $price_type->is_discount() ? '-' : '+',
1956
+				'PRT_is_percent' => $price_type->get('PRT_is_percent') ? 1 : 0,
1957
+			);
1958
+			$price_option_spans .= EEH_Template::display_template(
1959
+				PRICING_TEMPLATE_PATH . 'event_tickets_datetime_price_option_span.template.php',
1960
+				$span_args,
1961
+				true
1962
+			);
1963
+		}
1964
+		$select_name               = $disabled ? 'archive_price[' . $ticket_row . '][' . $price_row . '][PRT_ID]'
1965
+			: $select_name;
1966
+		$select_input              = new EE_Select_Input(
1967
+			$all_price_types,
1968
+			array(
1969
+				'default'               => $selected_price_type_id,
1970
+				'html_name'             => $select_name,
1971
+				'html_class'            => 'edit-price-PRT_ID',
1972
+				'html_other_attributes' => $disabled ? 'style="width:auto;" disabled' : 'style="width:auto;"',
1973
+			)
1974
+		);
1975
+		$price_selected_operator   = $price instanceof EE_Price && $price->is_discount() ? '-' : '+';
1976
+		$price_selected_operator   = $default && ! $price instanceof EE_Price ? '' : $price_selected_operator;
1977
+		$price_selected_is_percent = $price instanceof EE_Price && $price->is_percent() ? 1 : 0;
1978
+		$price_selected_is_percent = $default && ! $price instanceof EE_Price ? '' : $price_selected_is_percent;
1979
+		$template_args             = array(
1980
+			'tkt_row'                   => $default ? 'TICKETNUM' : $ticket_row,
1981
+			'PRC_order'                 => $default && ! $price instanceof EE_Price ? 'PRICENUM' : $price_row,
1982
+			'price_modifier_selector'   => $select_input->get_html_for_input(),
1983
+			'main_name'                 => $select_name,
1984
+			'selected_price_type_id'    => $selected_price_type_id,
1985
+			'price_option_spans'        => $price_option_spans,
1986
+			'price_selected_operator'   => $price_selected_operator,
1987
+			'price_selected_is_percent' => $price_selected_is_percent,
1988
+			'disabled'                  => $disabled,
1989
+		);
1990
+		$template_args             = apply_filters(
1991
+			'FHEE__espresso_events_Pricing_Hooks___get_price_modifier_template__template_args',
1992
+			$template_args,
1993
+			$ticket_row,
1994
+			$price_row,
1995
+			$price,
1996
+			$default,
1997
+			$disabled,
1998
+			$this->_is_creating_event
1999
+		);
2000
+		return EEH_Template::display_template(
2001
+			PRICING_TEMPLATE_PATH . 'event_tickets_datetime_price_modifier_selector.template.php',
2002
+			$template_args,
2003
+			true
2004
+		);
2005
+	}
2006 2006
 
2007 2007
 
2008
-    /**
2009
-     * @param int              $datetime_row
2010
-     * @param int              $ticket_row
2011
-     * @param EE_Datetime|null $datetime
2012
-     * @param EE_Ticket|null   $ticket
2013
-     * @param array            $ticket_datetimes
2014
-     * @param bool             $default
2015
-     * @return mixed
2016
-     * @throws DomainException
2017
-     * @throws EE_Error
2018
-     */
2019
-    protected function _get_ticket_datetime_list_item(
2020
-        $datetime_row,
2021
-        $ticket_row,
2022
-        $datetime,
2023
-        $ticket,
2024
-        $ticket_datetimes = array(),
2025
-        $default
2026
-    ) {
2027
-        $tkt_datetimes = $ticket instanceof EE_Ticket && isset($ticket_datetimes[ $ticket->ID() ])
2028
-            ? $ticket_datetimes[ $ticket->ID() ]
2029
-            : array();
2030
-        $template_args = array(
2031
-            'dtt_row'                  => $default && ! $datetime instanceof EE_Datetime
2032
-                ? 'DTTNUM'
2033
-                : $datetime_row,
2034
-            'tkt_row'                  => $default
2035
-                ? 'TICKETNUM'
2036
-                : $ticket_row,
2037
-            'ticket_datetime_selected' => in_array($datetime_row, $tkt_datetimes, true)
2038
-                ? ' ticket-selected'
2039
-                : '',
2040
-            'ticket_datetime_checked'  => in_array($datetime_row, $tkt_datetimes, true)
2041
-                ? ' checked="checked"'
2042
-                : '',
2043
-            'DTT_name'                 => $default && empty($datetime)
2044
-                ? 'DTTNAME'
2045
-                : $datetime->get_dtt_display_name(true),
2046
-            'tkt_status_class'         => '',
2047
-        );
2048
-        $template_args = apply_filters(
2049
-            'FHEE__espresso_events_Pricing_Hooks___get_ticket_datetime_list_item__template_args',
2050
-            $template_args,
2051
-            $datetime_row,
2052
-            $ticket_row,
2053
-            $datetime,
2054
-            $ticket,
2055
-            $ticket_datetimes,
2056
-            $default,
2057
-            $this->_is_creating_event
2058
-        );
2059
-        return EEH_Template::display_template(
2060
-            PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_datetimes_list_item.template.php',
2061
-            $template_args,
2062
-            true
2063
-        );
2064
-    }
2008
+	/**
2009
+	 * @param int              $datetime_row
2010
+	 * @param int              $ticket_row
2011
+	 * @param EE_Datetime|null $datetime
2012
+	 * @param EE_Ticket|null   $ticket
2013
+	 * @param array            $ticket_datetimes
2014
+	 * @param bool             $default
2015
+	 * @return mixed
2016
+	 * @throws DomainException
2017
+	 * @throws EE_Error
2018
+	 */
2019
+	protected function _get_ticket_datetime_list_item(
2020
+		$datetime_row,
2021
+		$ticket_row,
2022
+		$datetime,
2023
+		$ticket,
2024
+		$ticket_datetimes = array(),
2025
+		$default
2026
+	) {
2027
+		$tkt_datetimes = $ticket instanceof EE_Ticket && isset($ticket_datetimes[ $ticket->ID() ])
2028
+			? $ticket_datetimes[ $ticket->ID() ]
2029
+			: array();
2030
+		$template_args = array(
2031
+			'dtt_row'                  => $default && ! $datetime instanceof EE_Datetime
2032
+				? 'DTTNUM'
2033
+				: $datetime_row,
2034
+			'tkt_row'                  => $default
2035
+				? 'TICKETNUM'
2036
+				: $ticket_row,
2037
+			'ticket_datetime_selected' => in_array($datetime_row, $tkt_datetimes, true)
2038
+				? ' ticket-selected'
2039
+				: '',
2040
+			'ticket_datetime_checked'  => in_array($datetime_row, $tkt_datetimes, true)
2041
+				? ' checked="checked"'
2042
+				: '',
2043
+			'DTT_name'                 => $default && empty($datetime)
2044
+				? 'DTTNAME'
2045
+				: $datetime->get_dtt_display_name(true),
2046
+			'tkt_status_class'         => '',
2047
+		);
2048
+		$template_args = apply_filters(
2049
+			'FHEE__espresso_events_Pricing_Hooks___get_ticket_datetime_list_item__template_args',
2050
+			$template_args,
2051
+			$datetime_row,
2052
+			$ticket_row,
2053
+			$datetime,
2054
+			$ticket,
2055
+			$ticket_datetimes,
2056
+			$default,
2057
+			$this->_is_creating_event
2058
+		);
2059
+		return EEH_Template::display_template(
2060
+			PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_datetimes_list_item.template.php',
2061
+			$template_args,
2062
+			true
2063
+		);
2064
+	}
2065 2065
 
2066 2066
 
2067
-    /**
2068
-     * @param array $all_datetimes
2069
-     * @param array $all_tickets
2070
-     * @return mixed
2071
-     * @throws ReflectionException
2072
-     * @throws InvalidArgumentException
2073
-     * @throws InvalidInterfaceException
2074
-     * @throws InvalidDataTypeException
2075
-     * @throws DomainException
2076
-     * @throws EE_Error
2077
-     */
2078
-    protected function _get_ticket_js_structure($all_datetimes = array(), $all_tickets = array())
2079
-    {
2080
-        $template_args = array(
2081
-            'default_datetime_edit_row'                => $this->_get_dtt_edit_row(
2082
-                'DTTNUM',
2083
-                null,
2084
-                true,
2085
-                $all_datetimes
2086
-            ),
2087
-            'default_ticket_row'                       => $this->_get_ticket_row(
2088
-                'TICKETNUM',
2089
-                null,
2090
-                array(),
2091
-                array(),
2092
-                true
2093
-            ),
2094
-            'default_price_row'                        => $this->_get_ticket_price_row(
2095
-                'TICKETNUM',
2096
-                'PRICENUM',
2097
-                null,
2098
-                true,
2099
-                null
2100
-            ),
2101
-            'default_price_rows'                       => '',
2102
-            'default_base_price_amount'                => 0,
2103
-            'default_base_price_name'                  => '',
2104
-            'default_base_price_description'           => '',
2105
-            'default_price_modifier_selector_row'      => $this->_get_price_modifier_template(
2106
-                'TICKETNUM',
2107
-                'PRICENUM',
2108
-                null,
2109
-                true
2110
-            ),
2111
-            'default_available_tickets_for_datetime'   => $this->_get_dtt_attached_tickets_row(
2112
-                'DTTNUM',
2113
-                null,
2114
-                array(),
2115
-                array(),
2116
-                true
2117
-            ),
2118
-            'existing_available_datetime_tickets_list' => '',
2119
-            'existing_available_ticket_datetimes_list' => '',
2120
-            'new_available_datetime_ticket_list_item'  => $this->_get_datetime_tickets_list_item(
2121
-                'DTTNUM',
2122
-                'TICKETNUM',
2123
-                null,
2124
-                null,
2125
-                array(),
2126
-                true
2127
-            ),
2128
-            'new_available_ticket_datetime_list_item'  => $this->_get_ticket_datetime_list_item(
2129
-                'DTTNUM',
2130
-                'TICKETNUM',
2131
-                null,
2132
-                null,
2133
-                array(),
2134
-                true
2135
-            ),
2136
-        );
2137
-        $ticket_row    = 1;
2138
-        foreach ($all_tickets as $ticket) {
2139
-            $template_args['existing_available_datetime_tickets_list'] .= $this->_get_datetime_tickets_list_item(
2140
-                'DTTNUM',
2141
-                $ticket_row,
2142
-                null,
2143
-                $ticket,
2144
-                array(),
2145
-                true
2146
-            );
2147
-            $ticket_row++;
2148
-        }
2149
-        $datetime_row = 1;
2150
-        foreach ($all_datetimes as $datetime) {
2151
-            $template_args['existing_available_ticket_datetimes_list'] .= $this->_get_ticket_datetime_list_item(
2152
-                $datetime_row,
2153
-                'TICKETNUM',
2154
-                $datetime,
2155
-                null,
2156
-                array(),
2157
-                true
2158
-            );
2159
-            $datetime_row++;
2160
-        }
2161
-        /** @var EEM_Price $price_model */
2162
-        $price_model    = EE_Registry::instance()->load_model('Price');
2163
-        $default_prices = $price_model->get_all_default_prices();
2164
-        $price_row      = 1;
2165
-        foreach ($default_prices as $price) {
2166
-            if (! $price instanceof EE_Price) {
2167
-                continue;
2168
-            }
2169
-            if ($price->is_base_price()) {
2170
-                $template_args['default_base_price_amount']      = $price->get_pretty(
2171
-                    'PRC_amount',
2172
-                    'localized_float'
2173
-                );
2174
-                $template_args['default_base_price_name']        = $price->get('PRC_name');
2175
-                $template_args['default_base_price_description'] = $price->get('PRC_desc');
2176
-                $price_row++;
2177
-                continue;
2178
-            }
2179
-            $show_trash                          = ! ((count($default_prices) > 1 && $price_row === 1)
2180
-                                                      || count($default_prices) === 1);
2181
-            $show_create                         = ! (count($default_prices) > 1
2182
-                                                      && count($default_prices)
2183
-                                                         !== $price_row);
2184
-            $template_args['default_price_rows'] .= $this->_get_ticket_price_row(
2185
-                'TICKETNUM',
2186
-                $price_row,
2187
-                $price,
2188
-                true,
2189
-                null,
2190
-                $show_trash,
2191
-                $show_create
2192
-            );
2193
-            $price_row++;
2194
-        }
2195
-        $template_args = apply_filters(
2196
-            'FHEE__espresso_events_Pricing_Hooks___get_ticket_js_structure__template_args',
2197
-            $template_args,
2198
-            $all_datetimes,
2199
-            $all_tickets,
2200
-            $this->_is_creating_event
2201
-        );
2202
-        return EEH_Template::display_template(
2203
-            PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_js_structure.template.php',
2204
-            $template_args,
2205
-            true
2206
-        );
2207
-    }
2067
+	/**
2068
+	 * @param array $all_datetimes
2069
+	 * @param array $all_tickets
2070
+	 * @return mixed
2071
+	 * @throws ReflectionException
2072
+	 * @throws InvalidArgumentException
2073
+	 * @throws InvalidInterfaceException
2074
+	 * @throws InvalidDataTypeException
2075
+	 * @throws DomainException
2076
+	 * @throws EE_Error
2077
+	 */
2078
+	protected function _get_ticket_js_structure($all_datetimes = array(), $all_tickets = array())
2079
+	{
2080
+		$template_args = array(
2081
+			'default_datetime_edit_row'                => $this->_get_dtt_edit_row(
2082
+				'DTTNUM',
2083
+				null,
2084
+				true,
2085
+				$all_datetimes
2086
+			),
2087
+			'default_ticket_row'                       => $this->_get_ticket_row(
2088
+				'TICKETNUM',
2089
+				null,
2090
+				array(),
2091
+				array(),
2092
+				true
2093
+			),
2094
+			'default_price_row'                        => $this->_get_ticket_price_row(
2095
+				'TICKETNUM',
2096
+				'PRICENUM',
2097
+				null,
2098
+				true,
2099
+				null
2100
+			),
2101
+			'default_price_rows'                       => '',
2102
+			'default_base_price_amount'                => 0,
2103
+			'default_base_price_name'                  => '',
2104
+			'default_base_price_description'           => '',
2105
+			'default_price_modifier_selector_row'      => $this->_get_price_modifier_template(
2106
+				'TICKETNUM',
2107
+				'PRICENUM',
2108
+				null,
2109
+				true
2110
+			),
2111
+			'default_available_tickets_for_datetime'   => $this->_get_dtt_attached_tickets_row(
2112
+				'DTTNUM',
2113
+				null,
2114
+				array(),
2115
+				array(),
2116
+				true
2117
+			),
2118
+			'existing_available_datetime_tickets_list' => '',
2119
+			'existing_available_ticket_datetimes_list' => '',
2120
+			'new_available_datetime_ticket_list_item'  => $this->_get_datetime_tickets_list_item(
2121
+				'DTTNUM',
2122
+				'TICKETNUM',
2123
+				null,
2124
+				null,
2125
+				array(),
2126
+				true
2127
+			),
2128
+			'new_available_ticket_datetime_list_item'  => $this->_get_ticket_datetime_list_item(
2129
+				'DTTNUM',
2130
+				'TICKETNUM',
2131
+				null,
2132
+				null,
2133
+				array(),
2134
+				true
2135
+			),
2136
+		);
2137
+		$ticket_row    = 1;
2138
+		foreach ($all_tickets as $ticket) {
2139
+			$template_args['existing_available_datetime_tickets_list'] .= $this->_get_datetime_tickets_list_item(
2140
+				'DTTNUM',
2141
+				$ticket_row,
2142
+				null,
2143
+				$ticket,
2144
+				array(),
2145
+				true
2146
+			);
2147
+			$ticket_row++;
2148
+		}
2149
+		$datetime_row = 1;
2150
+		foreach ($all_datetimes as $datetime) {
2151
+			$template_args['existing_available_ticket_datetimes_list'] .= $this->_get_ticket_datetime_list_item(
2152
+				$datetime_row,
2153
+				'TICKETNUM',
2154
+				$datetime,
2155
+				null,
2156
+				array(),
2157
+				true
2158
+			);
2159
+			$datetime_row++;
2160
+		}
2161
+		/** @var EEM_Price $price_model */
2162
+		$price_model    = EE_Registry::instance()->load_model('Price');
2163
+		$default_prices = $price_model->get_all_default_prices();
2164
+		$price_row      = 1;
2165
+		foreach ($default_prices as $price) {
2166
+			if (! $price instanceof EE_Price) {
2167
+				continue;
2168
+			}
2169
+			if ($price->is_base_price()) {
2170
+				$template_args['default_base_price_amount']      = $price->get_pretty(
2171
+					'PRC_amount',
2172
+					'localized_float'
2173
+				);
2174
+				$template_args['default_base_price_name']        = $price->get('PRC_name');
2175
+				$template_args['default_base_price_description'] = $price->get('PRC_desc');
2176
+				$price_row++;
2177
+				continue;
2178
+			}
2179
+			$show_trash                          = ! ((count($default_prices) > 1 && $price_row === 1)
2180
+													  || count($default_prices) === 1);
2181
+			$show_create                         = ! (count($default_prices) > 1
2182
+													  && count($default_prices)
2183
+														 !== $price_row);
2184
+			$template_args['default_price_rows'] .= $this->_get_ticket_price_row(
2185
+				'TICKETNUM',
2186
+				$price_row,
2187
+				$price,
2188
+				true,
2189
+				null,
2190
+				$show_trash,
2191
+				$show_create
2192
+			);
2193
+			$price_row++;
2194
+		}
2195
+		$template_args = apply_filters(
2196
+			'FHEE__espresso_events_Pricing_Hooks___get_ticket_js_structure__template_args',
2197
+			$template_args,
2198
+			$all_datetimes,
2199
+			$all_tickets,
2200
+			$this->_is_creating_event
2201
+		);
2202
+		return EEH_Template::display_template(
2203
+			PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_js_structure.template.php',
2204
+			$template_args,
2205
+			true
2206
+		);
2207
+	}
2208 2208
 } //end class espresso_events_Pricing_Hooks
Please login to merge, or discard this patch.
core/domain/services/admin/ExitModal.php 1 patch
Indentation   +56 added lines, -56 removed lines patch added patch discarded remove patch
@@ -18,68 +18,68 @@
 block discarded – undo
18 18
 class ExitModal
19 19
 {
20 20
 
21
-    /**
22
-     * @var Registry
23
-     */
24
-    private $assets_registry;
21
+	/**
22
+	 * @var Registry
23
+	 */
24
+	private $assets_registry;
25 25
 
26
-    /**
27
-     * ExitModal constructor.
28
-     *
29
-     * @param Registry $assets_registry
30
-     */
31
-    public function __construct(Registry $assets_registry)
32
-    {
33
-        $this->assets_registry = $assets_registry;
34
-        add_action('in_admin_footer', array($this, 'modalContainer'));
35
-        add_action('admin_enqueue_scripts', array($this, 'enqueues'));
36
-    }
26
+	/**
27
+	 * ExitModal constructor.
28
+	 *
29
+	 * @param Registry $assets_registry
30
+	 */
31
+	public function __construct(Registry $assets_registry)
32
+	{
33
+		$this->assets_registry = $assets_registry;
34
+		add_action('in_admin_footer', array($this, 'modalContainer'));
35
+		add_action('admin_enqueue_scripts', array($this, 'enqueues'));
36
+	}
37 37
 
38 38
 
39
-    /**
40
-     * Callback on in_admin_footer that is used to output the exit modal container.
41
-     */
42
-    public function modalContainer()
43
-    {
44
-        echo '<div id="ee-exit-survey-modal"></div>';
45
-    }
39
+	/**
40
+	 * Callback on in_admin_footer that is used to output the exit modal container.
41
+	 */
42
+	public function modalContainer()
43
+	{
44
+		echo '<div id="ee-exit-survey-modal"></div>';
45
+	}
46 46
 
47 47
 
48
-    /**
49
-     * Callback for `admin_enqueue_scripts` to take care of enqueueing scripts and styles specific to the modal.
50
-     *
51
-     * @throws InvalidArgumentException
52
-     */
53
-    public function enqueues()
54
-    {
55
-        $current_user = new WP_User(get_current_user_id());
56
-        $this->assets_registry->addData(
57
-            'exitModalInfo',
58
-            array(
59
-                'firstname' => htmlspecialchars($current_user->user_firstname),
60
-                'emailaddress' => htmlspecialchars($current_user->user_email),
61
-                'website' => htmlspecialchars(site_url()),
62
-                'isModalActive' => $this->isModalActive()
63
-            )
64
-        );
48
+	/**
49
+	 * Callback for `admin_enqueue_scripts` to take care of enqueueing scripts and styles specific to the modal.
50
+	 *
51
+	 * @throws InvalidArgumentException
52
+	 */
53
+	public function enqueues()
54
+	{
55
+		$current_user = new WP_User(get_current_user_id());
56
+		$this->assets_registry->addData(
57
+			'exitModalInfo',
58
+			array(
59
+				'firstname' => htmlspecialchars($current_user->user_firstname),
60
+				'emailaddress' => htmlspecialchars($current_user->user_email),
61
+				'website' => htmlspecialchars(site_url()),
62
+				'isModalActive' => $this->isModalActive()
63
+			)
64
+		);
65 65
 
66
-        wp_enqueue_script('ee-wp-plugins-page');
67
-        wp_enqueue_style('ee-wp-plugins-page');
68
-    }
66
+		wp_enqueue_script('ee-wp-plugins-page');
67
+		wp_enqueue_style('ee-wp-plugins-page');
68
+	}
69 69
 
70 70
 
71
-    /**
72
-     * Exposes a filter switch for turning off the enqueueing of the modal script.
73
-     * @return bool
74
-     */
75
-    private function isModalActive()
76
-    {
77
-        return filter_var(
78
-            apply_filters(
79
-                'FHEE__EventEspresso_core_domain_services_admin_ExitModal__isModalActive',
80
-                true
81
-            ),
82
-            FILTER_VALIDATE_BOOLEAN
83
-        );
84
-    }
71
+	/**
72
+	 * Exposes a filter switch for turning off the enqueueing of the modal script.
73
+	 * @return bool
74
+	 */
75
+	private function isModalActive()
76
+	{
77
+		return filter_var(
78
+			apply_filters(
79
+				'FHEE__EventEspresso_core_domain_services_admin_ExitModal__isModalActive',
80
+				true
81
+			),
82
+			FILTER_VALIDATE_BOOLEAN
83
+		);
84
+	}
85 85
 }
86 86
\ No newline at end of file
Please login to merge, or discard this patch.
modules/ical/EED_Ical.module.php 1 patch
Spacing   +57 added lines, -57 removed lines patch added patch discarded remove patch
@@ -19,7 +19,7 @@  discard block
 block discarded – undo
19 19
 	 * @return EED_Ical|EED_Module
20 20
 	 */
21 21
 	public static function instance() {
22
-		return parent::get_instance( __CLASS__ );
22
+		return parent::get_instance(__CLASS__);
23 23
 	}
24 24
 
25 25
 
@@ -34,12 +34,12 @@  discard block
 block discarded – undo
34 34
 		// create download buttons
35 35
 		add_filter(
36 36
 		    'FHEE__espresso_list_of_event_dates__datetime_html',
37
-            array( 'EED_Ical', 'generate_add_to_iCal_button' ),
37
+            array('EED_Ical', 'generate_add_to_iCal_button'),
38 38
             10,
39 39
             2
40 40
         );
41 41
 		 // process ics download request
42
-		EE_Config::register_route( 'download_ics_file', 'EED_Ical', 'download_ics_file' );
42
+		EE_Config::register_route('download_ics_file', 'EED_Ical', 'download_ics_file');
43 43
 	}
44 44
 
45 45
 
@@ -62,7 +62,7 @@  discard block
 block discarded – undo
62 62
 	 * @param    WP $WP
63 63
 	 * @return    void
64 64
 	 */
65
-	public function run( $WP ) {}
65
+	public function run($WP) {}
66 66
 
67 67
 
68 68
 
@@ -75,35 +75,35 @@  discard block
 block discarded – undo
75 75
      * @return    string
76 76
      * @throws \EE_Error
77 77
      */
78
-	public static function generate_add_to_iCal_button( $html, $datetime ) {
78
+	public static function generate_add_to_iCal_button($html, $datetime) {
79 79
 		// first verify a proper datetime object has been received
80
-		if ( $datetime instanceof EE_Datetime ) {
80
+		if ($datetime instanceof EE_Datetime) {
81 81
 			// set whether a link or submit button is shown
82
-			$iCal_type = apply_filters( 'FHEE__EED_Ical__generate_add_to_iCal_button__iCal_type', 'submit' );
82
+			$iCal_type = apply_filters('FHEE__EED_Ical__generate_add_to_iCal_button__iCal_type', 'submit');
83 83
 			// generate a link to the route we registered in set_hooks()
84
-			$URL = add_query_arg( array( 'ee' => 'download_ics_file', 'ics_id' => $datetime->ID() ), site_url() );
84
+			$URL = add_query_arg(array('ee' => 'download_ics_file', 'ics_id' => $datetime->ID()), site_url());
85 85
 			// what type ?
86
-			switch ( $iCal_type ) {
86
+			switch ($iCal_type) {
87 87
 				// submit buttons appear as buttons and are very compatible with a theme's style
88 88
 				case 'submit' :
89
-					$html .= '<form id="download-iCal-frm-' . $datetime->ID();
90
-					$html .= '" class="download-iCal-frm" action="' . $URL . '" method="post" >';
89
+					$html .= '<form id="download-iCal-frm-'.$datetime->ID();
90
+					$html .= '" class="download-iCal-frm" action="'.$URL.'" method="post" >';
91 91
 					$html .= '<input type="submit" class="ee-ical-sbmt" value="&#xf145;" title="';
92
-					$html .= __( 'Add to iCal Calendar', 'event_espresso' ) . '"/>';
92
+					$html .= __('Add to iCal Calendar', 'event_espresso').'"/>';
93 93
 					$html .= '</form>';
94 94
 					break;
95 95
 				// buttons are just links that have been styled to appear as buttons,
96 96
                 // but may not be blend with a theme as well as submit buttons
97 97
 				case 'button' :
98
-					$html .= '<a class="ee-ical-btn small ee-button ee-roundish" href="' . $URL;
99
-					$html .= '" title="' . __( 'Add to iCal Calendar', 'event_espresso' ) . '">';
98
+					$html .= '<a class="ee-ical-btn small ee-button ee-roundish" href="'.$URL;
99
+					$html .= '" title="'.__('Add to iCal Calendar', 'event_espresso').'">';
100 100
 					$html .= ' <span class="dashicons dashicons-calendar"></span>';
101 101
 					$html .= '</a>';
102 102
 					break;
103 103
 				// links are just links that use the calendar dashicon
104 104
 				case 'icon' :
105
-					$html .= '<a class="ee-ical-lnk" href="' . $URL . '" title="';
106
-					$html .= __( 'Add to iCal Calendar', 'event_espresso' ) . '">';
105
+					$html .= '<a class="ee-ical-lnk" href="'.$URL.'" title="';
106
+					$html .= __('Add to iCal Calendar', 'event_espresso').'">';
107 107
 					$html .= ' <span class="dashicons dashicons-calendar"></span>';
108 108
 					$html .= '</a>';
109 109
 					break;
@@ -122,29 +122,29 @@  discard block
 block discarded – undo
122 122
      * @throws \EE_Error
123 123
      */
124 124
 	public static function download_ics_file() {
125
-		if ( EE_Registry::instance()->REQ->is_set( 'ics_id' )) {
126
-			$DTT_ID = absint( EE_Registry::instance()->REQ->get( 'ics_id' ));
127
-			$datetime = EE_Registry::instance()->load_model( 'Datetime' )->get_one_by_ID( $DTT_ID );
128
-			if ( $datetime instanceof EE_Datetime ) {
125
+		if (EE_Registry::instance()->REQ->is_set('ics_id')) {
126
+			$DTT_ID = absint(EE_Registry::instance()->REQ->get('ics_id'));
127
+			$datetime = EE_Registry::instance()->load_model('Datetime')->get_one_by_ID($DTT_ID);
128
+			if ($datetime instanceof EE_Datetime) {
129 129
 				// get related event, venues, and event categories
130 130
 				$event = $datetime->event();
131 131
 				// get related category Term object and it's name
132 132
 				$category = $event->first_event_category();
133
-				if ( $category instanceof EE_Term ) {
133
+				if ($category instanceof EE_Term) {
134 134
 					$category = $category->name();
135 135
 				}
136 136
 				$location = '';
137 137
 				// get first related venue and convert to CSV string
138
-				$venue = $event->venues(array( 'limit'=>1 ));
139
-				if ( is_array( $venue ) && ! empty( $venue )) {
140
-					$venue = array_shift( $venue );
141
-					if ( $venue instanceof EE_Venue ) {
142
-						$location = espresso_venue_raw_address( 'inline', $venue->ID(), FALSE );
138
+				$venue = $event->venues(array('limit'=>1));
139
+				if (is_array($venue) && ! empty($venue)) {
140
+					$venue = array_shift($venue);
141
+					if ($venue instanceof EE_Venue) {
142
+						$location = espresso_venue_raw_address('inline', $venue->ID(), FALSE);
143 143
 					}
144 144
 				}
145 145
 
146 146
 				//Generate filename
147
-				$filename = $event->slug() . '-' . $datetime->start_date( 'Y-m-d' ) . '.ics';
147
+				$filename = $event->slug().'-'.$datetime->start_date('Y-m-d').'.ics';
148 148
 
149 149
 				//Check the datetime status has not been cancelled and set the ics value accordingly
150 150
 				$status = $datetime->get_active_status();
@@ -153,48 +153,48 @@  discard block
 block discarded – undo
153 153
 				// Create array of ics details, escape strings, convert timestamps to ics format, etc
154 154
 				$ics_data = array(
155 155
 					'ORGANIZER_NAME' => EE_Registry::instance()->CFG->organization->name,
156
-					'UID' => md5( $event->name() . $event->ID() . $datetime->ID() ),
156
+					'UID' => md5($event->name().$event->ID().$datetime->ID()),
157 157
 					'ORGANIZER' => EE_Registry::instance()->CFG->organization->email,
158
-					'DTSTAMP' => date( EED_Ical::iCal_datetime_format ),
158
+					'DTSTAMP' => date(EED_Ical::iCal_datetime_format),
159 159
 					'LOCATION' => $location,
160 160
 					'SUMMARY' => $event->name(),
161
-					'DESCRIPTION' => wp_strip_all_tags( $event->description() ),
161
+					'DESCRIPTION' => wp_strip_all_tags($event->description()),
162 162
 					'STATUS' => $status,
163 163
 					'CATEGORIES' => $category,
164
-					'URL;VALUE=URI' => get_permalink( $event->ID() ),
165
-					'DTSTART' => date( EED_Ical::iCal_datetime_format, $datetime->start() ),
166
-					'DTEND' => date( EED_Ical::iCal_datetime_format, $datetime->end() ),
164
+					'URL;VALUE=URI' => get_permalink($event->ID()),
165
+					'DTSTART' => date(EED_Ical::iCal_datetime_format, $datetime->start()),
166
+					'DTEND' => date(EED_Ical::iCal_datetime_format, $datetime->end()),
167 167
 				);
168 168
 
169 169
 				//Filter the values used within the ics output.
170 170
 				//NOTE - all values within ics_data will be escaped automatically.
171
-				$ics_data = apply_filters( 'FHEE__EED_Ical__download_ics_file_ics_data', $ics_data, $datetime );
171
+				$ics_data = apply_filters('FHEE__EED_Ical__download_ics_file_ics_data', $ics_data, $datetime);
172 172
 
173 173
 				//Escape all ics data
174
-				foreach( $ics_data as $key => $value ) {
174
+				foreach ($ics_data as $key => $value) {
175 175
 					//Description is escaped differently from all all values
176
-					if( $key === 'DESCRIPTION' ) {
177
-						$ics_data[$key] = EED_Ical::_escape_ICal_description( wp_strip_all_tags( $value ) );
176
+					if ($key === 'DESCRIPTION') {
177
+						$ics_data[$key] = EED_Ical::_escape_ICal_description(wp_strip_all_tags($value));
178 178
 					} else {
179
-						$ics_data[$key] = EED_Ical::_escape_ICal_data( $value );
179
+						$ics_data[$key] = EED_Ical::_escape_ICal_data($value);
180 180
 					}
181 181
 				}
182 182
 
183 183
 				//Pull the organizer name from ics_data and remove it from the array.
184
-				$organizer_name = isset( $ics_data['ORGANIZER_NAME'] ) ? $ics_data['ORGANIZER_NAME'] : '';
185
-				unset( $ics_data['ORGANIZER_NAME'] );
184
+				$organizer_name = isset($ics_data['ORGANIZER_NAME']) ? $ics_data['ORGANIZER_NAME'] : '';
185
+				unset($ics_data['ORGANIZER_NAME']);
186 186
 
187 187
 				// set headers
188
-				header( 'Content-type: text/calendar; charset=utf-8' );
189
-				header( 'Content-Disposition: attachment; filename="' . $filename . '"' );
190
-				header( 'Cache-Control: private, max-age=0, must-revalidate' );
191
-				header( 'Pragma: public' );
192
-				header( 'Content-Type: application/octet-stream' );
193
-				header( 'Content-Type: application/force-download' );
194
-				header( 'Cache-Control: no-cache, must-revalidate' );
195
-				header( 'Content-Transfer-Encoding: binary' );
196
-				header( 'Expires: Sat, 26 Jul 1997 05:00:00 GMT' ); // past date
197
-				ini_set( 'zlib.output_compression', '0' );
188
+				header('Content-type: text/calendar; charset=utf-8');
189
+				header('Content-Disposition: attachment; filename="'.$filename.'"');
190
+				header('Cache-Control: private, max-age=0, must-revalidate');
191
+				header('Pragma: public');
192
+				header('Content-Type: application/octet-stream');
193
+				header('Content-Type: application/force-download');
194
+				header('Cache-Control: no-cache, must-revalidate');
195
+				header('Content-Transfer-Encoding: binary');
196
+				header('Expires: Sat, 26 Jul 1997 05:00:00 GMT'); // past date
197
+				ini_set('zlib.output_compression', '0');
198 198
 				// echo the output
199 199
 				echo "BEGIN:VCALENDAR\r\n";
200 200
 				echo "VERSION:2.0\r\n";
@@ -203,8 +203,8 @@  discard block
 block discarded – undo
203 203
 				echo "BEGIN:VEVENT\r\n";
204 204
 				
205 205
 				//Output all remaining values from ics_data.
206
-				foreach( $ics_data as $key => $value ) {
207
-					echo $key . ':' . $value . "\r\n";
206
+				foreach ($ics_data as $key => $value) {
207
+					echo $key.':'.$value."\r\n";
208 208
 				}
209 209
 
210 210
 				echo "END:VEVENT\r\n";
@@ -223,8 +223,8 @@  discard block
 block discarded – undo
223 223
 	 *  	@param	string $string
224 224
 	 *  	@return	string
225 225
 	 */
226
-	private static function _escape_ICal_data( $string = '' ) {
227
-		return preg_replace( '/([\,;])/', '\\\$1', $string );
226
+	private static function _escape_ICal_data($string = '') {
227
+		return preg_replace('/([\,;])/', '\\\$1', $string);
228 228
 	}
229 229
 
230 230
 	/**
@@ -234,13 +234,13 @@  discard block
 block discarded – undo
234 234
 	 *  	@param	string $description
235 235
 	 *  	@return	string
236 236
 	 */
237
-	private static function _escape_ICal_description( $description = '' ) {
237
+	private static function _escape_ICal_description($description = '') {
238 238
 
239 239
 			//Escape special chars within the description
240
-			$description = EED_Ical::_escape_ICal_data( $description );
240
+			$description = EED_Ical::_escape_ICal_data($description);
241 241
 
242 242
 		    //Remove line breaks and output in iCal format
243
-		    $description = str_replace( array( "\r\n", "\n"), '\n', $description );
243
+		    $description = str_replace(array("\r\n", "\n"), '\n', $description);
244 244
 
245 245
 		return $description;
246 246
 	}
Please login to merge, or discard this patch.
core/services/assets/I18nRegistry.php 2 patches
Indentation   +224 added lines, -224 removed lines patch added patch discarded remove patch
@@ -14,228 +14,228 @@
 block discarded – undo
14 14
  */
15 15
 class I18nRegistry
16 16
 {
17
-    /**
18
-     * @var DomainInterface
19
-     */
20
-    private $domain;
21
-
22
-    /**
23
-     * Will hold all registered i18n scripts.
24
-     *
25
-     * @var array
26
-     */
27
-    private $registered_i18n = array();
28
-
29
-
30
-    /**
31
-     * Used to hold queued translations for the chunks loading in a view.
32
-     *
33
-     * @var array
34
-     */
35
-    private $queued_handle_translations = array();
36
-
37
-
38
-    /**
39
-     * Obtained from the generated json file from the all javascript using wp.i18n with a map of script handle names to
40
-     * translation strings.
41
-     *
42
-     * @var array
43
-     */
44
-    private $i18n_map;
45
-
46
-
47
-    /**
48
-     * I18nRegistry constructor.
49
-     *
50
-     * @param array() $i18n_map  An array of script handle names and the strings translated for those handles.  If not
51
-     *                            provided, the class will look for map in root of plugin with filename of
52
-     *                            'translation-map.json'.
53
-     * @param DomainInterface $domain
54
-     */
55
-    public function __construct(array $i18n_map = array(), DomainInterface $domain)
56
-    {
57
-        $this->domain = $domain;
58
-        $this->setI18nMap($i18n_map);
59
-        add_filter('print_scripts_array', array($this, 'queueI18n'));
60
-    }
61
-
62
-
63
-    /**
64
-     * Used to register a script that has i18n strings for its $handle
65
-     *
66
-     * @param string $handle The script handle reference.
67
-     * @param string $domain The i18n domain for the strings.
68
-     */
69
-    public function registerScriptI18n($handle, $domain = 'event_espresso')
70
-    {
71
-        $this->registered_i18n[$handle] = $domain;
72
-    }
73
-
74
-
75
-
76
-    /**
77
-     * Callback on print_scripts_array to listen for scripts enqueued and handle setting up the localized data.
78
-     *
79
-     * @param array $handles Array of registered script handles.
80
-     * @return array
81
-     */
82
-    public function queueI18n(array $handles)
83
-    {
84
-        if (empty($this->registered_i18n) || empty($this->i18n_map)) {
85
-            return $handles;
86
-        }
87
-        foreach ($handles as $handle) {
88
-            $this->queueI18nTranslationsForHandle($handle);
89
-        }
90
-        if ($this->queued_handle_translations) {
91
-            foreach ($this->queued_handle_translations as $handle => $translations_for_domain) {
92
-                $this->registerInlineScript(
93
-                    $handle,
94
-                    $translations_for_domain['translations'],
95
-                    $translations_for_domain['domain']
96
-                );
97
-            }
98
-        }
99
-        return $handles;
100
-    }
101
-
102
-
103
-    /**
104
-     * Registers inline script with translations for given handle and domain.
105
-     *
106
-     * @param string $handle       Handle used to register javascript file containing translations.
107
-     * @param array  $translations Array of string translations.
108
-     * @param string $domain       Domain for translations.  If left empty then strings are registered with the default
109
-     *                             domain for the javascript.
110
-     */
111
-    private function registerInlineScript($handle, array $translations, $domain)
112
-    {
113
-        $script = $domain ?
114
-            'wp.i18n.setLocaleData( ' . wp_json_encode($translations) . ', ' . $domain . ' );' :
115
-            'wp.i18n.setLocaleData( ' . wp_json_encode($translations) . ' );';
116
-        wp_add_inline_script($handle, $script, 'before');
117
-    }
118
-
119
-
120
-    /**
121
-     * Queues up the translation strings for the given handle.
122
-     *
123
-     * @param string $handle The script handle being queued up.
124
-     */
125
-    private function queueI18nTranslationsForHandle($handle)
126
-    {
127
-        if (isset($this->registered_i18n[$handle])) {
128
-            $domain = $this->registered_i18n[$handle];
129
-            $translations = $this->getJedLocaleDataForDomainAndChunk($handle, $domain);
130
-            if (count($translations) > 1) {
131
-                $this->queued_handle_translations[$handle] = array(
132
-                    'domain'       => $domain,
133
-                    'translations' => $translations,
134
-                );
135
-            }
136
-            unset($this->registered_i18n[$handle]);
137
-        }
138
-    }
139
-
140
-
141
-    /**
142
-     * Sets the internal i18n_map property.
143
-     * If $chunk_map is empty or not an array, will attempt to load a chunk map from a default named map.
144
-     *
145
-     * @param array $i18n_map  If provided, an array of translation strings indexed by script handle names they
146
-     *                         correspond to.
147
-     */
148
-    private function setI18nMap(array $i18n_map)
149
-    {
150
-        if (empty($i18n_map)) {
151
-            $i18n_map = file_exists($this->domain->pluginPath() . 'translation-map.json')
152
-                ? json_decode(
153
-                        file_get_contents($this->domain->pluginPath() . 'translation-map.json'),
154
-                        true
155
-                    )
156
-                : array();
157
-        }
158
-        $this->i18n_map = $i18n_map;
159
-    }
160
-
161
-
162
-    /**
163
-     * Get the jed locale data for a given $handle and domain
164
-     *
165
-     * @param string $handle The name for the script handle we want strings returned for.
166
-     * @param string $domain The i18n domain.
167
-     * @return array
168
-     */
169
-    protected function getJedLocaleDataForDomainAndChunk($handle, $domain)
170
-    {
171
-        $translations = $this->getJedLocaleData($domain);
172
-        // get index for adding back after extracting strings for this $chunk.
173
-        $index = $translations[''];
174
-        $translations = $this->getLocaleDataMatchingMap(
175
-            $this->getOriginalStringsForHandleFromMap($handle),
176
-            $translations
177
-        );
178
-        $translations[''] = $index;
179
-        return $translations;
180
-    }
181
-
182
-
183
-    /**
184
-     * Get locale data for given strings from given translations
185
-     *
186
-     * @param array $string_set   This is the subset of strings (msgIds) we want to extract from the translations array.
187
-     * @param array $translations Translation data to extra strings from.
188
-     * @return array
189
-     */
190
-    protected function getLocaleDataMatchingMap(array $string_set, array $translations)
191
-    {
192
-        if (empty($string_set)) {
193
-            return array();
194
-        }
195
-        // some strings with quotes in them will break on the array_flip, so making sure quotes in the string are
196
-        // slashed also filter falsey values.
197
-        $string_set = array_unique(array_filter(wp_slash($string_set)));
198
-        return array_intersect_key($translations, array_flip($string_set));
199
-    }
200
-
201
-
202
-    /**
203
-     * Get original strings to translate for the given chunk from the map
204
-     *
205
-     * @param string $handle The script handle name to get strings from the map for.
206
-     * @return array
207
-     */
208
-    protected function getOriginalStringsForHandleFromMap($handle)
209
-    {
210
-        return isset($this->i18n_map[$handle]) ? $this->i18n_map[$handle] : array();
211
-    }
212
-
213
-
214
-    /**
215
-     * Returns Jed-formatted localization data.
216
-     *
217
-     * @param  string $domain Translation domain.
218
-     * @return array
219
-     */
220
-    private function getJedLocaleData($domain)
221
-    {
222
-        $translations = get_translations_for_domain($domain);
223
-
224
-        $locale = array(
225
-            '' => array(
226
-                'domain' => $domain,
227
-                'lang'   => is_admin() ? get_user_locale() : get_locale(),
228
-            ),
229
-        );
230
-
231
-        if (! empty($translations->headers['Plural-Forms'])) {
232
-            $locale['']['plural_forms'] = $translations->headers['Plural-Forms'];
233
-        }
234
-
235
-        foreach ($translations->entries as $msgid => $entry) {
236
-            $locale[$msgid] = $entry->translations;
237
-        }
238
-
239
-        return $locale;
240
-    }
17
+	/**
18
+	 * @var DomainInterface
19
+	 */
20
+	private $domain;
21
+
22
+	/**
23
+	 * Will hold all registered i18n scripts.
24
+	 *
25
+	 * @var array
26
+	 */
27
+	private $registered_i18n = array();
28
+
29
+
30
+	/**
31
+	 * Used to hold queued translations for the chunks loading in a view.
32
+	 *
33
+	 * @var array
34
+	 */
35
+	private $queued_handle_translations = array();
36
+
37
+
38
+	/**
39
+	 * Obtained from the generated json file from the all javascript using wp.i18n with a map of script handle names to
40
+	 * translation strings.
41
+	 *
42
+	 * @var array
43
+	 */
44
+	private $i18n_map;
45
+
46
+
47
+	/**
48
+	 * I18nRegistry constructor.
49
+	 *
50
+	 * @param array() $i18n_map  An array of script handle names and the strings translated for those handles.  If not
51
+	 *                            provided, the class will look for map in root of plugin with filename of
52
+	 *                            'translation-map.json'.
53
+	 * @param DomainInterface $domain
54
+	 */
55
+	public function __construct(array $i18n_map = array(), DomainInterface $domain)
56
+	{
57
+		$this->domain = $domain;
58
+		$this->setI18nMap($i18n_map);
59
+		add_filter('print_scripts_array', array($this, 'queueI18n'));
60
+	}
61
+
62
+
63
+	/**
64
+	 * Used to register a script that has i18n strings for its $handle
65
+	 *
66
+	 * @param string $handle The script handle reference.
67
+	 * @param string $domain The i18n domain for the strings.
68
+	 */
69
+	public function registerScriptI18n($handle, $domain = 'event_espresso')
70
+	{
71
+		$this->registered_i18n[$handle] = $domain;
72
+	}
73
+
74
+
75
+
76
+	/**
77
+	 * Callback on print_scripts_array to listen for scripts enqueued and handle setting up the localized data.
78
+	 *
79
+	 * @param array $handles Array of registered script handles.
80
+	 * @return array
81
+	 */
82
+	public function queueI18n(array $handles)
83
+	{
84
+		if (empty($this->registered_i18n) || empty($this->i18n_map)) {
85
+			return $handles;
86
+		}
87
+		foreach ($handles as $handle) {
88
+			$this->queueI18nTranslationsForHandle($handle);
89
+		}
90
+		if ($this->queued_handle_translations) {
91
+			foreach ($this->queued_handle_translations as $handle => $translations_for_domain) {
92
+				$this->registerInlineScript(
93
+					$handle,
94
+					$translations_for_domain['translations'],
95
+					$translations_for_domain['domain']
96
+				);
97
+			}
98
+		}
99
+		return $handles;
100
+	}
101
+
102
+
103
+	/**
104
+	 * Registers inline script with translations for given handle and domain.
105
+	 *
106
+	 * @param string $handle       Handle used to register javascript file containing translations.
107
+	 * @param array  $translations Array of string translations.
108
+	 * @param string $domain       Domain for translations.  If left empty then strings are registered with the default
109
+	 *                             domain for the javascript.
110
+	 */
111
+	private function registerInlineScript($handle, array $translations, $domain)
112
+	{
113
+		$script = $domain ?
114
+			'wp.i18n.setLocaleData( ' . wp_json_encode($translations) . ', ' . $domain . ' );' :
115
+			'wp.i18n.setLocaleData( ' . wp_json_encode($translations) . ' );';
116
+		wp_add_inline_script($handle, $script, 'before');
117
+	}
118
+
119
+
120
+	/**
121
+	 * Queues up the translation strings for the given handle.
122
+	 *
123
+	 * @param string $handle The script handle being queued up.
124
+	 */
125
+	private function queueI18nTranslationsForHandle($handle)
126
+	{
127
+		if (isset($this->registered_i18n[$handle])) {
128
+			$domain = $this->registered_i18n[$handle];
129
+			$translations = $this->getJedLocaleDataForDomainAndChunk($handle, $domain);
130
+			if (count($translations) > 1) {
131
+				$this->queued_handle_translations[$handle] = array(
132
+					'domain'       => $domain,
133
+					'translations' => $translations,
134
+				);
135
+			}
136
+			unset($this->registered_i18n[$handle]);
137
+		}
138
+	}
139
+
140
+
141
+	/**
142
+	 * Sets the internal i18n_map property.
143
+	 * If $chunk_map is empty or not an array, will attempt to load a chunk map from a default named map.
144
+	 *
145
+	 * @param array $i18n_map  If provided, an array of translation strings indexed by script handle names they
146
+	 *                         correspond to.
147
+	 */
148
+	private function setI18nMap(array $i18n_map)
149
+	{
150
+		if (empty($i18n_map)) {
151
+			$i18n_map = file_exists($this->domain->pluginPath() . 'translation-map.json')
152
+				? json_decode(
153
+						file_get_contents($this->domain->pluginPath() . 'translation-map.json'),
154
+						true
155
+					)
156
+				: array();
157
+		}
158
+		$this->i18n_map = $i18n_map;
159
+	}
160
+
161
+
162
+	/**
163
+	 * Get the jed locale data for a given $handle and domain
164
+	 *
165
+	 * @param string $handle The name for the script handle we want strings returned for.
166
+	 * @param string $domain The i18n domain.
167
+	 * @return array
168
+	 */
169
+	protected function getJedLocaleDataForDomainAndChunk($handle, $domain)
170
+	{
171
+		$translations = $this->getJedLocaleData($domain);
172
+		// get index for adding back after extracting strings for this $chunk.
173
+		$index = $translations[''];
174
+		$translations = $this->getLocaleDataMatchingMap(
175
+			$this->getOriginalStringsForHandleFromMap($handle),
176
+			$translations
177
+		);
178
+		$translations[''] = $index;
179
+		return $translations;
180
+	}
181
+
182
+
183
+	/**
184
+	 * Get locale data for given strings from given translations
185
+	 *
186
+	 * @param array $string_set   This is the subset of strings (msgIds) we want to extract from the translations array.
187
+	 * @param array $translations Translation data to extra strings from.
188
+	 * @return array
189
+	 */
190
+	protected function getLocaleDataMatchingMap(array $string_set, array $translations)
191
+	{
192
+		if (empty($string_set)) {
193
+			return array();
194
+		}
195
+		// some strings with quotes in them will break on the array_flip, so making sure quotes in the string are
196
+		// slashed also filter falsey values.
197
+		$string_set = array_unique(array_filter(wp_slash($string_set)));
198
+		return array_intersect_key($translations, array_flip($string_set));
199
+	}
200
+
201
+
202
+	/**
203
+	 * Get original strings to translate for the given chunk from the map
204
+	 *
205
+	 * @param string $handle The script handle name to get strings from the map for.
206
+	 * @return array
207
+	 */
208
+	protected function getOriginalStringsForHandleFromMap($handle)
209
+	{
210
+		return isset($this->i18n_map[$handle]) ? $this->i18n_map[$handle] : array();
211
+	}
212
+
213
+
214
+	/**
215
+	 * Returns Jed-formatted localization data.
216
+	 *
217
+	 * @param  string $domain Translation domain.
218
+	 * @return array
219
+	 */
220
+	private function getJedLocaleData($domain)
221
+	{
222
+		$translations = get_translations_for_domain($domain);
223
+
224
+		$locale = array(
225
+			'' => array(
226
+				'domain' => $domain,
227
+				'lang'   => is_admin() ? get_user_locale() : get_locale(),
228
+			),
229
+		);
230
+
231
+		if (! empty($translations->headers['Plural-Forms'])) {
232
+			$locale['']['plural_forms'] = $translations->headers['Plural-Forms'];
233
+		}
234
+
235
+		foreach ($translations->entries as $msgid => $entry) {
236
+			$locale[$msgid] = $entry->translations;
237
+		}
238
+
239
+		return $locale;
240
+	}
241 241
 }
242 242
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +4 added lines, -5 removed lines patch added patch discarded remove patch
@@ -111,8 +111,7 @@  discard block
 block discarded – undo
111 111
     private function registerInlineScript($handle, array $translations, $domain)
112 112
     {
113 113
         $script = $domain ?
114
-            'wp.i18n.setLocaleData( ' . wp_json_encode($translations) . ', ' . $domain . ' );' :
115
-            'wp.i18n.setLocaleData( ' . wp_json_encode($translations) . ' );';
114
+            'wp.i18n.setLocaleData( '.wp_json_encode($translations).', '.$domain.' );' : 'wp.i18n.setLocaleData( '.wp_json_encode($translations).' );';
116 115
         wp_add_inline_script($handle, $script, 'before');
117 116
     }
118 117
 
@@ -148,9 +147,9 @@  discard block
 block discarded – undo
148 147
     private function setI18nMap(array $i18n_map)
149 148
     {
150 149
         if (empty($i18n_map)) {
151
-            $i18n_map = file_exists($this->domain->pluginPath() . 'translation-map.json')
150
+            $i18n_map = file_exists($this->domain->pluginPath().'translation-map.json')
152 151
                 ? json_decode(
153
-                        file_get_contents($this->domain->pluginPath() . 'translation-map.json'),
152
+                        file_get_contents($this->domain->pluginPath().'translation-map.json'),
154 153
                         true
155 154
                     )
156 155
                 : array();
@@ -228,7 +227,7 @@  discard block
 block discarded – undo
228 227
             ),
229 228
         );
230 229
 
231
-        if (! empty($translations->headers['Plural-Forms'])) {
230
+        if ( ! empty($translations->headers['Plural-Forms'])) {
232 231
             $locale['']['plural_forms'] = $translations->headers['Plural-Forms'];
233 232
         }
234 233
 
Please login to merge, or discard this patch.