1
|
|
|
<?php |
2
|
|
|
namespace EventEspresso\modules\ticket_selector; |
3
|
|
|
|
4
|
|
|
defined('ABSPATH') || exit; |
5
|
|
|
|
6
|
|
|
|
7
|
|
|
|
8
|
|
|
/** |
9
|
|
|
* Class DatetimeSelector |
10
|
|
|
* Description |
11
|
|
|
* |
12
|
|
|
* @package Event Espresso |
13
|
|
|
* @author Brent Christensen |
14
|
|
|
* @since $VID:$ |
15
|
|
|
*/ |
16
|
|
|
class DatetimeSelector |
17
|
|
|
{ |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* @var \EE_Event $event |
21
|
|
|
*/ |
22
|
|
|
protected $event; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @var \EE_Ticket[] $tickets |
26
|
|
|
*/ |
27
|
|
|
protected $tickets; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @var \EE_Datetime[] $datetimes |
31
|
|
|
*/ |
32
|
|
|
protected $datetimes; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @var \EE_Ticket_Selector_Config $template_settings |
36
|
|
|
*/ |
37
|
|
|
protected $template_settings; |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @var boolean $active |
41
|
|
|
*/ |
42
|
|
|
protected $active = false; |
43
|
|
|
|
44
|
|
|
|
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* DatetimeSelector constructor. |
48
|
|
|
* |
49
|
|
|
* @param \EE_Event $event |
50
|
|
|
* @param \EE_Ticket[] $tickets |
51
|
|
|
* @param \EE_Ticket_Selector_Config $template_settings |
52
|
|
|
* @throws \EE_Error |
53
|
|
|
*/ |
54
|
|
|
public function __construct(\EE_Event $event, array $tickets, \EE_Ticket_Selector_Config $template_settings) |
55
|
|
|
{ |
56
|
|
|
$this->event = $event; |
57
|
|
|
$this->tickets = $tickets; |
58
|
|
|
$this->template_settings = $template_settings; |
59
|
|
|
$this->datetimes = $this->getAllDatetimesForAllTicket($tickets); |
60
|
|
|
$this->active = $this->template_settings->showDatetimeSelector($this->datetimes); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
|
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* @param \EE_Ticket[] $tickets |
67
|
|
|
* @return array |
68
|
|
|
* @throws \EE_Error |
69
|
|
|
*/ |
70
|
|
|
protected function getAllDatetimesForAllTicket($tickets = array()) |
71
|
|
|
{ |
72
|
|
|
$datetimes = array(); |
73
|
|
|
foreach ($tickets as $ticket) { |
74
|
|
|
$datetimes = $this->getTicketDatetimes($ticket, $datetimes); |
75
|
|
|
} |
76
|
|
|
return $datetimes; |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
|
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* @param \EE_Ticket $ticket |
83
|
|
|
* @param \EE_Datetime[] $datetimes |
84
|
|
|
* @return \EE_Datetime[] |
85
|
|
|
* @throws \EE_Error |
86
|
|
|
*/ |
87
|
|
|
protected function getTicketDatetimes(\EE_Ticket $ticket, $datetimes = array()) |
88
|
|
|
{ |
89
|
|
|
$ticket_datetimes = $ticket->datetimes(); |
90
|
|
|
foreach ($ticket_datetimes as $ticket_datetime) { |
91
|
|
|
if ( ! $ticket_datetime instanceof \EE_Datetime) { |
92
|
|
|
continue; |
93
|
|
|
} |
94
|
|
|
$datetimes[ $ticket_datetime->ID() ] = $ticket_datetime; |
95
|
|
|
} |
96
|
|
|
return $datetimes; |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
|
100
|
|
|
|
101
|
|
|
/** |
102
|
|
|
* @param \EE_Ticket $ticket |
103
|
|
|
* @return string |
104
|
|
|
* @throws \EE_Error |
105
|
|
|
*/ |
106
|
|
|
public function getTicketDatetimeClasses( \EE_Ticket $ticket ) { |
107
|
|
|
if ( ! $this->active) { |
108
|
|
|
return ''; |
109
|
|
|
} |
110
|
|
|
$ticket_datetimes = $this->getTicketDatetimes($ticket); |
111
|
|
|
$classes = ''; |
112
|
|
|
foreach ($this->datetimes as $datetime) { |
113
|
|
|
if ( ! $datetime instanceof \EE_Datetime || ! in_array($datetime, $ticket_datetimes)) { |
114
|
|
|
continue; |
115
|
|
|
} |
116
|
|
|
$classes .= ' ee-ticket-datetimes-' . $datetime->date_range('Y_m_d', '-'); |
117
|
|
|
} |
118
|
|
|
$classes .= ' ee-hidden-ticket-tr'; |
119
|
|
|
return $classes; |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
|
123
|
|
|
|
124
|
|
|
/** |
125
|
|
|
* @param string $date_format |
126
|
|
|
* @return string |
127
|
|
|
* @throws \EE_Error |
128
|
|
|
*/ |
129
|
|
|
public function getDatetimeSelector($date_format = 'Y-m-d') { |
130
|
|
|
if ( ! $this->active) { |
131
|
|
|
return ''; |
132
|
|
|
} |
133
|
|
|
$html = \EEH_HTML::div('', '', 'datetime_selector-dv'); |
134
|
|
|
$html .= \EEH_HTML::label( |
135
|
|
|
\EEH_HTML::span('', '', 'dashicons dashicons-calendar-alt') . esc_html__('Datetimes', 'event_espresso'), |
136
|
|
|
'', 'datetime_selector-lbl' |
137
|
|
|
); |
138
|
|
|
$html .= "\n" . '<select name="datetime_selector-' . $this->event->ID() . '"'; |
139
|
|
|
$html .= ' id="datetime-selector-' . $this->event->ID() . '"'; |
140
|
|
|
$html .= ' class="ticket-selector-datetime-selector-slct"'; |
141
|
|
|
$html .= ' data-tkt_slctr_evt="' . $this->event->ID() . '">'; |
142
|
|
|
$html .= "\n" |
143
|
|
|
. '<option value="0">' |
144
|
|
|
. esc_html__('- please select a datetime -', 'event_espresso') |
145
|
|
|
. '</option>'; |
146
|
|
|
// offer ticket quantities from the min to the max |
147
|
|
|
foreach ($this->datetimes as $datetime) { |
148
|
|
|
if ( ! $datetime instanceof \EE_Datetime) { |
149
|
|
|
continue; |
150
|
|
|
} |
151
|
|
|
$html .= "\n" . '<option value="' . $datetime->date_range('Y_m_d', '-') . '">'; |
152
|
|
|
$html .= $datetime->date_range($date_format); |
153
|
|
|
$html .= '</option>'; |
154
|
|
|
} |
155
|
|
|
$html .= "\n</select>"; |
156
|
|
|
$html .= \EEH_HTML::br(2); |
157
|
|
|
$html .= \EEH_HTML::divx(); |
158
|
|
|
return $html; |
159
|
|
|
} |
160
|
|
|
|
161
|
|
|
|
162
|
|
|
|
163
|
|
|
} |
164
|
|
|
// End of file DatetimeSelector.php |
165
|
|
|
// Location: EventEspresso\modules\ticket_selector/DatetimeSelector.php |