Completed
Branch BUG-10381-asset-loading (189bf4)
by
unknown
13:54
created

TicketSelectorStandard::addTemplateArgs()   B

Complexity

Conditions 6
Paths 8

Size

Total Lines 54
Code Lines 44

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 6
eloc 44
nc 8
nop 0
dl 0
loc 54
rs 8.7449
c 0
b 0
f 0

How to fix   Long Method   

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
defined('ABSPATH') || exit;
5
6
7
8
/**
9
 * Class TicketSelectorStandard
10
 * regular ticket selector that displays one row for each ticket
11
 * with a dropdown for selecting the desired ticket quantity
12
 *
13
 * @package       Event Espresso
14
 * @author        Brent Christensen
15
 * @since         4.9.18
16
 */
17
class TicketSelectorStandard extends TicketSelector
18
{
19
20
    /**
21
     * @var string $date_format
22
     */
23
    protected $date_format;
24
25
    /**
26
     * @var string $time_format
27
     */
28
    protected $time_format;
29
30
    /**
31
     * @var \EE_Ticket_Selector_Config $ticket_selector_config
32
     */
33
    protected $ticket_selector_config;
34
35
    /**
36
     * @var \EE_Tax_Config $tax_config
37
     */
38
    protected $tax_config;
39
40
41
42
    /**
43
     * TicketSelectorSimple constructor.
44
     *
45
     * @param \EE_Event                  $event
46
     * @param \EE_Ticket[]               $tickets
47
     * @param int                        $max_attendees
48
     * @param array                      $template_args
49
     * @param string                     $date_format
50
     * @param string                     $time_format
51
     * @param \EE_Ticket_Selector_Config $ticket_selector_config
52
     * @param \EE_Tax_Config             $tax_config
53
     */
54
    public function __construct(
55
        \EE_Event $event,
56
        array $tickets,
57
        $max_attendees,
58
        array $template_args,
59
        $date_format = 'Y-m-d',
60
        $time_format = 'g:i a',
61
        \EE_Ticket_Selector_Config $ticket_selector_config = null,
0 ignored issues
show
Unused Code introduced by
The parameter $ticket_selector_config is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
62
        \EE_Tax_Config $tax_config = null
0 ignored issues
show
Unused Code introduced by
The parameter $tax_config is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
63
    ) {
64
        $this->date_format = $date_format;
65
        $this->time_format = $time_format;
66
        // get EE_Ticket_Selector_Config and TicketDetails
67
        $this->ticket_selector_config = isset (\EE_Registry::instance()->CFG->template_settings->EED_Ticket_Selector)
68
            ? \EE_Registry::instance()->CFG->template_settings->EED_Ticket_Selector
69
            : new \EE_Ticket_Selector_Config();
70
        // $template_settings->setDatetimeSelectorThreshold(2);
71
        // \EEH_Debug_Tools::printr($template_settings->getShowDatetimeSelector(), 'getShowDatetimeSelector', __FILE__, __LINE__);
72
        // \EEH_Debug_Tools::printr($template_settings->getDatetimeSelectorThreshold(), 'getDatetimeSelectorThreshold', __FILE__, __LINE__);
73
        $this->tax_config = isset (\EE_Registry::instance()->CFG->tax_settings)
74
            ? \EE_Registry::instance()->CFG->tax_settings
75
            : new \EE_Tax_Config();
76
        parent::__construct($event, $tickets, $max_attendees, $template_args);
77
    }
78
79
80
81
    /**
82
     * sets any and all template args that are required for this Ticket Selector
83
     *
84
     * @return void
85
     * @throws \EE_Error
86
     */
87
    protected function addTemplateArgs()
88
    {
89
        $row = 1;
90
        $ticket_row_html = '';
91
        $required_ticket_sold_out = false;
92
        // flag to indicate that at least one taxable ticket has been encountered
93
        $taxable_tickets = false;
94
        $datetime_selector = null;
95
        $this->template_args['datetime_selector'] = '';
96
        if (
97
            $this->ticket_selector_config->getShowDatetimeSelector()
98
            !== \EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR
99
        ) {
100
            $datetime_selector = new DatetimeSelector(
101
                $this->event,
102
                $this->tickets,
103
                $this->ticket_selector_config,
104
                $this->date_format,
105
                $this->time_format
106
            );
107
            $this->template_args['datetime_selector'] = $datetime_selector->getDatetimeSelector();
108
        }
109
        // loop through tickets
110
        foreach ($this->tickets as $TKT_ID => $ticket) {
111
            if ($ticket instanceof \EE_Ticket) {
112
                $cols = 2;
113
                $taxable_tickets = $ticket->taxable() ? true : $taxable_tickets;
114
                $ticket_selector_row = new TicketSelectorRowStandard(
115
                    $ticket,
116
                    new TicketDetails($ticket, $this->ticket_selector_config, $this->template_args),
117
                    $this->ticket_selector_config,
118
                    $this->tax_config,
119
                    $this->max_attendees,
120
                    $row,
121
                    $cols,
122
                    $required_ticket_sold_out,
123
                    $this->template_args['event_status'],
124
                    $this->template_args['date_format'],
125
                    $datetime_selector instanceof DatetimeSelector
126
                        ? $datetime_selector->getTicketDatetimeClasses($ticket)
127
                        : ''
128
                );
129
                $ticket_row_html .= $ticket_selector_row->getHtml();
130
                $required_ticket_sold_out = $ticket_selector_row->getRequiredTicketSoldOut();
131
                $row++;
132
            }
133
        }
134
        $this->template_args['row'] = $row;
135
        $this->template_args['ticket_row_html'] = $ticket_row_html;
136
        $this->template_args['taxable_tickets'] = $taxable_tickets;
137
        $this->template_args['prices_displayed_including_taxes'] = $this->tax_config->prices_displayed_including_taxes;
138
        $this->template_args['template_path'] = TICKET_SELECTOR_TEMPLATES_PATH . 'standard_ticket_selector.template.php';
139
        remove_all_filters('FHEE__EE_Ticket_Selector__hide_ticket_selector');
140
    }
141
142
143
144
}
145
// End of file TicketSelectorStandard.php
146
// Location: EventEspresso\modules\ticket_selector/TicketSelectorStandard.php