Completed
Branch BUG-10375-migrations-not-repor... (1e9646)
by
unknown
62:53 queued 49:42
created

DisplayTicketSelector::displaySubmitButton()   C

Complexity

Conditions 13
Paths 19

Size

Total Lines 72
Code Lines 47

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 13
eloc 47
nc 19
nop 1
dl 0
loc 72
rs 5.5073
c 0
b 0
f 0

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
namespace EventEspresso\modules\ticket_selector;
3
4
if ( ! defined( 'EVENT_ESPRESSO_VERSION' ) ) {
5
    exit( 'No direct script access allowed' );
6
}
7
8
9
10
/**
11
 * Class DisplayTicketSelector
12
 * Description
13
 *
14
 * @package       Event Espresso
15
 * @subpackage    core
16
 * @author        Brent Christensen
17
 * @since         $VID:$
18
 */
19
class DisplayTicketSelector
20
{
21
22
    /**
23
     * event that ticket selector is being generated for
24
     *
25
     * @access protected
26
     * @var \EE_Event $event
27
     */
28
    protected $event;
29
30
    /**
31
     * Used to flag when the ticket selector is being called from an external iframe.
32
     *
33
     * @var bool $iframe
34
     */
35
    protected $iframe = false;
36
37
    /**
38
     * max attendees that can register for event at one time
39
     *
40
     * @var int $max_attendees
41
     */
42
    private $max_attendees = EE_INF;
43
44
    /**
45
     *@var string $date_format
46
     */
47
    private $date_format = '';
48
49
    /**
50
     *@var string $time_format
51
     */
52
    private $time_format = '';
53
54
55
56
    /**
57
     * DisplayTicketSelector constructor.
58
     */
59
    public function __construct()
60
    {
61
        $this->date_format = apply_filters(
62
            'FHEE__EED_Ticket_Selector__display_ticket_selector__date_format',
63
            get_option('date_format')
64
        );
65
        $this->time_format = apply_filters(
66
            'FHEE__EED_Ticket_Selector__display_ticket_selector__time_format',
67
            get_option('time_format')
68
        );
69
    }
70
71
72
73
    /**
74
     * @param boolean $iframe
75
     */
76
    public function setIframe( $iframe = true )
77
    {
78
        $this->iframe = filter_var( $iframe, FILTER_VALIDATE_BOOLEAN );
79
    }
80
81
82
83
    /**
84
     * finds and sets the \EE_Event object for use throughout class
85
     *
86
     * @param    mixed $event
87
     * @return    bool
88
     */
89
    protected function setEvent( $event = null )
90
    {
91
        if ( $event === null ) {
92
            global $post;
93
            $event = $post;
94
        }
95
        if ( $event instanceof \EE_Event ) {
96
            $this->event = $event;
97
        } else if ( $event instanceof \WP_Post ) {
0 ignored issues
show
Bug introduced by
The class WP_Post does not exist. Did you forget a USE statement, or did you not list all dependencies?

This error could be the result of:

1. Missing dependencies

PHP Analyzer uses your composer.json file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects the composer.json to be in the root folder of your repository.

Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the require or require-dev section?

2. Missing use statement

PHP does not complain about undefined classes in ìnstanceof checks. For example, the following PHP code will work perfectly fine:

if ($x instanceof DoesNotExist) {
    // Do something.
}

If you have not tested against this specific condition, such errors might go unnoticed.

Loading history...
98
            if ( isset( $event->EE_Event ) && $event->EE_Event instanceof \EE_Event ) {
99
                $this->event = $event->EE_Event;
100
            } else if ( $event->post_type === 'espresso_events' ) {
101
                $event->EE_Event = \EEM_Event::instance()->instantiate_class_from_post_object( $event );
102
                $this->event = $event->EE_Event;
0 ignored issues
show
Documentation Bug introduced by
It seems like $event->EE_Event can also be of type object<EE_Base_Class>. However, the property $event is declared as type object<EE_Event>. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
103
            }
104 View Code Duplication
        } else {
105
            $user_msg = __( 'No Event object or an invalid Event object was supplied.', 'event_espresso' );
106
            $dev_msg = $user_msg . __(
107
                    '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.',
108
                    'event_espresso'
109
                );
110
            \EE_Error::add_error( $user_msg . '||' . $dev_msg, __FILE__, __FUNCTION__, __LINE__ );
111
            return false;
112
        }
113
        return true;
114
    }
115
116
117
118
    /**
119
     * @return int
120
     */
121
    public function getMaxAttendees()
122
    {
123
        return $this->max_attendees;
124
    }
125
126
127
128
    /**
129
     * @param int $max_attendees
130
     */
131
    public function setMaxAttendees($max_attendees)
132
    {
133
        $this->max_attendees = absint(
134
            apply_filters(
135
                'FHEE__EE_Ticket_Selector__display_ticket_selector__max_tickets',
136
                $max_attendees
137
            )
138
        );
139
    }
140
141
142
143
    /**
144
     * creates buttons for selecting number of attendees for an event
145
     *
146
     * @param \WP_Post|int $event
147
     * @param bool         $view_details
148
     * @return string
149
     * @throws \EE_Error
150
     */
151
    public function display( $event = null, $view_details = false )
152
    {
153
        // reset filter for displaying submit button
154
        remove_filter( 'FHEE__EE_Ticket_Selector__display_ticket_selector_submit', '__return_true' );
155
        // poke and prod incoming event till it tells us what it is
156
        if ( ! $this->setEvent( $event ) ) {
157
            return false;
158
        }
159
        // begin gathering template arguments by getting event status
160
        $template_args = array( 'event_status' => $this->event->get_active_status() );
161
        if ( $this->activeEventAndShowTicketSelector($event, $template_args['event_status'], $view_details) ) {
0 ignored issues
show
Bug introduced by
It seems like $event defined by parameter $event on line 151 can also be of type null; however, EventEspresso\modules\ti...AndShowTicketSelector() does only seem to accept object<WP_Post>|integer, maybe add an additional type check?

This check looks at variables that have been passed in as parameters and are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
Documentation introduced by
$template_args['event_status'] is of type boolean, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
162
            return ! is_single() ? $this->displayViewDetailsButton() : '';
163
        }
164
        // filter the maximum qty that can appear in the Ticket Selector qty dropdowns
165
        $this->setMaxAttendees($this->event->additional_limit());
0 ignored issues
show
Documentation introduced by
$this->event->additional_limit() is of type boolean, but the function expects a integer.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
166
        if ($this->getMaxAttendees() < 1) {
167
            return $this->ticketSalesClosedMessage();
168
        }
169
        // is the event expired ?
170
        $template_args['event_is_expired'] = $this->event->is_expired();
171
        if ( $template_args[ 'event_is_expired' ] ) {
172
            return $this->expiredEventMessage();
173
        }
174
        // get all tickets for this event ordered by the datetime
175
        $tickets = $this->getTickets();
176
        if (count($tickets) < 1) {
177
            return $this->noTicketAvailableMessage();
178
        }
179
        // redirecting to another site for registration ??
180
        $external_url = (string) $this->event->external_url();
181
        // if redirecting to another site for registration, then we don't load the TS
182
        $ticket_selector = $external_url
183
            ? $this->externalEventRegistration()
184
            : $this->loadTicketSelector($tickets,$template_args);
0 ignored issues
show
Documentation introduced by
$tickets is of type array<integer,object<EE_Base_Class>>, but the function expects a array<integer,object<EE_Ticket>>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
185
        // now set up the form (but not for the admin)
186
        $ticket_selector = ! is_admin()
187
            ? $this->formOpen($this->event->ID(), $external_url) . $ticket_selector
188
            : $ticket_selector;
189
        // submit button and form close tag
190
        $ticket_selector .= ! is_admin() ? $this->displaySubmitButton($external_url) : '';
191
        return $ticket_selector;
192
    }
193
194
195
196
    /**
197
     * displayTicketSelector
198
     * examines the event properties and determines whether a Ticket Selector should be displayed
199
     *
200
     * @param \WP_Post|int $event
201
     * @param string       $_event_active_status
202
     * @param bool         $view_details
203
     * @return bool
204
     * @throws \EE_Error
205
     */
206
    protected function activeEventAndShowTicketSelector($event, $_event_active_status, $view_details)
207
    {
208
        $event_post = $this->event instanceof \EE_Event ? $this->event->ID() : $event;
209
        return ! is_admin()
210
               && (
211
                   ! $this->event->display_ticket_selector()
212
                   || $view_details
213
                   || post_password_required($event_post)
214
                   || (
215
                       $_event_active_status !== \EE_Datetime::active
216
                       && $_event_active_status !== \EE_Datetime::upcoming
217
                       && $_event_active_status !== \EE_Datetime::sold_out
218
                       && ! (
219
                           $_event_active_status === \EE_Datetime::inactive
220
                           && is_user_logged_in()
221
                       )
222
                   )
223
               );
224
    }
225
226
227
228
    /**
229
     * noTicketAvailableMessage
230
     * notice displayed if event is expired
231
     *
232
     * @return string
233
     * @throws \EE_Error
234
     */
235
    protected function expiredEventMessage()
236
    {
237
        return '<div class="ee-event-expired-notice"><span class="important-notice">' . esc_html__(
238
            'We\'re sorry, but all tickets sales have ended because the event is expired.',
239
            'event_espresso'
240
        ) . '</span></div>';
241
    }
242
243
244
245
    /**
246
     * noTicketAvailableMessage
247
     * notice displayed if event has no more tickets available
248
     *
249
     * @return string
250
     * @throws \EE_Error
251
     */
252 View Code Duplication
    protected function noTicketAvailableMessage()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
253
    {
254
        $no_ticket_available_msg = esc_html__( 'We\'re sorry, but all ticket sales have ended.', 'event_espresso' );
255
        if (current_user_can('edit_post', $this->event->ID())) {
256
            $no_ticket_available_msg .= sprintf(
257
                esc_html__(
258
                    '%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',
259
                    'event_espresso'
260
                ),
261
                '<div class="ee-attention" style="text-align: left;"><b>',
262
                '</b><br />',
263
                '<span class="edit-link"><a class="post-edit-link" href="'.get_edit_post_link($this->event->ID()).'">',
264
                '</a></span></div>'
265
            );
266
        }
267
        return '
268
            <div class="ee-event-expired-notice">
269
                <span class="important-notice">' . $no_ticket_available_msg . '</span>
270
            </div>';
271
    }
272
273
274
275
    /**
276
     * ticketSalesClosed
277
     * notice displayed if event ticket sales are turned off
278
     *
279
     * @return string
280
     * @throws \EE_Error
281
     */
282 View Code Duplication
    protected function ticketSalesClosedMessage()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
283
    {
284
        $sales_closed_msg = esc_html__(
285
            'We\'re sorry, but ticket sales have been closed at this time. Please check back again later.',
286
            'event_espresso'
287
        );
288
        if (current_user_can('edit_post', $this->event->ID())) {
289
            $sales_closed_msg .= sprintf(
290
                esc_html__(
291
                    '%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',
292
                    'event_espresso'
293
                ),
294
                '<div class="ee-attention" style="text-align: left;"><b>',
295
                '</b><br />',
296
                '<span class="edit-link"><a class="post-edit-link" href="'.get_edit_post_link($this->event->ID()).'">',
297
                '</a></span></div>'
298
            );
299
        }
300
        return '<p><span class="important-notice">' . $sales_closed_msg . '</span></p>';
301
    }
302
303
304
305
    /**
306
     * getTickets
307
     *
308
     * @return \EE_Base_Class[]|\EE_Ticket[]
309
     * @throws \EE_Error
310
     */
311
    protected function getTickets()
312
    {
313
        $ticket_query_args = array(
314
            array('Datetime.EVT_ID' => $this->event->ID()),
315
            'order_by' => array(
316
                'TKT_order'              => 'ASC',
317
                'TKT_required'           => 'DESC',
318
                'TKT_start_date'         => 'ASC',
319
                'TKT_end_date'           => 'ASC',
320
                'Datetime.DTT_EVT_start' => 'DESC',
321
            ),
322
        );
323
        if ( ! \EE_Registry::instance()->CFG->template_settings->EED_Ticket_Selector->show_expired_tickets) {
324
            //use the correct applicable time query depending on what version of core is being run.
325
            $current_time = method_exists('EEM_Datetime', 'current_time_for_query')
326
                ? time()
327
                : current_time('timestamp');
328
            $ticket_query_args[0]['TKT_end_date'] = array('>', $current_time);
329
        }
330
        return \EEM_Ticket::instance()->get_all($ticket_query_args);
331
    }
332
333
334
335
    /**
336
     * loadTicketSelector
337
     * begins to assemble template arguments
338
     * and decides whether to load a "simple" ticket selector, or the standard
339
     *
340
     * @param \EE_Ticket[] $tickets
341
     * @param array $template_args
342
     * @return string
343
     * @throws \EE_Error
344
     */
345
    protected function loadTicketSelector(array $tickets, array $template_args)
346
    {
347
        $template_args['event'] = $this->event;
348
        $template_args['EVT_ID'] = $this->event->ID();
349
        $template_args['event_is_expired'] = $this->event->is_expired();
350
        $template_args['max_atndz'] = $this->getMaxAttendees();
351
        $template_args['date_format'] = $this->date_format;
352
        $template_args['time_format'] = $this->time_format;
353
        /**
354
         * Filters the anchor ID used when redirecting to the Ticket Selector if no quantity selected
355
         *
356
         * @since 4.9.13
357
         * @param     string  '#tkt-slctr-tbl-' . $EVT_ID The html ID to anchor to
358
         * @param int $EVT_ID The Event ID
359
         */
360
        $template_args['anchor_id'] = apply_filters(
361
            'FHEE__EE_Ticket_Selector__redirect_anchor_id',
362
            '#tkt-slctr-tbl-' . $this->event->ID(),
363
            $this->event->ID()
364
        );
365
        $template_args['tickets'] = $tickets;
366
        $template_args['ticket_count'] = count($tickets);
367
        $ticket_selector = $this->simpleTicketSelector( $tickets, $template_args);
368
        return $ticket_selector instanceof TicketSelectorSimple
369
            ? $ticket_selector
370
            : new TicketSelectorStandard(
371
                $this->event,
372
                $tickets,
373
                $this->getMaxAttendees(),
374
                $template_args,
375
                $this->date_format,
376
                $this->time_format
377
            );
378
    }
379
380
381
382
    /**
383
     * simpleTicketSelector
384
     * there's one ticket, and max attendees is set to one,
385
     * so if the event is free, then this is a "simple" ticket selector
386
     * a.k.a. "Dude Where's my Ticket Selector?"
387
     *
388
     * @param \EE_Ticket[] $tickets
389
     * @param array  $template_args
390
     * @return string
391
     * @throws \EE_Error
392
     */
393
    protected function simpleTicketSelector($tickets, array $template_args)
394
    {
395
        // if there is only ONE ticket with a max qty of ONE
396
        if (count($tickets) > 1 || $this->getMaxAttendees() !== 1) {
397
            return '';
398
        }
399
        /** @var \EE_Ticket $ticket */
400
        $ticket = reset($tickets);
401
        // if the ticket is free... then not much need for the ticket selector
402
        if (
403
            apply_filters(
404
                'FHEE__ticket_selector_chart_template__hide_ticket_selector',
405
                $ticket->is_free(),
406
                $this->event->ID()
407
            )
408
        ) {
409
            return new TicketSelectorSimple(
410
                $this->event,
411
                $ticket,
412
                $this->getMaxAttendees(),
413
                $template_args
414
            );
415
        }
416
        return '';
417
    }
418
419
420
421
    /**
422
     * externalEventRegistration
423
     *
424
     * @return string
425
     */
426
    public function externalEventRegistration()
427
    {
428
        // if not we still need to trigger the display of the submit button
429
        add_filter('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', '__return_true');
430
        //display notice to admin that registration is external
431
        return is_admin()
432
            ? esc_html__(
433
                'Registration is at an external URL for this event.',
434
                'event_espresso'
435
            )
436
            : '';
437
    }
438
439
440
441
    /**
442
     * formOpen
443
     *
444
     * @param        int    $ID
445
     * @param        string $external_url
446
     * @return        string
447
     */
448
    public function formOpen( $ID = 0, $external_url = '' )
449
    {
450
        // if redirecting, we don't need any anything else
451
        if ( $external_url ) {
452
            $html = '<form method="GET" action="' . \EEH_URL::refactor_url($external_url) . '"';
453
            // open link in new window ?
454
            $html .= apply_filters(
455
                'FHEE__EventEspresso_modules_ticket_selector_DisplayTicketSelector__formOpen__external_url_target_blank',
456
                false
457
            )
458
                ? ' target="_blank"'
459
                : '';
460
            $html .= '>';
461
            $query_args = \EEH_URL::get_query_string( $external_url );
462
            foreach ( (array)$query_args as $query_arg => $value ) {
463
                $html .= '<input type="hidden" name="' . $query_arg . '" value="' . $value . '">';
464
            }
465
            return $html;
466
        }
467
        // if there is no submit button, then don't start building a form
468
        // because the "View Details" button will build its own form
469
        if ( ! apply_filters( 'FHEE__EE_Ticket_Selector__display_ticket_selector_submit', false ) ) {
470
            return '';
471
        }
472
        $checkout_url = \EEH_Event_View::event_link_url( $ID );
473
        if ( ! $checkout_url ) {
474
            \EE_Error::add_error(
475
                esc_html__( 'The URL for the Event Details page could not be retrieved.', 'event_espresso' ),
476
                __FILE__,
477
                __FUNCTION__,
478
                __LINE__
479
            );
480
        }
481
        // set no cache headers and constants
482
        \EE_System::do_not_cache();
483
        $extra_params = $this->iframe ? ' target="_blank"' : '';
484
        $html = '<form method="POST" action="' . $checkout_url . '"' . $extra_params . '>';
485
        $html .= wp_nonce_field( 'process_ticket_selections', 'process_ticket_selections_nonce_' . $ID, true, false );
486
        $html .= '<input type="hidden" name="ee" value="process_ticket_selections">';
487
        $html = apply_filters( 'FHEE__EE_Ticket_Selector__ticket_selector_form_open__html', $html, $this->event );
488
        return $html;
489
    }
490
491
492
493
    /**
494
     * displaySubmitButton
495
     *
496
     * @param  string $external_url
497
     * @return string
498
     * @throws \EE_Error
499
     */
500
    public function displaySubmitButton($external_url = '')
501
    {
502
        $html = '';
503
        if ( ! is_admin()) {
504
            // standard TS displayed with submit button, ie: "Register Now"
505
            if (apply_filters('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', false)) {
506
                $html .= $this->displayRegisterNowButton();
507
                $html .= empty($external_url)
508
                    ? $this->ticketSelectorEndDiv()
509
                    : $this->clearTicketSelector();
510
                $html .= '<br/>' . $this->formClose();
511
            } else if ($this->getMaxAttendees() === 1) {
512
                // its a "Dude Where's my Ticket Selector?" (DWMTS) type event (ie: $_max_atndz === 1)
513
                if ($this->event->is_sold_out()) {
514
                    // then instead of a View Details or Submit button, just display a "Sold Out" message
515
                    $html .= apply_filters(
516
                        'FHEE__EE_Ticket_Selector__display_ticket_selector_submit__sold_out_msg',
517
                        sprintf(
518
                            __(
519
                                '%1$s"%2$s" is currently sold out.%4$sPlease check back again later, as spots may become available.%3$s',
520
                                'event_espresso'
521
                            ),
522
                            '<p class="no-ticket-selector-msg clear-float">',
523
                            $this->event->name(),
524
                            '</p>',
525
                            '<br />'
526
                        ),
527
                        $this->event
528
                    );
529
                    if (
530
                    apply_filters(
531
                        'FHEE__EE_Ticket_Selector__display_ticket_selector_submit__no_tickets_but_display_register_now_button',
532
                        false,
533
                        $this->event
534
                    )
535
                    ) {
536
                        $html .= $this->displayRegisterNowButton();
537
                    }
538
                    // sold out DWMTS event, no TS, no submit or view details button, but has additional content
539
                    $html .= $this->ticketSelectorEndDiv();
540
                } else if (
541
                    apply_filters('FHEE__EE_Ticket_Selector__hide_ticket_selector', false)
542
                    && ! is_single()
543
                ) {
544
                    // this is a "Dude Where's my Ticket Selector?" (DWMTS) type event,
545
                    // but no tickets are available, so display event's "View Details" button.
546
                    // it is being viewed via somewhere other than a single post
547
                    $html .= $this->displayViewDetailsButton(true);
548
                }
549
            } else if (is_archive()) {
550
                // event list, no tickets available so display event's "View Details" button
551
                $html .= $this->ticketSelectorEndDiv();
552
                $html .= $this->displayViewDetailsButton();
553
            } else {
554
                if (
555
                apply_filters(
556
                    'FHEE__EE_Ticket_Selector__display_ticket_selector_submit__no_tickets_but_display_register_now_button',
557
                    false,
558
                    $this->event
559
                )
560
                ) {
561
                    $html .= $this->displayRegisterNowButton();
562
                }
563
                // no submit or view details button, and no additional content
564
                $html .= $this->ticketSelectorEndDiv();
565
            }
566
            if ( ! $this->iframe && ! is_archive()) {
567
                $html .= \EEH_Template::powered_by_event_espresso('', '', array('utm_content' => 'ticket_selector'));
568
            }
569
        }
570
        return $html;
571
    }
572
573
574
575
    /**
576
     * @return string
577
     * @throws \EE_Error
578
     */
579
    public function displayRegisterNowButton()
580
    {
581
        $btn_text = apply_filters(
582
            'FHEE__EE_Ticket_Selector__display_ticket_selector_submit__btn_text',
583
            __('Register Now', 'event_espresso'),
584
            $this->event
585
        );
586
        $external_url = $this->event->external_url();
587
        $html = \EEH_HTML::div(
588
            '', 'ticket-selector-submit-' . $this->event->ID() . '-btn-wrap', 'ticket-selector-submit-btn-wrap'
589
        );
590
        $html .= '<input id="ticket-selector-submit-' . $this->event->ID() . '-btn"';
591
        $html .= ' class="ticket-selector-submit-btn ';
592
        $html .= empty($external_url) ? 'ticket-selector-submit-ajax"' : '"';
593
        $html .= ' type="submit" value="' . $btn_text . '" />';
594
        $html .= \EEH_HTML::divx();
595
        $html .= apply_filters(
596
            'FHEE__EE_Ticket_Selector__after_ticket_selector_submit',
597
            '',
598
            $this->event
599
        );
600
        return $html;
601
    }
602
603
604
    /**
605
     * displayViewDetailsButton
606
     *
607
     * @param bool $DWMTS indicates a "Dude Where's my Ticket Selector?" (DWMTS) type event
608
     *                    (ie: $_max_atndz === 1) where there are no available tickets,
609
     *                    either because they are sold out, expired, or not yet on sale.
610
     *                    In this case, we need to close the form BEFORE adding any closing divs
611
     * @return string
612
     * @throws \EE_Error
613
     */
614
    public function displayViewDetailsButton( $DWMTS = false )
615
    {
616
        if ( ! $this->event->get_permalink() ) {
617
            \EE_Error::add_error(
618
                esc_html__( 'The URL for the Event Details page could not be retrieved.', 'event_espresso' ),
619
                __FILE__, __FUNCTION__, __LINE__
620
            );
621
        }
622
        $view_details_btn = '<form method="POST" action="';
623
        $view_details_btn .= apply_filters(
624
            'FHEE__EE_Ticket_Selector__display_view_details_btn__btn_url',
625
            $this->event->get_permalink(),
626
            $this->event
627
        );
628
        $view_details_btn .= '">';
629
        $btn_text = apply_filters(
630
            'FHEE__EE_Ticket_Selector__display_view_details_btn__btn_text',
631
            esc_html__('View Details', 'event_espresso'),
632
            $this->event
633
        );
634
        $view_details_btn .= '<input id="ticket-selector-submit-'
635
                             . $this->event->ID()
636
                             . '-btn" class="ticket-selector-submit-btn view-details-btn" type="submit" value="'
637
                             . $btn_text
638
                             . '" />';
639
        $view_details_btn .= apply_filters( 'FHEE__EE_Ticket_Selector__after_view_details_btn', '', $this->event );
640
        if ($DWMTS) {
641
            $view_details_btn .= $this->formClose();
642
            $view_details_btn .= $this->ticketSelectorEndDiv();
643
            $view_details_btn .= '<br/>';
644
        } else {
645
            $view_details_btn .= $this->clearTicketSelector();
646
            $view_details_btn .= '<br/>';
647
            $view_details_btn .= $this->formClose();
648
        }
649
        return $view_details_btn;
650
    }
651
652
653
654
    /**
655
     * @return string
656
     */
657
    public function ticketSelectorEndDiv()
658
    {
659
        return '<div class="clear"></div></div>';
660
    }
661
662
663
664
    /**
665
     * @return string
666
     */
667
    public function clearTicketSelector()
668
    {
669
        // standard TS displayed, appears after a "Register Now" or "view Details" button
670
        return '<div class="clear"></div>';
671
    }
672
673
674
675
    /**
676
     * @access        public
677
     * @return        string
678
     */
679
    public function formClose()
680
    {
681
        return '</form>';
682
    }
683
684
685
686
}
687
// End of file DisplayTicketSelector.php
688
// Location: /DisplayTicketSelector.php