Completed
Branch BUG/11268/release-reserved-cou... (6d4092)
by
unknown
26:45 queued 13:23
created
4_9_0_stages/EE_DMS_4_9_0_Email_System_Question.dmsstage.php 1 patch
Spacing   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 
3
-if (!defined('EVENT_ESPRESSO_VERSION')) {
3
+if ( ! defined('EVENT_ESPRESSO_VERSION')) {
4 4
 	exit('No direct script access allowed');
5 5
 }
6 6
 
@@ -13,7 +13,7 @@  discard block
 block discarded – undo
13 13
  * @author				Brent Christensen
14 14
  *
15 15
  */
16
-class EE_DMS_4_9_0_Email_System_Question extends EE_Data_Migration_Script_Stage_Table{
16
+class EE_DMS_4_9_0_Email_System_Question extends EE_Data_Migration_Script_Stage_Table {
17 17
 
18 18
 
19 19
 
@@ -24,7 +24,7 @@  discard block
 block discarded – undo
24 24
 	 */
25 25
 	public function __construct() {
26 26
 		global $wpdb;
27
-		$this->_pretty_name = __( 'Email - System Question', 'event_espresso' );
27
+		$this->_pretty_name = __('Email - System Question', 'event_espresso');
28 28
 		$this->_old_table = $wpdb->prefix.'esp_question';
29 29
 		$this->_extra_where_sql = "WHERE QST_system = 'email'";
30 30
 		parent::__construct();
@@ -37,21 +37,21 @@  discard block
 block discarded – undo
37 37
 	 * @param array $question an associative array where keys are column names and values are their values.
38 38
 	 * @return null
39 39
 	 */
40
-	protected function _migrate_old_row( $question ) {
41
-		if ( $question['QST_ID'] && $question['QST_system'] == 'email' ) {
40
+	protected function _migrate_old_row($question) {
41
+		if ($question['QST_ID'] && $question['QST_system'] == 'email') {
42 42
 			global $wpdb;
43 43
 			$success = $wpdb->update(
44 44
 				$this->_old_table,
45
-				array( 'QST_type' => 'EMAIL' ),  // data
46
-				array( 'QST_ID' => $question['QST_ID'] ),  // where
47
-				array( '%s' ),   // data format
48
-				array( '%d' )  // where format
45
+				array('QST_type' => 'EMAIL'), // data
46
+				array('QST_ID' => $question['QST_ID']), // where
47
+				array('%s'), // data format
48
+				array('%d')  // where format
49 49
 			);
50
-			if ( ! $success ) {
50
+			if ( ! $success) {
51 51
 				$this->add_error(
52 52
 					sprintf(
53
-						__( 'Could not update question system name "%1$s" for question ID=%2$d because "%3$s"', 'event_espresso' ),
54
-						wp_json_encode( $question['QST_system'] ),
53
+						__('Could not update question system name "%1$s" for question ID=%2$d because "%3$s"', 'event_espresso'),
54
+						wp_json_encode($question['QST_system']),
55 55
 						$question['QST_ID'],
56 56
 						$wpdb->last_error
57 57
 					)
Please login to merge, or discard this patch.
admin_pages/events/templates/event_publish_box_extras.template.php 1 patch
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -1,22 +1,22 @@  discard block
 block discarded – undo
1 1
 
2 2
 <div class="misc-pub-section">
3 3
 	<span class="dashicons dashicons-groups ee-icon-color-ee-green ee-icon-size-20"></span>
4
-	<a href="<?php echo $view_approved_reg_url;?>">
5
-		<?php printf( __('%s Registrations', 'event_espresso'), EEH_Template::pretty_status(EEM_Registration::status_id_approved, FALSE, 'sentence') ); ?>
4
+	<a href="<?php echo $view_approved_reg_url; ?>">
5
+		<?php printf(__('%s Registrations', 'event_espresso'), EEH_Template::pretty_status(EEM_Registration::status_id_approved, FALSE, 'sentence')); ?>
6 6
 	</a>:
7 7
 	<?php echo $approved_regs; ?>
8 8
 </div>
9 9
 <div class="misc-pub-section">
10 10
 	<span class="dashicons dashicons-groups ee-icon-color-ee-blue ee-icon-size-20"></span>
11
-	<a href="<?php echo $view_pending_payment_reg_url;?>">
12
-		<?php printf( __('%s Registrations', 'event_espresso'), EEH_Template::pretty_status(EEM_Registration::status_id_pending_payment, FALSE, 'sentence') ); ?>
11
+	<a href="<?php echo $view_pending_payment_reg_url; ?>">
12
+		<?php printf(__('%s Registrations', 'event_espresso'), EEH_Template::pretty_status(EEM_Registration::status_id_pending_payment, FALSE, 'sentence')); ?>
13 13
 	</a>:
14 14
 	<?php echo $pending_payment_regs; ?>
15 15
 </div>
16 16
 <div class="misc-pub-section">
17 17
 	<span class="dashicons dashicons-groups ee-icon-color-ee-orange ee-icon-size-20"></span>
18
-	<a href="<?php echo $view_not_approved_reg_url;?>">
19
-		<?php printf( __('%s Registrations', 'event_espresso'), EEH_Template::pretty_status(EEM_Registration::status_id_not_approved, FALSE, 'sentence') ); ?>
18
+	<a href="<?php echo $view_not_approved_reg_url; ?>">
19
+		<?php printf(__('%s Registrations', 'event_espresso'), EEH_Template::pretty_status(EEM_Registration::status_id_not_approved, FALSE, 'sentence')); ?>
20 20
 	</a>:
21 21
 	<?php echo $not_approved_regs; ?>
22 22
 </div>
@@ -29,5 +29,5 @@  discard block
 block discarded – undo
29 29
 	</a>
30 30
 </div> /**/ ?>
31 31
 
32
-<?php echo $event_editor_overview_add;?>
32
+<?php echo $event_editor_overview_add; ?>
33 33
 <br/>
Please login to merge, or discard this patch.
templates/txn_admin_details_side_meta_box_registrant.template.php 3 patches
Indentation   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -17,7 +17,7 @@  discard block
 block discarded – undo
17 17
 <?php else : ?>
18 18
     <p class="clearfix">
19 19
         <span class="admin-side-mbox-label-spn lt-grey-txt float-left"><?php _e('Name',
20
-                    'event_espresso'); ?></span><?php echo $prime_reg_fname . ' ' . $prime_reg_lname; ?>
20
+					'event_espresso'); ?></span><?php echo $prime_reg_fname . ' ' . $prime_reg_lname; ?>
21 21
     </p>
22 22
     <p class="clearfix">
23 23
         <span class="admin-side-mbox-label-spn lt-grey-txt float-left"><?php _e('Email', 'event_espresso'); ?></span><a
@@ -25,7 +25,7 @@  discard block
 block discarded – undo
25 25
     </p>
26 26
     <p class="clearfix">
27 27
         <span class="admin-side-mbox-label-spn lt-grey-txt float-left"><?php _e('Phone #',
28
-                    'event_espresso'); ?></span><?php echo $prime_reg_phone; ?>
28
+					'event_espresso'); ?></span><?php echo $prime_reg_phone; ?>
29 29
     </p>
30 30
     <p class="clearfix">
31 31
         <span class="admin-side-mbox-label-spn lt-grey-txt float-left"><?php _e('Address', 'event_espresso'); ?></span>
@@ -36,13 +36,13 @@  discard block
 block discarded – undo
36 36
     </div> <!-- end #admin-side-mbox-primary-registrant-dv -->
37 37
 
38 38
     <?php
39
-    /** only show if logged in user has access */
40
-    if ( EE_Registry::instance()->CAP->current_user_can(
41
-            'ee_edit_contact',
42
-            'view_or_edit_contact_button',
43
-            $ATT_ID
44
-    )
45
-    ) : ?>
39
+	/** only show if logged in user has access */
40
+	if ( EE_Registry::instance()->CAP->current_user_can(
41
+			'ee_edit_contact',
42
+			'view_or_edit_contact_button',
43
+			$ATT_ID
44
+	)
45
+	) : ?>
46 46
     <p style="text-align:right;">
47 47
         <a class="button button-small" href="<?php echo $edit_attendee_url; ?>"
48 48
            title="<?php esc_attr_e('View details for this contact.', 'event_espresso'); ?>">
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -17,7 +17,7 @@  discard block
 block discarded – undo
17 17
 <?php else : ?>
18 18
     <p class="clearfix">
19 19
         <span class="admin-side-mbox-label-spn lt-grey-txt float-left"><?php _e('Name',
20
-                    'event_espresso'); ?></span><?php echo $prime_reg_fname . ' ' . $prime_reg_lname; ?>
20
+                    'event_espresso'); ?></span><?php echo $prime_reg_fname.' '.$prime_reg_lname; ?>
21 21
     </p>
22 22
     <p class="clearfix">
23 23
         <span class="admin-side-mbox-label-spn lt-grey-txt float-left"><?php _e('Email', 'event_espresso'); ?></span><a
@@ -37,7 +37,7 @@  discard block
 block discarded – undo
37 37
 
38 38
     <?php
39 39
     /** only show if logged in user has access */
40
-    if ( EE_Registry::instance()->CAP->current_user_can(
40
+    if (EE_Registry::instance()->CAP->current_user_can(
41 41
             'ee_edit_contact',
42 42
             'view_or_edit_contact_button',
43 43
             $ATT_ID
@@ -50,4 +50,4 @@  discard block
 block discarded – undo
50 50
         </a>
51 51
     </p>
52 52
     <?php endif; ?>
53
-<?php endif;  //end no attendee check?>
53
+<?php endif; //end no attendee check?>
Please login to merge, or discard this patch.
Braces   +5 added lines, -2 removed lines patch added patch discarded remove patch
@@ -14,10 +14,13 @@
 block discarded – undo
14 14
         <?php echo $no_attendee_message; ?>
15 15
     </p>
16 16
 </div> <!-- end #admin-side-mbox-primary-registrant-dv -->
17
-<?php else : ?>
17
+<?php else {
18
+	: ?>
18 19
     <p class="clearfix">
19 20
         <span class="admin-side-mbox-label-spn lt-grey-txt float-left"><?php _e('Name',
20
-                    'event_espresso'); ?></span><?php echo $prime_reg_fname . ' ' . $prime_reg_lname; ?>
21
+                    'event_espresso');
22
+}
23
+?></span><?php echo $prime_reg_fname . ' ' . $prime_reg_lname; ?>
21 24
     </p>
22 25
     <p class="clearfix">
23 26
         <span class="admin-side-mbox-label-spn lt-grey-txt float-left"><?php _e('Email', 'event_espresso'); ?></span><a
Please login to merge, or discard this patch.
core/db_models/EEM_Datetime.model.php 3 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -529,7 +529,7 @@
 block discarded – undo
529 529
     /**
530 530
      * This returns an array of counts of datetimes in the database for each Datetime status that can be queried.
531 531
      *
532
-     * @param  array $stati_to_include If included you can restrict the statuses we return counts for by including the
532
+     * @param  string[] $stati_to_include If included you can restrict the statuses we return counts for by including the
533 533
      *                                 stati you want counts for as values in the array.  An empty array returns counts
534 534
      *                                 for all valid stati.
535 535
      * @param  array $query_params     If included can be used to refine the conditions for returning the count (i.e.
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -482,9 +482,9 @@
 block discarded – undo
482 482
         $query_params['order_by'] = array('DTT_EVT_start' => 'DESC');
483 483
         $query_interval = EEH_DTT_Helper::get_sql_query_interval_for_offset($this->get_timezone(), 'DTT_EVT_start');
484 484
         $columns_to_select = array(
485
-            'dtt_year'      => array('YEAR(' . $query_interval . ')', '%s'),
486
-            'dtt_month'     => array('MONTHNAME(' . $query_interval . ')', '%s'),
487
-            'dtt_month_num' => array('MONTH(' . $query_interval . ')', '%s'),
485
+            'dtt_year'      => array('YEAR('.$query_interval.')', '%s'),
486
+            'dtt_month'     => array('MONTHNAME('.$query_interval.')', '%s'),
487
+            'dtt_month_num' => array('MONTH('.$query_interval.')', '%s'),
488 488
         );
489 489
         return $this->_get_all_wpdb_results($query_params, OBJECT, $columns_to_select);
490 490
     }
Please login to merge, or discard this patch.
Indentation   +590 added lines, -590 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php if ( ! defined('EVENT_ESPRESSO_VERSION')) {
2
-    exit('No direct script access allowed');
2
+	exit('No direct script access allowed');
3 3
 }
4 4
 /**
5 5
  * Class Datetime Model
@@ -11,595 +11,595 @@  discard block
 block discarded – undo
11 11
 class EEM_Datetime extends EEM_Soft_Delete_Base
12 12
 {
13 13
 
14
-    /**
15
-     * @var EEM_Datetime $_instance
16
-     */
17
-    protected static $_instance;
18
-
19
-
20
-
21
-    /**
22
-     *        private constructor to prevent direct creation
23
-     *
24
-     * @Constructor
25
-     * @access private
26
-     * @param string $timezone string representing the timezone we want to set for returned Date Time Strings (and any
27
-     *                         incoming timezone data that gets saved).  Note this just sends the timezone info to the
28
-     *                         date time model field objects.  Default is NULL (and will be assumed using the set
29
-     *                         timezone in the 'timezone_string' wp option)
30
-     * @throws \EE_Error
31
-     */
32
-    protected function __construct($timezone)
33
-    {
34
-        $this->singular_item = __('Datetime', 'event_espresso');
35
-        $this->plural_item = __('Datetimes', 'event_espresso');
36
-        $this->_tables = array(
37
-            'Datetime' => new EE_Primary_Table('esp_datetime', 'DTT_ID'),
38
-        );
39
-        $this->_fields = array(
40
-            'Datetime' => array(
41
-                'DTT_ID'          => new EE_Primary_Key_Int_Field('DTT_ID', __('Datetime ID', 'event_espresso')),
42
-                'EVT_ID'          => new EE_Foreign_Key_Int_Field(
43
-                    'EVT_ID', __('Event ID', 'event_espresso'), false, 0, 'Event'
44
-                ),
45
-                'DTT_name'        => new EE_Plain_Text_Field(
46
-                    'DTT_name', __('Datetime Name', 'event_espresso'), false, ''
47
-                ),
48
-                'DTT_description' => new EE_Post_Content_Field(
49
-                    'DTT_description', __('Description for Datetime', 'event_espresso'), false, ''
50
-                ),
51
-                'DTT_EVT_start'   => new EE_Datetime_Field(
52
-                    'DTT_EVT_start', __('Start time/date of Event', 'event_espresso'), false, EE_Datetime_Field::now,
53
-                    $timezone
54
-                ),
55
-                'DTT_EVT_end'     => new EE_Datetime_Field(
56
-                    'DTT_EVT_end', __('End time/date of Event', 'event_espresso'), false, EE_Datetime_Field::now,
57
-                    $timezone
58
-                ),
59
-                'DTT_reg_limit'   => new EE_Infinite_Integer_Field(
60
-                    'DTT_reg_limit', __('Registration Limit for this time', 'event_espresso'), true, EE_INF),
61
-                'DTT_sold'        => new EE_Integer_Field(
62
-                    'DTT_sold', __('How many sales for this Datetime that have occurred', 'event_espresso'), true, 0
63
-                ),
64
-                'DTT_reserved' => new EE_Integer_Field('DTT_reserved',
65
-                    __('Quantity of tickets reserved, but not yet fully purchased', 'event_espresso'), false, 0
66
-                ),
67
-                'DTT_is_primary'  => new EE_Boolean_Field(
68
-                    'DTT_is_primary', __('Flag indicating datetime is primary one for event', 'event_espresso'),
69
-                    false, false
70
-                ),
71
-                'DTT_order'       => new EE_Integer_Field(
72
-                    'DTT_order', __('The order in which the Datetime is displayed', 'event_espresso'), false, 0
73
-                ),
74
-                'DTT_parent'      => new EE_Integer_Field(
75
-                    'DTT_parent', __('Indicates what DTT_ID is the parent of this DTT_ID'), true, 0
76
-                ),
77
-                'DTT_deleted'     => new EE_Trashed_Flag_Field(
78
-                    'DTT_deleted', __('Flag indicating datetime is archived', 'event_espresso'), false, false
79
-                ),
80
-            ),
81
-        );
82
-        $this->_model_relations = array(
83
-            'Ticket'  => new EE_HABTM_Relation('Datetime_Ticket'),
84
-            'Event'   => new EE_Belongs_To_Relation(),
85
-            'Checkin' => new EE_Has_Many_Relation(),
86
-        );
87
-        $this->_model_chain_to_wp_user = 'Event';
88
-        //this model is generally available for reading
89
-        $this->_cap_restriction_generators[EEM_Base::caps_read] = new EE_Restriction_Generator_Event_Related_Public('Event');
90
-        $this->_cap_restriction_generators[EEM_Base::caps_read_admin] = new EE_Restriction_Generator_Event_Related_Protected('Event');
91
-        $this->_cap_restriction_generators[EEM_Base::caps_edit] = new EE_Restriction_Generator_Event_Related_Protected('Event');
92
-        $this->_cap_restriction_generators[EEM_Base::caps_delete] = new EE_Restriction_Generator_Event_Related_Protected('Event',
93
-            EEM_Base::caps_edit);
94
-        parent::__construct($timezone);
95
-    }
96
-
97
-
98
-
99
-    /**
100
-     * create new blank datetime
101
-     *
102
-     * @access public
103
-     * @return EE_Datetime[] array on success, FALSE on fail
104
-     * @throws \EE_Error
105
-     */
106
-    public function create_new_blank_datetime()
107
-    {
108
-        //makes sure timezone is always set.
109
-        $timezone_string = $this->get_timezone();
110
-        $blank_datetime = EE_Datetime::new_instance(
111
-            array(
112
-                'DTT_EVT_start' => $this->current_time_for_query('DTT_EVT_start', true) + MONTH_IN_SECONDS,
113
-                'DTT_EVT_end'   => $this->current_time_for_query('DTT_EVT_end', true) + MONTH_IN_SECONDS,
114
-                'DTT_order'     => 1,
115
-                'DTT_reg_limit' => EE_INF,
116
-            ),
117
-            $timezone_string
118
-        );
119
-        $blank_datetime->set_start_time($this->convert_datetime_for_query('DTT_EVT_start', '8am', 'ga',
120
-            $timezone_string));
121
-        $blank_datetime->set_end_time($this->convert_datetime_for_query('DTT_EVT_end', '5pm', 'ga', $timezone_string));
122
-        return array($blank_datetime);
123
-    }
124
-
125
-
126
-
127
-    /**
128
-     * get event start date from db
129
-     *
130
-     * @access public
131
-     * @param  int $EVT_ID
132
-     * @return EE_Datetime[] array on success, FALSE on fail
133
-     * @throws \EE_Error
134
-     */
135
-    public function get_all_event_dates($EVT_ID = 0)
136
-    {
137
-        if ( ! $EVT_ID) { // on add_new_event event_id gets set to 0
138
-            return $this->create_new_blank_datetime();
139
-        }
140
-        $results = $this->get_datetimes_for_event_ordered_by_DTT_order($EVT_ID);
141
-        if (empty($results)) {
142
-            return $this->create_new_blank_datetime();
143
-        }
144
-        return $results;
145
-    }
146
-
147
-
148
-
149
-    /**
150
-     * get all datetimes attached to an event ordered by the DTT_order field
151
-     *
152
-     * @public
153
-     * @param  int    $EVT_ID     event id
154
-     * @param boolean $include_expired
155
-     * @param boolean $include_deleted
156
-     * @param  int    $limit      If included then limit the count of results by
157
-     *                            the given number
158
-     * @return EE_Datetime[]
159
-     * @throws \EE_Error
160
-     */
161
-    public function get_datetimes_for_event_ordered_by_DTT_order(
162
-        $EVT_ID,
163
-        $include_expired = true,
164
-        $include_deleted = true,
165
-        $limit = null
166
-    ) {
167
-        //sanitize EVT_ID
168
-        $EVT_ID = absint($EVT_ID);
169
-        $old_assumption = $this->get_assumption_concerning_values_already_prepared_by_model_object();
170
-        $this->assume_values_already_prepared_by_model_object(EEM_Base::prepared_for_use_in_db);
171
-        $where_params = array('Event.EVT_ID' => $EVT_ID);
172
-        $query_params = ! empty($limit)
173
-            ? array(
174
-                $where_params,
175
-                'limit'                    => $limit,
176
-                'order_by'                 => array('DTT_order' => 'ASC'),
177
-                'default_where_conditions' => 'none',
178
-            )
179
-            : array(
180
-                $where_params,
181
-                'order_by'                 => array('DTT_order' => 'ASC'),
182
-                'default_where_conditions' => 'none',
183
-            );
184
-        if ( ! $include_expired) {
185
-            $query_params[0]['DTT_EVT_end'] = array('>=', current_time('mysql', true));
186
-        }
187
-        if ($include_deleted) {
188
-            $query_params[0]['DTT_deleted'] = array('IN', array(true, false));
189
-        }
190
-        /** @var EE_Datetime[] $result */
191
-        $result = $this->get_all($query_params);
192
-        $this->assume_values_already_prepared_by_model_object($old_assumption);
193
-        return $result;
194
-    }
195
-
196
-
197
-
198
-    /**
199
-     * Gets the datetimes for the event (with the given limit), and orders them by "importance". By importance, we mean
200
-     * that the primary datetimes are most important (DEPRECATED FOR NOW), and then the earlier datetimes are the most
201
-     * important. Maybe we'll want this to take into account datetimes that haven't already passed, but we don't yet.
202
-     *
203
-     * @param int $EVT_ID
204
-     * @param int $limit
205
-     * @return EE_Datetime[]|EE_Base_Class[]
206
-     * @throws \EE_Error
207
-     */
208
-    public function get_datetimes_for_event_ordered_by_importance($EVT_ID = 0, $limit = null)
209
-    {
210
-        return $this->get_all(
211
-            array(
212
-                array('Event.EVT_ID' => $EVT_ID),
213
-                'limit'                    => $limit,
214
-                'order_by'                 => array('DTT_EVT_start' => 'ASC'),
215
-                'default_where_conditions' => 'none',
216
-            )
217
-        );
218
-    }
219
-
220
-
221
-
222
-    /**
223
-     * @param int     $EVT_ID
224
-     * @param boolean $include_expired
225
-     * @param boolean $include_deleted
226
-     * @return EE_Datetime
227
-     * @throws \EE_Error
228
-     */
229
-    public function get_oldest_datetime_for_event($EVT_ID, $include_expired = false, $include_deleted = false)
230
-    {
231
-        $results = $this->get_datetimes_for_event_ordered_by_start_time($EVT_ID, $include_expired, $include_deleted, 1);
232
-        if ($results) {
233
-            return array_shift($results);
234
-        } else {
235
-            return null;
236
-        }
237
-    }
238
-
239
-
240
-
241
-    /**
242
-     * Gets the 'primary' datetime for an event.
243
-     *
244
-     * @param int  $EVT_ID
245
-     * @param bool $try_to_exclude_expired
246
-     * @param bool $try_to_exclude_deleted
247
-     * @return \EE_Datetime
248
-     * @throws \EE_Error
249
-     */
250
-    public function get_primary_datetime_for_event(
251
-        $EVT_ID,
252
-        $try_to_exclude_expired = true,
253
-        $try_to_exclude_deleted = true
254
-    ) {
255
-        if ($try_to_exclude_expired) {
256
-            $non_expired = $this->get_oldest_datetime_for_event($EVT_ID, false, false);
257
-            if ($non_expired) {
258
-                return $non_expired;
259
-            }
260
-        }
261
-        if ($try_to_exclude_deleted) {
262
-            $expired_even = $this->get_oldest_datetime_for_event($EVT_ID, true);
263
-            if ($expired_even) {
264
-                return $expired_even;
265
-            }
266
-        }
267
-        return $this->get_oldest_datetime_for_event($EVT_ID, true, true);
268
-    }
269
-
270
-
271
-
272
-    /**
273
-     * Gets ALL the datetimes for an event (including trashed ones, for now), ordered
274
-     * only by start date
275
-     *
276
-     * @param int     $EVT_ID
277
-     * @param boolean $include_expired
278
-     * @param boolean $include_deleted
279
-     * @param int     $limit
280
-     * @return EE_Datetime[]
281
-     * @throws \EE_Error
282
-     */
283
-    public function get_datetimes_for_event_ordered_by_start_time(
284
-        $EVT_ID,
285
-        $include_expired = true,
286
-        $include_deleted = true,
287
-        $limit = null
288
-    ) {
289
-        //sanitize EVT_ID
290
-        $EVT_ID = absint($EVT_ID);
291
-        $old_assumption = $this->get_assumption_concerning_values_already_prepared_by_model_object();
292
-        $this->assume_values_already_prepared_by_model_object(EEM_Base::prepared_for_use_in_db);
293
-        $query_params = array(array('Event.EVT_ID' => $EVT_ID), 'order_by' => array('DTT_EVT_start' => 'asc'));
294
-        if ( ! $include_expired) {
295
-            $query_params[0]['DTT_EVT_end'] = array('>=', current_time('mysql', true));
296
-        }
297
-        if ($include_deleted) {
298
-            $query_params[0]['DTT_deleted'] = array('IN', array(true, false));
299
-        }
300
-        if ($limit) {
301
-            $query_params['limit'] = $limit;
302
-        }
303
-        /** @var EE_Datetime[] $result */
304
-        $result = $this->get_all($query_params);
305
-        $this->assume_values_already_prepared_by_model_object($old_assumption);
306
-        return $result;
307
-    }
308
-
309
-
310
-
311
-    /**
312
-     * Gets ALL the datetimes for an ticket (including trashed ones, for now), ordered
313
-     * only by start date
314
-     *
315
-     * @param int     $TKT_ID
316
-     * @param boolean $include_expired
317
-     * @param boolean $include_deleted
318
-     * @param int     $limit
319
-     * @return EE_Datetime[]
320
-     * @throws \EE_Error
321
-     */
322
-    public function get_datetimes_for_ticket_ordered_by_start_time(
323
-        $TKT_ID,
324
-        $include_expired = true,
325
-        $include_deleted = true,
326
-        $limit = null
327
-    ) {
328
-        //sanitize TKT_ID
329
-        $TKT_ID = absint($TKT_ID);
330
-        $old_assumption = $this->get_assumption_concerning_values_already_prepared_by_model_object();
331
-        $this->assume_values_already_prepared_by_model_object(EEM_Base::prepared_for_use_in_db);
332
-        $query_params = array(array('Ticket.TKT_ID' => $TKT_ID), 'order_by' => array('DTT_EVT_start' => 'asc'));
333
-        if ( ! $include_expired) {
334
-            $query_params[0]['DTT_EVT_end'] = array('>=', current_time('mysql', true));
335
-        }
336
-        if ($include_deleted) {
337
-            $query_params[0]['DTT_deleted'] = array('IN', array(true, false));
338
-        }
339
-        if ($limit) {
340
-            $query_params['limit'] = $limit;
341
-        }
342
-        /** @var EE_Datetime[] $result */
343
-        $result = $this->get_all($query_params);
344
-        $this->assume_values_already_prepared_by_model_object($old_assumption);
345
-        return $result;
346
-    }
347
-
348
-
349
-
350
-    /**
351
-     * Gets all the datetimes for a ticket (including trashed ones, for now), ordered by the DTT_order for the
352
-     * datetimes.
353
-     *
354
-     * @param  int      $TKT_ID          ID of ticket to retrieve the datetimes for
355
-     * @param  boolean  $include_expired whether to include expired datetimes or not
356
-     * @param  boolean  $include_deleted whether to include trashed datetimes or not.
357
-     * @param  int|null $limit           if null, no limit, if int then limit results by
358
-     *                                   that number
359
-     * @return EE_Datetime[]
360
-     * @throws \EE_Error
361
-     */
362
-    public function get_datetimes_for_ticket_ordered_by_DTT_order(
363
-        $TKT_ID,
364
-        $include_expired = true,
365
-        $include_deleted = true,
366
-        $limit = null
367
-    ) {
368
-        //sanitize id.
369
-        $TKT_ID = absint($TKT_ID);
370
-        $old_assumption = $this->get_assumption_concerning_values_already_prepared_by_model_object();
371
-        $this->assume_values_already_prepared_by_model_object(EEM_Base::prepared_for_use_in_db);
372
-        $where_params = array('Ticket.TKT_ID' => $TKT_ID);
373
-        $query_params = array($where_params, 'order_by' => array('DTT_order' => 'ASC'));
374
-        if ( ! $include_expired) {
375
-            $query_params[0]['DTT_EVT_end'] = array('>=', current_time('mysql', true));
376
-        }
377
-        if ($include_deleted) {
378
-            $query_params[0]['DTT_deleted'] = array('IN', array(true, false));
379
-        }
380
-        if ($limit) {
381
-            $query_params['limit'] = $limit;
382
-        }
383
-        /** @var EE_Datetime[] $result */
384
-        $result = $this->get_all($query_params);
385
-        $this->assume_values_already_prepared_by_model_object($old_assumption);
386
-        return $result;
387
-    }
388
-
389
-
390
-
391
-    /**
392
-     * Gets the most important datetime for a particular event (ie, the primary event usually. But if for some WACK
393
-     * reason it doesn't exist, we consider the earliest event the most important)
394
-     *
395
-     * @param int $EVT_ID
396
-     * @return EE_Datetime
397
-     * @throws \EE_Error
398
-     */
399
-    public function get_most_important_datetime_for_event($EVT_ID)
400
-    {
401
-        $results = $this->get_datetimes_for_event_ordered_by_importance($EVT_ID, 1);
402
-        if ($results) {
403
-            return array_shift($results);
404
-        } else {
405
-            return null;
406
-        }
407
-    }
408
-
409
-
410
-
411
-    /**
412
-     * This returns a wpdb->results        Array of all DTT month and years matching the incoming query params and
413
-     * grouped by month and year.
414
-     *
415
-     * @param  array  $where_params      Array of query_params as described in the comments for EEM_Base::get_all()
416
-     * @param  string $evt_active_status A string representing the evt active status to filter the months by.
417
-     *                                   Can be:
418
-     *                                   - '' = no filter
419
-     *                                   - upcoming = Published events with at least one upcoming datetime.
420
-     *                                   - expired = Events with all datetimes expired.
421
-     *                                   - active = Events that are published and have at least one datetime that
422
-     *                                   starts before now and ends after now.
423
-     *                                   - inactive = Events that are either not published.
424
-     * @return EE_Base_Class[]
425
-     * @throws \EE_Error
426
-     */
427
-    public function get_dtt_months_and_years($where_params, $evt_active_status = '')
428
-    {
429
-        $current_time_for_DTT_EVT_start = $this->current_time_for_query('DTT_EVT_start');
430
-        $current_time_for_DTT_EVT_end = $this->current_time_for_query('DTT_EVT_end');
431
-        switch ($evt_active_status) {
432
-            case 'upcoming' :
433
-                $where_params['Event.status'] = 'publish';
434
-                //if there are already query_params matching DTT_EVT_start then we need to modify that to add them.
435
-                if (isset($where_params['DTT_EVT_start'])) {
436
-                    $where_params['DTT_EVT_start*****'] = $where_params['DTT_EVT_start'];
437
-                }
438
-                $where_params['DTT_EVT_start'] = array('>', $current_time_for_DTT_EVT_start);
439
-                break;
440
-            case 'expired' :
441
-                if (isset($where_params['Event.status'])) {
442
-                    unset($where_params['Event.status']);
443
-                }
444
-                //get events to exclude
445
-                $exclude_query[0] = array_merge($where_params,
446
-                    array('DTT_EVT_end' => array('>', $current_time_for_DTT_EVT_end)));
447
-                //first get all events that have datetimes where its not expired.
448
-                $event_ids = $this->_get_all_wpdb_results($exclude_query, OBJECT_K, 'Datetime.EVT_ID');
449
-                $event_ids = array_keys($event_ids);
450
-                if (isset($where_params['DTT_EVT_end'])) {
451
-                    $where_params['DTT_EVT_end****'] = $where_params['DTT_EVT_end'];
452
-                }
453
-                $where_params['DTT_EVT_end'] = array('<', $current_time_for_DTT_EVT_end);
454
-                $where_params['Event.EVT_ID'] = array('NOT IN', $event_ids);
455
-                break;
456
-            case 'active' :
457
-                $where_params['Event.status'] = 'publish';
458
-                if (isset($where_params['DTT_EVT_start'])) {
459
-                    $where_params['Datetime.DTT_EVT_start******'] = $where_params['DTT_EVT_start'];
460
-                }
461
-                if (isset($where_params['Datetime.DTT_EVT_end'])) {
462
-                    $where_params['Datetime.DTT_EVT_end*****'] = $where_params['DTT_EVT_end'];
463
-                }
464
-                $where_params['DTT_EVT_start'] = array('<', $current_time_for_DTT_EVT_start);
465
-                $where_params['DTT_EVT_end'] = array('>', $current_time_for_DTT_EVT_end);
466
-                break;
467
-            case 'inactive' :
468
-                if (isset($where_params['Event.status'])) {
469
-                    unset($where_params['Event.status']);
470
-                }
471
-                if (isset($where_params['OR'])) {
472
-                    $where_params['AND']['OR'] = $where_params['OR'];
473
-                }
474
-                if (isset($where_params['DTT_EVT_end'])) {
475
-                    $where_params['AND']['DTT_EVT_end****'] = $where_params['DTT_EVT_end'];
476
-                    unset($where_params['DTT_EVT_end']);
477
-                }
478
-                if (isset($where_params['DTT_EVT_start'])) {
479
-                    $where_params['AND']['DTT_EVT_start'] = $where_params['DTT_EVT_start'];
480
-                    unset($where_params['DTT_EVT_start']);
481
-                }
482
-                $where_params['AND']['Event.status'] = array('!=', 'publish');
483
-                break;
484
-        }
485
-        $query_params[0] = $where_params;
486
-        $query_params['group_by'] = array('dtt_year', 'dtt_month');
487
-        $query_params['order_by'] = array('DTT_EVT_start' => 'DESC');
488
-        $query_interval = EEH_DTT_Helper::get_sql_query_interval_for_offset($this->get_timezone(), 'DTT_EVT_start');
489
-        $columns_to_select = array(
490
-            'dtt_year'      => array('YEAR(' . $query_interval . ')', '%s'),
491
-            'dtt_month'     => array('MONTHNAME(' . $query_interval . ')', '%s'),
492
-            'dtt_month_num' => array('MONTH(' . $query_interval . ')', '%s'),
493
-        );
494
-        return $this->_get_all_wpdb_results($query_params, OBJECT, $columns_to_select);
495
-    }
496
-
497
-
498
-
499
-    /**
500
-     * Updates the DTT_sold attribute on each datetime (based on the registrations
501
-     * for the tickets for each datetime)
502
-     *
503
-     * @param EE_Base_Class[]|EE_Datetime[] $datetimes
504
-     * @throws \EE_Error
505
-     */
506
-    public function update_sold($datetimes)
507
-    {
508
-        EE_Error::doing_it_wrong(
509
-            __FUNCTION__,
510
-            esc_html__(
511
-                'Please use \EEM_Ticket::update_tickets_sold() instead which will in turn correctly update both the Ticket AND Datetime counts.',
512
-                'event_espresso'
513
-            ),
514
-            '4.9.32.rc.005'
515
-        );
516
-        foreach ($datetimes as $datetime) {
517
-            $datetime->update_sold();
518
-        }
519
-    }
520
-
521
-
522
-
523
-    /**
524
-     *    Gets the total number of tickets available at a particular datetime
525
-     *    (does NOT take into account the datetime's spaces available)
526
-     *
527
-     * @param int   $DTT_ID
528
-     * @param array $query_params
529
-     * @return int of tickets available. If sold out, return less than 1. If infinite, returns EE_INF,  IF there are NO
530
-     *             tickets attached to datetime then FALSE is returned.
531
-     */
532
-    public function sum_tickets_currently_available_at_datetime($DTT_ID, array $query_params = array())
533
-    {
534
-        $datetime = $this->get_one_by_ID($DTT_ID);
535
-        if ($datetime instanceof EE_Datetime) {
536
-            return $datetime->tickets_remaining($query_params);
537
-        }
538
-        return 0;
539
-    }
540
-
541
-
542
-
543
-    /**
544
-     * This returns an array of counts of datetimes in the database for each Datetime status that can be queried.
545
-     *
546
-     * @param  array $stati_to_include If included you can restrict the statuses we return counts for by including the
547
-     *                                 stati you want counts for as values in the array.  An empty array returns counts
548
-     *                                 for all valid stati.
549
-     * @param  array $query_params     If included can be used to refine the conditions for returning the count (i.e.
550
-     *                                 only for Datetimes connected to a specific event, or specific ticket.
551
-     * @return array  The value returned is an array indexed by Datetime Status and the values are the counts.  The
552
-     * @throws \EE_Error
553
-     *                                 stati used as index keys are: EE_Datetime::active EE_Datetime::upcoming EE_Datetime::expired
554
-     */
555
-    public function get_datetime_counts_by_status(array $stati_to_include = array(), array $query_params = array())
556
-    {
557
-        //only accept where conditions for this query.
558
-        $_where = isset($query_params[0]) ? $query_params[0] : array();
559
-        $status_query_args = array(
560
-            EE_Datetime::active   => array_merge(
561
-                $_where,
562
-                array('DTT_EVT_start' => array('<', time()), 'DTT_EVT_end' => array('>', time()))
563
-            ),
564
-            EE_Datetime::upcoming => array_merge(
565
-                $_where,
566
-                array('DTT_EVT_start' => array('>', time()))
567
-            ),
568
-            EE_Datetime::expired  => array_merge(
569
-                $_where,
570
-                array('DTT_EVT_end' => array('<', time()))
571
-            ),
572
-        );
573
-        if ( ! empty($stati_to_include)) {
574
-            foreach (array_keys($status_query_args) as $status) {
575
-                if ( ! in_array($status, $stati_to_include, true)) {
576
-                    unset($status_query_args[$status]);
577
-                }
578
-            }
579
-        }
580
-        //loop through and query counts for each stati.
581
-        $status_query_results = array();
582
-        foreach ($status_query_args as $status => $status_where_conditions) {
583
-            $status_query_results[$status] = EEM_Datetime::count(array($status_where_conditions), 'DTT_ID', true);
584
-        }
585
-        return $status_query_results;
586
-    }
587
-
588
-
589
-
590
-    /**
591
-     * Returns the specific count for a given Datetime status matching any given query_params.
592
-     *
593
-     * @param string $status Valid string representation for Datetime status requested. (Defaults to Active).
594
-     * @param array  $query_params
595
-     * @return int
596
-     * @throws \EE_Error
597
-     */
598
-    public function get_datetime_count_for_status($status = EE_Datetime::active, array $query_params = array())
599
-    {
600
-        $count = $this->get_datetime_counts_by_status(array($status), $query_params);
601
-        return ! empty($count[$status]) ? $count[$status] : 0;
602
-    }
14
+	/**
15
+	 * @var EEM_Datetime $_instance
16
+	 */
17
+	protected static $_instance;
18
+
19
+
20
+
21
+	/**
22
+	 *        private constructor to prevent direct creation
23
+	 *
24
+	 * @Constructor
25
+	 * @access private
26
+	 * @param string $timezone string representing the timezone we want to set for returned Date Time Strings (and any
27
+	 *                         incoming timezone data that gets saved).  Note this just sends the timezone info to the
28
+	 *                         date time model field objects.  Default is NULL (and will be assumed using the set
29
+	 *                         timezone in the 'timezone_string' wp option)
30
+	 * @throws \EE_Error
31
+	 */
32
+	protected function __construct($timezone)
33
+	{
34
+		$this->singular_item = __('Datetime', 'event_espresso');
35
+		$this->plural_item = __('Datetimes', 'event_espresso');
36
+		$this->_tables = array(
37
+			'Datetime' => new EE_Primary_Table('esp_datetime', 'DTT_ID'),
38
+		);
39
+		$this->_fields = array(
40
+			'Datetime' => array(
41
+				'DTT_ID'          => new EE_Primary_Key_Int_Field('DTT_ID', __('Datetime ID', 'event_espresso')),
42
+				'EVT_ID'          => new EE_Foreign_Key_Int_Field(
43
+					'EVT_ID', __('Event ID', 'event_espresso'), false, 0, 'Event'
44
+				),
45
+				'DTT_name'        => new EE_Plain_Text_Field(
46
+					'DTT_name', __('Datetime Name', 'event_espresso'), false, ''
47
+				),
48
+				'DTT_description' => new EE_Post_Content_Field(
49
+					'DTT_description', __('Description for Datetime', 'event_espresso'), false, ''
50
+				),
51
+				'DTT_EVT_start'   => new EE_Datetime_Field(
52
+					'DTT_EVT_start', __('Start time/date of Event', 'event_espresso'), false, EE_Datetime_Field::now,
53
+					$timezone
54
+				),
55
+				'DTT_EVT_end'     => new EE_Datetime_Field(
56
+					'DTT_EVT_end', __('End time/date of Event', 'event_espresso'), false, EE_Datetime_Field::now,
57
+					$timezone
58
+				),
59
+				'DTT_reg_limit'   => new EE_Infinite_Integer_Field(
60
+					'DTT_reg_limit', __('Registration Limit for this time', 'event_espresso'), true, EE_INF),
61
+				'DTT_sold'        => new EE_Integer_Field(
62
+					'DTT_sold', __('How many sales for this Datetime that have occurred', 'event_espresso'), true, 0
63
+				),
64
+				'DTT_reserved' => new EE_Integer_Field('DTT_reserved',
65
+					__('Quantity of tickets reserved, but not yet fully purchased', 'event_espresso'), false, 0
66
+				),
67
+				'DTT_is_primary'  => new EE_Boolean_Field(
68
+					'DTT_is_primary', __('Flag indicating datetime is primary one for event', 'event_espresso'),
69
+					false, false
70
+				),
71
+				'DTT_order'       => new EE_Integer_Field(
72
+					'DTT_order', __('The order in which the Datetime is displayed', 'event_espresso'), false, 0
73
+				),
74
+				'DTT_parent'      => new EE_Integer_Field(
75
+					'DTT_parent', __('Indicates what DTT_ID is the parent of this DTT_ID'), true, 0
76
+				),
77
+				'DTT_deleted'     => new EE_Trashed_Flag_Field(
78
+					'DTT_deleted', __('Flag indicating datetime is archived', 'event_espresso'), false, false
79
+				),
80
+			),
81
+		);
82
+		$this->_model_relations = array(
83
+			'Ticket'  => new EE_HABTM_Relation('Datetime_Ticket'),
84
+			'Event'   => new EE_Belongs_To_Relation(),
85
+			'Checkin' => new EE_Has_Many_Relation(),
86
+		);
87
+		$this->_model_chain_to_wp_user = 'Event';
88
+		//this model is generally available for reading
89
+		$this->_cap_restriction_generators[EEM_Base::caps_read] = new EE_Restriction_Generator_Event_Related_Public('Event');
90
+		$this->_cap_restriction_generators[EEM_Base::caps_read_admin] = new EE_Restriction_Generator_Event_Related_Protected('Event');
91
+		$this->_cap_restriction_generators[EEM_Base::caps_edit] = new EE_Restriction_Generator_Event_Related_Protected('Event');
92
+		$this->_cap_restriction_generators[EEM_Base::caps_delete] = new EE_Restriction_Generator_Event_Related_Protected('Event',
93
+			EEM_Base::caps_edit);
94
+		parent::__construct($timezone);
95
+	}
96
+
97
+
98
+
99
+	/**
100
+	 * create new blank datetime
101
+	 *
102
+	 * @access public
103
+	 * @return EE_Datetime[] array on success, FALSE on fail
104
+	 * @throws \EE_Error
105
+	 */
106
+	public function create_new_blank_datetime()
107
+	{
108
+		//makes sure timezone is always set.
109
+		$timezone_string = $this->get_timezone();
110
+		$blank_datetime = EE_Datetime::new_instance(
111
+			array(
112
+				'DTT_EVT_start' => $this->current_time_for_query('DTT_EVT_start', true) + MONTH_IN_SECONDS,
113
+				'DTT_EVT_end'   => $this->current_time_for_query('DTT_EVT_end', true) + MONTH_IN_SECONDS,
114
+				'DTT_order'     => 1,
115
+				'DTT_reg_limit' => EE_INF,
116
+			),
117
+			$timezone_string
118
+		);
119
+		$blank_datetime->set_start_time($this->convert_datetime_for_query('DTT_EVT_start', '8am', 'ga',
120
+			$timezone_string));
121
+		$blank_datetime->set_end_time($this->convert_datetime_for_query('DTT_EVT_end', '5pm', 'ga', $timezone_string));
122
+		return array($blank_datetime);
123
+	}
124
+
125
+
126
+
127
+	/**
128
+	 * get event start date from db
129
+	 *
130
+	 * @access public
131
+	 * @param  int $EVT_ID
132
+	 * @return EE_Datetime[] array on success, FALSE on fail
133
+	 * @throws \EE_Error
134
+	 */
135
+	public function get_all_event_dates($EVT_ID = 0)
136
+	{
137
+		if ( ! $EVT_ID) { // on add_new_event event_id gets set to 0
138
+			return $this->create_new_blank_datetime();
139
+		}
140
+		$results = $this->get_datetimes_for_event_ordered_by_DTT_order($EVT_ID);
141
+		if (empty($results)) {
142
+			return $this->create_new_blank_datetime();
143
+		}
144
+		return $results;
145
+	}
146
+
147
+
148
+
149
+	/**
150
+	 * get all datetimes attached to an event ordered by the DTT_order field
151
+	 *
152
+	 * @public
153
+	 * @param  int    $EVT_ID     event id
154
+	 * @param boolean $include_expired
155
+	 * @param boolean $include_deleted
156
+	 * @param  int    $limit      If included then limit the count of results by
157
+	 *                            the given number
158
+	 * @return EE_Datetime[]
159
+	 * @throws \EE_Error
160
+	 */
161
+	public function get_datetimes_for_event_ordered_by_DTT_order(
162
+		$EVT_ID,
163
+		$include_expired = true,
164
+		$include_deleted = true,
165
+		$limit = null
166
+	) {
167
+		//sanitize EVT_ID
168
+		$EVT_ID = absint($EVT_ID);
169
+		$old_assumption = $this->get_assumption_concerning_values_already_prepared_by_model_object();
170
+		$this->assume_values_already_prepared_by_model_object(EEM_Base::prepared_for_use_in_db);
171
+		$where_params = array('Event.EVT_ID' => $EVT_ID);
172
+		$query_params = ! empty($limit)
173
+			? array(
174
+				$where_params,
175
+				'limit'                    => $limit,
176
+				'order_by'                 => array('DTT_order' => 'ASC'),
177
+				'default_where_conditions' => 'none',
178
+			)
179
+			: array(
180
+				$where_params,
181
+				'order_by'                 => array('DTT_order' => 'ASC'),
182
+				'default_where_conditions' => 'none',
183
+			);
184
+		if ( ! $include_expired) {
185
+			$query_params[0]['DTT_EVT_end'] = array('>=', current_time('mysql', true));
186
+		}
187
+		if ($include_deleted) {
188
+			$query_params[0]['DTT_deleted'] = array('IN', array(true, false));
189
+		}
190
+		/** @var EE_Datetime[] $result */
191
+		$result = $this->get_all($query_params);
192
+		$this->assume_values_already_prepared_by_model_object($old_assumption);
193
+		return $result;
194
+	}
195
+
196
+
197
+
198
+	/**
199
+	 * Gets the datetimes for the event (with the given limit), and orders them by "importance". By importance, we mean
200
+	 * that the primary datetimes are most important (DEPRECATED FOR NOW), and then the earlier datetimes are the most
201
+	 * important. Maybe we'll want this to take into account datetimes that haven't already passed, but we don't yet.
202
+	 *
203
+	 * @param int $EVT_ID
204
+	 * @param int $limit
205
+	 * @return EE_Datetime[]|EE_Base_Class[]
206
+	 * @throws \EE_Error
207
+	 */
208
+	public function get_datetimes_for_event_ordered_by_importance($EVT_ID = 0, $limit = null)
209
+	{
210
+		return $this->get_all(
211
+			array(
212
+				array('Event.EVT_ID' => $EVT_ID),
213
+				'limit'                    => $limit,
214
+				'order_by'                 => array('DTT_EVT_start' => 'ASC'),
215
+				'default_where_conditions' => 'none',
216
+			)
217
+		);
218
+	}
219
+
220
+
221
+
222
+	/**
223
+	 * @param int     $EVT_ID
224
+	 * @param boolean $include_expired
225
+	 * @param boolean $include_deleted
226
+	 * @return EE_Datetime
227
+	 * @throws \EE_Error
228
+	 */
229
+	public function get_oldest_datetime_for_event($EVT_ID, $include_expired = false, $include_deleted = false)
230
+	{
231
+		$results = $this->get_datetimes_for_event_ordered_by_start_time($EVT_ID, $include_expired, $include_deleted, 1);
232
+		if ($results) {
233
+			return array_shift($results);
234
+		} else {
235
+			return null;
236
+		}
237
+	}
238
+
239
+
240
+
241
+	/**
242
+	 * Gets the 'primary' datetime for an event.
243
+	 *
244
+	 * @param int  $EVT_ID
245
+	 * @param bool $try_to_exclude_expired
246
+	 * @param bool $try_to_exclude_deleted
247
+	 * @return \EE_Datetime
248
+	 * @throws \EE_Error
249
+	 */
250
+	public function get_primary_datetime_for_event(
251
+		$EVT_ID,
252
+		$try_to_exclude_expired = true,
253
+		$try_to_exclude_deleted = true
254
+	) {
255
+		if ($try_to_exclude_expired) {
256
+			$non_expired = $this->get_oldest_datetime_for_event($EVT_ID, false, false);
257
+			if ($non_expired) {
258
+				return $non_expired;
259
+			}
260
+		}
261
+		if ($try_to_exclude_deleted) {
262
+			$expired_even = $this->get_oldest_datetime_for_event($EVT_ID, true);
263
+			if ($expired_even) {
264
+				return $expired_even;
265
+			}
266
+		}
267
+		return $this->get_oldest_datetime_for_event($EVT_ID, true, true);
268
+	}
269
+
270
+
271
+
272
+	/**
273
+	 * Gets ALL the datetimes for an event (including trashed ones, for now), ordered
274
+	 * only by start date
275
+	 *
276
+	 * @param int     $EVT_ID
277
+	 * @param boolean $include_expired
278
+	 * @param boolean $include_deleted
279
+	 * @param int     $limit
280
+	 * @return EE_Datetime[]
281
+	 * @throws \EE_Error
282
+	 */
283
+	public function get_datetimes_for_event_ordered_by_start_time(
284
+		$EVT_ID,
285
+		$include_expired = true,
286
+		$include_deleted = true,
287
+		$limit = null
288
+	) {
289
+		//sanitize EVT_ID
290
+		$EVT_ID = absint($EVT_ID);
291
+		$old_assumption = $this->get_assumption_concerning_values_already_prepared_by_model_object();
292
+		$this->assume_values_already_prepared_by_model_object(EEM_Base::prepared_for_use_in_db);
293
+		$query_params = array(array('Event.EVT_ID' => $EVT_ID), 'order_by' => array('DTT_EVT_start' => 'asc'));
294
+		if ( ! $include_expired) {
295
+			$query_params[0]['DTT_EVT_end'] = array('>=', current_time('mysql', true));
296
+		}
297
+		if ($include_deleted) {
298
+			$query_params[0]['DTT_deleted'] = array('IN', array(true, false));
299
+		}
300
+		if ($limit) {
301
+			$query_params['limit'] = $limit;
302
+		}
303
+		/** @var EE_Datetime[] $result */
304
+		$result = $this->get_all($query_params);
305
+		$this->assume_values_already_prepared_by_model_object($old_assumption);
306
+		return $result;
307
+	}
308
+
309
+
310
+
311
+	/**
312
+	 * Gets ALL the datetimes for an ticket (including trashed ones, for now), ordered
313
+	 * only by start date
314
+	 *
315
+	 * @param int     $TKT_ID
316
+	 * @param boolean $include_expired
317
+	 * @param boolean $include_deleted
318
+	 * @param int     $limit
319
+	 * @return EE_Datetime[]
320
+	 * @throws \EE_Error
321
+	 */
322
+	public function get_datetimes_for_ticket_ordered_by_start_time(
323
+		$TKT_ID,
324
+		$include_expired = true,
325
+		$include_deleted = true,
326
+		$limit = null
327
+	) {
328
+		//sanitize TKT_ID
329
+		$TKT_ID = absint($TKT_ID);
330
+		$old_assumption = $this->get_assumption_concerning_values_already_prepared_by_model_object();
331
+		$this->assume_values_already_prepared_by_model_object(EEM_Base::prepared_for_use_in_db);
332
+		$query_params = array(array('Ticket.TKT_ID' => $TKT_ID), 'order_by' => array('DTT_EVT_start' => 'asc'));
333
+		if ( ! $include_expired) {
334
+			$query_params[0]['DTT_EVT_end'] = array('>=', current_time('mysql', true));
335
+		}
336
+		if ($include_deleted) {
337
+			$query_params[0]['DTT_deleted'] = array('IN', array(true, false));
338
+		}
339
+		if ($limit) {
340
+			$query_params['limit'] = $limit;
341
+		}
342
+		/** @var EE_Datetime[] $result */
343
+		$result = $this->get_all($query_params);
344
+		$this->assume_values_already_prepared_by_model_object($old_assumption);
345
+		return $result;
346
+	}
347
+
348
+
349
+
350
+	/**
351
+	 * Gets all the datetimes for a ticket (including trashed ones, for now), ordered by the DTT_order for the
352
+	 * datetimes.
353
+	 *
354
+	 * @param  int      $TKT_ID          ID of ticket to retrieve the datetimes for
355
+	 * @param  boolean  $include_expired whether to include expired datetimes or not
356
+	 * @param  boolean  $include_deleted whether to include trashed datetimes or not.
357
+	 * @param  int|null $limit           if null, no limit, if int then limit results by
358
+	 *                                   that number
359
+	 * @return EE_Datetime[]
360
+	 * @throws \EE_Error
361
+	 */
362
+	public function get_datetimes_for_ticket_ordered_by_DTT_order(
363
+		$TKT_ID,
364
+		$include_expired = true,
365
+		$include_deleted = true,
366
+		$limit = null
367
+	) {
368
+		//sanitize id.
369
+		$TKT_ID = absint($TKT_ID);
370
+		$old_assumption = $this->get_assumption_concerning_values_already_prepared_by_model_object();
371
+		$this->assume_values_already_prepared_by_model_object(EEM_Base::prepared_for_use_in_db);
372
+		$where_params = array('Ticket.TKT_ID' => $TKT_ID);
373
+		$query_params = array($where_params, 'order_by' => array('DTT_order' => 'ASC'));
374
+		if ( ! $include_expired) {
375
+			$query_params[0]['DTT_EVT_end'] = array('>=', current_time('mysql', true));
376
+		}
377
+		if ($include_deleted) {
378
+			$query_params[0]['DTT_deleted'] = array('IN', array(true, false));
379
+		}
380
+		if ($limit) {
381
+			$query_params['limit'] = $limit;
382
+		}
383
+		/** @var EE_Datetime[] $result */
384
+		$result = $this->get_all($query_params);
385
+		$this->assume_values_already_prepared_by_model_object($old_assumption);
386
+		return $result;
387
+	}
388
+
389
+
390
+
391
+	/**
392
+	 * Gets the most important datetime for a particular event (ie, the primary event usually. But if for some WACK
393
+	 * reason it doesn't exist, we consider the earliest event the most important)
394
+	 *
395
+	 * @param int $EVT_ID
396
+	 * @return EE_Datetime
397
+	 * @throws \EE_Error
398
+	 */
399
+	public function get_most_important_datetime_for_event($EVT_ID)
400
+	{
401
+		$results = $this->get_datetimes_for_event_ordered_by_importance($EVT_ID, 1);
402
+		if ($results) {
403
+			return array_shift($results);
404
+		} else {
405
+			return null;
406
+		}
407
+	}
408
+
409
+
410
+
411
+	/**
412
+	 * This returns a wpdb->results        Array of all DTT month and years matching the incoming query params and
413
+	 * grouped by month and year.
414
+	 *
415
+	 * @param  array  $where_params      Array of query_params as described in the comments for EEM_Base::get_all()
416
+	 * @param  string $evt_active_status A string representing the evt active status to filter the months by.
417
+	 *                                   Can be:
418
+	 *                                   - '' = no filter
419
+	 *                                   - upcoming = Published events with at least one upcoming datetime.
420
+	 *                                   - expired = Events with all datetimes expired.
421
+	 *                                   - active = Events that are published and have at least one datetime that
422
+	 *                                   starts before now and ends after now.
423
+	 *                                   - inactive = Events that are either not published.
424
+	 * @return EE_Base_Class[]
425
+	 * @throws \EE_Error
426
+	 */
427
+	public function get_dtt_months_and_years($where_params, $evt_active_status = '')
428
+	{
429
+		$current_time_for_DTT_EVT_start = $this->current_time_for_query('DTT_EVT_start');
430
+		$current_time_for_DTT_EVT_end = $this->current_time_for_query('DTT_EVT_end');
431
+		switch ($evt_active_status) {
432
+			case 'upcoming' :
433
+				$where_params['Event.status'] = 'publish';
434
+				//if there are already query_params matching DTT_EVT_start then we need to modify that to add them.
435
+				if (isset($where_params['DTT_EVT_start'])) {
436
+					$where_params['DTT_EVT_start*****'] = $where_params['DTT_EVT_start'];
437
+				}
438
+				$where_params['DTT_EVT_start'] = array('>', $current_time_for_DTT_EVT_start);
439
+				break;
440
+			case 'expired' :
441
+				if (isset($where_params['Event.status'])) {
442
+					unset($where_params['Event.status']);
443
+				}
444
+				//get events to exclude
445
+				$exclude_query[0] = array_merge($where_params,
446
+					array('DTT_EVT_end' => array('>', $current_time_for_DTT_EVT_end)));
447
+				//first get all events that have datetimes where its not expired.
448
+				$event_ids = $this->_get_all_wpdb_results($exclude_query, OBJECT_K, 'Datetime.EVT_ID');
449
+				$event_ids = array_keys($event_ids);
450
+				if (isset($where_params['DTT_EVT_end'])) {
451
+					$where_params['DTT_EVT_end****'] = $where_params['DTT_EVT_end'];
452
+				}
453
+				$where_params['DTT_EVT_end'] = array('<', $current_time_for_DTT_EVT_end);
454
+				$where_params['Event.EVT_ID'] = array('NOT IN', $event_ids);
455
+				break;
456
+			case 'active' :
457
+				$where_params['Event.status'] = 'publish';
458
+				if (isset($where_params['DTT_EVT_start'])) {
459
+					$where_params['Datetime.DTT_EVT_start******'] = $where_params['DTT_EVT_start'];
460
+				}
461
+				if (isset($where_params['Datetime.DTT_EVT_end'])) {
462
+					$where_params['Datetime.DTT_EVT_end*****'] = $where_params['DTT_EVT_end'];
463
+				}
464
+				$where_params['DTT_EVT_start'] = array('<', $current_time_for_DTT_EVT_start);
465
+				$where_params['DTT_EVT_end'] = array('>', $current_time_for_DTT_EVT_end);
466
+				break;
467
+			case 'inactive' :
468
+				if (isset($where_params['Event.status'])) {
469
+					unset($where_params['Event.status']);
470
+				}
471
+				if (isset($where_params['OR'])) {
472
+					$where_params['AND']['OR'] = $where_params['OR'];
473
+				}
474
+				if (isset($where_params['DTT_EVT_end'])) {
475
+					$where_params['AND']['DTT_EVT_end****'] = $where_params['DTT_EVT_end'];
476
+					unset($where_params['DTT_EVT_end']);
477
+				}
478
+				if (isset($where_params['DTT_EVT_start'])) {
479
+					$where_params['AND']['DTT_EVT_start'] = $where_params['DTT_EVT_start'];
480
+					unset($where_params['DTT_EVT_start']);
481
+				}
482
+				$where_params['AND']['Event.status'] = array('!=', 'publish');
483
+				break;
484
+		}
485
+		$query_params[0] = $where_params;
486
+		$query_params['group_by'] = array('dtt_year', 'dtt_month');
487
+		$query_params['order_by'] = array('DTT_EVT_start' => 'DESC');
488
+		$query_interval = EEH_DTT_Helper::get_sql_query_interval_for_offset($this->get_timezone(), 'DTT_EVT_start');
489
+		$columns_to_select = array(
490
+			'dtt_year'      => array('YEAR(' . $query_interval . ')', '%s'),
491
+			'dtt_month'     => array('MONTHNAME(' . $query_interval . ')', '%s'),
492
+			'dtt_month_num' => array('MONTH(' . $query_interval . ')', '%s'),
493
+		);
494
+		return $this->_get_all_wpdb_results($query_params, OBJECT, $columns_to_select);
495
+	}
496
+
497
+
498
+
499
+	/**
500
+	 * Updates the DTT_sold attribute on each datetime (based on the registrations
501
+	 * for the tickets for each datetime)
502
+	 *
503
+	 * @param EE_Base_Class[]|EE_Datetime[] $datetimes
504
+	 * @throws \EE_Error
505
+	 */
506
+	public function update_sold($datetimes)
507
+	{
508
+		EE_Error::doing_it_wrong(
509
+			__FUNCTION__,
510
+			esc_html__(
511
+				'Please use \EEM_Ticket::update_tickets_sold() instead which will in turn correctly update both the Ticket AND Datetime counts.',
512
+				'event_espresso'
513
+			),
514
+			'4.9.32.rc.005'
515
+		);
516
+		foreach ($datetimes as $datetime) {
517
+			$datetime->update_sold();
518
+		}
519
+	}
520
+
521
+
522
+
523
+	/**
524
+	 *    Gets the total number of tickets available at a particular datetime
525
+	 *    (does NOT take into account the datetime's spaces available)
526
+	 *
527
+	 * @param int   $DTT_ID
528
+	 * @param array $query_params
529
+	 * @return int of tickets available. If sold out, return less than 1. If infinite, returns EE_INF,  IF there are NO
530
+	 *             tickets attached to datetime then FALSE is returned.
531
+	 */
532
+	public function sum_tickets_currently_available_at_datetime($DTT_ID, array $query_params = array())
533
+	{
534
+		$datetime = $this->get_one_by_ID($DTT_ID);
535
+		if ($datetime instanceof EE_Datetime) {
536
+			return $datetime->tickets_remaining($query_params);
537
+		}
538
+		return 0;
539
+	}
540
+
541
+
542
+
543
+	/**
544
+	 * This returns an array of counts of datetimes in the database for each Datetime status that can be queried.
545
+	 *
546
+	 * @param  array $stati_to_include If included you can restrict the statuses we return counts for by including the
547
+	 *                                 stati you want counts for as values in the array.  An empty array returns counts
548
+	 *                                 for all valid stati.
549
+	 * @param  array $query_params     If included can be used to refine the conditions for returning the count (i.e.
550
+	 *                                 only for Datetimes connected to a specific event, or specific ticket.
551
+	 * @return array  The value returned is an array indexed by Datetime Status and the values are the counts.  The
552
+	 * @throws \EE_Error
553
+	 *                                 stati used as index keys are: EE_Datetime::active EE_Datetime::upcoming EE_Datetime::expired
554
+	 */
555
+	public function get_datetime_counts_by_status(array $stati_to_include = array(), array $query_params = array())
556
+	{
557
+		//only accept where conditions for this query.
558
+		$_where = isset($query_params[0]) ? $query_params[0] : array();
559
+		$status_query_args = array(
560
+			EE_Datetime::active   => array_merge(
561
+				$_where,
562
+				array('DTT_EVT_start' => array('<', time()), 'DTT_EVT_end' => array('>', time()))
563
+			),
564
+			EE_Datetime::upcoming => array_merge(
565
+				$_where,
566
+				array('DTT_EVT_start' => array('>', time()))
567
+			),
568
+			EE_Datetime::expired  => array_merge(
569
+				$_where,
570
+				array('DTT_EVT_end' => array('<', time()))
571
+			),
572
+		);
573
+		if ( ! empty($stati_to_include)) {
574
+			foreach (array_keys($status_query_args) as $status) {
575
+				if ( ! in_array($status, $stati_to_include, true)) {
576
+					unset($status_query_args[$status]);
577
+				}
578
+			}
579
+		}
580
+		//loop through and query counts for each stati.
581
+		$status_query_results = array();
582
+		foreach ($status_query_args as $status => $status_where_conditions) {
583
+			$status_query_results[$status] = EEM_Datetime::count(array($status_where_conditions), 'DTT_ID', true);
584
+		}
585
+		return $status_query_results;
586
+	}
587
+
588
+
589
+
590
+	/**
591
+	 * Returns the specific count for a given Datetime status matching any given query_params.
592
+	 *
593
+	 * @param string $status Valid string representation for Datetime status requested. (Defaults to Active).
594
+	 * @param array  $query_params
595
+	 * @return int
596
+	 * @throws \EE_Error
597
+	 */
598
+	public function get_datetime_count_for_status($status = EE_Datetime::active, array $query_params = array())
599
+	{
600
+		$count = $this->get_datetime_counts_by_status(array($status), $query_params);
601
+		return ! empty($count[$status]) ? $count[$status] : 0;
602
+	}
603 603
 
604 604
 
605 605
 
Please login to merge, or discard this patch.
public/Espresso_Arabica_2014/content-espresso_events-datetimes.php 1 patch
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -1,15 +1,15 @@
 block discarded – undo
1 1
 <?php
2 2
 //echo '<br/><h6 style="color:#2EA2CC;">'. __FILE__ . ' &nbsp; <span style="font-weight:normal;color:#E76700"> Line #: ' . __LINE__ . '</span></h6>';
3 3
 
4
-if ( is_single() || ( is_archive() && espresso_display_datetimes_in_event_list() ) ) :
4
+if (is_single() || (is_archive() && espresso_display_datetimes_in_event_list())) :
5 5
 global $post;
6
-do_action( 'AHEE_event_details_before_event_date', $post );
6
+do_action('AHEE_event_details_before_event_date', $post);
7 7
 ?>
8 8
 	<div class="event-datetimes">
9
-		<?php espresso_list_of_event_dates( $post->ID );?>
9
+		<?php espresso_list_of_event_dates($post->ID); ?>
10 10
 	</div>
11 11
 	<!-- .event-datetimes -->
12 12
 <?php
13
-do_action( 'AHEE_event_details_after_event_date', $post );
13
+do_action('AHEE_event_details_after_event_date', $post);
14 14
 endif;
15 15
 ?>
16 16
\ No newline at end of file
Please login to merge, or discard this patch.
core/db_models/helpers/EE_Table_Base.php 2 patches
Indentation   +160 added lines, -160 removed lines patch added patch discarded remove patch
@@ -9,164 +9,164 @@
 block discarded – undo
9 9
 abstract class EE_Table_Base
10 10
 {
11 11
 
12
-    /**
13
-     * This holds the table_name without the table prefix.
14
-     *
15
-     * @var string
16
-     */
17
-    var $_table_name;
18
-
19
-
20
-    /**
21
-     * This holds what is used as the alias for the table in queries.
22
-     *
23
-     * @var string
24
-     */
25
-    var $_table_alias;
26
-
27
-
28
-    /**
29
-     * Table's private key column
30
-     *
31
-     * @var string
32
-     */
33
-    protected $_pk_column;
34
-
35
-
36
-    /**
37
-     * Whether this table is a global table (in multisite) or specific to site.
38
-     *
39
-     * @var bool
40
-     */
41
-    protected $_global;
42
-
43
-
44
-
45
-    /**
46
-     * @global wpdb   $wpdb
47
-     * @param string  $table_name with or without wpdb prefix
48
-     * @param string  $pk_column
49
-     * @param boolean $global     whether the table is "global" as in there is only 1 table on an entire multisite
50
-     *                            install, or whether each site on a multisite install has a copy of this table
51
-     */
52
-    function __construct($table_name, $pk_column, $global = false)
53
-    {
54
-        $this->_global = $global;
55
-        $prefix = $this->get_table_prefix();
56
-        //if they added the prefix, let's remove it because we delay adding the prefix until right when its needed.
57
-        if (strpos($table_name, $prefix) === 0) {
58
-            $table_name = ltrim($table_name, $prefix);
59
-        }
60
-        $this->_table_name = $table_name;
61
-        $this->_pk_column = $pk_column;
62
-    }
63
-
64
-
65
-
66
-    /**
67
-     * This returns the table prefix for the current model state.
68
-     *
69
-     * @global wpdb $wpdb
70
-     * @return string
71
-     */
72
-    public function get_table_prefix()
73
-    {
74
-        global $wpdb;
75
-        if ($this->_global) {
76
-            $prefix = $wpdb->base_prefix;
77
-        } else {
78
-            $prefix = $wpdb->get_blog_prefix(EEM_Base::get_model_query_blog_id());
79
-        }
80
-        return $prefix;
81
-    }
82
-
83
-
84
-
85
-    /**
86
-     * Used to set the table_alias property
87
-     *
88
-     * @param string $table_alias
89
-     */
90
-    function _construct_finalize_with_alias($table_alias)
91
-    {
92
-        $this->_table_alias = $table_alias;
93
-    }
94
-
95
-
96
-
97
-    /**
98
-     * Returns the fully qualified table name for the database (includes the table prefix current for the blog).
99
-     *
100
-     * @return string
101
-     */
102
-    function get_table_name()
103
-    {
104
-        return $this->get_table_prefix() . $this->_table_name;
105
-    }
106
-
107
-
108
-
109
-    /**
110
-     * Provides what is currently set as the alias for the table to be used in queries.
111
-     *
112
-     * @return string
113
-     * @throws EE_Error
114
-     */
115
-    function get_table_alias()
116
-    {
117
-        if ( ! $this->_table_alias) {
118
-            throw new EE_Error("You must call _construct_finalize_with_alias before using the EE_Table_Base. Did you forget to call parent::__construct at the end of your EEMerimental_Base child's __construct?");
119
-        }
120
-        return $this->_table_alias;
121
-    }
122
-
123
-
124
-
125
-    /**
126
-     * @return string name of column of PK
127
-     */
128
-    function get_pk_column()
129
-    {
130
-        return $this->_pk_column;
131
-    }
132
-
133
-
134
-
135
-    /**
136
-     * returns a string with the table alias, a period, and the private key's column.
137
-     *
138
-     * @return string
139
-     */
140
-    function get_fully_qualified_pk_column()
141
-    {
142
-        $sql = $this->get_table_alias() . "." . $this->get_pk_column();
143
-        return $sql;
144
-    }
145
-
146
-
147
-
148
-    /**
149
-     * returns the special sql for a inner select with a limit.
150
-     *
151
-     * @return string    SQL select
152
-     */
153
-    public function get_select_join_limit($limit)
154
-    {
155
-        $limit = is_array($limit) ? 'LIMIT ' . implode(',', array_map('intval', $limit)) : 'LIMIT ' . (int)$limit;
156
-        $SQL = SP . '(SELECT * FROM ' . $this->_table_name . SP . $limit . ') AS ' . $this->_table_alias;
157
-        return $SQL;
158
-    }
159
-
160
-
161
-
162
-    /**
163
-     * Returns whether or not htis is a global table (ie, on multisite there's
164
-     * only one of these tables, on the main blog)
165
-     *
166
-     * @return boolean
167
-     */
168
-    public function is_global()
169
-    {
170
-        return $this->_global;
171
-    }
12
+	/**
13
+	 * This holds the table_name without the table prefix.
14
+	 *
15
+	 * @var string
16
+	 */
17
+	var $_table_name;
18
+
19
+
20
+	/**
21
+	 * This holds what is used as the alias for the table in queries.
22
+	 *
23
+	 * @var string
24
+	 */
25
+	var $_table_alias;
26
+
27
+
28
+	/**
29
+	 * Table's private key column
30
+	 *
31
+	 * @var string
32
+	 */
33
+	protected $_pk_column;
34
+
35
+
36
+	/**
37
+	 * Whether this table is a global table (in multisite) or specific to site.
38
+	 *
39
+	 * @var bool
40
+	 */
41
+	protected $_global;
42
+
43
+
44
+
45
+	/**
46
+	 * @global wpdb   $wpdb
47
+	 * @param string  $table_name with or without wpdb prefix
48
+	 * @param string  $pk_column
49
+	 * @param boolean $global     whether the table is "global" as in there is only 1 table on an entire multisite
50
+	 *                            install, or whether each site on a multisite install has a copy of this table
51
+	 */
52
+	function __construct($table_name, $pk_column, $global = false)
53
+	{
54
+		$this->_global = $global;
55
+		$prefix = $this->get_table_prefix();
56
+		//if they added the prefix, let's remove it because we delay adding the prefix until right when its needed.
57
+		if (strpos($table_name, $prefix) === 0) {
58
+			$table_name = ltrim($table_name, $prefix);
59
+		}
60
+		$this->_table_name = $table_name;
61
+		$this->_pk_column = $pk_column;
62
+	}
63
+
64
+
65
+
66
+	/**
67
+	 * This returns the table prefix for the current model state.
68
+	 *
69
+	 * @global wpdb $wpdb
70
+	 * @return string
71
+	 */
72
+	public function get_table_prefix()
73
+	{
74
+		global $wpdb;
75
+		if ($this->_global) {
76
+			$prefix = $wpdb->base_prefix;
77
+		} else {
78
+			$prefix = $wpdb->get_blog_prefix(EEM_Base::get_model_query_blog_id());
79
+		}
80
+		return $prefix;
81
+	}
82
+
83
+
84
+
85
+	/**
86
+	 * Used to set the table_alias property
87
+	 *
88
+	 * @param string $table_alias
89
+	 */
90
+	function _construct_finalize_with_alias($table_alias)
91
+	{
92
+		$this->_table_alias = $table_alias;
93
+	}
94
+
95
+
96
+
97
+	/**
98
+	 * Returns the fully qualified table name for the database (includes the table prefix current for the blog).
99
+	 *
100
+	 * @return string
101
+	 */
102
+	function get_table_name()
103
+	{
104
+		return $this->get_table_prefix() . $this->_table_name;
105
+	}
106
+
107
+
108
+
109
+	/**
110
+	 * Provides what is currently set as the alias for the table to be used in queries.
111
+	 *
112
+	 * @return string
113
+	 * @throws EE_Error
114
+	 */
115
+	function get_table_alias()
116
+	{
117
+		if ( ! $this->_table_alias) {
118
+			throw new EE_Error("You must call _construct_finalize_with_alias before using the EE_Table_Base. Did you forget to call parent::__construct at the end of your EEMerimental_Base child's __construct?");
119
+		}
120
+		return $this->_table_alias;
121
+	}
122
+
123
+
124
+
125
+	/**
126
+	 * @return string name of column of PK
127
+	 */
128
+	function get_pk_column()
129
+	{
130
+		return $this->_pk_column;
131
+	}
132
+
133
+
134
+
135
+	/**
136
+	 * returns a string with the table alias, a period, and the private key's column.
137
+	 *
138
+	 * @return string
139
+	 */
140
+	function get_fully_qualified_pk_column()
141
+	{
142
+		$sql = $this->get_table_alias() . "." . $this->get_pk_column();
143
+		return $sql;
144
+	}
145
+
146
+
147
+
148
+	/**
149
+	 * returns the special sql for a inner select with a limit.
150
+	 *
151
+	 * @return string    SQL select
152
+	 */
153
+	public function get_select_join_limit($limit)
154
+	{
155
+		$limit = is_array($limit) ? 'LIMIT ' . implode(',', array_map('intval', $limit)) : 'LIMIT ' . (int)$limit;
156
+		$SQL = SP . '(SELECT * FROM ' . $this->_table_name . SP . $limit . ') AS ' . $this->_table_alias;
157
+		return $SQL;
158
+	}
159
+
160
+
161
+
162
+	/**
163
+	 * Returns whether or not htis is a global table (ie, on multisite there's
164
+	 * only one of these tables, on the main blog)
165
+	 *
166
+	 * @return boolean
167
+	 */
168
+	public function is_global()
169
+	{
170
+		return $this->_global;
171
+	}
172 172
 }
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -101,7 +101,7 @@  discard block
 block discarded – undo
101 101
      */
102 102
     function get_table_name()
103 103
     {
104
-        return $this->get_table_prefix() . $this->_table_name;
104
+        return $this->get_table_prefix().$this->_table_name;
105 105
     }
106 106
 
107 107
 
@@ -139,7 +139,7 @@  discard block
 block discarded – undo
139 139
      */
140 140
     function get_fully_qualified_pk_column()
141 141
     {
142
-        $sql = $this->get_table_alias() . "." . $this->get_pk_column();
142
+        $sql = $this->get_table_alias().".".$this->get_pk_column();
143 143
         return $sql;
144 144
     }
145 145
 
@@ -152,8 +152,8 @@  discard block
 block discarded – undo
152 152
      */
153 153
     public function get_select_join_limit($limit)
154 154
     {
155
-        $limit = is_array($limit) ? 'LIMIT ' . implode(',', array_map('intval', $limit)) : 'LIMIT ' . (int)$limit;
156
-        $SQL = SP . '(SELECT * FROM ' . $this->_table_name . SP . $limit . ') AS ' . $this->_table_alias;
155
+        $limit = is_array($limit) ? 'LIMIT '.implode(',', array_map('intval', $limit)) : 'LIMIT '.(int) $limit;
156
+        $SQL = SP.'(SELECT * FROM '.$this->_table_name.SP.$limit.') AS '.$this->_table_alias;
157 157
         return $SQL;
158 158
     }
159 159
 
Please login to merge, or discard this patch.
admin_pages/registrations/Registrations_Admin_Page.core.php 3 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -1247,7 +1247,7 @@
 block discarded – undo
1247 1247
     /**
1248 1248
      * Sets up the limit for the registrations query.
1249 1249
      *
1250
-     * @param $per_page
1250
+     * @param integer $per_page
1251 1251
      * @return array
1252 1252
      */
1253 1253
     protected function _get_limit($per_page)
Please login to merge, or discard this patch.
Spacing   +86 added lines, -86 removed lines patch added patch discarded remove patch
@@ -76,7 +76,7 @@  discard block
 block discarded – undo
76 76
         // when adding a new registration...
77 77
         if (isset($this->_req_data['action']) && $this->_req_data['action'] === 'new_registration') {
78 78
             EE_System::do_not_cache();
79
-            if (! isset($this->_req_data['processing_registration'])
79
+            if ( ! isset($this->_req_data['processing_registration'])
80 80
                  || absint($this->_req_data['processing_registration']) !== 1
81 81
             ) {
82 82
                 // and it's NOT the attendee information reg step
@@ -171,7 +171,7 @@  discard block
 block discarded – undo
171 171
     public function _set_page_routes()
172 172
     {
173 173
         $this->_get_registration_status_array();
174
-        $reg_id             = ! empty($this->_req_data['_REG_ID']) && ! is_array($this->_req_data['_REG_ID'])
174
+        $reg_id = ! empty($this->_req_data['_REG_ID']) && ! is_array($this->_req_data['_REG_ID'])
175 175
             ? $this->_req_data['_REG_ID'] : 0;
176 176
         $reg_id = empty($reg_id) && ! empty($this->_req_data['reg_status_change_form']['REG_ID'])
177 177
             ? $this->_req_data['reg_status_change_form']['REG_ID']
@@ -669,7 +669,7 @@  discard block
 block discarded – undo
669 669
         //style
670 670
         wp_register_style(
671 671
             'espresso_reg',
672
-            REG_ASSETS_URL . 'espresso_registrations_admin.css',
672
+            REG_ASSETS_URL.'espresso_registrations_admin.css',
673 673
             array('ee-admin-css'),
674 674
             EVENT_ESPRESSO_VERSION
675 675
         );
@@ -677,7 +677,7 @@  discard block
 block discarded – undo
677 677
         //script
678 678
         wp_register_script(
679 679
             'espresso_reg',
680
-            REG_ASSETS_URL . 'espresso_registrations_admin.js',
680
+            REG_ASSETS_URL.'espresso_registrations_admin.js',
681 681
             array('jquery-ui-datepicker', 'jquery-ui-draggable', 'ee_admin_js'),
682 682
             EVENT_ESPRESSO_VERSION,
683 683
             true
@@ -715,7 +715,7 @@  discard block
 block discarded – undo
715 715
         wp_deregister_style('espresso_reg');
716 716
         wp_register_style(
717 717
             'espresso_att',
718
-            REG_ASSETS_URL . 'espresso_attendees_admin.css',
718
+            REG_ASSETS_URL.'espresso_attendees_admin.css',
719 719
             array('ee-admin-css'),
720 720
             EVENT_ESPRESSO_VERSION
721 721
         );
@@ -727,7 +727,7 @@  discard block
 block discarded – undo
727 727
     {
728 728
         wp_register_script(
729 729
             'ee-spco-for-admin',
730
-            REG_ASSETS_URL . 'spco_for_admin.js',
730
+            REG_ASSETS_URL.'spco_for_admin.js',
731 731
             array('underscore', 'jquery'),
732 732
             EVENT_ESPRESSO_VERSION,
733 733
             true
@@ -861,7 +861,7 @@  discard block
 block discarded – undo
861 861
                     'trash_registrations' => esc_html__('Trash Registrations', 'event_espresso'),
862 862
                 ),
863 863
             );
864
-            $this->_views['trash']      = array(
864
+            $this->_views['trash'] = array(
865 865
                 'slug'        => 'trash',
866 866
                 'label'       => esc_html__('Trash', 'event_espresso'),
867 867
                 'count'       => 0,
@@ -950,7 +950,7 @@  discard block
 block discarded – undo
950 950
         }
951 951
         $sc_items = array(
952 952
             'approved_status'   => array(
953
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_approved,
953
+                'class' => 'ee-status-legend ee-status-legend-'.EEM_Registration::status_id_approved,
954 954
                 'desc'  => EEH_Template::pretty_status(
955 955
                     EEM_Registration::status_id_approved,
956 956
                     false,
@@ -958,7 +958,7 @@  discard block
 block discarded – undo
958 958
                 ),
959 959
             ),
960 960
             'pending_status'    => array(
961
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_pending_payment,
961
+                'class' => 'ee-status-legend ee-status-legend-'.EEM_Registration::status_id_pending_payment,
962 962
                 'desc'  => EEH_Template::pretty_status(
963 963
                     EEM_Registration::status_id_pending_payment,
964 964
                     false,
@@ -966,7 +966,7 @@  discard block
 block discarded – undo
966 966
                 ),
967 967
             ),
968 968
             'wait_list'         => array(
969
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_wait_list,
969
+                'class' => 'ee-status-legend ee-status-legend-'.EEM_Registration::status_id_wait_list,
970 970
                 'desc'  => EEH_Template::pretty_status(
971 971
                     EEM_Registration::status_id_wait_list,
972 972
                     false,
@@ -974,7 +974,7 @@  discard block
 block discarded – undo
974 974
                 ),
975 975
             ),
976 976
             'incomplete_status' => array(
977
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_incomplete,
977
+                'class' => 'ee-status-legend ee-status-legend-'.EEM_Registration::status_id_incomplete,
978 978
                 'desc'  => EEH_Template::pretty_status(
979 979
                     EEM_Registration::status_id_incomplete,
980 980
                     false,
@@ -982,7 +982,7 @@  discard block
 block discarded – undo
982 982
                 ),
983 983
             ),
984 984
             'not_approved'      => array(
985
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_not_approved,
985
+                'class' => 'ee-status-legend ee-status-legend-'.EEM_Registration::status_id_not_approved,
986 986
                 'desc'  => EEH_Template::pretty_status(
987 987
                     EEM_Registration::status_id_not_approved,
988 988
                     false,
@@ -990,7 +990,7 @@  discard block
 block discarded – undo
990 990
                 ),
991 991
             ),
992 992
             'declined_status'   => array(
993
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_declined,
993
+                'class' => 'ee-status-legend ee-status-legend-'.EEM_Registration::status_id_declined,
994 994
                 'desc'  => EEH_Template::pretty_status(
995 995
                     EEM_Registration::status_id_declined,
996 996
                     false,
@@ -998,7 +998,7 @@  discard block
 block discarded – undo
998 998
                 ),
999 999
             ),
1000 1000
             'cancelled_status'  => array(
1001
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_cancelled,
1001
+                'class' => 'ee-status-legend ee-status-legend-'.EEM_Registration::status_id_cancelled,
1002 1002
                 'desc'  => EEH_Template::pretty_status(
1003 1003
                     EEM_Registration::status_id_cancelled,
1004 1004
                     false,
@@ -1027,7 +1027,7 @@  discard block
 block discarded – undo
1027 1027
                 'espresso_registrations_new_registration',
1028 1028
                 $EVT_ID
1029 1029
             )) {
1030
-                $this->_admin_page_title .= ' ' . $this->get_action_link_or_button(
1030
+                $this->_admin_page_title .= ' '.$this->get_action_link_or_button(
1031 1031
                     'new_registration',
1032 1032
                     'add-registrant',
1033 1033
                     array('event_id' => $EVT_ID),
@@ -1067,7 +1067,7 @@  discard block
 block discarded – undo
1067 1067
                 $this->_template_args['admin_page_header'] .= ' &nbsp;<span class="drk-grey-text">';
1068 1068
                 $this->_template_args['admin_page_header'] .= '<span class="dashicons dashicons-calendar"></span>';
1069 1069
                 $this->_template_args['admin_page_header'] .= $datetime->name();
1070
-                $this->_template_args['admin_page_header'] .= ' ( ' . $datetime->start_date() . ' )';
1070
+                $this->_template_args['admin_page_header'] .= ' ( '.$datetime->start_date().' )';
1071 1071
                 $this->_template_args['admin_page_header'] .= '</span></h3>';
1072 1072
             }
1073 1073
         }
@@ -1174,7 +1174,7 @@  discard block
 block discarded – undo
1174 1174
             'caps'                     => EEM_Registration::caps_read_admin,
1175 1175
             'default_where_conditions' => 'this_model_only',
1176 1176
         );
1177
-        if (! $count) {
1177
+        if ( ! $count) {
1178 1178
             $query_params = array_merge(
1179 1179
                 $query_params,
1180 1180
                 $this->_get_orderby_for_registrations_query(),
@@ -1195,7 +1195,7 @@  discard block
 block discarded – undo
1195 1195
     protected function _add_event_id_to_where_conditions(array $request)
1196 1196
     {
1197 1197
         $where = array();
1198
-        if (! empty($request['event_id'])) {
1198
+        if ( ! empty($request['event_id'])) {
1199 1199
             $where['EVT_ID'] = absint($request['event_id']);
1200 1200
         }
1201 1201
         return $where;
@@ -1211,7 +1211,7 @@  discard block
 block discarded – undo
1211 1211
     protected function _add_category_id_to_where_conditions(array $request)
1212 1212
     {
1213 1213
         $where = array();
1214
-        if (! empty($request['EVT_CAT']) && (int)$request['EVT_CAT'] !== -1) {
1214
+        if ( ! empty($request['EVT_CAT']) && (int) $request['EVT_CAT'] !== -1) {
1215 1215
             $where['Event.Term_Taxonomy.term_id'] = absint($request['EVT_CAT']);
1216 1216
         }
1217 1217
         return $where;
@@ -1227,10 +1227,10 @@  discard block
 block discarded – undo
1227 1227
     protected function _add_datetime_id_to_where_conditions(array $request)
1228 1228
     {
1229 1229
         $where = array();
1230
-        if (! empty($request['datetime_id'])) {
1230
+        if ( ! empty($request['datetime_id'])) {
1231 1231
             $where['Ticket.Datetime.DTT_ID'] = absint($request['datetime_id']);
1232 1232
         }
1233
-        if (! empty($request['DTT_ID'])) {
1233
+        if ( ! empty($request['DTT_ID'])) {
1234 1234
             $where['Ticket.Datetime.DTT_ID'] = absint($request['DTT_ID']);
1235 1235
         }
1236 1236
         return $where;
@@ -1256,7 +1256,7 @@  discard block
 block discarded – undo
1256 1256
          * If not filtering by specified status, then we show all registrations excluding incomplete registrations
1257 1257
          * UNLESS viewing trashed registrations.
1258 1258
          */
1259
-        if (! empty($registration_status)) {
1259
+        if ( ! empty($registration_status)) {
1260 1260
             $where['STS_ID'] = $registration_status;
1261 1261
         } else {
1262 1262
             //make sure we exclude incomplete registrations, but only if not trashed.
@@ -1299,12 +1299,12 @@  discard block
 block discarded – undo
1299 1299
                 array(
1300 1300
                     EEM_Registration::instance()->convert_datetime_for_query(
1301 1301
                         'REG_date',
1302
-                        $now . ' 00:00:00',
1302
+                        $now.' 00:00:00',
1303 1303
                         'Y-m-d H:i:s'
1304 1304
                     ),
1305 1305
                     EEM_Registration::instance()->convert_datetime_for_query(
1306 1306
                         'REG_date',
1307
-                        $now . ' 23:59:59',
1307
+                        $now.' 23:59:59',
1308 1308
                         'Y-m-d H:i:s'
1309 1309
                     ),
1310 1310
                 ),
@@ -1317,12 +1317,12 @@  discard block
 block discarded – undo
1317 1317
                 array(
1318 1318
                     EEM_Registration::instance()->convert_datetime_for_query(
1319 1319
                         'REG_date',
1320
-                        $current_year_and_month . '-01 00:00:00',
1320
+                        $current_year_and_month.'-01 00:00:00',
1321 1321
                         'Y-m-d H:i:s'
1322 1322
                     ),
1323 1323
                     EEM_Registration::instance()->convert_datetime_for_query(
1324 1324
                         'REG_date',
1325
-                        $current_year_and_month . '-' . $days_this_month . ' 23:59:59',
1325
+                        $current_year_and_month.'-'.$days_this_month.' 23:59:59',
1326 1326
                         'Y-m-d H:i:s'
1327 1327
                     ),
1328 1328
                 ),
@@ -1337,18 +1337,18 @@  discard block
 block discarded – undo
1337 1337
                 : '';
1338 1338
             //if there is not a month or year then we can't go further
1339 1339
             if ($month_requested && $year_requested) {
1340
-                $days_in_month     = date('t', strtotime($year_requested . '-' . $month_requested . '-' . '01'));
1340
+                $days_in_month     = date('t', strtotime($year_requested.'-'.$month_requested.'-'.'01'));
1341 1341
                 $where['REG_date'] = array(
1342 1342
                     'BETWEEN',
1343 1343
                     array(
1344 1344
                         EEM_Registration::instance()->convert_datetime_for_query(
1345 1345
                             'REG_date',
1346
-                            $year_requested . '-' . $month_requested . '-01 00:00:00',
1346
+                            $year_requested.'-'.$month_requested.'-01 00:00:00',
1347 1347
                             'Y-m-d H:i:s'
1348 1348
                         ),
1349 1349
                         EEM_Registration::instance()->convert_datetime_for_query(
1350 1350
                             'REG_date',
1351
-                            $year_requested . '-' . $month_requested . '-' . $days_in_month . ' 23:59:59',
1351
+                            $year_requested.'-'.$month_requested.'-'.$days_in_month.' 23:59:59',
1352 1352
                             'Y-m-d H:i:s'
1353 1353
                         ),
1354 1354
                     ),
@@ -1368,8 +1368,8 @@  discard block
 block discarded – undo
1368 1368
     protected function _add_search_to_where_conditions(array $request)
1369 1369
     {
1370 1370
         $where = array();
1371
-        if (! empty($request['s'])) {
1372
-            $search_string = '%' . sanitize_text_field($request['s']) . '%';
1371
+        if ( ! empty($request['s'])) {
1372
+            $search_string = '%'.sanitize_text_field($request['s']).'%';
1373 1373
             $where['OR*search_conditions'] = array(
1374 1374
                 'Event.EVT_name'                          => array('LIKE', $search_string),
1375 1375
                 'Event.EVT_desc'                          => array('LIKE', $search_string),
@@ -1487,7 +1487,7 @@  discard block
 block discarded – undo
1487 1487
             : $per_page;
1488 1488
 
1489 1489
         //-1 means return all results so get out if that's set.
1490
-        if ((int)$per_page === -1) {
1490
+        if ((int) $per_page === -1) {
1491 1491
             return array();
1492 1492
         }
1493 1493
         $per_page = absint($per_page);
@@ -1543,7 +1543,7 @@  discard block
 block discarded – undo
1543 1543
                 ),
1544 1544
                 REG_ADMIN_URL
1545 1545
             );
1546
-            $this->_template_args['filtered_transactions_link']  = EE_Admin_Page::add_query_args_and_nonce(
1546
+            $this->_template_args['filtered_transactions_link'] = EE_Admin_Page::add_query_args_and_nonce(
1547 1547
                 array(
1548 1548
                     'action' => 'default',
1549 1549
                     'EVT_ID' => $event_id,
@@ -1551,7 +1551,7 @@  discard block
 block discarded – undo
1551 1551
                 ),
1552 1552
                 admin_url('admin.php')
1553 1553
             );
1554
-            $this->_template_args['event_link']                  = EE_Admin_Page::add_query_args_and_nonce(
1554
+            $this->_template_args['event_link'] = EE_Admin_Page::add_query_args_and_nonce(
1555 1555
                 array(
1556 1556
                     'page'   => 'espresso_events',
1557 1557
                     'action' => 'edit',
@@ -1560,12 +1560,12 @@  discard block
 block discarded – undo
1560 1560
                 admin_url('admin.php')
1561 1561
             );
1562 1562
             //next and previous links
1563
-            $next_reg                                      = $this->_registration->next(
1563
+            $next_reg = $this->_registration->next(
1564 1564
                 null,
1565 1565
                 array(),
1566 1566
                 'REG_ID'
1567 1567
             );
1568
-            $this->_template_args['next_registration']     = $next_reg
1568
+            $this->_template_args['next_registration'] = $next_reg
1569 1569
                 ? $this->_next_link(
1570 1570
                     EE_Admin_Page::add_query_args_and_nonce(
1571 1571
                         array(
@@ -1577,7 +1577,7 @@  discard block
 block discarded – undo
1577 1577
                     'dashicons dashicons-arrow-right ee-icon-size-22'
1578 1578
                 )
1579 1579
                 : '';
1580
-            $previous_reg                                  = $this->_registration->previous(
1580
+            $previous_reg = $this->_registration->previous(
1581 1581
                 null,
1582 1582
                 array(),
1583 1583
                 'REG_ID'
@@ -1595,7 +1595,7 @@  discard block
 block discarded – undo
1595 1595
                 )
1596 1596
                 : '';
1597 1597
             // grab header
1598
-            $template_path                             = REG_TEMPLATE_PATH . 'reg_admin_details_header.template.php';
1598
+            $template_path                             = REG_TEMPLATE_PATH.'reg_admin_details_header.template.php';
1599 1599
             $this->_template_args['REG_ID']            = $this->_registration->ID();
1600 1600
             $this->_template_args['admin_page_header'] = EEH_Template::display_template(
1601 1601
                 $template_path,
@@ -1715,7 +1715,7 @@  discard block
 block discarded – undo
1715 1715
                             EEH_HTML::strong(
1716 1716
                                 $this->_registration->pretty_status(),
1717 1717
                                 '',
1718
-                                'status-' . $this->_registration->status_ID(),
1718
+                                'status-'.$this->_registration->status_ID(),
1719 1719
                                 'line-height: 1em; font-size: 1.5em; font-weight: bold;'
1720 1720
                             )
1721 1721
                         )
@@ -1795,11 +1795,11 @@  discard block
 block discarded – undo
1795 1795
     {
1796 1796
         if (isset($this->_req_data['reg_status_change_form'])) {
1797 1797
             $REG_IDs = isset($this->_req_data['reg_status_change_form']['REG_ID'])
1798
-                ? (array)$this->_req_data['reg_status_change_form']['REG_ID']
1798
+                ? (array) $this->_req_data['reg_status_change_form']['REG_ID']
1799 1799
                 : array();
1800 1800
         } else {
1801 1801
             $REG_IDs = isset($this->_req_data['_REG_ID'])
1802
-                ? (array)$this->_req_data['_REG_ID']
1802
+                ? (array) $this->_req_data['_REG_ID']
1803 1803
                 : array();
1804 1804
         }
1805 1805
         // sanitize $REG_IDs
@@ -1862,7 +1862,7 @@  discard block
 block discarded – undo
1862 1862
     {
1863 1863
         $success = false;
1864 1864
         // typecast $REG_IDs
1865
-        $REG_IDs = (array)$REG_IDs;
1865
+        $REG_IDs = (array) $REG_IDs;
1866 1866
         if ( ! empty($REG_IDs)) {
1867 1867
             $success = true;
1868 1868
             // set default status if none is passed
@@ -2012,7 +2012,7 @@  discard block
 block discarded – undo
2012 2012
             $action,
2013 2013
             $notify
2014 2014
         );
2015
-        $method = $action . '_registration';
2015
+        $method = $action.'_registration';
2016 2016
         if (method_exists($this, $method)) {
2017 2017
             $this->$method($notify);
2018 2018
         }
@@ -2130,7 +2130,7 @@  discard block
 block discarded – undo
2130 2130
             $filtered_line_item_tree,
2131 2131
             array('EE_Registration' => $this->_registration)
2132 2132
         );
2133
-        $attendee                                = $this->_registration->attendee();
2133
+        $attendee = $this->_registration->attendee();
2134 2134
         if (EE_Registry::instance()->CAP->current_user_can(
2135 2135
             'ee_read_transaction',
2136 2136
             'espresso_transactions_view_transaction'
@@ -2209,7 +2209,7 @@  discard block
 block discarded – undo
2209 2209
                 'Payment method response',
2210 2210
                 'event_espresso'
2211 2211
             );
2212
-            $this->_template_args['reg_details']['response_msg']['class']   = 'regular-text';
2212
+            $this->_template_args['reg_details']['response_msg']['class'] = 'regular-text';
2213 2213
         }
2214 2214
         $this->_template_args['reg_details']['registration_session']['value'] = $reg_details['registration_session'];
2215 2215
         $this->_template_args['reg_details']['registration_session']['label'] = esc_html__(
@@ -2237,7 +2237,7 @@  discard block
 block discarded – undo
2237 2237
         $this->_template_args['REG_ID']                                       = $this->_registration->ID();
2238 2238
         $this->_template_args['event_id']                                     = $this->_registration->event_ID();
2239 2239
         $template_path                                                        =
2240
-            REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_reg_details.template.php';
2240
+            REG_TEMPLATE_PATH.'reg_admin_details_main_meta_box_reg_details.template.php';
2241 2241
         echo EEH_Template::display_template($template_path, $this->_template_args, true);
2242 2242
     }
2243 2243
 
@@ -2266,7 +2266,7 @@  discard block
 block discarded – undo
2266 2266
             $this->_template_args['reg_questions_form_action'] = 'edit_registration';
2267 2267
             $this->_template_args['REG_ID']                    = $this->_registration->ID();
2268 2268
             $template_path                                     =
2269
-                REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_reg_questions.template.php';
2269
+                REG_TEMPLATE_PATH.'reg_admin_details_main_meta_box_reg_questions.template.php';
2270 2270
             echo EEH_Template::display_template($template_path, $this->_template_args, true);
2271 2271
         }
2272 2272
     }
@@ -2283,7 +2283,7 @@  discard block
 block discarded – undo
2283 2283
     public function form_before_question_group($output)
2284 2284
     {
2285 2285
         EE_Error::doing_it_wrong(
2286
-            __CLASS__ . '::' . __FUNCTION__,
2286
+            __CLASS__.'::'.__FUNCTION__,
2287 2287
             esc_html__(
2288 2288
                 'This method would have been protected but was used on a filter callback so needed to be public. Please discontinue usage as it will be removed soon.',
2289 2289
                 'event_espresso'
@@ -2308,7 +2308,7 @@  discard block
 block discarded – undo
2308 2308
     public function form_after_question_group($output)
2309 2309
     {
2310 2310
         EE_Error::doing_it_wrong(
2311
-            __CLASS__ . '::' . __FUNCTION__,
2311
+            __CLASS__.'::'.__FUNCTION__,
2312 2312
             esc_html__(
2313 2313
                 'This method would have been protected but was used on a filter callback so needed to be public. Please discontinue usage as it will be removed soon.',
2314 2314
                 'event_espresso'
@@ -2346,7 +2346,7 @@  discard block
 block discarded – undo
2346 2346
     public function form_form_field_label_wrap($label)
2347 2347
     {
2348 2348
         EE_Error::doing_it_wrong(
2349
-            __CLASS__ . '::' . __FUNCTION__,
2349
+            __CLASS__.'::'.__FUNCTION__,
2350 2350
             esc_html__(
2351 2351
                 'This method would have been protected but was used on a filter callback so needed to be public. Please discontinue usage as it will be removed soon.',
2352 2352
                 'event_espresso'
@@ -2356,7 +2356,7 @@  discard block
 block discarded – undo
2356 2356
         return '
2357 2357
 			<tr>
2358 2358
 				<th>
2359
-					' . $label . '
2359
+					' . $label.'
2360 2360
 				</th>';
2361 2361
     }
2362 2362
 
@@ -2372,7 +2372,7 @@  discard block
 block discarded – undo
2372 2372
     public function form_form_field_input__wrap($input)
2373 2373
     {
2374 2374
         EE_Error::doing_it_wrong(
2375
-            __CLASS__ . '::' . __FUNCTION__,
2375
+            __CLASS__.'::'.__FUNCTION__,
2376 2376
             esc_html__(
2377 2377
                 'This method would have been protected but was used on a filter callback so needed to be public. Please discontinue usage as it will be removed soon.',
2378 2378
                 'event_espresso'
@@ -2381,7 +2381,7 @@  discard block
 block discarded – undo
2381 2381
         );
2382 2382
         return '
2383 2383
 				<td class="reg-admin-attendee-questions-input-td disabled-input">
2384
-					' . $input . '
2384
+					' . $input.'
2385 2385
 				</td>
2386 2386
 			</tr>';
2387 2387
     }
@@ -2426,7 +2426,7 @@  discard block
 block discarded – undo
2426 2426
     protected function _get_reg_custom_questions_form($REG_ID)
2427 2427
     {
2428 2428
         if ( ! $this->_reg_custom_questions_form) {
2429
-            require_once(REG_ADMIN . 'form_sections' . DS . 'EE_Registration_Custom_Questions_Form.form.php');
2429
+            require_once(REG_ADMIN.'form_sections'.DS.'EE_Registration_Custom_Questions_Form.form.php');
2430 2430
             $this->_reg_custom_questions_form = new EE_Registration_Custom_Questions_Form(
2431 2431
                 EEM_Registration::instance()->get_one_by_ID($REG_ID)
2432 2432
             );
@@ -2462,7 +2462,7 @@  discard block
 block discarded – undo
2462 2462
         if ($form->is_valid()) {
2463 2463
             foreach ($form->subforms() as $question_group_id => $question_group_form) {
2464 2464
                 foreach ($question_group_form->inputs() as $question_id => $input) {
2465
-                    $where_conditions    = array(
2465
+                    $where_conditions = array(
2466 2466
                         'QST_ID' => $question_id,
2467 2467
                         'REG_ID' => $REG_ID,
2468 2468
                     );
@@ -2503,7 +2503,7 @@  discard block
 block discarded – undo
2503 2503
         $REG = EEM_Registration::instance();
2504 2504
         //get all other registrations on this transaction, and cache
2505 2505
         //the attendees for them so we don't have to run another query using force_join
2506
-        $registrations                           = $REG->get_all(array(
2506
+        $registrations = $REG->get_all(array(
2507 2507
             array(
2508 2508
                 'TXN_ID' => $this->_registration->transaction_ID(),
2509 2509
                 'REG_ID' => array('!=', $this->_registration->ID()),
@@ -2527,7 +2527,7 @@  discard block
 block discarded – undo
2527 2527
             $att_nmbr = 1;
2528 2528
             foreach ($registrations as $registration) {
2529 2529
                 /* @var $registration EE_Registration */
2530
-                $attendee                                                    = $registration->attendee()
2530
+                $attendee = $registration->attendee()
2531 2531
                     ? $registration->attendee()
2532 2532
                     : EEM_Attendee::instance()
2533 2533
                                   ->create_default_object();
@@ -2540,19 +2540,19 @@  discard block
 block discarded – undo
2540 2540
                     ', ',
2541 2541
                     $attendee->full_address_as_array()
2542 2542
                 );
2543
-                $this->_template_args['attendees'][$att_nmbr]['att_link']    = self::add_query_args_and_nonce(
2543
+                $this->_template_args['attendees'][$att_nmbr]['att_link'] = self::add_query_args_and_nonce(
2544 2544
                     array(
2545 2545
                         'action' => 'edit_attendee',
2546 2546
                         'post'   => $attendee->ID(),
2547 2547
                     ),
2548 2548
                     REG_ADMIN_URL
2549 2549
                 );
2550
-                $this->_template_args['attendees'][$att_nmbr]['event_name']  = $registration->event_obj()->name();
2550
+                $this->_template_args['attendees'][$att_nmbr]['event_name'] = $registration->event_obj()->name();
2551 2551
                 $att_nmbr++;
2552 2552
             }
2553 2553
             $this->_template_args['currency_sign'] = EE_Registry::instance()->CFG->currency->sign;
2554 2554
         }
2555
-        $template_path = REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_attendees.template.php';
2555
+        $template_path = REG_TEMPLATE_PATH.'reg_admin_details_main_meta_box_attendees.template.php';
2556 2556
         echo EEH_Template::display_template($template_path, $this->_template_args, true);
2557 2557
     }
2558 2558
 
@@ -2595,20 +2595,20 @@  discard block
 block discarded – undo
2595 2595
         $this->_template_args['phone']             = $attendee->phone();
2596 2596
         $this->_template_args['formatted_address'] = EEH_Address::format($attendee);
2597 2597
         //edit link
2598
-        $this->_template_args['att_edit_link']  = EE_Admin_Page::add_query_args_and_nonce(array(
2598
+        $this->_template_args['att_edit_link'] = EE_Admin_Page::add_query_args_and_nonce(array(
2599 2599
             'action' => 'edit_attendee',
2600 2600
             'post'   => $attendee->ID(),
2601 2601
         ), REG_ADMIN_URL);
2602 2602
         $this->_template_args['att_edit_label'] = esc_html__('View/Edit Contact', 'event_espresso');
2603 2603
         //create link
2604
-        $this->_template_args['create_link']  = $primary_registration instanceof EE_Registration
2604
+        $this->_template_args['create_link'] = $primary_registration instanceof EE_Registration
2605 2605
             ? EE_Admin_Page::add_query_args_and_nonce(array(
2606 2606
                 'action'  => 'duplicate_attendee',
2607 2607
                 '_REG_ID' => $this->_registration->ID(),
2608 2608
             ), REG_ADMIN_URL) : '';
2609 2609
         $this->_template_args['create_label'] = esc_html__('Create Contact', 'event_espresso');
2610 2610
         $this->_template_args['att_check']    = $att_check;
2611
-        $template_path                        = REG_TEMPLATE_PATH . 'reg_admin_details_side_meta_box_registrant.template.php';
2611
+        $template_path                        = REG_TEMPLATE_PATH.'reg_admin_details_side_meta_box_registrant.template.php';
2612 2612
         echo EEH_Template::display_template($template_path, $this->_template_args, true);
2613 2613
     }
2614 2614
 
@@ -2653,7 +2653,7 @@  discard block
 block discarded – undo
2653 2653
             /** @var EE_Registration $REG */
2654 2654
             $REG = EEM_Registration::instance()->get_one_by_ID($REG_ID);
2655 2655
             $payments = $REG->registration_payments();
2656
-            if (! empty($payments)) {
2656
+            if ( ! empty($payments)) {
2657 2657
                 $name = $REG->attendee() instanceof EE_Attendee
2658 2658
                     ? $REG->attendee()->full_name()
2659 2659
                     : esc_html__('Unknown Attendee', 'event_espresso');
@@ -2849,7 +2849,7 @@  discard block
 block discarded – undo
2849 2849
                 'action' => 'edit',
2850 2850
                 'post'   => $this->_reg_event->ID(),
2851 2851
             ), EVENTS_ADMIN_URL);
2852
-            $edit_event_lnk                     = '<a href="'
2852
+            $edit_event_lnk = '<a href="'
2853 2853
                                                   . $edit_event_url
2854 2854
                                                   . '" title="'
2855 2855
                                                   . esc_attr__('Edit ', 'event_espresso')
@@ -2867,7 +2867,7 @@  discard block
 block discarded – undo
2867 2867
         }
2868 2868
         // grab header
2869 2869
         $template_path                              =
2870
-            REG_TEMPLATE_PATH . 'reg_admin_register_new_attendee.template.php';
2870
+            REG_TEMPLATE_PATH.'reg_admin_register_new_attendee.template.php';
2871 2871
         $this->_template_args['admin_page_content'] = EEH_Template::display_template($template_path,
2872 2872
             $this->_template_args, true);
2873 2873
         //$this->_set_publish_post_box_vars( NULL, FALSE, FALSE, NULL, FALSE );
@@ -2905,7 +2905,7 @@  discard block
 block discarded – undo
2905 2905
                 '</b>'
2906 2906
             );
2907 2907
             return '
2908
-	<div id="ee-add-reg-back-button-dv"><p>' . $warning_msg . '</p></div>
2908
+	<div id="ee-add-reg-back-button-dv"><p>' . $warning_msg.'</p></div>
2909 2909
 	<script >
2910 2910
 		// WHOAH !!! it appears that someone is using the back button from the Transaction admin page
2911 2911
 		// after just adding a new registration... we gotta try to put a stop to that !!!
@@ -2973,7 +2973,7 @@  discard block
 block discarded – undo
2973 2973
         //we come back to the process_registration_step route.
2974 2974
         $this->_set_add_edit_form_tags('process_reg_step', $hidden_fields);
2975 2975
         return EEH_Template::display_template(
2976
-            REG_TEMPLATE_PATH . 'reg_admin_register_new_attendee_step_content.template.php',
2976
+            REG_TEMPLATE_PATH.'reg_admin_register_new_attendee_step_content.template.php',
2977 2977
             $template_args,
2978 2978
             true
2979 2979
         );
@@ -2995,7 +2995,7 @@  discard block
 block discarded – undo
2995 2995
         if (is_object($this->_reg_event)) {
2996 2996
             return true;
2997 2997
         }
2998
-        $EVT_ID = (! empty($this->_req_data['event_id'])) ? absint($this->_req_data['event_id']) : false;
2998
+        $EVT_ID = ( ! empty($this->_req_data['event_id'])) ? absint($this->_req_data['event_id']) : false;
2999 2999
         if ( ! $EVT_ID) {
3000 3000
             return false;
3001 3001
         }
@@ -3065,7 +3065,7 @@  discard block
 block discarded – undo
3065 3065
                 }
3066 3066
                 break;
3067 3067
             case 'questions' :
3068
-                if (! isset(
3068
+                if ( ! isset(
3069 3069
                     $this->_req_data['txn_reg_status_change'],
3070 3070
                     $this->_req_data['txn_reg_status_change']['send_notifications'])
3071 3071
                 ) {
@@ -3185,7 +3185,7 @@  discard block
 block discarded – undo
3185 3185
     public function get_attendees($per_page, $count = false, $trash = false)
3186 3186
     {
3187 3187
         do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3188
-        require_once(REG_ADMIN . 'EE_Attendee_Contact_List_Table.class.php');
3188
+        require_once(REG_ADMIN.'EE_Attendee_Contact_List_Table.class.php');
3189 3189
         $ATT_MDL                    = EEM_Attendee::instance();
3190 3190
         $this->_req_data['orderby'] = ! empty($this->_req_data['orderby']) ? $this->_req_data['orderby'] : '';
3191 3191
         switch ($this->_req_data['orderby']) {
@@ -3222,7 +3222,7 @@  discard block
 block discarded – undo
3222 3222
             : $per_page;
3223 3223
         $_where       = array();
3224 3224
         if ( ! empty($this->_req_data['s'])) {
3225
-            $sstr         = '%' . $this->_req_data['s'] . '%';
3225
+            $sstr         = '%'.$this->_req_data['s'].'%';
3226 3226
             $_where['OR'] = array(
3227 3227
                 'Registration.Event.EVT_name'       => array('LIKE', $sstr),
3228 3228
                 'Registration.Event.EVT_desc'       => array('LIKE', $sstr),
@@ -3298,9 +3298,9 @@  discard block
 block discarded – undo
3298 3298
      *                                                     the query parameters from the request
3299 3299
      * @return void ends the request with a redirect or download
3300 3300
      */
3301
-    public function _registrations_report_base( $method_name_for_getting_query_params )
3301
+    public function _registrations_report_base($method_name_for_getting_query_params)
3302 3302
     {
3303
-        if (! defined('EE_USE_OLD_CSV_REPORT_CLASS')) {
3303
+        if ( ! defined('EE_USE_OLD_CSV_REPORT_CLASS')) {
3304 3304
             wp_redirect(EE_Admin_Page::add_query_args_and_nonce(
3305 3305
                 array(
3306 3306
                     'page'        => 'espresso_batch',
@@ -3309,7 +3309,7 @@  discard block
 block discarded – undo
3309 3309
                     'filters'     => urlencode(
3310 3310
                         serialize(
3311 3311
                             call_user_func(
3312
-                                array( $this, $method_name_for_getting_query_params ),
3312
+                                array($this, $method_name_for_getting_query_params),
3313 3313
                                 EEH_Array::is_set(
3314 3314
                                     $this->_req_data,
3315 3315
                                     'filters',
@@ -3329,8 +3329,8 @@  discard block
 block discarded – undo
3329 3329
                 'EVT_ID' => isset($this->_req_data['EVT_ID']) ? $this->_req_data['EVT_ID'] : null,
3330 3330
             );
3331 3331
             $this->_req_data = array_merge($this->_req_data, $new_request_args);
3332
-            if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
3333
-                require_once(EE_CLASSES . 'EE_Export.class.php');
3332
+            if (is_readable(EE_CLASSES.'EE_Export.class.php')) {
3333
+                require_once(EE_CLASSES.'EE_Export.class.php');
3334 3334
                 $EE_Export = EE_Export::instance($this->_req_data);
3335 3335
                 $EE_Export->export();
3336 3336
             }
@@ -3351,8 +3351,8 @@  discard block
 block discarded – undo
3351 3351
 
3352 3352
     public function _contact_list_export()
3353 3353
     {
3354
-        if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
3355
-            require_once(EE_CLASSES . 'EE_Export.class.php');
3354
+        if (is_readable(EE_CLASSES.'EE_Export.class.php')) {
3355
+            require_once(EE_CLASSES.'EE_Export.class.php');
3356 3356
             $EE_Export = EE_Export::instance($this->_req_data);
3357 3357
             $EE_Export->export_attendees();
3358 3358
         }
@@ -3369,8 +3369,8 @@  discard block
 block discarded – undo
3369 3369
                 'return_url'  => urlencode($this->_req_data['return_url']),
3370 3370
             )));
3371 3371
         } else {
3372
-            if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
3373
-                require_once(EE_CLASSES . 'EE_Export.class.php');
3372
+            if (is_readable(EE_CLASSES.'EE_Export.class.php')) {
3373
+                require_once(EE_CLASSES.'EE_Export.class.php');
3374 3374
                 $EE_Export = EE_Export::instance($this->_req_data);
3375 3375
                 $EE_Export->report_attendees();
3376 3376
             }
@@ -3452,7 +3452,7 @@  discard block
 block discarded – undo
3452 3452
             $updated_fields = array(
3453 3453
                 'ATT_fname'     => $this->_req_data['ATT_fname'],
3454 3454
                 'ATT_lname'     => $this->_req_data['ATT_lname'],
3455
-                'ATT_full_name' => $this->_req_data['ATT_fname'] . ' ' . $this->_req_data['ATT_lname'],
3455
+                'ATT_full_name' => $this->_req_data['ATT_fname'].' '.$this->_req_data['ATT_lname'],
3456 3456
                 'ATT_address'   => isset($this->_req_data['ATT_address']) ? $this->_req_data['ATT_address'] : '',
3457 3457
                 'ATT_address2'  => isset($this->_req_data['ATT_address2']) ? $this->_req_data['ATT_address2'] : '',
3458 3458
                 'ATT_city'      => isset($this->_req_data['ATT_city']) ? $this->_req_data['ATT_city'] : '',
@@ -3670,8 +3670,8 @@  discard block
 block discarded – undo
3670 3670
                 )
3671 3671
             )
3672 3672
         );
3673
-        $template                             =
3674
-            REG_TEMPLATE_PATH . 'attendee_address_details_metabox_content.template.php';
3673
+        $template =
3674
+            REG_TEMPLATE_PATH.'attendee_address_details_metabox_content.template.php';
3675 3675
         EEH_Template::display_template($template, $this->_template_args);
3676 3676
     }
3677 3677
 
@@ -3690,7 +3690,7 @@  discard block
 block discarded – undo
3690 3690
         $this->_template_args['attendee']      = $this->_cpt_model_obj;
3691 3691
         $this->_template_args['registrations'] = $this->_cpt_model_obj->get_many_related('Registration');
3692 3692
         $template                              =
3693
-            REG_TEMPLATE_PATH . 'attendee_registrations_main_meta_box.template.php';
3693
+            REG_TEMPLATE_PATH.'attendee_registrations_main_meta_box.template.php';
3694 3694
         EEH_Template::display_template($template, $this->_template_args);
3695 3695
     }
3696 3696
 
@@ -3705,7 +3705,7 @@  discard block
 block discarded – undo
3705 3705
     public function after_title_form_fields($post)
3706 3706
     {
3707 3707
         if ($post->post_type == 'espresso_attendees') {
3708
-            $template                  = REG_TEMPLATE_PATH . 'attendee_details_after_title_form_fields.template.php';
3708
+            $template                  = REG_TEMPLATE_PATH.'attendee_details_after_title_form_fields.template.php';
3709 3709
             $template_args['attendee'] = $this->_cpt_model_obj;
3710 3710
             EEH_Template::display_template($template, $template_args);
3711 3711
         }
Please login to merge, or discard this patch.
Indentation   +3688 added lines, -3688 removed lines patch added patch discarded remove patch
@@ -30,2299 +30,2299 @@  discard block
 block discarded – undo
30 30
 class Registrations_Admin_Page extends EE_Admin_Page_CPT
31 31
 {
32 32
 
33
-    /**
34
-     * @var EE_Registration
35
-     */
36
-    private $_registration;
37
-
38
-    /**
39
-     * @var EE_Event
40
-     */
41
-    private $_reg_event;
42
-
43
-    /**
44
-     * @var EE_Session
45
-     */
46
-    private $_session;
47
-
48
-    private static $_reg_status;
49
-
50
-    /**
51
-     * Form for displaying the custom questions for this registration.
52
-     * This gets used a few times throughout the request so its best to cache it
53
-     *
54
-     * @var EE_Registration_Custom_Questions_Form
55
-     */
56
-    protected $_reg_custom_questions_form = null;
57
-
58
-
59
-    /**
60
-     *        constructor
61
-     *
62
-     * @Constructor
63
-     * @access public
64
-     * @param bool $routing
65
-     * @return Registrations_Admin_Page
66
-     */
67
-    public function __construct($routing = true)
68
-    {
69
-        parent::__construct($routing);
70
-        add_action('wp_loaded', array($this, 'wp_loaded'));
71
-    }
72
-
73
-
74
-    public function wp_loaded()
75
-    {
76
-        // when adding a new registration...
77
-        if (isset($this->_req_data['action']) && $this->_req_data['action'] === 'new_registration') {
78
-            EE_System::do_not_cache();
79
-            if (! isset($this->_req_data['processing_registration'])
80
-                 || absint($this->_req_data['processing_registration']) !== 1
81
-            ) {
82
-                // and it's NOT the attendee information reg step
83
-                // force cookie expiration by setting time to last week
84
-                setcookie('ee_registration_added', 0, time() - WEEK_IN_SECONDS, '/');
85
-                // and update the global
86
-                $_COOKIE['ee_registration_added'] = 0;
87
-            }
88
-        }
89
-    }
90
-
91
-
92
-    protected function _init_page_props()
93
-    {
94
-        $this->page_slug        = REG_PG_SLUG;
95
-        $this->_admin_base_url  = REG_ADMIN_URL;
96
-        $this->_admin_base_path = REG_ADMIN;
97
-        $this->page_label       = esc_html__('Registrations', 'event_espresso');
98
-        $this->_cpt_routes      = array(
99
-            'add_new_attendee' => 'espresso_attendees',
100
-            'edit_attendee'    => 'espresso_attendees',
101
-            'insert_attendee'  => 'espresso_attendees',
102
-            'update_attendee'  => 'espresso_attendees',
103
-        );
104
-        $this->_cpt_model_names = array(
105
-            'add_new_attendee' => 'EEM_Attendee',
106
-            'edit_attendee'    => 'EEM_Attendee',
107
-        );
108
-        $this->_cpt_edit_routes = array(
109
-            'espresso_attendees' => 'edit_attendee',
110
-        );
111
-        $this->_pagenow_map     = array(
112
-            'add_new_attendee' => 'post-new.php',
113
-            'edit_attendee'    => 'post.php',
114
-            'trash'            => 'post.php',
115
-        );
116
-        add_action('edit_form_after_title', array($this, 'after_title_form_fields'), 10);
117
-        //add filters so that the comment urls don't take users to a confusing 404 page
118
-        add_filter('get_comment_link', array($this, 'clear_comment_link'), 10, 3);
119
-    }
120
-
121
-
122
-    public function clear_comment_link($link, $comment, $args)
123
-    {
124
-        //gotta make sure this only happens on this route
125
-        $post_type = get_post_type($comment->comment_post_ID);
126
-        if ($post_type === 'espresso_attendees') {
127
-            return '#commentsdiv';
128
-        }
129
-        return $link;
130
-    }
131
-
132
-
133
-    protected function _ajax_hooks()
134
-    {
135
-        //todo: all hooks for registrations ajax goes in here
136
-        add_action('wp_ajax_toggle_checkin_status', array($this, 'toggle_checkin_status'));
137
-    }
138
-
139
-
140
-    protected function _define_page_props()
141
-    {
142
-        $this->_admin_page_title = $this->page_label;
143
-        $this->_labels           = array(
144
-            'buttons'                      => array(
145
-                'add-registrant'      => esc_html__('Add New Registration', 'event_espresso'),
146
-                'add-attendee'        => esc_html__('Add Contact', 'event_espresso'),
147
-                'edit'                => esc_html__('Edit Contact', 'event_espresso'),
148
-                'report'              => esc_html__("Event Registrations CSV Report", "event_espresso"),
149
-                'report_all'          => esc_html__('All Registrations CSV Report', 'event_espresso'),
150
-                'report_filtered'     => esc_html__('Filtered CSV Report', 'event_espresso'),
151
-                'contact_list_report' => esc_html__('Contact List Report', 'event_espresso'),
152
-                'contact_list_export' => esc_html__("Export Data", "event_espresso"),
153
-            ),
154
-            'publishbox'                   => array(
155
-                'add_new_attendee' => esc_html__("Add Contact Record", 'event_espresso'),
156
-                'edit_attendee'    => esc_html__("Update Contact Record", 'event_espresso'),
157
-            ),
158
-            'hide_add_button_on_cpt_route' => array(
159
-                'edit_attendee' => true,
160
-            ),
161
-        );
162
-    }
163
-
164
-
165
-    /**
166
-     *        grab url requests and route them
167
-     *
168
-     * @access private
169
-     * @return void
170
-     */
171
-    public function _set_page_routes()
172
-    {
173
-        $this->_get_registration_status_array();
174
-        $reg_id             = ! empty($this->_req_data['_REG_ID']) && ! is_array($this->_req_data['_REG_ID'])
175
-            ? $this->_req_data['_REG_ID'] : 0;
176
-        $reg_id = empty($reg_id) && ! empty($this->_req_data['reg_status_change_form']['REG_ID'])
177
-            ? $this->_req_data['reg_status_change_form']['REG_ID']
178
-            : $reg_id;
179
-        $att_id             = ! empty($this->_req_data['ATT_ID']) && ! is_array($this->_req_data['ATT_ID'])
180
-            ? $this->_req_data['ATT_ID'] : 0;
181
-        $att_id             = ! empty($this->_req_data['post']) && ! is_array($this->_req_data['post'])
182
-            ? $this->_req_data['post']
183
-            : $att_id;
184
-        $this->_page_routes = array(
185
-            'default'                            => array(
186
-                'func'       => '_registrations_overview_list_table',
187
-                'capability' => 'ee_read_registrations',
188
-            ),
189
-            'view_registration'                  => array(
190
-                'func'       => '_registration_details',
191
-                'capability' => 'ee_read_registration',
192
-                'obj_id'     => $reg_id,
193
-            ),
194
-            'edit_registration'                  => array(
195
-                'func'               => '_update_attendee_registration_form',
196
-                'noheader'           => true,
197
-                'headers_sent_route' => 'view_registration',
198
-                'capability'         => 'ee_edit_registration',
199
-                'obj_id'             => $reg_id,
200
-                '_REG_ID'            => $reg_id,
201
-            ),
202
-            'trash_registrations'                => array(
203
-                'func'       => '_trash_or_restore_registrations',
204
-                'args'       => array('trash' => true),
205
-                'noheader'   => true,
206
-                'capability' => 'ee_delete_registrations',
207
-            ),
208
-            'restore_registrations'              => array(
209
-                'func'       => '_trash_or_restore_registrations',
210
-                'args'       => array('trash' => false),
211
-                'noheader'   => true,
212
-                'capability' => 'ee_delete_registrations',
213
-            ),
214
-            'delete_registrations'               => array(
215
-                'func'       => '_delete_registrations',
216
-                'noheader'   => true,
217
-                'capability' => 'ee_delete_registrations',
218
-            ),
219
-            'new_registration'                   => array(
220
-                'func'       => 'new_registration',
221
-                'capability' => 'ee_edit_registrations',
222
-            ),
223
-            'process_reg_step'                   => array(
224
-                'func'       => 'process_reg_step',
225
-                'noheader'   => true,
226
-                'capability' => 'ee_edit_registrations',
227
-            ),
228
-            'redirect_to_txn'                    => array(
229
-                'func'       => 'redirect_to_txn',
230
-                'noheader'   => true,
231
-                'capability' => 'ee_edit_registrations',
232
-            ),
233
-            'change_reg_status'                  => array(
234
-                'func'       => '_change_reg_status',
235
-                'noheader'   => true,
236
-                'capability' => 'ee_edit_registration',
237
-                'obj_id'     => $reg_id,
238
-            ),
239
-            'approve_registration'               => array(
240
-                'func'       => 'approve_registration',
241
-                'noheader'   => true,
242
-                'capability' => 'ee_edit_registration',
243
-                'obj_id'     => $reg_id,
244
-            ),
245
-            'approve_and_notify_registration'    => array(
246
-                'func'       => 'approve_registration',
247
-                'noheader'   => true,
248
-                'args'       => array(true),
249
-                'capability' => 'ee_edit_registration',
250
-                'obj_id'     => $reg_id,
251
-            ),
252
-            'approve_registrations'               => array(
253
-                'func'       => 'bulk_action_on_registrations',
254
-                'noheader'   => true,
255
-                'capability' => 'ee_edit_registrations',
256
-                'args' => array('approve')
257
-            ),
258
-            'approve_and_notify_registrations'               => array(
259
-                'func'       => 'bulk_action_on_registrations',
260
-                'noheader'   => true,
261
-                'capability' => 'ee_edit_registrations',
262
-                'args' => array('approve', true)
263
-            ),
264
-            'decline_registration'               => array(
265
-                'func'       => 'decline_registration',
266
-                'noheader'   => true,
267
-                'capability' => 'ee_edit_registration',
268
-                'obj_id'     => $reg_id,
269
-            ),
270
-            'decline_and_notify_registration'    => array(
271
-                'func'       => 'decline_registration',
272
-                'noheader'   => true,
273
-                'args'       => array(true),
274
-                'capability' => 'ee_edit_registration',
275
-                'obj_id'     => $reg_id,
276
-            ),
277
-            'decline_registrations'               => array(
278
-                'func'       => 'bulk_action_on_registrations',
279
-                'noheader'   => true,
280
-                'capability' => 'ee_edit_registrations',
281
-                'args' => array('decline')
282
-            ),
283
-            'decline_and_notify_registrations'    => array(
284
-                'func'       => 'bulk_action_on_registrations',
285
-                'noheader'   => true,
286
-                'capability' => 'ee_edit_registrations',
287
-                'args' => array('decline', true)
288
-            ),
289
-            'pending_registration'               => array(
290
-                'func'       => 'pending_registration',
291
-                'noheader'   => true,
292
-                'capability' => 'ee_edit_registration',
293
-                'obj_id'     => $reg_id,
294
-            ),
295
-            'pending_and_notify_registration'    => array(
296
-                'func'       => 'pending_registration',
297
-                'noheader'   => true,
298
-                'args'       => array(true),
299
-                'capability' => 'ee_edit_registration',
300
-                'obj_id'     => $reg_id,
301
-            ),
302
-            'pending_registrations'               => array(
303
-                'func'       => 'bulk_action_on_registrations',
304
-                'noheader'   => true,
305
-                'capability' => 'ee_edit_registrations',
306
-                'args' => array('pending')
307
-            ),
308
-            'pending_and_notify_registrations'    => array(
309
-                'func'       => 'bulk_action_on_registrations',
310
-                'noheader'   => true,
311
-                'capability' => 'ee_edit_registrations',
312
-                'args' => array('pending', true)
313
-            ),
314
-            'no_approve_registration'            => array(
315
-                'func'       => 'not_approve_registration',
316
-                'noheader'   => true,
317
-                'capability' => 'ee_edit_registration',
318
-                'obj_id'     => $reg_id,
319
-            ),
320
-            'no_approve_and_notify_registration' => array(
321
-                'func'       => 'not_approve_registration',
322
-                'noheader'   => true,
323
-                'args'       => array(true),
324
-                'capability' => 'ee_edit_registration',
325
-                'obj_id'     => $reg_id,
326
-            ),
327
-            'no_approve_registrations'            => array(
328
-                'func'       => 'bulk_action_on_registrations',
329
-                'noheader'   => true,
330
-                'capability' => 'ee_edit_registrations',
331
-                'args' => array('not_approve')
332
-            ),
333
-            'no_approve_and_notify_registrations' => array(
334
-                'func'       => 'bulk_action_on_registrations',
335
-                'noheader'   => true,
336
-                'capability' => 'ee_edit_registrations',
337
-                'args' => array('not_approve', true)
338
-            ),
339
-            'cancel_registration'                => array(
340
-                'func'       => 'cancel_registration',
341
-                'noheader'   => true,
342
-                'capability' => 'ee_edit_registration',
343
-                'obj_id'     => $reg_id,
344
-            ),
345
-            'cancel_and_notify_registration'     => array(
346
-                'func'       => 'cancel_registration',
347
-                'noheader'   => true,
348
-                'args'       => array(true),
349
-                'capability' => 'ee_edit_registration',
350
-                'obj_id'     => $reg_id,
351
-            ),
352
-            'cancel_registrations'                => array(
353
-                'func'       => 'bulk_action_on_registrations',
354
-                'noheader'   => true,
355
-                'capability' => 'ee_edit_registrations',
356
-                'args' => array('cancel')
357
-            ),
358
-            'cancel_and_notify_registrations'     => array(
359
-                'func'       => 'bulk_action_on_registrations',
360
-                'noheader'   => true,
361
-                'capability' => 'ee_edit_registrations',
362
-                'args' => array('cancel', true)
363
-            ),
364
-            'wait_list_registration' => array(
365
-                'func'       => 'wait_list_registration',
366
-                'noheader'   => true,
367
-                'capability' => 'ee_edit_registration',
368
-                'obj_id'     => $reg_id,
369
-            ),
370
-            'wait_list_and_notify_registration' => array(
371
-                'func'       => 'wait_list_registration',
372
-                'noheader'   => true,
373
-                'args'       => array(true),
374
-                'capability' => 'ee_edit_registration',
375
-                'obj_id'     => $reg_id,
376
-            ),
377
-            'contact_list'                       => array(
378
-                'func'       => '_attendee_contact_list_table',
379
-                'capability' => 'ee_read_contacts',
380
-            ),
381
-            'add_new_attendee'                   => array(
382
-                'func' => '_create_new_cpt_item',
383
-                'args' => array(
384
-                    'new_attendee' => true,
385
-                    'capability'   => 'ee_edit_contacts',
386
-                ),
387
-            ),
388
-            'edit_attendee'                      => array(
389
-                'func'       => '_edit_cpt_item',
390
-                'capability' => 'ee_edit_contacts',
391
-                'obj_id'     => $att_id,
392
-            ),
393
-            'duplicate_attendee'                 => array(
394
-                'func'       => '_duplicate_attendee',
395
-                'noheader'   => true,
396
-                'capability' => 'ee_edit_contacts',
397
-                'obj_id'     => $att_id,
398
-            ),
399
-            'insert_attendee'                    => array(
400
-                'func'       => '_insert_or_update_attendee',
401
-                'args'       => array(
402
-                    'new_attendee' => true,
403
-                ),
404
-                'noheader'   => true,
405
-                'capability' => 'ee_edit_contacts',
406
-            ),
407
-            'update_attendee'                    => array(
408
-                'func'       => '_insert_or_update_attendee',
409
-                'args'       => array(
410
-                    'new_attendee' => false,
411
-                ),
412
-                'noheader'   => true,
413
-                'capability' => 'ee_edit_contacts',
414
-                'obj_id'     => $att_id,
415
-            ),
416
-            'trash_attendees' => array(
417
-                'func' => '_trash_or_restore_attendees',
418
-                'args' => array(
419
-                    'trash' => 'true'
420
-                ),
421
-                'noheader' => true,
422
-                'capability' => 'ee_delete_contacts'
423
-            ),
424
-            'trash_attendee'                    => array(
425
-                'func'       => '_trash_or_restore_attendees',
426
-                'args'       => array(
427
-                    'trash' => true,
428
-                ),
429
-                'noheader'   => true,
430
-                'capability' => 'ee_delete_contacts',
431
-                'obj_id'     => $att_id,
432
-            ),
433
-            'restore_attendees'                  => array(
434
-                'func'       => '_trash_or_restore_attendees',
435
-                'args'       => array(
436
-                    'trash' => false,
437
-                ),
438
-                'noheader'   => true,
439
-                'capability' => 'ee_delete_contacts',
440
-                'obj_id'     => $att_id,
441
-            ),
442
-            'resend_registration'                => array(
443
-                'func'       => '_resend_registration',
444
-                'noheader'   => true,
445
-                'capability' => 'ee_send_message',
446
-            ),
447
-            'registrations_report'               => array(
448
-                'func'       => '_registrations_report',
449
-                'noheader'   => true,
450
-                'capability' => 'ee_read_registrations',
451
-            ),
452
-            'contact_list_export'                => array(
453
-                'func'       => '_contact_list_export',
454
-                'noheader'   => true,
455
-                'capability' => 'export',
456
-            ),
457
-            'contact_list_report'                => array(
458
-                'func'       => '_contact_list_report',
459
-                'noheader'   => true,
460
-                'capability' => 'ee_read_contacts',
461
-            ),
462
-        );
463
-    }
464
-
465
-
466
-    protected function _set_page_config()
467
-    {
468
-        $this->_page_config = array(
469
-            'default'           => array(
470
-                'nav'           => array(
471
-                    'label' => esc_html__('Overview', 'event_espresso'),
472
-                    'order' => 5,
473
-                ),
474
-                'help_tabs'     => array(
475
-                    'registrations_overview_help_tab'                       => array(
476
-                        'title'    => esc_html__('Registrations Overview', 'event_espresso'),
477
-                        'filename' => 'registrations_overview',
478
-                    ),
479
-                    'registrations_overview_table_column_headings_help_tab' => array(
480
-                        'title'    => esc_html__('Registrations Table Column Headings', 'event_espresso'),
481
-                        'filename' => 'registrations_overview_table_column_headings',
482
-                    ),
483
-                    'registrations_overview_filters_help_tab'               => array(
484
-                        'title'    => esc_html__('Registration Filters', 'event_espresso'),
485
-                        'filename' => 'registrations_overview_filters',
486
-                    ),
487
-                    'registrations_overview_views_help_tab'                 => array(
488
-                        'title'    => esc_html__('Registration Views', 'event_espresso'),
489
-                        'filename' => 'registrations_overview_views',
490
-                    ),
491
-                    'registrations_regoverview_other_help_tab'              => array(
492
-                        'title'    => esc_html__('Registrations Other', 'event_espresso'),
493
-                        'filename' => 'registrations_overview_other',
494
-                    ),
495
-                ),
496
-                'help_tour'     => array('Registration_Overview_Help_Tour'),
497
-                'qtips'         => array('Registration_List_Table_Tips'),
498
-                'list_table'    => 'EE_Registrations_List_Table',
499
-                'require_nonce' => false,
500
-            ),
501
-            'view_registration' => array(
502
-                'nav'           => array(
503
-                    'label'      => esc_html__('REG Details', 'event_espresso'),
504
-                    'order'      => 15,
505
-                    'url'        => isset($this->_req_data['_REG_ID'])
506
-                        ? add_query_arg(array('_REG_ID' => $this->_req_data['_REG_ID']), $this->_current_page_view_url)
507
-                        : $this->_admin_base_url,
508
-                    'persistent' => false,
509
-                ),
510
-                'help_tabs'     => array(
511
-                    'registrations_details_help_tab'                    => array(
512
-                        'title'    => esc_html__('Registration Details', 'event_espresso'),
513
-                        'filename' => 'registrations_details',
514
-                    ),
515
-                    'registrations_details_table_help_tab'              => array(
516
-                        'title'    => esc_html__('Registration Details Table', 'event_espresso'),
517
-                        'filename' => 'registrations_details_table',
518
-                    ),
519
-                    'registrations_details_form_answers_help_tab'       => array(
520
-                        'title'    => esc_html__('Registration Form Answers', 'event_espresso'),
521
-                        'filename' => 'registrations_details_form_answers',
522
-                    ),
523
-                    'registrations_details_registrant_details_help_tab' => array(
524
-                        'title'    => esc_html__('Contact Details', 'event_espresso'),
525
-                        'filename' => 'registrations_details_registrant_details',
526
-                    ),
527
-                ),
528
-                'help_tour'     => array('Registration_Details_Help_Tour'),
529
-                'metaboxes'     => array_merge(
530
-                    $this->_default_espresso_metaboxes,
531
-                    array('_registration_details_metaboxes')
532
-                ),
533
-                'require_nonce' => false,
534
-            ),
535
-            'new_registration'  => array(
536
-                'nav'           => array(
537
-                    'label'      => esc_html__('Add New Registration', 'event_espresso'),
538
-                    'url'        => '#',
539
-                    'order'      => 15,
540
-                    'persistent' => false,
541
-                ),
542
-                'metaboxes'     => $this->_default_espresso_metaboxes,
543
-                'labels'        => array(
544
-                    'publishbox' => esc_html__('Save Registration', 'event_espresso'),
545
-                ),
546
-                'require_nonce' => false,
547
-            ),
548
-            'add_new_attendee'  => array(
549
-                'nav'           => array(
550
-                    'label'      => esc_html__('Add Contact', 'event_espresso'),
551
-                    'order'      => 15,
552
-                    'persistent' => false,
553
-                ),
554
-                'metaboxes'     => array_merge(
555
-                    $this->_default_espresso_metaboxes,
556
-                    array('_publish_post_box', 'attendee_editor_metaboxes')
557
-                ),
558
-                'require_nonce' => false,
559
-            ),
560
-            'edit_attendee'     => array(
561
-                'nav'           => array(
562
-                    'label'      => esc_html__('Edit Contact', 'event_espresso'),
563
-                    'order'      => 15,
564
-                    'persistent' => false,
565
-                    'url'        => isset($this->_req_data['ATT_ID'])
566
-                        ? add_query_arg(array('ATT_ID' => $this->_req_data['ATT_ID']), $this->_current_page_view_url)
567
-                        : $this->_admin_base_url,
568
-                ),
569
-                'metaboxes'     => array('attendee_editor_metaboxes'),
570
-                'require_nonce' => false,
571
-            ),
572
-            'contact_list'      => array(
573
-                'nav'           => array(
574
-                    'label' => esc_html__('Contact List', 'event_espresso'),
575
-                    'order' => 20,
576
-                ),
577
-                'list_table'    => 'EE_Attendee_Contact_List_Table',
578
-                'help_tabs'     => array(
579
-                    'registrations_contact_list_help_tab'                       => array(
580
-                        'title'    => esc_html__('Registrations Contact List', 'event_espresso'),
581
-                        'filename' => 'registrations_contact_list',
582
-                    ),
583
-                    'registrations_contact-list_table_column_headings_help_tab' => array(
584
-                        'title'    => esc_html__('Contact List Table Column Headings', 'event_espresso'),
585
-                        'filename' => 'registrations_contact_list_table_column_headings',
586
-                    ),
587
-                    'registrations_contact_list_views_help_tab'                 => array(
588
-                        'title'    => esc_html__('Contact List Views', 'event_espresso'),
589
-                        'filename' => 'registrations_contact_list_views',
590
-                    ),
591
-                    'registrations_contact_list_other_help_tab'                 => array(
592
-                        'title'    => esc_html__('Contact List Other', 'event_espresso'),
593
-                        'filename' => 'registrations_contact_list_other',
594
-                    ),
595
-                ),
596
-                'help_tour'     => array('Contact_List_Help_Tour'),
597
-                'metaboxes'     => array(),
598
-                'require_nonce' => false,
599
-            ),
600
-            //override default cpt routes
601
-            'create_new'        => '',
602
-            'edit'              => '',
603
-        );
604
-    }
605
-
606
-
607
-    /**
608
-     * The below methods aren't used by this class currently
609
-     */
610
-    protected function _add_screen_options()
611
-    {
612
-    }
613
-
614
-
615
-    protected function _add_feature_pointers()
616
-    {
617
-    }
618
-
619
-
620
-    public function admin_init()
621
-    {
622
-        EE_Registry::$i18n_js_strings['update_att_qstns'] = esc_html__(
623
-            'click "Update Registration Questions" to save your changes',
624
-            'event_espresso'
625
-        );
626
-    }
627
-
628
-
629
-    public function admin_notices()
630
-    {
631
-    }
632
-
633
-
634
-    public function admin_footer_scripts()
635
-    {
636
-    }
637
-
638
-
639
-    /**
640
-     *        get list of registration statuses
641
-     *
642
-     * @access private
643
-     * @return void
644
-     * @throws EE_Error
645
-     */
646
-    private function _get_registration_status_array()
647
-    {
648
-        self::$_reg_status = EEM_Registration::reg_status_array(array(), true);
649
-    }
650
-
651
-
652
-    protected function _add_screen_options_default()
653
-    {
654
-        $this->_per_page_screen_option();
655
-    }
656
-
657
-
658
-    protected function _add_screen_options_contact_list()
659
-    {
660
-        $page_title              = $this->_admin_page_title;
661
-        $this->_admin_page_title = esc_html__("Contacts", 'event_espresso');
662
-        $this->_per_page_screen_option();
663
-        $this->_admin_page_title = $page_title;
664
-    }
665
-
666
-
667
-    public function load_scripts_styles()
668
-    {
669
-        //style
670
-        wp_register_style(
671
-            'espresso_reg',
672
-            REG_ASSETS_URL . 'espresso_registrations_admin.css',
673
-            array('ee-admin-css'),
674
-            EVENT_ESPRESSO_VERSION
675
-        );
676
-        wp_enqueue_style('espresso_reg');
677
-        //script
678
-        wp_register_script(
679
-            'espresso_reg',
680
-            REG_ASSETS_URL . 'espresso_registrations_admin.js',
681
-            array('jquery-ui-datepicker', 'jquery-ui-draggable', 'ee_admin_js'),
682
-            EVENT_ESPRESSO_VERSION,
683
-            true
684
-        );
685
-        wp_enqueue_script('espresso_reg');
686
-    }
687
-
688
-
689
-    public function load_scripts_styles_edit_attendee()
690
-    {
691
-        //stuff to only show up on our attendee edit details page.
692
-        $attendee_details_translations = array(
693
-            'att_publish_text' => sprintf(
694
-                esc_html__('Created on: <b>%1$s</b>', 'event_espresso'),
695
-                $this->_cpt_model_obj->get_datetime('ATT_created')
696
-            ),
697
-        );
698
-        wp_localize_script('espresso_reg', 'ATTENDEE_DETAILS', $attendee_details_translations);
699
-        wp_enqueue_script('jquery-validate');
700
-    }
701
-
702
-
703
-    public function load_scripts_styles_view_registration()
704
-    {
705
-        //styles
706
-        wp_enqueue_style('espresso-ui-theme');
707
-        //scripts
708
-        $this->_get_reg_custom_questions_form($this->_registration->ID());
709
-        $this->_reg_custom_questions_form->wp_enqueue_scripts(true);
710
-    }
711
-
712
-
713
-    public function load_scripts_styles_contact_list()
714
-    {
715
-        wp_deregister_style('espresso_reg');
716
-        wp_register_style(
717
-            'espresso_att',
718
-            REG_ASSETS_URL . 'espresso_attendees_admin.css',
719
-            array('ee-admin-css'),
720
-            EVENT_ESPRESSO_VERSION
721
-        );
722
-        wp_enqueue_style('espresso_att');
723
-    }
724
-
725
-
726
-    public function load_scripts_styles_new_registration()
727
-    {
728
-        wp_register_script(
729
-            'ee-spco-for-admin',
730
-            REG_ASSETS_URL . 'spco_for_admin.js',
731
-            array('underscore', 'jquery'),
732
-            EVENT_ESPRESSO_VERSION,
733
-            true
734
-        );
735
-        wp_enqueue_script('ee-spco-for-admin');
736
-        add_filter('FHEE__EED_Ticket_Selector__load_tckt_slctr_assets', '__return_true');
737
-        EE_Form_Section_Proper::wp_enqueue_scripts();
738
-        EED_Ticket_Selector::load_tckt_slctr_assets();
739
-        EE_Datepicker_Input::enqueue_styles_and_scripts();
740
-    }
741
-
742
-
743
-    public function AHEE__EE_Admin_Page__route_admin_request_resend_registration()
744
-    {
745
-        add_filter('FHEE_load_EE_messages', '__return_true');
746
-    }
747
-
748
-
749
-    public function AHEE__EE_Admin_Page__route_admin_request_approve_registration()
750
-    {
751
-        add_filter('FHEE_load_EE_messages', '__return_true');
752
-    }
753
-
754
-
755
-    protected function _set_list_table_views_default()
756
-    {
757
-        //for notification related bulk actions we need to make sure only active messengers have an option.
758
-        EED_Messages::set_autoloaders();
759
-        /** @type EE_Message_Resource_Manager $message_resource_manager */
760
-        $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
761
-        $active_mts               = $message_resource_manager->list_of_active_message_types();
762
-        //key= bulk_action_slug, value= message type.
763
-        $match_array = array(
764
-            'approve_registrations'    => 'registration',
765
-            'decline_registrations'    => 'declined_registration',
766
-            'pending_registrations'    => 'pending_approval',
767
-            'no_approve_registrations' => 'not_approved_registration',
768
-            'cancel_registrations'     => 'cancelled_registration',
769
-        );
770
-        $can_send = EE_Registry::instance()->CAP->current_user_can(
771
-            'ee_send_message',
772
-            'batch_send_messages'
773
-        );
774
-        /** setup reg status bulk actions **/
775
-        $def_reg_status_actions['approve_registrations'] = esc_html__('Approve Registrations', 'event_espresso');
776
-        if ($can_send && in_array($match_array['approve_registrations'], $active_mts, true)) {
777
-                $def_reg_status_actions['approve_and_notify_registrations'] = esc_html__(
778
-                    'Approve and Notify Registrations',
779
-                    'event_espresso'
780
-                );
781
-        }
782
-        $def_reg_status_actions['decline_registrations'] = esc_html__('Decline Registrations', 'event_espresso');
783
-        if ($can_send && in_array($match_array['decline_registrations'], $active_mts, true)) {
784
-                $def_reg_status_actions['decline_and_notify_registrations'] = esc_html__(
785
-                    'Decline and Notify Registrations',
786
-                    'event_espresso'
787
-                );
788
-        }
789
-        $def_reg_status_actions['pending_registrations'] = esc_html__(
790
-            'Set Registrations to Pending Payment',
791
-            'event_espresso'
792
-        );
793
-        if ($can_send && in_array($match_array['pending_registrations'], $active_mts, true)) {
794
-                $def_reg_status_actions['pending_and_notify_registrations'] = esc_html__(
795
-                    'Set Registrations to Pending Payment and Notify',
796
-                    'event_espresso'
797
-                );
798
-        }
799
-        $def_reg_status_actions['no_approve_registrations'] = esc_html__(
800
-            'Set Registrations to Not Approved',
801
-            'event_espresso'
802
-        );
803
-        if ($can_send && in_array($match_array['no_approve_registrations'], $active_mts, true)) {
804
-                $def_reg_status_actions['no_approve_and_notify_registrations'] = esc_html__(
805
-                    'Set Registrations to Not Approved and Notify',
806
-                    'event_espresso'
807
-                );
808
-        }
809
-        $def_reg_status_actions['cancel_registrations'] = esc_html__('Cancel Registrations', 'event_espresso');
810
-        if ($can_send && in_array($match_array['cancel_registrations'], $active_mts, true)) {
811
-                $def_reg_status_actions['cancel_and_notify_registrations'] = esc_html__(
812
-                    'Cancel Registrations and Notify',
813
-                    'event_espresso'
814
-                );
815
-        }
816
-        $def_reg_status_actions = apply_filters(
817
-            'FHEE__Registrations_Admin_Page___set_list_table_views_default__def_reg_status_actions_array',
818
-            $def_reg_status_actions,
819
-            $active_mts,
820
-            $can_send
821
-        );
822
-
823
-        $this->_views = array(
824
-            'all'   => array(
825
-                'slug'        => 'all',
826
-                'label'       => esc_html__('View All Registrations', 'event_espresso'),
827
-                'count'       => 0,
828
-                'bulk_action' => array_merge($def_reg_status_actions, array(
829
-                    'trash_registrations' => esc_html__('Trash Registrations', 'event_espresso'),
830
-                )),
831
-            ),
832
-            'month' => array(
833
-                'slug'        => 'month',
834
-                'label'       => esc_html__('This Month', 'event_espresso'),
835
-                'count'       => 0,
836
-                'bulk_action' => array_merge($def_reg_status_actions, array(
837
-                    'trash_registrations' => esc_html__('Trash Registrations', 'event_espresso'),
838
-                )),
839
-            ),
840
-            'today' => array(
841
-                'slug'        => 'today',
842
-                'label'       => sprintf(
843
-                    esc_html__('Today - %s', 'event_espresso'),
844
-                    date('M d, Y', current_time('timestamp'))
845
-                ),
846
-                'count'       => 0,
847
-                'bulk_action' => array_merge($def_reg_status_actions, array(
848
-                    'trash_registrations' => esc_html__('Trash Registrations', 'event_espresso'),
849
-                )),
850
-            ),
851
-        );
852
-        if (EE_Registry::instance()->CAP->current_user_can(
853
-            'ee_delete_registrations',
854
-            'espresso_registrations_delete_registration'
855
-        )) {
856
-            $this->_views['incomplete'] = array(
857
-                'slug'        => 'incomplete',
858
-                'label'       => esc_html__('Incomplete', 'event_espresso'),
859
-                'count'       => 0,
860
-                'bulk_action' => array(
861
-                    'trash_registrations' => esc_html__('Trash Registrations', 'event_espresso'),
862
-                ),
863
-            );
864
-            $this->_views['trash']      = array(
865
-                'slug'        => 'trash',
866
-                'label'       => esc_html__('Trash', 'event_espresso'),
867
-                'count'       => 0,
868
-                'bulk_action' => array(
869
-                    'restore_registrations' => esc_html__('Restore Registrations', 'event_espresso'),
870
-                    'delete_registrations'  => esc_html__('Delete Registrations Permanently', 'event_espresso'),
871
-                ),
872
-            );
873
-        }
874
-    }
875
-
876
-
877
-    protected function _set_list_table_views_contact_list()
878
-    {
879
-        $this->_views = array(
880
-            'in_use' => array(
881
-                'slug'        => 'in_use',
882
-                'label'       => esc_html__('In Use', 'event_espresso'),
883
-                'count'       => 0,
884
-                'bulk_action' => array(
885
-                    'trash_attendees' => esc_html__('Move to Trash', 'event_espresso'),
886
-                ),
887
-            ),
888
-        );
889
-        if (EE_Registry::instance()->CAP->current_user_can('ee_delete_contacts',
890
-            'espresso_registrations_trash_attendees')
891
-        ) {
892
-            $this->_views['trash'] = array(
893
-                'slug'        => 'trash',
894
-                'label'       => esc_html__('Trash', 'event_espresso'),
895
-                'count'       => 0,
896
-                'bulk_action' => array(
897
-                    'restore_attendees' => esc_html__('Restore from Trash', 'event_espresso'),
898
-                ),
899
-            );
900
-        }
901
-    }
902
-
903
-
904
-    protected function _registration_legend_items()
905
-    {
906
-        $fc_items = array(
907
-            'star-icon'        => array(
908
-                'class' => 'dashicons dashicons-star-filled lt-blue-icon ee-icon-size-8',
909
-                'desc'  => esc_html__('This is the Primary Registrant', 'event_espresso'),
910
-            ),
911
-            'view_details'     => array(
912
-                'class' => 'dashicons dashicons-clipboard',
913
-                'desc'  => esc_html__('View Registration Details', 'event_espresso'),
914
-            ),
915
-            'edit_attendee'    => array(
916
-                'class' => 'ee-icon ee-icon-user-edit ee-icon-size-16',
917
-                'desc'  => esc_html__('Edit Contact Details', 'event_espresso'),
918
-            ),
919
-            'view_transaction' => array(
920
-                'class' => 'dashicons dashicons-cart',
921
-                'desc'  => esc_html__('View Transaction Details', 'event_espresso'),
922
-            ),
923
-            'view_invoice'     => array(
924
-                'class' => 'dashicons dashicons-media-spreadsheet',
925
-                'desc'  => esc_html__('View Transaction Invoice', 'event_espresso'),
926
-            ),
927
-        );
928
-        if (EE_Registry::instance()->CAP->current_user_can(
929
-            'ee_send_message',
930
-            'espresso_registrations_resend_registration'
931
-        )) {
932
-            $fc_items['resend_registration'] = array(
933
-                'class' => 'dashicons dashicons-email-alt',
934
-                'desc'  => esc_html__('Resend Registration Details', 'event_espresso'),
935
-            );
936
-        } else {
937
-            $fc_items['blank'] = array('class' => 'blank', 'desc' => '');
938
-        }
939
-        if (EE_Registry::instance()->CAP->current_user_can(
940
-            'ee_read_global_messages',
941
-            'view_filtered_messages'
942
-        )) {
943
-            $related_for_icon = EEH_MSG_Template::get_message_action_icon('see_notifications_for');
944
-            if (isset($related_for_icon['css_class']) && isset($related_for_icon['label'])) {
945
-                $fc_items['view_related_messages'] = array(
946
-                    'class' => $related_for_icon['css_class'],
947
-                    'desc'  => $related_for_icon['label'],
948
-                );
949
-            }
950
-        }
951
-        $sc_items = array(
952
-            'approved_status'   => array(
953
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_approved,
954
-                'desc'  => EEH_Template::pretty_status(
955
-                    EEM_Registration::status_id_approved,
956
-                    false,
957
-                    'sentence'
958
-                ),
959
-            ),
960
-            'pending_status'    => array(
961
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_pending_payment,
962
-                'desc'  => EEH_Template::pretty_status(
963
-                    EEM_Registration::status_id_pending_payment,
964
-                    false,
965
-                    'sentence'
966
-                ),
967
-            ),
968
-            'wait_list'         => array(
969
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_wait_list,
970
-                'desc'  => EEH_Template::pretty_status(
971
-                    EEM_Registration::status_id_wait_list,
972
-                    false,
973
-                    'sentence'
974
-                ),
975
-            ),
976
-            'incomplete_status' => array(
977
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_incomplete,
978
-                'desc'  => EEH_Template::pretty_status(
979
-                    EEM_Registration::status_id_incomplete,
980
-                    false,
981
-                    'sentence'
982
-                ),
983
-            ),
984
-            'not_approved'      => array(
985
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_not_approved,
986
-                'desc'  => EEH_Template::pretty_status(
987
-                    EEM_Registration::status_id_not_approved,
988
-                    false,
989
-                    'sentence'
990
-                ),
991
-            ),
992
-            'declined_status'   => array(
993
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_declined,
994
-                'desc'  => EEH_Template::pretty_status(
995
-                    EEM_Registration::status_id_declined,
996
-                    false,
997
-                    'sentence'
998
-                ),
999
-            ),
1000
-            'cancelled_status'  => array(
1001
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_cancelled,
1002
-                'desc'  => EEH_Template::pretty_status(
1003
-                    EEM_Registration::status_id_cancelled,
1004
-                    false,
1005
-                    'sentence'
1006
-                ),
1007
-            ),
1008
-        );
1009
-        return array_merge($fc_items, $sc_items);
1010
-    }
1011
-
1012
-
1013
-
1014
-    /***************************************        REGISTRATION OVERVIEW        **************************************/
1015
-    /**
1016
-     * @throws \EE_Error
1017
-     */
1018
-    protected function _registrations_overview_list_table()
1019
-    {
1020
-        $this->_template_args['admin_page_header'] = '';
1021
-        $EVT_ID                                    = ! empty($this->_req_data['event_id'])
1022
-            ? absint($this->_req_data['event_id'])
1023
-            : 0;
1024
-        if ($EVT_ID) {
1025
-            if (EE_Registry::instance()->CAP->current_user_can(
1026
-                'ee_edit_registrations',
1027
-                'espresso_registrations_new_registration',
1028
-                $EVT_ID
1029
-            )) {
1030
-                $this->_admin_page_title .= ' ' . $this->get_action_link_or_button(
1031
-                    'new_registration',
1032
-                    'add-registrant',
1033
-                    array('event_id' => $EVT_ID),
1034
-                    'add-new-h2'
1035
-                );
1036
-            }
1037
-            $event = EEM_Event::instance()->get_one_by_ID($EVT_ID);
1038
-            if ($event instanceof EE_Event) {
1039
-                $this->_template_args['admin_page_header'] = sprintf(
1040
-                    esc_html__(
1041
-                        '%s Viewing registrations for the event: %s%s',
1042
-                        'event_espresso'
1043
-                    ),
1044
-                    '<h3 style="line-height:1.5em;">',
1045
-                    '<br /><a href="'
1046
-                        . EE_Admin_Page::add_query_args_and_nonce(
1047
-                            array(
1048
-                                'action' => 'edit',
1049
-                                'post'   => $event->ID(),
1050
-                            ),
1051
-                            EVENTS_ADMIN_URL
1052
-                        )
1053
-                        . '">&nbsp;'
1054
-                        . $event->get('EVT_name')
1055
-                        . '&nbsp;</a>&nbsp;',
1056
-                    '</h3>'
1057
-                );
1058
-            }
1059
-            $DTT_ID   = ! empty($this->_req_data['datetime_id']) ? absint($this->_req_data['datetime_id']) : 0;
1060
-            $datetime = EEM_Datetime::instance()->get_one_by_ID($DTT_ID);
1061
-            if ($datetime instanceof EE_Datetime && $this->_template_args['admin_page_header'] !== '') {
1062
-                $this->_template_args['admin_page_header'] = substr(
1063
-                    $this->_template_args['admin_page_header'],
1064
-                    0,
1065
-                    -5
1066
-                );
1067
-                $this->_template_args['admin_page_header'] .= ' &nbsp;<span class="drk-grey-text">';
1068
-                $this->_template_args['admin_page_header'] .= '<span class="dashicons dashicons-calendar"></span>';
1069
-                $this->_template_args['admin_page_header'] .= $datetime->name();
1070
-                $this->_template_args['admin_page_header'] .= ' ( ' . $datetime->start_date() . ' )';
1071
-                $this->_template_args['admin_page_header'] .= '</span></h3>';
1072
-            }
1073
-        }
1074
-        $this->_template_args['after_list_table'] = $this->_display_legend($this->_registration_legend_items());
1075
-        $this->display_admin_list_table_page_with_no_sidebar();
1076
-    }
1077
-
1078
-
1079
-    /**
1080
-     * This sets the _registration property for the registration details screen
1081
-     *
1082
-     * @access private
1083
-     * @return bool
1084
-     * @throws EE_Error
1085
-     * @throws InvalidArgumentException
1086
-     * @throws InvalidDataTypeException
1087
-     * @throws InvalidInterfaceException
1088
-     */
1089
-    private function _set_registration_object()
1090
-    {
1091
-        //get out if we've already set the object
1092
-        if ($this->_registration instanceof EE_Registration) {
1093
-            return true;
1094
-        }
1095
-        $REG    = EEM_Registration::instance();
1096
-        $REG_ID = ( ! empty($this->_req_data['_REG_ID'])) ? absint($this->_req_data['_REG_ID']) : false;
1097
-        if ($this->_registration = $REG->get_one_by_ID($REG_ID)) {
1098
-            return true;
1099
-        } else {
1100
-            $error_msg = sprintf(
1101
-                esc_html__(
1102
-                    'An error occurred and the details for Registration ID #%s could not be retrieved.',
1103
-                    'event_espresso'
1104
-                ),
1105
-                $REG_ID
1106
-            );
1107
-            EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__);
1108
-            $this->_registration = null;
1109
-            return false;
1110
-        }
1111
-    }
1112
-
1113
-
1114
-    /**
1115
-     * Used to retrieve registrations for the list table.
1116
-     *
1117
-     * @param int  $per_page
1118
-     * @param bool $count
1119
-     * @param bool $this_month
1120
-     * @param bool $today
1121
-     * @return EE_Registration[]|int
1122
-     * @throws EE_Error
1123
-     * @throws InvalidArgumentException
1124
-     * @throws InvalidDataTypeException
1125
-     * @throws InvalidInterfaceException
1126
-     */
1127
-    public function get_registrations(
1128
-        $per_page = 10,
1129
-        $count = false,
1130
-        $this_month = false,
1131
-        $today = false
1132
-    ) {
1133
-        if ($this_month) {
1134
-            $this->_req_data['status'] = 'month';
1135
-        }
1136
-        if ($today) {
1137
-            $this->_req_data['status'] = 'today';
1138
-        }
1139
-        $query_params = $this->_get_registration_query_parameters($this->_req_data, $per_page, $count);
1140
-        /**
1141
-         * Override the default groupby added by EEM_Base so that sorts with multiple order bys work as expected
1142
-         * @link https://events.codebasehq.com/projects/event-espresso/tickets/10093
1143
-         * @see EEM_Base::get_all()
1144
-         */
1145
-        $query_params['group_by'] = '';
1146
-
1147
-        return $count
1148
-            ? EEM_Registration::instance()->count($query_params)
1149
-            /** @type EE_Registration[] */
1150
-            : EEM_Registration::instance()->get_all($query_params);
1151
-    }
1152
-
1153
-
1154
-    /**
1155
-     * Retrieves the query parameters to be used by the Registration model for getting registrations.
1156
-     * Note: this listens to values on the request for some of the query parameters.
1157
-     *
1158
-     * @param array $request
1159
-     * @param int   $per_page
1160
-     * @param bool  $count
1161
-     * @return array
1162
-     * @throws EE_Error
1163
-     */
1164
-    protected function _get_registration_query_parameters(
1165
-        $request = array(),
1166
-        $per_page = 10,
1167
-        $count = false
1168
-    ) {
1169
-
1170
-        $query_params = array(
1171
-            0                          => $this->_get_where_conditions_for_registrations_query(
1172
-                $request
1173
-            ),
1174
-            'caps'                     => EEM_Registration::caps_read_admin,
1175
-            'default_where_conditions' => 'this_model_only',
1176
-        );
1177
-        if (! $count) {
1178
-            $query_params = array_merge(
1179
-                $query_params,
1180
-                $this->_get_orderby_for_registrations_query(),
1181
-                $this->_get_limit($per_page)
1182
-            );
1183
-        }
1184
-
1185
-        return $query_params;
1186
-    }
1187
-
1188
-
1189
-    /**
1190
-     * This will add EVT_ID to the provided $where array for EE model query parameters.
1191
-     *
1192
-     * @param array $request usually the same as $this->_req_data but not necessarily
1193
-     * @return array
1194
-     */
1195
-    protected function _add_event_id_to_where_conditions(array $request)
1196
-    {
1197
-        $where = array();
1198
-        if (! empty($request['event_id'])) {
1199
-            $where['EVT_ID'] = absint($request['event_id']);
1200
-        }
1201
-        return $where;
1202
-    }
1203
-
1204
-
1205
-    /**
1206
-     * Adds category ID if it exists in the request to the where conditions for the registrations query.
1207
-     *
1208
-     * @param array $request usually the same as $this->_req_data but not necessarily
1209
-     * @return array
1210
-     */
1211
-    protected function _add_category_id_to_where_conditions(array $request)
1212
-    {
1213
-        $where = array();
1214
-        if (! empty($request['EVT_CAT']) && (int)$request['EVT_CAT'] !== -1) {
1215
-            $where['Event.Term_Taxonomy.term_id'] = absint($request['EVT_CAT']);
1216
-        }
1217
-        return $where;
1218
-    }
1219
-
1220
-
1221
-    /**
1222
-     * Adds the datetime ID if it exists in the request to the where conditions for the registrations query.
1223
-     *
1224
-     * @param array $request usually the same as $this->_req_data but not necessarily
1225
-     * @return array
1226
-     */
1227
-    protected function _add_datetime_id_to_where_conditions(array $request)
1228
-    {
1229
-        $where = array();
1230
-        if (! empty($request['datetime_id'])) {
1231
-            $where['Ticket.Datetime.DTT_ID'] = absint($request['datetime_id']);
1232
-        }
1233
-        if (! empty($request['DTT_ID'])) {
1234
-            $where['Ticket.Datetime.DTT_ID'] = absint($request['DTT_ID']);
1235
-        }
1236
-        return $where;
1237
-    }
1238
-
1239
-
1240
-    /**
1241
-     * Adds the correct registration status to the where conditions for the registrations query.
1242
-     *
1243
-     * @param array $request usually the same as $this->_req_data but not necessarily
1244
-     * @return array
1245
-     */
1246
-    protected function _add_registration_status_to_where_conditions(array $request)
1247
-    {
1248
-        $where = array();
1249
-        $view = EEH_Array::is_set($request, 'status', '');
1250
-        $registration_status = ! empty($request['_reg_status'])
1251
-            ? sanitize_text_field($request['_reg_status'])
1252
-            : '';
1253
-
1254
-        /*
33
+	/**
34
+	 * @var EE_Registration
35
+	 */
36
+	private $_registration;
37
+
38
+	/**
39
+	 * @var EE_Event
40
+	 */
41
+	private $_reg_event;
42
+
43
+	/**
44
+	 * @var EE_Session
45
+	 */
46
+	private $_session;
47
+
48
+	private static $_reg_status;
49
+
50
+	/**
51
+	 * Form for displaying the custom questions for this registration.
52
+	 * This gets used a few times throughout the request so its best to cache it
53
+	 *
54
+	 * @var EE_Registration_Custom_Questions_Form
55
+	 */
56
+	protected $_reg_custom_questions_form = null;
57
+
58
+
59
+	/**
60
+	 *        constructor
61
+	 *
62
+	 * @Constructor
63
+	 * @access public
64
+	 * @param bool $routing
65
+	 * @return Registrations_Admin_Page
66
+	 */
67
+	public function __construct($routing = true)
68
+	{
69
+		parent::__construct($routing);
70
+		add_action('wp_loaded', array($this, 'wp_loaded'));
71
+	}
72
+
73
+
74
+	public function wp_loaded()
75
+	{
76
+		// when adding a new registration...
77
+		if (isset($this->_req_data['action']) && $this->_req_data['action'] === 'new_registration') {
78
+			EE_System::do_not_cache();
79
+			if (! isset($this->_req_data['processing_registration'])
80
+				 || absint($this->_req_data['processing_registration']) !== 1
81
+			) {
82
+				// and it's NOT the attendee information reg step
83
+				// force cookie expiration by setting time to last week
84
+				setcookie('ee_registration_added', 0, time() - WEEK_IN_SECONDS, '/');
85
+				// and update the global
86
+				$_COOKIE['ee_registration_added'] = 0;
87
+			}
88
+		}
89
+	}
90
+
91
+
92
+	protected function _init_page_props()
93
+	{
94
+		$this->page_slug        = REG_PG_SLUG;
95
+		$this->_admin_base_url  = REG_ADMIN_URL;
96
+		$this->_admin_base_path = REG_ADMIN;
97
+		$this->page_label       = esc_html__('Registrations', 'event_espresso');
98
+		$this->_cpt_routes      = array(
99
+			'add_new_attendee' => 'espresso_attendees',
100
+			'edit_attendee'    => 'espresso_attendees',
101
+			'insert_attendee'  => 'espresso_attendees',
102
+			'update_attendee'  => 'espresso_attendees',
103
+		);
104
+		$this->_cpt_model_names = array(
105
+			'add_new_attendee' => 'EEM_Attendee',
106
+			'edit_attendee'    => 'EEM_Attendee',
107
+		);
108
+		$this->_cpt_edit_routes = array(
109
+			'espresso_attendees' => 'edit_attendee',
110
+		);
111
+		$this->_pagenow_map     = array(
112
+			'add_new_attendee' => 'post-new.php',
113
+			'edit_attendee'    => 'post.php',
114
+			'trash'            => 'post.php',
115
+		);
116
+		add_action('edit_form_after_title', array($this, 'after_title_form_fields'), 10);
117
+		//add filters so that the comment urls don't take users to a confusing 404 page
118
+		add_filter('get_comment_link', array($this, 'clear_comment_link'), 10, 3);
119
+	}
120
+
121
+
122
+	public function clear_comment_link($link, $comment, $args)
123
+	{
124
+		//gotta make sure this only happens on this route
125
+		$post_type = get_post_type($comment->comment_post_ID);
126
+		if ($post_type === 'espresso_attendees') {
127
+			return '#commentsdiv';
128
+		}
129
+		return $link;
130
+	}
131
+
132
+
133
+	protected function _ajax_hooks()
134
+	{
135
+		//todo: all hooks for registrations ajax goes in here
136
+		add_action('wp_ajax_toggle_checkin_status', array($this, 'toggle_checkin_status'));
137
+	}
138
+
139
+
140
+	protected function _define_page_props()
141
+	{
142
+		$this->_admin_page_title = $this->page_label;
143
+		$this->_labels           = array(
144
+			'buttons'                      => array(
145
+				'add-registrant'      => esc_html__('Add New Registration', 'event_espresso'),
146
+				'add-attendee'        => esc_html__('Add Contact', 'event_espresso'),
147
+				'edit'                => esc_html__('Edit Contact', 'event_espresso'),
148
+				'report'              => esc_html__("Event Registrations CSV Report", "event_espresso"),
149
+				'report_all'          => esc_html__('All Registrations CSV Report', 'event_espresso'),
150
+				'report_filtered'     => esc_html__('Filtered CSV Report', 'event_espresso'),
151
+				'contact_list_report' => esc_html__('Contact List Report', 'event_espresso'),
152
+				'contact_list_export' => esc_html__("Export Data", "event_espresso"),
153
+			),
154
+			'publishbox'                   => array(
155
+				'add_new_attendee' => esc_html__("Add Contact Record", 'event_espresso'),
156
+				'edit_attendee'    => esc_html__("Update Contact Record", 'event_espresso'),
157
+			),
158
+			'hide_add_button_on_cpt_route' => array(
159
+				'edit_attendee' => true,
160
+			),
161
+		);
162
+	}
163
+
164
+
165
+	/**
166
+	 *        grab url requests and route them
167
+	 *
168
+	 * @access private
169
+	 * @return void
170
+	 */
171
+	public function _set_page_routes()
172
+	{
173
+		$this->_get_registration_status_array();
174
+		$reg_id             = ! empty($this->_req_data['_REG_ID']) && ! is_array($this->_req_data['_REG_ID'])
175
+			? $this->_req_data['_REG_ID'] : 0;
176
+		$reg_id = empty($reg_id) && ! empty($this->_req_data['reg_status_change_form']['REG_ID'])
177
+			? $this->_req_data['reg_status_change_form']['REG_ID']
178
+			: $reg_id;
179
+		$att_id             = ! empty($this->_req_data['ATT_ID']) && ! is_array($this->_req_data['ATT_ID'])
180
+			? $this->_req_data['ATT_ID'] : 0;
181
+		$att_id             = ! empty($this->_req_data['post']) && ! is_array($this->_req_data['post'])
182
+			? $this->_req_data['post']
183
+			: $att_id;
184
+		$this->_page_routes = array(
185
+			'default'                            => array(
186
+				'func'       => '_registrations_overview_list_table',
187
+				'capability' => 'ee_read_registrations',
188
+			),
189
+			'view_registration'                  => array(
190
+				'func'       => '_registration_details',
191
+				'capability' => 'ee_read_registration',
192
+				'obj_id'     => $reg_id,
193
+			),
194
+			'edit_registration'                  => array(
195
+				'func'               => '_update_attendee_registration_form',
196
+				'noheader'           => true,
197
+				'headers_sent_route' => 'view_registration',
198
+				'capability'         => 'ee_edit_registration',
199
+				'obj_id'             => $reg_id,
200
+				'_REG_ID'            => $reg_id,
201
+			),
202
+			'trash_registrations'                => array(
203
+				'func'       => '_trash_or_restore_registrations',
204
+				'args'       => array('trash' => true),
205
+				'noheader'   => true,
206
+				'capability' => 'ee_delete_registrations',
207
+			),
208
+			'restore_registrations'              => array(
209
+				'func'       => '_trash_or_restore_registrations',
210
+				'args'       => array('trash' => false),
211
+				'noheader'   => true,
212
+				'capability' => 'ee_delete_registrations',
213
+			),
214
+			'delete_registrations'               => array(
215
+				'func'       => '_delete_registrations',
216
+				'noheader'   => true,
217
+				'capability' => 'ee_delete_registrations',
218
+			),
219
+			'new_registration'                   => array(
220
+				'func'       => 'new_registration',
221
+				'capability' => 'ee_edit_registrations',
222
+			),
223
+			'process_reg_step'                   => array(
224
+				'func'       => 'process_reg_step',
225
+				'noheader'   => true,
226
+				'capability' => 'ee_edit_registrations',
227
+			),
228
+			'redirect_to_txn'                    => array(
229
+				'func'       => 'redirect_to_txn',
230
+				'noheader'   => true,
231
+				'capability' => 'ee_edit_registrations',
232
+			),
233
+			'change_reg_status'                  => array(
234
+				'func'       => '_change_reg_status',
235
+				'noheader'   => true,
236
+				'capability' => 'ee_edit_registration',
237
+				'obj_id'     => $reg_id,
238
+			),
239
+			'approve_registration'               => array(
240
+				'func'       => 'approve_registration',
241
+				'noheader'   => true,
242
+				'capability' => 'ee_edit_registration',
243
+				'obj_id'     => $reg_id,
244
+			),
245
+			'approve_and_notify_registration'    => array(
246
+				'func'       => 'approve_registration',
247
+				'noheader'   => true,
248
+				'args'       => array(true),
249
+				'capability' => 'ee_edit_registration',
250
+				'obj_id'     => $reg_id,
251
+			),
252
+			'approve_registrations'               => array(
253
+				'func'       => 'bulk_action_on_registrations',
254
+				'noheader'   => true,
255
+				'capability' => 'ee_edit_registrations',
256
+				'args' => array('approve')
257
+			),
258
+			'approve_and_notify_registrations'               => array(
259
+				'func'       => 'bulk_action_on_registrations',
260
+				'noheader'   => true,
261
+				'capability' => 'ee_edit_registrations',
262
+				'args' => array('approve', true)
263
+			),
264
+			'decline_registration'               => array(
265
+				'func'       => 'decline_registration',
266
+				'noheader'   => true,
267
+				'capability' => 'ee_edit_registration',
268
+				'obj_id'     => $reg_id,
269
+			),
270
+			'decline_and_notify_registration'    => array(
271
+				'func'       => 'decline_registration',
272
+				'noheader'   => true,
273
+				'args'       => array(true),
274
+				'capability' => 'ee_edit_registration',
275
+				'obj_id'     => $reg_id,
276
+			),
277
+			'decline_registrations'               => array(
278
+				'func'       => 'bulk_action_on_registrations',
279
+				'noheader'   => true,
280
+				'capability' => 'ee_edit_registrations',
281
+				'args' => array('decline')
282
+			),
283
+			'decline_and_notify_registrations'    => array(
284
+				'func'       => 'bulk_action_on_registrations',
285
+				'noheader'   => true,
286
+				'capability' => 'ee_edit_registrations',
287
+				'args' => array('decline', true)
288
+			),
289
+			'pending_registration'               => array(
290
+				'func'       => 'pending_registration',
291
+				'noheader'   => true,
292
+				'capability' => 'ee_edit_registration',
293
+				'obj_id'     => $reg_id,
294
+			),
295
+			'pending_and_notify_registration'    => array(
296
+				'func'       => 'pending_registration',
297
+				'noheader'   => true,
298
+				'args'       => array(true),
299
+				'capability' => 'ee_edit_registration',
300
+				'obj_id'     => $reg_id,
301
+			),
302
+			'pending_registrations'               => array(
303
+				'func'       => 'bulk_action_on_registrations',
304
+				'noheader'   => true,
305
+				'capability' => 'ee_edit_registrations',
306
+				'args' => array('pending')
307
+			),
308
+			'pending_and_notify_registrations'    => array(
309
+				'func'       => 'bulk_action_on_registrations',
310
+				'noheader'   => true,
311
+				'capability' => 'ee_edit_registrations',
312
+				'args' => array('pending', true)
313
+			),
314
+			'no_approve_registration'            => array(
315
+				'func'       => 'not_approve_registration',
316
+				'noheader'   => true,
317
+				'capability' => 'ee_edit_registration',
318
+				'obj_id'     => $reg_id,
319
+			),
320
+			'no_approve_and_notify_registration' => array(
321
+				'func'       => 'not_approve_registration',
322
+				'noheader'   => true,
323
+				'args'       => array(true),
324
+				'capability' => 'ee_edit_registration',
325
+				'obj_id'     => $reg_id,
326
+			),
327
+			'no_approve_registrations'            => array(
328
+				'func'       => 'bulk_action_on_registrations',
329
+				'noheader'   => true,
330
+				'capability' => 'ee_edit_registrations',
331
+				'args' => array('not_approve')
332
+			),
333
+			'no_approve_and_notify_registrations' => array(
334
+				'func'       => 'bulk_action_on_registrations',
335
+				'noheader'   => true,
336
+				'capability' => 'ee_edit_registrations',
337
+				'args' => array('not_approve', true)
338
+			),
339
+			'cancel_registration'                => array(
340
+				'func'       => 'cancel_registration',
341
+				'noheader'   => true,
342
+				'capability' => 'ee_edit_registration',
343
+				'obj_id'     => $reg_id,
344
+			),
345
+			'cancel_and_notify_registration'     => array(
346
+				'func'       => 'cancel_registration',
347
+				'noheader'   => true,
348
+				'args'       => array(true),
349
+				'capability' => 'ee_edit_registration',
350
+				'obj_id'     => $reg_id,
351
+			),
352
+			'cancel_registrations'                => array(
353
+				'func'       => 'bulk_action_on_registrations',
354
+				'noheader'   => true,
355
+				'capability' => 'ee_edit_registrations',
356
+				'args' => array('cancel')
357
+			),
358
+			'cancel_and_notify_registrations'     => array(
359
+				'func'       => 'bulk_action_on_registrations',
360
+				'noheader'   => true,
361
+				'capability' => 'ee_edit_registrations',
362
+				'args' => array('cancel', true)
363
+			),
364
+			'wait_list_registration' => array(
365
+				'func'       => 'wait_list_registration',
366
+				'noheader'   => true,
367
+				'capability' => 'ee_edit_registration',
368
+				'obj_id'     => $reg_id,
369
+			),
370
+			'wait_list_and_notify_registration' => array(
371
+				'func'       => 'wait_list_registration',
372
+				'noheader'   => true,
373
+				'args'       => array(true),
374
+				'capability' => 'ee_edit_registration',
375
+				'obj_id'     => $reg_id,
376
+			),
377
+			'contact_list'                       => array(
378
+				'func'       => '_attendee_contact_list_table',
379
+				'capability' => 'ee_read_contacts',
380
+			),
381
+			'add_new_attendee'                   => array(
382
+				'func' => '_create_new_cpt_item',
383
+				'args' => array(
384
+					'new_attendee' => true,
385
+					'capability'   => 'ee_edit_contacts',
386
+				),
387
+			),
388
+			'edit_attendee'                      => array(
389
+				'func'       => '_edit_cpt_item',
390
+				'capability' => 'ee_edit_contacts',
391
+				'obj_id'     => $att_id,
392
+			),
393
+			'duplicate_attendee'                 => array(
394
+				'func'       => '_duplicate_attendee',
395
+				'noheader'   => true,
396
+				'capability' => 'ee_edit_contacts',
397
+				'obj_id'     => $att_id,
398
+			),
399
+			'insert_attendee'                    => array(
400
+				'func'       => '_insert_or_update_attendee',
401
+				'args'       => array(
402
+					'new_attendee' => true,
403
+				),
404
+				'noheader'   => true,
405
+				'capability' => 'ee_edit_contacts',
406
+			),
407
+			'update_attendee'                    => array(
408
+				'func'       => '_insert_or_update_attendee',
409
+				'args'       => array(
410
+					'new_attendee' => false,
411
+				),
412
+				'noheader'   => true,
413
+				'capability' => 'ee_edit_contacts',
414
+				'obj_id'     => $att_id,
415
+			),
416
+			'trash_attendees' => array(
417
+				'func' => '_trash_or_restore_attendees',
418
+				'args' => array(
419
+					'trash' => 'true'
420
+				),
421
+				'noheader' => true,
422
+				'capability' => 'ee_delete_contacts'
423
+			),
424
+			'trash_attendee'                    => array(
425
+				'func'       => '_trash_or_restore_attendees',
426
+				'args'       => array(
427
+					'trash' => true,
428
+				),
429
+				'noheader'   => true,
430
+				'capability' => 'ee_delete_contacts',
431
+				'obj_id'     => $att_id,
432
+			),
433
+			'restore_attendees'                  => array(
434
+				'func'       => '_trash_or_restore_attendees',
435
+				'args'       => array(
436
+					'trash' => false,
437
+				),
438
+				'noheader'   => true,
439
+				'capability' => 'ee_delete_contacts',
440
+				'obj_id'     => $att_id,
441
+			),
442
+			'resend_registration'                => array(
443
+				'func'       => '_resend_registration',
444
+				'noheader'   => true,
445
+				'capability' => 'ee_send_message',
446
+			),
447
+			'registrations_report'               => array(
448
+				'func'       => '_registrations_report',
449
+				'noheader'   => true,
450
+				'capability' => 'ee_read_registrations',
451
+			),
452
+			'contact_list_export'                => array(
453
+				'func'       => '_contact_list_export',
454
+				'noheader'   => true,
455
+				'capability' => 'export',
456
+			),
457
+			'contact_list_report'                => array(
458
+				'func'       => '_contact_list_report',
459
+				'noheader'   => true,
460
+				'capability' => 'ee_read_contacts',
461
+			),
462
+		);
463
+	}
464
+
465
+
466
+	protected function _set_page_config()
467
+	{
468
+		$this->_page_config = array(
469
+			'default'           => array(
470
+				'nav'           => array(
471
+					'label' => esc_html__('Overview', 'event_espresso'),
472
+					'order' => 5,
473
+				),
474
+				'help_tabs'     => array(
475
+					'registrations_overview_help_tab'                       => array(
476
+						'title'    => esc_html__('Registrations Overview', 'event_espresso'),
477
+						'filename' => 'registrations_overview',
478
+					),
479
+					'registrations_overview_table_column_headings_help_tab' => array(
480
+						'title'    => esc_html__('Registrations Table Column Headings', 'event_espresso'),
481
+						'filename' => 'registrations_overview_table_column_headings',
482
+					),
483
+					'registrations_overview_filters_help_tab'               => array(
484
+						'title'    => esc_html__('Registration Filters', 'event_espresso'),
485
+						'filename' => 'registrations_overview_filters',
486
+					),
487
+					'registrations_overview_views_help_tab'                 => array(
488
+						'title'    => esc_html__('Registration Views', 'event_espresso'),
489
+						'filename' => 'registrations_overview_views',
490
+					),
491
+					'registrations_regoverview_other_help_tab'              => array(
492
+						'title'    => esc_html__('Registrations Other', 'event_espresso'),
493
+						'filename' => 'registrations_overview_other',
494
+					),
495
+				),
496
+				'help_tour'     => array('Registration_Overview_Help_Tour'),
497
+				'qtips'         => array('Registration_List_Table_Tips'),
498
+				'list_table'    => 'EE_Registrations_List_Table',
499
+				'require_nonce' => false,
500
+			),
501
+			'view_registration' => array(
502
+				'nav'           => array(
503
+					'label'      => esc_html__('REG Details', 'event_espresso'),
504
+					'order'      => 15,
505
+					'url'        => isset($this->_req_data['_REG_ID'])
506
+						? add_query_arg(array('_REG_ID' => $this->_req_data['_REG_ID']), $this->_current_page_view_url)
507
+						: $this->_admin_base_url,
508
+					'persistent' => false,
509
+				),
510
+				'help_tabs'     => array(
511
+					'registrations_details_help_tab'                    => array(
512
+						'title'    => esc_html__('Registration Details', 'event_espresso'),
513
+						'filename' => 'registrations_details',
514
+					),
515
+					'registrations_details_table_help_tab'              => array(
516
+						'title'    => esc_html__('Registration Details Table', 'event_espresso'),
517
+						'filename' => 'registrations_details_table',
518
+					),
519
+					'registrations_details_form_answers_help_tab'       => array(
520
+						'title'    => esc_html__('Registration Form Answers', 'event_espresso'),
521
+						'filename' => 'registrations_details_form_answers',
522
+					),
523
+					'registrations_details_registrant_details_help_tab' => array(
524
+						'title'    => esc_html__('Contact Details', 'event_espresso'),
525
+						'filename' => 'registrations_details_registrant_details',
526
+					),
527
+				),
528
+				'help_tour'     => array('Registration_Details_Help_Tour'),
529
+				'metaboxes'     => array_merge(
530
+					$this->_default_espresso_metaboxes,
531
+					array('_registration_details_metaboxes')
532
+				),
533
+				'require_nonce' => false,
534
+			),
535
+			'new_registration'  => array(
536
+				'nav'           => array(
537
+					'label'      => esc_html__('Add New Registration', 'event_espresso'),
538
+					'url'        => '#',
539
+					'order'      => 15,
540
+					'persistent' => false,
541
+				),
542
+				'metaboxes'     => $this->_default_espresso_metaboxes,
543
+				'labels'        => array(
544
+					'publishbox' => esc_html__('Save Registration', 'event_espresso'),
545
+				),
546
+				'require_nonce' => false,
547
+			),
548
+			'add_new_attendee'  => array(
549
+				'nav'           => array(
550
+					'label'      => esc_html__('Add Contact', 'event_espresso'),
551
+					'order'      => 15,
552
+					'persistent' => false,
553
+				),
554
+				'metaboxes'     => array_merge(
555
+					$this->_default_espresso_metaboxes,
556
+					array('_publish_post_box', 'attendee_editor_metaboxes')
557
+				),
558
+				'require_nonce' => false,
559
+			),
560
+			'edit_attendee'     => array(
561
+				'nav'           => array(
562
+					'label'      => esc_html__('Edit Contact', 'event_espresso'),
563
+					'order'      => 15,
564
+					'persistent' => false,
565
+					'url'        => isset($this->_req_data['ATT_ID'])
566
+						? add_query_arg(array('ATT_ID' => $this->_req_data['ATT_ID']), $this->_current_page_view_url)
567
+						: $this->_admin_base_url,
568
+				),
569
+				'metaboxes'     => array('attendee_editor_metaboxes'),
570
+				'require_nonce' => false,
571
+			),
572
+			'contact_list'      => array(
573
+				'nav'           => array(
574
+					'label' => esc_html__('Contact List', 'event_espresso'),
575
+					'order' => 20,
576
+				),
577
+				'list_table'    => 'EE_Attendee_Contact_List_Table',
578
+				'help_tabs'     => array(
579
+					'registrations_contact_list_help_tab'                       => array(
580
+						'title'    => esc_html__('Registrations Contact List', 'event_espresso'),
581
+						'filename' => 'registrations_contact_list',
582
+					),
583
+					'registrations_contact-list_table_column_headings_help_tab' => array(
584
+						'title'    => esc_html__('Contact List Table Column Headings', 'event_espresso'),
585
+						'filename' => 'registrations_contact_list_table_column_headings',
586
+					),
587
+					'registrations_contact_list_views_help_tab'                 => array(
588
+						'title'    => esc_html__('Contact List Views', 'event_espresso'),
589
+						'filename' => 'registrations_contact_list_views',
590
+					),
591
+					'registrations_contact_list_other_help_tab'                 => array(
592
+						'title'    => esc_html__('Contact List Other', 'event_espresso'),
593
+						'filename' => 'registrations_contact_list_other',
594
+					),
595
+				),
596
+				'help_tour'     => array('Contact_List_Help_Tour'),
597
+				'metaboxes'     => array(),
598
+				'require_nonce' => false,
599
+			),
600
+			//override default cpt routes
601
+			'create_new'        => '',
602
+			'edit'              => '',
603
+		);
604
+	}
605
+
606
+
607
+	/**
608
+	 * The below methods aren't used by this class currently
609
+	 */
610
+	protected function _add_screen_options()
611
+	{
612
+	}
613
+
614
+
615
+	protected function _add_feature_pointers()
616
+	{
617
+	}
618
+
619
+
620
+	public function admin_init()
621
+	{
622
+		EE_Registry::$i18n_js_strings['update_att_qstns'] = esc_html__(
623
+			'click "Update Registration Questions" to save your changes',
624
+			'event_espresso'
625
+		);
626
+	}
627
+
628
+
629
+	public function admin_notices()
630
+	{
631
+	}
632
+
633
+
634
+	public function admin_footer_scripts()
635
+	{
636
+	}
637
+
638
+
639
+	/**
640
+	 *        get list of registration statuses
641
+	 *
642
+	 * @access private
643
+	 * @return void
644
+	 * @throws EE_Error
645
+	 */
646
+	private function _get_registration_status_array()
647
+	{
648
+		self::$_reg_status = EEM_Registration::reg_status_array(array(), true);
649
+	}
650
+
651
+
652
+	protected function _add_screen_options_default()
653
+	{
654
+		$this->_per_page_screen_option();
655
+	}
656
+
657
+
658
+	protected function _add_screen_options_contact_list()
659
+	{
660
+		$page_title              = $this->_admin_page_title;
661
+		$this->_admin_page_title = esc_html__("Contacts", 'event_espresso');
662
+		$this->_per_page_screen_option();
663
+		$this->_admin_page_title = $page_title;
664
+	}
665
+
666
+
667
+	public function load_scripts_styles()
668
+	{
669
+		//style
670
+		wp_register_style(
671
+			'espresso_reg',
672
+			REG_ASSETS_URL . 'espresso_registrations_admin.css',
673
+			array('ee-admin-css'),
674
+			EVENT_ESPRESSO_VERSION
675
+		);
676
+		wp_enqueue_style('espresso_reg');
677
+		//script
678
+		wp_register_script(
679
+			'espresso_reg',
680
+			REG_ASSETS_URL . 'espresso_registrations_admin.js',
681
+			array('jquery-ui-datepicker', 'jquery-ui-draggable', 'ee_admin_js'),
682
+			EVENT_ESPRESSO_VERSION,
683
+			true
684
+		);
685
+		wp_enqueue_script('espresso_reg');
686
+	}
687
+
688
+
689
+	public function load_scripts_styles_edit_attendee()
690
+	{
691
+		//stuff to only show up on our attendee edit details page.
692
+		$attendee_details_translations = array(
693
+			'att_publish_text' => sprintf(
694
+				esc_html__('Created on: <b>%1$s</b>', 'event_espresso'),
695
+				$this->_cpt_model_obj->get_datetime('ATT_created')
696
+			),
697
+		);
698
+		wp_localize_script('espresso_reg', 'ATTENDEE_DETAILS', $attendee_details_translations);
699
+		wp_enqueue_script('jquery-validate');
700
+	}
701
+
702
+
703
+	public function load_scripts_styles_view_registration()
704
+	{
705
+		//styles
706
+		wp_enqueue_style('espresso-ui-theme');
707
+		//scripts
708
+		$this->_get_reg_custom_questions_form($this->_registration->ID());
709
+		$this->_reg_custom_questions_form->wp_enqueue_scripts(true);
710
+	}
711
+
712
+
713
+	public function load_scripts_styles_contact_list()
714
+	{
715
+		wp_deregister_style('espresso_reg');
716
+		wp_register_style(
717
+			'espresso_att',
718
+			REG_ASSETS_URL . 'espresso_attendees_admin.css',
719
+			array('ee-admin-css'),
720
+			EVENT_ESPRESSO_VERSION
721
+		);
722
+		wp_enqueue_style('espresso_att');
723
+	}
724
+
725
+
726
+	public function load_scripts_styles_new_registration()
727
+	{
728
+		wp_register_script(
729
+			'ee-spco-for-admin',
730
+			REG_ASSETS_URL . 'spco_for_admin.js',
731
+			array('underscore', 'jquery'),
732
+			EVENT_ESPRESSO_VERSION,
733
+			true
734
+		);
735
+		wp_enqueue_script('ee-spco-for-admin');
736
+		add_filter('FHEE__EED_Ticket_Selector__load_tckt_slctr_assets', '__return_true');
737
+		EE_Form_Section_Proper::wp_enqueue_scripts();
738
+		EED_Ticket_Selector::load_tckt_slctr_assets();
739
+		EE_Datepicker_Input::enqueue_styles_and_scripts();
740
+	}
741
+
742
+
743
+	public function AHEE__EE_Admin_Page__route_admin_request_resend_registration()
744
+	{
745
+		add_filter('FHEE_load_EE_messages', '__return_true');
746
+	}
747
+
748
+
749
+	public function AHEE__EE_Admin_Page__route_admin_request_approve_registration()
750
+	{
751
+		add_filter('FHEE_load_EE_messages', '__return_true');
752
+	}
753
+
754
+
755
+	protected function _set_list_table_views_default()
756
+	{
757
+		//for notification related bulk actions we need to make sure only active messengers have an option.
758
+		EED_Messages::set_autoloaders();
759
+		/** @type EE_Message_Resource_Manager $message_resource_manager */
760
+		$message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
761
+		$active_mts               = $message_resource_manager->list_of_active_message_types();
762
+		//key= bulk_action_slug, value= message type.
763
+		$match_array = array(
764
+			'approve_registrations'    => 'registration',
765
+			'decline_registrations'    => 'declined_registration',
766
+			'pending_registrations'    => 'pending_approval',
767
+			'no_approve_registrations' => 'not_approved_registration',
768
+			'cancel_registrations'     => 'cancelled_registration',
769
+		);
770
+		$can_send = EE_Registry::instance()->CAP->current_user_can(
771
+			'ee_send_message',
772
+			'batch_send_messages'
773
+		);
774
+		/** setup reg status bulk actions **/
775
+		$def_reg_status_actions['approve_registrations'] = esc_html__('Approve Registrations', 'event_espresso');
776
+		if ($can_send && in_array($match_array['approve_registrations'], $active_mts, true)) {
777
+				$def_reg_status_actions['approve_and_notify_registrations'] = esc_html__(
778
+					'Approve and Notify Registrations',
779
+					'event_espresso'
780
+				);
781
+		}
782
+		$def_reg_status_actions['decline_registrations'] = esc_html__('Decline Registrations', 'event_espresso');
783
+		if ($can_send && in_array($match_array['decline_registrations'], $active_mts, true)) {
784
+				$def_reg_status_actions['decline_and_notify_registrations'] = esc_html__(
785
+					'Decline and Notify Registrations',
786
+					'event_espresso'
787
+				);
788
+		}
789
+		$def_reg_status_actions['pending_registrations'] = esc_html__(
790
+			'Set Registrations to Pending Payment',
791
+			'event_espresso'
792
+		);
793
+		if ($can_send && in_array($match_array['pending_registrations'], $active_mts, true)) {
794
+				$def_reg_status_actions['pending_and_notify_registrations'] = esc_html__(
795
+					'Set Registrations to Pending Payment and Notify',
796
+					'event_espresso'
797
+				);
798
+		}
799
+		$def_reg_status_actions['no_approve_registrations'] = esc_html__(
800
+			'Set Registrations to Not Approved',
801
+			'event_espresso'
802
+		);
803
+		if ($can_send && in_array($match_array['no_approve_registrations'], $active_mts, true)) {
804
+				$def_reg_status_actions['no_approve_and_notify_registrations'] = esc_html__(
805
+					'Set Registrations to Not Approved and Notify',
806
+					'event_espresso'
807
+				);
808
+		}
809
+		$def_reg_status_actions['cancel_registrations'] = esc_html__('Cancel Registrations', 'event_espresso');
810
+		if ($can_send && in_array($match_array['cancel_registrations'], $active_mts, true)) {
811
+				$def_reg_status_actions['cancel_and_notify_registrations'] = esc_html__(
812
+					'Cancel Registrations and Notify',
813
+					'event_espresso'
814
+				);
815
+		}
816
+		$def_reg_status_actions = apply_filters(
817
+			'FHEE__Registrations_Admin_Page___set_list_table_views_default__def_reg_status_actions_array',
818
+			$def_reg_status_actions,
819
+			$active_mts,
820
+			$can_send
821
+		);
822
+
823
+		$this->_views = array(
824
+			'all'   => array(
825
+				'slug'        => 'all',
826
+				'label'       => esc_html__('View All Registrations', 'event_espresso'),
827
+				'count'       => 0,
828
+				'bulk_action' => array_merge($def_reg_status_actions, array(
829
+					'trash_registrations' => esc_html__('Trash Registrations', 'event_espresso'),
830
+				)),
831
+			),
832
+			'month' => array(
833
+				'slug'        => 'month',
834
+				'label'       => esc_html__('This Month', 'event_espresso'),
835
+				'count'       => 0,
836
+				'bulk_action' => array_merge($def_reg_status_actions, array(
837
+					'trash_registrations' => esc_html__('Trash Registrations', 'event_espresso'),
838
+				)),
839
+			),
840
+			'today' => array(
841
+				'slug'        => 'today',
842
+				'label'       => sprintf(
843
+					esc_html__('Today - %s', 'event_espresso'),
844
+					date('M d, Y', current_time('timestamp'))
845
+				),
846
+				'count'       => 0,
847
+				'bulk_action' => array_merge($def_reg_status_actions, array(
848
+					'trash_registrations' => esc_html__('Trash Registrations', 'event_espresso'),
849
+				)),
850
+			),
851
+		);
852
+		if (EE_Registry::instance()->CAP->current_user_can(
853
+			'ee_delete_registrations',
854
+			'espresso_registrations_delete_registration'
855
+		)) {
856
+			$this->_views['incomplete'] = array(
857
+				'slug'        => 'incomplete',
858
+				'label'       => esc_html__('Incomplete', 'event_espresso'),
859
+				'count'       => 0,
860
+				'bulk_action' => array(
861
+					'trash_registrations' => esc_html__('Trash Registrations', 'event_espresso'),
862
+				),
863
+			);
864
+			$this->_views['trash']      = array(
865
+				'slug'        => 'trash',
866
+				'label'       => esc_html__('Trash', 'event_espresso'),
867
+				'count'       => 0,
868
+				'bulk_action' => array(
869
+					'restore_registrations' => esc_html__('Restore Registrations', 'event_espresso'),
870
+					'delete_registrations'  => esc_html__('Delete Registrations Permanently', 'event_espresso'),
871
+				),
872
+			);
873
+		}
874
+	}
875
+
876
+
877
+	protected function _set_list_table_views_contact_list()
878
+	{
879
+		$this->_views = array(
880
+			'in_use' => array(
881
+				'slug'        => 'in_use',
882
+				'label'       => esc_html__('In Use', 'event_espresso'),
883
+				'count'       => 0,
884
+				'bulk_action' => array(
885
+					'trash_attendees' => esc_html__('Move to Trash', 'event_espresso'),
886
+				),
887
+			),
888
+		);
889
+		if (EE_Registry::instance()->CAP->current_user_can('ee_delete_contacts',
890
+			'espresso_registrations_trash_attendees')
891
+		) {
892
+			$this->_views['trash'] = array(
893
+				'slug'        => 'trash',
894
+				'label'       => esc_html__('Trash', 'event_espresso'),
895
+				'count'       => 0,
896
+				'bulk_action' => array(
897
+					'restore_attendees' => esc_html__('Restore from Trash', 'event_espresso'),
898
+				),
899
+			);
900
+		}
901
+	}
902
+
903
+
904
+	protected function _registration_legend_items()
905
+	{
906
+		$fc_items = array(
907
+			'star-icon'        => array(
908
+				'class' => 'dashicons dashicons-star-filled lt-blue-icon ee-icon-size-8',
909
+				'desc'  => esc_html__('This is the Primary Registrant', 'event_espresso'),
910
+			),
911
+			'view_details'     => array(
912
+				'class' => 'dashicons dashicons-clipboard',
913
+				'desc'  => esc_html__('View Registration Details', 'event_espresso'),
914
+			),
915
+			'edit_attendee'    => array(
916
+				'class' => 'ee-icon ee-icon-user-edit ee-icon-size-16',
917
+				'desc'  => esc_html__('Edit Contact Details', 'event_espresso'),
918
+			),
919
+			'view_transaction' => array(
920
+				'class' => 'dashicons dashicons-cart',
921
+				'desc'  => esc_html__('View Transaction Details', 'event_espresso'),
922
+			),
923
+			'view_invoice'     => array(
924
+				'class' => 'dashicons dashicons-media-spreadsheet',
925
+				'desc'  => esc_html__('View Transaction Invoice', 'event_espresso'),
926
+			),
927
+		);
928
+		if (EE_Registry::instance()->CAP->current_user_can(
929
+			'ee_send_message',
930
+			'espresso_registrations_resend_registration'
931
+		)) {
932
+			$fc_items['resend_registration'] = array(
933
+				'class' => 'dashicons dashicons-email-alt',
934
+				'desc'  => esc_html__('Resend Registration Details', 'event_espresso'),
935
+			);
936
+		} else {
937
+			$fc_items['blank'] = array('class' => 'blank', 'desc' => '');
938
+		}
939
+		if (EE_Registry::instance()->CAP->current_user_can(
940
+			'ee_read_global_messages',
941
+			'view_filtered_messages'
942
+		)) {
943
+			$related_for_icon = EEH_MSG_Template::get_message_action_icon('see_notifications_for');
944
+			if (isset($related_for_icon['css_class']) && isset($related_for_icon['label'])) {
945
+				$fc_items['view_related_messages'] = array(
946
+					'class' => $related_for_icon['css_class'],
947
+					'desc'  => $related_for_icon['label'],
948
+				);
949
+			}
950
+		}
951
+		$sc_items = array(
952
+			'approved_status'   => array(
953
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_approved,
954
+				'desc'  => EEH_Template::pretty_status(
955
+					EEM_Registration::status_id_approved,
956
+					false,
957
+					'sentence'
958
+				),
959
+			),
960
+			'pending_status'    => array(
961
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_pending_payment,
962
+				'desc'  => EEH_Template::pretty_status(
963
+					EEM_Registration::status_id_pending_payment,
964
+					false,
965
+					'sentence'
966
+				),
967
+			),
968
+			'wait_list'         => array(
969
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_wait_list,
970
+				'desc'  => EEH_Template::pretty_status(
971
+					EEM_Registration::status_id_wait_list,
972
+					false,
973
+					'sentence'
974
+				),
975
+			),
976
+			'incomplete_status' => array(
977
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_incomplete,
978
+				'desc'  => EEH_Template::pretty_status(
979
+					EEM_Registration::status_id_incomplete,
980
+					false,
981
+					'sentence'
982
+				),
983
+			),
984
+			'not_approved'      => array(
985
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_not_approved,
986
+				'desc'  => EEH_Template::pretty_status(
987
+					EEM_Registration::status_id_not_approved,
988
+					false,
989
+					'sentence'
990
+				),
991
+			),
992
+			'declined_status'   => array(
993
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_declined,
994
+				'desc'  => EEH_Template::pretty_status(
995
+					EEM_Registration::status_id_declined,
996
+					false,
997
+					'sentence'
998
+				),
999
+			),
1000
+			'cancelled_status'  => array(
1001
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_cancelled,
1002
+				'desc'  => EEH_Template::pretty_status(
1003
+					EEM_Registration::status_id_cancelled,
1004
+					false,
1005
+					'sentence'
1006
+				),
1007
+			),
1008
+		);
1009
+		return array_merge($fc_items, $sc_items);
1010
+	}
1011
+
1012
+
1013
+
1014
+	/***************************************        REGISTRATION OVERVIEW        **************************************/
1015
+	/**
1016
+	 * @throws \EE_Error
1017
+	 */
1018
+	protected function _registrations_overview_list_table()
1019
+	{
1020
+		$this->_template_args['admin_page_header'] = '';
1021
+		$EVT_ID                                    = ! empty($this->_req_data['event_id'])
1022
+			? absint($this->_req_data['event_id'])
1023
+			: 0;
1024
+		if ($EVT_ID) {
1025
+			if (EE_Registry::instance()->CAP->current_user_can(
1026
+				'ee_edit_registrations',
1027
+				'espresso_registrations_new_registration',
1028
+				$EVT_ID
1029
+			)) {
1030
+				$this->_admin_page_title .= ' ' . $this->get_action_link_or_button(
1031
+					'new_registration',
1032
+					'add-registrant',
1033
+					array('event_id' => $EVT_ID),
1034
+					'add-new-h2'
1035
+				);
1036
+			}
1037
+			$event = EEM_Event::instance()->get_one_by_ID($EVT_ID);
1038
+			if ($event instanceof EE_Event) {
1039
+				$this->_template_args['admin_page_header'] = sprintf(
1040
+					esc_html__(
1041
+						'%s Viewing registrations for the event: %s%s',
1042
+						'event_espresso'
1043
+					),
1044
+					'<h3 style="line-height:1.5em;">',
1045
+					'<br /><a href="'
1046
+						. EE_Admin_Page::add_query_args_and_nonce(
1047
+							array(
1048
+								'action' => 'edit',
1049
+								'post'   => $event->ID(),
1050
+							),
1051
+							EVENTS_ADMIN_URL
1052
+						)
1053
+						. '">&nbsp;'
1054
+						. $event->get('EVT_name')
1055
+						. '&nbsp;</a>&nbsp;',
1056
+					'</h3>'
1057
+				);
1058
+			}
1059
+			$DTT_ID   = ! empty($this->_req_data['datetime_id']) ? absint($this->_req_data['datetime_id']) : 0;
1060
+			$datetime = EEM_Datetime::instance()->get_one_by_ID($DTT_ID);
1061
+			if ($datetime instanceof EE_Datetime && $this->_template_args['admin_page_header'] !== '') {
1062
+				$this->_template_args['admin_page_header'] = substr(
1063
+					$this->_template_args['admin_page_header'],
1064
+					0,
1065
+					-5
1066
+				);
1067
+				$this->_template_args['admin_page_header'] .= ' &nbsp;<span class="drk-grey-text">';
1068
+				$this->_template_args['admin_page_header'] .= '<span class="dashicons dashicons-calendar"></span>';
1069
+				$this->_template_args['admin_page_header'] .= $datetime->name();
1070
+				$this->_template_args['admin_page_header'] .= ' ( ' . $datetime->start_date() . ' )';
1071
+				$this->_template_args['admin_page_header'] .= '</span></h3>';
1072
+			}
1073
+		}
1074
+		$this->_template_args['after_list_table'] = $this->_display_legend($this->_registration_legend_items());
1075
+		$this->display_admin_list_table_page_with_no_sidebar();
1076
+	}
1077
+
1078
+
1079
+	/**
1080
+	 * This sets the _registration property for the registration details screen
1081
+	 *
1082
+	 * @access private
1083
+	 * @return bool
1084
+	 * @throws EE_Error
1085
+	 * @throws InvalidArgumentException
1086
+	 * @throws InvalidDataTypeException
1087
+	 * @throws InvalidInterfaceException
1088
+	 */
1089
+	private function _set_registration_object()
1090
+	{
1091
+		//get out if we've already set the object
1092
+		if ($this->_registration instanceof EE_Registration) {
1093
+			return true;
1094
+		}
1095
+		$REG    = EEM_Registration::instance();
1096
+		$REG_ID = ( ! empty($this->_req_data['_REG_ID'])) ? absint($this->_req_data['_REG_ID']) : false;
1097
+		if ($this->_registration = $REG->get_one_by_ID($REG_ID)) {
1098
+			return true;
1099
+		} else {
1100
+			$error_msg = sprintf(
1101
+				esc_html__(
1102
+					'An error occurred and the details for Registration ID #%s could not be retrieved.',
1103
+					'event_espresso'
1104
+				),
1105
+				$REG_ID
1106
+			);
1107
+			EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__);
1108
+			$this->_registration = null;
1109
+			return false;
1110
+		}
1111
+	}
1112
+
1113
+
1114
+	/**
1115
+	 * Used to retrieve registrations for the list table.
1116
+	 *
1117
+	 * @param int  $per_page
1118
+	 * @param bool $count
1119
+	 * @param bool $this_month
1120
+	 * @param bool $today
1121
+	 * @return EE_Registration[]|int
1122
+	 * @throws EE_Error
1123
+	 * @throws InvalidArgumentException
1124
+	 * @throws InvalidDataTypeException
1125
+	 * @throws InvalidInterfaceException
1126
+	 */
1127
+	public function get_registrations(
1128
+		$per_page = 10,
1129
+		$count = false,
1130
+		$this_month = false,
1131
+		$today = false
1132
+	) {
1133
+		if ($this_month) {
1134
+			$this->_req_data['status'] = 'month';
1135
+		}
1136
+		if ($today) {
1137
+			$this->_req_data['status'] = 'today';
1138
+		}
1139
+		$query_params = $this->_get_registration_query_parameters($this->_req_data, $per_page, $count);
1140
+		/**
1141
+		 * Override the default groupby added by EEM_Base so that sorts with multiple order bys work as expected
1142
+		 * @link https://events.codebasehq.com/projects/event-espresso/tickets/10093
1143
+		 * @see EEM_Base::get_all()
1144
+		 */
1145
+		$query_params['group_by'] = '';
1146
+
1147
+		return $count
1148
+			? EEM_Registration::instance()->count($query_params)
1149
+			/** @type EE_Registration[] */
1150
+			: EEM_Registration::instance()->get_all($query_params);
1151
+	}
1152
+
1153
+
1154
+	/**
1155
+	 * Retrieves the query parameters to be used by the Registration model for getting registrations.
1156
+	 * Note: this listens to values on the request for some of the query parameters.
1157
+	 *
1158
+	 * @param array $request
1159
+	 * @param int   $per_page
1160
+	 * @param bool  $count
1161
+	 * @return array
1162
+	 * @throws EE_Error
1163
+	 */
1164
+	protected function _get_registration_query_parameters(
1165
+		$request = array(),
1166
+		$per_page = 10,
1167
+		$count = false
1168
+	) {
1169
+
1170
+		$query_params = array(
1171
+			0                          => $this->_get_where_conditions_for_registrations_query(
1172
+				$request
1173
+			),
1174
+			'caps'                     => EEM_Registration::caps_read_admin,
1175
+			'default_where_conditions' => 'this_model_only',
1176
+		);
1177
+		if (! $count) {
1178
+			$query_params = array_merge(
1179
+				$query_params,
1180
+				$this->_get_orderby_for_registrations_query(),
1181
+				$this->_get_limit($per_page)
1182
+			);
1183
+		}
1184
+
1185
+		return $query_params;
1186
+	}
1187
+
1188
+
1189
+	/**
1190
+	 * This will add EVT_ID to the provided $where array for EE model query parameters.
1191
+	 *
1192
+	 * @param array $request usually the same as $this->_req_data but not necessarily
1193
+	 * @return array
1194
+	 */
1195
+	protected function _add_event_id_to_where_conditions(array $request)
1196
+	{
1197
+		$where = array();
1198
+		if (! empty($request['event_id'])) {
1199
+			$where['EVT_ID'] = absint($request['event_id']);
1200
+		}
1201
+		return $where;
1202
+	}
1203
+
1204
+
1205
+	/**
1206
+	 * Adds category ID if it exists in the request to the where conditions for the registrations query.
1207
+	 *
1208
+	 * @param array $request usually the same as $this->_req_data but not necessarily
1209
+	 * @return array
1210
+	 */
1211
+	protected function _add_category_id_to_where_conditions(array $request)
1212
+	{
1213
+		$where = array();
1214
+		if (! empty($request['EVT_CAT']) && (int)$request['EVT_CAT'] !== -1) {
1215
+			$where['Event.Term_Taxonomy.term_id'] = absint($request['EVT_CAT']);
1216
+		}
1217
+		return $where;
1218
+	}
1219
+
1220
+
1221
+	/**
1222
+	 * Adds the datetime ID if it exists in the request to the where conditions for the registrations query.
1223
+	 *
1224
+	 * @param array $request usually the same as $this->_req_data but not necessarily
1225
+	 * @return array
1226
+	 */
1227
+	protected function _add_datetime_id_to_where_conditions(array $request)
1228
+	{
1229
+		$where = array();
1230
+		if (! empty($request['datetime_id'])) {
1231
+			$where['Ticket.Datetime.DTT_ID'] = absint($request['datetime_id']);
1232
+		}
1233
+		if (! empty($request['DTT_ID'])) {
1234
+			$where['Ticket.Datetime.DTT_ID'] = absint($request['DTT_ID']);
1235
+		}
1236
+		return $where;
1237
+	}
1238
+
1239
+
1240
+	/**
1241
+	 * Adds the correct registration status to the where conditions for the registrations query.
1242
+	 *
1243
+	 * @param array $request usually the same as $this->_req_data but not necessarily
1244
+	 * @return array
1245
+	 */
1246
+	protected function _add_registration_status_to_where_conditions(array $request)
1247
+	{
1248
+		$where = array();
1249
+		$view = EEH_Array::is_set($request, 'status', '');
1250
+		$registration_status = ! empty($request['_reg_status'])
1251
+			? sanitize_text_field($request['_reg_status'])
1252
+			: '';
1253
+
1254
+		/*
1255 1255
          * If filtering by registration status, then we show registrations matching that status.
1256 1256
          * If not filtering by specified status, then we show all registrations excluding incomplete registrations
1257 1257
          * UNLESS viewing trashed registrations.
1258 1258
          */
1259
-        if (! empty($registration_status)) {
1260
-            $where['STS_ID'] = $registration_status;
1261
-        } else {
1262
-            //make sure we exclude incomplete registrations, but only if not trashed.
1263
-            if ($view === 'trash') {
1264
-                $where['REG_deleted'] = true;
1265
-            } elseif ($view === 'incomplete') {
1266
-                $where['STS_ID'] = EEM_Registration::status_id_incomplete;
1267
-            } else {
1268
-                $where['STS_ID'] = array('!=', EEM_Registration::status_id_incomplete);
1269
-            }
1270
-        }
1271
-        return $where;
1272
-    }
1273
-
1274
-
1275
-    /**
1276
-     * Adds any provided date restraints to the where conditions for the registrations query.
1277
-     *
1278
-     * @param array $request usually the same as $this->_req_data but not necessarily
1279
-     * @return array
1280
-     * @throws EE_Error
1281
-     * @throws InvalidArgumentException
1282
-     * @throws InvalidDataTypeException
1283
-     * @throws InvalidInterfaceException
1284
-     */
1285
-    protected function _add_date_to_where_conditions(array $request)
1286
-    {
1287
-        $where = array();
1288
-        $view = EEH_Array::is_set($request, 'status', '');
1289
-        $month_range             = ! empty($request['month_range'])
1290
-            ? sanitize_text_field($request['month_range'])
1291
-            : '';
1292
-        $retrieve_for_today      = $view === 'today';
1293
-        $retrieve_for_this_month = $view === 'month';
1294
-
1295
-        if ($retrieve_for_today) {
1296
-            $now               = date('Y-m-d', current_time('timestamp'));
1297
-            $where['REG_date'] = array(
1298
-                'BETWEEN',
1299
-                array(
1300
-                    EEM_Registration::instance()->convert_datetime_for_query(
1301
-                        'REG_date',
1302
-                        $now . ' 00:00:00',
1303
-                        'Y-m-d H:i:s'
1304
-                    ),
1305
-                    EEM_Registration::instance()->convert_datetime_for_query(
1306
-                        'REG_date',
1307
-                        $now . ' 23:59:59',
1308
-                        'Y-m-d H:i:s'
1309
-                    ),
1310
-                ),
1311
-            );
1312
-        } elseif ($retrieve_for_this_month) {
1313
-            $current_year_and_month = date('Y-m', current_time('timestamp'));
1314
-            $days_this_month        = date('t', current_time('timestamp'));
1315
-            $where['REG_date']      = array(
1316
-                'BETWEEN',
1317
-                array(
1318
-                    EEM_Registration::instance()->convert_datetime_for_query(
1319
-                        'REG_date',
1320
-                        $current_year_and_month . '-01 00:00:00',
1321
-                        'Y-m-d H:i:s'
1322
-                    ),
1323
-                    EEM_Registration::instance()->convert_datetime_for_query(
1324
-                        'REG_date',
1325
-                        $current_year_and_month . '-' . $days_this_month . ' 23:59:59',
1326
-                        'Y-m-d H:i:s'
1327
-                    ),
1328
-                ),
1329
-            );
1330
-        } elseif ($month_range) {
1331
-            $pieces          = explode(' ', $month_range, 3);
1332
-            $month_requested = ! empty($pieces[0])
1333
-                ? date('m', \EEH_DTT_Helper::first_of_month_timestamp($pieces[0]))
1334
-                : '';
1335
-            $year_requested  = ! empty($pieces[1])
1336
-                ? $pieces[1]
1337
-                : '';
1338
-            //if there is not a month or year then we can't go further
1339
-            if ($month_requested && $year_requested) {
1340
-                $days_in_month     = date('t', strtotime($year_requested . '-' . $month_requested . '-' . '01'));
1341
-                $where['REG_date'] = array(
1342
-                    'BETWEEN',
1343
-                    array(
1344
-                        EEM_Registration::instance()->convert_datetime_for_query(
1345
-                            'REG_date',
1346
-                            $year_requested . '-' . $month_requested . '-01 00:00:00',
1347
-                            'Y-m-d H:i:s'
1348
-                        ),
1349
-                        EEM_Registration::instance()->convert_datetime_for_query(
1350
-                            'REG_date',
1351
-                            $year_requested . '-' . $month_requested . '-' . $days_in_month . ' 23:59:59',
1352
-                            'Y-m-d H:i:s'
1353
-                        ),
1354
-                    ),
1355
-                );
1356
-            }
1357
-        }
1358
-        return $where;
1359
-    }
1360
-
1361
-
1362
-    /**
1363
-     * Adds any provided search restraints to the where conditions for the registrations query
1364
-     *
1365
-     * @param array $request usually the same as $this->_req_data but not necessarily
1366
-     * @return array
1367
-     */
1368
-    protected function _add_search_to_where_conditions(array $request)
1369
-    {
1370
-        $where = array();
1371
-        if (! empty($request['s'])) {
1372
-            $search_string = '%' . sanitize_text_field($request['s']) . '%';
1373
-            $where['OR*search_conditions'] = array(
1374
-                'Event.EVT_name'                          => array('LIKE', $search_string),
1375
-                'Event.EVT_desc'                          => array('LIKE', $search_string),
1376
-                'Event.EVT_short_desc'                    => array('LIKE', $search_string),
1377
-                'Attendee.ATT_full_name'                  => array('LIKE', $search_string),
1378
-                'Attendee.ATT_fname'                      => array('LIKE', $search_string),
1379
-                'Attendee.ATT_lname'                      => array('LIKE', $search_string),
1380
-                'Attendee.ATT_short_bio'                  => array('LIKE', $search_string),
1381
-                'Attendee.ATT_email'                      => array('LIKE', $search_string),
1382
-                'Attendee.ATT_address'                    => array('LIKE', $search_string),
1383
-                'Attendee.ATT_address2'                   => array('LIKE', $search_string),
1384
-                'Attendee.ATT_city'                       => array('LIKE', $search_string),
1385
-                'REG_final_price'                         => array('LIKE', $search_string),
1386
-                'REG_code'                                => array('LIKE', $search_string),
1387
-                'REG_count'                               => array('LIKE', $search_string),
1388
-                'REG_group_size'                          => array('LIKE', $search_string),
1389
-                'Ticket.TKT_name'                         => array('LIKE', $search_string),
1390
-                'Ticket.TKT_description'                  => array('LIKE', $search_string),
1391
-                'Transaction.Payment.PAY_txn_id_chq_nmbr' => array('LIKE', $search_string),
1392
-            );
1393
-        }
1394
-        return $where;
1395
-    }
1396
-
1397
-
1398
-    /**
1399
-     * Sets up the where conditions for the registrations query.
1400
-     *
1401
-     * @param array $request
1402
-     * @return array
1403
-     * @throws EE_Error
1404
-     */
1405
-    protected function _get_where_conditions_for_registrations_query($request)
1406
-    {
1407
-        return apply_filters(
1408
-            'FHEE__Registrations_Admin_Page___get_where_conditions_for_registrations_query',
1409
-            array_merge(
1410
-                $this->_add_event_id_to_where_conditions($request),
1411
-                $this->_add_category_id_to_where_conditions($request),
1412
-                $this->_add_datetime_id_to_where_conditions($request),
1413
-                $this->_add_registration_status_to_where_conditions($request),
1414
-                $this->_add_date_to_where_conditions($request),
1415
-                $this->_add_search_to_where_conditions($request)
1416
-            ),
1417
-            $request
1418
-        );
1419
-    }
1420
-
1421
-
1422
-    /**
1423
-     * Sets up the orderby for the registrations query.
1424
-     *
1425
-     * @return array
1426
-     */
1427
-    protected function _get_orderby_for_registrations_query()
1428
-    {
1429
-        $orderby_field = ! empty($this->_req_data['orderby'])
1430
-            ? sanitize_text_field($this->_req_data['orderby'])
1431
-            : '';
1432
-        switch ($orderby_field) {
1433
-            case '_REG_ID':
1434
-                $orderby = array('REG_ID');
1435
-                break;
1436
-            case '_Reg_status':
1437
-                $orderby = array('STS_ID');
1438
-                break;
1439
-            case 'ATT_fname':
1440
-                $orderby = array('Attendee.ATT_fname', 'Attendee.ATT_lname');
1441
-                break;
1442
-            case 'ATT_lname':
1443
-                $orderby = array('Attendee.ATT_lname', 'Attendee.ATT_fname');
1444
-                break;
1445
-            case 'event_name':
1446
-                $orderby = array('Event.EVT_name');
1447
-                break;
1448
-            case 'DTT_EVT_start':
1449
-                $orderby = array('Event.Datetime.DTT_EVT_start');
1450
-                break;
1451
-            default: //'REG_date'
1452
-                $orderby = array('REG_date');
1453
-        }
1454
-
1455
-        //order
1456
-        $order = ! empty($this->_req_data['order'])
1457
-            ? sanitize_text_field($this->_req_data['order'])
1458
-            : 'DESC';
1459
-        $orderby = array_combine(
1460
-            $orderby,
1461
-            array_fill(0, count($orderby), $order)
1462
-        );
1463
-        //because there are many registrations with the same date, define
1464
-        //a secondary way to order them, otherwise MySQL seems to be a bit random
1465
-        if (empty($orderby['REG_ID'])) {
1466
-            $orderby['REG_ID'] = $order;
1467
-        }
1468
-        return array('order_by' => $orderby);
1469
-    }
1470
-
1471
-
1472
-    /**
1473
-     * Sets up the limit for the registrations query.
1474
-     *
1475
-     * @param $per_page
1476
-     * @return array
1477
-     */
1478
-    protected function _get_limit($per_page)
1479
-    {
1480
-        $current_page = ! empty($this->_req_data['paged'])
1481
-            ? absint($this->_req_data['paged'])
1482
-            : 1;
1483
-        $per_page     = ! empty($this->_req_data['perpage'])
1484
-            ? $this->_req_data['perpage']
1485
-            : $per_page;
1486
-
1487
-        //-1 means return all results so get out if that's set.
1488
-        if ((int)$per_page === -1) {
1489
-            return array();
1490
-        }
1491
-        $per_page = absint($per_page);
1492
-        $offset   = ($current_page - 1) * $per_page;
1493
-        return array('limit' => array($offset, $per_page));
1494
-    }
1495
-
1496
-
1497
-    public function get_registration_status_array()
1498
-    {
1499
-        return self::$_reg_status;
1500
-    }
1501
-
1502
-
1503
-
1504
-
1505
-    /***************************************        REGISTRATION DETAILS        ***************************************/
1506
-    /**
1507
-     *        generates HTML for the View Registration Details Admin page
1508
-     *
1509
-     * @access protected
1510
-     * @return void
1511
-     * @throws DomainException
1512
-     * @throws EE_Error
1513
-     * @throws InvalidArgumentException
1514
-     * @throws InvalidDataTypeException
1515
-     * @throws InvalidInterfaceException
1516
-     * @throws EntityNotFoundException
1517
-     */
1518
-    protected function _registration_details()
1519
-    {
1520
-        $this->_template_args = array();
1521
-        $this->_set_registration_object();
1522
-        if (is_object($this->_registration)) {
1523
-            $transaction                                   = $this->_registration->transaction()
1524
-                ? $this->_registration->transaction()
1525
-                : EE_Transaction::new_instance();
1526
-            $this->_session                                = $transaction->session_data();
1527
-            $event_id                                      = $this->_registration->event_ID();
1528
-            $this->_template_args['reg_nmbr']['value']     = $this->_registration->ID();
1529
-            $this->_template_args['reg_nmbr']['label']     = esc_html__('Registration Number', 'event_espresso');
1530
-            $this->_template_args['reg_datetime']['value'] = $this->_registration->get_i18n_datetime('REG_date');
1531
-            $this->_template_args['reg_datetime']['label'] = esc_html__('Date', 'event_espresso');
1532
-            $this->_template_args['grand_total']           = $transaction->total();
1533
-            $this->_template_args['currency_sign']         = EE_Registry::instance()->CFG->currency->sign;
1534
-            // link back to overview
1535
-            $this->_template_args['reg_overview_url']            = REG_ADMIN_URL;
1536
-            $this->_template_args['registration']                = $this->_registration;
1537
-            $this->_template_args['filtered_registrations_link'] = EE_Admin_Page::add_query_args_and_nonce(
1538
-                array(
1539
-                    'action'   => 'default',
1540
-                    'event_id' => $event_id,
1541
-                ),
1542
-                REG_ADMIN_URL
1543
-            );
1544
-            $this->_template_args['filtered_transactions_link']  = EE_Admin_Page::add_query_args_and_nonce(
1545
-                array(
1546
-                    'action' => 'default',
1547
-                    'EVT_ID' => $event_id,
1548
-                    'page'   => 'espresso_transactions',
1549
-                ),
1550
-                admin_url('admin.php')
1551
-            );
1552
-            $this->_template_args['event_link']                  = EE_Admin_Page::add_query_args_and_nonce(
1553
-                array(
1554
-                    'page'   => 'espresso_events',
1555
-                    'action' => 'edit',
1556
-                    'post'   => $event_id,
1557
-                ),
1558
-                admin_url('admin.php')
1559
-            );
1560
-            //next and previous links
1561
-            $next_reg                                      = $this->_registration->next(
1562
-                null,
1563
-                array(),
1564
-                'REG_ID'
1565
-            );
1566
-            $this->_template_args['next_registration']     = $next_reg
1567
-                ? $this->_next_link(
1568
-                    EE_Admin_Page::add_query_args_and_nonce(
1569
-                        array(
1570
-                            'action'  => 'view_registration',
1571
-                            '_REG_ID' => $next_reg['REG_ID'],
1572
-                        ),
1573
-                        REG_ADMIN_URL
1574
-                    ),
1575
-                    'dashicons dashicons-arrow-right ee-icon-size-22'
1576
-                )
1577
-                : '';
1578
-            $previous_reg                                  = $this->_registration->previous(
1579
-                null,
1580
-                array(),
1581
-                'REG_ID'
1582
-            );
1583
-            $this->_template_args['previous_registration'] = $previous_reg
1584
-                ? $this->_previous_link(
1585
-                    EE_Admin_Page::add_query_args_and_nonce(
1586
-                        array(
1587
-                            'action'  => 'view_registration',
1588
-                            '_REG_ID' => $previous_reg['REG_ID'],
1589
-                        ),
1590
-                        REG_ADMIN_URL
1591
-                    ),
1592
-                    'dashicons dashicons-arrow-left ee-icon-size-22'
1593
-                )
1594
-                : '';
1595
-            // grab header
1596
-            $template_path                             = REG_TEMPLATE_PATH . 'reg_admin_details_header.template.php';
1597
-            $this->_template_args['REG_ID']            = $this->_registration->ID();
1598
-            $this->_template_args['admin_page_header'] = EEH_Template::display_template(
1599
-                $template_path,
1600
-                $this->_template_args,
1601
-                true
1602
-            );
1603
-        } else {
1604
-            $this->_template_args['admin_page_header'] = $this->display_espresso_notices();
1605
-        }
1606
-        // the details template wrapper
1607
-        $this->display_admin_page_with_sidebar();
1608
-    }
1609
-
1610
-
1611
-    protected function _registration_details_metaboxes()
1612
-    {
1613
-        do_action('AHEE__Registrations_Admin_Page___registration_details_metabox__start', $this);
1614
-        $this->_set_registration_object();
1615
-        $attendee = $this->_registration instanceof EE_Registration ? $this->_registration->attendee() : null;
1616
-        add_meta_box('edit-reg-status-mbox', esc_html__('Registration Status', 'event_espresso'),
1617
-            array($this, 'set_reg_status_buttons_metabox'), $this->wp_page_slug, 'normal', 'high');
1618
-        add_meta_box('edit-reg-details-mbox', esc_html__('Registration Details', 'event_espresso'),
1619
-            array($this, '_reg_details_meta_box'), $this->wp_page_slug, 'normal', 'high');
1620
-        if ($attendee instanceof EE_Attendee
1621
-            && EE_Registry::instance()->CAP->current_user_can(
1622
-                'ee_edit_registration',
1623
-                'edit-reg-questions-mbox',
1624
-                $this->_registration->ID()
1625
-            )
1626
-        ) {
1627
-            add_meta_box(
1628
-                'edit-reg-questions-mbox',
1629
-                esc_html__('Registration Form Answers', 'event_espresso'),
1630
-                array($this, '_reg_questions_meta_box'),
1631
-                $this->wp_page_slug,
1632
-                'normal',
1633
-                'high'
1634
-            );
1635
-        }
1636
-        add_meta_box(
1637
-            'edit-reg-registrant-mbox',
1638
-            esc_html__('Contact Details', 'event_espresso'),
1639
-            array($this, '_reg_registrant_side_meta_box'),
1640
-            $this->wp_page_slug,
1641
-            'side',
1642
-            'high'
1643
-        );
1644
-        if ($this->_registration->group_size() > 1) {
1645
-            add_meta_box(
1646
-                'edit-reg-attendees-mbox',
1647
-                esc_html__('Other Registrations in this Transaction', 'event_espresso'),
1648
-                array($this, '_reg_attendees_meta_box'),
1649
-                $this->wp_page_slug,
1650
-                'normal',
1651
-                'high'
1652
-            );
1653
-        }
1654
-    }
1655
-
1656
-
1657
-    /**
1658
-     * set_reg_status_buttons_metabox
1659
-     *
1660
-     * @access protected
1661
-     * @return string
1662
-     * @throws \EE_Error
1663
-     */
1664
-    public function set_reg_status_buttons_metabox()
1665
-    {
1666
-        $this->_set_registration_object();
1667
-        $change_reg_status_form = $this->_generate_reg_status_change_form();
1668
-        echo $change_reg_status_form->form_open(
1669
-            self::add_query_args_and_nonce(
1670
-                array(
1671
-                    'action' => 'change_reg_status',
1672
-                ),
1673
-                REG_ADMIN_URL
1674
-            )
1675
-        );
1676
-        echo $change_reg_status_form->get_html();
1677
-        echo $change_reg_status_form->form_close();
1678
-    }
1679
-
1680
-
1681
-    /**
1682
-     * @return EE_Form_Section_Proper
1683
-     * @throws EE_Error
1684
-     * @throws InvalidArgumentException
1685
-     * @throws InvalidDataTypeException
1686
-     * @throws InvalidInterfaceException
1687
-     * @throws \EventEspresso\core\exceptions\EntityNotFoundException
1688
-     */
1689
-    protected function _generate_reg_status_change_form()
1690
-    {
1691
-        return new EE_Form_Section_Proper(array(
1692
-            'name'            => 'reg_status_change_form',
1693
-            'html_id'         => 'reg-status-change-form',
1694
-            'layout_strategy' => new EE_Admin_Two_Column_Layout(),
1695
-            'subsections'     => array(
1696
-                'return'             => new EE_Hidden_Input(array(
1697
-                    'name'    => 'return',
1698
-                    'default' => 'view_registration',
1699
-                )),
1700
-                'REG_ID'             => new EE_Hidden_Input(array(
1701
-                    'name'    => 'REG_ID',
1702
-                    'default' => $this->_registration->ID(),
1703
-                )),
1704
-                'current_status'     => new EE_Form_Section_HTML(
1705
-                    EEH_HTML::tr(
1706
-                        EEH_HTML::th(
1707
-                            EEH_HTML::label(
1708
-                                EEH_HTML::strong(esc_html__('Current Registration Status', 'event_espresso')
1709
-                                )
1710
-                            )
1711
-                        )
1712
-                        . EEH_HTML::td(
1713
-                            EEH_HTML::strong(
1714
-                                $this->_registration->pretty_status(),
1715
-                                '',
1716
-                                'status-' . $this->_registration->status_ID(),
1717
-                                'line-height: 1em; font-size: 1.5em; font-weight: bold;'
1718
-                            )
1719
-                        )
1720
-                    )
1721
-                ),
1722
-                'reg_status'         => new EE_Select_Input(
1723
-                    $this->_get_reg_statuses(),
1724
-                    array(
1725
-                        'html_label_text' => esc_html__('Change Registration Status to', 'event_espresso'),
1726
-                        'default'         => $this->_registration->status_ID(),
1727
-                    )
1728
-                ),
1729
-                'send_notifications' => new EE_Yes_No_Input(
1730
-                    array(
1731
-                        'html_label_text' => esc_html__('Send Related Messages', 'event_espresso'),
1732
-                        'default'         => false,
1733
-                        'html_help_text'  => esc_html__(
1734
-                            'If set to "Yes", then the related messages will be sent to the registrant.',
1735
-                            'event_espresso'
1736
-                        ),
1737
-                    )
1738
-                ),
1739
-                'submit'             => new EE_Submit_Input(
1740
-                    array(
1741
-                        'html_class'      => 'button-primary',
1742
-                        'html_label_text' => '&nbsp;',
1743
-                        'default'         => esc_html__('Update Registration Status', 'event_espresso'),
1744
-                    )
1745
-                ),
1746
-            ),
1747
-        ));
1748
-    }
1749
-
1750
-
1751
-    /**
1752
-     * Returns an array of all the buttons for the various statuses and switch status actions
1753
-     *
1754
-     * @return array
1755
-     * @throws EE_Error
1756
-     * @throws InvalidArgumentException
1757
-     * @throws InvalidDataTypeException
1758
-     * @throws InvalidInterfaceException
1759
-     * @throws EntityNotFoundException
1760
-     */
1761
-    protected function _get_reg_statuses()
1762
-    {
1763
-        $reg_status_array = EEM_Registration::instance()->reg_status_array();
1764
-        unset ($reg_status_array[EEM_Registration::status_id_incomplete]);
1765
-        // get current reg status
1766
-        $current_status = $this->_registration->status_ID();
1767
-        // is registration for free event? This will determine whether to display the pending payment option
1768
-        if (
1769
-            $current_status !== EEM_Registration::status_id_pending_payment
1770
-            && EEH_Money::compare_floats($this->_registration->ticket()->price(), 0.00)
1771
-        ) {
1772
-            unset($reg_status_array[EEM_Registration::status_id_pending_payment]);
1773
-        }
1774
-        return EEM_Status::instance()->localized_status($reg_status_array, false, 'sentence');
1775
-    }
1776
-
1777
-
1778
-    /**
1779
-     * This method is used when using _REG_ID from request which may or may not be an array of reg_ids.
1780
-     *
1781
-     * @param bool $status REG status given for changing registrations to.
1782
-     * @param bool $notify Whether to send messages notifications or not.
1783
-     * @return array (array with reg_id(s) updated and whether update was successful.
1784
-     * @throws EE_Error
1785
-     * @throws InvalidArgumentException
1786
-     * @throws InvalidDataTypeException
1787
-     * @throws InvalidInterfaceException
1788
-     * @throws ReflectionException
1789
-     * @throws RuntimeException
1790
-     * @throws EntityNotFoundException
1791
-     */
1792
-    protected function _set_registration_status_from_request($status = false, $notify = false)
1793
-    {
1794
-        if (isset($this->_req_data['reg_status_change_form'])) {
1795
-            $REG_IDs = isset($this->_req_data['reg_status_change_form']['REG_ID'])
1796
-                ? (array)$this->_req_data['reg_status_change_form']['REG_ID']
1797
-                : array();
1798
-        } else {
1799
-            $REG_IDs = isset($this->_req_data['_REG_ID'])
1800
-                ? (array)$this->_req_data['_REG_ID']
1801
-                : array();
1802
-        }
1803
-        // sanitize $REG_IDs
1804
-        $REG_IDs = array_map('absint', $REG_IDs);
1805
-        // and remove empty entries
1806
-        $REG_IDs = array_filter($REG_IDs);
1807
-
1808
-        $result = $this->_set_registration_status($REG_IDs, $status, $notify);
1809
-
1810
-        /**
1811
-         * Set and filter $_req_data['_REG_ID'] for any potential future messages notifications.
1812
-         * Currently this value is used downstream by the _process_resend_registration method.
1813
-         *
1814
-         * @param int|array                $registration_ids The registration ids that have had their status changed successfully.
1815
-         * @param bool                     $status           The status registrations were changed to.
1816
-         * @param bool                     $success          If the status was changed successfully for all registrations.
1817
-         * @param Registrations_Admin_Page $admin_page_object
1818
-         */
1819
-        $this->_req_data['_REG_ID'] = apply_filters(
1820
-            'FHEE__Registrations_Admin_Page___set_registration_status_from_request__REG_IDs',
1821
-            $result['REG_ID'],
1822
-            $status,
1823
-            $result['success'],
1824
-            $this
1825
-        );
1826
-
1827
-        //notify?
1828
-        if ($notify
1829
-            && $result['success']
1830
-            && ! empty($this->_req_data['_REG_ID'])
1831
-            && EE_Registry::instance()->CAP->current_user_can(
1832
-                'ee_send_message',
1833
-                'espresso_registrations_resend_registration'
1834
-            )
1835
-        ) {
1836
-            $this->_process_resend_registration();
1837
-        }
1838
-        return $result;
1839
-    }
1840
-
1841
-
1842
-    /**
1843
-     * Set the registration status for the given reg_id (which may or may not be an array, it gets typecast to an
1844
-     * array). Note, this method does NOT take care of possible notifications.  That is required by calling code.
1845
-     *
1846
-     * @param array  $REG_IDs
1847
-     * @param string $status
1848
-     * @param bool   $notify  Used to indicate whether notification was requested or not.  This determines the context
1849
-     *                        slug sent with setting the registration status.
1850
-     * @return array (an array with 'success' key representing whether status change was successful, and 'REG_ID' as
1851
-     * @throws EE_Error
1852
-     * @throws InvalidArgumentException
1853
-     * @throws InvalidDataTypeException
1854
-     * @throws InvalidInterfaceException
1855
-     * @throws ReflectionException
1856
-     * @throws RuntimeException
1857
-     * @throws EntityNotFoundException
1858
-     */
1859
-    protected function _set_registration_status($REG_IDs = array(), $status = '', $notify = false)
1860
-    {
1861
-        $success = false;
1862
-        // typecast $REG_IDs
1863
-        $REG_IDs = (array)$REG_IDs;
1864
-        if ( ! empty($REG_IDs)) {
1865
-            $success = true;
1866
-            // set default status if none is passed
1867
-            $status = $status ? $status : EEM_Registration::status_id_pending_payment;
1868
-            $status_context = $notify
1869
-                ? Domain::CONTEXT_REGISTRATION_STATUS_CHANGE_REGISTRATION_ADMIN_NOTIFY
1870
-                : Domain::CONTEXT_REGISTRATION_STATUS_CHANGE_REGISTRATION_ADMIN;
1871
-            //loop through REG_ID's and change status
1872
-            foreach ($REG_IDs as $REG_ID) {
1873
-                $registration = EEM_Registration::instance()->get_one_by_ID($REG_ID);
1874
-                if ($registration instanceof EE_Registration) {
1875
-                    $registration->set_status(
1876
-                        $status,
1877
-                        false,
1878
-                        new Context(
1879
-                            $status_context,
1880
-                            esc_html__(
1881
-                                'Manually triggered status change on a Registration Admin Page route.',
1882
-                                'event_espresso'
1883
-                            )
1884
-                        )
1885
-                    );
1886
-                    $result = $registration->save();
1887
-                    // verifying explicit fails because update *may* just return 0 for 0 rows affected
1888
-                    $success = $result !== false ? $success : false;
1889
-                }
1890
-            }
1891
-        }
1892
-
1893
-        //return $success and processed registrations
1894
-        return array('REG_ID' => $REG_IDs, 'success' => $success);
1895
-    }
1896
-
1897
-
1898
-    /**
1899
-     * Common logic for setting up success message and redirecting to appropriate route
1900
-     *
1901
-     * @param  string $STS_ID status id for the registration changed to
1902
-     * @param   bool  $notify indicates whether the _set_registration_status_from_request does notifications or not.
1903
-     * @return void
1904
-     * @throws EE_Error
1905
-     */
1906
-    protected function _reg_status_change_return($STS_ID, $notify = false)
1907
-    {
1908
-        $result  = ! empty($STS_ID) ? $this->_set_registration_status_from_request($STS_ID, $notify)
1909
-            : array('success' => false);
1910
-        $success = isset($result['success']) && $result['success'];
1911
-        //setup success message
1912
-        if ($success) {
1913
-            if (is_array($result['REG_ID']) && count($result['REG_ID']) === 1) {
1914
-                $msg = sprintf(esc_html__('Registration status has been set to %s', 'event_espresso'),
1915
-                    EEH_Template::pretty_status($STS_ID, false, 'lower'));
1916
-            } else {
1917
-                $msg = sprintf(esc_html__('Registrations have been set to %s.', 'event_espresso'),
1918
-                    EEH_Template::pretty_status($STS_ID, false, 'lower'));
1919
-            }
1920
-            EE_Error::add_success($msg);
1921
-        } else {
1922
-            EE_Error::add_error(
1923
-                esc_html__(
1924
-                    'Something went wrong, and the status was not changed',
1925
-                    'event_espresso'
1926
-                ), __FILE__, __LINE__, __FUNCTION__
1927
-            );
1928
-        }
1929
-        if (isset($this->_req_data['return']) && $this->_req_data['return'] == 'view_registration') {
1930
-            $route = array('action' => 'view_registration', '_REG_ID' => reset($result['REG_ID']));
1931
-        } else {
1932
-            $route = array('action' => 'default');
1933
-        }
1934
-        //unset nonces
1935
-        foreach ($this->_req_data as $ref => $value) {
1936
-            if (strpos($ref, 'nonce') !== false) {
1937
-                unset($this->_req_data[$ref]);
1938
-                continue;
1939
-            }
1940
-            $value                 = is_array($value) ? array_map('urlencode', $value) : urlencode($value);
1941
-            $this->_req_data[$ref] = $value;
1942
-        }
1943
-        //merge request vars so that the reloaded list table contains any existing filter query params
1944
-        $route = array_merge($this->_req_data, $route);
1945
-        $this->_redirect_after_action($success, '', '', $route, true);
1946
-    }
1947
-
1948
-
1949
-    /**
1950
-     * incoming reg status change from reg details page.
1951
-     *
1952
-     * @return void
1953
-     */
1954
-    protected function _change_reg_status()
1955
-    {
1956
-        $this->_req_data['return'] = 'view_registration';
1957
-        //set notify based on whether the send notifications toggle is set or not
1958
-        $notify = ! empty($this->_req_data['reg_status_change_form']['send_notifications']);
1959
-        //$notify = ! empty( $this->_req_data['txn_reg_status_change']['send_notifications'] );
1960
-        $this->_req_data['reg_status_change_form']['reg_status'] = isset($this->_req_data['reg_status_change_form']['reg_status'])
1961
-            ? $this->_req_data['reg_status_change_form']['reg_status'] : '';
1962
-        switch ($this->_req_data['reg_status_change_form']['reg_status']) {
1963
-            case EEM_Registration::status_id_approved :
1964
-            case EEH_Template::pretty_status(EEM_Registration::status_id_approved, false, 'sentence') :
1965
-                $this->approve_registration($notify);
1966
-                break;
1967
-            case EEM_Registration::status_id_pending_payment :
1968
-            case EEH_Template::pretty_status(EEM_Registration::status_id_pending_payment, false, 'sentence') :
1969
-                $this->pending_registration($notify);
1970
-                break;
1971
-            case EEM_Registration::status_id_not_approved :
1972
-            case EEH_Template::pretty_status(EEM_Registration::status_id_not_approved, false, 'sentence') :
1973
-                $this->not_approve_registration($notify);
1974
-                break;
1975
-            case EEM_Registration::status_id_declined :
1976
-            case EEH_Template::pretty_status(EEM_Registration::status_id_declined, false, 'sentence') :
1977
-                $this->decline_registration($notify);
1978
-                break;
1979
-            case EEM_Registration::status_id_cancelled :
1980
-            case EEH_Template::pretty_status(EEM_Registration::status_id_cancelled, false, 'sentence') :
1981
-                $this->cancel_registration($notify);
1982
-                break;
1983
-            case EEM_Registration::status_id_wait_list :
1984
-            case EEH_Template::pretty_status(EEM_Registration::status_id_wait_list, false, 'sentence') :
1985
-                $this->wait_list_registration($notify);
1986
-                break;
1987
-            case EEM_Registration::status_id_incomplete :
1988
-            default :
1989
-                $result['success'] = false;
1990
-                unset($this->_req_data['return']);
1991
-                $this->_reg_status_change_return('', false);
1992
-                break;
1993
-        }
1994
-    }
1995
-
1996
-
1997
-    /**
1998
-     * Callback for bulk action routes.
1999
-     * Note: although we could just register the singular route callbacks for each bulk action route as well, this
2000
-     * method was chosen so there is one central place all the registration status bulk actions are going through.
2001
-     * Potentially, this provides an easier place to locate logic that is specific to these bulk actions (as opposed to
2002
-     * when an action is happening on just a single registration).
2003
-     * @param      $action
2004
-     * @param bool $notify
2005
-     */
2006
-    protected function bulk_action_on_registrations($action, $notify = false) {
2007
-        do_action(
2008
-            'AHEE__Registrations_Admin_Page__bulk_action_on_registrations__before_execution',
2009
-            $this,
2010
-            $action,
2011
-            $notify
2012
-        );
2013
-        $method = $action . '_registration';
2014
-        if (method_exists($this, $method)) {
2015
-            $this->$method($notify);
2016
-        }
2017
-    }
2018
-
2019
-
2020
-    /**
2021
-     * approve_registration
2022
-     *
2023
-     * @access protected
2024
-     * @param bool $notify whether or not to notify the registrant about their approval.
2025
-     * @return void
2026
-     */
2027
-    protected function approve_registration($notify = false)
2028
-    {
2029
-        $this->_reg_status_change_return(EEM_Registration::status_id_approved, $notify);
2030
-    }
2031
-
2032
-
2033
-    /**
2034
-     *        decline_registration
2035
-     *
2036
-     * @access protected
2037
-     * @param bool $notify whether or not to notify the registrant about their status change.
2038
-     * @return void
2039
-     */
2040
-    protected function decline_registration($notify = false)
2041
-    {
2042
-        $this->_reg_status_change_return(EEM_Registration::status_id_declined, $notify);
2043
-    }
2044
-
2045
-
2046
-    /**
2047
-     *        cancel_registration
2048
-     *
2049
-     * @access protected
2050
-     * @param bool $notify whether or not to notify the registrant about their status change.
2051
-     * @return void
2052
-     */
2053
-    protected function cancel_registration($notify = false)
2054
-    {
2055
-        $this->_reg_status_change_return(EEM_Registration::status_id_cancelled, $notify);
2056
-    }
2057
-
2058
-
2059
-    /**
2060
-     *        not_approve_registration
2061
-     *
2062
-     * @access protected
2063
-     * @param bool $notify whether or not to notify the registrant about their status change.
2064
-     * @return void
2065
-     */
2066
-    protected function not_approve_registration($notify = false)
2067
-    {
2068
-        $this->_reg_status_change_return(EEM_Registration::status_id_not_approved, $notify);
2069
-    }
2070
-
2071
-
2072
-    /**
2073
-     *        decline_registration
2074
-     *
2075
-     * @access protected
2076
-     * @param bool $notify whether or not to notify the registrant about their status change.
2077
-     * @return void
2078
-     */
2079
-    protected function pending_registration($notify = false)
2080
-    {
2081
-        $this->_reg_status_change_return(EEM_Registration::status_id_pending_payment, $notify);
2082
-    }
2083
-
2084
-
2085
-    /**
2086
-     * waitlist_registration
2087
-     *
2088
-     * @access protected
2089
-     * @param bool $notify whether or not to notify the registrant about their status change.
2090
-     * @return void
2091
-     */
2092
-    protected function wait_list_registration($notify = false)
2093
-    {
2094
-        $this->_reg_status_change_return(EEM_Registration::status_id_wait_list, $notify);
2095
-    }
2096
-
2097
-
2098
-    /**
2099
-     *        generates HTML for the Registration main meta box
2100
-     *
2101
-     * @access public
2102
-     * @return void
2103
-     * @throws DomainException
2104
-     * @throws EE_Error
2105
-     * @throws InvalidArgumentException
2106
-     * @throws InvalidDataTypeException
2107
-     * @throws InvalidInterfaceException
2108
-     * @throws ReflectionException
2109
-     * @throws EntityNotFoundException
2110
-     */
2111
-    public function _reg_details_meta_box()
2112
-    {
2113
-        EEH_Autoloader::register_line_item_display_autoloaders();
2114
-        EEH_Autoloader::register_line_item_filter_autoloaders();
2115
-        EE_Registry::instance()->load_helper('Line_Item');
2116
-        $transaction    = $this->_registration->transaction() ? $this->_registration->transaction()
2117
-            : EE_Transaction::new_instance();
2118
-        $this->_session = $transaction->session_data();
2119
-        $filters        = new EE_Line_Item_Filter_Collection();
2120
-        //$filters->add( new EE_Non_Zero_Line_Item_Filter() );
2121
-        $filters->add(new EE_Single_Registration_Line_Item_Filter($this->_registration));
2122
-        $line_item_filter_processor              = new EE_Line_Item_Filter_Processor($filters,
2123
-            $transaction->total_line_item());
2124
-        $filtered_line_item_tree                 = $line_item_filter_processor->process();
2125
-        $line_item_display                       = new EE_Line_Item_Display('reg_admin_table',
2126
-            'EE_Admin_Table_Registration_Line_Item_Display_Strategy');
2127
-        $this->_template_args['line_item_table'] = $line_item_display->display_line_item(
2128
-            $filtered_line_item_tree,
2129
-            array('EE_Registration' => $this->_registration)
2130
-        );
2131
-        $attendee                                = $this->_registration->attendee();
2132
-        if (EE_Registry::instance()->CAP->current_user_can(
2133
-            'ee_read_transaction',
2134
-            'espresso_transactions_view_transaction'
2135
-        )) {
2136
-            $this->_template_args['view_transaction_button'] = EEH_Template::get_button_or_link(
2137
-                EE_Admin_Page::add_query_args_and_nonce(
2138
-                    array(
2139
-                        'action' => 'view_transaction',
2140
-                        'TXN_ID' => $transaction->ID(),
2141
-                    ),
2142
-                    TXN_ADMIN_URL
2143
-                ),
2144
-                esc_html__(' View Transaction', 'event_espresso'),
2145
-                'button secondary-button right',
2146
-                'dashicons dashicons-cart'
2147
-            );
2148
-        } else {
2149
-            $this->_template_args['view_transaction_button'] = '';
2150
-        }
2151
-        if ($attendee instanceof EE_Attendee
2152
-            && EE_Registry::instance()->CAP->current_user_can(
2153
-                'ee_send_message',
2154
-                'espresso_registrations_resend_registration'
2155
-            )
2156
-        ) {
2157
-            $this->_template_args['resend_registration_button'] = EEH_Template::get_button_or_link(
2158
-                EE_Admin_Page::add_query_args_and_nonce(
2159
-                    array(
2160
-                        'action'      => 'resend_registration',
2161
-                        '_REG_ID'     => $this->_registration->ID(),
2162
-                        'redirect_to' => 'view_registration',
2163
-                    ),
2164
-                    REG_ADMIN_URL
2165
-                ),
2166
-                esc_html__(' Resend Registration', 'event_espresso'),
2167
-                'button secondary-button right',
2168
-                'dashicons dashicons-email-alt'
2169
-            );
2170
-        } else {
2171
-            $this->_template_args['resend_registration_button'] = '';
2172
-        }
2173
-        $this->_template_args['currency_sign'] = EE_Registry::instance()->CFG->currency->sign;
2174
-        $payment                               = $transaction->get_first_related('Payment');
2175
-        $payment                               = ! $payment instanceof EE_Payment
2176
-            ? EE_Payment::new_instance()
2177
-            : $payment;
2178
-        $payment_method                        = $payment->get_first_related('Payment_Method');
2179
-        $payment_method                        = ! $payment_method instanceof EE_Payment_Method
2180
-            ? EE_Payment_Method::new_instance()
2181
-            : $payment_method;
2182
-        $reg_details                           = array(
2183
-            'payment_method'       => $payment_method->name(),
2184
-            'response_msg'         => $payment->gateway_response(),
2185
-            'registration_id'      => $this->_registration->get('REG_code'),
2186
-            'registration_session' => $this->_registration->session_ID(),
2187
-            'ip_address'           => isset($this->_session['ip_address']) ? $this->_session['ip_address'] : '',
2188
-            'user_agent'           => isset($this->_session['user_agent']) ? $this->_session['user_agent'] : '',
2189
-        );
2190
-        if (isset($reg_details['registration_id'])) {
2191
-            $this->_template_args['reg_details']['registration_id']['value'] = $reg_details['registration_id'];
2192
-            $this->_template_args['reg_details']['registration_id']['label'] = esc_html__(
2193
-                'Registration ID',
2194
-                'event_espresso'
2195
-            );
2196
-            $this->_template_args['reg_details']['registration_id']['class'] = 'regular-text';
2197
-        }
2198
-        if (isset($reg_details['payment_method'])) {
2199
-            $this->_template_args['reg_details']['payment_method']['value'] = $reg_details['payment_method'];
2200
-            $this->_template_args['reg_details']['payment_method']['label'] = esc_html__(
2201
-                'Most Recent Payment Method',
2202
-                'event_espresso'
2203
-            );
2204
-            $this->_template_args['reg_details']['payment_method']['class'] = 'regular-text';
2205
-            $this->_template_args['reg_details']['response_msg']['value']   = $reg_details['response_msg'];
2206
-            $this->_template_args['reg_details']['response_msg']['label']   = esc_html__(
2207
-                'Payment method response',
2208
-                'event_espresso'
2209
-            );
2210
-            $this->_template_args['reg_details']['response_msg']['class']   = 'regular-text';
2211
-        }
2212
-        $this->_template_args['reg_details']['registration_session']['value'] = $reg_details['registration_session'];
2213
-        $this->_template_args['reg_details']['registration_session']['label'] = esc_html__(
2214
-            'Registration Session',
2215
-            'event_espresso'
2216
-        );
2217
-        $this->_template_args['reg_details']['registration_session']['class'] = 'regular-text';
2218
-        $this->_template_args['reg_details']['ip_address']['value']           = $reg_details['ip_address'];
2219
-        $this->_template_args['reg_details']['ip_address']['label']           = esc_html__(
2220
-            'Registration placed from IP',
2221
-            'event_espresso'
2222
-        );
2223
-        $this->_template_args['reg_details']['ip_address']['class']           = 'regular-text';
2224
-        $this->_template_args['reg_details']['user_agent']['value']           = $reg_details['user_agent'];
2225
-        $this->_template_args['reg_details']['user_agent']['label']           = esc_html__('Registrant User Agent',
2226
-            'event_espresso');
2227
-        $this->_template_args['reg_details']['user_agent']['class']           = 'large-text';
2228
-        $this->_template_args['event_link']                                   = EE_Admin_Page::add_query_args_and_nonce(
2229
-            array(
2230
-                'action'   => 'default',
2231
-                'event_id' => $this->_registration->event_ID(),
2232
-            ),
2233
-            REG_ADMIN_URL
2234
-        );
2235
-        $this->_template_args['REG_ID']                                       = $this->_registration->ID();
2236
-        $this->_template_args['event_id']                                     = $this->_registration->event_ID();
2237
-        $template_path                                                        =
2238
-            REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_reg_details.template.php';
2239
-        echo EEH_Template::display_template($template_path, $this->_template_args, true);
2240
-    }
2241
-
2242
-
2243
-    /**
2244
-     * generates HTML for the Registration Questions meta box.
2245
-     * If pre-4.8.32.rc.000 hooks are used, uses old methods (with its filters),
2246
-     * otherwise uses new forms system
2247
-     *
2248
-     * @access public
2249
-     * @return void
2250
-     * @throws DomainException
2251
-     * @throws EE_Error
2252
-     */
2253
-    public function _reg_questions_meta_box()
2254
-    {
2255
-        //allow someone to override this method entirely
2256
-        if (apply_filters('FHEE__Registrations_Admin_Page___reg_questions_meta_box__do_default', true, $this,
2257
-            $this->_registration)) {
2258
-            $form                                              = $this->_get_reg_custom_questions_form(
2259
-                $this->_registration->ID()
2260
-            );
2261
-            $this->_template_args['att_questions']             = count($form->subforms()) > 0
2262
-                ? $form->get_html_and_js()
2263
-                : '';
2264
-            $this->_template_args['reg_questions_form_action'] = 'edit_registration';
2265
-            $this->_template_args['REG_ID']                    = $this->_registration->ID();
2266
-            $template_path                                     =
2267
-                REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_reg_questions.template.php';
2268
-            echo EEH_Template::display_template($template_path, $this->_template_args, true);
2269
-        }
2270
-    }
2271
-
2272
-
2273
-    /**
2274
-     * form_before_question_group
2275
-     *
2276
-     * @deprecated    as of 4.8.32.rc.000
2277
-     * @access        public
2278
-     * @param        string $output
2279
-     * @return        string
2280
-     */
2281
-    public function form_before_question_group($output)
2282
-    {
2283
-        EE_Error::doing_it_wrong(
2284
-            __CLASS__ . '::' . __FUNCTION__,
2285
-            esc_html__(
2286
-                'This method would have been protected but was used on a filter callback so needed to be public. Please discontinue usage as it will be removed soon.',
2287
-                'event_espresso'
2288
-            ),
2289
-            '4.8.32.rc.000'
2290
-        );
2291
-        return '
1259
+		if (! empty($registration_status)) {
1260
+			$where['STS_ID'] = $registration_status;
1261
+		} else {
1262
+			//make sure we exclude incomplete registrations, but only if not trashed.
1263
+			if ($view === 'trash') {
1264
+				$where['REG_deleted'] = true;
1265
+			} elseif ($view === 'incomplete') {
1266
+				$where['STS_ID'] = EEM_Registration::status_id_incomplete;
1267
+			} else {
1268
+				$where['STS_ID'] = array('!=', EEM_Registration::status_id_incomplete);
1269
+			}
1270
+		}
1271
+		return $where;
1272
+	}
1273
+
1274
+
1275
+	/**
1276
+	 * Adds any provided date restraints to the where conditions for the registrations query.
1277
+	 *
1278
+	 * @param array $request usually the same as $this->_req_data but not necessarily
1279
+	 * @return array
1280
+	 * @throws EE_Error
1281
+	 * @throws InvalidArgumentException
1282
+	 * @throws InvalidDataTypeException
1283
+	 * @throws InvalidInterfaceException
1284
+	 */
1285
+	protected function _add_date_to_where_conditions(array $request)
1286
+	{
1287
+		$where = array();
1288
+		$view = EEH_Array::is_set($request, 'status', '');
1289
+		$month_range             = ! empty($request['month_range'])
1290
+			? sanitize_text_field($request['month_range'])
1291
+			: '';
1292
+		$retrieve_for_today      = $view === 'today';
1293
+		$retrieve_for_this_month = $view === 'month';
1294
+
1295
+		if ($retrieve_for_today) {
1296
+			$now               = date('Y-m-d', current_time('timestamp'));
1297
+			$where['REG_date'] = array(
1298
+				'BETWEEN',
1299
+				array(
1300
+					EEM_Registration::instance()->convert_datetime_for_query(
1301
+						'REG_date',
1302
+						$now . ' 00:00:00',
1303
+						'Y-m-d H:i:s'
1304
+					),
1305
+					EEM_Registration::instance()->convert_datetime_for_query(
1306
+						'REG_date',
1307
+						$now . ' 23:59:59',
1308
+						'Y-m-d H:i:s'
1309
+					),
1310
+				),
1311
+			);
1312
+		} elseif ($retrieve_for_this_month) {
1313
+			$current_year_and_month = date('Y-m', current_time('timestamp'));
1314
+			$days_this_month        = date('t', current_time('timestamp'));
1315
+			$where['REG_date']      = array(
1316
+				'BETWEEN',
1317
+				array(
1318
+					EEM_Registration::instance()->convert_datetime_for_query(
1319
+						'REG_date',
1320
+						$current_year_and_month . '-01 00:00:00',
1321
+						'Y-m-d H:i:s'
1322
+					),
1323
+					EEM_Registration::instance()->convert_datetime_for_query(
1324
+						'REG_date',
1325
+						$current_year_and_month . '-' . $days_this_month . ' 23:59:59',
1326
+						'Y-m-d H:i:s'
1327
+					),
1328
+				),
1329
+			);
1330
+		} elseif ($month_range) {
1331
+			$pieces          = explode(' ', $month_range, 3);
1332
+			$month_requested = ! empty($pieces[0])
1333
+				? date('m', \EEH_DTT_Helper::first_of_month_timestamp($pieces[0]))
1334
+				: '';
1335
+			$year_requested  = ! empty($pieces[1])
1336
+				? $pieces[1]
1337
+				: '';
1338
+			//if there is not a month or year then we can't go further
1339
+			if ($month_requested && $year_requested) {
1340
+				$days_in_month     = date('t', strtotime($year_requested . '-' . $month_requested . '-' . '01'));
1341
+				$where['REG_date'] = array(
1342
+					'BETWEEN',
1343
+					array(
1344
+						EEM_Registration::instance()->convert_datetime_for_query(
1345
+							'REG_date',
1346
+							$year_requested . '-' . $month_requested . '-01 00:00:00',
1347
+							'Y-m-d H:i:s'
1348
+						),
1349
+						EEM_Registration::instance()->convert_datetime_for_query(
1350
+							'REG_date',
1351
+							$year_requested . '-' . $month_requested . '-' . $days_in_month . ' 23:59:59',
1352
+							'Y-m-d H:i:s'
1353
+						),
1354
+					),
1355
+				);
1356
+			}
1357
+		}
1358
+		return $where;
1359
+	}
1360
+
1361
+
1362
+	/**
1363
+	 * Adds any provided search restraints to the where conditions for the registrations query
1364
+	 *
1365
+	 * @param array $request usually the same as $this->_req_data but not necessarily
1366
+	 * @return array
1367
+	 */
1368
+	protected function _add_search_to_where_conditions(array $request)
1369
+	{
1370
+		$where = array();
1371
+		if (! empty($request['s'])) {
1372
+			$search_string = '%' . sanitize_text_field($request['s']) . '%';
1373
+			$where['OR*search_conditions'] = array(
1374
+				'Event.EVT_name'                          => array('LIKE', $search_string),
1375
+				'Event.EVT_desc'                          => array('LIKE', $search_string),
1376
+				'Event.EVT_short_desc'                    => array('LIKE', $search_string),
1377
+				'Attendee.ATT_full_name'                  => array('LIKE', $search_string),
1378
+				'Attendee.ATT_fname'                      => array('LIKE', $search_string),
1379
+				'Attendee.ATT_lname'                      => array('LIKE', $search_string),
1380
+				'Attendee.ATT_short_bio'                  => array('LIKE', $search_string),
1381
+				'Attendee.ATT_email'                      => array('LIKE', $search_string),
1382
+				'Attendee.ATT_address'                    => array('LIKE', $search_string),
1383
+				'Attendee.ATT_address2'                   => array('LIKE', $search_string),
1384
+				'Attendee.ATT_city'                       => array('LIKE', $search_string),
1385
+				'REG_final_price'                         => array('LIKE', $search_string),
1386
+				'REG_code'                                => array('LIKE', $search_string),
1387
+				'REG_count'                               => array('LIKE', $search_string),
1388
+				'REG_group_size'                          => array('LIKE', $search_string),
1389
+				'Ticket.TKT_name'                         => array('LIKE', $search_string),
1390
+				'Ticket.TKT_description'                  => array('LIKE', $search_string),
1391
+				'Transaction.Payment.PAY_txn_id_chq_nmbr' => array('LIKE', $search_string),
1392
+			);
1393
+		}
1394
+		return $where;
1395
+	}
1396
+
1397
+
1398
+	/**
1399
+	 * Sets up the where conditions for the registrations query.
1400
+	 *
1401
+	 * @param array $request
1402
+	 * @return array
1403
+	 * @throws EE_Error
1404
+	 */
1405
+	protected function _get_where_conditions_for_registrations_query($request)
1406
+	{
1407
+		return apply_filters(
1408
+			'FHEE__Registrations_Admin_Page___get_where_conditions_for_registrations_query',
1409
+			array_merge(
1410
+				$this->_add_event_id_to_where_conditions($request),
1411
+				$this->_add_category_id_to_where_conditions($request),
1412
+				$this->_add_datetime_id_to_where_conditions($request),
1413
+				$this->_add_registration_status_to_where_conditions($request),
1414
+				$this->_add_date_to_where_conditions($request),
1415
+				$this->_add_search_to_where_conditions($request)
1416
+			),
1417
+			$request
1418
+		);
1419
+	}
1420
+
1421
+
1422
+	/**
1423
+	 * Sets up the orderby for the registrations query.
1424
+	 *
1425
+	 * @return array
1426
+	 */
1427
+	protected function _get_orderby_for_registrations_query()
1428
+	{
1429
+		$orderby_field = ! empty($this->_req_data['orderby'])
1430
+			? sanitize_text_field($this->_req_data['orderby'])
1431
+			: '';
1432
+		switch ($orderby_field) {
1433
+			case '_REG_ID':
1434
+				$orderby = array('REG_ID');
1435
+				break;
1436
+			case '_Reg_status':
1437
+				$orderby = array('STS_ID');
1438
+				break;
1439
+			case 'ATT_fname':
1440
+				$orderby = array('Attendee.ATT_fname', 'Attendee.ATT_lname');
1441
+				break;
1442
+			case 'ATT_lname':
1443
+				$orderby = array('Attendee.ATT_lname', 'Attendee.ATT_fname');
1444
+				break;
1445
+			case 'event_name':
1446
+				$orderby = array('Event.EVT_name');
1447
+				break;
1448
+			case 'DTT_EVT_start':
1449
+				$orderby = array('Event.Datetime.DTT_EVT_start');
1450
+				break;
1451
+			default: //'REG_date'
1452
+				$orderby = array('REG_date');
1453
+		}
1454
+
1455
+		//order
1456
+		$order = ! empty($this->_req_data['order'])
1457
+			? sanitize_text_field($this->_req_data['order'])
1458
+			: 'DESC';
1459
+		$orderby = array_combine(
1460
+			$orderby,
1461
+			array_fill(0, count($orderby), $order)
1462
+		);
1463
+		//because there are many registrations with the same date, define
1464
+		//a secondary way to order them, otherwise MySQL seems to be a bit random
1465
+		if (empty($orderby['REG_ID'])) {
1466
+			$orderby['REG_ID'] = $order;
1467
+		}
1468
+		return array('order_by' => $orderby);
1469
+	}
1470
+
1471
+
1472
+	/**
1473
+	 * Sets up the limit for the registrations query.
1474
+	 *
1475
+	 * @param $per_page
1476
+	 * @return array
1477
+	 */
1478
+	protected function _get_limit($per_page)
1479
+	{
1480
+		$current_page = ! empty($this->_req_data['paged'])
1481
+			? absint($this->_req_data['paged'])
1482
+			: 1;
1483
+		$per_page     = ! empty($this->_req_data['perpage'])
1484
+			? $this->_req_data['perpage']
1485
+			: $per_page;
1486
+
1487
+		//-1 means return all results so get out if that's set.
1488
+		if ((int)$per_page === -1) {
1489
+			return array();
1490
+		}
1491
+		$per_page = absint($per_page);
1492
+		$offset   = ($current_page - 1) * $per_page;
1493
+		return array('limit' => array($offset, $per_page));
1494
+	}
1495
+
1496
+
1497
+	public function get_registration_status_array()
1498
+	{
1499
+		return self::$_reg_status;
1500
+	}
1501
+
1502
+
1503
+
1504
+
1505
+	/***************************************        REGISTRATION DETAILS        ***************************************/
1506
+	/**
1507
+	 *        generates HTML for the View Registration Details Admin page
1508
+	 *
1509
+	 * @access protected
1510
+	 * @return void
1511
+	 * @throws DomainException
1512
+	 * @throws EE_Error
1513
+	 * @throws InvalidArgumentException
1514
+	 * @throws InvalidDataTypeException
1515
+	 * @throws InvalidInterfaceException
1516
+	 * @throws EntityNotFoundException
1517
+	 */
1518
+	protected function _registration_details()
1519
+	{
1520
+		$this->_template_args = array();
1521
+		$this->_set_registration_object();
1522
+		if (is_object($this->_registration)) {
1523
+			$transaction                                   = $this->_registration->transaction()
1524
+				? $this->_registration->transaction()
1525
+				: EE_Transaction::new_instance();
1526
+			$this->_session                                = $transaction->session_data();
1527
+			$event_id                                      = $this->_registration->event_ID();
1528
+			$this->_template_args['reg_nmbr']['value']     = $this->_registration->ID();
1529
+			$this->_template_args['reg_nmbr']['label']     = esc_html__('Registration Number', 'event_espresso');
1530
+			$this->_template_args['reg_datetime']['value'] = $this->_registration->get_i18n_datetime('REG_date');
1531
+			$this->_template_args['reg_datetime']['label'] = esc_html__('Date', 'event_espresso');
1532
+			$this->_template_args['grand_total']           = $transaction->total();
1533
+			$this->_template_args['currency_sign']         = EE_Registry::instance()->CFG->currency->sign;
1534
+			// link back to overview
1535
+			$this->_template_args['reg_overview_url']            = REG_ADMIN_URL;
1536
+			$this->_template_args['registration']                = $this->_registration;
1537
+			$this->_template_args['filtered_registrations_link'] = EE_Admin_Page::add_query_args_and_nonce(
1538
+				array(
1539
+					'action'   => 'default',
1540
+					'event_id' => $event_id,
1541
+				),
1542
+				REG_ADMIN_URL
1543
+			);
1544
+			$this->_template_args['filtered_transactions_link']  = EE_Admin_Page::add_query_args_and_nonce(
1545
+				array(
1546
+					'action' => 'default',
1547
+					'EVT_ID' => $event_id,
1548
+					'page'   => 'espresso_transactions',
1549
+				),
1550
+				admin_url('admin.php')
1551
+			);
1552
+			$this->_template_args['event_link']                  = EE_Admin_Page::add_query_args_and_nonce(
1553
+				array(
1554
+					'page'   => 'espresso_events',
1555
+					'action' => 'edit',
1556
+					'post'   => $event_id,
1557
+				),
1558
+				admin_url('admin.php')
1559
+			);
1560
+			//next and previous links
1561
+			$next_reg                                      = $this->_registration->next(
1562
+				null,
1563
+				array(),
1564
+				'REG_ID'
1565
+			);
1566
+			$this->_template_args['next_registration']     = $next_reg
1567
+				? $this->_next_link(
1568
+					EE_Admin_Page::add_query_args_and_nonce(
1569
+						array(
1570
+							'action'  => 'view_registration',
1571
+							'_REG_ID' => $next_reg['REG_ID'],
1572
+						),
1573
+						REG_ADMIN_URL
1574
+					),
1575
+					'dashicons dashicons-arrow-right ee-icon-size-22'
1576
+				)
1577
+				: '';
1578
+			$previous_reg                                  = $this->_registration->previous(
1579
+				null,
1580
+				array(),
1581
+				'REG_ID'
1582
+			);
1583
+			$this->_template_args['previous_registration'] = $previous_reg
1584
+				? $this->_previous_link(
1585
+					EE_Admin_Page::add_query_args_and_nonce(
1586
+						array(
1587
+							'action'  => 'view_registration',
1588
+							'_REG_ID' => $previous_reg['REG_ID'],
1589
+						),
1590
+						REG_ADMIN_URL
1591
+					),
1592
+					'dashicons dashicons-arrow-left ee-icon-size-22'
1593
+				)
1594
+				: '';
1595
+			// grab header
1596
+			$template_path                             = REG_TEMPLATE_PATH . 'reg_admin_details_header.template.php';
1597
+			$this->_template_args['REG_ID']            = $this->_registration->ID();
1598
+			$this->_template_args['admin_page_header'] = EEH_Template::display_template(
1599
+				$template_path,
1600
+				$this->_template_args,
1601
+				true
1602
+			);
1603
+		} else {
1604
+			$this->_template_args['admin_page_header'] = $this->display_espresso_notices();
1605
+		}
1606
+		// the details template wrapper
1607
+		$this->display_admin_page_with_sidebar();
1608
+	}
1609
+
1610
+
1611
+	protected function _registration_details_metaboxes()
1612
+	{
1613
+		do_action('AHEE__Registrations_Admin_Page___registration_details_metabox__start', $this);
1614
+		$this->_set_registration_object();
1615
+		$attendee = $this->_registration instanceof EE_Registration ? $this->_registration->attendee() : null;
1616
+		add_meta_box('edit-reg-status-mbox', esc_html__('Registration Status', 'event_espresso'),
1617
+			array($this, 'set_reg_status_buttons_metabox'), $this->wp_page_slug, 'normal', 'high');
1618
+		add_meta_box('edit-reg-details-mbox', esc_html__('Registration Details', 'event_espresso'),
1619
+			array($this, '_reg_details_meta_box'), $this->wp_page_slug, 'normal', 'high');
1620
+		if ($attendee instanceof EE_Attendee
1621
+			&& EE_Registry::instance()->CAP->current_user_can(
1622
+				'ee_edit_registration',
1623
+				'edit-reg-questions-mbox',
1624
+				$this->_registration->ID()
1625
+			)
1626
+		) {
1627
+			add_meta_box(
1628
+				'edit-reg-questions-mbox',
1629
+				esc_html__('Registration Form Answers', 'event_espresso'),
1630
+				array($this, '_reg_questions_meta_box'),
1631
+				$this->wp_page_slug,
1632
+				'normal',
1633
+				'high'
1634
+			);
1635
+		}
1636
+		add_meta_box(
1637
+			'edit-reg-registrant-mbox',
1638
+			esc_html__('Contact Details', 'event_espresso'),
1639
+			array($this, '_reg_registrant_side_meta_box'),
1640
+			$this->wp_page_slug,
1641
+			'side',
1642
+			'high'
1643
+		);
1644
+		if ($this->_registration->group_size() > 1) {
1645
+			add_meta_box(
1646
+				'edit-reg-attendees-mbox',
1647
+				esc_html__('Other Registrations in this Transaction', 'event_espresso'),
1648
+				array($this, '_reg_attendees_meta_box'),
1649
+				$this->wp_page_slug,
1650
+				'normal',
1651
+				'high'
1652
+			);
1653
+		}
1654
+	}
1655
+
1656
+
1657
+	/**
1658
+	 * set_reg_status_buttons_metabox
1659
+	 *
1660
+	 * @access protected
1661
+	 * @return string
1662
+	 * @throws \EE_Error
1663
+	 */
1664
+	public function set_reg_status_buttons_metabox()
1665
+	{
1666
+		$this->_set_registration_object();
1667
+		$change_reg_status_form = $this->_generate_reg_status_change_form();
1668
+		echo $change_reg_status_form->form_open(
1669
+			self::add_query_args_and_nonce(
1670
+				array(
1671
+					'action' => 'change_reg_status',
1672
+				),
1673
+				REG_ADMIN_URL
1674
+			)
1675
+		);
1676
+		echo $change_reg_status_form->get_html();
1677
+		echo $change_reg_status_form->form_close();
1678
+	}
1679
+
1680
+
1681
+	/**
1682
+	 * @return EE_Form_Section_Proper
1683
+	 * @throws EE_Error
1684
+	 * @throws InvalidArgumentException
1685
+	 * @throws InvalidDataTypeException
1686
+	 * @throws InvalidInterfaceException
1687
+	 * @throws \EventEspresso\core\exceptions\EntityNotFoundException
1688
+	 */
1689
+	protected function _generate_reg_status_change_form()
1690
+	{
1691
+		return new EE_Form_Section_Proper(array(
1692
+			'name'            => 'reg_status_change_form',
1693
+			'html_id'         => 'reg-status-change-form',
1694
+			'layout_strategy' => new EE_Admin_Two_Column_Layout(),
1695
+			'subsections'     => array(
1696
+				'return'             => new EE_Hidden_Input(array(
1697
+					'name'    => 'return',
1698
+					'default' => 'view_registration',
1699
+				)),
1700
+				'REG_ID'             => new EE_Hidden_Input(array(
1701
+					'name'    => 'REG_ID',
1702
+					'default' => $this->_registration->ID(),
1703
+				)),
1704
+				'current_status'     => new EE_Form_Section_HTML(
1705
+					EEH_HTML::tr(
1706
+						EEH_HTML::th(
1707
+							EEH_HTML::label(
1708
+								EEH_HTML::strong(esc_html__('Current Registration Status', 'event_espresso')
1709
+								)
1710
+							)
1711
+						)
1712
+						. EEH_HTML::td(
1713
+							EEH_HTML::strong(
1714
+								$this->_registration->pretty_status(),
1715
+								'',
1716
+								'status-' . $this->_registration->status_ID(),
1717
+								'line-height: 1em; font-size: 1.5em; font-weight: bold;'
1718
+							)
1719
+						)
1720
+					)
1721
+				),
1722
+				'reg_status'         => new EE_Select_Input(
1723
+					$this->_get_reg_statuses(),
1724
+					array(
1725
+						'html_label_text' => esc_html__('Change Registration Status to', 'event_espresso'),
1726
+						'default'         => $this->_registration->status_ID(),
1727
+					)
1728
+				),
1729
+				'send_notifications' => new EE_Yes_No_Input(
1730
+					array(
1731
+						'html_label_text' => esc_html__('Send Related Messages', 'event_espresso'),
1732
+						'default'         => false,
1733
+						'html_help_text'  => esc_html__(
1734
+							'If set to "Yes", then the related messages will be sent to the registrant.',
1735
+							'event_espresso'
1736
+						),
1737
+					)
1738
+				),
1739
+				'submit'             => new EE_Submit_Input(
1740
+					array(
1741
+						'html_class'      => 'button-primary',
1742
+						'html_label_text' => '&nbsp;',
1743
+						'default'         => esc_html__('Update Registration Status', 'event_espresso'),
1744
+					)
1745
+				),
1746
+			),
1747
+		));
1748
+	}
1749
+
1750
+
1751
+	/**
1752
+	 * Returns an array of all the buttons for the various statuses and switch status actions
1753
+	 *
1754
+	 * @return array
1755
+	 * @throws EE_Error
1756
+	 * @throws InvalidArgumentException
1757
+	 * @throws InvalidDataTypeException
1758
+	 * @throws InvalidInterfaceException
1759
+	 * @throws EntityNotFoundException
1760
+	 */
1761
+	protected function _get_reg_statuses()
1762
+	{
1763
+		$reg_status_array = EEM_Registration::instance()->reg_status_array();
1764
+		unset ($reg_status_array[EEM_Registration::status_id_incomplete]);
1765
+		// get current reg status
1766
+		$current_status = $this->_registration->status_ID();
1767
+		// is registration for free event? This will determine whether to display the pending payment option
1768
+		if (
1769
+			$current_status !== EEM_Registration::status_id_pending_payment
1770
+			&& EEH_Money::compare_floats($this->_registration->ticket()->price(), 0.00)
1771
+		) {
1772
+			unset($reg_status_array[EEM_Registration::status_id_pending_payment]);
1773
+		}
1774
+		return EEM_Status::instance()->localized_status($reg_status_array, false, 'sentence');
1775
+	}
1776
+
1777
+
1778
+	/**
1779
+	 * This method is used when using _REG_ID from request which may or may not be an array of reg_ids.
1780
+	 *
1781
+	 * @param bool $status REG status given for changing registrations to.
1782
+	 * @param bool $notify Whether to send messages notifications or not.
1783
+	 * @return array (array with reg_id(s) updated and whether update was successful.
1784
+	 * @throws EE_Error
1785
+	 * @throws InvalidArgumentException
1786
+	 * @throws InvalidDataTypeException
1787
+	 * @throws InvalidInterfaceException
1788
+	 * @throws ReflectionException
1789
+	 * @throws RuntimeException
1790
+	 * @throws EntityNotFoundException
1791
+	 */
1792
+	protected function _set_registration_status_from_request($status = false, $notify = false)
1793
+	{
1794
+		if (isset($this->_req_data['reg_status_change_form'])) {
1795
+			$REG_IDs = isset($this->_req_data['reg_status_change_form']['REG_ID'])
1796
+				? (array)$this->_req_data['reg_status_change_form']['REG_ID']
1797
+				: array();
1798
+		} else {
1799
+			$REG_IDs = isset($this->_req_data['_REG_ID'])
1800
+				? (array)$this->_req_data['_REG_ID']
1801
+				: array();
1802
+		}
1803
+		// sanitize $REG_IDs
1804
+		$REG_IDs = array_map('absint', $REG_IDs);
1805
+		// and remove empty entries
1806
+		$REG_IDs = array_filter($REG_IDs);
1807
+
1808
+		$result = $this->_set_registration_status($REG_IDs, $status, $notify);
1809
+
1810
+		/**
1811
+		 * Set and filter $_req_data['_REG_ID'] for any potential future messages notifications.
1812
+		 * Currently this value is used downstream by the _process_resend_registration method.
1813
+		 *
1814
+		 * @param int|array                $registration_ids The registration ids that have had their status changed successfully.
1815
+		 * @param bool                     $status           The status registrations were changed to.
1816
+		 * @param bool                     $success          If the status was changed successfully for all registrations.
1817
+		 * @param Registrations_Admin_Page $admin_page_object
1818
+		 */
1819
+		$this->_req_data['_REG_ID'] = apply_filters(
1820
+			'FHEE__Registrations_Admin_Page___set_registration_status_from_request__REG_IDs',
1821
+			$result['REG_ID'],
1822
+			$status,
1823
+			$result['success'],
1824
+			$this
1825
+		);
1826
+
1827
+		//notify?
1828
+		if ($notify
1829
+			&& $result['success']
1830
+			&& ! empty($this->_req_data['_REG_ID'])
1831
+			&& EE_Registry::instance()->CAP->current_user_can(
1832
+				'ee_send_message',
1833
+				'espresso_registrations_resend_registration'
1834
+			)
1835
+		) {
1836
+			$this->_process_resend_registration();
1837
+		}
1838
+		return $result;
1839
+	}
1840
+
1841
+
1842
+	/**
1843
+	 * Set the registration status for the given reg_id (which may or may not be an array, it gets typecast to an
1844
+	 * array). Note, this method does NOT take care of possible notifications.  That is required by calling code.
1845
+	 *
1846
+	 * @param array  $REG_IDs
1847
+	 * @param string $status
1848
+	 * @param bool   $notify  Used to indicate whether notification was requested or not.  This determines the context
1849
+	 *                        slug sent with setting the registration status.
1850
+	 * @return array (an array with 'success' key representing whether status change was successful, and 'REG_ID' as
1851
+	 * @throws EE_Error
1852
+	 * @throws InvalidArgumentException
1853
+	 * @throws InvalidDataTypeException
1854
+	 * @throws InvalidInterfaceException
1855
+	 * @throws ReflectionException
1856
+	 * @throws RuntimeException
1857
+	 * @throws EntityNotFoundException
1858
+	 */
1859
+	protected function _set_registration_status($REG_IDs = array(), $status = '', $notify = false)
1860
+	{
1861
+		$success = false;
1862
+		// typecast $REG_IDs
1863
+		$REG_IDs = (array)$REG_IDs;
1864
+		if ( ! empty($REG_IDs)) {
1865
+			$success = true;
1866
+			// set default status if none is passed
1867
+			$status = $status ? $status : EEM_Registration::status_id_pending_payment;
1868
+			$status_context = $notify
1869
+				? Domain::CONTEXT_REGISTRATION_STATUS_CHANGE_REGISTRATION_ADMIN_NOTIFY
1870
+				: Domain::CONTEXT_REGISTRATION_STATUS_CHANGE_REGISTRATION_ADMIN;
1871
+			//loop through REG_ID's and change status
1872
+			foreach ($REG_IDs as $REG_ID) {
1873
+				$registration = EEM_Registration::instance()->get_one_by_ID($REG_ID);
1874
+				if ($registration instanceof EE_Registration) {
1875
+					$registration->set_status(
1876
+						$status,
1877
+						false,
1878
+						new Context(
1879
+							$status_context,
1880
+							esc_html__(
1881
+								'Manually triggered status change on a Registration Admin Page route.',
1882
+								'event_espresso'
1883
+							)
1884
+						)
1885
+					);
1886
+					$result = $registration->save();
1887
+					// verifying explicit fails because update *may* just return 0 for 0 rows affected
1888
+					$success = $result !== false ? $success : false;
1889
+				}
1890
+			}
1891
+		}
1892
+
1893
+		//return $success and processed registrations
1894
+		return array('REG_ID' => $REG_IDs, 'success' => $success);
1895
+	}
1896
+
1897
+
1898
+	/**
1899
+	 * Common logic for setting up success message and redirecting to appropriate route
1900
+	 *
1901
+	 * @param  string $STS_ID status id for the registration changed to
1902
+	 * @param   bool  $notify indicates whether the _set_registration_status_from_request does notifications or not.
1903
+	 * @return void
1904
+	 * @throws EE_Error
1905
+	 */
1906
+	protected function _reg_status_change_return($STS_ID, $notify = false)
1907
+	{
1908
+		$result  = ! empty($STS_ID) ? $this->_set_registration_status_from_request($STS_ID, $notify)
1909
+			: array('success' => false);
1910
+		$success = isset($result['success']) && $result['success'];
1911
+		//setup success message
1912
+		if ($success) {
1913
+			if (is_array($result['REG_ID']) && count($result['REG_ID']) === 1) {
1914
+				$msg = sprintf(esc_html__('Registration status has been set to %s', 'event_espresso'),
1915
+					EEH_Template::pretty_status($STS_ID, false, 'lower'));
1916
+			} else {
1917
+				$msg = sprintf(esc_html__('Registrations have been set to %s.', 'event_espresso'),
1918
+					EEH_Template::pretty_status($STS_ID, false, 'lower'));
1919
+			}
1920
+			EE_Error::add_success($msg);
1921
+		} else {
1922
+			EE_Error::add_error(
1923
+				esc_html__(
1924
+					'Something went wrong, and the status was not changed',
1925
+					'event_espresso'
1926
+				), __FILE__, __LINE__, __FUNCTION__
1927
+			);
1928
+		}
1929
+		if (isset($this->_req_data['return']) && $this->_req_data['return'] == 'view_registration') {
1930
+			$route = array('action' => 'view_registration', '_REG_ID' => reset($result['REG_ID']));
1931
+		} else {
1932
+			$route = array('action' => 'default');
1933
+		}
1934
+		//unset nonces
1935
+		foreach ($this->_req_data as $ref => $value) {
1936
+			if (strpos($ref, 'nonce') !== false) {
1937
+				unset($this->_req_data[$ref]);
1938
+				continue;
1939
+			}
1940
+			$value                 = is_array($value) ? array_map('urlencode', $value) : urlencode($value);
1941
+			$this->_req_data[$ref] = $value;
1942
+		}
1943
+		//merge request vars so that the reloaded list table contains any existing filter query params
1944
+		$route = array_merge($this->_req_data, $route);
1945
+		$this->_redirect_after_action($success, '', '', $route, true);
1946
+	}
1947
+
1948
+
1949
+	/**
1950
+	 * incoming reg status change from reg details page.
1951
+	 *
1952
+	 * @return void
1953
+	 */
1954
+	protected function _change_reg_status()
1955
+	{
1956
+		$this->_req_data['return'] = 'view_registration';
1957
+		//set notify based on whether the send notifications toggle is set or not
1958
+		$notify = ! empty($this->_req_data['reg_status_change_form']['send_notifications']);
1959
+		//$notify = ! empty( $this->_req_data['txn_reg_status_change']['send_notifications'] );
1960
+		$this->_req_data['reg_status_change_form']['reg_status'] = isset($this->_req_data['reg_status_change_form']['reg_status'])
1961
+			? $this->_req_data['reg_status_change_form']['reg_status'] : '';
1962
+		switch ($this->_req_data['reg_status_change_form']['reg_status']) {
1963
+			case EEM_Registration::status_id_approved :
1964
+			case EEH_Template::pretty_status(EEM_Registration::status_id_approved, false, 'sentence') :
1965
+				$this->approve_registration($notify);
1966
+				break;
1967
+			case EEM_Registration::status_id_pending_payment :
1968
+			case EEH_Template::pretty_status(EEM_Registration::status_id_pending_payment, false, 'sentence') :
1969
+				$this->pending_registration($notify);
1970
+				break;
1971
+			case EEM_Registration::status_id_not_approved :
1972
+			case EEH_Template::pretty_status(EEM_Registration::status_id_not_approved, false, 'sentence') :
1973
+				$this->not_approve_registration($notify);
1974
+				break;
1975
+			case EEM_Registration::status_id_declined :
1976
+			case EEH_Template::pretty_status(EEM_Registration::status_id_declined, false, 'sentence') :
1977
+				$this->decline_registration($notify);
1978
+				break;
1979
+			case EEM_Registration::status_id_cancelled :
1980
+			case EEH_Template::pretty_status(EEM_Registration::status_id_cancelled, false, 'sentence') :
1981
+				$this->cancel_registration($notify);
1982
+				break;
1983
+			case EEM_Registration::status_id_wait_list :
1984
+			case EEH_Template::pretty_status(EEM_Registration::status_id_wait_list, false, 'sentence') :
1985
+				$this->wait_list_registration($notify);
1986
+				break;
1987
+			case EEM_Registration::status_id_incomplete :
1988
+			default :
1989
+				$result['success'] = false;
1990
+				unset($this->_req_data['return']);
1991
+				$this->_reg_status_change_return('', false);
1992
+				break;
1993
+		}
1994
+	}
1995
+
1996
+
1997
+	/**
1998
+	 * Callback for bulk action routes.
1999
+	 * Note: although we could just register the singular route callbacks for each bulk action route as well, this
2000
+	 * method was chosen so there is one central place all the registration status bulk actions are going through.
2001
+	 * Potentially, this provides an easier place to locate logic that is specific to these bulk actions (as opposed to
2002
+	 * when an action is happening on just a single registration).
2003
+	 * @param      $action
2004
+	 * @param bool $notify
2005
+	 */
2006
+	protected function bulk_action_on_registrations($action, $notify = false) {
2007
+		do_action(
2008
+			'AHEE__Registrations_Admin_Page__bulk_action_on_registrations__before_execution',
2009
+			$this,
2010
+			$action,
2011
+			$notify
2012
+		);
2013
+		$method = $action . '_registration';
2014
+		if (method_exists($this, $method)) {
2015
+			$this->$method($notify);
2016
+		}
2017
+	}
2018
+
2019
+
2020
+	/**
2021
+	 * approve_registration
2022
+	 *
2023
+	 * @access protected
2024
+	 * @param bool $notify whether or not to notify the registrant about their approval.
2025
+	 * @return void
2026
+	 */
2027
+	protected function approve_registration($notify = false)
2028
+	{
2029
+		$this->_reg_status_change_return(EEM_Registration::status_id_approved, $notify);
2030
+	}
2031
+
2032
+
2033
+	/**
2034
+	 *        decline_registration
2035
+	 *
2036
+	 * @access protected
2037
+	 * @param bool $notify whether or not to notify the registrant about their status change.
2038
+	 * @return void
2039
+	 */
2040
+	protected function decline_registration($notify = false)
2041
+	{
2042
+		$this->_reg_status_change_return(EEM_Registration::status_id_declined, $notify);
2043
+	}
2044
+
2045
+
2046
+	/**
2047
+	 *        cancel_registration
2048
+	 *
2049
+	 * @access protected
2050
+	 * @param bool $notify whether or not to notify the registrant about their status change.
2051
+	 * @return void
2052
+	 */
2053
+	protected function cancel_registration($notify = false)
2054
+	{
2055
+		$this->_reg_status_change_return(EEM_Registration::status_id_cancelled, $notify);
2056
+	}
2057
+
2058
+
2059
+	/**
2060
+	 *        not_approve_registration
2061
+	 *
2062
+	 * @access protected
2063
+	 * @param bool $notify whether or not to notify the registrant about their status change.
2064
+	 * @return void
2065
+	 */
2066
+	protected function not_approve_registration($notify = false)
2067
+	{
2068
+		$this->_reg_status_change_return(EEM_Registration::status_id_not_approved, $notify);
2069
+	}
2070
+
2071
+
2072
+	/**
2073
+	 *        decline_registration
2074
+	 *
2075
+	 * @access protected
2076
+	 * @param bool $notify whether or not to notify the registrant about their status change.
2077
+	 * @return void
2078
+	 */
2079
+	protected function pending_registration($notify = false)
2080
+	{
2081
+		$this->_reg_status_change_return(EEM_Registration::status_id_pending_payment, $notify);
2082
+	}
2083
+
2084
+
2085
+	/**
2086
+	 * waitlist_registration
2087
+	 *
2088
+	 * @access protected
2089
+	 * @param bool $notify whether or not to notify the registrant about their status change.
2090
+	 * @return void
2091
+	 */
2092
+	protected function wait_list_registration($notify = false)
2093
+	{
2094
+		$this->_reg_status_change_return(EEM_Registration::status_id_wait_list, $notify);
2095
+	}
2096
+
2097
+
2098
+	/**
2099
+	 *        generates HTML for the Registration main meta box
2100
+	 *
2101
+	 * @access public
2102
+	 * @return void
2103
+	 * @throws DomainException
2104
+	 * @throws EE_Error
2105
+	 * @throws InvalidArgumentException
2106
+	 * @throws InvalidDataTypeException
2107
+	 * @throws InvalidInterfaceException
2108
+	 * @throws ReflectionException
2109
+	 * @throws EntityNotFoundException
2110
+	 */
2111
+	public function _reg_details_meta_box()
2112
+	{
2113
+		EEH_Autoloader::register_line_item_display_autoloaders();
2114
+		EEH_Autoloader::register_line_item_filter_autoloaders();
2115
+		EE_Registry::instance()->load_helper('Line_Item');
2116
+		$transaction    = $this->_registration->transaction() ? $this->_registration->transaction()
2117
+			: EE_Transaction::new_instance();
2118
+		$this->_session = $transaction->session_data();
2119
+		$filters        = new EE_Line_Item_Filter_Collection();
2120
+		//$filters->add( new EE_Non_Zero_Line_Item_Filter() );
2121
+		$filters->add(new EE_Single_Registration_Line_Item_Filter($this->_registration));
2122
+		$line_item_filter_processor              = new EE_Line_Item_Filter_Processor($filters,
2123
+			$transaction->total_line_item());
2124
+		$filtered_line_item_tree                 = $line_item_filter_processor->process();
2125
+		$line_item_display                       = new EE_Line_Item_Display('reg_admin_table',
2126
+			'EE_Admin_Table_Registration_Line_Item_Display_Strategy');
2127
+		$this->_template_args['line_item_table'] = $line_item_display->display_line_item(
2128
+			$filtered_line_item_tree,
2129
+			array('EE_Registration' => $this->_registration)
2130
+		);
2131
+		$attendee                                = $this->_registration->attendee();
2132
+		if (EE_Registry::instance()->CAP->current_user_can(
2133
+			'ee_read_transaction',
2134
+			'espresso_transactions_view_transaction'
2135
+		)) {
2136
+			$this->_template_args['view_transaction_button'] = EEH_Template::get_button_or_link(
2137
+				EE_Admin_Page::add_query_args_and_nonce(
2138
+					array(
2139
+						'action' => 'view_transaction',
2140
+						'TXN_ID' => $transaction->ID(),
2141
+					),
2142
+					TXN_ADMIN_URL
2143
+				),
2144
+				esc_html__(' View Transaction', 'event_espresso'),
2145
+				'button secondary-button right',
2146
+				'dashicons dashicons-cart'
2147
+			);
2148
+		} else {
2149
+			$this->_template_args['view_transaction_button'] = '';
2150
+		}
2151
+		if ($attendee instanceof EE_Attendee
2152
+			&& EE_Registry::instance()->CAP->current_user_can(
2153
+				'ee_send_message',
2154
+				'espresso_registrations_resend_registration'
2155
+			)
2156
+		) {
2157
+			$this->_template_args['resend_registration_button'] = EEH_Template::get_button_or_link(
2158
+				EE_Admin_Page::add_query_args_and_nonce(
2159
+					array(
2160
+						'action'      => 'resend_registration',
2161
+						'_REG_ID'     => $this->_registration->ID(),
2162
+						'redirect_to' => 'view_registration',
2163
+					),
2164
+					REG_ADMIN_URL
2165
+				),
2166
+				esc_html__(' Resend Registration', 'event_espresso'),
2167
+				'button secondary-button right',
2168
+				'dashicons dashicons-email-alt'
2169
+			);
2170
+		} else {
2171
+			$this->_template_args['resend_registration_button'] = '';
2172
+		}
2173
+		$this->_template_args['currency_sign'] = EE_Registry::instance()->CFG->currency->sign;
2174
+		$payment                               = $transaction->get_first_related('Payment');
2175
+		$payment                               = ! $payment instanceof EE_Payment
2176
+			? EE_Payment::new_instance()
2177
+			: $payment;
2178
+		$payment_method                        = $payment->get_first_related('Payment_Method');
2179
+		$payment_method                        = ! $payment_method instanceof EE_Payment_Method
2180
+			? EE_Payment_Method::new_instance()
2181
+			: $payment_method;
2182
+		$reg_details                           = array(
2183
+			'payment_method'       => $payment_method->name(),
2184
+			'response_msg'         => $payment->gateway_response(),
2185
+			'registration_id'      => $this->_registration->get('REG_code'),
2186
+			'registration_session' => $this->_registration->session_ID(),
2187
+			'ip_address'           => isset($this->_session['ip_address']) ? $this->_session['ip_address'] : '',
2188
+			'user_agent'           => isset($this->_session['user_agent']) ? $this->_session['user_agent'] : '',
2189
+		);
2190
+		if (isset($reg_details['registration_id'])) {
2191
+			$this->_template_args['reg_details']['registration_id']['value'] = $reg_details['registration_id'];
2192
+			$this->_template_args['reg_details']['registration_id']['label'] = esc_html__(
2193
+				'Registration ID',
2194
+				'event_espresso'
2195
+			);
2196
+			$this->_template_args['reg_details']['registration_id']['class'] = 'regular-text';
2197
+		}
2198
+		if (isset($reg_details['payment_method'])) {
2199
+			$this->_template_args['reg_details']['payment_method']['value'] = $reg_details['payment_method'];
2200
+			$this->_template_args['reg_details']['payment_method']['label'] = esc_html__(
2201
+				'Most Recent Payment Method',
2202
+				'event_espresso'
2203
+			);
2204
+			$this->_template_args['reg_details']['payment_method']['class'] = 'regular-text';
2205
+			$this->_template_args['reg_details']['response_msg']['value']   = $reg_details['response_msg'];
2206
+			$this->_template_args['reg_details']['response_msg']['label']   = esc_html__(
2207
+				'Payment method response',
2208
+				'event_espresso'
2209
+			);
2210
+			$this->_template_args['reg_details']['response_msg']['class']   = 'regular-text';
2211
+		}
2212
+		$this->_template_args['reg_details']['registration_session']['value'] = $reg_details['registration_session'];
2213
+		$this->_template_args['reg_details']['registration_session']['label'] = esc_html__(
2214
+			'Registration Session',
2215
+			'event_espresso'
2216
+		);
2217
+		$this->_template_args['reg_details']['registration_session']['class'] = 'regular-text';
2218
+		$this->_template_args['reg_details']['ip_address']['value']           = $reg_details['ip_address'];
2219
+		$this->_template_args['reg_details']['ip_address']['label']           = esc_html__(
2220
+			'Registration placed from IP',
2221
+			'event_espresso'
2222
+		);
2223
+		$this->_template_args['reg_details']['ip_address']['class']           = 'regular-text';
2224
+		$this->_template_args['reg_details']['user_agent']['value']           = $reg_details['user_agent'];
2225
+		$this->_template_args['reg_details']['user_agent']['label']           = esc_html__('Registrant User Agent',
2226
+			'event_espresso');
2227
+		$this->_template_args['reg_details']['user_agent']['class']           = 'large-text';
2228
+		$this->_template_args['event_link']                                   = EE_Admin_Page::add_query_args_and_nonce(
2229
+			array(
2230
+				'action'   => 'default',
2231
+				'event_id' => $this->_registration->event_ID(),
2232
+			),
2233
+			REG_ADMIN_URL
2234
+		);
2235
+		$this->_template_args['REG_ID']                                       = $this->_registration->ID();
2236
+		$this->_template_args['event_id']                                     = $this->_registration->event_ID();
2237
+		$template_path                                                        =
2238
+			REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_reg_details.template.php';
2239
+		echo EEH_Template::display_template($template_path, $this->_template_args, true);
2240
+	}
2241
+
2242
+
2243
+	/**
2244
+	 * generates HTML for the Registration Questions meta box.
2245
+	 * If pre-4.8.32.rc.000 hooks are used, uses old methods (with its filters),
2246
+	 * otherwise uses new forms system
2247
+	 *
2248
+	 * @access public
2249
+	 * @return void
2250
+	 * @throws DomainException
2251
+	 * @throws EE_Error
2252
+	 */
2253
+	public function _reg_questions_meta_box()
2254
+	{
2255
+		//allow someone to override this method entirely
2256
+		if (apply_filters('FHEE__Registrations_Admin_Page___reg_questions_meta_box__do_default', true, $this,
2257
+			$this->_registration)) {
2258
+			$form                                              = $this->_get_reg_custom_questions_form(
2259
+				$this->_registration->ID()
2260
+			);
2261
+			$this->_template_args['att_questions']             = count($form->subforms()) > 0
2262
+				? $form->get_html_and_js()
2263
+				: '';
2264
+			$this->_template_args['reg_questions_form_action'] = 'edit_registration';
2265
+			$this->_template_args['REG_ID']                    = $this->_registration->ID();
2266
+			$template_path                                     =
2267
+				REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_reg_questions.template.php';
2268
+			echo EEH_Template::display_template($template_path, $this->_template_args, true);
2269
+		}
2270
+	}
2271
+
2272
+
2273
+	/**
2274
+	 * form_before_question_group
2275
+	 *
2276
+	 * @deprecated    as of 4.8.32.rc.000
2277
+	 * @access        public
2278
+	 * @param        string $output
2279
+	 * @return        string
2280
+	 */
2281
+	public function form_before_question_group($output)
2282
+	{
2283
+		EE_Error::doing_it_wrong(
2284
+			__CLASS__ . '::' . __FUNCTION__,
2285
+			esc_html__(
2286
+				'This method would have been protected but was used on a filter callback so needed to be public. Please discontinue usage as it will be removed soon.',
2287
+				'event_espresso'
2288
+			),
2289
+			'4.8.32.rc.000'
2290
+		);
2291
+		return '
2292 2292
 	<table class="form-table ee-width-100">
2293 2293
 		<tbody>
2294 2294
 			';
2295
-    }
2296
-
2297
-
2298
-    /**
2299
-     * form_after_question_group
2300
-     *
2301
-     * @deprecated    as of 4.8.32.rc.000
2302
-     * @access        public
2303
-     * @param        string $output
2304
-     * @return        string
2305
-     */
2306
-    public function form_after_question_group($output)
2307
-    {
2308
-        EE_Error::doing_it_wrong(
2309
-            __CLASS__ . '::' . __FUNCTION__,
2310
-            esc_html__(
2311
-                'This method would have been protected but was used on a filter callback so needed to be public. Please discontinue usage as it will be removed soon.',
2312
-                'event_espresso'
2313
-            ),
2314
-            '4.8.32.rc.000'
2315
-        );
2316
-        return '
2295
+	}
2296
+
2297
+
2298
+	/**
2299
+	 * form_after_question_group
2300
+	 *
2301
+	 * @deprecated    as of 4.8.32.rc.000
2302
+	 * @access        public
2303
+	 * @param        string $output
2304
+	 * @return        string
2305
+	 */
2306
+	public function form_after_question_group($output)
2307
+	{
2308
+		EE_Error::doing_it_wrong(
2309
+			__CLASS__ . '::' . __FUNCTION__,
2310
+			esc_html__(
2311
+				'This method would have been protected but was used on a filter callback so needed to be public. Please discontinue usage as it will be removed soon.',
2312
+				'event_espresso'
2313
+			),
2314
+			'4.8.32.rc.000'
2315
+		);
2316
+		return '
2317 2317
 			<tr class="hide-if-no-js">
2318 2318
 				<th> </th>
2319 2319
 				<td class="reg-admin-edit-attendee-question-td">
2320 2320
 					<a class="reg-admin-edit-attendee-question-lnk" href="#" title="'
2321
-               . esc_attr__('click to edit question', 'event_espresso')
2322
-               . '">
2321
+			   . esc_attr__('click to edit question', 'event_espresso')
2322
+			   . '">
2323 2323
 						<span class="reg-admin-edit-question-group-spn lt-grey-txt">'
2324
-               . esc_html__('edit the above question group', 'event_espresso')
2325
-               . '</span>
2324
+			   . esc_html__('edit the above question group', 'event_espresso')
2325
+			   . '</span>
2326 2326
 						<div class="dashicons dashicons-edit"></div>
2327 2327
 					</a>
2328 2328
 				</td>
@@ -2330,579 +2330,579 @@  discard block
 block discarded – undo
2330 2330
 		</tbody>
2331 2331
 	</table>
2332 2332
 ';
2333
-    }
2334
-
2335
-
2336
-    /**
2337
-     * form_form_field_label_wrap
2338
-     *
2339
-     * @deprecated    as of 4.8.32.rc.000
2340
-     * @access        public
2341
-     * @param        string $label
2342
-     * @return        string
2343
-     */
2344
-    public function form_form_field_label_wrap($label)
2345
-    {
2346
-        EE_Error::doing_it_wrong(
2347
-            __CLASS__ . '::' . __FUNCTION__,
2348
-            esc_html__(
2349
-                'This method would have been protected but was used on a filter callback so needed to be public. Please discontinue usage as it will be removed soon.',
2350
-                'event_espresso'
2351
-            ),
2352
-            '4.8.32.rc.000'
2353
-        );
2354
-        return '
2333
+	}
2334
+
2335
+
2336
+	/**
2337
+	 * form_form_field_label_wrap
2338
+	 *
2339
+	 * @deprecated    as of 4.8.32.rc.000
2340
+	 * @access        public
2341
+	 * @param        string $label
2342
+	 * @return        string
2343
+	 */
2344
+	public function form_form_field_label_wrap($label)
2345
+	{
2346
+		EE_Error::doing_it_wrong(
2347
+			__CLASS__ . '::' . __FUNCTION__,
2348
+			esc_html__(
2349
+				'This method would have been protected but was used on a filter callback so needed to be public. Please discontinue usage as it will be removed soon.',
2350
+				'event_espresso'
2351
+			),
2352
+			'4.8.32.rc.000'
2353
+		);
2354
+		return '
2355 2355
 			<tr>
2356 2356
 				<th>
2357 2357
 					' . $label . '
2358 2358
 				</th>';
2359
-    }
2360
-
2361
-
2362
-    /**
2363
-     * form_form_field_input__wrap
2364
-     *
2365
-     * @deprecated    as of 4.8.32.rc.000
2366
-     * @access        public
2367
-     * @param        string $input
2368
-     * @return        string
2369
-     */
2370
-    public function form_form_field_input__wrap($input)
2371
-    {
2372
-        EE_Error::doing_it_wrong(
2373
-            __CLASS__ . '::' . __FUNCTION__,
2374
-            esc_html__(
2375
-                'This method would have been protected but was used on a filter callback so needed to be public. Please discontinue usage as it will be removed soon.',
2376
-                'event_espresso'
2377
-            ),
2378
-            '4.8.32.rc.000'
2379
-        );
2380
-        return '
2359
+	}
2360
+
2361
+
2362
+	/**
2363
+	 * form_form_field_input__wrap
2364
+	 *
2365
+	 * @deprecated    as of 4.8.32.rc.000
2366
+	 * @access        public
2367
+	 * @param        string $input
2368
+	 * @return        string
2369
+	 */
2370
+	public function form_form_field_input__wrap($input)
2371
+	{
2372
+		EE_Error::doing_it_wrong(
2373
+			__CLASS__ . '::' . __FUNCTION__,
2374
+			esc_html__(
2375
+				'This method would have been protected but was used on a filter callback so needed to be public. Please discontinue usage as it will be removed soon.',
2376
+				'event_espresso'
2377
+			),
2378
+			'4.8.32.rc.000'
2379
+		);
2380
+		return '
2381 2381
 				<td class="reg-admin-attendee-questions-input-td disabled-input">
2382 2382
 					' . $input . '
2383 2383
 				</td>
2384 2384
 			</tr>';
2385
-    }
2386
-
2387
-
2388
-    /**
2389
-     * Updates the registration's custom questions according to the form info, if the form is submitted.
2390
-     * If it's not a post, the "view_registrations" route will be called next on the SAME request
2391
-     * to display the page
2392
-     *
2393
-     * @access protected
2394
-     * @return void
2395
-     * @throws EE_Error
2396
-     */
2397
-    protected function _update_attendee_registration_form()
2398
-    {
2399
-        do_action('AHEE__Registrations_Admin_Page___update_attendee_registration_form__start', $this);
2400
-        if ($_SERVER['REQUEST_METHOD'] == 'POST') {
2401
-            $REG_ID  = isset($this->_req_data['_REG_ID']) ? absint($this->_req_data['_REG_ID']) : false;
2402
-            $success = $this->_save_reg_custom_questions_form($REG_ID);
2403
-            if ($success) {
2404
-                $what  = esc_html__('Registration Form', 'event_espresso');
2405
-                $route = $REG_ID ? array('action' => 'view_registration', '_REG_ID' => $REG_ID)
2406
-                    : array('action' => 'default');
2407
-                $this->_redirect_after_action($success, $what, esc_html__('updated', 'event_espresso'), $route);
2408
-            }
2409
-        }
2410
-    }
2411
-
2412
-
2413
-    /**
2414
-     * Gets the form for saving registrations custom questions (if done
2415
-     * previously retrieves the cached form object, which may have validation errors in it)
2416
-     *
2417
-     * @param int $REG_ID
2418
-     * @return EE_Registration_Custom_Questions_Form
2419
-     * @throws EE_Error
2420
-     * @throws InvalidArgumentException
2421
-     * @throws InvalidDataTypeException
2422
-     * @throws InvalidInterfaceException
2423
-     */
2424
-    protected function _get_reg_custom_questions_form($REG_ID)
2425
-    {
2426
-        if ( ! $this->_reg_custom_questions_form) {
2427
-            require_once(REG_ADMIN . 'form_sections' . DS . 'EE_Registration_Custom_Questions_Form.form.php');
2428
-            $this->_reg_custom_questions_form = new EE_Registration_Custom_Questions_Form(
2429
-                EEM_Registration::instance()->get_one_by_ID($REG_ID)
2430
-            );
2431
-            $this->_reg_custom_questions_form->_construct_finalize(null, null);
2432
-        }
2433
-        return $this->_reg_custom_questions_form;
2434
-    }
2435
-
2436
-
2437
-    /**
2438
-     * Saves
2439
-     *
2440
-     * @access private
2441
-     * @param bool $REG_ID
2442
-     * @return bool
2443
-     * @throws EE_Error
2444
-     * @throws InvalidArgumentException
2445
-     * @throws InvalidDataTypeException
2446
-     * @throws InvalidInterfaceException
2447
-     */
2448
-    private function _save_reg_custom_questions_form($REG_ID = false)
2449
-    {
2450
-        if ( ! $REG_ID) {
2451
-            EE_Error::add_error(
2452
-                esc_html__(
2453
-                    'An error occurred. No registration ID was received.', 'event_espresso'),
2454
-                __FILE__, __FUNCTION__, __LINE__
2455
-            );
2456
-        }
2457
-        $form = $this->_get_reg_custom_questions_form($REG_ID);
2458
-        $form->receive_form_submission($this->_req_data);
2459
-        $success = false;
2460
-        if ($form->is_valid()) {
2461
-            foreach ($form->subforms() as $question_group_id => $question_group_form) {
2462
-                foreach ($question_group_form->inputs() as $question_id => $input) {
2463
-                    $where_conditions    = array(
2464
-                        'QST_ID' => $question_id,
2465
-                        'REG_ID' => $REG_ID,
2466
-                    );
2467
-                    $possibly_new_values = array(
2468
-                        'ANS_value' => $input->normalized_value(),
2469
-                    );
2470
-                    $answer              = EEM_Answer::instance()->get_one(array($where_conditions));
2471
-                    if ($answer instanceof EE_Answer) {
2472
-                        $success = $answer->save($possibly_new_values);
2473
-                    } else {
2474
-                        //insert it then
2475
-                        $cols_n_vals = array_merge($where_conditions, $possibly_new_values);
2476
-                        $answer      = EE_Answer::new_instance($cols_n_vals);
2477
-                        $success     = $answer->save();
2478
-                    }
2479
-                }
2480
-            }
2481
-        } else {
2482
-            EE_Error::add_error($form->get_validation_error_string(), __FILE__, __FUNCTION__, __LINE__);
2483
-        }
2484
-        return $success;
2485
-    }
2486
-
2487
-
2488
-    /**
2489
-     *        generates HTML for the Registration main meta box
2490
-     *
2491
-     * @access public
2492
-     * @return void
2493
-     * @throws DomainException
2494
-     * @throws EE_Error
2495
-     * @throws InvalidArgumentException
2496
-     * @throws InvalidDataTypeException
2497
-     * @throws InvalidInterfaceException
2498
-     */
2499
-    public function _reg_attendees_meta_box()
2500
-    {
2501
-        $REG = EEM_Registration::instance();
2502
-        //get all other registrations on this transaction, and cache
2503
-        //the attendees for them so we don't have to run another query using force_join
2504
-        $registrations                           = $REG->get_all(array(
2505
-            array(
2506
-                'TXN_ID' => $this->_registration->transaction_ID(),
2507
-                'REG_ID' => array('!=', $this->_registration->ID()),
2508
-            ),
2509
-            'force_join' => array('Attendee'),
2510
-        ));
2511
-        $this->_template_args['attendees']       = array();
2512
-        $this->_template_args['attendee_notice'] = '';
2513
-        if (empty($registrations)
2514
-            || (is_array($registrations)
2515
-                && ! EEH_Array::get_one_item_from_array($registrations))
2516
-        ) {
2517
-            EE_Error::add_error(
2518
-                esc_html__(
2519
-                    'There are no records attached to this registration. Something may have gone wrong with the registration',
2520
-                    'event_espresso'
2521
-                ), __FILE__, __FUNCTION__, __LINE__
2522
-            );
2523
-            $this->_template_args['attendee_notice'] = EE_Error::get_notices();
2524
-        } else {
2525
-            $att_nmbr = 1;
2526
-            foreach ($registrations as $registration) {
2527
-                /* @var $registration EE_Registration */
2528
-                $attendee                                                    = $registration->attendee()
2529
-                    ? $registration->attendee()
2530
-                    : EEM_Attendee::instance()
2531
-                                  ->create_default_object();
2532
-                $this->_template_args['attendees'][$att_nmbr]['STS_ID']      = $registration->status_ID();
2533
-                $this->_template_args['attendees'][$att_nmbr]['fname']       = $attendee->fname();
2534
-                $this->_template_args['attendees'][$att_nmbr]['lname']       = $attendee->lname();
2535
-                $this->_template_args['attendees'][$att_nmbr]['email']       = $attendee->email();
2536
-                $this->_template_args['attendees'][$att_nmbr]['final_price'] = $registration->final_price();
2537
-                $this->_template_args['attendees'][$att_nmbr]['address']     = implode(
2538
-                    ', ',
2539
-                    $attendee->full_address_as_array()
2540
-                );
2541
-                $this->_template_args['attendees'][$att_nmbr]['att_link']    = self::add_query_args_and_nonce(
2542
-                    array(
2543
-                        'action' => 'edit_attendee',
2544
-                        'post'   => $attendee->ID(),
2545
-                    ),
2546
-                    REG_ADMIN_URL
2547
-                );
2548
-                $this->_template_args['attendees'][$att_nmbr]['event_name']  = $registration->event_obj()->name();
2549
-                $att_nmbr++;
2550
-            }
2551
-            $this->_template_args['currency_sign'] = EE_Registry::instance()->CFG->currency->sign;
2552
-        }
2553
-        $template_path = REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_attendees.template.php';
2554
-        echo EEH_Template::display_template($template_path, $this->_template_args, true);
2555
-    }
2556
-
2557
-
2558
-    /**
2559
-     *        generates HTML for the Edit Registration side meta box
2560
-     *
2561
-     * @access public
2562
-     * @return void
2563
-     * @throws DomainException
2564
-     * @throws EE_Error
2565
-     * @throws InvalidArgumentException
2566
-     * @throws InvalidDataTypeException
2567
-     * @throws InvalidInterfaceException
2568
-     */
2569
-    public function _reg_registrant_side_meta_box()
2570
-    {
2571
-        /*@var $attendee EE_Attendee */
2572
-        $att_check = $this->_registration->attendee();
2573
-        $attendee  = $att_check instanceof EE_Attendee ? $att_check : EEM_Attendee::instance()->create_default_object();
2574
-        //now let's determine if this is not the primary registration.  If it isn't then we set the
2575
-        //primary_registration object for reference BUT ONLY if the Attendee object loaded is not the same as the
2576
-        //primary registration object (that way we know if we need to show create button or not)
2577
-        if ( ! $this->_registration->is_primary_registrant()) {
2578
-            $primary_registration = $this->_registration->get_primary_registration();
2579
-            $primary_attendee     = $primary_registration instanceof EE_Registration ? $primary_registration->attendee()
2580
-                : null;
2581
-            if ( ! $primary_attendee instanceof EE_Attendee || $attendee->ID() !== $primary_attendee->ID()) {
2582
-                //in here?  This means the displayed registration is not the primary registrant but ALREADY HAS its own
2583
-                //custom attendee object so let's not worry about the primary reg.
2584
-                $primary_registration = null;
2585
-            }
2586
-        } else {
2587
-            $primary_registration = null;
2588
-        }
2589
-        $this->_template_args['ATT_ID']            = $attendee->ID();
2590
-        $this->_template_args['fname']             = $attendee->fname();
2591
-        $this->_template_args['lname']             = $attendee->lname();
2592
-        $this->_template_args['email']             = $attendee->email();
2593
-        $this->_template_args['phone']             = $attendee->phone();
2594
-        $this->_template_args['formatted_address'] = EEH_Address::format($attendee);
2595
-        //edit link
2596
-        $this->_template_args['att_edit_link']  = EE_Admin_Page::add_query_args_and_nonce(array(
2597
-            'action' => 'edit_attendee',
2598
-            'post'   => $attendee->ID(),
2599
-        ), REG_ADMIN_URL);
2600
-        $this->_template_args['att_edit_label'] = esc_html__('View/Edit Contact', 'event_espresso');
2601
-        //create link
2602
-        $this->_template_args['create_link']  = $primary_registration instanceof EE_Registration
2603
-            ? EE_Admin_Page::add_query_args_and_nonce(array(
2604
-                'action'  => 'duplicate_attendee',
2605
-                '_REG_ID' => $this->_registration->ID(),
2606
-            ), REG_ADMIN_URL) : '';
2607
-        $this->_template_args['create_label'] = esc_html__('Create Contact', 'event_espresso');
2608
-        $this->_template_args['att_check']    = $att_check;
2609
-        $template_path                        = REG_TEMPLATE_PATH . 'reg_admin_details_side_meta_box_registrant.template.php';
2610
-        echo EEH_Template::display_template($template_path, $this->_template_args, true);
2611
-    }
2612
-
2613
-
2614
-    /**
2615
-     * trash or restore registrations
2616
-     *
2617
-     * @param  boolean $trash whether to archive or restore
2618
-     * @return void
2619
-     * @throws EE_Error
2620
-     * @throws InvalidArgumentException
2621
-     * @throws InvalidDataTypeException
2622
-     * @throws InvalidInterfaceException
2623
-     * @throws RuntimeException
2624
-     * @access protected
2625
-     */
2626
-    protected function _trash_or_restore_registrations($trash = true)
2627
-    {
2628
-        //if empty _REG_ID then get out because there's nothing to do
2629
-        if (empty($this->_req_data['_REG_ID'])) {
2630
-            EE_Error::add_error(
2631
-                sprintf(
2632
-                    esc_html__(
2633
-                        'In order to %1$s registrations you must select which ones you wish to %1$s by clicking the checkboxes.',
2634
-                        'event_espresso'
2635
-                    ),
2636
-                    $trash ? 'trash' : 'restore'
2637
-                ),
2638
-                __FILE__, __LINE__, __FUNCTION__
2639
-            );
2640
-            $this->_redirect_after_action(false, '', '', array(), true);
2641
-        }
2642
-        $success = 0;
2643
-        $overwrite_msgs = false;
2644
-        //Checkboxes
2645
-        if ( ! is_array($this->_req_data['_REG_ID'])) {
2646
-            $this->_req_data['_REG_ID'] = array($this->_req_data['_REG_ID']);
2647
-        }
2648
-        $reg_count = count($this->_req_data['_REG_ID']);
2649
-        // cycle thru checkboxes
2650
-        foreach ($this->_req_data['_REG_ID'] as $REG_ID) {
2651
-            /** @var EE_Registration $REG */
2652
-            $REG = EEM_Registration::instance()->get_one_by_ID($REG_ID);
2653
-            $payments = $REG->registration_payments();
2654
-            if (! empty($payments)) {
2655
-                $name = $REG->attendee() instanceof EE_Attendee
2656
-                    ? $REG->attendee()->full_name()
2657
-                    : esc_html__('Unknown Attendee', 'event_espresso');
2658
-                $overwrite_msgs = true;
2659
-                EE_Error::add_error(
2660
-                    sprintf(
2661
-                        esc_html__(
2662
-                            'The registration for %s could not be trashed because it has payments attached to the related transaction.  If you wish to trash this registration you must first delete the payments on the related transaction.',
2663
-                            'event_espresso'
2664
-                        ),
2665
-                        $name
2666
-                    ),
2667
-                    __FILE__, __FUNCTION__, __LINE__
2668
-                );
2669
-                //can't trash this registration because it has payments.
2670
-                continue;
2671
-            }
2672
-            $updated = $trash ? $REG->delete() : $REG->restore();
2673
-            if ($updated) {
2674
-                $success++;
2675
-            }
2676
-        }
2677
-        $this->_redirect_after_action(
2678
-            $success === $reg_count, // were ALL registrations affected?
2679
-            $success > 1
2680
-                ? esc_html__('Registrations', 'event_espresso')
2681
-                : esc_html__('Registration', 'event_espresso'),
2682
-            $trash
2683
-                ? esc_html__('moved to the trash', 'event_espresso')
2684
-                : esc_html__('restored', 'event_espresso'),
2685
-            array('action' => 'default'),
2686
-            $overwrite_msgs
2687
-        );
2688
-    }
2689
-
2690
-
2691
-    /**
2692
-     * This is used to permanently delete registrations.  Note, this will handle not only deleting permanently the
2693
-     * registration but also.
2694
-     * 1. Removing relations to EE_Attendee
2695
-     * 2. Deleting permanently the related transaction, but ONLY if all related registrations to the transaction are
2696
-     * ALSO trashed.
2697
-     * 3. Deleting permanently any related Line items but only if the above conditions are met.
2698
-     * 4. Removing relationships between all tickets and the related registrations
2699
-     * 5. Deleting permanently any related Answers (and the answers for other related registrations that were deleted.)
2700
-     * 6. Deleting permanently any related Checkins.
2701
-     *
2702
-     * @return void
2703
-     * @throws EE_Error
2704
-     * @throws InvalidArgumentException
2705
-     * @throws InvalidDataTypeException
2706
-     * @throws InvalidInterfaceException
2707
-     */
2708
-    protected function _delete_registrations()
2709
-    {
2710
-        $REG_MDL = EEM_Registration::instance();
2711
-        $success = 1;
2712
-        //Checkboxes
2713
-        if ( ! empty($this->_req_data['_REG_ID']) && is_array($this->_req_data['_REG_ID'])) {
2714
-            // if array has more than one element than success message should be plural
2715
-            $success = count($this->_req_data['_REG_ID']) > 1 ? 2 : 1;
2716
-            // cycle thru checkboxes
2717
-            while (list($ind, $REG_ID) = each($this->_req_data['_REG_ID'])) {
2718
-                $REG = $REG_MDL->get_one_by_ID($REG_ID);
2719
-                if ( ! $REG instanceof EE_Registration) {
2720
-                    continue;
2721
-                }
2722
-                $deleted = $this->_delete_registration($REG);
2723
-                if ( ! $deleted) {
2724
-                    $success = 0;
2725
-                }
2726
-            }
2727
-        } else {
2728
-            // grab single id and delete
2729
-            $REG_ID  = $this->_req_data['_REG_ID'];
2730
-            $REG     = $REG_MDL->get_one_by_ID($REG_ID);
2731
-            $deleted = $this->_delete_registration($REG);
2732
-            if ( ! $deleted) {
2733
-                $success = 0;
2734
-            }
2735
-        }
2736
-        $what        = $success > 1
2737
-            ? esc_html__('Registrations', 'event_espresso')
2738
-            : esc_html__('Registration', 'event_espresso');
2739
-        $action_desc = esc_html__('permanently deleted.', 'event_espresso');
2740
-        $this->_redirect_after_action(
2741
-            $success,
2742
-            $what,
2743
-            $action_desc,
2744
-            array('action' => 'default'),
2745
-            true
2746
-        );
2747
-    }
2748
-
2749
-
2750
-    /**
2751
-     * handles the permanent deletion of a registration.  See comments with _delete_registrations() for details on what
2752
-     * models get affected.
2753
-     *
2754
-     * @param  EE_Registration $REG registration to be deleted permenantly
2755
-     * @return bool true = successful deletion, false = fail.
2756
-     * @throws EE_Error
2757
-     */
2758
-    protected function _delete_registration(EE_Registration $REG)
2759
-    {
2760
-        //first we start with the transaction... ultimately, we WILL not delete permanently if there are any related
2761
-        //registrations on the transaction that are NOT trashed.
2762
-        $TXN         = $REG->get_first_related('Transaction');
2763
-        $REGS        = $TXN->get_many_related('Registration');
2764
-        $all_trashed = true;
2765
-        foreach ($REGS as $registration) {
2766
-            if ( ! $registration->get('REG_deleted')) {
2767
-                $all_trashed = false;
2768
-            }
2769
-        }
2770
-        if ( ! $all_trashed) {
2771
-            EE_Error::add_error(
2772
-                esc_html__(
2773
-                    'Unable to permanently delete this registration. Before this registration can be permanently deleted, all registrations made in the same transaction must be trashed as well.  These registrations will be permanently deleted in the same action.',
2774
-                    'event_espresso'
2775
-                ),
2776
-                __FILE__, __FUNCTION__, __LINE__
2777
-            );
2778
-            return false;
2779
-        }
2780
-        //k made it here so that means we can delete all the related transactions and their answers (but let's do them
2781
-        //separately from THIS one).
2782
-        foreach ($REGS as $registration) {
2783
-            //delete related answers
2784
-            $registration->delete_related_permanently('Answer');
2785
-            //remove relationship to EE_Attendee (but we ALWAYS leave the contact record intact)
2786
-            $attendee = $registration->get_first_related('Attendee');
2787
-            if ($attendee instanceof EE_Attendee) {
2788
-                $registration->_remove_relation_to($attendee, 'Attendee');
2789
-            }
2790
-            //now remove relationships to tickets on this registration.
2791
-            $registration->_remove_relations('Ticket');
2792
-            //now delete permanently the checkins related to this registration.
2793
-            $registration->delete_related_permanently('Checkin');
2794
-            if ($registration->ID() === $REG->ID()) {
2795
-                continue;
2796
-            } //we don't want to delete permanently the existing registration just yet.
2797
-            //remove relation to transaction for these registrations if NOT the existing registrations
2798
-            $registration->_remove_relations('Transaction');
2799
-            //delete permanently any related messages.
2800
-            $registration->delete_related_permanently('Message');
2801
-            //now delete this registration permanently
2802
-            $registration->delete_permanently();
2803
-        }
2804
-        //now all related registrations on the transaction are handled.  So let's just handle this registration itself
2805
-        // (the transaction and line items should be all that's left).
2806
-        // delete the line items related to the transaction for this registration.
2807
-        $TXN->delete_related_permanently('Line_Item');
2808
-        //we need to remove all the relationships on the transaction
2809
-        $TXN->delete_related_permanently('Payment');
2810
-        $TXN->delete_related_permanently('Extra_Meta');
2811
-        $TXN->delete_related_permanently('Message');
2812
-        //now we can delete this REG permanently (and the transaction of course)
2813
-        $REG->delete_related_permanently('Transaction');
2814
-        return $REG->delete_permanently();
2815
-    }
2816
-
2817
-
2818
-    /**
2819
-     *    generates HTML for the Register New Attendee Admin page
2820
-     *
2821
-     * @access private
2822
-     * @throws DomainException
2823
-     * @throws EE_Error
2824
-     */
2825
-    public function new_registration()
2826
-    {
2827
-        if ( ! $this->_set_reg_event()) {
2828
-            throw new EE_Error(
2829
-                esc_html__(
2830
-                    'Unable to continue with registering because there is no Event ID in the request',
2831
-                    'event_espresso'
2832
-                )
2833
-            );
2834
-        }
2835
-        EE_Registry::instance()->REQ->set_espresso_page(true);
2836
-        // gotta start with a clean slate if we're not coming here via ajax
2837
-        if ( ! defined('DOING_AJAX')
2838
-             && ( ! isset($this->_req_data['processing_registration']) || isset($this->_req_data['step_error']))
2839
-        ) {
2840
-            EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
2841
-        }
2842
-        $this->_template_args['event_name'] = '';
2843
-        // event name
2844
-        if ($this->_reg_event) {
2845
-            $this->_template_args['event_name'] = $this->_reg_event->name();
2846
-            $edit_event_url                     = self::add_query_args_and_nonce(array(
2847
-                'action' => 'edit',
2848
-                'post'   => $this->_reg_event->ID(),
2849
-            ), EVENTS_ADMIN_URL);
2850
-            $edit_event_lnk                     = '<a href="'
2851
-                                                  . $edit_event_url
2852
-                                                  . '" title="'
2853
-                                                  . esc_attr__('Edit ', 'event_espresso')
2854
-                                                  . $this->_reg_event->name()
2855
-                                                  . '">'
2856
-                                                  . esc_html__('Edit Event', 'event_espresso')
2857
-                                                  . '</a>';
2858
-            $this->_template_args['event_name'] .= ' <span class="admin-page-header-edit-lnk not-bold">'
2859
-                                                   . $edit_event_lnk
2860
-                                                   . '</span>';
2861
-        }
2862
-        $this->_template_args['step_content'] = $this->_get_registration_step_content();
2863
-        if (defined('DOING_AJAX')) {
2864
-            $this->_return_json();
2865
-        }
2866
-        // grab header
2867
-        $template_path                              =
2868
-            REG_TEMPLATE_PATH . 'reg_admin_register_new_attendee.template.php';
2869
-        $this->_template_args['admin_page_content'] = EEH_Template::display_template($template_path,
2870
-            $this->_template_args, true);
2871
-        //$this->_set_publish_post_box_vars( NULL, FALSE, FALSE, NULL, FALSE );
2872
-        // the details template wrapper
2873
-        $this->display_admin_page_with_sidebar();
2874
-    }
2875
-
2876
-
2877
-    /**
2878
-     * This returns the content for a registration step
2879
-     *
2880
-     * @access protected
2881
-     * @return string html
2882
-     * @throws DomainException
2883
-     * @throws EE_Error
2884
-     * @throws InvalidArgumentException
2885
-     * @throws InvalidDataTypeException
2886
-     * @throws InvalidInterfaceException
2887
-     */
2888
-    protected function _get_registration_step_content()
2889
-    {
2890
-        if (isset($_COOKIE['ee_registration_added']) && $_COOKIE['ee_registration_added']) {
2891
-            $warning_msg = sprintf(
2892
-                esc_html__(
2893
-                    '%2$sWARNING!!!%3$s%1$sPlease do not use the back button to return to this page for the purpose of adding another registration.%1$sThis can result in lost and/or corrupted data.%1$sIf you wish to add another registration, then please click the%1$s%7$s"Add Another New Registration to Event"%8$s button%1$son the Transaction details page, after you are redirected.%1$s%1$s%4$s redirecting in %5$s seconds %6$s',
2894
-                    'event_espresso'
2895
-                ),
2896
-                '<br />',
2897
-                '<h3 class="important-notice">',
2898
-                '</h3>',
2899
-                '<div class="float-right">',
2900
-                '<span id="redirect_timer" class="important-notice">30</span>',
2901
-                '</div>',
2902
-                '<b>',
2903
-                '</b>'
2904
-            );
2905
-            return '
2385
+	}
2386
+
2387
+
2388
+	/**
2389
+	 * Updates the registration's custom questions according to the form info, if the form is submitted.
2390
+	 * If it's not a post, the "view_registrations" route will be called next on the SAME request
2391
+	 * to display the page
2392
+	 *
2393
+	 * @access protected
2394
+	 * @return void
2395
+	 * @throws EE_Error
2396
+	 */
2397
+	protected function _update_attendee_registration_form()
2398
+	{
2399
+		do_action('AHEE__Registrations_Admin_Page___update_attendee_registration_form__start', $this);
2400
+		if ($_SERVER['REQUEST_METHOD'] == 'POST') {
2401
+			$REG_ID  = isset($this->_req_data['_REG_ID']) ? absint($this->_req_data['_REG_ID']) : false;
2402
+			$success = $this->_save_reg_custom_questions_form($REG_ID);
2403
+			if ($success) {
2404
+				$what  = esc_html__('Registration Form', 'event_espresso');
2405
+				$route = $REG_ID ? array('action' => 'view_registration', '_REG_ID' => $REG_ID)
2406
+					: array('action' => 'default');
2407
+				$this->_redirect_after_action($success, $what, esc_html__('updated', 'event_espresso'), $route);
2408
+			}
2409
+		}
2410
+	}
2411
+
2412
+
2413
+	/**
2414
+	 * Gets the form for saving registrations custom questions (if done
2415
+	 * previously retrieves the cached form object, which may have validation errors in it)
2416
+	 *
2417
+	 * @param int $REG_ID
2418
+	 * @return EE_Registration_Custom_Questions_Form
2419
+	 * @throws EE_Error
2420
+	 * @throws InvalidArgumentException
2421
+	 * @throws InvalidDataTypeException
2422
+	 * @throws InvalidInterfaceException
2423
+	 */
2424
+	protected function _get_reg_custom_questions_form($REG_ID)
2425
+	{
2426
+		if ( ! $this->_reg_custom_questions_form) {
2427
+			require_once(REG_ADMIN . 'form_sections' . DS . 'EE_Registration_Custom_Questions_Form.form.php');
2428
+			$this->_reg_custom_questions_form = new EE_Registration_Custom_Questions_Form(
2429
+				EEM_Registration::instance()->get_one_by_ID($REG_ID)
2430
+			);
2431
+			$this->_reg_custom_questions_form->_construct_finalize(null, null);
2432
+		}
2433
+		return $this->_reg_custom_questions_form;
2434
+	}
2435
+
2436
+
2437
+	/**
2438
+	 * Saves
2439
+	 *
2440
+	 * @access private
2441
+	 * @param bool $REG_ID
2442
+	 * @return bool
2443
+	 * @throws EE_Error
2444
+	 * @throws InvalidArgumentException
2445
+	 * @throws InvalidDataTypeException
2446
+	 * @throws InvalidInterfaceException
2447
+	 */
2448
+	private function _save_reg_custom_questions_form($REG_ID = false)
2449
+	{
2450
+		if ( ! $REG_ID) {
2451
+			EE_Error::add_error(
2452
+				esc_html__(
2453
+					'An error occurred. No registration ID was received.', 'event_espresso'),
2454
+				__FILE__, __FUNCTION__, __LINE__
2455
+			);
2456
+		}
2457
+		$form = $this->_get_reg_custom_questions_form($REG_ID);
2458
+		$form->receive_form_submission($this->_req_data);
2459
+		$success = false;
2460
+		if ($form->is_valid()) {
2461
+			foreach ($form->subforms() as $question_group_id => $question_group_form) {
2462
+				foreach ($question_group_form->inputs() as $question_id => $input) {
2463
+					$where_conditions    = array(
2464
+						'QST_ID' => $question_id,
2465
+						'REG_ID' => $REG_ID,
2466
+					);
2467
+					$possibly_new_values = array(
2468
+						'ANS_value' => $input->normalized_value(),
2469
+					);
2470
+					$answer              = EEM_Answer::instance()->get_one(array($where_conditions));
2471
+					if ($answer instanceof EE_Answer) {
2472
+						$success = $answer->save($possibly_new_values);
2473
+					} else {
2474
+						//insert it then
2475
+						$cols_n_vals = array_merge($where_conditions, $possibly_new_values);
2476
+						$answer      = EE_Answer::new_instance($cols_n_vals);
2477
+						$success     = $answer->save();
2478
+					}
2479
+				}
2480
+			}
2481
+		} else {
2482
+			EE_Error::add_error($form->get_validation_error_string(), __FILE__, __FUNCTION__, __LINE__);
2483
+		}
2484
+		return $success;
2485
+	}
2486
+
2487
+
2488
+	/**
2489
+	 *        generates HTML for the Registration main meta box
2490
+	 *
2491
+	 * @access public
2492
+	 * @return void
2493
+	 * @throws DomainException
2494
+	 * @throws EE_Error
2495
+	 * @throws InvalidArgumentException
2496
+	 * @throws InvalidDataTypeException
2497
+	 * @throws InvalidInterfaceException
2498
+	 */
2499
+	public function _reg_attendees_meta_box()
2500
+	{
2501
+		$REG = EEM_Registration::instance();
2502
+		//get all other registrations on this transaction, and cache
2503
+		//the attendees for them so we don't have to run another query using force_join
2504
+		$registrations                           = $REG->get_all(array(
2505
+			array(
2506
+				'TXN_ID' => $this->_registration->transaction_ID(),
2507
+				'REG_ID' => array('!=', $this->_registration->ID()),
2508
+			),
2509
+			'force_join' => array('Attendee'),
2510
+		));
2511
+		$this->_template_args['attendees']       = array();
2512
+		$this->_template_args['attendee_notice'] = '';
2513
+		if (empty($registrations)
2514
+			|| (is_array($registrations)
2515
+				&& ! EEH_Array::get_one_item_from_array($registrations))
2516
+		) {
2517
+			EE_Error::add_error(
2518
+				esc_html__(
2519
+					'There are no records attached to this registration. Something may have gone wrong with the registration',
2520
+					'event_espresso'
2521
+				), __FILE__, __FUNCTION__, __LINE__
2522
+			);
2523
+			$this->_template_args['attendee_notice'] = EE_Error::get_notices();
2524
+		} else {
2525
+			$att_nmbr = 1;
2526
+			foreach ($registrations as $registration) {
2527
+				/* @var $registration EE_Registration */
2528
+				$attendee                                                    = $registration->attendee()
2529
+					? $registration->attendee()
2530
+					: EEM_Attendee::instance()
2531
+								  ->create_default_object();
2532
+				$this->_template_args['attendees'][$att_nmbr]['STS_ID']      = $registration->status_ID();
2533
+				$this->_template_args['attendees'][$att_nmbr]['fname']       = $attendee->fname();
2534
+				$this->_template_args['attendees'][$att_nmbr]['lname']       = $attendee->lname();
2535
+				$this->_template_args['attendees'][$att_nmbr]['email']       = $attendee->email();
2536
+				$this->_template_args['attendees'][$att_nmbr]['final_price'] = $registration->final_price();
2537
+				$this->_template_args['attendees'][$att_nmbr]['address']     = implode(
2538
+					', ',
2539
+					$attendee->full_address_as_array()
2540
+				);
2541
+				$this->_template_args['attendees'][$att_nmbr]['att_link']    = self::add_query_args_and_nonce(
2542
+					array(
2543
+						'action' => 'edit_attendee',
2544
+						'post'   => $attendee->ID(),
2545
+					),
2546
+					REG_ADMIN_URL
2547
+				);
2548
+				$this->_template_args['attendees'][$att_nmbr]['event_name']  = $registration->event_obj()->name();
2549
+				$att_nmbr++;
2550
+			}
2551
+			$this->_template_args['currency_sign'] = EE_Registry::instance()->CFG->currency->sign;
2552
+		}
2553
+		$template_path = REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_attendees.template.php';
2554
+		echo EEH_Template::display_template($template_path, $this->_template_args, true);
2555
+	}
2556
+
2557
+
2558
+	/**
2559
+	 *        generates HTML for the Edit Registration side meta box
2560
+	 *
2561
+	 * @access public
2562
+	 * @return void
2563
+	 * @throws DomainException
2564
+	 * @throws EE_Error
2565
+	 * @throws InvalidArgumentException
2566
+	 * @throws InvalidDataTypeException
2567
+	 * @throws InvalidInterfaceException
2568
+	 */
2569
+	public function _reg_registrant_side_meta_box()
2570
+	{
2571
+		/*@var $attendee EE_Attendee */
2572
+		$att_check = $this->_registration->attendee();
2573
+		$attendee  = $att_check instanceof EE_Attendee ? $att_check : EEM_Attendee::instance()->create_default_object();
2574
+		//now let's determine if this is not the primary registration.  If it isn't then we set the
2575
+		//primary_registration object for reference BUT ONLY if the Attendee object loaded is not the same as the
2576
+		//primary registration object (that way we know if we need to show create button or not)
2577
+		if ( ! $this->_registration->is_primary_registrant()) {
2578
+			$primary_registration = $this->_registration->get_primary_registration();
2579
+			$primary_attendee     = $primary_registration instanceof EE_Registration ? $primary_registration->attendee()
2580
+				: null;
2581
+			if ( ! $primary_attendee instanceof EE_Attendee || $attendee->ID() !== $primary_attendee->ID()) {
2582
+				//in here?  This means the displayed registration is not the primary registrant but ALREADY HAS its own
2583
+				//custom attendee object so let's not worry about the primary reg.
2584
+				$primary_registration = null;
2585
+			}
2586
+		} else {
2587
+			$primary_registration = null;
2588
+		}
2589
+		$this->_template_args['ATT_ID']            = $attendee->ID();
2590
+		$this->_template_args['fname']             = $attendee->fname();
2591
+		$this->_template_args['lname']             = $attendee->lname();
2592
+		$this->_template_args['email']             = $attendee->email();
2593
+		$this->_template_args['phone']             = $attendee->phone();
2594
+		$this->_template_args['formatted_address'] = EEH_Address::format($attendee);
2595
+		//edit link
2596
+		$this->_template_args['att_edit_link']  = EE_Admin_Page::add_query_args_and_nonce(array(
2597
+			'action' => 'edit_attendee',
2598
+			'post'   => $attendee->ID(),
2599
+		), REG_ADMIN_URL);
2600
+		$this->_template_args['att_edit_label'] = esc_html__('View/Edit Contact', 'event_espresso');
2601
+		//create link
2602
+		$this->_template_args['create_link']  = $primary_registration instanceof EE_Registration
2603
+			? EE_Admin_Page::add_query_args_and_nonce(array(
2604
+				'action'  => 'duplicate_attendee',
2605
+				'_REG_ID' => $this->_registration->ID(),
2606
+			), REG_ADMIN_URL) : '';
2607
+		$this->_template_args['create_label'] = esc_html__('Create Contact', 'event_espresso');
2608
+		$this->_template_args['att_check']    = $att_check;
2609
+		$template_path                        = REG_TEMPLATE_PATH . 'reg_admin_details_side_meta_box_registrant.template.php';
2610
+		echo EEH_Template::display_template($template_path, $this->_template_args, true);
2611
+	}
2612
+
2613
+
2614
+	/**
2615
+	 * trash or restore registrations
2616
+	 *
2617
+	 * @param  boolean $trash whether to archive or restore
2618
+	 * @return void
2619
+	 * @throws EE_Error
2620
+	 * @throws InvalidArgumentException
2621
+	 * @throws InvalidDataTypeException
2622
+	 * @throws InvalidInterfaceException
2623
+	 * @throws RuntimeException
2624
+	 * @access protected
2625
+	 */
2626
+	protected function _trash_or_restore_registrations($trash = true)
2627
+	{
2628
+		//if empty _REG_ID then get out because there's nothing to do
2629
+		if (empty($this->_req_data['_REG_ID'])) {
2630
+			EE_Error::add_error(
2631
+				sprintf(
2632
+					esc_html__(
2633
+						'In order to %1$s registrations you must select which ones you wish to %1$s by clicking the checkboxes.',
2634
+						'event_espresso'
2635
+					),
2636
+					$trash ? 'trash' : 'restore'
2637
+				),
2638
+				__FILE__, __LINE__, __FUNCTION__
2639
+			);
2640
+			$this->_redirect_after_action(false, '', '', array(), true);
2641
+		}
2642
+		$success = 0;
2643
+		$overwrite_msgs = false;
2644
+		//Checkboxes
2645
+		if ( ! is_array($this->_req_data['_REG_ID'])) {
2646
+			$this->_req_data['_REG_ID'] = array($this->_req_data['_REG_ID']);
2647
+		}
2648
+		$reg_count = count($this->_req_data['_REG_ID']);
2649
+		// cycle thru checkboxes
2650
+		foreach ($this->_req_data['_REG_ID'] as $REG_ID) {
2651
+			/** @var EE_Registration $REG */
2652
+			$REG = EEM_Registration::instance()->get_one_by_ID($REG_ID);
2653
+			$payments = $REG->registration_payments();
2654
+			if (! empty($payments)) {
2655
+				$name = $REG->attendee() instanceof EE_Attendee
2656
+					? $REG->attendee()->full_name()
2657
+					: esc_html__('Unknown Attendee', 'event_espresso');
2658
+				$overwrite_msgs = true;
2659
+				EE_Error::add_error(
2660
+					sprintf(
2661
+						esc_html__(
2662
+							'The registration for %s could not be trashed because it has payments attached to the related transaction.  If you wish to trash this registration you must first delete the payments on the related transaction.',
2663
+							'event_espresso'
2664
+						),
2665
+						$name
2666
+					),
2667
+					__FILE__, __FUNCTION__, __LINE__
2668
+				);
2669
+				//can't trash this registration because it has payments.
2670
+				continue;
2671
+			}
2672
+			$updated = $trash ? $REG->delete() : $REG->restore();
2673
+			if ($updated) {
2674
+				$success++;
2675
+			}
2676
+		}
2677
+		$this->_redirect_after_action(
2678
+			$success === $reg_count, // were ALL registrations affected?
2679
+			$success > 1
2680
+				? esc_html__('Registrations', 'event_espresso')
2681
+				: esc_html__('Registration', 'event_espresso'),
2682
+			$trash
2683
+				? esc_html__('moved to the trash', 'event_espresso')
2684
+				: esc_html__('restored', 'event_espresso'),
2685
+			array('action' => 'default'),
2686
+			$overwrite_msgs
2687
+		);
2688
+	}
2689
+
2690
+
2691
+	/**
2692
+	 * This is used to permanently delete registrations.  Note, this will handle not only deleting permanently the
2693
+	 * registration but also.
2694
+	 * 1. Removing relations to EE_Attendee
2695
+	 * 2. Deleting permanently the related transaction, but ONLY if all related registrations to the transaction are
2696
+	 * ALSO trashed.
2697
+	 * 3. Deleting permanently any related Line items but only if the above conditions are met.
2698
+	 * 4. Removing relationships between all tickets and the related registrations
2699
+	 * 5. Deleting permanently any related Answers (and the answers for other related registrations that were deleted.)
2700
+	 * 6. Deleting permanently any related Checkins.
2701
+	 *
2702
+	 * @return void
2703
+	 * @throws EE_Error
2704
+	 * @throws InvalidArgumentException
2705
+	 * @throws InvalidDataTypeException
2706
+	 * @throws InvalidInterfaceException
2707
+	 */
2708
+	protected function _delete_registrations()
2709
+	{
2710
+		$REG_MDL = EEM_Registration::instance();
2711
+		$success = 1;
2712
+		//Checkboxes
2713
+		if ( ! empty($this->_req_data['_REG_ID']) && is_array($this->_req_data['_REG_ID'])) {
2714
+			// if array has more than one element than success message should be plural
2715
+			$success = count($this->_req_data['_REG_ID']) > 1 ? 2 : 1;
2716
+			// cycle thru checkboxes
2717
+			while (list($ind, $REG_ID) = each($this->_req_data['_REG_ID'])) {
2718
+				$REG = $REG_MDL->get_one_by_ID($REG_ID);
2719
+				if ( ! $REG instanceof EE_Registration) {
2720
+					continue;
2721
+				}
2722
+				$deleted = $this->_delete_registration($REG);
2723
+				if ( ! $deleted) {
2724
+					$success = 0;
2725
+				}
2726
+			}
2727
+		} else {
2728
+			// grab single id and delete
2729
+			$REG_ID  = $this->_req_data['_REG_ID'];
2730
+			$REG     = $REG_MDL->get_one_by_ID($REG_ID);
2731
+			$deleted = $this->_delete_registration($REG);
2732
+			if ( ! $deleted) {
2733
+				$success = 0;
2734
+			}
2735
+		}
2736
+		$what        = $success > 1
2737
+			? esc_html__('Registrations', 'event_espresso')
2738
+			: esc_html__('Registration', 'event_espresso');
2739
+		$action_desc = esc_html__('permanently deleted.', 'event_espresso');
2740
+		$this->_redirect_after_action(
2741
+			$success,
2742
+			$what,
2743
+			$action_desc,
2744
+			array('action' => 'default'),
2745
+			true
2746
+		);
2747
+	}
2748
+
2749
+
2750
+	/**
2751
+	 * handles the permanent deletion of a registration.  See comments with _delete_registrations() for details on what
2752
+	 * models get affected.
2753
+	 *
2754
+	 * @param  EE_Registration $REG registration to be deleted permenantly
2755
+	 * @return bool true = successful deletion, false = fail.
2756
+	 * @throws EE_Error
2757
+	 */
2758
+	protected function _delete_registration(EE_Registration $REG)
2759
+	{
2760
+		//first we start with the transaction... ultimately, we WILL not delete permanently if there are any related
2761
+		//registrations on the transaction that are NOT trashed.
2762
+		$TXN         = $REG->get_first_related('Transaction');
2763
+		$REGS        = $TXN->get_many_related('Registration');
2764
+		$all_trashed = true;
2765
+		foreach ($REGS as $registration) {
2766
+			if ( ! $registration->get('REG_deleted')) {
2767
+				$all_trashed = false;
2768
+			}
2769
+		}
2770
+		if ( ! $all_trashed) {
2771
+			EE_Error::add_error(
2772
+				esc_html__(
2773
+					'Unable to permanently delete this registration. Before this registration can be permanently deleted, all registrations made in the same transaction must be trashed as well.  These registrations will be permanently deleted in the same action.',
2774
+					'event_espresso'
2775
+				),
2776
+				__FILE__, __FUNCTION__, __LINE__
2777
+			);
2778
+			return false;
2779
+		}
2780
+		//k made it here so that means we can delete all the related transactions and their answers (but let's do them
2781
+		//separately from THIS one).
2782
+		foreach ($REGS as $registration) {
2783
+			//delete related answers
2784
+			$registration->delete_related_permanently('Answer');
2785
+			//remove relationship to EE_Attendee (but we ALWAYS leave the contact record intact)
2786
+			$attendee = $registration->get_first_related('Attendee');
2787
+			if ($attendee instanceof EE_Attendee) {
2788
+				$registration->_remove_relation_to($attendee, 'Attendee');
2789
+			}
2790
+			//now remove relationships to tickets on this registration.
2791
+			$registration->_remove_relations('Ticket');
2792
+			//now delete permanently the checkins related to this registration.
2793
+			$registration->delete_related_permanently('Checkin');
2794
+			if ($registration->ID() === $REG->ID()) {
2795
+				continue;
2796
+			} //we don't want to delete permanently the existing registration just yet.
2797
+			//remove relation to transaction for these registrations if NOT the existing registrations
2798
+			$registration->_remove_relations('Transaction');
2799
+			//delete permanently any related messages.
2800
+			$registration->delete_related_permanently('Message');
2801
+			//now delete this registration permanently
2802
+			$registration->delete_permanently();
2803
+		}
2804
+		//now all related registrations on the transaction are handled.  So let's just handle this registration itself
2805
+		// (the transaction and line items should be all that's left).
2806
+		// delete the line items related to the transaction for this registration.
2807
+		$TXN->delete_related_permanently('Line_Item');
2808
+		//we need to remove all the relationships on the transaction
2809
+		$TXN->delete_related_permanently('Payment');
2810
+		$TXN->delete_related_permanently('Extra_Meta');
2811
+		$TXN->delete_related_permanently('Message');
2812
+		//now we can delete this REG permanently (and the transaction of course)
2813
+		$REG->delete_related_permanently('Transaction');
2814
+		return $REG->delete_permanently();
2815
+	}
2816
+
2817
+
2818
+	/**
2819
+	 *    generates HTML for the Register New Attendee Admin page
2820
+	 *
2821
+	 * @access private
2822
+	 * @throws DomainException
2823
+	 * @throws EE_Error
2824
+	 */
2825
+	public function new_registration()
2826
+	{
2827
+		if ( ! $this->_set_reg_event()) {
2828
+			throw new EE_Error(
2829
+				esc_html__(
2830
+					'Unable to continue with registering because there is no Event ID in the request',
2831
+					'event_espresso'
2832
+				)
2833
+			);
2834
+		}
2835
+		EE_Registry::instance()->REQ->set_espresso_page(true);
2836
+		// gotta start with a clean slate if we're not coming here via ajax
2837
+		if ( ! defined('DOING_AJAX')
2838
+			 && ( ! isset($this->_req_data['processing_registration']) || isset($this->_req_data['step_error']))
2839
+		) {
2840
+			EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
2841
+		}
2842
+		$this->_template_args['event_name'] = '';
2843
+		// event name
2844
+		if ($this->_reg_event) {
2845
+			$this->_template_args['event_name'] = $this->_reg_event->name();
2846
+			$edit_event_url                     = self::add_query_args_and_nonce(array(
2847
+				'action' => 'edit',
2848
+				'post'   => $this->_reg_event->ID(),
2849
+			), EVENTS_ADMIN_URL);
2850
+			$edit_event_lnk                     = '<a href="'
2851
+												  . $edit_event_url
2852
+												  . '" title="'
2853
+												  . esc_attr__('Edit ', 'event_espresso')
2854
+												  . $this->_reg_event->name()
2855
+												  . '">'
2856
+												  . esc_html__('Edit Event', 'event_espresso')
2857
+												  . '</a>';
2858
+			$this->_template_args['event_name'] .= ' <span class="admin-page-header-edit-lnk not-bold">'
2859
+												   . $edit_event_lnk
2860
+												   . '</span>';
2861
+		}
2862
+		$this->_template_args['step_content'] = $this->_get_registration_step_content();
2863
+		if (defined('DOING_AJAX')) {
2864
+			$this->_return_json();
2865
+		}
2866
+		// grab header
2867
+		$template_path                              =
2868
+			REG_TEMPLATE_PATH . 'reg_admin_register_new_attendee.template.php';
2869
+		$this->_template_args['admin_page_content'] = EEH_Template::display_template($template_path,
2870
+			$this->_template_args, true);
2871
+		//$this->_set_publish_post_box_vars( NULL, FALSE, FALSE, NULL, FALSE );
2872
+		// the details template wrapper
2873
+		$this->display_admin_page_with_sidebar();
2874
+	}
2875
+
2876
+
2877
+	/**
2878
+	 * This returns the content for a registration step
2879
+	 *
2880
+	 * @access protected
2881
+	 * @return string html
2882
+	 * @throws DomainException
2883
+	 * @throws EE_Error
2884
+	 * @throws InvalidArgumentException
2885
+	 * @throws InvalidDataTypeException
2886
+	 * @throws InvalidInterfaceException
2887
+	 */
2888
+	protected function _get_registration_step_content()
2889
+	{
2890
+		if (isset($_COOKIE['ee_registration_added']) && $_COOKIE['ee_registration_added']) {
2891
+			$warning_msg = sprintf(
2892
+				esc_html__(
2893
+					'%2$sWARNING!!!%3$s%1$sPlease do not use the back button to return to this page for the purpose of adding another registration.%1$sThis can result in lost and/or corrupted data.%1$sIf you wish to add another registration, then please click the%1$s%7$s"Add Another New Registration to Event"%8$s button%1$son the Transaction details page, after you are redirected.%1$s%1$s%4$s redirecting in %5$s seconds %6$s',
2894
+					'event_espresso'
2895
+				),
2896
+				'<br />',
2897
+				'<h3 class="important-notice">',
2898
+				'</h3>',
2899
+				'<div class="float-right">',
2900
+				'<span id="redirect_timer" class="important-notice">30</span>',
2901
+				'</div>',
2902
+				'<b>',
2903
+				'</b>'
2904
+			);
2905
+			return '
2906 2906
 	<div id="ee-add-reg-back-button-dv"><p>' . $warning_msg . '</p></div>
2907 2907
 	<script >
2908 2908
 		// WHOAH !!! it appears that someone is using the back button from the Transaction admin page
@@ -2915,847 +2915,847 @@  discard block
 block discarded – undo
2915 2915
 	        }
2916 2916
 	    }, 800 );
2917 2917
 	</script >';
2918
-        }
2919
-        $template_args = array(
2920
-            'title'                    => '',
2921
-            'content'                  => '',
2922
-            'step_button_text'         => '',
2923
-            'show_notification_toggle' => false,
2924
-        );
2925
-        //to indicate we're processing a new registration
2926
-        $hidden_fields = array(
2927
-            'processing_registration' => array(
2928
-                'type'  => 'hidden',
2929
-                'value' => 0,
2930
-            ),
2931
-            'event_id'                => array(
2932
-                'type'  => 'hidden',
2933
-                'value' => $this->_reg_event->ID(),
2934
-            ),
2935
-        );
2936
-        //if the cart is empty then we know we're at step one so we'll display ticket selector
2937
-        $cart = EE_Registry::instance()->SSN->cart();
2938
-        $step = ! $cart instanceof EE_Cart ? 'ticket' : 'questions';
2939
-        switch ($step) {
2940
-            case 'ticket' :
2941
-                $hidden_fields['processing_registration']['value'] = 1;
2942
-                $template_args['title']                            = esc_html__(
2943
-                    'Step One: Select the Ticket for this registration',
2944
-                    'event_espresso'
2945
-                );
2946
-                $template_args['content']                          =
2947
-                    EED_Ticket_Selector::instance()->display_ticket_selector($this->_reg_event);
2948
-                $template_args['step_button_text']                 = esc_html__(
2949
-                    'Add Tickets and Continue to Registrant Details',
2950
-                    'event_espresso'
2951
-                );
2952
-                $template_args['show_notification_toggle']         = false;
2953
-                break;
2954
-            case 'questions' :
2955
-                $hidden_fields['processing_registration']['value'] = 2;
2956
-                $template_args['title']                            = esc_html__(
2957
-                    'Step Two: Add Registrant Details for this Registration',
2958
-                    'event_espresso'
2959
-                );
2960
-                //in theory we should be able to run EED_SPCO at this point because the cart should have been setup
2961
-                // properly by the first process_reg_step run.
2962
-                $template_args['content']                  =
2963
-                    EED_Single_Page_Checkout::registration_checkout_for_admin();
2964
-                $template_args['step_button_text']         = esc_html__(
2965
-                    'Save Registration and Continue to Details',
2966
-                    'event_espresso'
2967
-                );
2968
-                $template_args['show_notification_toggle'] = true;
2969
-                break;
2970
-        }
2971
-        //we come back to the process_registration_step route.
2972
-        $this->_set_add_edit_form_tags('process_reg_step', $hidden_fields);
2973
-        return EEH_Template::display_template(
2974
-            REG_TEMPLATE_PATH . 'reg_admin_register_new_attendee_step_content.template.php',
2975
-            $template_args,
2976
-            true
2977
-        );
2978
-    }
2979
-
2980
-
2981
-    /**
2982
-     *        set_reg_event
2983
-     *
2984
-     * @access private
2985
-     * @return bool
2986
-     * @throws EE_Error
2987
-     * @throws InvalidArgumentException
2988
-     * @throws InvalidDataTypeException
2989
-     * @throws InvalidInterfaceException
2990
-     */
2991
-    private function _set_reg_event()
2992
-    {
2993
-        if (is_object($this->_reg_event)) {
2994
-            return true;
2995
-        }
2996
-        $EVT_ID = (! empty($this->_req_data['event_id'])) ? absint($this->_req_data['event_id']) : false;
2997
-        if ( ! $EVT_ID) {
2998
-            return false;
2999
-        }
3000
-        $this->_reg_event = EEM_Event::instance()->get_one_by_ID($EVT_ID);
3001
-        return true;
3002
-    }
3003
-
3004
-
3005
-    /**
3006
-     * process_reg_step
3007
-     *
3008
-     * @access        public
3009
-     * @return string
3010
-     * @throws DomainException
3011
-     * @throws EE_Error
3012
-     * @throws InvalidArgumentException
3013
-     * @throws InvalidDataTypeException
3014
-     * @throws InvalidInterfaceException
3015
-     * @throws ReflectionException
3016
-     * @throws RuntimeException
3017
-     */
3018
-    public function process_reg_step()
3019
-    {
3020
-        EE_System::do_not_cache();
3021
-        $this->_set_reg_event();
3022
-        EE_Registry::instance()->REQ->set_espresso_page(true);
3023
-        EE_Registry::instance()->REQ->set('uts', time());
3024
-        //what step are we on?
3025
-        $cart = EE_Registry::instance()->SSN->cart();
3026
-        $step = ! $cart instanceof EE_Cart ? 'ticket' : 'questions';
3027
-        //if doing ajax then we need to verify the nonce
3028
-        if (defined('DOING_AJAX')) {
3029
-            $nonce = isset($this->_req_data[$this->_req_nonce])
3030
-                ? sanitize_text_field($this->_req_data[$this->_req_nonce]) : '';
3031
-            $this->_verify_nonce($nonce, $this->_req_nonce);
3032
-        }
3033
-        switch ($step) {
3034
-            case 'ticket' :
3035
-                //process ticket selection
3036
-                $success = EED_Ticket_Selector::instance()->process_ticket_selections();
3037
-                if ($success) {
3038
-                    EE_Error::add_success(
3039
-                        esc_html__(
3040
-                            'Tickets Selected. Now complete the registration.',
3041
-                            'event_espresso'
3042
-                        )
3043
-                    );
3044
-                } else {
3045
-                    $query_args['step_error'] = $this->_req_data['step_error'] = true;
3046
-                }
3047
-                if (defined('DOING_AJAX')) {
3048
-                    $this->new_registration(); //display next step
3049
-                } else {
3050
-                    $query_args = array(
3051
-                        'action'                  => 'new_registration',
3052
-                        'processing_registration' => 1,
3053
-                        'event_id'                => $this->_reg_event->ID(),
3054
-                        'uts'                     => time(),
3055
-                    );
3056
-                    $this->_redirect_after_action(
3057
-                        false,
3058
-                        '',
3059
-                        '',
3060
-                        $query_args,
3061
-                        true
3062
-                    );
3063
-                }
3064
-                break;
3065
-            case 'questions' :
3066
-                if (! isset(
3067
-                    $this->_req_data['txn_reg_status_change'],
3068
-                    $this->_req_data['txn_reg_status_change']['send_notifications'])
3069
-                ) {
3070
-                    add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_false', 15);
3071
-                }
3072
-                //process registration
3073
-                $transaction = EED_Single_Page_Checkout::instance()->process_registration_from_admin();
3074
-                if ($cart instanceof EE_Cart) {
3075
-                    $grand_total = $cart->get_cart_grand_total();
3076
-                    if ($grand_total instanceof EE_Line_Item) {
3077
-                        $grand_total->save_this_and_descendants_to_txn();
3078
-                    }
3079
-                }
3080
-                if ( ! $transaction instanceof EE_Transaction) {
3081
-                    $query_args = array(
3082
-                        'action'                  => 'new_registration',
3083
-                        'processing_registration' => 2,
3084
-                        'event_id'                => $this->_reg_event->ID(),
3085
-                        'uts'                     => time(),
3086
-                    );
3087
-                    if (defined('DOING_AJAX')) {
3088
-                        //display registration form again because there are errors (maybe validation?)
3089
-                        $this->new_registration();
3090
-                        return;
3091
-                    } else {
3092
-                        $this->_redirect_after_action(
3093
-                            false,
3094
-                            '',
3095
-                            '',
3096
-                            $query_args,
3097
-                            true
3098
-                        );
3099
-                        return;
3100
-                    }
3101
-                }
3102
-                // maybe update status, and make sure to save transaction if not done already
3103
-                if ( ! $transaction->update_status_based_on_total_paid()) {
3104
-                    $transaction->save();
3105
-                }
3106
-                EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
3107
-                $this->_req_data = array();
3108
-                $query_args      = array(
3109
-                    'action'        => 'redirect_to_txn',
3110
-                    'TXN_ID'        => $transaction->ID(),
3111
-                    'EVT_ID'        => $this->_reg_event->ID(),
3112
-                    'event_name'    => urlencode($this->_reg_event->name()),
3113
-                    'redirect_from' => 'new_registration',
3114
-                );
3115
-                $this->_redirect_after_action(false, '', '', $query_args, true);
3116
-                break;
3117
-        }
3118
-        //what are you looking here for?  Should be nothing to do at this point.
3119
-    }
3120
-
3121
-
3122
-    /**
3123
-     * redirect_to_txn
3124
-     *
3125
-     * @access public
3126
-     * @return void
3127
-     * @throws EE_Error
3128
-     * @throws InvalidArgumentException
3129
-     * @throws InvalidDataTypeException
3130
-     * @throws InvalidInterfaceException
3131
-     */
3132
-    public function redirect_to_txn()
3133
-    {
3134
-        EE_System::do_not_cache();
3135
-        EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
3136
-        $query_args = array(
3137
-            'action' => 'view_transaction',
3138
-            'TXN_ID' => isset($this->_req_data['TXN_ID']) ? absint($this->_req_data['TXN_ID']) : 0,
3139
-            'page'   => 'espresso_transactions',
3140
-        );
3141
-        if (isset($this->_req_data['EVT_ID'], $this->_req_data['redirect_from'])) {
3142
-            $query_args['EVT_ID']        = $this->_req_data['EVT_ID'];
3143
-            $query_args['event_name']    = urlencode($this->_req_data['event_name']);
3144
-            $query_args['redirect_from'] = $this->_req_data['redirect_from'];
3145
-        }
3146
-        EE_Error::add_success(
3147
-            esc_html__(
3148
-                'Registration Created.  Please review the transaction and add any payments as necessary',
3149
-                'event_espresso'
3150
-            )
3151
-        );
3152
-        $this->_redirect_after_action(false, '', '', $query_args, true);
3153
-    }
3154
-
3155
-
3156
-    /**
3157
-     *        generates HTML for the Attendee Contact List
3158
-     *
3159
-     * @access protected
3160
-     * @return void
3161
-     */
3162
-    protected function _attendee_contact_list_table()
3163
-    {
3164
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3165
-        $this->_search_btn_label = esc_html__('Contacts', 'event_espresso');
3166
-        $this->display_admin_list_table_page_with_no_sidebar();
3167
-    }
3168
-
3169
-
3170
-    /**
3171
-     *        get_attendees
3172
-     *
3173
-     * @param      $per_page
3174
-     * @param bool $count whether to return count or data.
3175
-     * @param bool $trash
3176
-     * @return array
3177
-     * @throws EE_Error
3178
-     * @throws InvalidArgumentException
3179
-     * @throws InvalidDataTypeException
3180
-     * @throws InvalidInterfaceException
3181
-     * @access public
3182
-     */
3183
-    public function get_attendees($per_page, $count = false, $trash = false)
3184
-    {
3185
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3186
-        require_once(REG_ADMIN . 'EE_Attendee_Contact_List_Table.class.php');
3187
-        $ATT_MDL                    = EEM_Attendee::instance();
3188
-        $this->_req_data['orderby'] = ! empty($this->_req_data['orderby']) ? $this->_req_data['orderby'] : '';
3189
-        switch ($this->_req_data['orderby']) {
3190
-            case 'ATT_ID':
3191
-                $orderby = 'ATT_ID';
3192
-                break;
3193
-            case 'ATT_fname':
3194
-                $orderby = 'ATT_fname';
3195
-                break;
3196
-            case 'ATT_email':
3197
-                $orderby = 'ATT_email';
3198
-                break;
3199
-            case 'ATT_city':
3200
-                $orderby = 'ATT_city';
3201
-                break;
3202
-            case 'STA_ID':
3203
-                $orderby = 'STA_ID';
3204
-                break;
3205
-            case 'CNT_ID':
3206
-                $orderby = 'CNT_ID';
3207
-                break;
3208
-            default:
3209
-                $orderby = 'ATT_lname';
3210
-        }
3211
-        $sort         = (isset($this->_req_data['order']) && ! empty($this->_req_data['order']))
3212
-            ? $this->_req_data['order']
3213
-            : 'ASC';
3214
-        $current_page = isset($this->_req_data['paged']) && ! empty($this->_req_data['paged'])
3215
-            ? $this->_req_data['paged']
3216
-            : 1;
3217
-        $per_page     = isset($per_page) && ! empty($per_page) ? $per_page : 10;
3218
-        $per_page     = isset($this->_req_data['perpage']) && ! empty($this->_req_data['perpage'])
3219
-            ? $this->_req_data['perpage']
3220
-            : $per_page;
3221
-        $_where       = array();
3222
-        if ( ! empty($this->_req_data['s'])) {
3223
-            $sstr         = '%' . $this->_req_data['s'] . '%';
3224
-            $_where['OR'] = array(
3225
-                'Registration.Event.EVT_name'       => array('LIKE', $sstr),
3226
-                'Registration.Event.EVT_desc'       => array('LIKE', $sstr),
3227
-                'Registration.Event.EVT_short_desc' => array('LIKE', $sstr),
3228
-                'ATT_fname'                         => array('LIKE', $sstr),
3229
-                'ATT_lname'                         => array('LIKE', $sstr),
3230
-                'ATT_short_bio'                     => array('LIKE', $sstr),
3231
-                'ATT_email'                         => array('LIKE', $sstr),
3232
-                'ATT_address'                       => array('LIKE', $sstr),
3233
-                'ATT_address2'                      => array('LIKE', $sstr),
3234
-                'ATT_city'                          => array('LIKE', $sstr),
3235
-                'Country.CNT_name'                  => array('LIKE', $sstr),
3236
-                'State.STA_name'                    => array('LIKE', $sstr),
3237
-                'ATT_phone'                         => array('LIKE', $sstr),
3238
-                'Registration.REG_final_price'      => array('LIKE', $sstr),
3239
-                'Registration.REG_code'             => array('LIKE', $sstr),
3240
-                'Registration.REG_count'            => array('LIKE', $sstr),
3241
-                'Registration.REG_group_size'       => array('LIKE', $sstr),
3242
-            );
3243
-        }
3244
-        $offset = ($current_page - 1) * $per_page;
3245
-        $limit  = $count ? null : array($offset, $per_page);
3246
-        if ($trash) {
3247
-            $_where['status'] = array('!=', 'publish');
3248
-            $all_attendees    = $count
3249
-                ? $ATT_MDL->count(array(
3250
-                    $_where,
3251
-                    'order_by' => array($orderby => $sort),
3252
-                    'limit'    => $limit,
3253
-                ), 'ATT_ID', true)
3254
-                : $ATT_MDL->get_all(array(
3255
-                    $_where,
3256
-                    'order_by' => array($orderby => $sort),
3257
-                    'limit'    => $limit,
3258
-                ));
3259
-        } else {
3260
-            $_where['status'] = array('IN', array('publish'));
3261
-            $all_attendees    = $count
3262
-                ? $ATT_MDL->count(array(
3263
-                    $_where,
3264
-                    'order_by' => array($orderby => $sort),
3265
-                    'limit'    => $limit,
3266
-                ), 'ATT_ID', true)
3267
-                : $ATT_MDL->get_all(array(
3268
-                    $_where,
3269
-                    'order_by' => array($orderby => $sort),
3270
-                    'limit'    => $limit,
3271
-                ));
3272
-        }
3273
-        return $all_attendees;
3274
-    }
3275
-
3276
-
3277
-    /**
3278
-     * This is just taking care of resending the registration confirmation
3279
-     *
3280
-     * @access protected
3281
-     * @return void
3282
-     */
3283
-    protected function _resend_registration()
3284
-    {
3285
-        $this->_process_resend_registration();
3286
-        $query_args = isset($this->_req_data['redirect_to'])
3287
-            ? array('action' => $this->_req_data['redirect_to'], '_REG_ID' => $this->_req_data['_REG_ID'])
3288
-            : array('action' => 'default');
3289
-        $this->_redirect_after_action(false, '', '', $query_args, true);
3290
-    }
3291
-
3292
-    /**
3293
-     * Creates a registration report, but accepts the name of a method to use for preparing the query parameters
3294
-     * to use when selecting registrations
3295
-     * @param string $method_name_for_getting_query_params the name of the method (on this class) to use for preparing
3296
-     *                                                     the query parameters from the request
3297
-     * @return void ends the request with a redirect or download
3298
-     */
3299
-    public function _registrations_report_base( $method_name_for_getting_query_params )
3300
-    {
3301
-        if (! defined('EE_USE_OLD_CSV_REPORT_CLASS')) {
3302
-            wp_redirect(EE_Admin_Page::add_query_args_and_nonce(
3303
-                array(
3304
-                    'page'        => 'espresso_batch',
3305
-                    'batch'       => 'file',
3306
-                    'EVT_ID'      => isset($this->_req_data['EVT_ID']) ? $this->_req_data['EVT_ID'] : null,
3307
-                    'filters'     => urlencode(
3308
-                        serialize(
3309
-                            call_user_func(
3310
-                                array( $this, $method_name_for_getting_query_params ),
3311
-                                EEH_Array::is_set(
3312
-                                    $this->_req_data,
3313
-                                    'filters',
3314
-                                    array()
3315
-                                )
3316
-                            )
3317
-                        )
3318
-                ),
3319
-                'use_filters' => EEH_Array::is_set($this->_req_data, 'use_filters', false),
3320
-                'job_handler' => urlencode('EventEspressoBatchRequest\JobHandlers\RegistrationsReport'),
3321
-                'return_url'  => urlencode($this->_req_data['return_url']),
3322
-            )));
3323
-        } else {
3324
-            $new_request_args = array(
3325
-                'export' => 'report',
3326
-                'action' => 'registrations_report_for_event',
3327
-                'EVT_ID' => isset($this->_req_data['EVT_ID']) ? $this->_req_data['EVT_ID'] : null,
3328
-            );
3329
-            $this->_req_data = array_merge($this->_req_data, $new_request_args);
3330
-            if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
3331
-                require_once(EE_CLASSES . 'EE_Export.class.php');
3332
-                $EE_Export = EE_Export::instance($this->_req_data);
3333
-                $EE_Export->export();
3334
-            }
3335
-        }
3336
-    }
3337
-
3338
-
3339
-
3340
-    /**
3341
-     * Creates a registration report using only query parameters in the request
3342
-     * @return void
3343
-     */
3344
-    public function _registrations_report()
3345
-    {
3346
-        $this->_registrations_report_base('_get_registration_query_parameters');
3347
-    }
3348
-
3349
-
3350
-    public function _contact_list_export()
3351
-    {
3352
-        if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
3353
-            require_once(EE_CLASSES . 'EE_Export.class.php');
3354
-            $EE_Export = EE_Export::instance($this->_req_data);
3355
-            $EE_Export->export_attendees();
3356
-        }
3357
-    }
3358
-
3359
-
3360
-    public function _contact_list_report()
3361
-    {
3362
-        if ( ! defined('EE_USE_OLD_CSV_REPORT_CLASS')) {
3363
-            wp_redirect(EE_Admin_Page::add_query_args_and_nonce(array(
3364
-                'page'        => 'espresso_batch',
3365
-                'batch'       => 'file',
3366
-                'job_handler' => urlencode('EventEspressoBatchRequest\JobHandlers\AttendeesReport'),
3367
-                'return_url'  => urlencode($this->_req_data['return_url']),
3368
-            )));
3369
-        } else {
3370
-            if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
3371
-                require_once(EE_CLASSES . 'EE_Export.class.php');
3372
-                $EE_Export = EE_Export::instance($this->_req_data);
3373
-                $EE_Export->report_attendees();
3374
-            }
3375
-        }
3376
-    }
3377
-
3378
-
3379
-
3380
-
3381
-
3382
-    /***************************************        ATTENDEE DETAILS        ***************************************/
3383
-    /**
3384
-     * This duplicates the attendee object for the given incoming registration id and attendee_id.
3385
-     *
3386
-     * @return void
3387
-     * @throws EE_Error
3388
-     * @throws InvalidArgumentException
3389
-     * @throws InvalidDataTypeException
3390
-     * @throws InvalidInterfaceException
3391
-     */
3392
-    protected function _duplicate_attendee()
3393
-    {
3394
-        $action = ! empty($this->_req_data['return']) ? $this->_req_data['return'] : 'default';
3395
-        //verify we have necessary info
3396
-        if (empty($this->_req_data['_REG_ID'])) {
3397
-            EE_Error::add_error(
3398
-                esc_html__(
3399
-                    'Unable to create the contact for the registration because the required parameters are not present (_REG_ID )',
3400
-                    'event_espresso'
3401
-                ), __FILE__, __LINE__, __FUNCTION__
3402
-            );
3403
-            $query_args = array('action' => $action);
3404
-            $this->_redirect_after_action('', '', '', $query_args, true);
3405
-        }
3406
-        //okay necessary deets present... let's dupe the incoming attendee and attach to incoming registration.
3407
-        $registration = EEM_Registration::instance()->get_one_by_ID($this->_req_data['_REG_ID']);
3408
-        $attendee     = $registration->attendee();
3409
-        //remove relation of existing attendee on registration
3410
-        $registration->_remove_relation_to($attendee, 'Attendee');
3411
-        //new attendee
3412
-        $new_attendee = clone $attendee;
3413
-        $new_attendee->set('ATT_ID', 0);
3414
-        $new_attendee->save();
3415
-        //add new attendee to reg
3416
-        $registration->_add_relation_to($new_attendee, 'Attendee');
3417
-        EE_Error::add_success(
3418
-            esc_html__(
3419
-                'New Contact record created.  Now make any edits you wish to make for this contact.',
3420
-                'event_espresso'
3421
-            )
3422
-        );
3423
-        //redirect to edit page for attendee
3424
-        $query_args = array('post' => $new_attendee->ID(), 'action' => 'edit_attendee');
3425
-        $this->_redirect_after_action('', '', '', $query_args, true);
3426
-    }
3427
-
3428
-
3429
-    /**
3430
-     * Callback invoked by parent EE_Admin_CPT class hooked in on `save_post` wp hook.
3431
-     * @param int      $post_id
3432
-     * @param WP_POST $post
3433
-     * @throws DomainException
3434
-     * @throws EE_Error
3435
-     * @throws InvalidArgumentException
3436
-     * @throws InvalidDataTypeException
3437
-     * @throws InvalidInterfaceException
3438
-     * @throws LogicException
3439
-     * @throws InvalidFormSubmissionException
3440
-     */
3441
-    protected function _insert_update_cpt_item($post_id, $post)
3442
-    {
3443
-        $success  = true;
3444
-        $attendee = $post instanceof WP_Post && $post->post_type === 'espresso_attendees'
3445
-            ? EEM_Attendee::instance()->get_one_by_ID($post_id)
3446
-            : null;
3447
-        //for attendee updates
3448
-        if ($attendee instanceof EE_Attendee) {
3449
-            //note we should only be UPDATING attendees at this point.
3450
-            $updated_fields = array(
3451
-                'ATT_fname'     => $this->_req_data['ATT_fname'],
3452
-                'ATT_lname'     => $this->_req_data['ATT_lname'],
3453
-                'ATT_full_name' => $this->_req_data['ATT_fname'] . ' ' . $this->_req_data['ATT_lname'],
3454
-                'ATT_address'   => isset($this->_req_data['ATT_address']) ? $this->_req_data['ATT_address'] : '',
3455
-                'ATT_address2'  => isset($this->_req_data['ATT_address2']) ? $this->_req_data['ATT_address2'] : '',
3456
-                'ATT_city'      => isset($this->_req_data['ATT_city']) ? $this->_req_data['ATT_city'] : '',
3457
-                'STA_ID'        => isset($this->_req_data['STA_ID']) ? $this->_req_data['STA_ID'] : '',
3458
-                'CNT_ISO'       => isset($this->_req_data['CNT_ISO']) ? $this->_req_data['CNT_ISO'] : '',
3459
-                'ATT_zip'       => isset($this->_req_data['ATT_zip']) ? $this->_req_data['ATT_zip'] : '',
3460
-            );
3461
-            foreach ($updated_fields as $field => $value) {
3462
-                $attendee->set($field, $value);
3463
-            }
3464
-
3465
-            //process contact details metabox form handler (which will also save the attendee)
3466
-            $contact_details_form = $this->getAttendeeContactDetailsMetaboxFormHandler($attendee);
3467
-            $success = $contact_details_form->process($this->_req_data);
3468
-
3469
-            $attendee_update_callbacks = apply_filters(
3470
-                'FHEE__Registrations_Admin_Page__insert_update_cpt_item__attendee_update',
3471
-                array()
3472
-            );
3473
-            foreach ($attendee_update_callbacks as $a_callback) {
3474
-                if (false === call_user_func_array($a_callback, array($attendee, $this->_req_data))) {
3475
-                    throw new EE_Error(
3476
-                        sprintf(
3477
-                            esc_html__(
3478
-                                'The %s callback given for the "FHEE__Registrations_Admin_Page__insert_update_cpt_item__attendee_update" filter is not a valid callback.  Please check the spelling.',
3479
-                                'event_espresso'
3480
-                            ),
3481
-                            $a_callback
3482
-                        )
3483
-                    );
3484
-                }
3485
-            }
3486
-        }
3487
-
3488
-        if ($success === false) {
3489
-            EE_Error::add_error(
3490
-                esc_html__(
3491
-                    'Something went wrong with updating the meta table data for the registration.',
3492
-                    'event_espresso'
3493
-                ),
3494
-                __FILE__, __FUNCTION__, __LINE__
3495
-            );
3496
-        }
3497
-    }
3498
-
3499
-
3500
-    public function trash_cpt_item($post_id)
3501
-    {
3502
-    }
3503
-
3504
-
3505
-    public function delete_cpt_item($post_id)
3506
-    {
3507
-    }
3508
-
3509
-
3510
-    public function restore_cpt_item($post_id)
3511
-    {
3512
-    }
3513
-
3514
-
3515
-    protected function _restore_cpt_item($post_id, $revision_id)
3516
-    {
3517
-    }
3518
-
3519
-
3520
-    public function attendee_editor_metaboxes()
3521
-    {
3522
-        $this->verify_cpt_object();
3523
-        remove_meta_box(
3524
-            'postexcerpt',
3525
-            esc_html__('Excerpt', 'event_espresso'),
3526
-            'post_excerpt_meta_box',
3527
-            $this->_cpt_routes[$this->_req_action],
3528
-            'normal',
3529
-            'core'
3530
-        );
3531
-        remove_meta_box('commentstatusdiv', $this->_cpt_routes[$this->_req_action], 'normal', 'core');
3532
-        if (post_type_supports('espresso_attendees', 'excerpt')) {
3533
-            add_meta_box(
3534
-                'postexcerpt',
3535
-                esc_html__('Short Biography', 'event_espresso'),
3536
-                'post_excerpt_meta_box',
3537
-                $this->_cpt_routes[$this->_req_action],
3538
-                'normal'
3539
-            );
3540
-        }
3541
-        if (post_type_supports('espresso_attendees', 'comments')) {
3542
-            add_meta_box(
3543
-                'commentsdiv',
3544
-                esc_html__('Notes on the Contact', 'event_espresso'),
3545
-                'post_comment_meta_box',
3546
-                $this->_cpt_routes[$this->_req_action],
3547
-                'normal',
3548
-                'core'
3549
-            );
3550
-        }
3551
-        add_meta_box(
3552
-            'attendee_contact_info',
3553
-            esc_html__('Contact Info', 'event_espresso'),
3554
-            array($this, 'attendee_contact_info'),
3555
-            $this->_cpt_routes[$this->_req_action],
3556
-            'side',
3557
-            'core'
3558
-        );
3559
-        add_meta_box(
3560
-            'attendee_details_address',
3561
-            esc_html__('Address Details', 'event_espresso'),
3562
-            array($this, 'attendee_address_details'),
3563
-            $this->_cpt_routes[$this->_req_action],
3564
-            'normal',
3565
-            'core'
3566
-        );
3567
-        add_meta_box(
3568
-            'attendee_registrations',
3569
-            esc_html__('Registrations for this Contact', 'event_espresso'),
3570
-            array($this, 'attendee_registrations_meta_box'),
3571
-            $this->_cpt_routes[$this->_req_action],
3572
-            'normal',
3573
-            'high'
3574
-        );
3575
-    }
3576
-
3577
-
3578
-    /**
3579
-     * Metabox for attendee contact info
3580
-     *
3581
-     * @param  WP_Post $post wp post object
3582
-     * @return string attendee contact info ( and form )
3583
-     * @throws EE_Error
3584
-     * @throws InvalidArgumentException
3585
-     * @throws InvalidDataTypeException
3586
-     * @throws InvalidInterfaceException
3587
-     * @throws LogicException
3588
-     * @throws DomainException
3589
-     */
3590
-    public function attendee_contact_info($post)
3591
-    {
3592
-        //get attendee object ( should already have it )
3593
-        $form = $this->getAttendeeContactDetailsMetaboxFormHandler($this->_cpt_model_obj);
3594
-        $form->enqueueStylesAndScripts();
3595
-        echo $form->display();
3596
-    }
3597
-
3598
-
3599
-    /**
3600
-     * Return form handler for the contact details metabox
3601
-     *
3602
-     * @param EE_Attendee $attendee
3603
-     * @return AttendeeContactDetailsMetaboxFormHandler
3604
-     * @throws DomainException
3605
-     * @throws InvalidArgumentException
3606
-     * @throws InvalidDataTypeException
3607
-     * @throws InvalidInterfaceException
3608
-     */
3609
-    protected function getAttendeeContactDetailsMetaboxFormHandler(EE_Attendee $attendee)
3610
-    {
3611
-        return new AttendeeContactDetailsMetaboxFormHandler($attendee, EE_Registry::instance());
3612
-    }
3613
-
3614
-
3615
-    /**
3616
-     * Metabox for attendee details
3617
-     *
3618
-     * @param  WP_Post $post wp post object
3619
-     * @throws DomainException
3620
-     */
3621
-    public function attendee_address_details($post)
3622
-    {
3623
-        //get attendee object (should already have it)
3624
-        $this->_template_args['attendee']     = $this->_cpt_model_obj;
3625
-        $this->_template_args['state_html']   = EEH_Form_Fields::generate_form_input(
3626
-            new EE_Question_Form_Input(
3627
-                EE_Question::new_instance(
3628
-                    array(
3629
-                        'QST_ID'           => 0,
3630
-                        'QST_display_text' => esc_html__('State/Province', 'event_espresso'),
3631
-                        'QST_system'       => 'admin-state',
3632
-                    )
3633
-                ),
3634
-                EE_Answer::new_instance(
3635
-                    array(
3636
-                        'ANS_ID'    => 0,
3637
-                        'ANS_value' => $this->_cpt_model_obj->state_ID(),
3638
-                    )
3639
-                ),
3640
-                array(
3641
-                    'input_id'       => 'STA_ID',
3642
-                    'input_name'     => 'STA_ID',
3643
-                    'input_prefix'   => '',
3644
-                    'append_qstn_id' => false,
3645
-                )
3646
-            )
3647
-        );
3648
-        $this->_template_args['country_html'] = EEH_Form_Fields::generate_form_input(
3649
-            new EE_Question_Form_Input(
3650
-                EE_Question::new_instance(
3651
-                    array(
3652
-                        'QST_ID'           => 0,
3653
-                        'QST_display_text' => esc_html__('Country', 'event_espresso'),
3654
-                        'QST_system'       => 'admin-country',
3655
-                    )
3656
-                ),
3657
-                EE_Answer::new_instance(
3658
-                    array(
3659
-                        'ANS_ID'    => 0,
3660
-                        'ANS_value' => $this->_cpt_model_obj->country_ID(),
3661
-                    )
3662
-                ),
3663
-                array(
3664
-                    'input_id'       => 'CNT_ISO',
3665
-                    'input_name'     => 'CNT_ISO',
3666
-                    'input_prefix'   => '',
3667
-                    'append_qstn_id' => false,
3668
-                )
3669
-            )
3670
-        );
3671
-        $template                             =
3672
-            REG_TEMPLATE_PATH . 'attendee_address_details_metabox_content.template.php';
3673
-        EEH_Template::display_template($template, $this->_template_args);
3674
-    }
3675
-
3676
-
3677
-    /**
3678
-     *        _attendee_details
3679
-     *
3680
-     * @access protected
3681
-     * @param $post
3682
-     * @return void
3683
-     * @throws DomainException
3684
-     * @throws EE_Error
3685
-     */
3686
-    public function attendee_registrations_meta_box($post)
3687
-    {
3688
-        $this->_template_args['attendee']      = $this->_cpt_model_obj;
3689
-        $this->_template_args['registrations'] = $this->_cpt_model_obj->get_many_related('Registration');
3690
-        $template                              =
3691
-            REG_TEMPLATE_PATH . 'attendee_registrations_main_meta_box.template.php';
3692
-        EEH_Template::display_template($template, $this->_template_args);
3693
-    }
3694
-
3695
-
3696
-    /**
3697
-     * add in the form fields for the attendee edit
3698
-     *
3699
-     * @param  WP_Post $post wp post object
3700
-     * @return string html for new form.
3701
-     * @throws DomainException
3702
-     */
3703
-    public function after_title_form_fields($post)
3704
-    {
3705
-        if ($post->post_type == 'espresso_attendees') {
3706
-            $template                  = REG_TEMPLATE_PATH . 'attendee_details_after_title_form_fields.template.php';
3707
-            $template_args['attendee'] = $this->_cpt_model_obj;
3708
-            EEH_Template::display_template($template, $template_args);
3709
-        }
3710
-    }
3711
-
3712
-
3713
-    /**
3714
-     *        _trash_or_restore_attendee
3715
-     *
3716
-     * @param boolean $trash - whether to move item to trash (TRUE) or restore it (FALSE)
3717
-     * @return void
3718
-     * @throws EE_Error
3719
-     * @throws InvalidArgumentException
3720
-     * @throws InvalidDataTypeException
3721
-     * @throws InvalidInterfaceException
3722
-     * @access protected
3723
-     */
3724
-    protected function _trash_or_restore_attendees($trash = true)
3725
-    {
3726
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3727
-        $ATT_MDL = EEM_Attendee::instance();
3728
-        $success = 1;
3729
-        //Checkboxes
3730
-        if ( ! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
3731
-            // if array has more than one element than success message should be plural
3732
-            $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1;
3733
-            // cycle thru checkboxes
3734
-            while (list($ATT_ID, $value) = each($this->_req_data['checkbox'])) {
3735
-                $updated = $trash ? $ATT_MDL->update_by_ID(array('status' => 'trash'), $ATT_ID)
3736
-                    : $ATT_MDL->update_by_ID(array('status' => 'publish'), $ATT_ID);
3737
-                if ( ! $updated) {
3738
-                    $success = 0;
3739
-                }
3740
-            }
3741
-        } else {
3742
-            // grab single id and delete
3743
-            $ATT_ID = absint($this->_req_data['ATT_ID']);
3744
-            //get attendee
3745
-            $att     = $ATT_MDL->get_one_by_ID($ATT_ID);
3746
-            $updated = $trash ? $att->set_status('trash') : $att->set_status('publish');
3747
-            $updated = $att->save();
3748
-            if ( ! $updated) {
3749
-                $success = 0;
3750
-            }
3751
-        }
3752
-        $what        = $success > 1
3753
-            ? esc_html__('Contacts', 'event_espresso')
3754
-            : esc_html__('Contact', 'event_espresso');
3755
-        $action_desc = $trash
3756
-            ? esc_html__('moved to the trash', 'event_espresso')
3757
-            : esc_html__('restored', 'event_espresso');
3758
-        $this->_redirect_after_action($success, $what, $action_desc, array('action' => 'contact_list'));
3759
-    }
2918
+		}
2919
+		$template_args = array(
2920
+			'title'                    => '',
2921
+			'content'                  => '',
2922
+			'step_button_text'         => '',
2923
+			'show_notification_toggle' => false,
2924
+		);
2925
+		//to indicate we're processing a new registration
2926
+		$hidden_fields = array(
2927
+			'processing_registration' => array(
2928
+				'type'  => 'hidden',
2929
+				'value' => 0,
2930
+			),
2931
+			'event_id'                => array(
2932
+				'type'  => 'hidden',
2933
+				'value' => $this->_reg_event->ID(),
2934
+			),
2935
+		);
2936
+		//if the cart is empty then we know we're at step one so we'll display ticket selector
2937
+		$cart = EE_Registry::instance()->SSN->cart();
2938
+		$step = ! $cart instanceof EE_Cart ? 'ticket' : 'questions';
2939
+		switch ($step) {
2940
+			case 'ticket' :
2941
+				$hidden_fields['processing_registration']['value'] = 1;
2942
+				$template_args['title']                            = esc_html__(
2943
+					'Step One: Select the Ticket for this registration',
2944
+					'event_espresso'
2945
+				);
2946
+				$template_args['content']                          =
2947
+					EED_Ticket_Selector::instance()->display_ticket_selector($this->_reg_event);
2948
+				$template_args['step_button_text']                 = esc_html__(
2949
+					'Add Tickets and Continue to Registrant Details',
2950
+					'event_espresso'
2951
+				);
2952
+				$template_args['show_notification_toggle']         = false;
2953
+				break;
2954
+			case 'questions' :
2955
+				$hidden_fields['processing_registration']['value'] = 2;
2956
+				$template_args['title']                            = esc_html__(
2957
+					'Step Two: Add Registrant Details for this Registration',
2958
+					'event_espresso'
2959
+				);
2960
+				//in theory we should be able to run EED_SPCO at this point because the cart should have been setup
2961
+				// properly by the first process_reg_step run.
2962
+				$template_args['content']                  =
2963
+					EED_Single_Page_Checkout::registration_checkout_for_admin();
2964
+				$template_args['step_button_text']         = esc_html__(
2965
+					'Save Registration and Continue to Details',
2966
+					'event_espresso'
2967
+				);
2968
+				$template_args['show_notification_toggle'] = true;
2969
+				break;
2970
+		}
2971
+		//we come back to the process_registration_step route.
2972
+		$this->_set_add_edit_form_tags('process_reg_step', $hidden_fields);
2973
+		return EEH_Template::display_template(
2974
+			REG_TEMPLATE_PATH . 'reg_admin_register_new_attendee_step_content.template.php',
2975
+			$template_args,
2976
+			true
2977
+		);
2978
+	}
2979
+
2980
+
2981
+	/**
2982
+	 *        set_reg_event
2983
+	 *
2984
+	 * @access private
2985
+	 * @return bool
2986
+	 * @throws EE_Error
2987
+	 * @throws InvalidArgumentException
2988
+	 * @throws InvalidDataTypeException
2989
+	 * @throws InvalidInterfaceException
2990
+	 */
2991
+	private function _set_reg_event()
2992
+	{
2993
+		if (is_object($this->_reg_event)) {
2994
+			return true;
2995
+		}
2996
+		$EVT_ID = (! empty($this->_req_data['event_id'])) ? absint($this->_req_data['event_id']) : false;
2997
+		if ( ! $EVT_ID) {
2998
+			return false;
2999
+		}
3000
+		$this->_reg_event = EEM_Event::instance()->get_one_by_ID($EVT_ID);
3001
+		return true;
3002
+	}
3003
+
3004
+
3005
+	/**
3006
+	 * process_reg_step
3007
+	 *
3008
+	 * @access        public
3009
+	 * @return string
3010
+	 * @throws DomainException
3011
+	 * @throws EE_Error
3012
+	 * @throws InvalidArgumentException
3013
+	 * @throws InvalidDataTypeException
3014
+	 * @throws InvalidInterfaceException
3015
+	 * @throws ReflectionException
3016
+	 * @throws RuntimeException
3017
+	 */
3018
+	public function process_reg_step()
3019
+	{
3020
+		EE_System::do_not_cache();
3021
+		$this->_set_reg_event();
3022
+		EE_Registry::instance()->REQ->set_espresso_page(true);
3023
+		EE_Registry::instance()->REQ->set('uts', time());
3024
+		//what step are we on?
3025
+		$cart = EE_Registry::instance()->SSN->cart();
3026
+		$step = ! $cart instanceof EE_Cart ? 'ticket' : 'questions';
3027
+		//if doing ajax then we need to verify the nonce
3028
+		if (defined('DOING_AJAX')) {
3029
+			$nonce = isset($this->_req_data[$this->_req_nonce])
3030
+				? sanitize_text_field($this->_req_data[$this->_req_nonce]) : '';
3031
+			$this->_verify_nonce($nonce, $this->_req_nonce);
3032
+		}
3033
+		switch ($step) {
3034
+			case 'ticket' :
3035
+				//process ticket selection
3036
+				$success = EED_Ticket_Selector::instance()->process_ticket_selections();
3037
+				if ($success) {
3038
+					EE_Error::add_success(
3039
+						esc_html__(
3040
+							'Tickets Selected. Now complete the registration.',
3041
+							'event_espresso'
3042
+						)
3043
+					);
3044
+				} else {
3045
+					$query_args['step_error'] = $this->_req_data['step_error'] = true;
3046
+				}
3047
+				if (defined('DOING_AJAX')) {
3048
+					$this->new_registration(); //display next step
3049
+				} else {
3050
+					$query_args = array(
3051
+						'action'                  => 'new_registration',
3052
+						'processing_registration' => 1,
3053
+						'event_id'                => $this->_reg_event->ID(),
3054
+						'uts'                     => time(),
3055
+					);
3056
+					$this->_redirect_after_action(
3057
+						false,
3058
+						'',
3059
+						'',
3060
+						$query_args,
3061
+						true
3062
+					);
3063
+				}
3064
+				break;
3065
+			case 'questions' :
3066
+				if (! isset(
3067
+					$this->_req_data['txn_reg_status_change'],
3068
+					$this->_req_data['txn_reg_status_change']['send_notifications'])
3069
+				) {
3070
+					add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_false', 15);
3071
+				}
3072
+				//process registration
3073
+				$transaction = EED_Single_Page_Checkout::instance()->process_registration_from_admin();
3074
+				if ($cart instanceof EE_Cart) {
3075
+					$grand_total = $cart->get_cart_grand_total();
3076
+					if ($grand_total instanceof EE_Line_Item) {
3077
+						$grand_total->save_this_and_descendants_to_txn();
3078
+					}
3079
+				}
3080
+				if ( ! $transaction instanceof EE_Transaction) {
3081
+					$query_args = array(
3082
+						'action'                  => 'new_registration',
3083
+						'processing_registration' => 2,
3084
+						'event_id'                => $this->_reg_event->ID(),
3085
+						'uts'                     => time(),
3086
+					);
3087
+					if (defined('DOING_AJAX')) {
3088
+						//display registration form again because there are errors (maybe validation?)
3089
+						$this->new_registration();
3090
+						return;
3091
+					} else {
3092
+						$this->_redirect_after_action(
3093
+							false,
3094
+							'',
3095
+							'',
3096
+							$query_args,
3097
+							true
3098
+						);
3099
+						return;
3100
+					}
3101
+				}
3102
+				// maybe update status, and make sure to save transaction if not done already
3103
+				if ( ! $transaction->update_status_based_on_total_paid()) {
3104
+					$transaction->save();
3105
+				}
3106
+				EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
3107
+				$this->_req_data = array();
3108
+				$query_args      = array(
3109
+					'action'        => 'redirect_to_txn',
3110
+					'TXN_ID'        => $transaction->ID(),
3111
+					'EVT_ID'        => $this->_reg_event->ID(),
3112
+					'event_name'    => urlencode($this->_reg_event->name()),
3113
+					'redirect_from' => 'new_registration',
3114
+				);
3115
+				$this->_redirect_after_action(false, '', '', $query_args, true);
3116
+				break;
3117
+		}
3118
+		//what are you looking here for?  Should be nothing to do at this point.
3119
+	}
3120
+
3121
+
3122
+	/**
3123
+	 * redirect_to_txn
3124
+	 *
3125
+	 * @access public
3126
+	 * @return void
3127
+	 * @throws EE_Error
3128
+	 * @throws InvalidArgumentException
3129
+	 * @throws InvalidDataTypeException
3130
+	 * @throws InvalidInterfaceException
3131
+	 */
3132
+	public function redirect_to_txn()
3133
+	{
3134
+		EE_System::do_not_cache();
3135
+		EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
3136
+		$query_args = array(
3137
+			'action' => 'view_transaction',
3138
+			'TXN_ID' => isset($this->_req_data['TXN_ID']) ? absint($this->_req_data['TXN_ID']) : 0,
3139
+			'page'   => 'espresso_transactions',
3140
+		);
3141
+		if (isset($this->_req_data['EVT_ID'], $this->_req_data['redirect_from'])) {
3142
+			$query_args['EVT_ID']        = $this->_req_data['EVT_ID'];
3143
+			$query_args['event_name']    = urlencode($this->_req_data['event_name']);
3144
+			$query_args['redirect_from'] = $this->_req_data['redirect_from'];
3145
+		}
3146
+		EE_Error::add_success(
3147
+			esc_html__(
3148
+				'Registration Created.  Please review the transaction and add any payments as necessary',
3149
+				'event_espresso'
3150
+			)
3151
+		);
3152
+		$this->_redirect_after_action(false, '', '', $query_args, true);
3153
+	}
3154
+
3155
+
3156
+	/**
3157
+	 *        generates HTML for the Attendee Contact List
3158
+	 *
3159
+	 * @access protected
3160
+	 * @return void
3161
+	 */
3162
+	protected function _attendee_contact_list_table()
3163
+	{
3164
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3165
+		$this->_search_btn_label = esc_html__('Contacts', 'event_espresso');
3166
+		$this->display_admin_list_table_page_with_no_sidebar();
3167
+	}
3168
+
3169
+
3170
+	/**
3171
+	 *        get_attendees
3172
+	 *
3173
+	 * @param      $per_page
3174
+	 * @param bool $count whether to return count or data.
3175
+	 * @param bool $trash
3176
+	 * @return array
3177
+	 * @throws EE_Error
3178
+	 * @throws InvalidArgumentException
3179
+	 * @throws InvalidDataTypeException
3180
+	 * @throws InvalidInterfaceException
3181
+	 * @access public
3182
+	 */
3183
+	public function get_attendees($per_page, $count = false, $trash = false)
3184
+	{
3185
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3186
+		require_once(REG_ADMIN . 'EE_Attendee_Contact_List_Table.class.php');
3187
+		$ATT_MDL                    = EEM_Attendee::instance();
3188
+		$this->_req_data['orderby'] = ! empty($this->_req_data['orderby']) ? $this->_req_data['orderby'] : '';
3189
+		switch ($this->_req_data['orderby']) {
3190
+			case 'ATT_ID':
3191
+				$orderby = 'ATT_ID';
3192
+				break;
3193
+			case 'ATT_fname':
3194
+				$orderby = 'ATT_fname';
3195
+				break;
3196
+			case 'ATT_email':
3197
+				$orderby = 'ATT_email';
3198
+				break;
3199
+			case 'ATT_city':
3200
+				$orderby = 'ATT_city';
3201
+				break;
3202
+			case 'STA_ID':
3203
+				$orderby = 'STA_ID';
3204
+				break;
3205
+			case 'CNT_ID':
3206
+				$orderby = 'CNT_ID';
3207
+				break;
3208
+			default:
3209
+				$orderby = 'ATT_lname';
3210
+		}
3211
+		$sort         = (isset($this->_req_data['order']) && ! empty($this->_req_data['order']))
3212
+			? $this->_req_data['order']
3213
+			: 'ASC';
3214
+		$current_page = isset($this->_req_data['paged']) && ! empty($this->_req_data['paged'])
3215
+			? $this->_req_data['paged']
3216
+			: 1;
3217
+		$per_page     = isset($per_page) && ! empty($per_page) ? $per_page : 10;
3218
+		$per_page     = isset($this->_req_data['perpage']) && ! empty($this->_req_data['perpage'])
3219
+			? $this->_req_data['perpage']
3220
+			: $per_page;
3221
+		$_where       = array();
3222
+		if ( ! empty($this->_req_data['s'])) {
3223
+			$sstr         = '%' . $this->_req_data['s'] . '%';
3224
+			$_where['OR'] = array(
3225
+				'Registration.Event.EVT_name'       => array('LIKE', $sstr),
3226
+				'Registration.Event.EVT_desc'       => array('LIKE', $sstr),
3227
+				'Registration.Event.EVT_short_desc' => array('LIKE', $sstr),
3228
+				'ATT_fname'                         => array('LIKE', $sstr),
3229
+				'ATT_lname'                         => array('LIKE', $sstr),
3230
+				'ATT_short_bio'                     => array('LIKE', $sstr),
3231
+				'ATT_email'                         => array('LIKE', $sstr),
3232
+				'ATT_address'                       => array('LIKE', $sstr),
3233
+				'ATT_address2'                      => array('LIKE', $sstr),
3234
+				'ATT_city'                          => array('LIKE', $sstr),
3235
+				'Country.CNT_name'                  => array('LIKE', $sstr),
3236
+				'State.STA_name'                    => array('LIKE', $sstr),
3237
+				'ATT_phone'                         => array('LIKE', $sstr),
3238
+				'Registration.REG_final_price'      => array('LIKE', $sstr),
3239
+				'Registration.REG_code'             => array('LIKE', $sstr),
3240
+				'Registration.REG_count'            => array('LIKE', $sstr),
3241
+				'Registration.REG_group_size'       => array('LIKE', $sstr),
3242
+			);
3243
+		}
3244
+		$offset = ($current_page - 1) * $per_page;
3245
+		$limit  = $count ? null : array($offset, $per_page);
3246
+		if ($trash) {
3247
+			$_where['status'] = array('!=', 'publish');
3248
+			$all_attendees    = $count
3249
+				? $ATT_MDL->count(array(
3250
+					$_where,
3251
+					'order_by' => array($orderby => $sort),
3252
+					'limit'    => $limit,
3253
+				), 'ATT_ID', true)
3254
+				: $ATT_MDL->get_all(array(
3255
+					$_where,
3256
+					'order_by' => array($orderby => $sort),
3257
+					'limit'    => $limit,
3258
+				));
3259
+		} else {
3260
+			$_where['status'] = array('IN', array('publish'));
3261
+			$all_attendees    = $count
3262
+				? $ATT_MDL->count(array(
3263
+					$_where,
3264
+					'order_by' => array($orderby => $sort),
3265
+					'limit'    => $limit,
3266
+				), 'ATT_ID', true)
3267
+				: $ATT_MDL->get_all(array(
3268
+					$_where,
3269
+					'order_by' => array($orderby => $sort),
3270
+					'limit'    => $limit,
3271
+				));
3272
+		}
3273
+		return $all_attendees;
3274
+	}
3275
+
3276
+
3277
+	/**
3278
+	 * This is just taking care of resending the registration confirmation
3279
+	 *
3280
+	 * @access protected
3281
+	 * @return void
3282
+	 */
3283
+	protected function _resend_registration()
3284
+	{
3285
+		$this->_process_resend_registration();
3286
+		$query_args = isset($this->_req_data['redirect_to'])
3287
+			? array('action' => $this->_req_data['redirect_to'], '_REG_ID' => $this->_req_data['_REG_ID'])
3288
+			: array('action' => 'default');
3289
+		$this->_redirect_after_action(false, '', '', $query_args, true);
3290
+	}
3291
+
3292
+	/**
3293
+	 * Creates a registration report, but accepts the name of a method to use for preparing the query parameters
3294
+	 * to use when selecting registrations
3295
+	 * @param string $method_name_for_getting_query_params the name of the method (on this class) to use for preparing
3296
+	 *                                                     the query parameters from the request
3297
+	 * @return void ends the request with a redirect or download
3298
+	 */
3299
+	public function _registrations_report_base( $method_name_for_getting_query_params )
3300
+	{
3301
+		if (! defined('EE_USE_OLD_CSV_REPORT_CLASS')) {
3302
+			wp_redirect(EE_Admin_Page::add_query_args_and_nonce(
3303
+				array(
3304
+					'page'        => 'espresso_batch',
3305
+					'batch'       => 'file',
3306
+					'EVT_ID'      => isset($this->_req_data['EVT_ID']) ? $this->_req_data['EVT_ID'] : null,
3307
+					'filters'     => urlencode(
3308
+						serialize(
3309
+							call_user_func(
3310
+								array( $this, $method_name_for_getting_query_params ),
3311
+								EEH_Array::is_set(
3312
+									$this->_req_data,
3313
+									'filters',
3314
+									array()
3315
+								)
3316
+							)
3317
+						)
3318
+				),
3319
+				'use_filters' => EEH_Array::is_set($this->_req_data, 'use_filters', false),
3320
+				'job_handler' => urlencode('EventEspressoBatchRequest\JobHandlers\RegistrationsReport'),
3321
+				'return_url'  => urlencode($this->_req_data['return_url']),
3322
+			)));
3323
+		} else {
3324
+			$new_request_args = array(
3325
+				'export' => 'report',
3326
+				'action' => 'registrations_report_for_event',
3327
+				'EVT_ID' => isset($this->_req_data['EVT_ID']) ? $this->_req_data['EVT_ID'] : null,
3328
+			);
3329
+			$this->_req_data = array_merge($this->_req_data, $new_request_args);
3330
+			if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
3331
+				require_once(EE_CLASSES . 'EE_Export.class.php');
3332
+				$EE_Export = EE_Export::instance($this->_req_data);
3333
+				$EE_Export->export();
3334
+			}
3335
+		}
3336
+	}
3337
+
3338
+
3339
+
3340
+	/**
3341
+	 * Creates a registration report using only query parameters in the request
3342
+	 * @return void
3343
+	 */
3344
+	public function _registrations_report()
3345
+	{
3346
+		$this->_registrations_report_base('_get_registration_query_parameters');
3347
+	}
3348
+
3349
+
3350
+	public function _contact_list_export()
3351
+	{
3352
+		if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
3353
+			require_once(EE_CLASSES . 'EE_Export.class.php');
3354
+			$EE_Export = EE_Export::instance($this->_req_data);
3355
+			$EE_Export->export_attendees();
3356
+		}
3357
+	}
3358
+
3359
+
3360
+	public function _contact_list_report()
3361
+	{
3362
+		if ( ! defined('EE_USE_OLD_CSV_REPORT_CLASS')) {
3363
+			wp_redirect(EE_Admin_Page::add_query_args_and_nonce(array(
3364
+				'page'        => 'espresso_batch',
3365
+				'batch'       => 'file',
3366
+				'job_handler' => urlencode('EventEspressoBatchRequest\JobHandlers\AttendeesReport'),
3367
+				'return_url'  => urlencode($this->_req_data['return_url']),
3368
+			)));
3369
+		} else {
3370
+			if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
3371
+				require_once(EE_CLASSES . 'EE_Export.class.php');
3372
+				$EE_Export = EE_Export::instance($this->_req_data);
3373
+				$EE_Export->report_attendees();
3374
+			}
3375
+		}
3376
+	}
3377
+
3378
+
3379
+
3380
+
3381
+
3382
+	/***************************************        ATTENDEE DETAILS        ***************************************/
3383
+	/**
3384
+	 * This duplicates the attendee object for the given incoming registration id and attendee_id.
3385
+	 *
3386
+	 * @return void
3387
+	 * @throws EE_Error
3388
+	 * @throws InvalidArgumentException
3389
+	 * @throws InvalidDataTypeException
3390
+	 * @throws InvalidInterfaceException
3391
+	 */
3392
+	protected function _duplicate_attendee()
3393
+	{
3394
+		$action = ! empty($this->_req_data['return']) ? $this->_req_data['return'] : 'default';
3395
+		//verify we have necessary info
3396
+		if (empty($this->_req_data['_REG_ID'])) {
3397
+			EE_Error::add_error(
3398
+				esc_html__(
3399
+					'Unable to create the contact for the registration because the required parameters are not present (_REG_ID )',
3400
+					'event_espresso'
3401
+				), __FILE__, __LINE__, __FUNCTION__
3402
+			);
3403
+			$query_args = array('action' => $action);
3404
+			$this->_redirect_after_action('', '', '', $query_args, true);
3405
+		}
3406
+		//okay necessary deets present... let's dupe the incoming attendee and attach to incoming registration.
3407
+		$registration = EEM_Registration::instance()->get_one_by_ID($this->_req_data['_REG_ID']);
3408
+		$attendee     = $registration->attendee();
3409
+		//remove relation of existing attendee on registration
3410
+		$registration->_remove_relation_to($attendee, 'Attendee');
3411
+		//new attendee
3412
+		$new_attendee = clone $attendee;
3413
+		$new_attendee->set('ATT_ID', 0);
3414
+		$new_attendee->save();
3415
+		//add new attendee to reg
3416
+		$registration->_add_relation_to($new_attendee, 'Attendee');
3417
+		EE_Error::add_success(
3418
+			esc_html__(
3419
+				'New Contact record created.  Now make any edits you wish to make for this contact.',
3420
+				'event_espresso'
3421
+			)
3422
+		);
3423
+		//redirect to edit page for attendee
3424
+		$query_args = array('post' => $new_attendee->ID(), 'action' => 'edit_attendee');
3425
+		$this->_redirect_after_action('', '', '', $query_args, true);
3426
+	}
3427
+
3428
+
3429
+	/**
3430
+	 * Callback invoked by parent EE_Admin_CPT class hooked in on `save_post` wp hook.
3431
+	 * @param int      $post_id
3432
+	 * @param WP_POST $post
3433
+	 * @throws DomainException
3434
+	 * @throws EE_Error
3435
+	 * @throws InvalidArgumentException
3436
+	 * @throws InvalidDataTypeException
3437
+	 * @throws InvalidInterfaceException
3438
+	 * @throws LogicException
3439
+	 * @throws InvalidFormSubmissionException
3440
+	 */
3441
+	protected function _insert_update_cpt_item($post_id, $post)
3442
+	{
3443
+		$success  = true;
3444
+		$attendee = $post instanceof WP_Post && $post->post_type === 'espresso_attendees'
3445
+			? EEM_Attendee::instance()->get_one_by_ID($post_id)
3446
+			: null;
3447
+		//for attendee updates
3448
+		if ($attendee instanceof EE_Attendee) {
3449
+			//note we should only be UPDATING attendees at this point.
3450
+			$updated_fields = array(
3451
+				'ATT_fname'     => $this->_req_data['ATT_fname'],
3452
+				'ATT_lname'     => $this->_req_data['ATT_lname'],
3453
+				'ATT_full_name' => $this->_req_data['ATT_fname'] . ' ' . $this->_req_data['ATT_lname'],
3454
+				'ATT_address'   => isset($this->_req_data['ATT_address']) ? $this->_req_data['ATT_address'] : '',
3455
+				'ATT_address2'  => isset($this->_req_data['ATT_address2']) ? $this->_req_data['ATT_address2'] : '',
3456
+				'ATT_city'      => isset($this->_req_data['ATT_city']) ? $this->_req_data['ATT_city'] : '',
3457
+				'STA_ID'        => isset($this->_req_data['STA_ID']) ? $this->_req_data['STA_ID'] : '',
3458
+				'CNT_ISO'       => isset($this->_req_data['CNT_ISO']) ? $this->_req_data['CNT_ISO'] : '',
3459
+				'ATT_zip'       => isset($this->_req_data['ATT_zip']) ? $this->_req_data['ATT_zip'] : '',
3460
+			);
3461
+			foreach ($updated_fields as $field => $value) {
3462
+				$attendee->set($field, $value);
3463
+			}
3464
+
3465
+			//process contact details metabox form handler (which will also save the attendee)
3466
+			$contact_details_form = $this->getAttendeeContactDetailsMetaboxFormHandler($attendee);
3467
+			$success = $contact_details_form->process($this->_req_data);
3468
+
3469
+			$attendee_update_callbacks = apply_filters(
3470
+				'FHEE__Registrations_Admin_Page__insert_update_cpt_item__attendee_update',
3471
+				array()
3472
+			);
3473
+			foreach ($attendee_update_callbacks as $a_callback) {
3474
+				if (false === call_user_func_array($a_callback, array($attendee, $this->_req_data))) {
3475
+					throw new EE_Error(
3476
+						sprintf(
3477
+							esc_html__(
3478
+								'The %s callback given for the "FHEE__Registrations_Admin_Page__insert_update_cpt_item__attendee_update" filter is not a valid callback.  Please check the spelling.',
3479
+								'event_espresso'
3480
+							),
3481
+							$a_callback
3482
+						)
3483
+					);
3484
+				}
3485
+			}
3486
+		}
3487
+
3488
+		if ($success === false) {
3489
+			EE_Error::add_error(
3490
+				esc_html__(
3491
+					'Something went wrong with updating the meta table data for the registration.',
3492
+					'event_espresso'
3493
+				),
3494
+				__FILE__, __FUNCTION__, __LINE__
3495
+			);
3496
+		}
3497
+	}
3498
+
3499
+
3500
+	public function trash_cpt_item($post_id)
3501
+	{
3502
+	}
3503
+
3504
+
3505
+	public function delete_cpt_item($post_id)
3506
+	{
3507
+	}
3508
+
3509
+
3510
+	public function restore_cpt_item($post_id)
3511
+	{
3512
+	}
3513
+
3514
+
3515
+	protected function _restore_cpt_item($post_id, $revision_id)
3516
+	{
3517
+	}
3518
+
3519
+
3520
+	public function attendee_editor_metaboxes()
3521
+	{
3522
+		$this->verify_cpt_object();
3523
+		remove_meta_box(
3524
+			'postexcerpt',
3525
+			esc_html__('Excerpt', 'event_espresso'),
3526
+			'post_excerpt_meta_box',
3527
+			$this->_cpt_routes[$this->_req_action],
3528
+			'normal',
3529
+			'core'
3530
+		);
3531
+		remove_meta_box('commentstatusdiv', $this->_cpt_routes[$this->_req_action], 'normal', 'core');
3532
+		if (post_type_supports('espresso_attendees', 'excerpt')) {
3533
+			add_meta_box(
3534
+				'postexcerpt',
3535
+				esc_html__('Short Biography', 'event_espresso'),
3536
+				'post_excerpt_meta_box',
3537
+				$this->_cpt_routes[$this->_req_action],
3538
+				'normal'
3539
+			);
3540
+		}
3541
+		if (post_type_supports('espresso_attendees', 'comments')) {
3542
+			add_meta_box(
3543
+				'commentsdiv',
3544
+				esc_html__('Notes on the Contact', 'event_espresso'),
3545
+				'post_comment_meta_box',
3546
+				$this->_cpt_routes[$this->_req_action],
3547
+				'normal',
3548
+				'core'
3549
+			);
3550
+		}
3551
+		add_meta_box(
3552
+			'attendee_contact_info',
3553
+			esc_html__('Contact Info', 'event_espresso'),
3554
+			array($this, 'attendee_contact_info'),
3555
+			$this->_cpt_routes[$this->_req_action],
3556
+			'side',
3557
+			'core'
3558
+		);
3559
+		add_meta_box(
3560
+			'attendee_details_address',
3561
+			esc_html__('Address Details', 'event_espresso'),
3562
+			array($this, 'attendee_address_details'),
3563
+			$this->_cpt_routes[$this->_req_action],
3564
+			'normal',
3565
+			'core'
3566
+		);
3567
+		add_meta_box(
3568
+			'attendee_registrations',
3569
+			esc_html__('Registrations for this Contact', 'event_espresso'),
3570
+			array($this, 'attendee_registrations_meta_box'),
3571
+			$this->_cpt_routes[$this->_req_action],
3572
+			'normal',
3573
+			'high'
3574
+		);
3575
+	}
3576
+
3577
+
3578
+	/**
3579
+	 * Metabox for attendee contact info
3580
+	 *
3581
+	 * @param  WP_Post $post wp post object
3582
+	 * @return string attendee contact info ( and form )
3583
+	 * @throws EE_Error
3584
+	 * @throws InvalidArgumentException
3585
+	 * @throws InvalidDataTypeException
3586
+	 * @throws InvalidInterfaceException
3587
+	 * @throws LogicException
3588
+	 * @throws DomainException
3589
+	 */
3590
+	public function attendee_contact_info($post)
3591
+	{
3592
+		//get attendee object ( should already have it )
3593
+		$form = $this->getAttendeeContactDetailsMetaboxFormHandler($this->_cpt_model_obj);
3594
+		$form->enqueueStylesAndScripts();
3595
+		echo $form->display();
3596
+	}
3597
+
3598
+
3599
+	/**
3600
+	 * Return form handler for the contact details metabox
3601
+	 *
3602
+	 * @param EE_Attendee $attendee
3603
+	 * @return AttendeeContactDetailsMetaboxFormHandler
3604
+	 * @throws DomainException
3605
+	 * @throws InvalidArgumentException
3606
+	 * @throws InvalidDataTypeException
3607
+	 * @throws InvalidInterfaceException
3608
+	 */
3609
+	protected function getAttendeeContactDetailsMetaboxFormHandler(EE_Attendee $attendee)
3610
+	{
3611
+		return new AttendeeContactDetailsMetaboxFormHandler($attendee, EE_Registry::instance());
3612
+	}
3613
+
3614
+
3615
+	/**
3616
+	 * Metabox for attendee details
3617
+	 *
3618
+	 * @param  WP_Post $post wp post object
3619
+	 * @throws DomainException
3620
+	 */
3621
+	public function attendee_address_details($post)
3622
+	{
3623
+		//get attendee object (should already have it)
3624
+		$this->_template_args['attendee']     = $this->_cpt_model_obj;
3625
+		$this->_template_args['state_html']   = EEH_Form_Fields::generate_form_input(
3626
+			new EE_Question_Form_Input(
3627
+				EE_Question::new_instance(
3628
+					array(
3629
+						'QST_ID'           => 0,
3630
+						'QST_display_text' => esc_html__('State/Province', 'event_espresso'),
3631
+						'QST_system'       => 'admin-state',
3632
+					)
3633
+				),
3634
+				EE_Answer::new_instance(
3635
+					array(
3636
+						'ANS_ID'    => 0,
3637
+						'ANS_value' => $this->_cpt_model_obj->state_ID(),
3638
+					)
3639
+				),
3640
+				array(
3641
+					'input_id'       => 'STA_ID',
3642
+					'input_name'     => 'STA_ID',
3643
+					'input_prefix'   => '',
3644
+					'append_qstn_id' => false,
3645
+				)
3646
+			)
3647
+		);
3648
+		$this->_template_args['country_html'] = EEH_Form_Fields::generate_form_input(
3649
+			new EE_Question_Form_Input(
3650
+				EE_Question::new_instance(
3651
+					array(
3652
+						'QST_ID'           => 0,
3653
+						'QST_display_text' => esc_html__('Country', 'event_espresso'),
3654
+						'QST_system'       => 'admin-country',
3655
+					)
3656
+				),
3657
+				EE_Answer::new_instance(
3658
+					array(
3659
+						'ANS_ID'    => 0,
3660
+						'ANS_value' => $this->_cpt_model_obj->country_ID(),
3661
+					)
3662
+				),
3663
+				array(
3664
+					'input_id'       => 'CNT_ISO',
3665
+					'input_name'     => 'CNT_ISO',
3666
+					'input_prefix'   => '',
3667
+					'append_qstn_id' => false,
3668
+				)
3669
+			)
3670
+		);
3671
+		$template                             =
3672
+			REG_TEMPLATE_PATH . 'attendee_address_details_metabox_content.template.php';
3673
+		EEH_Template::display_template($template, $this->_template_args);
3674
+	}
3675
+
3676
+
3677
+	/**
3678
+	 *        _attendee_details
3679
+	 *
3680
+	 * @access protected
3681
+	 * @param $post
3682
+	 * @return void
3683
+	 * @throws DomainException
3684
+	 * @throws EE_Error
3685
+	 */
3686
+	public function attendee_registrations_meta_box($post)
3687
+	{
3688
+		$this->_template_args['attendee']      = $this->_cpt_model_obj;
3689
+		$this->_template_args['registrations'] = $this->_cpt_model_obj->get_many_related('Registration');
3690
+		$template                              =
3691
+			REG_TEMPLATE_PATH . 'attendee_registrations_main_meta_box.template.php';
3692
+		EEH_Template::display_template($template, $this->_template_args);
3693
+	}
3694
+
3695
+
3696
+	/**
3697
+	 * add in the form fields for the attendee edit
3698
+	 *
3699
+	 * @param  WP_Post $post wp post object
3700
+	 * @return string html for new form.
3701
+	 * @throws DomainException
3702
+	 */
3703
+	public function after_title_form_fields($post)
3704
+	{
3705
+		if ($post->post_type == 'espresso_attendees') {
3706
+			$template                  = REG_TEMPLATE_PATH . 'attendee_details_after_title_form_fields.template.php';
3707
+			$template_args['attendee'] = $this->_cpt_model_obj;
3708
+			EEH_Template::display_template($template, $template_args);
3709
+		}
3710
+	}
3711
+
3712
+
3713
+	/**
3714
+	 *        _trash_or_restore_attendee
3715
+	 *
3716
+	 * @param boolean $trash - whether to move item to trash (TRUE) or restore it (FALSE)
3717
+	 * @return void
3718
+	 * @throws EE_Error
3719
+	 * @throws InvalidArgumentException
3720
+	 * @throws InvalidDataTypeException
3721
+	 * @throws InvalidInterfaceException
3722
+	 * @access protected
3723
+	 */
3724
+	protected function _trash_or_restore_attendees($trash = true)
3725
+	{
3726
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3727
+		$ATT_MDL = EEM_Attendee::instance();
3728
+		$success = 1;
3729
+		//Checkboxes
3730
+		if ( ! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
3731
+			// if array has more than one element than success message should be plural
3732
+			$success = count($this->_req_data['checkbox']) > 1 ? 2 : 1;
3733
+			// cycle thru checkboxes
3734
+			while (list($ATT_ID, $value) = each($this->_req_data['checkbox'])) {
3735
+				$updated = $trash ? $ATT_MDL->update_by_ID(array('status' => 'trash'), $ATT_ID)
3736
+					: $ATT_MDL->update_by_ID(array('status' => 'publish'), $ATT_ID);
3737
+				if ( ! $updated) {
3738
+					$success = 0;
3739
+				}
3740
+			}
3741
+		} else {
3742
+			// grab single id and delete
3743
+			$ATT_ID = absint($this->_req_data['ATT_ID']);
3744
+			//get attendee
3745
+			$att     = $ATT_MDL->get_one_by_ID($ATT_ID);
3746
+			$updated = $trash ? $att->set_status('trash') : $att->set_status('publish');
3747
+			$updated = $att->save();
3748
+			if ( ! $updated) {
3749
+				$success = 0;
3750
+			}
3751
+		}
3752
+		$what        = $success > 1
3753
+			? esc_html__('Contacts', 'event_espresso')
3754
+			: esc_html__('Contact', 'event_espresso');
3755
+		$action_desc = $trash
3756
+			? esc_html__('moved to the trash', 'event_espresso')
3757
+			: esc_html__('restored', 'event_espresso');
3758
+		$this->_redirect_after_action($success, $what, $action_desc, array('action' => 'contact_list'));
3759
+	}
3760 3760
 
3761 3761
 }
Please login to merge, or discard this patch.
core/db_models/EEM_CPT_Base.model.php 2 patches
Indentation   +514 added lines, -514 removed lines patch added patch discarded remove patch
@@ -18,519 +18,519 @@
 block discarded – undo
18 18
 abstract class EEM_CPT_Base extends EEM_Soft_Delete_Base
19 19
 {
20 20
 
21
-    /**
22
-     * @var string post_status_publish - the wp post status for published cpts
23
-     */
24
-    const post_status_publish = 'publish';
25
-
26
-    /**
27
-     * @var string post_status_future - the wp post status for scheduled cpts
28
-     */
29
-    const post_status_future = 'future';
30
-
31
-    /**
32
-     * @var string post_status_draft - the wp post status for draft cpts
33
-     */
34
-    const post_status_draft = 'draft';
35
-
36
-    /**
37
-     * @var string post_status_pending - the wp post status for pending cpts
38
-     */
39
-    const post_status_pending = 'pending';
40
-
41
-    /**
42
-     * @var string post_status_private - the wp post status for private cpts
43
-     */
44
-    const post_status_private = 'private';
45
-
46
-    /**
47
-     * @var string post_status_trashed - the wp post status for trashed cpts
48
-     */
49
-    const post_status_trashed = 'trash';
50
-
51
-    /**
52
-     * This is an array of custom statuses for the given CPT model (modified by children)
53
-     * format:
54
-     * array(
55
-     *        'status_name' => array(
56
-     *            'label' => __('Status Name', 'event_espresso'),
57
-     *            'public' => TRUE //whether a public status or not.
58
-     *        )
59
-     * )
60
-     *
61
-     * @var array
62
-     */
63
-    protected $_custom_stati = array();
64
-
65
-
66
-
67
-    /**
68
-     * Adds a relationship to Term_Taxonomy for each CPT_Base
69
-     *
70
-     * @param string $timezone
71
-     * @throws \EE_Error
72
-     */
73
-    protected function __construct($timezone = null)
74
-    {
75
-        //adds a relationship to Term_Taxonomy for all these models. For this to work
76
-        //Term_Relationship must have a relation to each model subclassing EE_CPT_Base explicitly
77
-        //eg, in EEM_Term_Relationship, inside the _model_relations array, there must be an entry
78
-        //with key equalling the subclassing model's model name (eg 'Event' or 'Venue'), and the value
79
-        //must also be new EE_HABTM_Relation('Term_Relationship');
80
-        $this->_model_relations['Term_Taxonomy'] = new EE_HABTM_Relation('Term_Relationship');
81
-        $primary_table_name = null;
82
-        //add  the common _status field to all CPT primary tables.
83
-        foreach ($this->_tables as $alias => $table_obj) {
84
-            if ($table_obj instanceof EE_Primary_Table) {
85
-                $primary_table_name = $alias;
86
-            }
87
-        }
88
-        //set default wp post statuses if child has not already set.
89
-        if ( ! isset($this->_fields[$primary_table_name]['status'])) {
90
-            $this->_fields[$primary_table_name]['status'] = new EE_WP_Post_Status_Field('post_status',
91
-                __("Event Status", "event_espresso"), false, 'draft');
92
-        }
93
-        if ( ! isset($this->_fields[$primary_table_name]['to_ping'])) {
94
-            $this->_fields[$primary_table_name]['to_ping'] = new EE_DB_Only_Text_Field('to_ping',
95
-                __('To Ping', 'event_espresso'), false, '');
96
-        }
97
-        if ( ! isset($this->_fields[$primary_table_name]['pinged'])) {
98
-            $this->_fields[$primary_table_name]['pinged'] = new EE_DB_Only_Text_Field('pinged',
99
-                __('Pinged', 'event_espresso'), false, '');
100
-        }
101
-        if ( ! isset($this->_fields[$primary_table_name]['comment_status'])) {
102
-            $this->_fields[$primary_table_name]['comment_status'] = new EE_Plain_Text_Field('comment_status',
103
-                __('Comment Status', 'event_espresso'), false, 'open');
104
-        }
105
-        if ( ! isset($this->_fields[$primary_table_name]['ping_status'])) {
106
-            $this->_fields[$primary_table_name]['ping_status'] = new EE_Plain_Text_Field('ping_status',
107
-                __('Ping Status', 'event_espresso'), false, 'open');
108
-        }
109
-        if ( ! isset($this->_fields[$primary_table_name]['post_content_filtered'])) {
110
-            $this->_fields[$primary_table_name]['post_content_filtered'] = new EE_DB_Only_Text_Field('post_content_filtered',
111
-                __('Post Content Filtered', 'event_espresso'), false, '');
112
-        }
113
-        if ( ! isset($this->_model_relations['Post_Meta'])) {
114
-            //don't block deletes though because we want to maintain the current behaviour
115
-            $this->_model_relations['Post_Meta'] = new EE_Has_Many_Relation(false);
116
-        }
117
-        if ( ! $this->_minimum_where_conditions_strategy instanceof EE_Default_Where_Conditions) {
118
-            //nothing was set during child constructor, so set default
119
-            $this->_minimum_where_conditions_strategy = new EE_CPT_Minimum_Where_Conditions($this->post_type());
120
-        }
121
-        if ( ! $this->_default_where_conditions_strategy instanceof EE_Default_Where_Conditions) {
122
-            //nothing was set during child constructor, so set default
123
-            //it's ok for child classes to specify this, but generally this is more DRY
124
-            $this->_default_where_conditions_strategy = new EE_CPT_Where_Conditions($this->post_type());
125
-        }
126
-        parent::__construct($timezone);
127
-    }
128
-
129
-
130
-
131
-    /**
132
-     * @return array
133
-     */
134
-    public function public_event_stati()
135
-    {
136
-        // @see wp-includes/post.php
137
-        return get_post_stati(array('public' => true));
138
-    }
139
-
140
-
141
-
142
-    /**
143
-     * Searches for field on this model of type 'deleted_flag'. if it is found,
144
-     * returns it's name. BUT That doesn't apply to CPTs. We should instead use post_status_field_name
145
-     *
146
-     * @return string
147
-     * @throws EE_Error
148
-     */
149
-    public function deleted_field_name()
150
-    {
151
-        throw new EE_Error(sprintf(__("EEM_CPT_Base should nto call deleted_field_name! It should instead use post_status_field_name",
152
-            "event_espresso")));
153
-    }
154
-
155
-
156
-
157
-    /**
158
-     * Gets the field's name that sets the post status
159
-     *
160
-     * @return string
161
-     * @throws EE_Error
162
-     */
163
-    public function post_status_field_name()
164
-    {
165
-        $field = $this->get_a_field_of_type('EE_WP_Post_Status_Field');
166
-        if ($field) {
167
-            return $field->get_name();
168
-        } else {
169
-            throw new EE_Error(sprintf(__('We are trying to find the post status flag field on %s, but none was found. Are you sure there is a field of type EE_Trashed_Flag_Field in %s constructor?',
170
-                'event_espresso'), get_class($this), get_class($this)));
171
-        }
172
-    }
173
-
174
-
175
-
176
-    /**
177
-     * Alters the query params so that only trashed/soft-deleted items are considered
178
-     *
179
-     * @param array $query_params like EEM_Base::get_all's $query_params
180
-     * @return array like EEM_Base::get_all's $query_params
181
-     */
182
-    protected function _alter_query_params_so_only_trashed_items_included($query_params)
183
-    {
184
-        $post_status_field_name = $this->post_status_field_name();
185
-        $query_params[0][$post_status_field_name] = self::post_status_trashed;
186
-        return $query_params;
187
-    }
188
-
189
-
190
-
191
-    /**
192
-     * Alters the query params so each item's deleted status is ignored.
193
-     *
194
-     * @param array $query_params
195
-     * @return array
196
-     */
197
-    protected function _alter_query_params_so_deleted_and_undeleted_items_included($query_params)
198
-    {
199
-        $query_params['default_where_conditions'] = 'minimum';
200
-        return $query_params;
201
-    }
202
-
203
-
204
-
205
-    /**
206
-     * Performs deletes or restores on items. Both soft-deleted and non-soft-deleted items considered.
207
-     *
208
-     * @param boolean $delete       true to indicate deletion, false to indicate restoration
209
-     * @param array   $query_params like EEM_Base::get_all
210
-     * @return boolean success
211
-     */
212
-    function delete_or_restore($delete = true, $query_params = array())
213
-    {
214
-        $post_status_field_name = $this->post_status_field_name();
215
-        $query_params = $this->_alter_query_params_so_deleted_and_undeleted_items_included($query_params);
216
-        $new_status = $delete ? self::post_status_trashed : 'draft';
217
-        if ($this->update(array($post_status_field_name => $new_status), $query_params)) {
218
-            return true;
219
-        } else {
220
-            return false;
221
-        }
222
-    }
223
-
224
-
225
-
226
-    /**
227
-     * meta_table
228
-     * returns first EE_Secondary_Table table name
229
-     *
230
-     * @access public
231
-     * @return string
232
-     */
233
-    public function meta_table()
234
-    {
235
-        $meta_table = $this->_get_other_tables();
236
-        $meta_table = reset($meta_table);
237
-        return $meta_table instanceof EE_Secondary_Table ? $meta_table->get_table_name() : null;
238
-    }
239
-
240
-
241
-
242
-    /**
243
-     * This simply returns an array of the meta table fields (useful for when we just need to update those fields)
244
-     *
245
-     * @param  bool $all triggers whether we include DB_Only fields or JUST non DB_Only fields.  Defaults to false (no
246
-     *                   db only fields)
247
-     * @return array
248
-     */
249
-    public function get_meta_table_fields($all = false)
250
-    {
251
-        $all_fields = $fields_to_return = array();
252
-        foreach ($this->_tables as $alias => $table_obj) {
253
-            if ($table_obj instanceof EE_Secondary_Table) {
254
-                $all_fields = array_merge($this->_get_fields_for_table($alias), $all_fields);
255
-            }
256
-        }
257
-        if ( ! $all) {
258
-            foreach ($all_fields as $name => $obj) {
259
-                if ($obj instanceof EE_DB_Only_Field_Base) {
260
-                    continue;
261
-                }
262
-                $fields_to_return[] = $name;
263
-            }
264
-        } else {
265
-            $fields_to_return = array_keys($all_fields);
266
-        }
267
-        return $fields_to_return;
268
-    }
269
-
270
-
271
-
272
-    /**
273
-     * Adds an event category with the specified name and description to the specified
274
-     * $cpt_model_object. Intelligently adds a term if necessary, and adds a term_taxonomy if necessary,
275
-     * and adds an entry in the term_relationship if necessary.
276
-     *
277
-     * @param EE_CPT_Base $cpt_model_object
278
-     * @param string      $category_name (used to derive the term slug too)
279
-     * @param string      $category_description
280
-     * @param int         $parent_term_taxonomy_id
281
-     * @return EE_Term_Taxonomy
282
-     */
283
-    function add_event_category(
284
-        EE_CPT_Base $cpt_model_object,
285
-        $category_name,
286
-        $category_description = '',
287
-        $parent_term_taxonomy_id = null
288
-    ) {
289
-        //create term
290
-        require_once(EE_MODELS . 'EEM_Term.model.php');
291
-        //first, check for a term by the same name or slug
292
-        $category_slug = sanitize_title($category_name);
293
-        $term = EEM_Term::instance()->get_one(array(
294
-            array(
295
-                'OR' => array(
296
-                    'name' => $category_name,
297
-                    'slug' => $category_slug,
298
-                ),
299
-            ),
300
-        ));
301
-        if ( ! $term) {
302
-            $term = EE_Term::new_instance(array(
303
-                'name' => $category_name,
304
-                'slug' => $category_slug,
305
-            ));
306
-            $term->save();
307
-        }
308
-        //make sure there's a term-taxonomy entry too
309
-        require_once(EE_MODELS . 'EEM_Term_Taxonomy.model.php');
310
-        $term_taxonomy = EEM_Term_Taxonomy::instance()->get_one(array(
311
-            array(
312
-                'term_id'  => $term->ID(),
313
-                'taxonomy' => EE_Event_Category_Taxonomy,
314
-            ),
315
-        ));
316
-        /** @var $term_taxonomy EE_Term_Taxonomy */
317
-        if ( ! $term_taxonomy) {
318
-            $term_taxonomy = EE_Term_Taxonomy::new_instance(array(
319
-                'term_id'     => $term->ID(),
320
-                'taxonomy'    => EE_Event_Category_Taxonomy,
321
-                'description' => $category_description,
322
-                'count'       => 1,
323
-                'parent'      => $parent_term_taxonomy_id,
324
-            ));
325
-            $term_taxonomy->save();
326
-        } else {
327
-            $term_taxonomy->set_count($term_taxonomy->count() + 1);
328
-            $term_taxonomy->save();
329
-        }
330
-        return $this->add_relationship_to($cpt_model_object, $term_taxonomy, 'Term_Taxonomy');
331
-    }
332
-
333
-
334
-
335
-    /**
336
-     * Removed the category specified by name as having a relation to this event.
337
-     * Does not remove the term or term_taxonomy.
338
-     *
339
-     * @param EE_CPT_Base $cpt_model_object_event
340
-     * @param string      $category_name name of the event category (term)
341
-     * @return bool
342
-     */
343
-    function remove_event_category(EE_CPT_Base $cpt_model_object_event, $category_name)
344
-    {
345
-        //find the term_taxonomy by that name
346
-        $term_taxonomy = $this->get_first_related($cpt_model_object_event, 'Term_Taxonomy',
347
-            array(array('Term.name' => $category_name, 'taxonomy' => EE_Event_Category_Taxonomy)));
348
-        /** @var $term_taxonomy EE_Term_Taxonomy */
349
-        if ($term_taxonomy) {
350
-            $term_taxonomy->set_count($term_taxonomy->count() - 1);
351
-            $term_taxonomy->save();
352
-        }
353
-        return $this->remove_relationship_to($cpt_model_object_event, $term_taxonomy, 'Term_Taxonomy');
354
-    }
355
-
356
-
357
-
358
-    /**
359
-     * This is a wrapper for the WordPress get_the_post_thumbnail() function that returns the feature image for the
360
-     * given CPT ID.  It accepts the same params as what get_the_post_thumbnail() accepts.
361
-     *
362
-     * @link   http://codex.wordpress.org/Function_Reference/get_the_post_thumbnail
363
-     * @access public
364
-     * @param int          $id   the ID for the cpt we want the feature image for
365
-     * @param string|array $size (optional) Image size. Defaults to 'post-thumbnail' but can also be a 2-item array
366
-     *                           representing width and height in pixels (i.e. array(32,32) ).
367
-     * @param string|array $attr Optional. Query string or array of attributes.
368
-     * @return string HTML image element
369
-     */
370
-    public function get_feature_image($id, $size = 'thumbnail', $attr = '')
371
-    {
372
-        return get_the_post_thumbnail($id, $size, $attr);
373
-    }
374
-
375
-
376
-
377
-    /**
378
-     * Just a handy way to get the list of post statuses currently registered with WP.
379
-     *
380
-     * @global array $wp_post_statuses set in wp core for storing all the post stati
381
-     * @return array
382
-     */
383
-    public function get_post_statuses()
384
-    {
385
-        global $wp_post_statuses;
386
-        $statuses = array();
387
-        foreach ($wp_post_statuses as $post_status => $args_object) {
388
-            $statuses[$post_status] = $args_object->label;
389
-        }
390
-        return $statuses;
391
-    }
392
-
393
-
394
-
395
-    /**
396
-     * public method that can be used to retrieve the protected status array on the instantiated cpt model
397
-     *
398
-     * @return array array of statuses.
399
-     */
400
-    public function get_status_array()
401
-    {
402
-        $statuses = $this->get_post_statuses();
403
-        //first the global filter
404
-        $statuses = apply_filters('FHEE_EEM_CPT_Base__get_status_array', $statuses);
405
-        //now the class specific filter
406
-        $statuses = apply_filters('FHEE_EEM_' . get_class($this) . '__get_status_array', $statuses);
407
-        return $statuses;
408
-    }
409
-
410
-
411
-
412
-    /**
413
-     * this returns the post statuses that are NOT the default wordpress status
414
-     *
415
-     * @return array
416
-     */
417
-    public function get_custom_post_statuses()
418
-    {
419
-        $new_stati = array();
420
-        foreach ($this->_custom_stati as $status => $props) {
421
-            $new_stati[$status] = $props['label'];
422
-        }
423
-        return $new_stati;
424
-    }
425
-
426
-
427
-
428
-    /**
429
-     * Creates a child of EE_CPT_Base given a WP_Post or array of wpdb results which
430
-     * are a row from the posts table. If we're missing any fields required for the model,
431
-     * we just fetch the entire entry from the DB (ie, if you want to use this to save DB queries,
432
-     * make sure you are attaching all the model's fields onto the post)
433
-     *
434
-     * @param WP_Post|array $post
435
-     * @return EE_Base_Class|EE_Soft_Delete_Base_Class
436
-     */
437
-    public function instantiate_class_from_post_object_orig($post)
438
-    {
439
-        $post = (array)$post;
440
-        $has_all_necessary_fields_for_table = true;
441
-        //check if the post has fields on the meta table already
442
-        foreach ($this->_get_other_tables() as $table_obj) {
443
-            $fields_for_that_table = $this->_get_fields_for_table($table_obj->get_table_alias());
444
-            foreach ($fields_for_that_table as $field_obj) {
445
-                if ( ! isset($post[$field_obj->get_table_column()])
446
-                     && ! isset($post[$field_obj->get_qualified_column()])
447
-                ) {
448
-                    $has_all_necessary_fields_for_table = false;
449
-                }
450
-            }
451
-        }
452
-        //if we don't have all the fields we need, then just fetch the proper model from the DB
453
-        if ( ! $has_all_necessary_fields_for_table) {
454
-            return $this->get_one_by_ID($post['ID']);
455
-        } else {
456
-            return $this->instantiate_class_from_array_or_object($post);
457
-        }
458
-    }
459
-
460
-
461
-
462
-    /**
463
-     * @param null $post
464
-     * @return EE_Base_Class|EE_Soft_Delete_Base_Class
465
-     */
466
-    public function instantiate_class_from_post_object($post = null)
467
-    {
468
-        if (empty($post)) {
469
-            global $post;
470
-        }
471
-        $post = (array)$post;
472
-        $tables_needing_to_be_queried = array();
473
-        //check if the post has fields on the meta table already
474
-        foreach ($this->get_tables() as $table_obj) {
475
-            $fields_for_that_table = $this->_get_fields_for_table($table_obj->get_table_alias());
476
-            foreach ($fields_for_that_table as $field_obj) {
477
-                if ( ! isset($post[$field_obj->get_table_column()])
478
-                     && ! isset($post[$field_obj->get_qualified_column()])
479
-                ) {
480
-                    $tables_needing_to_be_queried[$table_obj->get_table_alias()] = $table_obj;
481
-                }
482
-            }
483
-        }
484
-        //if we don't have all the fields we need, then just fetch the proper model from the DB
485
-        if ($tables_needing_to_be_queried) {
486
-            if (count($tables_needing_to_be_queried) == 1
487
-                && reset($tables_needing_to_be_queried)
488
-                   instanceof
489
-                   EE_Secondary_Table
490
-            ) {
491
-                //so we're only missing data from a secondary table. Well that's not too hard to query for
492
-                $table_to_query = reset($tables_needing_to_be_queried);
493
-                $missing_data = $this->_do_wpdb_query('get_row', array(
494
-                    'SELECT * FROM '
495
-                    . $table_to_query->get_table_name()
496
-                    . ' WHERE '
497
-                    . $table_to_query->get_fk_on_table()
498
-                    . ' = '
499
-                    . $post['ID'],
500
-                    ARRAY_A,
501
-                ));
502
-                if ( ! empty($missing_data)) {
503
-                    $post = array_merge($post, $missing_data);
504
-                }
505
-            } else {
506
-                return $this->get_one_by_ID($post['ID']);
507
-            }
508
-        }
509
-        return $this->instantiate_class_from_array_or_object($post);
510
-    }
511
-
512
-
513
-
514
-    /**
515
-     * Gets the post type associated with this
516
-     *
517
-     * @throws EE_Error
518
-     * @return string
519
-     */
520
-    public function post_type()
521
-    {
522
-        $post_type_field = null;
523
-        foreach ($this->field_settings(true) as $field_obj) {
524
-            if ($field_obj instanceof EE_WP_Post_Type_Field) {
525
-                $post_type_field = $field_obj;
526
-                break;
527
-            }
528
-        }
529
-        if ($post_type_field == null) {
530
-            throw new EE_Error(sprintf(__("CPT Model %s should have a field of type EE_WP_Post_Type, but doesnt",
531
-                "event_espresso"), get_class($this)));
532
-        }
533
-        return $post_type_field->get_default_value();
534
-    }
21
+	/**
22
+	 * @var string post_status_publish - the wp post status for published cpts
23
+	 */
24
+	const post_status_publish = 'publish';
25
+
26
+	/**
27
+	 * @var string post_status_future - the wp post status for scheduled cpts
28
+	 */
29
+	const post_status_future = 'future';
30
+
31
+	/**
32
+	 * @var string post_status_draft - the wp post status for draft cpts
33
+	 */
34
+	const post_status_draft = 'draft';
35
+
36
+	/**
37
+	 * @var string post_status_pending - the wp post status for pending cpts
38
+	 */
39
+	const post_status_pending = 'pending';
40
+
41
+	/**
42
+	 * @var string post_status_private - the wp post status for private cpts
43
+	 */
44
+	const post_status_private = 'private';
45
+
46
+	/**
47
+	 * @var string post_status_trashed - the wp post status for trashed cpts
48
+	 */
49
+	const post_status_trashed = 'trash';
50
+
51
+	/**
52
+	 * This is an array of custom statuses for the given CPT model (modified by children)
53
+	 * format:
54
+	 * array(
55
+	 *        'status_name' => array(
56
+	 *            'label' => __('Status Name', 'event_espresso'),
57
+	 *            'public' => TRUE //whether a public status or not.
58
+	 *        )
59
+	 * )
60
+	 *
61
+	 * @var array
62
+	 */
63
+	protected $_custom_stati = array();
64
+
65
+
66
+
67
+	/**
68
+	 * Adds a relationship to Term_Taxonomy for each CPT_Base
69
+	 *
70
+	 * @param string $timezone
71
+	 * @throws \EE_Error
72
+	 */
73
+	protected function __construct($timezone = null)
74
+	{
75
+		//adds a relationship to Term_Taxonomy for all these models. For this to work
76
+		//Term_Relationship must have a relation to each model subclassing EE_CPT_Base explicitly
77
+		//eg, in EEM_Term_Relationship, inside the _model_relations array, there must be an entry
78
+		//with key equalling the subclassing model's model name (eg 'Event' or 'Venue'), and the value
79
+		//must also be new EE_HABTM_Relation('Term_Relationship');
80
+		$this->_model_relations['Term_Taxonomy'] = new EE_HABTM_Relation('Term_Relationship');
81
+		$primary_table_name = null;
82
+		//add  the common _status field to all CPT primary tables.
83
+		foreach ($this->_tables as $alias => $table_obj) {
84
+			if ($table_obj instanceof EE_Primary_Table) {
85
+				$primary_table_name = $alias;
86
+			}
87
+		}
88
+		//set default wp post statuses if child has not already set.
89
+		if ( ! isset($this->_fields[$primary_table_name]['status'])) {
90
+			$this->_fields[$primary_table_name]['status'] = new EE_WP_Post_Status_Field('post_status',
91
+				__("Event Status", "event_espresso"), false, 'draft');
92
+		}
93
+		if ( ! isset($this->_fields[$primary_table_name]['to_ping'])) {
94
+			$this->_fields[$primary_table_name]['to_ping'] = new EE_DB_Only_Text_Field('to_ping',
95
+				__('To Ping', 'event_espresso'), false, '');
96
+		}
97
+		if ( ! isset($this->_fields[$primary_table_name]['pinged'])) {
98
+			$this->_fields[$primary_table_name]['pinged'] = new EE_DB_Only_Text_Field('pinged',
99
+				__('Pinged', 'event_espresso'), false, '');
100
+		}
101
+		if ( ! isset($this->_fields[$primary_table_name]['comment_status'])) {
102
+			$this->_fields[$primary_table_name]['comment_status'] = new EE_Plain_Text_Field('comment_status',
103
+				__('Comment Status', 'event_espresso'), false, 'open');
104
+		}
105
+		if ( ! isset($this->_fields[$primary_table_name]['ping_status'])) {
106
+			$this->_fields[$primary_table_name]['ping_status'] = new EE_Plain_Text_Field('ping_status',
107
+				__('Ping Status', 'event_espresso'), false, 'open');
108
+		}
109
+		if ( ! isset($this->_fields[$primary_table_name]['post_content_filtered'])) {
110
+			$this->_fields[$primary_table_name]['post_content_filtered'] = new EE_DB_Only_Text_Field('post_content_filtered',
111
+				__('Post Content Filtered', 'event_espresso'), false, '');
112
+		}
113
+		if ( ! isset($this->_model_relations['Post_Meta'])) {
114
+			//don't block deletes though because we want to maintain the current behaviour
115
+			$this->_model_relations['Post_Meta'] = new EE_Has_Many_Relation(false);
116
+		}
117
+		if ( ! $this->_minimum_where_conditions_strategy instanceof EE_Default_Where_Conditions) {
118
+			//nothing was set during child constructor, so set default
119
+			$this->_minimum_where_conditions_strategy = new EE_CPT_Minimum_Where_Conditions($this->post_type());
120
+		}
121
+		if ( ! $this->_default_where_conditions_strategy instanceof EE_Default_Where_Conditions) {
122
+			//nothing was set during child constructor, so set default
123
+			//it's ok for child classes to specify this, but generally this is more DRY
124
+			$this->_default_where_conditions_strategy = new EE_CPT_Where_Conditions($this->post_type());
125
+		}
126
+		parent::__construct($timezone);
127
+	}
128
+
129
+
130
+
131
+	/**
132
+	 * @return array
133
+	 */
134
+	public function public_event_stati()
135
+	{
136
+		// @see wp-includes/post.php
137
+		return get_post_stati(array('public' => true));
138
+	}
139
+
140
+
141
+
142
+	/**
143
+	 * Searches for field on this model of type 'deleted_flag'. if it is found,
144
+	 * returns it's name. BUT That doesn't apply to CPTs. We should instead use post_status_field_name
145
+	 *
146
+	 * @return string
147
+	 * @throws EE_Error
148
+	 */
149
+	public function deleted_field_name()
150
+	{
151
+		throw new EE_Error(sprintf(__("EEM_CPT_Base should nto call deleted_field_name! It should instead use post_status_field_name",
152
+			"event_espresso")));
153
+	}
154
+
155
+
156
+
157
+	/**
158
+	 * Gets the field's name that sets the post status
159
+	 *
160
+	 * @return string
161
+	 * @throws EE_Error
162
+	 */
163
+	public function post_status_field_name()
164
+	{
165
+		$field = $this->get_a_field_of_type('EE_WP_Post_Status_Field');
166
+		if ($field) {
167
+			return $field->get_name();
168
+		} else {
169
+			throw new EE_Error(sprintf(__('We are trying to find the post status flag field on %s, but none was found. Are you sure there is a field of type EE_Trashed_Flag_Field in %s constructor?',
170
+				'event_espresso'), get_class($this), get_class($this)));
171
+		}
172
+	}
173
+
174
+
175
+
176
+	/**
177
+	 * Alters the query params so that only trashed/soft-deleted items are considered
178
+	 *
179
+	 * @param array $query_params like EEM_Base::get_all's $query_params
180
+	 * @return array like EEM_Base::get_all's $query_params
181
+	 */
182
+	protected function _alter_query_params_so_only_trashed_items_included($query_params)
183
+	{
184
+		$post_status_field_name = $this->post_status_field_name();
185
+		$query_params[0][$post_status_field_name] = self::post_status_trashed;
186
+		return $query_params;
187
+	}
188
+
189
+
190
+
191
+	/**
192
+	 * Alters the query params so each item's deleted status is ignored.
193
+	 *
194
+	 * @param array $query_params
195
+	 * @return array
196
+	 */
197
+	protected function _alter_query_params_so_deleted_and_undeleted_items_included($query_params)
198
+	{
199
+		$query_params['default_where_conditions'] = 'minimum';
200
+		return $query_params;
201
+	}
202
+
203
+
204
+
205
+	/**
206
+	 * Performs deletes or restores on items. Both soft-deleted and non-soft-deleted items considered.
207
+	 *
208
+	 * @param boolean $delete       true to indicate deletion, false to indicate restoration
209
+	 * @param array   $query_params like EEM_Base::get_all
210
+	 * @return boolean success
211
+	 */
212
+	function delete_or_restore($delete = true, $query_params = array())
213
+	{
214
+		$post_status_field_name = $this->post_status_field_name();
215
+		$query_params = $this->_alter_query_params_so_deleted_and_undeleted_items_included($query_params);
216
+		$new_status = $delete ? self::post_status_trashed : 'draft';
217
+		if ($this->update(array($post_status_field_name => $new_status), $query_params)) {
218
+			return true;
219
+		} else {
220
+			return false;
221
+		}
222
+	}
223
+
224
+
225
+
226
+	/**
227
+	 * meta_table
228
+	 * returns first EE_Secondary_Table table name
229
+	 *
230
+	 * @access public
231
+	 * @return string
232
+	 */
233
+	public function meta_table()
234
+	{
235
+		$meta_table = $this->_get_other_tables();
236
+		$meta_table = reset($meta_table);
237
+		return $meta_table instanceof EE_Secondary_Table ? $meta_table->get_table_name() : null;
238
+	}
239
+
240
+
241
+
242
+	/**
243
+	 * This simply returns an array of the meta table fields (useful for when we just need to update those fields)
244
+	 *
245
+	 * @param  bool $all triggers whether we include DB_Only fields or JUST non DB_Only fields.  Defaults to false (no
246
+	 *                   db only fields)
247
+	 * @return array
248
+	 */
249
+	public function get_meta_table_fields($all = false)
250
+	{
251
+		$all_fields = $fields_to_return = array();
252
+		foreach ($this->_tables as $alias => $table_obj) {
253
+			if ($table_obj instanceof EE_Secondary_Table) {
254
+				$all_fields = array_merge($this->_get_fields_for_table($alias), $all_fields);
255
+			}
256
+		}
257
+		if ( ! $all) {
258
+			foreach ($all_fields as $name => $obj) {
259
+				if ($obj instanceof EE_DB_Only_Field_Base) {
260
+					continue;
261
+				}
262
+				$fields_to_return[] = $name;
263
+			}
264
+		} else {
265
+			$fields_to_return = array_keys($all_fields);
266
+		}
267
+		return $fields_to_return;
268
+	}
269
+
270
+
271
+
272
+	/**
273
+	 * Adds an event category with the specified name and description to the specified
274
+	 * $cpt_model_object. Intelligently adds a term if necessary, and adds a term_taxonomy if necessary,
275
+	 * and adds an entry in the term_relationship if necessary.
276
+	 *
277
+	 * @param EE_CPT_Base $cpt_model_object
278
+	 * @param string      $category_name (used to derive the term slug too)
279
+	 * @param string      $category_description
280
+	 * @param int         $parent_term_taxonomy_id
281
+	 * @return EE_Term_Taxonomy
282
+	 */
283
+	function add_event_category(
284
+		EE_CPT_Base $cpt_model_object,
285
+		$category_name,
286
+		$category_description = '',
287
+		$parent_term_taxonomy_id = null
288
+	) {
289
+		//create term
290
+		require_once(EE_MODELS . 'EEM_Term.model.php');
291
+		//first, check for a term by the same name or slug
292
+		$category_slug = sanitize_title($category_name);
293
+		$term = EEM_Term::instance()->get_one(array(
294
+			array(
295
+				'OR' => array(
296
+					'name' => $category_name,
297
+					'slug' => $category_slug,
298
+				),
299
+			),
300
+		));
301
+		if ( ! $term) {
302
+			$term = EE_Term::new_instance(array(
303
+				'name' => $category_name,
304
+				'slug' => $category_slug,
305
+			));
306
+			$term->save();
307
+		}
308
+		//make sure there's a term-taxonomy entry too
309
+		require_once(EE_MODELS . 'EEM_Term_Taxonomy.model.php');
310
+		$term_taxonomy = EEM_Term_Taxonomy::instance()->get_one(array(
311
+			array(
312
+				'term_id'  => $term->ID(),
313
+				'taxonomy' => EE_Event_Category_Taxonomy,
314
+			),
315
+		));
316
+		/** @var $term_taxonomy EE_Term_Taxonomy */
317
+		if ( ! $term_taxonomy) {
318
+			$term_taxonomy = EE_Term_Taxonomy::new_instance(array(
319
+				'term_id'     => $term->ID(),
320
+				'taxonomy'    => EE_Event_Category_Taxonomy,
321
+				'description' => $category_description,
322
+				'count'       => 1,
323
+				'parent'      => $parent_term_taxonomy_id,
324
+			));
325
+			$term_taxonomy->save();
326
+		} else {
327
+			$term_taxonomy->set_count($term_taxonomy->count() + 1);
328
+			$term_taxonomy->save();
329
+		}
330
+		return $this->add_relationship_to($cpt_model_object, $term_taxonomy, 'Term_Taxonomy');
331
+	}
332
+
333
+
334
+
335
+	/**
336
+	 * Removed the category specified by name as having a relation to this event.
337
+	 * Does not remove the term or term_taxonomy.
338
+	 *
339
+	 * @param EE_CPT_Base $cpt_model_object_event
340
+	 * @param string      $category_name name of the event category (term)
341
+	 * @return bool
342
+	 */
343
+	function remove_event_category(EE_CPT_Base $cpt_model_object_event, $category_name)
344
+	{
345
+		//find the term_taxonomy by that name
346
+		$term_taxonomy = $this->get_first_related($cpt_model_object_event, 'Term_Taxonomy',
347
+			array(array('Term.name' => $category_name, 'taxonomy' => EE_Event_Category_Taxonomy)));
348
+		/** @var $term_taxonomy EE_Term_Taxonomy */
349
+		if ($term_taxonomy) {
350
+			$term_taxonomy->set_count($term_taxonomy->count() - 1);
351
+			$term_taxonomy->save();
352
+		}
353
+		return $this->remove_relationship_to($cpt_model_object_event, $term_taxonomy, 'Term_Taxonomy');
354
+	}
355
+
356
+
357
+
358
+	/**
359
+	 * This is a wrapper for the WordPress get_the_post_thumbnail() function that returns the feature image for the
360
+	 * given CPT ID.  It accepts the same params as what get_the_post_thumbnail() accepts.
361
+	 *
362
+	 * @link   http://codex.wordpress.org/Function_Reference/get_the_post_thumbnail
363
+	 * @access public
364
+	 * @param int          $id   the ID for the cpt we want the feature image for
365
+	 * @param string|array $size (optional) Image size. Defaults to 'post-thumbnail' but can also be a 2-item array
366
+	 *                           representing width and height in pixels (i.e. array(32,32) ).
367
+	 * @param string|array $attr Optional. Query string or array of attributes.
368
+	 * @return string HTML image element
369
+	 */
370
+	public function get_feature_image($id, $size = 'thumbnail', $attr = '')
371
+	{
372
+		return get_the_post_thumbnail($id, $size, $attr);
373
+	}
374
+
375
+
376
+
377
+	/**
378
+	 * Just a handy way to get the list of post statuses currently registered with WP.
379
+	 *
380
+	 * @global array $wp_post_statuses set in wp core for storing all the post stati
381
+	 * @return array
382
+	 */
383
+	public function get_post_statuses()
384
+	{
385
+		global $wp_post_statuses;
386
+		$statuses = array();
387
+		foreach ($wp_post_statuses as $post_status => $args_object) {
388
+			$statuses[$post_status] = $args_object->label;
389
+		}
390
+		return $statuses;
391
+	}
392
+
393
+
394
+
395
+	/**
396
+	 * public method that can be used to retrieve the protected status array on the instantiated cpt model
397
+	 *
398
+	 * @return array array of statuses.
399
+	 */
400
+	public function get_status_array()
401
+	{
402
+		$statuses = $this->get_post_statuses();
403
+		//first the global filter
404
+		$statuses = apply_filters('FHEE_EEM_CPT_Base__get_status_array', $statuses);
405
+		//now the class specific filter
406
+		$statuses = apply_filters('FHEE_EEM_' . get_class($this) . '__get_status_array', $statuses);
407
+		return $statuses;
408
+	}
409
+
410
+
411
+
412
+	/**
413
+	 * this returns the post statuses that are NOT the default wordpress status
414
+	 *
415
+	 * @return array
416
+	 */
417
+	public function get_custom_post_statuses()
418
+	{
419
+		$new_stati = array();
420
+		foreach ($this->_custom_stati as $status => $props) {
421
+			$new_stati[$status] = $props['label'];
422
+		}
423
+		return $new_stati;
424
+	}
425
+
426
+
427
+
428
+	/**
429
+	 * Creates a child of EE_CPT_Base given a WP_Post or array of wpdb results which
430
+	 * are a row from the posts table. If we're missing any fields required for the model,
431
+	 * we just fetch the entire entry from the DB (ie, if you want to use this to save DB queries,
432
+	 * make sure you are attaching all the model's fields onto the post)
433
+	 *
434
+	 * @param WP_Post|array $post
435
+	 * @return EE_Base_Class|EE_Soft_Delete_Base_Class
436
+	 */
437
+	public function instantiate_class_from_post_object_orig($post)
438
+	{
439
+		$post = (array)$post;
440
+		$has_all_necessary_fields_for_table = true;
441
+		//check if the post has fields on the meta table already
442
+		foreach ($this->_get_other_tables() as $table_obj) {
443
+			$fields_for_that_table = $this->_get_fields_for_table($table_obj->get_table_alias());
444
+			foreach ($fields_for_that_table as $field_obj) {
445
+				if ( ! isset($post[$field_obj->get_table_column()])
446
+					 && ! isset($post[$field_obj->get_qualified_column()])
447
+				) {
448
+					$has_all_necessary_fields_for_table = false;
449
+				}
450
+			}
451
+		}
452
+		//if we don't have all the fields we need, then just fetch the proper model from the DB
453
+		if ( ! $has_all_necessary_fields_for_table) {
454
+			return $this->get_one_by_ID($post['ID']);
455
+		} else {
456
+			return $this->instantiate_class_from_array_or_object($post);
457
+		}
458
+	}
459
+
460
+
461
+
462
+	/**
463
+	 * @param null $post
464
+	 * @return EE_Base_Class|EE_Soft_Delete_Base_Class
465
+	 */
466
+	public function instantiate_class_from_post_object($post = null)
467
+	{
468
+		if (empty($post)) {
469
+			global $post;
470
+		}
471
+		$post = (array)$post;
472
+		$tables_needing_to_be_queried = array();
473
+		//check if the post has fields on the meta table already
474
+		foreach ($this->get_tables() as $table_obj) {
475
+			$fields_for_that_table = $this->_get_fields_for_table($table_obj->get_table_alias());
476
+			foreach ($fields_for_that_table as $field_obj) {
477
+				if ( ! isset($post[$field_obj->get_table_column()])
478
+					 && ! isset($post[$field_obj->get_qualified_column()])
479
+				) {
480
+					$tables_needing_to_be_queried[$table_obj->get_table_alias()] = $table_obj;
481
+				}
482
+			}
483
+		}
484
+		//if we don't have all the fields we need, then just fetch the proper model from the DB
485
+		if ($tables_needing_to_be_queried) {
486
+			if (count($tables_needing_to_be_queried) == 1
487
+				&& reset($tables_needing_to_be_queried)
488
+				   instanceof
489
+				   EE_Secondary_Table
490
+			) {
491
+				//so we're only missing data from a secondary table. Well that's not too hard to query for
492
+				$table_to_query = reset($tables_needing_to_be_queried);
493
+				$missing_data = $this->_do_wpdb_query('get_row', array(
494
+					'SELECT * FROM '
495
+					. $table_to_query->get_table_name()
496
+					. ' WHERE '
497
+					. $table_to_query->get_fk_on_table()
498
+					. ' = '
499
+					. $post['ID'],
500
+					ARRAY_A,
501
+				));
502
+				if ( ! empty($missing_data)) {
503
+					$post = array_merge($post, $missing_data);
504
+				}
505
+			} else {
506
+				return $this->get_one_by_ID($post['ID']);
507
+			}
508
+		}
509
+		return $this->instantiate_class_from_array_or_object($post);
510
+	}
511
+
512
+
513
+
514
+	/**
515
+	 * Gets the post type associated with this
516
+	 *
517
+	 * @throws EE_Error
518
+	 * @return string
519
+	 */
520
+	public function post_type()
521
+	{
522
+		$post_type_field = null;
523
+		foreach ($this->field_settings(true) as $field_obj) {
524
+			if ($field_obj instanceof EE_WP_Post_Type_Field) {
525
+				$post_type_field = $field_obj;
526
+				break;
527
+			}
528
+		}
529
+		if ($post_type_field == null) {
530
+			throw new EE_Error(sprintf(__("CPT Model %s should have a field of type EE_WP_Post_Type, but doesnt",
531
+				"event_espresso"), get_class($this)));
532
+		}
533
+		return $post_type_field->get_default_value();
534
+	}
535 535
 
536 536
 }
Please login to merge, or discard this patch.
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -287,7 +287,7 @@  discard block
 block discarded – undo
287 287
         $parent_term_taxonomy_id = null
288 288
     ) {
289 289
         //create term
290
-        require_once(EE_MODELS . 'EEM_Term.model.php');
290
+        require_once(EE_MODELS.'EEM_Term.model.php');
291 291
         //first, check for a term by the same name or slug
292 292
         $category_slug = sanitize_title($category_name);
293 293
         $term = EEM_Term::instance()->get_one(array(
@@ -306,7 +306,7 @@  discard block
 block discarded – undo
306 306
             $term->save();
307 307
         }
308 308
         //make sure there's a term-taxonomy entry too
309
-        require_once(EE_MODELS . 'EEM_Term_Taxonomy.model.php');
309
+        require_once(EE_MODELS.'EEM_Term_Taxonomy.model.php');
310 310
         $term_taxonomy = EEM_Term_Taxonomy::instance()->get_one(array(
311 311
             array(
312 312
                 'term_id'  => $term->ID(),
@@ -403,7 +403,7 @@  discard block
 block discarded – undo
403 403
         //first the global filter
404 404
         $statuses = apply_filters('FHEE_EEM_CPT_Base__get_status_array', $statuses);
405 405
         //now the class specific filter
406
-        $statuses = apply_filters('FHEE_EEM_' . get_class($this) . '__get_status_array', $statuses);
406
+        $statuses = apply_filters('FHEE_EEM_'.get_class($this).'__get_status_array', $statuses);
407 407
         return $statuses;
408 408
     }
409 409
 
@@ -436,7 +436,7 @@  discard block
 block discarded – undo
436 436
      */
437 437
     public function instantiate_class_from_post_object_orig($post)
438 438
     {
439
-        $post = (array)$post;
439
+        $post = (array) $post;
440 440
         $has_all_necessary_fields_for_table = true;
441 441
         //check if the post has fields on the meta table already
442 442
         foreach ($this->_get_other_tables() as $table_obj) {
@@ -468,7 +468,7 @@  discard block
 block discarded – undo
468 468
         if (empty($post)) {
469 469
             global $post;
470 470
         }
471
-        $post = (array)$post;
471
+        $post = (array) $post;
472 472
         $tables_needing_to_be_queried = array();
473 473
         //check if the post has fields on the meta table already
474 474
         foreach ($this->get_tables() as $table_obj) {
Please login to merge, or discard this patch.
core/db_models/EEM_Venue.model.php 2 patches
Indentation   +79 added lines, -79 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php if ( ! defined('EVENT_ESPRESSO_VERSION')) {
2
-    exit('No direct script access allowed');
2
+	exit('No direct script access allowed');
3 3
 }
4 4
 /**
5 5
  * Event Espresso
@@ -25,87 +25,87 @@  discard block
 block discarded – undo
25 25
 class EEM_Venue extends EEM_CPT_Base
26 26
 {
27 27
 
28
-    // private instance of the Attendee object
29
-    protected static $_instance = null;
28
+	// private instance of the Attendee object
29
+	protected static $_instance = null;
30 30
 
31 31
 
32 32
 
33
-    protected function __construct($timezone = null)
34
-    {
35
-        $this->singular_item = __('Venue', 'event_espresso');
36
-        $this->plural_item = __('Venues', 'event_espresso');
37
-        $this->_tables = array(
38
-            'Venue_CPT'  => new EE_Primary_Table('posts', 'ID'),
39
-            'Venue_Meta' => new EE_Secondary_Table('esp_venue_meta', 'VNUM_ID', 'VNU_ID'),
40
-        );
41
-        $this->_fields = array(
42
-            'Venue_CPT'  => array(
43
-                'VNU_ID'         => new EE_Primary_Key_Int_Field('ID', __("Venue ID", "event_espresso")),
44
-                'VNU_name'       => new EE_Plain_Text_Field('post_title', __("Venue Name", "event_espresso"), false,
45
-                    ''),
46
-                'VNU_desc'       => new EE_Post_Content_Field('post_content', __("Venue Description", "event_espresso"),
47
-                    false, ''),
48
-                'VNU_identifier' => new EE_Slug_Field('post_name', __("Venue Identifier", "event_espresso"), false, ''),
49
-                'VNU_created'    => new EE_Datetime_Field('post_date', __("Date Venue Created", "event_espresso"),
50
-                    false, EE_Datetime_Field::now),
51
-                'VNU_short_desc' => new EE_Plain_Text_Field('post_excerpt',
52
-                    __("Short Description of Venue", "event_espresso"), true, ''),
53
-                'VNU_modified'   => new EE_Datetime_Field('post_modified', __("Venue Modified Date", "event_espresso"),
54
-                    false, EE_Datetime_Field::now),
55
-                'VNU_wp_user'    => new EE_WP_User_Field('post_author', __("Venue Creator ID", "event_espresso"),
56
-                    false),
57
-                'parent'         => new EE_Integer_Field('post_parent', __("Venue Parent ID", "event_espresso"), false,
58
-                    0),
59
-                'VNU_order'      => new EE_Integer_Field('menu_order', __("Venue order", "event_espresso"), false, 1),
60
-                'post_type'      => new EE_WP_Post_Type_Field('espresso_venues'),
61
-                // EE_Plain_Text_Field('post_type', __("Venue post type", "event_espresso"), false, 'espresso_venues'),
62
-            ),
63
-            'Venue_Meta' => array(
64
-                'VNUM_ID'             => new EE_DB_Only_Int_Field('VNUM_ID',
65
-                    __("ID of Venue Meta Row", "event_espresso"), false),
66
-                'VNU_ID_fk'           => new EE_DB_Only_Int_Field('VNU_ID',
67
-                    __("Foreign Key to Venue Post ", "event_espresso"), false),
68
-                'VNU_address'         => new EE_Plain_Text_Field('VNU_address',
69
-                    __("Venue Address line 1", "event_espresso"), true, ''),
70
-                'VNU_address2'        => new EE_Plain_Text_Field('VNU_address2',
71
-                    __("Venue Address line 2", "event_espresso"), true, ''),
72
-                'VNU_city'            => new EE_Plain_Text_Field('VNU_city', __("Venue City", "event_espresso"), true,
73
-                    ''),
74
-                'STA_ID'              => new EE_Foreign_Key_Int_Field('STA_ID', __("State ID", "event_espresso"), true,
75
-                    null, 'State'),
76
-                'CNT_ISO'             => new EE_Foreign_Key_String_Field('CNT_ISO',
77
-                    __("Country Code", "event_espresso"), true, null, 'Country'),
78
-                'VNU_zip'             => new EE_Plain_Text_Field('VNU_zip',
79
-                    __("Venue Zip/Postal Code", "event_espresso"), true),
80
-                'VNU_phone'           => new EE_Plain_Text_Field('VNU_phone', __("Venue Phone", "event_espresso"),
81
-                    true),
82
-                'VNU_capacity'        => new EE_Infinite_Integer_Field('VNU_capacity',
83
-                    __("Venue Capacity", "event_espresso"), true, EE_INF),
84
-                'VNU_url'             => new EE_Plain_Text_Field('VNU_url', __('Venue Website', 'event_espresso'),
85
-                    true),
86
-                'VNU_virtual_phone'   => new EE_Plain_Text_Field('VNU_virtual_phone',
87
-                    __('Call in Number', 'event_espresso'), true),
88
-                'VNU_virtual_url'     => new EE_Plain_Text_Field('VNU_virtual_url', __('Virtual URL', 'event_espresso'),
89
-                    true),
90
-                'VNU_google_map_link' => new EE_Plain_Text_Field('VNU_google_map_link',
91
-                    __('Google Map Link', 'event_espresso'), true),
92
-                'VNU_enable_for_gmap' => new EE_Boolean_Field('VNU_enable_for_gmap',
93
-                    __('Show Google Map?', 'event_espresso'), false, false),
94
-            ),
95
-        );
96
-        $this->_model_relations = array(
97
-            'Event'             => new EE_HABTM_Relation('Event_Venue'),
98
-            'State'             => new EE_Belongs_To_Relation(),
99
-            'Country'           => new EE_Belongs_To_Relation(),
100
-            'Event_Venue'       => new EE_Has_Many_Relation(),
101
-            'WP_User'           => new EE_Belongs_To_Relation(),
102
-            'Term_Relationship' => new EE_Has_Many_Relation(),
103
-            'Term_Taxonomy'     => new EE_HABTM_Relation('Term_Relationship'),
104
-        );
105
-        //this model is generally available for reading
106
-        $this->_cap_restriction_generators[EEM_Base::caps_read] = new EE_Restriction_Generator_Public();
107
-        parent::__construct($timezone);
108
-    }
33
+	protected function __construct($timezone = null)
34
+	{
35
+		$this->singular_item = __('Venue', 'event_espresso');
36
+		$this->plural_item = __('Venues', 'event_espresso');
37
+		$this->_tables = array(
38
+			'Venue_CPT'  => new EE_Primary_Table('posts', 'ID'),
39
+			'Venue_Meta' => new EE_Secondary_Table('esp_venue_meta', 'VNUM_ID', 'VNU_ID'),
40
+		);
41
+		$this->_fields = array(
42
+			'Venue_CPT'  => array(
43
+				'VNU_ID'         => new EE_Primary_Key_Int_Field('ID', __("Venue ID", "event_espresso")),
44
+				'VNU_name'       => new EE_Plain_Text_Field('post_title', __("Venue Name", "event_espresso"), false,
45
+					''),
46
+				'VNU_desc'       => new EE_Post_Content_Field('post_content', __("Venue Description", "event_espresso"),
47
+					false, ''),
48
+				'VNU_identifier' => new EE_Slug_Field('post_name', __("Venue Identifier", "event_espresso"), false, ''),
49
+				'VNU_created'    => new EE_Datetime_Field('post_date', __("Date Venue Created", "event_espresso"),
50
+					false, EE_Datetime_Field::now),
51
+				'VNU_short_desc' => new EE_Plain_Text_Field('post_excerpt',
52
+					__("Short Description of Venue", "event_espresso"), true, ''),
53
+				'VNU_modified'   => new EE_Datetime_Field('post_modified', __("Venue Modified Date", "event_espresso"),
54
+					false, EE_Datetime_Field::now),
55
+				'VNU_wp_user'    => new EE_WP_User_Field('post_author', __("Venue Creator ID", "event_espresso"),
56
+					false),
57
+				'parent'         => new EE_Integer_Field('post_parent', __("Venue Parent ID", "event_espresso"), false,
58
+					0),
59
+				'VNU_order'      => new EE_Integer_Field('menu_order', __("Venue order", "event_espresso"), false, 1),
60
+				'post_type'      => new EE_WP_Post_Type_Field('espresso_venues'),
61
+				// EE_Plain_Text_Field('post_type', __("Venue post type", "event_espresso"), false, 'espresso_venues'),
62
+			),
63
+			'Venue_Meta' => array(
64
+				'VNUM_ID'             => new EE_DB_Only_Int_Field('VNUM_ID',
65
+					__("ID of Venue Meta Row", "event_espresso"), false),
66
+				'VNU_ID_fk'           => new EE_DB_Only_Int_Field('VNU_ID',
67
+					__("Foreign Key to Venue Post ", "event_espresso"), false),
68
+				'VNU_address'         => new EE_Plain_Text_Field('VNU_address',
69
+					__("Venue Address line 1", "event_espresso"), true, ''),
70
+				'VNU_address2'        => new EE_Plain_Text_Field('VNU_address2',
71
+					__("Venue Address line 2", "event_espresso"), true, ''),
72
+				'VNU_city'            => new EE_Plain_Text_Field('VNU_city', __("Venue City", "event_espresso"), true,
73
+					''),
74
+				'STA_ID'              => new EE_Foreign_Key_Int_Field('STA_ID', __("State ID", "event_espresso"), true,
75
+					null, 'State'),
76
+				'CNT_ISO'             => new EE_Foreign_Key_String_Field('CNT_ISO',
77
+					__("Country Code", "event_espresso"), true, null, 'Country'),
78
+				'VNU_zip'             => new EE_Plain_Text_Field('VNU_zip',
79
+					__("Venue Zip/Postal Code", "event_espresso"), true),
80
+				'VNU_phone'           => new EE_Plain_Text_Field('VNU_phone', __("Venue Phone", "event_espresso"),
81
+					true),
82
+				'VNU_capacity'        => new EE_Infinite_Integer_Field('VNU_capacity',
83
+					__("Venue Capacity", "event_espresso"), true, EE_INF),
84
+				'VNU_url'             => new EE_Plain_Text_Field('VNU_url', __('Venue Website', 'event_espresso'),
85
+					true),
86
+				'VNU_virtual_phone'   => new EE_Plain_Text_Field('VNU_virtual_phone',
87
+					__('Call in Number', 'event_espresso'), true),
88
+				'VNU_virtual_url'     => new EE_Plain_Text_Field('VNU_virtual_url', __('Virtual URL', 'event_espresso'),
89
+					true),
90
+				'VNU_google_map_link' => new EE_Plain_Text_Field('VNU_google_map_link',
91
+					__('Google Map Link', 'event_espresso'), true),
92
+				'VNU_enable_for_gmap' => new EE_Boolean_Field('VNU_enable_for_gmap',
93
+					__('Show Google Map?', 'event_espresso'), false, false),
94
+			),
95
+		);
96
+		$this->_model_relations = array(
97
+			'Event'             => new EE_HABTM_Relation('Event_Venue'),
98
+			'State'             => new EE_Belongs_To_Relation(),
99
+			'Country'           => new EE_Belongs_To_Relation(),
100
+			'Event_Venue'       => new EE_Has_Many_Relation(),
101
+			'WP_User'           => new EE_Belongs_To_Relation(),
102
+			'Term_Relationship' => new EE_Has_Many_Relation(),
103
+			'Term_Taxonomy'     => new EE_HABTM_Relation('Term_Relationship'),
104
+		);
105
+		//this model is generally available for reading
106
+		$this->_cap_restriction_generators[EEM_Base::caps_read] = new EE_Restriction_Generator_Public();
107
+		parent::__construct($timezone);
108
+	}
109 109
 
110 110
 }
111 111
 // End of file EEM_Venue.model.php
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -18,7 +18,7 @@
 block discarded – undo
18 18
  * @author                Michael Nelson
19 19
  *                        ------------------------------------------------------------------------
20 20
  */
21
-require_once(EE_MODELS . 'EEM_Base.model.php');
21
+require_once(EE_MODELS.'EEM_Base.model.php');
22 22
 
23 23
 
24 24
 
Please login to merge, or discard this patch.