Completed
Branch FET-10766-extract-activation-d... (a650cc)
by
unknown
87:01 queued 68:06
created
form_sections/strategies/layout/EE_Div_Per_Section_Layout.strategy.php 2 patches
Indentation   +126 added lines, -126 removed lines patch added patch discarded remove patch
@@ -14,132 +14,132 @@
 block discarded – undo
14 14
 class EE_Div_Per_Section_Layout extends EE_Form_Section_Layout_Base
15 15
 {
16 16
 
17
-    /**
18
-     * opening div tag for a form
19
-     *
20
-     * @return string
21
-     */
22
-    public function layout_form_begin()
23
-    {
24
-        return EEH_HTML::div(
25
-            '',
26
-            $this->_form_section->html_id(),
27
-            $this->_form_section->html_class(),
28
-            $this->_form_section->html_style()
29
-        );
30
-    }
31
-
32
-
33
-
34
-    /**
35
-     * Lays out the row for the input, including label and errors
36
-     *
37
-     * @param EE_Form_Input_Base $input
38
-     * @return string
39
-     * @throws \EE_Error
40
-     */
41
-    public function layout_input($input)
42
-    {
43
-        $html = '';
44
-        // set something unique for the id
45
-        $html_id = (string)$input->html_id() !== ''
46
-            ? (string)$input->html_id()
47
-            : spl_object_hash($input);
48
-        // and add a generic input type class
49
-        $html_class = sanitize_key(str_replace('_', '-', get_class($input))) . '-dv';
50
-        if ($input instanceof EE_Hidden_Input) {
51
-            $html .= EEH_HTML::nl() . $input->get_html_for_input();
52
-        } else if ($input instanceof EE_Submit_Input) {
53
-            $html .= EEH_HTML::div(
54
-                $input->get_html_for_input(),
55
-                $html_id . '-submit-dv',
56
-                "{$input->html_class()}-submit-dv {$html_class}"
57
-            );
58
-        } else if ($input instanceof EE_Select_Input) {
59
-            $html .= EEH_HTML::div(
60
-                EEH_HTML::nl(1) . $input->get_html_for_label() .
61
-                EEH_HTML::nl() . $input->get_html_for_errors() .
62
-                EEH_HTML::nl() . $input->get_html_for_input() .
63
-                EEH_HTML::nl() . $input->get_html_for_help(),
64
-                $html_id . '-input-dv',
65
-                "{$input->html_class()}-input-dv {$html_class}"
66
-            );
67
-        } else if ($input instanceof EE_Form_Input_With_Options_Base) {
68
-            $html .= EEH_HTML::div(
69
-                EEH_HTML::nl() . $this->_display_label_for_option_type_question($input) .
70
-                EEH_HTML::nl() . $input->get_html_for_errors() .
71
-                EEH_HTML::nl() . $input->get_html_for_input() .
72
-                EEH_HTML::nl() . $input->get_html_for_help(),
73
-                $html_id . '-input-dv',
74
-                "{$input->html_class()}-input-dv {$html_class}"
75
-            );
76
-        } else {
77
-            $html .= EEH_HTML::div(
78
-                EEH_HTML::nl(1) . $input->get_html_for_label() .
79
-                EEH_HTML::nl() . $input->get_html_for_errors() .
80
-                EEH_HTML::nl() . $input->get_html_for_input() .
81
-                EEH_HTML::nl() . $input->get_html_for_help(),
82
-                $html_id . '-input-dv',
83
-                "{$input->html_class()}-input-dv {$html_class}"
84
-            );
85
-        }
86
-        return $html;
87
-    }
88
-
89
-
90
-
91
-    /**
92
-     *
93
-     * _display_label_for_option_type_question
94
-     * Gets the HTML for the 'label', which is just text for this (because labels
95
-     * should be for each input)
96
-     *
97
-     * @param EE_Form_Input_With_Options_Base $input
98
-     * @return string
99
-     */
100
-    protected function _display_label_for_option_type_question(EE_Form_Input_With_Options_Base $input)
101
-    {
102
-        if ($input->display_html_label_text() !== '') {
103
-            return EEH_HTML::div(
104
-                $input->required()
105
-                    ? $input->html_label_text() . EEH_HTML::span('*', '', 'ee-asterisk')
106
-                    : $input->html_label_text(),
107
-                $input->html_label_id(),
108
-                $input->required()
109
-                    ? 'ee-required-label ' . $input->html_label_class()
110
-                    : $input->html_label_class(),
111
-                $input->html_label_style(),
112
-                $input->html_other_attributes()
113
-            );
114
-        }
115
-        return '';
116
-    }
117
-
118
-
119
-
120
-    /**
121
-     * Lays out a row for the subsection
122
-     *
123
-     * @param EE_Form_Section_Proper $form_section
124
-     * @return string
125
-     */
126
-    public function layout_subsection($form_section)
127
-    {
128
-        //		d( $form_section );
129
-        return EEH_HTML::nl(1) . $form_section->get_html() . EEH_HTML::nl(-1);
130
-    }
131
-
132
-
133
-
134
-    /**
135
-     * closing div tag for a form
136
-     *
137
-     * @return string
138
-     */
139
-    public function layout_form_end()
140
-    {
141
-        return EEH_HTML::divx($this->_form_section->html_id(), $this->_form_section->html_class());
142
-    }
17
+	/**
18
+	 * opening div tag for a form
19
+	 *
20
+	 * @return string
21
+	 */
22
+	public function layout_form_begin()
23
+	{
24
+		return EEH_HTML::div(
25
+			'',
26
+			$this->_form_section->html_id(),
27
+			$this->_form_section->html_class(),
28
+			$this->_form_section->html_style()
29
+		);
30
+	}
31
+
32
+
33
+
34
+	/**
35
+	 * Lays out the row for the input, including label and errors
36
+	 *
37
+	 * @param EE_Form_Input_Base $input
38
+	 * @return string
39
+	 * @throws \EE_Error
40
+	 */
41
+	public function layout_input($input)
42
+	{
43
+		$html = '';
44
+		// set something unique for the id
45
+		$html_id = (string)$input->html_id() !== ''
46
+			? (string)$input->html_id()
47
+			: spl_object_hash($input);
48
+		// and add a generic input type class
49
+		$html_class = sanitize_key(str_replace('_', '-', get_class($input))) . '-dv';
50
+		if ($input instanceof EE_Hidden_Input) {
51
+			$html .= EEH_HTML::nl() . $input->get_html_for_input();
52
+		} else if ($input instanceof EE_Submit_Input) {
53
+			$html .= EEH_HTML::div(
54
+				$input->get_html_for_input(),
55
+				$html_id . '-submit-dv',
56
+				"{$input->html_class()}-submit-dv {$html_class}"
57
+			);
58
+		} else if ($input instanceof EE_Select_Input) {
59
+			$html .= EEH_HTML::div(
60
+				EEH_HTML::nl(1) . $input->get_html_for_label() .
61
+				EEH_HTML::nl() . $input->get_html_for_errors() .
62
+				EEH_HTML::nl() . $input->get_html_for_input() .
63
+				EEH_HTML::nl() . $input->get_html_for_help(),
64
+				$html_id . '-input-dv',
65
+				"{$input->html_class()}-input-dv {$html_class}"
66
+			);
67
+		} else if ($input instanceof EE_Form_Input_With_Options_Base) {
68
+			$html .= EEH_HTML::div(
69
+				EEH_HTML::nl() . $this->_display_label_for_option_type_question($input) .
70
+				EEH_HTML::nl() . $input->get_html_for_errors() .
71
+				EEH_HTML::nl() . $input->get_html_for_input() .
72
+				EEH_HTML::nl() . $input->get_html_for_help(),
73
+				$html_id . '-input-dv',
74
+				"{$input->html_class()}-input-dv {$html_class}"
75
+			);
76
+		} else {
77
+			$html .= EEH_HTML::div(
78
+				EEH_HTML::nl(1) . $input->get_html_for_label() .
79
+				EEH_HTML::nl() . $input->get_html_for_errors() .
80
+				EEH_HTML::nl() . $input->get_html_for_input() .
81
+				EEH_HTML::nl() . $input->get_html_for_help(),
82
+				$html_id . '-input-dv',
83
+				"{$input->html_class()}-input-dv {$html_class}"
84
+			);
85
+		}
86
+		return $html;
87
+	}
88
+
89
+
90
+
91
+	/**
92
+	 *
93
+	 * _display_label_for_option_type_question
94
+	 * Gets the HTML for the 'label', which is just text for this (because labels
95
+	 * should be for each input)
96
+	 *
97
+	 * @param EE_Form_Input_With_Options_Base $input
98
+	 * @return string
99
+	 */
100
+	protected function _display_label_for_option_type_question(EE_Form_Input_With_Options_Base $input)
101
+	{
102
+		if ($input->display_html_label_text() !== '') {
103
+			return EEH_HTML::div(
104
+				$input->required()
105
+					? $input->html_label_text() . EEH_HTML::span('*', '', 'ee-asterisk')
106
+					: $input->html_label_text(),
107
+				$input->html_label_id(),
108
+				$input->required()
109
+					? 'ee-required-label ' . $input->html_label_class()
110
+					: $input->html_label_class(),
111
+				$input->html_label_style(),
112
+				$input->html_other_attributes()
113
+			);
114
+		}
115
+		return '';
116
+	}
117
+
118
+
119
+
120
+	/**
121
+	 * Lays out a row for the subsection
122
+	 *
123
+	 * @param EE_Form_Section_Proper $form_section
124
+	 * @return string
125
+	 */
126
+	public function layout_subsection($form_section)
127
+	{
128
+		//		d( $form_section );
129
+		return EEH_HTML::nl(1) . $form_section->get_html() . EEH_HTML::nl(-1);
130
+	}
131
+
132
+
133
+
134
+	/**
135
+	 * closing div tag for a form
136
+	 *
137
+	 * @return string
138
+	 */
139
+	public function layout_form_end()
140
+	{
141
+		return EEH_HTML::divx($this->_form_section->html_id(), $this->_form_section->html_class());
142
+	}
143 143
 
144 144
 
145 145
 
Please login to merge, or discard this patch.
Spacing   +23 added lines, -23 removed lines patch added patch discarded remove patch
@@ -42,44 +42,44 @@  discard block
 block discarded – undo
42 42
     {
43 43
         $html = '';
44 44
         // set something unique for the id
45
-        $html_id = (string)$input->html_id() !== ''
46
-            ? (string)$input->html_id()
45
+        $html_id = (string) $input->html_id() !== ''
46
+            ? (string) $input->html_id()
47 47
             : spl_object_hash($input);
48 48
         // and add a generic input type class
49
-        $html_class = sanitize_key(str_replace('_', '-', get_class($input))) . '-dv';
49
+        $html_class = sanitize_key(str_replace('_', '-', get_class($input))).'-dv';
50 50
         if ($input instanceof EE_Hidden_Input) {
51
-            $html .= EEH_HTML::nl() . $input->get_html_for_input();
51
+            $html .= EEH_HTML::nl().$input->get_html_for_input();
52 52
         } else if ($input instanceof EE_Submit_Input) {
53 53
             $html .= EEH_HTML::div(
54 54
                 $input->get_html_for_input(),
55
-                $html_id . '-submit-dv',
55
+                $html_id.'-submit-dv',
56 56
                 "{$input->html_class()}-submit-dv {$html_class}"
57 57
             );
58 58
         } else if ($input instanceof EE_Select_Input) {
59 59
             $html .= EEH_HTML::div(
60
-                EEH_HTML::nl(1) . $input->get_html_for_label() .
61
-                EEH_HTML::nl() . $input->get_html_for_errors() .
62
-                EEH_HTML::nl() . $input->get_html_for_input() .
63
-                EEH_HTML::nl() . $input->get_html_for_help(),
64
-                $html_id . '-input-dv',
60
+                EEH_HTML::nl(1).$input->get_html_for_label().
61
+                EEH_HTML::nl().$input->get_html_for_errors().
62
+                EEH_HTML::nl().$input->get_html_for_input().
63
+                EEH_HTML::nl().$input->get_html_for_help(),
64
+                $html_id.'-input-dv',
65 65
                 "{$input->html_class()}-input-dv {$html_class}"
66 66
             );
67 67
         } else if ($input instanceof EE_Form_Input_With_Options_Base) {
68 68
             $html .= EEH_HTML::div(
69
-                EEH_HTML::nl() . $this->_display_label_for_option_type_question($input) .
70
-                EEH_HTML::nl() . $input->get_html_for_errors() .
71
-                EEH_HTML::nl() . $input->get_html_for_input() .
72
-                EEH_HTML::nl() . $input->get_html_for_help(),
73
-                $html_id . '-input-dv',
69
+                EEH_HTML::nl().$this->_display_label_for_option_type_question($input).
70
+                EEH_HTML::nl().$input->get_html_for_errors().
71
+                EEH_HTML::nl().$input->get_html_for_input().
72
+                EEH_HTML::nl().$input->get_html_for_help(),
73
+                $html_id.'-input-dv',
74 74
                 "{$input->html_class()}-input-dv {$html_class}"
75 75
             );
76 76
         } else {
77 77
             $html .= EEH_HTML::div(
78
-                EEH_HTML::nl(1) . $input->get_html_for_label() .
79
-                EEH_HTML::nl() . $input->get_html_for_errors() .
80
-                EEH_HTML::nl() . $input->get_html_for_input() .
81
-                EEH_HTML::nl() . $input->get_html_for_help(),
82
-                $html_id . '-input-dv',
78
+                EEH_HTML::nl(1).$input->get_html_for_label().
79
+                EEH_HTML::nl().$input->get_html_for_errors().
80
+                EEH_HTML::nl().$input->get_html_for_input().
81
+                EEH_HTML::nl().$input->get_html_for_help(),
82
+                $html_id.'-input-dv',
83 83
                 "{$input->html_class()}-input-dv {$html_class}"
84 84
             );
85 85
         }
@@ -102,11 +102,11 @@  discard block
 block discarded – undo
102 102
         if ($input->display_html_label_text() !== '') {
103 103
             return EEH_HTML::div(
104 104
                 $input->required()
105
-                    ? $input->html_label_text() . EEH_HTML::span('*', '', 'ee-asterisk')
105
+                    ? $input->html_label_text().EEH_HTML::span('*', '', 'ee-asterisk')
106 106
                     : $input->html_label_text(),
107 107
                 $input->html_label_id(),
108 108
                 $input->required()
109
-                    ? 'ee-required-label ' . $input->html_label_class()
109
+                    ? 'ee-required-label '.$input->html_label_class()
110 110
                     : $input->html_label_class(),
111 111
                 $input->html_label_style(),
112 112
                 $input->html_other_attributes()
@@ -126,7 +126,7 @@  discard block
 block discarded – undo
126 126
     public function layout_subsection($form_section)
127 127
     {
128 128
         //		d( $form_section );
129
-        return EEH_HTML::nl(1) . $form_section->get_html() . EEH_HTML::nl(-1);
129
+        return EEH_HTML::nl(1).$form_section->get_html().EEH_HTML::nl(-1);
130 130
     }
131 131
 
132 132
 
Please login to merge, or discard this patch.
core/domain/services/event/EventSpacesCalculator.php 2 patches
Indentation   +614 added lines, -614 removed lines patch added patch discarded remove patch
@@ -31,620 +31,620 @@
 block discarded – undo
31 31
 class EventSpacesCalculator
32 32
 {
33 33
 
34
-    /**
35
-     * @var EE_Event $event
36
-     */
37
-    private $event;
38
-
39
-    /**
40
-     * @var array $datetime_query_params
41
-     */
42
-    private $datetime_query_params;
43
-
44
-    /**
45
-     * @var EE_Ticket[] $active_tickets
46
-     */
47
-    private $active_tickets = array();
48
-
49
-    /**
50
-     * @var EE_Datetime[] $datetimes
51
-     */
52
-    private $datetimes = array();
53
-
54
-    /**
55
-     * Array of Ticket IDs grouped by Datetime
56
-     *
57
-     * @var array $datetimes
58
-     */
59
-    private $datetime_tickets = array();
60
-
61
-    /**
62
-     * Max spaces for each Datetime (reg limit - previous sold)
63
-     *
64
-     * @var array $datetime_spaces
65
-     */
66
-    private $datetime_spaces = array();
67
-
68
-    /**
69
-     * Array of Datetime IDs grouped by Ticket
70
-     *
71
-     * @var array $ticket_datetimes
72
-     */
73
-    private $ticket_datetimes = array();
74
-
75
-    /**
76
-     * maximum ticket quantities for each ticket (adjusted for reg limit)
77
-     *
78
-     * @var array $ticket_quantities
79
-     */
80
-    private $ticket_quantities = array();
81
-
82
-    /**
83
-     * total quantity of sold and reserved for each ticket
84
-     *
85
-     * @var array $tickets_sold
86
-     */
87
-    private $tickets_sold = array();
88
-
89
-    /**
90
-     * total spaces available across all datetimes
91
-     *
92
-     * @var array $total_spaces
93
-     */
94
-    private $total_spaces = array();
95
-
96
-    /**
97
-     * @var boolean $debug
98
-     */
99
-    private $debug = false;
100
-
101
-
102
-
103
-    /**
104
-     * EventSpacesCalculator constructor.
105
-     *
106
-     * @param EE_Event $event
107
-     * @param array    $datetime_query_params
108
-     * @throws EE_Error
109
-     */
110
-    public function __construct(EE_Event $event, array $datetime_query_params = array())
111
-    {
112
-        $this->event                 = $event;
113
-        $this->datetime_query_params = $datetime_query_params + array('order_by' => array('DTT_reg_limit' => 'ASC'));
114
-    }
115
-
116
-
117
-
118
-    /**
119
-     * @return EE_Ticket[]
120
-     * @throws EE_Error
121
-     * @throws InvalidDataTypeException
122
-     * @throws InvalidInterfaceException
123
-     * @throws InvalidArgumentException
124
-     */
125
-    public function getActiveTickets()
126
-    {
127
-        if (empty($this->active_tickets)) {
128
-            $this->active_tickets = $this->event->tickets(
129
-                array(
130
-                    array(
131
-                        'TKT_end_date' => array('>=', EEM_Ticket::instance()->current_time_for_query('TKT_end_date')),
132
-                        'TKT_deleted'  => false,
133
-                    ),
134
-                    'order_by' => array('TKT_qty' => 'ASC'),
135
-                )
136
-            );
137
-        }
138
-        return $this->active_tickets;
139
-    }
140
-
141
-
142
-
143
-    /**
144
-     * @param EE_Ticket[] $active_tickets
145
-     * @throws EE_Error
146
-     * @throws DomainException
147
-     * @throws UnexpectedEntityException
148
-     */
149
-    public function setActiveTickets(array $active_tickets = array())
150
-    {
151
-        if ( ! empty($active_tickets)) {
152
-            foreach ($active_tickets as $active_ticket) {
153
-                $this->validateTicket($active_ticket);
154
-            }
155
-            // sort incoming array by ticket quantity (asc)
156
-            usort(
157
-                $active_tickets,
158
-                function (EE_Ticket $a, EE_Ticket $b) {
159
-                    if ($a->qty() === $b->qty()) {
160
-                        return 0;
161
-                    }
162
-                    return ($a->qty() < $b->qty())
163
-                        ? -1
164
-                        : 1;
165
-                }
166
-            );
167
-        }
168
-        $this->active_tickets = $active_tickets;
169
-    }
170
-
171
-
172
-
173
-    /**
174
-     * @param $ticket
175
-     * @throws DomainException
176
-     * @throws EE_Error
177
-     * @throws UnexpectedEntityException
178
-     */
179
-    private function validateTicket($ticket)
180
-    {
181
-        if ( ! $ticket instanceof EE_Ticket) {
182
-            throw new DomainException(
183
-                esc_html__(
184
-                    'Invalid Ticket. Only EE_Ticket objects can be used to calculate event space availability.',
185
-                    'event_espresso'
186
-                )
187
-            );
188
-        }
189
-        if ($ticket->get_event_ID() !== $this->event->ID()) {
190
-            throw new DomainException(
191
-                sprintf(
192
-                    esc_html__(
193
-                        'An EE_Ticket for Event %1$d was supplied while calculating event space availability for Event %2$d.',
194
-                        'event_espresso'
195
-                    ),
196
-                    $ticket->get_event_ID(),
197
-                    $this->event->ID()
198
-                )
199
-            );
200
-        }
201
-    }
202
-
203
-
204
-
205
-    /**
206
-     * @return EE_Datetime[]
207
-     */
208
-    public function getDatetimes()
209
-    {
210
-        return $this->datetimes;
211
-    }
212
-
213
-
214
-
215
-    /**
216
-     * @param EE_Datetime $datetime
217
-     * @throws EE_Error
218
-     * @throws DomainException
219
-     */
220
-    public function setDatetime(EE_Datetime $datetime)
221
-    {
222
-        if ($datetime->event()->ID() !== $this->event->ID()) {
223
-            throw new DomainException(
224
-                sprintf(
225
-                    esc_html__(
226
-                        'An EE_Datetime for Event %1$d was supplied while calculating event space availability for Event %2$d.',
227
-                        'event_espresso'
228
-                    ),
229
-                    $datetime->event()->ID(),
230
-                    $this->event->ID()
231
-                )
232
-            );
233
-        }
234
-        $this->datetimes[ $datetime->ID() ] = $datetime;
235
-    }
236
-
237
-
238
-
239
-    /**
240
-     * calculate spaces remaining based on "saleable" tickets
241
-     *
242
-     * @return float|int
243
-     * @throws EE_Error
244
-     * @throws DomainException
245
-     * @throws UnexpectedEntityException
246
-     * @throws InvalidDataTypeException
247
-     * @throws InvalidInterfaceException
248
-     * @throws InvalidArgumentException
249
-     */
250
-    public function spacesRemaining()
251
-    {
252
-        $this->initialize();
253
-        return $this->calculate();
254
-    }
255
-
256
-
257
-
258
-    /**
259
-     * calculates total available spaces for an event with no regard for sold tickets
260
-     *
261
-     * @return int|float
262
-     * @throws EE_Error
263
-     * @throws DomainException
264
-     * @throws UnexpectedEntityException
265
-     * @throws InvalidDataTypeException
266
-     * @throws InvalidInterfaceException
267
-     * @throws InvalidArgumentException
268
-     */
269
-    public function totalSpacesAvailable()
270
-    {
271
-        $this->initialize();
272
-        return $this->calculate(false);
273
-    }
274
-
275
-
276
-
277
-    /**
278
-     * Loops through the active tickets for the event
279
-     * and builds a series of data arrays that will be used for calculating
280
-     * the total maximum available spaces, as well as the spaces remaining.
281
-     * Because ticket quantities affect datetime spaces and vice versa,
282
-     * we need to be constantly updating these data arrays as things change,
283
-     * which is the entire reason for their existence.
284
-     *
285
-     * @throws EE_Error
286
-     * @throws DomainException
287
-     * @throws UnexpectedEntityException
288
-     * @throws InvalidDataTypeException
289
-     * @throws InvalidInterfaceException
290
-     * @throws InvalidArgumentException
291
-     */
292
-    private function initialize()
293
-    {
294
-        if ($this->debug) {
295
-            \EEH_Debug_Tools::printr(__FUNCTION__, __CLASS__, __FILE__, __LINE__, 2);
296
-        }
297
-        $this->datetime_tickets  = array();
298
-        $this->datetime_spaces   = array();
299
-        $this->ticket_datetimes  = array();
300
-        $this->ticket_quantities = array();
301
-        $this->tickets_sold      = array();
302
-        $this->total_spaces      = array();
303
-        $active_tickets          = $this->getActiveTickets();
304
-        if ( ! empty($active_tickets)) {
305
-            foreach ($active_tickets as $ticket) {
306
-                $this->validateTicket($ticket);
307
-                // we need to index our data arrays using strings for the purpose of sorting,
308
-                // but we also need them to be unique, so  we'll just prepend a letter T to the ID
309
-                $ticket_identifier = "T{$ticket->ID()}";
310
-                // to start, we'll just consider the raw qty to be the maximum availability for this ticket
311
-                $max_tickets = $ticket->qty();
312
-                // but we'll adjust that after looping over each datetime for the ticket and checking reg limits
313
-                $ticket_datetimes = $ticket->datetimes($this->datetime_query_params);
314
-                foreach ($ticket_datetimes as $datetime) {
315
-                    // save all datetimes
316
-                    $this->setDatetime($datetime);
317
-                    $datetime_identifier = "D{$datetime->ID()}";
318
-                    $reg_limit           = $datetime->reg_limit();
319
-                    // ticket quantity can not exceed datetime reg limit
320
-                    $max_tickets = min($max_tickets, $reg_limit);
321
-                    // as described earlier, because we need to be able to constantly adjust numbers for things,
322
-                    // we are going to move all of our data into the following arrays:
323
-                    // datetime spaces initially represents the reg limit for each datetime,
324
-                    // but this will get adjusted as tickets are accounted for
325
-                    $this->datetime_spaces[ $datetime_identifier ] = $reg_limit;
326
-                    // just an array of ticket IDs grouped by datetime
327
-                    $this->datetime_tickets[ $datetime_identifier ][] = $ticket_identifier;
328
-                    // and an array of datetime IDs grouped by ticket
329
-                    $this->ticket_datetimes[ $ticket_identifier ][] = $datetime_identifier;
330
-                }
331
-                // total quantity of sold and reserved for each ticket
332
-                $this->tickets_sold[ $ticket_identifier ] = $ticket->sold() + $ticket->reserved();
333
-                // and the maximum ticket quantities for each ticket (adjusted for reg limit)
334
-                $this->ticket_quantities[ $ticket_identifier ] = $max_tickets;
335
-            }
336
-        }
337
-        // sort datetime spaces by reg limit, but maintain our string indexes
338
-        asort($this->datetime_spaces, SORT_NUMERIC);
339
-        // datetime tickets need to be sorted in the SAME order as the above array...
340
-        // so we'll just use array_merge() to take the structure of datetime_spaces
341
-        // but overwrite all of the data with that from datetime_tickets
342
-        $this->datetime_tickets = array_merge(
343
-            $this->datetime_spaces,
344
-            $this->datetime_tickets
345
-        );
346
-        if ($this->debug) {
347
-            \EEH_Debug_Tools::printr($this->datetime_spaces, 'datetime_spaces', __FILE__, __LINE__);
348
-            \EEH_Debug_Tools::printr($this->datetime_tickets, 'datetime_tickets', __FILE__, __LINE__);
349
-            \EEH_Debug_Tools::printr($this->ticket_quantities, 'ticket_quantities', __FILE__, __LINE__);
350
-        }
351
-    }
352
-
353
-
354
-
355
-    /**
356
-     * performs calculations on initialized data
357
-     *
358
-     * @param bool $consider_sold
359
-     * @return int|float
360
-     */
361
-    private function calculate($consider_sold = true)
362
-    {
363
-        if ($this->debug) {
364
-            \EEH_Debug_Tools::printr(__FUNCTION__, __CLASS__, __FILE__, __LINE__, 2);
365
-        }
366
-        if ($consider_sold) {
367
-            // subtract amounts sold from all ticket quantities and datetime spaces
368
-            $this->adjustTicketQuantitiesDueToSales();
369
-        }
370
-        foreach ($this->datetime_tickets as $datetime_identifier => $tickets) {
371
-            $this->trackAvailableSpacesForDatetimes($datetime_identifier, $tickets);
372
-        }
373
-        // total spaces available is just the sum of the spaces available for each datetime
374
-        $spaces_remaining = array_sum($this->total_spaces);
375
-        if ($this->debug) {
376
-            \EEH_Debug_Tools::printr($this->total_spaces, '$this->total_spaces', __FILE__, __LINE__);
377
-            \EEH_Debug_Tools::printr($this->tickets_sold, '$this->tickets_sold', __FILE__, __LINE__);
378
-            \EEH_Debug_Tools::printr($spaces_remaining, '$spaces_remaining', __FILE__, __LINE__);
379
-        }
380
-        return $spaces_remaining;
381
-    }
382
-
383
-
384
-    /**
385
-     * subtracts amount of  tickets sold from ticket quantities and datetime spaces
386
-     */
387
-    private function adjustTicketQuantitiesDueToSales()
388
-    {
389
-        if ($this->debug) {
390
-            \EEH_Debug_Tools::printr(__FUNCTION__, __CLASS__, __FILE__, __LINE__, 2);
391
-        }
392
-        foreach ($this->tickets_sold as $ticket_identifier => $tickets_sold) {
393
-            if (isset($this->ticket_quantities[ $ticket_identifier ])){
394
-                $this->ticket_quantities[ $ticket_identifier ] -= $tickets_sold;
395
-                if ($this->debug) {
396
-                    \EEH_Debug_Tools::printr("{$tickets_sold} sales for ticket {$ticket_identifier} ", 'subtracting', __FILE__, __LINE__);
397
-                }
398
-            }
399
-            if (
400
-                isset($this->ticket_datetimes[ $ticket_identifier ])
401
-                && is_array($this->ticket_datetimes[ $ticket_identifier ])
402
-            ){
403
-                foreach ($this->ticket_datetimes[ $ticket_identifier ] as $ticket_datetime) {
404
-                    if (isset($this->ticket_quantities[ $ticket_identifier ])) {
405
-                        $this->datetime_spaces[ $ticket_datetime ] -= $tickets_sold;
406
-                        if ($this->debug) {
407
-                            \EEH_Debug_Tools::printr("{$tickets_sold} sales for datetime {$ticket_datetime} ",
408
-                                'subtracting', __FILE__, __LINE__);
409
-                        }
410
-                    }
411
-                }
412
-            }
413
-        }
414
-    }
415
-
416
-
417
-
418
-    /**
419
-     * @param string $datetime_identifier
420
-     * @param array  $tickets
421
-     */
422
-    private function trackAvailableSpacesForDatetimes($datetime_identifier, array $tickets)
423
-    {
424
-        // make sure a reg limit is set for the datetime
425
-        $reg_limit = isset($this->datetime_spaces[ $datetime_identifier ])
426
-            ? $this->datetime_spaces[ $datetime_identifier ]
427
-            : 0;
428
-        // and bail if it is not
429
-        if ( ! $reg_limit) {
430
-            if ($this->debug) {
431
-                \EEH_Debug_Tools::printr('AT CAPACITY', " . {$datetime_identifier}", __FILE__, __LINE__);
432
-            }
433
-            return;
434
-        }
435
-        if ($this->debug) {
436
-            \EEH_Debug_Tools::printr($datetime_identifier, '* $datetime_identifier', __FILE__, __LINE__, 1);
437
-            \EEH_Debug_Tools::printr("{$reg_limit}", 'REG LIMIT', __FILE__, __LINE__);
438
-        }
439
-        // number of allocated spaces always starts at zero
440
-        $spaces_allocated                           = 0;
441
-        $this->total_spaces[ $datetime_identifier ] = 0;
442
-        foreach ($tickets as $ticket_identifier) {
443
-            $spaces_allocated = $this->calculateAvailableSpacesForTicket(
444
-                $datetime_identifier,
445
-                $reg_limit,
446
-                $ticket_identifier,
447
-                $spaces_allocated
448
-            );
449
-        }
450
-        // spaces can't be negative
451
-        $spaces_allocated = max($spaces_allocated, 0);
452
-        if ($spaces_allocated) {
453
-            // track any non-zero values
454
-            $this->total_spaces[ $datetime_identifier ] += $spaces_allocated;
455
-            if ($this->debug) {
456
-                \EEH_Debug_Tools::printr((string)$spaces_allocated, ' . $spaces_allocated: ', __FILE__, __LINE__);
457
-            }
458
-        } else {
459
-            if ($this->debug) {
460
-                \EEH_Debug_Tools::printr(' ', ' . NO TICKETS AVAILABLE FOR DATETIME', __FILE__, __LINE__);
461
-            }
462
-        }
463
-        if ($this->debug) {
464
-            \EEH_Debug_Tools::printr($this->total_spaces[ $datetime_identifier ], '$total_spaces', __FILE__,
465
-                __LINE__);
466
-            \EEH_Debug_Tools::printr($this->ticket_quantities, '$ticket_quantities', __FILE__, __LINE__);
467
-            \EEH_Debug_Tools::printr($this->datetime_spaces, 'datetime_spaces', __FILE__, __LINE__);
468
-        }
469
-    }
470
-
471
-
472
-
473
-    /**
474
-     * @param string $datetime_identifier
475
-     * @param int    $reg_limit
476
-     * @param string $ticket_identifier
477
-     * @param int    $spaces_allocated
478
-     * @return int
479
-     */
480
-    private function calculateAvailableSpacesForTicket(
481
-        $datetime_identifier,
482
-        $reg_limit,
483
-        $ticket_identifier,
484
-        $spaces_allocated
485
-    ) {
486
-        // make sure ticket quantity is set
487
-        $ticket_quantity = isset($this->ticket_quantities[ $ticket_identifier ])
488
-            ? $this->ticket_quantities[ $ticket_identifier ]
489
-            : 0;
490
-        if ($this->debug) {
491
-            \EEH_Debug_Tools::printr("{$spaces_allocated}", '$spaces_allocated', __FILE__, __LINE__);
492
-            \EEH_Debug_Tools::printr("{$ticket_quantity}", "ticket $ticket_identifier quantity: ",
493
-                __FILE__, __LINE__, 2);
494
-        }
495
-        if ($ticket_quantity) {
496
-            if ($this->debug) {
497
-                \EEH_Debug_Tools::printr(
498
-                    ($spaces_allocated <= $reg_limit)
499
-                        ? 'true'
500
-                        : 'false',
501
-                    ' . spaces_allocated <= reg_limit = ',
502
-                    __FILE__, __LINE__
503
-                );
504
-            }
505
-            // if the datetime is NOT at full capacity yet
506
-            if ($spaces_allocated <= $reg_limit) {
507
-                // then the maximum ticket quantity we can allocate is the lowest value of either:
508
-                //  the number of remaining spaces for the datetime, which is the limit - spaces already taken
509
-                //  or the maximum ticket quantity
510
-                $ticket_quantity = min($reg_limit - $spaces_allocated, $ticket_quantity);
511
-                // adjust the available quantity in our tracking array
512
-                $this->ticket_quantities[ $ticket_identifier ] -= $ticket_quantity;
513
-                // and increment spaces allocated for this datetime
514
-                $spaces_allocated += $ticket_quantity;
515
-                $at_capacity = $spaces_allocated >= $reg_limit;
516
-                if ($this->debug) {
517
-                    \EEH_Debug_Tools::printr("{$ticket_quantity} {$ticket_identifier} tickets", ' > > allocate ',
518
-                        __FILE__, __LINE__,   3);
519
-                    if ($at_capacity) {
520
-                        \EEH_Debug_Tools::printr('AT CAPACITY', " . {$datetime_identifier}", __FILE__, __LINE__, 3);
521
-                    }
522
-                }
523
-                // now adjust all other datetimes that allow access to this ticket
524
-                $this->adjustDatetimes(
525
-                    $datetime_identifier,
526
-                    $ticket_identifier,
527
-                    $ticket_quantity,
528
-                    $at_capacity
529
-                );
530
-            }
531
-        }
532
-        return $spaces_allocated;
533
-    }
534
-
535
-
536
-
537
-    /**
538
-     * subtracts ticket amounts from all datetime reg limits
539
-     * that allow access to the ticket specified,
540
-     * because that ticket could be used
541
-     * to attend any of the datetimes it has access to
542
-     *
543
-     * @param string $datetime_identifier
544
-     * @param string $ticket_identifier
545
-     * @param bool   $at_capacity
546
-     * @param int    $ticket_quantity
547
-     */
548
-    private function adjustDatetimes(
549
-        $datetime_identifier,
550
-        $ticket_identifier,
551
-        $ticket_quantity,
552
-        $at_capacity
553
-    ) {
554
-        foreach ($this->datetime_tickets as $datetime_ID => $datetime_tickets) {
555
-            if ($datetime_ID !== $datetime_identifier || ! is_array($datetime_tickets)) {
556
-                continue;
557
-            }
558
-            $adjusted = $this->adjustDatetimeSpaces(
559
-                $datetime_ID,
560
-                $ticket_identifier,
561
-                $ticket_quantity
562
-            );
563
-            // skip to next ticket if nothing changed
564
-            if (! ($adjusted || $at_capacity)) {
565
-                continue;
566
-            }
567
-            // then all of it's tickets are now unavailable
568
-            foreach ($datetime_tickets as $datetime_ticket) {
569
-                if (
570
-                    ($ticket_identifier === $datetime_ticket || $at_capacity)
571
-                    && isset($this->ticket_quantities[ $datetime_ticket ])
572
-                    && $this->ticket_quantities[ $datetime_ticket ] > 0
573
-                ) {
574
-                    if ($this->debug) {
575
-                        \EEH_Debug_Tools::printr($datetime_ticket, ' . . . adjust ticket quantities for', __FILE__,
576
-                            __LINE__);
577
-                    }
578
-                    // if this datetime is at full capacity, set any tracked available quantities to zero
579
-                    // otherwise just subtract the ticket quantity
580
-                    $new_quantity = $at_capacity
581
-                        ? 0
582
-                        : $this->ticket_quantities[ $datetime_ticket ] - $ticket_quantity;
583
-                    // don't let ticket quantity go below zero
584
-                    $this->ticket_quantities[ $datetime_ticket ] = max($new_quantity, 0);
585
-                    if ($this->debug) {
586
-                        \EEH_Debug_Tools::printr(
587
-                            $at_capacity
588
-                                ? "0 because Datetime {$datetime_identifier} is at capacity"
589
-                                : "{$this->ticket_quantities[ $datetime_ticket ]}",
590
-                            " . . . . {$datetime_ticket} quantity set to ",
591
-                            __FILE__, __LINE__
592
-                        );
593
-                    }
594
-                }
595
-                // but we also need to adjust spaces for any other datetimes this ticket has access to
596
-                if ($datetime_ticket === $ticket_identifier) {
597
-                    if (isset($this->ticket_datetimes[ $datetime_ticket ])
598
-                        && is_array($this->ticket_datetimes[ $datetime_ticket ])
599
-                    ) {
600
-                        if ($this->debug) {
601
-                            \EEH_Debug_Tools::printr($datetime_ticket, ' . . adjust other Datetimes for', __FILE__,
602
-                                __LINE__);
603
-                        }
604
-                        foreach ($this->ticket_datetimes[ $datetime_ticket ] as $datetime) {
605
-                            // don't adjust the current datetime twice
606
-                            if ($datetime !== $datetime_identifier) {
607
-                                $this->adjustDatetimeSpaces(
608
-                                    $datetime,
609
-                                    $datetime_ticket,
610
-                                    $ticket_quantity
611
-                                );
612
-                            }
613
-                        }
614
-                    }
615
-                }
616
-            }
617
-        }
618
-    }
619
-
620
-    private function adjustDatetimeSpaces($datetime_identifier, $ticket_identifier, $ticket_quantity = 0)
621
-    {
622
-        // does datetime have spaces available?
623
-        // and does the supplied ticket have access to this datetime ?
624
-        if (
625
-            $this->datetime_spaces[ $datetime_identifier ] > 0
626
-            && isset($this->datetime_spaces[ $datetime_identifier ], $this->datetime_tickets[ $datetime_identifier ])
627
-            && in_array($ticket_identifier, $this->datetime_tickets[ $datetime_identifier ], true)
628
-            ) {
629
-            if ($this->debug) {
630
-                \EEH_Debug_Tools::printr($datetime_identifier, ' . . adjust Datetime Spaces for', __FILE__, __LINE__);
631
-                \EEH_Debug_Tools::printr("{$this->datetime_spaces[ $datetime_identifier ]}", " . . current  {$datetime_identifier} spaces available", __FILE__, __LINE__);
632
-            }
633
-            // then decrement the available spaces for the datetime
634
-            $this->datetime_spaces[ $datetime_identifier ] -= $ticket_quantity;
635
-            // but don't let quantities go below zero
636
-            $this->datetime_spaces[ $datetime_identifier ] = max(
637
-                $this->datetime_spaces[ $datetime_identifier ],
638
-                0
639
-            );
640
-            if ($this->debug) {
641
-                \EEH_Debug_Tools::printr("{$ticket_quantity}",
642
-                    " . . . {$datetime_identifier} capacity reduced by", __FILE__, __LINE__);
643
-            }
644
-            return true;
645
-        }
646
-        return false;
647
-    }
34
+	/**
35
+	 * @var EE_Event $event
36
+	 */
37
+	private $event;
38
+
39
+	/**
40
+	 * @var array $datetime_query_params
41
+	 */
42
+	private $datetime_query_params;
43
+
44
+	/**
45
+	 * @var EE_Ticket[] $active_tickets
46
+	 */
47
+	private $active_tickets = array();
48
+
49
+	/**
50
+	 * @var EE_Datetime[] $datetimes
51
+	 */
52
+	private $datetimes = array();
53
+
54
+	/**
55
+	 * Array of Ticket IDs grouped by Datetime
56
+	 *
57
+	 * @var array $datetimes
58
+	 */
59
+	private $datetime_tickets = array();
60
+
61
+	/**
62
+	 * Max spaces for each Datetime (reg limit - previous sold)
63
+	 *
64
+	 * @var array $datetime_spaces
65
+	 */
66
+	private $datetime_spaces = array();
67
+
68
+	/**
69
+	 * Array of Datetime IDs grouped by Ticket
70
+	 *
71
+	 * @var array $ticket_datetimes
72
+	 */
73
+	private $ticket_datetimes = array();
74
+
75
+	/**
76
+	 * maximum ticket quantities for each ticket (adjusted for reg limit)
77
+	 *
78
+	 * @var array $ticket_quantities
79
+	 */
80
+	private $ticket_quantities = array();
81
+
82
+	/**
83
+	 * total quantity of sold and reserved for each ticket
84
+	 *
85
+	 * @var array $tickets_sold
86
+	 */
87
+	private $tickets_sold = array();
88
+
89
+	/**
90
+	 * total spaces available across all datetimes
91
+	 *
92
+	 * @var array $total_spaces
93
+	 */
94
+	private $total_spaces = array();
95
+
96
+	/**
97
+	 * @var boolean $debug
98
+	 */
99
+	private $debug = false;
100
+
101
+
102
+
103
+	/**
104
+	 * EventSpacesCalculator constructor.
105
+	 *
106
+	 * @param EE_Event $event
107
+	 * @param array    $datetime_query_params
108
+	 * @throws EE_Error
109
+	 */
110
+	public function __construct(EE_Event $event, array $datetime_query_params = array())
111
+	{
112
+		$this->event                 = $event;
113
+		$this->datetime_query_params = $datetime_query_params + array('order_by' => array('DTT_reg_limit' => 'ASC'));
114
+	}
115
+
116
+
117
+
118
+	/**
119
+	 * @return EE_Ticket[]
120
+	 * @throws EE_Error
121
+	 * @throws InvalidDataTypeException
122
+	 * @throws InvalidInterfaceException
123
+	 * @throws InvalidArgumentException
124
+	 */
125
+	public function getActiveTickets()
126
+	{
127
+		if (empty($this->active_tickets)) {
128
+			$this->active_tickets = $this->event->tickets(
129
+				array(
130
+					array(
131
+						'TKT_end_date' => array('>=', EEM_Ticket::instance()->current_time_for_query('TKT_end_date')),
132
+						'TKT_deleted'  => false,
133
+					),
134
+					'order_by' => array('TKT_qty' => 'ASC'),
135
+				)
136
+			);
137
+		}
138
+		return $this->active_tickets;
139
+	}
140
+
141
+
142
+
143
+	/**
144
+	 * @param EE_Ticket[] $active_tickets
145
+	 * @throws EE_Error
146
+	 * @throws DomainException
147
+	 * @throws UnexpectedEntityException
148
+	 */
149
+	public function setActiveTickets(array $active_tickets = array())
150
+	{
151
+		if ( ! empty($active_tickets)) {
152
+			foreach ($active_tickets as $active_ticket) {
153
+				$this->validateTicket($active_ticket);
154
+			}
155
+			// sort incoming array by ticket quantity (asc)
156
+			usort(
157
+				$active_tickets,
158
+				function (EE_Ticket $a, EE_Ticket $b) {
159
+					if ($a->qty() === $b->qty()) {
160
+						return 0;
161
+					}
162
+					return ($a->qty() < $b->qty())
163
+						? -1
164
+						: 1;
165
+				}
166
+			);
167
+		}
168
+		$this->active_tickets = $active_tickets;
169
+	}
170
+
171
+
172
+
173
+	/**
174
+	 * @param $ticket
175
+	 * @throws DomainException
176
+	 * @throws EE_Error
177
+	 * @throws UnexpectedEntityException
178
+	 */
179
+	private function validateTicket($ticket)
180
+	{
181
+		if ( ! $ticket instanceof EE_Ticket) {
182
+			throw new DomainException(
183
+				esc_html__(
184
+					'Invalid Ticket. Only EE_Ticket objects can be used to calculate event space availability.',
185
+					'event_espresso'
186
+				)
187
+			);
188
+		}
189
+		if ($ticket->get_event_ID() !== $this->event->ID()) {
190
+			throw new DomainException(
191
+				sprintf(
192
+					esc_html__(
193
+						'An EE_Ticket for Event %1$d was supplied while calculating event space availability for Event %2$d.',
194
+						'event_espresso'
195
+					),
196
+					$ticket->get_event_ID(),
197
+					$this->event->ID()
198
+				)
199
+			);
200
+		}
201
+	}
202
+
203
+
204
+
205
+	/**
206
+	 * @return EE_Datetime[]
207
+	 */
208
+	public function getDatetimes()
209
+	{
210
+		return $this->datetimes;
211
+	}
212
+
213
+
214
+
215
+	/**
216
+	 * @param EE_Datetime $datetime
217
+	 * @throws EE_Error
218
+	 * @throws DomainException
219
+	 */
220
+	public function setDatetime(EE_Datetime $datetime)
221
+	{
222
+		if ($datetime->event()->ID() !== $this->event->ID()) {
223
+			throw new DomainException(
224
+				sprintf(
225
+					esc_html__(
226
+						'An EE_Datetime for Event %1$d was supplied while calculating event space availability for Event %2$d.',
227
+						'event_espresso'
228
+					),
229
+					$datetime->event()->ID(),
230
+					$this->event->ID()
231
+				)
232
+			);
233
+		}
234
+		$this->datetimes[ $datetime->ID() ] = $datetime;
235
+	}
236
+
237
+
238
+
239
+	/**
240
+	 * calculate spaces remaining based on "saleable" tickets
241
+	 *
242
+	 * @return float|int
243
+	 * @throws EE_Error
244
+	 * @throws DomainException
245
+	 * @throws UnexpectedEntityException
246
+	 * @throws InvalidDataTypeException
247
+	 * @throws InvalidInterfaceException
248
+	 * @throws InvalidArgumentException
249
+	 */
250
+	public function spacesRemaining()
251
+	{
252
+		$this->initialize();
253
+		return $this->calculate();
254
+	}
255
+
256
+
257
+
258
+	/**
259
+	 * calculates total available spaces for an event with no regard for sold tickets
260
+	 *
261
+	 * @return int|float
262
+	 * @throws EE_Error
263
+	 * @throws DomainException
264
+	 * @throws UnexpectedEntityException
265
+	 * @throws InvalidDataTypeException
266
+	 * @throws InvalidInterfaceException
267
+	 * @throws InvalidArgumentException
268
+	 */
269
+	public function totalSpacesAvailable()
270
+	{
271
+		$this->initialize();
272
+		return $this->calculate(false);
273
+	}
274
+
275
+
276
+
277
+	/**
278
+	 * Loops through the active tickets for the event
279
+	 * and builds a series of data arrays that will be used for calculating
280
+	 * the total maximum available spaces, as well as the spaces remaining.
281
+	 * Because ticket quantities affect datetime spaces and vice versa,
282
+	 * we need to be constantly updating these data arrays as things change,
283
+	 * which is the entire reason for their existence.
284
+	 *
285
+	 * @throws EE_Error
286
+	 * @throws DomainException
287
+	 * @throws UnexpectedEntityException
288
+	 * @throws InvalidDataTypeException
289
+	 * @throws InvalidInterfaceException
290
+	 * @throws InvalidArgumentException
291
+	 */
292
+	private function initialize()
293
+	{
294
+		if ($this->debug) {
295
+			\EEH_Debug_Tools::printr(__FUNCTION__, __CLASS__, __FILE__, __LINE__, 2);
296
+		}
297
+		$this->datetime_tickets  = array();
298
+		$this->datetime_spaces   = array();
299
+		$this->ticket_datetimes  = array();
300
+		$this->ticket_quantities = array();
301
+		$this->tickets_sold      = array();
302
+		$this->total_spaces      = array();
303
+		$active_tickets          = $this->getActiveTickets();
304
+		if ( ! empty($active_tickets)) {
305
+			foreach ($active_tickets as $ticket) {
306
+				$this->validateTicket($ticket);
307
+				// we need to index our data arrays using strings for the purpose of sorting,
308
+				// but we also need them to be unique, so  we'll just prepend a letter T to the ID
309
+				$ticket_identifier = "T{$ticket->ID()}";
310
+				// to start, we'll just consider the raw qty to be the maximum availability for this ticket
311
+				$max_tickets = $ticket->qty();
312
+				// but we'll adjust that after looping over each datetime for the ticket and checking reg limits
313
+				$ticket_datetimes = $ticket->datetimes($this->datetime_query_params);
314
+				foreach ($ticket_datetimes as $datetime) {
315
+					// save all datetimes
316
+					$this->setDatetime($datetime);
317
+					$datetime_identifier = "D{$datetime->ID()}";
318
+					$reg_limit           = $datetime->reg_limit();
319
+					// ticket quantity can not exceed datetime reg limit
320
+					$max_tickets = min($max_tickets, $reg_limit);
321
+					// as described earlier, because we need to be able to constantly adjust numbers for things,
322
+					// we are going to move all of our data into the following arrays:
323
+					// datetime spaces initially represents the reg limit for each datetime,
324
+					// but this will get adjusted as tickets are accounted for
325
+					$this->datetime_spaces[ $datetime_identifier ] = $reg_limit;
326
+					// just an array of ticket IDs grouped by datetime
327
+					$this->datetime_tickets[ $datetime_identifier ][] = $ticket_identifier;
328
+					// and an array of datetime IDs grouped by ticket
329
+					$this->ticket_datetimes[ $ticket_identifier ][] = $datetime_identifier;
330
+				}
331
+				// total quantity of sold and reserved for each ticket
332
+				$this->tickets_sold[ $ticket_identifier ] = $ticket->sold() + $ticket->reserved();
333
+				// and the maximum ticket quantities for each ticket (adjusted for reg limit)
334
+				$this->ticket_quantities[ $ticket_identifier ] = $max_tickets;
335
+			}
336
+		}
337
+		// sort datetime spaces by reg limit, but maintain our string indexes
338
+		asort($this->datetime_spaces, SORT_NUMERIC);
339
+		// datetime tickets need to be sorted in the SAME order as the above array...
340
+		// so we'll just use array_merge() to take the structure of datetime_spaces
341
+		// but overwrite all of the data with that from datetime_tickets
342
+		$this->datetime_tickets = array_merge(
343
+			$this->datetime_spaces,
344
+			$this->datetime_tickets
345
+		);
346
+		if ($this->debug) {
347
+			\EEH_Debug_Tools::printr($this->datetime_spaces, 'datetime_spaces', __FILE__, __LINE__);
348
+			\EEH_Debug_Tools::printr($this->datetime_tickets, 'datetime_tickets', __FILE__, __LINE__);
349
+			\EEH_Debug_Tools::printr($this->ticket_quantities, 'ticket_quantities', __FILE__, __LINE__);
350
+		}
351
+	}
352
+
353
+
354
+
355
+	/**
356
+	 * performs calculations on initialized data
357
+	 *
358
+	 * @param bool $consider_sold
359
+	 * @return int|float
360
+	 */
361
+	private function calculate($consider_sold = true)
362
+	{
363
+		if ($this->debug) {
364
+			\EEH_Debug_Tools::printr(__FUNCTION__, __CLASS__, __FILE__, __LINE__, 2);
365
+		}
366
+		if ($consider_sold) {
367
+			// subtract amounts sold from all ticket quantities and datetime spaces
368
+			$this->adjustTicketQuantitiesDueToSales();
369
+		}
370
+		foreach ($this->datetime_tickets as $datetime_identifier => $tickets) {
371
+			$this->trackAvailableSpacesForDatetimes($datetime_identifier, $tickets);
372
+		}
373
+		// total spaces available is just the sum of the spaces available for each datetime
374
+		$spaces_remaining = array_sum($this->total_spaces);
375
+		if ($this->debug) {
376
+			\EEH_Debug_Tools::printr($this->total_spaces, '$this->total_spaces', __FILE__, __LINE__);
377
+			\EEH_Debug_Tools::printr($this->tickets_sold, '$this->tickets_sold', __FILE__, __LINE__);
378
+			\EEH_Debug_Tools::printr($spaces_remaining, '$spaces_remaining', __FILE__, __LINE__);
379
+		}
380
+		return $spaces_remaining;
381
+	}
382
+
383
+
384
+	/**
385
+	 * subtracts amount of  tickets sold from ticket quantities and datetime spaces
386
+	 */
387
+	private function adjustTicketQuantitiesDueToSales()
388
+	{
389
+		if ($this->debug) {
390
+			\EEH_Debug_Tools::printr(__FUNCTION__, __CLASS__, __FILE__, __LINE__, 2);
391
+		}
392
+		foreach ($this->tickets_sold as $ticket_identifier => $tickets_sold) {
393
+			if (isset($this->ticket_quantities[ $ticket_identifier ])){
394
+				$this->ticket_quantities[ $ticket_identifier ] -= $tickets_sold;
395
+				if ($this->debug) {
396
+					\EEH_Debug_Tools::printr("{$tickets_sold} sales for ticket {$ticket_identifier} ", 'subtracting', __FILE__, __LINE__);
397
+				}
398
+			}
399
+			if (
400
+				isset($this->ticket_datetimes[ $ticket_identifier ])
401
+				&& is_array($this->ticket_datetimes[ $ticket_identifier ])
402
+			){
403
+				foreach ($this->ticket_datetimes[ $ticket_identifier ] as $ticket_datetime) {
404
+					if (isset($this->ticket_quantities[ $ticket_identifier ])) {
405
+						$this->datetime_spaces[ $ticket_datetime ] -= $tickets_sold;
406
+						if ($this->debug) {
407
+							\EEH_Debug_Tools::printr("{$tickets_sold} sales for datetime {$ticket_datetime} ",
408
+								'subtracting', __FILE__, __LINE__);
409
+						}
410
+					}
411
+				}
412
+			}
413
+		}
414
+	}
415
+
416
+
417
+
418
+	/**
419
+	 * @param string $datetime_identifier
420
+	 * @param array  $tickets
421
+	 */
422
+	private function trackAvailableSpacesForDatetimes($datetime_identifier, array $tickets)
423
+	{
424
+		// make sure a reg limit is set for the datetime
425
+		$reg_limit = isset($this->datetime_spaces[ $datetime_identifier ])
426
+			? $this->datetime_spaces[ $datetime_identifier ]
427
+			: 0;
428
+		// and bail if it is not
429
+		if ( ! $reg_limit) {
430
+			if ($this->debug) {
431
+				\EEH_Debug_Tools::printr('AT CAPACITY', " . {$datetime_identifier}", __FILE__, __LINE__);
432
+			}
433
+			return;
434
+		}
435
+		if ($this->debug) {
436
+			\EEH_Debug_Tools::printr($datetime_identifier, '* $datetime_identifier', __FILE__, __LINE__, 1);
437
+			\EEH_Debug_Tools::printr("{$reg_limit}", 'REG LIMIT', __FILE__, __LINE__);
438
+		}
439
+		// number of allocated spaces always starts at zero
440
+		$spaces_allocated                           = 0;
441
+		$this->total_spaces[ $datetime_identifier ] = 0;
442
+		foreach ($tickets as $ticket_identifier) {
443
+			$spaces_allocated = $this->calculateAvailableSpacesForTicket(
444
+				$datetime_identifier,
445
+				$reg_limit,
446
+				$ticket_identifier,
447
+				$spaces_allocated
448
+			);
449
+		}
450
+		// spaces can't be negative
451
+		$spaces_allocated = max($spaces_allocated, 0);
452
+		if ($spaces_allocated) {
453
+			// track any non-zero values
454
+			$this->total_spaces[ $datetime_identifier ] += $spaces_allocated;
455
+			if ($this->debug) {
456
+				\EEH_Debug_Tools::printr((string)$spaces_allocated, ' . $spaces_allocated: ', __FILE__, __LINE__);
457
+			}
458
+		} else {
459
+			if ($this->debug) {
460
+				\EEH_Debug_Tools::printr(' ', ' . NO TICKETS AVAILABLE FOR DATETIME', __FILE__, __LINE__);
461
+			}
462
+		}
463
+		if ($this->debug) {
464
+			\EEH_Debug_Tools::printr($this->total_spaces[ $datetime_identifier ], '$total_spaces', __FILE__,
465
+				__LINE__);
466
+			\EEH_Debug_Tools::printr($this->ticket_quantities, '$ticket_quantities', __FILE__, __LINE__);
467
+			\EEH_Debug_Tools::printr($this->datetime_spaces, 'datetime_spaces', __FILE__, __LINE__);
468
+		}
469
+	}
470
+
471
+
472
+
473
+	/**
474
+	 * @param string $datetime_identifier
475
+	 * @param int    $reg_limit
476
+	 * @param string $ticket_identifier
477
+	 * @param int    $spaces_allocated
478
+	 * @return int
479
+	 */
480
+	private function calculateAvailableSpacesForTicket(
481
+		$datetime_identifier,
482
+		$reg_limit,
483
+		$ticket_identifier,
484
+		$spaces_allocated
485
+	) {
486
+		// make sure ticket quantity is set
487
+		$ticket_quantity = isset($this->ticket_quantities[ $ticket_identifier ])
488
+			? $this->ticket_quantities[ $ticket_identifier ]
489
+			: 0;
490
+		if ($this->debug) {
491
+			\EEH_Debug_Tools::printr("{$spaces_allocated}", '$spaces_allocated', __FILE__, __LINE__);
492
+			\EEH_Debug_Tools::printr("{$ticket_quantity}", "ticket $ticket_identifier quantity: ",
493
+				__FILE__, __LINE__, 2);
494
+		}
495
+		if ($ticket_quantity) {
496
+			if ($this->debug) {
497
+				\EEH_Debug_Tools::printr(
498
+					($spaces_allocated <= $reg_limit)
499
+						? 'true'
500
+						: 'false',
501
+					' . spaces_allocated <= reg_limit = ',
502
+					__FILE__, __LINE__
503
+				);
504
+			}
505
+			// if the datetime is NOT at full capacity yet
506
+			if ($spaces_allocated <= $reg_limit) {
507
+				// then the maximum ticket quantity we can allocate is the lowest value of either:
508
+				//  the number of remaining spaces for the datetime, which is the limit - spaces already taken
509
+				//  or the maximum ticket quantity
510
+				$ticket_quantity = min($reg_limit - $spaces_allocated, $ticket_quantity);
511
+				// adjust the available quantity in our tracking array
512
+				$this->ticket_quantities[ $ticket_identifier ] -= $ticket_quantity;
513
+				// and increment spaces allocated for this datetime
514
+				$spaces_allocated += $ticket_quantity;
515
+				$at_capacity = $spaces_allocated >= $reg_limit;
516
+				if ($this->debug) {
517
+					\EEH_Debug_Tools::printr("{$ticket_quantity} {$ticket_identifier} tickets", ' > > allocate ',
518
+						__FILE__, __LINE__,   3);
519
+					if ($at_capacity) {
520
+						\EEH_Debug_Tools::printr('AT CAPACITY', " . {$datetime_identifier}", __FILE__, __LINE__, 3);
521
+					}
522
+				}
523
+				// now adjust all other datetimes that allow access to this ticket
524
+				$this->adjustDatetimes(
525
+					$datetime_identifier,
526
+					$ticket_identifier,
527
+					$ticket_quantity,
528
+					$at_capacity
529
+				);
530
+			}
531
+		}
532
+		return $spaces_allocated;
533
+	}
534
+
535
+
536
+
537
+	/**
538
+	 * subtracts ticket amounts from all datetime reg limits
539
+	 * that allow access to the ticket specified,
540
+	 * because that ticket could be used
541
+	 * to attend any of the datetimes it has access to
542
+	 *
543
+	 * @param string $datetime_identifier
544
+	 * @param string $ticket_identifier
545
+	 * @param bool   $at_capacity
546
+	 * @param int    $ticket_quantity
547
+	 */
548
+	private function adjustDatetimes(
549
+		$datetime_identifier,
550
+		$ticket_identifier,
551
+		$ticket_quantity,
552
+		$at_capacity
553
+	) {
554
+		foreach ($this->datetime_tickets as $datetime_ID => $datetime_tickets) {
555
+			if ($datetime_ID !== $datetime_identifier || ! is_array($datetime_tickets)) {
556
+				continue;
557
+			}
558
+			$adjusted = $this->adjustDatetimeSpaces(
559
+				$datetime_ID,
560
+				$ticket_identifier,
561
+				$ticket_quantity
562
+			);
563
+			// skip to next ticket if nothing changed
564
+			if (! ($adjusted || $at_capacity)) {
565
+				continue;
566
+			}
567
+			// then all of it's tickets are now unavailable
568
+			foreach ($datetime_tickets as $datetime_ticket) {
569
+				if (
570
+					($ticket_identifier === $datetime_ticket || $at_capacity)
571
+					&& isset($this->ticket_quantities[ $datetime_ticket ])
572
+					&& $this->ticket_quantities[ $datetime_ticket ] > 0
573
+				) {
574
+					if ($this->debug) {
575
+						\EEH_Debug_Tools::printr($datetime_ticket, ' . . . adjust ticket quantities for', __FILE__,
576
+							__LINE__);
577
+					}
578
+					// if this datetime is at full capacity, set any tracked available quantities to zero
579
+					// otherwise just subtract the ticket quantity
580
+					$new_quantity = $at_capacity
581
+						? 0
582
+						: $this->ticket_quantities[ $datetime_ticket ] - $ticket_quantity;
583
+					// don't let ticket quantity go below zero
584
+					$this->ticket_quantities[ $datetime_ticket ] = max($new_quantity, 0);
585
+					if ($this->debug) {
586
+						\EEH_Debug_Tools::printr(
587
+							$at_capacity
588
+								? "0 because Datetime {$datetime_identifier} is at capacity"
589
+								: "{$this->ticket_quantities[ $datetime_ticket ]}",
590
+							" . . . . {$datetime_ticket} quantity set to ",
591
+							__FILE__, __LINE__
592
+						);
593
+					}
594
+				}
595
+				// but we also need to adjust spaces for any other datetimes this ticket has access to
596
+				if ($datetime_ticket === $ticket_identifier) {
597
+					if (isset($this->ticket_datetimes[ $datetime_ticket ])
598
+						&& is_array($this->ticket_datetimes[ $datetime_ticket ])
599
+					) {
600
+						if ($this->debug) {
601
+							\EEH_Debug_Tools::printr($datetime_ticket, ' . . adjust other Datetimes for', __FILE__,
602
+								__LINE__);
603
+						}
604
+						foreach ($this->ticket_datetimes[ $datetime_ticket ] as $datetime) {
605
+							// don't adjust the current datetime twice
606
+							if ($datetime !== $datetime_identifier) {
607
+								$this->adjustDatetimeSpaces(
608
+									$datetime,
609
+									$datetime_ticket,
610
+									$ticket_quantity
611
+								);
612
+							}
613
+						}
614
+					}
615
+				}
616
+			}
617
+		}
618
+	}
619
+
620
+	private function adjustDatetimeSpaces($datetime_identifier, $ticket_identifier, $ticket_quantity = 0)
621
+	{
622
+		// does datetime have spaces available?
623
+		// and does the supplied ticket have access to this datetime ?
624
+		if (
625
+			$this->datetime_spaces[ $datetime_identifier ] > 0
626
+			&& isset($this->datetime_spaces[ $datetime_identifier ], $this->datetime_tickets[ $datetime_identifier ])
627
+			&& in_array($ticket_identifier, $this->datetime_tickets[ $datetime_identifier ], true)
628
+			) {
629
+			if ($this->debug) {
630
+				\EEH_Debug_Tools::printr($datetime_identifier, ' . . adjust Datetime Spaces for', __FILE__, __LINE__);
631
+				\EEH_Debug_Tools::printr("{$this->datetime_spaces[ $datetime_identifier ]}", " . . current  {$datetime_identifier} spaces available", __FILE__, __LINE__);
632
+			}
633
+			// then decrement the available spaces for the datetime
634
+			$this->datetime_spaces[ $datetime_identifier ] -= $ticket_quantity;
635
+			// but don't let quantities go below zero
636
+			$this->datetime_spaces[ $datetime_identifier ] = max(
637
+				$this->datetime_spaces[ $datetime_identifier ],
638
+				0
639
+			);
640
+			if ($this->debug) {
641
+				\EEH_Debug_Tools::printr("{$ticket_quantity}",
642
+					" . . . {$datetime_identifier} capacity reduced by", __FILE__, __LINE__);
643
+			}
644
+			return true;
645
+		}
646
+		return false;
647
+	}
648 648
 
649 649
 }
650 650
 // Location: EventSpacesCalculator.php
Please login to merge, or discard this patch.
Spacing   +41 added lines, -41 removed lines patch added patch discarded remove patch
@@ -155,7 +155,7 @@  discard block
 block discarded – undo
155 155
             // sort incoming array by ticket quantity (asc)
156 156
             usort(
157 157
                 $active_tickets,
158
-                function (EE_Ticket $a, EE_Ticket $b) {
158
+                function(EE_Ticket $a, EE_Ticket $b) {
159 159
                     if ($a->qty() === $b->qty()) {
160 160
                         return 0;
161 161
                     }
@@ -231,7 +231,7 @@  discard block
 block discarded – undo
231 231
                 )
232 232
             );
233 233
         }
234
-        $this->datetimes[ $datetime->ID() ] = $datetime;
234
+        $this->datetimes[$datetime->ID()] = $datetime;
235 235
     }
236 236
 
237 237
 
@@ -322,16 +322,16 @@  discard block
 block discarded – undo
322 322
                     // we are going to move all of our data into the following arrays:
323 323
                     // datetime spaces initially represents the reg limit for each datetime,
324 324
                     // but this will get adjusted as tickets are accounted for
325
-                    $this->datetime_spaces[ $datetime_identifier ] = $reg_limit;
325
+                    $this->datetime_spaces[$datetime_identifier] = $reg_limit;
326 326
                     // just an array of ticket IDs grouped by datetime
327
-                    $this->datetime_tickets[ $datetime_identifier ][] = $ticket_identifier;
327
+                    $this->datetime_tickets[$datetime_identifier][] = $ticket_identifier;
328 328
                     // and an array of datetime IDs grouped by ticket
329
-                    $this->ticket_datetimes[ $ticket_identifier ][] = $datetime_identifier;
329
+                    $this->ticket_datetimes[$ticket_identifier][] = $datetime_identifier;
330 330
                 }
331 331
                 // total quantity of sold and reserved for each ticket
332
-                $this->tickets_sold[ $ticket_identifier ] = $ticket->sold() + $ticket->reserved();
332
+                $this->tickets_sold[$ticket_identifier] = $ticket->sold() + $ticket->reserved();
333 333
                 // and the maximum ticket quantities for each ticket (adjusted for reg limit)
334
-                $this->ticket_quantities[ $ticket_identifier ] = $max_tickets;
334
+                $this->ticket_quantities[$ticket_identifier] = $max_tickets;
335 335
             }
336 336
         }
337 337
         // sort datetime spaces by reg limit, but maintain our string indexes
@@ -390,19 +390,19 @@  discard block
 block discarded – undo
390 390
             \EEH_Debug_Tools::printr(__FUNCTION__, __CLASS__, __FILE__, __LINE__, 2);
391 391
         }
392 392
         foreach ($this->tickets_sold as $ticket_identifier => $tickets_sold) {
393
-            if (isset($this->ticket_quantities[ $ticket_identifier ])){
394
-                $this->ticket_quantities[ $ticket_identifier ] -= $tickets_sold;
393
+            if (isset($this->ticket_quantities[$ticket_identifier])) {
394
+                $this->ticket_quantities[$ticket_identifier] -= $tickets_sold;
395 395
                 if ($this->debug) {
396 396
                     \EEH_Debug_Tools::printr("{$tickets_sold} sales for ticket {$ticket_identifier} ", 'subtracting', __FILE__, __LINE__);
397 397
                 }
398 398
             }
399 399
             if (
400
-                isset($this->ticket_datetimes[ $ticket_identifier ])
401
-                && is_array($this->ticket_datetimes[ $ticket_identifier ])
402
-            ){
403
-                foreach ($this->ticket_datetimes[ $ticket_identifier ] as $ticket_datetime) {
404
-                    if (isset($this->ticket_quantities[ $ticket_identifier ])) {
405
-                        $this->datetime_spaces[ $ticket_datetime ] -= $tickets_sold;
400
+                isset($this->ticket_datetimes[$ticket_identifier])
401
+                && is_array($this->ticket_datetimes[$ticket_identifier])
402
+            ) {
403
+                foreach ($this->ticket_datetimes[$ticket_identifier] as $ticket_datetime) {
404
+                    if (isset($this->ticket_quantities[$ticket_identifier])) {
405
+                        $this->datetime_spaces[$ticket_datetime] -= $tickets_sold;
406 406
                         if ($this->debug) {
407 407
                             \EEH_Debug_Tools::printr("{$tickets_sold} sales for datetime {$ticket_datetime} ",
408 408
                                 'subtracting', __FILE__, __LINE__);
@@ -422,8 +422,8 @@  discard block
 block discarded – undo
422 422
     private function trackAvailableSpacesForDatetimes($datetime_identifier, array $tickets)
423 423
     {
424 424
         // make sure a reg limit is set for the datetime
425
-        $reg_limit = isset($this->datetime_spaces[ $datetime_identifier ])
426
-            ? $this->datetime_spaces[ $datetime_identifier ]
425
+        $reg_limit = isset($this->datetime_spaces[$datetime_identifier])
426
+            ? $this->datetime_spaces[$datetime_identifier]
427 427
             : 0;
428 428
         // and bail if it is not
429 429
         if ( ! $reg_limit) {
@@ -438,7 +438,7 @@  discard block
 block discarded – undo
438 438
         }
439 439
         // number of allocated spaces always starts at zero
440 440
         $spaces_allocated                           = 0;
441
-        $this->total_spaces[ $datetime_identifier ] = 0;
441
+        $this->total_spaces[$datetime_identifier] = 0;
442 442
         foreach ($tickets as $ticket_identifier) {
443 443
             $spaces_allocated = $this->calculateAvailableSpacesForTicket(
444 444
                 $datetime_identifier,
@@ -451,9 +451,9 @@  discard block
 block discarded – undo
451 451
         $spaces_allocated = max($spaces_allocated, 0);
452 452
         if ($spaces_allocated) {
453 453
             // track any non-zero values
454
-            $this->total_spaces[ $datetime_identifier ] += $spaces_allocated;
454
+            $this->total_spaces[$datetime_identifier] += $spaces_allocated;
455 455
             if ($this->debug) {
456
-                \EEH_Debug_Tools::printr((string)$spaces_allocated, ' . $spaces_allocated: ', __FILE__, __LINE__);
456
+                \EEH_Debug_Tools::printr((string) $spaces_allocated, ' . $spaces_allocated: ', __FILE__, __LINE__);
457 457
             }
458 458
         } else {
459 459
             if ($this->debug) {
@@ -461,7 +461,7 @@  discard block
 block discarded – undo
461 461
             }
462 462
         }
463 463
         if ($this->debug) {
464
-            \EEH_Debug_Tools::printr($this->total_spaces[ $datetime_identifier ], '$total_spaces', __FILE__,
464
+            \EEH_Debug_Tools::printr($this->total_spaces[$datetime_identifier], '$total_spaces', __FILE__,
465 465
                 __LINE__);
466 466
             \EEH_Debug_Tools::printr($this->ticket_quantities, '$ticket_quantities', __FILE__, __LINE__);
467 467
             \EEH_Debug_Tools::printr($this->datetime_spaces, 'datetime_spaces', __FILE__, __LINE__);
@@ -484,8 +484,8 @@  discard block
 block discarded – undo
484 484
         $spaces_allocated
485 485
     ) {
486 486
         // make sure ticket quantity is set
487
-        $ticket_quantity = isset($this->ticket_quantities[ $ticket_identifier ])
488
-            ? $this->ticket_quantities[ $ticket_identifier ]
487
+        $ticket_quantity = isset($this->ticket_quantities[$ticket_identifier])
488
+            ? $this->ticket_quantities[$ticket_identifier]
489 489
             : 0;
490 490
         if ($this->debug) {
491 491
             \EEH_Debug_Tools::printr("{$spaces_allocated}", '$spaces_allocated', __FILE__, __LINE__);
@@ -509,13 +509,13 @@  discard block
 block discarded – undo
509 509
                 //  or the maximum ticket quantity
510 510
                 $ticket_quantity = min($reg_limit - $spaces_allocated, $ticket_quantity);
511 511
                 // adjust the available quantity in our tracking array
512
-                $this->ticket_quantities[ $ticket_identifier ] -= $ticket_quantity;
512
+                $this->ticket_quantities[$ticket_identifier] -= $ticket_quantity;
513 513
                 // and increment spaces allocated for this datetime
514 514
                 $spaces_allocated += $ticket_quantity;
515 515
                 $at_capacity = $spaces_allocated >= $reg_limit;
516 516
                 if ($this->debug) {
517 517
                     \EEH_Debug_Tools::printr("{$ticket_quantity} {$ticket_identifier} tickets", ' > > allocate ',
518
-                        __FILE__, __LINE__,   3);
518
+                        __FILE__, __LINE__, 3);
519 519
                     if ($at_capacity) {
520 520
                         \EEH_Debug_Tools::printr('AT CAPACITY', " . {$datetime_identifier}", __FILE__, __LINE__, 3);
521 521
                     }
@@ -561,15 +561,15 @@  discard block
 block discarded – undo
561 561
                 $ticket_quantity
562 562
             );
563 563
             // skip to next ticket if nothing changed
564
-            if (! ($adjusted || $at_capacity)) {
564
+            if ( ! ($adjusted || $at_capacity)) {
565 565
                 continue;
566 566
             }
567 567
             // then all of it's tickets are now unavailable
568 568
             foreach ($datetime_tickets as $datetime_ticket) {
569 569
                 if (
570 570
                     ($ticket_identifier === $datetime_ticket || $at_capacity)
571
-                    && isset($this->ticket_quantities[ $datetime_ticket ])
572
-                    && $this->ticket_quantities[ $datetime_ticket ] > 0
571
+                    && isset($this->ticket_quantities[$datetime_ticket])
572
+                    && $this->ticket_quantities[$datetime_ticket] > 0
573 573
                 ) {
574 574
                     if ($this->debug) {
575 575
                         \EEH_Debug_Tools::printr($datetime_ticket, ' . . . adjust ticket quantities for', __FILE__,
@@ -579,14 +579,14 @@  discard block
 block discarded – undo
579 579
                     // otherwise just subtract the ticket quantity
580 580
                     $new_quantity = $at_capacity
581 581
                         ? 0
582
-                        : $this->ticket_quantities[ $datetime_ticket ] - $ticket_quantity;
582
+                        : $this->ticket_quantities[$datetime_ticket] - $ticket_quantity;
583 583
                     // don't let ticket quantity go below zero
584
-                    $this->ticket_quantities[ $datetime_ticket ] = max($new_quantity, 0);
584
+                    $this->ticket_quantities[$datetime_ticket] = max($new_quantity, 0);
585 585
                     if ($this->debug) {
586 586
                         \EEH_Debug_Tools::printr(
587 587
                             $at_capacity
588 588
                                 ? "0 because Datetime {$datetime_identifier} is at capacity"
589
-                                : "{$this->ticket_quantities[ $datetime_ticket ]}",
589
+                                : "{$this->ticket_quantities[$datetime_ticket]}",
590 590
                             " . . . . {$datetime_ticket} quantity set to ",
591 591
                             __FILE__, __LINE__
592 592
                         );
@@ -594,14 +594,14 @@  discard block
 block discarded – undo
594 594
                 }
595 595
                 // but we also need to adjust spaces for any other datetimes this ticket has access to
596 596
                 if ($datetime_ticket === $ticket_identifier) {
597
-                    if (isset($this->ticket_datetimes[ $datetime_ticket ])
598
-                        && is_array($this->ticket_datetimes[ $datetime_ticket ])
597
+                    if (isset($this->ticket_datetimes[$datetime_ticket])
598
+                        && is_array($this->ticket_datetimes[$datetime_ticket])
599 599
                     ) {
600 600
                         if ($this->debug) {
601 601
                             \EEH_Debug_Tools::printr($datetime_ticket, ' . . adjust other Datetimes for', __FILE__,
602 602
                                 __LINE__);
603 603
                         }
604
-                        foreach ($this->ticket_datetimes[ $datetime_ticket ] as $datetime) {
604
+                        foreach ($this->ticket_datetimes[$datetime_ticket] as $datetime) {
605 605
                             // don't adjust the current datetime twice
606 606
                             if ($datetime !== $datetime_identifier) {
607 607
                                 $this->adjustDatetimeSpaces(
@@ -622,19 +622,19 @@  discard block
 block discarded – undo
622 622
         // does datetime have spaces available?
623 623
         // and does the supplied ticket have access to this datetime ?
624 624
         if (
625
-            $this->datetime_spaces[ $datetime_identifier ] > 0
626
-            && isset($this->datetime_spaces[ $datetime_identifier ], $this->datetime_tickets[ $datetime_identifier ])
627
-            && in_array($ticket_identifier, $this->datetime_tickets[ $datetime_identifier ], true)
625
+            $this->datetime_spaces[$datetime_identifier] > 0
626
+            && isset($this->datetime_spaces[$datetime_identifier], $this->datetime_tickets[$datetime_identifier])
627
+            && in_array($ticket_identifier, $this->datetime_tickets[$datetime_identifier], true)
628 628
             ) {
629 629
             if ($this->debug) {
630 630
                 \EEH_Debug_Tools::printr($datetime_identifier, ' . . adjust Datetime Spaces for', __FILE__, __LINE__);
631
-                \EEH_Debug_Tools::printr("{$this->datetime_spaces[ $datetime_identifier ]}", " . . current  {$datetime_identifier} spaces available", __FILE__, __LINE__);
631
+                \EEH_Debug_Tools::printr("{$this->datetime_spaces[$datetime_identifier]}", " . . current  {$datetime_identifier} spaces available", __FILE__, __LINE__);
632 632
             }
633 633
             // then decrement the available spaces for the datetime
634
-            $this->datetime_spaces[ $datetime_identifier ] -= $ticket_quantity;
634
+            $this->datetime_spaces[$datetime_identifier] -= $ticket_quantity;
635 635
             // but don't let quantities go below zero
636
-            $this->datetime_spaces[ $datetime_identifier ] = max(
637
-                $this->datetime_spaces[ $datetime_identifier ],
636
+            $this->datetime_spaces[$datetime_identifier] = max(
637
+                $this->datetime_spaces[$datetime_identifier],
638 638
                 0
639 639
             );
640 640
             if ($this->debug) {
Please login to merge, or discard this patch.
core/libraries/messages/EE_Messages_Generator.lib.php 3 patches
Doc Comments   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -459,7 +459,7 @@  discard block
 block discarded – undo
459 459
      * there's a single shared message template group among all the events.  Otherwise it returns null.
460 460
      *
461 461
      * @param array $event_ids
462
-     * @return EE_Message_Template_Group|null
462
+     * @return null|EE_Base_Class
463 463
      * @throws EE_Error
464 464
      * @throws InvalidArgumentException
465 465
      * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
@@ -495,7 +495,7 @@  discard block
 block discarded – undo
495 495
     /**
496 496
      * Retrieves the global message template group for the current messenger and message type.
497 497
      *
498
-     * @return EE_Message_Template_Group|null
498
+     * @return null|EE_Base_Class
499 499
      * @throws EE_Error
500 500
      * @throws InvalidArgumentException
501 501
      * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
@@ -641,7 +641,7 @@  discard block
 block discarded – undo
641 641
      * @param EE_Messages_Addressee     $recipient
642 642
      * @param array                     $templates formatted array of templates used for parsing data.
643 643
      * @param EE_Message_Template_Group $message_template_group
644
-     * @return bool|EE_Message
644
+     * @return EE_Message
645 645
      * @throws EE_Error
646 646
      */
647 647
     protected function _setup_message_object(
Please login to merge, or discard this patch.
Indentation   +966 added lines, -966 removed lines patch added patch discarded remove patch
@@ -13,970 +13,970 @@
 block discarded – undo
13 13
 {
14 14
 
15 15
 
16
-    /**
17
-     * @type EE_Messages_Data_Handler_Collection
18
-     */
19
-    protected $_data_handler_collection;
20
-
21
-    /**
22
-     * @type  EE_Message_Template_Group_Collection
23
-     */
24
-    protected $_template_collection;
25
-
26
-    /**
27
-     * This will hold the data handler for the current EE_Message being generated.
28
-     *
29
-     * @type EE_Messages_incoming_data
30
-     */
31
-    protected $_current_data_handler;
32
-
33
-    /**
34
-     * This holds the EE_Messages_Queue that contains the messages to generate.
35
-     *
36
-     * @type EE_Messages_Queue
37
-     */
38
-    protected $_generation_queue;
39
-
40
-    /**
41
-     * This holds the EE_Messages_Queue that will store the generated EE_Message objects.
42
-     *
43
-     * @type EE_Messages_Queue
44
-     */
45
-    protected $_ready_queue;
46
-
47
-    /**
48
-     * This is a container for any error messages that get created through the generation
49
-     * process.
50
-     *
51
-     * @type array
52
-     */
53
-    protected $_error_msg = array();
54
-
55
-    /**
56
-     * Flag used to set when the current EE_Message in the generation queue has been verified.
57
-     *
58
-     * @type bool
59
-     */
60
-    protected $_verified = false;
61
-
62
-    /**
63
-     * This will hold the current messenger object corresponding with the current EE_Message in the generation queue.
64
-     *
65
-     * @type EE_messenger
66
-     */
67
-    protected $_current_messenger;
68
-
69
-    /**
70
-     * This will hold the current message type object corresponding with the current EE_Message in the generation queue.
71
-     *
72
-     * @type EE_message_type
73
-     */
74
-    protected $_current_message_type;
75
-
76
-    /**
77
-     * @type EEH_Parse_Shortcodes
78
-     */
79
-    protected $_shortcode_parser;
80
-
81
-
82
-    /**
83
-     * @param EE_Messages_Queue                     $generation_queue
84
-     * @param \EE_Messages_Queue                    $ready_queue
85
-     * @param \EE_Messages_Data_Handler_Collection  $data_handler_collection
86
-     * @param \EE_Message_Template_Group_Collection $template_collection
87
-     * @param \EEH_Parse_Shortcodes                 $shortcode_parser
88
-     */
89
-    public function __construct(
90
-        EE_Messages_Queue $generation_queue,
91
-        EE_Messages_Queue $ready_queue,
92
-        EE_Messages_Data_Handler_Collection $data_handler_collection,
93
-        EE_Message_Template_Group_Collection $template_collection,
94
-        EEH_Parse_Shortcodes $shortcode_parser
95
-    ) {
96
-        $this->_generation_queue        = $generation_queue;
97
-        $this->_ready_queue             = $ready_queue;
98
-        $this->_data_handler_collection = $data_handler_collection;
99
-        $this->_template_collection     = $template_collection;
100
-        $this->_shortcode_parser        = $shortcode_parser;
101
-    }
102
-
103
-
104
-    /**
105
-     * @return EE_Messages_Queue
106
-     */
107
-    public function generation_queue()
108
-    {
109
-        return $this->_generation_queue;
110
-    }
111
-
112
-
113
-    /**
114
-     *  This iterates through the provided queue and generates the EE_Message objects.
115
-     *  When iterating through the queue, the queued item that served as the base for generating other EE_Message
116
-     *  objects gets removed and the new EE_Message objects get added to a NEW queue.  The NEW queue is then returned
117
-     *  for the caller to decide what to do with it.
118
-     *
119
-     * @param   bool $save Whether to save the EE_Message objects in the new queue or just return.
120
-     * @return EE_Messages_Queue The new queue for holding generated EE_Message objects.
121
-     * @throws EE_Error
122
-     * @throws ReflectionException
123
-     */
124
-    public function generate($save = true)
125
-    {
126
-        //iterate through the messages in the queue, generate, and add to new queue.
127
-        $this->_generation_queue->get_message_repository()->rewind();
128
-        while ($this->_generation_queue->get_message_repository()->valid()) {
129
-            //reset "current" properties
130
-            $this->_reset_current_properties();
131
-
132
-            /** @type EE_Message $msg */
133
-            $msg = $this->_generation_queue->get_message_repository()->current();
134
-
135
-            /**
136
-             * need to get the next object and capture it for setting manually after deletes.  The reason is that when
137
-             * an object is removed from the repo then valid for the next object will fail.
138
-             */
139
-            $this->_generation_queue->get_message_repository()->next();
140
-            $next_msg = $this->_generation_queue->get_message_repository()->current();
141
-            //restore pointer to current item
142
-            $this->_generation_queue->get_message_repository()->set_current($msg);
143
-
144
-            //skip and delete if the current $msg is NOT incomplete (queued for generation)
145
-            if ($msg->STS_ID() !== EEM_Message::status_incomplete) {
146
-                //we keep this item in the db just remove from the repo.
147
-                $this->_generation_queue->get_message_repository()->remove($msg);
148
-                //next item
149
-                $this->_generation_queue->get_message_repository()->set_current($next_msg);
150
-                continue;
151
-            }
152
-
153
-            if ($this->_verify()) {
154
-                //let's get generating!
155
-                $this->_generate();
156
-            }
157
-
158
-            //don't persist debug_only messages if the messages system is not in debug mode.
159
-            if ($msg->STS_ID() === EEM_Message::status_debug_only
160
-                && ! EEM_Message::debug()
161
-            ) {
162
-                do_action(
163
-                    'AHEE__EE_Messages_Generator__generate__before_debug_delete',
164
-                    $msg,
165
-                    $this->_error_msg,
166
-                    $this->_current_messenger,
167
-                    $this->_current_message_type,
168
-                    $this->_current_data_handler
169
-                );
170
-                $this->_generation_queue->get_message_repository()->delete();
171
-                $this->_generation_queue->get_message_repository()->set_current($next_msg);
172
-                continue;
173
-            }
174
-
175
-            //if there are error messages then let's set the status and the error message.
176
-            if ($this->_error_msg) {
177
-                //if the status is already debug only, then let's leave it at that.
178
-                if ($msg->STS_ID() !== EEM_Message::status_debug_only) {
179
-                    $msg->set_STS_ID(EEM_Message::status_failed);
180
-                }
181
-                do_action(
182
-                    'AHEE__EE_Messages_Generator__generate__processing_failed_message',
183
-                    $msg,
184
-                    $this->_error_msg,
185
-                    $this->_current_messenger,
186
-                    $this->_current_message_type,
187
-                    $this->_current_data_handler
188
-                );
189
-                $msg->set_error_message(
190
-                    esc_html__('Message failed to generate for the following reasons: ', 'event_espresso')
191
-                    . "\n"
192
-                    . implode("\n", $this->_error_msg)
193
-                );
194
-                $msg->set_modified(time());
195
-            } else {
196
-                do_action(
197
-                    'AHEE__EE_Messages_Generator__generate__before_successful_generated_message_delete',
198
-                    $msg,
199
-                    $this->_error_msg,
200
-                    $this->_current_messenger,
201
-                    $this->_current_message_type,
202
-                    $this->_current_data_handler
203
-                );
204
-                //remove from db
205
-                $this->_generation_queue->get_message_repository()->delete();
206
-            }
207
-            //next item
208
-            $this->_generation_queue->get_message_repository()->set_current($next_msg);
209
-        }
210
-
211
-        //generation queue is ALWAYS saved to record any errors in the generation process.
212
-        $this->_generation_queue->save();
213
-
214
-        /**
215
-         * save _ready_queue if flag set.
216
-         * Note: The EE_Message objects have values set via the EE_Base_Class::set_field_or_extra_meta() method.  This
217
-         * means if a field was added that is not a valid database column.  The EE_Message was already saved to the db
218
-         * so a EE_Extra_Meta entry could be created and attached to the EE_Message.  In those cases the save flag is
219
-         * irrelevant.
220
-         */
221
-        if ($save) {
222
-            $this->_ready_queue->save();
223
-        }
224
-
225
-        //final reset of properties
226
-        $this->_reset_current_properties();
227
-
228
-        return $this->_ready_queue;
229
-    }
230
-
231
-
232
-    /**
233
-     * This resets all the properties used for holding "current" values corresponding to the current EE_Message object
234
-     * in the generation queue.
235
-     */
236
-    protected function _reset_current_properties()
237
-    {
238
-        $this->_verified = false;
239
-        //make sure any _data value in the current message type is reset
240
-        if ($this->_current_message_type instanceof EE_message_type) {
241
-            $this->_current_message_type->reset_data();
242
-        }
243
-        $this->_current_messenger = $this->_current_message_type = $this->_current_data_handler = null;
244
-    }
245
-
246
-
247
-    /**
248
-     * This proceeds with the actual generation of a message.  By the time this is called, there should already be a
249
-     * $_current_data_handler set and all incoming information should be validated for the current EE_Message in the
250
-     * _generating_queue.
251
-     *
252
-     * @return bool Whether the message was successfully generated or not.
253
-     * @throws EE_Error
254
-     * @throws InvalidArgumentException
255
-     * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
256
-     * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
257
-     */
258
-    protected function _generate()
259
-    {
260
-        //double check verification has run and that everything is ready to work with (saves us having to validate
261
-        // everything again).
262
-        if (! $this->_verified) {
263
-            return false; //get out because we don't have a valid setup to work with.
264
-        }
265
-
266
-
267
-        try {
268
-            $addressees = $this->_current_message_type->get_addressees(
269
-                $this->_current_data_handler,
270
-                $this->_generation_queue->get_message_repository()->current()->context()
271
-            );
272
-        } catch (EE_Error $e) {
273
-            $this->_error_msg[] = $e->getMessage();
274
-            return false;
275
-        }
276
-
277
-
278
-        //if no addressees then get out because there is nothing to generation (possible bad data).
279
-        if (! $this->_valid_addressees($addressees)) {
280
-            do_action(
281
-                'AHEE__EE_Messages_Generator___generate__invalid_addressees',
282
-                $this->_generation_queue->get_message_repository()->current(),
283
-                $addressees,
284
-                $this->_current_messenger,
285
-                $this->_current_message_type,
286
-                $this->_current_data_handler
287
-            );
288
-            $this->_generation_queue->get_message_repository()->current()->set_STS_ID(
289
-                EEM_Message::status_debug_only
290
-            );
291
-            $this->_error_msg[] = esc_html__(
292
-                'This is not a critical error but an informational notice. Unable to generate messages EE_Messages_Addressee objects.  There were no attendees prepared by the data handler. Sometimes this is because messages only get generated for certain registration statuses. For example, the ticket notice message type only goes to approved registrations.',
293
-                'event_espresso'
294
-            );
295
-            return false;
296
-        }
297
-
298
-        $message_template_group = $this->_get_message_template_group();
299
-
300
-        //in the unlikely event there is no EE_Message_Template_Group available, get out!
301
-        if (! $message_template_group instanceof EE_Message_Template_Group) {
302
-            $this->_error_msg[] = esc_html__(
303
-                'Unable to get the Message Templates for the Message being generated.  No message template group accessible.',
304
-                'event_espresso'
305
-            );
306
-            return false;
307
-        }
308
-
309
-        //get formatted templates for using to parse and setup EE_Message objects.
310
-        $templates = $this->_get_templates($message_template_group);
311
-
312
-
313
-        //setup new EE_Message objects (and add to _ready_queue)
314
-        return $this->_assemble_messages($addressees, $templates, $message_template_group);
315
-    }
316
-
317
-
318
-    /**
319
-     * Retrieves the message template group being used for generating messages.
320
-     * Note: this also utilizes the EE_Message_Template_Group_Collection to avoid having to hit the db multiple times.
321
-     *
322
-     * @return EE_Message_Template_Group|null
323
-     * @throws EE_Error
324
-     * @throws InvalidArgumentException
325
-     * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
326
-     * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
327
-     */
328
-    protected function _get_message_template_group()
329
-    {
330
-        //first see if there is a specific message template group requested (current message in the queue has a specific
331
-        //GRP_ID
332
-        $message_template_group = $this->_specific_message_template_group_from_queue();
333
-        if ($message_template_group instanceof EE_Message_Template_Group) {
334
-            return $message_template_group;
335
-        }
336
-
337
-        //get event_ids from the datahandler so we can check to see if there's already a message template group for them
338
-        //in the collection.
339
-        $event_ids              = $this->_get_event_ids_from_current_data_handler();
340
-        $message_template_group = $this->_template_collection->get_by_key(
341
-            $this->_template_collection->getKey(
342
-                $this->_current_messenger->name,
343
-                $this->_current_message_type->name,
344
-                $event_ids
345
-            )
346
-        );
347
-
348
-        //if we have a message template group then no need to hit the database, just return it.
349
-        if ($message_template_group instanceof EE_Message_Template_Group) {
350
-            return $message_template_group;
351
-        }
352
-
353
-        //okay made it here, so let's get the global group first for this messenger and message type to ensure
354
-        //there is no override set.
355
-        $global_message_template_group =
356
-            $this->_get_global_message_template_group_for_current_messenger_and_message_type();
357
-
358
-        if ($global_message_template_group instanceof EE_Message_Template_Group
359
-            && $global_message_template_group->get('MTP_is_override')
360
-        ) {
361
-            return $global_message_template_group;
362
-        }
363
-
364
-        //if we're still here, that means there was no message template group for the events in the collection and
365
-        //the global message template group for the messenger and message type is not set for override.  So next step is
366
-        //to see if there is a common shared custom message template group for this set of events.
367
-        $message_template_group = $this->_get_shared_message_template_for_events($event_ids);
368
-        if ($message_template_group instanceof EE_Message_Template_Group) {
369
-            return $message_template_group;
370
-        }
371
-
372
-        //STILL here?  Okay that means the fallback is to just use the global message template group for this event set.
373
-        //So we'll cache the global group for this event set (so this logic doesn't have to be repeated in this request)
374
-        //and return it.
375
-        if ($global_message_template_group instanceof EE_Message_Template_Group) {
376
-            $this->_template_collection->add(
377
-                $global_message_template_group,
378
-                $event_ids
379
-            );
380
-            return $global_message_template_group;
381
-        }
382
-
383
-        //if we land here that means there's NO active message template group for this set.
384
-        //TODO this will be a good target for some optimization down the road.  Whenever there is no active message
385
-        //template group for a given event set then cache that result so we don't repeat the logic.  However, for now,
386
-        //this should likely bit hit rarely enough that it's not a significant issue.
387
-        return null;
388
-    }
389
-
390
-
391
-    /**
392
-     * This checks the current message in the queue and determines if there is a specific Message Template Group
393
-     * requested for that message.
394
-     *
395
-     * @return EE_Message_Template_Group|null
396
-     * @throws EE_Error
397
-     * @throws InvalidArgumentException
398
-     * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
399
-     * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
400
-     */
401
-    protected function _specific_message_template_group_from_queue()
402
-    {
403
-        //is there a GRP_ID already on the EE_Message object?  If there is, then a specific template has been requested
404
-        //so let's use that.
405
-        $GRP_ID = $this->_generation_queue->get_message_repository()->current()->GRP_ID();
406
-
407
-        if ($GRP_ID) {
408
-            //attempt to retrieve from repo first
409
-            $message_template_group = $this->_template_collection->get_by_ID($GRP_ID);
410
-            if ($message_template_group instanceof EE_Message_Template_Group) {
411
-                return $message_template_group;  //got it!
412
-            }
413
-
414
-            //nope don't have it yet.  Get from DB then add to repo if its not here, then that means the current GRP_ID
415
-            //is not valid, so we'll continue on in the code assuming there's NO GRP_ID.
416
-            $message_template_group = EEM_Message_Template_Group::instance()->get_one_by_ID($GRP_ID);
417
-            if ($message_template_group instanceof EE_Message_Template_Group) {
418
-                $this->_template_collection->add($message_template_group);
419
-                return $message_template_group;
420
-            }
421
-        }
422
-        return null;
423
-    }
424
-
425
-
426
-    /**
427
-     * Returns whether the event ids passed in all share the same message template group for the current message type
428
-     * and messenger.
429
-     *
430
-     * @param array $event_ids
431
-     * @return bool true means they DO share the same message template group, false means they don't.
432
-     * @throws EE_Error
433
-     * @throws InvalidArgumentException
434
-     * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
435
-     * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
436
-     */
437
-    protected function _queue_shares_same_message_template_group_for_events(array $event_ids)
438
-    {
439
-        foreach ($this->_current_data_handler->events as $event) {
440
-            $event_ids[$event['ID']] = $event['ID'];
441
-        }
442
-        $count_of_message_template_groups = EEM_Message_Template_Group::instance()->count(
443
-            array(
444
-                array(
445
-                    'Event.EVT_ID'           => array('IN', $event_ids),
446
-                    'MTP_messenger'    => $this->_current_messenger->name,
447
-                    'MTP_message_type' => $this->_current_message_type->name,
448
-                ),
449
-            ),
450
-            'GRP_ID',
451
-            true
452
-        );
453
-        return $count_of_message_template_groups === 1;
454
-    }
455
-
456
-
457
-    /**
458
-     * This will get the shared message template group for events that are in the current data handler but ONLY if
459
-     * there's a single shared message template group among all the events.  Otherwise it returns null.
460
-     *
461
-     * @param array $event_ids
462
-     * @return EE_Message_Template_Group|null
463
-     * @throws EE_Error
464
-     * @throws InvalidArgumentException
465
-     * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
466
-     * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
467
-     */
468
-    protected function _get_shared_message_template_for_events(array $event_ids)
469
-    {
470
-        $message_template_group = null;
471
-        if ($this->_queue_shares_same_message_template_group_for_events($event_ids)) {
472
-            $message_template_group = EEM_Message_Template_Group::instance()->get_one(
473
-                array(
474
-                    array(
475
-                        'Event.EVT_ID'           => array('IN', $event_ids),
476
-                        'MTP_messenger'    => $this->_current_messenger->name,
477
-                        'MTP_message_type' => $this->_current_message_type->name,
478
-                        'MTP_is_active'    => true,
479
-                    ),
480
-                    'group_by' => 'GRP_ID',
481
-                )
482
-            );
483
-            //store this in the collection if its valid
484
-            if ($message_template_group instanceof EE_Message_Template_Group) {
485
-                $this->_template_collection->add(
486
-                    $message_template_group,
487
-                    $event_ids
488
-                );
489
-            }
490
-        }
491
-        return $message_template_group;
492
-    }
493
-
494
-
495
-    /**
496
-     * Retrieves the global message template group for the current messenger and message type.
497
-     *
498
-     * @return EE_Message_Template_Group|null
499
-     * @throws EE_Error
500
-     * @throws InvalidArgumentException
501
-     * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
502
-     * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
503
-     */
504
-    protected function _get_global_message_template_group_for_current_messenger_and_message_type()
505
-    {
506
-        //first check the collection (we use an array with 0 in it to represent global groups).
507
-        $global_message_template_group = $this->_template_collection->get_by_key(
508
-            $this->_template_collection->getKey(
509
-                $this->_current_messenger->name,
510
-                $this->_current_message_type->name,
511
-                array(0)
512
-            )
513
-        );
514
-
515
-        //if we don't have a group lets hit the db.
516
-        if (! $global_message_template_group instanceof EE_Message_Template_Group) {
517
-            $global_message_template_group = EEM_Message_Template_Group::instance()->get_one(
518
-                array(
519
-                    array(
520
-                        'MTP_messenger'    => $this->_current_messenger->name,
521
-                        'MTP_message_type' => $this->_current_message_type->name,
522
-                        'MTP_is_active'    => true,
523
-                        'MTP_is_global'    => true,
524
-                    ),
525
-                )
526
-            );
527
-            //if we have a group, add it to the collection.
528
-            if ($global_message_template_group instanceof EE_Message_Template_Group) {
529
-                $this->_template_collection->add(
530
-                    $global_message_template_group,
531
-                    array(0)
532
-                );
533
-            }
534
-        }
535
-        return $global_message_template_group;
536
-    }
537
-
538
-
539
-    /**
540
-     * Returns an array of event ids for all the events within the current data handler.
541
-     *
542
-     * @return array
543
-     */
544
-    protected function _get_event_ids_from_current_data_handler()
545
-    {
546
-        $event_ids = array();
547
-        foreach ($this->_current_data_handler->events as $event) {
548
-            $event_ids[$event['ID']] = $event['ID'];
549
-        }
550
-        return $event_ids;
551
-    }
552
-
553
-
554
-    /**
555
-     *  Retrieves formatted array of template information for each context specific to the given
556
-     *  EE_Message_Template_Group
557
-     *
558
-     * @param EE_Message_Template_Group $message_template_group
559
-     * @return array The returned array is in this structure:
560
-     *                          array(
561
-     *                          'field_name' => array(
562
-     *                          'context' => 'content'
563
-     *                          )
564
-     *                          )
565
-     * @throws EE_Error
566
-     */
567
-    protected function _get_templates(EE_Message_Template_Group $message_template_group)
568
-    {
569
-        $templates         = array();
570
-        $context_templates = $message_template_group->context_templates();
571
-        foreach ($context_templates as $context => $template_fields) {
572
-            foreach ($template_fields as $template_field => $template_obj) {
573
-                if (! $template_obj instanceof EE_Message_Template) {
574
-                    continue;
575
-                }
576
-                $templates[$template_field][$context] = $template_obj->get('MTP_content');
577
-            }
578
-        }
579
-        return $templates;
580
-    }
581
-
582
-
583
-    /**
584
-     * Assembles new fully generated EE_Message objects and adds to _ready_queue
585
-     *
586
-     * @param array                     $addressees  Array of EE_Messages_Addressee objects indexed by message type
587
-     *                                               context.
588
-     * @param array                     $templates   formatted array of templates used for parsing data.
589
-     * @param EE_Message_Template_Group $message_template_group
590
-     * @return bool true if message generation went a-ok.  false if some sort of exception occurred.  Note: The
591
-     *                                               method will attempt to generate ALL EE_Message objects and add to
592
-     *                                               the _ready_queue.  Successfully generated messages get added to the
593
-     *                                               queue with EEM_Message::status_idle, unsuccessfully generated
594
-     *                                               messages will get added to the queue as EEM_Message::status_failed.
595
-     *                                               Very rarely should "false" be returned from this method.
596
-     * @throws EE_Error
597
-     */
598
-    protected function _assemble_messages($addressees, $templates, EE_Message_Template_Group $message_template_group)
599
-    {
600
-
601
-        //if templates are empty then get out because we can't generate anything.
602
-        if (! $templates) {
603
-            $this->_error_msg[] = esc_html__(
604
-                'Unable to assemble messages because there are no templates retrieved for generating the messages with',
605
-                'event_espresso'
606
-            );
607
-            return false;
608
-        }
609
-
610
-        //We use this as the counter for generated messages because don't forget we may be executing this inside of a
611
-        //generation_queue.  So _ready_queue may have generated EE_Message objects already.
612
-        $generated_count = 0;
613
-        foreach ($addressees as $context => $recipients) {
614
-            foreach ($recipients as $recipient) {
615
-                $message = $this->_setup_message_object($context, $recipient, $templates, $message_template_group);
616
-                if ($message instanceof EE_Message) {
617
-                    $this->_ready_queue->add(
618
-                        $message,
619
-                        array(),
620
-                        $this->_generation_queue->get_message_repository()->is_preview(),
621
-                        $this->_generation_queue->get_message_repository()->is_test_send()
622
-                    );
623
-                    $generated_count++;
624
-                }
625
-
626
-                //if the current MSG being generated is for a test send then we'll only use ONE message in the
627
-                // generation.
628
-                if ($this->_generation_queue->get_message_repository()->is_test_send()) {
629
-                    break 2;
630
-                }
631
-            }
632
-        }
633
-
634
-        //if there are no generated messages then something else fatal went wrong.
635
-        return $generated_count > 0;
636
-    }
637
-
638
-
639
-    /**
640
-     * @param string                    $context   The context for the generated message.
641
-     * @param EE_Messages_Addressee     $recipient
642
-     * @param array                     $templates formatted array of templates used for parsing data.
643
-     * @param EE_Message_Template_Group $message_template_group
644
-     * @return bool|EE_Message
645
-     * @throws EE_Error
646
-     */
647
-    protected function _setup_message_object(
648
-        $context,
649
-        EE_Messages_Addressee $recipient,
650
-        $templates,
651
-        EE_Message_Template_Group $message_template_group
652
-    ) {
653
-        //stuff we already know
654
-        $transaction_id = $recipient->txn instanceof EE_Transaction ? $recipient->txn->ID() : 0;
655
-        $transaction_id = empty($transaction_id) && $this->_current_data_handler->txn instanceof EE_Transaction
656
-            ? $this->_current_data_handler->txn->ID()
657
-            : $transaction_id;
658
-        $message_fields = array(
659
-            'GRP_ID'           => $message_template_group->ID(),
660
-            'TXN_ID'           => $transaction_id,
661
-            'MSG_messenger'    => $this->_current_messenger->name,
662
-            'MSG_message_type' => $this->_current_message_type->name,
663
-            'MSG_context'      => $context,
664
-        );
665
-
666
-        //recipient id and type should be on the EE_Messages_Addressee object but if this is empty, let's try to grab
667
-        // the info from the att_obj found in the EE_Messages_Addressee object.
668
-        if (empty($recipient->recipient_id) || empty($recipient->recipient_type)) {
669
-            $message_fields['MSG_recipient_ID']   = $recipient->att_obj instanceof EE_Attendee
670
-                ? $recipient->att_obj->ID()
671
-                : 0;
672
-            $message_fields['MSG_recipient_type'] = 'Attendee';
673
-        } else {
674
-            $message_fields['MSG_recipient_ID']   = $recipient->recipient_id;
675
-            $message_fields['MSG_recipient_type'] = $recipient->recipient_type;
676
-        }
677
-        $message = EE_Message_Factory::create($message_fields);
678
-
679
-        //grab valid shortcodes for shortcode parser
680
-        $mt_shortcodes = $this->_current_message_type->get_valid_shortcodes();
681
-        $m_shortcodes  = $this->_current_messenger->get_valid_shortcodes();
682
-
683
-        //if the 'to' field is empty or the context is inactive we skip EXCEPT if we're previewing
684
-        if ((
685
-                (
686
-                    empty($templates['to'][$context])
687
-                    && ! $this->_current_messenger->allow_empty_to_field()
688
-                )
689
-                || ! $message_template_group->is_context_active($context)
690
-            )
691
-            && ! $this->_generation_queue->get_message_repository()->is_preview()
692
-        ) {
693
-            //we silently exit here and do NOT record a fail because the message is "turned off" by having no "to"
694
-            //field.
695
-            return false;
696
-        }
697
-        $error_msg = array();
698
-        foreach ($templates as $field => $field_context) {
699
-            $error_msg = array();
700
-            //let's setup the valid shortcodes for the incoming context.
701
-            $valid_shortcodes = $mt_shortcodes[$context];
702
-            //merge in valid shortcodes for the field.
703
-            $shortcodes = isset($m_shortcodes[$field]) ? $m_shortcodes[$field] : $valid_shortcodes;
704
-            if (isset($templates[$field][$context])) {
705
-                //prefix field.
706
-                $column_name = 'MSG_' . $field;
707
-                try {
708
-                    $content = $this->_shortcode_parser->parse_message_template(
709
-                        $templates[$field][$context],
710
-                        $recipient,
711
-                        $shortcodes,
712
-                        $this->_current_message_type,
713
-                        $this->_current_messenger,
714
-                        $message
715
-                    );
716
-                    $message->set_field_or_extra_meta($column_name, $content);
717
-                } catch (EE_Error $e) {
718
-                    $error_msg[] = sprintf(
719
-                        esc_html__(
720
-                            'There was a problem generating the content for the field %s: %s',
721
-                            'event_espresso'
722
-                        ),
723
-                        $field,
724
-                        $e->getMessage()
725
-                    );
726
-                    $message->set_STS_ID(EEM_Message::status_failed);
727
-                }
728
-            }
729
-        }
730
-
731
-        if ($message->STS_ID() === EEM_Message::status_failed) {
732
-            $error_msg = esc_html__('There were problems generating this message:', 'event_espresso')
733
-                         . "\n"
734
-                         . implode("\n", $error_msg);
735
-            $message->set_error_message($error_msg);
736
-        } else {
737
-            $message->set_STS_ID(EEM_Message::status_idle);
738
-        }
739
-        return $message;
740
-    }
741
-
742
-
743
-    /**
744
-     * This verifies that the incoming array has a EE_messenger object and a EE_message_type object and sets appropriate
745
-     * error message if either is missing.
746
-     *
747
-     * @return bool true means there were no errors, false means there were errors.
748
-     * @throws EE_Error
749
-     * @throws ReflectionException
750
-     */
751
-    protected function _verify()
752
-    {
753
-        //reset error message to an empty array.
754
-        $this->_error_msg = array();
755
-        $valid            = true;
756
-        $valid            = $valid ? $this->_validate_messenger_and_message_type() : $valid;
757
-        $valid            = $valid ? $this->_validate_and_setup_data() : $valid;
758
-
759
-        //set the verified flag so we know everything has been validated.
760
-        $this->_verified = $valid;
761
-
762
-        return $valid;
763
-    }
764
-
765
-
766
-    /**
767
-     * This accepts an array and validates that it is an array indexed by context with each value being an array of
768
-     * EE_Messages_Addressee objects.
769
-     *
770
-     * @param array $addressees Keys correspond to contexts for the message type and values are EE_Messages_Addressee[]
771
-     * @return bool
772
-     */
773
-    protected function _valid_addressees($addressees)
774
-    {
775
-        if (! $addressees || ! is_array($addressees)) {
776
-            return false;
777
-        }
778
-
779
-        foreach ($addressees as $addressee_array) {
780
-            foreach ($addressee_array as $addressee) {
781
-                if (! $addressee instanceof EE_Messages_Addressee) {
782
-                    return false;
783
-                }
784
-            }
785
-        }
786
-        return true;
787
-    }
788
-
789
-
790
-    /**
791
-     * This validates the messenger, message type, and presences of generation data for the current EE_Message in the
792
-     * queue. This process sets error messages if something is wrong.
793
-     *
794
-     * @return bool   true is if there are no errors.  false is if there is.
795
-     */
796
-    protected function _validate_messenger_and_message_type()
797
-    {
798
-
799
-        //first are there any existing error messages?  If so then return.
800
-        if ($this->_error_msg) {
801
-            return false;
802
-        }
803
-        /** @type EE_Message $message */
804
-        $message = $this->_generation_queue->get_message_repository()->current();
805
-        try {
806
-            $this->_current_messenger = $message->valid_messenger(true)
807
-                ? $message->messenger_object()
808
-                : null;
809
-        } catch (Exception $e) {
810
-            $this->_error_msg[] = $e->getMessage();
811
-        }
812
-        try {
813
-            $this->_current_message_type = $message->valid_message_type(true)
814
-                ? $message->message_type_object()
815
-                : null;
816
-        } catch (Exception $e) {
817
-            $this->_error_msg[] = $e->getMessage();
818
-        }
819
-
820
-        /**
821
-         * Check if there is any generation data, but only if this is not for a preview.
822
-         */
823
-        if (! $this->_generation_queue->get_message_repository()->get_generation_data()
824
-            && (
825
-                ! $this->_generation_queue->get_message_repository()->is_preview()
826
-                && $this->_generation_queue->get_message_repository()->get_data_handler()
827
-                   !== 'EE_Messages_Preview_incoming_data'
828
-            )
829
-        ) {
830
-            $this->_error_msg[] = esc_html__(
831
-                'There is no generation data for this message. Unable to generate.',
832
-                'event_espresso'
833
-            );
834
-        }
835
-
836
-        return empty($this->_error_msg);
837
-    }
838
-
839
-
840
-    /**
841
-     * This method retrieves the expected data handler for the message type and validates the generation data for that
842
-     * data handler.
843
-     *
844
-     * @return bool true means there are no errors.  false means there were errors (and handler did not get setup).
845
-     * @throws EE_Error
846
-     * @throws ReflectionException
847
-     */
848
-    protected function _validate_and_setup_data()
849
-    {
850
-
851
-        //First, are there any existing error messages?  If so, return because if there were errors elsewhere this can't
852
-        //be used anyways.
853
-        if ($this->_error_msg) {
854
-            return false;
855
-        }
856
-
857
-        $generation_data = $this->_generation_queue->get_message_repository()->get_generation_data();
858
-
859
-        /** @type EE_Messages_incoming_data $data_handler_class_name - well not really... just the class name actually*/
860
-        $data_handler_class_name = $this->_generation_queue->get_message_repository()->get_data_handler()
861
-            ? $this->_generation_queue->get_message_repository()->get_data_handler()
862
-            : 'EE_Messages_' . $this->_current_message_type->get_data_handler($generation_data) . '_incoming_data';
863
-
864
-        //If this EE_Message is for a preview, then let's switch out to the preview data handler.
865
-        if ($this->_generation_queue->get_message_repository()->is_preview()) {
866
-            $data_handler_class_name = 'EE_Messages_Preview_incoming_data';
867
-        }
868
-
869
-        //First get the class name for the data handler (and also verifies it exists.
870
-        if (! class_exists($data_handler_class_name)) {
871
-            $this->_error_msg[] = sprintf(
872
-                esc_html__(
873
-                    'The included data handler class name does not match any valid, accessible, "%1$s" classes.  Looking for %2$s.',
874
-                    'event_espresso'
875
-                ),
876
-                'EE_Messages_incoming_data',
877
-                $data_handler_class_name
878
-            );
879
-            return false;
880
-        }
881
-
882
-        //convert generation_data for data_handler_instantiation.
883
-        $generation_data = $data_handler_class_name::convert_data_from_persistent_storage($generation_data);
884
-
885
-        //note, this may set error messages as well.
886
-        $this->_set_data_handler($generation_data, $data_handler_class_name);
887
-
888
-        return empty($this->_error_msg);
889
-    }
890
-
891
-
892
-    /**
893
-     * Sets the $_current_data_handler property that is used for generating the current EE_Message in the queue, and
894
-     * adds it to the _data repository.
895
-     *
896
-     * @param mixed  $generating_data           This is data expected by the instantiated data handler.
897
-     * @param string $data_handler_class_name   This is the reference string indicating what data handler is being
898
-     *                                          instantiated.
899
-     * @return void .
900
-     * @throws EE_Error
901
-     * @throws ReflectionException
902
-     */
903
-    protected function _set_data_handler($generating_data, $data_handler_class_name)
904
-    {
905
-        //valid classname for the data handler.  Now let's setup the key for the data handler repository to see if there
906
-        //is already a ready data handler in the repository.
907
-        $this->_current_data_handler = $this->_data_handler_collection->get_by_key(
908
-            $this->_data_handler_collection->get_key(
909
-                $data_handler_class_name,
910
-                $generating_data
911
-            )
912
-        );
913
-        if (! $this->_current_data_handler instanceof EE_Messages_incoming_data) {
914
-            //no saved data_handler in the repo so let's set one up and add it to the repo.
915
-            try {
916
-                $this->_current_data_handler = new $data_handler_class_name($generating_data);
917
-                $this->_data_handler_collection->add($this->_current_data_handler, $generating_data);
918
-            } catch (EE_Error $e) {
919
-                $this->_error_msg[] = $e->get_error();
920
-            }
921
-        }
922
-    }
923
-
924
-
925
-    /**
926
-     * The queued EE_Message for generation does not save the data used for generation as objects
927
-     * because serialization of those objects could be problematic if the data is saved to the db.
928
-     * So this method calls the static method on the associated data_handler for the given message_type
929
-     * and that preps the data for later instantiation when generating.
930
-     *
931
-     * @param EE_Message_To_Generate $message_to_generate
932
-     * @param bool                   $preview Indicate whether this is being used for a preview or not.
933
-     * @return mixed Prepped data for persisting to the queue.  false is returned if unable to prep data.
934
-     */
935
-    protected function _prepare_data_for_queue(EE_Message_To_Generate $message_to_generate, $preview)
936
-    {
937
-        /** @type EE_Messages_incoming_data $data_handler - well not really... just the class name actually */
938
-        $data_handler = $message_to_generate->get_data_handler_class_name($preview);
939
-        if (! $message_to_generate->valid()) {
940
-            return false; //unable to get the data because the info in the EE_Message_To_Generate class is invalid.
941
-        }
942
-        return $data_handler::convert_data_for_persistent_storage($message_to_generate->data());
943
-    }
944
-
945
-
946
-    /**
947
-     * This sets up a EEM_Message::status_incomplete EE_Message object and adds it to the generation queue.
948
-     *
949
-     * @param EE_Message_To_Generate $message_to_generate
950
-     * @param bool                   $test_send Whether this is just a test send or not.  Typically used for previews.
951
-     * @throws InvalidArgumentException
952
-     * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
953
-     * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
954
-     */
955
-    public function create_and_add_message_to_queue(EE_Message_To_Generate $message_to_generate, $test_send = false)
956
-    {
957
-        //prep data
958
-        $data = $this->_prepare_data_for_queue($message_to_generate, $message_to_generate->preview());
959
-
960
-        $message = $message_to_generate->get_EE_Message();
961
-
962
-        //is there a GRP_ID in the request?
963
-        if ($GRP_ID = EE_Registry::instance()->REQ->get('GRP_ID')) {
964
-            $message->set_GRP_ID($GRP_ID);
965
-        }
966
-
967
-        if ($data === false) {
968
-            $message->set_STS_ID(EEM_Message::status_failed);
969
-            $message->set_error_message(
970
-                esc_html__(
971
-                    'Unable to prepare data for persistence to the database.',
972
-                    'event_espresso'
973
-                )
974
-            );
975
-        } else {
976
-            //make sure that the data handler is cached on the message as well
977
-            $data['data_handler_class_name'] = $message_to_generate->get_data_handler_class_name();
978
-        }
979
-
980
-        $this->_generation_queue->add($message, $data, $message_to_generate->preview(), $test_send);
981
-    }
16
+	/**
17
+	 * @type EE_Messages_Data_Handler_Collection
18
+	 */
19
+	protected $_data_handler_collection;
20
+
21
+	/**
22
+	 * @type  EE_Message_Template_Group_Collection
23
+	 */
24
+	protected $_template_collection;
25
+
26
+	/**
27
+	 * This will hold the data handler for the current EE_Message being generated.
28
+	 *
29
+	 * @type EE_Messages_incoming_data
30
+	 */
31
+	protected $_current_data_handler;
32
+
33
+	/**
34
+	 * This holds the EE_Messages_Queue that contains the messages to generate.
35
+	 *
36
+	 * @type EE_Messages_Queue
37
+	 */
38
+	protected $_generation_queue;
39
+
40
+	/**
41
+	 * This holds the EE_Messages_Queue that will store the generated EE_Message objects.
42
+	 *
43
+	 * @type EE_Messages_Queue
44
+	 */
45
+	protected $_ready_queue;
46
+
47
+	/**
48
+	 * This is a container for any error messages that get created through the generation
49
+	 * process.
50
+	 *
51
+	 * @type array
52
+	 */
53
+	protected $_error_msg = array();
54
+
55
+	/**
56
+	 * Flag used to set when the current EE_Message in the generation queue has been verified.
57
+	 *
58
+	 * @type bool
59
+	 */
60
+	protected $_verified = false;
61
+
62
+	/**
63
+	 * This will hold the current messenger object corresponding with the current EE_Message in the generation queue.
64
+	 *
65
+	 * @type EE_messenger
66
+	 */
67
+	protected $_current_messenger;
68
+
69
+	/**
70
+	 * This will hold the current message type object corresponding with the current EE_Message in the generation queue.
71
+	 *
72
+	 * @type EE_message_type
73
+	 */
74
+	protected $_current_message_type;
75
+
76
+	/**
77
+	 * @type EEH_Parse_Shortcodes
78
+	 */
79
+	protected $_shortcode_parser;
80
+
81
+
82
+	/**
83
+	 * @param EE_Messages_Queue                     $generation_queue
84
+	 * @param \EE_Messages_Queue                    $ready_queue
85
+	 * @param \EE_Messages_Data_Handler_Collection  $data_handler_collection
86
+	 * @param \EE_Message_Template_Group_Collection $template_collection
87
+	 * @param \EEH_Parse_Shortcodes                 $shortcode_parser
88
+	 */
89
+	public function __construct(
90
+		EE_Messages_Queue $generation_queue,
91
+		EE_Messages_Queue $ready_queue,
92
+		EE_Messages_Data_Handler_Collection $data_handler_collection,
93
+		EE_Message_Template_Group_Collection $template_collection,
94
+		EEH_Parse_Shortcodes $shortcode_parser
95
+	) {
96
+		$this->_generation_queue        = $generation_queue;
97
+		$this->_ready_queue             = $ready_queue;
98
+		$this->_data_handler_collection = $data_handler_collection;
99
+		$this->_template_collection     = $template_collection;
100
+		$this->_shortcode_parser        = $shortcode_parser;
101
+	}
102
+
103
+
104
+	/**
105
+	 * @return EE_Messages_Queue
106
+	 */
107
+	public function generation_queue()
108
+	{
109
+		return $this->_generation_queue;
110
+	}
111
+
112
+
113
+	/**
114
+	 *  This iterates through the provided queue and generates the EE_Message objects.
115
+	 *  When iterating through the queue, the queued item that served as the base for generating other EE_Message
116
+	 *  objects gets removed and the new EE_Message objects get added to a NEW queue.  The NEW queue is then returned
117
+	 *  for the caller to decide what to do with it.
118
+	 *
119
+	 * @param   bool $save Whether to save the EE_Message objects in the new queue or just return.
120
+	 * @return EE_Messages_Queue The new queue for holding generated EE_Message objects.
121
+	 * @throws EE_Error
122
+	 * @throws ReflectionException
123
+	 */
124
+	public function generate($save = true)
125
+	{
126
+		//iterate through the messages in the queue, generate, and add to new queue.
127
+		$this->_generation_queue->get_message_repository()->rewind();
128
+		while ($this->_generation_queue->get_message_repository()->valid()) {
129
+			//reset "current" properties
130
+			$this->_reset_current_properties();
131
+
132
+			/** @type EE_Message $msg */
133
+			$msg = $this->_generation_queue->get_message_repository()->current();
134
+
135
+			/**
136
+			 * need to get the next object and capture it for setting manually after deletes.  The reason is that when
137
+			 * an object is removed from the repo then valid for the next object will fail.
138
+			 */
139
+			$this->_generation_queue->get_message_repository()->next();
140
+			$next_msg = $this->_generation_queue->get_message_repository()->current();
141
+			//restore pointer to current item
142
+			$this->_generation_queue->get_message_repository()->set_current($msg);
143
+
144
+			//skip and delete if the current $msg is NOT incomplete (queued for generation)
145
+			if ($msg->STS_ID() !== EEM_Message::status_incomplete) {
146
+				//we keep this item in the db just remove from the repo.
147
+				$this->_generation_queue->get_message_repository()->remove($msg);
148
+				//next item
149
+				$this->_generation_queue->get_message_repository()->set_current($next_msg);
150
+				continue;
151
+			}
152
+
153
+			if ($this->_verify()) {
154
+				//let's get generating!
155
+				$this->_generate();
156
+			}
157
+
158
+			//don't persist debug_only messages if the messages system is not in debug mode.
159
+			if ($msg->STS_ID() === EEM_Message::status_debug_only
160
+				&& ! EEM_Message::debug()
161
+			) {
162
+				do_action(
163
+					'AHEE__EE_Messages_Generator__generate__before_debug_delete',
164
+					$msg,
165
+					$this->_error_msg,
166
+					$this->_current_messenger,
167
+					$this->_current_message_type,
168
+					$this->_current_data_handler
169
+				);
170
+				$this->_generation_queue->get_message_repository()->delete();
171
+				$this->_generation_queue->get_message_repository()->set_current($next_msg);
172
+				continue;
173
+			}
174
+
175
+			//if there are error messages then let's set the status and the error message.
176
+			if ($this->_error_msg) {
177
+				//if the status is already debug only, then let's leave it at that.
178
+				if ($msg->STS_ID() !== EEM_Message::status_debug_only) {
179
+					$msg->set_STS_ID(EEM_Message::status_failed);
180
+				}
181
+				do_action(
182
+					'AHEE__EE_Messages_Generator__generate__processing_failed_message',
183
+					$msg,
184
+					$this->_error_msg,
185
+					$this->_current_messenger,
186
+					$this->_current_message_type,
187
+					$this->_current_data_handler
188
+				);
189
+				$msg->set_error_message(
190
+					esc_html__('Message failed to generate for the following reasons: ', 'event_espresso')
191
+					. "\n"
192
+					. implode("\n", $this->_error_msg)
193
+				);
194
+				$msg->set_modified(time());
195
+			} else {
196
+				do_action(
197
+					'AHEE__EE_Messages_Generator__generate__before_successful_generated_message_delete',
198
+					$msg,
199
+					$this->_error_msg,
200
+					$this->_current_messenger,
201
+					$this->_current_message_type,
202
+					$this->_current_data_handler
203
+				);
204
+				//remove from db
205
+				$this->_generation_queue->get_message_repository()->delete();
206
+			}
207
+			//next item
208
+			$this->_generation_queue->get_message_repository()->set_current($next_msg);
209
+		}
210
+
211
+		//generation queue is ALWAYS saved to record any errors in the generation process.
212
+		$this->_generation_queue->save();
213
+
214
+		/**
215
+		 * save _ready_queue if flag set.
216
+		 * Note: The EE_Message objects have values set via the EE_Base_Class::set_field_or_extra_meta() method.  This
217
+		 * means if a field was added that is not a valid database column.  The EE_Message was already saved to the db
218
+		 * so a EE_Extra_Meta entry could be created and attached to the EE_Message.  In those cases the save flag is
219
+		 * irrelevant.
220
+		 */
221
+		if ($save) {
222
+			$this->_ready_queue->save();
223
+		}
224
+
225
+		//final reset of properties
226
+		$this->_reset_current_properties();
227
+
228
+		return $this->_ready_queue;
229
+	}
230
+
231
+
232
+	/**
233
+	 * This resets all the properties used for holding "current" values corresponding to the current EE_Message object
234
+	 * in the generation queue.
235
+	 */
236
+	protected function _reset_current_properties()
237
+	{
238
+		$this->_verified = false;
239
+		//make sure any _data value in the current message type is reset
240
+		if ($this->_current_message_type instanceof EE_message_type) {
241
+			$this->_current_message_type->reset_data();
242
+		}
243
+		$this->_current_messenger = $this->_current_message_type = $this->_current_data_handler = null;
244
+	}
245
+
246
+
247
+	/**
248
+	 * This proceeds with the actual generation of a message.  By the time this is called, there should already be a
249
+	 * $_current_data_handler set and all incoming information should be validated for the current EE_Message in the
250
+	 * _generating_queue.
251
+	 *
252
+	 * @return bool Whether the message was successfully generated or not.
253
+	 * @throws EE_Error
254
+	 * @throws InvalidArgumentException
255
+	 * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
256
+	 * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
257
+	 */
258
+	protected function _generate()
259
+	{
260
+		//double check verification has run and that everything is ready to work with (saves us having to validate
261
+		// everything again).
262
+		if (! $this->_verified) {
263
+			return false; //get out because we don't have a valid setup to work with.
264
+		}
265
+
266
+
267
+		try {
268
+			$addressees = $this->_current_message_type->get_addressees(
269
+				$this->_current_data_handler,
270
+				$this->_generation_queue->get_message_repository()->current()->context()
271
+			);
272
+		} catch (EE_Error $e) {
273
+			$this->_error_msg[] = $e->getMessage();
274
+			return false;
275
+		}
276
+
277
+
278
+		//if no addressees then get out because there is nothing to generation (possible bad data).
279
+		if (! $this->_valid_addressees($addressees)) {
280
+			do_action(
281
+				'AHEE__EE_Messages_Generator___generate__invalid_addressees',
282
+				$this->_generation_queue->get_message_repository()->current(),
283
+				$addressees,
284
+				$this->_current_messenger,
285
+				$this->_current_message_type,
286
+				$this->_current_data_handler
287
+			);
288
+			$this->_generation_queue->get_message_repository()->current()->set_STS_ID(
289
+				EEM_Message::status_debug_only
290
+			);
291
+			$this->_error_msg[] = esc_html__(
292
+				'This is not a critical error but an informational notice. Unable to generate messages EE_Messages_Addressee objects.  There were no attendees prepared by the data handler. Sometimes this is because messages only get generated for certain registration statuses. For example, the ticket notice message type only goes to approved registrations.',
293
+				'event_espresso'
294
+			);
295
+			return false;
296
+		}
297
+
298
+		$message_template_group = $this->_get_message_template_group();
299
+
300
+		//in the unlikely event there is no EE_Message_Template_Group available, get out!
301
+		if (! $message_template_group instanceof EE_Message_Template_Group) {
302
+			$this->_error_msg[] = esc_html__(
303
+				'Unable to get the Message Templates for the Message being generated.  No message template group accessible.',
304
+				'event_espresso'
305
+			);
306
+			return false;
307
+		}
308
+
309
+		//get formatted templates for using to parse and setup EE_Message objects.
310
+		$templates = $this->_get_templates($message_template_group);
311
+
312
+
313
+		//setup new EE_Message objects (and add to _ready_queue)
314
+		return $this->_assemble_messages($addressees, $templates, $message_template_group);
315
+	}
316
+
317
+
318
+	/**
319
+	 * Retrieves the message template group being used for generating messages.
320
+	 * Note: this also utilizes the EE_Message_Template_Group_Collection to avoid having to hit the db multiple times.
321
+	 *
322
+	 * @return EE_Message_Template_Group|null
323
+	 * @throws EE_Error
324
+	 * @throws InvalidArgumentException
325
+	 * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
326
+	 * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
327
+	 */
328
+	protected function _get_message_template_group()
329
+	{
330
+		//first see if there is a specific message template group requested (current message in the queue has a specific
331
+		//GRP_ID
332
+		$message_template_group = $this->_specific_message_template_group_from_queue();
333
+		if ($message_template_group instanceof EE_Message_Template_Group) {
334
+			return $message_template_group;
335
+		}
336
+
337
+		//get event_ids from the datahandler so we can check to see if there's already a message template group for them
338
+		//in the collection.
339
+		$event_ids              = $this->_get_event_ids_from_current_data_handler();
340
+		$message_template_group = $this->_template_collection->get_by_key(
341
+			$this->_template_collection->getKey(
342
+				$this->_current_messenger->name,
343
+				$this->_current_message_type->name,
344
+				$event_ids
345
+			)
346
+		);
347
+
348
+		//if we have a message template group then no need to hit the database, just return it.
349
+		if ($message_template_group instanceof EE_Message_Template_Group) {
350
+			return $message_template_group;
351
+		}
352
+
353
+		//okay made it here, so let's get the global group first for this messenger and message type to ensure
354
+		//there is no override set.
355
+		$global_message_template_group =
356
+			$this->_get_global_message_template_group_for_current_messenger_and_message_type();
357
+
358
+		if ($global_message_template_group instanceof EE_Message_Template_Group
359
+			&& $global_message_template_group->get('MTP_is_override')
360
+		) {
361
+			return $global_message_template_group;
362
+		}
363
+
364
+		//if we're still here, that means there was no message template group for the events in the collection and
365
+		//the global message template group for the messenger and message type is not set for override.  So next step is
366
+		//to see if there is a common shared custom message template group for this set of events.
367
+		$message_template_group = $this->_get_shared_message_template_for_events($event_ids);
368
+		if ($message_template_group instanceof EE_Message_Template_Group) {
369
+			return $message_template_group;
370
+		}
371
+
372
+		//STILL here?  Okay that means the fallback is to just use the global message template group for this event set.
373
+		//So we'll cache the global group for this event set (so this logic doesn't have to be repeated in this request)
374
+		//and return it.
375
+		if ($global_message_template_group instanceof EE_Message_Template_Group) {
376
+			$this->_template_collection->add(
377
+				$global_message_template_group,
378
+				$event_ids
379
+			);
380
+			return $global_message_template_group;
381
+		}
382
+
383
+		//if we land here that means there's NO active message template group for this set.
384
+		//TODO this will be a good target for some optimization down the road.  Whenever there is no active message
385
+		//template group for a given event set then cache that result so we don't repeat the logic.  However, for now,
386
+		//this should likely bit hit rarely enough that it's not a significant issue.
387
+		return null;
388
+	}
389
+
390
+
391
+	/**
392
+	 * This checks the current message in the queue and determines if there is a specific Message Template Group
393
+	 * requested for that message.
394
+	 *
395
+	 * @return EE_Message_Template_Group|null
396
+	 * @throws EE_Error
397
+	 * @throws InvalidArgumentException
398
+	 * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
399
+	 * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
400
+	 */
401
+	protected function _specific_message_template_group_from_queue()
402
+	{
403
+		//is there a GRP_ID already on the EE_Message object?  If there is, then a specific template has been requested
404
+		//so let's use that.
405
+		$GRP_ID = $this->_generation_queue->get_message_repository()->current()->GRP_ID();
406
+
407
+		if ($GRP_ID) {
408
+			//attempt to retrieve from repo first
409
+			$message_template_group = $this->_template_collection->get_by_ID($GRP_ID);
410
+			if ($message_template_group instanceof EE_Message_Template_Group) {
411
+				return $message_template_group;  //got it!
412
+			}
413
+
414
+			//nope don't have it yet.  Get from DB then add to repo if its not here, then that means the current GRP_ID
415
+			//is not valid, so we'll continue on in the code assuming there's NO GRP_ID.
416
+			$message_template_group = EEM_Message_Template_Group::instance()->get_one_by_ID($GRP_ID);
417
+			if ($message_template_group instanceof EE_Message_Template_Group) {
418
+				$this->_template_collection->add($message_template_group);
419
+				return $message_template_group;
420
+			}
421
+		}
422
+		return null;
423
+	}
424
+
425
+
426
+	/**
427
+	 * Returns whether the event ids passed in all share the same message template group for the current message type
428
+	 * and messenger.
429
+	 *
430
+	 * @param array $event_ids
431
+	 * @return bool true means they DO share the same message template group, false means they don't.
432
+	 * @throws EE_Error
433
+	 * @throws InvalidArgumentException
434
+	 * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
435
+	 * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
436
+	 */
437
+	protected function _queue_shares_same_message_template_group_for_events(array $event_ids)
438
+	{
439
+		foreach ($this->_current_data_handler->events as $event) {
440
+			$event_ids[$event['ID']] = $event['ID'];
441
+		}
442
+		$count_of_message_template_groups = EEM_Message_Template_Group::instance()->count(
443
+			array(
444
+				array(
445
+					'Event.EVT_ID'           => array('IN', $event_ids),
446
+					'MTP_messenger'    => $this->_current_messenger->name,
447
+					'MTP_message_type' => $this->_current_message_type->name,
448
+				),
449
+			),
450
+			'GRP_ID',
451
+			true
452
+		);
453
+		return $count_of_message_template_groups === 1;
454
+	}
455
+
456
+
457
+	/**
458
+	 * This will get the shared message template group for events that are in the current data handler but ONLY if
459
+	 * there's a single shared message template group among all the events.  Otherwise it returns null.
460
+	 *
461
+	 * @param array $event_ids
462
+	 * @return EE_Message_Template_Group|null
463
+	 * @throws EE_Error
464
+	 * @throws InvalidArgumentException
465
+	 * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
466
+	 * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
467
+	 */
468
+	protected function _get_shared_message_template_for_events(array $event_ids)
469
+	{
470
+		$message_template_group = null;
471
+		if ($this->_queue_shares_same_message_template_group_for_events($event_ids)) {
472
+			$message_template_group = EEM_Message_Template_Group::instance()->get_one(
473
+				array(
474
+					array(
475
+						'Event.EVT_ID'           => array('IN', $event_ids),
476
+						'MTP_messenger'    => $this->_current_messenger->name,
477
+						'MTP_message_type' => $this->_current_message_type->name,
478
+						'MTP_is_active'    => true,
479
+					),
480
+					'group_by' => 'GRP_ID',
481
+				)
482
+			);
483
+			//store this in the collection if its valid
484
+			if ($message_template_group instanceof EE_Message_Template_Group) {
485
+				$this->_template_collection->add(
486
+					$message_template_group,
487
+					$event_ids
488
+				);
489
+			}
490
+		}
491
+		return $message_template_group;
492
+	}
493
+
494
+
495
+	/**
496
+	 * Retrieves the global message template group for the current messenger and message type.
497
+	 *
498
+	 * @return EE_Message_Template_Group|null
499
+	 * @throws EE_Error
500
+	 * @throws InvalidArgumentException
501
+	 * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
502
+	 * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
503
+	 */
504
+	protected function _get_global_message_template_group_for_current_messenger_and_message_type()
505
+	{
506
+		//first check the collection (we use an array with 0 in it to represent global groups).
507
+		$global_message_template_group = $this->_template_collection->get_by_key(
508
+			$this->_template_collection->getKey(
509
+				$this->_current_messenger->name,
510
+				$this->_current_message_type->name,
511
+				array(0)
512
+			)
513
+		);
514
+
515
+		//if we don't have a group lets hit the db.
516
+		if (! $global_message_template_group instanceof EE_Message_Template_Group) {
517
+			$global_message_template_group = EEM_Message_Template_Group::instance()->get_one(
518
+				array(
519
+					array(
520
+						'MTP_messenger'    => $this->_current_messenger->name,
521
+						'MTP_message_type' => $this->_current_message_type->name,
522
+						'MTP_is_active'    => true,
523
+						'MTP_is_global'    => true,
524
+					),
525
+				)
526
+			);
527
+			//if we have a group, add it to the collection.
528
+			if ($global_message_template_group instanceof EE_Message_Template_Group) {
529
+				$this->_template_collection->add(
530
+					$global_message_template_group,
531
+					array(0)
532
+				);
533
+			}
534
+		}
535
+		return $global_message_template_group;
536
+	}
537
+
538
+
539
+	/**
540
+	 * Returns an array of event ids for all the events within the current data handler.
541
+	 *
542
+	 * @return array
543
+	 */
544
+	protected function _get_event_ids_from_current_data_handler()
545
+	{
546
+		$event_ids = array();
547
+		foreach ($this->_current_data_handler->events as $event) {
548
+			$event_ids[$event['ID']] = $event['ID'];
549
+		}
550
+		return $event_ids;
551
+	}
552
+
553
+
554
+	/**
555
+	 *  Retrieves formatted array of template information for each context specific to the given
556
+	 *  EE_Message_Template_Group
557
+	 *
558
+	 * @param EE_Message_Template_Group $message_template_group
559
+	 * @return array The returned array is in this structure:
560
+	 *                          array(
561
+	 *                          'field_name' => array(
562
+	 *                          'context' => 'content'
563
+	 *                          )
564
+	 *                          )
565
+	 * @throws EE_Error
566
+	 */
567
+	protected function _get_templates(EE_Message_Template_Group $message_template_group)
568
+	{
569
+		$templates         = array();
570
+		$context_templates = $message_template_group->context_templates();
571
+		foreach ($context_templates as $context => $template_fields) {
572
+			foreach ($template_fields as $template_field => $template_obj) {
573
+				if (! $template_obj instanceof EE_Message_Template) {
574
+					continue;
575
+				}
576
+				$templates[$template_field][$context] = $template_obj->get('MTP_content');
577
+			}
578
+		}
579
+		return $templates;
580
+	}
581
+
582
+
583
+	/**
584
+	 * Assembles new fully generated EE_Message objects and adds to _ready_queue
585
+	 *
586
+	 * @param array                     $addressees  Array of EE_Messages_Addressee objects indexed by message type
587
+	 *                                               context.
588
+	 * @param array                     $templates   formatted array of templates used for parsing data.
589
+	 * @param EE_Message_Template_Group $message_template_group
590
+	 * @return bool true if message generation went a-ok.  false if some sort of exception occurred.  Note: The
591
+	 *                                               method will attempt to generate ALL EE_Message objects and add to
592
+	 *                                               the _ready_queue.  Successfully generated messages get added to the
593
+	 *                                               queue with EEM_Message::status_idle, unsuccessfully generated
594
+	 *                                               messages will get added to the queue as EEM_Message::status_failed.
595
+	 *                                               Very rarely should "false" be returned from this method.
596
+	 * @throws EE_Error
597
+	 */
598
+	protected function _assemble_messages($addressees, $templates, EE_Message_Template_Group $message_template_group)
599
+	{
600
+
601
+		//if templates are empty then get out because we can't generate anything.
602
+		if (! $templates) {
603
+			$this->_error_msg[] = esc_html__(
604
+				'Unable to assemble messages because there are no templates retrieved for generating the messages with',
605
+				'event_espresso'
606
+			);
607
+			return false;
608
+		}
609
+
610
+		//We use this as the counter for generated messages because don't forget we may be executing this inside of a
611
+		//generation_queue.  So _ready_queue may have generated EE_Message objects already.
612
+		$generated_count = 0;
613
+		foreach ($addressees as $context => $recipients) {
614
+			foreach ($recipients as $recipient) {
615
+				$message = $this->_setup_message_object($context, $recipient, $templates, $message_template_group);
616
+				if ($message instanceof EE_Message) {
617
+					$this->_ready_queue->add(
618
+						$message,
619
+						array(),
620
+						$this->_generation_queue->get_message_repository()->is_preview(),
621
+						$this->_generation_queue->get_message_repository()->is_test_send()
622
+					);
623
+					$generated_count++;
624
+				}
625
+
626
+				//if the current MSG being generated is for a test send then we'll only use ONE message in the
627
+				// generation.
628
+				if ($this->_generation_queue->get_message_repository()->is_test_send()) {
629
+					break 2;
630
+				}
631
+			}
632
+		}
633
+
634
+		//if there are no generated messages then something else fatal went wrong.
635
+		return $generated_count > 0;
636
+	}
637
+
638
+
639
+	/**
640
+	 * @param string                    $context   The context for the generated message.
641
+	 * @param EE_Messages_Addressee     $recipient
642
+	 * @param array                     $templates formatted array of templates used for parsing data.
643
+	 * @param EE_Message_Template_Group $message_template_group
644
+	 * @return bool|EE_Message
645
+	 * @throws EE_Error
646
+	 */
647
+	protected function _setup_message_object(
648
+		$context,
649
+		EE_Messages_Addressee $recipient,
650
+		$templates,
651
+		EE_Message_Template_Group $message_template_group
652
+	) {
653
+		//stuff we already know
654
+		$transaction_id = $recipient->txn instanceof EE_Transaction ? $recipient->txn->ID() : 0;
655
+		$transaction_id = empty($transaction_id) && $this->_current_data_handler->txn instanceof EE_Transaction
656
+			? $this->_current_data_handler->txn->ID()
657
+			: $transaction_id;
658
+		$message_fields = array(
659
+			'GRP_ID'           => $message_template_group->ID(),
660
+			'TXN_ID'           => $transaction_id,
661
+			'MSG_messenger'    => $this->_current_messenger->name,
662
+			'MSG_message_type' => $this->_current_message_type->name,
663
+			'MSG_context'      => $context,
664
+		);
665
+
666
+		//recipient id and type should be on the EE_Messages_Addressee object but if this is empty, let's try to grab
667
+		// the info from the att_obj found in the EE_Messages_Addressee object.
668
+		if (empty($recipient->recipient_id) || empty($recipient->recipient_type)) {
669
+			$message_fields['MSG_recipient_ID']   = $recipient->att_obj instanceof EE_Attendee
670
+				? $recipient->att_obj->ID()
671
+				: 0;
672
+			$message_fields['MSG_recipient_type'] = 'Attendee';
673
+		} else {
674
+			$message_fields['MSG_recipient_ID']   = $recipient->recipient_id;
675
+			$message_fields['MSG_recipient_type'] = $recipient->recipient_type;
676
+		}
677
+		$message = EE_Message_Factory::create($message_fields);
678
+
679
+		//grab valid shortcodes for shortcode parser
680
+		$mt_shortcodes = $this->_current_message_type->get_valid_shortcodes();
681
+		$m_shortcodes  = $this->_current_messenger->get_valid_shortcodes();
682
+
683
+		//if the 'to' field is empty or the context is inactive we skip EXCEPT if we're previewing
684
+		if ((
685
+				(
686
+					empty($templates['to'][$context])
687
+					&& ! $this->_current_messenger->allow_empty_to_field()
688
+				)
689
+				|| ! $message_template_group->is_context_active($context)
690
+			)
691
+			&& ! $this->_generation_queue->get_message_repository()->is_preview()
692
+		) {
693
+			//we silently exit here and do NOT record a fail because the message is "turned off" by having no "to"
694
+			//field.
695
+			return false;
696
+		}
697
+		$error_msg = array();
698
+		foreach ($templates as $field => $field_context) {
699
+			$error_msg = array();
700
+			//let's setup the valid shortcodes for the incoming context.
701
+			$valid_shortcodes = $mt_shortcodes[$context];
702
+			//merge in valid shortcodes for the field.
703
+			$shortcodes = isset($m_shortcodes[$field]) ? $m_shortcodes[$field] : $valid_shortcodes;
704
+			if (isset($templates[$field][$context])) {
705
+				//prefix field.
706
+				$column_name = 'MSG_' . $field;
707
+				try {
708
+					$content = $this->_shortcode_parser->parse_message_template(
709
+						$templates[$field][$context],
710
+						$recipient,
711
+						$shortcodes,
712
+						$this->_current_message_type,
713
+						$this->_current_messenger,
714
+						$message
715
+					);
716
+					$message->set_field_or_extra_meta($column_name, $content);
717
+				} catch (EE_Error $e) {
718
+					$error_msg[] = sprintf(
719
+						esc_html__(
720
+							'There was a problem generating the content for the field %s: %s',
721
+							'event_espresso'
722
+						),
723
+						$field,
724
+						$e->getMessage()
725
+					);
726
+					$message->set_STS_ID(EEM_Message::status_failed);
727
+				}
728
+			}
729
+		}
730
+
731
+		if ($message->STS_ID() === EEM_Message::status_failed) {
732
+			$error_msg = esc_html__('There were problems generating this message:', 'event_espresso')
733
+						 . "\n"
734
+						 . implode("\n", $error_msg);
735
+			$message->set_error_message($error_msg);
736
+		} else {
737
+			$message->set_STS_ID(EEM_Message::status_idle);
738
+		}
739
+		return $message;
740
+	}
741
+
742
+
743
+	/**
744
+	 * This verifies that the incoming array has a EE_messenger object and a EE_message_type object and sets appropriate
745
+	 * error message if either is missing.
746
+	 *
747
+	 * @return bool true means there were no errors, false means there were errors.
748
+	 * @throws EE_Error
749
+	 * @throws ReflectionException
750
+	 */
751
+	protected function _verify()
752
+	{
753
+		//reset error message to an empty array.
754
+		$this->_error_msg = array();
755
+		$valid            = true;
756
+		$valid            = $valid ? $this->_validate_messenger_and_message_type() : $valid;
757
+		$valid            = $valid ? $this->_validate_and_setup_data() : $valid;
758
+
759
+		//set the verified flag so we know everything has been validated.
760
+		$this->_verified = $valid;
761
+
762
+		return $valid;
763
+	}
764
+
765
+
766
+	/**
767
+	 * This accepts an array and validates that it is an array indexed by context with each value being an array of
768
+	 * EE_Messages_Addressee objects.
769
+	 *
770
+	 * @param array $addressees Keys correspond to contexts for the message type and values are EE_Messages_Addressee[]
771
+	 * @return bool
772
+	 */
773
+	protected function _valid_addressees($addressees)
774
+	{
775
+		if (! $addressees || ! is_array($addressees)) {
776
+			return false;
777
+		}
778
+
779
+		foreach ($addressees as $addressee_array) {
780
+			foreach ($addressee_array as $addressee) {
781
+				if (! $addressee instanceof EE_Messages_Addressee) {
782
+					return false;
783
+				}
784
+			}
785
+		}
786
+		return true;
787
+	}
788
+
789
+
790
+	/**
791
+	 * This validates the messenger, message type, and presences of generation data for the current EE_Message in the
792
+	 * queue. This process sets error messages if something is wrong.
793
+	 *
794
+	 * @return bool   true is if there are no errors.  false is if there is.
795
+	 */
796
+	protected function _validate_messenger_and_message_type()
797
+	{
798
+
799
+		//first are there any existing error messages?  If so then return.
800
+		if ($this->_error_msg) {
801
+			return false;
802
+		}
803
+		/** @type EE_Message $message */
804
+		$message = $this->_generation_queue->get_message_repository()->current();
805
+		try {
806
+			$this->_current_messenger = $message->valid_messenger(true)
807
+				? $message->messenger_object()
808
+				: null;
809
+		} catch (Exception $e) {
810
+			$this->_error_msg[] = $e->getMessage();
811
+		}
812
+		try {
813
+			$this->_current_message_type = $message->valid_message_type(true)
814
+				? $message->message_type_object()
815
+				: null;
816
+		} catch (Exception $e) {
817
+			$this->_error_msg[] = $e->getMessage();
818
+		}
819
+
820
+		/**
821
+		 * Check if there is any generation data, but only if this is not for a preview.
822
+		 */
823
+		if (! $this->_generation_queue->get_message_repository()->get_generation_data()
824
+			&& (
825
+				! $this->_generation_queue->get_message_repository()->is_preview()
826
+				&& $this->_generation_queue->get_message_repository()->get_data_handler()
827
+				   !== 'EE_Messages_Preview_incoming_data'
828
+			)
829
+		) {
830
+			$this->_error_msg[] = esc_html__(
831
+				'There is no generation data for this message. Unable to generate.',
832
+				'event_espresso'
833
+			);
834
+		}
835
+
836
+		return empty($this->_error_msg);
837
+	}
838
+
839
+
840
+	/**
841
+	 * This method retrieves the expected data handler for the message type and validates the generation data for that
842
+	 * data handler.
843
+	 *
844
+	 * @return bool true means there are no errors.  false means there were errors (and handler did not get setup).
845
+	 * @throws EE_Error
846
+	 * @throws ReflectionException
847
+	 */
848
+	protected function _validate_and_setup_data()
849
+	{
850
+
851
+		//First, are there any existing error messages?  If so, return because if there were errors elsewhere this can't
852
+		//be used anyways.
853
+		if ($this->_error_msg) {
854
+			return false;
855
+		}
856
+
857
+		$generation_data = $this->_generation_queue->get_message_repository()->get_generation_data();
858
+
859
+		/** @type EE_Messages_incoming_data $data_handler_class_name - well not really... just the class name actually*/
860
+		$data_handler_class_name = $this->_generation_queue->get_message_repository()->get_data_handler()
861
+			? $this->_generation_queue->get_message_repository()->get_data_handler()
862
+			: 'EE_Messages_' . $this->_current_message_type->get_data_handler($generation_data) . '_incoming_data';
863
+
864
+		//If this EE_Message is for a preview, then let's switch out to the preview data handler.
865
+		if ($this->_generation_queue->get_message_repository()->is_preview()) {
866
+			$data_handler_class_name = 'EE_Messages_Preview_incoming_data';
867
+		}
868
+
869
+		//First get the class name for the data handler (and also verifies it exists.
870
+		if (! class_exists($data_handler_class_name)) {
871
+			$this->_error_msg[] = sprintf(
872
+				esc_html__(
873
+					'The included data handler class name does not match any valid, accessible, "%1$s" classes.  Looking for %2$s.',
874
+					'event_espresso'
875
+				),
876
+				'EE_Messages_incoming_data',
877
+				$data_handler_class_name
878
+			);
879
+			return false;
880
+		}
881
+
882
+		//convert generation_data for data_handler_instantiation.
883
+		$generation_data = $data_handler_class_name::convert_data_from_persistent_storage($generation_data);
884
+
885
+		//note, this may set error messages as well.
886
+		$this->_set_data_handler($generation_data, $data_handler_class_name);
887
+
888
+		return empty($this->_error_msg);
889
+	}
890
+
891
+
892
+	/**
893
+	 * Sets the $_current_data_handler property that is used for generating the current EE_Message in the queue, and
894
+	 * adds it to the _data repository.
895
+	 *
896
+	 * @param mixed  $generating_data           This is data expected by the instantiated data handler.
897
+	 * @param string $data_handler_class_name   This is the reference string indicating what data handler is being
898
+	 *                                          instantiated.
899
+	 * @return void .
900
+	 * @throws EE_Error
901
+	 * @throws ReflectionException
902
+	 */
903
+	protected function _set_data_handler($generating_data, $data_handler_class_name)
904
+	{
905
+		//valid classname for the data handler.  Now let's setup the key for the data handler repository to see if there
906
+		//is already a ready data handler in the repository.
907
+		$this->_current_data_handler = $this->_data_handler_collection->get_by_key(
908
+			$this->_data_handler_collection->get_key(
909
+				$data_handler_class_name,
910
+				$generating_data
911
+			)
912
+		);
913
+		if (! $this->_current_data_handler instanceof EE_Messages_incoming_data) {
914
+			//no saved data_handler in the repo so let's set one up and add it to the repo.
915
+			try {
916
+				$this->_current_data_handler = new $data_handler_class_name($generating_data);
917
+				$this->_data_handler_collection->add($this->_current_data_handler, $generating_data);
918
+			} catch (EE_Error $e) {
919
+				$this->_error_msg[] = $e->get_error();
920
+			}
921
+		}
922
+	}
923
+
924
+
925
+	/**
926
+	 * The queued EE_Message for generation does not save the data used for generation as objects
927
+	 * because serialization of those objects could be problematic if the data is saved to the db.
928
+	 * So this method calls the static method on the associated data_handler for the given message_type
929
+	 * and that preps the data for later instantiation when generating.
930
+	 *
931
+	 * @param EE_Message_To_Generate $message_to_generate
932
+	 * @param bool                   $preview Indicate whether this is being used for a preview or not.
933
+	 * @return mixed Prepped data for persisting to the queue.  false is returned if unable to prep data.
934
+	 */
935
+	protected function _prepare_data_for_queue(EE_Message_To_Generate $message_to_generate, $preview)
936
+	{
937
+		/** @type EE_Messages_incoming_data $data_handler - well not really... just the class name actually */
938
+		$data_handler = $message_to_generate->get_data_handler_class_name($preview);
939
+		if (! $message_to_generate->valid()) {
940
+			return false; //unable to get the data because the info in the EE_Message_To_Generate class is invalid.
941
+		}
942
+		return $data_handler::convert_data_for_persistent_storage($message_to_generate->data());
943
+	}
944
+
945
+
946
+	/**
947
+	 * This sets up a EEM_Message::status_incomplete EE_Message object and adds it to the generation queue.
948
+	 *
949
+	 * @param EE_Message_To_Generate $message_to_generate
950
+	 * @param bool                   $test_send Whether this is just a test send or not.  Typically used for previews.
951
+	 * @throws InvalidArgumentException
952
+	 * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
953
+	 * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
954
+	 */
955
+	public function create_and_add_message_to_queue(EE_Message_To_Generate $message_to_generate, $test_send = false)
956
+	{
957
+		//prep data
958
+		$data = $this->_prepare_data_for_queue($message_to_generate, $message_to_generate->preview());
959
+
960
+		$message = $message_to_generate->get_EE_Message();
961
+
962
+		//is there a GRP_ID in the request?
963
+		if ($GRP_ID = EE_Registry::instance()->REQ->get('GRP_ID')) {
964
+			$message->set_GRP_ID($GRP_ID);
965
+		}
966
+
967
+		if ($data === false) {
968
+			$message->set_STS_ID(EEM_Message::status_failed);
969
+			$message->set_error_message(
970
+				esc_html__(
971
+					'Unable to prepare data for persistence to the database.',
972
+					'event_espresso'
973
+				)
974
+			);
975
+		} else {
976
+			//make sure that the data handler is cached on the message as well
977
+			$data['data_handler_class_name'] = $message_to_generate->get_data_handler_class_name();
978
+		}
979
+
980
+		$this->_generation_queue->add($message, $data, $message_to_generate->preview(), $test_send);
981
+	}
982 982
 }
Please login to merge, or discard this patch.
Spacing   +15 added lines, -15 removed lines patch added patch discarded remove patch
@@ -259,7 +259,7 @@  discard block
 block discarded – undo
259 259
     {
260 260
         //double check verification has run and that everything is ready to work with (saves us having to validate
261 261
         // everything again).
262
-        if (! $this->_verified) {
262
+        if ( ! $this->_verified) {
263 263
             return false; //get out because we don't have a valid setup to work with.
264 264
         }
265 265
 
@@ -276,7 +276,7 @@  discard block
 block discarded – undo
276 276
 
277 277
 
278 278
         //if no addressees then get out because there is nothing to generation (possible bad data).
279
-        if (! $this->_valid_addressees($addressees)) {
279
+        if ( ! $this->_valid_addressees($addressees)) {
280 280
             do_action(
281 281
                 'AHEE__EE_Messages_Generator___generate__invalid_addressees',
282 282
                 $this->_generation_queue->get_message_repository()->current(),
@@ -298,7 +298,7 @@  discard block
 block discarded – undo
298 298
         $message_template_group = $this->_get_message_template_group();
299 299
 
300 300
         //in the unlikely event there is no EE_Message_Template_Group available, get out!
301
-        if (! $message_template_group instanceof EE_Message_Template_Group) {
301
+        if ( ! $message_template_group instanceof EE_Message_Template_Group) {
302 302
             $this->_error_msg[] = esc_html__(
303 303
                 'Unable to get the Message Templates for the Message being generated.  No message template group accessible.',
304 304
                 'event_espresso'
@@ -408,7 +408,7 @@  discard block
 block discarded – undo
408 408
             //attempt to retrieve from repo first
409 409
             $message_template_group = $this->_template_collection->get_by_ID($GRP_ID);
410 410
             if ($message_template_group instanceof EE_Message_Template_Group) {
411
-                return $message_template_group;  //got it!
411
+                return $message_template_group; //got it!
412 412
             }
413 413
 
414 414
             //nope don't have it yet.  Get from DB then add to repo if its not here, then that means the current GRP_ID
@@ -513,7 +513,7 @@  discard block
 block discarded – undo
513 513
         );
514 514
 
515 515
         //if we don't have a group lets hit the db.
516
-        if (! $global_message_template_group instanceof EE_Message_Template_Group) {
516
+        if ( ! $global_message_template_group instanceof EE_Message_Template_Group) {
517 517
             $global_message_template_group = EEM_Message_Template_Group::instance()->get_one(
518 518
                 array(
519 519
                     array(
@@ -570,7 +570,7 @@  discard block
 block discarded – undo
570 570
         $context_templates = $message_template_group->context_templates();
571 571
         foreach ($context_templates as $context => $template_fields) {
572 572
             foreach ($template_fields as $template_field => $template_obj) {
573
-                if (! $template_obj instanceof EE_Message_Template) {
573
+                if ( ! $template_obj instanceof EE_Message_Template) {
574 574
                     continue;
575 575
                 }
576 576
                 $templates[$template_field][$context] = $template_obj->get('MTP_content');
@@ -599,7 +599,7 @@  discard block
 block discarded – undo
599 599
     {
600 600
 
601 601
         //if templates are empty then get out because we can't generate anything.
602
-        if (! $templates) {
602
+        if ( ! $templates) {
603 603
             $this->_error_msg[] = esc_html__(
604 604
                 'Unable to assemble messages because there are no templates retrieved for generating the messages with',
605 605
                 'event_espresso'
@@ -703,7 +703,7 @@  discard block
 block discarded – undo
703 703
             $shortcodes = isset($m_shortcodes[$field]) ? $m_shortcodes[$field] : $valid_shortcodes;
704 704
             if (isset($templates[$field][$context])) {
705 705
                 //prefix field.
706
-                $column_name = 'MSG_' . $field;
706
+                $column_name = 'MSG_'.$field;
707 707
                 try {
708 708
                     $content = $this->_shortcode_parser->parse_message_template(
709 709
                         $templates[$field][$context],
@@ -772,13 +772,13 @@  discard block
 block discarded – undo
772 772
      */
773 773
     protected function _valid_addressees($addressees)
774 774
     {
775
-        if (! $addressees || ! is_array($addressees)) {
775
+        if ( ! $addressees || ! is_array($addressees)) {
776 776
             return false;
777 777
         }
778 778
 
779 779
         foreach ($addressees as $addressee_array) {
780 780
             foreach ($addressee_array as $addressee) {
781
-                if (! $addressee instanceof EE_Messages_Addressee) {
781
+                if ( ! $addressee instanceof EE_Messages_Addressee) {
782 782
                     return false;
783 783
                 }
784 784
             }
@@ -820,7 +820,7 @@  discard block
 block discarded – undo
820 820
         /**
821 821
          * Check if there is any generation data, but only if this is not for a preview.
822 822
          */
823
-        if (! $this->_generation_queue->get_message_repository()->get_generation_data()
823
+        if ( ! $this->_generation_queue->get_message_repository()->get_generation_data()
824 824
             && (
825 825
                 ! $this->_generation_queue->get_message_repository()->is_preview()
826 826
                 && $this->_generation_queue->get_message_repository()->get_data_handler()
@@ -859,7 +859,7 @@  discard block
 block discarded – undo
859 859
         /** @type EE_Messages_incoming_data $data_handler_class_name - well not really... just the class name actually*/
860 860
         $data_handler_class_name = $this->_generation_queue->get_message_repository()->get_data_handler()
861 861
             ? $this->_generation_queue->get_message_repository()->get_data_handler()
862
-            : 'EE_Messages_' . $this->_current_message_type->get_data_handler($generation_data) . '_incoming_data';
862
+            : 'EE_Messages_'.$this->_current_message_type->get_data_handler($generation_data).'_incoming_data';
863 863
 
864 864
         //If this EE_Message is for a preview, then let's switch out to the preview data handler.
865 865
         if ($this->_generation_queue->get_message_repository()->is_preview()) {
@@ -867,7 +867,7 @@  discard block
 block discarded – undo
867 867
         }
868 868
 
869 869
         //First get the class name for the data handler (and also verifies it exists.
870
-        if (! class_exists($data_handler_class_name)) {
870
+        if ( ! class_exists($data_handler_class_name)) {
871 871
             $this->_error_msg[] = sprintf(
872 872
                 esc_html__(
873 873
                     'The included data handler class name does not match any valid, accessible, "%1$s" classes.  Looking for %2$s.',
@@ -910,7 +910,7 @@  discard block
 block discarded – undo
910 910
                 $generating_data
911 911
             )
912 912
         );
913
-        if (! $this->_current_data_handler instanceof EE_Messages_incoming_data) {
913
+        if ( ! $this->_current_data_handler instanceof EE_Messages_incoming_data) {
914 914
             //no saved data_handler in the repo so let's set one up and add it to the repo.
915 915
             try {
916 916
                 $this->_current_data_handler = new $data_handler_class_name($generating_data);
@@ -936,7 +936,7 @@  discard block
 block discarded – undo
936 936
     {
937 937
         /** @type EE_Messages_incoming_data $data_handler - well not really... just the class name actually */
938 938
         $data_handler = $message_to_generate->get_data_handler_class_name($preview);
939
-        if (! $message_to_generate->valid()) {
939
+        if ( ! $message_to_generate->valid()) {
940 940
             return false; //unable to get the data because the info in the EE_Message_To_Generate class is invalid.
941 941
         }
942 942
         return $data_handler::convert_data_for_persistent_storage($message_to_generate->data());
Please login to merge, or discard this patch.
messages/templates/ee_msg_editor_active_context_element.template.php 1 patch
Indentation   +18 added lines, -18 removed lines patch added patch discarded remove patch
@@ -10,22 +10,22 @@  discard block
 block discarded – undo
10 10
  * @var int    $message_template_group_id The ID for the message template group this context belongs to.
11 11
  */
12 12
 $active_message = sprintf(
13
-    esc_html__(
14
-        'The template for %1$s is currently %2$sactive%3$s.',
15
-        'event_espresso'
16
-    ),
17
-    $context_label,
18
-    '<strong>',
19
-    '</strong>'
13
+	esc_html__(
14
+		'The template for %1$s is currently %2$sactive%3$s.',
15
+		'event_espresso'
16
+	),
17
+	$context_label,
18
+	'<strong>',
19
+	'</strong>'
20 20
 );
21 21
 $inactive_message = sprintf(
22
-    esc_html__(
23
-        'The template for %1$s is currently %2$sinactive%3$s.',
24
-        'event_espresso'
25
-    ),
26
-    $context_label,
27
-    '<strong>',
28
-    '</strong>'
22
+	esc_html__(
23
+		'The template for %1$s is currently %2$sinactive%3$s.',
24
+		'event_espresso'
25
+	),
26
+	$context_label,
27
+	'<strong>',
28
+	'</strong>'
29 29
 );
30 30
 ?>
31 31
 <div class="context-active-control-container">
@@ -34,8 +34,8 @@  discard block
 block discarded – undo
34 34
         <span id="on-off-nonce-<?php echo $context; ?>" class="hidden"><?php echo $nonce; ?></span>
35 35
         <span class="ee-on-off-toggle-label">
36 36
             <?php
37
-            echo $is_active ? $active_message : $inactive_message;
38
-            ?>
37
+			echo $is_active ? $active_message : $inactive_message;
38
+			?>
39 39
         </span>
40 40
         <div class="hidden js-data">
41 41
             <span class="ee-active-message"><?php echo $active_message; ?></span>
@@ -43,8 +43,8 @@  discard block
 block discarded – undo
43 43
         </div>
44 44
         <div class="switch">
45 45
             <?php
46
-            $checked = $is_active ? ' checked="checked"' : '';
47
-            ?>
46
+			$checked = $is_active ? ' checked="checked"' : '';
47
+			?>
48 48
             <input data-grpid="<?php echo $message_template_group_id; ?>" id="ee-on-off-toggle-<?php echo $context; ?>" type="checkbox" class="ee-on-off-toggle ee-toggle-round-flat"<?php echo $checked; ?> value="<?php echo $on_off_action; ?>">
49 49
             <label for="ee-on-off-toggle-<?php echo $context; ?>"></label>
50 50
         </div>
Please login to merge, or discard this patch.
admin_pages/messages/Messages_Template_List_Table.class.php 2 patches
Indentation   +368 added lines, -368 removed lines patch added patch discarded remove patch
@@ -13,373 +13,373 @@
 block discarded – undo
13 13
 {
14 14
 
15 15
 
16
-    /**
17
-     * @return Messages_Admin_Page
18
-     */
19
-    public function get_admin_page()
20
-    {
21
-        return $this->_admin_page;
22
-    }
23
-
24
-
25
-    /**
26
-     * Setup data object
27
-     */
28
-    protected function _setup_data()
29
-    {
30
-        $this->_data           = $this->get_admin_page()->get_message_templates(
31
-            $this->_per_page,
32
-            $this->_view,
33
-            false
34
-        );
35
-        $this->_all_data_count = $this->get_admin_page()->get_message_templates(
36
-            $this->_per_page,
37
-            $this->_view,
38
-            true,
39
-            true
40
-        );
41
-    }
42
-
43
-
44
-    /**
45
-     * Set internal properties
46
-     */
47
-    protected function _set_properties()
48
-    {
49
-        $this->_wp_list_args = array(
50
-            'singular' => esc_html__('Message Template Group', 'event_espresso'),
51
-            'plural'   => esc_html__('Message Template', 'event_espresso'),
52
-            'ajax'     => true, //for now,
53
-            'screen'   => $this->get_admin_page()->get_current_screen()->id,
54
-        );
55
-        $this->_columns      = array(
56
-            //'cb' => '<input type="checkbox" />', //no deleting default (global) templates!
57
-            'message_type' => esc_html__('Message Type', 'event_espresso'),
58
-            'messenger'    => esc_html__('Messenger', 'event_espresso'),
59
-            'description'  => esc_html__('Description', 'event_espresso'),
60
-        );
61
-
62
-        $this->_sortable_columns = array(
63
-            'messenger' => array('MTP_messenger' => true),
64
-        );
65
-
66
-        $this->_hidden_columns = array();
67
-    }
68
-
69
-
70
-    /**
71
-     * Overriding the single_row method from parent to verify whether the $item has an accessible
72
-     * message_type or messenger object before generating the row.
73
-     *
74
-     * @param EE_Message_Template_Group $item
75
-     * @return string
76
-     * @throws EE_Error
77
-     */
78
-    public function single_row($item)
79
-    {
80
-        $message_type = $item->message_type_obj();
81
-        $messenger    = $item->messenger_obj();
82
-
83
-        if (! $message_type instanceof EE_message_type || ! $messenger instanceof EE_messenger) {
84
-            echo '';
85
-            return;
86
-        }
87
-
88
-        parent::single_row($item);
89
-    }
90
-
91
-
92
-    /**
93
-     * @return array
94
-     * @throws EE_Error
95
-     */
96
-    protected function _get_table_filters()
97
-    {
98
-        $filters = array();
99
-
100
-        //get select inputs
101
-        $select_inputs = array(
102
-            $this->_get_messengers_dropdown_filter(),
103
-            $this->_get_message_types_dropdown_filter(),
104
-        );
105
-
106
-        //set filters to select inputs if they aren't empty
107
-        foreach ($select_inputs as $select_input) {
108
-            if ($select_input) {
109
-                $filters[] = $select_input;
110
-            }
111
-        }
112
-        return $filters;
113
-    }
114
-
115
-    /**
116
-     * We're just removing the search box for message templates, not needed.
117
-     *
118
-     * @param string $text
119
-     * @param string $input_id
120
-     * @return string ;
121
-     */
122
-    public function search_box($text, $input_id)
123
-    {
124
-        return '';
125
-    }
126
-
127
-
128
-    /**
129
-     * Add counts to the _views property
130
-     */
131
-    protected function _add_view_counts()
132
-    {
133
-        foreach ($this->_views as $view => $args) {
134
-            $this->_views[$view]['count'] = $this->get_admin_page()->get_message_templates(
135
-                $this->_per_page,
136
-                $view,
137
-                true,
138
-                true
139
-            );
140
-        }
141
-    }
142
-
143
-
144
-    /**
145
-     * @param EE_Message_Template_Group $item
146
-     * @return string
147
-     */
148
-    public function column_cb($item)
149
-    {
150
-        return '';
151
-    }
152
-
153
-
154
-    /**
155
-     * @param EE_Message_Template_Group $item
156
-     * @return string
157
-     * @throws EE_Error
158
-     */
159
-    public function column_description($item)
160
-    {
161
-        return '<p>' . $item->message_type_obj()->description . '</p>';
162
-    }
163
-
164
-
165
-    /**
166
-     * @param EE_Message_Template_Group $item
167
-     * @return string
168
-     * @throws EE_Error
169
-     */
170
-    public function column_messenger($item)
171
-    {
172
-        //Return the name contents
173
-        return sprintf(
174
-            '%1$s <span style="color:silver">(id:%2$s)</span><br />%3$s%4$s',
175
-            /* $1%s */
176
-            $this->_get_name_link_for_messenger($item),
177
-            /* $2%s */
178
-            $item->GRP_ID(),
179
-            /* %4$s */
180
-            $this->_get_context_links($item),
181
-            /* $3%s */
182
-            $this->row_actions($this->_get_actions_for_messenger_column($item))
183
-        );
184
-    }
185
-
186
-    /**
187
-     * column_message_type
188
-     *
189
-     * @param  EE_Message_Template_Group $item message info for the row
190
-     * @return string message_type name
191
-     * @throws EE_Error
192
-     */
193
-    public function column_message_type($item)
194
-    {
195
-        return ucwords($item->message_type_obj()->label['singular']);
196
-    }
197
-
198
-
199
-    /**
200
-     * Generate dropdown filter select input for messengers
201
-     *
202
-     * @param bool $global
203
-     * @return string
204
-     * @throws EE_Error
205
-     */
206
-    protected function _get_messengers_dropdown_filter($global = true)
207
-    {
208
-        $messenger_options                                   = array();
209
-        $active_message_template_groups_grouped_by_messenger = EEM_Message_Template_Group::instance()->get_all(
210
-            array(
211
-                array(
212
-                    'MTP_is_active' => true,
213
-                    'MTP_is_global' => $global,
214
-                ),
215
-                'group_by' => 'MTP_messenger',
216
-            )
217
-        );
218
-
219
-        foreach ($active_message_template_groups_grouped_by_messenger as $active_message_template_group) {
220
-            if ($active_message_template_group instanceof EE_Message_Template_Group) {
221
-                $messenger                          = $active_message_template_group->messenger_obj();
222
-                $messenger_label                    = $messenger instanceof EE_messenger
223
-                    ? $messenger->label['singular']
224
-                    : $active_message_template_group->messenger();
225
-                $messenger_options[$active_message_template_group->messenger()] = ucwords($messenger_label);
226
-            }
227
-        }
228
-        return $this->get_admin_page()->get_messengers_select_input($messenger_options);
229
-    }
230
-
231
-
232
-    /**
233
-     * Generate dropdown filter select input for message types
234
-     *
235
-     * @param bool $global
236
-     * @return string
237
-     * @throws EE_Error
238
-     */
239
-    protected function _get_message_types_dropdown_filter($global = true)
240
-    {
241
-        $message_type_options                                   = array();
242
-        $active_message_template_groups_grouped_by_message_type = EEM_Message_Template_Group::instance()->get_all(
243
-            array(
244
-                array(
245
-                    'MTP_is_active' => true,
246
-                    'MTP_is_global' => true,
247
-                ),
248
-                'group_by' => 'MTP_message_type',
249
-            )
250
-        );
251
-
252
-        foreach ($active_message_template_groups_grouped_by_message_type as $active_message_template_group) {
253
-            if ($active_message_template_group instanceof EE_Message_Template_Group) {
254
-                $message_type               = $active_message_template_group->message_type_obj();
255
-                $message_type_label         = $message_type instanceof EE_message_type
256
-                    ? $message_type->label['singular']
257
-                    : $active_message_template_group->message_type();
258
-                $message_type_options[$active_message_template_group->message_type()] = ucwords($message_type_label);
259
-            }
260
-        }
261
-        return $this->get_admin_page()->get_message_types_select_input($message_type_options);
262
-    }
263
-
264
-
265
-    /**
266
-     * Return the edit url for the message template group.
267
-     * @param EE_Message_Template_Group $item
268
-     * @return string
269
-     * @throws EE_Error
270
-     */
271
-    protected function _get_edit_url(EE_Message_Template_Group $item)
272
-    {
273
-        $edit_url = '';
274
-        // edit link but only if item isn't trashed.
275
-        if (! $item->get('MTP_deleted')
276
-            && EE_Registry::instance()->CAP->current_user_can(
277
-                'ee_edit_message',
278
-                'espresso_messages_edit_message_template',
279
-                $item->ID()
280
-            )) {
281
-            $edit_url = EE_Admin_Page::add_query_args_and_nonce(
282
-                array(
283
-                    'action' => 'edit_message_template',
284
-                    'id'     => $item->GRP_ID(),
285
-                ),
286
-                EE_MSG_ADMIN_URL
287
-            );
288
-        }
289
-        return $edit_url;
290
-    }
291
-
292
-
293
-    /**
294
-     * Get the context link string for the messenger column.
295
-     * @param EE_Message_Template_Group $item
296
-     * @return string
297
-     * @throws EE_Error
298
-     */
299
-    protected function _get_context_links(EE_Message_Template_Group $item)
300
-    {
301
-        //first check if we even show the context links or not.
302
-        if (! EE_Registry::instance()->CAP->current_user_can(
303
-            'ee_edit_message',
304
-            'espresso_messages_edit_message_template',
305
-            $item->ID()
306
-        )
307
-            || $item->get('MTP_deleted')
308
-        ) {
309
-            return '';
310
-        }
311
-        //we want to display the contexts in here so we need to set them up
312
-        $c_label           = $item->context_label();
313
-        $c_configs         = $item->contexts_config();
314
-        $ctxt              = array();
315
-        $context_templates = $item->context_templates();
316
-        foreach ($context_templates as $context => $template_fields) {
317
-            $mtp_to        = ! empty($context_templates[$context]['to'])
318
-                             && $context_templates[$context]['to'] instanceof EE_Message_Template
319
-                ? $context_templates[$context]['to']->get('MTP_content')
320
-                : null;
321
-            $inactive_class      = (
322
-                empty($mtp_to)
323
-                && ! empty($context_templates[$context]['to'])
324
-            )
325
-            || ! $item->is_context_active($context)
326
-                ? ' mtp-inactive'
327
-                : '';
328
-            $context_title = ucwords($c_configs[$context]['label']);
329
-            $edit_link     = EE_Admin_Page::add_query_args_and_nonce(array(
330
-                'action'  => 'edit_message_template',
331
-                'id'      => $item->GRP_ID(),
332
-                'context' => $context,
333
-            ), EE_MSG_ADMIN_URL);
334
-            $ctxt[]        =  '<a'
335
-                  . ' href="' . $edit_link . '"'
336
-                  . ' class="' . $item->message_type() . '-' . $context . '-edit-link' .$inactive_class . '"'
337
-                  . ' title="' . esc_attr__('Edit Context', 'event_espresso') . '">'
338
-                  . $context_title
339
-                  . '</a>';
340
-        }
341
-
342
-        return sprintf('<strong>%s:</strong> ', ucwords($c_label['plural'])) . implode(' | ', $ctxt);
343
-    }
344
-
345
-
346
-    /**
347
-     * Get the Name string from the messenger column (linked to edit if the context allows for that).
348
-     * @param EE_Message_Template_Group $item
349
-     * @return string
350
-     * @throws EE_Error
351
-     */
352
-    protected function _get_name_link_for_messenger(EE_Message_Template_Group $item)
353
-    {
354
-        $edit_url = $this->_get_edit_url($item);
355
-        return $edit_url
356
-            ? '<a href="' . $edit_url . '"'
357
-              . ' title="' . esc_attr__('Edit Template Group', 'event_espresso') . '">'
358
-              . ucwords($item->messenger_obj()->label['singular'])
359
-              . '</a>'
360
-            : ucwords($item->messenger_obj()->label['singular']);
361
-    }
362
-
363
-
364
-    /**
365
-     * Return the actions array for the messenger column.
366
-     * @param EE_Message_Template_Group $item
367
-     * @return array
368
-     * @throws EE_Error
369
-     */
370
-    protected function _get_actions_for_messenger_column(EE_Message_Template_Group $item)
371
-    {
372
-        $actions = array();
373
-        if ($edit_url = $this->_get_edit_url($item)) {
374
-            $actions = array(
375
-                'edit' => '<a href="' . $edit_url . '"'
376
-                          . ' class="' . $item->message_type() . '-edit-link"'
377
-                          . ' title="' . esc_attr__('Edit Template Group', 'event_espresso') . '">'
378
-                          . esc_html__('Edit', 'event_espresso')
379
-                          . '</a>'
380
-            );
381
-        }
382
-        return $actions;
383
-    }
16
+	/**
17
+	 * @return Messages_Admin_Page
18
+	 */
19
+	public function get_admin_page()
20
+	{
21
+		return $this->_admin_page;
22
+	}
23
+
24
+
25
+	/**
26
+	 * Setup data object
27
+	 */
28
+	protected function _setup_data()
29
+	{
30
+		$this->_data           = $this->get_admin_page()->get_message_templates(
31
+			$this->_per_page,
32
+			$this->_view,
33
+			false
34
+		);
35
+		$this->_all_data_count = $this->get_admin_page()->get_message_templates(
36
+			$this->_per_page,
37
+			$this->_view,
38
+			true,
39
+			true
40
+		);
41
+	}
42
+
43
+
44
+	/**
45
+	 * Set internal properties
46
+	 */
47
+	protected function _set_properties()
48
+	{
49
+		$this->_wp_list_args = array(
50
+			'singular' => esc_html__('Message Template Group', 'event_espresso'),
51
+			'plural'   => esc_html__('Message Template', 'event_espresso'),
52
+			'ajax'     => true, //for now,
53
+			'screen'   => $this->get_admin_page()->get_current_screen()->id,
54
+		);
55
+		$this->_columns      = array(
56
+			//'cb' => '<input type="checkbox" />', //no deleting default (global) templates!
57
+			'message_type' => esc_html__('Message Type', 'event_espresso'),
58
+			'messenger'    => esc_html__('Messenger', 'event_espresso'),
59
+			'description'  => esc_html__('Description', 'event_espresso'),
60
+		);
61
+
62
+		$this->_sortable_columns = array(
63
+			'messenger' => array('MTP_messenger' => true),
64
+		);
65
+
66
+		$this->_hidden_columns = array();
67
+	}
68
+
69
+
70
+	/**
71
+	 * Overriding the single_row method from parent to verify whether the $item has an accessible
72
+	 * message_type or messenger object before generating the row.
73
+	 *
74
+	 * @param EE_Message_Template_Group $item
75
+	 * @return string
76
+	 * @throws EE_Error
77
+	 */
78
+	public function single_row($item)
79
+	{
80
+		$message_type = $item->message_type_obj();
81
+		$messenger    = $item->messenger_obj();
82
+
83
+		if (! $message_type instanceof EE_message_type || ! $messenger instanceof EE_messenger) {
84
+			echo '';
85
+			return;
86
+		}
87
+
88
+		parent::single_row($item);
89
+	}
90
+
91
+
92
+	/**
93
+	 * @return array
94
+	 * @throws EE_Error
95
+	 */
96
+	protected function _get_table_filters()
97
+	{
98
+		$filters = array();
99
+
100
+		//get select inputs
101
+		$select_inputs = array(
102
+			$this->_get_messengers_dropdown_filter(),
103
+			$this->_get_message_types_dropdown_filter(),
104
+		);
105
+
106
+		//set filters to select inputs if they aren't empty
107
+		foreach ($select_inputs as $select_input) {
108
+			if ($select_input) {
109
+				$filters[] = $select_input;
110
+			}
111
+		}
112
+		return $filters;
113
+	}
114
+
115
+	/**
116
+	 * We're just removing the search box for message templates, not needed.
117
+	 *
118
+	 * @param string $text
119
+	 * @param string $input_id
120
+	 * @return string ;
121
+	 */
122
+	public function search_box($text, $input_id)
123
+	{
124
+		return '';
125
+	}
126
+
127
+
128
+	/**
129
+	 * Add counts to the _views property
130
+	 */
131
+	protected function _add_view_counts()
132
+	{
133
+		foreach ($this->_views as $view => $args) {
134
+			$this->_views[$view]['count'] = $this->get_admin_page()->get_message_templates(
135
+				$this->_per_page,
136
+				$view,
137
+				true,
138
+				true
139
+			);
140
+		}
141
+	}
142
+
143
+
144
+	/**
145
+	 * @param EE_Message_Template_Group $item
146
+	 * @return string
147
+	 */
148
+	public function column_cb($item)
149
+	{
150
+		return '';
151
+	}
152
+
153
+
154
+	/**
155
+	 * @param EE_Message_Template_Group $item
156
+	 * @return string
157
+	 * @throws EE_Error
158
+	 */
159
+	public function column_description($item)
160
+	{
161
+		return '<p>' . $item->message_type_obj()->description . '</p>';
162
+	}
163
+
164
+
165
+	/**
166
+	 * @param EE_Message_Template_Group $item
167
+	 * @return string
168
+	 * @throws EE_Error
169
+	 */
170
+	public function column_messenger($item)
171
+	{
172
+		//Return the name contents
173
+		return sprintf(
174
+			'%1$s <span style="color:silver">(id:%2$s)</span><br />%3$s%4$s',
175
+			/* $1%s */
176
+			$this->_get_name_link_for_messenger($item),
177
+			/* $2%s */
178
+			$item->GRP_ID(),
179
+			/* %4$s */
180
+			$this->_get_context_links($item),
181
+			/* $3%s */
182
+			$this->row_actions($this->_get_actions_for_messenger_column($item))
183
+		);
184
+	}
185
+
186
+	/**
187
+	 * column_message_type
188
+	 *
189
+	 * @param  EE_Message_Template_Group $item message info for the row
190
+	 * @return string message_type name
191
+	 * @throws EE_Error
192
+	 */
193
+	public function column_message_type($item)
194
+	{
195
+		return ucwords($item->message_type_obj()->label['singular']);
196
+	}
197
+
198
+
199
+	/**
200
+	 * Generate dropdown filter select input for messengers
201
+	 *
202
+	 * @param bool $global
203
+	 * @return string
204
+	 * @throws EE_Error
205
+	 */
206
+	protected function _get_messengers_dropdown_filter($global = true)
207
+	{
208
+		$messenger_options                                   = array();
209
+		$active_message_template_groups_grouped_by_messenger = EEM_Message_Template_Group::instance()->get_all(
210
+			array(
211
+				array(
212
+					'MTP_is_active' => true,
213
+					'MTP_is_global' => $global,
214
+				),
215
+				'group_by' => 'MTP_messenger',
216
+			)
217
+		);
218
+
219
+		foreach ($active_message_template_groups_grouped_by_messenger as $active_message_template_group) {
220
+			if ($active_message_template_group instanceof EE_Message_Template_Group) {
221
+				$messenger                          = $active_message_template_group->messenger_obj();
222
+				$messenger_label                    = $messenger instanceof EE_messenger
223
+					? $messenger->label['singular']
224
+					: $active_message_template_group->messenger();
225
+				$messenger_options[$active_message_template_group->messenger()] = ucwords($messenger_label);
226
+			}
227
+		}
228
+		return $this->get_admin_page()->get_messengers_select_input($messenger_options);
229
+	}
230
+
231
+
232
+	/**
233
+	 * Generate dropdown filter select input for message types
234
+	 *
235
+	 * @param bool $global
236
+	 * @return string
237
+	 * @throws EE_Error
238
+	 */
239
+	protected function _get_message_types_dropdown_filter($global = true)
240
+	{
241
+		$message_type_options                                   = array();
242
+		$active_message_template_groups_grouped_by_message_type = EEM_Message_Template_Group::instance()->get_all(
243
+			array(
244
+				array(
245
+					'MTP_is_active' => true,
246
+					'MTP_is_global' => true,
247
+				),
248
+				'group_by' => 'MTP_message_type',
249
+			)
250
+		);
251
+
252
+		foreach ($active_message_template_groups_grouped_by_message_type as $active_message_template_group) {
253
+			if ($active_message_template_group instanceof EE_Message_Template_Group) {
254
+				$message_type               = $active_message_template_group->message_type_obj();
255
+				$message_type_label         = $message_type instanceof EE_message_type
256
+					? $message_type->label['singular']
257
+					: $active_message_template_group->message_type();
258
+				$message_type_options[$active_message_template_group->message_type()] = ucwords($message_type_label);
259
+			}
260
+		}
261
+		return $this->get_admin_page()->get_message_types_select_input($message_type_options);
262
+	}
263
+
264
+
265
+	/**
266
+	 * Return the edit url for the message template group.
267
+	 * @param EE_Message_Template_Group $item
268
+	 * @return string
269
+	 * @throws EE_Error
270
+	 */
271
+	protected function _get_edit_url(EE_Message_Template_Group $item)
272
+	{
273
+		$edit_url = '';
274
+		// edit link but only if item isn't trashed.
275
+		if (! $item->get('MTP_deleted')
276
+			&& EE_Registry::instance()->CAP->current_user_can(
277
+				'ee_edit_message',
278
+				'espresso_messages_edit_message_template',
279
+				$item->ID()
280
+			)) {
281
+			$edit_url = EE_Admin_Page::add_query_args_and_nonce(
282
+				array(
283
+					'action' => 'edit_message_template',
284
+					'id'     => $item->GRP_ID(),
285
+				),
286
+				EE_MSG_ADMIN_URL
287
+			);
288
+		}
289
+		return $edit_url;
290
+	}
291
+
292
+
293
+	/**
294
+	 * Get the context link string for the messenger column.
295
+	 * @param EE_Message_Template_Group $item
296
+	 * @return string
297
+	 * @throws EE_Error
298
+	 */
299
+	protected function _get_context_links(EE_Message_Template_Group $item)
300
+	{
301
+		//first check if we even show the context links or not.
302
+		if (! EE_Registry::instance()->CAP->current_user_can(
303
+			'ee_edit_message',
304
+			'espresso_messages_edit_message_template',
305
+			$item->ID()
306
+		)
307
+			|| $item->get('MTP_deleted')
308
+		) {
309
+			return '';
310
+		}
311
+		//we want to display the contexts in here so we need to set them up
312
+		$c_label           = $item->context_label();
313
+		$c_configs         = $item->contexts_config();
314
+		$ctxt              = array();
315
+		$context_templates = $item->context_templates();
316
+		foreach ($context_templates as $context => $template_fields) {
317
+			$mtp_to        = ! empty($context_templates[$context]['to'])
318
+							 && $context_templates[$context]['to'] instanceof EE_Message_Template
319
+				? $context_templates[$context]['to']->get('MTP_content')
320
+				: null;
321
+			$inactive_class      = (
322
+				empty($mtp_to)
323
+				&& ! empty($context_templates[$context]['to'])
324
+			)
325
+			|| ! $item->is_context_active($context)
326
+				? ' mtp-inactive'
327
+				: '';
328
+			$context_title = ucwords($c_configs[$context]['label']);
329
+			$edit_link     = EE_Admin_Page::add_query_args_and_nonce(array(
330
+				'action'  => 'edit_message_template',
331
+				'id'      => $item->GRP_ID(),
332
+				'context' => $context,
333
+			), EE_MSG_ADMIN_URL);
334
+			$ctxt[]        =  '<a'
335
+				  . ' href="' . $edit_link . '"'
336
+				  . ' class="' . $item->message_type() . '-' . $context . '-edit-link' .$inactive_class . '"'
337
+				  . ' title="' . esc_attr__('Edit Context', 'event_espresso') . '">'
338
+				  . $context_title
339
+				  . '</a>';
340
+		}
341
+
342
+		return sprintf('<strong>%s:</strong> ', ucwords($c_label['plural'])) . implode(' | ', $ctxt);
343
+	}
344
+
345
+
346
+	/**
347
+	 * Get the Name string from the messenger column (linked to edit if the context allows for that).
348
+	 * @param EE_Message_Template_Group $item
349
+	 * @return string
350
+	 * @throws EE_Error
351
+	 */
352
+	protected function _get_name_link_for_messenger(EE_Message_Template_Group $item)
353
+	{
354
+		$edit_url = $this->_get_edit_url($item);
355
+		return $edit_url
356
+			? '<a href="' . $edit_url . '"'
357
+			  . ' title="' . esc_attr__('Edit Template Group', 'event_espresso') . '">'
358
+			  . ucwords($item->messenger_obj()->label['singular'])
359
+			  . '</a>'
360
+			: ucwords($item->messenger_obj()->label['singular']);
361
+	}
362
+
363
+
364
+	/**
365
+	 * Return the actions array for the messenger column.
366
+	 * @param EE_Message_Template_Group $item
367
+	 * @return array
368
+	 * @throws EE_Error
369
+	 */
370
+	protected function _get_actions_for_messenger_column(EE_Message_Template_Group $item)
371
+	{
372
+		$actions = array();
373
+		if ($edit_url = $this->_get_edit_url($item)) {
374
+			$actions = array(
375
+				'edit' => '<a href="' . $edit_url . '"'
376
+						  . ' class="' . $item->message_type() . '-edit-link"'
377
+						  . ' title="' . esc_attr__('Edit Template Group', 'event_espresso') . '">'
378
+						  . esc_html__('Edit', 'event_espresso')
379
+						  . '</a>'
380
+			);
381
+		}
382
+		return $actions;
383
+	}
384 384
 }
385 385
 
Please login to merge, or discard this patch.
Spacing   +17 added lines, -17 removed lines patch added patch discarded remove patch
@@ -27,7 +27,7 @@  discard block
 block discarded – undo
27 27
      */
28 28
     protected function _setup_data()
29 29
     {
30
-        $this->_data           = $this->get_admin_page()->get_message_templates(
30
+        $this->_data = $this->get_admin_page()->get_message_templates(
31 31
             $this->_per_page,
32 32
             $this->_view,
33 33
             false
@@ -52,7 +52,7 @@  discard block
 block discarded – undo
52 52
             'ajax'     => true, //for now,
53 53
             'screen'   => $this->get_admin_page()->get_current_screen()->id,
54 54
         );
55
-        $this->_columns      = array(
55
+        $this->_columns = array(
56 56
             //'cb' => '<input type="checkbox" />', //no deleting default (global) templates!
57 57
             'message_type' => esc_html__('Message Type', 'event_espresso'),
58 58
             'messenger'    => esc_html__('Messenger', 'event_espresso'),
@@ -80,7 +80,7 @@  discard block
 block discarded – undo
80 80
         $message_type = $item->message_type_obj();
81 81
         $messenger    = $item->messenger_obj();
82 82
 
83
-        if (! $message_type instanceof EE_message_type || ! $messenger instanceof EE_messenger) {
83
+        if ( ! $message_type instanceof EE_message_type || ! $messenger instanceof EE_messenger) {
84 84
             echo '';
85 85
             return;
86 86
         }
@@ -158,7 +158,7 @@  discard block
 block discarded – undo
158 158
      */
159 159
     public function column_description($item)
160 160
     {
161
-        return '<p>' . $item->message_type_obj()->description . '</p>';
161
+        return '<p>'.$item->message_type_obj()->description.'</p>';
162 162
     }
163 163
 
164 164
 
@@ -272,7 +272,7 @@  discard block
 block discarded – undo
272 272
     {
273 273
         $edit_url = '';
274 274
         // edit link but only if item isn't trashed.
275
-        if (! $item->get('MTP_deleted')
275
+        if ( ! $item->get('MTP_deleted')
276 276
             && EE_Registry::instance()->CAP->current_user_can(
277 277
                 'ee_edit_message',
278 278
                 'espresso_messages_edit_message_template',
@@ -299,7 +299,7 @@  discard block
 block discarded – undo
299 299
     protected function _get_context_links(EE_Message_Template_Group $item)
300 300
     {
301 301
         //first check if we even show the context links or not.
302
-        if (! EE_Registry::instance()->CAP->current_user_can(
302
+        if ( ! EE_Registry::instance()->CAP->current_user_can(
303 303
             'ee_edit_message',
304 304
             'espresso_messages_edit_message_template',
305 305
             $item->ID()
@@ -318,7 +318,7 @@  discard block
 block discarded – undo
318 318
                              && $context_templates[$context]['to'] instanceof EE_Message_Template
319 319
                 ? $context_templates[$context]['to']->get('MTP_content')
320 320
                 : null;
321
-            $inactive_class      = (
321
+            $inactive_class = (
322 322
                 empty($mtp_to)
323 323
                 && ! empty($context_templates[$context]['to'])
324 324
             )
@@ -331,15 +331,15 @@  discard block
 block discarded – undo
331 331
                 'id'      => $item->GRP_ID(),
332 332
                 'context' => $context,
333 333
             ), EE_MSG_ADMIN_URL);
334
-            $ctxt[]        =  '<a'
335
-                  . ' href="' . $edit_link . '"'
336
-                  . ' class="' . $item->message_type() . '-' . $context . '-edit-link' .$inactive_class . '"'
337
-                  . ' title="' . esc_attr__('Edit Context', 'event_espresso') . '">'
334
+            $ctxt[] = '<a'
335
+                  . ' href="'.$edit_link.'"'
336
+                  . ' class="'.$item->message_type().'-'.$context.'-edit-link'.$inactive_class.'"'
337
+                  . ' title="'.esc_attr__('Edit Context', 'event_espresso').'">'
338 338
                   . $context_title
339 339
                   . '</a>';
340 340
         }
341 341
 
342
-        return sprintf('<strong>%s:</strong> ', ucwords($c_label['plural'])) . implode(' | ', $ctxt);
342
+        return sprintf('<strong>%s:</strong> ', ucwords($c_label['plural'])).implode(' | ', $ctxt);
343 343
     }
344 344
 
345 345
 
@@ -353,8 +353,8 @@  discard block
 block discarded – undo
353 353
     {
354 354
         $edit_url = $this->_get_edit_url($item);
355 355
         return $edit_url
356
-            ? '<a href="' . $edit_url . '"'
357
-              . ' title="' . esc_attr__('Edit Template Group', 'event_espresso') . '">'
356
+            ? '<a href="'.$edit_url.'"'
357
+              . ' title="'.esc_attr__('Edit Template Group', 'event_espresso').'">'
358 358
               . ucwords($item->messenger_obj()->label['singular'])
359 359
               . '</a>'
360 360
             : ucwords($item->messenger_obj()->label['singular']);
@@ -372,9 +372,9 @@  discard block
 block discarded – undo
372 372
         $actions = array();
373 373
         if ($edit_url = $this->_get_edit_url($item)) {
374 374
             $actions = array(
375
-                'edit' => '<a href="' . $edit_url . '"'
376
-                          . ' class="' . $item->message_type() . '-edit-link"'
377
-                          . ' title="' . esc_attr__('Edit Template Group', 'event_espresso') . '">'
375
+                'edit' => '<a href="'.$edit_url.'"'
376
+                          . ' class="'.$item->message_type().'-edit-link"'
377
+                          . ' title="'.esc_attr__('Edit Template Group', 'event_espresso').'">'
378 378
                           . esc_html__('Edit', 'event_espresso')
379 379
                           . '</a>'
380 380
             );
Please login to merge, or discard this patch.
acceptance_tests/Page/MessagesAdmin.php 1 patch
Indentation   +272 added lines, -272 removed lines patch added patch discarded remove patch
@@ -14,286 +14,286 @@
 block discarded – undo
14 14
 class MessagesAdmin extends CoreAdmin
15 15
 {
16 16
 
17
-    /**
18
-     * Context slug for the admin messages context.
19
-     * @var string
20
-     */
21
-    const ADMIN_CONTEXT_SLUG = 'admin';
17
+	/**
18
+	 * Context slug for the admin messages context.
19
+	 * @var string
20
+	 */
21
+	const ADMIN_CONTEXT_SLUG = 'admin';
22 22
 
23
-    /**
24
-     * Context slug for the primary attendee messages context
25
-     * @var string
26
-     */
27
-    const PRIMARY_ATTENDEE_CONTEXT_SLUG = 'primary_attendee';
23
+	/**
24
+	 * Context slug for the primary attendee messages context
25
+	 * @var string
26
+	 */
27
+	const PRIMARY_ATTENDEE_CONTEXT_SLUG = 'primary_attendee';
28 28
 
29 29
 
30
-    /**
31
-     * Status reference for the EEM_Message::status_sent status.
32
-     * @var string
33
-     */
34
-    const MESSAGE_STATUS_SENT = 'MSN';
30
+	/**
31
+	 * Status reference for the EEM_Message::status_sent status.
32
+	 * @var string
33
+	 */
34
+	const MESSAGE_STATUS_SENT = 'MSN';
35 35
 
36 36
 
37
-    /**
38
-     * Message type slug for the Payment Failed message type
39
-     */
40
-    const PAYMENT_FAILED_MESSAGE_TYPE_SLUG = 'payment_failed';
37
+	/**
38
+	 * Message type slug for the Payment Failed message type
39
+	 */
40
+	const PAYMENT_FAILED_MESSAGE_TYPE_SLUG = 'payment_failed';
41 41
 
42 42
 
43
-    /**
44
-     * Selector for the Global Messages "Send on same request" field in the Messages Settings tab.
45
-     * @var string
46
-     */
47
-    const GLOBAL_MESSAGES_SETTINGS_ON_REQUEST_SELECTION_SELECTOR =
48
-        '#global_messages_settings-do-messages-on-same-request';
43
+	/**
44
+	 * Selector for the Global Messages "Send on same request" field in the Messages Settings tab.
45
+	 * @var string
46
+	 */
47
+	const GLOBAL_MESSAGES_SETTINGS_ON_REQUEST_SELECTION_SELECTOR =
48
+		'#global_messages_settings-do-messages-on-same-request';
49 49
 
50 50
 
51
-    /**
52
-     * Selector for the Global Messages Settings submit button in the Messages Settings tab.
53
-     * @var string
54
-     */
55
-    const GLOBAL_MESSAGES_SETTINGS_SUBMIT_SELECTOR = '#global_messages_settings-update-settings-submit';
56
-
51
+	/**
52
+	 * Selector for the Global Messages Settings submit button in the Messages Settings tab.
53
+	 * @var string
54
+	 */
55
+	const GLOBAL_MESSAGES_SETTINGS_SUBMIT_SELECTOR = '#global_messages_settings-update-settings-submit';
56
+
57 57
 
58
-    /**
59
-     * This is the container where active message types for a messenger are found/dragged to.
60
-     * @var string
61
-     */
62
-    const MESSAGES_SETTINGS_ACTIVE_MESSAGE_TYPES_CONTAINER_SELECTOR = '#active-message-types';
63
-
64
-
65
-    /**
66
-     * Locator for the context switcher selector on the Message Template Editor page.
67
-     * @var string
68
-     */
69
-    const MESSAGES_CONTEXT_SWITCHER_SELECTOR = "//form[@id='ee-msg-context-switcher-frm']/select";
70
-
71
-
72
-    /**
73
-     * Locator for the context switcher submit button in the Message Template Editor page.
74
-     * @var string
75
-     */
76
-    const MESSAGES_CONTEXT_SWITCHER_BUTTON_SELECTOR = "#submit-msg-context-switcher-sbmt";
77
-
78
-
79
-    /**
80
-     * Locator for the dialog container used for housing viewed messages in the message activity list table.
81
-     * @var string
82
-     */
83
-    const MESSAGES_LIST_TABLE_VIEW_MESSAGE_DIALOG_CONTAINER_SELECTOR = '.ee-admin-dialog-container-inner-content';
84
-
85
-
86
-    /**
87
-     * Returns the selector for the on/off toggle for context on the message template editor.
88
-     */
89
-    const MESSAGES_CONTEXT_ACTIVE_STATE_TOGGLE =
90
-        "//div[@class='activate_context_on_off_toggle_container']/div[@class='switch']/label";
91
-
92
-
93
-
94
-    /**
95
-     * @param string $additional_params Any additional request parameters for the generated url should be included as
96
-     *                                  a string.
97
-     * @return string
98
-     */
99
-    public static function messageActivityListTableUrl($additional_params = '')
100
-    {
101
-        return self::adminUrl('espresso_messages', 'default', $additional_params);
102
-    }
103
-
104
-
105
-    /**
106
-     * @param string $additional_params Any additional request parameters for the generated url should be included as
107
-     *                                  a string.
108
-     * @return string
109
-     */
110
-    public static function defaultMessageTemplateListTableUrl($additional_params = '')
111
-    {
112
-        return self::adminUrl('espresso_messages', 'global_mtps', $additional_params);
113
-    }
114
-
115
-
116
-    /**
117
-     * @param string $additional_params Any additional request parameters for the generated url should be included as
118
-     *                                  a string.
119
-     * @return string
120
-     */
121
-    public static function customMessageTemplateListTableUrl($additional_params = '')
122
-    {
123
-        return self::adminUrl('espresso_messages', 'custom_mtps', $additional_params);
124
-    }
125
-
126
-
127
-    /**
128
-     * @return string
129
-     */
130
-    public static function messageSettingsUrl()
131
-    {
132
-        return self::adminUrl('espresso_messages', 'settings');
133
-    }
134
-
135
-
136
-
137
-    public static function draggableSettingsBoxSelectorForMessageTypeAndMessenger(
138
-        $message_type_slug,
139
-        $messenger_slug = 'email'
140
-    ) {
141
-        return "#$message_type_slug-messagetype-$messenger_slug";
142
-    }
143
-
144
-
145
-    /**
146
-     * @param string $message_type_slug
147
-     * @param string $context
148
-     * @return string
149
-     */
150
-    public static function editMessageTemplateClassByMessageType($message_type_slug, $context = '')
151
-    {
152
-        return $context
153
-            ? '.' . $message_type_slug . '-' . $context . '-edit-link'
154
-            : '.' . $message_type_slug . '-edit-link';
155
-    }
156
-
157
-
158
-    /**
159
-     * Selector for (a) specific table cell(s) in the Messages Activity list table for the given parameters.
160
-     *
161
-     * @param        $field
162
-     * @param        $message_type_label
163
-     * @param string $message_status
164
-     * @param string $messenger
165
-     * @param string $context
166
-     * @param string $table_cell_content_for_field
167
-     * @param int    $number_in_set   It's possible that the given parameters could match multiple items in the view.
168
-     *                                This allows you to indicate which item from the set to match.  If this is set to 0
169
-     *                                then all matches for the locator will be returned.
170
-     * @return string
171
-     * @throws \InvalidArgumentException
172
-     */
173
-    public static function messagesActivityListTableCellSelectorFor(
174
-        $field,
175
-        $message_type_label,
176
-        $message_status = self::MESSAGE_STATUS_SENT,
177
-        $messenger = 'Email',
178
-        $context = 'Event Admin',
179
-        $table_cell_content_for_field = '',
180
-        $number_in_set = 1
181
-    ) {
182
-        $selector = "//tbody[@id='the-list']";
183
-        $selector .= "//tr[contains(@class, 'msg-status-$message_status')]"
184
-                     . "//td[contains(@class, 'message_type') and text()='$message_type_label']";
185
-        if ($messenger) {
186
-            $selector .= "/ancestor::tr/td[contains(@class, 'messenger') and text()='$messenger']";
187
-        }
188
-        $selector .= "/ancestor::tr/td[contains(@class, 'column-context') and text()='$context']";
189
-        $selector .= $table_cell_content_for_field
190
-            ? "/ancestor::tr/td[contains(@class, 'column-$field') and text()='$table_cell_content_for_field']"
191
-            : "/ancestor::tr/td[contains(@class, 'column-$field')]";
192
-        return $number_in_set > 0 ? Locator::elementAt($selector, $number_in_set) : $selector;
193
-    }
194
-
195
-
196
-    /**
197
-     * Selector for the Create Custom button found in the message template list table.
198
-     * @param string $message_type_label
199
-     * @param string $messenger_label
200
-     * @return string
201
-     */
202
-    public static function createCustomButtonForMessageTypeAndMessenger($message_type_label, $messenger_label)
203
-    {
204
-        $selector = "//tr/td[contains(@class, 'message_type') and text()='$message_type_label']"
205
-                    . "//ancestor::tr/td[contains(@class, 'messenger') and contains(., '$messenger_label')]"
206
-                    . "//ancestor::tr/td/a[@class='button button-small']";
207
-        return $selector;
208
-    }
209
-
210
-
211
-    /**
212
-     * Note, this could potentially match multiple buttons in the view so the selector is intentionally restricted to
213
-     * the FIRST match (which will be the latest message sent if the table is default sorted).
214
-     *
215
-     * @param string $message_type_label    The visible message type label for the row you want to match
216
-     * @param string $message_status        The status of the message for the row you want to match.
217
-     * @param string $messenger             The visible messenger label for the row you want to match.
218
-     * @param string $context               The visible context label for the row you want to match.
219
-     * @param int    $number_in_set         It's possible that the given parameters could match multiple items in the
220
-     *                                      view. This allows you to indicate which item from the set to match.
221
-     * @return string
222
-     * @throws \InvalidArgumentException
223
-     */
224
-    public static function messagesActivityListTableViewButtonSelectorFor(
225
-        $message_type_label,
226
-        $message_status = self::MESSAGE_STATUS_SENT,
227
-        $messenger = 'Email',
228
-        $context = 'Event Admin',
229
-        $number_in_set = 1
230
-    ) {
231
-        $selector = self::messagesActivityListTableCellSelectorFor(
232
-            'action',
233
-            $message_type_label,
234
-            $message_status,
235
-            $messenger,
236
-            $context,
237
-            '',
238
-            $number_in_set
239
-        );
240
-        $selector .= "/a/span[contains(@class, 'ee-message-action-link-view')"
241
-                     . " and not(contains(@class, 'ee-message-action-link-view_transaction'))]";
242
-        return $selector;
243
-    }
244
-
245
-
246
-    /**
247
-     * Locator for the delete action link for a message item in the message activity list table.
248
-     * Note: The link is not visible by default, so the column would need hovered over for the link to appear.
249
-     *
250
-     * @param        $message_type_label
251
-     * @param string $message_status
252
-     * @param string $messenger
253
-     * @param string $context
254
-     * @param int    $number_in_set
255
-     * @return string
256
-     * @throws \InvalidArgumentException
257
-     */
258
-    public static function messagesActivityListTableDeleteActionSelectorFor(
259
-        $message_type_label,
260
-        $message_status = self::MESSAGE_STATUS_SENT,
261
-        $messenger = 'Email',
262
-        $context = 'Event Admin',
263
-        $number_in_set = 1
264
-    ) {
265
-        $selector = self::messagesActivityListTableCellSelectorFor(
266
-            'to',
267
-            $message_type_label,
268
-            $message_status,
269
-            $messenger,
270
-            $context,
271
-            '',
272
-            $number_in_set
273
-        );
274
-        $selector .= "/div/span[@class='delete']/a";
275
-        return $selector;
276
-    }
277
-
278
-
279
-
280
-    /**
281
-     * Returns the input selector for a given field in the message template editor.
282
-     * Assumes one is already viewing the Message Template Editor.
283
-     * @param string     $field
284
-     * @return string
285
-     */
286
-    public static function messageInputFieldSelectorFor($field)
287
-    {
288
-        return "//div[@id='post-body']//input[@id='$field-content']";
289
-    }
290
-
291
-
292
-    /**
293
-     * Wrapper for self::messageInputFieldSelectorFor('to') that takes care of getting the input for the To field.
294
-     */
295
-    public static function messageTemplateToFieldSelector()
296
-    {
297
-        return self::messageInputFieldSelectorFor('to');
298
-    }
58
+	/**
59
+	 * This is the container where active message types for a messenger are found/dragged to.
60
+	 * @var string
61
+	 */
62
+	const MESSAGES_SETTINGS_ACTIVE_MESSAGE_TYPES_CONTAINER_SELECTOR = '#active-message-types';
63
+
64
+
65
+	/**
66
+	 * Locator for the context switcher selector on the Message Template Editor page.
67
+	 * @var string
68
+	 */
69
+	const MESSAGES_CONTEXT_SWITCHER_SELECTOR = "//form[@id='ee-msg-context-switcher-frm']/select";
70
+
71
+
72
+	/**
73
+	 * Locator for the context switcher submit button in the Message Template Editor page.
74
+	 * @var string
75
+	 */
76
+	const MESSAGES_CONTEXT_SWITCHER_BUTTON_SELECTOR = "#submit-msg-context-switcher-sbmt";
77
+
78
+
79
+	/**
80
+	 * Locator for the dialog container used for housing viewed messages in the message activity list table.
81
+	 * @var string
82
+	 */
83
+	const MESSAGES_LIST_TABLE_VIEW_MESSAGE_DIALOG_CONTAINER_SELECTOR = '.ee-admin-dialog-container-inner-content';
84
+
85
+
86
+	/**
87
+	 * Returns the selector for the on/off toggle for context on the message template editor.
88
+	 */
89
+	const MESSAGES_CONTEXT_ACTIVE_STATE_TOGGLE =
90
+		"//div[@class='activate_context_on_off_toggle_container']/div[@class='switch']/label";
91
+
92
+
93
+
94
+	/**
95
+	 * @param string $additional_params Any additional request parameters for the generated url should be included as
96
+	 *                                  a string.
97
+	 * @return string
98
+	 */
99
+	public static function messageActivityListTableUrl($additional_params = '')
100
+	{
101
+		return self::adminUrl('espresso_messages', 'default', $additional_params);
102
+	}
103
+
104
+
105
+	/**
106
+	 * @param string $additional_params Any additional request parameters for the generated url should be included as
107
+	 *                                  a string.
108
+	 * @return string
109
+	 */
110
+	public static function defaultMessageTemplateListTableUrl($additional_params = '')
111
+	{
112
+		return self::adminUrl('espresso_messages', 'global_mtps', $additional_params);
113
+	}
114
+
115
+
116
+	/**
117
+	 * @param string $additional_params Any additional request parameters for the generated url should be included as
118
+	 *                                  a string.
119
+	 * @return string
120
+	 */
121
+	public static function customMessageTemplateListTableUrl($additional_params = '')
122
+	{
123
+		return self::adminUrl('espresso_messages', 'custom_mtps', $additional_params);
124
+	}
125
+
126
+
127
+	/**
128
+	 * @return string
129
+	 */
130
+	public static function messageSettingsUrl()
131
+	{
132
+		return self::adminUrl('espresso_messages', 'settings');
133
+	}
134
+
135
+
136
+
137
+	public static function draggableSettingsBoxSelectorForMessageTypeAndMessenger(
138
+		$message_type_slug,
139
+		$messenger_slug = 'email'
140
+	) {
141
+		return "#$message_type_slug-messagetype-$messenger_slug";
142
+	}
143
+
144
+
145
+	/**
146
+	 * @param string $message_type_slug
147
+	 * @param string $context
148
+	 * @return string
149
+	 */
150
+	public static function editMessageTemplateClassByMessageType($message_type_slug, $context = '')
151
+	{
152
+		return $context
153
+			? '.' . $message_type_slug . '-' . $context . '-edit-link'
154
+			: '.' . $message_type_slug . '-edit-link';
155
+	}
156
+
157
+
158
+	/**
159
+	 * Selector for (a) specific table cell(s) in the Messages Activity list table for the given parameters.
160
+	 *
161
+	 * @param        $field
162
+	 * @param        $message_type_label
163
+	 * @param string $message_status
164
+	 * @param string $messenger
165
+	 * @param string $context
166
+	 * @param string $table_cell_content_for_field
167
+	 * @param int    $number_in_set   It's possible that the given parameters could match multiple items in the view.
168
+	 *                                This allows you to indicate which item from the set to match.  If this is set to 0
169
+	 *                                then all matches for the locator will be returned.
170
+	 * @return string
171
+	 * @throws \InvalidArgumentException
172
+	 */
173
+	public static function messagesActivityListTableCellSelectorFor(
174
+		$field,
175
+		$message_type_label,
176
+		$message_status = self::MESSAGE_STATUS_SENT,
177
+		$messenger = 'Email',
178
+		$context = 'Event Admin',
179
+		$table_cell_content_for_field = '',
180
+		$number_in_set = 1
181
+	) {
182
+		$selector = "//tbody[@id='the-list']";
183
+		$selector .= "//tr[contains(@class, 'msg-status-$message_status')]"
184
+					 . "//td[contains(@class, 'message_type') and text()='$message_type_label']";
185
+		if ($messenger) {
186
+			$selector .= "/ancestor::tr/td[contains(@class, 'messenger') and text()='$messenger']";
187
+		}
188
+		$selector .= "/ancestor::tr/td[contains(@class, 'column-context') and text()='$context']";
189
+		$selector .= $table_cell_content_for_field
190
+			? "/ancestor::tr/td[contains(@class, 'column-$field') and text()='$table_cell_content_for_field']"
191
+			: "/ancestor::tr/td[contains(@class, 'column-$field')]";
192
+		return $number_in_set > 0 ? Locator::elementAt($selector, $number_in_set) : $selector;
193
+	}
194
+
195
+
196
+	/**
197
+	 * Selector for the Create Custom button found in the message template list table.
198
+	 * @param string $message_type_label
199
+	 * @param string $messenger_label
200
+	 * @return string
201
+	 */
202
+	public static function createCustomButtonForMessageTypeAndMessenger($message_type_label, $messenger_label)
203
+	{
204
+		$selector = "//tr/td[contains(@class, 'message_type') and text()='$message_type_label']"
205
+					. "//ancestor::tr/td[contains(@class, 'messenger') and contains(., '$messenger_label')]"
206
+					. "//ancestor::tr/td/a[@class='button button-small']";
207
+		return $selector;
208
+	}
209
+
210
+
211
+	/**
212
+	 * Note, this could potentially match multiple buttons in the view so the selector is intentionally restricted to
213
+	 * the FIRST match (which will be the latest message sent if the table is default sorted).
214
+	 *
215
+	 * @param string $message_type_label    The visible message type label for the row you want to match
216
+	 * @param string $message_status        The status of the message for the row you want to match.
217
+	 * @param string $messenger             The visible messenger label for the row you want to match.
218
+	 * @param string $context               The visible context label for the row you want to match.
219
+	 * @param int    $number_in_set         It's possible that the given parameters could match multiple items in the
220
+	 *                                      view. This allows you to indicate which item from the set to match.
221
+	 * @return string
222
+	 * @throws \InvalidArgumentException
223
+	 */
224
+	public static function messagesActivityListTableViewButtonSelectorFor(
225
+		$message_type_label,
226
+		$message_status = self::MESSAGE_STATUS_SENT,
227
+		$messenger = 'Email',
228
+		$context = 'Event Admin',
229
+		$number_in_set = 1
230
+	) {
231
+		$selector = self::messagesActivityListTableCellSelectorFor(
232
+			'action',
233
+			$message_type_label,
234
+			$message_status,
235
+			$messenger,
236
+			$context,
237
+			'',
238
+			$number_in_set
239
+		);
240
+		$selector .= "/a/span[contains(@class, 'ee-message-action-link-view')"
241
+					 . " and not(contains(@class, 'ee-message-action-link-view_transaction'))]";
242
+		return $selector;
243
+	}
244
+
245
+
246
+	/**
247
+	 * Locator for the delete action link for a message item in the message activity list table.
248
+	 * Note: The link is not visible by default, so the column would need hovered over for the link to appear.
249
+	 *
250
+	 * @param        $message_type_label
251
+	 * @param string $message_status
252
+	 * @param string $messenger
253
+	 * @param string $context
254
+	 * @param int    $number_in_set
255
+	 * @return string
256
+	 * @throws \InvalidArgumentException
257
+	 */
258
+	public static function messagesActivityListTableDeleteActionSelectorFor(
259
+		$message_type_label,
260
+		$message_status = self::MESSAGE_STATUS_SENT,
261
+		$messenger = 'Email',
262
+		$context = 'Event Admin',
263
+		$number_in_set = 1
264
+	) {
265
+		$selector = self::messagesActivityListTableCellSelectorFor(
266
+			'to',
267
+			$message_type_label,
268
+			$message_status,
269
+			$messenger,
270
+			$context,
271
+			'',
272
+			$number_in_set
273
+		);
274
+		$selector .= "/div/span[@class='delete']/a";
275
+		return $selector;
276
+	}
277
+
278
+
279
+
280
+	/**
281
+	 * Returns the input selector for a given field in the message template editor.
282
+	 * Assumes one is already viewing the Message Template Editor.
283
+	 * @param string     $field
284
+	 * @return string
285
+	 */
286
+	public static function messageInputFieldSelectorFor($field)
287
+	{
288
+		return "//div[@id='post-body']//input[@id='$field-content']";
289
+	}
290
+
291
+
292
+	/**
293
+	 * Wrapper for self::messageInputFieldSelectorFor('to') that takes care of getting the input for the To field.
294
+	 */
295
+	public static function messageTemplateToFieldSelector()
296
+	{
297
+		return self::messageInputFieldSelectorFor('to');
298
+	}
299 299
 }
300 300
\ No newline at end of file
Please login to merge, or discard this patch.
acceptance_tests/Helpers/MessagesAdmin.php 1 patch
Indentation   +243 added lines, -243 removed lines patch added patch discarded remove patch
@@ -10,276 +10,276 @@
 block discarded – undo
10 10
  */
11 11
 trait MessagesAdmin
12 12
 {
13
-    /**
14
-     * @param string $additional_params Any additional request parameters for the generated url should be included as
15
-     *                                  a string.
16
-     */
17
-    public function amOnMessagesActivityListTablePage($additional_params = '')
18
-    {
19
-        $this->actor()->amOnAdminPage(MessagesPage::messageActivityListTableUrl($additional_params));
20
-    }
13
+	/**
14
+	 * @param string $additional_params Any additional request parameters for the generated url should be included as
15
+	 *                                  a string.
16
+	 */
17
+	public function amOnMessagesActivityListTablePage($additional_params = '')
18
+	{
19
+		$this->actor()->amOnAdminPage(MessagesPage::messageActivityListTableUrl($additional_params));
20
+	}
21 21
 
22
-    /**
23
-     * @param string $additional_params Any additional request parameters for the generated url should be included as
24
-     *                                  a string.
25
-     */
26
-    public function amOnDefaultMessageTemplateListTablePage($additional_params = '')
27
-    {
28
-        $this->actor()->amOnAdminPage(MessagesPage::defaultMessageTemplateListTableUrl($additional_params));
29
-    }
22
+	/**
23
+	 * @param string $additional_params Any additional request parameters for the generated url should be included as
24
+	 *                                  a string.
25
+	 */
26
+	public function amOnDefaultMessageTemplateListTablePage($additional_params = '')
27
+	{
28
+		$this->actor()->amOnAdminPage(MessagesPage::defaultMessageTemplateListTableUrl($additional_params));
29
+	}
30 30
 
31 31
 
32
-    /**
33
-     * @param string $additional_params Any additional request parameters for the generated url should be included as
34
-     *                                  a string.
35
-     */
36
-    public function amOnCustomMessageTemplateListTablePage($additional_params = '')
37
-    {
38
-        $this->actor()->amOnAdminPage(MessagesPage::customMessageTemplateListTableUrl($additional_params));
39
-    }
32
+	/**
33
+	 * @param string $additional_params Any additional request parameters for the generated url should be included as
34
+	 *                                  a string.
35
+	 */
36
+	public function amOnCustomMessageTemplateListTablePage($additional_params = '')
37
+	{
38
+		$this->actor()->amOnAdminPage(MessagesPage::customMessageTemplateListTableUrl($additional_params));
39
+	}
40 40
 
41 41
 
42
-    /**
43
-     * Directs to message settings page
44
-     */
45
-    public function amOnMessageSettingsPage()
46
-    {
47
-        $this->actor()->amOnAdminPage(MessagesPage::messageSettingsUrl());
48
-    }
42
+	/**
43
+	 * Directs to message settings page
44
+	 */
45
+	public function amOnMessageSettingsPage()
46
+	{
47
+		$this->actor()->amOnAdminPage(MessagesPage::messageSettingsUrl());
48
+	}
49 49
 
50 50
 
51
-    public function activateMessageTypeForMessenger($message_type_slug, $messenger_slug = 'email')
52
-    {
53
-        $this->actor()->dragAndDrop(
54
-            MessagesPage::draggableSettingsBoxSelectorForMessageTypeAndMessenger($message_type_slug, $messenger_slug),
55
-            MessagesPage::MESSAGES_SETTINGS_ACTIVE_MESSAGE_TYPES_CONTAINER_SELECTOR
56
-        );
57
-    }
51
+	public function activateMessageTypeForMessenger($message_type_slug, $messenger_slug = 'email')
52
+	{
53
+		$this->actor()->dragAndDrop(
54
+			MessagesPage::draggableSettingsBoxSelectorForMessageTypeAndMessenger($message_type_slug, $messenger_slug),
55
+			MessagesPage::MESSAGES_SETTINGS_ACTIVE_MESSAGE_TYPES_CONTAINER_SELECTOR
56
+		);
57
+	}
58 58
 
59 59
 
60
-    /**
61
-     * Assumes you are already on the list table page that has the ui for editing the template.
62
-     * @param string $message_type_slug
63
-     * @param string $context [optional] if you want to click directly to the given context in the editor
64
-     */
65
-    public function clickToEditMessageTemplateByMessageType($message_type_slug, $context = '')
66
-    {
67
-        $this->actor()->click(MessagesPage::editMessageTemplateClassByMessageType($message_type_slug, $context));
68
-    }
60
+	/**
61
+	 * Assumes you are already on the list table page that has the ui for editing the template.
62
+	 * @param string $message_type_slug
63
+	 * @param string $context [optional] if you want to click directly to the given context in the editor
64
+	 */
65
+	public function clickToEditMessageTemplateByMessageType($message_type_slug, $context = '')
66
+	{
67
+		$this->actor()->click(MessagesPage::editMessageTemplateClassByMessageType($message_type_slug, $context));
68
+	}
69 69
 
70 70
 
71
-    /**
72
-     * Use this action to verify that the count for the given text in the specified field is as expected.  For example
73
-     * filling the condition of, "There should only be 1 instance of `[email protected]` in all the 'to' column.
74
-     *
75
-     * @param int    $expected_occurence_count
76
-     * @param string $text_to_check_for
77
-     * @param string $field
78
-     * @param string $message_type_label
79
-     * @param string $message_status
80
-     * @param string $messenger
81
-     * @param string $context
82
-     */
83
-    public function verifyMatchingCountofTextInMessageActivityListTableFor(
84
-        $expected_occurence_count,
85
-        $text_to_check_for,
86
-        $field,
87
-        $message_type_label,
88
-        $message_status = MessagesPage::MESSAGE_STATUS_SENT,
89
-        $messenger = 'Email',
90
-        $context = 'Event Admin'
91
-    ) {
92
-        $elements = $this->actor()->grabMultiple(MessagesPage::messagesActivityListTableCellSelectorFor(
93
-            $field,
94
-            $message_type_label,
95
-            $message_status,
96
-            $messenger,
97
-            $context,
98
-            $text_to_check_for,
99
-            0
100
-        ));
101
-        $actual_count = count($elements);
102
-        $this->actor()->assertEquals(
103
-            $expected_occurence_count,
104
-            $actual_count,
105
-            sprintf(
106
-                'Expected %s of the %s text for the %s field but there were actually %s counted.',
107
-                $expected_occurence_count,
108
-                $text_to_check_for,
109
-                $field,
110
-                $actual_count
111
-            )
112
-        );
113
-    }
71
+	/**
72
+	 * Use this action to verify that the count for the given text in the specified field is as expected.  For example
73
+	 * filling the condition of, "There should only be 1 instance of `[email protected]` in all the 'to' column.
74
+	 *
75
+	 * @param int    $expected_occurence_count
76
+	 * @param string $text_to_check_for
77
+	 * @param string $field
78
+	 * @param string $message_type_label
79
+	 * @param string $message_status
80
+	 * @param string $messenger
81
+	 * @param string $context
82
+	 */
83
+	public function verifyMatchingCountofTextInMessageActivityListTableFor(
84
+		$expected_occurence_count,
85
+		$text_to_check_for,
86
+		$field,
87
+		$message_type_label,
88
+		$message_status = MessagesPage::MESSAGE_STATUS_SENT,
89
+		$messenger = 'Email',
90
+		$context = 'Event Admin'
91
+	) {
92
+		$elements = $this->actor()->grabMultiple(MessagesPage::messagesActivityListTableCellSelectorFor(
93
+			$field,
94
+			$message_type_label,
95
+			$message_status,
96
+			$messenger,
97
+			$context,
98
+			$text_to_check_for,
99
+			0
100
+		));
101
+		$actual_count = count($elements);
102
+		$this->actor()->assertEquals(
103
+			$expected_occurence_count,
104
+			$actual_count,
105
+			sprintf(
106
+				'Expected %s of the %s text for the %s field but there were actually %s counted.',
107
+				$expected_occurence_count,
108
+				$text_to_check_for,
109
+				$field,
110
+				$actual_count
111
+			)
112
+		);
113
+	}
114 114
 
115 115
 
116
-    /**
117
-     * This will create a custom message template for the given messenger and message type from the context of the
118
-     * default (global) message template list table.
119
-     * Also takes care of verifying the template was created.
120
-     * @param string $message_type_label
121
-     * @param string $messenger_label
122
-     */
123
-    public function createCustomMessageTemplateFromDefaultFor($message_type_label, $messenger_label)
124
-    {
125
-        $this->amOnDefaultMessageTemplateListTablePage();
126
-        $this->actor()->click(
127
-            MessagesPage::createCustomButtonForMessageTypeAndMessenger(
128
-                $message_type_label,
129
-                $messenger_label
130
-            )
131
-        );
132
-        $this->actor()->seeInField('#title', 'New Custom Template');
133
-    }
116
+	/**
117
+	 * This will create a custom message template for the given messenger and message type from the context of the
118
+	 * default (global) message template list table.
119
+	 * Also takes care of verifying the template was created.
120
+	 * @param string $message_type_label
121
+	 * @param string $messenger_label
122
+	 */
123
+	public function createCustomMessageTemplateFromDefaultFor($message_type_label, $messenger_label)
124
+	{
125
+		$this->amOnDefaultMessageTemplateListTablePage();
126
+		$this->actor()->click(
127
+			MessagesPage::createCustomButtonForMessageTypeAndMessenger(
128
+				$message_type_label,
129
+				$messenger_label
130
+			)
131
+		);
132
+		$this->actor()->seeInField('#title', 'New Custom Template');
133
+	}
134 134
 
135 135
 
136
-    /**
137
-     * This switches the context of the current messages template to the given reference.
138
-     * @param string $context_reference  This should be the visible label for the option.
139
-     */
140
-    public function switchContextTo($context_reference)
141
-    {
142
-        $this->actor()->selectOption(MessagesPage::MESSAGES_CONTEXT_SWITCHER_SELECTOR, $context_reference);
143
-        $this->actor()->click(MessagesPage::MESSAGES_CONTEXT_SWITCHER_BUTTON_SELECTOR);
144
-        $this->actor()->waitForText($context_reference, 10, 'h1');
145
-    }
136
+	/**
137
+	 * This switches the context of the current messages template to the given reference.
138
+	 * @param string $context_reference  This should be the visible label for the option.
139
+	 */
140
+	public function switchContextTo($context_reference)
141
+	{
142
+		$this->actor()->selectOption(MessagesPage::MESSAGES_CONTEXT_SWITCHER_SELECTOR, $context_reference);
143
+		$this->actor()->click(MessagesPage::MESSAGES_CONTEXT_SWITCHER_BUTTON_SELECTOR);
144
+		$this->actor()->waitForText($context_reference, 10, 'h1');
145
+	}
146 146
 
147 147
 
148
-    /**
149
-     * Toggles Context so its turned off or on (depending on where it started) and verifies the expected state after
150
-     * toggling.
151
-     *
152
-     * @param string $context_string           What context is being switched (used for the expected state text)
153
-     * @param bool   $expected_state_is_active Used to indicate whether the expected state is active (true) or inactive
154
-     *                                         (false)
155
-     */
156
-    public function toggleContextState($context_string, $expected_state_is_active = true)
157
-    {
158
-        $this->actor()->click(MessagesPage::MESSAGES_CONTEXT_ACTIVE_STATE_TOGGLE);
159
-        if ($expected_state_is_active) {
160
-            $this->actor()->waitForText("The template for $context_string is currently active.");
161
-        } else {
162
-            $this->actor()->waitForText("The template for $context_string is currently inactive");
163
-        }
164
-    }
148
+	/**
149
+	 * Toggles Context so its turned off or on (depending on where it started) and verifies the expected state after
150
+	 * toggling.
151
+	 *
152
+	 * @param string $context_string           What context is being switched (used for the expected state text)
153
+	 * @param bool   $expected_state_is_active Used to indicate whether the expected state is active (true) or inactive
154
+	 *                                         (false)
155
+	 */
156
+	public function toggleContextState($context_string, $expected_state_is_active = true)
157
+	{
158
+		$this->actor()->click(MessagesPage::MESSAGES_CONTEXT_ACTIVE_STATE_TOGGLE);
159
+		if ($expected_state_is_active) {
160
+			$this->actor()->waitForText("The template for $context_string is currently active.");
161
+		} else {
162
+			$this->actor()->waitForText("The template for $context_string is currently inactive");
163
+		}
164
+	}
165 165
 
166 166
 
167
-    /**
168
-     * Triggers saving the message template.
169
-     * @param bool $and_close   Use to indicate to click the Save and Close button.
170
-     */
171
-    public function saveMessageTemplate($and_close = false)
172
-    {
173
-        if ($and_close) {
174
-            $this->actor()->click('Save and Close');
175
-        } else {
176
-            $this->actor()->click('Save');
177
-        }
178
-        $this->actor()->waitForText('successfully updated');
179
-    }
167
+	/**
168
+	 * Triggers saving the message template.
169
+	 * @param bool $and_close   Use to indicate to click the Save and Close button.
170
+	 */
171
+	public function saveMessageTemplate($and_close = false)
172
+	{
173
+		if ($and_close) {
174
+			$this->actor()->click('Save and Close');
175
+		} else {
176
+			$this->actor()->click('Save');
177
+		}
178
+		$this->actor()->waitForText('successfully updated');
179
+	}
180 180
 
181 181
 
182
-    /**
183
-     * This takes care of clicking the View Message icon for the given parameters.
184
-     * Assumes you are already viewing the messages activity list table.
185
-     * @param        $message_type_label
186
-     * @param        $message_status
187
-     * @param string $messenger
188
-     * @param string $context
189
-     * @param int    $number_in_set
190
-     */
191
-    public function viewMessageInMessagesListTableFor(
192
-        $message_type_label,
193
-        $message_status = MessagesPage::MESSAGE_STATUS_SENT,
194
-        $messenger = 'Email',
195
-        $context = 'Event Admin',
196
-        $number_in_set = 1
197
-    ) {
198
-        $this->actor()->click(MessagesPage::messagesActivityListTableViewButtonSelectorFor(
199
-            $message_type_label,
200
-            $message_status,
201
-            $messenger,
202
-            $context,
203
-            $number_in_set
204
-        ));
205
-    }
182
+	/**
183
+	 * This takes care of clicking the View Message icon for the given parameters.
184
+	 * Assumes you are already viewing the messages activity list table.
185
+	 * @param        $message_type_label
186
+	 * @param        $message_status
187
+	 * @param string $messenger
188
+	 * @param string $context
189
+	 * @param int    $number_in_set
190
+	 */
191
+	public function viewMessageInMessagesListTableFor(
192
+		$message_type_label,
193
+		$message_status = MessagesPage::MESSAGE_STATUS_SENT,
194
+		$messenger = 'Email',
195
+		$context = 'Event Admin',
196
+		$number_in_set = 1
197
+	) {
198
+		$this->actor()->click(MessagesPage::messagesActivityListTableViewButtonSelectorFor(
199
+			$message_type_label,
200
+			$message_status,
201
+			$messenger,
202
+			$context,
203
+			$number_in_set
204
+		));
205
+	}
206 206
 
207 207
 
208
-    /**
209
-     * Takes care of deleting a message matching the given parameters via the message activity list table.
210
-     * Assumes you are already viewing the messages activity list table.
211
-     * @param        $message_type_label
212
-     * @param        $message_status
213
-     * @param string $messenger
214
-     * @param string $context
215
-     * @param int    $number_in_set
216
-     */
217
-    public function deleteMessageInMessagesListTableFor(
218
-        $message_type_label,
219
-        $message_status = MessagesPage::MESSAGE_STATUS_SENT,
220
-        $messenger = 'Email',
221
-        $context = 'Event Admin',
222
-        $number_in_set = 1
223
-    ) {
224
-        $delete_action_selector = MessagesPage::messagesActivityListTableDeleteActionSelectorFor(
225
-            $message_type_label,
226
-            $message_status,
227
-            $messenger,
228
-            $context,
229
-            $number_in_set
230
-        );
231
-        $this->actor()->moveMouseOver(
232
-            MessagesPage::messagesActivityListTableCellSelectorFor(
233
-                'to',
234
-                $message_type_label,
235
-                $message_status,
236
-                $messenger,
237
-                $context,
238
-                '',
239
-                $number_in_set
240
-            ),
241
-            5,
242
-            5
243
-        );
244
-        $this->actor()->waitForElementVisible(
245
-            $delete_action_selector
246
-        );
247
-        $this->actor()->click(
248
-            $delete_action_selector
249
-        );
250
-        $this->actor()->waitForText('successfully deleted');
251
-    }
208
+	/**
209
+	 * Takes care of deleting a message matching the given parameters via the message activity list table.
210
+	 * Assumes you are already viewing the messages activity list table.
211
+	 * @param        $message_type_label
212
+	 * @param        $message_status
213
+	 * @param string $messenger
214
+	 * @param string $context
215
+	 * @param int    $number_in_set
216
+	 */
217
+	public function deleteMessageInMessagesListTableFor(
218
+		$message_type_label,
219
+		$message_status = MessagesPage::MESSAGE_STATUS_SENT,
220
+		$messenger = 'Email',
221
+		$context = 'Event Admin',
222
+		$number_in_set = 1
223
+	) {
224
+		$delete_action_selector = MessagesPage::messagesActivityListTableDeleteActionSelectorFor(
225
+			$message_type_label,
226
+			$message_status,
227
+			$messenger,
228
+			$context,
229
+			$number_in_set
230
+		);
231
+		$this->actor()->moveMouseOver(
232
+			MessagesPage::messagesActivityListTableCellSelectorFor(
233
+				'to',
234
+				$message_type_label,
235
+				$message_status,
236
+				$messenger,
237
+				$context,
238
+				'',
239
+				$number_in_set
240
+			),
241
+			5,
242
+			5
243
+		);
244
+		$this->actor()->waitForElementVisible(
245
+			$delete_action_selector
246
+		);
247
+		$this->actor()->click(
248
+			$delete_action_selector
249
+		);
250
+		$this->actor()->waitForText('successfully deleted');
251
+	}
252 252
 
253 253
 
254
-    /**
255
-     * Assuming you have already triggered the view modal for a single message from the context of the message activity
256
-     * list table, this will take care of validating the given text is in that window.
257
-     * @param string $text_to_view
258
-     */
259
-    public function seeTextInViewMessageModal($text_to_view, $should_not_see = false)
260
-    {
261
-        $this->actor()->waitForElementVisible('.ee-admin-dialog-container-inner-content');
262
-        $this->actor()->switchToIframe('message-view-window');
263
-        $should_not_see ? $this->actor()->dontSee($text_to_view) : $this->actor()->see($text_to_view);
264
-        $this->actor()->switchToIframe();
265
-    }
254
+	/**
255
+	 * Assuming you have already triggered the view modal for a single message from the context of the message activity
256
+	 * list table, this will take care of validating the given text is in that window.
257
+	 * @param string $text_to_view
258
+	 */
259
+	public function seeTextInViewMessageModal($text_to_view, $should_not_see = false)
260
+	{
261
+		$this->actor()->waitForElementVisible('.ee-admin-dialog-container-inner-content');
262
+		$this->actor()->switchToIframe('message-view-window');
263
+		$should_not_see ? $this->actor()->dontSee($text_to_view) : $this->actor()->see($text_to_view);
264
+		$this->actor()->switchToIframe();
265
+	}
266 266
 
267 267
 
268
-    /**
269
-     * Assuming you have already triggered the view modal for a single message from the context of the message activity
270
-     * list table, this will take care of validating the given text is NOT that window.
271
-     * @param string $text_to_view
272
-     */
273
-    public function dontSeeTextInViewMessageModal($text_to_view)
274
-    {
275
-        $this->seeTextInViewMessageModal($text_to_view, true);
276
-    }
268
+	/**
269
+	 * Assuming you have already triggered the view modal for a single message from the context of the message activity
270
+	 * list table, this will take care of validating the given text is NOT that window.
271
+	 * @param string $text_to_view
272
+	 */
273
+	public function dontSeeTextInViewMessageModal($text_to_view)
274
+	{
275
+		$this->seeTextInViewMessageModal($text_to_view, true);
276
+	}
277 277
 
278 278
 
279
-    public function dismissMessageModal()
280
-    {
281
-        $this->actor()->click('#espresso-admin-page-overlay-dv');
282
-        //this is needed otherwise phantom js gets stuck in the wrong context and any future element events will fail.
283
-        $this->actor()->click('form#EE_Message_List_Table-table-frm');
284
-    }
279
+	public function dismissMessageModal()
280
+	{
281
+		$this->actor()->click('#espresso-admin-page-overlay-dv');
282
+		//this is needed otherwise phantom js gets stuck in the wrong context and any future element events will fail.
283
+		$this->actor()->click('form#EE_Message_List_Table-table-frm');
284
+	}
285 285
 }
Please login to merge, or discard this patch.
acceptance_tests/tests/e-TestContextActivationToggleCept.php 1 patch
Indentation   +62 added lines, -62 removed lines patch added patch discarded remove patch
@@ -8,8 +8,8 @@  discard block
 block discarded – undo
8 8
 $event_label = 'Testing Context Deactivation';
9 9
 
10 10
 $I->wantTo(
11
-    'Test that the context activation toggle for turning on or off specific contexts for message sending works as'
12
-    . ' expected'
11
+	'Test that the context activation toggle for turning on or off specific contexts for message sending works as'
12
+	. ' expected'
13 13
 );
14 14
 
15 15
 $I->loginAsAdmin();
@@ -34,7 +34,7 @@  discard block
 block discarded – undo
34 34
 $I->see('The template for Primary Registrant Recipient is currently inactive.');
35 35
 
36 36
 $I->amGoingTo(
37
-    'Trigger Registration Approved Messages and verify primary registrant context is excluded from sent messages.'
37
+	'Trigger Registration Approved Messages and verify primary registrant context is excluded from sent messages.'
38 38
 );
39 39
 $I->amOnDefaultEventsListTablePage();
40 40
 $I->click(EventsAdmin::ADD_NEW_EVENT_BUTTON_SELECTOR);
@@ -44,9 +44,9 @@  discard block
 block discarded – undo
44 44
 $event_link = $I->observeLinkUrlAt(EventsAdmin::EVENT_EDITOR_VIEW_LINK_AFTER_PUBLISH_SELECTOR);
45 45
 $event_id = $I->observeValueFromInputAt(EventsAdmin::EVENT_EDITOR_EVT_ID_SELECTOR);
46 46
 $test_registration_details = array(
47
-    'fname' => 'ContextTestGuy',
48
-    'lname' => 'ContextTestDude',
49
-    'email' => '[email protected]',
47
+	'fname' => 'ContextTestGuy',
48
+	'lname' => 'ContextTestDude',
49
+	'email' => '[email protected]',
50 50
 );
51 51
 $I->logOut();
52 52
 $I->amOnUrl($event_link);
@@ -63,48 +63,48 @@  discard block
 block discarded – undo
63 63
 $I->amOnMessagesActivityListTablePage();
64 64
 //verify registrant context
65 65
 $I->see(
66
-    $test_registration_details['email'],
67
-    MessagesAdmin::messagesActivityListTableCellSelectorFor(
68
-        'to',
69
-        'Registration Approved',
70
-        MessagesAdmin::MESSAGE_STATUS_SENT,
71
-        '',
72
-        'Registrant'
73
-    )
66
+	$test_registration_details['email'],
67
+	MessagesAdmin::messagesActivityListTableCellSelectorFor(
68
+		'to',
69
+		'Registration Approved',
70
+		MessagesAdmin::MESSAGE_STATUS_SENT,
71
+		'',
72
+		'Registrant'
73
+	)
74 74
 );
75 75
 $I->deleteMessageInMessagesListTableFor(
76
-    'Registration Approved',
77
-    MessagesAdmin::MESSAGE_STATUS_SENT,
78
-    'Email',
79
-    'Registrant'
76
+	'Registration Approved',
77
+	MessagesAdmin::MESSAGE_STATUS_SENT,
78
+	'Email',
79
+	'Registrant'
80 80
 );
81 81
 //verify admin context
82 82
 $I->see(
83
-    '[email protected]',
84
-    MessagesAdmin::messagesActivityListTableCellSelectorFor(
85
-        'to',
86
-        'Registration Approved',
87
-        MessagesAdmin::MESSAGE_STATUS_SENT
88
-    )
83
+	'[email protected]',
84
+	MessagesAdmin::messagesActivityListTableCellSelectorFor(
85
+		'to',
86
+		'Registration Approved',
87
+		MessagesAdmin::MESSAGE_STATUS_SENT
88
+	)
89 89
 );
90 90
 $I->deleteMessageInMessagesListTableFor(
91
-    'Registration Approved'
91
+	'Registration Approved'
92 92
 );
93 93
 //verify primary registrant context is NOT present.
94 94
 $I->dontSee(
95
-    $test_registration_details['email'],
96
-    MessagesAdmin::messagesActivityListTableCellSelectorFor(
97
-        'to',
98
-        'Registration Approved',
99
-        MessagesAdmin::MESSAGE_STATUS_SENT,
100
-        '',
101
-        'Primary Registrant'
102
-    )
95
+	$test_registration_details['email'],
96
+	MessagesAdmin::messagesActivityListTableCellSelectorFor(
97
+		'to',
98
+		'Registration Approved',
99
+		MessagesAdmin::MESSAGE_STATUS_SENT,
100
+		'',
101
+		'Primary Registrant'
102
+	)
103 103
 );
104 104
 
105 105
 $I->amGoingTo(
106
-    'Deactivate primary registrant context for Registration Approved Message Templates and restore the "To"'
107
-    . ' field to an empty string to verify the message does not send for that context.'
106
+	'Deactivate primary registrant context for Registration Approved Message Templates and restore the "To"'
107
+	. ' field to an empty string to verify the message does not send for that context.'
108 108
 );
109 109
 $I->amOnDefaultMessageTemplateListTablePage();
110 110
 $I->clickToEditMessageTemplateByMessageType('registration', 'primary_attendee');
@@ -128,41 +128,41 @@  discard block
 block discarded – undo
128 128
 $I->amOnMessagesActivityListTablePage();
129 129
 //verify registrant context
130 130
 $I->see(
131
-    $test_registration_details['email'],
132
-    MessagesAdmin::messagesActivityListTableCellSelectorFor(
133
-        'to',
134
-        'Registration Approved',
135
-        MessagesAdmin::MESSAGE_STATUS_SENT,
136
-        '',
137
-        'Registrant'
138
-    )
131
+	$test_registration_details['email'],
132
+	MessagesAdmin::messagesActivityListTableCellSelectorFor(
133
+		'to',
134
+		'Registration Approved',
135
+		MessagesAdmin::MESSAGE_STATUS_SENT,
136
+		'',
137
+		'Registrant'
138
+	)
139 139
 );
140 140
 $I->deleteMessageInMessagesListTableFor(
141
-    'Registration Approved',
142
-    MessagesAdmin::MESSAGE_STATUS_SENT,
143
-    'Email',
144
-    'Registrant'
141
+	'Registration Approved',
142
+	MessagesAdmin::MESSAGE_STATUS_SENT,
143
+	'Email',
144
+	'Registrant'
145 145
 );
146 146
 //verify admin context
147 147
 $I->see(
148
-    '[email protected]',
149
-    MessagesAdmin::messagesActivityListTableCellSelectorFor(
150
-        'to',
151
-        'Registration Approved',
152
-        MessagesAdmin::MESSAGE_STATUS_SENT
153
-    )
148
+	'[email protected]',
149
+	MessagesAdmin::messagesActivityListTableCellSelectorFor(
150
+		'to',
151
+		'Registration Approved',
152
+		MessagesAdmin::MESSAGE_STATUS_SENT
153
+	)
154 154
 );
155 155
 $I->deleteMessageInMessagesListTableFor(
156
-    'Registration Approved'
156
+	'Registration Approved'
157 157
 );
158 158
 //verify primary registrant context is NOT present.
159 159
 $I->dontSee(
160
-    $test_registration_details['email'],
161
-    MessagesAdmin::messagesActivityListTableCellSelectorFor(
162
-        'to',
163
-        'Registration Approved',
164
-        MessagesAdmin::MESSAGE_STATUS_SENT,
165
-        '',
166
-        'Primary Registrant'
167
-    )
160
+	$test_registration_details['email'],
161
+	MessagesAdmin::messagesActivityListTableCellSelectorFor(
162
+		'to',
163
+		'Registration Approved',
164
+		MessagesAdmin::MESSAGE_STATUS_SENT,
165
+		'',
166
+		'Primary Registrant'
167
+	)
168 168
 );
169 169
\ No newline at end of file
Please login to merge, or discard this patch.
admin_pages/registrations/Registrations_Admin_Page.core.php 1 patch
Indentation   +3532 added lines, -3532 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
 
@@ -23,2218 +23,2218 @@  discard block
 block discarded – undo
23 23
 class Registrations_Admin_Page extends EE_Admin_Page_CPT
24 24
 {
25 25
 
26
-    /**
27
-     * @var EE_Registration
28
-     */
29
-    private $_registration;
30
-
31
-    /**
32
-     * @var EE_Event
33
-     */
34
-    private $_reg_event;
35
-
36
-    /**
37
-     * @var EE_Session
38
-     */
39
-    private $_session;
40
-
41
-    private static $_reg_status;
42
-
43
-    /**
44
-     * Form for displaying the custom questions for this registration.
45
-     * This gets used a few times throughout the request so its best to cache it
46
-     *
47
-     * @var EE_Registration_Custom_Questions_Form
48
-     */
49
-    protected $_reg_custom_questions_form = null;
50
-
51
-
52
-    /**
53
-     *        constructor
54
-     *
55
-     * @Constructor
56
-     * @access public
57
-     * @param bool $routing
58
-     * @return Registrations_Admin_Page
59
-     */
60
-    public function __construct($routing = true)
61
-    {
62
-        parent::__construct($routing);
63
-        add_action('wp_loaded', array($this, 'wp_loaded'));
64
-    }
65
-
66
-
67
-    public function wp_loaded()
68
-    {
69
-        // when adding a new registration...
70
-        if (isset($this->_req_data['action']) && $this->_req_data['action'] === 'new_registration') {
71
-            EE_System::do_not_cache();
72
-            if (! isset($this->_req_data['processing_registration'])
73
-                 || absint($this->_req_data['processing_registration']) !== 1
74
-            ) {
75
-                // and it's NOT the attendee information reg step
76
-                // force cookie expiration by setting time to last week
77
-                setcookie('ee_registration_added', 0, time() - WEEK_IN_SECONDS, '/');
78
-                // and update the global
79
-                $_COOKIE['ee_registration_added'] = 0;
80
-            }
81
-        }
82
-    }
83
-
84
-
85
-    protected function _init_page_props()
86
-    {
87
-        $this->page_slug        = REG_PG_SLUG;
88
-        $this->_admin_base_url  = REG_ADMIN_URL;
89
-        $this->_admin_base_path = REG_ADMIN;
90
-        $this->page_label       = esc_html__('Registrations', 'event_espresso');
91
-        $this->_cpt_routes      = array(
92
-            'add_new_attendee' => 'espresso_attendees',
93
-            'edit_attendee'    => 'espresso_attendees',
94
-            'insert_attendee'  => 'espresso_attendees',
95
-            'update_attendee'  => 'espresso_attendees',
96
-        );
97
-        $this->_cpt_model_names = array(
98
-            'add_new_attendee' => 'EEM_Attendee',
99
-            'edit_attendee'    => 'EEM_Attendee',
100
-        );
101
-        $this->_cpt_edit_routes = array(
102
-            'espresso_attendees' => 'edit_attendee',
103
-        );
104
-        $this->_pagenow_map     = array(
105
-            'add_new_attendee' => 'post-new.php',
106
-            'edit_attendee'    => 'post.php',
107
-            'trash'            => 'post.php',
108
-        );
109
-        add_action('edit_form_after_title', array($this, 'after_title_form_fields'), 10);
110
-        //add filters so that the comment urls don't take users to a confusing 404 page
111
-        add_filter('get_comment_link', array($this, 'clear_comment_link'), 10, 3);
112
-    }
113
-
114
-
115
-    public function clear_comment_link($link, $comment, $args)
116
-    {
117
-        //gotta make sure this only happens on this route
118
-        $post_type = get_post_type($comment->comment_post_ID);
119
-        if ($post_type === 'espresso_attendees') {
120
-            return '#commentsdiv';
121
-        }
122
-        return $link;
123
-    }
124
-
125
-
126
-    protected function _ajax_hooks()
127
-    {
128
-        //todo: all hooks for registrations ajax goes in here
129
-        add_action('wp_ajax_toggle_checkin_status', array($this, 'toggle_checkin_status'));
130
-    }
131
-
132
-
133
-    protected function _define_page_props()
134
-    {
135
-        $this->_admin_page_title = $this->page_label;
136
-        $this->_labels           = array(
137
-            'buttons'                      => array(
138
-                'add-registrant'      => esc_html__('Add New Registration', 'event_espresso'),
139
-                'add-attendee'        => esc_html__('Add Contact', 'event_espresso'),
140
-                'edit'                => esc_html__('Edit Contact', 'event_espresso'),
141
-                'report'              => esc_html__("Event Registrations CSV Report", "event_espresso"),
142
-                'report_all'          => esc_html__('All Registrations CSV Report', 'event_espresso'),
143
-                'report_filtered'     => esc_html__('Filtered CSV Report', 'event_espresso'),
144
-                'contact_list_report' => esc_html__('Contact List Report', 'event_espresso'),
145
-                'contact_list_export' => esc_html__("Export Data", "event_espresso"),
146
-            ),
147
-            'publishbox'                   => array(
148
-                'add_new_attendee' => esc_html__("Add Contact Record", 'event_espresso'),
149
-                'edit_attendee'    => esc_html__("Update Contact Record", 'event_espresso'),
150
-            ),
151
-            'hide_add_button_on_cpt_route' => array(
152
-                'edit_attendee' => true,
153
-            ),
154
-        );
155
-    }
156
-
157
-
158
-    /**
159
-     *        grab url requests and route them
160
-     *
161
-     * @access private
162
-     * @return void
163
-     */
164
-    public function _set_page_routes()
165
-    {
166
-        $this->_get_registration_status_array();
167
-        $reg_id             = ! empty($this->_req_data['_REG_ID']) && ! is_array($this->_req_data['_REG_ID'])
168
-            ? $this->_req_data['_REG_ID'] : 0;
169
-        $reg_id = empty($reg_id) && ! empty($this->_req_data['reg_status_change_form']['REG_ID'])
170
-            ? $this->_req_data['reg_status_change_form']['REG_ID']
171
-            : $reg_id;
172
-        $att_id             = ! empty($this->_req_data['ATT_ID']) && ! is_array($this->_req_data['ATT_ID'])
173
-            ? $this->_req_data['ATT_ID'] : 0;
174
-        $att_id             = ! empty($this->_req_data['post']) && ! is_array($this->_req_data['post'])
175
-            ? $this->_req_data['post']
176
-            : $att_id;
177
-        $this->_page_routes = array(
178
-            'default'                            => array(
179
-                'func'       => '_registrations_overview_list_table',
180
-                'capability' => 'ee_read_registrations',
181
-            ),
182
-            'view_registration'                  => array(
183
-                'func'       => '_registration_details',
184
-                'capability' => 'ee_read_registration',
185
-                'obj_id'     => $reg_id,
186
-            ),
187
-            'edit_registration'                  => array(
188
-                'func'               => '_update_attendee_registration_form',
189
-                'noheader'           => true,
190
-                'headers_sent_route' => 'view_registration',
191
-                'capability'         => 'ee_edit_registration',
192
-                'obj_id'             => $reg_id,
193
-                '_REG_ID'            => $reg_id,
194
-            ),
195
-            'trash_registrations'                => array(
196
-                'func'       => '_trash_or_restore_registrations',
197
-                'args'       => array('trash' => true),
198
-                'noheader'   => true,
199
-                'capability' => 'ee_delete_registrations',
200
-            ),
201
-            'restore_registrations'              => array(
202
-                'func'       => '_trash_or_restore_registrations',
203
-                'args'       => array('trash' => false),
204
-                'noheader'   => true,
205
-                'capability' => 'ee_delete_registrations',
206
-            ),
207
-            'delete_registrations'               => array(
208
-                'func'       => '_delete_registrations',
209
-                'noheader'   => true,
210
-                'capability' => 'ee_delete_registrations',
211
-            ),
212
-            'new_registration'                   => array(
213
-                'func'       => 'new_registration',
214
-                'capability' => 'ee_edit_registrations',
215
-            ),
216
-            'process_reg_step'                   => array(
217
-                'func'       => 'process_reg_step',
218
-                'noheader'   => true,
219
-                'capability' => 'ee_edit_registrations',
220
-            ),
221
-            'redirect_to_txn'                    => array(
222
-                'func'       => 'redirect_to_txn',
223
-                'noheader'   => true,
224
-                'capability' => 'ee_edit_registrations',
225
-            ),
226
-            'change_reg_status'                  => array(
227
-                'func'       => '_change_reg_status',
228
-                'noheader'   => true,
229
-                'capability' => 'ee_edit_registration',
230
-                'obj_id'     => $reg_id,
231
-            ),
232
-            'approve_registration'               => array(
233
-                'func'       => 'approve_registration',
234
-                'noheader'   => true,
235
-                'capability' => 'ee_edit_registration',
236
-                'obj_id'     => $reg_id,
237
-            ),
238
-            'approve_and_notify_registration'    => array(
239
-                'func'       => 'approve_registration',
240
-                'noheader'   => true,
241
-                'args'       => array(true),
242
-                'capability' => 'ee_edit_registration',
243
-                'obj_id'     => $reg_id,
244
-            ),
245
-            'approve_registrations'               => array(
246
-                'func'       => 'bulk_action_on_registrations',
247
-                'noheader'   => true,
248
-                'capability' => 'ee_edit_registrations',
249
-                'args' => array('approve')
250
-            ),
251
-            'approve_and_notify_registrations'               => array(
252
-                'func'       => 'bulk_action_on_registrations',
253
-                'noheader'   => true,
254
-                'capability' => 'ee_edit_registrations',
255
-                'args' => array('approve', true)
256
-            ),
257
-            'decline_registration'               => array(
258
-                'func'       => 'decline_registration',
259
-                'noheader'   => true,
260
-                'capability' => 'ee_edit_registration',
261
-                'obj_id'     => $reg_id,
262
-            ),
263
-            'decline_and_notify_registration'    => array(
264
-                'func'       => 'decline_registration',
265
-                'noheader'   => true,
266
-                'args'       => array(true),
267
-                'capability' => 'ee_edit_registration',
268
-                'obj_id'     => $reg_id,
269
-            ),
270
-            'decline_registrations'               => array(
271
-                'func'       => 'bulk_action_on_registrations',
272
-                'noheader'   => true,
273
-                'capability' => 'ee_edit_registrations',
274
-                'args' => array('decline')
275
-            ),
276
-            'decline_and_notify_registrations'    => array(
277
-                'func'       => 'bulk_action_on_registrations',
278
-                'noheader'   => true,
279
-                'capability' => 'ee_edit_registrations',
280
-                'args' => array('decline', true)
281
-            ),
282
-            'pending_registration'               => array(
283
-                'func'       => 'pending_registration',
284
-                'noheader'   => true,
285
-                'capability' => 'ee_edit_registration',
286
-                'obj_id'     => $reg_id,
287
-            ),
288
-            'pending_and_notify_registration'    => array(
289
-                'func'       => 'pending_registration',
290
-                'noheader'   => true,
291
-                'args'       => array(true),
292
-                'capability' => 'ee_edit_registration',
293
-                'obj_id'     => $reg_id,
294
-            ),
295
-            'pending_registrations'               => array(
296
-                'func'       => 'bulk_action_on_registrations',
297
-                'noheader'   => true,
298
-                'capability' => 'ee_edit_registrations',
299
-                'args' => array('pending')
300
-            ),
301
-            'pending_and_notify_registrations'    => array(
302
-                'func'       => 'bulk_action_on_registrations',
303
-                'noheader'   => true,
304
-                'capability' => 'ee_edit_registrations',
305
-                'args' => array('pending', true)
306
-            ),
307
-            'no_approve_registration'            => array(
308
-                'func'       => 'not_approve_registration',
309
-                'noheader'   => true,
310
-                'capability' => 'ee_edit_registration',
311
-                'obj_id'     => $reg_id,
312
-            ),
313
-            'no_approve_and_notify_registration' => array(
314
-                'func'       => 'not_approve_registration',
315
-                'noheader'   => true,
316
-                'args'       => array(true),
317
-                'capability' => 'ee_edit_registration',
318
-                'obj_id'     => $reg_id,
319
-            ),
320
-            'no_approve_registrations'            => array(
321
-                'func'       => 'bulk_action_on_registrations',
322
-                'noheader'   => true,
323
-                'capability' => 'ee_edit_registrations',
324
-                'args' => array('not_approve')
325
-            ),
326
-            'no_approve_and_notify_registrations' => array(
327
-                'func'       => 'bulk_action_on_registrations',
328
-                'noheader'   => true,
329
-                'capability' => 'ee_edit_registrations',
330
-                'args' => array('not_approve', true)
331
-            ),
332
-            'cancel_registration'                => array(
333
-                'func'       => 'cancel_registration',
334
-                'noheader'   => true,
335
-                'capability' => 'ee_edit_registration',
336
-                'obj_id'     => $reg_id,
337
-            ),
338
-            'cancel_and_notify_registration'     => array(
339
-                'func'       => 'cancel_registration',
340
-                'noheader'   => true,
341
-                'args'       => array(true),
342
-                'capability' => 'ee_edit_registration',
343
-                'obj_id'     => $reg_id,
344
-            ),
345
-            'cancel_registrations'                => array(
346
-                'func'       => 'bulk_action_on_registrations',
347
-                'noheader'   => true,
348
-                'capability' => 'ee_edit_registrations',
349
-                'args' => array('cancel')
350
-            ),
351
-            'cancel_and_notify_registrations'     => array(
352
-                'func'       => 'bulk_action_on_registrations',
353
-                'noheader'   => true,
354
-                'capability' => 'ee_edit_registrations',
355
-                'args' => array('cancel', true)
356
-            ),
357
-            'wait_list_registration' => array(
358
-                'func'       => 'wait_list_registration',
359
-                'noheader'   => true,
360
-                'capability' => 'ee_edit_registration',
361
-                'obj_id'     => $reg_id,
362
-            ),
363
-            'contact_list'                       => array(
364
-                'func'       => '_attendee_contact_list_table',
365
-                'capability' => 'ee_read_contacts',
366
-            ),
367
-            'add_new_attendee'                   => array(
368
-                'func' => '_create_new_cpt_item',
369
-                'args' => array(
370
-                    'new_attendee' => true,
371
-                    'capability'   => 'ee_edit_contacts',
372
-                ),
373
-            ),
374
-            'edit_attendee'                      => array(
375
-                'func'       => '_edit_cpt_item',
376
-                'capability' => 'ee_edit_contacts',
377
-                'obj_id'     => $att_id,
378
-            ),
379
-            'duplicate_attendee'                 => array(
380
-                'func'       => '_duplicate_attendee',
381
-                'noheader'   => true,
382
-                'capability' => 'ee_edit_contacts',
383
-                'obj_id'     => $att_id,
384
-            ),
385
-            'insert_attendee'                    => array(
386
-                'func'       => '_insert_or_update_attendee',
387
-                'args'       => array(
388
-                    'new_attendee' => true,
389
-                ),
390
-                'noheader'   => true,
391
-                'capability' => 'ee_edit_contacts',
392
-            ),
393
-            'update_attendee'                    => array(
394
-                'func'       => '_insert_or_update_attendee',
395
-                'args'       => array(
396
-                    'new_attendee' => false,
397
-                ),
398
-                'noheader'   => true,
399
-                'capability' => 'ee_edit_contacts',
400
-                'obj_id'     => $att_id,
401
-            ),
402
-            'trash_attendees' => array(
403
-                'func' => '_trash_or_restore_attendees',
404
-                'args' => array(
405
-                    'trash' => 'true'
406
-                ),
407
-                'noheader' => true,
408
-                'capability' => 'ee_delete_contacts'
409
-            ),
410
-            'trash_attendee'                    => array(
411
-                'func'       => '_trash_or_restore_attendees',
412
-                'args'       => array(
413
-                    'trash' => true,
414
-                ),
415
-                'noheader'   => true,
416
-                'capability' => 'ee_delete_contacts',
417
-                'obj_id'     => $att_id,
418
-            ),
419
-            'restore_attendees'                  => array(
420
-                'func'       => '_trash_or_restore_attendees',
421
-                'args'       => array(
422
-                    'trash' => false,
423
-                ),
424
-                'noheader'   => true,
425
-                'capability' => 'ee_delete_contacts',
426
-                'obj_id'     => $att_id,
427
-            ),
428
-            'resend_registration'                => array(
429
-                'func'       => '_resend_registration',
430
-                'noheader'   => true,
431
-                'capability' => 'ee_send_message',
432
-            ),
433
-            'registrations_report'               => array(
434
-                'func'       => '_registrations_report',
435
-                'noheader'   => true,
436
-                'capability' => 'ee_read_registrations',
437
-            ),
438
-            'contact_list_export'                => array(
439
-                'func'       => '_contact_list_export',
440
-                'noheader'   => true,
441
-                'capability' => 'export',
442
-            ),
443
-            'contact_list_report'                => array(
444
-                'func'       => '_contact_list_report',
445
-                'noheader'   => true,
446
-                'capability' => 'ee_read_contacts',
447
-            ),
448
-        );
449
-    }
450
-
451
-
452
-    protected function _set_page_config()
453
-    {
454
-        $this->_page_config = array(
455
-            'default'           => array(
456
-                'nav'           => array(
457
-                    'label' => esc_html__('Overview', 'event_espresso'),
458
-                    'order' => 5,
459
-                ),
460
-                'help_tabs'     => array(
461
-                    'registrations_overview_help_tab'                       => array(
462
-                        'title'    => esc_html__('Registrations Overview', 'event_espresso'),
463
-                        'filename' => 'registrations_overview',
464
-                    ),
465
-                    'registrations_overview_table_column_headings_help_tab' => array(
466
-                        'title'    => esc_html__('Registrations Table Column Headings', 'event_espresso'),
467
-                        'filename' => 'registrations_overview_table_column_headings',
468
-                    ),
469
-                    'registrations_overview_filters_help_tab'               => array(
470
-                        'title'    => esc_html__('Registration Filters', 'event_espresso'),
471
-                        'filename' => 'registrations_overview_filters',
472
-                    ),
473
-                    'registrations_overview_views_help_tab'                 => array(
474
-                        'title'    => esc_html__('Registration Views', 'event_espresso'),
475
-                        'filename' => 'registrations_overview_views',
476
-                    ),
477
-                    'registrations_regoverview_other_help_tab'              => array(
478
-                        'title'    => esc_html__('Registrations Other', 'event_espresso'),
479
-                        'filename' => 'registrations_overview_other',
480
-                    ),
481
-                ),
482
-                'help_tour'     => array('Registration_Overview_Help_Tour'),
483
-                'qtips'         => array('Registration_List_Table_Tips'),
484
-                'list_table'    => 'EE_Registrations_List_Table',
485
-                'require_nonce' => false,
486
-            ),
487
-            'view_registration' => array(
488
-                'nav'           => array(
489
-                    'label'      => esc_html__('REG Details', 'event_espresso'),
490
-                    'order'      => 15,
491
-                    'url'        => isset($this->_req_data['_REG_ID'])
492
-                        ? add_query_arg(array('_REG_ID' => $this->_req_data['_REG_ID']), $this->_current_page_view_url)
493
-                        : $this->_admin_base_url,
494
-                    'persistent' => false,
495
-                ),
496
-                'help_tabs'     => array(
497
-                    'registrations_details_help_tab'                    => array(
498
-                        'title'    => esc_html__('Registration Details', 'event_espresso'),
499
-                        'filename' => 'registrations_details',
500
-                    ),
501
-                    'registrations_details_table_help_tab'              => array(
502
-                        'title'    => esc_html__('Registration Details Table', 'event_espresso'),
503
-                        'filename' => 'registrations_details_table',
504
-                    ),
505
-                    'registrations_details_form_answers_help_tab'       => array(
506
-                        'title'    => esc_html__('Registration Form Answers', 'event_espresso'),
507
-                        'filename' => 'registrations_details_form_answers',
508
-                    ),
509
-                    'registrations_details_registrant_details_help_tab' => array(
510
-                        'title'    => esc_html__('Contact Details', 'event_espresso'),
511
-                        'filename' => 'registrations_details_registrant_details',
512
-                    ),
513
-                ),
514
-                'help_tour'     => array('Registration_Details_Help_Tour'),
515
-                'metaboxes'     => array_merge(
516
-                    $this->_default_espresso_metaboxes,
517
-                    array('_registration_details_metaboxes')
518
-                ),
519
-                'require_nonce' => false,
520
-            ),
521
-            'new_registration'  => array(
522
-                'nav'           => array(
523
-                    'label'      => esc_html__('Add New Registration', 'event_espresso'),
524
-                    'url'        => '#',
525
-                    'order'      => 15,
526
-                    'persistent' => false,
527
-                ),
528
-                'metaboxes'     => $this->_default_espresso_metaboxes,
529
-                'labels'        => array(
530
-                    'publishbox' => esc_html__('Save Registration', 'event_espresso'),
531
-                ),
532
-                'require_nonce' => false,
533
-            ),
534
-            'add_new_attendee'  => array(
535
-                'nav'           => array(
536
-                    'label'      => esc_html__('Add Contact', 'event_espresso'),
537
-                    'order'      => 15,
538
-                    'persistent' => false,
539
-                ),
540
-                'metaboxes'     => array_merge(
541
-                    $this->_default_espresso_metaboxes,
542
-                    array('_publish_post_box', 'attendee_editor_metaboxes')
543
-                ),
544
-                'require_nonce' => false,
545
-            ),
546
-            'edit_attendee'     => array(
547
-                'nav'           => array(
548
-                    'label'      => esc_html__('Edit Contact', 'event_espresso'),
549
-                    'order'      => 15,
550
-                    'persistent' => false,
551
-                    'url'        => isset($this->_req_data['ATT_ID'])
552
-                        ? add_query_arg(array('ATT_ID' => $this->_req_data['ATT_ID']), $this->_current_page_view_url)
553
-                        : $this->_admin_base_url,
554
-                ),
555
-                'metaboxes'     => array('attendee_editor_metaboxes'),
556
-                'require_nonce' => false,
557
-            ),
558
-            'contact_list'      => array(
559
-                'nav'           => array(
560
-                    'label' => esc_html__('Contact List', 'event_espresso'),
561
-                    'order' => 20,
562
-                ),
563
-                'list_table'    => 'EE_Attendee_Contact_List_Table',
564
-                'help_tabs'     => array(
565
-                    'registrations_contact_list_help_tab'                       => array(
566
-                        'title'    => esc_html__('Registrations Contact List', 'event_espresso'),
567
-                        'filename' => 'registrations_contact_list',
568
-                    ),
569
-                    'registrations_contact-list_table_column_headings_help_tab' => array(
570
-                        'title'    => esc_html__('Contact List Table Column Headings', 'event_espresso'),
571
-                        'filename' => 'registrations_contact_list_table_column_headings',
572
-                    ),
573
-                    'registrations_contact_list_views_help_tab'                 => array(
574
-                        'title'    => esc_html__('Contact List Views', 'event_espresso'),
575
-                        'filename' => 'registrations_contact_list_views',
576
-                    ),
577
-                    'registrations_contact_list_other_help_tab'                 => array(
578
-                        'title'    => esc_html__('Contact List Other', 'event_espresso'),
579
-                        'filename' => 'registrations_contact_list_other',
580
-                    ),
581
-                ),
582
-                'help_tour'     => array('Contact_List_Help_Tour'),
583
-                'metaboxes'     => array(),
584
-                'require_nonce' => false,
585
-            ),
586
-            //override default cpt routes
587
-            'create_new'        => '',
588
-            'edit'              => '',
589
-        );
590
-    }
591
-
592
-
593
-    /**
594
-     * The below methods aren't used by this class currently
595
-     */
596
-    protected function _add_screen_options()
597
-    {
598
-    }
599
-
600
-
601
-    protected function _add_feature_pointers()
602
-    {
603
-    }
604
-
605
-
606
-    public function admin_init()
607
-    {
608
-        EE_Registry::$i18n_js_strings['update_att_qstns'] = esc_html__(
609
-            'click "Update Registration Questions" to save your changes',
610
-            'event_espresso'
611
-        );
612
-    }
613
-
614
-
615
-    public function admin_notices()
616
-    {
617
-    }
618
-
619
-
620
-    public function admin_footer_scripts()
621
-    {
622
-    }
623
-
624
-
625
-    /**
626
-     *        get list of registration statuses
627
-     *
628
-     * @access private
629
-     * @return void
630
-     */
631
-    private function _get_registration_status_array()
632
-    {
633
-        self::$_reg_status = EEM_Registration::reg_status_array(array(), true);
634
-    }
635
-
636
-
637
-    protected function _add_screen_options_default()
638
-    {
639
-        $this->_per_page_screen_option();
640
-    }
641
-
642
-
643
-    protected function _add_screen_options_contact_list()
644
-    {
645
-        $page_title              = $this->_admin_page_title;
646
-        $this->_admin_page_title = esc_html__("Contacts", 'event_espresso');
647
-        $this->_per_page_screen_option();
648
-        $this->_admin_page_title = $page_title;
649
-    }
650
-
651
-
652
-    public function load_scripts_styles()
653
-    {
654
-        //style
655
-        wp_register_style(
656
-            'espresso_reg',
657
-            REG_ASSETS_URL . 'espresso_registrations_admin.css',
658
-            array('ee-admin-css'),
659
-            EVENT_ESPRESSO_VERSION
660
-        );
661
-        wp_enqueue_style('espresso_reg');
662
-        //script
663
-        wp_register_script(
664
-            'espresso_reg',
665
-            REG_ASSETS_URL . 'espresso_registrations_admin.js',
666
-            array('jquery-ui-datepicker', 'jquery-ui-draggable', 'ee_admin_js'),
667
-            EVENT_ESPRESSO_VERSION,
668
-            true
669
-        );
670
-        wp_enqueue_script('espresso_reg');
671
-    }
672
-
673
-
674
-    public function load_scripts_styles_edit_attendee()
675
-    {
676
-        //stuff to only show up on our attendee edit details page.
677
-        $attendee_details_translations = array(
678
-            'att_publish_text' => sprintf(
679
-                esc_html__('Created on: <b>%1$s</b>', 'event_espresso'),
680
-                $this->_cpt_model_obj->get_datetime('ATT_created')
681
-            ),
682
-        );
683
-        wp_localize_script('espresso_reg', 'ATTENDEE_DETAILS', $attendee_details_translations);
684
-        wp_enqueue_script('jquery-validate');
685
-    }
686
-
687
-
688
-    public function load_scripts_styles_view_registration()
689
-    {
690
-        //styles
691
-        wp_enqueue_style('espresso-ui-theme');
692
-        //scripts
693
-        $this->_get_reg_custom_questions_form($this->_registration->ID());
694
-        $this->_reg_custom_questions_form->wp_enqueue_scripts(true);
695
-    }
696
-
697
-
698
-    public function load_scripts_styles_contact_list()
699
-    {
700
-        wp_deregister_style('espresso_reg');
701
-        wp_register_style(
702
-            'espresso_att',
703
-            REG_ASSETS_URL . 'espresso_attendees_admin.css',
704
-            array('ee-admin-css'),
705
-            EVENT_ESPRESSO_VERSION
706
-        );
707
-        wp_enqueue_style('espresso_att');
708
-    }
709
-
710
-
711
-    public function load_scripts_styles_new_registration()
712
-    {
713
-        wp_register_script(
714
-            'ee-spco-for-admin',
715
-            REG_ASSETS_URL . 'spco_for_admin.js',
716
-            array('underscore', 'jquery'),
717
-            EVENT_ESPRESSO_VERSION,
718
-            true
719
-        );
720
-        wp_enqueue_script('ee-spco-for-admin');
721
-        add_filter('FHEE__EED_Ticket_Selector__load_tckt_slctr_assets', '__return_true');
722
-        EE_Form_Section_Proper::wp_enqueue_scripts();
723
-        EED_Ticket_Selector::load_tckt_slctr_assets();
724
-        EE_Datepicker_Input::enqueue_styles_and_scripts();
725
-    }
726
-
727
-
728
-    public function AHEE__EE_Admin_Page__route_admin_request_resend_registration()
729
-    {
730
-        add_filter('FHEE_load_EE_messages', '__return_true');
731
-    }
732
-
733
-
734
-    public function AHEE__EE_Admin_Page__route_admin_request_approve_registration()
735
-    {
736
-        add_filter('FHEE_load_EE_messages', '__return_true');
737
-    }
738
-
739
-
740
-    protected function _set_list_table_views_default()
741
-    {
742
-        //for notification related bulk actions we need to make sure only active messengers have an option.
743
-        EED_Messages::set_autoloaders();
744
-        /** @type EE_Message_Resource_Manager $message_resource_manager */
745
-        $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
746
-        $active_mts               = $message_resource_manager->list_of_active_message_types();
747
-        //key= bulk_action_slug, value= message type.
748
-        $match_array = array(
749
-            'approve_registrations'    => 'registration',
750
-            'decline_registrations'    => 'declined_registration',
751
-            'pending_registrations'    => 'pending_approval',
752
-            'no_approve_registrations' => 'not_approved_registration',
753
-            'cancel_registrations'     => 'cancelled_registration',
754
-        );
755
-        $can_send = EE_Registry::instance()->CAP->current_user_can(
756
-            'ee_send_message',
757
-            'batch_send_messages'
758
-        );
759
-        /** setup reg status bulk actions **/
760
-        $def_reg_status_actions['approve_registrations'] = esc_html__('Approve Registrations', 'event_espresso');
761
-        if ($can_send && in_array($match_array['approve_registrations'], $active_mts, true)) {
762
-                $def_reg_status_actions['approve_and_notify_registrations'] = esc_html__(
763
-                    'Approve and Notify Registrations',
764
-                    'event_espresso'
765
-                );
766
-        }
767
-        $def_reg_status_actions['decline_registrations'] = esc_html__('Decline Registrations', 'event_espresso');
768
-        if ($can_send && in_array($match_array['decline_registrations'], $active_mts, true)) {
769
-                $def_reg_status_actions['decline_and_notify_registrations'] = esc_html__(
770
-                    'Decline and Notify Registrations',
771
-                    'event_espresso'
772
-                );
773
-        }
774
-        $def_reg_status_actions['pending_registrations'] = esc_html__(
775
-            'Set Registrations to Pending Payment',
776
-            'event_espresso'
777
-        );
778
-        if ($can_send && in_array($match_array['pending_registrations'], $active_mts, true)) {
779
-                $def_reg_status_actions['pending_and_notify_registrations'] = esc_html__(
780
-                    'Set Registrations to Pending Payment and Notify',
781
-                    'event_espresso'
782
-                );
783
-        }
784
-        $def_reg_status_actions['no_approve_registrations'] = esc_html__(
785
-            'Set Registrations to Not Approved',
786
-            'event_espresso'
787
-        );
788
-        if ($can_send && in_array($match_array['no_approve_registrations'], $active_mts, true)) {
789
-                $def_reg_status_actions['no_approve_and_notify_registrations'] = esc_html__(
790
-                    'Set Registrations to Not Approved and Notify',
791
-                    'event_espresso'
792
-                );
793
-        }
794
-        $def_reg_status_actions['cancel_registrations'] = esc_html__('Cancel Registrations', 'event_espresso');
795
-        if ($can_send && in_array($match_array['cancel_registrations'], $active_mts, true)) {
796
-                $def_reg_status_actions['cancel_and_notify_registrations'] = esc_html__(
797
-                    'Cancel Registrations and Notify',
798
-                    'event_espresso'
799
-                );
800
-        }
801
-        $def_reg_status_actions = apply_filters(
802
-            'FHEE__Registrations_Admin_Page___set_list_table_views_default__def_reg_status_actions_array',
803
-            $def_reg_status_actions,
804
-            $active_mts
805
-        );
806
-
807
-        $this->_views = array(
808
-            'all'   => array(
809
-                'slug'        => 'all',
810
-                'label'       => esc_html__('View All Registrations', 'event_espresso'),
811
-                'count'       => 0,
812
-                'bulk_action' => array_merge($def_reg_status_actions, array(
813
-                    'trash_registrations' => esc_html__('Trash Registrations', 'event_espresso'),
814
-                )),
815
-            ),
816
-            'month' => array(
817
-                'slug'        => 'month',
818
-                'label'       => esc_html__('This Month', 'event_espresso'),
819
-                'count'       => 0,
820
-                'bulk_action' => array_merge($def_reg_status_actions, array(
821
-                    'trash_registrations' => esc_html__('Trash Registrations', 'event_espresso'),
822
-                )),
823
-            ),
824
-            'today' => array(
825
-                'slug'        => 'today',
826
-                'label'       => sprintf(
827
-                    esc_html__('Today - %s', 'event_espresso'),
828
-                    date('M d, Y', current_time('timestamp'))
829
-                ),
830
-                'count'       => 0,
831
-                'bulk_action' => array_merge($def_reg_status_actions, array(
832
-                    'trash_registrations' => esc_html__('Trash Registrations', 'event_espresso'),
833
-                )),
834
-            ),
835
-        );
836
-        if (EE_Registry::instance()->CAP->current_user_can(
837
-            'ee_delete_registrations',
838
-            'espresso_registrations_delete_registration'
839
-        )) {
840
-            $this->_views['incomplete'] = array(
841
-                'slug'        => 'incomplete',
842
-                'label'       => esc_html__('Incomplete', 'event_espresso'),
843
-                'count'       => 0,
844
-                'bulk_action' => array(
845
-                    'trash_registrations' => esc_html__('Trash Registrations', 'event_espresso'),
846
-                ),
847
-            );
848
-            $this->_views['trash']      = array(
849
-                'slug'        => 'trash',
850
-                'label'       => esc_html__('Trash', 'event_espresso'),
851
-                'count'       => 0,
852
-                'bulk_action' => array(
853
-                    'restore_registrations' => esc_html__('Restore Registrations', 'event_espresso'),
854
-                    'delete_registrations'  => esc_html__('Delete Registrations Permanently', 'event_espresso'),
855
-                ),
856
-            );
857
-        }
858
-    }
859
-
860
-
861
-    protected function _set_list_table_views_contact_list()
862
-    {
863
-        $this->_views = array(
864
-            'in_use' => array(
865
-                'slug'        => 'in_use',
866
-                'label'       => esc_html__('In Use', 'event_espresso'),
867
-                'count'       => 0,
868
-                'bulk_action' => array(
869
-                    'trash_attendees' => esc_html__('Move to Trash', 'event_espresso'),
870
-                ),
871
-            ),
872
-        );
873
-        if (EE_Registry::instance()->CAP->current_user_can('ee_delete_contacts',
874
-            'espresso_registrations_trash_attendees')
875
-        ) {
876
-            $this->_views['trash'] = array(
877
-                'slug'        => 'trash',
878
-                'label'       => esc_html__('Trash', 'event_espresso'),
879
-                'count'       => 0,
880
-                'bulk_action' => array(
881
-                    'restore_attendees' => esc_html__('Restore from Trash', 'event_espresso'),
882
-                ),
883
-            );
884
-        }
885
-    }
886
-
887
-
888
-    protected function _registration_legend_items()
889
-    {
890
-        $fc_items = array(
891
-            'star-icon'        => array(
892
-                'class' => 'dashicons dashicons-star-filled lt-blue-icon ee-icon-size-8',
893
-                'desc'  => esc_html__('This is the Primary Registrant', 'event_espresso'),
894
-            ),
895
-            'view_details'     => array(
896
-                'class' => 'dashicons dashicons-clipboard',
897
-                'desc'  => esc_html__('View Registration Details', 'event_espresso'),
898
-            ),
899
-            'edit_attendee'    => array(
900
-                'class' => 'ee-icon ee-icon-user-edit ee-icon-size-16',
901
-                'desc'  => esc_html__('Edit Contact Details', 'event_espresso'),
902
-            ),
903
-            'view_transaction' => array(
904
-                'class' => 'dashicons dashicons-cart',
905
-                'desc'  => esc_html__('View Transaction Details', 'event_espresso'),
906
-            ),
907
-            'view_invoice'     => array(
908
-                'class' => 'dashicons dashicons-media-spreadsheet',
909
-                'desc'  => esc_html__('View Transaction Invoice', 'event_espresso'),
910
-            ),
911
-        );
912
-        if (EE_Registry::instance()->CAP->current_user_can(
913
-            'ee_send_message',
914
-            'espresso_registrations_resend_registration'
915
-        )) {
916
-            $fc_items['resend_registration'] = array(
917
-                'class' => 'dashicons dashicons-email-alt',
918
-                'desc'  => esc_html__('Resend Registration Details', 'event_espresso'),
919
-            );
920
-        } else {
921
-            $fc_items['blank'] = array('class' => 'blank', 'desc' => '');
922
-        }
923
-        if (EE_Registry::instance()->CAP->current_user_can(
924
-            'ee_read_global_messages',
925
-            'view_filtered_messages'
926
-        )) {
927
-            $related_for_icon = EEH_MSG_Template::get_message_action_icon('see_notifications_for');
928
-            if (isset($related_for_icon['css_class']) && isset($related_for_icon['label'])) {
929
-                $fc_items['view_related_messages'] = array(
930
-                    'class' => $related_for_icon['css_class'],
931
-                    'desc'  => $related_for_icon['label'],
932
-                );
933
-            }
934
-        }
935
-        $sc_items = array(
936
-            'approved_status'   => array(
937
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_approved,
938
-                'desc'  => EEH_Template::pretty_status(
939
-                    EEM_Registration::status_id_approved,
940
-                    false,
941
-                    'sentence'
942
-                ),
943
-            ),
944
-            'pending_status'    => array(
945
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_pending_payment,
946
-                'desc'  => EEH_Template::pretty_status(
947
-                    EEM_Registration::status_id_pending_payment,
948
-                    false,
949
-                    'sentence'
950
-                ),
951
-            ),
952
-            'wait_list'         => array(
953
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_wait_list,
954
-                'desc'  => EEH_Template::pretty_status(
955
-                    EEM_Registration::status_id_wait_list,
956
-                    false,
957
-                    'sentence'
958
-                ),
959
-            ),
960
-            'incomplete_status' => array(
961
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_incomplete,
962
-                'desc'  => EEH_Template::pretty_status(
963
-                    EEM_Registration::status_id_incomplete,
964
-                    false,
965
-                    'sentence'
966
-                ),
967
-            ),
968
-            'not_approved'      => array(
969
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_not_approved,
970
-                'desc'  => EEH_Template::pretty_status(
971
-                    EEM_Registration::status_id_not_approved,
972
-                    false,
973
-                    'sentence'
974
-                ),
975
-            ),
976
-            'declined_status'   => array(
977
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_declined,
978
-                'desc'  => EEH_Template::pretty_status(
979
-                    EEM_Registration::status_id_declined,
980
-                    false,
981
-                    'sentence'
982
-                ),
983
-            ),
984
-            'cancelled_status'  => array(
985
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_cancelled,
986
-                'desc'  => EEH_Template::pretty_status(
987
-                    EEM_Registration::status_id_cancelled,
988
-                    false,
989
-                    'sentence'
990
-                ),
991
-            ),
992
-        );
993
-        return array_merge($fc_items, $sc_items);
994
-    }
995
-
996
-
997
-
998
-    /***************************************        REGISTRATION OVERVIEW        **************************************/
999
-    /**
1000
-     * @throws \EE_Error
1001
-     */
1002
-    protected function _registrations_overview_list_table()
1003
-    {
1004
-        $this->_template_args['admin_page_header'] = '';
1005
-        $EVT_ID                                    = ! empty($this->_req_data['event_id'])
1006
-            ? absint($this->_req_data['event_id'])
1007
-            : 0;
1008
-        if ($EVT_ID) {
1009
-            if (EE_Registry::instance()->CAP->current_user_can(
1010
-                'ee_edit_registrations',
1011
-                'espresso_registrations_new_registration',
1012
-                $EVT_ID
1013
-            )) {
1014
-                $this->_admin_page_title .= ' ' . $this->get_action_link_or_button(
1015
-                    'new_registration',
1016
-                    'add-registrant',
1017
-                    array('event_id' => $EVT_ID),
1018
-                    'add-new-h2'
1019
-                );
1020
-            }
1021
-            $event = EEM_Event::instance()->get_one_by_ID($EVT_ID);
1022
-            if ($event instanceof EE_Event) {
1023
-                $this->_template_args['admin_page_header'] = sprintf(
1024
-                    esc_html__(
1025
-                        '%s Viewing registrations for the event: %s%s',
1026
-                        'event_espresso'
1027
-                    ),
1028
-                    '<h3 style="line-height:1.5em;">',
1029
-                    '<br /><a href="'
1030
-                        . EE_Admin_Page::add_query_args_and_nonce(
1031
-                            array(
1032
-                                'action' => 'edit',
1033
-                                'post'   => $event->ID(),
1034
-                            ),
1035
-                            EVENTS_ADMIN_URL
1036
-                        )
1037
-                        . '">&nbsp;'
1038
-                        . $event->get('EVT_name')
1039
-                        . '&nbsp;</a>&nbsp;',
1040
-                    '</h3>'
1041
-                );
1042
-            }
1043
-            $DTT_ID   = ! empty($this->_req_data['datetime_id']) ? absint($this->_req_data['datetime_id']) : 0;
1044
-            $datetime = EEM_Datetime::instance()->get_one_by_ID($DTT_ID);
1045
-            if ($datetime instanceof EE_Datetime && $this->_template_args['admin_page_header'] !== '') {
1046
-                $this->_template_args['admin_page_header'] = substr(
1047
-                    $this->_template_args['admin_page_header'],
1048
-                    0,
1049
-                    -5
1050
-                );
1051
-                $this->_template_args['admin_page_header'] .= ' &nbsp;<span class="drk-grey-text">';
1052
-                $this->_template_args['admin_page_header'] .= '<span class="dashicons dashicons-calendar"></span>';
1053
-                $this->_template_args['admin_page_header'] .= $datetime->name();
1054
-                $this->_template_args['admin_page_header'] .= ' ( ' . $datetime->start_date() . ' )';
1055
-                $this->_template_args['admin_page_header'] .= '</span></h3>';
1056
-            }
1057
-        }
1058
-        $this->_template_args['after_list_table'] = $this->_display_legend($this->_registration_legend_items());
1059
-        $this->display_admin_list_table_page_with_no_sidebar();
1060
-    }
1061
-
1062
-
1063
-    /**
1064
-     * This sets the _registration property for the registration details screen
1065
-     *
1066
-     * @access private
1067
-     * @return bool
1068
-     */
1069
-    private function _set_registration_object()
1070
-    {
1071
-        //get out if we've already set the object
1072
-        if (is_object($this->_registration)) {
1073
-            return true;
1074
-        }
1075
-        $REG    = EEM_Registration::instance();
1076
-        $REG_ID = ( ! empty($this->_req_data['_REG_ID'])) ? absint($this->_req_data['_REG_ID']) : false;
1077
-        if ($this->_registration = $REG->get_one_by_ID($REG_ID)) {
1078
-            return true;
1079
-        } else {
1080
-            $error_msg = sprintf(
1081
-                esc_html__(
1082
-                    'An error occurred and the details for Registration ID #%s could not be retrieved.',
1083
-                    'event_espresso'
1084
-                ),
1085
-                $REG_ID
1086
-            );
1087
-            EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__);
1088
-            $this->_registration = null;
1089
-            return false;
1090
-        }
1091
-    }
1092
-
1093
-
1094
-    /**
1095
-     * Used to retrieve registrations for the list table.
1096
-     *
1097
-     * @param int  $per_page
1098
-     * @param bool $count
1099
-     * @param bool $this_month
1100
-     * @param bool $today
1101
-     * @return EE_Registration[]|int
1102
-     * @throws EE_Error
1103
-     */
1104
-    public function get_registrations(
1105
-        $per_page = 10,
1106
-        $count = false,
1107
-        $this_month = false,
1108
-        $today = false
1109
-    ) {
1110
-        if ($this_month) {
1111
-            $this->_req_data['status'] = 'month';
1112
-        }
1113
-        if ($today) {
1114
-            $this->_req_data['status'] = 'today';
1115
-        }
1116
-        $query_params = $this->_get_registration_query_parameters($this->_req_data, $per_page, $count);
1117
-        /**
1118
-         * Override the default groupby added by EEM_Base so that sorts with multiple order bys work as expected
1119
-         * @link https://events.codebasehq.com/projects/event-espresso/tickets/10093
1120
-         * @see EEM_Base::get_all()
1121
-         */
1122
-        $query_params['group_by'] = '';
1123
-
1124
-        return $count
1125
-            ? EEM_Registration::instance()->count($query_params)
1126
-            /** @type EE_Registration[] */
1127
-            : EEM_Registration::instance()->get_all($query_params);
1128
-    }
1129
-
1130
-
1131
-
1132
-    /**
1133
-     * Retrieves the query parameters to be used by the Registration model for getting registrations.
1134
-     * Note: this listens to values on the request for some of the query parameters.
1135
-     *
1136
-     * @param array $request
1137
-     * @param int    $per_page
1138
-     * @param bool   $count
1139
-     * @return array
1140
-     */
1141
-    protected function _get_registration_query_parameters(
1142
-        $request = array(),
1143
-        $per_page = 10,
1144
-        $count = false
1145
-    ) {
1146
-
1147
-        $query_params = array(
1148
-            0                          => $this->_get_where_conditions_for_registrations_query(
1149
-                $request
1150
-            ),
1151
-            'caps'                     => EEM_Registration::caps_read_admin,
1152
-            'default_where_conditions' => 'this_model_only',
1153
-        );
1154
-        if (! $count) {
1155
-            $query_params = array_merge(
1156
-                $query_params,
1157
-                $this->_get_orderby_for_registrations_query(),
1158
-                $this->_get_limit($per_page)
1159
-            );
1160
-        }
1161
-
1162
-        return $query_params;
1163
-    }
1164
-
1165
-
1166
-    /**
1167
-     * This will add EVT_ID to the provided $where array for EE model query parameters.
1168
-     *
1169
-     * @param array $request usually the same as $this->_req_data but not necessarily
1170
-     * @return array
1171
-     */
1172
-    protected function _add_event_id_to_where_conditions(array $request)
1173
-    {
1174
-        $where = array();
1175
-        if (! empty($request['event_id'])) {
1176
-            $where['EVT_ID'] = absint($request['event_id']);
1177
-        }
1178
-        return $where;
1179
-    }
1180
-
1181
-
1182
-    /**
1183
-     * Adds category ID if it exists in the request to the where conditions for the registrations query.
1184
-     *
1185
-     * @param array $request usually the same as $this->_req_data but not necessarily
1186
-     * @return array
1187
-     */
1188
-    protected function _add_category_id_to_where_conditions(array $request)
1189
-    {
1190
-        $where = array();
1191
-        if (! empty($request['EVT_CAT']) && (int)$request['EVT_CAT'] !== -1) {
1192
-            $where['Event.Term_Taxonomy.term_id'] = absint($request['EVT_CAT']);
1193
-        }
1194
-        return $where;
1195
-    }
1196
-
1197
-
1198
-    /**
1199
-     * Adds the datetime ID if it exists in the request to the where conditions for the registrations query.
1200
-     *
1201
-     * @param array $request usually the same as $this->_req_data but not necessarily
1202
-     * @return array
1203
-     */
1204
-    protected function _add_datetime_id_to_where_conditions(array $request)
1205
-    {
1206
-        $where = array();
1207
-        if (! empty($request['datetime_id'])) {
1208
-            $where['Ticket.Datetime.DTT_ID'] = absint($request['datetime_id']);
1209
-        }
1210
-        if (! empty($request['DTT_ID'])) {
1211
-            $where['Ticket.Datetime.DTT_ID'] = absint($request['DTT_ID']);
1212
-        }
1213
-        return $where;
1214
-    }
1215
-
1216
-
1217
-    /**
1218
-     * Adds the correct registration status to the where conditions for the registrations query.
1219
-     *
1220
-     * @param array $request usually the same as $this->_req_data but not necessarily
1221
-     * @return array
1222
-     */
1223
-    protected function _add_registration_status_to_where_conditions(array $request)
1224
-    {
1225
-        $where = array();
1226
-        $view = EEH_Array::is_set($request, 'status', '');
1227
-        $registration_status = ! empty($request['_reg_status'])
1228
-            ? sanitize_text_field($request['_reg_status'])
1229
-            : '';
1230
-
1231
-        /*
26
+	/**
27
+	 * @var EE_Registration
28
+	 */
29
+	private $_registration;
30
+
31
+	/**
32
+	 * @var EE_Event
33
+	 */
34
+	private $_reg_event;
35
+
36
+	/**
37
+	 * @var EE_Session
38
+	 */
39
+	private $_session;
40
+
41
+	private static $_reg_status;
42
+
43
+	/**
44
+	 * Form for displaying the custom questions for this registration.
45
+	 * This gets used a few times throughout the request so its best to cache it
46
+	 *
47
+	 * @var EE_Registration_Custom_Questions_Form
48
+	 */
49
+	protected $_reg_custom_questions_form = null;
50
+
51
+
52
+	/**
53
+	 *        constructor
54
+	 *
55
+	 * @Constructor
56
+	 * @access public
57
+	 * @param bool $routing
58
+	 * @return Registrations_Admin_Page
59
+	 */
60
+	public function __construct($routing = true)
61
+	{
62
+		parent::__construct($routing);
63
+		add_action('wp_loaded', array($this, 'wp_loaded'));
64
+	}
65
+
66
+
67
+	public function wp_loaded()
68
+	{
69
+		// when adding a new registration...
70
+		if (isset($this->_req_data['action']) && $this->_req_data['action'] === 'new_registration') {
71
+			EE_System::do_not_cache();
72
+			if (! isset($this->_req_data['processing_registration'])
73
+				 || absint($this->_req_data['processing_registration']) !== 1
74
+			) {
75
+				// and it's NOT the attendee information reg step
76
+				// force cookie expiration by setting time to last week
77
+				setcookie('ee_registration_added', 0, time() - WEEK_IN_SECONDS, '/');
78
+				// and update the global
79
+				$_COOKIE['ee_registration_added'] = 0;
80
+			}
81
+		}
82
+	}
83
+
84
+
85
+	protected function _init_page_props()
86
+	{
87
+		$this->page_slug        = REG_PG_SLUG;
88
+		$this->_admin_base_url  = REG_ADMIN_URL;
89
+		$this->_admin_base_path = REG_ADMIN;
90
+		$this->page_label       = esc_html__('Registrations', 'event_espresso');
91
+		$this->_cpt_routes      = array(
92
+			'add_new_attendee' => 'espresso_attendees',
93
+			'edit_attendee'    => 'espresso_attendees',
94
+			'insert_attendee'  => 'espresso_attendees',
95
+			'update_attendee'  => 'espresso_attendees',
96
+		);
97
+		$this->_cpt_model_names = array(
98
+			'add_new_attendee' => 'EEM_Attendee',
99
+			'edit_attendee'    => 'EEM_Attendee',
100
+		);
101
+		$this->_cpt_edit_routes = array(
102
+			'espresso_attendees' => 'edit_attendee',
103
+		);
104
+		$this->_pagenow_map     = array(
105
+			'add_new_attendee' => 'post-new.php',
106
+			'edit_attendee'    => 'post.php',
107
+			'trash'            => 'post.php',
108
+		);
109
+		add_action('edit_form_after_title', array($this, 'after_title_form_fields'), 10);
110
+		//add filters so that the comment urls don't take users to a confusing 404 page
111
+		add_filter('get_comment_link', array($this, 'clear_comment_link'), 10, 3);
112
+	}
113
+
114
+
115
+	public function clear_comment_link($link, $comment, $args)
116
+	{
117
+		//gotta make sure this only happens on this route
118
+		$post_type = get_post_type($comment->comment_post_ID);
119
+		if ($post_type === 'espresso_attendees') {
120
+			return '#commentsdiv';
121
+		}
122
+		return $link;
123
+	}
124
+
125
+
126
+	protected function _ajax_hooks()
127
+	{
128
+		//todo: all hooks for registrations ajax goes in here
129
+		add_action('wp_ajax_toggle_checkin_status', array($this, 'toggle_checkin_status'));
130
+	}
131
+
132
+
133
+	protected function _define_page_props()
134
+	{
135
+		$this->_admin_page_title = $this->page_label;
136
+		$this->_labels           = array(
137
+			'buttons'                      => array(
138
+				'add-registrant'      => esc_html__('Add New Registration', 'event_espresso'),
139
+				'add-attendee'        => esc_html__('Add Contact', 'event_espresso'),
140
+				'edit'                => esc_html__('Edit Contact', 'event_espresso'),
141
+				'report'              => esc_html__("Event Registrations CSV Report", "event_espresso"),
142
+				'report_all'          => esc_html__('All Registrations CSV Report', 'event_espresso'),
143
+				'report_filtered'     => esc_html__('Filtered CSV Report', 'event_espresso'),
144
+				'contact_list_report' => esc_html__('Contact List Report', 'event_espresso'),
145
+				'contact_list_export' => esc_html__("Export Data", "event_espresso"),
146
+			),
147
+			'publishbox'                   => array(
148
+				'add_new_attendee' => esc_html__("Add Contact Record", 'event_espresso'),
149
+				'edit_attendee'    => esc_html__("Update Contact Record", 'event_espresso'),
150
+			),
151
+			'hide_add_button_on_cpt_route' => array(
152
+				'edit_attendee' => true,
153
+			),
154
+		);
155
+	}
156
+
157
+
158
+	/**
159
+	 *        grab url requests and route them
160
+	 *
161
+	 * @access private
162
+	 * @return void
163
+	 */
164
+	public function _set_page_routes()
165
+	{
166
+		$this->_get_registration_status_array();
167
+		$reg_id             = ! empty($this->_req_data['_REG_ID']) && ! is_array($this->_req_data['_REG_ID'])
168
+			? $this->_req_data['_REG_ID'] : 0;
169
+		$reg_id = empty($reg_id) && ! empty($this->_req_data['reg_status_change_form']['REG_ID'])
170
+			? $this->_req_data['reg_status_change_form']['REG_ID']
171
+			: $reg_id;
172
+		$att_id             = ! empty($this->_req_data['ATT_ID']) && ! is_array($this->_req_data['ATT_ID'])
173
+			? $this->_req_data['ATT_ID'] : 0;
174
+		$att_id             = ! empty($this->_req_data['post']) && ! is_array($this->_req_data['post'])
175
+			? $this->_req_data['post']
176
+			: $att_id;
177
+		$this->_page_routes = array(
178
+			'default'                            => array(
179
+				'func'       => '_registrations_overview_list_table',
180
+				'capability' => 'ee_read_registrations',
181
+			),
182
+			'view_registration'                  => array(
183
+				'func'       => '_registration_details',
184
+				'capability' => 'ee_read_registration',
185
+				'obj_id'     => $reg_id,
186
+			),
187
+			'edit_registration'                  => array(
188
+				'func'               => '_update_attendee_registration_form',
189
+				'noheader'           => true,
190
+				'headers_sent_route' => 'view_registration',
191
+				'capability'         => 'ee_edit_registration',
192
+				'obj_id'             => $reg_id,
193
+				'_REG_ID'            => $reg_id,
194
+			),
195
+			'trash_registrations'                => array(
196
+				'func'       => '_trash_or_restore_registrations',
197
+				'args'       => array('trash' => true),
198
+				'noheader'   => true,
199
+				'capability' => 'ee_delete_registrations',
200
+			),
201
+			'restore_registrations'              => array(
202
+				'func'       => '_trash_or_restore_registrations',
203
+				'args'       => array('trash' => false),
204
+				'noheader'   => true,
205
+				'capability' => 'ee_delete_registrations',
206
+			),
207
+			'delete_registrations'               => array(
208
+				'func'       => '_delete_registrations',
209
+				'noheader'   => true,
210
+				'capability' => 'ee_delete_registrations',
211
+			),
212
+			'new_registration'                   => array(
213
+				'func'       => 'new_registration',
214
+				'capability' => 'ee_edit_registrations',
215
+			),
216
+			'process_reg_step'                   => array(
217
+				'func'       => 'process_reg_step',
218
+				'noheader'   => true,
219
+				'capability' => 'ee_edit_registrations',
220
+			),
221
+			'redirect_to_txn'                    => array(
222
+				'func'       => 'redirect_to_txn',
223
+				'noheader'   => true,
224
+				'capability' => 'ee_edit_registrations',
225
+			),
226
+			'change_reg_status'                  => array(
227
+				'func'       => '_change_reg_status',
228
+				'noheader'   => true,
229
+				'capability' => 'ee_edit_registration',
230
+				'obj_id'     => $reg_id,
231
+			),
232
+			'approve_registration'               => array(
233
+				'func'       => 'approve_registration',
234
+				'noheader'   => true,
235
+				'capability' => 'ee_edit_registration',
236
+				'obj_id'     => $reg_id,
237
+			),
238
+			'approve_and_notify_registration'    => array(
239
+				'func'       => 'approve_registration',
240
+				'noheader'   => true,
241
+				'args'       => array(true),
242
+				'capability' => 'ee_edit_registration',
243
+				'obj_id'     => $reg_id,
244
+			),
245
+			'approve_registrations'               => array(
246
+				'func'       => 'bulk_action_on_registrations',
247
+				'noheader'   => true,
248
+				'capability' => 'ee_edit_registrations',
249
+				'args' => array('approve')
250
+			),
251
+			'approve_and_notify_registrations'               => array(
252
+				'func'       => 'bulk_action_on_registrations',
253
+				'noheader'   => true,
254
+				'capability' => 'ee_edit_registrations',
255
+				'args' => array('approve', true)
256
+			),
257
+			'decline_registration'               => array(
258
+				'func'       => 'decline_registration',
259
+				'noheader'   => true,
260
+				'capability' => 'ee_edit_registration',
261
+				'obj_id'     => $reg_id,
262
+			),
263
+			'decline_and_notify_registration'    => array(
264
+				'func'       => 'decline_registration',
265
+				'noheader'   => true,
266
+				'args'       => array(true),
267
+				'capability' => 'ee_edit_registration',
268
+				'obj_id'     => $reg_id,
269
+			),
270
+			'decline_registrations'               => array(
271
+				'func'       => 'bulk_action_on_registrations',
272
+				'noheader'   => true,
273
+				'capability' => 'ee_edit_registrations',
274
+				'args' => array('decline')
275
+			),
276
+			'decline_and_notify_registrations'    => array(
277
+				'func'       => 'bulk_action_on_registrations',
278
+				'noheader'   => true,
279
+				'capability' => 'ee_edit_registrations',
280
+				'args' => array('decline', true)
281
+			),
282
+			'pending_registration'               => array(
283
+				'func'       => 'pending_registration',
284
+				'noheader'   => true,
285
+				'capability' => 'ee_edit_registration',
286
+				'obj_id'     => $reg_id,
287
+			),
288
+			'pending_and_notify_registration'    => array(
289
+				'func'       => 'pending_registration',
290
+				'noheader'   => true,
291
+				'args'       => array(true),
292
+				'capability' => 'ee_edit_registration',
293
+				'obj_id'     => $reg_id,
294
+			),
295
+			'pending_registrations'               => array(
296
+				'func'       => 'bulk_action_on_registrations',
297
+				'noheader'   => true,
298
+				'capability' => 'ee_edit_registrations',
299
+				'args' => array('pending')
300
+			),
301
+			'pending_and_notify_registrations'    => array(
302
+				'func'       => 'bulk_action_on_registrations',
303
+				'noheader'   => true,
304
+				'capability' => 'ee_edit_registrations',
305
+				'args' => array('pending', true)
306
+			),
307
+			'no_approve_registration'            => array(
308
+				'func'       => 'not_approve_registration',
309
+				'noheader'   => true,
310
+				'capability' => 'ee_edit_registration',
311
+				'obj_id'     => $reg_id,
312
+			),
313
+			'no_approve_and_notify_registration' => array(
314
+				'func'       => 'not_approve_registration',
315
+				'noheader'   => true,
316
+				'args'       => array(true),
317
+				'capability' => 'ee_edit_registration',
318
+				'obj_id'     => $reg_id,
319
+			),
320
+			'no_approve_registrations'            => array(
321
+				'func'       => 'bulk_action_on_registrations',
322
+				'noheader'   => true,
323
+				'capability' => 'ee_edit_registrations',
324
+				'args' => array('not_approve')
325
+			),
326
+			'no_approve_and_notify_registrations' => array(
327
+				'func'       => 'bulk_action_on_registrations',
328
+				'noheader'   => true,
329
+				'capability' => 'ee_edit_registrations',
330
+				'args' => array('not_approve', true)
331
+			),
332
+			'cancel_registration'                => array(
333
+				'func'       => 'cancel_registration',
334
+				'noheader'   => true,
335
+				'capability' => 'ee_edit_registration',
336
+				'obj_id'     => $reg_id,
337
+			),
338
+			'cancel_and_notify_registration'     => array(
339
+				'func'       => 'cancel_registration',
340
+				'noheader'   => true,
341
+				'args'       => array(true),
342
+				'capability' => 'ee_edit_registration',
343
+				'obj_id'     => $reg_id,
344
+			),
345
+			'cancel_registrations'                => array(
346
+				'func'       => 'bulk_action_on_registrations',
347
+				'noheader'   => true,
348
+				'capability' => 'ee_edit_registrations',
349
+				'args' => array('cancel')
350
+			),
351
+			'cancel_and_notify_registrations'     => array(
352
+				'func'       => 'bulk_action_on_registrations',
353
+				'noheader'   => true,
354
+				'capability' => 'ee_edit_registrations',
355
+				'args' => array('cancel', true)
356
+			),
357
+			'wait_list_registration' => array(
358
+				'func'       => 'wait_list_registration',
359
+				'noheader'   => true,
360
+				'capability' => 'ee_edit_registration',
361
+				'obj_id'     => $reg_id,
362
+			),
363
+			'contact_list'                       => array(
364
+				'func'       => '_attendee_contact_list_table',
365
+				'capability' => 'ee_read_contacts',
366
+			),
367
+			'add_new_attendee'                   => array(
368
+				'func' => '_create_new_cpt_item',
369
+				'args' => array(
370
+					'new_attendee' => true,
371
+					'capability'   => 'ee_edit_contacts',
372
+				),
373
+			),
374
+			'edit_attendee'                      => array(
375
+				'func'       => '_edit_cpt_item',
376
+				'capability' => 'ee_edit_contacts',
377
+				'obj_id'     => $att_id,
378
+			),
379
+			'duplicate_attendee'                 => array(
380
+				'func'       => '_duplicate_attendee',
381
+				'noheader'   => true,
382
+				'capability' => 'ee_edit_contacts',
383
+				'obj_id'     => $att_id,
384
+			),
385
+			'insert_attendee'                    => array(
386
+				'func'       => '_insert_or_update_attendee',
387
+				'args'       => array(
388
+					'new_attendee' => true,
389
+				),
390
+				'noheader'   => true,
391
+				'capability' => 'ee_edit_contacts',
392
+			),
393
+			'update_attendee'                    => array(
394
+				'func'       => '_insert_or_update_attendee',
395
+				'args'       => array(
396
+					'new_attendee' => false,
397
+				),
398
+				'noheader'   => true,
399
+				'capability' => 'ee_edit_contacts',
400
+				'obj_id'     => $att_id,
401
+			),
402
+			'trash_attendees' => array(
403
+				'func' => '_trash_or_restore_attendees',
404
+				'args' => array(
405
+					'trash' => 'true'
406
+				),
407
+				'noheader' => true,
408
+				'capability' => 'ee_delete_contacts'
409
+			),
410
+			'trash_attendee'                    => array(
411
+				'func'       => '_trash_or_restore_attendees',
412
+				'args'       => array(
413
+					'trash' => true,
414
+				),
415
+				'noheader'   => true,
416
+				'capability' => 'ee_delete_contacts',
417
+				'obj_id'     => $att_id,
418
+			),
419
+			'restore_attendees'                  => array(
420
+				'func'       => '_trash_or_restore_attendees',
421
+				'args'       => array(
422
+					'trash' => false,
423
+				),
424
+				'noheader'   => true,
425
+				'capability' => 'ee_delete_contacts',
426
+				'obj_id'     => $att_id,
427
+			),
428
+			'resend_registration'                => array(
429
+				'func'       => '_resend_registration',
430
+				'noheader'   => true,
431
+				'capability' => 'ee_send_message',
432
+			),
433
+			'registrations_report'               => array(
434
+				'func'       => '_registrations_report',
435
+				'noheader'   => true,
436
+				'capability' => 'ee_read_registrations',
437
+			),
438
+			'contact_list_export'                => array(
439
+				'func'       => '_contact_list_export',
440
+				'noheader'   => true,
441
+				'capability' => 'export',
442
+			),
443
+			'contact_list_report'                => array(
444
+				'func'       => '_contact_list_report',
445
+				'noheader'   => true,
446
+				'capability' => 'ee_read_contacts',
447
+			),
448
+		);
449
+	}
450
+
451
+
452
+	protected function _set_page_config()
453
+	{
454
+		$this->_page_config = array(
455
+			'default'           => array(
456
+				'nav'           => array(
457
+					'label' => esc_html__('Overview', 'event_espresso'),
458
+					'order' => 5,
459
+				),
460
+				'help_tabs'     => array(
461
+					'registrations_overview_help_tab'                       => array(
462
+						'title'    => esc_html__('Registrations Overview', 'event_espresso'),
463
+						'filename' => 'registrations_overview',
464
+					),
465
+					'registrations_overview_table_column_headings_help_tab' => array(
466
+						'title'    => esc_html__('Registrations Table Column Headings', 'event_espresso'),
467
+						'filename' => 'registrations_overview_table_column_headings',
468
+					),
469
+					'registrations_overview_filters_help_tab'               => array(
470
+						'title'    => esc_html__('Registration Filters', 'event_espresso'),
471
+						'filename' => 'registrations_overview_filters',
472
+					),
473
+					'registrations_overview_views_help_tab'                 => array(
474
+						'title'    => esc_html__('Registration Views', 'event_espresso'),
475
+						'filename' => 'registrations_overview_views',
476
+					),
477
+					'registrations_regoverview_other_help_tab'              => array(
478
+						'title'    => esc_html__('Registrations Other', 'event_espresso'),
479
+						'filename' => 'registrations_overview_other',
480
+					),
481
+				),
482
+				'help_tour'     => array('Registration_Overview_Help_Tour'),
483
+				'qtips'         => array('Registration_List_Table_Tips'),
484
+				'list_table'    => 'EE_Registrations_List_Table',
485
+				'require_nonce' => false,
486
+			),
487
+			'view_registration' => array(
488
+				'nav'           => array(
489
+					'label'      => esc_html__('REG Details', 'event_espresso'),
490
+					'order'      => 15,
491
+					'url'        => isset($this->_req_data['_REG_ID'])
492
+						? add_query_arg(array('_REG_ID' => $this->_req_data['_REG_ID']), $this->_current_page_view_url)
493
+						: $this->_admin_base_url,
494
+					'persistent' => false,
495
+				),
496
+				'help_tabs'     => array(
497
+					'registrations_details_help_tab'                    => array(
498
+						'title'    => esc_html__('Registration Details', 'event_espresso'),
499
+						'filename' => 'registrations_details',
500
+					),
501
+					'registrations_details_table_help_tab'              => array(
502
+						'title'    => esc_html__('Registration Details Table', 'event_espresso'),
503
+						'filename' => 'registrations_details_table',
504
+					),
505
+					'registrations_details_form_answers_help_tab'       => array(
506
+						'title'    => esc_html__('Registration Form Answers', 'event_espresso'),
507
+						'filename' => 'registrations_details_form_answers',
508
+					),
509
+					'registrations_details_registrant_details_help_tab' => array(
510
+						'title'    => esc_html__('Contact Details', 'event_espresso'),
511
+						'filename' => 'registrations_details_registrant_details',
512
+					),
513
+				),
514
+				'help_tour'     => array('Registration_Details_Help_Tour'),
515
+				'metaboxes'     => array_merge(
516
+					$this->_default_espresso_metaboxes,
517
+					array('_registration_details_metaboxes')
518
+				),
519
+				'require_nonce' => false,
520
+			),
521
+			'new_registration'  => array(
522
+				'nav'           => array(
523
+					'label'      => esc_html__('Add New Registration', 'event_espresso'),
524
+					'url'        => '#',
525
+					'order'      => 15,
526
+					'persistent' => false,
527
+				),
528
+				'metaboxes'     => $this->_default_espresso_metaboxes,
529
+				'labels'        => array(
530
+					'publishbox' => esc_html__('Save Registration', 'event_espresso'),
531
+				),
532
+				'require_nonce' => false,
533
+			),
534
+			'add_new_attendee'  => array(
535
+				'nav'           => array(
536
+					'label'      => esc_html__('Add Contact', 'event_espresso'),
537
+					'order'      => 15,
538
+					'persistent' => false,
539
+				),
540
+				'metaboxes'     => array_merge(
541
+					$this->_default_espresso_metaboxes,
542
+					array('_publish_post_box', 'attendee_editor_metaboxes')
543
+				),
544
+				'require_nonce' => false,
545
+			),
546
+			'edit_attendee'     => array(
547
+				'nav'           => array(
548
+					'label'      => esc_html__('Edit Contact', 'event_espresso'),
549
+					'order'      => 15,
550
+					'persistent' => false,
551
+					'url'        => isset($this->_req_data['ATT_ID'])
552
+						? add_query_arg(array('ATT_ID' => $this->_req_data['ATT_ID']), $this->_current_page_view_url)
553
+						: $this->_admin_base_url,
554
+				),
555
+				'metaboxes'     => array('attendee_editor_metaboxes'),
556
+				'require_nonce' => false,
557
+			),
558
+			'contact_list'      => array(
559
+				'nav'           => array(
560
+					'label' => esc_html__('Contact List', 'event_espresso'),
561
+					'order' => 20,
562
+				),
563
+				'list_table'    => 'EE_Attendee_Contact_List_Table',
564
+				'help_tabs'     => array(
565
+					'registrations_contact_list_help_tab'                       => array(
566
+						'title'    => esc_html__('Registrations Contact List', 'event_espresso'),
567
+						'filename' => 'registrations_contact_list',
568
+					),
569
+					'registrations_contact-list_table_column_headings_help_tab' => array(
570
+						'title'    => esc_html__('Contact List Table Column Headings', 'event_espresso'),
571
+						'filename' => 'registrations_contact_list_table_column_headings',
572
+					),
573
+					'registrations_contact_list_views_help_tab'                 => array(
574
+						'title'    => esc_html__('Contact List Views', 'event_espresso'),
575
+						'filename' => 'registrations_contact_list_views',
576
+					),
577
+					'registrations_contact_list_other_help_tab'                 => array(
578
+						'title'    => esc_html__('Contact List Other', 'event_espresso'),
579
+						'filename' => 'registrations_contact_list_other',
580
+					),
581
+				),
582
+				'help_tour'     => array('Contact_List_Help_Tour'),
583
+				'metaboxes'     => array(),
584
+				'require_nonce' => false,
585
+			),
586
+			//override default cpt routes
587
+			'create_new'        => '',
588
+			'edit'              => '',
589
+		);
590
+	}
591
+
592
+
593
+	/**
594
+	 * The below methods aren't used by this class currently
595
+	 */
596
+	protected function _add_screen_options()
597
+	{
598
+	}
599
+
600
+
601
+	protected function _add_feature_pointers()
602
+	{
603
+	}
604
+
605
+
606
+	public function admin_init()
607
+	{
608
+		EE_Registry::$i18n_js_strings['update_att_qstns'] = esc_html__(
609
+			'click "Update Registration Questions" to save your changes',
610
+			'event_espresso'
611
+		);
612
+	}
613
+
614
+
615
+	public function admin_notices()
616
+	{
617
+	}
618
+
619
+
620
+	public function admin_footer_scripts()
621
+	{
622
+	}
623
+
624
+
625
+	/**
626
+	 *        get list of registration statuses
627
+	 *
628
+	 * @access private
629
+	 * @return void
630
+	 */
631
+	private function _get_registration_status_array()
632
+	{
633
+		self::$_reg_status = EEM_Registration::reg_status_array(array(), true);
634
+	}
635
+
636
+
637
+	protected function _add_screen_options_default()
638
+	{
639
+		$this->_per_page_screen_option();
640
+	}
641
+
642
+
643
+	protected function _add_screen_options_contact_list()
644
+	{
645
+		$page_title              = $this->_admin_page_title;
646
+		$this->_admin_page_title = esc_html__("Contacts", 'event_espresso');
647
+		$this->_per_page_screen_option();
648
+		$this->_admin_page_title = $page_title;
649
+	}
650
+
651
+
652
+	public function load_scripts_styles()
653
+	{
654
+		//style
655
+		wp_register_style(
656
+			'espresso_reg',
657
+			REG_ASSETS_URL . 'espresso_registrations_admin.css',
658
+			array('ee-admin-css'),
659
+			EVENT_ESPRESSO_VERSION
660
+		);
661
+		wp_enqueue_style('espresso_reg');
662
+		//script
663
+		wp_register_script(
664
+			'espresso_reg',
665
+			REG_ASSETS_URL . 'espresso_registrations_admin.js',
666
+			array('jquery-ui-datepicker', 'jquery-ui-draggable', 'ee_admin_js'),
667
+			EVENT_ESPRESSO_VERSION,
668
+			true
669
+		);
670
+		wp_enqueue_script('espresso_reg');
671
+	}
672
+
673
+
674
+	public function load_scripts_styles_edit_attendee()
675
+	{
676
+		//stuff to only show up on our attendee edit details page.
677
+		$attendee_details_translations = array(
678
+			'att_publish_text' => sprintf(
679
+				esc_html__('Created on: <b>%1$s</b>', 'event_espresso'),
680
+				$this->_cpt_model_obj->get_datetime('ATT_created')
681
+			),
682
+		);
683
+		wp_localize_script('espresso_reg', 'ATTENDEE_DETAILS', $attendee_details_translations);
684
+		wp_enqueue_script('jquery-validate');
685
+	}
686
+
687
+
688
+	public function load_scripts_styles_view_registration()
689
+	{
690
+		//styles
691
+		wp_enqueue_style('espresso-ui-theme');
692
+		//scripts
693
+		$this->_get_reg_custom_questions_form($this->_registration->ID());
694
+		$this->_reg_custom_questions_form->wp_enqueue_scripts(true);
695
+	}
696
+
697
+
698
+	public function load_scripts_styles_contact_list()
699
+	{
700
+		wp_deregister_style('espresso_reg');
701
+		wp_register_style(
702
+			'espresso_att',
703
+			REG_ASSETS_URL . 'espresso_attendees_admin.css',
704
+			array('ee-admin-css'),
705
+			EVENT_ESPRESSO_VERSION
706
+		);
707
+		wp_enqueue_style('espresso_att');
708
+	}
709
+
710
+
711
+	public function load_scripts_styles_new_registration()
712
+	{
713
+		wp_register_script(
714
+			'ee-spco-for-admin',
715
+			REG_ASSETS_URL . 'spco_for_admin.js',
716
+			array('underscore', 'jquery'),
717
+			EVENT_ESPRESSO_VERSION,
718
+			true
719
+		);
720
+		wp_enqueue_script('ee-spco-for-admin');
721
+		add_filter('FHEE__EED_Ticket_Selector__load_tckt_slctr_assets', '__return_true');
722
+		EE_Form_Section_Proper::wp_enqueue_scripts();
723
+		EED_Ticket_Selector::load_tckt_slctr_assets();
724
+		EE_Datepicker_Input::enqueue_styles_and_scripts();
725
+	}
726
+
727
+
728
+	public function AHEE__EE_Admin_Page__route_admin_request_resend_registration()
729
+	{
730
+		add_filter('FHEE_load_EE_messages', '__return_true');
731
+	}
732
+
733
+
734
+	public function AHEE__EE_Admin_Page__route_admin_request_approve_registration()
735
+	{
736
+		add_filter('FHEE_load_EE_messages', '__return_true');
737
+	}
738
+
739
+
740
+	protected function _set_list_table_views_default()
741
+	{
742
+		//for notification related bulk actions we need to make sure only active messengers have an option.
743
+		EED_Messages::set_autoloaders();
744
+		/** @type EE_Message_Resource_Manager $message_resource_manager */
745
+		$message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
746
+		$active_mts               = $message_resource_manager->list_of_active_message_types();
747
+		//key= bulk_action_slug, value= message type.
748
+		$match_array = array(
749
+			'approve_registrations'    => 'registration',
750
+			'decline_registrations'    => 'declined_registration',
751
+			'pending_registrations'    => 'pending_approval',
752
+			'no_approve_registrations' => 'not_approved_registration',
753
+			'cancel_registrations'     => 'cancelled_registration',
754
+		);
755
+		$can_send = EE_Registry::instance()->CAP->current_user_can(
756
+			'ee_send_message',
757
+			'batch_send_messages'
758
+		);
759
+		/** setup reg status bulk actions **/
760
+		$def_reg_status_actions['approve_registrations'] = esc_html__('Approve Registrations', 'event_espresso');
761
+		if ($can_send && in_array($match_array['approve_registrations'], $active_mts, true)) {
762
+				$def_reg_status_actions['approve_and_notify_registrations'] = esc_html__(
763
+					'Approve and Notify Registrations',
764
+					'event_espresso'
765
+				);
766
+		}
767
+		$def_reg_status_actions['decline_registrations'] = esc_html__('Decline Registrations', 'event_espresso');
768
+		if ($can_send && in_array($match_array['decline_registrations'], $active_mts, true)) {
769
+				$def_reg_status_actions['decline_and_notify_registrations'] = esc_html__(
770
+					'Decline and Notify Registrations',
771
+					'event_espresso'
772
+				);
773
+		}
774
+		$def_reg_status_actions['pending_registrations'] = esc_html__(
775
+			'Set Registrations to Pending Payment',
776
+			'event_espresso'
777
+		);
778
+		if ($can_send && in_array($match_array['pending_registrations'], $active_mts, true)) {
779
+				$def_reg_status_actions['pending_and_notify_registrations'] = esc_html__(
780
+					'Set Registrations to Pending Payment and Notify',
781
+					'event_espresso'
782
+				);
783
+		}
784
+		$def_reg_status_actions['no_approve_registrations'] = esc_html__(
785
+			'Set Registrations to Not Approved',
786
+			'event_espresso'
787
+		);
788
+		if ($can_send && in_array($match_array['no_approve_registrations'], $active_mts, true)) {
789
+				$def_reg_status_actions['no_approve_and_notify_registrations'] = esc_html__(
790
+					'Set Registrations to Not Approved and Notify',
791
+					'event_espresso'
792
+				);
793
+		}
794
+		$def_reg_status_actions['cancel_registrations'] = esc_html__('Cancel Registrations', 'event_espresso');
795
+		if ($can_send && in_array($match_array['cancel_registrations'], $active_mts, true)) {
796
+				$def_reg_status_actions['cancel_and_notify_registrations'] = esc_html__(
797
+					'Cancel Registrations and Notify',
798
+					'event_espresso'
799
+				);
800
+		}
801
+		$def_reg_status_actions = apply_filters(
802
+			'FHEE__Registrations_Admin_Page___set_list_table_views_default__def_reg_status_actions_array',
803
+			$def_reg_status_actions,
804
+			$active_mts
805
+		);
806
+
807
+		$this->_views = array(
808
+			'all'   => array(
809
+				'slug'        => 'all',
810
+				'label'       => esc_html__('View All Registrations', 'event_espresso'),
811
+				'count'       => 0,
812
+				'bulk_action' => array_merge($def_reg_status_actions, array(
813
+					'trash_registrations' => esc_html__('Trash Registrations', 'event_espresso'),
814
+				)),
815
+			),
816
+			'month' => array(
817
+				'slug'        => 'month',
818
+				'label'       => esc_html__('This Month', 'event_espresso'),
819
+				'count'       => 0,
820
+				'bulk_action' => array_merge($def_reg_status_actions, array(
821
+					'trash_registrations' => esc_html__('Trash Registrations', 'event_espresso'),
822
+				)),
823
+			),
824
+			'today' => array(
825
+				'slug'        => 'today',
826
+				'label'       => sprintf(
827
+					esc_html__('Today - %s', 'event_espresso'),
828
+					date('M d, Y', current_time('timestamp'))
829
+				),
830
+				'count'       => 0,
831
+				'bulk_action' => array_merge($def_reg_status_actions, array(
832
+					'trash_registrations' => esc_html__('Trash Registrations', 'event_espresso'),
833
+				)),
834
+			),
835
+		);
836
+		if (EE_Registry::instance()->CAP->current_user_can(
837
+			'ee_delete_registrations',
838
+			'espresso_registrations_delete_registration'
839
+		)) {
840
+			$this->_views['incomplete'] = array(
841
+				'slug'        => 'incomplete',
842
+				'label'       => esc_html__('Incomplete', 'event_espresso'),
843
+				'count'       => 0,
844
+				'bulk_action' => array(
845
+					'trash_registrations' => esc_html__('Trash Registrations', 'event_espresso'),
846
+				),
847
+			);
848
+			$this->_views['trash']      = array(
849
+				'slug'        => 'trash',
850
+				'label'       => esc_html__('Trash', 'event_espresso'),
851
+				'count'       => 0,
852
+				'bulk_action' => array(
853
+					'restore_registrations' => esc_html__('Restore Registrations', 'event_espresso'),
854
+					'delete_registrations'  => esc_html__('Delete Registrations Permanently', 'event_espresso'),
855
+				),
856
+			);
857
+		}
858
+	}
859
+
860
+
861
+	protected function _set_list_table_views_contact_list()
862
+	{
863
+		$this->_views = array(
864
+			'in_use' => array(
865
+				'slug'        => 'in_use',
866
+				'label'       => esc_html__('In Use', 'event_espresso'),
867
+				'count'       => 0,
868
+				'bulk_action' => array(
869
+					'trash_attendees' => esc_html__('Move to Trash', 'event_espresso'),
870
+				),
871
+			),
872
+		);
873
+		if (EE_Registry::instance()->CAP->current_user_can('ee_delete_contacts',
874
+			'espresso_registrations_trash_attendees')
875
+		) {
876
+			$this->_views['trash'] = array(
877
+				'slug'        => 'trash',
878
+				'label'       => esc_html__('Trash', 'event_espresso'),
879
+				'count'       => 0,
880
+				'bulk_action' => array(
881
+					'restore_attendees' => esc_html__('Restore from Trash', 'event_espresso'),
882
+				),
883
+			);
884
+		}
885
+	}
886
+
887
+
888
+	protected function _registration_legend_items()
889
+	{
890
+		$fc_items = array(
891
+			'star-icon'        => array(
892
+				'class' => 'dashicons dashicons-star-filled lt-blue-icon ee-icon-size-8',
893
+				'desc'  => esc_html__('This is the Primary Registrant', 'event_espresso'),
894
+			),
895
+			'view_details'     => array(
896
+				'class' => 'dashicons dashicons-clipboard',
897
+				'desc'  => esc_html__('View Registration Details', 'event_espresso'),
898
+			),
899
+			'edit_attendee'    => array(
900
+				'class' => 'ee-icon ee-icon-user-edit ee-icon-size-16',
901
+				'desc'  => esc_html__('Edit Contact Details', 'event_espresso'),
902
+			),
903
+			'view_transaction' => array(
904
+				'class' => 'dashicons dashicons-cart',
905
+				'desc'  => esc_html__('View Transaction Details', 'event_espresso'),
906
+			),
907
+			'view_invoice'     => array(
908
+				'class' => 'dashicons dashicons-media-spreadsheet',
909
+				'desc'  => esc_html__('View Transaction Invoice', 'event_espresso'),
910
+			),
911
+		);
912
+		if (EE_Registry::instance()->CAP->current_user_can(
913
+			'ee_send_message',
914
+			'espresso_registrations_resend_registration'
915
+		)) {
916
+			$fc_items['resend_registration'] = array(
917
+				'class' => 'dashicons dashicons-email-alt',
918
+				'desc'  => esc_html__('Resend Registration Details', 'event_espresso'),
919
+			);
920
+		} else {
921
+			$fc_items['blank'] = array('class' => 'blank', 'desc' => '');
922
+		}
923
+		if (EE_Registry::instance()->CAP->current_user_can(
924
+			'ee_read_global_messages',
925
+			'view_filtered_messages'
926
+		)) {
927
+			$related_for_icon = EEH_MSG_Template::get_message_action_icon('see_notifications_for');
928
+			if (isset($related_for_icon['css_class']) && isset($related_for_icon['label'])) {
929
+				$fc_items['view_related_messages'] = array(
930
+					'class' => $related_for_icon['css_class'],
931
+					'desc'  => $related_for_icon['label'],
932
+				);
933
+			}
934
+		}
935
+		$sc_items = array(
936
+			'approved_status'   => array(
937
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_approved,
938
+				'desc'  => EEH_Template::pretty_status(
939
+					EEM_Registration::status_id_approved,
940
+					false,
941
+					'sentence'
942
+				),
943
+			),
944
+			'pending_status'    => array(
945
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_pending_payment,
946
+				'desc'  => EEH_Template::pretty_status(
947
+					EEM_Registration::status_id_pending_payment,
948
+					false,
949
+					'sentence'
950
+				),
951
+			),
952
+			'wait_list'         => array(
953
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_wait_list,
954
+				'desc'  => EEH_Template::pretty_status(
955
+					EEM_Registration::status_id_wait_list,
956
+					false,
957
+					'sentence'
958
+				),
959
+			),
960
+			'incomplete_status' => array(
961
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_incomplete,
962
+				'desc'  => EEH_Template::pretty_status(
963
+					EEM_Registration::status_id_incomplete,
964
+					false,
965
+					'sentence'
966
+				),
967
+			),
968
+			'not_approved'      => array(
969
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_not_approved,
970
+				'desc'  => EEH_Template::pretty_status(
971
+					EEM_Registration::status_id_not_approved,
972
+					false,
973
+					'sentence'
974
+				),
975
+			),
976
+			'declined_status'   => array(
977
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_declined,
978
+				'desc'  => EEH_Template::pretty_status(
979
+					EEM_Registration::status_id_declined,
980
+					false,
981
+					'sentence'
982
+				),
983
+			),
984
+			'cancelled_status'  => array(
985
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_cancelled,
986
+				'desc'  => EEH_Template::pretty_status(
987
+					EEM_Registration::status_id_cancelled,
988
+					false,
989
+					'sentence'
990
+				),
991
+			),
992
+		);
993
+		return array_merge($fc_items, $sc_items);
994
+	}
995
+
996
+
997
+
998
+	/***************************************        REGISTRATION OVERVIEW        **************************************/
999
+	/**
1000
+	 * @throws \EE_Error
1001
+	 */
1002
+	protected function _registrations_overview_list_table()
1003
+	{
1004
+		$this->_template_args['admin_page_header'] = '';
1005
+		$EVT_ID                                    = ! empty($this->_req_data['event_id'])
1006
+			? absint($this->_req_data['event_id'])
1007
+			: 0;
1008
+		if ($EVT_ID) {
1009
+			if (EE_Registry::instance()->CAP->current_user_can(
1010
+				'ee_edit_registrations',
1011
+				'espresso_registrations_new_registration',
1012
+				$EVT_ID
1013
+			)) {
1014
+				$this->_admin_page_title .= ' ' . $this->get_action_link_or_button(
1015
+					'new_registration',
1016
+					'add-registrant',
1017
+					array('event_id' => $EVT_ID),
1018
+					'add-new-h2'
1019
+				);
1020
+			}
1021
+			$event = EEM_Event::instance()->get_one_by_ID($EVT_ID);
1022
+			if ($event instanceof EE_Event) {
1023
+				$this->_template_args['admin_page_header'] = sprintf(
1024
+					esc_html__(
1025
+						'%s Viewing registrations for the event: %s%s',
1026
+						'event_espresso'
1027
+					),
1028
+					'<h3 style="line-height:1.5em;">',
1029
+					'<br /><a href="'
1030
+						. EE_Admin_Page::add_query_args_and_nonce(
1031
+							array(
1032
+								'action' => 'edit',
1033
+								'post'   => $event->ID(),
1034
+							),
1035
+							EVENTS_ADMIN_URL
1036
+						)
1037
+						. '">&nbsp;'
1038
+						. $event->get('EVT_name')
1039
+						. '&nbsp;</a>&nbsp;',
1040
+					'</h3>'
1041
+				);
1042
+			}
1043
+			$DTT_ID   = ! empty($this->_req_data['datetime_id']) ? absint($this->_req_data['datetime_id']) : 0;
1044
+			$datetime = EEM_Datetime::instance()->get_one_by_ID($DTT_ID);
1045
+			if ($datetime instanceof EE_Datetime && $this->_template_args['admin_page_header'] !== '') {
1046
+				$this->_template_args['admin_page_header'] = substr(
1047
+					$this->_template_args['admin_page_header'],
1048
+					0,
1049
+					-5
1050
+				);
1051
+				$this->_template_args['admin_page_header'] .= ' &nbsp;<span class="drk-grey-text">';
1052
+				$this->_template_args['admin_page_header'] .= '<span class="dashicons dashicons-calendar"></span>';
1053
+				$this->_template_args['admin_page_header'] .= $datetime->name();
1054
+				$this->_template_args['admin_page_header'] .= ' ( ' . $datetime->start_date() . ' )';
1055
+				$this->_template_args['admin_page_header'] .= '</span></h3>';
1056
+			}
1057
+		}
1058
+		$this->_template_args['after_list_table'] = $this->_display_legend($this->_registration_legend_items());
1059
+		$this->display_admin_list_table_page_with_no_sidebar();
1060
+	}
1061
+
1062
+
1063
+	/**
1064
+	 * This sets the _registration property for the registration details screen
1065
+	 *
1066
+	 * @access private
1067
+	 * @return bool
1068
+	 */
1069
+	private function _set_registration_object()
1070
+	{
1071
+		//get out if we've already set the object
1072
+		if (is_object($this->_registration)) {
1073
+			return true;
1074
+		}
1075
+		$REG    = EEM_Registration::instance();
1076
+		$REG_ID = ( ! empty($this->_req_data['_REG_ID'])) ? absint($this->_req_data['_REG_ID']) : false;
1077
+		if ($this->_registration = $REG->get_one_by_ID($REG_ID)) {
1078
+			return true;
1079
+		} else {
1080
+			$error_msg = sprintf(
1081
+				esc_html__(
1082
+					'An error occurred and the details for Registration ID #%s could not be retrieved.',
1083
+					'event_espresso'
1084
+				),
1085
+				$REG_ID
1086
+			);
1087
+			EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__);
1088
+			$this->_registration = null;
1089
+			return false;
1090
+		}
1091
+	}
1092
+
1093
+
1094
+	/**
1095
+	 * Used to retrieve registrations for the list table.
1096
+	 *
1097
+	 * @param int  $per_page
1098
+	 * @param bool $count
1099
+	 * @param bool $this_month
1100
+	 * @param bool $today
1101
+	 * @return EE_Registration[]|int
1102
+	 * @throws EE_Error
1103
+	 */
1104
+	public function get_registrations(
1105
+		$per_page = 10,
1106
+		$count = false,
1107
+		$this_month = false,
1108
+		$today = false
1109
+	) {
1110
+		if ($this_month) {
1111
+			$this->_req_data['status'] = 'month';
1112
+		}
1113
+		if ($today) {
1114
+			$this->_req_data['status'] = 'today';
1115
+		}
1116
+		$query_params = $this->_get_registration_query_parameters($this->_req_data, $per_page, $count);
1117
+		/**
1118
+		 * Override the default groupby added by EEM_Base so that sorts with multiple order bys work as expected
1119
+		 * @link https://events.codebasehq.com/projects/event-espresso/tickets/10093
1120
+		 * @see EEM_Base::get_all()
1121
+		 */
1122
+		$query_params['group_by'] = '';
1123
+
1124
+		return $count
1125
+			? EEM_Registration::instance()->count($query_params)
1126
+			/** @type EE_Registration[] */
1127
+			: EEM_Registration::instance()->get_all($query_params);
1128
+	}
1129
+
1130
+
1131
+
1132
+	/**
1133
+	 * Retrieves the query parameters to be used by the Registration model for getting registrations.
1134
+	 * Note: this listens to values on the request for some of the query parameters.
1135
+	 *
1136
+	 * @param array $request
1137
+	 * @param int    $per_page
1138
+	 * @param bool   $count
1139
+	 * @return array
1140
+	 */
1141
+	protected function _get_registration_query_parameters(
1142
+		$request = array(),
1143
+		$per_page = 10,
1144
+		$count = false
1145
+	) {
1146
+
1147
+		$query_params = array(
1148
+			0                          => $this->_get_where_conditions_for_registrations_query(
1149
+				$request
1150
+			),
1151
+			'caps'                     => EEM_Registration::caps_read_admin,
1152
+			'default_where_conditions' => 'this_model_only',
1153
+		);
1154
+		if (! $count) {
1155
+			$query_params = array_merge(
1156
+				$query_params,
1157
+				$this->_get_orderby_for_registrations_query(),
1158
+				$this->_get_limit($per_page)
1159
+			);
1160
+		}
1161
+
1162
+		return $query_params;
1163
+	}
1164
+
1165
+
1166
+	/**
1167
+	 * This will add EVT_ID to the provided $where array for EE model query parameters.
1168
+	 *
1169
+	 * @param array $request usually the same as $this->_req_data but not necessarily
1170
+	 * @return array
1171
+	 */
1172
+	protected function _add_event_id_to_where_conditions(array $request)
1173
+	{
1174
+		$where = array();
1175
+		if (! empty($request['event_id'])) {
1176
+			$where['EVT_ID'] = absint($request['event_id']);
1177
+		}
1178
+		return $where;
1179
+	}
1180
+
1181
+
1182
+	/**
1183
+	 * Adds category ID if it exists in the request to the where conditions for the registrations query.
1184
+	 *
1185
+	 * @param array $request usually the same as $this->_req_data but not necessarily
1186
+	 * @return array
1187
+	 */
1188
+	protected function _add_category_id_to_where_conditions(array $request)
1189
+	{
1190
+		$where = array();
1191
+		if (! empty($request['EVT_CAT']) && (int)$request['EVT_CAT'] !== -1) {
1192
+			$where['Event.Term_Taxonomy.term_id'] = absint($request['EVT_CAT']);
1193
+		}
1194
+		return $where;
1195
+	}
1196
+
1197
+
1198
+	/**
1199
+	 * Adds the datetime ID if it exists in the request to the where conditions for the registrations query.
1200
+	 *
1201
+	 * @param array $request usually the same as $this->_req_data but not necessarily
1202
+	 * @return array
1203
+	 */
1204
+	protected function _add_datetime_id_to_where_conditions(array $request)
1205
+	{
1206
+		$where = array();
1207
+		if (! empty($request['datetime_id'])) {
1208
+			$where['Ticket.Datetime.DTT_ID'] = absint($request['datetime_id']);
1209
+		}
1210
+		if (! empty($request['DTT_ID'])) {
1211
+			$where['Ticket.Datetime.DTT_ID'] = absint($request['DTT_ID']);
1212
+		}
1213
+		return $where;
1214
+	}
1215
+
1216
+
1217
+	/**
1218
+	 * Adds the correct registration status to the where conditions for the registrations query.
1219
+	 *
1220
+	 * @param array $request usually the same as $this->_req_data but not necessarily
1221
+	 * @return array
1222
+	 */
1223
+	protected function _add_registration_status_to_where_conditions(array $request)
1224
+	{
1225
+		$where = array();
1226
+		$view = EEH_Array::is_set($request, 'status', '');
1227
+		$registration_status = ! empty($request['_reg_status'])
1228
+			? sanitize_text_field($request['_reg_status'])
1229
+			: '';
1230
+
1231
+		/*
1232 1232
          * If filtering by registration status, then we show registrations matching that status.
1233 1233
          * If not filtering by specified status, then we show all registrations excluding incomplete registrations
1234 1234
          * UNLESS viewing trashed registrations.
1235 1235
          */
1236
-        if (! empty($registration_status)) {
1237
-            $where['STS_ID'] = $registration_status;
1238
-        } else {
1239
-            //make sure we exclude incomplete registrations, but only if not trashed.
1240
-            if ($view === 'trash') {
1241
-                $where['REG_deleted'] = true;
1242
-            } elseif ($view === 'incomplete') {
1243
-                $where['STS_ID'] = EEM_Registration::status_id_incomplete;
1244
-            } else {
1245
-                $where['STS_ID'] = array('!=', EEM_Registration::status_id_incomplete);
1246
-            }
1247
-        }
1248
-        return $where;
1249
-    }
1250
-
1251
-
1252
-    /**
1253
-     * Adds any provided date restraints to the where conditions for the registrations query.
1254
-     *
1255
-     * @param array $request usually the same as $this->_req_data but not necessarily
1256
-     * @return array
1257
-     * @throws EE_Error
1258
-     */
1259
-    protected function _add_date_to_where_conditions(array $request)
1260
-    {
1261
-        $where = array();
1262
-        $view = EEH_Array::is_set($request, 'status', '');
1263
-        $month_range             = ! empty($request['month_range'])
1264
-            ? sanitize_text_field($request['month_range'])
1265
-            : '';
1266
-        $retrieve_for_today      = $view === 'today';
1267
-        $retrieve_for_this_month = $view === 'month';
1268
-
1269
-        if ($retrieve_for_today) {
1270
-            $now               = date('Y-m-d', current_time('timestamp'));
1271
-            $where['REG_date'] = array(
1272
-                'BETWEEN',
1273
-                array(
1274
-                    EEM_Registration::instance()->convert_datetime_for_query(
1275
-                        'REG_date',
1276
-                        $now . ' 00:00:00',
1277
-                        'Y-m-d H:i:s'
1278
-                    ),
1279
-                    EEM_Registration::instance()->convert_datetime_for_query(
1280
-                        'REG_date',
1281
-                        $now . ' 23:59:59',
1282
-                        'Y-m-d H:i:s'
1283
-                    ),
1284
-                ),
1285
-            );
1286
-        } elseif ($retrieve_for_this_month) {
1287
-            $current_year_and_month = date('Y-m', current_time('timestamp'));
1288
-            $days_this_month        = date('t', current_time('timestamp'));
1289
-            $where['REG_date']      = array(
1290
-                'BETWEEN',
1291
-                array(
1292
-                    EEM_Registration::instance()->convert_datetime_for_query(
1293
-                        'REG_date',
1294
-                        $current_year_and_month . '-01 00:00:00',
1295
-                        'Y-m-d H:i:s'
1296
-                    ),
1297
-                    EEM_Registration::instance()->convert_datetime_for_query(
1298
-                        'REG_date',
1299
-                        $current_year_and_month . '-' . $days_this_month . ' 23:59:59',
1300
-                        'Y-m-d H:i:s'
1301
-                    ),
1302
-                ),
1303
-            );
1304
-        } elseif ($month_range) {
1305
-            $pieces          = explode(' ', $month_range, 3);
1306
-            $month_requested = ! empty($pieces[0])
1307
-                ? date('m', \EEH_DTT_Helper::first_of_month_timestamp($pieces[0]))
1308
-                : '';
1309
-            $year_requested  = ! empty($pieces[1])
1310
-                ? $pieces[1]
1311
-                : '';
1312
-            //if there is not a month or year then we can't go further
1313
-            if ($month_requested && $year_requested) {
1314
-                $days_in_month     = date('t', strtotime($year_requested . '-' . $month_requested . '-' . '01'));
1315
-                $where['REG_date'] = array(
1316
-                    'BETWEEN',
1317
-                    array(
1318
-                        EEM_Registration::instance()->convert_datetime_for_query(
1319
-                            'REG_date',
1320
-                            $year_requested . '-' . $month_requested . '-01 00:00:00',
1321
-                            'Y-m-d H:i:s'
1322
-                        ),
1323
-                        EEM_Registration::instance()->convert_datetime_for_query(
1324
-                            'REG_date',
1325
-                            $year_requested . '-' . $month_requested . '-' . $days_in_month . ' 23:59:59',
1326
-                            'Y-m-d H:i:s'
1327
-                        ),
1328
-                    ),
1329
-                );
1330
-            }
1331
-        }
1332
-        return $where;
1333
-    }
1334
-
1335
-
1336
-    /**
1337
-     * Adds any provided search restraints to the where conditions for the registrations query
1338
-     *
1339
-     * @param array $request usually the same as $this->_req_data but not necessarily
1340
-     * @return array
1341
-     */
1342
-    protected function _add_search_to_where_conditions(array $request)
1343
-    {
1344
-        $where = array();
1345
-        if (! empty($request['s'])) {
1346
-            $search_string = '%' . sanitize_text_field($request['s']) . '%';
1347
-            $where['OR*search_conditions'] = array(
1348
-                'Event.EVT_name'                          => array('LIKE', $search_string),
1349
-                'Event.EVT_desc'                          => array('LIKE', $search_string),
1350
-                'Event.EVT_short_desc'                    => array('LIKE', $search_string),
1351
-                'Attendee.ATT_full_name'                  => array('LIKE', $search_string),
1352
-                'Attendee.ATT_fname'                      => array('LIKE', $search_string),
1353
-                'Attendee.ATT_lname'                      => array('LIKE', $search_string),
1354
-                'Attendee.ATT_short_bio'                  => array('LIKE', $search_string),
1355
-                'Attendee.ATT_email'                      => array('LIKE', $search_string),
1356
-                'Attendee.ATT_address'                    => array('LIKE', $search_string),
1357
-                'Attendee.ATT_address2'                   => array('LIKE', $search_string),
1358
-                'Attendee.ATT_city'                       => array('LIKE', $search_string),
1359
-                'REG_final_price'                         => array('LIKE', $search_string),
1360
-                'REG_code'                                => array('LIKE', $search_string),
1361
-                'REG_count'                               => array('LIKE', $search_string),
1362
-                'REG_group_size'                          => array('LIKE', $search_string),
1363
-                'Ticket.TKT_name'                         => array('LIKE', $search_string),
1364
-                'Ticket.TKT_description'                  => array('LIKE', $search_string),
1365
-                'Transaction.Payment.PAY_txn_id_chq_nmbr' => array('LIKE', $search_string),
1366
-            );
1367
-        }
1368
-        return $where;
1369
-    }
1370
-
1371
-
1372
-    /**
1373
-     * Sets up the where conditions for the registrations query.
1374
-     *
1375
-     * @param array $request
1376
-     * @return array
1377
-     * @throws EE_Error
1378
-     */
1379
-    protected function _get_where_conditions_for_registrations_query($request)
1380
-    {
1381
-        return apply_filters(
1382
-            'FHEE__Registrations_Admin_Page___get_where_conditions_for_registrations_query',
1383
-            array_merge(
1384
-                $this->_add_event_id_to_where_conditions($request),
1385
-                $this->_add_category_id_to_where_conditions($request),
1386
-                $this->_add_datetime_id_to_where_conditions($request),
1387
-                $this->_add_registration_status_to_where_conditions($request),
1388
-                $this->_add_date_to_where_conditions($request),
1389
-                $this->_add_search_to_where_conditions($request)
1390
-            ),
1391
-            $request
1392
-        );
1393
-    }
1394
-
1395
-
1396
-    /**
1397
-     * Sets up the orderby for the registrations query.
1398
-     *
1399
-     * @return array
1400
-     */
1401
-    protected function _get_orderby_for_registrations_query()
1402
-    {
1403
-        $orderby_field = ! empty($this->_req_data['orderby'])
1404
-            ? sanitize_text_field($this->_req_data['orderby'])
1405
-            : '';
1406
-        switch ($orderby_field) {
1407
-            case '_REG_ID':
1408
-                $orderby_field = 'REG_ID';
1409
-                break;
1410
-            case '_Reg_status':
1411
-                $orderby_field = 'STS_ID';
1412
-                break;
1413
-            case 'ATT_fname':
1414
-                $orderby_field = array('Attendee.ATT_fname', 'Attendee.ATT_lname');
1415
-                break;
1416
-            case 'ATT_lname':
1417
-                $orderby_field = array('Attendee.ATT_lname', 'Attendee.ATT_fname');
1418
-                break;
1419
-            case 'event_name':
1420
-                $orderby_field = 'Event.EVT_name';
1421
-                break;
1422
-            case 'DTT_EVT_start':
1423
-                $orderby_field = 'Event.Datetime.DTT_EVT_start';
1424
-                break;
1425
-            default: //'REG_date'
1426
-                $orderby_field = 'REG_date';
1427
-        }
1428
-
1429
-        //order
1430
-        $order = ! empty($this->_req_data['order'])
1431
-            ? sanitize_text_field($this->_req_data['order'])
1432
-            : 'DESC';
1433
-
1434
-        //mutate orderby_field
1435
-        $orderby_field = array_combine(
1436
-            (array) $orderby_field,
1437
-            array_fill(0, count($orderby_field), $order)
1438
-        );
1439
-        return array('order_by' => $orderby_field);
1440
-    }
1441
-
1442
-
1443
-    /**
1444
-     * Sets up the limit for the registrations query.
1445
-     *
1446
-     * @param $per_page
1447
-     * @return array
1448
-     */
1449
-    protected function _get_limit($per_page)
1450
-    {
1451
-        $current_page = ! empty($this->_req_data['paged'])
1452
-            ? absint($this->_req_data['paged'])
1453
-            : 1;
1454
-        $per_page     = ! empty($this->_req_data['perpage'])
1455
-            ? $this->_req_data['perpage']
1456
-            : $per_page;
1457
-
1458
-        //-1 means return all results so get out if that's set.
1459
-        if ((int)$per_page === -1) {
1460
-            return array();
1461
-        }
1462
-        $per_page = absint($per_page);
1463
-        $offset   = ($current_page - 1) * $per_page;
1464
-        return array('limit' => array($offset, $per_page));
1465
-    }
1466
-
1467
-
1468
-    public function get_registration_status_array()
1469
-    {
1470
-        return self::$_reg_status;
1471
-    }
1472
-
1473
-
1474
-
1475
-
1476
-    /***************************************        REGISTRATION DETAILS        ***************************************/
1477
-    /**
1478
-     *        generates HTML for the View Registration Details Admin page
1479
-     *
1480
-     * @access protected
1481
-     * @return void
1482
-     * @throws DomainException
1483
-     * @throws EE_Error
1484
-     * @throws \EventEspresso\core\exceptions\EntityNotFoundException
1485
-     */
1486
-    protected function _registration_details()
1487
-    {
1488
-        $this->_template_args = array();
1489
-        $this->_set_registration_object();
1490
-        if (is_object($this->_registration)) {
1491
-            $transaction                                   = $this->_registration->transaction()
1492
-                ? $this->_registration->transaction()
1493
-                : EE_Transaction::new_instance();
1494
-            $this->_session                                = $transaction->session_data();
1495
-            $event_id                                      = $this->_registration->event_ID();
1496
-            $this->_template_args['reg_nmbr']['value']     = $this->_registration->ID();
1497
-            $this->_template_args['reg_nmbr']['label']     = esc_html__('Registration Number', 'event_espresso');
1498
-            $this->_template_args['reg_datetime']['value'] = $this->_registration->get_i18n_datetime('REG_date');
1499
-            $this->_template_args['reg_datetime']['label'] = esc_html__('Date', 'event_espresso');
1500
-            $this->_template_args['grand_total']           = $transaction->total();
1501
-            $this->_template_args['currency_sign']         = EE_Registry::instance()->CFG->currency->sign;
1502
-            // link back to overview
1503
-            $this->_template_args['reg_overview_url']            = REG_ADMIN_URL;
1504
-            $this->_template_args['registration']                = $this->_registration;
1505
-            $this->_template_args['filtered_registrations_link'] = EE_Admin_Page::add_query_args_and_nonce(
1506
-                array(
1507
-                    'action'   => 'default',
1508
-                    'event_id' => $event_id,
1509
-                ),
1510
-                REG_ADMIN_URL
1511
-            );
1512
-            $this->_template_args['filtered_transactions_link']  = EE_Admin_Page::add_query_args_and_nonce(
1513
-                array(
1514
-                    'action' => 'default',
1515
-                    'EVT_ID' => $event_id,
1516
-                    'page'   => 'espresso_transactions',
1517
-                ),
1518
-                admin_url('admin.php')
1519
-            );
1520
-            $this->_template_args['event_link']                  = EE_Admin_Page::add_query_args_and_nonce(
1521
-                array(
1522
-                    'page'   => 'espresso_events',
1523
-                    'action' => 'edit',
1524
-                    'post'   => $event_id,
1525
-                ),
1526
-                admin_url('admin.php')
1527
-            );
1528
-            //next and previous links
1529
-            $next_reg                                      = $this->_registration->next(
1530
-                null,
1531
-                array(),
1532
-                'REG_ID'
1533
-            );
1534
-            $this->_template_args['next_registration']     = $next_reg
1535
-                ? $this->_next_link(
1536
-                    EE_Admin_Page::add_query_args_and_nonce(
1537
-                        array(
1538
-                            'action'  => 'view_registration',
1539
-                            '_REG_ID' => $next_reg['REG_ID'],
1540
-                        ),
1541
-                        REG_ADMIN_URL
1542
-                    ),
1543
-                    'dashicons dashicons-arrow-right ee-icon-size-22'
1544
-                )
1545
-                : '';
1546
-            $previous_reg                                  = $this->_registration->previous(
1547
-                null,
1548
-                array(),
1549
-                'REG_ID'
1550
-            );
1551
-            $this->_template_args['previous_registration'] = $previous_reg
1552
-                ? $this->_previous_link(
1553
-                    EE_Admin_Page::add_query_args_and_nonce(
1554
-                        array(
1555
-                            'action'  => 'view_registration',
1556
-                            '_REG_ID' => $previous_reg['REG_ID'],
1557
-                        ),
1558
-                        REG_ADMIN_URL
1559
-                    ),
1560
-                    'dashicons dashicons-arrow-left ee-icon-size-22'
1561
-                )
1562
-                : '';
1563
-            // grab header
1564
-            $template_path                             = REG_TEMPLATE_PATH . 'reg_admin_details_header.template.php';
1565
-            $this->_template_args['REG_ID']            = $this->_registration->ID();
1566
-            $this->_template_args['admin_page_header'] = EEH_Template::display_template(
1567
-                $template_path,
1568
-                $this->_template_args,
1569
-                true
1570
-            );
1571
-        } else {
1572
-            $this->_template_args['admin_page_header'] = $this->display_espresso_notices();
1573
-        }
1574
-        // the details template wrapper
1575
-        $this->display_admin_page_with_sidebar();
1576
-    }
1577
-
1578
-
1579
-    protected function _registration_details_metaboxes()
1580
-    {
1581
-        do_action('AHEE__Registrations_Admin_Page___registration_details_metabox__start', $this);
1582
-        $this->_set_registration_object();
1583
-        $attendee = $this->_registration instanceof EE_Registration ? $this->_registration->attendee() : null;
1584
-        add_meta_box('edit-reg-status-mbox', esc_html__('Registration Status', 'event_espresso'),
1585
-            array($this, 'set_reg_status_buttons_metabox'), $this->wp_page_slug, 'normal', 'high');
1586
-        add_meta_box('edit-reg-details-mbox', esc_html__('Registration Details', 'event_espresso'),
1587
-            array($this, '_reg_details_meta_box'), $this->wp_page_slug, 'normal', 'high');
1588
-        if ($attendee instanceof EE_Attendee
1589
-            && EE_Registry::instance()->CAP->current_user_can(
1590
-                'ee_edit_registration',
1591
-                'edit-reg-questions-mbox',
1592
-                $this->_registration->ID()
1593
-            )
1594
-        ) {
1595
-            add_meta_box(
1596
-                'edit-reg-questions-mbox',
1597
-                esc_html__('Registration Form Answers', 'event_espresso'),
1598
-                array($this, '_reg_questions_meta_box'),
1599
-                $this->wp_page_slug,
1600
-                'normal',
1601
-                'high'
1602
-            );
1603
-        }
1604
-        add_meta_box(
1605
-            'edit-reg-registrant-mbox',
1606
-            esc_html__('Contact Details', 'event_espresso'),
1607
-            array($this, '_reg_registrant_side_meta_box'),
1608
-            $this->wp_page_slug,
1609
-            'side',
1610
-            'high'
1611
-        );
1612
-        if ($this->_registration->group_size() > 1) {
1613
-            add_meta_box(
1614
-                'edit-reg-attendees-mbox',
1615
-                esc_html__('Other Registrations in this Transaction', 'event_espresso'),
1616
-                array($this, '_reg_attendees_meta_box'),
1617
-                $this->wp_page_slug,
1618
-                'normal',
1619
-                'high'
1620
-            );
1621
-        }
1622
-    }
1623
-
1624
-
1625
-    /**
1626
-     * set_reg_status_buttons_metabox
1627
-     *
1628
-     * @access protected
1629
-     * @return string
1630
-     * @throws \EE_Error
1631
-     */
1632
-    public function set_reg_status_buttons_metabox()
1633
-    {
1634
-        $this->_set_registration_object();
1635
-        $change_reg_status_form = $this->_generate_reg_status_change_form();
1636
-        echo $change_reg_status_form->form_open(
1637
-            self::add_query_args_and_nonce(
1638
-                array(
1639
-                    'action' => 'change_reg_status',
1640
-                ),
1641
-                REG_ADMIN_URL
1642
-            )
1643
-        );
1644
-        echo $change_reg_status_form->get_html();
1645
-        echo $change_reg_status_form->form_close();
1646
-    }
1647
-
1648
-
1649
-
1650
-    /**
1651
-     * @return EE_Form_Section_Proper
1652
-     * @throws EE_Error
1653
-     */
1654
-    protected function _generate_reg_status_change_form()
1655
-    {
1656
-        return new EE_Form_Section_Proper(array(
1657
-            'name'            => 'reg_status_change_form',
1658
-            'html_id'         => 'reg-status-change-form',
1659
-            'layout_strategy' => new EE_Admin_Two_Column_Layout(),
1660
-            'subsections'     => array(
1661
-                'return'             => new EE_Hidden_Input(array(
1662
-                    'name'    => 'return',
1663
-                    'default' => 'view_registration',
1664
-                )),
1665
-                'REG_ID'             => new EE_Hidden_Input(array(
1666
-                    'name'    => 'REG_ID',
1667
-                    'default' => $this->_registration->ID(),
1668
-                )),
1669
-                'current_status'     => new EE_Form_Section_HTML(
1670
-                    EEH_HTML::tr(
1671
-                        EEH_HTML::th(
1672
-                            EEH_HTML::label(
1673
-                                EEH_HTML::strong(esc_html__('Current Registration Status', 'event_espresso')
1674
-                                )
1675
-                            )
1676
-                        )
1677
-                        . EEH_HTML::td(
1678
-                            EEH_HTML::strong(
1679
-                                $this->_registration->pretty_status(),
1680
-                                '',
1681
-                                'status-' . $this->_registration->status_ID(),
1682
-                                'line-height: 1em; font-size: 1.5em; font-weight: bold;'
1683
-                            )
1684
-                        )
1685
-                    )
1686
-                ),
1687
-                'reg_status'         => new EE_Select_Input(
1688
-                    $this->_get_reg_statuses(),
1689
-                    array(
1690
-                        'html_label_text' => esc_html__('Change Registration Status to', 'event_espresso'),
1691
-                        'default'         => $this->_registration->status_ID(),
1692
-                    )
1693
-                ),
1694
-                'send_notifications' => new EE_Yes_No_Input(
1695
-                    array(
1696
-                        'html_label_text' => esc_html__('Send Related Messages', 'event_espresso'),
1697
-                        'default'         => false,
1698
-                        'html_help_text'  => esc_html__(
1699
-                            'If set to "Yes", then the related messages will be sent to the registrant.',
1700
-                            'event_espresso'
1701
-                        ),
1702
-                    )
1703
-                ),
1704
-                'submit'             => new EE_Submit_Input(
1705
-                    array(
1706
-                        'html_class'      => 'button-primary',
1707
-                        'html_label_text' => '&nbsp;',
1708
-                        'default'         => esc_html__('Update Registration Status', 'event_espresso'),
1709
-                    )
1710
-                ),
1711
-            ),
1712
-        ));
1713
-    }
1714
-
1715
-
1716
-    /**
1717
-     * Returns an array of all the buttons for the various statuses and switch status actions
1718
-     *
1719
-     * @return array
1720
-     * @throws EE_Error
1721
-     * @throws \EventEspresso\core\exceptions\EntityNotFoundException
1722
-     */
1723
-    protected function _get_reg_statuses()
1724
-    {
1725
-        $reg_status_array = EEM_Registration::instance()->reg_status_array();
1726
-        unset ($reg_status_array[EEM_Registration::status_id_incomplete]);
1727
-        // get current reg status
1728
-        $current_status = $this->_registration->status_ID();
1729
-        // is registration for free event? This will determine whether to display the pending payment option
1730
-        if (
1731
-            $current_status !== EEM_Registration::status_id_pending_payment
1732
-            && $this->_registration->transaction()->is_free()
1733
-        ) {
1734
-            unset($reg_status_array[EEM_Registration::status_id_pending_payment]);
1735
-        }
1736
-        return EEM_Status::instance()->localized_status($reg_status_array, false, 'sentence');
1737
-    }
1738
-
1739
-
1740
-
1741
-    /**
1742
-     * This method is used when using _REG_ID from request which may or may not be an array of reg_ids.
1743
-     *
1744
-     * @param bool $status REG status given for changing registrations to.
1745
-     * @param bool $notify Whether to send messages notifications or not.
1746
-     * @return array  (array with reg_id(s) updated and whether update was successful.
1747
-     * @throws \EE_Error
1748
-     */
1749
-    protected function _set_registration_status_from_request($status = false, $notify = false)
1750
-    {
1751
-        if (isset($this->_req_data['reg_status_change_form'])) {
1752
-            $REG_IDs = isset($this->_req_data['reg_status_change_form']['REG_ID'])
1753
-                ? (array)$this->_req_data['reg_status_change_form']['REG_ID'] : array();
1754
-        } else {
1755
-            $REG_IDs = isset($this->_req_data['_REG_ID']) ? (array)$this->_req_data['_REG_ID'] : array();
1756
-        }
1757
-        $success = $this->_set_registration_status($REG_IDs, $status);
1758
-        //notify?
1759
-        if ($success
1760
-            && $notify
1761
-            && EE_Registry::instance()->CAP->current_user_can(
1762
-                'ee_send_message',
1763
-                'espresso_registrations_resend_registration'
1764
-            )
1765
-        ) {
1766
-            $this->_process_resend_registration();
1767
-        }
1768
-        return $success;
1769
-    }
1770
-
1771
-
1772
-
1773
-    /**
1774
-     * Set the registration status for the given reg_id (which may or may not be an array, it gets typecast to an
1775
-     * array). Note, this method does NOT take care of possible notifications.  That is required by calling code.
1776
-     *
1777
-     * @param array $REG_IDs
1778
-     * @param bool  $status
1779
-     * @return array (an array with 'success' key representing whether status change was successful, and 'REG_ID' as
1780
-     * @throws \RuntimeException
1781
-     * @throws \EE_Error
1782
-     *               the array of updated registrations).
1783
-     * @throws EE_Error
1784
-     * @throws RuntimeException
1785
-     */
1786
-    protected function _set_registration_status($REG_IDs = array(), $status = false)
1787
-    {
1788
-        $success = false;
1789
-        // typecast $REG_IDs
1790
-        $REG_IDs = (array)$REG_IDs;
1791
-        if ( ! empty($REG_IDs)) {
1792
-            $success = true;
1793
-            // set default status if none is passed
1794
-            $status = $status ? $status : EEM_Registration::status_id_pending_payment;
1795
-            // sanitize $REG_IDs
1796
-            $REG_IDs = array_filter($REG_IDs, 'absint');
1797
-            //loop through REG_ID's and change status
1798
-            foreach ($REG_IDs as $REG_ID) {
1799
-                $registration = EEM_Registration::instance()->get_one_by_ID($REG_ID);
1800
-                if ($registration instanceof EE_Registration) {
1801
-                    $registration->set_status($status);
1802
-                    $result = $registration->save();
1803
-                    // verifying explicit fails because update *may* just return 0 for 0 rows affected
1804
-                    $success = $result !== false ? $success : false;
1805
-                }
1806
-            }
1807
-        }
1808
-        //reset _req_data['_REG_ID'] for any potential future messages notifications
1809
-        $this->_req_data['_REG_ID'] = $REG_IDs;
1810
-        //return $success and processed registrations
1811
-        return array('REG_ID' => $REG_IDs, 'success' => $success);
1812
-    }
1813
-
1814
-
1815
-    /**
1816
-     * Common logic for setting up success message and redirecting to appropriate route
1817
-     *
1818
-     * @param  string $STS_ID status id for the registration changed to
1819
-     * @param   bool  $notify indicates whether the _set_registration_status_from_request does notifications or not.
1820
-     * @return void
1821
-     */
1822
-    protected function _reg_status_change_return($STS_ID, $notify = false)
1823
-    {
1824
-        $result  = ! empty($STS_ID) ? $this->_set_registration_status_from_request($STS_ID, $notify)
1825
-            : array('success' => false);
1826
-        $success = isset($result['success']) && $result['success'];
1827
-        //setup success message
1828
-        if ($success) {
1829
-            if (is_array($result['REG_ID']) && count($result['REG_ID']) === 1) {
1830
-                $msg = sprintf(esc_html__('Registration status has been set to %s', 'event_espresso'),
1831
-                    EEH_Template::pretty_status($STS_ID, false, 'lower'));
1832
-            } else {
1833
-                $msg = sprintf(esc_html__('Registrations have been set to %s.', 'event_espresso'),
1834
-                    EEH_Template::pretty_status($STS_ID, false, 'lower'));
1835
-            }
1836
-            EE_Error::add_success($msg);
1837
-        } else {
1838
-            EE_Error::add_error(
1839
-                esc_html__(
1840
-                    'Something went wrong, and the status was not changed',
1841
-                    'event_espresso'
1842
-                ), __FILE__, __LINE__, __FUNCTION__
1843
-            );
1844
-        }
1845
-        if (isset($this->_req_data['return']) && $this->_req_data['return'] == 'view_registration') {
1846
-            $route = array('action' => 'view_registration', '_REG_ID' => reset($result['REG_ID']));
1847
-        } else {
1848
-            $route = array('action' => 'default');
1849
-        }
1850
-        //unset nonces
1851
-        foreach ($this->_req_data as $ref => $value) {
1852
-            if (strpos($ref, 'nonce') !== false) {
1853
-                unset($this->_req_data[$ref]);
1854
-                continue;
1855
-            }
1856
-            $value                 = is_array($value) ? array_map('urlencode', $value) : urlencode($value);
1857
-            $this->_req_data[$ref] = $value;
1858
-        }
1859
-        //merge request vars so that the reloaded list table contains any existing filter query params
1860
-        $route = array_merge($this->_req_data, $route);
1861
-        $this->_redirect_after_action($success, '', '', $route, true);
1862
-    }
1863
-
1864
-
1865
-    /**
1866
-     * incoming reg status change from reg details page.
1867
-     *
1868
-     * @return void
1869
-     */
1870
-    protected function _change_reg_status()
1871
-    {
1872
-        $this->_req_data['return'] = 'view_registration';
1873
-        //set notify based on whether the send notifications toggle is set or not
1874
-        $notify = ! empty($this->_req_data['reg_status_change_form']['send_notifications']);
1875
-        //$notify = ! empty( $this->_req_data['txn_reg_status_change']['send_notifications'] );
1876
-        $this->_req_data['reg_status_change_form']['reg_status'] = isset($this->_req_data['reg_status_change_form']['reg_status'])
1877
-            ? $this->_req_data['reg_status_change_form']['reg_status'] : '';
1878
-        switch ($this->_req_data['reg_status_change_form']['reg_status']) {
1879
-            case EEM_Registration::status_id_approved :
1880
-            case EEH_Template::pretty_status(EEM_Registration::status_id_approved, false, 'sentence') :
1881
-                $this->approve_registration($notify);
1882
-                break;
1883
-            case EEM_Registration::status_id_pending_payment :
1884
-            case EEH_Template::pretty_status(EEM_Registration::status_id_pending_payment, false, 'sentence') :
1885
-                $this->pending_registration($notify);
1886
-                break;
1887
-            case EEM_Registration::status_id_not_approved :
1888
-            case EEH_Template::pretty_status(EEM_Registration::status_id_not_approved, false, 'sentence') :
1889
-                $this->not_approve_registration($notify);
1890
-                break;
1891
-            case EEM_Registration::status_id_declined :
1892
-            case EEH_Template::pretty_status(EEM_Registration::status_id_declined, false, 'sentence') :
1893
-                $this->decline_registration($notify);
1894
-                break;
1895
-            case EEM_Registration::status_id_cancelled :
1896
-            case EEH_Template::pretty_status(EEM_Registration::status_id_cancelled, false, 'sentence') :
1897
-                $this->cancel_registration($notify);
1898
-                break;
1899
-            case EEM_Registration::status_id_wait_list :
1900
-            case EEH_Template::pretty_status(EEM_Registration::status_id_wait_list, false, 'sentence') :
1901
-                $this->wait_list_registration($notify);
1902
-                break;
1903
-            case EEM_Registration::status_id_incomplete :
1904
-            default :
1905
-                $result['success'] = false;
1906
-                unset($this->_req_data['return']);
1907
-                $this->_reg_status_change_return('', false);
1908
-                break;
1909
-        }
1910
-    }
1911
-
1912
-
1913
-    /**
1914
-     * Callback for bulk action routes.
1915
-     * Note: although we could just register the singular route callbacks for each bulk action route as well, this
1916
-     * method was chosen so there is one central place all the registration status bulk actions are going through.
1917
-     * Potentially, this provides an easier place to locate logic that is specific to these bulk actions (as opposed to
1918
-     * when an action is happening on just a single registration).
1919
-     * @param      $action
1920
-     * @param bool $notify
1921
-     */
1922
-    protected function bulk_action_on_registrations($action, $notify = false) {
1923
-        do_action(
1924
-            'AHEE__Registrations_Admin_Page__bulk_action_on_registrations__before_execution',
1925
-            $this,
1926
-            $action,
1927
-            $notify
1928
-        );
1929
-        $method = $action . '_registration';
1930
-        if (method_exists($this, $method)) {
1931
-            $this->$method($notify);
1932
-        }
1933
-    }
1934
-
1935
-
1936
-    /**
1937
-     * approve_registration
1938
-     *
1939
-     * @access protected
1940
-     * @param bool $notify whether or not to notify the registrant about their approval.
1941
-     * @return void
1942
-     */
1943
-    protected function approve_registration($notify = false)
1944
-    {
1945
-        $this->_reg_status_change_return(EEM_Registration::status_id_approved, $notify);
1946
-    }
1947
-
1948
-
1949
-    /**
1950
-     *        decline_registration
1951
-     *
1952
-     * @access protected
1953
-     * @param bool $notify whether or not to notify the registrant about their status change.
1954
-     * @return void
1955
-     */
1956
-    protected function decline_registration($notify = false)
1957
-    {
1958
-        $this->_reg_status_change_return(EEM_Registration::status_id_declined, $notify);
1959
-    }
1960
-
1961
-
1962
-    /**
1963
-     *        cancel_registration
1964
-     *
1965
-     * @access protected
1966
-     * @param bool $notify whether or not to notify the registrant about their status change.
1967
-     * @return void
1968
-     */
1969
-    protected function cancel_registration($notify = false)
1970
-    {
1971
-        $this->_reg_status_change_return(EEM_Registration::status_id_cancelled, $notify);
1972
-    }
1973
-
1974
-
1975
-    /**
1976
-     *        not_approve_registration
1977
-     *
1978
-     * @access protected
1979
-     * @param bool $notify whether or not to notify the registrant about their status change.
1980
-     * @return void
1981
-     */
1982
-    protected function not_approve_registration($notify = false)
1983
-    {
1984
-        $this->_reg_status_change_return(EEM_Registration::status_id_not_approved, $notify);
1985
-    }
1986
-
1987
-
1988
-    /**
1989
-     *        decline_registration
1990
-     *
1991
-     * @access protected
1992
-     * @param bool $notify whether or not to notify the registrant about their status change.
1993
-     * @return void
1994
-     */
1995
-    protected function pending_registration($notify = false)
1996
-    {
1997
-        $this->_reg_status_change_return(EEM_Registration::status_id_pending_payment, $notify);
1998
-    }
1999
-
2000
-
2001
-    /**
2002
-     * waitlist_registration
2003
-     *
2004
-     * @access protected
2005
-     * @param bool $notify whether or not to notify the registrant about their status change.
2006
-     * @return void
2007
-     */
2008
-    protected function wait_list_registration($notify = false)
2009
-    {
2010
-        $this->_reg_status_change_return(EEM_Registration::status_id_wait_list, $notify);
2011
-    }
2012
-
2013
-
2014
-    /**
2015
-     *        generates HTML for the Registration main meta box
2016
-     *
2017
-     * @access public
2018
-     * @return void
2019
-     * @throws DomainException
2020
-     * @throws EE_Error
2021
-     * @throws \EventEspresso\core\exceptions\EntityNotFoundException
2022
-     */
2023
-    public function _reg_details_meta_box()
2024
-    {
2025
-        EEH_Autoloader::register_line_item_display_autoloaders();
2026
-        EEH_Autoloader::register_line_item_filter_autoloaders();
2027
-        EE_Registry::instance()->load_helper('Line_Item');
2028
-        $transaction    = $this->_registration->transaction() ? $this->_registration->transaction()
2029
-            : EE_Transaction::new_instance();
2030
-        $this->_session = $transaction->session_data();
2031
-        $filters        = new EE_Line_Item_Filter_Collection();
2032
-        //$filters->add( new EE_Non_Zero_Line_Item_Filter() );
2033
-        $filters->add(new EE_Single_Registration_Line_Item_Filter($this->_registration));
2034
-        $line_item_filter_processor              = new EE_Line_Item_Filter_Processor($filters,
2035
-            $transaction->total_line_item());
2036
-        $filtered_line_item_tree                 = $line_item_filter_processor->process();
2037
-        $line_item_display                       = new EE_Line_Item_Display('reg_admin_table',
2038
-            'EE_Admin_Table_Registration_Line_Item_Display_Strategy');
2039
-        $this->_template_args['line_item_table'] = $line_item_display->display_line_item(
2040
-            $filtered_line_item_tree,
2041
-            array('EE_Registration' => $this->_registration)
2042
-        );
2043
-        $attendee                                = $this->_registration->attendee();
2044
-        if (EE_Registry::instance()->CAP->current_user_can(
2045
-            'ee_read_transaction',
2046
-            'espresso_transactions_view_transaction'
2047
-        )) {
2048
-            $this->_template_args['view_transaction_button'] = EEH_Template::get_button_or_link(
2049
-                EE_Admin_Page::add_query_args_and_nonce(
2050
-                    array(
2051
-                        'action' => 'view_transaction',
2052
-                        'TXN_ID' => $transaction->ID(),
2053
-                    ),
2054
-                    TXN_ADMIN_URL
2055
-                ),
2056
-                esc_html__(' View Transaction', 'event_espresso'),
2057
-                'button secondary-button right',
2058
-                'dashicons dashicons-cart'
2059
-            );
2060
-        } else {
2061
-            $this->_template_args['view_transaction_button'] = '';
2062
-        }
2063
-        if ($attendee instanceof EE_Attendee
2064
-            && EE_Registry::instance()->CAP->current_user_can(
2065
-                'ee_send_message',
2066
-                'espresso_registrations_resend_registration'
2067
-            )
2068
-        ) {
2069
-            $this->_template_args['resend_registration_button'] = EEH_Template::get_button_or_link(
2070
-                EE_Admin_Page::add_query_args_and_nonce(
2071
-                    array(
2072
-                        'action'      => 'resend_registration',
2073
-                        '_REG_ID'     => $this->_registration->ID(),
2074
-                        'redirect_to' => 'view_registration',
2075
-                    ),
2076
-                    REG_ADMIN_URL
2077
-                ),
2078
-                esc_html__(' Resend Registration', 'event_espresso'),
2079
-                'button secondary-button right',
2080
-                'dashicons dashicons-email-alt'
2081
-            );
2082
-        } else {
2083
-            $this->_template_args['resend_registration_button'] = '';
2084
-        }
2085
-        $this->_template_args['currency_sign'] = EE_Registry::instance()->CFG->currency->sign;
2086
-        $payment                               = $transaction->get_first_related('Payment');
2087
-        $payment                               = ! $payment instanceof EE_Payment
2088
-            ? EE_Payment::new_instance()
2089
-            : $payment;
2090
-        $payment_method                        = $payment->get_first_related('Payment_Method');
2091
-        $payment_method                        = ! $payment_method instanceof EE_Payment_Method
2092
-            ? EE_Payment_Method::new_instance()
2093
-            : $payment_method;
2094
-        $reg_details                           = array(
2095
-            'payment_method'       => $payment_method->name(),
2096
-            'response_msg'         => $payment->gateway_response(),
2097
-            'registration_id'      => $this->_registration->get('REG_code'),
2098
-            'registration_session' => $this->_registration->session_ID(),
2099
-            'ip_address'           => isset($this->_session['ip_address']) ? $this->_session['ip_address'] : '',
2100
-            'user_agent'           => isset($this->_session['user_agent']) ? $this->_session['user_agent'] : '',
2101
-        );
2102
-        if (isset($reg_details['registration_id'])) {
2103
-            $this->_template_args['reg_details']['registration_id']['value'] = $reg_details['registration_id'];
2104
-            $this->_template_args['reg_details']['registration_id']['label'] = esc_html__(
2105
-                'Registration ID',
2106
-                'event_espresso'
2107
-            );
2108
-            $this->_template_args['reg_details']['registration_id']['class'] = 'regular-text';
2109
-        }
2110
-        if (isset($reg_details['payment_method'])) {
2111
-            $this->_template_args['reg_details']['payment_method']['value'] = $reg_details['payment_method'];
2112
-            $this->_template_args['reg_details']['payment_method']['label'] = esc_html__(
2113
-                'Most Recent Payment Method',
2114
-                'event_espresso'
2115
-            );
2116
-            $this->_template_args['reg_details']['payment_method']['class'] = 'regular-text';
2117
-            $this->_template_args['reg_details']['response_msg']['value']   = $reg_details['response_msg'];
2118
-            $this->_template_args['reg_details']['response_msg']['label']   = esc_html__(
2119
-                'Payment method response',
2120
-                'event_espresso'
2121
-            );
2122
-            $this->_template_args['reg_details']['response_msg']['class']   = 'regular-text';
2123
-        }
2124
-        $this->_template_args['reg_details']['registration_session']['value'] = $reg_details['registration_session'];
2125
-        $this->_template_args['reg_details']['registration_session']['label'] = esc_html__(
2126
-            'Registration Session',
2127
-            'event_espresso'
2128
-        );
2129
-        $this->_template_args['reg_details']['registration_session']['class'] = 'regular-text';
2130
-        $this->_template_args['reg_details']['ip_address']['value']           = $reg_details['ip_address'];
2131
-        $this->_template_args['reg_details']['ip_address']['label']           = esc_html__(
2132
-            'Registration placed from IP',
2133
-            'event_espresso'
2134
-        );
2135
-        $this->_template_args['reg_details']['ip_address']['class']           = 'regular-text';
2136
-        $this->_template_args['reg_details']['user_agent']['value']           = $reg_details['user_agent'];
2137
-        $this->_template_args['reg_details']['user_agent']['label']           = esc_html__('Registrant User Agent',
2138
-            'event_espresso');
2139
-        $this->_template_args['reg_details']['user_agent']['class']           = 'large-text';
2140
-        $this->_template_args['event_link']                                   = EE_Admin_Page::add_query_args_and_nonce(
2141
-            array(
2142
-                'action'   => 'default',
2143
-                'event_id' => $this->_registration->event_ID(),
2144
-            ),
2145
-            REG_ADMIN_URL
2146
-        );
2147
-        $this->_template_args['REG_ID']                                       = $this->_registration->ID();
2148
-        $this->_template_args['event_id']                                     = $this->_registration->event_ID();
2149
-        $template_path                                                        =
2150
-            REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_reg_details.template.php';
2151
-        echo EEH_Template::display_template($template_path, $this->_template_args, true);
2152
-    }
2153
-
2154
-
2155
-    /**
2156
-     * generates HTML for the Registration Questions meta box.
2157
-     * If pre-4.8.32.rc.000 hooks are used, uses old methods (with its filters),
2158
-     * otherwise uses new forms system
2159
-     *
2160
-     * @access public
2161
-     * @return void
2162
-     * @throws DomainException
2163
-     * @throws EE_Error
2164
-     */
2165
-    public function _reg_questions_meta_box()
2166
-    {
2167
-        //allow someone to override this method entirely
2168
-        if (apply_filters('FHEE__Registrations_Admin_Page___reg_questions_meta_box__do_default', true, $this,
2169
-            $this->_registration)) {
2170
-            $form                                              = $this->_get_reg_custom_questions_form(
2171
-                $this->_registration->ID()
2172
-            );
2173
-            $this->_template_args['att_questions']             = count($form->subforms()) > 0
2174
-                ? $form->get_html_and_js()
2175
-                : '';
2176
-            $this->_template_args['reg_questions_form_action'] = 'edit_registration';
2177
-            $this->_template_args['REG_ID']                    = $this->_registration->ID();
2178
-            $template_path                                     =
2179
-                REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_reg_questions.template.php';
2180
-            echo EEH_Template::display_template($template_path, $this->_template_args, true);
2181
-        }
2182
-    }
2183
-
2184
-
2185
-    /**
2186
-     * form_before_question_group
2187
-     *
2188
-     * @deprecated    as of 4.8.32.rc.000
2189
-     * @access        public
2190
-     * @param        string $output
2191
-     * @return        string
2192
-     */
2193
-    public function form_before_question_group($output)
2194
-    {
2195
-        EE_Error::doing_it_wrong(
2196
-            __CLASS__ . '::' . __FUNCTION__,
2197
-            esc_html__(
2198
-                '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.',
2199
-                'event_espresso'
2200
-            ),
2201
-            '4.8.32.rc.000'
2202
-        );
2203
-        return '
1236
+		if (! empty($registration_status)) {
1237
+			$where['STS_ID'] = $registration_status;
1238
+		} else {
1239
+			//make sure we exclude incomplete registrations, but only if not trashed.
1240
+			if ($view === 'trash') {
1241
+				$where['REG_deleted'] = true;
1242
+			} elseif ($view === 'incomplete') {
1243
+				$where['STS_ID'] = EEM_Registration::status_id_incomplete;
1244
+			} else {
1245
+				$where['STS_ID'] = array('!=', EEM_Registration::status_id_incomplete);
1246
+			}
1247
+		}
1248
+		return $where;
1249
+	}
1250
+
1251
+
1252
+	/**
1253
+	 * Adds any provided date restraints to the where conditions for the registrations query.
1254
+	 *
1255
+	 * @param array $request usually the same as $this->_req_data but not necessarily
1256
+	 * @return array
1257
+	 * @throws EE_Error
1258
+	 */
1259
+	protected function _add_date_to_where_conditions(array $request)
1260
+	{
1261
+		$where = array();
1262
+		$view = EEH_Array::is_set($request, 'status', '');
1263
+		$month_range             = ! empty($request['month_range'])
1264
+			? sanitize_text_field($request['month_range'])
1265
+			: '';
1266
+		$retrieve_for_today      = $view === 'today';
1267
+		$retrieve_for_this_month = $view === 'month';
1268
+
1269
+		if ($retrieve_for_today) {
1270
+			$now               = date('Y-m-d', current_time('timestamp'));
1271
+			$where['REG_date'] = array(
1272
+				'BETWEEN',
1273
+				array(
1274
+					EEM_Registration::instance()->convert_datetime_for_query(
1275
+						'REG_date',
1276
+						$now . ' 00:00:00',
1277
+						'Y-m-d H:i:s'
1278
+					),
1279
+					EEM_Registration::instance()->convert_datetime_for_query(
1280
+						'REG_date',
1281
+						$now . ' 23:59:59',
1282
+						'Y-m-d H:i:s'
1283
+					),
1284
+				),
1285
+			);
1286
+		} elseif ($retrieve_for_this_month) {
1287
+			$current_year_and_month = date('Y-m', current_time('timestamp'));
1288
+			$days_this_month        = date('t', current_time('timestamp'));
1289
+			$where['REG_date']      = array(
1290
+				'BETWEEN',
1291
+				array(
1292
+					EEM_Registration::instance()->convert_datetime_for_query(
1293
+						'REG_date',
1294
+						$current_year_and_month . '-01 00:00:00',
1295
+						'Y-m-d H:i:s'
1296
+					),
1297
+					EEM_Registration::instance()->convert_datetime_for_query(
1298
+						'REG_date',
1299
+						$current_year_and_month . '-' . $days_this_month . ' 23:59:59',
1300
+						'Y-m-d H:i:s'
1301
+					),
1302
+				),
1303
+			);
1304
+		} elseif ($month_range) {
1305
+			$pieces          = explode(' ', $month_range, 3);
1306
+			$month_requested = ! empty($pieces[0])
1307
+				? date('m', \EEH_DTT_Helper::first_of_month_timestamp($pieces[0]))
1308
+				: '';
1309
+			$year_requested  = ! empty($pieces[1])
1310
+				? $pieces[1]
1311
+				: '';
1312
+			//if there is not a month or year then we can't go further
1313
+			if ($month_requested && $year_requested) {
1314
+				$days_in_month     = date('t', strtotime($year_requested . '-' . $month_requested . '-' . '01'));
1315
+				$where['REG_date'] = array(
1316
+					'BETWEEN',
1317
+					array(
1318
+						EEM_Registration::instance()->convert_datetime_for_query(
1319
+							'REG_date',
1320
+							$year_requested . '-' . $month_requested . '-01 00:00:00',
1321
+							'Y-m-d H:i:s'
1322
+						),
1323
+						EEM_Registration::instance()->convert_datetime_for_query(
1324
+							'REG_date',
1325
+							$year_requested . '-' . $month_requested . '-' . $days_in_month . ' 23:59:59',
1326
+							'Y-m-d H:i:s'
1327
+						),
1328
+					),
1329
+				);
1330
+			}
1331
+		}
1332
+		return $where;
1333
+	}
1334
+
1335
+
1336
+	/**
1337
+	 * Adds any provided search restraints to the where conditions for the registrations query
1338
+	 *
1339
+	 * @param array $request usually the same as $this->_req_data but not necessarily
1340
+	 * @return array
1341
+	 */
1342
+	protected function _add_search_to_where_conditions(array $request)
1343
+	{
1344
+		$where = array();
1345
+		if (! empty($request['s'])) {
1346
+			$search_string = '%' . sanitize_text_field($request['s']) . '%';
1347
+			$where['OR*search_conditions'] = array(
1348
+				'Event.EVT_name'                          => array('LIKE', $search_string),
1349
+				'Event.EVT_desc'                          => array('LIKE', $search_string),
1350
+				'Event.EVT_short_desc'                    => array('LIKE', $search_string),
1351
+				'Attendee.ATT_full_name'                  => array('LIKE', $search_string),
1352
+				'Attendee.ATT_fname'                      => array('LIKE', $search_string),
1353
+				'Attendee.ATT_lname'                      => array('LIKE', $search_string),
1354
+				'Attendee.ATT_short_bio'                  => array('LIKE', $search_string),
1355
+				'Attendee.ATT_email'                      => array('LIKE', $search_string),
1356
+				'Attendee.ATT_address'                    => array('LIKE', $search_string),
1357
+				'Attendee.ATT_address2'                   => array('LIKE', $search_string),
1358
+				'Attendee.ATT_city'                       => array('LIKE', $search_string),
1359
+				'REG_final_price'                         => array('LIKE', $search_string),
1360
+				'REG_code'                                => array('LIKE', $search_string),
1361
+				'REG_count'                               => array('LIKE', $search_string),
1362
+				'REG_group_size'                          => array('LIKE', $search_string),
1363
+				'Ticket.TKT_name'                         => array('LIKE', $search_string),
1364
+				'Ticket.TKT_description'                  => array('LIKE', $search_string),
1365
+				'Transaction.Payment.PAY_txn_id_chq_nmbr' => array('LIKE', $search_string),
1366
+			);
1367
+		}
1368
+		return $where;
1369
+	}
1370
+
1371
+
1372
+	/**
1373
+	 * Sets up the where conditions for the registrations query.
1374
+	 *
1375
+	 * @param array $request
1376
+	 * @return array
1377
+	 * @throws EE_Error
1378
+	 */
1379
+	protected function _get_where_conditions_for_registrations_query($request)
1380
+	{
1381
+		return apply_filters(
1382
+			'FHEE__Registrations_Admin_Page___get_where_conditions_for_registrations_query',
1383
+			array_merge(
1384
+				$this->_add_event_id_to_where_conditions($request),
1385
+				$this->_add_category_id_to_where_conditions($request),
1386
+				$this->_add_datetime_id_to_where_conditions($request),
1387
+				$this->_add_registration_status_to_where_conditions($request),
1388
+				$this->_add_date_to_where_conditions($request),
1389
+				$this->_add_search_to_where_conditions($request)
1390
+			),
1391
+			$request
1392
+		);
1393
+	}
1394
+
1395
+
1396
+	/**
1397
+	 * Sets up the orderby for the registrations query.
1398
+	 *
1399
+	 * @return array
1400
+	 */
1401
+	protected function _get_orderby_for_registrations_query()
1402
+	{
1403
+		$orderby_field = ! empty($this->_req_data['orderby'])
1404
+			? sanitize_text_field($this->_req_data['orderby'])
1405
+			: '';
1406
+		switch ($orderby_field) {
1407
+			case '_REG_ID':
1408
+				$orderby_field = 'REG_ID';
1409
+				break;
1410
+			case '_Reg_status':
1411
+				$orderby_field = 'STS_ID';
1412
+				break;
1413
+			case 'ATT_fname':
1414
+				$orderby_field = array('Attendee.ATT_fname', 'Attendee.ATT_lname');
1415
+				break;
1416
+			case 'ATT_lname':
1417
+				$orderby_field = array('Attendee.ATT_lname', 'Attendee.ATT_fname');
1418
+				break;
1419
+			case 'event_name':
1420
+				$orderby_field = 'Event.EVT_name';
1421
+				break;
1422
+			case 'DTT_EVT_start':
1423
+				$orderby_field = 'Event.Datetime.DTT_EVT_start';
1424
+				break;
1425
+			default: //'REG_date'
1426
+				$orderby_field = 'REG_date';
1427
+		}
1428
+
1429
+		//order
1430
+		$order = ! empty($this->_req_data['order'])
1431
+			? sanitize_text_field($this->_req_data['order'])
1432
+			: 'DESC';
1433
+
1434
+		//mutate orderby_field
1435
+		$orderby_field = array_combine(
1436
+			(array) $orderby_field,
1437
+			array_fill(0, count($orderby_field), $order)
1438
+		);
1439
+		return array('order_by' => $orderby_field);
1440
+	}
1441
+
1442
+
1443
+	/**
1444
+	 * Sets up the limit for the registrations query.
1445
+	 *
1446
+	 * @param $per_page
1447
+	 * @return array
1448
+	 */
1449
+	protected function _get_limit($per_page)
1450
+	{
1451
+		$current_page = ! empty($this->_req_data['paged'])
1452
+			? absint($this->_req_data['paged'])
1453
+			: 1;
1454
+		$per_page     = ! empty($this->_req_data['perpage'])
1455
+			? $this->_req_data['perpage']
1456
+			: $per_page;
1457
+
1458
+		//-1 means return all results so get out if that's set.
1459
+		if ((int)$per_page === -1) {
1460
+			return array();
1461
+		}
1462
+		$per_page = absint($per_page);
1463
+		$offset   = ($current_page - 1) * $per_page;
1464
+		return array('limit' => array($offset, $per_page));
1465
+	}
1466
+
1467
+
1468
+	public function get_registration_status_array()
1469
+	{
1470
+		return self::$_reg_status;
1471
+	}
1472
+
1473
+
1474
+
1475
+
1476
+	/***************************************        REGISTRATION DETAILS        ***************************************/
1477
+	/**
1478
+	 *        generates HTML for the View Registration Details Admin page
1479
+	 *
1480
+	 * @access protected
1481
+	 * @return void
1482
+	 * @throws DomainException
1483
+	 * @throws EE_Error
1484
+	 * @throws \EventEspresso\core\exceptions\EntityNotFoundException
1485
+	 */
1486
+	protected function _registration_details()
1487
+	{
1488
+		$this->_template_args = array();
1489
+		$this->_set_registration_object();
1490
+		if (is_object($this->_registration)) {
1491
+			$transaction                                   = $this->_registration->transaction()
1492
+				? $this->_registration->transaction()
1493
+				: EE_Transaction::new_instance();
1494
+			$this->_session                                = $transaction->session_data();
1495
+			$event_id                                      = $this->_registration->event_ID();
1496
+			$this->_template_args['reg_nmbr']['value']     = $this->_registration->ID();
1497
+			$this->_template_args['reg_nmbr']['label']     = esc_html__('Registration Number', 'event_espresso');
1498
+			$this->_template_args['reg_datetime']['value'] = $this->_registration->get_i18n_datetime('REG_date');
1499
+			$this->_template_args['reg_datetime']['label'] = esc_html__('Date', 'event_espresso');
1500
+			$this->_template_args['grand_total']           = $transaction->total();
1501
+			$this->_template_args['currency_sign']         = EE_Registry::instance()->CFG->currency->sign;
1502
+			// link back to overview
1503
+			$this->_template_args['reg_overview_url']            = REG_ADMIN_URL;
1504
+			$this->_template_args['registration']                = $this->_registration;
1505
+			$this->_template_args['filtered_registrations_link'] = EE_Admin_Page::add_query_args_and_nonce(
1506
+				array(
1507
+					'action'   => 'default',
1508
+					'event_id' => $event_id,
1509
+				),
1510
+				REG_ADMIN_URL
1511
+			);
1512
+			$this->_template_args['filtered_transactions_link']  = EE_Admin_Page::add_query_args_and_nonce(
1513
+				array(
1514
+					'action' => 'default',
1515
+					'EVT_ID' => $event_id,
1516
+					'page'   => 'espresso_transactions',
1517
+				),
1518
+				admin_url('admin.php')
1519
+			);
1520
+			$this->_template_args['event_link']                  = EE_Admin_Page::add_query_args_and_nonce(
1521
+				array(
1522
+					'page'   => 'espresso_events',
1523
+					'action' => 'edit',
1524
+					'post'   => $event_id,
1525
+				),
1526
+				admin_url('admin.php')
1527
+			);
1528
+			//next and previous links
1529
+			$next_reg                                      = $this->_registration->next(
1530
+				null,
1531
+				array(),
1532
+				'REG_ID'
1533
+			);
1534
+			$this->_template_args['next_registration']     = $next_reg
1535
+				? $this->_next_link(
1536
+					EE_Admin_Page::add_query_args_and_nonce(
1537
+						array(
1538
+							'action'  => 'view_registration',
1539
+							'_REG_ID' => $next_reg['REG_ID'],
1540
+						),
1541
+						REG_ADMIN_URL
1542
+					),
1543
+					'dashicons dashicons-arrow-right ee-icon-size-22'
1544
+				)
1545
+				: '';
1546
+			$previous_reg                                  = $this->_registration->previous(
1547
+				null,
1548
+				array(),
1549
+				'REG_ID'
1550
+			);
1551
+			$this->_template_args['previous_registration'] = $previous_reg
1552
+				? $this->_previous_link(
1553
+					EE_Admin_Page::add_query_args_and_nonce(
1554
+						array(
1555
+							'action'  => 'view_registration',
1556
+							'_REG_ID' => $previous_reg['REG_ID'],
1557
+						),
1558
+						REG_ADMIN_URL
1559
+					),
1560
+					'dashicons dashicons-arrow-left ee-icon-size-22'
1561
+				)
1562
+				: '';
1563
+			// grab header
1564
+			$template_path                             = REG_TEMPLATE_PATH . 'reg_admin_details_header.template.php';
1565
+			$this->_template_args['REG_ID']            = $this->_registration->ID();
1566
+			$this->_template_args['admin_page_header'] = EEH_Template::display_template(
1567
+				$template_path,
1568
+				$this->_template_args,
1569
+				true
1570
+			);
1571
+		} else {
1572
+			$this->_template_args['admin_page_header'] = $this->display_espresso_notices();
1573
+		}
1574
+		// the details template wrapper
1575
+		$this->display_admin_page_with_sidebar();
1576
+	}
1577
+
1578
+
1579
+	protected function _registration_details_metaboxes()
1580
+	{
1581
+		do_action('AHEE__Registrations_Admin_Page___registration_details_metabox__start', $this);
1582
+		$this->_set_registration_object();
1583
+		$attendee = $this->_registration instanceof EE_Registration ? $this->_registration->attendee() : null;
1584
+		add_meta_box('edit-reg-status-mbox', esc_html__('Registration Status', 'event_espresso'),
1585
+			array($this, 'set_reg_status_buttons_metabox'), $this->wp_page_slug, 'normal', 'high');
1586
+		add_meta_box('edit-reg-details-mbox', esc_html__('Registration Details', 'event_espresso'),
1587
+			array($this, '_reg_details_meta_box'), $this->wp_page_slug, 'normal', 'high');
1588
+		if ($attendee instanceof EE_Attendee
1589
+			&& EE_Registry::instance()->CAP->current_user_can(
1590
+				'ee_edit_registration',
1591
+				'edit-reg-questions-mbox',
1592
+				$this->_registration->ID()
1593
+			)
1594
+		) {
1595
+			add_meta_box(
1596
+				'edit-reg-questions-mbox',
1597
+				esc_html__('Registration Form Answers', 'event_espresso'),
1598
+				array($this, '_reg_questions_meta_box'),
1599
+				$this->wp_page_slug,
1600
+				'normal',
1601
+				'high'
1602
+			);
1603
+		}
1604
+		add_meta_box(
1605
+			'edit-reg-registrant-mbox',
1606
+			esc_html__('Contact Details', 'event_espresso'),
1607
+			array($this, '_reg_registrant_side_meta_box'),
1608
+			$this->wp_page_slug,
1609
+			'side',
1610
+			'high'
1611
+		);
1612
+		if ($this->_registration->group_size() > 1) {
1613
+			add_meta_box(
1614
+				'edit-reg-attendees-mbox',
1615
+				esc_html__('Other Registrations in this Transaction', 'event_espresso'),
1616
+				array($this, '_reg_attendees_meta_box'),
1617
+				$this->wp_page_slug,
1618
+				'normal',
1619
+				'high'
1620
+			);
1621
+		}
1622
+	}
1623
+
1624
+
1625
+	/**
1626
+	 * set_reg_status_buttons_metabox
1627
+	 *
1628
+	 * @access protected
1629
+	 * @return string
1630
+	 * @throws \EE_Error
1631
+	 */
1632
+	public function set_reg_status_buttons_metabox()
1633
+	{
1634
+		$this->_set_registration_object();
1635
+		$change_reg_status_form = $this->_generate_reg_status_change_form();
1636
+		echo $change_reg_status_form->form_open(
1637
+			self::add_query_args_and_nonce(
1638
+				array(
1639
+					'action' => 'change_reg_status',
1640
+				),
1641
+				REG_ADMIN_URL
1642
+			)
1643
+		);
1644
+		echo $change_reg_status_form->get_html();
1645
+		echo $change_reg_status_form->form_close();
1646
+	}
1647
+
1648
+
1649
+
1650
+	/**
1651
+	 * @return EE_Form_Section_Proper
1652
+	 * @throws EE_Error
1653
+	 */
1654
+	protected function _generate_reg_status_change_form()
1655
+	{
1656
+		return new EE_Form_Section_Proper(array(
1657
+			'name'            => 'reg_status_change_form',
1658
+			'html_id'         => 'reg-status-change-form',
1659
+			'layout_strategy' => new EE_Admin_Two_Column_Layout(),
1660
+			'subsections'     => array(
1661
+				'return'             => new EE_Hidden_Input(array(
1662
+					'name'    => 'return',
1663
+					'default' => 'view_registration',
1664
+				)),
1665
+				'REG_ID'             => new EE_Hidden_Input(array(
1666
+					'name'    => 'REG_ID',
1667
+					'default' => $this->_registration->ID(),
1668
+				)),
1669
+				'current_status'     => new EE_Form_Section_HTML(
1670
+					EEH_HTML::tr(
1671
+						EEH_HTML::th(
1672
+							EEH_HTML::label(
1673
+								EEH_HTML::strong(esc_html__('Current Registration Status', 'event_espresso')
1674
+								)
1675
+							)
1676
+						)
1677
+						. EEH_HTML::td(
1678
+							EEH_HTML::strong(
1679
+								$this->_registration->pretty_status(),
1680
+								'',
1681
+								'status-' . $this->_registration->status_ID(),
1682
+								'line-height: 1em; font-size: 1.5em; font-weight: bold;'
1683
+							)
1684
+						)
1685
+					)
1686
+				),
1687
+				'reg_status'         => new EE_Select_Input(
1688
+					$this->_get_reg_statuses(),
1689
+					array(
1690
+						'html_label_text' => esc_html__('Change Registration Status to', 'event_espresso'),
1691
+						'default'         => $this->_registration->status_ID(),
1692
+					)
1693
+				),
1694
+				'send_notifications' => new EE_Yes_No_Input(
1695
+					array(
1696
+						'html_label_text' => esc_html__('Send Related Messages', 'event_espresso'),
1697
+						'default'         => false,
1698
+						'html_help_text'  => esc_html__(
1699
+							'If set to "Yes", then the related messages will be sent to the registrant.',
1700
+							'event_espresso'
1701
+						),
1702
+					)
1703
+				),
1704
+				'submit'             => new EE_Submit_Input(
1705
+					array(
1706
+						'html_class'      => 'button-primary',
1707
+						'html_label_text' => '&nbsp;',
1708
+						'default'         => esc_html__('Update Registration Status', 'event_espresso'),
1709
+					)
1710
+				),
1711
+			),
1712
+		));
1713
+	}
1714
+
1715
+
1716
+	/**
1717
+	 * Returns an array of all the buttons for the various statuses and switch status actions
1718
+	 *
1719
+	 * @return array
1720
+	 * @throws EE_Error
1721
+	 * @throws \EventEspresso\core\exceptions\EntityNotFoundException
1722
+	 */
1723
+	protected function _get_reg_statuses()
1724
+	{
1725
+		$reg_status_array = EEM_Registration::instance()->reg_status_array();
1726
+		unset ($reg_status_array[EEM_Registration::status_id_incomplete]);
1727
+		// get current reg status
1728
+		$current_status = $this->_registration->status_ID();
1729
+		// is registration for free event? This will determine whether to display the pending payment option
1730
+		if (
1731
+			$current_status !== EEM_Registration::status_id_pending_payment
1732
+			&& $this->_registration->transaction()->is_free()
1733
+		) {
1734
+			unset($reg_status_array[EEM_Registration::status_id_pending_payment]);
1735
+		}
1736
+		return EEM_Status::instance()->localized_status($reg_status_array, false, 'sentence');
1737
+	}
1738
+
1739
+
1740
+
1741
+	/**
1742
+	 * This method is used when using _REG_ID from request which may or may not be an array of reg_ids.
1743
+	 *
1744
+	 * @param bool $status REG status given for changing registrations to.
1745
+	 * @param bool $notify Whether to send messages notifications or not.
1746
+	 * @return array  (array with reg_id(s) updated and whether update was successful.
1747
+	 * @throws \EE_Error
1748
+	 */
1749
+	protected function _set_registration_status_from_request($status = false, $notify = false)
1750
+	{
1751
+		if (isset($this->_req_data['reg_status_change_form'])) {
1752
+			$REG_IDs = isset($this->_req_data['reg_status_change_form']['REG_ID'])
1753
+				? (array)$this->_req_data['reg_status_change_form']['REG_ID'] : array();
1754
+		} else {
1755
+			$REG_IDs = isset($this->_req_data['_REG_ID']) ? (array)$this->_req_data['_REG_ID'] : array();
1756
+		}
1757
+		$success = $this->_set_registration_status($REG_IDs, $status);
1758
+		//notify?
1759
+		if ($success
1760
+			&& $notify
1761
+			&& EE_Registry::instance()->CAP->current_user_can(
1762
+				'ee_send_message',
1763
+				'espresso_registrations_resend_registration'
1764
+			)
1765
+		) {
1766
+			$this->_process_resend_registration();
1767
+		}
1768
+		return $success;
1769
+	}
1770
+
1771
+
1772
+
1773
+	/**
1774
+	 * Set the registration status for the given reg_id (which may or may not be an array, it gets typecast to an
1775
+	 * array). Note, this method does NOT take care of possible notifications.  That is required by calling code.
1776
+	 *
1777
+	 * @param array $REG_IDs
1778
+	 * @param bool  $status
1779
+	 * @return array (an array with 'success' key representing whether status change was successful, and 'REG_ID' as
1780
+	 * @throws \RuntimeException
1781
+	 * @throws \EE_Error
1782
+	 *               the array of updated registrations).
1783
+	 * @throws EE_Error
1784
+	 * @throws RuntimeException
1785
+	 */
1786
+	protected function _set_registration_status($REG_IDs = array(), $status = false)
1787
+	{
1788
+		$success = false;
1789
+		// typecast $REG_IDs
1790
+		$REG_IDs = (array)$REG_IDs;
1791
+		if ( ! empty($REG_IDs)) {
1792
+			$success = true;
1793
+			// set default status if none is passed
1794
+			$status = $status ? $status : EEM_Registration::status_id_pending_payment;
1795
+			// sanitize $REG_IDs
1796
+			$REG_IDs = array_filter($REG_IDs, 'absint');
1797
+			//loop through REG_ID's and change status
1798
+			foreach ($REG_IDs as $REG_ID) {
1799
+				$registration = EEM_Registration::instance()->get_one_by_ID($REG_ID);
1800
+				if ($registration instanceof EE_Registration) {
1801
+					$registration->set_status($status);
1802
+					$result = $registration->save();
1803
+					// verifying explicit fails because update *may* just return 0 for 0 rows affected
1804
+					$success = $result !== false ? $success : false;
1805
+				}
1806
+			}
1807
+		}
1808
+		//reset _req_data['_REG_ID'] for any potential future messages notifications
1809
+		$this->_req_data['_REG_ID'] = $REG_IDs;
1810
+		//return $success and processed registrations
1811
+		return array('REG_ID' => $REG_IDs, 'success' => $success);
1812
+	}
1813
+
1814
+
1815
+	/**
1816
+	 * Common logic for setting up success message and redirecting to appropriate route
1817
+	 *
1818
+	 * @param  string $STS_ID status id for the registration changed to
1819
+	 * @param   bool  $notify indicates whether the _set_registration_status_from_request does notifications or not.
1820
+	 * @return void
1821
+	 */
1822
+	protected function _reg_status_change_return($STS_ID, $notify = false)
1823
+	{
1824
+		$result  = ! empty($STS_ID) ? $this->_set_registration_status_from_request($STS_ID, $notify)
1825
+			: array('success' => false);
1826
+		$success = isset($result['success']) && $result['success'];
1827
+		//setup success message
1828
+		if ($success) {
1829
+			if (is_array($result['REG_ID']) && count($result['REG_ID']) === 1) {
1830
+				$msg = sprintf(esc_html__('Registration status has been set to %s', 'event_espresso'),
1831
+					EEH_Template::pretty_status($STS_ID, false, 'lower'));
1832
+			} else {
1833
+				$msg = sprintf(esc_html__('Registrations have been set to %s.', 'event_espresso'),
1834
+					EEH_Template::pretty_status($STS_ID, false, 'lower'));
1835
+			}
1836
+			EE_Error::add_success($msg);
1837
+		} else {
1838
+			EE_Error::add_error(
1839
+				esc_html__(
1840
+					'Something went wrong, and the status was not changed',
1841
+					'event_espresso'
1842
+				), __FILE__, __LINE__, __FUNCTION__
1843
+			);
1844
+		}
1845
+		if (isset($this->_req_data['return']) && $this->_req_data['return'] == 'view_registration') {
1846
+			$route = array('action' => 'view_registration', '_REG_ID' => reset($result['REG_ID']));
1847
+		} else {
1848
+			$route = array('action' => 'default');
1849
+		}
1850
+		//unset nonces
1851
+		foreach ($this->_req_data as $ref => $value) {
1852
+			if (strpos($ref, 'nonce') !== false) {
1853
+				unset($this->_req_data[$ref]);
1854
+				continue;
1855
+			}
1856
+			$value                 = is_array($value) ? array_map('urlencode', $value) : urlencode($value);
1857
+			$this->_req_data[$ref] = $value;
1858
+		}
1859
+		//merge request vars so that the reloaded list table contains any existing filter query params
1860
+		$route = array_merge($this->_req_data, $route);
1861
+		$this->_redirect_after_action($success, '', '', $route, true);
1862
+	}
1863
+
1864
+
1865
+	/**
1866
+	 * incoming reg status change from reg details page.
1867
+	 *
1868
+	 * @return void
1869
+	 */
1870
+	protected function _change_reg_status()
1871
+	{
1872
+		$this->_req_data['return'] = 'view_registration';
1873
+		//set notify based on whether the send notifications toggle is set or not
1874
+		$notify = ! empty($this->_req_data['reg_status_change_form']['send_notifications']);
1875
+		//$notify = ! empty( $this->_req_data['txn_reg_status_change']['send_notifications'] );
1876
+		$this->_req_data['reg_status_change_form']['reg_status'] = isset($this->_req_data['reg_status_change_form']['reg_status'])
1877
+			? $this->_req_data['reg_status_change_form']['reg_status'] : '';
1878
+		switch ($this->_req_data['reg_status_change_form']['reg_status']) {
1879
+			case EEM_Registration::status_id_approved :
1880
+			case EEH_Template::pretty_status(EEM_Registration::status_id_approved, false, 'sentence') :
1881
+				$this->approve_registration($notify);
1882
+				break;
1883
+			case EEM_Registration::status_id_pending_payment :
1884
+			case EEH_Template::pretty_status(EEM_Registration::status_id_pending_payment, false, 'sentence') :
1885
+				$this->pending_registration($notify);
1886
+				break;
1887
+			case EEM_Registration::status_id_not_approved :
1888
+			case EEH_Template::pretty_status(EEM_Registration::status_id_not_approved, false, 'sentence') :
1889
+				$this->not_approve_registration($notify);
1890
+				break;
1891
+			case EEM_Registration::status_id_declined :
1892
+			case EEH_Template::pretty_status(EEM_Registration::status_id_declined, false, 'sentence') :
1893
+				$this->decline_registration($notify);
1894
+				break;
1895
+			case EEM_Registration::status_id_cancelled :
1896
+			case EEH_Template::pretty_status(EEM_Registration::status_id_cancelled, false, 'sentence') :
1897
+				$this->cancel_registration($notify);
1898
+				break;
1899
+			case EEM_Registration::status_id_wait_list :
1900
+			case EEH_Template::pretty_status(EEM_Registration::status_id_wait_list, false, 'sentence') :
1901
+				$this->wait_list_registration($notify);
1902
+				break;
1903
+			case EEM_Registration::status_id_incomplete :
1904
+			default :
1905
+				$result['success'] = false;
1906
+				unset($this->_req_data['return']);
1907
+				$this->_reg_status_change_return('', false);
1908
+				break;
1909
+		}
1910
+	}
1911
+
1912
+
1913
+	/**
1914
+	 * Callback for bulk action routes.
1915
+	 * Note: although we could just register the singular route callbacks for each bulk action route as well, this
1916
+	 * method was chosen so there is one central place all the registration status bulk actions are going through.
1917
+	 * Potentially, this provides an easier place to locate logic that is specific to these bulk actions (as opposed to
1918
+	 * when an action is happening on just a single registration).
1919
+	 * @param      $action
1920
+	 * @param bool $notify
1921
+	 */
1922
+	protected function bulk_action_on_registrations($action, $notify = false) {
1923
+		do_action(
1924
+			'AHEE__Registrations_Admin_Page__bulk_action_on_registrations__before_execution',
1925
+			$this,
1926
+			$action,
1927
+			$notify
1928
+		);
1929
+		$method = $action . '_registration';
1930
+		if (method_exists($this, $method)) {
1931
+			$this->$method($notify);
1932
+		}
1933
+	}
1934
+
1935
+
1936
+	/**
1937
+	 * approve_registration
1938
+	 *
1939
+	 * @access protected
1940
+	 * @param bool $notify whether or not to notify the registrant about their approval.
1941
+	 * @return void
1942
+	 */
1943
+	protected function approve_registration($notify = false)
1944
+	{
1945
+		$this->_reg_status_change_return(EEM_Registration::status_id_approved, $notify);
1946
+	}
1947
+
1948
+
1949
+	/**
1950
+	 *        decline_registration
1951
+	 *
1952
+	 * @access protected
1953
+	 * @param bool $notify whether or not to notify the registrant about their status change.
1954
+	 * @return void
1955
+	 */
1956
+	protected function decline_registration($notify = false)
1957
+	{
1958
+		$this->_reg_status_change_return(EEM_Registration::status_id_declined, $notify);
1959
+	}
1960
+
1961
+
1962
+	/**
1963
+	 *        cancel_registration
1964
+	 *
1965
+	 * @access protected
1966
+	 * @param bool $notify whether or not to notify the registrant about their status change.
1967
+	 * @return void
1968
+	 */
1969
+	protected function cancel_registration($notify = false)
1970
+	{
1971
+		$this->_reg_status_change_return(EEM_Registration::status_id_cancelled, $notify);
1972
+	}
1973
+
1974
+
1975
+	/**
1976
+	 *        not_approve_registration
1977
+	 *
1978
+	 * @access protected
1979
+	 * @param bool $notify whether or not to notify the registrant about their status change.
1980
+	 * @return void
1981
+	 */
1982
+	protected function not_approve_registration($notify = false)
1983
+	{
1984
+		$this->_reg_status_change_return(EEM_Registration::status_id_not_approved, $notify);
1985
+	}
1986
+
1987
+
1988
+	/**
1989
+	 *        decline_registration
1990
+	 *
1991
+	 * @access protected
1992
+	 * @param bool $notify whether or not to notify the registrant about their status change.
1993
+	 * @return void
1994
+	 */
1995
+	protected function pending_registration($notify = false)
1996
+	{
1997
+		$this->_reg_status_change_return(EEM_Registration::status_id_pending_payment, $notify);
1998
+	}
1999
+
2000
+
2001
+	/**
2002
+	 * waitlist_registration
2003
+	 *
2004
+	 * @access protected
2005
+	 * @param bool $notify whether or not to notify the registrant about their status change.
2006
+	 * @return void
2007
+	 */
2008
+	protected function wait_list_registration($notify = false)
2009
+	{
2010
+		$this->_reg_status_change_return(EEM_Registration::status_id_wait_list, $notify);
2011
+	}
2012
+
2013
+
2014
+	/**
2015
+	 *        generates HTML for the Registration main meta box
2016
+	 *
2017
+	 * @access public
2018
+	 * @return void
2019
+	 * @throws DomainException
2020
+	 * @throws EE_Error
2021
+	 * @throws \EventEspresso\core\exceptions\EntityNotFoundException
2022
+	 */
2023
+	public function _reg_details_meta_box()
2024
+	{
2025
+		EEH_Autoloader::register_line_item_display_autoloaders();
2026
+		EEH_Autoloader::register_line_item_filter_autoloaders();
2027
+		EE_Registry::instance()->load_helper('Line_Item');
2028
+		$transaction    = $this->_registration->transaction() ? $this->_registration->transaction()
2029
+			: EE_Transaction::new_instance();
2030
+		$this->_session = $transaction->session_data();
2031
+		$filters        = new EE_Line_Item_Filter_Collection();
2032
+		//$filters->add( new EE_Non_Zero_Line_Item_Filter() );
2033
+		$filters->add(new EE_Single_Registration_Line_Item_Filter($this->_registration));
2034
+		$line_item_filter_processor              = new EE_Line_Item_Filter_Processor($filters,
2035
+			$transaction->total_line_item());
2036
+		$filtered_line_item_tree                 = $line_item_filter_processor->process();
2037
+		$line_item_display                       = new EE_Line_Item_Display('reg_admin_table',
2038
+			'EE_Admin_Table_Registration_Line_Item_Display_Strategy');
2039
+		$this->_template_args['line_item_table'] = $line_item_display->display_line_item(
2040
+			$filtered_line_item_tree,
2041
+			array('EE_Registration' => $this->_registration)
2042
+		);
2043
+		$attendee                                = $this->_registration->attendee();
2044
+		if (EE_Registry::instance()->CAP->current_user_can(
2045
+			'ee_read_transaction',
2046
+			'espresso_transactions_view_transaction'
2047
+		)) {
2048
+			$this->_template_args['view_transaction_button'] = EEH_Template::get_button_or_link(
2049
+				EE_Admin_Page::add_query_args_and_nonce(
2050
+					array(
2051
+						'action' => 'view_transaction',
2052
+						'TXN_ID' => $transaction->ID(),
2053
+					),
2054
+					TXN_ADMIN_URL
2055
+				),
2056
+				esc_html__(' View Transaction', 'event_espresso'),
2057
+				'button secondary-button right',
2058
+				'dashicons dashicons-cart'
2059
+			);
2060
+		} else {
2061
+			$this->_template_args['view_transaction_button'] = '';
2062
+		}
2063
+		if ($attendee instanceof EE_Attendee
2064
+			&& EE_Registry::instance()->CAP->current_user_can(
2065
+				'ee_send_message',
2066
+				'espresso_registrations_resend_registration'
2067
+			)
2068
+		) {
2069
+			$this->_template_args['resend_registration_button'] = EEH_Template::get_button_or_link(
2070
+				EE_Admin_Page::add_query_args_and_nonce(
2071
+					array(
2072
+						'action'      => 'resend_registration',
2073
+						'_REG_ID'     => $this->_registration->ID(),
2074
+						'redirect_to' => 'view_registration',
2075
+					),
2076
+					REG_ADMIN_URL
2077
+				),
2078
+				esc_html__(' Resend Registration', 'event_espresso'),
2079
+				'button secondary-button right',
2080
+				'dashicons dashicons-email-alt'
2081
+			);
2082
+		} else {
2083
+			$this->_template_args['resend_registration_button'] = '';
2084
+		}
2085
+		$this->_template_args['currency_sign'] = EE_Registry::instance()->CFG->currency->sign;
2086
+		$payment                               = $transaction->get_first_related('Payment');
2087
+		$payment                               = ! $payment instanceof EE_Payment
2088
+			? EE_Payment::new_instance()
2089
+			: $payment;
2090
+		$payment_method                        = $payment->get_first_related('Payment_Method');
2091
+		$payment_method                        = ! $payment_method instanceof EE_Payment_Method
2092
+			? EE_Payment_Method::new_instance()
2093
+			: $payment_method;
2094
+		$reg_details                           = array(
2095
+			'payment_method'       => $payment_method->name(),
2096
+			'response_msg'         => $payment->gateway_response(),
2097
+			'registration_id'      => $this->_registration->get('REG_code'),
2098
+			'registration_session' => $this->_registration->session_ID(),
2099
+			'ip_address'           => isset($this->_session['ip_address']) ? $this->_session['ip_address'] : '',
2100
+			'user_agent'           => isset($this->_session['user_agent']) ? $this->_session['user_agent'] : '',
2101
+		);
2102
+		if (isset($reg_details['registration_id'])) {
2103
+			$this->_template_args['reg_details']['registration_id']['value'] = $reg_details['registration_id'];
2104
+			$this->_template_args['reg_details']['registration_id']['label'] = esc_html__(
2105
+				'Registration ID',
2106
+				'event_espresso'
2107
+			);
2108
+			$this->_template_args['reg_details']['registration_id']['class'] = 'regular-text';
2109
+		}
2110
+		if (isset($reg_details['payment_method'])) {
2111
+			$this->_template_args['reg_details']['payment_method']['value'] = $reg_details['payment_method'];
2112
+			$this->_template_args['reg_details']['payment_method']['label'] = esc_html__(
2113
+				'Most Recent Payment Method',
2114
+				'event_espresso'
2115
+			);
2116
+			$this->_template_args['reg_details']['payment_method']['class'] = 'regular-text';
2117
+			$this->_template_args['reg_details']['response_msg']['value']   = $reg_details['response_msg'];
2118
+			$this->_template_args['reg_details']['response_msg']['label']   = esc_html__(
2119
+				'Payment method response',
2120
+				'event_espresso'
2121
+			);
2122
+			$this->_template_args['reg_details']['response_msg']['class']   = 'regular-text';
2123
+		}
2124
+		$this->_template_args['reg_details']['registration_session']['value'] = $reg_details['registration_session'];
2125
+		$this->_template_args['reg_details']['registration_session']['label'] = esc_html__(
2126
+			'Registration Session',
2127
+			'event_espresso'
2128
+		);
2129
+		$this->_template_args['reg_details']['registration_session']['class'] = 'regular-text';
2130
+		$this->_template_args['reg_details']['ip_address']['value']           = $reg_details['ip_address'];
2131
+		$this->_template_args['reg_details']['ip_address']['label']           = esc_html__(
2132
+			'Registration placed from IP',
2133
+			'event_espresso'
2134
+		);
2135
+		$this->_template_args['reg_details']['ip_address']['class']           = 'regular-text';
2136
+		$this->_template_args['reg_details']['user_agent']['value']           = $reg_details['user_agent'];
2137
+		$this->_template_args['reg_details']['user_agent']['label']           = esc_html__('Registrant User Agent',
2138
+			'event_espresso');
2139
+		$this->_template_args['reg_details']['user_agent']['class']           = 'large-text';
2140
+		$this->_template_args['event_link']                                   = EE_Admin_Page::add_query_args_and_nonce(
2141
+			array(
2142
+				'action'   => 'default',
2143
+				'event_id' => $this->_registration->event_ID(),
2144
+			),
2145
+			REG_ADMIN_URL
2146
+		);
2147
+		$this->_template_args['REG_ID']                                       = $this->_registration->ID();
2148
+		$this->_template_args['event_id']                                     = $this->_registration->event_ID();
2149
+		$template_path                                                        =
2150
+			REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_reg_details.template.php';
2151
+		echo EEH_Template::display_template($template_path, $this->_template_args, true);
2152
+	}
2153
+
2154
+
2155
+	/**
2156
+	 * generates HTML for the Registration Questions meta box.
2157
+	 * If pre-4.8.32.rc.000 hooks are used, uses old methods (with its filters),
2158
+	 * otherwise uses new forms system
2159
+	 *
2160
+	 * @access public
2161
+	 * @return void
2162
+	 * @throws DomainException
2163
+	 * @throws EE_Error
2164
+	 */
2165
+	public function _reg_questions_meta_box()
2166
+	{
2167
+		//allow someone to override this method entirely
2168
+		if (apply_filters('FHEE__Registrations_Admin_Page___reg_questions_meta_box__do_default', true, $this,
2169
+			$this->_registration)) {
2170
+			$form                                              = $this->_get_reg_custom_questions_form(
2171
+				$this->_registration->ID()
2172
+			);
2173
+			$this->_template_args['att_questions']             = count($form->subforms()) > 0
2174
+				? $form->get_html_and_js()
2175
+				: '';
2176
+			$this->_template_args['reg_questions_form_action'] = 'edit_registration';
2177
+			$this->_template_args['REG_ID']                    = $this->_registration->ID();
2178
+			$template_path                                     =
2179
+				REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_reg_questions.template.php';
2180
+			echo EEH_Template::display_template($template_path, $this->_template_args, true);
2181
+		}
2182
+	}
2183
+
2184
+
2185
+	/**
2186
+	 * form_before_question_group
2187
+	 *
2188
+	 * @deprecated    as of 4.8.32.rc.000
2189
+	 * @access        public
2190
+	 * @param        string $output
2191
+	 * @return        string
2192
+	 */
2193
+	public function form_before_question_group($output)
2194
+	{
2195
+		EE_Error::doing_it_wrong(
2196
+			__CLASS__ . '::' . __FUNCTION__,
2197
+			esc_html__(
2198
+				'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.',
2199
+				'event_espresso'
2200
+			),
2201
+			'4.8.32.rc.000'
2202
+		);
2203
+		return '
2204 2204
 	<table class="form-table ee-width-100">
2205 2205
 		<tbody>
2206 2206
 			';
2207
-    }
2208
-
2209
-
2210
-    /**
2211
-     * form_after_question_group
2212
-     *
2213
-     * @deprecated    as of 4.8.32.rc.000
2214
-     * @access        public
2215
-     * @param        string $output
2216
-     * @return        string
2217
-     */
2218
-    public function form_after_question_group($output)
2219
-    {
2220
-        EE_Error::doing_it_wrong(
2221
-            __CLASS__ . '::' . __FUNCTION__,
2222
-            esc_html__(
2223
-                '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.',
2224
-                'event_espresso'
2225
-            ),
2226
-            '4.8.32.rc.000'
2227
-        );
2228
-        return '
2207
+	}
2208
+
2209
+
2210
+	/**
2211
+	 * form_after_question_group
2212
+	 *
2213
+	 * @deprecated    as of 4.8.32.rc.000
2214
+	 * @access        public
2215
+	 * @param        string $output
2216
+	 * @return        string
2217
+	 */
2218
+	public function form_after_question_group($output)
2219
+	{
2220
+		EE_Error::doing_it_wrong(
2221
+			__CLASS__ . '::' . __FUNCTION__,
2222
+			esc_html__(
2223
+				'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.',
2224
+				'event_espresso'
2225
+			),
2226
+			'4.8.32.rc.000'
2227
+		);
2228
+		return '
2229 2229
 			<tr class="hide-if-no-js">
2230 2230
 				<th> </th>
2231 2231
 				<td class="reg-admin-edit-attendee-question-td">
2232 2232
 					<a class="reg-admin-edit-attendee-question-lnk" href="#" title="'
2233
-               . esc_attr__('click to edit question', 'event_espresso')
2234
-               . '">
2233
+			   . esc_attr__('click to edit question', 'event_espresso')
2234
+			   . '">
2235 2235
 						<span class="reg-admin-edit-question-group-spn lt-grey-txt">'
2236
-               . esc_html__('edit the above question group', 'event_espresso')
2237
-               . '</span>
2236
+			   . esc_html__('edit the above question group', 'event_espresso')
2237
+			   . '</span>
2238 2238
 						<div class="dashicons dashicons-edit"></div>
2239 2239
 					</a>
2240 2240
 				</td>
@@ -2242,558 +2242,558 @@  discard block
 block discarded – undo
2242 2242
 		</tbody>
2243 2243
 	</table>
2244 2244
 ';
2245
-    }
2246
-
2247
-
2248
-    /**
2249
-     * form_form_field_label_wrap
2250
-     *
2251
-     * @deprecated    as of 4.8.32.rc.000
2252
-     * @access        public
2253
-     * @param        string $label
2254
-     * @return        string
2255
-     */
2256
-    public function form_form_field_label_wrap($label)
2257
-    {
2258
-        EE_Error::doing_it_wrong(
2259
-            __CLASS__ . '::' . __FUNCTION__,
2260
-            esc_html__(
2261
-                '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.',
2262
-                'event_espresso'
2263
-            ),
2264
-            '4.8.32.rc.000'
2265
-        );
2266
-        return '
2245
+	}
2246
+
2247
+
2248
+	/**
2249
+	 * form_form_field_label_wrap
2250
+	 *
2251
+	 * @deprecated    as of 4.8.32.rc.000
2252
+	 * @access        public
2253
+	 * @param        string $label
2254
+	 * @return        string
2255
+	 */
2256
+	public function form_form_field_label_wrap($label)
2257
+	{
2258
+		EE_Error::doing_it_wrong(
2259
+			__CLASS__ . '::' . __FUNCTION__,
2260
+			esc_html__(
2261
+				'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.',
2262
+				'event_espresso'
2263
+			),
2264
+			'4.8.32.rc.000'
2265
+		);
2266
+		return '
2267 2267
 			<tr>
2268 2268
 				<th>
2269 2269
 					' . $label . '
2270 2270
 				</th>';
2271
-    }
2272
-
2273
-
2274
-    /**
2275
-     * form_form_field_input__wrap
2276
-     *
2277
-     * @deprecated    as of 4.8.32.rc.000
2278
-     * @access        public
2279
-     * @param        string $input
2280
-     * @return        string
2281
-     */
2282
-    public function form_form_field_input__wrap($input)
2283
-    {
2284
-        EE_Error::doing_it_wrong(
2285
-            __CLASS__ . '::' . __FUNCTION__,
2286
-            esc_html__(
2287
-                '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.',
2288
-                'event_espresso'
2289
-            ),
2290
-            '4.8.32.rc.000'
2291
-        );
2292
-        return '
2271
+	}
2272
+
2273
+
2274
+	/**
2275
+	 * form_form_field_input__wrap
2276
+	 *
2277
+	 * @deprecated    as of 4.8.32.rc.000
2278
+	 * @access        public
2279
+	 * @param        string $input
2280
+	 * @return        string
2281
+	 */
2282
+	public function form_form_field_input__wrap($input)
2283
+	{
2284
+		EE_Error::doing_it_wrong(
2285
+			__CLASS__ . '::' . __FUNCTION__,
2286
+			esc_html__(
2287
+				'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.',
2288
+				'event_espresso'
2289
+			),
2290
+			'4.8.32.rc.000'
2291
+		);
2292
+		return '
2293 2293
 				<td class="reg-admin-attendee-questions-input-td disabled-input">
2294 2294
 					' . $input . '
2295 2295
 				</td>
2296 2296
 			</tr>';
2297
-    }
2298
-
2299
-
2300
-    /**
2301
-     * Updates the registration's custom questions according to the form info, if the form is submitted.
2302
-     * If it's not a post, the "view_registrations" route will be called next on the SAME request
2303
-     * to display the page
2304
-     *
2305
-     * @access protected
2306
-     * @return void
2307
-     * @throws EE_Error
2308
-     */
2309
-    protected function _update_attendee_registration_form()
2310
-    {
2311
-        do_action('AHEE__Registrations_Admin_Page___update_attendee_registration_form__start', $this);
2312
-        if ($_SERVER['REQUEST_METHOD'] == 'POST') {
2313
-            $REG_ID  = isset($this->_req_data['_REG_ID']) ? absint($this->_req_data['_REG_ID']) : false;
2314
-            $success = $this->_save_reg_custom_questions_form($REG_ID);
2315
-            if ($success) {
2316
-                $what  = esc_html__('Registration Form', 'event_espresso');
2317
-                $route = $REG_ID ? array('action' => 'view_registration', '_REG_ID' => $REG_ID)
2318
-                    : array('action' => 'default');
2319
-                $this->_redirect_after_action($success, $what, esc_html__('updated', 'event_espresso'), $route);
2320
-            }
2321
-        }
2322
-    }
2323
-
2324
-
2325
-    /**
2326
-     * Gets the form for saving registrations custom questions (if done
2327
-     * previously retrieves the cached form object, which may have validation errors in it)
2328
-     *
2329
-     * @param int $REG_ID
2330
-     * @return EE_Registration_Custom_Questions_Form
2331
-     * @throws EE_Error
2332
-     */
2333
-    protected function _get_reg_custom_questions_form($REG_ID)
2334
-    {
2335
-        if ( ! $this->_reg_custom_questions_form) {
2336
-            require_once(REG_ADMIN . 'form_sections' . DS . 'EE_Registration_Custom_Questions_Form.form.php');
2337
-            $this->_reg_custom_questions_form = new EE_Registration_Custom_Questions_Form(
2338
-                EEM_Registration::instance()->get_one_by_ID($REG_ID)
2339
-            );
2340
-            $this->_reg_custom_questions_form->_construct_finalize(null, null);
2341
-        }
2342
-        return $this->_reg_custom_questions_form;
2343
-    }
2344
-
2345
-
2346
-    /**
2347
-     * Saves
2348
-     *
2349
-     * @access private
2350
-     * @param bool $REG_ID
2351
-     * @return bool
2352
-     * @throws EE_Error
2353
-     */
2354
-    private function _save_reg_custom_questions_form($REG_ID = false)
2355
-    {
2356
-        if ( ! $REG_ID) {
2357
-            EE_Error::add_error(
2358
-                esc_html__(
2359
-                    'An error occurred. No registration ID was received.', 'event_espresso'),
2360
-                __FILE__, __FUNCTION__, __LINE__
2361
-            );
2362
-        }
2363
-        $form = $this->_get_reg_custom_questions_form($REG_ID);
2364
-        $form->receive_form_submission($this->_req_data);
2365
-        $success = false;
2366
-        if ($form->is_valid()) {
2367
-            foreach ($form->subforms() as $question_group_id => $question_group_form) {
2368
-                foreach ($question_group_form->inputs() as $question_id => $input) {
2369
-                    $where_conditions    = array(
2370
-                        'QST_ID' => $question_id,
2371
-                        'REG_ID' => $REG_ID,
2372
-                    );
2373
-                    $possibly_new_values = array(
2374
-                        'ANS_value' => $input->normalized_value(),
2375
-                    );
2376
-                    $answer              = EEM_Answer::instance()->get_one(array($where_conditions));
2377
-                    if ($answer instanceof EE_Answer) {
2378
-                        $success = $answer->save($possibly_new_values);
2379
-                    } else {
2380
-                        //insert it then
2381
-                        $cols_n_vals = array_merge($where_conditions, $possibly_new_values);
2382
-                        $answer      = EE_Answer::new_instance($cols_n_vals);
2383
-                        $success     = $answer->save();
2384
-                    }
2385
-                }
2386
-            }
2387
-        } else {
2388
-            EE_Error::add_error($form->get_validation_error_string(), __FILE__, __FUNCTION__, __LINE__);
2389
-        }
2390
-        return $success;
2391
-    }
2392
-
2393
-
2394
-    /**
2395
-     *        generates HTML for the Registration main meta box
2396
-     *
2397
-     * @access public
2398
-     * @return void
2399
-     * @throws DomainException
2400
-     * @throws EE_Error
2401
-     */
2402
-    public function _reg_attendees_meta_box()
2403
-    {
2404
-        $REG = EEM_Registration::instance();
2405
-        //get all other registrations on this transaction, and cache
2406
-        //the attendees for them so we don't have to run another query using force_join
2407
-        $registrations                           = $REG->get_all(array(
2408
-            array(
2409
-                'TXN_ID' => $this->_registration->transaction_ID(),
2410
-                'REG_ID' => array('!=', $this->_registration->ID()),
2411
-            ),
2412
-            'force_join' => array('Attendee'),
2413
-        ));
2414
-        $this->_template_args['attendees']       = array();
2415
-        $this->_template_args['attendee_notice'] = '';
2416
-        if (empty($registrations)
2417
-            || (is_array($registrations)
2418
-                && ! EEH_Array::get_one_item_from_array($registrations))
2419
-        ) {
2420
-            EE_Error::add_error(
2421
-                esc_html__(
2422
-                    'There are no records attached to this registration. Something may have gone wrong with the registration',
2423
-                    'event_espresso'
2424
-                ), __FILE__, __FUNCTION__, __LINE__
2425
-            );
2426
-            $this->_template_args['attendee_notice'] = EE_Error::get_notices();
2427
-        } else {
2428
-            $att_nmbr = 1;
2429
-            foreach ($registrations as $registration) {
2430
-                /* @var $registration EE_Registration */
2431
-                $attendee                                                    = $registration->attendee()
2432
-                    ? $registration->attendee()
2433
-                    : EEM_Attendee::instance()
2434
-                                  ->create_default_object();
2435
-                $this->_template_args['attendees'][$att_nmbr]['STS_ID']      = $registration->status_ID();
2436
-                $this->_template_args['attendees'][$att_nmbr]['fname']       = $attendee->fname();
2437
-                $this->_template_args['attendees'][$att_nmbr]['lname']       = $attendee->lname();
2438
-                $this->_template_args['attendees'][$att_nmbr]['email']       = $attendee->email();
2439
-                $this->_template_args['attendees'][$att_nmbr]['final_price'] = $registration->final_price();
2440
-                $this->_template_args['attendees'][$att_nmbr]['address']     = implode(
2441
-                    ', ',
2442
-                    $attendee->full_address_as_array()
2443
-                );
2444
-                $this->_template_args['attendees'][$att_nmbr]['att_link']    = self::add_query_args_and_nonce(
2445
-                    array(
2446
-                        'action' => 'edit_attendee',
2447
-                        'post'   => $attendee->ID(),
2448
-                    ),
2449
-                    REG_ADMIN_URL
2450
-                );
2451
-                $this->_template_args['attendees'][$att_nmbr]['event_name']  = $registration->event_obj()->name();
2452
-                $att_nmbr++;
2453
-            }
2454
-            $this->_template_args['currency_sign'] = EE_Registry::instance()->CFG->currency->sign;
2455
-        }
2456
-        $template_path = REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_attendees.template.php';
2457
-        echo EEH_Template::display_template($template_path, $this->_template_args, true);
2458
-    }
2459
-
2460
-
2461
-    /**
2462
-     *        generates HTML for the Edit Registration side meta box
2463
-     *
2464
-     * @access public
2465
-     * @return void
2466
-     * @throws DomainException
2467
-     * @throws EE_Error
2468
-     */
2469
-    public function _reg_registrant_side_meta_box()
2470
-    {
2471
-        /*@var $attendee EE_Attendee */
2472
-        $att_check = $this->_registration->attendee();
2473
-        $attendee  = $att_check instanceof EE_Attendee ? $att_check : EEM_Attendee::instance()->create_default_object();
2474
-        //now let's determine if this is not the primary registration.  If it isn't then we set the
2475
-        //primary_registration object for reference BUT ONLY if the Attendee object loaded is not the same as the
2476
-        //primary registration object (that way we know if we need to show create button or not)
2477
-        if ( ! $this->_registration->is_primary_registrant()) {
2478
-            $primary_registration = $this->_registration->get_primary_registration();
2479
-            $primary_attendee     = $primary_registration instanceof EE_Registration ? $primary_registration->attendee()
2480
-                : null;
2481
-            if ( ! $primary_attendee instanceof EE_Attendee || $attendee->ID() !== $primary_attendee->ID()) {
2482
-                //in here?  This means the displayed registration is not the primary registrant but ALREADY HAS its own
2483
-                //custom attendee object so let's not worry about the primary reg.
2484
-                $primary_registration = null;
2485
-            }
2486
-        } else {
2487
-            $primary_registration = null;
2488
-        }
2489
-        $this->_template_args['ATT_ID']            = $attendee->ID();
2490
-        $this->_template_args['fname']             = $attendee->fname();
2491
-        $this->_template_args['lname']             = $attendee->lname();
2492
-        $this->_template_args['email']             = $attendee->email();
2493
-        $this->_template_args['phone']             = $attendee->phone();
2494
-        $this->_template_args['formatted_address'] = EEH_Address::format($attendee);
2495
-        //edit link
2496
-        $this->_template_args['att_edit_link']  = EE_Admin_Page::add_query_args_and_nonce(array(
2497
-            'action' => 'edit_attendee',
2498
-            'post'   => $attendee->ID(),
2499
-        ), REG_ADMIN_URL);
2500
-        $this->_template_args['att_edit_label'] = esc_html__('View/Edit Contact', 'event_espresso');
2501
-        //create link
2502
-        $this->_template_args['create_link']  = $primary_registration instanceof EE_Registration
2503
-            ? EE_Admin_Page::add_query_args_and_nonce(array(
2504
-                'action'  => 'duplicate_attendee',
2505
-                '_REG_ID' => $this->_registration->ID(),
2506
-            ), REG_ADMIN_URL) : '';
2507
-        $this->_template_args['create_label'] = esc_html__('Create Contact', 'event_espresso');
2508
-        $this->_template_args['att_check']    = $att_check;
2509
-        $template_path                        = REG_TEMPLATE_PATH . 'reg_admin_details_side_meta_box_registrant.template.php';
2510
-        echo EEH_Template::display_template($template_path, $this->_template_args, true);
2511
-    }
2512
-
2513
-
2514
-    /**
2515
-     * trash or restore registrations
2516
-     *
2517
-     * @param  boolean $trash whether to archive or restore
2518
-     * @return void
2519
-     * @throws EE_Error
2520
-     * @throws RuntimeException
2521
-     * @access protected
2522
-     */
2523
-    protected function _trash_or_restore_registrations($trash = true)
2524
-    {
2525
-        //if empty _REG_ID then get out because there's nothing to do
2526
-        if (empty($this->_req_data['_REG_ID'])) {
2527
-            EE_Error::add_error(
2528
-                sprintf(
2529
-                    esc_html__(
2530
-                        'In order to %1$s registrations you must select which ones you wish to %1$s by clicking the checkboxes.',
2531
-                        'event_espresso'
2532
-                    ),
2533
-                    $trash ? 'trash' : 'restore'
2534
-                ),
2535
-                __FILE__, __LINE__, __FUNCTION__
2536
-            );
2537
-            $this->_redirect_after_action(false, '', '', array(), true);
2538
-        }
2539
-        $success = 0;
2540
-        $overwrite_msgs = false;
2541
-        //Checkboxes
2542
-        if ( ! is_array($this->_req_data['_REG_ID'])) {
2543
-            $this->_req_data['_REG_ID'] = array($this->_req_data['_REG_ID']);
2544
-        }
2545
-        $reg_count = count($this->_req_data['_REG_ID']);
2546
-        // cycle thru checkboxes
2547
-        foreach ($this->_req_data['_REG_ID'] as $REG_ID) {
2548
-            /** @var EE_Registration $REG */
2549
-            $REG = EEM_Registration::instance()->get_one_by_ID($REG_ID);
2550
-            $payments = $REG->registration_payments();
2551
-            if (! empty($payments)) {
2552
-                $name = $REG->attendee() instanceof EE_Attendee
2553
-                    ? $REG->attendee()->full_name()
2554
-                    : esc_html__('Unknown Attendee', 'event_espresso');
2555
-                $overwrite_msgs = true;
2556
-                EE_Error::add_error(
2557
-                    sprintf(
2558
-                        esc_html__(
2559
-                            '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.',
2560
-                            'event_espresso'
2561
-                        ),
2562
-                        $name
2563
-                    ),
2564
-                    __FILE__, __FUNCTION__, __LINE__
2565
-                );
2566
-                //can't trash this registration because it has payments.
2567
-                continue;
2568
-            }
2569
-            $updated = $trash ? $REG->delete() : $REG->restore();
2570
-            if ($updated) {
2571
-                $success++;
2572
-            }
2573
-        }
2574
-        $this->_redirect_after_action(
2575
-            $success === $reg_count, // were ALL registrations affected?
2576
-            $success > 1
2577
-                ? esc_html__('Registrations', 'event_espresso')
2578
-                : esc_html__('Registration', 'event_espresso'),
2579
-            $trash
2580
-                ? esc_html__('moved to the trash', 'event_espresso')
2581
-                : esc_html__('restored', 'event_espresso'),
2582
-            array('action' => 'default'),
2583
-            $overwrite_msgs
2584
-        );
2585
-    }
2586
-
2587
-
2588
-    /**
2589
-     * This is used to permanently delete registrations.  Note, this will handle not only deleting permanently the
2590
-     * registration but also.
2591
-     * 1. Removing relations to EE_Attendee
2592
-     * 2. Deleting permanently the related transaction, but ONLY if all related registrations to the transaction are
2593
-     * ALSO trashed.
2594
-     * 3. Deleting permanently any related Line items but only if the above conditions are met.
2595
-     * 4. Removing relationships between all tickets and the related registrations
2596
-     * 5. Deleting permanently any related Answers (and the answers for other related registrations that were deleted.)
2597
-     * 6. Deleting permanently any related Checkins.
2598
-     *
2599
-     * @return void
2600
-     * @throws EE_Error
2601
-     */
2602
-    protected function _delete_registrations()
2603
-    {
2604
-        $REG_MDL = EEM_Registration::instance();
2605
-        $success = 1;
2606
-        //Checkboxes
2607
-        if ( ! empty($this->_req_data['_REG_ID']) && is_array($this->_req_data['_REG_ID'])) {
2608
-            // if array has more than one element than success message should be plural
2609
-            $success = count($this->_req_data['_REG_ID']) > 1 ? 2 : 1;
2610
-            // cycle thru checkboxes
2611
-            while (list($ind, $REG_ID) = each($this->_req_data['_REG_ID'])) {
2612
-                $REG = $REG_MDL->get_one_by_ID($REG_ID);
2613
-                if ( ! $REG instanceof EE_Registration) {
2614
-                    continue;
2615
-                }
2616
-                $deleted = $this->_delete_registration($REG);
2617
-                if ( ! $deleted) {
2618
-                    $success = 0;
2619
-                }
2620
-            }
2621
-        } else {
2622
-            // grab single id and delete
2623
-            $REG_ID  = $this->_req_data['_REG_ID'];
2624
-            $REG     = $REG_MDL->get_one_by_ID($REG_ID);
2625
-            $deleted = $this->_delete_registration($REG);
2626
-            if ( ! $deleted) {
2627
-                $success = 0;
2628
-            }
2629
-        }
2630
-        $what        = $success > 1
2631
-            ? esc_html__('Registrations', 'event_espresso')
2632
-            : esc_html__('Registration', 'event_espresso');
2633
-        $action_desc = esc_html__('permanently deleted.', 'event_espresso');
2634
-        $this->_redirect_after_action(
2635
-            $success,
2636
-            $what,
2637
-            $action_desc,
2638
-            array('action' => 'default'),
2639
-            true
2640
-        );
2641
-    }
2642
-
2643
-
2644
-    /**
2645
-     * handles the permanent deletion of a registration.  See comments with _delete_registrations() for details on what
2646
-     * models get affected.
2647
-     *
2648
-     * @param  EE_Registration $REG registration to be deleted permenantly
2649
-     * @return bool true = successful deletion, false = fail.
2650
-     * @throws EE_Error
2651
-     */
2652
-    protected function _delete_registration(EE_Registration $REG)
2653
-    {
2654
-        //first we start with the transaction... ultimately, we WILL not delete permanently if there are any related
2655
-        //registrations on the transaction that are NOT trashed.
2656
-        $TXN         = $REG->get_first_related('Transaction');
2657
-        $REGS        = $TXN->get_many_related('Registration');
2658
-        $all_trashed = true;
2659
-        foreach ($REGS as $registration) {
2660
-            if ( ! $registration->get('REG_deleted')) {
2661
-                $all_trashed = false;
2662
-            }
2663
-        }
2664
-        if ( ! $all_trashed) {
2665
-            EE_Error::add_error(
2666
-                esc_html__(
2667
-                    '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.',
2668
-                    'event_espresso'
2669
-                ),
2670
-                __FILE__, __FUNCTION__, __LINE__
2671
-            );
2672
-            return false;
2673
-        }
2674
-        //k made it here so that means we can delete all the related transactions and their answers (but let's do them
2675
-        //separately from THIS one).
2676
-        foreach ($REGS as $registration) {
2677
-            //delete related answers
2678
-            $registration->delete_related_permanently('Answer');
2679
-            //remove relationship to EE_Attendee (but we ALWAYS leave the contact record intact)
2680
-            $attendee = $registration->get_first_related('Attendee');
2681
-            if ($attendee instanceof EE_Attendee) {
2682
-                $registration->_remove_relation_to($attendee, 'Attendee');
2683
-            }
2684
-            //now remove relationships to tickets on this registration.
2685
-            $registration->_remove_relations('Ticket');
2686
-            //now delete permanently the checkins related to this registration.
2687
-            $registration->delete_related_permanently('Checkin');
2688
-            if ($registration->ID() === $REG->ID()) {
2689
-                continue;
2690
-            } //we don't want to delete permanently the existing registration just yet.
2691
-            //remove relation to transaction for these registrations if NOT the existing registrations
2692
-            $registration->_remove_relations('Transaction');
2693
-            //delete permanently any related messages.
2694
-            $registration->delete_related_permanently('Message');
2695
-            //now delete this registration permanently
2696
-            $registration->delete_permanently();
2697
-        }
2698
-        //now all related registrations on the transaction are handled.  So let's just handle this registration itself
2699
-        // (the transaction and line items should be all that's left).
2700
-        // delete the line items related to the transaction for this registration.
2701
-        $TXN->delete_related_permanently('Line_Item');
2702
-        //we need to remove all the relationships on the transaction
2703
-        $TXN->delete_related_permanently('Payment');
2704
-        $TXN->delete_related_permanently('Extra_Meta');
2705
-        $TXN->delete_related_permanently('Message');
2706
-        //now we can delete this REG permanently (and the transaction of course)
2707
-        $REG->delete_related_permanently('Transaction');
2708
-        return $REG->delete_permanently();
2709
-    }
2710
-
2711
-
2712
-    /**
2713
-     *    generates HTML for the Register New Attendee Admin page
2714
-     *
2715
-     * @access private
2716
-     * @throws DomainException
2717
-     * @throws EE_Error
2718
-     */
2719
-    public function new_registration()
2720
-    {
2721
-        if ( ! $this->_set_reg_event()) {
2722
-            throw new EE_Error(
2723
-                esc_html__(
2724
-                    'Unable to continue with registering because there is no Event ID in the request',
2725
-                    'event_espresso'
2726
-                )
2727
-            );
2728
-        }
2729
-        EE_Registry::instance()->REQ->set_espresso_page(true);
2730
-        // gotta start with a clean slate if we're not coming here via ajax
2731
-        if ( ! defined('DOING_AJAX')
2732
-             && ( ! isset($this->_req_data['processing_registration']) || isset($this->_req_data['step_error']))
2733
-        ) {
2734
-            EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
2735
-        }
2736
-        $this->_template_args['event_name'] = '';
2737
-        // event name
2738
-        if ($this->_reg_event) {
2739
-            $this->_template_args['event_name'] = $this->_reg_event->name();
2740
-            $edit_event_url                     = self::add_query_args_and_nonce(array(
2741
-                'action' => 'edit',
2742
-                'post'   => $this->_reg_event->ID(),
2743
-            ), EVENTS_ADMIN_URL);
2744
-            $edit_event_lnk                     = '<a href="'
2745
-                                                  . $edit_event_url
2746
-                                                  . '" title="'
2747
-                                                  . esc_attr__('Edit ', 'event_espresso')
2748
-                                                  . $this->_reg_event->name()
2749
-                                                  . '">'
2750
-                                                  . esc_html__('Edit Event', 'event_espresso')
2751
-                                                  . '</a>';
2752
-            $this->_template_args['event_name'] .= ' <span class="admin-page-header-edit-lnk not-bold">'
2753
-                                                   . $edit_event_lnk
2754
-                                                   . '</span>';
2755
-        }
2756
-        $this->_template_args['step_content'] = $this->_get_registration_step_content();
2757
-        if (defined('DOING_AJAX')) {
2758
-            $this->_return_json();
2759
-        }
2760
-        // grab header
2761
-        $template_path                              =
2762
-            REG_TEMPLATE_PATH . 'reg_admin_register_new_attendee.template.php';
2763
-        $this->_template_args['admin_page_content'] = EEH_Template::display_template($template_path,
2764
-            $this->_template_args, true);
2765
-        //$this->_set_publish_post_box_vars( NULL, FALSE, FALSE, NULL, FALSE );
2766
-        // the details template wrapper
2767
-        $this->display_admin_page_with_sidebar();
2768
-    }
2769
-
2770
-
2771
-    /**
2772
-     * This returns the content for a registration step
2773
-     *
2774
-     * @access protected
2775
-     * @return string html
2776
-     * @throws DomainException
2777
-     * @throws EE_Error
2778
-     */
2779
-    protected function _get_registration_step_content()
2780
-    {
2781
-        if (isset($_COOKIE['ee_registration_added']) && $_COOKIE['ee_registration_added']) {
2782
-            $warning_msg = sprintf(
2783
-                esc_html__(
2784
-                    '%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',
2785
-                    'event_espresso'
2786
-                ),
2787
-                '<br />',
2788
-                '<h3 class="important-notice">',
2789
-                '</h3>',
2790
-                '<div class="float-right">',
2791
-                '<span id="redirect_timer" class="important-notice">30</span>',
2792
-                '</div>',
2793
-                '<b>',
2794
-                '</b>'
2795
-            );
2796
-            return '
2297
+	}
2298
+
2299
+
2300
+	/**
2301
+	 * Updates the registration's custom questions according to the form info, if the form is submitted.
2302
+	 * If it's not a post, the "view_registrations" route will be called next on the SAME request
2303
+	 * to display the page
2304
+	 *
2305
+	 * @access protected
2306
+	 * @return void
2307
+	 * @throws EE_Error
2308
+	 */
2309
+	protected function _update_attendee_registration_form()
2310
+	{
2311
+		do_action('AHEE__Registrations_Admin_Page___update_attendee_registration_form__start', $this);
2312
+		if ($_SERVER['REQUEST_METHOD'] == 'POST') {
2313
+			$REG_ID  = isset($this->_req_data['_REG_ID']) ? absint($this->_req_data['_REG_ID']) : false;
2314
+			$success = $this->_save_reg_custom_questions_form($REG_ID);
2315
+			if ($success) {
2316
+				$what  = esc_html__('Registration Form', 'event_espresso');
2317
+				$route = $REG_ID ? array('action' => 'view_registration', '_REG_ID' => $REG_ID)
2318
+					: array('action' => 'default');
2319
+				$this->_redirect_after_action($success, $what, esc_html__('updated', 'event_espresso'), $route);
2320
+			}
2321
+		}
2322
+	}
2323
+
2324
+
2325
+	/**
2326
+	 * Gets the form for saving registrations custom questions (if done
2327
+	 * previously retrieves the cached form object, which may have validation errors in it)
2328
+	 *
2329
+	 * @param int $REG_ID
2330
+	 * @return EE_Registration_Custom_Questions_Form
2331
+	 * @throws EE_Error
2332
+	 */
2333
+	protected function _get_reg_custom_questions_form($REG_ID)
2334
+	{
2335
+		if ( ! $this->_reg_custom_questions_form) {
2336
+			require_once(REG_ADMIN . 'form_sections' . DS . 'EE_Registration_Custom_Questions_Form.form.php');
2337
+			$this->_reg_custom_questions_form = new EE_Registration_Custom_Questions_Form(
2338
+				EEM_Registration::instance()->get_one_by_ID($REG_ID)
2339
+			);
2340
+			$this->_reg_custom_questions_form->_construct_finalize(null, null);
2341
+		}
2342
+		return $this->_reg_custom_questions_form;
2343
+	}
2344
+
2345
+
2346
+	/**
2347
+	 * Saves
2348
+	 *
2349
+	 * @access private
2350
+	 * @param bool $REG_ID
2351
+	 * @return bool
2352
+	 * @throws EE_Error
2353
+	 */
2354
+	private function _save_reg_custom_questions_form($REG_ID = false)
2355
+	{
2356
+		if ( ! $REG_ID) {
2357
+			EE_Error::add_error(
2358
+				esc_html__(
2359
+					'An error occurred. No registration ID was received.', 'event_espresso'),
2360
+				__FILE__, __FUNCTION__, __LINE__
2361
+			);
2362
+		}
2363
+		$form = $this->_get_reg_custom_questions_form($REG_ID);
2364
+		$form->receive_form_submission($this->_req_data);
2365
+		$success = false;
2366
+		if ($form->is_valid()) {
2367
+			foreach ($form->subforms() as $question_group_id => $question_group_form) {
2368
+				foreach ($question_group_form->inputs() as $question_id => $input) {
2369
+					$where_conditions    = array(
2370
+						'QST_ID' => $question_id,
2371
+						'REG_ID' => $REG_ID,
2372
+					);
2373
+					$possibly_new_values = array(
2374
+						'ANS_value' => $input->normalized_value(),
2375
+					);
2376
+					$answer              = EEM_Answer::instance()->get_one(array($where_conditions));
2377
+					if ($answer instanceof EE_Answer) {
2378
+						$success = $answer->save($possibly_new_values);
2379
+					} else {
2380
+						//insert it then
2381
+						$cols_n_vals = array_merge($where_conditions, $possibly_new_values);
2382
+						$answer      = EE_Answer::new_instance($cols_n_vals);
2383
+						$success     = $answer->save();
2384
+					}
2385
+				}
2386
+			}
2387
+		} else {
2388
+			EE_Error::add_error($form->get_validation_error_string(), __FILE__, __FUNCTION__, __LINE__);
2389
+		}
2390
+		return $success;
2391
+	}
2392
+
2393
+
2394
+	/**
2395
+	 *        generates HTML for the Registration main meta box
2396
+	 *
2397
+	 * @access public
2398
+	 * @return void
2399
+	 * @throws DomainException
2400
+	 * @throws EE_Error
2401
+	 */
2402
+	public function _reg_attendees_meta_box()
2403
+	{
2404
+		$REG = EEM_Registration::instance();
2405
+		//get all other registrations on this transaction, and cache
2406
+		//the attendees for them so we don't have to run another query using force_join
2407
+		$registrations                           = $REG->get_all(array(
2408
+			array(
2409
+				'TXN_ID' => $this->_registration->transaction_ID(),
2410
+				'REG_ID' => array('!=', $this->_registration->ID()),
2411
+			),
2412
+			'force_join' => array('Attendee'),
2413
+		));
2414
+		$this->_template_args['attendees']       = array();
2415
+		$this->_template_args['attendee_notice'] = '';
2416
+		if (empty($registrations)
2417
+			|| (is_array($registrations)
2418
+				&& ! EEH_Array::get_one_item_from_array($registrations))
2419
+		) {
2420
+			EE_Error::add_error(
2421
+				esc_html__(
2422
+					'There are no records attached to this registration. Something may have gone wrong with the registration',
2423
+					'event_espresso'
2424
+				), __FILE__, __FUNCTION__, __LINE__
2425
+			);
2426
+			$this->_template_args['attendee_notice'] = EE_Error::get_notices();
2427
+		} else {
2428
+			$att_nmbr = 1;
2429
+			foreach ($registrations as $registration) {
2430
+				/* @var $registration EE_Registration */
2431
+				$attendee                                                    = $registration->attendee()
2432
+					? $registration->attendee()
2433
+					: EEM_Attendee::instance()
2434
+								  ->create_default_object();
2435
+				$this->_template_args['attendees'][$att_nmbr]['STS_ID']      = $registration->status_ID();
2436
+				$this->_template_args['attendees'][$att_nmbr]['fname']       = $attendee->fname();
2437
+				$this->_template_args['attendees'][$att_nmbr]['lname']       = $attendee->lname();
2438
+				$this->_template_args['attendees'][$att_nmbr]['email']       = $attendee->email();
2439
+				$this->_template_args['attendees'][$att_nmbr]['final_price'] = $registration->final_price();
2440
+				$this->_template_args['attendees'][$att_nmbr]['address']     = implode(
2441
+					', ',
2442
+					$attendee->full_address_as_array()
2443
+				);
2444
+				$this->_template_args['attendees'][$att_nmbr]['att_link']    = self::add_query_args_and_nonce(
2445
+					array(
2446
+						'action' => 'edit_attendee',
2447
+						'post'   => $attendee->ID(),
2448
+					),
2449
+					REG_ADMIN_URL
2450
+				);
2451
+				$this->_template_args['attendees'][$att_nmbr]['event_name']  = $registration->event_obj()->name();
2452
+				$att_nmbr++;
2453
+			}
2454
+			$this->_template_args['currency_sign'] = EE_Registry::instance()->CFG->currency->sign;
2455
+		}
2456
+		$template_path = REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_attendees.template.php';
2457
+		echo EEH_Template::display_template($template_path, $this->_template_args, true);
2458
+	}
2459
+
2460
+
2461
+	/**
2462
+	 *        generates HTML for the Edit Registration side meta box
2463
+	 *
2464
+	 * @access public
2465
+	 * @return void
2466
+	 * @throws DomainException
2467
+	 * @throws EE_Error
2468
+	 */
2469
+	public function _reg_registrant_side_meta_box()
2470
+	{
2471
+		/*@var $attendee EE_Attendee */
2472
+		$att_check = $this->_registration->attendee();
2473
+		$attendee  = $att_check instanceof EE_Attendee ? $att_check : EEM_Attendee::instance()->create_default_object();
2474
+		//now let's determine if this is not the primary registration.  If it isn't then we set the
2475
+		//primary_registration object for reference BUT ONLY if the Attendee object loaded is not the same as the
2476
+		//primary registration object (that way we know if we need to show create button or not)
2477
+		if ( ! $this->_registration->is_primary_registrant()) {
2478
+			$primary_registration = $this->_registration->get_primary_registration();
2479
+			$primary_attendee     = $primary_registration instanceof EE_Registration ? $primary_registration->attendee()
2480
+				: null;
2481
+			if ( ! $primary_attendee instanceof EE_Attendee || $attendee->ID() !== $primary_attendee->ID()) {
2482
+				//in here?  This means the displayed registration is not the primary registrant but ALREADY HAS its own
2483
+				//custom attendee object so let's not worry about the primary reg.
2484
+				$primary_registration = null;
2485
+			}
2486
+		} else {
2487
+			$primary_registration = null;
2488
+		}
2489
+		$this->_template_args['ATT_ID']            = $attendee->ID();
2490
+		$this->_template_args['fname']             = $attendee->fname();
2491
+		$this->_template_args['lname']             = $attendee->lname();
2492
+		$this->_template_args['email']             = $attendee->email();
2493
+		$this->_template_args['phone']             = $attendee->phone();
2494
+		$this->_template_args['formatted_address'] = EEH_Address::format($attendee);
2495
+		//edit link
2496
+		$this->_template_args['att_edit_link']  = EE_Admin_Page::add_query_args_and_nonce(array(
2497
+			'action' => 'edit_attendee',
2498
+			'post'   => $attendee->ID(),
2499
+		), REG_ADMIN_URL);
2500
+		$this->_template_args['att_edit_label'] = esc_html__('View/Edit Contact', 'event_espresso');
2501
+		//create link
2502
+		$this->_template_args['create_link']  = $primary_registration instanceof EE_Registration
2503
+			? EE_Admin_Page::add_query_args_and_nonce(array(
2504
+				'action'  => 'duplicate_attendee',
2505
+				'_REG_ID' => $this->_registration->ID(),
2506
+			), REG_ADMIN_URL) : '';
2507
+		$this->_template_args['create_label'] = esc_html__('Create Contact', 'event_espresso');
2508
+		$this->_template_args['att_check']    = $att_check;
2509
+		$template_path                        = REG_TEMPLATE_PATH . 'reg_admin_details_side_meta_box_registrant.template.php';
2510
+		echo EEH_Template::display_template($template_path, $this->_template_args, true);
2511
+	}
2512
+
2513
+
2514
+	/**
2515
+	 * trash or restore registrations
2516
+	 *
2517
+	 * @param  boolean $trash whether to archive or restore
2518
+	 * @return void
2519
+	 * @throws EE_Error
2520
+	 * @throws RuntimeException
2521
+	 * @access protected
2522
+	 */
2523
+	protected function _trash_or_restore_registrations($trash = true)
2524
+	{
2525
+		//if empty _REG_ID then get out because there's nothing to do
2526
+		if (empty($this->_req_data['_REG_ID'])) {
2527
+			EE_Error::add_error(
2528
+				sprintf(
2529
+					esc_html__(
2530
+						'In order to %1$s registrations you must select which ones you wish to %1$s by clicking the checkboxes.',
2531
+						'event_espresso'
2532
+					),
2533
+					$trash ? 'trash' : 'restore'
2534
+				),
2535
+				__FILE__, __LINE__, __FUNCTION__
2536
+			);
2537
+			$this->_redirect_after_action(false, '', '', array(), true);
2538
+		}
2539
+		$success = 0;
2540
+		$overwrite_msgs = false;
2541
+		//Checkboxes
2542
+		if ( ! is_array($this->_req_data['_REG_ID'])) {
2543
+			$this->_req_data['_REG_ID'] = array($this->_req_data['_REG_ID']);
2544
+		}
2545
+		$reg_count = count($this->_req_data['_REG_ID']);
2546
+		// cycle thru checkboxes
2547
+		foreach ($this->_req_data['_REG_ID'] as $REG_ID) {
2548
+			/** @var EE_Registration $REG */
2549
+			$REG = EEM_Registration::instance()->get_one_by_ID($REG_ID);
2550
+			$payments = $REG->registration_payments();
2551
+			if (! empty($payments)) {
2552
+				$name = $REG->attendee() instanceof EE_Attendee
2553
+					? $REG->attendee()->full_name()
2554
+					: esc_html__('Unknown Attendee', 'event_espresso');
2555
+				$overwrite_msgs = true;
2556
+				EE_Error::add_error(
2557
+					sprintf(
2558
+						esc_html__(
2559
+							'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.',
2560
+							'event_espresso'
2561
+						),
2562
+						$name
2563
+					),
2564
+					__FILE__, __FUNCTION__, __LINE__
2565
+				);
2566
+				//can't trash this registration because it has payments.
2567
+				continue;
2568
+			}
2569
+			$updated = $trash ? $REG->delete() : $REG->restore();
2570
+			if ($updated) {
2571
+				$success++;
2572
+			}
2573
+		}
2574
+		$this->_redirect_after_action(
2575
+			$success === $reg_count, // were ALL registrations affected?
2576
+			$success > 1
2577
+				? esc_html__('Registrations', 'event_espresso')
2578
+				: esc_html__('Registration', 'event_espresso'),
2579
+			$trash
2580
+				? esc_html__('moved to the trash', 'event_espresso')
2581
+				: esc_html__('restored', 'event_espresso'),
2582
+			array('action' => 'default'),
2583
+			$overwrite_msgs
2584
+		);
2585
+	}
2586
+
2587
+
2588
+	/**
2589
+	 * This is used to permanently delete registrations.  Note, this will handle not only deleting permanently the
2590
+	 * registration but also.
2591
+	 * 1. Removing relations to EE_Attendee
2592
+	 * 2. Deleting permanently the related transaction, but ONLY if all related registrations to the transaction are
2593
+	 * ALSO trashed.
2594
+	 * 3. Deleting permanently any related Line items but only if the above conditions are met.
2595
+	 * 4. Removing relationships between all tickets and the related registrations
2596
+	 * 5. Deleting permanently any related Answers (and the answers for other related registrations that were deleted.)
2597
+	 * 6. Deleting permanently any related Checkins.
2598
+	 *
2599
+	 * @return void
2600
+	 * @throws EE_Error
2601
+	 */
2602
+	protected function _delete_registrations()
2603
+	{
2604
+		$REG_MDL = EEM_Registration::instance();
2605
+		$success = 1;
2606
+		//Checkboxes
2607
+		if ( ! empty($this->_req_data['_REG_ID']) && is_array($this->_req_data['_REG_ID'])) {
2608
+			// if array has more than one element than success message should be plural
2609
+			$success = count($this->_req_data['_REG_ID']) > 1 ? 2 : 1;
2610
+			// cycle thru checkboxes
2611
+			while (list($ind, $REG_ID) = each($this->_req_data['_REG_ID'])) {
2612
+				$REG = $REG_MDL->get_one_by_ID($REG_ID);
2613
+				if ( ! $REG instanceof EE_Registration) {
2614
+					continue;
2615
+				}
2616
+				$deleted = $this->_delete_registration($REG);
2617
+				if ( ! $deleted) {
2618
+					$success = 0;
2619
+				}
2620
+			}
2621
+		} else {
2622
+			// grab single id and delete
2623
+			$REG_ID  = $this->_req_data['_REG_ID'];
2624
+			$REG     = $REG_MDL->get_one_by_ID($REG_ID);
2625
+			$deleted = $this->_delete_registration($REG);
2626
+			if ( ! $deleted) {
2627
+				$success = 0;
2628
+			}
2629
+		}
2630
+		$what        = $success > 1
2631
+			? esc_html__('Registrations', 'event_espresso')
2632
+			: esc_html__('Registration', 'event_espresso');
2633
+		$action_desc = esc_html__('permanently deleted.', 'event_espresso');
2634
+		$this->_redirect_after_action(
2635
+			$success,
2636
+			$what,
2637
+			$action_desc,
2638
+			array('action' => 'default'),
2639
+			true
2640
+		);
2641
+	}
2642
+
2643
+
2644
+	/**
2645
+	 * handles the permanent deletion of a registration.  See comments with _delete_registrations() for details on what
2646
+	 * models get affected.
2647
+	 *
2648
+	 * @param  EE_Registration $REG registration to be deleted permenantly
2649
+	 * @return bool true = successful deletion, false = fail.
2650
+	 * @throws EE_Error
2651
+	 */
2652
+	protected function _delete_registration(EE_Registration $REG)
2653
+	{
2654
+		//first we start with the transaction... ultimately, we WILL not delete permanently if there are any related
2655
+		//registrations on the transaction that are NOT trashed.
2656
+		$TXN         = $REG->get_first_related('Transaction');
2657
+		$REGS        = $TXN->get_many_related('Registration');
2658
+		$all_trashed = true;
2659
+		foreach ($REGS as $registration) {
2660
+			if ( ! $registration->get('REG_deleted')) {
2661
+				$all_trashed = false;
2662
+			}
2663
+		}
2664
+		if ( ! $all_trashed) {
2665
+			EE_Error::add_error(
2666
+				esc_html__(
2667
+					'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.',
2668
+					'event_espresso'
2669
+				),
2670
+				__FILE__, __FUNCTION__, __LINE__
2671
+			);
2672
+			return false;
2673
+		}
2674
+		//k made it here so that means we can delete all the related transactions and their answers (but let's do them
2675
+		//separately from THIS one).
2676
+		foreach ($REGS as $registration) {
2677
+			//delete related answers
2678
+			$registration->delete_related_permanently('Answer');
2679
+			//remove relationship to EE_Attendee (but we ALWAYS leave the contact record intact)
2680
+			$attendee = $registration->get_first_related('Attendee');
2681
+			if ($attendee instanceof EE_Attendee) {
2682
+				$registration->_remove_relation_to($attendee, 'Attendee');
2683
+			}
2684
+			//now remove relationships to tickets on this registration.
2685
+			$registration->_remove_relations('Ticket');
2686
+			//now delete permanently the checkins related to this registration.
2687
+			$registration->delete_related_permanently('Checkin');
2688
+			if ($registration->ID() === $REG->ID()) {
2689
+				continue;
2690
+			} //we don't want to delete permanently the existing registration just yet.
2691
+			//remove relation to transaction for these registrations if NOT the existing registrations
2692
+			$registration->_remove_relations('Transaction');
2693
+			//delete permanently any related messages.
2694
+			$registration->delete_related_permanently('Message');
2695
+			//now delete this registration permanently
2696
+			$registration->delete_permanently();
2697
+		}
2698
+		//now all related registrations on the transaction are handled.  So let's just handle this registration itself
2699
+		// (the transaction and line items should be all that's left).
2700
+		// delete the line items related to the transaction for this registration.
2701
+		$TXN->delete_related_permanently('Line_Item');
2702
+		//we need to remove all the relationships on the transaction
2703
+		$TXN->delete_related_permanently('Payment');
2704
+		$TXN->delete_related_permanently('Extra_Meta');
2705
+		$TXN->delete_related_permanently('Message');
2706
+		//now we can delete this REG permanently (and the transaction of course)
2707
+		$REG->delete_related_permanently('Transaction');
2708
+		return $REG->delete_permanently();
2709
+	}
2710
+
2711
+
2712
+	/**
2713
+	 *    generates HTML for the Register New Attendee Admin page
2714
+	 *
2715
+	 * @access private
2716
+	 * @throws DomainException
2717
+	 * @throws EE_Error
2718
+	 */
2719
+	public function new_registration()
2720
+	{
2721
+		if ( ! $this->_set_reg_event()) {
2722
+			throw new EE_Error(
2723
+				esc_html__(
2724
+					'Unable to continue with registering because there is no Event ID in the request',
2725
+					'event_espresso'
2726
+				)
2727
+			);
2728
+		}
2729
+		EE_Registry::instance()->REQ->set_espresso_page(true);
2730
+		// gotta start with a clean slate if we're not coming here via ajax
2731
+		if ( ! defined('DOING_AJAX')
2732
+			 && ( ! isset($this->_req_data['processing_registration']) || isset($this->_req_data['step_error']))
2733
+		) {
2734
+			EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
2735
+		}
2736
+		$this->_template_args['event_name'] = '';
2737
+		// event name
2738
+		if ($this->_reg_event) {
2739
+			$this->_template_args['event_name'] = $this->_reg_event->name();
2740
+			$edit_event_url                     = self::add_query_args_and_nonce(array(
2741
+				'action' => 'edit',
2742
+				'post'   => $this->_reg_event->ID(),
2743
+			), EVENTS_ADMIN_URL);
2744
+			$edit_event_lnk                     = '<a href="'
2745
+												  . $edit_event_url
2746
+												  . '" title="'
2747
+												  . esc_attr__('Edit ', 'event_espresso')
2748
+												  . $this->_reg_event->name()
2749
+												  . '">'
2750
+												  . esc_html__('Edit Event', 'event_espresso')
2751
+												  . '</a>';
2752
+			$this->_template_args['event_name'] .= ' <span class="admin-page-header-edit-lnk not-bold">'
2753
+												   . $edit_event_lnk
2754
+												   . '</span>';
2755
+		}
2756
+		$this->_template_args['step_content'] = $this->_get_registration_step_content();
2757
+		if (defined('DOING_AJAX')) {
2758
+			$this->_return_json();
2759
+		}
2760
+		// grab header
2761
+		$template_path                              =
2762
+			REG_TEMPLATE_PATH . 'reg_admin_register_new_attendee.template.php';
2763
+		$this->_template_args['admin_page_content'] = EEH_Template::display_template($template_path,
2764
+			$this->_template_args, true);
2765
+		//$this->_set_publish_post_box_vars( NULL, FALSE, FALSE, NULL, FALSE );
2766
+		// the details template wrapper
2767
+		$this->display_admin_page_with_sidebar();
2768
+	}
2769
+
2770
+
2771
+	/**
2772
+	 * This returns the content for a registration step
2773
+	 *
2774
+	 * @access protected
2775
+	 * @return string html
2776
+	 * @throws DomainException
2777
+	 * @throws EE_Error
2778
+	 */
2779
+	protected function _get_registration_step_content()
2780
+	{
2781
+		if (isset($_COOKIE['ee_registration_added']) && $_COOKIE['ee_registration_added']) {
2782
+			$warning_msg = sprintf(
2783
+				esc_html__(
2784
+					'%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',
2785
+					'event_espresso'
2786
+				),
2787
+				'<br />',
2788
+				'<h3 class="important-notice">',
2789
+				'</h3>',
2790
+				'<div class="float-right">',
2791
+				'<span id="redirect_timer" class="important-notice">30</span>',
2792
+				'</div>',
2793
+				'<b>',
2794
+				'</b>'
2795
+			);
2796
+			return '
2797 2797
 	<div id="ee-add-reg-back-button-dv"><p>' . $warning_msg . '</p></div>
2798 2798
 	<script >
2799 2799
 		// WHOAH !!! it appears that someone is using the back button from the Transaction admin page
@@ -2806,792 +2806,792 @@  discard block
 block discarded – undo
2806 2806
 	        }
2807 2807
 	    }, 800 );
2808 2808
 	</script >';
2809
-        }
2810
-        $template_args = array(
2811
-            'title'                    => '',
2812
-            'content'                  => '',
2813
-            'step_button_text'         => '',
2814
-            'show_notification_toggle' => false,
2815
-        );
2816
-        //to indicate we're processing a new registration
2817
-        $hidden_fields = array(
2818
-            'processing_registration' => array(
2819
-                'type'  => 'hidden',
2820
-                'value' => 0,
2821
-            ),
2822
-            'event_id'                => array(
2823
-                'type'  => 'hidden',
2824
-                'value' => $this->_reg_event->ID(),
2825
-            ),
2826
-        );
2827
-        //if the cart is empty then we know we're at step one so we'll display ticket selector
2828
-        $cart = EE_Registry::instance()->SSN->cart();
2829
-        $step = ! $cart instanceof EE_Cart ? 'ticket' : 'questions';
2830
-        switch ($step) {
2831
-            case 'ticket' :
2832
-                $hidden_fields['processing_registration']['value'] = 1;
2833
-                $template_args['title']                            = esc_html__(
2834
-                    'Step One: Select the Ticket for this registration',
2835
-                    'event_espresso'
2836
-                );
2837
-                $template_args['content']                          =
2838
-                    EED_Ticket_Selector::instance()->display_ticket_selector($this->_reg_event);
2839
-                $template_args['step_button_text']                 = esc_html__(
2840
-                    'Add Tickets and Continue to Registrant Details',
2841
-                    'event_espresso'
2842
-                );
2843
-                $template_args['show_notification_toggle']         = false;
2844
-                break;
2845
-            case 'questions' :
2846
-                $hidden_fields['processing_registration']['value'] = 2;
2847
-                $template_args['title']                            = esc_html__(
2848
-                    'Step Two: Add Registrant Details for this Registration',
2849
-                    'event_espresso'
2850
-                );
2851
-                //in theory we should be able to run EED_SPCO at this point because the cart should have been setup
2852
-                // properly by the first process_reg_step run.
2853
-                $template_args['content']                  =
2854
-                    EED_Single_Page_Checkout::registration_checkout_for_admin();
2855
-                $template_args['step_button_text']         = esc_html__(
2856
-                    'Save Registration and Continue to Details',
2857
-                    'event_espresso'
2858
-                );
2859
-                $template_args['show_notification_toggle'] = true;
2860
-                break;
2861
-        }
2862
-        //we come back to the process_registration_step route.
2863
-        $this->_set_add_edit_form_tags('process_reg_step', $hidden_fields);
2864
-        return EEH_Template::display_template(
2865
-            REG_TEMPLATE_PATH . 'reg_admin_register_new_attendee_step_content.template.php',
2866
-            $template_args,
2867
-            true
2868
-        );
2869
-    }
2870
-
2871
-
2872
-    /**
2873
-     *        set_reg_event
2874
-     *
2875
-     * @access private
2876
-     * @return bool
2877
-     * @throws EE_Error
2878
-     */
2879
-    private function _set_reg_event()
2880
-    {
2881
-        if (is_object($this->_reg_event)) {
2882
-            return true;
2883
-        }
2884
-        $EVT_ID = (! empty($this->_req_data['event_id'])) ? absint($this->_req_data['event_id']) : false;
2885
-        if ( ! $EVT_ID) {
2886
-            return false;
2887
-        }
2888
-        $this->_reg_event = EEM_Event::instance()->get_one_by_ID($EVT_ID);
2889
-        return true;
2890
-    }
2891
-
2892
-
2893
-    /**
2894
-     * process_reg_step
2895
-     *
2896
-     * @access        public
2897
-     * @return string
2898
-     * @throws DomainException
2899
-     * @throws EE_Error
2900
-     * @throws RuntimeException
2901
-     */
2902
-    public function process_reg_step()
2903
-    {
2904
-        EE_System::do_not_cache();
2905
-        $this->_set_reg_event();
2906
-        EE_Registry::instance()->REQ->set_espresso_page(true);
2907
-        EE_Registry::instance()->REQ->set('uts', time());
2908
-        //what step are we on?
2909
-        $cart = EE_Registry::instance()->SSN->cart();
2910
-        $step = ! $cart instanceof EE_Cart ? 'ticket' : 'questions';
2911
-        //if doing ajax then we need to verify the nonce
2912
-        if (defined('DOING_AJAX')) {
2913
-            $nonce = isset($this->_req_data[$this->_req_nonce])
2914
-                ? sanitize_text_field($this->_req_data[$this->_req_nonce]) : '';
2915
-            $this->_verify_nonce($nonce, $this->_req_nonce);
2916
-        }
2917
-        switch ($step) {
2918
-            case 'ticket' :
2919
-                //process ticket selection
2920
-                $success = EED_Ticket_Selector::instance()->process_ticket_selections();
2921
-                if ($success) {
2922
-                    EE_Error::add_success(
2923
-                        esc_html__(
2924
-                            'Tickets Selected. Now complete the registration.',
2925
-                            'event_espresso'
2926
-                        )
2927
-                    );
2928
-                } else {
2929
-                    $query_args['step_error'] = $this->_req_data['step_error'] = true;
2930
-                }
2931
-                if (defined('DOING_AJAX')) {
2932
-                    $this->new_registration(); //display next step
2933
-                } else {
2934
-                    $query_args = array(
2935
-                        'action'                  => 'new_registration',
2936
-                        'processing_registration' => 1,
2937
-                        'event_id'                => $this->_reg_event->ID(),
2938
-                        'uts'                     => time(),
2939
-                    );
2940
-                    $this->_redirect_after_action(
2941
-                        false,
2942
-                        '',
2943
-                        '',
2944
-                        $query_args,
2945
-                        true
2946
-                    );
2947
-                }
2948
-                break;
2949
-            case 'questions' :
2950
-                if (! isset(
2951
-                    $this->_req_data['txn_reg_status_change'],
2952
-                    $this->_req_data['txn_reg_status_change']['send_notifications'])
2953
-                ) {
2954
-                    add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_false', 15);
2955
-                }
2956
-                //process registration
2957
-                $transaction = EED_Single_Page_Checkout::instance()->process_registration_from_admin();
2958
-                if ($cart instanceof EE_Cart) {
2959
-                    $grand_total = $cart->get_cart_grand_total();
2960
-                    if ($grand_total instanceof EE_Line_Item) {
2961
-                        $grand_total->save_this_and_descendants_to_txn();
2962
-                    }
2963
-                }
2964
-                if ( ! $transaction instanceof EE_Transaction) {
2965
-                    $query_args = array(
2966
-                        'action'                  => 'new_registration',
2967
-                        'processing_registration' => 2,
2968
-                        'event_id'                => $this->_reg_event->ID(),
2969
-                        'uts'                     => time(),
2970
-                    );
2971
-                    if (defined('DOING_AJAX')) {
2972
-                        //display registration form again because there are errors (maybe validation?)
2973
-                        $this->new_registration();
2974
-                        return;
2975
-                    } else {
2976
-                        $this->_redirect_after_action(
2977
-                            false,
2978
-                            '',
2979
-                            '',
2980
-                            $query_args,
2981
-                            true
2982
-                        );
2983
-                        return;
2984
-                    }
2985
-                }
2986
-                // maybe update status, and make sure to save transaction if not done already
2987
-                if ( ! $transaction->update_status_based_on_total_paid()) {
2988
-                    $transaction->save();
2989
-                }
2990
-                EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
2991
-                $this->_req_data = array();
2992
-                $query_args      = array(
2993
-                    'action'        => 'redirect_to_txn',
2994
-                    'TXN_ID'        => $transaction->ID(),
2995
-                    'EVT_ID'        => $this->_reg_event->ID(),
2996
-                    'event_name'    => urlencode($this->_reg_event->name()),
2997
-                    'redirect_from' => 'new_registration',
2998
-                );
2999
-                $this->_redirect_after_action(false, '', '', $query_args, true);
3000
-                break;
3001
-        }
3002
-        //what are you looking here for?  Should be nothing to do at this point.
3003
-    }
3004
-
3005
-
3006
-    /**
3007
-     * redirect_to_txn
3008
-     *
3009
-     * @access public
3010
-     * @return void
3011
-     * @throws EE_Error
3012
-     */
3013
-    public function redirect_to_txn()
3014
-    {
3015
-        EE_System::do_not_cache();
3016
-        EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
3017
-        $query_args = array(
3018
-            'action' => 'view_transaction',
3019
-            'TXN_ID' => isset($this->_req_data['TXN_ID']) ? absint($this->_req_data['TXN_ID']) : 0,
3020
-            'page'   => 'espresso_transactions',
3021
-        );
3022
-        if (isset($this->_req_data['EVT_ID'], $this->_req_data['redirect_from'])) {
3023
-            $query_args['EVT_ID']        = $this->_req_data['EVT_ID'];
3024
-            $query_args['event_name']    = urlencode($this->_req_data['event_name']);
3025
-            $query_args['redirect_from'] = $this->_req_data['redirect_from'];
3026
-        }
3027
-        EE_Error::add_success(
3028
-            esc_html__(
3029
-                'Registration Created.  Please review the transaction and add any payments as necessary',
3030
-                'event_espresso'
3031
-            )
3032
-        );
3033
-        $this->_redirect_after_action(false, '', '', $query_args, true);
3034
-    }
3035
-
3036
-
3037
-    /**
3038
-     *        generates HTML for the Attendee Contact List
3039
-     *
3040
-     * @access protected
3041
-     * @return void
3042
-     */
3043
-    protected function _attendee_contact_list_table()
3044
-    {
3045
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3046
-        $this->_search_btn_label = esc_html__('Contacts', 'event_espresso');
3047
-        $this->display_admin_list_table_page_with_no_sidebar();
3048
-    }
3049
-
3050
-
3051
-    /**
3052
-     *        get_attendees
3053
-     *
3054
-     * @param      $per_page
3055
-     * @param bool $count whether to return count or data.
3056
-     * @param bool $trash
3057
-     * @return array
3058
-     * @throws EE_Error
3059
-     * @access public
3060
-     */
3061
-    public function get_attendees($per_page, $count = false, $trash = false)
3062
-    {
3063
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3064
-        require_once(REG_ADMIN . 'EE_Attendee_Contact_List_Table.class.php');
3065
-        $ATT_MDL                    = EEM_Attendee::instance();
3066
-        $this->_req_data['orderby'] = ! empty($this->_req_data['orderby']) ? $this->_req_data['orderby'] : '';
3067
-        switch ($this->_req_data['orderby']) {
3068
-            case 'ATT_ID':
3069
-                $orderby = 'ATT_ID';
3070
-                break;
3071
-            case 'ATT_fname':
3072
-                $orderby = 'ATT_fname';
3073
-                break;
3074
-            case 'ATT_email':
3075
-                $orderby = 'ATT_email';
3076
-                break;
3077
-            case 'ATT_city':
3078
-                $orderby = 'ATT_city';
3079
-                break;
3080
-            case 'STA_ID':
3081
-                $orderby = 'STA_ID';
3082
-                break;
3083
-            case 'CNT_ID':
3084
-                $orderby = 'CNT_ID';
3085
-                break;
3086
-            default:
3087
-                $orderby = 'ATT_lname';
3088
-        }
3089
-        $sort         = (isset($this->_req_data['order']) && ! empty($this->_req_data['order']))
3090
-            ? $this->_req_data['order']
3091
-            : 'ASC';
3092
-        $current_page = isset($this->_req_data['paged']) && ! empty($this->_req_data['paged'])
3093
-            ? $this->_req_data['paged']
3094
-            : 1;
3095
-        $per_page     = isset($per_page) && ! empty($per_page) ? $per_page : 10;
3096
-        $per_page     = isset($this->_req_data['perpage']) && ! empty($this->_req_data['perpage'])
3097
-            ? $this->_req_data['perpage']
3098
-            : $per_page;
3099
-        $_where       = array();
3100
-        if ( ! empty($this->_req_data['s'])) {
3101
-            $sstr         = '%' . $this->_req_data['s'] . '%';
3102
-            $_where['OR'] = array(
3103
-                'Registration.Event.EVT_name'       => array('LIKE', $sstr),
3104
-                'Registration.Event.EVT_desc'       => array('LIKE', $sstr),
3105
-                'Registration.Event.EVT_short_desc' => array('LIKE', $sstr),
3106
-                'ATT_fname'                         => array('LIKE', $sstr),
3107
-                'ATT_lname'                         => array('LIKE', $sstr),
3108
-                'ATT_short_bio'                     => array('LIKE', $sstr),
3109
-                'ATT_email'                         => array('LIKE', $sstr),
3110
-                'ATT_address'                       => array('LIKE', $sstr),
3111
-                'ATT_address2'                      => array('LIKE', $sstr),
3112
-                'ATT_city'                          => array('LIKE', $sstr),
3113
-                'Country.CNT_name'                  => array('LIKE', $sstr),
3114
-                'State.STA_name'                    => array('LIKE', $sstr),
3115
-                'ATT_phone'                         => array('LIKE', $sstr),
3116
-                'Registration.REG_final_price'      => array('LIKE', $sstr),
3117
-                'Registration.REG_code'             => array('LIKE', $sstr),
3118
-                'Registration.REG_count'            => array('LIKE', $sstr),
3119
-                'Registration.REG_group_size'       => array('LIKE', $sstr),
3120
-            );
3121
-        }
3122
-        $offset = ($current_page - 1) * $per_page;
3123
-        $limit  = $count ? null : array($offset, $per_page);
3124
-        if ($trash) {
3125
-            $_where['status'] = array('!=', 'publish');
3126
-            $all_attendees    = $count
3127
-                ? $ATT_MDL->count(array(
3128
-                    $_where,
3129
-                    'order_by' => array($orderby => $sort),
3130
-                    'limit'    => $limit,
3131
-                ), 'ATT_ID', true)
3132
-                : $ATT_MDL->get_all(array(
3133
-                    $_where,
3134
-                    'order_by' => array($orderby => $sort),
3135
-                    'limit'    => $limit,
3136
-                ));
3137
-        } else {
3138
-            $_where['status'] = array('IN', array('publish'));
3139
-            $all_attendees    = $count
3140
-                ? $ATT_MDL->count(array(
3141
-                    $_where,
3142
-                    'order_by' => array($orderby => $sort),
3143
-                    'limit'    => $limit,
3144
-                ), 'ATT_ID', true)
3145
-                : $ATT_MDL->get_all(array(
3146
-                    $_where,
3147
-                    'order_by' => array($orderby => $sort),
3148
-                    'limit'    => $limit,
3149
-                ));
3150
-        }
3151
-        return $all_attendees;
3152
-    }
3153
-
3154
-
3155
-    /**
3156
-     * This is just taking care of resending the registration confirmation
3157
-     *
3158
-     * @access protected
3159
-     * @return void
3160
-     */
3161
-    protected function _resend_registration()
3162
-    {
3163
-        $this->_process_resend_registration();
3164
-        $query_args = isset($this->_req_data['redirect_to'])
3165
-            ? array('action' => $this->_req_data['redirect_to'], '_REG_ID' => $this->_req_data['_REG_ID'])
3166
-            : array('action' => 'default');
3167
-        $this->_redirect_after_action(false, '', '', $query_args, true);
3168
-    }
3169
-
3170
-    /**
3171
-     * Creates a registration report, but accepts the name of a method to use for preparing the query parameters
3172
-     * to use when selecting registrations
3173
-     * @param string $method_name_for_getting_query_params the name of the method (on this class) to use for preparing
3174
-     *                                                     the query parameters from the request
3175
-     * @return void ends the request with a redirect or download
3176
-     */
3177
-    public function _registrations_report_base( $method_name_for_getting_query_params )
3178
-    {
3179
-        if (! defined('EE_USE_OLD_CSV_REPORT_CLASS')) {
3180
-            wp_redirect(EE_Admin_Page::add_query_args_and_nonce(
3181
-                array(
3182
-                    'page'        => 'espresso_batch',
3183
-                    'batch'       => 'file',
3184
-                    'EVT_ID'      => isset($this->_req_data['EVT_ID']) ? $this->_req_data['EVT_ID'] : null,
3185
-                    'filters'     => urlencode(
3186
-                        serialize(
3187
-                            call_user_func(
3188
-                                array( $this, $method_name_for_getting_query_params ),
3189
-                                EEH_Array::is_set(
3190
-                                    $this->_req_data,
3191
-                                    'filters',
3192
-                                    array()
3193
-                                )
3194
-                            )
3195
-                        )
3196
-                ),
3197
-                'use_filters' => EEH_Array::is_set($this->_req_data, 'use_filters', false),
3198
-                'job_handler' => urlencode('EventEspressoBatchRequest\JobHandlers\RegistrationsReport'),
3199
-                'return_url'  => urlencode($this->_req_data['return_url']),
3200
-            )));
3201
-        } else {
3202
-            $new_request_args = array(
3203
-                'export' => 'report',
3204
-                'action' => 'registrations_report_for_event',
3205
-                'EVT_ID' => isset($this->_req_data['EVT_ID']) ? $this->_req_data['EVT_ID'] : null,
3206
-            );
3207
-            $this->_req_data = array_merge($this->_req_data, $new_request_args);
3208
-            if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
3209
-                require_once(EE_CLASSES . 'EE_Export.class.php');
3210
-                $EE_Export = EE_Export::instance($this->_req_data);
3211
-                $EE_Export->export();
3212
-            }
3213
-        }
3214
-    }
3215
-
3216
-
3217
-
3218
-    /**
3219
-     * Creates a registration report using only query parameters in the request
3220
-     * @return void
3221
-     */
3222
-    public function _registrations_report()
3223
-    {
3224
-        $this->_registrations_report_base('_get_registration_query_parameters');
3225
-    }
3226
-
3227
-
3228
-    public function _contact_list_export()
3229
-    {
3230
-        if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
3231
-            require_once(EE_CLASSES . 'EE_Export.class.php');
3232
-            $EE_Export = EE_Export::instance($this->_req_data);
3233
-            $EE_Export->export_attendees();
3234
-        }
3235
-    }
3236
-
3237
-
3238
-    public function _contact_list_report()
3239
-    {
3240
-        if ( ! defined('EE_USE_OLD_CSV_REPORT_CLASS')) {
3241
-            wp_redirect(EE_Admin_Page::add_query_args_and_nonce(array(
3242
-                'page'        => 'espresso_batch',
3243
-                'batch'       => 'file',
3244
-                'job_handler' => urlencode('EventEspressoBatchRequest\JobHandlers\AttendeesReport'),
3245
-                'return_url'  => urlencode($this->_req_data['return_url']),
3246
-            )));
3247
-        } else {
3248
-            if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
3249
-                require_once(EE_CLASSES . 'EE_Export.class.php');
3250
-                $EE_Export = EE_Export::instance($this->_req_data);
3251
-                $EE_Export->report_attendees();
3252
-            }
3253
-        }
3254
-    }
3255
-
3256
-
3257
-
3258
-
3259
-
3260
-    /***************************************        ATTENDEE DETAILS        ***************************************/
3261
-    /**
3262
-     * This duplicates the attendee object for the given incoming registration id and attendee_id.
3263
-     *
3264
-     * @return void
3265
-     * @throws EE_Error
3266
-     */
3267
-    protected function _duplicate_attendee()
3268
-    {
3269
-        $action = ! empty($this->_req_data['return']) ? $this->_req_data['return'] : 'default';
3270
-        //verify we have necessary info
3271
-        if (empty($this->_req_data['_REG_ID'])) {
3272
-            EE_Error::add_error(
3273
-                esc_html__(
3274
-                    'Unable to create the contact for the registration because the required parameters are not present (_REG_ID )',
3275
-                    'event_espresso'
3276
-                ), __FILE__, __LINE__, __FUNCTION__
3277
-            );
3278
-            $query_args = array('action' => $action);
3279
-            $this->_redirect_after_action('', '', '', $query_args, true);
3280
-        }
3281
-        //okay necessary deets present... let's dupe the incoming attendee and attach to incoming registration.
3282
-        $registration = EEM_Registration::instance()->get_one_by_ID($this->_req_data['_REG_ID']);
3283
-        $attendee     = $registration->attendee();
3284
-        //remove relation of existing attendee on registration
3285
-        $registration->_remove_relation_to($attendee, 'Attendee');
3286
-        //new attendee
3287
-        $new_attendee = clone $attendee;
3288
-        $new_attendee->set('ATT_ID', 0);
3289
-        $new_attendee->save();
3290
-        //add new attendee to reg
3291
-        $registration->_add_relation_to($new_attendee, 'Attendee');
3292
-        EE_Error::add_success(
3293
-            esc_html__(
3294
-                'New Contact record created.  Now make any edits you wish to make for this contact.',
3295
-                'event_espresso'
3296
-            )
3297
-        );
3298
-        //redirect to edit page for attendee
3299
-        $query_args = array('post' => $new_attendee->ID(), 'action' => 'edit_attendee');
3300
-        $this->_redirect_after_action('', '', '', $query_args, true);
3301
-    }
3302
-
3303
-
3304
-    //related to cpt routes
3305
-    protected function _insert_update_cpt_item($post_id, $post)
3306
-    {
3307
-        $success  = true;
3308
-        $attendee = EEM_Attendee::instance()->get_one_by_ID($post_id);
3309
-        //for attendee updates
3310
-        if ($post->post_type = 'espresso_attendees' && ! empty($attendee)) {
3311
-            //note we should only be UPDATING attendees at this point.
3312
-            $updated_fields = array(
3313
-                'ATT_fname'     => $this->_req_data['ATT_fname'],
3314
-                'ATT_lname'     => $this->_req_data['ATT_lname'],
3315
-                'ATT_full_name' => $this->_req_data['ATT_fname'] . ' ' . $this->_req_data['ATT_lname'],
3316
-                'ATT_address'   => isset($this->_req_data['ATT_address']) ? $this->_req_data['ATT_address'] : '',
3317
-                'ATT_address2'  => isset($this->_req_data['ATT_address2']) ? $this->_req_data['ATT_address2'] : '',
3318
-                'ATT_city'      => isset($this->_req_data['ATT_city']) ? $this->_req_data['ATT_city'] : '',
3319
-                'STA_ID'        => isset($this->_req_data['STA_ID']) ? $this->_req_data['STA_ID'] : '',
3320
-                'CNT_ISO'       => isset($this->_req_data['CNT_ISO']) ? $this->_req_data['CNT_ISO'] : '',
3321
-                'ATT_zip'       => isset($this->_req_data['ATT_zip']) ? $this->_req_data['ATT_zip'] : '',
3322
-                'ATT_email'     => isset($this->_req_data['ATT_email']) ? $this->_req_data['ATT_email'] : '',
3323
-                'ATT_phone'     => isset($this->_req_data['ATT_phone']) ? $this->_req_data['ATT_phone'] : '',
3324
-            );
3325
-            foreach ($updated_fields as $field => $value) {
3326
-                $attendee->set($field, $value);
3327
-            }
3328
-            $success                   = $attendee->save();
3329
-            $attendee_update_callbacks = apply_filters(
3330
-                'FHEE__Registrations_Admin_Page__insert_update_cpt_item__attendee_update',
3331
-                array()
3332
-            );
3333
-            foreach ($attendee_update_callbacks as $a_callback) {
3334
-                if (false === call_user_func_array($a_callback, array($attendee, $this->_req_data))) {
3335
-                    throw new EE_Error(
3336
-                        sprintf(
3337
-                            esc_html__(
3338
-                                '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.',
3339
-                                'event_espresso'
3340
-                            ),
3341
-                            $a_callback
3342
-                        )
3343
-                    );
3344
-                }
3345
-            }
3346
-        }
3347
-        if ($success === false) {
3348
-            EE_Error::add_error(
3349
-                esc_html__(
3350
-                    'Something went wrong with updating the meta table data for the registration.',
3351
-                    'event_espresso'
3352
-                ),
3353
-                __FILE__, __FUNCTION__, __LINE__
3354
-            );
3355
-        }
3356
-    }
3357
-
3358
-
3359
-    public function trash_cpt_item($post_id)
3360
-    {
3361
-    }
3362
-
3363
-
3364
-    public function delete_cpt_item($post_id)
3365
-    {
3366
-    }
3367
-
3368
-
3369
-    public function restore_cpt_item($post_id)
3370
-    {
3371
-    }
3372
-
3373
-
3374
-    protected function _restore_cpt_item($post_id, $revision_id)
3375
-    {
3376
-    }
3377
-
3378
-
3379
-    public function attendee_editor_metaboxes()
3380
-    {
3381
-        $this->verify_cpt_object();
3382
-        remove_meta_box(
3383
-            'postexcerpt',
3384
-            esc_html__('Excerpt', 'event_espresso'),
3385
-            'post_excerpt_meta_box',
3386
-            $this->_cpt_routes[$this->_req_action],
3387
-            'normal',
3388
-            'core'
3389
-        );
3390
-        remove_meta_box('commentstatusdiv', $this->_cpt_routes[$this->_req_action], 'normal', 'core');
3391
-        if (post_type_supports('espresso_attendees', 'excerpt')) {
3392
-            add_meta_box(
3393
-                'postexcerpt',
3394
-                esc_html__('Short Biography', 'event_espresso'),
3395
-                'post_excerpt_meta_box',
3396
-                $this->_cpt_routes[$this->_req_action],
3397
-                'normal'
3398
-            );
3399
-        }
3400
-        if (post_type_supports('espresso_attendees', 'comments')) {
3401
-            add_meta_box(
3402
-                'commentsdiv',
3403
-                esc_html__('Notes on the Contact', 'event_espresso'),
3404
-                'post_comment_meta_box',
3405
-                $this->_cpt_routes[$this->_req_action],
3406
-                'normal',
3407
-                'core'
3408
-            );
3409
-        }
3410
-        add_meta_box(
3411
-            'attendee_contact_info',
3412
-            esc_html__('Contact Info', 'event_espresso'),
3413
-            array($this, 'attendee_contact_info'),
3414
-            $this->_cpt_routes[$this->_req_action],
3415
-            'side',
3416
-            'core'
3417
-        );
3418
-        add_meta_box(
3419
-            'attendee_details_address',
3420
-            esc_html__('Address Details', 'event_espresso'),
3421
-            array($this, 'attendee_address_details'),
3422
-            $this->_cpt_routes[$this->_req_action],
3423
-            'normal',
3424
-            'core'
3425
-        );
3426
-        add_meta_box(
3427
-            'attendee_registrations',
3428
-            esc_html__('Registrations for this Contact', 'event_espresso'),
3429
-            array($this, 'attendee_registrations_meta_box'),
3430
-            $this->_cpt_routes[$this->_req_action],
3431
-            'normal',
3432
-            'high'
3433
-        );
3434
-    }
3435
-
3436
-
3437
-    /**
3438
-     * Metabox for attendee contact info
3439
-     *
3440
-     * @param  WP_Post $post wp post object
3441
-     * @return string attendee contact info ( and form )
3442
-     * @throws DomainException
3443
-     */
3444
-    public function attendee_contact_info($post)
3445
-    {
3446
-        //get attendee object ( should already have it )
3447
-        $this->_template_args['attendee'] = $this->_cpt_model_obj;
3448
-        $template                         = REG_TEMPLATE_PATH . 'attendee_contact_info_metabox_content.template.php';
3449
-        EEH_Template::display_template($template, $this->_template_args);
3450
-    }
3451
-
3452
-
3453
-    /**
3454
-     * Metabox for attendee details
3455
-     *
3456
-     * @param  WP_Post $post wp post object
3457
-     * @return string attendee address details (and form)
3458
-     * @throws DomainException
3459
-     */
3460
-    public function attendee_address_details($post)
3461
-    {
3462
-        //get attendee object (should already have it)
3463
-        $this->_template_args['attendee']     = $this->_cpt_model_obj;
3464
-        $this->_template_args['state_html']   = EEH_Form_Fields::generate_form_input(
3465
-            new EE_Question_Form_Input(
3466
-                EE_Question::new_instance(
3467
-                    array(
3468
-                        'QST_ID'           => 0,
3469
-                        'QST_display_text' => esc_html__('State/Province', 'event_espresso'),
3470
-                        'QST_system'       => 'admin-state',
3471
-                    )
3472
-                ),
3473
-                EE_Answer::new_instance(
3474
-                    array(
3475
-                        'ANS_ID'    => 0,
3476
-                        'ANS_value' => $this->_cpt_model_obj->state_ID(),
3477
-                    )
3478
-                ),
3479
-                array(
3480
-                    'input_id'       => 'STA_ID',
3481
-                    'input_name'     => 'STA_ID',
3482
-                    'input_prefix'   => '',
3483
-                    'append_qstn_id' => false,
3484
-                )
3485
-            )
3486
-        );
3487
-        $this->_template_args['country_html'] = EEH_Form_Fields::generate_form_input(
3488
-            new EE_Question_Form_Input(
3489
-                EE_Question::new_instance(
3490
-                    array(
3491
-                        'QST_ID'           => 0,
3492
-                        'QST_display_text' => esc_html__('Country', 'event_espresso'),
3493
-                        'QST_system'       => 'admin-country',
3494
-                    )
3495
-                ),
3496
-                EE_Answer::new_instance(
3497
-                    array(
3498
-                        'ANS_ID'    => 0,
3499
-                        'ANS_value' => $this->_cpt_model_obj->country_ID(),
3500
-                    )
3501
-                ),
3502
-                array(
3503
-                    'input_id'       => 'CNT_ISO',
3504
-                    'input_name'     => 'CNT_ISO',
3505
-                    'input_prefix'   => '',
3506
-                    'append_qstn_id' => false,
3507
-                )
3508
-            )
3509
-        );
3510
-        $template                             =
3511
-            REG_TEMPLATE_PATH . 'attendee_address_details_metabox_content.template.php';
3512
-        EEH_Template::display_template($template, $this->_template_args);
3513
-    }
3514
-
3515
-
3516
-    /**
3517
-     *        _attendee_details
3518
-     *
3519
-     * @access protected
3520
-     * @param $post
3521
-     * @return void
3522
-     * @throws DomainException
3523
-     * @throws EE_Error
3524
-     */
3525
-    public function attendee_registrations_meta_box($post)
3526
-    {
3527
-        $this->_template_args['attendee']      = $this->_cpt_model_obj;
3528
-        $this->_template_args['registrations'] = $this->_cpt_model_obj->get_many_related('Registration');
3529
-        $template                              =
3530
-            REG_TEMPLATE_PATH . 'attendee_registrations_main_meta_box.template.php';
3531
-        EEH_Template::display_template($template, $this->_template_args);
3532
-    }
3533
-
3534
-
3535
-    /**
3536
-     * add in the form fields for the attendee edit
3537
-     *
3538
-     * @param  WP_Post $post wp post object
3539
-     * @return string html for new form.
3540
-     * @throws DomainException
3541
-     */
3542
-    public function after_title_form_fields($post)
3543
-    {
3544
-        if ($post->post_type == 'espresso_attendees') {
3545
-            $template                  = REG_TEMPLATE_PATH . 'attendee_details_after_title_form_fields.template.php';
3546
-            $template_args['attendee'] = $this->_cpt_model_obj;
3547
-            EEH_Template::display_template($template, $template_args);
3548
-        }
3549
-    }
3550
-
3551
-
3552
-    /**
3553
-     *        _trash_or_restore_attendee
3554
-     *
3555
-     * @param boolean $trash - whether to move item to trash (TRUE) or restore it (FALSE)
3556
-     * @return void
3557
-     * @throws EE_Error
3558
-     * @access protected
3559
-     */
3560
-    protected function _trash_or_restore_attendees($trash = true)
3561
-    {
3562
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3563
-        $ATT_MDL = EEM_Attendee::instance();
3564
-        $success = 1;
3565
-        //Checkboxes
3566
-        if ( ! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
3567
-            // if array has more than one element than success message should be plural
3568
-            $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1;
3569
-            // cycle thru checkboxes
3570
-            while (list($ATT_ID, $value) = each($this->_req_data['checkbox'])) {
3571
-                $updated = $trash ? $ATT_MDL->update_by_ID(array('status' => 'trash'), $ATT_ID)
3572
-                    : $ATT_MDL->update_by_ID(array('status' => 'publish'), $ATT_ID);
3573
-                if ( ! $updated) {
3574
-                    $success = 0;
3575
-                }
3576
-            }
3577
-        } else {
3578
-            // grab single id and delete
3579
-            $ATT_ID = absint($this->_req_data['ATT_ID']);
3580
-            //get attendee
3581
-            $att     = $ATT_MDL->get_one_by_ID($ATT_ID);
3582
-            $updated = $trash ? $att->set_status('trash') : $att->set_status('publish');
3583
-            $updated = $att->save();
3584
-            if ( ! $updated) {
3585
-                $success = 0;
3586
-            }
3587
-        }
3588
-        $what        = $success > 1
3589
-            ? esc_html__('Contacts', 'event_espresso')
3590
-            : esc_html__('Contact', 'event_espresso');
3591
-        $action_desc = $trash
3592
-            ? esc_html__('moved to the trash', 'event_espresso')
3593
-            : esc_html__('restored', 'event_espresso');
3594
-        $this->_redirect_after_action($success, $what, $action_desc, array('action' => 'contact_list'));
3595
-    }
2809
+		}
2810
+		$template_args = array(
2811
+			'title'                    => '',
2812
+			'content'                  => '',
2813
+			'step_button_text'         => '',
2814
+			'show_notification_toggle' => false,
2815
+		);
2816
+		//to indicate we're processing a new registration
2817
+		$hidden_fields = array(
2818
+			'processing_registration' => array(
2819
+				'type'  => 'hidden',
2820
+				'value' => 0,
2821
+			),
2822
+			'event_id'                => array(
2823
+				'type'  => 'hidden',
2824
+				'value' => $this->_reg_event->ID(),
2825
+			),
2826
+		);
2827
+		//if the cart is empty then we know we're at step one so we'll display ticket selector
2828
+		$cart = EE_Registry::instance()->SSN->cart();
2829
+		$step = ! $cart instanceof EE_Cart ? 'ticket' : 'questions';
2830
+		switch ($step) {
2831
+			case 'ticket' :
2832
+				$hidden_fields['processing_registration']['value'] = 1;
2833
+				$template_args['title']                            = esc_html__(
2834
+					'Step One: Select the Ticket for this registration',
2835
+					'event_espresso'
2836
+				);
2837
+				$template_args['content']                          =
2838
+					EED_Ticket_Selector::instance()->display_ticket_selector($this->_reg_event);
2839
+				$template_args['step_button_text']                 = esc_html__(
2840
+					'Add Tickets and Continue to Registrant Details',
2841
+					'event_espresso'
2842
+				);
2843
+				$template_args['show_notification_toggle']         = false;
2844
+				break;
2845
+			case 'questions' :
2846
+				$hidden_fields['processing_registration']['value'] = 2;
2847
+				$template_args['title']                            = esc_html__(
2848
+					'Step Two: Add Registrant Details for this Registration',
2849
+					'event_espresso'
2850
+				);
2851
+				//in theory we should be able to run EED_SPCO at this point because the cart should have been setup
2852
+				// properly by the first process_reg_step run.
2853
+				$template_args['content']                  =
2854
+					EED_Single_Page_Checkout::registration_checkout_for_admin();
2855
+				$template_args['step_button_text']         = esc_html__(
2856
+					'Save Registration and Continue to Details',
2857
+					'event_espresso'
2858
+				);
2859
+				$template_args['show_notification_toggle'] = true;
2860
+				break;
2861
+		}
2862
+		//we come back to the process_registration_step route.
2863
+		$this->_set_add_edit_form_tags('process_reg_step', $hidden_fields);
2864
+		return EEH_Template::display_template(
2865
+			REG_TEMPLATE_PATH . 'reg_admin_register_new_attendee_step_content.template.php',
2866
+			$template_args,
2867
+			true
2868
+		);
2869
+	}
2870
+
2871
+
2872
+	/**
2873
+	 *        set_reg_event
2874
+	 *
2875
+	 * @access private
2876
+	 * @return bool
2877
+	 * @throws EE_Error
2878
+	 */
2879
+	private function _set_reg_event()
2880
+	{
2881
+		if (is_object($this->_reg_event)) {
2882
+			return true;
2883
+		}
2884
+		$EVT_ID = (! empty($this->_req_data['event_id'])) ? absint($this->_req_data['event_id']) : false;
2885
+		if ( ! $EVT_ID) {
2886
+			return false;
2887
+		}
2888
+		$this->_reg_event = EEM_Event::instance()->get_one_by_ID($EVT_ID);
2889
+		return true;
2890
+	}
2891
+
2892
+
2893
+	/**
2894
+	 * process_reg_step
2895
+	 *
2896
+	 * @access        public
2897
+	 * @return string
2898
+	 * @throws DomainException
2899
+	 * @throws EE_Error
2900
+	 * @throws RuntimeException
2901
+	 */
2902
+	public function process_reg_step()
2903
+	{
2904
+		EE_System::do_not_cache();
2905
+		$this->_set_reg_event();
2906
+		EE_Registry::instance()->REQ->set_espresso_page(true);
2907
+		EE_Registry::instance()->REQ->set('uts', time());
2908
+		//what step are we on?
2909
+		$cart = EE_Registry::instance()->SSN->cart();
2910
+		$step = ! $cart instanceof EE_Cart ? 'ticket' : 'questions';
2911
+		//if doing ajax then we need to verify the nonce
2912
+		if (defined('DOING_AJAX')) {
2913
+			$nonce = isset($this->_req_data[$this->_req_nonce])
2914
+				? sanitize_text_field($this->_req_data[$this->_req_nonce]) : '';
2915
+			$this->_verify_nonce($nonce, $this->_req_nonce);
2916
+		}
2917
+		switch ($step) {
2918
+			case 'ticket' :
2919
+				//process ticket selection
2920
+				$success = EED_Ticket_Selector::instance()->process_ticket_selections();
2921
+				if ($success) {
2922
+					EE_Error::add_success(
2923
+						esc_html__(
2924
+							'Tickets Selected. Now complete the registration.',
2925
+							'event_espresso'
2926
+						)
2927
+					);
2928
+				} else {
2929
+					$query_args['step_error'] = $this->_req_data['step_error'] = true;
2930
+				}
2931
+				if (defined('DOING_AJAX')) {
2932
+					$this->new_registration(); //display next step
2933
+				} else {
2934
+					$query_args = array(
2935
+						'action'                  => 'new_registration',
2936
+						'processing_registration' => 1,
2937
+						'event_id'                => $this->_reg_event->ID(),
2938
+						'uts'                     => time(),
2939
+					);
2940
+					$this->_redirect_after_action(
2941
+						false,
2942
+						'',
2943
+						'',
2944
+						$query_args,
2945
+						true
2946
+					);
2947
+				}
2948
+				break;
2949
+			case 'questions' :
2950
+				if (! isset(
2951
+					$this->_req_data['txn_reg_status_change'],
2952
+					$this->_req_data['txn_reg_status_change']['send_notifications'])
2953
+				) {
2954
+					add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_false', 15);
2955
+				}
2956
+				//process registration
2957
+				$transaction = EED_Single_Page_Checkout::instance()->process_registration_from_admin();
2958
+				if ($cart instanceof EE_Cart) {
2959
+					$grand_total = $cart->get_cart_grand_total();
2960
+					if ($grand_total instanceof EE_Line_Item) {
2961
+						$grand_total->save_this_and_descendants_to_txn();
2962
+					}
2963
+				}
2964
+				if ( ! $transaction instanceof EE_Transaction) {
2965
+					$query_args = array(
2966
+						'action'                  => 'new_registration',
2967
+						'processing_registration' => 2,
2968
+						'event_id'                => $this->_reg_event->ID(),
2969
+						'uts'                     => time(),
2970
+					);
2971
+					if (defined('DOING_AJAX')) {
2972
+						//display registration form again because there are errors (maybe validation?)
2973
+						$this->new_registration();
2974
+						return;
2975
+					} else {
2976
+						$this->_redirect_after_action(
2977
+							false,
2978
+							'',
2979
+							'',
2980
+							$query_args,
2981
+							true
2982
+						);
2983
+						return;
2984
+					}
2985
+				}
2986
+				// maybe update status, and make sure to save transaction if not done already
2987
+				if ( ! $transaction->update_status_based_on_total_paid()) {
2988
+					$transaction->save();
2989
+				}
2990
+				EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
2991
+				$this->_req_data = array();
2992
+				$query_args      = array(
2993
+					'action'        => 'redirect_to_txn',
2994
+					'TXN_ID'        => $transaction->ID(),
2995
+					'EVT_ID'        => $this->_reg_event->ID(),
2996
+					'event_name'    => urlencode($this->_reg_event->name()),
2997
+					'redirect_from' => 'new_registration',
2998
+				);
2999
+				$this->_redirect_after_action(false, '', '', $query_args, true);
3000
+				break;
3001
+		}
3002
+		//what are you looking here for?  Should be nothing to do at this point.
3003
+	}
3004
+
3005
+
3006
+	/**
3007
+	 * redirect_to_txn
3008
+	 *
3009
+	 * @access public
3010
+	 * @return void
3011
+	 * @throws EE_Error
3012
+	 */
3013
+	public function redirect_to_txn()
3014
+	{
3015
+		EE_System::do_not_cache();
3016
+		EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
3017
+		$query_args = array(
3018
+			'action' => 'view_transaction',
3019
+			'TXN_ID' => isset($this->_req_data['TXN_ID']) ? absint($this->_req_data['TXN_ID']) : 0,
3020
+			'page'   => 'espresso_transactions',
3021
+		);
3022
+		if (isset($this->_req_data['EVT_ID'], $this->_req_data['redirect_from'])) {
3023
+			$query_args['EVT_ID']        = $this->_req_data['EVT_ID'];
3024
+			$query_args['event_name']    = urlencode($this->_req_data['event_name']);
3025
+			$query_args['redirect_from'] = $this->_req_data['redirect_from'];
3026
+		}
3027
+		EE_Error::add_success(
3028
+			esc_html__(
3029
+				'Registration Created.  Please review the transaction and add any payments as necessary',
3030
+				'event_espresso'
3031
+			)
3032
+		);
3033
+		$this->_redirect_after_action(false, '', '', $query_args, true);
3034
+	}
3035
+
3036
+
3037
+	/**
3038
+	 *        generates HTML for the Attendee Contact List
3039
+	 *
3040
+	 * @access protected
3041
+	 * @return void
3042
+	 */
3043
+	protected function _attendee_contact_list_table()
3044
+	{
3045
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3046
+		$this->_search_btn_label = esc_html__('Contacts', 'event_espresso');
3047
+		$this->display_admin_list_table_page_with_no_sidebar();
3048
+	}
3049
+
3050
+
3051
+	/**
3052
+	 *        get_attendees
3053
+	 *
3054
+	 * @param      $per_page
3055
+	 * @param bool $count whether to return count or data.
3056
+	 * @param bool $trash
3057
+	 * @return array
3058
+	 * @throws EE_Error
3059
+	 * @access public
3060
+	 */
3061
+	public function get_attendees($per_page, $count = false, $trash = false)
3062
+	{
3063
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3064
+		require_once(REG_ADMIN . 'EE_Attendee_Contact_List_Table.class.php');
3065
+		$ATT_MDL                    = EEM_Attendee::instance();
3066
+		$this->_req_data['orderby'] = ! empty($this->_req_data['orderby']) ? $this->_req_data['orderby'] : '';
3067
+		switch ($this->_req_data['orderby']) {
3068
+			case 'ATT_ID':
3069
+				$orderby = 'ATT_ID';
3070
+				break;
3071
+			case 'ATT_fname':
3072
+				$orderby = 'ATT_fname';
3073
+				break;
3074
+			case 'ATT_email':
3075
+				$orderby = 'ATT_email';
3076
+				break;
3077
+			case 'ATT_city':
3078
+				$orderby = 'ATT_city';
3079
+				break;
3080
+			case 'STA_ID':
3081
+				$orderby = 'STA_ID';
3082
+				break;
3083
+			case 'CNT_ID':
3084
+				$orderby = 'CNT_ID';
3085
+				break;
3086
+			default:
3087
+				$orderby = 'ATT_lname';
3088
+		}
3089
+		$sort         = (isset($this->_req_data['order']) && ! empty($this->_req_data['order']))
3090
+			? $this->_req_data['order']
3091
+			: 'ASC';
3092
+		$current_page = isset($this->_req_data['paged']) && ! empty($this->_req_data['paged'])
3093
+			? $this->_req_data['paged']
3094
+			: 1;
3095
+		$per_page     = isset($per_page) && ! empty($per_page) ? $per_page : 10;
3096
+		$per_page     = isset($this->_req_data['perpage']) && ! empty($this->_req_data['perpage'])
3097
+			? $this->_req_data['perpage']
3098
+			: $per_page;
3099
+		$_where       = array();
3100
+		if ( ! empty($this->_req_data['s'])) {
3101
+			$sstr         = '%' . $this->_req_data['s'] . '%';
3102
+			$_where['OR'] = array(
3103
+				'Registration.Event.EVT_name'       => array('LIKE', $sstr),
3104
+				'Registration.Event.EVT_desc'       => array('LIKE', $sstr),
3105
+				'Registration.Event.EVT_short_desc' => array('LIKE', $sstr),
3106
+				'ATT_fname'                         => array('LIKE', $sstr),
3107
+				'ATT_lname'                         => array('LIKE', $sstr),
3108
+				'ATT_short_bio'                     => array('LIKE', $sstr),
3109
+				'ATT_email'                         => array('LIKE', $sstr),
3110
+				'ATT_address'                       => array('LIKE', $sstr),
3111
+				'ATT_address2'                      => array('LIKE', $sstr),
3112
+				'ATT_city'                          => array('LIKE', $sstr),
3113
+				'Country.CNT_name'                  => array('LIKE', $sstr),
3114
+				'State.STA_name'                    => array('LIKE', $sstr),
3115
+				'ATT_phone'                         => array('LIKE', $sstr),
3116
+				'Registration.REG_final_price'      => array('LIKE', $sstr),
3117
+				'Registration.REG_code'             => array('LIKE', $sstr),
3118
+				'Registration.REG_count'            => array('LIKE', $sstr),
3119
+				'Registration.REG_group_size'       => array('LIKE', $sstr),
3120
+			);
3121
+		}
3122
+		$offset = ($current_page - 1) * $per_page;
3123
+		$limit  = $count ? null : array($offset, $per_page);
3124
+		if ($trash) {
3125
+			$_where['status'] = array('!=', 'publish');
3126
+			$all_attendees    = $count
3127
+				? $ATT_MDL->count(array(
3128
+					$_where,
3129
+					'order_by' => array($orderby => $sort),
3130
+					'limit'    => $limit,
3131
+				), 'ATT_ID', true)
3132
+				: $ATT_MDL->get_all(array(
3133
+					$_where,
3134
+					'order_by' => array($orderby => $sort),
3135
+					'limit'    => $limit,
3136
+				));
3137
+		} else {
3138
+			$_where['status'] = array('IN', array('publish'));
3139
+			$all_attendees    = $count
3140
+				? $ATT_MDL->count(array(
3141
+					$_where,
3142
+					'order_by' => array($orderby => $sort),
3143
+					'limit'    => $limit,
3144
+				), 'ATT_ID', true)
3145
+				: $ATT_MDL->get_all(array(
3146
+					$_where,
3147
+					'order_by' => array($orderby => $sort),
3148
+					'limit'    => $limit,
3149
+				));
3150
+		}
3151
+		return $all_attendees;
3152
+	}
3153
+
3154
+
3155
+	/**
3156
+	 * This is just taking care of resending the registration confirmation
3157
+	 *
3158
+	 * @access protected
3159
+	 * @return void
3160
+	 */
3161
+	protected function _resend_registration()
3162
+	{
3163
+		$this->_process_resend_registration();
3164
+		$query_args = isset($this->_req_data['redirect_to'])
3165
+			? array('action' => $this->_req_data['redirect_to'], '_REG_ID' => $this->_req_data['_REG_ID'])
3166
+			: array('action' => 'default');
3167
+		$this->_redirect_after_action(false, '', '', $query_args, true);
3168
+	}
3169
+
3170
+	/**
3171
+	 * Creates a registration report, but accepts the name of a method to use for preparing the query parameters
3172
+	 * to use when selecting registrations
3173
+	 * @param string $method_name_for_getting_query_params the name of the method (on this class) to use for preparing
3174
+	 *                                                     the query parameters from the request
3175
+	 * @return void ends the request with a redirect or download
3176
+	 */
3177
+	public function _registrations_report_base( $method_name_for_getting_query_params )
3178
+	{
3179
+		if (! defined('EE_USE_OLD_CSV_REPORT_CLASS')) {
3180
+			wp_redirect(EE_Admin_Page::add_query_args_and_nonce(
3181
+				array(
3182
+					'page'        => 'espresso_batch',
3183
+					'batch'       => 'file',
3184
+					'EVT_ID'      => isset($this->_req_data['EVT_ID']) ? $this->_req_data['EVT_ID'] : null,
3185
+					'filters'     => urlencode(
3186
+						serialize(
3187
+							call_user_func(
3188
+								array( $this, $method_name_for_getting_query_params ),
3189
+								EEH_Array::is_set(
3190
+									$this->_req_data,
3191
+									'filters',
3192
+									array()
3193
+								)
3194
+							)
3195
+						)
3196
+				),
3197
+				'use_filters' => EEH_Array::is_set($this->_req_data, 'use_filters', false),
3198
+				'job_handler' => urlencode('EventEspressoBatchRequest\JobHandlers\RegistrationsReport'),
3199
+				'return_url'  => urlencode($this->_req_data['return_url']),
3200
+			)));
3201
+		} else {
3202
+			$new_request_args = array(
3203
+				'export' => 'report',
3204
+				'action' => 'registrations_report_for_event',
3205
+				'EVT_ID' => isset($this->_req_data['EVT_ID']) ? $this->_req_data['EVT_ID'] : null,
3206
+			);
3207
+			$this->_req_data = array_merge($this->_req_data, $new_request_args);
3208
+			if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
3209
+				require_once(EE_CLASSES . 'EE_Export.class.php');
3210
+				$EE_Export = EE_Export::instance($this->_req_data);
3211
+				$EE_Export->export();
3212
+			}
3213
+		}
3214
+	}
3215
+
3216
+
3217
+
3218
+	/**
3219
+	 * Creates a registration report using only query parameters in the request
3220
+	 * @return void
3221
+	 */
3222
+	public function _registrations_report()
3223
+	{
3224
+		$this->_registrations_report_base('_get_registration_query_parameters');
3225
+	}
3226
+
3227
+
3228
+	public function _contact_list_export()
3229
+	{
3230
+		if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
3231
+			require_once(EE_CLASSES . 'EE_Export.class.php');
3232
+			$EE_Export = EE_Export::instance($this->_req_data);
3233
+			$EE_Export->export_attendees();
3234
+		}
3235
+	}
3236
+
3237
+
3238
+	public function _contact_list_report()
3239
+	{
3240
+		if ( ! defined('EE_USE_OLD_CSV_REPORT_CLASS')) {
3241
+			wp_redirect(EE_Admin_Page::add_query_args_and_nonce(array(
3242
+				'page'        => 'espresso_batch',
3243
+				'batch'       => 'file',
3244
+				'job_handler' => urlencode('EventEspressoBatchRequest\JobHandlers\AttendeesReport'),
3245
+				'return_url'  => urlencode($this->_req_data['return_url']),
3246
+			)));
3247
+		} else {
3248
+			if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
3249
+				require_once(EE_CLASSES . 'EE_Export.class.php');
3250
+				$EE_Export = EE_Export::instance($this->_req_data);
3251
+				$EE_Export->report_attendees();
3252
+			}
3253
+		}
3254
+	}
3255
+
3256
+
3257
+
3258
+
3259
+
3260
+	/***************************************        ATTENDEE DETAILS        ***************************************/
3261
+	/**
3262
+	 * This duplicates the attendee object for the given incoming registration id and attendee_id.
3263
+	 *
3264
+	 * @return void
3265
+	 * @throws EE_Error
3266
+	 */
3267
+	protected function _duplicate_attendee()
3268
+	{
3269
+		$action = ! empty($this->_req_data['return']) ? $this->_req_data['return'] : 'default';
3270
+		//verify we have necessary info
3271
+		if (empty($this->_req_data['_REG_ID'])) {
3272
+			EE_Error::add_error(
3273
+				esc_html__(
3274
+					'Unable to create the contact for the registration because the required parameters are not present (_REG_ID )',
3275
+					'event_espresso'
3276
+				), __FILE__, __LINE__, __FUNCTION__
3277
+			);
3278
+			$query_args = array('action' => $action);
3279
+			$this->_redirect_after_action('', '', '', $query_args, true);
3280
+		}
3281
+		//okay necessary deets present... let's dupe the incoming attendee and attach to incoming registration.
3282
+		$registration = EEM_Registration::instance()->get_one_by_ID($this->_req_data['_REG_ID']);
3283
+		$attendee     = $registration->attendee();
3284
+		//remove relation of existing attendee on registration
3285
+		$registration->_remove_relation_to($attendee, 'Attendee');
3286
+		//new attendee
3287
+		$new_attendee = clone $attendee;
3288
+		$new_attendee->set('ATT_ID', 0);
3289
+		$new_attendee->save();
3290
+		//add new attendee to reg
3291
+		$registration->_add_relation_to($new_attendee, 'Attendee');
3292
+		EE_Error::add_success(
3293
+			esc_html__(
3294
+				'New Contact record created.  Now make any edits you wish to make for this contact.',
3295
+				'event_espresso'
3296
+			)
3297
+		);
3298
+		//redirect to edit page for attendee
3299
+		$query_args = array('post' => $new_attendee->ID(), 'action' => 'edit_attendee');
3300
+		$this->_redirect_after_action('', '', '', $query_args, true);
3301
+	}
3302
+
3303
+
3304
+	//related to cpt routes
3305
+	protected function _insert_update_cpt_item($post_id, $post)
3306
+	{
3307
+		$success  = true;
3308
+		$attendee = EEM_Attendee::instance()->get_one_by_ID($post_id);
3309
+		//for attendee updates
3310
+		if ($post->post_type = 'espresso_attendees' && ! empty($attendee)) {
3311
+			//note we should only be UPDATING attendees at this point.
3312
+			$updated_fields = array(
3313
+				'ATT_fname'     => $this->_req_data['ATT_fname'],
3314
+				'ATT_lname'     => $this->_req_data['ATT_lname'],
3315
+				'ATT_full_name' => $this->_req_data['ATT_fname'] . ' ' . $this->_req_data['ATT_lname'],
3316
+				'ATT_address'   => isset($this->_req_data['ATT_address']) ? $this->_req_data['ATT_address'] : '',
3317
+				'ATT_address2'  => isset($this->_req_data['ATT_address2']) ? $this->_req_data['ATT_address2'] : '',
3318
+				'ATT_city'      => isset($this->_req_data['ATT_city']) ? $this->_req_data['ATT_city'] : '',
3319
+				'STA_ID'        => isset($this->_req_data['STA_ID']) ? $this->_req_data['STA_ID'] : '',
3320
+				'CNT_ISO'       => isset($this->_req_data['CNT_ISO']) ? $this->_req_data['CNT_ISO'] : '',
3321
+				'ATT_zip'       => isset($this->_req_data['ATT_zip']) ? $this->_req_data['ATT_zip'] : '',
3322
+				'ATT_email'     => isset($this->_req_data['ATT_email']) ? $this->_req_data['ATT_email'] : '',
3323
+				'ATT_phone'     => isset($this->_req_data['ATT_phone']) ? $this->_req_data['ATT_phone'] : '',
3324
+			);
3325
+			foreach ($updated_fields as $field => $value) {
3326
+				$attendee->set($field, $value);
3327
+			}
3328
+			$success                   = $attendee->save();
3329
+			$attendee_update_callbacks = apply_filters(
3330
+				'FHEE__Registrations_Admin_Page__insert_update_cpt_item__attendee_update',
3331
+				array()
3332
+			);
3333
+			foreach ($attendee_update_callbacks as $a_callback) {
3334
+				if (false === call_user_func_array($a_callback, array($attendee, $this->_req_data))) {
3335
+					throw new EE_Error(
3336
+						sprintf(
3337
+							esc_html__(
3338
+								'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.',
3339
+								'event_espresso'
3340
+							),
3341
+							$a_callback
3342
+						)
3343
+					);
3344
+				}
3345
+			}
3346
+		}
3347
+		if ($success === false) {
3348
+			EE_Error::add_error(
3349
+				esc_html__(
3350
+					'Something went wrong with updating the meta table data for the registration.',
3351
+					'event_espresso'
3352
+				),
3353
+				__FILE__, __FUNCTION__, __LINE__
3354
+			);
3355
+		}
3356
+	}
3357
+
3358
+
3359
+	public function trash_cpt_item($post_id)
3360
+	{
3361
+	}
3362
+
3363
+
3364
+	public function delete_cpt_item($post_id)
3365
+	{
3366
+	}
3367
+
3368
+
3369
+	public function restore_cpt_item($post_id)
3370
+	{
3371
+	}
3372
+
3373
+
3374
+	protected function _restore_cpt_item($post_id, $revision_id)
3375
+	{
3376
+	}
3377
+
3378
+
3379
+	public function attendee_editor_metaboxes()
3380
+	{
3381
+		$this->verify_cpt_object();
3382
+		remove_meta_box(
3383
+			'postexcerpt',
3384
+			esc_html__('Excerpt', 'event_espresso'),
3385
+			'post_excerpt_meta_box',
3386
+			$this->_cpt_routes[$this->_req_action],
3387
+			'normal',
3388
+			'core'
3389
+		);
3390
+		remove_meta_box('commentstatusdiv', $this->_cpt_routes[$this->_req_action], 'normal', 'core');
3391
+		if (post_type_supports('espresso_attendees', 'excerpt')) {
3392
+			add_meta_box(
3393
+				'postexcerpt',
3394
+				esc_html__('Short Biography', 'event_espresso'),
3395
+				'post_excerpt_meta_box',
3396
+				$this->_cpt_routes[$this->_req_action],
3397
+				'normal'
3398
+			);
3399
+		}
3400
+		if (post_type_supports('espresso_attendees', 'comments')) {
3401
+			add_meta_box(
3402
+				'commentsdiv',
3403
+				esc_html__('Notes on the Contact', 'event_espresso'),
3404
+				'post_comment_meta_box',
3405
+				$this->_cpt_routes[$this->_req_action],
3406
+				'normal',
3407
+				'core'
3408
+			);
3409
+		}
3410
+		add_meta_box(
3411
+			'attendee_contact_info',
3412
+			esc_html__('Contact Info', 'event_espresso'),
3413
+			array($this, 'attendee_contact_info'),
3414
+			$this->_cpt_routes[$this->_req_action],
3415
+			'side',
3416
+			'core'
3417
+		);
3418
+		add_meta_box(
3419
+			'attendee_details_address',
3420
+			esc_html__('Address Details', 'event_espresso'),
3421
+			array($this, 'attendee_address_details'),
3422
+			$this->_cpt_routes[$this->_req_action],
3423
+			'normal',
3424
+			'core'
3425
+		);
3426
+		add_meta_box(
3427
+			'attendee_registrations',
3428
+			esc_html__('Registrations for this Contact', 'event_espresso'),
3429
+			array($this, 'attendee_registrations_meta_box'),
3430
+			$this->_cpt_routes[$this->_req_action],
3431
+			'normal',
3432
+			'high'
3433
+		);
3434
+	}
3435
+
3436
+
3437
+	/**
3438
+	 * Metabox for attendee contact info
3439
+	 *
3440
+	 * @param  WP_Post $post wp post object
3441
+	 * @return string attendee contact info ( and form )
3442
+	 * @throws DomainException
3443
+	 */
3444
+	public function attendee_contact_info($post)
3445
+	{
3446
+		//get attendee object ( should already have it )
3447
+		$this->_template_args['attendee'] = $this->_cpt_model_obj;
3448
+		$template                         = REG_TEMPLATE_PATH . 'attendee_contact_info_metabox_content.template.php';
3449
+		EEH_Template::display_template($template, $this->_template_args);
3450
+	}
3451
+
3452
+
3453
+	/**
3454
+	 * Metabox for attendee details
3455
+	 *
3456
+	 * @param  WP_Post $post wp post object
3457
+	 * @return string attendee address details (and form)
3458
+	 * @throws DomainException
3459
+	 */
3460
+	public function attendee_address_details($post)
3461
+	{
3462
+		//get attendee object (should already have it)
3463
+		$this->_template_args['attendee']     = $this->_cpt_model_obj;
3464
+		$this->_template_args['state_html']   = EEH_Form_Fields::generate_form_input(
3465
+			new EE_Question_Form_Input(
3466
+				EE_Question::new_instance(
3467
+					array(
3468
+						'QST_ID'           => 0,
3469
+						'QST_display_text' => esc_html__('State/Province', 'event_espresso'),
3470
+						'QST_system'       => 'admin-state',
3471
+					)
3472
+				),
3473
+				EE_Answer::new_instance(
3474
+					array(
3475
+						'ANS_ID'    => 0,
3476
+						'ANS_value' => $this->_cpt_model_obj->state_ID(),
3477
+					)
3478
+				),
3479
+				array(
3480
+					'input_id'       => 'STA_ID',
3481
+					'input_name'     => 'STA_ID',
3482
+					'input_prefix'   => '',
3483
+					'append_qstn_id' => false,
3484
+				)
3485
+			)
3486
+		);
3487
+		$this->_template_args['country_html'] = EEH_Form_Fields::generate_form_input(
3488
+			new EE_Question_Form_Input(
3489
+				EE_Question::new_instance(
3490
+					array(
3491
+						'QST_ID'           => 0,
3492
+						'QST_display_text' => esc_html__('Country', 'event_espresso'),
3493
+						'QST_system'       => 'admin-country',
3494
+					)
3495
+				),
3496
+				EE_Answer::new_instance(
3497
+					array(
3498
+						'ANS_ID'    => 0,
3499
+						'ANS_value' => $this->_cpt_model_obj->country_ID(),
3500
+					)
3501
+				),
3502
+				array(
3503
+					'input_id'       => 'CNT_ISO',
3504
+					'input_name'     => 'CNT_ISO',
3505
+					'input_prefix'   => '',
3506
+					'append_qstn_id' => false,
3507
+				)
3508
+			)
3509
+		);
3510
+		$template                             =
3511
+			REG_TEMPLATE_PATH . 'attendee_address_details_metabox_content.template.php';
3512
+		EEH_Template::display_template($template, $this->_template_args);
3513
+	}
3514
+
3515
+
3516
+	/**
3517
+	 *        _attendee_details
3518
+	 *
3519
+	 * @access protected
3520
+	 * @param $post
3521
+	 * @return void
3522
+	 * @throws DomainException
3523
+	 * @throws EE_Error
3524
+	 */
3525
+	public function attendee_registrations_meta_box($post)
3526
+	{
3527
+		$this->_template_args['attendee']      = $this->_cpt_model_obj;
3528
+		$this->_template_args['registrations'] = $this->_cpt_model_obj->get_many_related('Registration');
3529
+		$template                              =
3530
+			REG_TEMPLATE_PATH . 'attendee_registrations_main_meta_box.template.php';
3531
+		EEH_Template::display_template($template, $this->_template_args);
3532
+	}
3533
+
3534
+
3535
+	/**
3536
+	 * add in the form fields for the attendee edit
3537
+	 *
3538
+	 * @param  WP_Post $post wp post object
3539
+	 * @return string html for new form.
3540
+	 * @throws DomainException
3541
+	 */
3542
+	public function after_title_form_fields($post)
3543
+	{
3544
+		if ($post->post_type == 'espresso_attendees') {
3545
+			$template                  = REG_TEMPLATE_PATH . 'attendee_details_after_title_form_fields.template.php';
3546
+			$template_args['attendee'] = $this->_cpt_model_obj;
3547
+			EEH_Template::display_template($template, $template_args);
3548
+		}
3549
+	}
3550
+
3551
+
3552
+	/**
3553
+	 *        _trash_or_restore_attendee
3554
+	 *
3555
+	 * @param boolean $trash - whether to move item to trash (TRUE) or restore it (FALSE)
3556
+	 * @return void
3557
+	 * @throws EE_Error
3558
+	 * @access protected
3559
+	 */
3560
+	protected function _trash_or_restore_attendees($trash = true)
3561
+	{
3562
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3563
+		$ATT_MDL = EEM_Attendee::instance();
3564
+		$success = 1;
3565
+		//Checkboxes
3566
+		if ( ! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
3567
+			// if array has more than one element than success message should be plural
3568
+			$success = count($this->_req_data['checkbox']) > 1 ? 2 : 1;
3569
+			// cycle thru checkboxes
3570
+			while (list($ATT_ID, $value) = each($this->_req_data['checkbox'])) {
3571
+				$updated = $trash ? $ATT_MDL->update_by_ID(array('status' => 'trash'), $ATT_ID)
3572
+					: $ATT_MDL->update_by_ID(array('status' => 'publish'), $ATT_ID);
3573
+				if ( ! $updated) {
3574
+					$success = 0;
3575
+				}
3576
+			}
3577
+		} else {
3578
+			// grab single id and delete
3579
+			$ATT_ID = absint($this->_req_data['ATT_ID']);
3580
+			//get attendee
3581
+			$att     = $ATT_MDL->get_one_by_ID($ATT_ID);
3582
+			$updated = $trash ? $att->set_status('trash') : $att->set_status('publish');
3583
+			$updated = $att->save();
3584
+			if ( ! $updated) {
3585
+				$success = 0;
3586
+			}
3587
+		}
3588
+		$what        = $success > 1
3589
+			? esc_html__('Contacts', 'event_espresso')
3590
+			: esc_html__('Contact', 'event_espresso');
3591
+		$action_desc = $trash
3592
+			? esc_html__('moved to the trash', 'event_espresso')
3593
+			: esc_html__('restored', 'event_espresso');
3594
+		$this->_redirect_after_action($success, $what, $action_desc, array('action' => 'contact_list'));
3595
+	}
3596 3596
 
3597 3597
 }
Please login to merge, or discard this patch.