Completed
Branch BUG-10050-ticket-price-details (f8afc3)
by
unknown
130:17 queued 118:38
created

TicketDetails   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 158
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
dl 0
loc 158
rs 10
c 0
b 0
f 0
wmc 7
lcom 1
cbo 4

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 12 1
A showTicketDetails() 0 4 1
B getShowHideLinks() 0 33 2
A cssId() 0 7 1
B display() 0 35 2
1
<?php
2
namespace EventEspresso\modules\ticket_selector;
3
4
defined('ABSPATH') || exit;
5
6
7
8
/**
9
 * Class TicketDetails
10
 * class for loading template and resolving template args for the ticket details template
11
 *
12
 * @package       Event Espresso
13
 * @author        Brent Christensen
14
 * @since         $VID:$
15
 */
16
class TicketDetails
17
{
18
19
20
    /**
21
     * @var \EE_Ticket $ticket
22
     */
23
    protected $ticket;
24
25
    /**
26
     * @var \EE_Ticket_Selector_Config $template_settings
27
     */
28
    protected $template_settings;
29
30
    /**
31
     * @var string $date_format
32
     */
33
    protected $date_format;
34
35
    /**
36
     * @var string $time_format
37
     */
38
    protected $time_format;
39
40
    /**
41
     * @var boolean $event_is_expired
42
     */
43
    protected $event_is_expired;
44
45
46
47
    /**
48
     * TicketDetails constructor.
49
     *
50
     * @param \EE_Ticket                 $ticket
51
     * @param \EE_Ticket_Selector_Config $template_settings
52
     * @param array                      $template_args
53
     */
54
    public function __construct(
55
        \EE_Ticket $ticket,
56
        \EE_Ticket_Selector_Config $template_settings,
57
        array $template_args
58
    )
59
    {
60
        $this->ticket            = $ticket;
61
        $this->template_settings = $template_settings;
62
        $this->date_format       = $template_args['date_format'];
63
        $this->time_format       = $template_args['time_format'];
64
        $this->event_is_expired  = $template_args['event_is_expired'];
65
    }
66
67
68
69
    /**
70
     * @return bool
71
     */
72
    public function showTicketDetails()
73
    {
74
        return $this->template_settings->show_ticket_details;
75
    }
76
77
78
79
    /**
80
     * @return string
81
     */
82
    public function getShowHideLinks()
83
    {
84
        if ( ! $this->showTicketDetails()) {
85
            return '';
86
        }
87
        return \EEH_HTML::link(
88
            '',
89
            sprintf(__('show%1$sdetails%1$s+', 'event_espresso'), '&nbsp;'),
90
            esc_attr(
91
                apply_filters(
92
                    'FHEE__ticket_selector_chart_template__show_ticket_details_link_title',
93
                    __('click to show additional ticket details', 'event_espresso')
94
                )
95
            ),
96
            "display-{$this->cssId()}",
97
            'display-tckt-slctr-tkt-details display-the-hidden lt-grey-text smaller-text hide-if-no-js',
98
            '',
99
            'rel="' . $this->cssId() . '"'
100
        ) . \EEH_HTML::link(
101
            '',
102
            sprintf(__('hide%1$sdetails%1$s-', 'event_espresso'), '&nbsp;'),
103
            esc_attr(
104
                apply_filters(
105
                    'FHEE__ticket_selector_chart_template__hide_ticket_details_link_title',
106
                    __('click to hide additional ticket details', 'event_espresso')
107
                )
108
            ),
109
            "hide-{$this->cssId()}",
110
            'hide-tckt-slctr-tkt-details hide-the-displayed lt-grey-text smaller-text hide-if-no-js',
111
            'display:none;',
112
            'rel="' . $this->cssId() . '"'
113
        );
114
    }
115
116
117
118
    /**
119
     * @return string
120
     */
121
    public function cssId()
122
    {
123
        return apply_filters(
124
            'FHEE__ticket_selector_chart_template__ticket_details_css_id',
125
            "tckt-slctr-tkt-details-{$this->ticket->get_event_ID()}-{$this->ticket->ID()}"
126
        );
127
    }
128
129
130
131
    /**
132
     * @param float $ticket_price
133
     * @param int   $remaining
134
     * @param int   $cols
135
     * @return string
136
     */
137
    public function display(
138
        $ticket_price = 0.00,
139
        $remaining,
140
        $cols = 2
141
    ) {
142
        $template_args = array();
143
        $template_args['ticket'] = $this->ticket;
144
        $template_args['ticket_price'] = $ticket_price;
145
        $template_args['remaining'] = $remaining;
146
        $template_args['cols'] = $cols;
147
        $template_args['show_ticket_details'] = $this->template_settings->show_ticket_details;
148
        $template_args['show_ticket_sale_columns'] = $this->template_settings->show_ticket_sale_columns;
149
        $template_args['ticket_details_row_class'] = espresso_get_object_css_class($this->ticket, '', 'details');
150
        $template_args['ticket_details_css_id'] = $this->cssId();
151
        $template_args['display_ticket_price'] = $ticket_price !== 0 && apply_filters(
152
            'FHEE__ticket_selector_chart_template__display_ticket_price_details',
153
            true
154
        );
155
        $template_args['price_breakdown_heading'] = apply_filters(
156
            'FHEE__ticket_selector_chart_template__ticket_details_price_breakdown_heading',
157
            esc_html__('Price', 'event_espresso')
158
        );
159
        $template_args['date_format'] = $this->date_format;
160
        $template_args['time_format'] = $this->time_format;
161
        $template_args['event_is_expired'] = $this->event_is_expired;
162
163
        return \EEH_Template::locate_template(
164
            apply_filters(
165
                'FHEE__EventEspresso_modules_ticket_selector_TicketDetails__display__template_path',
166
                TICKET_SELECTOR_TEMPLATES_PATH . 'ticket_details.template.php',
167
                $this->ticket
168
            ),
169
            $template_args
170
        );
171
    }
172
173
}
174
// End of file TicketDetails.php
175
// Location: EventEspresso\modules\ticket_selector/TicketDetails.php