Completed
Branch ENH/stop-messages-extra-meta (4c222a)
by
unknown
39:42 queued 31:22
created
modules/ticket_selector/DisplayTicketSelector.php 1 patch
Indentation   +718 added lines, -718 removed lines patch added patch discarded remove patch
@@ -33,725 +33,725 @@
 block discarded – undo
33 33
 class DisplayTicketSelector
34 34
 {
35 35
 
36
-    /**
37
-     * event that ticket selector is being generated for
38
-     *
39
-     * @access protected
40
-     * @var EE_Event $event
41
-     */
42
-    protected $event;
43
-
44
-    /**
45
-     * Used to flag when the ticket selector is being called from an external iframe.
46
-     *
47
-     * @var bool $iframe
48
-     */
49
-    protected $iframe = false;
50
-
51
-    /**
52
-     * max attendees that can register for event at one time
53
-     *
54
-     * @var int $max_attendees
55
-     */
56
-    private $max_attendees = EE_INF;
57
-
58
-    /**
59
-     * @var string $date_format
60
-     */
61
-    private $date_format;
62
-
63
-    /**
64
-     * @var string $time_format
65
-     */
66
-    private $time_format;
67
-
68
-    /**
69
-     * @var boolean $display_full_ui
70
-     */
71
-    private $display_full_ui;
72
-
73
-
74
-    /**
75
-     * DisplayTicketSelector constructor.
76
-     *
77
-     * @param bool $iframe
78
-     */
79
-    public function __construct($iframe = false)
80
-    {
81
-        $this->iframe = $iframe;
82
-        $this->date_format = apply_filters(
83
-            'FHEE__EED_Ticket_Selector__display_ticket_selector__date_format',
84
-            get_option('date_format')
85
-        );
86
-        $this->time_format = apply_filters(
87
-            'FHEE__EED_Ticket_Selector__display_ticket_selector__time_format',
88
-            get_option('time_format')
89
-        );
90
-    }
91
-
92
-
93
-    /**
94
-     * @return bool
95
-     */
96
-    public function isIframe()
97
-    {
98
-        return $this->iframe;
99
-    }
100
-
101
-
102
-    /**
103
-     * @param boolean $iframe
104
-     */
105
-    public function setIframe($iframe = true)
106
-    {
107
-        $this->iframe = filter_var($iframe, FILTER_VALIDATE_BOOLEAN);
108
-    }
109
-
110
-
111
-    /**
112
-     * finds and sets the \EE_Event object for use throughout class
113
-     *
114
-     * @param mixed $event
115
-     * @return bool
116
-     * @throws EE_Error
117
-     * @throws InvalidDataTypeException
118
-     * @throws InvalidInterfaceException
119
-     * @throws InvalidArgumentException
120
-     */
121
-    protected function setEvent($event = null)
122
-    {
123
-        if ($event === null) {
124
-            global $post;
125
-            $event = $post;
126
-        }
127
-        if ($event instanceof EE_Event) {
128
-            $this->event = $event;
129
-        } elseif ($event instanceof WP_Post) {
130
-            if (isset($event->EE_Event) && $event->EE_Event instanceof EE_Event) {
131
-                $this->event = $event->EE_Event;
132
-            } elseif ($event->post_type === 'espresso_events') {
133
-                $event->EE_Event = EEM_Event::instance()->instantiate_class_from_post_object($event);
134
-                $this->event = $event->EE_Event;
135
-            }
136
-        } else {
137
-            $user_msg = __('No Event object or an invalid Event object was supplied.', 'event_espresso');
138
-            $dev_msg = $user_msg . __(
139
-                'In order to generate a ticket selector, please ensure you are passing either an EE_Event object or a WP_Post object of the post type "espresso_event" to the EE_Ticket_Selector class constructor.',
140
-                'event_espresso'
141
-            );
142
-            EE_Error::add_error($user_msg . '||' . $dev_msg, __FILE__, __FUNCTION__, __LINE__);
143
-            return false;
144
-        }
145
-        return true;
146
-    }
147
-
148
-
149
-    /**
150
-     * @return int
151
-     */
152
-    public function getMaxAttendees()
153
-    {
154
-        return $this->max_attendees;
155
-    }
156
-
157
-
158
-    /**
159
-     * @param int $max_attendees
160
-     */
161
-    public function setMaxAttendees($max_attendees)
162
-    {
163
-        $this->max_attendees = absint(
164
-            apply_filters(
165
-                'FHEE__EE_Ticket_Selector__display_ticket_selector__max_tickets',
166
-                $max_attendees
167
-            )
168
-        );
169
-    }
170
-
171
-
172
-    /**
173
-     * Returns whether or not the full ticket selector should be shown or not.
174
-     * Currently, it displays on the frontend (including ajax requests) but not the backend
175
-     *
176
-     * @return bool
177
-     */
178
-    private function display_full_ui()
179
-    {
180
-        if ($this->display_full_ui === null) {
181
-            $this->display_full_ui = ! is_admin() || (defined('DOING_AJAX') && DOING_AJAX);
182
-        }
183
-        return $this->display_full_ui;
184
-    }
185
-
186
-
187
-    /**
188
-     * creates buttons for selecting number of attendees for an event
189
-     *
190
-     * @param WP_Post|int $event
191
-     * @param bool        $view_details
192
-     * @return string
193
-     * @throws EE_Error
194
-     * @throws InvalidArgumentException
195
-     * @throws InvalidDataTypeException
196
-     * @throws InvalidInterfaceException
197
-     */
198
-    public function display($event = null, $view_details = false)
199
-    {
200
-        // reset filter for displaying submit button
201
-        remove_filter('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', '__return_true');
202
-        // poke and prod incoming event till it tells us what it is
203
-        if (! $this->setEvent($event)) {
204
-            return false;
205
-        }
206
-        // begin gathering template arguments by getting event status
207
-        $template_args = array('event_status' => $this->event->get_active_status());
208
-        if ($this->activeEventAndShowTicketSelector(
209
-            $event,
210
-            $template_args['event_status'],
211
-            $view_details
212
-        )) {
213
-            return ! is_single() ? $this->displayViewDetailsButton() : '';
214
-        }
215
-        // filter the maximum qty that can appear in the Ticket Selector qty dropdowns
216
-        $this->setMaxAttendees($this->event->additional_limit());
217
-        if ($this->getMaxAttendees() < 1) {
218
-            return $this->ticketSalesClosedMessage();
219
-        }
220
-        // is the event expired ?
221
-        $template_args['event_is_expired'] = ! is_admin() ? $this->event->is_expired() : false;
222
-        if ($template_args['event_is_expired']) {
223
-            return $this->expiredEventMessage();
224
-        }
225
-        // get all tickets for this event ordered by the datetime
226
-        $tickets = $this->getTickets();
227
-        if (count($tickets) < 1) {
228
-            return $this->noTicketAvailableMessage();
229
-        }
230
-        // redirecting to another site for registration ??
231
-        $external_url = (string) $this->event->external_url()
232
-            && $this->event->external_url() !== get_the_permalink()
233
-            ? $this->event->external_url()
234
-            : '';
235
-        // if redirecting to another site for registration, then we don't load the TS
236
-        $ticket_selector = $external_url
237
-            ? $this->externalEventRegistration()
238
-            : $this->loadTicketSelector($tickets, $template_args);
239
-        // now set up the form (but not for the admin)
240
-        $ticket_selector = $this->display_full_ui()
241
-            ? $this->formOpen($this->event->ID(), $external_url) . $ticket_selector
242
-            : $ticket_selector;
243
-        // submit button and form close tag
244
-        $ticket_selector .= $this->display_full_ui() ? $this->displaySubmitButton($external_url) : '';
245
-        return $ticket_selector;
246
-    }
247
-
248
-
249
-    /**
250
-     * displayTicketSelector
251
-     * examines the event properties and determines whether a Ticket Selector should be displayed
252
-     *
253
-     * @param WP_Post|int $event
254
-     * @param string      $_event_active_status
255
-     * @param bool        $view_details
256
-     * @return bool
257
-     * @throws EE_Error
258
-     */
259
-    protected function activeEventAndShowTicketSelector($event, $_event_active_status, $view_details)
260
-    {
261
-        $event_post = $this->event instanceof EE_Event ? $this->event->ID() : $event;
262
-        return $this->display_full_ui()
263
-               && (
264
-                   ! $this->event->display_ticket_selector()
265
-                   || $view_details
266
-                   || post_password_required($event_post)
267
-                   || (
268
-                       $_event_active_status !== EE_Datetime::active
269
-                       && $_event_active_status !== EE_Datetime::upcoming
270
-                       && $_event_active_status !== EE_Datetime::sold_out
271
-                       && ! (
272
-                           $_event_active_status === EE_Datetime::inactive
273
-                           && is_user_logged_in()
274
-                       )
275
-                   )
276
-               );
277
-    }
278
-
279
-
280
-    /**
281
-     * noTicketAvailableMessage
282
-     * notice displayed if event is expired
283
-     *
284
-     * @return string
285
-     * @throws EE_Error
286
-     */
287
-    protected function expiredEventMessage()
288
-    {
289
-        return '<div class="ee-event-expired-notice"><span class="important-notice">' . esc_html__(
290
-            'We\'re sorry, but all tickets sales have ended because the event is expired.',
291
-            'event_espresso'
292
-        ) . '</span></div><!-- .ee-event-expired-notice -->';
293
-    }
294
-
295
-
296
-    /**
297
-     * noTicketAvailableMessage
298
-     * notice displayed if event has no more tickets available
299
-     *
300
-     * @return string
301
-     * @throws EE_Error
302
-     */
303
-    protected function noTicketAvailableMessage()
304
-    {
305
-        $no_ticket_available_msg = esc_html__('We\'re sorry, but all ticket sales have ended.', 'event_espresso');
306
-        if (current_user_can('edit_post', $this->event->ID())) {
307
-            $no_ticket_available_msg .= sprintf(
308
-                esc_html__(
309
-                    '%1$sNote to Event Admin:%2$sNo tickets were found for this event. This effectively turns off ticket sales. Please ensure that at least one ticket is available for if you want people to be able to register.%3$s(click to edit this event)%4$s',
310
-                    'event_espresso'
311
-                ),
312
-                '<div class="ee-attention" style="text-align: left;"><b>',
313
-                '</b><br />',
314
-                '<span class="edit-link"><a class="post-edit-link" href="'
315
-                . get_edit_post_link($this->event->ID())
316
-                . '">',
317
-                '</a></span></div><!-- .ee-attention noTicketAvailableMessage -->'
318
-            );
319
-        }
320
-        return '
36
+	/**
37
+	 * event that ticket selector is being generated for
38
+	 *
39
+	 * @access protected
40
+	 * @var EE_Event $event
41
+	 */
42
+	protected $event;
43
+
44
+	/**
45
+	 * Used to flag when the ticket selector is being called from an external iframe.
46
+	 *
47
+	 * @var bool $iframe
48
+	 */
49
+	protected $iframe = false;
50
+
51
+	/**
52
+	 * max attendees that can register for event at one time
53
+	 *
54
+	 * @var int $max_attendees
55
+	 */
56
+	private $max_attendees = EE_INF;
57
+
58
+	/**
59
+	 * @var string $date_format
60
+	 */
61
+	private $date_format;
62
+
63
+	/**
64
+	 * @var string $time_format
65
+	 */
66
+	private $time_format;
67
+
68
+	/**
69
+	 * @var boolean $display_full_ui
70
+	 */
71
+	private $display_full_ui;
72
+
73
+
74
+	/**
75
+	 * DisplayTicketSelector constructor.
76
+	 *
77
+	 * @param bool $iframe
78
+	 */
79
+	public function __construct($iframe = false)
80
+	{
81
+		$this->iframe = $iframe;
82
+		$this->date_format = apply_filters(
83
+			'FHEE__EED_Ticket_Selector__display_ticket_selector__date_format',
84
+			get_option('date_format')
85
+		);
86
+		$this->time_format = apply_filters(
87
+			'FHEE__EED_Ticket_Selector__display_ticket_selector__time_format',
88
+			get_option('time_format')
89
+		);
90
+	}
91
+
92
+
93
+	/**
94
+	 * @return bool
95
+	 */
96
+	public function isIframe()
97
+	{
98
+		return $this->iframe;
99
+	}
100
+
101
+
102
+	/**
103
+	 * @param boolean $iframe
104
+	 */
105
+	public function setIframe($iframe = true)
106
+	{
107
+		$this->iframe = filter_var($iframe, FILTER_VALIDATE_BOOLEAN);
108
+	}
109
+
110
+
111
+	/**
112
+	 * finds and sets the \EE_Event object for use throughout class
113
+	 *
114
+	 * @param mixed $event
115
+	 * @return bool
116
+	 * @throws EE_Error
117
+	 * @throws InvalidDataTypeException
118
+	 * @throws InvalidInterfaceException
119
+	 * @throws InvalidArgumentException
120
+	 */
121
+	protected function setEvent($event = null)
122
+	{
123
+		if ($event === null) {
124
+			global $post;
125
+			$event = $post;
126
+		}
127
+		if ($event instanceof EE_Event) {
128
+			$this->event = $event;
129
+		} elseif ($event instanceof WP_Post) {
130
+			if (isset($event->EE_Event) && $event->EE_Event instanceof EE_Event) {
131
+				$this->event = $event->EE_Event;
132
+			} elseif ($event->post_type === 'espresso_events') {
133
+				$event->EE_Event = EEM_Event::instance()->instantiate_class_from_post_object($event);
134
+				$this->event = $event->EE_Event;
135
+			}
136
+		} else {
137
+			$user_msg = __('No Event object or an invalid Event object was supplied.', 'event_espresso');
138
+			$dev_msg = $user_msg . __(
139
+				'In order to generate a ticket selector, please ensure you are passing either an EE_Event object or a WP_Post object of the post type "espresso_event" to the EE_Ticket_Selector class constructor.',
140
+				'event_espresso'
141
+			);
142
+			EE_Error::add_error($user_msg . '||' . $dev_msg, __FILE__, __FUNCTION__, __LINE__);
143
+			return false;
144
+		}
145
+		return true;
146
+	}
147
+
148
+
149
+	/**
150
+	 * @return int
151
+	 */
152
+	public function getMaxAttendees()
153
+	{
154
+		return $this->max_attendees;
155
+	}
156
+
157
+
158
+	/**
159
+	 * @param int $max_attendees
160
+	 */
161
+	public function setMaxAttendees($max_attendees)
162
+	{
163
+		$this->max_attendees = absint(
164
+			apply_filters(
165
+				'FHEE__EE_Ticket_Selector__display_ticket_selector__max_tickets',
166
+				$max_attendees
167
+			)
168
+		);
169
+	}
170
+
171
+
172
+	/**
173
+	 * Returns whether or not the full ticket selector should be shown or not.
174
+	 * Currently, it displays on the frontend (including ajax requests) but not the backend
175
+	 *
176
+	 * @return bool
177
+	 */
178
+	private function display_full_ui()
179
+	{
180
+		if ($this->display_full_ui === null) {
181
+			$this->display_full_ui = ! is_admin() || (defined('DOING_AJAX') && DOING_AJAX);
182
+		}
183
+		return $this->display_full_ui;
184
+	}
185
+
186
+
187
+	/**
188
+	 * creates buttons for selecting number of attendees for an event
189
+	 *
190
+	 * @param WP_Post|int $event
191
+	 * @param bool        $view_details
192
+	 * @return string
193
+	 * @throws EE_Error
194
+	 * @throws InvalidArgumentException
195
+	 * @throws InvalidDataTypeException
196
+	 * @throws InvalidInterfaceException
197
+	 */
198
+	public function display($event = null, $view_details = false)
199
+	{
200
+		// reset filter for displaying submit button
201
+		remove_filter('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', '__return_true');
202
+		// poke and prod incoming event till it tells us what it is
203
+		if (! $this->setEvent($event)) {
204
+			return false;
205
+		}
206
+		// begin gathering template arguments by getting event status
207
+		$template_args = array('event_status' => $this->event->get_active_status());
208
+		if ($this->activeEventAndShowTicketSelector(
209
+			$event,
210
+			$template_args['event_status'],
211
+			$view_details
212
+		)) {
213
+			return ! is_single() ? $this->displayViewDetailsButton() : '';
214
+		}
215
+		// filter the maximum qty that can appear in the Ticket Selector qty dropdowns
216
+		$this->setMaxAttendees($this->event->additional_limit());
217
+		if ($this->getMaxAttendees() < 1) {
218
+			return $this->ticketSalesClosedMessage();
219
+		}
220
+		// is the event expired ?
221
+		$template_args['event_is_expired'] = ! is_admin() ? $this->event->is_expired() : false;
222
+		if ($template_args['event_is_expired']) {
223
+			return $this->expiredEventMessage();
224
+		}
225
+		// get all tickets for this event ordered by the datetime
226
+		$tickets = $this->getTickets();
227
+		if (count($tickets) < 1) {
228
+			return $this->noTicketAvailableMessage();
229
+		}
230
+		// redirecting to another site for registration ??
231
+		$external_url = (string) $this->event->external_url()
232
+			&& $this->event->external_url() !== get_the_permalink()
233
+			? $this->event->external_url()
234
+			: '';
235
+		// if redirecting to another site for registration, then we don't load the TS
236
+		$ticket_selector = $external_url
237
+			? $this->externalEventRegistration()
238
+			: $this->loadTicketSelector($tickets, $template_args);
239
+		// now set up the form (but not for the admin)
240
+		$ticket_selector = $this->display_full_ui()
241
+			? $this->formOpen($this->event->ID(), $external_url) . $ticket_selector
242
+			: $ticket_selector;
243
+		// submit button and form close tag
244
+		$ticket_selector .= $this->display_full_ui() ? $this->displaySubmitButton($external_url) : '';
245
+		return $ticket_selector;
246
+	}
247
+
248
+
249
+	/**
250
+	 * displayTicketSelector
251
+	 * examines the event properties and determines whether a Ticket Selector should be displayed
252
+	 *
253
+	 * @param WP_Post|int $event
254
+	 * @param string      $_event_active_status
255
+	 * @param bool        $view_details
256
+	 * @return bool
257
+	 * @throws EE_Error
258
+	 */
259
+	protected function activeEventAndShowTicketSelector($event, $_event_active_status, $view_details)
260
+	{
261
+		$event_post = $this->event instanceof EE_Event ? $this->event->ID() : $event;
262
+		return $this->display_full_ui()
263
+			   && (
264
+				   ! $this->event->display_ticket_selector()
265
+				   || $view_details
266
+				   || post_password_required($event_post)
267
+				   || (
268
+					   $_event_active_status !== EE_Datetime::active
269
+					   && $_event_active_status !== EE_Datetime::upcoming
270
+					   && $_event_active_status !== EE_Datetime::sold_out
271
+					   && ! (
272
+						   $_event_active_status === EE_Datetime::inactive
273
+						   && is_user_logged_in()
274
+					   )
275
+				   )
276
+			   );
277
+	}
278
+
279
+
280
+	/**
281
+	 * noTicketAvailableMessage
282
+	 * notice displayed if event is expired
283
+	 *
284
+	 * @return string
285
+	 * @throws EE_Error
286
+	 */
287
+	protected function expiredEventMessage()
288
+	{
289
+		return '<div class="ee-event-expired-notice"><span class="important-notice">' . esc_html__(
290
+			'We\'re sorry, but all tickets sales have ended because the event is expired.',
291
+			'event_espresso'
292
+		) . '</span></div><!-- .ee-event-expired-notice -->';
293
+	}
294
+
295
+
296
+	/**
297
+	 * noTicketAvailableMessage
298
+	 * notice displayed if event has no more tickets available
299
+	 *
300
+	 * @return string
301
+	 * @throws EE_Error
302
+	 */
303
+	protected function noTicketAvailableMessage()
304
+	{
305
+		$no_ticket_available_msg = esc_html__('We\'re sorry, but all ticket sales have ended.', 'event_espresso');
306
+		if (current_user_can('edit_post', $this->event->ID())) {
307
+			$no_ticket_available_msg .= sprintf(
308
+				esc_html__(
309
+					'%1$sNote to Event Admin:%2$sNo tickets were found for this event. This effectively turns off ticket sales. Please ensure that at least one ticket is available for if you want people to be able to register.%3$s(click to edit this event)%4$s',
310
+					'event_espresso'
311
+				),
312
+				'<div class="ee-attention" style="text-align: left;"><b>',
313
+				'</b><br />',
314
+				'<span class="edit-link"><a class="post-edit-link" href="'
315
+				. get_edit_post_link($this->event->ID())
316
+				. '">',
317
+				'</a></span></div><!-- .ee-attention noTicketAvailableMessage -->'
318
+			);
319
+		}
320
+		return '
321 321
             <div class="ee-event-expired-notice">
322 322
                 <span class="important-notice">' . $no_ticket_available_msg . '</span>
323 323
             </div><!-- .ee-event-expired-notice -->';
324
-    }
325
-
326
-
327
-    /**
328
-     * ticketSalesClosed
329
-     * notice displayed if event ticket sales are turned off
330
-     *
331
-     * @return string
332
-     * @throws EE_Error
333
-     */
334
-    protected function ticketSalesClosedMessage()
335
-    {
336
-        $sales_closed_msg = esc_html__(
337
-            'We\'re sorry, but ticket sales have been closed at this time. Please check back again later.',
338
-            'event_espresso'
339
-        );
340
-        if (current_user_can('edit_post', $this->event->ID())) {
341
-            $sales_closed_msg .= sprintf(
342
-                esc_html__(
343
-                    '%sNote to Event Admin:%sThe "Maximum number of tickets allowed per order for this event" in the Event Registration Options has been set to "0". This effectively turns off ticket sales. %s(click to edit this event)%s',
344
-                    'event_espresso'
345
-                ),
346
-                '<div class="ee-attention" style="text-align: left;"><b>',
347
-                '</b><br />',
348
-                '<span class="edit-link"><a class="post-edit-link" href="'
349
-                . get_edit_post_link($this->event->ID())
350
-                . '">',
351
-                '</a></span></div><!-- .ee-attention ticketSalesClosedMessage -->'
352
-            );
353
-        }
354
-        return '<p><span class="important-notice">' . $sales_closed_msg . '</span></p>';
355
-    }
356
-
357
-
358
-    /**
359
-     * getTickets
360
-     *
361
-     * @return \EE_Base_Class[]|\EE_Ticket[]
362
-     * @throws EE_Error
363
-     * @throws InvalidDataTypeException
364
-     * @throws InvalidInterfaceException
365
-     * @throws InvalidArgumentException
366
-     */
367
-    protected function getTickets()
368
-    {
369
-        $show_expired_tickets = is_admin() || (
370
-            EE_Registry::instance()->CFG->template_settings->EED_Ticket_Selector instanceof EE_Ticket_Selector_Config
371
-            && EE_Registry::instance()->CFG->template_settings->EED_Ticket_Selector->show_expired_tickets
372
-        );
373
-
374
-        $ticket_query_args = array(
375
-            array('Datetime.EVT_ID' => $this->event->ID()),
376
-            'order_by' => array(
377
-                'TKT_order'              => 'ASC',
378
-                'TKT_required'           => 'DESC',
379
-                'TKT_start_date'         => 'ASC',
380
-                'TKT_end_date'           => 'ASC',
381
-                'Datetime.DTT_EVT_start' => 'DESC',
382
-            ),
383
-        );
384
-        if (! $show_expired_tickets) {
385
-            // use the correct applicable time query depending on what version of core is being run.
386
-            $current_time = method_exists('EEM_Datetime', 'current_time_for_query')
387
-                ? time()
388
-                : current_time('timestamp');
389
-            $ticket_query_args[0]['TKT_end_date'] = array('>', $current_time);
390
-        }
391
-        return EEM_Ticket::instance()->get_all($ticket_query_args);
392
-    }
393
-
394
-
395
-    /**
396
-     * loadTicketSelector
397
-     * begins to assemble template arguments
398
-     * and decides whether to load a "simple" ticket selector, or the standard
399
-     *
400
-     * @param \EE_Ticket[] $tickets
401
-     * @param array        $template_args
402
-     * @return string
403
-     * @throws EE_Error
404
-     */
405
-    protected function loadTicketSelector(array $tickets, array $template_args)
406
-    {
407
-        $template_args['event'] = $this->event;
408
-        $template_args['EVT_ID'] = $this->event->ID();
409
-        $template_args['event_is_expired'] = $this->event->is_expired();
410
-        $template_args['max_atndz'] = $this->getMaxAttendees();
411
-        $template_args['date_format'] = $this->date_format;
412
-        $template_args['time_format'] = $this->time_format;
413
-        /**
414
-         * Filters the anchor ID used when redirecting to the Ticket Selector if no quantity selected
415
-         *
416
-         * @since 4.9.13
417
-         * @param     string  '#tkt-slctr-tbl-' . $EVT_ID The html ID to anchor to
418
-         * @param int $EVT_ID The Event ID
419
-         */
420
-        $template_args['anchor_id'] = apply_filters(
421
-            'FHEE__EE_Ticket_Selector__redirect_anchor_id',
422
-            '#tkt-slctr-tbl-' . $this->event->ID(),
423
-            $this->event->ID()
424
-        );
425
-        $template_args['tickets'] = $tickets;
426
-        $template_args['ticket_count'] = count($tickets);
427
-        $ticket_selector = $this->simpleTicketSelector($tickets, $template_args);
428
-        return $ticket_selector instanceof TicketSelectorSimple
429
-            ? $ticket_selector
430
-            : new TicketSelectorStandard(
431
-                $this->event,
432
-                $tickets,
433
-                $this->getMaxAttendees(),
434
-                $template_args,
435
-                $this->date_format,
436
-                $this->time_format
437
-            );
438
-    }
439
-
440
-
441
-    /**
442
-     * simpleTicketSelector
443
-     * there's one ticket, and max attendees is set to one,
444
-     * so if the event is free, then this is a "simple" ticket selector
445
-     * a.k.a. "Dude Where's my Ticket Selector?"
446
-     *
447
-     * @param \EE_Ticket[] $tickets
448
-     * @param array        $template_args
449
-     * @return string
450
-     * @throws EE_Error
451
-     */
452
-    protected function simpleTicketSelector($tickets, array $template_args)
453
-    {
454
-        // if there is only ONE ticket with a max qty of ONE
455
-        if (count($tickets) > 1 || $this->getMaxAttendees() !== 1) {
456
-            return '';
457
-        }
458
-        /** @var \EE_Ticket $ticket */
459
-        $ticket = reset($tickets);
460
-        // if the ticket is free... then not much need for the ticket selector
461
-        if (apply_filters(
462
-            'FHEE__ticket_selector_chart_template__hide_ticket_selector',
463
-            $ticket->is_free(),
464
-            $this->event->ID()
465
-        )) {
466
-            return new TicketSelectorSimple(
467
-                $this->event,
468
-                $ticket,
469
-                $this->getMaxAttendees(),
470
-                $template_args
471
-            );
472
-        }
473
-        return '';
474
-    }
475
-
476
-
477
-    /**
478
-     * externalEventRegistration
479
-     *
480
-     * @return string
481
-     */
482
-    public function externalEventRegistration()
483
-    {
484
-        // if not we still need to trigger the display of the submit button
485
-        add_filter('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', '__return_true');
486
-        // display notice to admin that registration is external
487
-        return $this->display_full_ui()
488
-            ? esc_html__(
489
-                'Registration is at an external URL for this event.',
490
-                'event_espresso'
491
-            )
492
-            : '';
493
-    }
494
-
495
-
496
-    /**
497
-     * formOpen
498
-     *
499
-     * @param        int    $ID
500
-     * @param        string $external_url
501
-     * @return        string
502
-     */
503
-    public function formOpen($ID = 0, $external_url = '')
504
-    {
505
-        // if redirecting, we don't need any anything else
506
-        if ($external_url) {
507
-            $html = '<form method="GET" ';
508
-            $html .= 'action="' . EEH_URL::refactor_url($external_url) . '" ';
509
-            $html .= 'name="ticket-selector-form-' . $ID . '"';
510
-            // open link in new window ?
511
-            $html .= apply_filters(
512
-                'FHEE__EventEspresso_modules_ticket_selector_DisplayTicketSelector__formOpen__external_url_target_blank',
513
-                $this->isIframe(),
514
-                $this
515
-            )
516
-                ? ' target="_blank"'
517
-                : '';
518
-            $html .= '>';
519
-            $query_args = EEH_URL::get_query_string($external_url);
520
-            foreach ((array) $query_args as $query_arg => $value) {
521
-                $html .= '<input type="hidden" name="' . $query_arg . '" value="' . $value . '">';
522
-            }
523
-            return $html;
524
-        }
525
-        // if there is no submit button, then don't start building a form
526
-        // because the "View Details" button will build its own form
527
-        if (! apply_filters('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', false)) {
528
-            return '';
529
-        }
530
-        $checkout_url = EEH_Event_View::event_link_url($ID);
531
-        if (! $checkout_url) {
532
-            EE_Error::add_error(
533
-                esc_html__('The URL for the Event Details page could not be retrieved.', 'event_espresso'),
534
-                __FILE__,
535
-                __FUNCTION__,
536
-                __LINE__
537
-            );
538
-        }
539
-        // set no cache headers and constants
540
-        EE_System::do_not_cache();
541
-        $html = '<form method="POST" ';
542
-        $html .= 'action="' . $checkout_url . '" ';
543
-        $html .= 'name="ticket-selector-form-' . $ID . '"';
544
-        $html .= $this->iframe ? ' target="_blank"' : '';
545
-        $html .= '>';
546
-        $html .= '<input type="hidden" name="ee" value="process_ticket_selections">';
547
-        $html = apply_filters('FHEE__EE_Ticket_Selector__ticket_selector_form_open__html', $html, $this->event);
548
-        return $html;
549
-    }
550
-
551
-
552
-    /**
553
-     * displaySubmitButton
554
-     *
555
-     * @param  string $external_url
556
-     * @return string
557
-     * @throws EE_Error
558
-     */
559
-    public function displaySubmitButton($external_url = '')
560
-    {
561
-        $html = '';
562
-        if ($this->display_full_ui()) {
563
-            // standard TS displayed with submit button, ie: "Register Now"
564
-            if (apply_filters('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', false)) {
565
-                $html .= $this->displayRegisterNowButton();
566
-                $html .= empty($external_url)
567
-                    ? $this->ticketSelectorEndDiv()
568
-                    : $this->clearTicketSelector();
569
-                $html .= '<br/>' . $this->formClose();
570
-            } elseif ($this->getMaxAttendees() === 1) {
571
-                // its a "Dude Where's my Ticket Selector?" (DWMTS) type event (ie: $_max_atndz === 1)
572
-                if ($this->event->is_sold_out()) {
573
-                    // then instead of a View Details or Submit button, just display a "Sold Out" message
574
-                    $html .= apply_filters(
575
-                        'FHEE__EE_Ticket_Selector__display_ticket_selector_submit__sold_out_msg',
576
-                        sprintf(
577
-                            __(
578
-                                '%1$s"%2$s" is currently sold out.%4$sPlease check back again later, as spots may become available.%3$s',
579
-                                'event_espresso'
580
-                            ),
581
-                            '<p class="no-ticket-selector-msg clear-float">',
582
-                            $this->event->name(),
583
-                            '</p>',
584
-                            '<br />'
585
-                        ),
586
-                        $this->event
587
-                    );
588
-                    if (apply_filters(
589
-                        'FHEE__EE_Ticket_Selector__display_ticket_selector_submit__no_tickets_but_display_register_now_button',
590
-                        false,
591
-                        $this->event
592
-                    )) {
593
-                        $html .= $this->displayRegisterNowButton();
594
-                    }
595
-                    // sold out DWMTS event, no TS, no submit or view details button, but has additional content
596
-                    $html .= $this->ticketSelectorEndDiv();
597
-                } elseif (apply_filters('FHEE__EE_Ticket_Selector__hide_ticket_selector', false)
598
-                          && ! is_single()
599
-                ) {
600
-                    // this is a "Dude Where's my Ticket Selector?" (DWMTS) type event,
601
-                    // but no tickets are available, so display event's "View Details" button.
602
-                    // it is being viewed via somewhere other than a single post
603
-                    $html .= $this->displayViewDetailsButton(true);
604
-                } else {
605
-                    $html .= $this->ticketSelectorEndDiv();
606
-                }
607
-            } elseif (is_archive()) {
608
-                // event list, no tickets available so display event's "View Details" button
609
-                $html .= $this->ticketSelectorEndDiv();
610
-                $html .= $this->displayViewDetailsButton();
611
-            } else {
612
-                if (apply_filters(
613
-                    'FHEE__EE_Ticket_Selector__display_ticket_selector_submit__no_tickets_but_display_register_now_button',
614
-                    false,
615
-                    $this->event
616
-                )) {
617
-                    $html .= $this->displayRegisterNowButton();
618
-                }
619
-                // no submit or view details button, and no additional content
620
-                $html .= $this->ticketSelectorEndDiv();
621
-            }
622
-            if (! $this->iframe && ! is_archive()) {
623
-                $html .= EEH_Template::powered_by_event_espresso('', '', array('utm_content' => 'ticket_selector'));
624
-            }
625
-        }
626
-        return apply_filters(
627
-            'FHEE__EventEspresso_modules_ticket_selector_DisplayTicketSelector__displaySubmitButton__html',
628
-            $html,
629
-            $this->event,
630
-            $this
631
-        );
632
-    }
633
-
634
-
635
-    /**
636
-     * @return string
637
-     * @throws EE_Error
638
-     */
639
-    public function displayRegisterNowButton()
640
-    {
641
-        $btn_text = apply_filters(
642
-            'FHEE__EE_Ticket_Selector__display_ticket_selector_submit__btn_text',
643
-            __('Register Now', 'event_espresso'),
644
-            $this->event
645
-        );
646
-        $external_url = (string) $this->event->external_url()
647
-            && $this->event->external_url() !== get_the_permalink()
648
-            ? $this->event->external_url()
649
-            : '';
650
-        $html = EEH_HTML::div(
651
-            '',
652
-            'ticket-selector-submit-' . $this->event->ID() . '-btn-wrap',
653
-            'ticket-selector-submit-btn-wrap'
654
-        );
655
-        $html .= '<input id="ticket-selector-submit-' . $this->event->ID() . '-btn"';
656
-        $html .= ' class="ticket-selector-submit-btn ';
657
-        $html .= empty($external_url) ? 'ticket-selector-submit-ajax"' : '"';
658
-        $html .= ' type="submit" value="' . $btn_text . '" data-ee-disable-after-recaptcha="true" />';
659
-        $html .= EEH_HTML::divx() . '<!-- .ticket-selector-submit-btn-wrap -->';
660
-        $html .= apply_filters(
661
-            'FHEE__EE_Ticket_Selector__after_ticket_selector_submit',
662
-            '',
663
-            $this->event,
664
-            $this->iframe
665
-        );
666
-        return $html;
667
-    }
668
-
669
-
670
-    /**
671
-     * displayViewDetailsButton
672
-     *
673
-     * @param bool $DWMTS indicates a "Dude Where's my Ticket Selector?" (DWMTS) type event
674
-     *                    (ie: $_max_atndz === 1) where there are no available tickets,
675
-     *                    either because they are sold out, expired, or not yet on sale.
676
-     *                    In this case, we need to close the form BEFORE adding any closing divs
677
-     * @return string
678
-     * @throws EE_Error
679
-     */
680
-    public function displayViewDetailsButton($DWMTS = false)
681
-    {
682
-        if (! $this->event->get_permalink()) {
683
-            EE_Error::add_error(
684
-                esc_html__('The URL for the Event Details page could not be retrieved.', 'event_espresso'),
685
-                __FILE__,
686
-                __FUNCTION__,
687
-                __LINE__
688
-            );
689
-        }
690
-        $view_details_btn = '<form method="GET" action="';
691
-        $view_details_btn .= apply_filters(
692
-            'FHEE__EE_Ticket_Selector__display_view_details_btn__btn_url',
693
-            $this->event->get_permalink(),
694
-            $this->event
695
-        );
696
-        $view_details_btn .= '"';
697
-        // open link in new window ?
698
-        $view_details_btn .= apply_filters(
699
-            'FHEE__EventEspresso_modules_ticket_selector_DisplayTicketSelector__displayViewDetailsButton__url_target_blank',
700
-            $this->isIframe(),
701
-            $this
702
-        )
703
-            ? ' target="_blank"'
704
-            : '';
705
-        $view_details_btn .= '>';
706
-        $btn_text = apply_filters(
707
-            'FHEE__EE_Ticket_Selector__display_view_details_btn__btn_text',
708
-            esc_html__('View Details', 'event_espresso'),
709
-            $this->event
710
-        );
711
-        $view_details_btn .= '<input id="ticket-selector-submit-'
712
-                             . $this->event->ID()
713
-                             . '-btn" class="ticket-selector-submit-btn view-details-btn" type="submit" value="'
714
-                             . $btn_text
715
-                             . '" />';
716
-        $view_details_btn .= apply_filters('FHEE__EE_Ticket_Selector__after_view_details_btn', '', $this->event);
717
-        if ($DWMTS) {
718
-            $view_details_btn .= $this->formClose();
719
-            $view_details_btn .= $this->ticketSelectorEndDiv();
720
-            $view_details_btn .= '<br/>';
721
-        } else {
722
-            $view_details_btn .= $this->clearTicketSelector();
723
-            $view_details_btn .= '<br/>';
724
-            $view_details_btn .= $this->formClose();
725
-        }
726
-        return $view_details_btn;
727
-    }
728
-
729
-
730
-    /**
731
-     * @return string
732
-     */
733
-    public function ticketSelectorEndDiv()
734
-    {
735
-        return $this->clearTicketSelector() . '</div><!-- ticketSelectorEndDiv -->';
736
-    }
737
-
738
-
739
-    /**
740
-     * @return string
741
-     */
742
-    public function clearTicketSelector()
743
-    {
744
-        // standard TS displayed, appears after a "Register Now" or "view Details" button
745
-        return '<div class="clear"></div><!-- clearTicketSelector -->';
746
-    }
747
-
748
-
749
-    /**
750
-     * @access        public
751
-     * @return        string
752
-     */
753
-    public function formClose()
754
-    {
755
-        return '</form>';
756
-    }
324
+	}
325
+
326
+
327
+	/**
328
+	 * ticketSalesClosed
329
+	 * notice displayed if event ticket sales are turned off
330
+	 *
331
+	 * @return string
332
+	 * @throws EE_Error
333
+	 */
334
+	protected function ticketSalesClosedMessage()
335
+	{
336
+		$sales_closed_msg = esc_html__(
337
+			'We\'re sorry, but ticket sales have been closed at this time. Please check back again later.',
338
+			'event_espresso'
339
+		);
340
+		if (current_user_can('edit_post', $this->event->ID())) {
341
+			$sales_closed_msg .= sprintf(
342
+				esc_html__(
343
+					'%sNote to Event Admin:%sThe "Maximum number of tickets allowed per order for this event" in the Event Registration Options has been set to "0". This effectively turns off ticket sales. %s(click to edit this event)%s',
344
+					'event_espresso'
345
+				),
346
+				'<div class="ee-attention" style="text-align: left;"><b>',
347
+				'</b><br />',
348
+				'<span class="edit-link"><a class="post-edit-link" href="'
349
+				. get_edit_post_link($this->event->ID())
350
+				. '">',
351
+				'</a></span></div><!-- .ee-attention ticketSalesClosedMessage -->'
352
+			);
353
+		}
354
+		return '<p><span class="important-notice">' . $sales_closed_msg . '</span></p>';
355
+	}
356
+
357
+
358
+	/**
359
+	 * getTickets
360
+	 *
361
+	 * @return \EE_Base_Class[]|\EE_Ticket[]
362
+	 * @throws EE_Error
363
+	 * @throws InvalidDataTypeException
364
+	 * @throws InvalidInterfaceException
365
+	 * @throws InvalidArgumentException
366
+	 */
367
+	protected function getTickets()
368
+	{
369
+		$show_expired_tickets = is_admin() || (
370
+			EE_Registry::instance()->CFG->template_settings->EED_Ticket_Selector instanceof EE_Ticket_Selector_Config
371
+			&& EE_Registry::instance()->CFG->template_settings->EED_Ticket_Selector->show_expired_tickets
372
+		);
373
+
374
+		$ticket_query_args = array(
375
+			array('Datetime.EVT_ID' => $this->event->ID()),
376
+			'order_by' => array(
377
+				'TKT_order'              => 'ASC',
378
+				'TKT_required'           => 'DESC',
379
+				'TKT_start_date'         => 'ASC',
380
+				'TKT_end_date'           => 'ASC',
381
+				'Datetime.DTT_EVT_start' => 'DESC',
382
+			),
383
+		);
384
+		if (! $show_expired_tickets) {
385
+			// use the correct applicable time query depending on what version of core is being run.
386
+			$current_time = method_exists('EEM_Datetime', 'current_time_for_query')
387
+				? time()
388
+				: current_time('timestamp');
389
+			$ticket_query_args[0]['TKT_end_date'] = array('>', $current_time);
390
+		}
391
+		return EEM_Ticket::instance()->get_all($ticket_query_args);
392
+	}
393
+
394
+
395
+	/**
396
+	 * loadTicketSelector
397
+	 * begins to assemble template arguments
398
+	 * and decides whether to load a "simple" ticket selector, or the standard
399
+	 *
400
+	 * @param \EE_Ticket[] $tickets
401
+	 * @param array        $template_args
402
+	 * @return string
403
+	 * @throws EE_Error
404
+	 */
405
+	protected function loadTicketSelector(array $tickets, array $template_args)
406
+	{
407
+		$template_args['event'] = $this->event;
408
+		$template_args['EVT_ID'] = $this->event->ID();
409
+		$template_args['event_is_expired'] = $this->event->is_expired();
410
+		$template_args['max_atndz'] = $this->getMaxAttendees();
411
+		$template_args['date_format'] = $this->date_format;
412
+		$template_args['time_format'] = $this->time_format;
413
+		/**
414
+		 * Filters the anchor ID used when redirecting to the Ticket Selector if no quantity selected
415
+		 *
416
+		 * @since 4.9.13
417
+		 * @param     string  '#tkt-slctr-tbl-' . $EVT_ID The html ID to anchor to
418
+		 * @param int $EVT_ID The Event ID
419
+		 */
420
+		$template_args['anchor_id'] = apply_filters(
421
+			'FHEE__EE_Ticket_Selector__redirect_anchor_id',
422
+			'#tkt-slctr-tbl-' . $this->event->ID(),
423
+			$this->event->ID()
424
+		);
425
+		$template_args['tickets'] = $tickets;
426
+		$template_args['ticket_count'] = count($tickets);
427
+		$ticket_selector = $this->simpleTicketSelector($tickets, $template_args);
428
+		return $ticket_selector instanceof TicketSelectorSimple
429
+			? $ticket_selector
430
+			: new TicketSelectorStandard(
431
+				$this->event,
432
+				$tickets,
433
+				$this->getMaxAttendees(),
434
+				$template_args,
435
+				$this->date_format,
436
+				$this->time_format
437
+			);
438
+	}
439
+
440
+
441
+	/**
442
+	 * simpleTicketSelector
443
+	 * there's one ticket, and max attendees is set to one,
444
+	 * so if the event is free, then this is a "simple" ticket selector
445
+	 * a.k.a. "Dude Where's my Ticket Selector?"
446
+	 *
447
+	 * @param \EE_Ticket[] $tickets
448
+	 * @param array        $template_args
449
+	 * @return string
450
+	 * @throws EE_Error
451
+	 */
452
+	protected function simpleTicketSelector($tickets, array $template_args)
453
+	{
454
+		// if there is only ONE ticket with a max qty of ONE
455
+		if (count($tickets) > 1 || $this->getMaxAttendees() !== 1) {
456
+			return '';
457
+		}
458
+		/** @var \EE_Ticket $ticket */
459
+		$ticket = reset($tickets);
460
+		// if the ticket is free... then not much need for the ticket selector
461
+		if (apply_filters(
462
+			'FHEE__ticket_selector_chart_template__hide_ticket_selector',
463
+			$ticket->is_free(),
464
+			$this->event->ID()
465
+		)) {
466
+			return new TicketSelectorSimple(
467
+				$this->event,
468
+				$ticket,
469
+				$this->getMaxAttendees(),
470
+				$template_args
471
+			);
472
+		}
473
+		return '';
474
+	}
475
+
476
+
477
+	/**
478
+	 * externalEventRegistration
479
+	 *
480
+	 * @return string
481
+	 */
482
+	public function externalEventRegistration()
483
+	{
484
+		// if not we still need to trigger the display of the submit button
485
+		add_filter('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', '__return_true');
486
+		// display notice to admin that registration is external
487
+		return $this->display_full_ui()
488
+			? esc_html__(
489
+				'Registration is at an external URL for this event.',
490
+				'event_espresso'
491
+			)
492
+			: '';
493
+	}
494
+
495
+
496
+	/**
497
+	 * formOpen
498
+	 *
499
+	 * @param        int    $ID
500
+	 * @param        string $external_url
501
+	 * @return        string
502
+	 */
503
+	public function formOpen($ID = 0, $external_url = '')
504
+	{
505
+		// if redirecting, we don't need any anything else
506
+		if ($external_url) {
507
+			$html = '<form method="GET" ';
508
+			$html .= 'action="' . EEH_URL::refactor_url($external_url) . '" ';
509
+			$html .= 'name="ticket-selector-form-' . $ID . '"';
510
+			// open link in new window ?
511
+			$html .= apply_filters(
512
+				'FHEE__EventEspresso_modules_ticket_selector_DisplayTicketSelector__formOpen__external_url_target_blank',
513
+				$this->isIframe(),
514
+				$this
515
+			)
516
+				? ' target="_blank"'
517
+				: '';
518
+			$html .= '>';
519
+			$query_args = EEH_URL::get_query_string($external_url);
520
+			foreach ((array) $query_args as $query_arg => $value) {
521
+				$html .= '<input type="hidden" name="' . $query_arg . '" value="' . $value . '">';
522
+			}
523
+			return $html;
524
+		}
525
+		// if there is no submit button, then don't start building a form
526
+		// because the "View Details" button will build its own form
527
+		if (! apply_filters('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', false)) {
528
+			return '';
529
+		}
530
+		$checkout_url = EEH_Event_View::event_link_url($ID);
531
+		if (! $checkout_url) {
532
+			EE_Error::add_error(
533
+				esc_html__('The URL for the Event Details page could not be retrieved.', 'event_espresso'),
534
+				__FILE__,
535
+				__FUNCTION__,
536
+				__LINE__
537
+			);
538
+		}
539
+		// set no cache headers and constants
540
+		EE_System::do_not_cache();
541
+		$html = '<form method="POST" ';
542
+		$html .= 'action="' . $checkout_url . '" ';
543
+		$html .= 'name="ticket-selector-form-' . $ID . '"';
544
+		$html .= $this->iframe ? ' target="_blank"' : '';
545
+		$html .= '>';
546
+		$html .= '<input type="hidden" name="ee" value="process_ticket_selections">';
547
+		$html = apply_filters('FHEE__EE_Ticket_Selector__ticket_selector_form_open__html', $html, $this->event);
548
+		return $html;
549
+	}
550
+
551
+
552
+	/**
553
+	 * displaySubmitButton
554
+	 *
555
+	 * @param  string $external_url
556
+	 * @return string
557
+	 * @throws EE_Error
558
+	 */
559
+	public function displaySubmitButton($external_url = '')
560
+	{
561
+		$html = '';
562
+		if ($this->display_full_ui()) {
563
+			// standard TS displayed with submit button, ie: "Register Now"
564
+			if (apply_filters('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', false)) {
565
+				$html .= $this->displayRegisterNowButton();
566
+				$html .= empty($external_url)
567
+					? $this->ticketSelectorEndDiv()
568
+					: $this->clearTicketSelector();
569
+				$html .= '<br/>' . $this->formClose();
570
+			} elseif ($this->getMaxAttendees() === 1) {
571
+				// its a "Dude Where's my Ticket Selector?" (DWMTS) type event (ie: $_max_atndz === 1)
572
+				if ($this->event->is_sold_out()) {
573
+					// then instead of a View Details or Submit button, just display a "Sold Out" message
574
+					$html .= apply_filters(
575
+						'FHEE__EE_Ticket_Selector__display_ticket_selector_submit__sold_out_msg',
576
+						sprintf(
577
+							__(
578
+								'%1$s"%2$s" is currently sold out.%4$sPlease check back again later, as spots may become available.%3$s',
579
+								'event_espresso'
580
+							),
581
+							'<p class="no-ticket-selector-msg clear-float">',
582
+							$this->event->name(),
583
+							'</p>',
584
+							'<br />'
585
+						),
586
+						$this->event
587
+					);
588
+					if (apply_filters(
589
+						'FHEE__EE_Ticket_Selector__display_ticket_selector_submit__no_tickets_but_display_register_now_button',
590
+						false,
591
+						$this->event
592
+					)) {
593
+						$html .= $this->displayRegisterNowButton();
594
+					}
595
+					// sold out DWMTS event, no TS, no submit or view details button, but has additional content
596
+					$html .= $this->ticketSelectorEndDiv();
597
+				} elseif (apply_filters('FHEE__EE_Ticket_Selector__hide_ticket_selector', false)
598
+						  && ! is_single()
599
+				) {
600
+					// this is a "Dude Where's my Ticket Selector?" (DWMTS) type event,
601
+					// but no tickets are available, so display event's "View Details" button.
602
+					// it is being viewed via somewhere other than a single post
603
+					$html .= $this->displayViewDetailsButton(true);
604
+				} else {
605
+					$html .= $this->ticketSelectorEndDiv();
606
+				}
607
+			} elseif (is_archive()) {
608
+				// event list, no tickets available so display event's "View Details" button
609
+				$html .= $this->ticketSelectorEndDiv();
610
+				$html .= $this->displayViewDetailsButton();
611
+			} else {
612
+				if (apply_filters(
613
+					'FHEE__EE_Ticket_Selector__display_ticket_selector_submit__no_tickets_but_display_register_now_button',
614
+					false,
615
+					$this->event
616
+				)) {
617
+					$html .= $this->displayRegisterNowButton();
618
+				}
619
+				// no submit or view details button, and no additional content
620
+				$html .= $this->ticketSelectorEndDiv();
621
+			}
622
+			if (! $this->iframe && ! is_archive()) {
623
+				$html .= EEH_Template::powered_by_event_espresso('', '', array('utm_content' => 'ticket_selector'));
624
+			}
625
+		}
626
+		return apply_filters(
627
+			'FHEE__EventEspresso_modules_ticket_selector_DisplayTicketSelector__displaySubmitButton__html',
628
+			$html,
629
+			$this->event,
630
+			$this
631
+		);
632
+	}
633
+
634
+
635
+	/**
636
+	 * @return string
637
+	 * @throws EE_Error
638
+	 */
639
+	public function displayRegisterNowButton()
640
+	{
641
+		$btn_text = apply_filters(
642
+			'FHEE__EE_Ticket_Selector__display_ticket_selector_submit__btn_text',
643
+			__('Register Now', 'event_espresso'),
644
+			$this->event
645
+		);
646
+		$external_url = (string) $this->event->external_url()
647
+			&& $this->event->external_url() !== get_the_permalink()
648
+			? $this->event->external_url()
649
+			: '';
650
+		$html = EEH_HTML::div(
651
+			'',
652
+			'ticket-selector-submit-' . $this->event->ID() . '-btn-wrap',
653
+			'ticket-selector-submit-btn-wrap'
654
+		);
655
+		$html .= '<input id="ticket-selector-submit-' . $this->event->ID() . '-btn"';
656
+		$html .= ' class="ticket-selector-submit-btn ';
657
+		$html .= empty($external_url) ? 'ticket-selector-submit-ajax"' : '"';
658
+		$html .= ' type="submit" value="' . $btn_text . '" data-ee-disable-after-recaptcha="true" />';
659
+		$html .= EEH_HTML::divx() . '<!-- .ticket-selector-submit-btn-wrap -->';
660
+		$html .= apply_filters(
661
+			'FHEE__EE_Ticket_Selector__after_ticket_selector_submit',
662
+			'',
663
+			$this->event,
664
+			$this->iframe
665
+		);
666
+		return $html;
667
+	}
668
+
669
+
670
+	/**
671
+	 * displayViewDetailsButton
672
+	 *
673
+	 * @param bool $DWMTS indicates a "Dude Where's my Ticket Selector?" (DWMTS) type event
674
+	 *                    (ie: $_max_atndz === 1) where there are no available tickets,
675
+	 *                    either because they are sold out, expired, or not yet on sale.
676
+	 *                    In this case, we need to close the form BEFORE adding any closing divs
677
+	 * @return string
678
+	 * @throws EE_Error
679
+	 */
680
+	public function displayViewDetailsButton($DWMTS = false)
681
+	{
682
+		if (! $this->event->get_permalink()) {
683
+			EE_Error::add_error(
684
+				esc_html__('The URL for the Event Details page could not be retrieved.', 'event_espresso'),
685
+				__FILE__,
686
+				__FUNCTION__,
687
+				__LINE__
688
+			);
689
+		}
690
+		$view_details_btn = '<form method="GET" action="';
691
+		$view_details_btn .= apply_filters(
692
+			'FHEE__EE_Ticket_Selector__display_view_details_btn__btn_url',
693
+			$this->event->get_permalink(),
694
+			$this->event
695
+		);
696
+		$view_details_btn .= '"';
697
+		// open link in new window ?
698
+		$view_details_btn .= apply_filters(
699
+			'FHEE__EventEspresso_modules_ticket_selector_DisplayTicketSelector__displayViewDetailsButton__url_target_blank',
700
+			$this->isIframe(),
701
+			$this
702
+		)
703
+			? ' target="_blank"'
704
+			: '';
705
+		$view_details_btn .= '>';
706
+		$btn_text = apply_filters(
707
+			'FHEE__EE_Ticket_Selector__display_view_details_btn__btn_text',
708
+			esc_html__('View Details', 'event_espresso'),
709
+			$this->event
710
+		);
711
+		$view_details_btn .= '<input id="ticket-selector-submit-'
712
+							 . $this->event->ID()
713
+							 . '-btn" class="ticket-selector-submit-btn view-details-btn" type="submit" value="'
714
+							 . $btn_text
715
+							 . '" />';
716
+		$view_details_btn .= apply_filters('FHEE__EE_Ticket_Selector__after_view_details_btn', '', $this->event);
717
+		if ($DWMTS) {
718
+			$view_details_btn .= $this->formClose();
719
+			$view_details_btn .= $this->ticketSelectorEndDiv();
720
+			$view_details_btn .= '<br/>';
721
+		} else {
722
+			$view_details_btn .= $this->clearTicketSelector();
723
+			$view_details_btn .= '<br/>';
724
+			$view_details_btn .= $this->formClose();
725
+		}
726
+		return $view_details_btn;
727
+	}
728
+
729
+
730
+	/**
731
+	 * @return string
732
+	 */
733
+	public function ticketSelectorEndDiv()
734
+	{
735
+		return $this->clearTicketSelector() . '</div><!-- ticketSelectorEndDiv -->';
736
+	}
737
+
738
+
739
+	/**
740
+	 * @return string
741
+	 */
742
+	public function clearTicketSelector()
743
+	{
744
+		// standard TS displayed, appears after a "Register Now" or "view Details" button
745
+		return '<div class="clear"></div><!-- clearTicketSelector -->';
746
+	}
747
+
748
+
749
+	/**
750
+	 * @access        public
751
+	 * @return        string
752
+	 */
753
+	public function formClose()
754
+	{
755
+		return '</form>';
756
+	}
757 757
 }
Please login to merge, or discard this patch.
espresso.php 1 patch
Indentation   +80 added lines, -80 removed lines patch added patch discarded remove patch
@@ -38,103 +38,103 @@
 block discarded – undo
38 38
  * @since           4.0
39 39
  */
40 40
 if (function_exists('espresso_version')) {
41
-    if (! function_exists('espresso_duplicate_plugin_error')) {
42
-        /**
43
-         *    espresso_duplicate_plugin_error
44
-         *    displays if more than one version of EE is activated at the same time
45
-         */
46
-        function espresso_duplicate_plugin_error()
47
-        {
48
-            ?>
41
+	if (! function_exists('espresso_duplicate_plugin_error')) {
42
+		/**
43
+		 *    espresso_duplicate_plugin_error
44
+		 *    displays if more than one version of EE is activated at the same time
45
+		 */
46
+		function espresso_duplicate_plugin_error()
47
+		{
48
+			?>
49 49
             <div class="error">
50 50
                 <p>
51 51
                     <?php
52
-                    echo esc_html__(
53
-                        'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.',
54
-                        'event_espresso'
55
-                    ); ?>
52
+					echo esc_html__(
53
+						'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.',
54
+						'event_espresso'
55
+					); ?>
56 56
                 </p>
57 57
             </div>
58 58
             <?php
59
-            espresso_deactivate_plugin(plugin_basename(__FILE__));
60
-        }
61
-    }
62
-    add_action('admin_notices', 'espresso_duplicate_plugin_error', 1);
59
+			espresso_deactivate_plugin(plugin_basename(__FILE__));
60
+		}
61
+	}
62
+	add_action('admin_notices', 'espresso_duplicate_plugin_error', 1);
63 63
 } else {
64
-    define('EE_MIN_PHP_VER_REQUIRED', '5.4.0');
65
-    if (! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) {
66
-        /**
67
-         * espresso_minimum_php_version_error
68
-         *
69
-         * @return void
70
-         */
71
-        function espresso_minimum_php_version_error()
72
-        {
73
-            ?>
64
+	define('EE_MIN_PHP_VER_REQUIRED', '5.4.0');
65
+	if (! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) {
66
+		/**
67
+		 * espresso_minimum_php_version_error
68
+		 *
69
+		 * @return void
70
+		 */
71
+		function espresso_minimum_php_version_error()
72
+		{
73
+			?>
74 74
             <div class="error">
75 75
                 <p>
76 76
                     <?php
77
-                    printf(
78
-                        esc_html__(
79
-                            'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.',
80
-                            'event_espresso'
81
-                        ),
82
-                        EE_MIN_PHP_VER_REQUIRED,
83
-                        PHP_VERSION,
84
-                        '<br/>',
85
-                        '<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>'
86
-                    );
87
-                    ?>
77
+					printf(
78
+						esc_html__(
79
+							'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.',
80
+							'event_espresso'
81
+						),
82
+						EE_MIN_PHP_VER_REQUIRED,
83
+						PHP_VERSION,
84
+						'<br/>',
85
+						'<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>'
86
+					);
87
+					?>
88 88
                 </p>
89 89
             </div>
90 90
             <?php
91
-            espresso_deactivate_plugin(plugin_basename(__FILE__));
92
-        }
91
+			espresso_deactivate_plugin(plugin_basename(__FILE__));
92
+		}
93 93
 
94
-        add_action('admin_notices', 'espresso_minimum_php_version_error', 1);
95
-    } else {
96
-        define('EVENT_ESPRESSO_MAIN_FILE', __FILE__);
97
-        /**
98
-         * espresso_version
99
-         * Returns the plugin version
100
-         *
101
-         * @return string
102
-         */
103
-        function espresso_version()
104
-        {
105
-            return apply_filters('FHEE__espresso__espresso_version', '4.10.7.rc.009');
106
-        }
94
+		add_action('admin_notices', 'espresso_minimum_php_version_error', 1);
95
+	} else {
96
+		define('EVENT_ESPRESSO_MAIN_FILE', __FILE__);
97
+		/**
98
+		 * espresso_version
99
+		 * Returns the plugin version
100
+		 *
101
+		 * @return string
102
+		 */
103
+		function espresso_version()
104
+		{
105
+			return apply_filters('FHEE__espresso__espresso_version', '4.10.7.rc.009');
106
+		}
107 107
 
108
-        /**
109
-         * espresso_plugin_activation
110
-         * adds a wp-option to indicate that EE has been activated via the WP admin plugins page
111
-         */
112
-        function espresso_plugin_activation()
113
-        {
114
-            update_option('ee_espresso_activation', true);
115
-        }
108
+		/**
109
+		 * espresso_plugin_activation
110
+		 * adds a wp-option to indicate that EE has been activated via the WP admin plugins page
111
+		 */
112
+		function espresso_plugin_activation()
113
+		{
114
+			update_option('ee_espresso_activation', true);
115
+		}
116 116
 
117
-        register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation');
117
+		register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation');
118 118
 
119
-        require_once __DIR__ . '/core/bootstrap_espresso.php';
120
-        bootstrap_espresso();
121
-    }
119
+		require_once __DIR__ . '/core/bootstrap_espresso.php';
120
+		bootstrap_espresso();
121
+	}
122 122
 }
123 123
 if (! function_exists('espresso_deactivate_plugin')) {
124
-    /**
125
-     *    deactivate_plugin
126
-     * usage:  espresso_deactivate_plugin( plugin_basename( __FILE__ ));
127
-     *
128
-     * @access public
129
-     * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file
130
-     * @return    void
131
-     */
132
-    function espresso_deactivate_plugin($plugin_basename = '')
133
-    {
134
-        if (! function_exists('deactivate_plugins')) {
135
-            require_once ABSPATH . 'wp-admin/includes/plugin.php';
136
-        }
137
-        unset($_GET['activate'], $_REQUEST['activate']);
138
-        deactivate_plugins($plugin_basename);
139
-    }
124
+	/**
125
+	 *    deactivate_plugin
126
+	 * usage:  espresso_deactivate_plugin( plugin_basename( __FILE__ ));
127
+	 *
128
+	 * @access public
129
+	 * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file
130
+	 * @return    void
131
+	 */
132
+	function espresso_deactivate_plugin($plugin_basename = '')
133
+	{
134
+		if (! function_exists('deactivate_plugins')) {
135
+			require_once ABSPATH . 'wp-admin/includes/plugin.php';
136
+		}
137
+		unset($_GET['activate'], $_REQUEST['activate']);
138
+		deactivate_plugins($plugin_basename);
139
+	}
140 140
 }
Please login to merge, or discard this patch.
core/db_classes/EE_Message.class.php 1 patch
Indentation   +869 added lines, -869 removed lines patch added patch discarded remove patch
@@ -10,877 +10,877 @@
 block discarded – undo
10 10
 class EE_Message extends EE_Base_Class implements EEI_Admin_Links
11 11
 {
12 12
 
13
-    /**
14
-     * @deprecated 4.9.0  Added for backward compat with add-on's
15
-     * @type null
16
-     */
17
-    public $template_pack;
18
-
19
-    /**
20
-     * @deprecated 4.9.0 Added for backward compat with add-on's
21
-     * @type null
22
-     */
23
-    public $template_variation;
24
-
25
-    /**
26
-     * @deprecated 4.9.0 Added for backward compat with add-on's
27
-     * @type string
28
-     */
29
-    public $content = '';
30
-
31
-
32
-    /**
33
-     * @type EE_messenger $_messenger
34
-     */
35
-    protected $_messenger = null;
36
-
37
-    /**
38
-     * @type EE_message_type $_message_type
39
-     */
40
-    protected $_message_type = null;
41
-
42
-
43
-    /**
44
-     * @param array  $props_n_values
45
-     * @param string $timezone
46
-     * @param array  $date_formats incoming date formats in an array.  First value is the date_format, second is time
47
-     *                             format.
48
-     * @return EE_Message
49
-     */
50
-    public static function new_instance($props_n_values = array(), $timezone = null, $date_formats = array())
51
-    {
52
-        $has_object = parent::_check_for_object($props_n_values, __CLASS__);
53
-        // if object doesn't exist, let's generate a unique token on instantiation so that its available even before saving to db.
54
-        if (! $has_object) {
55
-            EE_Registry::instance()->load_helper('URL');
56
-            $props_n_values['MSG_token'] = EEH_URL::generate_unique_token();
57
-        }
58
-        return $has_object ? $has_object : new self($props_n_values, false, $timezone, $date_formats);
59
-    }
60
-
61
-
62
-    /**
63
-     * @param array  $props_n_values
64
-     * @param string $timezone
65
-     * @return EE_Message
66
-     */
67
-    public static function new_instance_from_db($props_n_values = array(), $timezone = null)
68
-    {
69
-        return new self($props_n_values, true, $timezone);
70
-    }
71
-
72
-
73
-    /**
74
-     * Gets MSG_token
75
-     *
76
-     * @return int
77
-     */
78
-    public function MSG_token()
79
-    {
80
-        return $this->get('MSG_token');
81
-    }
82
-
83
-
84
-    /**
85
-     * Sets MSG_token
86
-     *
87
-     * @param int $MSG_token
88
-     */
89
-    public function set_MSG_token($MSG_token)
90
-    {
91
-        $this->set('MSG_token', $MSG_token);
92
-    }
93
-
94
-
95
-    /**
96
-     * Gets GRP_ID
97
-     *
98
-     * @return int
99
-     */
100
-    public function GRP_ID()
101
-    {
102
-        return $this->get('GRP_ID');
103
-    }
104
-
105
-
106
-    /**
107
-     * Sets GRP_ID
108
-     *
109
-     * @param int $GRP_ID
110
-     */
111
-    public function set_GRP_ID($GRP_ID)
112
-    {
113
-        $this->set('GRP_ID', $GRP_ID);
114
-    }
115
-
116
-
117
-    /**
118
-     * Gets TXN_ID
119
-     *
120
-     * @return int
121
-     */
122
-    public function TXN_ID()
123
-    {
124
-        return $this->get('TXN_ID');
125
-    }
126
-
127
-
128
-    /**
129
-     * Sets TXN_ID
130
-     *
131
-     * @param int $TXN_ID
132
-     */
133
-    public function set_TXN_ID($TXN_ID)
134
-    {
135
-        $this->set('TXN_ID', $TXN_ID);
136
-    }
137
-
138
-
139
-    /**
140
-     * Gets messenger
141
-     *
142
-     * @return string
143
-     */
144
-    public function messenger()
145
-    {
146
-        return $this->get('MSG_messenger');
147
-    }
148
-
149
-
150
-    /**
151
-     * Sets messenger
152
-     *
153
-     * @param string $messenger
154
-     */
155
-    public function set_messenger($messenger)
156
-    {
157
-        $this->set('MSG_messenger', $messenger);
158
-    }
159
-
160
-
161
-    /**
162
-     * Returns corresponding messenger object for the set messenger on this message
163
-     *
164
-     * @return EE_messenger | null
165
-     */
166
-    public function messenger_object()
167
-    {
168
-        return $this->_messenger;
169
-    }
170
-
171
-
172
-    /**
173
-     * Sets messenger
174
-     *
175
-     * @param EE_messenger $messenger
176
-     */
177
-    public function set_messenger_object(EE_messenger $messenger)
178
-    {
179
-        $this->_messenger = $messenger;
180
-    }
181
-
182
-
183
-    /**
184
-     * validates messenger
185
-     *
186
-     * @param bool $throw_exceptions
187
-     * @return bool
188
-     * @throws \EE_Error
189
-     */
190
-    public function valid_messenger($throw_exceptions = false)
191
-    {
192
-        if ($this->_messenger instanceof EE_messenger) {
193
-            return true;
194
-        }
195
-        if ($throw_exceptions) {
196
-            throw new EE_Error(
197
-                sprintf(
198
-                    __(
199
-                        'The "%1$s" messenger set for this message is missing or invalid. Please double-check the spelling and verify that the correct files exist.',
200
-                        'event_espresso'
201
-                    ),
202
-                    $this->messenger()
203
-                )
204
-            );
205
-        }
206
-        return false;
207
-    }
208
-
209
-
210
-    /**
211
-     * This returns the set localized label for the messenger on this message.
212
-     * Note, if unable to retrieve the EE_messenger object then will just return the messenger slug saved
213
-     * with this message.
214
-     *
215
-     * @param   bool $plural whether to return the plural label or not.
216
-     * @return string
217
-     */
218
-    public function messenger_label($plural = false)
219
-    {
220
-        $label_type = $plural ? 'plural' : 'singular';
221
-        $messenger = $this->messenger_object();
222
-        return $messenger instanceof EE_messenger ? $messenger->label[ $label_type ] : $this->messenger();
223
-    }
224
-
225
-
226
-    /**
227
-     * Gets message_type
228
-     *
229
-     * @return string
230
-     */
231
-    public function message_type()
232
-    {
233
-        return $this->get('MSG_message_type');
234
-    }
235
-
236
-
237
-    /**
238
-     * Sets message_type
239
-     *
240
-     * @param string $message_type
241
-     */
242
-    public function set_message_type($message_type)
243
-    {
244
-        $this->set('MSG_message_type', $message_type);
245
-    }
246
-
247
-
248
-    /**
249
-     * Returns the message type object for the set message type on this message
250
-     *
251
-     * @return EE_message_type | null
252
-     */
253
-    public function message_type_object()
254
-    {
255
-        return $this->_message_type;
256
-    }
257
-
258
-
259
-    /**
260
-     * Sets message_type
261
-     *
262
-     * @param EE_message_type $message_type
263
-     * @param bool            $set_priority   This indicates whether to set the priority to whatever the priority is on
264
-     *                                        the message type or not.
265
-     */
266
-    public function set_message_type_object(EE_message_type $message_type, $set_priority = false)
267
-    {
268
-        $this->_message_type = $message_type;
269
-        if ($set_priority) {
270
-            $this->set_priority($this->_message_type->get_priority());
271
-        }
272
-    }
273
-
274
-
275
-    /**
276
-     * validates message_type
277
-     *
278
-     * @param bool $throw_exceptions
279
-     * @return bool
280
-     * @throws \EE_Error
281
-     */
282
-    public function valid_message_type($throw_exceptions = false)
283
-    {
284
-        if ($this->_message_type instanceof EE_message_type) {
285
-            return true;
286
-        }
287
-        if ($throw_exceptions) {
288
-            throw new EE_Error(
289
-                sprintf(
290
-                    __(
291
-                        'The %1$s message type set for this message is missing or invalid. Please double-check the spelling and verify that the correct files exist.',
292
-                        'event_espresso'
293
-                    ),
294
-                    $this->message_type()
295
-                )
296
-            );
297
-        }
298
-        return false;
299
-    }
300
-
301
-
302
-    /**
303
-     * validates messenger and message_type (that they are valid EE_messenger and EE_message_type objects).
304
-     *
305
-     * @param bool $throw_exceptions
306
-     * @return bool
307
-     * @throws \EE_Error
308
-     */
309
-    public function is_valid($throw_exceptions = false)
310
-    {
311
-        if ($this->valid_messenger($throw_exceptions) && $this->valid_message_type($throw_exceptions)) {
312
-            return true;
313
-        }
314
-        return false;
315
-    }
316
-
317
-
318
-    /**
319
-     * This validates whether the internal messenger and message type objects are valid for sending.
320
-     * Three checks are done:
321
-     * 1. There is a valid messenger object.
322
-     * 2. There is a valid message type object.
323
-     * 3. The message type object is active for the messenger.
324
-     *
325
-     * @throws EE_Error  But only if $throw_exceptions is set to true.
326
-     * @param bool $throw_exceptions
327
-     * @return bool
328
-     */
329
-    public function is_valid_for_sending_or_generation($throw_exceptions = false)
330
-    {
331
-        $valid = false;
332
-        if ($this->is_valid($throw_exceptions)) {
333
-            /** @var EE_Message_Resource_Manager $message_resource_manager */
334
-            $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
335
-            $valid = $message_resource_manager->is_message_type_active_for_messenger(
336
-                $this->messenger(),
337
-                $this->message_type()
338
-            );
339
-            if (! $valid && $throw_exceptions) {
340
-                throw new EE_Error(
341
-                    sprintf(
342
-                        __(
343
-                            'The %1$s message type is not a valid message type for the %2$s messenger so it will not be sent.',
344
-                            'event_espresso'
345
-                        ),
346
-                        $this->message_type(),
347
-                        $this->messenger()
348
-                    )
349
-                );
350
-            }
351
-        }
352
-        return $valid;
353
-    }
354
-
355
-
356
-    /**
357
-     * This returns the set localized label for the message type on this message.
358
-     * Note, if unable to retrieve the EE_message_type object then will just return the message type slug saved
359
-     * with this message.
360
-     *
361
-     * @param   bool $plural whether to return the plural label or not.
362
-     * @return string
363
-     */
364
-    public function message_type_label($plural = false)
365
-    {
366
-        $label_type = $plural ? 'plural' : 'singular';
367
-        $message_type = $this->message_type_object();
368
-        return $message_type instanceof EE_message_type
369
-            ? $message_type->label[ $label_type ]
370
-            : str_replace(
371
-                '_',
372
-                ' ',
373
-                $this->message_type()
374
-            );
375
-    }
376
-
377
-
378
-    /**
379
-     * Gets context
380
-     *
381
-     * @return string
382
-     */
383
-    public function context()
384
-    {
385
-        return $this->get('MSG_context');
386
-    }
387
-
388
-
389
-    /**
390
-     * This returns the corresponding localized label for the given context slug, if possible from installed message
391
-     * types. Otherwise, this will just return the set context slug on this object.
392
-     *
393
-     * @return string
394
-     */
395
-    public function context_label()
396
-    {
397
-        /** @type EE_Message_Resource_Manager $message_resource_manager */
398
-        $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
399
-        $contexts = $message_resource_manager->get_all_contexts();
400
-        return isset($contexts[ $this->context() ]) ? $contexts[ $this->context() ] : $this->context();
401
-    }
402
-
403
-
404
-    /**
405
-     * Sets context
406
-     *
407
-     * @param string $context
408
-     */
409
-    public function set_context($context)
410
-    {
411
-        $this->set('MSG_context', $context);
412
-    }
413
-
414
-
415
-    /**
416
-     * Gets recipient_ID
417
-     *
418
-     * @return int
419
-     */
420
-    public function recipient_ID()
421
-    {
422
-        return $this->get('MSG_recipient_ID');
423
-    }
424
-
425
-
426
-    /**
427
-     * Sets recipient_ID
428
-     *
429
-     * @param string $recipient_ID
430
-     */
431
-    public function set_recipient_ID($recipient_ID)
432
-    {
433
-        $this->set('MSG_recipient_ID', $recipient_ID);
434
-    }
435
-
436
-
437
-    /**
438
-     * Gets recipient_type
439
-     *
440
-     * @return string
441
-     */
442
-    public function recipient_type()
443
-    {
444
-        return $this->get('MSG_recipient_type');
445
-    }
446
-
447
-
448
-    /**
449
-     * Return the related object matching the recipient type and ID.
450
-     *
451
-     * @return EE_Base_Class | null
452
-     */
453
-    public function recipient_object()
454
-    {
455
-        if (! $this->recipient_type() || ! $this->recipient_ID()) {
456
-            return null;
457
-        }
458
-
459
-        return $this->get_first_related($this->recipient_type());
460
-    }
461
-
462
-
463
-    /**
464
-     * Sets recipient_type
465
-     *
466
-     * @param string $recipient_type
467
-     */
468
-    public function set_recipient_type($recipient_type)
469
-    {
470
-        $this->set('MSG_recipient_type', $recipient_type);
471
-    }
472
-
473
-
474
-    /**
475
-     * Gets content
476
-     *
477
-     * @return string
478
-     */
479
-    public function content()
480
-    {
481
-        return $this->get('MSG_content');
482
-    }
483
-
484
-
485
-    /**
486
-     * Sets content
487
-     *
488
-     * @param string $content
489
-     */
490
-    public function set_content($content)
491
-    {
492
-        $this->set('MSG_content', $content);
493
-    }
494
-
495
-
496
-    /**
497
-     * Gets subject
498
-     *
499
-     * @return string
500
-     */
501
-    public function subject()
502
-    {
503
-        return $this->get('MSG_subject');
504
-    }
505
-
506
-
507
-    /**
508
-     * Sets subject
509
-     *
510
-     * @param string $subject
511
-     */
512
-    public function set_subject($subject)
513
-    {
514
-        $this->set('MSG_subject', $subject);
515
-    }
516
-
517
-
518
-    /**
519
-     * Gets to
520
-     *
521
-     * @return string
522
-     */
523
-    public function to()
524
-    {
525
-        $to = $this->get('MSG_to');
526
-        return empty($to) ? __('No recipient', 'event_espresso') : $to;
527
-    }
528
-
529
-
530
-    /**
531
-     * Sets to
532
-     *
533
-     * @param string $to
534
-     */
535
-    public function set_to($to)
536
-    {
537
-        $this->set('MSG_to', $to);
538
-    }
539
-
540
-
541
-    /**
542
-     * Gets from
543
-     *
544
-     * @return string
545
-     */
546
-    public function from()
547
-    {
548
-        return $this->get('MSG_from');
549
-    }
550
-
551
-
552
-    /**
553
-     * Sets from
554
-     *
555
-     * @param string $from
556
-     */
557
-    public function set_from($from)
558
-    {
559
-        $this->set('MSG_from', $from);
560
-    }
561
-
562
-
563
-    /**
564
-     * Gets priority
565
-     *
566
-     * @return int
567
-     */
568
-    public function priority()
569
-    {
570
-        return $this->get('MSG_priority');
571
-    }
572
-
573
-
574
-    /**
575
-     * Sets priority
576
-     * Note.  Send Now Messengers always override any priority that may be set on a Message.  So
577
-     * this method calls the send_now method to verify that.
578
-     *
579
-     * @param int $priority
580
-     */
581
-    public function set_priority($priority)
582
-    {
583
-        $priority = $this->send_now() ? EEM_Message::priority_high : $priority;
584
-        parent::set('MSG_priority', $priority);
585
-    }
586
-
587
-
588
-    /**
589
-     * Overrides parent::set method so we can capture any sets for priority.
590
-     *
591
-     * @see parent::set() for phpdocs
592
-     * @param string $field_name
593
-     * @param mixed  $field_value
594
-     * @param bool   $use_default
595
-     * @throws EE_Error
596
-     */
597
-    public function set($field_name, $field_value, $use_default = false)
598
-    {
599
-        if ($field_name === 'MSG_priority') {
600
-            $this->set_priority($field_value);
601
-        }
602
-        parent::set($field_name, $field_value, $use_default);
603
-    }
604
-
605
-
606
-    /**
607
-     * @return bool
608
-     * @throws \EE_Error
609
-     */
610
-    public function send_now()
611
-    {
612
-        $send_now = $this->valid_messenger() && $this->messenger_object()->send_now() ? EEM_Message::priority_high
613
-            : $this->priority();
614
-        return $send_now === EEM_Message::priority_high ? true : false;
615
-    }
616
-
617
-
618
-    /**
619
-     * Gets STS_ID
620
-     *
621
-     * @return string
622
-     */
623
-    public function STS_ID()
624
-    {
625
-        return $this->get('STS_ID');
626
-    }
627
-
628
-
629
-    /**
630
-     * Sets STS_ID
631
-     *
632
-     * @param string $STS_ID
633
-     */
634
-    public function set_STS_ID($STS_ID)
635
-    {
636
-        $this->set('STS_ID', $STS_ID);
637
-    }
638
-
639
-
640
-    /**
641
-     * Gets created
642
-     *
643
-     * @return string
644
-     */
645
-    public function created()
646
-    {
647
-        return $this->get('MSG_created');
648
-    }
649
-
650
-
651
-    /**
652
-     * Sets created
653
-     *
654
-     * @param string $created
655
-     */
656
-    public function set_created($created)
657
-    {
658
-        $this->set('MSG_created', $created);
659
-    }
660
-
661
-
662
-    /**
663
-     * Gets modified
664
-     *
665
-     * @return string
666
-     */
667
-    public function modified()
668
-    {
669
-        return $this->get('MSG_modified');
670
-    }
671
-
672
-
673
-    /**
674
-     * Sets modified
675
-     *
676
-     * @param string $modified
677
-     */
678
-    public function set_modified($modified)
679
-    {
680
-        $this->set('MSG_modified', $modified);
681
-    }
682
-
683
-
684
-    /**
685
-     * Sets generation data for this message.
686
-     *
687
-     * @param mixed $data
688
-     */
689
-    public function set_generation_data($data)
690
-    {
691
-        $this->set_field_or_extra_meta('MSG_generation_data', $data);
692
-    }
693
-
694
-
695
-    /**
696
-     * Returns any set generation data for this message.
697
-     *
698
-     * @return mixed|null
699
-     */
700
-    public function get_generation_data()
701
-    {
702
-        return $this->get_field_or_extra_meta('MSG_generation_data');
703
-    }
704
-
705
-
706
-    /**
707
-     * Gets any error message.
708
-     *
709
-     * @return mixed|null
710
-     */
711
-    public function error_message()
712
-    {
713
-        return $this->get_field_or_extra_meta('MSG_error');
714
-    }
715
-
716
-
717
-    /**
718
-     * Sets an error message.
719
-     *
720
-     * @param $message
721
-     * @return bool|int
722
-     */
723
-    public function set_error_message($message)
724
-    {
725
-        return $this->set_field_or_extra_meta('MSG_error', $message);
726
-    }
727
-
728
-
729
-    /**
730
-     * This retrieves the associated template pack with this message.
731
-     *
732
-     * @return EE_Messages_Template_Pack | null
733
-     */
734
-    public function get_template_pack()
735
-    {
736
-        /**
737
-         * This is deprecated functionality that will be removed eventually but included here now for backward compat.
738
-         */
739
-        if (! empty($this->template_pack)) {
740
-            return $this->template_pack;
741
-        }
742
-        /** @type EE_Message_Template_Group $grp */
743
-        $grp = $this->get_first_related('Message_Template_Group');
744
-        // if no group then let's try to get the first related group by internal messenger and message type (will use global grp).
745
-        if (! $grp instanceof EE_Message_Template_Group) {
746
-            $grp = EEM_Message_Template_Group::instance()->get_one(
747
-                array(
748
-                    array(
749
-                        'MTP_messenger'    => $this->messenger(),
750
-                        'MTP_message_type' => $this->message_type(),
751
-                        'MTP_is_global'    => true,
752
-                    ),
753
-                )
754
-            );
755
-        }
756
-
757
-        return $grp instanceof EE_Message_Template_Group ? $grp->get_template_pack() : null;
758
-    }
759
-
760
-
761
-    /**
762
-     * Retrieves the variation used for generating this message.
763
-     *
764
-     * @return string
765
-     */
766
-    public function get_template_pack_variation()
767
-    {
768
-        /**
769
-         * This is deprecated functionality that will be removed eventually but included here now for backward compat.
770
-         */
771
-        if (! empty($this->template_variation)) {
772
-            return $this->template_variation;
773
-        }
774
-
775
-        /** @type EE_Message_Template_Group $grp */
776
-        $grp = $this->get_first_related('Message_Template_Group');
777
-
778
-        // if no group then let's try to get the first related group by internal messenger and message type (will use global grp).
779
-        if (! $grp instanceof EE_Message_Template_Group) {
780
-            $grp = EEM_Message_Template_Group::instance()->get_one(
781
-                array(
782
-                    array(
783
-                        'MTP_messenger'    => $this->messenger(),
784
-                        'MTP_message_type' => $this->message_type(),
785
-                        'MTP_is_global'    => true,
786
-                    ),
787
-                )
788
-            );
789
-        }
790
-
791
-        return $grp instanceof EE_Message_Template_Group ? $grp->get_template_pack_variation() : '';
792
-    }
793
-
794
-    /**
795
-     * Return the link to the admin details for the object.
796
-     *
797
-     * @return string
798
-     */
799
-    public function get_admin_details_link()
800
-    {
801
-        EE_Registry::instance()->load_helper('URL');
802
-        EE_Registry::instance()->load_helper('MSG_Template');
803
-        switch ($this->STS_ID()) {
804
-            case EEM_Message::status_failed:
805
-            case EEM_Message::status_debug_only:
806
-                return EEH_MSG_Template::generate_error_display_trigger($this);
807
-                break;
808
-
809
-            case EEM_Message::status_sent:
810
-                return EEH_MSG_Template::generate_browser_trigger($this);
811
-                break;
812
-
813
-            default:
814
-                return '';
815
-        }
816
-    }
817
-
818
-    /**
819
-     * Returns the link to the editor for the object.  Sometimes this is the same as the details.
820
-     *
821
-     * @return string
822
-     */
823
-    public function get_admin_edit_link()
824
-    {
825
-        return $this->get_admin_details_link();
826
-    }
827
-
828
-    /**
829
-     * Returns the link to a settings page for the object.
830
-     *
831
-     * @return string
832
-     */
833
-    public function get_admin_settings_link()
834
-    {
835
-        EE_Registry::instance()->load_helper('URL');
836
-        return EEH_URL::add_query_args_and_nonce(
837
-            array(
838
-                'page'   => 'espresso_messages',
839
-                'action' => 'settings',
840
-            ),
841
-            admin_url('admin.php')
842
-        );
843
-    }
844
-
845
-    /**
846
-     * Returns the link to the "overview" for the object (typically the "list table" view).
847
-     *
848
-     * @return string
849
-     */
850
-    public function get_admin_overview_link()
851
-    {
852
-        EE_Registry::instance()->load_helper('URL');
853
-        return EEH_URL::add_query_args_and_nonce(
854
-            array(
855
-                'page'   => 'espresso_messages',
856
-                'action' => 'default',
857
-            ),
858
-            admin_url('admin.php')
859
-        );
860
-    }
861
-
862
-
863
-    /**
864
-     * This sets the EEM_Message::status_messenger_executing class on the message and the appropriate error message for
865
-     * it.
866
-     * Note this also SAVES the current message object to the db because it adds an error message to accompany the
867
-     * status.
868
-     *
869
-     */
870
-    public function set_messenger_is_executing()
871
-    {
872
-        $this->set_STS_ID(EEM_Message::status_messenger_executing);
873
-        if (EEM_Message::debug()) {
874
-            $this->set_error_message(
875
-                esc_html__(
876
-                    'A message with this status indicates that there was a problem that occurred while the message was being
13
+	/**
14
+	 * @deprecated 4.9.0  Added for backward compat with add-on's
15
+	 * @type null
16
+	 */
17
+	public $template_pack;
18
+
19
+	/**
20
+	 * @deprecated 4.9.0 Added for backward compat with add-on's
21
+	 * @type null
22
+	 */
23
+	public $template_variation;
24
+
25
+	/**
26
+	 * @deprecated 4.9.0 Added for backward compat with add-on's
27
+	 * @type string
28
+	 */
29
+	public $content = '';
30
+
31
+
32
+	/**
33
+	 * @type EE_messenger $_messenger
34
+	 */
35
+	protected $_messenger = null;
36
+
37
+	/**
38
+	 * @type EE_message_type $_message_type
39
+	 */
40
+	protected $_message_type = null;
41
+
42
+
43
+	/**
44
+	 * @param array  $props_n_values
45
+	 * @param string $timezone
46
+	 * @param array  $date_formats incoming date formats in an array.  First value is the date_format, second is time
47
+	 *                             format.
48
+	 * @return EE_Message
49
+	 */
50
+	public static function new_instance($props_n_values = array(), $timezone = null, $date_formats = array())
51
+	{
52
+		$has_object = parent::_check_for_object($props_n_values, __CLASS__);
53
+		// if object doesn't exist, let's generate a unique token on instantiation so that its available even before saving to db.
54
+		if (! $has_object) {
55
+			EE_Registry::instance()->load_helper('URL');
56
+			$props_n_values['MSG_token'] = EEH_URL::generate_unique_token();
57
+		}
58
+		return $has_object ? $has_object : new self($props_n_values, false, $timezone, $date_formats);
59
+	}
60
+
61
+
62
+	/**
63
+	 * @param array  $props_n_values
64
+	 * @param string $timezone
65
+	 * @return EE_Message
66
+	 */
67
+	public static function new_instance_from_db($props_n_values = array(), $timezone = null)
68
+	{
69
+		return new self($props_n_values, true, $timezone);
70
+	}
71
+
72
+
73
+	/**
74
+	 * Gets MSG_token
75
+	 *
76
+	 * @return int
77
+	 */
78
+	public function MSG_token()
79
+	{
80
+		return $this->get('MSG_token');
81
+	}
82
+
83
+
84
+	/**
85
+	 * Sets MSG_token
86
+	 *
87
+	 * @param int $MSG_token
88
+	 */
89
+	public function set_MSG_token($MSG_token)
90
+	{
91
+		$this->set('MSG_token', $MSG_token);
92
+	}
93
+
94
+
95
+	/**
96
+	 * Gets GRP_ID
97
+	 *
98
+	 * @return int
99
+	 */
100
+	public function GRP_ID()
101
+	{
102
+		return $this->get('GRP_ID');
103
+	}
104
+
105
+
106
+	/**
107
+	 * Sets GRP_ID
108
+	 *
109
+	 * @param int $GRP_ID
110
+	 */
111
+	public function set_GRP_ID($GRP_ID)
112
+	{
113
+		$this->set('GRP_ID', $GRP_ID);
114
+	}
115
+
116
+
117
+	/**
118
+	 * Gets TXN_ID
119
+	 *
120
+	 * @return int
121
+	 */
122
+	public function TXN_ID()
123
+	{
124
+		return $this->get('TXN_ID');
125
+	}
126
+
127
+
128
+	/**
129
+	 * Sets TXN_ID
130
+	 *
131
+	 * @param int $TXN_ID
132
+	 */
133
+	public function set_TXN_ID($TXN_ID)
134
+	{
135
+		$this->set('TXN_ID', $TXN_ID);
136
+	}
137
+
138
+
139
+	/**
140
+	 * Gets messenger
141
+	 *
142
+	 * @return string
143
+	 */
144
+	public function messenger()
145
+	{
146
+		return $this->get('MSG_messenger');
147
+	}
148
+
149
+
150
+	/**
151
+	 * Sets messenger
152
+	 *
153
+	 * @param string $messenger
154
+	 */
155
+	public function set_messenger($messenger)
156
+	{
157
+		$this->set('MSG_messenger', $messenger);
158
+	}
159
+
160
+
161
+	/**
162
+	 * Returns corresponding messenger object for the set messenger on this message
163
+	 *
164
+	 * @return EE_messenger | null
165
+	 */
166
+	public function messenger_object()
167
+	{
168
+		return $this->_messenger;
169
+	}
170
+
171
+
172
+	/**
173
+	 * Sets messenger
174
+	 *
175
+	 * @param EE_messenger $messenger
176
+	 */
177
+	public function set_messenger_object(EE_messenger $messenger)
178
+	{
179
+		$this->_messenger = $messenger;
180
+	}
181
+
182
+
183
+	/**
184
+	 * validates messenger
185
+	 *
186
+	 * @param bool $throw_exceptions
187
+	 * @return bool
188
+	 * @throws \EE_Error
189
+	 */
190
+	public function valid_messenger($throw_exceptions = false)
191
+	{
192
+		if ($this->_messenger instanceof EE_messenger) {
193
+			return true;
194
+		}
195
+		if ($throw_exceptions) {
196
+			throw new EE_Error(
197
+				sprintf(
198
+					__(
199
+						'The "%1$s" messenger set for this message is missing or invalid. Please double-check the spelling and verify that the correct files exist.',
200
+						'event_espresso'
201
+					),
202
+					$this->messenger()
203
+				)
204
+			);
205
+		}
206
+		return false;
207
+	}
208
+
209
+
210
+	/**
211
+	 * This returns the set localized label for the messenger on this message.
212
+	 * Note, if unable to retrieve the EE_messenger object then will just return the messenger slug saved
213
+	 * with this message.
214
+	 *
215
+	 * @param   bool $plural whether to return the plural label or not.
216
+	 * @return string
217
+	 */
218
+	public function messenger_label($plural = false)
219
+	{
220
+		$label_type = $plural ? 'plural' : 'singular';
221
+		$messenger = $this->messenger_object();
222
+		return $messenger instanceof EE_messenger ? $messenger->label[ $label_type ] : $this->messenger();
223
+	}
224
+
225
+
226
+	/**
227
+	 * Gets message_type
228
+	 *
229
+	 * @return string
230
+	 */
231
+	public function message_type()
232
+	{
233
+		return $this->get('MSG_message_type');
234
+	}
235
+
236
+
237
+	/**
238
+	 * Sets message_type
239
+	 *
240
+	 * @param string $message_type
241
+	 */
242
+	public function set_message_type($message_type)
243
+	{
244
+		$this->set('MSG_message_type', $message_type);
245
+	}
246
+
247
+
248
+	/**
249
+	 * Returns the message type object for the set message type on this message
250
+	 *
251
+	 * @return EE_message_type | null
252
+	 */
253
+	public function message_type_object()
254
+	{
255
+		return $this->_message_type;
256
+	}
257
+
258
+
259
+	/**
260
+	 * Sets message_type
261
+	 *
262
+	 * @param EE_message_type $message_type
263
+	 * @param bool            $set_priority   This indicates whether to set the priority to whatever the priority is on
264
+	 *                                        the message type or not.
265
+	 */
266
+	public function set_message_type_object(EE_message_type $message_type, $set_priority = false)
267
+	{
268
+		$this->_message_type = $message_type;
269
+		if ($set_priority) {
270
+			$this->set_priority($this->_message_type->get_priority());
271
+		}
272
+	}
273
+
274
+
275
+	/**
276
+	 * validates message_type
277
+	 *
278
+	 * @param bool $throw_exceptions
279
+	 * @return bool
280
+	 * @throws \EE_Error
281
+	 */
282
+	public function valid_message_type($throw_exceptions = false)
283
+	{
284
+		if ($this->_message_type instanceof EE_message_type) {
285
+			return true;
286
+		}
287
+		if ($throw_exceptions) {
288
+			throw new EE_Error(
289
+				sprintf(
290
+					__(
291
+						'The %1$s message type set for this message is missing or invalid. Please double-check the spelling and verify that the correct files exist.',
292
+						'event_espresso'
293
+					),
294
+					$this->message_type()
295
+				)
296
+			);
297
+		}
298
+		return false;
299
+	}
300
+
301
+
302
+	/**
303
+	 * validates messenger and message_type (that they are valid EE_messenger and EE_message_type objects).
304
+	 *
305
+	 * @param bool $throw_exceptions
306
+	 * @return bool
307
+	 * @throws \EE_Error
308
+	 */
309
+	public function is_valid($throw_exceptions = false)
310
+	{
311
+		if ($this->valid_messenger($throw_exceptions) && $this->valid_message_type($throw_exceptions)) {
312
+			return true;
313
+		}
314
+		return false;
315
+	}
316
+
317
+
318
+	/**
319
+	 * This validates whether the internal messenger and message type objects are valid for sending.
320
+	 * Three checks are done:
321
+	 * 1. There is a valid messenger object.
322
+	 * 2. There is a valid message type object.
323
+	 * 3. The message type object is active for the messenger.
324
+	 *
325
+	 * @throws EE_Error  But only if $throw_exceptions is set to true.
326
+	 * @param bool $throw_exceptions
327
+	 * @return bool
328
+	 */
329
+	public function is_valid_for_sending_or_generation($throw_exceptions = false)
330
+	{
331
+		$valid = false;
332
+		if ($this->is_valid($throw_exceptions)) {
333
+			/** @var EE_Message_Resource_Manager $message_resource_manager */
334
+			$message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
335
+			$valid = $message_resource_manager->is_message_type_active_for_messenger(
336
+				$this->messenger(),
337
+				$this->message_type()
338
+			);
339
+			if (! $valid && $throw_exceptions) {
340
+				throw new EE_Error(
341
+					sprintf(
342
+						__(
343
+							'The %1$s message type is not a valid message type for the %2$s messenger so it will not be sent.',
344
+							'event_espresso'
345
+						),
346
+						$this->message_type(),
347
+						$this->messenger()
348
+					)
349
+				);
350
+			}
351
+		}
352
+		return $valid;
353
+	}
354
+
355
+
356
+	/**
357
+	 * This returns the set localized label for the message type on this message.
358
+	 * Note, if unable to retrieve the EE_message_type object then will just return the message type slug saved
359
+	 * with this message.
360
+	 *
361
+	 * @param   bool $plural whether to return the plural label or not.
362
+	 * @return string
363
+	 */
364
+	public function message_type_label($plural = false)
365
+	{
366
+		$label_type = $plural ? 'plural' : 'singular';
367
+		$message_type = $this->message_type_object();
368
+		return $message_type instanceof EE_message_type
369
+			? $message_type->label[ $label_type ]
370
+			: str_replace(
371
+				'_',
372
+				' ',
373
+				$this->message_type()
374
+			);
375
+	}
376
+
377
+
378
+	/**
379
+	 * Gets context
380
+	 *
381
+	 * @return string
382
+	 */
383
+	public function context()
384
+	{
385
+		return $this->get('MSG_context');
386
+	}
387
+
388
+
389
+	/**
390
+	 * This returns the corresponding localized label for the given context slug, if possible from installed message
391
+	 * types. Otherwise, this will just return the set context slug on this object.
392
+	 *
393
+	 * @return string
394
+	 */
395
+	public function context_label()
396
+	{
397
+		/** @type EE_Message_Resource_Manager $message_resource_manager */
398
+		$message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
399
+		$contexts = $message_resource_manager->get_all_contexts();
400
+		return isset($contexts[ $this->context() ]) ? $contexts[ $this->context() ] : $this->context();
401
+	}
402
+
403
+
404
+	/**
405
+	 * Sets context
406
+	 *
407
+	 * @param string $context
408
+	 */
409
+	public function set_context($context)
410
+	{
411
+		$this->set('MSG_context', $context);
412
+	}
413
+
414
+
415
+	/**
416
+	 * Gets recipient_ID
417
+	 *
418
+	 * @return int
419
+	 */
420
+	public function recipient_ID()
421
+	{
422
+		return $this->get('MSG_recipient_ID');
423
+	}
424
+
425
+
426
+	/**
427
+	 * Sets recipient_ID
428
+	 *
429
+	 * @param string $recipient_ID
430
+	 */
431
+	public function set_recipient_ID($recipient_ID)
432
+	{
433
+		$this->set('MSG_recipient_ID', $recipient_ID);
434
+	}
435
+
436
+
437
+	/**
438
+	 * Gets recipient_type
439
+	 *
440
+	 * @return string
441
+	 */
442
+	public function recipient_type()
443
+	{
444
+		return $this->get('MSG_recipient_type');
445
+	}
446
+
447
+
448
+	/**
449
+	 * Return the related object matching the recipient type and ID.
450
+	 *
451
+	 * @return EE_Base_Class | null
452
+	 */
453
+	public function recipient_object()
454
+	{
455
+		if (! $this->recipient_type() || ! $this->recipient_ID()) {
456
+			return null;
457
+		}
458
+
459
+		return $this->get_first_related($this->recipient_type());
460
+	}
461
+
462
+
463
+	/**
464
+	 * Sets recipient_type
465
+	 *
466
+	 * @param string $recipient_type
467
+	 */
468
+	public function set_recipient_type($recipient_type)
469
+	{
470
+		$this->set('MSG_recipient_type', $recipient_type);
471
+	}
472
+
473
+
474
+	/**
475
+	 * Gets content
476
+	 *
477
+	 * @return string
478
+	 */
479
+	public function content()
480
+	{
481
+		return $this->get('MSG_content');
482
+	}
483
+
484
+
485
+	/**
486
+	 * Sets content
487
+	 *
488
+	 * @param string $content
489
+	 */
490
+	public function set_content($content)
491
+	{
492
+		$this->set('MSG_content', $content);
493
+	}
494
+
495
+
496
+	/**
497
+	 * Gets subject
498
+	 *
499
+	 * @return string
500
+	 */
501
+	public function subject()
502
+	{
503
+		return $this->get('MSG_subject');
504
+	}
505
+
506
+
507
+	/**
508
+	 * Sets subject
509
+	 *
510
+	 * @param string $subject
511
+	 */
512
+	public function set_subject($subject)
513
+	{
514
+		$this->set('MSG_subject', $subject);
515
+	}
516
+
517
+
518
+	/**
519
+	 * Gets to
520
+	 *
521
+	 * @return string
522
+	 */
523
+	public function to()
524
+	{
525
+		$to = $this->get('MSG_to');
526
+		return empty($to) ? __('No recipient', 'event_espresso') : $to;
527
+	}
528
+
529
+
530
+	/**
531
+	 * Sets to
532
+	 *
533
+	 * @param string $to
534
+	 */
535
+	public function set_to($to)
536
+	{
537
+		$this->set('MSG_to', $to);
538
+	}
539
+
540
+
541
+	/**
542
+	 * Gets from
543
+	 *
544
+	 * @return string
545
+	 */
546
+	public function from()
547
+	{
548
+		return $this->get('MSG_from');
549
+	}
550
+
551
+
552
+	/**
553
+	 * Sets from
554
+	 *
555
+	 * @param string $from
556
+	 */
557
+	public function set_from($from)
558
+	{
559
+		$this->set('MSG_from', $from);
560
+	}
561
+
562
+
563
+	/**
564
+	 * Gets priority
565
+	 *
566
+	 * @return int
567
+	 */
568
+	public function priority()
569
+	{
570
+		return $this->get('MSG_priority');
571
+	}
572
+
573
+
574
+	/**
575
+	 * Sets priority
576
+	 * Note.  Send Now Messengers always override any priority that may be set on a Message.  So
577
+	 * this method calls the send_now method to verify that.
578
+	 *
579
+	 * @param int $priority
580
+	 */
581
+	public function set_priority($priority)
582
+	{
583
+		$priority = $this->send_now() ? EEM_Message::priority_high : $priority;
584
+		parent::set('MSG_priority', $priority);
585
+	}
586
+
587
+
588
+	/**
589
+	 * Overrides parent::set method so we can capture any sets for priority.
590
+	 *
591
+	 * @see parent::set() for phpdocs
592
+	 * @param string $field_name
593
+	 * @param mixed  $field_value
594
+	 * @param bool   $use_default
595
+	 * @throws EE_Error
596
+	 */
597
+	public function set($field_name, $field_value, $use_default = false)
598
+	{
599
+		if ($field_name === 'MSG_priority') {
600
+			$this->set_priority($field_value);
601
+		}
602
+		parent::set($field_name, $field_value, $use_default);
603
+	}
604
+
605
+
606
+	/**
607
+	 * @return bool
608
+	 * @throws \EE_Error
609
+	 */
610
+	public function send_now()
611
+	{
612
+		$send_now = $this->valid_messenger() && $this->messenger_object()->send_now() ? EEM_Message::priority_high
613
+			: $this->priority();
614
+		return $send_now === EEM_Message::priority_high ? true : false;
615
+	}
616
+
617
+
618
+	/**
619
+	 * Gets STS_ID
620
+	 *
621
+	 * @return string
622
+	 */
623
+	public function STS_ID()
624
+	{
625
+		return $this->get('STS_ID');
626
+	}
627
+
628
+
629
+	/**
630
+	 * Sets STS_ID
631
+	 *
632
+	 * @param string $STS_ID
633
+	 */
634
+	public function set_STS_ID($STS_ID)
635
+	{
636
+		$this->set('STS_ID', $STS_ID);
637
+	}
638
+
639
+
640
+	/**
641
+	 * Gets created
642
+	 *
643
+	 * @return string
644
+	 */
645
+	public function created()
646
+	{
647
+		return $this->get('MSG_created');
648
+	}
649
+
650
+
651
+	/**
652
+	 * Sets created
653
+	 *
654
+	 * @param string $created
655
+	 */
656
+	public function set_created($created)
657
+	{
658
+		$this->set('MSG_created', $created);
659
+	}
660
+
661
+
662
+	/**
663
+	 * Gets modified
664
+	 *
665
+	 * @return string
666
+	 */
667
+	public function modified()
668
+	{
669
+		return $this->get('MSG_modified');
670
+	}
671
+
672
+
673
+	/**
674
+	 * Sets modified
675
+	 *
676
+	 * @param string $modified
677
+	 */
678
+	public function set_modified($modified)
679
+	{
680
+		$this->set('MSG_modified', $modified);
681
+	}
682
+
683
+
684
+	/**
685
+	 * Sets generation data for this message.
686
+	 *
687
+	 * @param mixed $data
688
+	 */
689
+	public function set_generation_data($data)
690
+	{
691
+		$this->set_field_or_extra_meta('MSG_generation_data', $data);
692
+	}
693
+
694
+
695
+	/**
696
+	 * Returns any set generation data for this message.
697
+	 *
698
+	 * @return mixed|null
699
+	 */
700
+	public function get_generation_data()
701
+	{
702
+		return $this->get_field_or_extra_meta('MSG_generation_data');
703
+	}
704
+
705
+
706
+	/**
707
+	 * Gets any error message.
708
+	 *
709
+	 * @return mixed|null
710
+	 */
711
+	public function error_message()
712
+	{
713
+		return $this->get_field_or_extra_meta('MSG_error');
714
+	}
715
+
716
+
717
+	/**
718
+	 * Sets an error message.
719
+	 *
720
+	 * @param $message
721
+	 * @return bool|int
722
+	 */
723
+	public function set_error_message($message)
724
+	{
725
+		return $this->set_field_or_extra_meta('MSG_error', $message);
726
+	}
727
+
728
+
729
+	/**
730
+	 * This retrieves the associated template pack with this message.
731
+	 *
732
+	 * @return EE_Messages_Template_Pack | null
733
+	 */
734
+	public function get_template_pack()
735
+	{
736
+		/**
737
+		 * This is deprecated functionality that will be removed eventually but included here now for backward compat.
738
+		 */
739
+		if (! empty($this->template_pack)) {
740
+			return $this->template_pack;
741
+		}
742
+		/** @type EE_Message_Template_Group $grp */
743
+		$grp = $this->get_first_related('Message_Template_Group');
744
+		// if no group then let's try to get the first related group by internal messenger and message type (will use global grp).
745
+		if (! $grp instanceof EE_Message_Template_Group) {
746
+			$grp = EEM_Message_Template_Group::instance()->get_one(
747
+				array(
748
+					array(
749
+						'MTP_messenger'    => $this->messenger(),
750
+						'MTP_message_type' => $this->message_type(),
751
+						'MTP_is_global'    => true,
752
+					),
753
+				)
754
+			);
755
+		}
756
+
757
+		return $grp instanceof EE_Message_Template_Group ? $grp->get_template_pack() : null;
758
+	}
759
+
760
+
761
+	/**
762
+	 * Retrieves the variation used for generating this message.
763
+	 *
764
+	 * @return string
765
+	 */
766
+	public function get_template_pack_variation()
767
+	{
768
+		/**
769
+		 * This is deprecated functionality that will be removed eventually but included here now for backward compat.
770
+		 */
771
+		if (! empty($this->template_variation)) {
772
+			return $this->template_variation;
773
+		}
774
+
775
+		/** @type EE_Message_Template_Group $grp */
776
+		$grp = $this->get_first_related('Message_Template_Group');
777
+
778
+		// if no group then let's try to get the first related group by internal messenger and message type (will use global grp).
779
+		if (! $grp instanceof EE_Message_Template_Group) {
780
+			$grp = EEM_Message_Template_Group::instance()->get_one(
781
+				array(
782
+					array(
783
+						'MTP_messenger'    => $this->messenger(),
784
+						'MTP_message_type' => $this->message_type(),
785
+						'MTP_is_global'    => true,
786
+					),
787
+				)
788
+			);
789
+		}
790
+
791
+		return $grp instanceof EE_Message_Template_Group ? $grp->get_template_pack_variation() : '';
792
+	}
793
+
794
+	/**
795
+	 * Return the link to the admin details for the object.
796
+	 *
797
+	 * @return string
798
+	 */
799
+	public function get_admin_details_link()
800
+	{
801
+		EE_Registry::instance()->load_helper('URL');
802
+		EE_Registry::instance()->load_helper('MSG_Template');
803
+		switch ($this->STS_ID()) {
804
+			case EEM_Message::status_failed:
805
+			case EEM_Message::status_debug_only:
806
+				return EEH_MSG_Template::generate_error_display_trigger($this);
807
+				break;
808
+
809
+			case EEM_Message::status_sent:
810
+				return EEH_MSG_Template::generate_browser_trigger($this);
811
+				break;
812
+
813
+			default:
814
+				return '';
815
+		}
816
+	}
817
+
818
+	/**
819
+	 * Returns the link to the editor for the object.  Sometimes this is the same as the details.
820
+	 *
821
+	 * @return string
822
+	 */
823
+	public function get_admin_edit_link()
824
+	{
825
+		return $this->get_admin_details_link();
826
+	}
827
+
828
+	/**
829
+	 * Returns the link to a settings page for the object.
830
+	 *
831
+	 * @return string
832
+	 */
833
+	public function get_admin_settings_link()
834
+	{
835
+		EE_Registry::instance()->load_helper('URL');
836
+		return EEH_URL::add_query_args_and_nonce(
837
+			array(
838
+				'page'   => 'espresso_messages',
839
+				'action' => 'settings',
840
+			),
841
+			admin_url('admin.php')
842
+		);
843
+	}
844
+
845
+	/**
846
+	 * Returns the link to the "overview" for the object (typically the "list table" view).
847
+	 *
848
+	 * @return string
849
+	 */
850
+	public function get_admin_overview_link()
851
+	{
852
+		EE_Registry::instance()->load_helper('URL');
853
+		return EEH_URL::add_query_args_and_nonce(
854
+			array(
855
+				'page'   => 'espresso_messages',
856
+				'action' => 'default',
857
+			),
858
+			admin_url('admin.php')
859
+		);
860
+	}
861
+
862
+
863
+	/**
864
+	 * This sets the EEM_Message::status_messenger_executing class on the message and the appropriate error message for
865
+	 * it.
866
+	 * Note this also SAVES the current message object to the db because it adds an error message to accompany the
867
+	 * status.
868
+	 *
869
+	 */
870
+	public function set_messenger_is_executing()
871
+	{
872
+		$this->set_STS_ID(EEM_Message::status_messenger_executing);
873
+		if (EEM_Message::debug()) {
874
+			$this->set_error_message(
875
+				esc_html__(
876
+					'A message with this status indicates that there was a problem that occurred while the message was being
877 877
                     processed by the messenger.  It is still possible that the message was sent successfully, but at some
878 878
                     point during the processing there was a failure.  This usually is indicative of a timeout issue with PHP 
879 879
                     or memory limits being reached.  If you see this repeatedly you may want to consider upgrading the memory 
880 880
                     available to PHP on your server.',
881
-                    'event_espresso'
882
-                )
883
-            );
884
-        }
885
-    }
881
+					'event_espresso'
882
+				)
883
+			);
884
+		}
885
+	}
886 886
 }
Please login to merge, or discard this patch.