Completed
Branch BUG-10381-asset-loading (189bf4)
by
unknown
13:54
created
modules/ticket_selector/DisplayTicketSelector.php 2 patches
Indentation   +659 added lines, -659 removed lines patch added patch discarded remove patch
@@ -2,7 +2,7 @@  discard block
 block discarded – undo
2 2
 namespace EventEspresso\modules\ticket_selector;
3 3
 
4 4
 if ( ! defined( 'EVENT_ESPRESSO_VERSION' ) ) {
5
-    exit( 'No direct script access allowed' );
5
+	exit( 'No direct script access allowed' );
6 6
 }
7 7
 
8 8
 
@@ -19,667 +19,667 @@  discard block
 block discarded – undo
19 19
 class DisplayTicketSelector
20 20
 {
21 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 ) {
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;
103
-            }
104
-        } 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) ) {
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());
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);
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
-    protected function noTicketAvailableMessage()
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 '
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 ) {
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;
103
+			}
104
+		} 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) ) {
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());
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);
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
+	protected function noTicketAvailableMessage()
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 268
             <div class="ee-event-expired-notice">
269 269
                 <span class="important-notice">' . $no_ticket_available_msg . '</span>
270 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
-    protected function ticketSalesClosedMessage()
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
-    }
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
+	protected function ticketSalesClosedMessage()
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 683
 
684 684
 
685 685
 
Please login to merge, or discard this patch.
Spacing   +50 added lines, -50 removed lines patch added patch discarded remove patch
@@ -1,8 +1,8 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 namespace EventEspresso\modules\ticket_selector;
3 3
 
4
-if ( ! defined( 'EVENT_ESPRESSO_VERSION' ) ) {
5
-    exit( 'No direct script access allowed' );
4
+if ( ! defined('EVENT_ESPRESSO_VERSION')) {
5
+    exit('No direct script access allowed');
6 6
 }
7 7
 
8 8
 
@@ -73,9 +73,9 @@  discard block
 block discarded – undo
73 73
     /**
74 74
      * @param boolean $iframe
75 75
      */
76
-    public function setIframe( $iframe = true )
76
+    public function setIframe($iframe = true)
77 77
     {
78
-        $this->iframe = filter_var( $iframe, FILTER_VALIDATE_BOOLEAN );
78
+        $this->iframe = filter_var($iframe, FILTER_VALIDATE_BOOLEAN);
79 79
     }
80 80
 
81 81
 
@@ -86,28 +86,28 @@  discard block
 block discarded – undo
86 86
      * @param    mixed $event
87 87
      * @return    bool
88 88
      */
89
-    protected function setEvent( $event = null )
89
+    protected function setEvent($event = null)
90 90
     {
91
-        if ( $event === null ) {
91
+        if ($event === null) {
92 92
             global $post;
93 93
             $event = $post;
94 94
         }
95
-        if ( $event instanceof \EE_Event ) {
95
+        if ($event instanceof \EE_Event) {
96 96
             $this->event = $event;
97
-        } else if ( $event instanceof \WP_Post ) {
98
-            if ( isset( $event->EE_Event ) && $event->EE_Event instanceof \EE_Event ) {
97
+        } else if ($event instanceof \WP_Post) {
98
+            if (isset($event->EE_Event) && $event->EE_Event instanceof \EE_Event) {
99 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 );
100
+            } else if ($event->post_type === 'espresso_events') {
101
+                $event->EE_Event = \EEM_Event::instance()->instantiate_class_from_post_object($event);
102 102
                 $this->event = $event->EE_Event;
103 103
             }
104 104
         } else {
105
-            $user_msg = __( 'No Event object or an invalid Event object was supplied.', 'event_espresso' );
106
-            $dev_msg = $user_msg . __(
105
+            $user_msg = __('No Event object or an invalid Event object was supplied.', 'event_espresso');
106
+            $dev_msg = $user_msg.__(
107 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 108
                     'event_espresso'
109 109
                 );
110
-            \EE_Error::add_error( $user_msg . '||' . $dev_msg, __FILE__, __FUNCTION__, __LINE__ );
110
+            \EE_Error::add_error($user_msg.'||'.$dev_msg, __FILE__, __FUNCTION__, __LINE__);
111 111
             return false;
112 112
         }
113 113
         return true;
@@ -148,17 +148,17 @@  discard block
 block discarded – undo
148 148
      * @return string
149 149
      * @throws \EE_Error
150 150
      */
151
-    public function display( $event = null, $view_details = false )
151
+    public function display($event = null, $view_details = false)
152 152
     {
153 153
         // reset filter for displaying submit button
154
-        remove_filter( 'FHEE__EE_Ticket_Selector__display_ticket_selector_submit', '__return_true' );
154
+        remove_filter('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', '__return_true');
155 155
         // poke and prod incoming event till it tells us what it is
156
-        if ( ! $this->setEvent( $event ) ) {
156
+        if ( ! $this->setEvent($event)) {
157 157
             return false;
158 158
         }
159 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) ) {
160
+        $template_args = array('event_status' => $this->event->get_active_status());
161
+        if ($this->activeEventAndShowTicketSelector($event, $template_args['event_status'], $view_details)) {
162 162
             return ! is_single() ? $this->displayViewDetailsButton() : '';
163 163
         }
164 164
         // filter the maximum qty that can appear in the Ticket Selector qty dropdowns
@@ -168,7 +168,7 @@  discard block
 block discarded – undo
168 168
         }
169 169
         // is the event expired ?
170 170
         $template_args['event_is_expired'] = $this->event->is_expired();
171
-        if ( $template_args[ 'event_is_expired' ] ) {
171
+        if ($template_args['event_is_expired']) {
172 172
             return $this->expiredEventMessage();
173 173
         }
174 174
         // get all tickets for this event ordered by the datetime
@@ -181,10 +181,10 @@  discard block
 block discarded – undo
181 181
         // if redirecting to another site for registration, then we don't load the TS
182 182
         $ticket_selector = $external_url
183 183
             ? $this->externalEventRegistration()
184
-            : $this->loadTicketSelector($tickets,$template_args);
184
+            : $this->loadTicketSelector($tickets, $template_args);
185 185
         // now set up the form (but not for the admin)
186 186
         $ticket_selector = ! is_admin()
187
-            ? $this->formOpen($this->event->ID(), $external_url) . $ticket_selector
187
+            ? $this->formOpen($this->event->ID(), $external_url).$ticket_selector
188 188
             : $ticket_selector;
189 189
         // submit button and form close tag
190 190
         $ticket_selector .= ! is_admin() ? $this->displaySubmitButton($external_url) : '';
@@ -234,10 +234,10 @@  discard block
 block discarded – undo
234 234
      */
235 235
     protected function expiredEventMessage()
236 236
     {
237
-        return '<div class="ee-event-expired-notice"><span class="important-notice">' . esc_html__(
237
+        return '<div class="ee-event-expired-notice"><span class="important-notice">'.esc_html__(
238 238
             'We\'re sorry, but all tickets sales have ended because the event is expired.',
239 239
             'event_espresso'
240
-        ) . '</span></div>';
240
+        ).'</span></div>';
241 241
     }
242 242
 
243 243
 
@@ -251,7 +251,7 @@  discard block
 block discarded – undo
251 251
      */
252 252
     protected function noTicketAvailableMessage()
253 253
     {
254
-        $no_ticket_available_msg = esc_html__( 'We\'re sorry, but all ticket sales have ended.', 'event_espresso' );
254
+        $no_ticket_available_msg = esc_html__('We\'re sorry, but all ticket sales have ended.', 'event_espresso');
255 255
         if (current_user_can('edit_post', $this->event->ID())) {
256 256
             $no_ticket_available_msg .= sprintf(
257 257
                 esc_html__(
@@ -266,7 +266,7 @@  discard block
 block discarded – undo
266 266
         }
267 267
         return '
268 268
             <div class="ee-event-expired-notice">
269
-                <span class="important-notice">' . $no_ticket_available_msg . '</span>
269
+                <span class="important-notice">' . $no_ticket_available_msg.'</span>
270 270
             </div>';
271 271
     }
272 272
 
@@ -297,7 +297,7 @@  discard block
 block discarded – undo
297 297
                 '</a></span></div>'
298 298
             );
299 299
         }
300
-        return '<p><span class="important-notice">' . $sales_closed_msg . '</span></p>';
300
+        return '<p><span class="important-notice">'.$sales_closed_msg.'</span></p>';
301 301
     }
302 302
 
303 303
 
@@ -359,12 +359,12 @@  discard block
 block discarded – undo
359 359
          */
360 360
         $template_args['anchor_id'] = apply_filters(
361 361
             'FHEE__EE_Ticket_Selector__redirect_anchor_id',
362
-            '#tkt-slctr-tbl-' . $this->event->ID(),
362
+            '#tkt-slctr-tbl-'.$this->event->ID(),
363 363
             $this->event->ID()
364 364
         );
365 365
         $template_args['tickets'] = $tickets;
366 366
         $template_args['ticket_count'] = count($tickets);
367
-        $ticket_selector = $this->simpleTicketSelector( $tickets, $template_args);
367
+        $ticket_selector = $this->simpleTicketSelector($tickets, $template_args);
368 368
         return $ticket_selector instanceof TicketSelectorSimple
369 369
             ? $ticket_selector
370 370
             : new TicketSelectorStandard(
@@ -445,11 +445,11 @@  discard block
 block discarded – undo
445 445
      * @param        string $external_url
446 446
      * @return        string
447 447
      */
448
-    public function formOpen( $ID = 0, $external_url = '' )
448
+    public function formOpen($ID = 0, $external_url = '')
449 449
     {
450 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) . '"';
451
+        if ($external_url) {
452
+            $html = '<form method="GET" action="'.\EEH_URL::refactor_url($external_url).'"';
453 453
             // open link in new window ?
454 454
             $html .= apply_filters(
455 455
                 'FHEE__EventEspresso_modules_ticket_selector_DisplayTicketSelector__formOpen__external_url_target_blank',
@@ -458,21 +458,21 @@  discard block
 block discarded – undo
458 458
                 ? ' target="_blank"'
459 459
                 : '';
460 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 . '">';
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 464
             }
465 465
             return $html;
466 466
         }
467 467
         // if there is no submit button, then don't start building a form
468 468
         // because the "View Details" button will build its own form
469
-        if ( ! apply_filters( 'FHEE__EE_Ticket_Selector__display_ticket_selector_submit', false ) ) {
469
+        if ( ! apply_filters('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', false)) {
470 470
             return '';
471 471
         }
472
-        $checkout_url = \EEH_Event_View::event_link_url( $ID );
473
-        if ( ! $checkout_url ) {
472
+        $checkout_url = \EEH_Event_View::event_link_url($ID);
473
+        if ( ! $checkout_url) {
474 474
             \EE_Error::add_error(
475
-                esc_html__( 'The URL for the Event Details page could not be retrieved.', 'event_espresso' ),
475
+                esc_html__('The URL for the Event Details page could not be retrieved.', 'event_espresso'),
476 476
                 __FILE__,
477 477
                 __FUNCTION__,
478 478
                 __LINE__
@@ -481,10 +481,10 @@  discard block
 block discarded – undo
481 481
         // set no cache headers and constants
482 482
         \EE_System::do_not_cache();
483 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 );
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 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 );
487
+        $html = apply_filters('FHEE__EE_Ticket_Selector__ticket_selector_form_open__html', $html, $this->event);
488 488
         return $html;
489 489
     }
490 490
 
@@ -507,7 +507,7 @@  discard block
 block discarded – undo
507 507
                 $html .= empty($external_url)
508 508
                     ? $this->ticketSelectorEndDiv()
509 509
                     : $this->clearTicketSelector();
510
-                $html .= '<br/>' . $this->formClose();
510
+                $html .= '<br/>'.$this->formClose();
511 511
             } else if ($this->getMaxAttendees() === 1) {
512 512
                 // its a "Dude Where's my Ticket Selector?" (DWMTS) type event (ie: $_max_atndz === 1)
513 513
                 if ($this->event->is_sold_out()) {
@@ -585,12 +585,12 @@  discard block
 block discarded – undo
585 585
         );
586 586
         $external_url = $this->event->external_url();
587 587
         $html = \EEH_HTML::div(
588
-            '', 'ticket-selector-submit-' . $this->event->ID() . '-btn-wrap', 'ticket-selector-submit-btn-wrap'
588
+            '', 'ticket-selector-submit-'.$this->event->ID().'-btn-wrap', 'ticket-selector-submit-btn-wrap'
589 589
         );
590
-        $html .= '<input id="ticket-selector-submit-' . $this->event->ID() . '-btn"';
590
+        $html .= '<input id="ticket-selector-submit-'.$this->event->ID().'-btn"';
591 591
         $html .= ' class="ticket-selector-submit-btn ';
592 592
         $html .= empty($external_url) ? 'ticket-selector-submit-ajax"' : '"';
593
-        $html .= ' type="submit" value="' . $btn_text . '" />';
593
+        $html .= ' type="submit" value="'.$btn_text.'" />';
594 594
         $html .= \EEH_HTML::divx();
595 595
         $html .= apply_filters(
596 596
             'FHEE__EE_Ticket_Selector__after_ticket_selector_submit',
@@ -611,11 +611,11 @@  discard block
 block discarded – undo
611 611
      * @return string
612 612
      * @throws \EE_Error
613 613
      */
614
-    public function displayViewDetailsButton( $DWMTS = false )
614
+    public function displayViewDetailsButton($DWMTS = false)
615 615
     {
616
-        if ( ! $this->event->get_permalink() ) {
616
+        if ( ! $this->event->get_permalink()) {
617 617
             \EE_Error::add_error(
618
-                esc_html__( 'The URL for the Event Details page could not be retrieved.', 'event_espresso' ),
618
+                esc_html__('The URL for the Event Details page could not be retrieved.', 'event_espresso'),
619 619
                 __FILE__, __FUNCTION__, __LINE__
620 620
             );
621 621
         }
@@ -636,7 +636,7 @@  discard block
 block discarded – undo
636 636
                              . '-btn" class="ticket-selector-submit-btn view-details-btn" type="submit" value="'
637 637
                              . $btn_text
638 638
                              . '" />';
639
-        $view_details_btn .= apply_filters( 'FHEE__EE_Ticket_Selector__after_view_details_btn', '', $this->event );
639
+        $view_details_btn .= apply_filters('FHEE__EE_Ticket_Selector__after_view_details_btn', '', $this->event);
640 640
         if ($DWMTS) {
641 641
             $view_details_btn .= $this->formClose();
642 642
             $view_details_btn .= $this->ticketSelectorEndDiv();
Please login to merge, or discard this patch.
core/services/database/TableManager.php 3 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -239,7 +239,7 @@
 block discarded – undo
239 239
 *@param string $table_name
240 240
      * @param string $index_name
241 241
      * @param string $column_name if none is provided, we assume the column name matches the index (often true in EE)
242
-     * @param string|int $desired_index_size defaults to 191, the max for utf8mb4.
242
+     * @param integer $desired_index_size defaults to 191, the max for utf8mb4.
243 243
      *                   See https://events.codebasehq.com/redirect?https://make.wordpress.org/core/2015/04/02/the-utf8mb4-upgrade/
244 244
      * @return bool
245 245
      * @throws /EE_Error if table analysis object isn't defined
Please login to merge, or discard this patch.
Indentation   +239 added lines, -241 removed lines patch added patch discarded remove patch
@@ -17,249 +17,247 @@
 block discarded – undo
17 17
 class TableManager extends \EE_Base
18 18
 {
19 19
 
20
-    /**
21
-     * @var TableAnalysis $table_analysis
22
-     */
23
-    private $table_analysis;
24
-
25
-
26
-
27
-    /**
28
-     * TableManager constructor.
29
-     *
30
-     * @param TableAnalysis $TableAnalysis
31
-     */
32
-    public function __construct(TableAnalysis $TableAnalysis)
33
-    {
34
-        $this->table_analysis = $TableAnalysis;
35
-    }
36
-
37
-
38
-
39
-    /**
40
-     * Gets the injected table analyzer, or throws an exception
41
-     *
42
-     * @return TableAnalysis
43
-     * @throws \EE_Error
44
-     */
45
-    protected function getTableAnalysis()
46
-    {
47
-        if ($this->table_analysis instanceof TableAnalysis) {
48
-            return $this->table_analysis;
49
-        } else {
50
-            throw new \EE_Error(
51
-                sprintf(
52
-                    __('Table analysis class on class %1$s is not set properly.', 'event_espresso'),
53
-                    get_class($this)
54
-                )
55
-            );
56
-        }
57
-    }
58
-
59
-
60
-
61
-    /**
62
-     * @param string $table_name which can optionally start with $wpdb->prefix or not
63
-     * @param string $column_name
64
-     * @param string $column_info
65
-     * @return bool|false|int
66
-     */
67
-    public function addColumn($table_name, $column_name, $column_info = 'INT UNSIGNED NOT NULL')
68
-    {
69
-        if (apply_filters('FHEE__EEH_Activation__add_column_if_it_doesnt_exist__short_circuit', false)) {
70
-            return false;
71
-        }
72
-        global $wpdb;
73
-        $full_table_name = $this->getTableAnalysis()->ensureTableNameHasPrefix($table_name);
74
-        $columns = $this->getTableColumns($table_name);
75
-        if ( ! in_array($column_name, $columns)) {
76
-            $alter_query = "ALTER TABLE {$full_table_name} ADD {$column_name} {$column_info}";
77
-            return $wpdb->query($alter_query);
78
-        }
79
-        return true;
80
-    }
81
-
82
-
83
-
84
-    /**
85
-     * Gets the name of all columns on the  table. $table_name can
86
-     * optionally start with $wpdb->prefix or not
87
-     *
88
-     * @global \wpdb $wpdb
89
-     * @param string $table_name
90
-     * @return array
91
-     */
92
-    public function getTableColumns($table_name)
93
-    {
94
-        global $wpdb;
95
-        $table_name = $this->getTableAnalysis()->ensureTableNameHasPrefix($table_name);
96
-        $field_array = array();
97
-        if ( ! empty($table_name)) {
98
-            $columns = $wpdb->get_results("SHOW COLUMNS FROM {$table_name} ");
99
-            if ($columns !== false) {
100
-                foreach ($columns as $column) {
101
-                    $field_array[] = $column->Field;
102
-                }
103
-            }
104
-        }
105
-        return $field_array;
106
-    }
107
-
108
-
109
-
110
-    /**
111
-     * Drops the specified table from the database. $table_name can
112
-     * optionally start with $wpdb->prefix or not
113
-     *
114
-     * @global \wpdb $wpdb
115
-     * @param string $table_name
116
-     * @return int
117
-     */
118
-    public function dropTable($table_name)
119
-    {
120
-        global $wpdb;
121
-        if ($this->getTableAnalysis()->tableExists($table_name)) {
122
-            $table_name = $this->getTableAnalysis()->ensureTableNameHasPrefix($table_name);
123
-            return $wpdb->query("DROP TABLE IF EXISTS {$table_name}");
124
-        }
125
-        return 0;
126
-    }
127
-
128
-
129
-
130
-    /**
131
-     * Drops all the tables mentioned in a single MYSQL query. Double-checks
132
-     * each table name provided has a wpdb prefix attached, and that it exists.
133
-     * Returns the list actually deleted
134
-     *
135
-     * @global WPDB $wpdb
136
-     * @param array $table_names
137
-     * @return array of table names which we deleted
138
-     */
139
-    public function dropTables($table_names)
140
-    {
141
-        $tables_to_delete = array();
142
-        foreach ($table_names as $table_name) {
143
-            $table_name = $this->getTableAnalysis()->ensureTableNameHasPrefix($table_name);
144
-            if ($this->getTableAnalysis()->tableExists($table_name)) {
145
-                $tables_to_delete[] = $table_name;
146
-            }
147
-        }
148
-        if( ! empty( $tables_to_delete ) ) {
149
-            global $wpdb;
150
-            $wpdb->query('DROP TABLE ' . implode(', ', $tables_to_delete));
151
-        }
152
-        return $tables_to_delete;
153
-    }
154
-
155
-
156
-
157
-    /**
158
-     * Drops the specified index from the specified table. $table_name can
159
-     * optionally start with $wpdb->prefix or not
160
-
161
-     *
20
+	/**
21
+	 * @var TableAnalysis $table_analysis
22
+	 */
23
+	private $table_analysis;
24
+
25
+
26
+
27
+	/**
28
+	 * TableManager constructor.
29
+	 *
30
+	 * @param TableAnalysis $TableAnalysis
31
+	 */
32
+	public function __construct(TableAnalysis $TableAnalysis)
33
+	{
34
+		$this->table_analysis = $TableAnalysis;
35
+	}
36
+
37
+
38
+
39
+	/**
40
+	 * Gets the injected table analyzer, or throws an exception
41
+	 *
42
+	 * @return TableAnalysis
43
+	 * @throws \EE_Error
44
+	 */
45
+	protected function getTableAnalysis()
46
+	{
47
+		if ($this->table_analysis instanceof TableAnalysis) {
48
+			return $this->table_analysis;
49
+		} else {
50
+			throw new \EE_Error(
51
+				sprintf(
52
+					__('Table analysis class on class %1$s is not set properly.', 'event_espresso'),
53
+					get_class($this)
54
+				)
55
+			);
56
+		}
57
+	}
58
+
59
+
60
+
61
+	/**
62
+	 * @param string $table_name which can optionally start with $wpdb->prefix or not
63
+	 * @param string $column_name
64
+	 * @param string $column_info
65
+	 * @return bool|false|int
66
+	 */
67
+	public function addColumn($table_name, $column_name, $column_info = 'INT UNSIGNED NOT NULL')
68
+	{
69
+		if (apply_filters('FHEE__EEH_Activation__add_column_if_it_doesnt_exist__short_circuit', false)) {
70
+			return false;
71
+		}
72
+		global $wpdb;
73
+		$full_table_name = $this->getTableAnalysis()->ensureTableNameHasPrefix($table_name);
74
+		$columns = $this->getTableColumns($table_name);
75
+		if ( ! in_array($column_name, $columns)) {
76
+			$alter_query = "ALTER TABLE {$full_table_name} ADD {$column_name} {$column_info}";
77
+			return $wpdb->query($alter_query);
78
+		}
79
+		return true;
80
+	}
81
+
82
+
83
+
84
+	/**
85
+	 * Gets the name of all columns on the  table. $table_name can
86
+	 * optionally start with $wpdb->prefix or not
87
+	 *
88
+	 * @global \wpdb $wpdb
89
+	 * @param string $table_name
90
+	 * @return array
91
+	 */
92
+	public function getTableColumns($table_name)
93
+	{
94
+		global $wpdb;
95
+		$table_name = $this->getTableAnalysis()->ensureTableNameHasPrefix($table_name);
96
+		$field_array = array();
97
+		if ( ! empty($table_name)) {
98
+			$columns = $wpdb->get_results("SHOW COLUMNS FROM {$table_name} ");
99
+			if ($columns !== false) {
100
+				foreach ($columns as $column) {
101
+					$field_array[] = $column->Field;
102
+				}
103
+			}
104
+		}
105
+		return $field_array;
106
+	}
107
+
108
+
109
+
110
+	/**
111
+	 * Drops the specified table from the database. $table_name can
112
+	 * optionally start with $wpdb->prefix or not
113
+	 *
114
+	 * @global \wpdb $wpdb
115
+	 * @param string $table_name
116
+	 * @return int
117
+	 */
118
+	public function dropTable($table_name)
119
+	{
120
+		global $wpdb;
121
+		if ($this->getTableAnalysis()->tableExists($table_name)) {
122
+			$table_name = $this->getTableAnalysis()->ensureTableNameHasPrefix($table_name);
123
+			return $wpdb->query("DROP TABLE IF EXISTS {$table_name}");
124
+		}
125
+		return 0;
126
+	}
127
+
128
+
129
+
130
+	/**
131
+	 * Drops all the tables mentioned in a single MYSQL query. Double-checks
132
+	 * each table name provided has a wpdb prefix attached, and that it exists.
133
+	 * Returns the list actually deleted
134
+	 *
135
+	 * @global WPDB $wpdb
136
+	 * @param array $table_names
137
+	 * @return array of table names which we deleted
138
+	 */
139
+	public function dropTables($table_names)
140
+	{
141
+		$tables_to_delete = array();
142
+		foreach ($table_names as $table_name) {
143
+			$table_name = $this->getTableAnalysis()->ensureTableNameHasPrefix($table_name);
144
+			if ($this->getTableAnalysis()->tableExists($table_name)) {
145
+				$tables_to_delete[] = $table_name;
146
+			}
147
+		}
148
+		if( ! empty( $tables_to_delete ) ) {
149
+			global $wpdb;
150
+			$wpdb->query('DROP TABLE ' . implode(', ', $tables_to_delete));
151
+		}
152
+		return $tables_to_delete;
153
+	}
154
+
155
+
156
+
157
+	/**
158
+	 * Drops the specified index from the specified table. $table_name can
159
+	 * optionally start with $wpdb->prefix or not
160
+	 *
162 161
 *@global \wpdb       $wpdb
163
-     * @param string $table_name
164
-     * @param string $index_name
165
-     * @return int
166
-     */
167
-    public function dropIndex($table_name, $index_name)
168
-    {
169
-        if (apply_filters('FHEE__EEH_Activation__drop_index__short_circuit', false)) {
170
-            return false;
171
-        }
172
-        global $wpdb;
173
-        $table_name = $this->getTableAnalysis()->ensureTableNameHasPrefix($table_name);
174
-        $index_exists_query = "SHOW INDEX FROM {$table_name} WHERE key_name = '{$index_name}'";
175
-        if (
176
-            $this->getTableAnalysis()->tableExists($table_name)
177
-            && $wpdb->get_var($index_exists_query)
178
-               === $table_name //using get_var with the $index_exists_query returns the table's name
179
-        ) {
180
-            return $wpdb->query("ALTER TABLE {$table_name} DROP INDEX {$index_name}");
181
-        }
182
-        return 0;
183
-    }
184
-
185
-
186
-
187
-    /**
188
-     * Just creates the requested table. $table_name can
189
-     * optionally start with $wpdb->prefix or not
190
-
191
-     *
162
+	 * @param string $table_name
163
+	 * @param string $index_name
164
+	 * @return int
165
+	 */
166
+	public function dropIndex($table_name, $index_name)
167
+	{
168
+		if (apply_filters('FHEE__EEH_Activation__drop_index__short_circuit', false)) {
169
+			return false;
170
+		}
171
+		global $wpdb;
172
+		$table_name = $this->getTableAnalysis()->ensureTableNameHasPrefix($table_name);
173
+		$index_exists_query = "SHOW INDEX FROM {$table_name} WHERE key_name = '{$index_name}'";
174
+		if (
175
+			$this->getTableAnalysis()->tableExists($table_name)
176
+			&& $wpdb->get_var($index_exists_query)
177
+			   === $table_name //using get_var with the $index_exists_query returns the table's name
178
+		) {
179
+			return $wpdb->query("ALTER TABLE {$table_name} DROP INDEX {$index_name}");
180
+		}
181
+		return 0;
182
+	}
183
+
184
+
185
+
186
+	/**
187
+	 * Just creates the requested table. $table_name can
188
+	 * optionally start with $wpdb->prefix or not
189
+	 *
192 190
 *@param string       $table_name
193
-     * @param string $create_sql defining the table's columns and indexes
194
-     * @param string $engine     (no need to specify "ENGINE=", that's implied)
195
-     * @return void
196
-     * @throws \EE_Error
197
-     */
198
-    public function createTable($table_name, $create_sql, $engine = 'MyISAM')
199
-    {
200
-        // does $sql contain valid column information? ( LPT: https://regex101.com/ is great for working out regex patterns )
201
-        if (preg_match('((((.*?))(,\s))+)', $create_sql, $valid_column_data)) {
202
-            $table_name = $this->getTableAnalysis()->ensureTableNameHasPrefix($table_name);
203
-            /** @var \wpdb $wpdb */
204
-            global $wpdb;
205
-            $SQL = "CREATE TABLE {$table_name} ( {$create_sql} ) ENGINE={$engine} " . $wpdb->get_charset_collate();
206
-
207
-            //get $wpdb to echo errors, but buffer them. This way at least WE know an error
208
-            //happened. And then we can choose to tell the end user
209
-            $old_show_errors_policy = $wpdb->show_errors(true);
210
-            $old_error_suppression_policy = $wpdb->suppress_errors(false);
211
-            ob_start();
212
-            dbDelta($SQL);
213
-            $output = ob_get_contents();
214
-            ob_end_clean();
215
-            $wpdb->show_errors($old_show_errors_policy);
216
-            $wpdb->suppress_errors($old_error_suppression_policy);
217
-            if ( ! empty($output)) {
218
-                throw new \EE_Error($output);
219
-            }
220
-        } else {
221
-            throw new \EE_Error(
222
-                sprintf(
223
-                    __('The following table creation SQL does not contain valid information about the table columns: %1$s %2$s',
224
-                        'event_espresso'),
225
-                    '<br />',
226
-                    $create_sql
227
-                )
228
-            );
229
-        }
230
-    }
231
-
232
-
233
-
234
-    /**
235
-     * Drops the specified index if it's size differs from $desired_index_size.
236
-     * WordPress' dbdelta method doesn't automatically change index sizes, so this
237
-     * method can be used to only drop the index if needed, and afterwards dbdelta can be used as normal.
238
-     *
191
+	 * @param string $create_sql defining the table's columns and indexes
192
+	 * @param string $engine     (no need to specify "ENGINE=", that's implied)
193
+	 * @return void
194
+	 * @throws \EE_Error
195
+	 */
196
+	public function createTable($table_name, $create_sql, $engine = 'MyISAM')
197
+	{
198
+		// does $sql contain valid column information? ( LPT: https://regex101.com/ is great for working out regex patterns )
199
+		if (preg_match('((((.*?))(,\s))+)', $create_sql, $valid_column_data)) {
200
+			$table_name = $this->getTableAnalysis()->ensureTableNameHasPrefix($table_name);
201
+			/** @var \wpdb $wpdb */
202
+			global $wpdb;
203
+			$SQL = "CREATE TABLE {$table_name} ( {$create_sql} ) ENGINE={$engine} " . $wpdb->get_charset_collate();
204
+
205
+			//get $wpdb to echo errors, but buffer them. This way at least WE know an error
206
+			//happened. And then we can choose to tell the end user
207
+			$old_show_errors_policy = $wpdb->show_errors(true);
208
+			$old_error_suppression_policy = $wpdb->suppress_errors(false);
209
+			ob_start();
210
+			dbDelta($SQL);
211
+			$output = ob_get_contents();
212
+			ob_end_clean();
213
+			$wpdb->show_errors($old_show_errors_policy);
214
+			$wpdb->suppress_errors($old_error_suppression_policy);
215
+			if ( ! empty($output)) {
216
+				throw new \EE_Error($output);
217
+			}
218
+		} else {
219
+			throw new \EE_Error(
220
+				sprintf(
221
+					__('The following table creation SQL does not contain valid information about the table columns: %1$s %2$s',
222
+						'event_espresso'),
223
+					'<br />',
224
+					$create_sql
225
+				)
226
+			);
227
+		}
228
+	}
229
+
230
+
231
+
232
+	/**
233
+	 * Drops the specified index if it's size differs from $desired_index_size.
234
+	 * WordPress' dbdelta method doesn't automatically change index sizes, so this
235
+	 * method can be used to only drop the index if needed, and afterwards dbdelta can be used as normal.
236
+	 *
239 237
 *@param string $table_name
240
-     * @param string $index_name
241
-     * @param string $column_name if none is provided, we assume the column name matches the index (often true in EE)
242
-     * @param string|int $desired_index_size defaults to 191, the max for utf8mb4.
243
-     *                   See https://events.codebasehq.com/redirect?https://make.wordpress.org/core/2015/04/02/the-utf8mb4-upgrade/
244
-     * @return bool
245
-     * @throws /EE_Error if table analysis object isn't defined
246
-     */
247
-    public function dropIndexIfSizeNot($table_name, $index_name, $column_name = null, $desired_index_size = 191)
248
-    {
249
-        if($column_name === null){
250
-            $column_name = $index_name;
251
-        }
252
-        $index_entries = $this->getTableAnalysis()->showIndexes($table_name,$index_name);
253
-        if(empty($index_entries)){
254
-            return false;
255
-        }
256
-        foreach($index_entries as $index_entry){
257
-            if( $column_name === $index_entry->Column_name
258
-                && (string)$desired_index_size !== $index_entry->Sub_part){
259
-                return $this->dropIndex($table_name,$index_name);
260
-            }
261
-        }
262
-        return false;
263
-    }
238
+	 * @param string $index_name
239
+	 * @param string $column_name if none is provided, we assume the column name matches the index (often true in EE)
240
+	 * @param string|int $desired_index_size defaults to 191, the max for utf8mb4.
241
+	 *                   See https://events.codebasehq.com/redirect?https://make.wordpress.org/core/2015/04/02/the-utf8mb4-upgrade/
242
+	 * @return bool
243
+	 * @throws /EE_Error if table analysis object isn't defined
244
+	 */
245
+	public function dropIndexIfSizeNot($table_name, $index_name, $column_name = null, $desired_index_size = 191)
246
+	{
247
+		if($column_name === null){
248
+			$column_name = $index_name;
249
+		}
250
+		$index_entries = $this->getTableAnalysis()->showIndexes($table_name,$index_name);
251
+		if(empty($index_entries)){
252
+			return false;
253
+		}
254
+		foreach($index_entries as $index_entry){
255
+			if( $column_name === $index_entry->Column_name
256
+				&& (string)$desired_index_size !== $index_entry->Sub_part){
257
+				return $this->dropIndex($table_name,$index_name);
258
+			}
259
+		}
260
+		return false;
261
+	}
264 262
 
265 263
 }
Please login to merge, or discard this patch.
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -145,9 +145,9 @@  discard block
 block discarded – undo
145 145
                 $tables_to_delete[] = $table_name;
146 146
             }
147 147
         }
148
-        if( ! empty( $tables_to_delete ) ) {
148
+        if ( ! empty($tables_to_delete)) {
149 149
             global $wpdb;
150
-            $wpdb->query('DROP TABLE ' . implode(', ', $tables_to_delete));
150
+            $wpdb->query('DROP TABLE '.implode(', ', $tables_to_delete));
151 151
         }
152 152
         return $tables_to_delete;
153 153
     }
@@ -202,7 +202,7 @@  discard block
 block discarded – undo
202 202
             $table_name = $this->getTableAnalysis()->ensureTableNameHasPrefix($table_name);
203 203
             /** @var \wpdb $wpdb */
204 204
             global $wpdb;
205
-            $SQL = "CREATE TABLE {$table_name} ( {$create_sql} ) ENGINE={$engine} " . $wpdb->get_charset_collate();
205
+            $SQL = "CREATE TABLE {$table_name} ( {$create_sql} ) ENGINE={$engine} ".$wpdb->get_charset_collate();
206 206
 
207 207
             //get $wpdb to echo errors, but buffer them. This way at least WE know an error
208 208
             //happened. And then we can choose to tell the end user
@@ -246,17 +246,17 @@  discard block
 block discarded – undo
246 246
      */
247 247
     public function dropIndexIfSizeNot($table_name, $index_name, $column_name = null, $desired_index_size = 191)
248 248
     {
249
-        if($column_name === null){
249
+        if ($column_name === null) {
250 250
             $column_name = $index_name;
251 251
         }
252
-        $index_entries = $this->getTableAnalysis()->showIndexes($table_name,$index_name);
253
-        if(empty($index_entries)){
252
+        $index_entries = $this->getTableAnalysis()->showIndexes($table_name, $index_name);
253
+        if (empty($index_entries)) {
254 254
             return false;
255 255
         }
256
-        foreach($index_entries as $index_entry){
257
-            if( $column_name === $index_entry->Column_name
258
-                && (string)$desired_index_size !== $index_entry->Sub_part){
259
-                return $this->dropIndex($table_name,$index_name);
256
+        foreach ($index_entries as $index_entry) {
257
+            if ($column_name === $index_entry->Column_name
258
+                && (string) $desired_index_size !== $index_entry->Sub_part) {
259
+                return $this->dropIndex($table_name, $index_name);
260 260
             }
261 261
         }
262 262
         return false;
Please login to merge, or discard this patch.
caffeinated/EE_Caf_Messages.class.php 2 patches
Indentation   +708 added lines, -708 removed lines patch added patch discarded remove patch
@@ -7,7 +7,7 @@  discard block
 block discarded – undo
7 7
  * @since           4.3.2
8 8
  */
9 9
 if ( ! defined('EVENT_ESPRESSO_VERSION')) {
10
-    exit('No direct script access allowed');
10
+	exit('No direct script access allowed');
11 11
 }
12 12
 
13 13
 /**
@@ -22,729 +22,729 @@  discard block
 block discarded – undo
22 22
 {
23 23
     
24 24
     
25
-    /**
26
-     * constructor.
27
-     */
28
-    public function __construct()
29
-    {
30
-        $this->_caf_hooks();
31
-    }
32
-    
33
-    
34
-    /**
35
-     * Contains all the hooks filters for setting up caffeinated messages functionality.
36
-     *
37
-     * @since 4.3.2
38
-     *
39
-     * @return void
40
-     */
41
-    private function _caf_hooks()
42
-    {
43
-        add_filter('FHEE__EED_Messages___set_messages_paths___MSG_PATHS', array($this, 'messages_autoload_paths'), 5);
44
-        add_filter('FHEE__EE_Email_messenger__get_validator_config', array($this, 'email_messenger_validator_config'),
45
-            5, 2);
46
-        add_filter('FHEE__EE_Email_messenger__get_template_fields', array($this, 'email_messenger_template_fields'), 5,
47
-            2);
48
-        add_filter('FHEE__EE_Html_messenger__get_template_fields', array($this, 'html_messenger_template_fields'), 5,
49
-            2);
50
-        add_filter('FHEE__EE_Html_messenger__get_validator_config', array($this, 'html_messenger_validator_config'), 5,
51
-            2);
52
-        add_filter('FHEE__EE_Pdf_messenger__get_template_fields', array($this, 'pdf_messenger_template_fields'), 5, 2);
53
-        add_filter('FHEE__EE_Pdf_messenger__get_validator_config', array($this, 'pdf_messenger_validator_config'), 5,
54
-            2);
55
-        add_filter('FHEE__EE_Messages_Template_Pack__get_specific_template__contents',
56
-            array($this, 'new_default_templates'), 5, 7);
57
-        add_filter('FHEE__EE_Messages_Base__get_valid_shortcodes', array($this, 'message_types_valid_shortcodes'), 5,
58
-            2);
59
-        
60
-        //shortcode parsers
61
-        add_filter('FHEE__EE_Attendee_Shortcodes__shortcodes', array($this, 'additional_attendee_shortcodes'), 5, 2);
62
-        add_filter('FHEE__EE_Attendee_Shortcodes__parser_after', array($this, 'additional_attendee_parser'), 5, 5);
63
-        add_filter('FHEE__EE_Recipient_List_Shortcodes__shortcodes',
64
-            array($this, 'additional_recipient_details_shortcodes'), 5, 2);
65
-        add_filter('FHEE__EE_Recipient_List_Shortcodes__parser_after',
66
-            array($this, 'additional_recipient_details_parser'), 5, 5);
67
-        add_filter('FHEE__EE_Primary_Registration_List_Shortcodes__shortcodes',
68
-            array($this, 'additional_primary_registration_details_shortcodes'), 5, 2);
69
-        add_filter('FHEE__EE_Primary_Registration_List_Shortcodes__parser_after',
70
-            array($this, 'additional_primary_registration_details_parser'), 5, 5);
71
-        
72
-        /**
73
-         * @since 4.2.0
74
-         */
75
-        add_filter('FHEE__EE_Datetime_Shortcodes__shortcodes', array($this, 'additional_datetime_shortcodes'), 10, 2);
76
-        add_filter('FHEE__EE_Datetime_Shortcodes__parser_after', array($this, 'additional_datetime_parser'), 10, 5);
77
-        
78
-        /**
79
-         * @since 4.3.0
80
-         */
81
-        //eat our own dog food!
82
-        add_action('EE_Brewing_Regular___messages_caf', array($this, 'register_caf_message_types'));
83
-        add_action('EE_Brewing_Regular___messages_caf', array($this, 'register_caf_shortcodes'));
84
-        do_action('EE_Brewing_Regular___messages_caf');
85
-    }
86
-    
87
-    
88
-    /**
89
-     * This just allows us to add additional paths to the autoloader (EED_Messages::autoload_messages()) for the
90
-     * messages system.
91
-     *
92
-     * @param  array $dir_ref original array of paths
93
-     *
94
-     * @return array           appended paths
95
-     */
96
-    public function messages_autoload_paths($dir_ref)
97
-    {
98
-        $dir_ref[] = EE_CAF_LIBRARIES . 'shortcodes/';
99
-        
100
-        return $dir_ref;
101
-    }
102
-    
103
-    
104
-    public function email_messenger_validator_config($validator_config, EE_Email_messenger $messenger)
105
-    {
106
-        $validator_config['attendee_list'] = array(
107
-            'shortcodes' => array('attendee', 'event_list', 'ticket_list', 'question_list'),
108
-            'required'   => array('[ATTENDEE_LIST]')
109
-        );
110
-        $validator_config['question_list'] = array(
111
-            'shortcodes' => array('question'),
112
-            'required'   => array('[QUESTION_LIST]')
113
-        );
114
-        
115
-        return $validator_config;
116
-    }
117
-    
118
-    
119
-    public function html_messenger_validator_config($validator_config, EE_Html_messenger $messenger)
120
-    {
121
-        $validator_config['attendee_list'] = array(
122
-            'shortcodes' => array('attendee', 'question_list'),
123
-            'required'   => array('[ATTENDEE_LIST]')
124
-        );
125
-        $validator_config['question_list'] = array(
126
-            'shortcodes' => array('question'),
127
-            'required'   => array('[QUESTION_LIST]')
128
-        );
129
-        
130
-        return $validator_config;
131
-    }
132
-    
133
-    
134
-    public function pdf_messenger_validator_config($validator_config, EE_Pdf_messenger $messenger)
135
-    {
136
-        $validator_config['attendee_list'] = array(
137
-            'shortcodes' => array('attendee', 'event_list', 'ticket_list', 'question_list'),
138
-            'required'   => array('[ATTENDEE_LIST]')
139
-        );
140
-        $validator_config['question_list'] = array(
141
-            'shortcodes' => array('question'),
142
-            'required'   => array('[QUESTION_LIST]')
143
-        );
144
-        
145
-        return $validator_config;
146
-    }
147
-    
148
-    
149
-    public function email_messenger_template_fields($template_fields, EE_Email_messenger $messenger)
150
-    {
151
-        $template_fields['extra']['content']['question_list'] = array(
152
-            'input'               => 'textarea',
153
-            'label'               => '[QUESTION_LIST]',
154
-            'type'                => 'string',
155
-            'required'            => true,
156
-            'validation'          => true,
157
-            'format'              => '%s',
158
-            'css_class'           => 'large-text',
159
-            'rows'                => '5',
160
-            'shortcodes_required' => array('[QUESTION_LIST]')
161
-        );
162
-        
163
-        return $template_fields;
164
-    }
165
-    
166
-    
167
-    public function html_messenger_template_fields($template_fields, EE_Html_messenger $messenger)
168
-    {
169
-        $template_fields['extra']['content']['question_list'] = array(
170
-            'input'               => 'textarea',
171
-            'label'               => '[QUESTION_LIST]',
172
-            'type'                => 'string',
173
-            'required'            => true,
174
-            'validation'          => true,
175
-            'format'              => '%s',
176
-            'css_class'           => 'large-text',
177
-            'rows'                => '5',
178
-            'shortcodes_required' => array('[QUESTION_LIST]')
179
-        );
180
-        
181
-        return $template_fields;
182
-    }
183
-    
184
-    
185
-    public function pdf_messenger_template_fields($template_fields, EE_Pdf_messenger $messenger)
186
-    {
187
-        $template_fields['extra']['content']['question_list'] = array(
188
-            'input'               => 'textarea',
189
-            'label'               => '[QUESTION_LIST]',
190
-            'type'                => 'string',
191
-            'required'            => true,
192
-            'validation'          => true,
193
-            'format'              => '%s',
194
-            'css_class'           => 'large-text',
195
-            'rows'                => '5',
196
-            'shortcodes_required' => array('[QUESTION_LIST]')
197
-        );
198
-        
199
-        return $template_fields;
200
-    }
201
-    
202
-    
203
-    public function new_default_templates(
204
-        $contents,
205
-        $actual_path,
206
-        EE_messenger $messenger,
207
-        EE_message_type $message_type,
208
-        $field,
209
-        $context,
210
-        EE_Messages_Template_Pack $template_pack
211
-    ) {
212
-        
213
-        //we're only modifying templates for the default template pack
214
-        if ( ! $template_pack instanceof EE_Messages_Template_Pack_Default) {
215
-            return $contents;
216
-        }
217
-        
218
-        //the template file name we're replacing contents for.
219
-        $template_file_prefix = $field . '_' . $context;
220
-        $msg_prefix           = $messenger->name . '_' . $message_type->name . '_';
221
-        
222
-        $base_path = EE_CAF_LIBRARIES . 'messages/defaults/default/';
223
-        
224
-        if ($messenger->name == 'email' && $message_type->name == 'registration') {
25
+	/**
26
+	 * constructor.
27
+	 */
28
+	public function __construct()
29
+	{
30
+		$this->_caf_hooks();
31
+	}
32
+    
33
+    
34
+	/**
35
+	 * Contains all the hooks filters for setting up caffeinated messages functionality.
36
+	 *
37
+	 * @since 4.3.2
38
+	 *
39
+	 * @return void
40
+	 */
41
+	private function _caf_hooks()
42
+	{
43
+		add_filter('FHEE__EED_Messages___set_messages_paths___MSG_PATHS', array($this, 'messages_autoload_paths'), 5);
44
+		add_filter('FHEE__EE_Email_messenger__get_validator_config', array($this, 'email_messenger_validator_config'),
45
+			5, 2);
46
+		add_filter('FHEE__EE_Email_messenger__get_template_fields', array($this, 'email_messenger_template_fields'), 5,
47
+			2);
48
+		add_filter('FHEE__EE_Html_messenger__get_template_fields', array($this, 'html_messenger_template_fields'), 5,
49
+			2);
50
+		add_filter('FHEE__EE_Html_messenger__get_validator_config', array($this, 'html_messenger_validator_config'), 5,
51
+			2);
52
+		add_filter('FHEE__EE_Pdf_messenger__get_template_fields', array($this, 'pdf_messenger_template_fields'), 5, 2);
53
+		add_filter('FHEE__EE_Pdf_messenger__get_validator_config', array($this, 'pdf_messenger_validator_config'), 5,
54
+			2);
55
+		add_filter('FHEE__EE_Messages_Template_Pack__get_specific_template__contents',
56
+			array($this, 'new_default_templates'), 5, 7);
57
+		add_filter('FHEE__EE_Messages_Base__get_valid_shortcodes', array($this, 'message_types_valid_shortcodes'), 5,
58
+			2);
59
+        
60
+		//shortcode parsers
61
+		add_filter('FHEE__EE_Attendee_Shortcodes__shortcodes', array($this, 'additional_attendee_shortcodes'), 5, 2);
62
+		add_filter('FHEE__EE_Attendee_Shortcodes__parser_after', array($this, 'additional_attendee_parser'), 5, 5);
63
+		add_filter('FHEE__EE_Recipient_List_Shortcodes__shortcodes',
64
+			array($this, 'additional_recipient_details_shortcodes'), 5, 2);
65
+		add_filter('FHEE__EE_Recipient_List_Shortcodes__parser_after',
66
+			array($this, 'additional_recipient_details_parser'), 5, 5);
67
+		add_filter('FHEE__EE_Primary_Registration_List_Shortcodes__shortcodes',
68
+			array($this, 'additional_primary_registration_details_shortcodes'), 5, 2);
69
+		add_filter('FHEE__EE_Primary_Registration_List_Shortcodes__parser_after',
70
+			array($this, 'additional_primary_registration_details_parser'), 5, 5);
71
+        
72
+		/**
73
+		 * @since 4.2.0
74
+		 */
75
+		add_filter('FHEE__EE_Datetime_Shortcodes__shortcodes', array($this, 'additional_datetime_shortcodes'), 10, 2);
76
+		add_filter('FHEE__EE_Datetime_Shortcodes__parser_after', array($this, 'additional_datetime_parser'), 10, 5);
77
+        
78
+		/**
79
+		 * @since 4.3.0
80
+		 */
81
+		//eat our own dog food!
82
+		add_action('EE_Brewing_Regular___messages_caf', array($this, 'register_caf_message_types'));
83
+		add_action('EE_Brewing_Regular___messages_caf', array($this, 'register_caf_shortcodes'));
84
+		do_action('EE_Brewing_Regular___messages_caf');
85
+	}
86
+    
87
+    
88
+	/**
89
+	 * This just allows us to add additional paths to the autoloader (EED_Messages::autoload_messages()) for the
90
+	 * messages system.
91
+	 *
92
+	 * @param  array $dir_ref original array of paths
93
+	 *
94
+	 * @return array           appended paths
95
+	 */
96
+	public function messages_autoload_paths($dir_ref)
97
+	{
98
+		$dir_ref[] = EE_CAF_LIBRARIES . 'shortcodes/';
99
+        
100
+		return $dir_ref;
101
+	}
102
+    
103
+    
104
+	public function email_messenger_validator_config($validator_config, EE_Email_messenger $messenger)
105
+	{
106
+		$validator_config['attendee_list'] = array(
107
+			'shortcodes' => array('attendee', 'event_list', 'ticket_list', 'question_list'),
108
+			'required'   => array('[ATTENDEE_LIST]')
109
+		);
110
+		$validator_config['question_list'] = array(
111
+			'shortcodes' => array('question'),
112
+			'required'   => array('[QUESTION_LIST]')
113
+		);
114
+        
115
+		return $validator_config;
116
+	}
117
+    
118
+    
119
+	public function html_messenger_validator_config($validator_config, EE_Html_messenger $messenger)
120
+	{
121
+		$validator_config['attendee_list'] = array(
122
+			'shortcodes' => array('attendee', 'question_list'),
123
+			'required'   => array('[ATTENDEE_LIST]')
124
+		);
125
+		$validator_config['question_list'] = array(
126
+			'shortcodes' => array('question'),
127
+			'required'   => array('[QUESTION_LIST]')
128
+		);
129
+        
130
+		return $validator_config;
131
+	}
132
+    
133
+    
134
+	public function pdf_messenger_validator_config($validator_config, EE_Pdf_messenger $messenger)
135
+	{
136
+		$validator_config['attendee_list'] = array(
137
+			'shortcodes' => array('attendee', 'event_list', 'ticket_list', 'question_list'),
138
+			'required'   => array('[ATTENDEE_LIST]')
139
+		);
140
+		$validator_config['question_list'] = array(
141
+			'shortcodes' => array('question'),
142
+			'required'   => array('[QUESTION_LIST]')
143
+		);
144
+        
145
+		return $validator_config;
146
+	}
147
+    
148
+    
149
+	public function email_messenger_template_fields($template_fields, EE_Email_messenger $messenger)
150
+	{
151
+		$template_fields['extra']['content']['question_list'] = array(
152
+			'input'               => 'textarea',
153
+			'label'               => '[QUESTION_LIST]',
154
+			'type'                => 'string',
155
+			'required'            => true,
156
+			'validation'          => true,
157
+			'format'              => '%s',
158
+			'css_class'           => 'large-text',
159
+			'rows'                => '5',
160
+			'shortcodes_required' => array('[QUESTION_LIST]')
161
+		);
162
+        
163
+		return $template_fields;
164
+	}
165
+    
166
+    
167
+	public function html_messenger_template_fields($template_fields, EE_Html_messenger $messenger)
168
+	{
169
+		$template_fields['extra']['content']['question_list'] = array(
170
+			'input'               => 'textarea',
171
+			'label'               => '[QUESTION_LIST]',
172
+			'type'                => 'string',
173
+			'required'            => true,
174
+			'validation'          => true,
175
+			'format'              => '%s',
176
+			'css_class'           => 'large-text',
177
+			'rows'                => '5',
178
+			'shortcodes_required' => array('[QUESTION_LIST]')
179
+		);
180
+        
181
+		return $template_fields;
182
+	}
183
+    
184
+    
185
+	public function pdf_messenger_template_fields($template_fields, EE_Pdf_messenger $messenger)
186
+	{
187
+		$template_fields['extra']['content']['question_list'] = array(
188
+			'input'               => 'textarea',
189
+			'label'               => '[QUESTION_LIST]',
190
+			'type'                => 'string',
191
+			'required'            => true,
192
+			'validation'          => true,
193
+			'format'              => '%s',
194
+			'css_class'           => 'large-text',
195
+			'rows'                => '5',
196
+			'shortcodes_required' => array('[QUESTION_LIST]')
197
+		);
198
+        
199
+		return $template_fields;
200
+	}
201
+    
202
+    
203
+	public function new_default_templates(
204
+		$contents,
205
+		$actual_path,
206
+		EE_messenger $messenger,
207
+		EE_message_type $message_type,
208
+		$field,
209
+		$context,
210
+		EE_Messages_Template_Pack $template_pack
211
+	) {
212
+        
213
+		//we're only modifying templates for the default template pack
214
+		if ( ! $template_pack instanceof EE_Messages_Template_Pack_Default) {
215
+			return $contents;
216
+		}
217
+        
218
+		//the template file name we're replacing contents for.
219
+		$template_file_prefix = $field . '_' . $context;
220
+		$msg_prefix           = $messenger->name . '_' . $message_type->name . '_';
221
+        
222
+		$base_path = EE_CAF_LIBRARIES . 'messages/defaults/default/';
223
+        
224
+		if ($messenger->name == 'email' && $message_type->name == 'registration') {
225 225
             
226
-            switch ($template_file_prefix) {
226
+			switch ($template_file_prefix) {
227 227
                 
228
-                case 'question_list_admin' :
229
-                case 'question_list_attendee' :
230
-                case 'question_list_primary_attendee' :
231
-                    $path     = $base_path . $msg_prefix . 'question_list.template.php';
232
-                    $contents = EEH_Template::display_template($path, array(), true);
233
-                    break;
228
+				case 'question_list_admin' :
229
+				case 'question_list_attendee' :
230
+				case 'question_list_primary_attendee' :
231
+					$path     = $base_path . $msg_prefix . 'question_list.template.php';
232
+					$contents = EEH_Template::display_template($path, array(), true);
233
+					break;
234 234
                 
235
-                case 'attendee_list_primary_attendee' :
236
-                    $path     = $base_path . $msg_prefix . 'attendee_list.template.php';
237
-                    $contents = EEH_Template::display_template($path, array(), true);
238
-                    break;
235
+				case 'attendee_list_primary_attendee' :
236
+					$path     = $base_path . $msg_prefix . 'attendee_list.template.php';
237
+					$contents = EEH_Template::display_template($path, array(), true);
238
+					break;
239 239
                 
240
-                case 'attendee_list_admin' :
241
-                    $path     = $base_path . $msg_prefix . 'attendee_list_admin.template.php';
242
-                    $contents = EEH_Template::display_template($path,
243
-                        array(), true);
244
-                    break;
240
+				case 'attendee_list_admin' :
241
+					$path     = $base_path . $msg_prefix . 'attendee_list_admin.template.php';
242
+					$contents = EEH_Template::display_template($path,
243
+						array(), true);
244
+					break;
245 245
                 
246
-                case 'attendee_list_attendee' :
247
-                    $contents = '';
248
-                    break;
246
+				case 'attendee_list_attendee' :
247
+					$contents = '';
248
+					break;
249 249
                 
250
-                case 'event_list_attendee' :
251
-                    $path     = $base_path . $msg_prefix . 'event_list_attendee.template.php';
252
-                    $contents = EEH_Template::display_template($path, array(), true);
253
-                    break;
254
-            }
255
-        } elseif ($messenger->name == 'email' && $message_type->name == 'newsletter') {
256
-            switch ($template_file_prefix) {
250
+				case 'event_list_attendee' :
251
+					$path     = $base_path . $msg_prefix . 'event_list_attendee.template.php';
252
+					$contents = EEH_Template::display_template($path, array(), true);
253
+					break;
254
+			}
255
+		} elseif ($messenger->name == 'email' && $message_type->name == 'newsletter') {
256
+			switch ($template_file_prefix) {
257 257
                 
258
-                case 'content_attendee' :
259
-                    $path     = $base_path . $msg_prefix . 'content.template.php';
260
-                    $contents = EEH_Template::display_template($path, array(), true);
261
-                    break;
258
+				case 'content_attendee' :
259
+					$path     = $base_path . $msg_prefix . 'content.template.php';
260
+					$contents = EEH_Template::display_template($path, array(), true);
261
+					break;
262 262
                 
263
-                case 'newsletter_content_attendee' :
264
-                    $path     = $base_path . $msg_prefix . 'newsletter_content.template.php';
265
-                    $contents = EEH_Template::display_template($path, array(), true);
266
-                    break;
263
+				case 'newsletter_content_attendee' :
264
+					$path     = $base_path . $msg_prefix . 'newsletter_content.template.php';
265
+					$contents = EEH_Template::display_template($path, array(), true);
266
+					break;
267 267
                 
268
-                case 'newsletter_subject_attendee' :
269
-                    $path     = $base_path . $msg_prefix . 'subject.template.php';
270
-                    $contents = EEH_Template::display_template($path, array(), true);
271
-                    break;
272
-            }
273
-        } elseif ($messenger->name == 'html' && $message_type->name == 'receipt') {
274
-            switch ($template_file_prefix) {
275
-                case 'attendee_list_purchaser' :
276
-                    $path     = $base_path . $msg_prefix . 'attendee_list.template.php';
277
-                    $contents = EEH_Template::display_template($path, array(), true);
278
-                    break;
279
-            }
280
-        }
281
-        
282
-        return $contents;
283
-        
284
-    }
285
-    
286
-    
287
-    public function message_types_valid_shortcodes($valid_shortcodes, EE_Messages_Base $msg)
288
-    {
289
-        //make sure question_list and question are ONLY added for the core message types.  Any other message types will have to explicitly set question_list as a valid shortcode.
290
-        $include_with = array(
291
-            'registration',
292
-            'cancelled_registration',
293
-            'declined_registration',
294
-            'not_approved_registration',
295
-            'payment_declined',
296
-            'payment_failed',
297
-            'payment_cancelled',
298
-            'payment',
299
-            'payment_reminder',
300
-            'pending_approval',
301
-            'registration_summary',
302
-            'invoice',
303
-            'receipt'
304
-        );
305
-        if ($msg instanceof EE_message_type && in_array($msg->name, $include_with)) {
306
-            $contexts = array_keys($msg->get_contexts());
307
-            foreach ($contexts as $context) {
308
-                $valid_shortcodes[$context][] = 'question_list';
309
-                $valid_shortcodes[$context][] = 'question';
310
-            }
311
-        }
312
-        
313
-        return $valid_shortcodes;
314
-    }
315
-    
316
-    
317
-    public function additional_attendee_shortcodes($shortcodes, $shortcode_parser)
318
-    {
319
-        $shortcodes['[ANSWER_*]'] = __('This is a special dynamic shortcode. Right after the "*", add the exact text of a existing question, and if there is an answer for that question for this registrant, that will take the place of this shortcode.',
320
-            'event_espresso');
321
-        
322
-        return $shortcodes;
323
-    }
324
-    
325
-    
326
-    public function additional_attendee_parser($parsed, $shortcode, $data, $extra_data, $shortcode_parser)
327
-    {
328
-        
329
-        if (strpos($shortcode,
330
-                '[ANSWER_*') === false || ! isset($extra_data['data']->questions) || ! isset($extra_data['data']->registrations)
331
-        ) {
332
-            return $parsed;
333
-        }
334
-        
335
-        //let's get the question from the code.
336
-        $shortcode = str_replace('[ANSWER_*', '', $shortcode);
337
-        $shortcode = trim(str_replace(']', '', $shortcode));
338
-        
339
-        $registration = $data instanceof EE_Registration ? $data : null;
340
-        $registration = ! $registration instanceof EE_Registration && is_array($extra_data) && isset($extra_data['data']) && $extra_data['data'] instanceof EE_Registration ? $extra_data['data'] : $registration;
341
-        
342
-        $aee = $data instanceof EE_Messages_Addressee ? $data : null;
343
-        $aee = ! $aee instanceof EE_Messages_Addressee && is_array($extra_data) && isset($extra_data['data']) ? $extra_data['data'] : $aee;
344
-        
345
-        if ( ! $registration instanceof EE_Registration || ! $aee instanceof EE_Messages_Addressee) {
346
-            return $parsed;
347
-        }
348
-        
349
-        //now let's figure out which question has this text.
350
-        foreach ($aee->questions as $ansid => $question) {
351
-            if (
352
-                $question instanceof EE_Question
353
-                && trim($question->display_text()) == trim($shortcode)
354
-                && isset($aee->registrations[$registration->ID()]['ans_objs'][$ansid])
355
-            ) {
356
-                return $aee->registrations[$registration->ID()]['ans_objs'][$ansid]->get_pretty('ANS_value',
357
-                    'no_wpautop');
358
-            }
359
-        }
360
-        
361
-        //nothing!
362
-        return $parsed;
363
-    }
364
-    
365
-    
366
-    /**
367
-     * Callback for additional shortcodes filter for adding additional datetime shortcodes.
368
-     *
369
-     * @since  4.2
370
-     *
371
-     * @param  array                  $shortcodes         array of shortcodes and
372
-     *                                                    descriptions
373
-     * @param  EE_Datetime_Shortcodes $shortcode_parser   EE_Shortcodes object
374
-     *
375
-     * @return array                                        array of shortcodes and
376
-     *                                                        descriptions
377
-     */
378
-    public function additional_datetime_shortcodes($shortcodes, $shortcode_parser)
379
-    {
380
-        $shortcodes['[DTT_NAME]']          = __('This will be parsed to the Title given for a Datetime',
381
-            'event_espresso');
382
-        $shortcodes['[DTT_DESCRIPTION]']   = __('This will be parsed to the description for a Datetime',
383
-            'event_espresso');
384
-        $shortcodes['[DTT_NAME_OR_DATES]'] = __('When parsed, if the Datetime has a name, it is used, otherwise a formatted string including the start date and end date will be used.',
385
-            'event_espresso');
386
-        
387
-        return $shortcodes;
388
-    }
389
-    
390
-    
391
-    /**
392
-     * Callback for additional shortcodes parser filter used for adding parser for new
393
-     * Datetime shortcodes
394
-     *
395
-     * @since  4.2
396
-     *
397
-     * @param  string                 $parsed     The finished parsed string for the given shortcode.
398
-     * @param  string                 $shortcode  The shortcode being parsed.
399
-     * @param  object                 $data       The incoming data object for the Shortcode Parser.
400
-     * @param  object                 $extra_data The incoming extra date object for the Shortcode
401
-     *                                            Parser.
402
-     * @param  EE_Datetime_Shortcodes $shortcode_parser
403
-     *
404
-     * @return string                   The new parsed string.
405
-     */
406
-    public function additional_datetime_parser($parsed, $shortcode, $data, $extra_data, $shortcode_parser)
407
-    {
408
-        
409
-        if ( ! $data instanceof EE_Datetime) {
410
-            return ''; //get out because we can only parse with the datetime object.
411
-        }
412
-        
413
-        switch ($shortcode) {
414
-            case '[DTT_NAME]' :
415
-                return $data->name();
416
-                break;
417
-            case '[DTT_DESCRIPTION]' :
418
-                return $data->description();
419
-                break;
420
-            case '[DTT_NAME_OR_DATES]' :
421
-                return $data->get_dtt_display_name(true);
422
-                break;
423
-            default :
424
-                return $parsed;
425
-                break;
426
-        }
427
-    }
428
-    
429
-    
430
-    public function additional_recipient_details_shortcodes($shortcodes, $shortcode_parser)
431
-    {
432
-        $shortcodes['[RECIPIENT_QUESTION_LIST]'] = __('This is used to indicate where you want the list of questions and answers to show for the person receiving the message.',
433
-            'event_espresso');
434
-        
435
-        return $shortcodes;
436
-    }
437
-    
438
-    
439
-    /**
440
-     * Callback for FHEE__EE_Recipient_List_Shortcodes__parser_after filter (dynamic filter).
441
-     *
442
-     * @param string         $parsed           The original parsed content for the shortcode
443
-     * @param string         $shortcode        The shortcode being parsed
444
-     * @param array          $data             The shortcode parser data array
445
-     * @param array          $extra_data       The shortcode parser extra data array
446
-     * @param \EE_Shortcodes $shortcode_parser Shortcode parser.
447
-     *
448
-     * @return string
449
-     */
450
-    public function additional_recipient_details_parser($parsed, $shortcode, $data, $extra_data, $shortcode_parser)
451
-    {
452
-        
453
-        if (array($data) && ! isset($data['data'])) {
454
-            return $parsed;
455
-        }
456
-        
457
-        $recipient = $data['data'] instanceof EE_Messages_Addressee ? $data['data'] : null;
458
-        $recipient = ! $recipient instanceof EE_Messages_Addressee && array($extra_data) && isset($extra_data['data']) && $extra_data['data'] instanceof EE_Messages_Addressee ? $extra_data['data'] : $recipient;
459
-        
460
-        if ( ! $recipient instanceof EE_Messages_Addressee) {
461
-            return $parsed;
462
-        }
463
-        
464
-        switch ($shortcode) {
465
-            case '[RECIPIENT_QUESTION_LIST]' :
466
-                $att                       = $recipient->att_obj;
467
-                $registrations_on_attendee = $att instanceof EE_Attendee ? $recipient->attendees[$att->ID()]['reg_objs'] : array();
468
-                $registrations_on_attendee = empty($registrations_on_attendee) && $recipient->reg_obj instanceof EE_Registration ? array($recipient->reg_obj) : $registrations_on_attendee;
469
-                $answers                   = array();
268
+				case 'newsletter_subject_attendee' :
269
+					$path     = $base_path . $msg_prefix . 'subject.template.php';
270
+					$contents = EEH_Template::display_template($path, array(), true);
271
+					break;
272
+			}
273
+		} elseif ($messenger->name == 'html' && $message_type->name == 'receipt') {
274
+			switch ($template_file_prefix) {
275
+				case 'attendee_list_purchaser' :
276
+					$path     = $base_path . $msg_prefix . 'attendee_list.template.php';
277
+					$contents = EEH_Template::display_template($path, array(), true);
278
+					break;
279
+			}
280
+		}
281
+        
282
+		return $contents;
283
+        
284
+	}
285
+    
286
+    
287
+	public function message_types_valid_shortcodes($valid_shortcodes, EE_Messages_Base $msg)
288
+	{
289
+		//make sure question_list and question are ONLY added for the core message types.  Any other message types will have to explicitly set question_list as a valid shortcode.
290
+		$include_with = array(
291
+			'registration',
292
+			'cancelled_registration',
293
+			'declined_registration',
294
+			'not_approved_registration',
295
+			'payment_declined',
296
+			'payment_failed',
297
+			'payment_cancelled',
298
+			'payment',
299
+			'payment_reminder',
300
+			'pending_approval',
301
+			'registration_summary',
302
+			'invoice',
303
+			'receipt'
304
+		);
305
+		if ($msg instanceof EE_message_type && in_array($msg->name, $include_with)) {
306
+			$contexts = array_keys($msg->get_contexts());
307
+			foreach ($contexts as $context) {
308
+				$valid_shortcodes[$context][] = 'question_list';
309
+				$valid_shortcodes[$context][] = 'question';
310
+			}
311
+		}
312
+        
313
+		return $valid_shortcodes;
314
+	}
315
+    
316
+    
317
+	public function additional_attendee_shortcodes($shortcodes, $shortcode_parser)
318
+	{
319
+		$shortcodes['[ANSWER_*]'] = __('This is a special dynamic shortcode. Right after the "*", add the exact text of a existing question, and if there is an answer for that question for this registrant, that will take the place of this shortcode.',
320
+			'event_espresso');
321
+        
322
+		return $shortcodes;
323
+	}
324
+    
325
+    
326
+	public function additional_attendee_parser($parsed, $shortcode, $data, $extra_data, $shortcode_parser)
327
+	{
328
+        
329
+		if (strpos($shortcode,
330
+				'[ANSWER_*') === false || ! isset($extra_data['data']->questions) || ! isset($extra_data['data']->registrations)
331
+		) {
332
+			return $parsed;
333
+		}
334
+        
335
+		//let's get the question from the code.
336
+		$shortcode = str_replace('[ANSWER_*', '', $shortcode);
337
+		$shortcode = trim(str_replace(']', '', $shortcode));
338
+        
339
+		$registration = $data instanceof EE_Registration ? $data : null;
340
+		$registration = ! $registration instanceof EE_Registration && is_array($extra_data) && isset($extra_data['data']) && $extra_data['data'] instanceof EE_Registration ? $extra_data['data'] : $registration;
341
+        
342
+		$aee = $data instanceof EE_Messages_Addressee ? $data : null;
343
+		$aee = ! $aee instanceof EE_Messages_Addressee && is_array($extra_data) && isset($extra_data['data']) ? $extra_data['data'] : $aee;
344
+        
345
+		if ( ! $registration instanceof EE_Registration || ! $aee instanceof EE_Messages_Addressee) {
346
+			return $parsed;
347
+		}
348
+        
349
+		//now let's figure out which question has this text.
350
+		foreach ($aee->questions as $ansid => $question) {
351
+			if (
352
+				$question instanceof EE_Question
353
+				&& trim($question->display_text()) == trim($shortcode)
354
+				&& isset($aee->registrations[$registration->ID()]['ans_objs'][$ansid])
355
+			) {
356
+				return $aee->registrations[$registration->ID()]['ans_objs'][$ansid]->get_pretty('ANS_value',
357
+					'no_wpautop');
358
+			}
359
+		}
360
+        
361
+		//nothing!
362
+		return $parsed;
363
+	}
364
+    
365
+    
366
+	/**
367
+	 * Callback for additional shortcodes filter for adding additional datetime shortcodes.
368
+	 *
369
+	 * @since  4.2
370
+	 *
371
+	 * @param  array                  $shortcodes         array of shortcodes and
372
+	 *                                                    descriptions
373
+	 * @param  EE_Datetime_Shortcodes $shortcode_parser   EE_Shortcodes object
374
+	 *
375
+	 * @return array                                        array of shortcodes and
376
+	 *                                                        descriptions
377
+	 */
378
+	public function additional_datetime_shortcodes($shortcodes, $shortcode_parser)
379
+	{
380
+		$shortcodes['[DTT_NAME]']          = __('This will be parsed to the Title given for a Datetime',
381
+			'event_espresso');
382
+		$shortcodes['[DTT_DESCRIPTION]']   = __('This will be parsed to the description for a Datetime',
383
+			'event_espresso');
384
+		$shortcodes['[DTT_NAME_OR_DATES]'] = __('When parsed, if the Datetime has a name, it is used, otherwise a formatted string including the start date and end date will be used.',
385
+			'event_espresso');
386
+        
387
+		return $shortcodes;
388
+	}
389
+    
390
+    
391
+	/**
392
+	 * Callback for additional shortcodes parser filter used for adding parser for new
393
+	 * Datetime shortcodes
394
+	 *
395
+	 * @since  4.2
396
+	 *
397
+	 * @param  string                 $parsed     The finished parsed string for the given shortcode.
398
+	 * @param  string                 $shortcode  The shortcode being parsed.
399
+	 * @param  object                 $data       The incoming data object for the Shortcode Parser.
400
+	 * @param  object                 $extra_data The incoming extra date object for the Shortcode
401
+	 *                                            Parser.
402
+	 * @param  EE_Datetime_Shortcodes $shortcode_parser
403
+	 *
404
+	 * @return string                   The new parsed string.
405
+	 */
406
+	public function additional_datetime_parser($parsed, $shortcode, $data, $extra_data, $shortcode_parser)
407
+	{
408
+        
409
+		if ( ! $data instanceof EE_Datetime) {
410
+			return ''; //get out because we can only parse with the datetime object.
411
+		}
412
+        
413
+		switch ($shortcode) {
414
+			case '[DTT_NAME]' :
415
+				return $data->name();
416
+				break;
417
+			case '[DTT_DESCRIPTION]' :
418
+				return $data->description();
419
+				break;
420
+			case '[DTT_NAME_OR_DATES]' :
421
+				return $data->get_dtt_display_name(true);
422
+				break;
423
+			default :
424
+				return $parsed;
425
+				break;
426
+		}
427
+	}
428
+    
429
+    
430
+	public function additional_recipient_details_shortcodes($shortcodes, $shortcode_parser)
431
+	{
432
+		$shortcodes['[RECIPIENT_QUESTION_LIST]'] = __('This is used to indicate where you want the list of questions and answers to show for the person receiving the message.',
433
+			'event_espresso');
434
+        
435
+		return $shortcodes;
436
+	}
437
+    
438
+    
439
+	/**
440
+	 * Callback for FHEE__EE_Recipient_List_Shortcodes__parser_after filter (dynamic filter).
441
+	 *
442
+	 * @param string         $parsed           The original parsed content for the shortcode
443
+	 * @param string         $shortcode        The shortcode being parsed
444
+	 * @param array          $data             The shortcode parser data array
445
+	 * @param array          $extra_data       The shortcode parser extra data array
446
+	 * @param \EE_Shortcodes $shortcode_parser Shortcode parser.
447
+	 *
448
+	 * @return string
449
+	 */
450
+	public function additional_recipient_details_parser($parsed, $shortcode, $data, $extra_data, $shortcode_parser)
451
+	{
452
+        
453
+		if (array($data) && ! isset($data['data'])) {
454
+			return $parsed;
455
+		}
456
+        
457
+		$recipient = $data['data'] instanceof EE_Messages_Addressee ? $data['data'] : null;
458
+		$recipient = ! $recipient instanceof EE_Messages_Addressee && array($extra_data) && isset($extra_data['data']) && $extra_data['data'] instanceof EE_Messages_Addressee ? $extra_data['data'] : $recipient;
459
+        
460
+		if ( ! $recipient instanceof EE_Messages_Addressee) {
461
+			return $parsed;
462
+		}
463
+        
464
+		switch ($shortcode) {
465
+			case '[RECIPIENT_QUESTION_LIST]' :
466
+				$att                       = $recipient->att_obj;
467
+				$registrations_on_attendee = $att instanceof EE_Attendee ? $recipient->attendees[$att->ID()]['reg_objs'] : array();
468
+				$registrations_on_attendee = empty($registrations_on_attendee) && $recipient->reg_obj instanceof EE_Registration ? array($recipient->reg_obj) : $registrations_on_attendee;
469
+				$answers                   = array();
470 470
                 
471
-                $template         = is_array($data['template']) && isset($data['template']['question_list']) ? $data['template']['question_list'] : $extra_data['template']['question_list'];
472
-                $valid_shortcodes = array('question');
471
+				$template         = is_array($data['template']) && isset($data['template']['question_list']) ? $data['template']['question_list'] : $extra_data['template']['question_list'];
472
+				$valid_shortcodes = array('question');
473 473
                 
474
-                //if the context is main_content then get all answers for all registrations on this attendee
475
-                if ($data['data'] instanceof EE_Messages_Addressee) {
474
+				//if the context is main_content then get all answers for all registrations on this attendee
475
+				if ($data['data'] instanceof EE_Messages_Addressee) {
476 476
                     
477
-                    foreach ($registrations_on_attendee as $reg) {
478
-                        if ($reg instanceof EE_Registration) {
479
-                            $anss = ! empty($recipient->registrations[$reg->ID()]['ans_objs']) ? $recipient->registrations[$reg->ID()]['ans_objs'] : array();
480
-                            foreach ($anss as $ans) {
481
-                                if ($ans instanceof EE_Answer) {
482
-                                    $answers[$ans->ID()] = $ans;
483
-                                }
484
-                            }
485
-                        }
486
-                    }
487
-                }
477
+					foreach ($registrations_on_attendee as $reg) {
478
+						if ($reg instanceof EE_Registration) {
479
+							$anss = ! empty($recipient->registrations[$reg->ID()]['ans_objs']) ? $recipient->registrations[$reg->ID()]['ans_objs'] : array();
480
+							foreach ($anss as $ans) {
481
+								if ($ans instanceof EE_Answer) {
482
+									$answers[$ans->ID()] = $ans;
483
+								}
484
+							}
485
+						}
486
+					}
487
+				}
488 488
                 
489
-                //if the context is the event list parser, then let's return just the answers for all registrations attached to the recipient for that event.
490
-                if ($data['data'] instanceof EE_Event) {
491
-                    $event = $data['data'];
492
-                    foreach ($registrations_on_attendee as $reg) {
493
-                        if ($reg instanceof EE_Registration && $reg->event_ID() == $event->ID()) {
494
-                            $anss = ! empty($recipient->registrations[$reg->ID()]['ans_objs']) ? $recipient->registrations[$reg->ID()]['ans_objs'] : array();
495
-                            foreach ($anss as $ans) {
496
-                                if ($ans instanceof EE_Answer) {
497
-                                    $answers[$ans->ID()] = $ans;
498
-                                }
499
-                            }
500
-                        }
501
-                    }
502
-                }
489
+				//if the context is the event list parser, then let's return just the answers for all registrations attached to the recipient for that event.
490
+				if ($data['data'] instanceof EE_Event) {
491
+					$event = $data['data'];
492
+					foreach ($registrations_on_attendee as $reg) {
493
+						if ($reg instanceof EE_Registration && $reg->event_ID() == $event->ID()) {
494
+							$anss = ! empty($recipient->registrations[$reg->ID()]['ans_objs']) ? $recipient->registrations[$reg->ID()]['ans_objs'] : array();
495
+							foreach ($anss as $ans) {
496
+								if ($ans instanceof EE_Answer) {
497
+									$answers[$ans->ID()] = $ans;
498
+								}
499
+							}
500
+						}
501
+					}
502
+				}
503 503
                 
504
-                $questions = $questions = isset($recipient->questions) ? $recipient->questions : array();
504
+				$questions = $questions = isset($recipient->questions) ? $recipient->questions : array();
505 505
                 
506
-                //if $extra_data does not have a 'data' key then let's make sure we add it and set the EE_Messages_Addressee
507
-                //object on it.
508
-                if ( ! isset( $extra_data['data'] ) ) {
509
-                    $extra_data['data'] = $recipient;
510
-                }
506
+				//if $extra_data does not have a 'data' key then let's make sure we add it and set the EE_Messages_Addressee
507
+				//object on it.
508
+				if ( ! isset( $extra_data['data'] ) ) {
509
+					$extra_data['data'] = $recipient;
510
+				}
511 511
                 
512
-                return $this->_parse_question_list_for_primary_or_recipient_registration(
513
-                    $shortcode_parser,
514
-                    $questions,
515
-                    $answers,
516
-                    $template,
517
-                    $valid_shortcodes,
518
-                    $extra_data
519
-                );
520
-                break;
512
+				return $this->_parse_question_list_for_primary_or_recipient_registration(
513
+					$shortcode_parser,
514
+					$questions,
515
+					$answers,
516
+					$template,
517
+					$valid_shortcodes,
518
+					$extra_data
519
+				);
520
+				break;
521 521
             
522
-            default :
523
-                return $parsed;
524
-                break;
525
-        }
526
-    }
527
-    
528
-    
529
-    public function additional_primary_registration_details_shortcodes($shortcodes, $shortcode_parser)
530
-    {
531
-        $shortcodes['[PRIMARY_REGISTRANT_QUESTION_LIST]'] = __('This is used to indicate the questions and answers for the primary_registrant. It should be placed in the "[attendee_list]" field',
532
-            'event_espresso');
533
-        
534
-        return $shortcodes;
535
-    }
536
-    
537
-    
538
-    /**
539
-     * Callback for FHEE__EE_Primary_Registration_List_Shortcodes__parser_after filter (dynamic filter).
540
-     *
541
-     * @param string         $parsed           The original parsed content for the shortcode
542
-     * @param string         $shortcode        The shortcode being parsed
543
-     * @param array          $data             The shortcode parser data array
544
-     * @param array          $extra_data       The shortcode parser extra data array
545
-     * @param \EE_Shortcodes $shortcode_parser Shortcode parser.
546
-     *
547
-     * @return string
548
-     */
549
-    public function additional_primary_registration_details_parser(
550
-        $parsed,
551
-        $shortcode,
552
-        $data,
553
-        $extra_data,
554
-        $shortcode_parser
555
-    ) {
556
-        if (array($data) && ! isset($data['data'])) {
557
-            return $parsed;
558
-        }
559
-        
560
-        $recipient = $data['data'] instanceof EE_Messages_Addressee ? $data['data'] : null;
561
-        $recipient = ! $recipient instanceof EE_Messages_Addressee && array($extra_data) && isset($extra_data['data']) && $extra_data['data'] instanceof EE_Messages_Addressee ? $extra_data['data'] : $recipient;
562
-        
563
-        if ( ! $recipient instanceof EE_Messages_Addressee) {
564
-            return $parsed;
565
-        }
566
-        
567
-        switch ($shortcode) {
568
-            case '[PRIMARY_REGISTRANT_QUESTION_LIST]' :
569
-                if ( ! $recipient->primary_att_obj instanceof EE_Attendee || ! $recipient->primary_reg_obj instanceof EE_Registration) {
570
-                    return '';
571
-                }
572
-                $registration     = $recipient->primary_reg_obj;
573
-                $template         = is_array($data['template']) && isset($data['template']['question_list']) ? $data['template']['question_list'] : $extra_data['template']['question_list'];
574
-                $valid_shortcodes = array('question');
575
-                $answers          = $recipient->registrations[$registration->ID()]['ans_objs'];
576
-                $questions = isset($recipient->questions) ? $recipient->questions : array();
577
-                //if $extra_data does not have a 'data' key then let's make sure we add it and set the EE_Messages_Addressee
578
-                //object on it.
579
-                if ( ! isset( $extra_data['data'] ) ){
580
-                    $extra_data['data'] = $recipient;
581
-                }
582
-                return $this->_parse_question_list_for_primary_or_recipient_registration(
583
-                    $shortcode_parser,
584
-                    $questions,
585
-                    $answers,
586
-                    $template,
587
-                    $valid_shortcodes,
588
-                    $extra_data
589
-                );
590
-                break;
522
+			default :
523
+				return $parsed;
524
+				break;
525
+		}
526
+	}
527
+    
528
+    
529
+	public function additional_primary_registration_details_shortcodes($shortcodes, $shortcode_parser)
530
+	{
531
+		$shortcodes['[PRIMARY_REGISTRANT_QUESTION_LIST]'] = __('This is used to indicate the questions and answers for the primary_registrant. It should be placed in the "[attendee_list]" field',
532
+			'event_espresso');
533
+        
534
+		return $shortcodes;
535
+	}
536
+    
537
+    
538
+	/**
539
+	 * Callback for FHEE__EE_Primary_Registration_List_Shortcodes__parser_after filter (dynamic filter).
540
+	 *
541
+	 * @param string         $parsed           The original parsed content for the shortcode
542
+	 * @param string         $shortcode        The shortcode being parsed
543
+	 * @param array          $data             The shortcode parser data array
544
+	 * @param array          $extra_data       The shortcode parser extra data array
545
+	 * @param \EE_Shortcodes $shortcode_parser Shortcode parser.
546
+	 *
547
+	 * @return string
548
+	 */
549
+	public function additional_primary_registration_details_parser(
550
+		$parsed,
551
+		$shortcode,
552
+		$data,
553
+		$extra_data,
554
+		$shortcode_parser
555
+	) {
556
+		if (array($data) && ! isset($data['data'])) {
557
+			return $parsed;
558
+		}
559
+        
560
+		$recipient = $data['data'] instanceof EE_Messages_Addressee ? $data['data'] : null;
561
+		$recipient = ! $recipient instanceof EE_Messages_Addressee && array($extra_data) && isset($extra_data['data']) && $extra_data['data'] instanceof EE_Messages_Addressee ? $extra_data['data'] : $recipient;
562
+        
563
+		if ( ! $recipient instanceof EE_Messages_Addressee) {
564
+			return $parsed;
565
+		}
566
+        
567
+		switch ($shortcode) {
568
+			case '[PRIMARY_REGISTRANT_QUESTION_LIST]' :
569
+				if ( ! $recipient->primary_att_obj instanceof EE_Attendee || ! $recipient->primary_reg_obj instanceof EE_Registration) {
570
+					return '';
571
+				}
572
+				$registration     = $recipient->primary_reg_obj;
573
+				$template         = is_array($data['template']) && isset($data['template']['question_list']) ? $data['template']['question_list'] : $extra_data['template']['question_list'];
574
+				$valid_shortcodes = array('question');
575
+				$answers          = $recipient->registrations[$registration->ID()]['ans_objs'];
576
+				$questions = isset($recipient->questions) ? $recipient->questions : array();
577
+				//if $extra_data does not have a 'data' key then let's make sure we add it and set the EE_Messages_Addressee
578
+				//object on it.
579
+				if ( ! isset( $extra_data['data'] ) ){
580
+					$extra_data['data'] = $recipient;
581
+				}
582
+				return $this->_parse_question_list_for_primary_or_recipient_registration(
583
+					$shortcode_parser,
584
+					$questions,
585
+					$answers,
586
+					$template,
587
+					$valid_shortcodes,
588
+					$extra_data
589
+				);
590
+				break;
591 591
             
592
-            default :
593
-                return $parsed;
594
-                break;
595
-        }
596
-    }
597
-    
598
-    
599
-    /**
600
-     * Takes care of registering the  message types that are only available in caffeinated EE.
601
-     *
602
-     * @since   4.3.2
603
-     *
604
-     * @return  void
605
-     */
606
-    public function register_caf_message_types()
607
-    {
608
-        //register newsletter message type
609
-        $setup_args = array(
610
-            'mtfilename'                  => 'EE_Newsletter_message_type.class.php',
611
-            'autoloadpaths'               => array(
612
-                EE_CAF_LIBRARIES . 'messages/message_type/newsletter/'
613
-            ),
614
-            'messengers_to_activate_with' => array('email'),
615
-            'messengers_to_validate_with' => array('email'),
616
-            'messengers_supporting_default_template_pack_with' => array('email')
617
-        );
618
-        EE_Register_Message_Type::register('newsletter', $setup_args);
619
-        
620
-        //register payment reminder message type
621
-        $setup_args = array(
622
-            'mtfilename'                  => 'EE_Payment_Reminder_message_type.class.php',
623
-            'autoloadpaths'               => array(EE_CAF_LIBRARIES . 'messages/message_type/payment_reminder/'),
624
-            'messengers_to_activate_with' => array('email'),
625
-            'messengers_to_validate_with' => array('email'),
626
-            'messengers_supporting_default_template_pack_with' => array('email')
627
-        );
628
-        EE_Register_Message_Type::register('payment_reminder', $setup_args);
629
-        
630
-        //register payment declined message type
631
-        $setup_args = array(
632
-            'mtfilename'                  => 'EE_Payment_Declined_message_type.class.php',
633
-            'autoloadpaths'               => array(EE_CAF_LIBRARIES . 'messages/message_type/payment_declined/'),
634
-            'messengers_to_activate_with' => array('email'),
635
-            'messengers_to_validate_with' => array('email'),
636
-            'messengers_supporting_default_template_pack_with' => array('email')
637
-        );
638
-        EE_Register_Message_Type::register('payment_declined', $setup_args);
639
-        
640
-        //register registration declined message type
641
-        $setup_args = array(
642
-            'mtfilename'                  => 'EE_Declined_Registration_message_type.class.php',
643
-            'autoloadpaths'               => array(EE_CAF_LIBRARIES . 'messages/message_type/declined_registration/'),
644
-            'messengers_to_activate_with' => array('email'),
645
-            'messengers_to_validate_with' => array('email'),
646
-            'messengers_supporting_default_template_pack_with' => array('email')
647
-        );
648
-        EE_Register_Message_Type::register('declined_registration', $setup_args);
649
-        
650
-        //register registration cancelled message type
651
-        $setup_args = array(
652
-            'mtfilename'                  => 'EE_Cancelled_Registration_message_type.class.php',
653
-            'autoloadpaths'               => array(EE_CAF_LIBRARIES . 'messages/message_type/cancelled_registration/'),
654
-            'messengers_to_activate_with' => array('email'),
655
-            'messengers_to_validate_with' => array('email'),
656
-            'messengers_supporting_default_template_pack_with' => array('email')
657
-        );
658
-        EE_Register_Message_Type::register('cancelled_registration', $setup_args);
659
-        
660
-        
661
-        //register payment failed message type
662
-        $setup_args = array(
663
-            'mtfilename'                  => 'EE_Payment_Failed_message_type.class.php',
664
-            'autoloadpaths'               => array(EE_CAF_LIBRARIES . 'messages/message_type/payment_failed/'),
665
-            'messengers_to_activate_with' => array('email'),
666
-            'messengers_to_validate_with' => array('email'),
667
-            'messengers_supporting_default_template_pack_with' => array('email')
668
-        );
669
-        EE_Register_Message_Type::register('payment_failed', $setup_args);
670
-        
671
-        //register payment declined message type
672
-        $setup_args = array(
673
-            'mtfilename'                  => 'EE_Payment_Cancelled_message_type.class.php',
674
-            'autoloadpaths'               => array(EE_CAF_LIBRARIES . 'messages/message_type/payment_cancelled/'),
675
-            'messengers_to_activate_with' => array('email'),
676
-            'messengers_to_validate_with' => array('email'),
677
-            'messengers_supporting_default_template_pack_with' => array('email')
678
-        );
679
-        EE_Register_Message_Type::register('payment_cancelled', $setup_args);
680
-    }
681
-    
682
-    
683
-    /**
684
-     * Takes care of registering the  shortcode libraries implemented with caffeinated EE and set up related items.
685
-     *
686
-     * @since   4.3.2
687
-     *
688
-     * @return void
689
-     */
690
-    public function register_caf_shortcodes()
691
-    {
692
-        $setup_args = array(
693
-            'autoloadpaths'                 => array(
694
-                EE_CAF_LIBRARIES . 'shortcodes/'
695
-            ),
696
-            'msgr_validator_callback'       => array('EE_Newsletter_Shortcodes', 'messenger_validator_config'),
697
-            'msgr_template_fields_callback' => array('EE_Newsletter_Shortcodes', 'messenger_template_fields'),
698
-            'list_type_shortcodes'          => array('[NEWSLETTER_CONTENT]')
699
-        );
700
-        EE_Register_Messages_Shortcode_Library::register('newsletter', $setup_args);
701
-    }
702
-    
703
-    
704
-    /**
705
-     * Parses a question list shortcode using given data and template
706
-     *
707
-     * @param \EE_Shortcodes $shortcode_parser
708
-     * @param EE_Question[]  $questions        An array of questions indexed by answer id.
709
-     * @param EE_Answer[]    $answers          An array of answer objects
710
-     * @param string         $template         Template content to be parsed.
711
-     * @param array          $valid_shortcodes Valid shortcodes for the template being parsed.
712
-     * @param array          $extra_data       Extra data that might be used when parsing the template.
713
-     */
714
-    protected function _parse_question_list_for_primary_or_recipient_registration(
715
-        $shortcode_parser,
716
-        $questions,
717
-        $answers,
718
-        $template,
719
-        $valid_shortcodes,
720
-        $extra_data
721
-    ) {
722
-        $question_list = '';
723
-        /** @var EEH_Parse_Shortcodes $shortcode_helper */
724
-        $shortcode_helper = $shortcode_parser->get_shortcode_helper();
725
-        foreach ($answers as $answer) {
726
-            if ($answer instanceof EE_Answer) {
727
-                //first see if the question is in our $questions array. If not then try to get from answer object.
728
-                $question = isset($questions[$answer->ID()]) ? $questions[$answer->ID()] : null;
729
-                $question = ! $question instanceof EE_Question ? $answer->question() : $question;
730
-                if (
731
-                    ! $question instanceof EE_Question
732
-                    || (
733
-                        $question instanceof EE_Question
734
-                        && $question->admin_only()
735
-                    )
736
-                ) {
737
-                    continue;
738
-                }
739
-                $question_list .= $shortcode_helper->parse_question_list_template(
740
-                    $template,
741
-                    $answer,
742
-                    $valid_shortcodes,
743
-                    $extra_data
744
-                );
745
-            }
746
-        }
747
-        
748
-        return $question_list;
749
-    }
592
+			default :
593
+				return $parsed;
594
+				break;
595
+		}
596
+	}
597
+    
598
+    
599
+	/**
600
+	 * Takes care of registering the  message types that are only available in caffeinated EE.
601
+	 *
602
+	 * @since   4.3.2
603
+	 *
604
+	 * @return  void
605
+	 */
606
+	public function register_caf_message_types()
607
+	{
608
+		//register newsletter message type
609
+		$setup_args = array(
610
+			'mtfilename'                  => 'EE_Newsletter_message_type.class.php',
611
+			'autoloadpaths'               => array(
612
+				EE_CAF_LIBRARIES . 'messages/message_type/newsletter/'
613
+			),
614
+			'messengers_to_activate_with' => array('email'),
615
+			'messengers_to_validate_with' => array('email'),
616
+			'messengers_supporting_default_template_pack_with' => array('email')
617
+		);
618
+		EE_Register_Message_Type::register('newsletter', $setup_args);
619
+        
620
+		//register payment reminder message type
621
+		$setup_args = array(
622
+			'mtfilename'                  => 'EE_Payment_Reminder_message_type.class.php',
623
+			'autoloadpaths'               => array(EE_CAF_LIBRARIES . 'messages/message_type/payment_reminder/'),
624
+			'messengers_to_activate_with' => array('email'),
625
+			'messengers_to_validate_with' => array('email'),
626
+			'messengers_supporting_default_template_pack_with' => array('email')
627
+		);
628
+		EE_Register_Message_Type::register('payment_reminder', $setup_args);
629
+        
630
+		//register payment declined message type
631
+		$setup_args = array(
632
+			'mtfilename'                  => 'EE_Payment_Declined_message_type.class.php',
633
+			'autoloadpaths'               => array(EE_CAF_LIBRARIES . 'messages/message_type/payment_declined/'),
634
+			'messengers_to_activate_with' => array('email'),
635
+			'messengers_to_validate_with' => array('email'),
636
+			'messengers_supporting_default_template_pack_with' => array('email')
637
+		);
638
+		EE_Register_Message_Type::register('payment_declined', $setup_args);
639
+        
640
+		//register registration declined message type
641
+		$setup_args = array(
642
+			'mtfilename'                  => 'EE_Declined_Registration_message_type.class.php',
643
+			'autoloadpaths'               => array(EE_CAF_LIBRARIES . 'messages/message_type/declined_registration/'),
644
+			'messengers_to_activate_with' => array('email'),
645
+			'messengers_to_validate_with' => array('email'),
646
+			'messengers_supporting_default_template_pack_with' => array('email')
647
+		);
648
+		EE_Register_Message_Type::register('declined_registration', $setup_args);
649
+        
650
+		//register registration cancelled message type
651
+		$setup_args = array(
652
+			'mtfilename'                  => 'EE_Cancelled_Registration_message_type.class.php',
653
+			'autoloadpaths'               => array(EE_CAF_LIBRARIES . 'messages/message_type/cancelled_registration/'),
654
+			'messengers_to_activate_with' => array('email'),
655
+			'messengers_to_validate_with' => array('email'),
656
+			'messengers_supporting_default_template_pack_with' => array('email')
657
+		);
658
+		EE_Register_Message_Type::register('cancelled_registration', $setup_args);
659
+        
660
+        
661
+		//register payment failed message type
662
+		$setup_args = array(
663
+			'mtfilename'                  => 'EE_Payment_Failed_message_type.class.php',
664
+			'autoloadpaths'               => array(EE_CAF_LIBRARIES . 'messages/message_type/payment_failed/'),
665
+			'messengers_to_activate_with' => array('email'),
666
+			'messengers_to_validate_with' => array('email'),
667
+			'messengers_supporting_default_template_pack_with' => array('email')
668
+		);
669
+		EE_Register_Message_Type::register('payment_failed', $setup_args);
670
+        
671
+		//register payment declined message type
672
+		$setup_args = array(
673
+			'mtfilename'                  => 'EE_Payment_Cancelled_message_type.class.php',
674
+			'autoloadpaths'               => array(EE_CAF_LIBRARIES . 'messages/message_type/payment_cancelled/'),
675
+			'messengers_to_activate_with' => array('email'),
676
+			'messengers_to_validate_with' => array('email'),
677
+			'messengers_supporting_default_template_pack_with' => array('email')
678
+		);
679
+		EE_Register_Message_Type::register('payment_cancelled', $setup_args);
680
+	}
681
+    
682
+    
683
+	/**
684
+	 * Takes care of registering the  shortcode libraries implemented with caffeinated EE and set up related items.
685
+	 *
686
+	 * @since   4.3.2
687
+	 *
688
+	 * @return void
689
+	 */
690
+	public function register_caf_shortcodes()
691
+	{
692
+		$setup_args = array(
693
+			'autoloadpaths'                 => array(
694
+				EE_CAF_LIBRARIES . 'shortcodes/'
695
+			),
696
+			'msgr_validator_callback'       => array('EE_Newsletter_Shortcodes', 'messenger_validator_config'),
697
+			'msgr_template_fields_callback' => array('EE_Newsletter_Shortcodes', 'messenger_template_fields'),
698
+			'list_type_shortcodes'          => array('[NEWSLETTER_CONTENT]')
699
+		);
700
+		EE_Register_Messages_Shortcode_Library::register('newsletter', $setup_args);
701
+	}
702
+    
703
+    
704
+	/**
705
+	 * Parses a question list shortcode using given data and template
706
+	 *
707
+	 * @param \EE_Shortcodes $shortcode_parser
708
+	 * @param EE_Question[]  $questions        An array of questions indexed by answer id.
709
+	 * @param EE_Answer[]    $answers          An array of answer objects
710
+	 * @param string         $template         Template content to be parsed.
711
+	 * @param array          $valid_shortcodes Valid shortcodes for the template being parsed.
712
+	 * @param array          $extra_data       Extra data that might be used when parsing the template.
713
+	 */
714
+	protected function _parse_question_list_for_primary_or_recipient_registration(
715
+		$shortcode_parser,
716
+		$questions,
717
+		$answers,
718
+		$template,
719
+		$valid_shortcodes,
720
+		$extra_data
721
+	) {
722
+		$question_list = '';
723
+		/** @var EEH_Parse_Shortcodes $shortcode_helper */
724
+		$shortcode_helper = $shortcode_parser->get_shortcode_helper();
725
+		foreach ($answers as $answer) {
726
+			if ($answer instanceof EE_Answer) {
727
+				//first see if the question is in our $questions array. If not then try to get from answer object.
728
+				$question = isset($questions[$answer->ID()]) ? $questions[$answer->ID()] : null;
729
+				$question = ! $question instanceof EE_Question ? $answer->question() : $question;
730
+				if (
731
+					! $question instanceof EE_Question
732
+					|| (
733
+						$question instanceof EE_Question
734
+						&& $question->admin_only()
735
+					)
736
+				) {
737
+					continue;
738
+				}
739
+				$question_list .= $shortcode_helper->parse_question_list_template(
740
+					$template,
741
+					$answer,
742
+					$valid_shortcodes,
743
+					$extra_data
744
+				);
745
+			}
746
+		}
747
+        
748
+		return $question_list;
749
+	}
750 750
 }
Please login to merge, or discard this patch.
Spacing   +22 added lines, -22 removed lines patch added patch discarded remove patch
@@ -95,7 +95,7 @@  discard block
 block discarded – undo
95 95
      */
96 96
     public function messages_autoload_paths($dir_ref)
97 97
     {
98
-        $dir_ref[] = EE_CAF_LIBRARIES . 'shortcodes/';
98
+        $dir_ref[] = EE_CAF_LIBRARIES.'shortcodes/';
99 99
         
100 100
         return $dir_ref;
101 101
     }
@@ -216,10 +216,10 @@  discard block
 block discarded – undo
216 216
         }
217 217
         
218 218
         //the template file name we're replacing contents for.
219
-        $template_file_prefix = $field . '_' . $context;
220
-        $msg_prefix           = $messenger->name . '_' . $message_type->name . '_';
219
+        $template_file_prefix = $field.'_'.$context;
220
+        $msg_prefix           = $messenger->name.'_'.$message_type->name.'_';
221 221
         
222
-        $base_path = EE_CAF_LIBRARIES . 'messages/defaults/default/';
222
+        $base_path = EE_CAF_LIBRARIES.'messages/defaults/default/';
223 223
         
224 224
         if ($messenger->name == 'email' && $message_type->name == 'registration') {
225 225
             
@@ -228,17 +228,17 @@  discard block
 block discarded – undo
228 228
                 case 'question_list_admin' :
229 229
                 case 'question_list_attendee' :
230 230
                 case 'question_list_primary_attendee' :
231
-                    $path     = $base_path . $msg_prefix . 'question_list.template.php';
231
+                    $path     = $base_path.$msg_prefix.'question_list.template.php';
232 232
                     $contents = EEH_Template::display_template($path, array(), true);
233 233
                     break;
234 234
                 
235 235
                 case 'attendee_list_primary_attendee' :
236
-                    $path     = $base_path . $msg_prefix . 'attendee_list.template.php';
236
+                    $path     = $base_path.$msg_prefix.'attendee_list.template.php';
237 237
                     $contents = EEH_Template::display_template($path, array(), true);
238 238
                     break;
239 239
                 
240 240
                 case 'attendee_list_admin' :
241
-                    $path     = $base_path . $msg_prefix . 'attendee_list_admin.template.php';
241
+                    $path     = $base_path.$msg_prefix.'attendee_list_admin.template.php';
242 242
                     $contents = EEH_Template::display_template($path,
243 243
                         array(), true);
244 244
                     break;
@@ -248,7 +248,7 @@  discard block
 block discarded – undo
248 248
                     break;
249 249
                 
250 250
                 case 'event_list_attendee' :
251
-                    $path     = $base_path . $msg_prefix . 'event_list_attendee.template.php';
251
+                    $path     = $base_path.$msg_prefix.'event_list_attendee.template.php';
252 252
                     $contents = EEH_Template::display_template($path, array(), true);
253 253
                     break;
254 254
             }
@@ -256,24 +256,24 @@  discard block
 block discarded – undo
256 256
             switch ($template_file_prefix) {
257 257
                 
258 258
                 case 'content_attendee' :
259
-                    $path     = $base_path . $msg_prefix . 'content.template.php';
259
+                    $path     = $base_path.$msg_prefix.'content.template.php';
260 260
                     $contents = EEH_Template::display_template($path, array(), true);
261 261
                     break;
262 262
                 
263 263
                 case 'newsletter_content_attendee' :
264
-                    $path     = $base_path . $msg_prefix . 'newsletter_content.template.php';
264
+                    $path     = $base_path.$msg_prefix.'newsletter_content.template.php';
265 265
                     $contents = EEH_Template::display_template($path, array(), true);
266 266
                     break;
267 267
                 
268 268
                 case 'newsletter_subject_attendee' :
269
-                    $path     = $base_path . $msg_prefix . 'subject.template.php';
269
+                    $path     = $base_path.$msg_prefix.'subject.template.php';
270 270
                     $contents = EEH_Template::display_template($path, array(), true);
271 271
                     break;
272 272
             }
273 273
         } elseif ($messenger->name == 'html' && $message_type->name == 'receipt') {
274 274
             switch ($template_file_prefix) {
275 275
                 case 'attendee_list_purchaser' :
276
-                    $path     = $base_path . $msg_prefix . 'attendee_list.template.php';
276
+                    $path     = $base_path.$msg_prefix.'attendee_list.template.php';
277 277
                     $contents = EEH_Template::display_template($path, array(), true);
278 278
                     break;
279 279
             }
@@ -505,7 +505,7 @@  discard block
 block discarded – undo
505 505
                 
506 506
                 //if $extra_data does not have a 'data' key then let's make sure we add it and set the EE_Messages_Addressee
507 507
                 //object on it.
508
-                if ( ! isset( $extra_data['data'] ) ) {
508
+                if ( ! isset($extra_data['data'])) {
509 509
                     $extra_data['data'] = $recipient;
510 510
                 }
511 511
                 
@@ -576,7 +576,7 @@  discard block
 block discarded – undo
576 576
                 $questions = isset($recipient->questions) ? $recipient->questions : array();
577 577
                 //if $extra_data does not have a 'data' key then let's make sure we add it and set the EE_Messages_Addressee
578 578
                 //object on it.
579
-                if ( ! isset( $extra_data['data'] ) ){
579
+                if ( ! isset($extra_data['data'])) {
580 580
                     $extra_data['data'] = $recipient;
581 581
                 }
582 582
                 return $this->_parse_question_list_for_primary_or_recipient_registration(
@@ -609,7 +609,7 @@  discard block
 block discarded – undo
609 609
         $setup_args = array(
610 610
             'mtfilename'                  => 'EE_Newsletter_message_type.class.php',
611 611
             'autoloadpaths'               => array(
612
-                EE_CAF_LIBRARIES . 'messages/message_type/newsletter/'
612
+                EE_CAF_LIBRARIES.'messages/message_type/newsletter/'
613 613
             ),
614 614
             'messengers_to_activate_with' => array('email'),
615 615
             'messengers_to_validate_with' => array('email'),
@@ -620,7 +620,7 @@  discard block
 block discarded – undo
620 620
         //register payment reminder message type
621 621
         $setup_args = array(
622 622
             'mtfilename'                  => 'EE_Payment_Reminder_message_type.class.php',
623
-            'autoloadpaths'               => array(EE_CAF_LIBRARIES . 'messages/message_type/payment_reminder/'),
623
+            'autoloadpaths'               => array(EE_CAF_LIBRARIES.'messages/message_type/payment_reminder/'),
624 624
             'messengers_to_activate_with' => array('email'),
625 625
             'messengers_to_validate_with' => array('email'),
626 626
             'messengers_supporting_default_template_pack_with' => array('email')
@@ -630,7 +630,7 @@  discard block
 block discarded – undo
630 630
         //register payment declined message type
631 631
         $setup_args = array(
632 632
             'mtfilename'                  => 'EE_Payment_Declined_message_type.class.php',
633
-            'autoloadpaths'               => array(EE_CAF_LIBRARIES . 'messages/message_type/payment_declined/'),
633
+            'autoloadpaths'               => array(EE_CAF_LIBRARIES.'messages/message_type/payment_declined/'),
634 634
             'messengers_to_activate_with' => array('email'),
635 635
             'messengers_to_validate_with' => array('email'),
636 636
             'messengers_supporting_default_template_pack_with' => array('email')
@@ -640,7 +640,7 @@  discard block
 block discarded – undo
640 640
         //register registration declined message type
641 641
         $setup_args = array(
642 642
             'mtfilename'                  => 'EE_Declined_Registration_message_type.class.php',
643
-            'autoloadpaths'               => array(EE_CAF_LIBRARIES . 'messages/message_type/declined_registration/'),
643
+            'autoloadpaths'               => array(EE_CAF_LIBRARIES.'messages/message_type/declined_registration/'),
644 644
             'messengers_to_activate_with' => array('email'),
645 645
             'messengers_to_validate_with' => array('email'),
646 646
             'messengers_supporting_default_template_pack_with' => array('email')
@@ -650,7 +650,7 @@  discard block
 block discarded – undo
650 650
         //register registration cancelled message type
651 651
         $setup_args = array(
652 652
             'mtfilename'                  => 'EE_Cancelled_Registration_message_type.class.php',
653
-            'autoloadpaths'               => array(EE_CAF_LIBRARIES . 'messages/message_type/cancelled_registration/'),
653
+            'autoloadpaths'               => array(EE_CAF_LIBRARIES.'messages/message_type/cancelled_registration/'),
654 654
             'messengers_to_activate_with' => array('email'),
655 655
             'messengers_to_validate_with' => array('email'),
656 656
             'messengers_supporting_default_template_pack_with' => array('email')
@@ -661,7 +661,7 @@  discard block
 block discarded – undo
661 661
         //register payment failed message type
662 662
         $setup_args = array(
663 663
             'mtfilename'                  => 'EE_Payment_Failed_message_type.class.php',
664
-            'autoloadpaths'               => array(EE_CAF_LIBRARIES . 'messages/message_type/payment_failed/'),
664
+            'autoloadpaths'               => array(EE_CAF_LIBRARIES.'messages/message_type/payment_failed/'),
665 665
             'messengers_to_activate_with' => array('email'),
666 666
             'messengers_to_validate_with' => array('email'),
667 667
             'messengers_supporting_default_template_pack_with' => array('email')
@@ -671,7 +671,7 @@  discard block
 block discarded – undo
671 671
         //register payment declined message type
672 672
         $setup_args = array(
673 673
             'mtfilename'                  => 'EE_Payment_Cancelled_message_type.class.php',
674
-            'autoloadpaths'               => array(EE_CAF_LIBRARIES . 'messages/message_type/payment_cancelled/'),
674
+            'autoloadpaths'               => array(EE_CAF_LIBRARIES.'messages/message_type/payment_cancelled/'),
675 675
             'messengers_to_activate_with' => array('email'),
676 676
             'messengers_to_validate_with' => array('email'),
677 677
             'messengers_supporting_default_template_pack_with' => array('email')
@@ -691,7 +691,7 @@  discard block
 block discarded – undo
691 691
     {
692 692
         $setup_args = array(
693 693
             'autoloadpaths'                 => array(
694
-                EE_CAF_LIBRARIES . 'shortcodes/'
694
+                EE_CAF_LIBRARIES.'shortcodes/'
695 695
             ),
696 696
             'msgr_validator_callback'       => array('EE_Newsletter_Shortcodes', 'messenger_validator_config'),
697 697
             'msgr_template_fields_callback' => array('EE_Newsletter_Shortcodes', 'messenger_template_fields'),
Please login to merge, or discard this patch.
core/db_models/EEM_Attendee.model.php 2 patches
Indentation   +316 added lines, -316 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php if ( ! defined('EVENT_ESPRESSO_VERSION')) {
2
-    exit('No direct script access allowed');
2
+	exit('No direct script access allowed');
3 3
 }
4 4
 require_once(EE_MODELS . 'EEM_Base.model.php');
5 5
 
@@ -15,329 +15,329 @@  discard block
 block discarded – undo
15 15
 class EEM_Attendee extends EEM_CPT_Base
16 16
 {
17 17
 
18
-    // private instance of the Attendee object
19
-    protected static $_instance = null;
18
+	// private instance of the Attendee object
19
+	protected static $_instance = null;
20 20
 
21
-    /**
22
-     * QST_system for questions are strings not ints now,
23
-     * so these constants are deprecated.
24
-     * Please instead use the EEM_Attendee::system_question_* constants
25
-     *
26
-     * @deprecated
27
-     */
28
-    const fname_question_id = 1;
21
+	/**
22
+	 * QST_system for questions are strings not ints now,
23
+	 * so these constants are deprecated.
24
+	 * Please instead use the EEM_Attendee::system_question_* constants
25
+	 *
26
+	 * @deprecated
27
+	 */
28
+	const fname_question_id = 1;
29 29
 
30
-    /**
31
-     * @deprecated
32
-     */
33
-    const lname_question_id = 2;
30
+	/**
31
+	 * @deprecated
32
+	 */
33
+	const lname_question_id = 2;
34 34
 
35 35
 
36
-    /**
37
-     * @deprecated
38
-     */
39
-    const email_question_id = 3;
36
+	/**
37
+	 * @deprecated
38
+	 */
39
+	const email_question_id = 3;
40 40
 
41 41
 
42
-    /**
43
-     * @deprecated
44
-     */
45
-    const address_question_id = 4;
42
+	/**
43
+	 * @deprecated
44
+	 */
45
+	const address_question_id = 4;
46 46
 
47 47
 
48
-    /**
49
-     * @deprecated
50
-     */
51
-    const address2_question_id = 5;
52
-
53
-
54
-    /**
55
-     * @deprecated
56
-     */
57
-    const city_question_id = 6;
58
-
59
-
60
-    /**
61
-     * @deprecated
62
-     */
63
-    const state_question_id = 7;
64
-
65
-
66
-    /**
67
-     * @deprecated
68
-     */
69
-    const country_question_id = 8;
70
-
71
-
72
-    /**
73
-     * @deprecated
74
-     */
75
-    const zip_question_id = 9;
76
-
77
-
78
-    /**
79
-     * @deprecated
80
-     */
81
-    const phone_question_id = 10;
82
-
83
-    /**
84
-     * When looking for questions that correspond to attendee fields,
85
-     * look for the question with this QST_system value.
86
-     * These replace the old constants like EEM_Attendee::*_question_id
87
-     */
88
-    const system_question_fname    = 'fname';
89
-
90
-    const system_question_lname    = 'lname';
91
-
92
-    const system_question_email    = 'email';
93
-
94
-    const system_question_address  = 'address';
95
-
96
-    const system_question_address2 = 'address2';
97
-
98
-    const system_question_city     = 'city';
99
-
100
-    const system_question_state    = 'state';
101
-
102
-    const system_question_country  = 'country';
103
-
104
-    const system_question_zip      = 'zip';
105
-
106
-    const system_question_phone    = 'phone';
107
-
108
-    /**
109
-     * Keys are all the EEM_Attendee::system_question_* constants, which are
110
-     * also all the values of QST_system in the questions table, and values
111
-     * are their corresponding Attendee field names
112
-     *
113
-     * @var array
114
-     */
115
-    protected $_system_question_to_attendee_field_name = array(
116
-        EEM_Attendee::system_question_fname    => 'ATT_fname',
117
-        EEM_Attendee::system_question_lname    => 'ATT_lname',
118
-        EEM_Attendee::system_question_email    => 'ATT_email',
119
-        EEM_Attendee::system_question_address  => 'ATT_address',
120
-        EEM_Attendee::system_question_address2 => 'ATT_address2',
121
-        EEM_Attendee::system_question_city     => 'ATT_city',
122
-        EEM_Attendee::system_question_state    => 'STA_ID',
123
-        EEM_Attendee::system_question_country  => 'CNT_ISO',
124
-        EEM_Attendee::system_question_zip      => 'ATT_zip',
125
-        EEM_Attendee::system_question_phone    => 'ATT_phone',
126
-    );
127
-
128
-
129
-
130
-    /**
131
-     *        private constructor to prevent direct creation
132
-     *
133
-     * @Constructor
134
-     * @access protected
135
-     * @param null $timezone
136
-     */
137
-    protected function __construct($timezone = null)
138
-    {
139
-        $this->singular_item = __('Attendee', 'event_espresso');
140
-        $this->plural_item = __('Attendees', 'event_espresso');
141
-        $this->_tables = array(
142
-            'Attendee_CPT'  => new EE_Primary_Table('posts', 'ID'),
143
-            'Attendee_Meta' => new EE_Secondary_Table('esp_attendee_meta', 'ATTM_ID', 'ATT_ID'),
144
-        );
145
-        $this->_fields = array(
146
-            'Attendee_CPT'  => array(
147
-                'ATT_ID'        => new EE_Primary_Key_Int_Field('ID', __("Attendee ID", "event_espresso")),
148
-                'ATT_full_name' => new EE_Plain_Text_Field('post_title', __("Attendee Full Name", "event_espresso"),
149
-                    false, __("Unknown", "event_espresso")),
150
-                'ATT_bio'       => new EE_Post_Content_Field('post_content', __("Attendee Biography", "event_espresso"),
151
-                    false, __("No Biography Provided", "event_espresso")),
152
-                'ATT_slug'      => new EE_Slug_Field('post_name', __("Attendee URL Slug", "event_espresso"), false),
153
-                'ATT_created'   => new EE_Datetime_Field('post_date', __("Time Attendee Created", "event_espresso"),
154
-                    false, EE_Datetime_Field::now),
155
-                'ATT_short_bio' => new EE_Simple_HTML_Field('post_excerpt',
156
-                    __("Attendee Short Biography", "event_espresso"), true,
157
-                    __("No Biography Provided", "event_espresso")),
158
-                'ATT_modified'  => new EE_Datetime_Field('post_modified',
159
-                    __("Time Attendee Last Modified", "event_espresso"), false, EE_Datetime_Field::now),
160
-                'ATT_author'    => new EE_WP_User_Field('post_author',
161
-                    __("Creator ID of the first Event attended", "event_espresso"), false),
162
-                'ATT_parent'    => new EE_DB_Only_Int_Field('post_parent',
163
-                    __("Parent Attendee (unused)", "event_espresso"), false, 0),
164
-                'post_type'     => new EE_WP_Post_Type_Field('espresso_attendees'),
165
-                // EE_DB_Only_Text_Field('post_type', __("Post Type of Attendee", "event_espresso"), false,'espresso_attendees'),
166
-                'status'        => new EE_WP_Post_Status_Field('post_status', __('Attendee Status', 'event_espresso'),
167
-                    false, 'publish'),
168
-            ),
169
-            'Attendee_Meta' => array(
170
-                'ATTM_ID'      => new EE_DB_Only_Int_Field('ATTM_ID', __('Attendee Meta Row ID', 'event_espresso'),
171
-                    false),
172
-                'ATT_ID_fk'    => new EE_DB_Only_Int_Field('ATT_ID',
173
-                    __("Foreign Key to Attendee in Post Table", "event_espresso"), false),
174
-                'ATT_fname'    => new EE_Plain_Text_Field('ATT_fname', __('First Name', 'event_espresso'), true, ''),
175
-                'ATT_lname'    => new EE_Plain_Text_Field('ATT_lname', __('Last Name', 'event_espresso'), true, ''),
176
-                'ATT_address'  => new EE_Plain_Text_Field('ATT_address', __('Address Part 1', 'event_espresso'), true,
177
-                    ''),
178
-                'ATT_address2' => new EE_Plain_Text_Field('ATT_address2', __('Address Part 2', 'event_espresso'), true,
179
-                    ''),
180
-                'ATT_city'     => new EE_Plain_Text_Field('ATT_city', __('City', 'event_espresso'), true, ''),
181
-                'STA_ID'       => new EE_Foreign_Key_Int_Field('STA_ID', __('State', 'event_espresso'), true, 0,
182
-                    'State'),
183
-                'CNT_ISO'      => new EE_Foreign_Key_String_Field('CNT_ISO', __('Country', 'event_espresso'), true, '',
184
-                    'Country'),
185
-                'ATT_zip'      => new EE_Plain_Text_Field('ATT_zip', __('ZIP/Postal Code', 'event_espresso'), true, ''),
186
-                'ATT_email'    => new EE_Email_Field('ATT_email', __('Email Address', 'event_espresso'), true, ''),
187
-                'ATT_phone'    => new EE_Plain_Text_Field('ATT_phone', __('Phone', 'event_espresso'), true, ''),
188
-            ),
189
-        );
190
-        $this->_model_relations = array(
191
-            'Registration'      => new EE_Has_Many_Relation(),
192
-            'State'             => new EE_Belongs_To_Relation(),
193
-            'Country'           => new EE_Belongs_To_Relation(),
194
-            'Event'             => new EE_HABTM_Relation('Registration', false),
195
-            'WP_User'           => new EE_Belongs_To_Relation(),
196
-            'Message'           => new EE_Has_Many_Any_Relation(false),
197
-            //allow deletion of attendees even if they have messages in the queue for them.
198
-            'Term_Relationship' => new EE_Has_Many_Relation(),
199
-            'Term_Taxonomy'     => new EE_HABTM_Relation('Term_Relationship'),
200
-        );
201
-        $this->_caps_slug = 'contacts';
202
-        parent::__construct($timezone);
203
-    }
204
-
205
-
206
-
207
-    /**
208
-     * Gets the name of the field on the attendee model corresponding to the system question string
209
-     * which should be one of the keys from EEM_Attendee::_system_question_to_attendee_field_name
210
-     *
211
-     * @param string $system_question_string
212
-     * @return string|null if not found
213
-     */
214
-    public function get_attendee_field_for_system_question($system_question_string)
215
-    {
216
-        return isset($this->_system_question_to_attendee_field_name[$system_question_string])
217
-            ? $this->_system_question_to_attendee_field_name[$system_question_string] : null;
218
-    }
219
-
220
-
221
-
222
-    /**
223
-     * Gets mapping from esp_question.QST_system values to their corresponding attendee field names
224
-     * @return array
225
-     */
226
-    public function system_question_to_attendee_field_mapping(){
227
-        return $this->_system_question_to_attendee_field_name;
228
-    }
229
-
230
-
231
-
232
-    /**
233
-     * Gets all the attendees for a transaction (by using the esp_registration as a join table)
234
-     *
235
-     * @param EE_Transaction /int $transaction_id_or_obj EE_Transaction or its ID
236
-     * @return EE_Attendee[]
237
-     */
238
-    public function get_attendees_for_transaction($transaction_id_or_obj)
239
-    {
240
-        return $this->get_all(array(
241
-            array(
242
-                'Registration.Transaction.TXN_ID' => $transaction_id_or_obj instanceof EE_Transaction
243
-                    ? $transaction_id_or_obj->ID() : $transaction_id_or_obj,
244
-            ),
245
-        ));
246
-    }
247
-
248
-
249
-
250
-    /**
251
-     *        retrieve  a single attendee from db via their ID
252
-     *
253
-     * @access        public
254
-     * @param        $ATT_ID
255
-     * @return        mixed        array on success, FALSE on fail
256
-     * @deprecated
257
-     */
258
-    public function get_attendee_by_ID($ATT_ID = false)
259
-    {
260
-        // retrieve a particular EE_Attendee
261
-        return $this->get_one_by_ID($ATT_ID);
262
-    }
263
-
264
-
265
-
266
-    /**
267
-     *        retrieve  a single attendee from db via their ID
268
-     *
269
-     * @access        public
270
-     * @param        array $where_cols_n_values
271
-     * @return        mixed        array on success, FALSE on fail
272
-     */
273
-    public function get_attendee($where_cols_n_values = array())
274
-    {
275
-        if (empty($where_cols_n_values)) {
276
-            return false;
277
-        }
278
-        $attendee = $this->get_all(array($where_cols_n_values));
279
-        if ( ! empty($attendee)) {
280
-            return array_shift($attendee);
281
-        } else {
282
-            return false;
283
-        }
284
-    }
285
-
286
-
287
-
288
-    /**
289
-     *        Search for an existing Attendee record in the DB
290
-     *
291
-     * @access        public
292
-     * @param array $where_cols_n_values
293
-     * @return bool|mixed
294
-     */
295
-    public function find_existing_attendee($where_cols_n_values = null)
296
-    {
297
-        // search by combo of first and last names plus the email address
298
-        $attendee_data_keys = array(
299
-            'ATT_fname' => $this->_ATT_fname,
300
-            'ATT_lname' => $this->_ATT_lname,
301
-            'ATT_email' => $this->_ATT_email,
302
-        );
303
-        // no search params means attendee object already exists.
304
-        $where_cols_n_values = is_array($where_cols_n_values) && ! empty($where_cols_n_values) ? $where_cols_n_values
305
-            : $attendee_data_keys;
306
-        $valid_data = true;
307
-        // check for required values
308
-        $valid_data = isset($where_cols_n_values['ATT_fname']) && ! empty($where_cols_n_values['ATT_fname'])
309
-            ? $valid_data : false;
310
-        $valid_data = isset($where_cols_n_values['ATT_lname']) && ! empty($where_cols_n_values['ATT_lname'])
311
-            ? $valid_data : false;
312
-        $valid_data = isset($where_cols_n_values['ATT_email']) && ! empty($where_cols_n_values['ATT_email'])
313
-            ? $valid_data : false;
314
-        if ($valid_data) {
315
-            $attendee = $this->get_attendee($where_cols_n_values);
316
-            if ($attendee instanceof EE_Attendee) {
317
-                return $attendee;
318
-            }
319
-        }
320
-        return false;
321
-    }
322
-
323
-
324
-
325
-    /**
326
-     * Takes an incoming array of EE_Registration ids and sends back a list of corresponding non duplicate
327
-     * EE_Attendee objects.
328
-     *
329
-     * @since    4.3.0
330
-     * @param  array $ids array of EE_Registration ids
331
-     * @return  EE_Attendee[]
332
-     */
333
-    public function get_array_of_contacts_from_reg_ids($ids)
334
-    {
335
-        $ids = (array)$ids;
336
-        $_where = array(
337
-            'Registration.REG_ID' => array('in', $ids),
338
-        );
339
-        return $this->get_all(array($_where));
340
-    }
48
+	/**
49
+	 * @deprecated
50
+	 */
51
+	const address2_question_id = 5;
52
+
53
+
54
+	/**
55
+	 * @deprecated
56
+	 */
57
+	const city_question_id = 6;
58
+
59
+
60
+	/**
61
+	 * @deprecated
62
+	 */
63
+	const state_question_id = 7;
64
+
65
+
66
+	/**
67
+	 * @deprecated
68
+	 */
69
+	const country_question_id = 8;
70
+
71
+
72
+	/**
73
+	 * @deprecated
74
+	 */
75
+	const zip_question_id = 9;
76
+
77
+
78
+	/**
79
+	 * @deprecated
80
+	 */
81
+	const phone_question_id = 10;
82
+
83
+	/**
84
+	 * When looking for questions that correspond to attendee fields,
85
+	 * look for the question with this QST_system value.
86
+	 * These replace the old constants like EEM_Attendee::*_question_id
87
+	 */
88
+	const system_question_fname    = 'fname';
89
+
90
+	const system_question_lname    = 'lname';
91
+
92
+	const system_question_email    = 'email';
93
+
94
+	const system_question_address  = 'address';
95
+
96
+	const system_question_address2 = 'address2';
97
+
98
+	const system_question_city     = 'city';
99
+
100
+	const system_question_state    = 'state';
101
+
102
+	const system_question_country  = 'country';
103
+
104
+	const system_question_zip      = 'zip';
105
+
106
+	const system_question_phone    = 'phone';
107
+
108
+	/**
109
+	 * Keys are all the EEM_Attendee::system_question_* constants, which are
110
+	 * also all the values of QST_system in the questions table, and values
111
+	 * are their corresponding Attendee field names
112
+	 *
113
+	 * @var array
114
+	 */
115
+	protected $_system_question_to_attendee_field_name = array(
116
+		EEM_Attendee::system_question_fname    => 'ATT_fname',
117
+		EEM_Attendee::system_question_lname    => 'ATT_lname',
118
+		EEM_Attendee::system_question_email    => 'ATT_email',
119
+		EEM_Attendee::system_question_address  => 'ATT_address',
120
+		EEM_Attendee::system_question_address2 => 'ATT_address2',
121
+		EEM_Attendee::system_question_city     => 'ATT_city',
122
+		EEM_Attendee::system_question_state    => 'STA_ID',
123
+		EEM_Attendee::system_question_country  => 'CNT_ISO',
124
+		EEM_Attendee::system_question_zip      => 'ATT_zip',
125
+		EEM_Attendee::system_question_phone    => 'ATT_phone',
126
+	);
127
+
128
+
129
+
130
+	/**
131
+	 *        private constructor to prevent direct creation
132
+	 *
133
+	 * @Constructor
134
+	 * @access protected
135
+	 * @param null $timezone
136
+	 */
137
+	protected function __construct($timezone = null)
138
+	{
139
+		$this->singular_item = __('Attendee', 'event_espresso');
140
+		$this->plural_item = __('Attendees', 'event_espresso');
141
+		$this->_tables = array(
142
+			'Attendee_CPT'  => new EE_Primary_Table('posts', 'ID'),
143
+			'Attendee_Meta' => new EE_Secondary_Table('esp_attendee_meta', 'ATTM_ID', 'ATT_ID'),
144
+		);
145
+		$this->_fields = array(
146
+			'Attendee_CPT'  => array(
147
+				'ATT_ID'        => new EE_Primary_Key_Int_Field('ID', __("Attendee ID", "event_espresso")),
148
+				'ATT_full_name' => new EE_Plain_Text_Field('post_title', __("Attendee Full Name", "event_espresso"),
149
+					false, __("Unknown", "event_espresso")),
150
+				'ATT_bio'       => new EE_Post_Content_Field('post_content', __("Attendee Biography", "event_espresso"),
151
+					false, __("No Biography Provided", "event_espresso")),
152
+				'ATT_slug'      => new EE_Slug_Field('post_name', __("Attendee URL Slug", "event_espresso"), false),
153
+				'ATT_created'   => new EE_Datetime_Field('post_date', __("Time Attendee Created", "event_espresso"),
154
+					false, EE_Datetime_Field::now),
155
+				'ATT_short_bio' => new EE_Simple_HTML_Field('post_excerpt',
156
+					__("Attendee Short Biography", "event_espresso"), true,
157
+					__("No Biography Provided", "event_espresso")),
158
+				'ATT_modified'  => new EE_Datetime_Field('post_modified',
159
+					__("Time Attendee Last Modified", "event_espresso"), false, EE_Datetime_Field::now),
160
+				'ATT_author'    => new EE_WP_User_Field('post_author',
161
+					__("Creator ID of the first Event attended", "event_espresso"), false),
162
+				'ATT_parent'    => new EE_DB_Only_Int_Field('post_parent',
163
+					__("Parent Attendee (unused)", "event_espresso"), false, 0),
164
+				'post_type'     => new EE_WP_Post_Type_Field('espresso_attendees'),
165
+				// EE_DB_Only_Text_Field('post_type', __("Post Type of Attendee", "event_espresso"), false,'espresso_attendees'),
166
+				'status'        => new EE_WP_Post_Status_Field('post_status', __('Attendee Status', 'event_espresso'),
167
+					false, 'publish'),
168
+			),
169
+			'Attendee_Meta' => array(
170
+				'ATTM_ID'      => new EE_DB_Only_Int_Field('ATTM_ID', __('Attendee Meta Row ID', 'event_espresso'),
171
+					false),
172
+				'ATT_ID_fk'    => new EE_DB_Only_Int_Field('ATT_ID',
173
+					__("Foreign Key to Attendee in Post Table", "event_espresso"), false),
174
+				'ATT_fname'    => new EE_Plain_Text_Field('ATT_fname', __('First Name', 'event_espresso'), true, ''),
175
+				'ATT_lname'    => new EE_Plain_Text_Field('ATT_lname', __('Last Name', 'event_espresso'), true, ''),
176
+				'ATT_address'  => new EE_Plain_Text_Field('ATT_address', __('Address Part 1', 'event_espresso'), true,
177
+					''),
178
+				'ATT_address2' => new EE_Plain_Text_Field('ATT_address2', __('Address Part 2', 'event_espresso'), true,
179
+					''),
180
+				'ATT_city'     => new EE_Plain_Text_Field('ATT_city', __('City', 'event_espresso'), true, ''),
181
+				'STA_ID'       => new EE_Foreign_Key_Int_Field('STA_ID', __('State', 'event_espresso'), true, 0,
182
+					'State'),
183
+				'CNT_ISO'      => new EE_Foreign_Key_String_Field('CNT_ISO', __('Country', 'event_espresso'), true, '',
184
+					'Country'),
185
+				'ATT_zip'      => new EE_Plain_Text_Field('ATT_zip', __('ZIP/Postal Code', 'event_espresso'), true, ''),
186
+				'ATT_email'    => new EE_Email_Field('ATT_email', __('Email Address', 'event_espresso'), true, ''),
187
+				'ATT_phone'    => new EE_Plain_Text_Field('ATT_phone', __('Phone', 'event_espresso'), true, ''),
188
+			),
189
+		);
190
+		$this->_model_relations = array(
191
+			'Registration'      => new EE_Has_Many_Relation(),
192
+			'State'             => new EE_Belongs_To_Relation(),
193
+			'Country'           => new EE_Belongs_To_Relation(),
194
+			'Event'             => new EE_HABTM_Relation('Registration', false),
195
+			'WP_User'           => new EE_Belongs_To_Relation(),
196
+			'Message'           => new EE_Has_Many_Any_Relation(false),
197
+			//allow deletion of attendees even if they have messages in the queue for them.
198
+			'Term_Relationship' => new EE_Has_Many_Relation(),
199
+			'Term_Taxonomy'     => new EE_HABTM_Relation('Term_Relationship'),
200
+		);
201
+		$this->_caps_slug = 'contacts';
202
+		parent::__construct($timezone);
203
+	}
204
+
205
+
206
+
207
+	/**
208
+	 * Gets the name of the field on the attendee model corresponding to the system question string
209
+	 * which should be one of the keys from EEM_Attendee::_system_question_to_attendee_field_name
210
+	 *
211
+	 * @param string $system_question_string
212
+	 * @return string|null if not found
213
+	 */
214
+	public function get_attendee_field_for_system_question($system_question_string)
215
+	{
216
+		return isset($this->_system_question_to_attendee_field_name[$system_question_string])
217
+			? $this->_system_question_to_attendee_field_name[$system_question_string] : null;
218
+	}
219
+
220
+
221
+
222
+	/**
223
+	 * Gets mapping from esp_question.QST_system values to their corresponding attendee field names
224
+	 * @return array
225
+	 */
226
+	public function system_question_to_attendee_field_mapping(){
227
+		return $this->_system_question_to_attendee_field_name;
228
+	}
229
+
230
+
231
+
232
+	/**
233
+	 * Gets all the attendees for a transaction (by using the esp_registration as a join table)
234
+	 *
235
+	 * @param EE_Transaction /int $transaction_id_or_obj EE_Transaction or its ID
236
+	 * @return EE_Attendee[]
237
+	 */
238
+	public function get_attendees_for_transaction($transaction_id_or_obj)
239
+	{
240
+		return $this->get_all(array(
241
+			array(
242
+				'Registration.Transaction.TXN_ID' => $transaction_id_or_obj instanceof EE_Transaction
243
+					? $transaction_id_or_obj->ID() : $transaction_id_or_obj,
244
+			),
245
+		));
246
+	}
247
+
248
+
249
+
250
+	/**
251
+	 *        retrieve  a single attendee from db via their ID
252
+	 *
253
+	 * @access        public
254
+	 * @param        $ATT_ID
255
+	 * @return        mixed        array on success, FALSE on fail
256
+	 * @deprecated
257
+	 */
258
+	public function get_attendee_by_ID($ATT_ID = false)
259
+	{
260
+		// retrieve a particular EE_Attendee
261
+		return $this->get_one_by_ID($ATT_ID);
262
+	}
263
+
264
+
265
+
266
+	/**
267
+	 *        retrieve  a single attendee from db via their ID
268
+	 *
269
+	 * @access        public
270
+	 * @param        array $where_cols_n_values
271
+	 * @return        mixed        array on success, FALSE on fail
272
+	 */
273
+	public function get_attendee($where_cols_n_values = array())
274
+	{
275
+		if (empty($where_cols_n_values)) {
276
+			return false;
277
+		}
278
+		$attendee = $this->get_all(array($where_cols_n_values));
279
+		if ( ! empty($attendee)) {
280
+			return array_shift($attendee);
281
+		} else {
282
+			return false;
283
+		}
284
+	}
285
+
286
+
287
+
288
+	/**
289
+	 *        Search for an existing Attendee record in the DB
290
+	 *
291
+	 * @access        public
292
+	 * @param array $where_cols_n_values
293
+	 * @return bool|mixed
294
+	 */
295
+	public function find_existing_attendee($where_cols_n_values = null)
296
+	{
297
+		// search by combo of first and last names plus the email address
298
+		$attendee_data_keys = array(
299
+			'ATT_fname' => $this->_ATT_fname,
300
+			'ATT_lname' => $this->_ATT_lname,
301
+			'ATT_email' => $this->_ATT_email,
302
+		);
303
+		// no search params means attendee object already exists.
304
+		$where_cols_n_values = is_array($where_cols_n_values) && ! empty($where_cols_n_values) ? $where_cols_n_values
305
+			: $attendee_data_keys;
306
+		$valid_data = true;
307
+		// check for required values
308
+		$valid_data = isset($where_cols_n_values['ATT_fname']) && ! empty($where_cols_n_values['ATT_fname'])
309
+			? $valid_data : false;
310
+		$valid_data = isset($where_cols_n_values['ATT_lname']) && ! empty($where_cols_n_values['ATT_lname'])
311
+			? $valid_data : false;
312
+		$valid_data = isset($where_cols_n_values['ATT_email']) && ! empty($where_cols_n_values['ATT_email'])
313
+			? $valid_data : false;
314
+		if ($valid_data) {
315
+			$attendee = $this->get_attendee($where_cols_n_values);
316
+			if ($attendee instanceof EE_Attendee) {
317
+				return $attendee;
318
+			}
319
+		}
320
+		return false;
321
+	}
322
+
323
+
324
+
325
+	/**
326
+	 * Takes an incoming array of EE_Registration ids and sends back a list of corresponding non duplicate
327
+	 * EE_Attendee objects.
328
+	 *
329
+	 * @since    4.3.0
330
+	 * @param  array $ids array of EE_Registration ids
331
+	 * @return  EE_Attendee[]
332
+	 */
333
+	public function get_array_of_contacts_from_reg_ids($ids)
334
+	{
335
+		$ids = (array)$ids;
336
+		$_where = array(
337
+			'Registration.REG_ID' => array('in', $ids),
338
+		);
339
+		return $this->get_all(array($_where));
340
+	}
341 341
 
342 342
 
343 343
 }
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -1,7 +1,7 @@  discard block
 block discarded – undo
1 1
 <?php if ( ! defined('EVENT_ESPRESSO_VERSION')) {
2 2
     exit('No direct script access allowed');
3 3
 }
4
-require_once(EE_MODELS . 'EEM_Base.model.php');
4
+require_once(EE_MODELS.'EEM_Base.model.php');
5 5
 
6 6
 
7 7
 
@@ -223,7 +223,7 @@  discard block
 block discarded – undo
223 223
      * Gets mapping from esp_question.QST_system values to their corresponding attendee field names
224 224
      * @return array
225 225
      */
226
-    public function system_question_to_attendee_field_mapping(){
226
+    public function system_question_to_attendee_field_mapping() {
227 227
         return $this->_system_question_to_attendee_field_name;
228 228
     }
229 229
 
@@ -332,7 +332,7 @@  discard block
 block discarded – undo
332 332
      */
333 333
     public function get_array_of_contacts_from_reg_ids($ids)
334 334
     {
335
-        $ids = (array)$ids;
335
+        $ids = (array) $ids;
336 336
         $_where = array(
337 337
             'Registration.REG_ID' => array('in', $ids),
338 338
         );
Please login to merge, or discard this patch.
core/libraries/batch/JobHandlers/RegistrationsReport.php 2 patches
Indentation   +398 added lines, -399 removed lines patch added patch discarded remove patch
@@ -17,7 +17,7 @@  discard block
 block discarded – undo
17 17
 use EventEspressoBatchRequest\Helpers\JobStepResponse;
18 18
 
19 19
 if ( ! defined('EVENT_ESPRESSO_VERSION')) {
20
-    exit('No direct script access allowed');
20
+	exit('No direct script access allowed');
21 21
 }
22 22
 
23 23
 
@@ -25,427 +25,426 @@  discard block
 block discarded – undo
25 25
 class RegistrationsReport extends JobHandlerFile
26 26
 {
27 27
 
28
-    /**
29
-     * Performs any necessary setup for starting the job. This is also a good
30
-     * place to setup the $job_arguments which will be used for subsequent HTTP requests
31
-     * when continue_job will be called
32
-     *
33
-     * @param JobParameters $job_parameters
34
-     * @throws BatchRequestException
35
-     * @return JobStepResponse
36
-     */
37
-    public function create_job(JobParameters $job_parameters)
38
-    {
39
-        $event_id = intval($job_parameters->request_datum('EVT_ID', '0'));
40
-        if ( ! \EE_Capabilities::instance()->current_user_can('ee_read_registrations', 'generating_report')) {
41
-            throw new BatchRequestException(__('You do not have permission to view registrations', 'event_espresso'));
42
-        }
43
-        $filepath = $this->create_file_from_job_with_name($job_parameters->job_id(),
44
-            $this->get_filename($event_id));
45
-        $job_parameters->add_extra_data('filepath', $filepath);
46
-        if ($job_parameters->request_datum('use_filters', false)) {
47
-            $query_params = maybe_unserialize(stripslashes($job_parameters->request_datum('filters', array())));
48
-        } else {
49
-            $query_params = apply_filters('FHEE__EE_Export__report_registration_for_event', array(
50
-                array(
51
-                    'OR'                 => array(
52
-                        //don't include registrations from failed or abandoned transactions...
53
-                        'Transaction.STS_ID' => array(
54
-                            'NOT IN',
55
-                            array(
56
-                                \EEM_Transaction::failed_status_code,
57
-                                \EEM_Transaction::abandoned_status_code,
58
-                            ),
59
-                        ),
60
-                        //unless the registration is approved, in which case include it regardless of transaction status
61
-                        'STS_ID'             => \EEM_Registration::status_id_approved,
62
-                    ),
63
-                    'Ticket.TKT_deleted' => array('IN', array(true, false)),
64
-                ),
65
-                'order_by'   => array('Transaction.TXN_ID' => 'asc', 'REG_count' => 'asc'),
66
-                'force_join' => array('Transaction', 'Ticket', 'Attendee'),
67
-                'caps'       => \EEM_Base::caps_read_admin,
68
-            ), $event_id);
69
-            if ($event_id) {
70
-                $query_params[0]['EVT_ID'] = $event_id;
71
-            } else {
72
-                $query_params['force_join'][] = 'Event';
73
-            }
74
-        }
75
-        if ( ! isset($query_params['force_join'])) {
76
-            $query_params['force_join'] = array('Event', 'Transaction', 'Ticket', 'Attendee');
77
-        }
78
-        $job_parameters->add_extra_data('query_params', $query_params);
79
-        $question_labels = $this->_get_question_labels($query_params);
80
-        $job_parameters->add_extra_data('question_labels', $question_labels);
81
-        $job_parameters->set_job_size(
82
-            \EEM_Registration::instance()->count(
83
-                array_diff_key(
84
-                    $query_params,
85
-                    array_flip(
86
-                        array( 'limit' )
87
-                    )
88
-                )
89
-            )
90
-        );
91
-        //we should also set the header columns
92
-        $csv_data_for_row = $this->get_csv_data_for($event_id, 0, 1, $job_parameters->extra_datum('question_labels'),
93
-            $job_parameters->extra_datum('query_params'));
94
-        \EEH_Export::write_data_array_to_csv($filepath, $csv_data_for_row, true);
95
-        //if we actually processed a row there, record it
96
-        if ($job_parameters->job_size()) {
97
-            $job_parameters->mark_processed(1);
98
-        }
99
-        return new JobStepResponse($job_parameters,
100
-            __('Registrations report started successfully...', 'event_espresso'));
101
-    }
28
+	/**
29
+	 * Performs any necessary setup for starting the job. This is also a good
30
+	 * place to setup the $job_arguments which will be used for subsequent HTTP requests
31
+	 * when continue_job will be called
32
+	 *
33
+	 * @param JobParameters $job_parameters
34
+	 * @throws BatchRequestException
35
+	 * @return JobStepResponse
36
+	 */
37
+	public function create_job(JobParameters $job_parameters)
38
+	{
39
+		$event_id = intval($job_parameters->request_datum('EVT_ID', '0'));
40
+		if ( ! \EE_Capabilities::instance()->current_user_can('ee_read_registrations', 'generating_report')) {
41
+			throw new BatchRequestException(__('You do not have permission to view registrations', 'event_espresso'));
42
+		}
43
+		$filepath = $this->create_file_from_job_with_name($job_parameters->job_id(),
44
+			$this->get_filename($event_id));
45
+		$job_parameters->add_extra_data('filepath', $filepath);
46
+		if ($job_parameters->request_datum('use_filters', false)) {
47
+			$query_params = maybe_unserialize(stripslashes($job_parameters->request_datum('filters', array())));
48
+		} else {
49
+			$query_params = apply_filters('FHEE__EE_Export__report_registration_for_event', array(
50
+				array(
51
+					'OR'                 => array(
52
+						//don't include registrations from failed or abandoned transactions...
53
+						'Transaction.STS_ID' => array(
54
+							'NOT IN',
55
+							array(
56
+								\EEM_Transaction::failed_status_code,
57
+								\EEM_Transaction::abandoned_status_code,
58
+							),
59
+						),
60
+						//unless the registration is approved, in which case include it regardless of transaction status
61
+						'STS_ID'             => \EEM_Registration::status_id_approved,
62
+					),
63
+					'Ticket.TKT_deleted' => array('IN', array(true, false)),
64
+				),
65
+				'order_by'   => array('Transaction.TXN_ID' => 'asc', 'REG_count' => 'asc'),
66
+				'force_join' => array('Transaction', 'Ticket', 'Attendee'),
67
+				'caps'       => \EEM_Base::caps_read_admin,
68
+			), $event_id);
69
+			if ($event_id) {
70
+				$query_params[0]['EVT_ID'] = $event_id;
71
+			} else {
72
+				$query_params['force_join'][] = 'Event';
73
+			}
74
+		}
75
+		if ( ! isset($query_params['force_join'])) {
76
+			$query_params['force_join'] = array('Event', 'Transaction', 'Ticket', 'Attendee');
77
+		}
78
+		$job_parameters->add_extra_data('query_params', $query_params);
79
+		$question_labels = $this->_get_question_labels($query_params);
80
+		$job_parameters->add_extra_data('question_labels', $question_labels);
81
+		$job_parameters->set_job_size(
82
+			\EEM_Registration::instance()->count(
83
+				array_diff_key(
84
+					$query_params,
85
+					array_flip(
86
+						array( 'limit' )
87
+					)
88
+				)
89
+			)
90
+		);
91
+		//we should also set the header columns
92
+		$csv_data_for_row = $this->get_csv_data_for($event_id, 0, 1, $job_parameters->extra_datum('question_labels'),
93
+			$job_parameters->extra_datum('query_params'));
94
+		\EEH_Export::write_data_array_to_csv($filepath, $csv_data_for_row, true);
95
+		//if we actually processed a row there, record it
96
+		if ($job_parameters->job_size()) {
97
+			$job_parameters->mark_processed(1);
98
+		}
99
+		return new JobStepResponse($job_parameters,
100
+			__('Registrations report started successfully...', 'event_espresso'));
101
+	}
102 102
 
103 103
 
104 104
 
105
-    /**
106
-     * Gets the filename
107
-     * @return string
108
-     */
109
-    protected function get_filename()
110
-    {
111
-        return sprintf("event-espresso-registrations-%s.csv", str_replace(':', '-', current_time('mysql')));
112
-    }
105
+	/**
106
+	 * Gets the filename
107
+	 * @return string
108
+	 */
109
+	protected function get_filename()
110
+	{
111
+		return sprintf("event-espresso-registrations-%s.csv", str_replace(':', '-', current_time('mysql')));
112
+	}
113 113
 
114 114
 
115 115
 
116
-    /**
117
-     * Gets the questions which are to be used for this report, so they
118
-     * can be remembered for later
119
-     *
120
-     * @param array $registration_query_params
121
-     * @return array question admin labels to be used for this report
122
-     */
123
-    protected function _get_question_labels($registration_query_params)
124
-    {
125
-        $where = isset($registration_query_params[0]) ? $registration_query_params[0] : null;
126
-        $question_query_params = array();
127
-        if ($where !== null) {
128
-            $question_query_params = array(
129
-                $this->_change_registration_where_params_to_question_where_params($registration_query_params[0]),
130
-            );
131
-        }
132
-        $question_query_params[0]['QST_system'] = array('NOT_IN', array_keys(\EEM_Attendee::instance()->system_question_to_attendee_field_mapping()));
133
-        if(apply_filters('FHEE__EventEspressoBatchRequest__JobHandlers__RegistrationsReport___get_question_labels__only_include_answered_questions', false, $registration_query_params)) {
134
-            $question_query_params[0]['Answer.ANS_ID'] = array('IS_NOT_NULL');
135
-        }
136
-        $question_query_params['group_by'] = array( 'QST_ID' );
137
-        return array_unique( \EEM_Question::instance()->get_col( $question_query_params, 'QST_admin_label' ) );
138
-    }
116
+	/**
117
+	 * Gets the questions which are to be used for this report, so they
118
+	 * can be remembered for later
119
+	 *
120
+	 * @param array $registration_query_params
121
+	 * @return array question admin labels to be used for this report
122
+	 */
123
+	protected function _get_question_labels($registration_query_params)
124
+	{
125
+		$where = isset($registration_query_params[0]) ? $registration_query_params[0] : null;
126
+		$question_query_params = array();
127
+		if ($where !== null) {
128
+			$question_query_params = array(
129
+				$this->_change_registration_where_params_to_question_where_params($registration_query_params[0]),
130
+			);
131
+		}
132
+		$question_query_params[0]['QST_system'] = array('NOT_IN', array_keys(\EEM_Attendee::instance()->system_question_to_attendee_field_mapping()));
133
+		if(apply_filters('FHEE__EventEspressoBatchRequest__JobHandlers__RegistrationsReport___get_question_labels__only_include_answered_questions', false, $registration_query_params)) {
134
+			$question_query_params[0]['Answer.ANS_ID'] = array('IS_NOT_NULL');
135
+		}
136
+		$question_query_params['group_by'] = array( 'QST_ID' );
137
+		return array_unique( \EEM_Question::instance()->get_col( $question_query_params, 'QST_admin_label' ) );
138
+	}
139 139
 
140 140
 
141 141
 
142
-    /**
143
-     * Takes where params meant for registrations and changes them to work for questions
144
-     *
145
-     * @param array $reg_where_params
146
-     * @return array
147
-     */
148
-    protected function _change_registration_where_params_to_question_where_params($reg_where_params)
149
-    {
150
-        $question_where_params = array();
151
-        foreach ($reg_where_params as $key => $val) {
152
-            if (\EEM_Registration::instance()->is_logic_query_param_key($key)) {
153
-                $question_where_params[$key] = $this->_change_registration_where_params_to_question_where_params($val);
154
-            } else {
155
-                //it's a normal where condition
156
-                $question_where_params['Question_Group.Event.Registration.' . $key] = $val;
157
-            }
158
-        }
159
-        return $question_where_params;
160
-    }
142
+	/**
143
+	 * Takes where params meant for registrations and changes them to work for questions
144
+	 *
145
+	 * @param array $reg_where_params
146
+	 * @return array
147
+	 */
148
+	protected function _change_registration_where_params_to_question_where_params($reg_where_params)
149
+	{
150
+		$question_where_params = array();
151
+		foreach ($reg_where_params as $key => $val) {
152
+			if (\EEM_Registration::instance()->is_logic_query_param_key($key)) {
153
+				$question_where_params[$key] = $this->_change_registration_where_params_to_question_where_params($val);
154
+			} else {
155
+				//it's a normal where condition
156
+				$question_where_params['Question_Group.Event.Registration.' . $key] = $val;
157
+			}
158
+		}
159
+		return $question_where_params;
160
+	}
161 161
 
162 162
 
163 163
 
164
-    /**
165
-     * Performs another step of the job
166
-     *
167
-     * @param JobParameters $job_parameters
168
-     * @param int           $batch_size
169
-     * @return JobStepResponse
170
-     * @throws \EE_Error
171
-     */
172
-    public function continue_job(JobParameters $job_parameters, $batch_size = 50)
173
-    {
174
-        if( $job_parameters->units_processed() < $job_parameters->job_size() ) {
175
-            $csv_data = $this->get_csv_data_for($job_parameters->request_datum('EVT_ID', '0'),
176
-                $job_parameters->units_processed(), $batch_size, $job_parameters->extra_datum('question_labels'),
177
-                $job_parameters->extra_datum('query_params'));
178
-            \EEH_Export::write_data_array_to_csv($job_parameters->extra_datum('filepath'), $csv_data, false);
179
-            $units_processed = count($csv_data);
180
-        }else{
181
-            $units_processed = 0;
182
-        }
183
-        $job_parameters->mark_processed($units_processed);
184
-        $extra_response_data = array(
185
-            'file_url' => '',
186
-        );
187
-        if ($units_processed < $batch_size) {
188
-            $job_parameters->set_status(JobParameters::status_complete);
189
-            $extra_response_data['file_url'] = $this->get_url_to_file($job_parameters->extra_datum('filepath'));
190
-        }
164
+	/**
165
+	 * Performs another step of the job
166
+	 *
167
+	 * @param JobParameters $job_parameters
168
+	 * @param int           $batch_size
169
+	 * @return JobStepResponse
170
+	 * @throws \EE_Error
171
+	 */
172
+	public function continue_job(JobParameters $job_parameters, $batch_size = 50)
173
+	{
174
+		if( $job_parameters->units_processed() < $job_parameters->job_size() ) {
175
+			$csv_data = $this->get_csv_data_for($job_parameters->request_datum('EVT_ID', '0'),
176
+				$job_parameters->units_processed(), $batch_size, $job_parameters->extra_datum('question_labels'),
177
+				$job_parameters->extra_datum('query_params'));
178
+			\EEH_Export::write_data_array_to_csv($job_parameters->extra_datum('filepath'), $csv_data, false);
179
+			$units_processed = count($csv_data);
180
+		}else{
181
+			$units_processed = 0;
182
+		}
183
+		$job_parameters->mark_processed($units_processed);
184
+		$extra_response_data = array(
185
+			'file_url' => '',
186
+		);
187
+		if ($units_processed < $batch_size) {
188
+			$job_parameters->set_status(JobParameters::status_complete);
189
+			$extra_response_data['file_url'] = $this->get_url_to_file($job_parameters->extra_datum('filepath'));
190
+		}
191 191
 
192
-        return new JobStepResponse($job_parameters,
193
-            sprintf(__('Wrote %1$s rows to report CSV file...', 'event_espresso'), count($csv_data)),
194
-            $extra_response_data);
195
-    }
192
+		return new JobStepResponse($job_parameters,
193
+			sprintf(__('Wrote %1$s rows to report CSV file...', 'event_espresso'), count($csv_data)),
194
+			$extra_response_data);
195
+	}
196 196
 
197 197
 
198 198
 
199
-    /**
200
-     * Gets the csv data for a batch of registrations
201
-
202
-     *
199
+	/**
200
+	 * Gets the csv data for a batch of registrations
201
+	 *
203 202
 *@param int|null    $event_id
204
-     * @param int   $offset
205
-     * @param int   $limit
206
-     * @param array $question_labels the IDs for all the questions which were answered by someone in this selection
207
-     * @param array $query_params    for using where querying the model
208
-     * @return array top-level keys are numeric, next-level keys are column headers
209
-     */
210
-    function get_csv_data_for($event_id, $offset, $limit, $question_labels, $query_params)
211
-    {
212
-        $reg_fields_to_include = array(
213
-            'TXN_ID',
214
-            'ATT_ID',
215
-            'REG_ID',
216
-            'REG_date',
217
-            'REG_code',
218
-            'REG_count',
219
-            'REG_final_price',
220
-        );
221
-        $att_fields_to_include = array(
222
-            'ATT_fname',
223
-            'ATT_lname',
224
-            'ATT_email',
225
-            'ATT_address',
226
-            'ATT_address2',
227
-            'ATT_city',
228
-            'STA_ID',
229
-            'CNT_ISO',
230
-            'ATT_zip',
231
-            'ATT_phone',
232
-        );
233
-        $registrations_csv_ready_array = array();
234
-        $reg_model = \EE_Registry::instance()->load_model('Registration');
235
-        $query_params['limit'] = array($offset, $limit);
236
-        $registration_rows = $reg_model->get_all_wpdb_results($query_params);
237
-        $registration_ids = array();
238
-        foreach ($registration_rows as $reg_row) {
239
-            $registration_ids[] = intval($reg_row['Registration.REG_ID']);
240
-        }
241
-        foreach ($registration_rows as $reg_row) {
242
-            if (is_array($reg_row)) {
243
-                $reg_csv_array = array();
244
-                if ( ! $event_id) {
245
-                    //get the event's name and Id
246
-                    $reg_csv_array[__('Event', 'event_espresso')] = sprintf(__('%1$s (%2$s)', 'event_espresso'),
247
-                        \EEH_Export::prepare_value_from_db_for_display(\EEM_Event::instance(), 'EVT_name',
248
-                            $reg_row['Event_CPT.post_title']), $reg_row['Event_CPT.ID']);
249
-                }
250
-                $is_primary_reg = $reg_row['Registration.REG_count'] == '1' ? true : false;
251
-                /*@var $reg_row EE_Registration */
252
-                foreach ($reg_fields_to_include as $field_name) {
253
-                    $field = $reg_model->field_settings_for($field_name);
254
-                    if ($field_name == 'REG_final_price') {
255
-                        $value = \EEH_Export::prepare_value_from_db_for_display($reg_model, $field_name,
256
-                            $reg_row['Registration.REG_final_price'], 'localized_float');
257
-                    } elseif ($field_name == 'REG_count') {
258
-                        $value = sprintf(__('%s of %s', 'event_espresso'),
259
-                            \EEH_Export::prepare_value_from_db_for_display($reg_model, 'REG_count',
260
-                                $reg_row['Registration.REG_count']),
261
-                            \EEH_Export::prepare_value_from_db_for_display($reg_model, 'REG_group_size',
262
-                                $reg_row['Registration.REG_group_size']));
263
-                    } elseif ($field_name == 'REG_date') {
264
-                        $value = \EEH_Export::prepare_value_from_db_for_display($reg_model, $field_name,
265
-                            $reg_row['Registration.REG_date'], 'no_html');
266
-                    } else {
267
-                        $value = \EEH_Export::prepare_value_from_db_for_display($reg_model, $field_name,
268
-                            $reg_row[$field->get_qualified_column()]);
269
-                    }
270
-                    $reg_csv_array[\EEH_Export::get_column_name_for_field($field)] = $value;
271
-                    if ($field_name == 'REG_final_price') {
272
-                        //add a column named Currency after the final price
273
-                        $reg_csv_array[__("Currency", "event_espresso")] = \EE_Config::instance()->currency->code;
274
-                    }
275
-                }
276
-                //get pretty status
277
-                $stati = \EEM_Status::instance()->localized_status(array(
278
-                    $reg_row['Registration.STS_ID']     => __('unknown', 'event_espresso'),
279
-                    $reg_row['TransactionTable.STS_ID'] => __('unknown', 'event_espresso'),
280
-                ), false, 'sentence');
281
-                $reg_csv_array[__("Registration Status", 'event_espresso')] = $stati[$reg_row['Registration.STS_ID']];
282
-                //get pretty transaction status
283
-                $reg_csv_array[__("Transaction Status",
284
-                    'event_espresso')] = $stati[$reg_row['TransactionTable.STS_ID']];
285
-                $reg_csv_array[__('Transaction Amount Due', 'event_espresso')] = $is_primary_reg
286
-                    ? \EEH_Export::prepare_value_from_db_for_display(\EEM_Transaction::instance(), 'TXN_total',
287
-                        $reg_row['TransactionTable.TXN_total'], 'localized_float') : '0.00';
288
-                $reg_csv_array[__('Amount Paid', 'event_espresso')] = $is_primary_reg
289
-                    ? \EEH_Export::prepare_value_from_db_for_display(\EEM_Transaction::instance(), 'TXN_paid',
290
-                        $reg_row['TransactionTable.TXN_paid'], 'localized_float') : '0.00';
291
-                $payment_methods = array();
292
-                $gateway_txn_ids_etc = array();
293
-                $payment_times = array();
294
-                if ($is_primary_reg && $reg_row['TransactionTable.TXN_ID']) {
295
-                    $payments_info = \EEM_Payment::instance()->get_all_wpdb_results(array(
296
-                        array(
297
-                            'TXN_ID' => $reg_row['TransactionTable.TXN_ID'],
298
-                            'STS_ID' => \EEM_Payment::status_id_approved,
299
-                        ),
300
-                        'force_join' => array('Payment_Method'),
301
-                    ), ARRAY_A,
302
-                        'Payment_Method.PMD_admin_name as name, Payment.PAY_txn_id_chq_nmbr as gateway_txn_id, Payment.PAY_timestamp as payment_time');
303
-                    foreach ($payments_info as $payment_method_and_gateway_txn_id) {
304
-                        $payment_methods[] = isset($payment_method_and_gateway_txn_id['name'])
305
-                            ? $payment_method_and_gateway_txn_id['name'] : __('Unknown', 'event_espresso');
306
-                        $gateway_txn_ids_etc[] = isset($payment_method_and_gateway_txn_id['gateway_txn_id'])
307
-                            ? $payment_method_and_gateway_txn_id['gateway_txn_id'] : '';
308
-                        $payment_times[] = isset($payment_method_and_gateway_txn_id['payment_time'])
309
-                            ? $payment_method_and_gateway_txn_id['payment_time'] : '';
310
-                    }
311
-                }
312
-                $reg_csv_array[__('Payment Date(s)', 'event_espresso')] = implode(',', $payment_times);
313
-                $reg_csv_array[__('Payment Method(s)', 'event_espresso')] = implode(",", $payment_methods);
314
-                $reg_csv_array[__('Gateway Transaction ID(s)', 'event_espresso')] = implode(',', $gateway_txn_ids_etc);
315
-                //get whether or not the user has checked in
316
-                $reg_csv_array[__("Check-Ins",
317
-                    "event_espresso")] = $reg_model->count_related($reg_row['Registration.REG_ID'], 'Checkin');
318
-                //get ticket of registration and its price
319
-                $ticket_model = \EE_Registry::instance()->load_model('Ticket');
320
-                if ($reg_row['Ticket.TKT_ID']) {
321
-                    $ticket_name = \EEH_Export::prepare_value_from_db_for_display($ticket_model, 'TKT_name',
322
-                        $reg_row['Ticket.TKT_name']);
323
-                    $datetimes_strings = array();
324
-                    foreach (
325
-                        \EEM_Datetime::instance()->get_all_wpdb_results(array(
326
-                            array('Ticket.TKT_ID' => $reg_row['Ticket.TKT_ID']),
327
-                            'order_by'                 => array('DTT_EVT_start' => 'ASC'),
328
-                            'default_where_conditions' => 'none',
329
-                        )) as $datetime
330
-                    ) {
331
-                        $datetimes_strings[] = \EEH_Export::prepare_value_from_db_for_display(\EEM_Datetime::instance(),
332
-                            'DTT_EVT_start', $datetime['Datetime.DTT_EVT_start']);
333
-                    }
334
-                } else {
335
-                    $ticket_name = __('Unknown', 'event_espresso');
336
-                    $datetimes_strings = array(__('Unknown', 'event_espresso'));
337
-                }
338
-                $reg_csv_array[$ticket_model->field_settings_for('TKT_name')->get_nicename()] = $ticket_name;
339
-                $reg_csv_array[__("Datetimes of Ticket", "event_espresso")] = implode(", ", $datetimes_strings);
340
-                //get datetime(s) of registration
341
-                //add attendee columns
342
-                foreach ($att_fields_to_include as $att_field_name) {
343
-                    $field_obj = \EEM_Attendee::instance()->field_settings_for($att_field_name);
344
-                    if ($reg_row['Attendee_CPT.ID']) {
345
-                        if ($att_field_name == 'STA_ID') {
346
-                            $value = \EEM_State::instance()
347
-                                               ->get_var(array(array('STA_ID' => $reg_row['Attendee_Meta.STA_ID'])),
348
-                                                   'STA_name');
349
-                        } elseif ($att_field_name == 'CNT_ISO') {
350
-                            $value = \EEM_Country::instance()
351
-                                                 ->get_var(array(array('CNT_ISO' => $reg_row['Attendee_Meta.CNT_ISO'])),
352
-                                                     'CNT_name');
353
-                        } else {
354
-                            $value = \EEH_Export::prepare_value_from_db_for_display(\EEM_Attendee::instance(),
355
-                                $att_field_name, $reg_row[$field_obj->get_qualified_column()]);
356
-                        }
357
-                    } else {
358
-                        $value = '';
359
-                    }
360
-                    $reg_csv_array[\EEH_Export::get_column_name_for_field($field_obj)] = $value;
361
-                }
362
-                //make sure each registration has the same questions in the same order
363
-                foreach ($question_labels as $question_label) {
364
-                    if ( ! isset($reg_csv_array[$question_label])) {
365
-                        $reg_csv_array[$question_label] = null;
366
-                    }
367
-                }
368
-                $answers = \EEM_Answer::instance()->get_all_wpdb_results(array(
369
-                    array('REG_ID' => $reg_row['Registration.REG_ID']),
370
-                    'force_join' => array('Question'),
371
-                ));
372
-                //now fill out the questions THEY answered
373
-                foreach ($answers as $answer_row) {
374
-                    if ($answer_row['Question.QST_ID']) {
375
-                        $question_label = \EEH_Export::prepare_value_from_db_for_display(\EEM_Question::instance(),
376
-                            'QST_admin_label', $answer_row['Question.QST_admin_label']);
377
-                    } else {
378
-                        $question_label = sprintf(__('Question $s', 'event_espresso'), $answer_row['Answer.QST_ID']);
379
-                    }
380
-                    if (isset($answer_row['Question.QST_type'])
381
-                        && $answer_row['Question.QST_type'] == \EEM_Question::QST_type_state
382
-                    ) {
383
-                        $reg_csv_array[$question_label] = \EEM_State::instance()
384
-                                                                    ->get_state_name_by_ID($answer_row['Answer.ANS_value']);
385
-                    } else {
386
-                        //this isn't for html, so don't show html entities
387
-                        $reg_csv_array[$question_label] = html_entity_decode(\EEH_Export::prepare_value_from_db_for_display(\EEM_Answer::instance(),
388
-                            'ANS_value', $answer_row['Answer.ANS_value']));
389
-                    }
390
-                }
391
-                $registrations_csv_ready_array[] = apply_filters('FHEE__EE_Export__report_registrations__reg_csv_array',
392
-                    $reg_csv_array, $reg_row);
393
-            }
394
-        }
395
-        //if we couldn't export anything, we want to at least show the column headers
396
-        if (empty($registrations_csv_ready_array)) {
397
-            $reg_csv_array = array();
398
-            $model_and_fields_to_include = array(
399
-                'Registration' => $reg_fields_to_include,
400
-                'Attendee'     => $att_fields_to_include,
401
-            );
402
-            foreach ($model_and_fields_to_include as $model_name => $field_list) {
403
-                $model = \EE_Registry::instance()->load_model($model_name);
404
-                foreach ($field_list as $field_name) {
405
-                    $field = $model->field_settings_for($field_name);
406
-                    $reg_csv_array[\EEH_Export::get_column_name_for_field($field)] = null;
407
-                }
408
-            }
409
-            $registrations_csv_ready_array[] = $reg_csv_array;
410
-        }
411
-        return $registrations_csv_ready_array;
412
-    }
203
+	 * @param int   $offset
204
+	 * @param int   $limit
205
+	 * @param array $question_labels the IDs for all the questions which were answered by someone in this selection
206
+	 * @param array $query_params    for using where querying the model
207
+	 * @return array top-level keys are numeric, next-level keys are column headers
208
+	 */
209
+	function get_csv_data_for($event_id, $offset, $limit, $question_labels, $query_params)
210
+	{
211
+		$reg_fields_to_include = array(
212
+			'TXN_ID',
213
+			'ATT_ID',
214
+			'REG_ID',
215
+			'REG_date',
216
+			'REG_code',
217
+			'REG_count',
218
+			'REG_final_price',
219
+		);
220
+		$att_fields_to_include = array(
221
+			'ATT_fname',
222
+			'ATT_lname',
223
+			'ATT_email',
224
+			'ATT_address',
225
+			'ATT_address2',
226
+			'ATT_city',
227
+			'STA_ID',
228
+			'CNT_ISO',
229
+			'ATT_zip',
230
+			'ATT_phone',
231
+		);
232
+		$registrations_csv_ready_array = array();
233
+		$reg_model = \EE_Registry::instance()->load_model('Registration');
234
+		$query_params['limit'] = array($offset, $limit);
235
+		$registration_rows = $reg_model->get_all_wpdb_results($query_params);
236
+		$registration_ids = array();
237
+		foreach ($registration_rows as $reg_row) {
238
+			$registration_ids[] = intval($reg_row['Registration.REG_ID']);
239
+		}
240
+		foreach ($registration_rows as $reg_row) {
241
+			if (is_array($reg_row)) {
242
+				$reg_csv_array = array();
243
+				if ( ! $event_id) {
244
+					//get the event's name and Id
245
+					$reg_csv_array[__('Event', 'event_espresso')] = sprintf(__('%1$s (%2$s)', 'event_espresso'),
246
+						\EEH_Export::prepare_value_from_db_for_display(\EEM_Event::instance(), 'EVT_name',
247
+							$reg_row['Event_CPT.post_title']), $reg_row['Event_CPT.ID']);
248
+				}
249
+				$is_primary_reg = $reg_row['Registration.REG_count'] == '1' ? true : false;
250
+				/*@var $reg_row EE_Registration */
251
+				foreach ($reg_fields_to_include as $field_name) {
252
+					$field = $reg_model->field_settings_for($field_name);
253
+					if ($field_name == 'REG_final_price') {
254
+						$value = \EEH_Export::prepare_value_from_db_for_display($reg_model, $field_name,
255
+							$reg_row['Registration.REG_final_price'], 'localized_float');
256
+					} elseif ($field_name == 'REG_count') {
257
+						$value = sprintf(__('%s of %s', 'event_espresso'),
258
+							\EEH_Export::prepare_value_from_db_for_display($reg_model, 'REG_count',
259
+								$reg_row['Registration.REG_count']),
260
+							\EEH_Export::prepare_value_from_db_for_display($reg_model, 'REG_group_size',
261
+								$reg_row['Registration.REG_group_size']));
262
+					} elseif ($field_name == 'REG_date') {
263
+						$value = \EEH_Export::prepare_value_from_db_for_display($reg_model, $field_name,
264
+							$reg_row['Registration.REG_date'], 'no_html');
265
+					} else {
266
+						$value = \EEH_Export::prepare_value_from_db_for_display($reg_model, $field_name,
267
+							$reg_row[$field->get_qualified_column()]);
268
+					}
269
+					$reg_csv_array[\EEH_Export::get_column_name_for_field($field)] = $value;
270
+					if ($field_name == 'REG_final_price') {
271
+						//add a column named Currency after the final price
272
+						$reg_csv_array[__("Currency", "event_espresso")] = \EE_Config::instance()->currency->code;
273
+					}
274
+				}
275
+				//get pretty status
276
+				$stati = \EEM_Status::instance()->localized_status(array(
277
+					$reg_row['Registration.STS_ID']     => __('unknown', 'event_espresso'),
278
+					$reg_row['TransactionTable.STS_ID'] => __('unknown', 'event_espresso'),
279
+				), false, 'sentence');
280
+				$reg_csv_array[__("Registration Status", 'event_espresso')] = $stati[$reg_row['Registration.STS_ID']];
281
+				//get pretty transaction status
282
+				$reg_csv_array[__("Transaction Status",
283
+					'event_espresso')] = $stati[$reg_row['TransactionTable.STS_ID']];
284
+				$reg_csv_array[__('Transaction Amount Due', 'event_espresso')] = $is_primary_reg
285
+					? \EEH_Export::prepare_value_from_db_for_display(\EEM_Transaction::instance(), 'TXN_total',
286
+						$reg_row['TransactionTable.TXN_total'], 'localized_float') : '0.00';
287
+				$reg_csv_array[__('Amount Paid', 'event_espresso')] = $is_primary_reg
288
+					? \EEH_Export::prepare_value_from_db_for_display(\EEM_Transaction::instance(), 'TXN_paid',
289
+						$reg_row['TransactionTable.TXN_paid'], 'localized_float') : '0.00';
290
+				$payment_methods = array();
291
+				$gateway_txn_ids_etc = array();
292
+				$payment_times = array();
293
+				if ($is_primary_reg && $reg_row['TransactionTable.TXN_ID']) {
294
+					$payments_info = \EEM_Payment::instance()->get_all_wpdb_results(array(
295
+						array(
296
+							'TXN_ID' => $reg_row['TransactionTable.TXN_ID'],
297
+							'STS_ID' => \EEM_Payment::status_id_approved,
298
+						),
299
+						'force_join' => array('Payment_Method'),
300
+					), ARRAY_A,
301
+						'Payment_Method.PMD_admin_name as name, Payment.PAY_txn_id_chq_nmbr as gateway_txn_id, Payment.PAY_timestamp as payment_time');
302
+					foreach ($payments_info as $payment_method_and_gateway_txn_id) {
303
+						$payment_methods[] = isset($payment_method_and_gateway_txn_id['name'])
304
+							? $payment_method_and_gateway_txn_id['name'] : __('Unknown', 'event_espresso');
305
+						$gateway_txn_ids_etc[] = isset($payment_method_and_gateway_txn_id['gateway_txn_id'])
306
+							? $payment_method_and_gateway_txn_id['gateway_txn_id'] : '';
307
+						$payment_times[] = isset($payment_method_and_gateway_txn_id['payment_time'])
308
+							? $payment_method_and_gateway_txn_id['payment_time'] : '';
309
+					}
310
+				}
311
+				$reg_csv_array[__('Payment Date(s)', 'event_espresso')] = implode(',', $payment_times);
312
+				$reg_csv_array[__('Payment Method(s)', 'event_espresso')] = implode(",", $payment_methods);
313
+				$reg_csv_array[__('Gateway Transaction ID(s)', 'event_espresso')] = implode(',', $gateway_txn_ids_etc);
314
+				//get whether or not the user has checked in
315
+				$reg_csv_array[__("Check-Ins",
316
+					"event_espresso")] = $reg_model->count_related($reg_row['Registration.REG_ID'], 'Checkin');
317
+				//get ticket of registration and its price
318
+				$ticket_model = \EE_Registry::instance()->load_model('Ticket');
319
+				if ($reg_row['Ticket.TKT_ID']) {
320
+					$ticket_name = \EEH_Export::prepare_value_from_db_for_display($ticket_model, 'TKT_name',
321
+						$reg_row['Ticket.TKT_name']);
322
+					$datetimes_strings = array();
323
+					foreach (
324
+						\EEM_Datetime::instance()->get_all_wpdb_results(array(
325
+							array('Ticket.TKT_ID' => $reg_row['Ticket.TKT_ID']),
326
+							'order_by'                 => array('DTT_EVT_start' => 'ASC'),
327
+							'default_where_conditions' => 'none',
328
+						)) as $datetime
329
+					) {
330
+						$datetimes_strings[] = \EEH_Export::prepare_value_from_db_for_display(\EEM_Datetime::instance(),
331
+							'DTT_EVT_start', $datetime['Datetime.DTT_EVT_start']);
332
+					}
333
+				} else {
334
+					$ticket_name = __('Unknown', 'event_espresso');
335
+					$datetimes_strings = array(__('Unknown', 'event_espresso'));
336
+				}
337
+				$reg_csv_array[$ticket_model->field_settings_for('TKT_name')->get_nicename()] = $ticket_name;
338
+				$reg_csv_array[__("Datetimes of Ticket", "event_espresso")] = implode(", ", $datetimes_strings);
339
+				//get datetime(s) of registration
340
+				//add attendee columns
341
+				foreach ($att_fields_to_include as $att_field_name) {
342
+					$field_obj = \EEM_Attendee::instance()->field_settings_for($att_field_name);
343
+					if ($reg_row['Attendee_CPT.ID']) {
344
+						if ($att_field_name == 'STA_ID') {
345
+							$value = \EEM_State::instance()
346
+											   ->get_var(array(array('STA_ID' => $reg_row['Attendee_Meta.STA_ID'])),
347
+												   'STA_name');
348
+						} elseif ($att_field_name == 'CNT_ISO') {
349
+							$value = \EEM_Country::instance()
350
+												 ->get_var(array(array('CNT_ISO' => $reg_row['Attendee_Meta.CNT_ISO'])),
351
+													 'CNT_name');
352
+						} else {
353
+							$value = \EEH_Export::prepare_value_from_db_for_display(\EEM_Attendee::instance(),
354
+								$att_field_name, $reg_row[$field_obj->get_qualified_column()]);
355
+						}
356
+					} else {
357
+						$value = '';
358
+					}
359
+					$reg_csv_array[\EEH_Export::get_column_name_for_field($field_obj)] = $value;
360
+				}
361
+				//make sure each registration has the same questions in the same order
362
+				foreach ($question_labels as $question_label) {
363
+					if ( ! isset($reg_csv_array[$question_label])) {
364
+						$reg_csv_array[$question_label] = null;
365
+					}
366
+				}
367
+				$answers = \EEM_Answer::instance()->get_all_wpdb_results(array(
368
+					array('REG_ID' => $reg_row['Registration.REG_ID']),
369
+					'force_join' => array('Question'),
370
+				));
371
+				//now fill out the questions THEY answered
372
+				foreach ($answers as $answer_row) {
373
+					if ($answer_row['Question.QST_ID']) {
374
+						$question_label = \EEH_Export::prepare_value_from_db_for_display(\EEM_Question::instance(),
375
+							'QST_admin_label', $answer_row['Question.QST_admin_label']);
376
+					} else {
377
+						$question_label = sprintf(__('Question $s', 'event_espresso'), $answer_row['Answer.QST_ID']);
378
+					}
379
+					if (isset($answer_row['Question.QST_type'])
380
+						&& $answer_row['Question.QST_type'] == \EEM_Question::QST_type_state
381
+					) {
382
+						$reg_csv_array[$question_label] = \EEM_State::instance()
383
+																	->get_state_name_by_ID($answer_row['Answer.ANS_value']);
384
+					} else {
385
+						//this isn't for html, so don't show html entities
386
+						$reg_csv_array[$question_label] = html_entity_decode(\EEH_Export::prepare_value_from_db_for_display(\EEM_Answer::instance(),
387
+							'ANS_value', $answer_row['Answer.ANS_value']));
388
+					}
389
+				}
390
+				$registrations_csv_ready_array[] = apply_filters('FHEE__EE_Export__report_registrations__reg_csv_array',
391
+					$reg_csv_array, $reg_row);
392
+			}
393
+		}
394
+		//if we couldn't export anything, we want to at least show the column headers
395
+		if (empty($registrations_csv_ready_array)) {
396
+			$reg_csv_array = array();
397
+			$model_and_fields_to_include = array(
398
+				'Registration' => $reg_fields_to_include,
399
+				'Attendee'     => $att_fields_to_include,
400
+			);
401
+			foreach ($model_and_fields_to_include as $model_name => $field_list) {
402
+				$model = \EE_Registry::instance()->load_model($model_name);
403
+				foreach ($field_list as $field_name) {
404
+					$field = $model->field_settings_for($field_name);
405
+					$reg_csv_array[\EEH_Export::get_column_name_for_field($field)] = null;
406
+				}
407
+			}
408
+			$registrations_csv_ready_array[] = $reg_csv_array;
409
+		}
410
+		return $registrations_csv_ready_array;
411
+	}
413 412
 
414 413
 
415 414
 
416
-    /**
417
-     * Counts total unit to process
418
-     *
419
-     * @deprecated since 4.9.19
420
-     * @param int|array $event_id
421
-     * @return int
422
-     */
423
-    public function count_units_to_process($event_id)
424
-    {
425
-        //use the legacy filter
426
-        if ($event_id) {
427
-            $query_params[0]['EVT_ID'] = $event_id;
428
-        } else {
429
-            $query_params['force_join'][] = 'Event';
430
-        }
431
-        return \EEM_Registration::instance()->count($query_params);
432
-    }
415
+	/**
416
+	 * Counts total unit to process
417
+	 *
418
+	 * @deprecated since 4.9.19
419
+	 * @param int|array $event_id
420
+	 * @return int
421
+	 */
422
+	public function count_units_to_process($event_id)
423
+	{
424
+		//use the legacy filter
425
+		if ($event_id) {
426
+			$query_params[0]['EVT_ID'] = $event_id;
427
+		} else {
428
+			$query_params['force_join'][] = 'Event';
429
+		}
430
+		return \EEM_Registration::instance()->count($query_params);
431
+	}
433 432
 
434 433
 
435 434
 
436
-    /**
437
-     * Performs any clean-up logic when we know the job is completed.
438
-     * In this case, we delete the temporary file
439
-     *
440
-     * @param JobParameters $job_parameters
441
-     * @return boolean
442
-     */
443
-    public function cleanup_job(JobParameters $job_parameters)
444
-    {
445
-        $this->_file_helper->delete(\EEH_File::remove_filename_from_filepath($job_parameters->extra_datum('filepath')),
446
-            true, 'd');
447
-        return new JobStepResponse($job_parameters, __('Cleaned up temporary file', 'event_espresso'));
448
-    }
435
+	/**
436
+	 * Performs any clean-up logic when we know the job is completed.
437
+	 * In this case, we delete the temporary file
438
+	 *
439
+	 * @param JobParameters $job_parameters
440
+	 * @return boolean
441
+	 */
442
+	public function cleanup_job(JobParameters $job_parameters)
443
+	{
444
+		$this->_file_helper->delete(\EEH_File::remove_filename_from_filepath($job_parameters->extra_datum('filepath')),
445
+			true, 'd');
446
+		return new JobStepResponse($job_parameters, __('Cleaned up temporary file', 'event_espresso'));
447
+	}
449 448
 }
450 449
 
451 450
 
Please login to merge, or discard this patch.
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -83,7 +83,7 @@  discard block
 block discarded – undo
83 83
                 array_diff_key(
84 84
                     $query_params,
85 85
                     array_flip(
86
-                        array( 'limit' )
86
+                        array('limit')
87 87
                     )
88 88
                 )
89 89
             )
@@ -130,11 +130,11 @@  discard block
 block discarded – undo
130 130
             );
131 131
         }
132 132
         $question_query_params[0]['QST_system'] = array('NOT_IN', array_keys(\EEM_Attendee::instance()->system_question_to_attendee_field_mapping()));
133
-        if(apply_filters('FHEE__EventEspressoBatchRequest__JobHandlers__RegistrationsReport___get_question_labels__only_include_answered_questions', false, $registration_query_params)) {
133
+        if (apply_filters('FHEE__EventEspressoBatchRequest__JobHandlers__RegistrationsReport___get_question_labels__only_include_answered_questions', false, $registration_query_params)) {
134 134
             $question_query_params[0]['Answer.ANS_ID'] = array('IS_NOT_NULL');
135 135
         }
136
-        $question_query_params['group_by'] = array( 'QST_ID' );
137
-        return array_unique( \EEM_Question::instance()->get_col( $question_query_params, 'QST_admin_label' ) );
136
+        $question_query_params['group_by'] = array('QST_ID');
137
+        return array_unique(\EEM_Question::instance()->get_col($question_query_params, 'QST_admin_label'));
138 138
     }
139 139
 
140 140
 
@@ -153,7 +153,7 @@  discard block
 block discarded – undo
153 153
                 $question_where_params[$key] = $this->_change_registration_where_params_to_question_where_params($val);
154 154
             } else {
155 155
                 //it's a normal where condition
156
-                $question_where_params['Question_Group.Event.Registration.' . $key] = $val;
156
+                $question_where_params['Question_Group.Event.Registration.'.$key] = $val;
157 157
             }
158 158
         }
159 159
         return $question_where_params;
@@ -171,13 +171,13 @@  discard block
 block discarded – undo
171 171
      */
172 172
     public function continue_job(JobParameters $job_parameters, $batch_size = 50)
173 173
     {
174
-        if( $job_parameters->units_processed() < $job_parameters->job_size() ) {
174
+        if ($job_parameters->units_processed() < $job_parameters->job_size()) {
175 175
             $csv_data = $this->get_csv_data_for($job_parameters->request_datum('EVT_ID', '0'),
176 176
                 $job_parameters->units_processed(), $batch_size, $job_parameters->extra_datum('question_labels'),
177 177
                 $job_parameters->extra_datum('query_params'));
178 178
             \EEH_Export::write_data_array_to_csv($job_parameters->extra_datum('filepath'), $csv_data, false);
179 179
             $units_processed = count($csv_data);
180
-        }else{
180
+        } else {
181 181
             $units_processed = 0;
182 182
         }
183 183
         $job_parameters->mark_processed($units_processed);
Please login to merge, or discard this patch.
core/helpers/EEH_DTT_Helper.helper.php 3 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -944,7 +944,7 @@
 block discarded – undo
944 944
      * this method will add that "1" into your date regardless of the format.
945 945
      *
946 946
      * @param string $month
947
-     * @return string
947
+     * @return integer
948 948
      */
949 949
     public static function first_of_month_timestamp($month = '')
950 950
     {
Please login to merge, or discard this patch.
Indentation   +912 added lines, -912 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 if (! defined('EVENT_ESPRESSO_VERSION')) {
3
-    exit('NO direct script access allowed');
3
+	exit('NO direct script access allowed');
4 4
 }
5 5
 
6 6
 /**
@@ -26,233 +26,233 @@  discard block
 block discarded – undo
26 26
 {
27 27
 
28 28
 
29
-    /**
30
-     * return the timezone set for the WP install
31
-     *
32
-     * @return string valid timezone string for PHP DateTimeZone() class
33
-     */
34
-    public static function get_timezone()
35
-    {
36
-        return EEH_DTT_Helper::get_valid_timezone_string();
37
-    }
38
-
39
-
40
-    /**
41
-     * get_valid_timezone_string
42
-     *    ensures that a valid timezone string is returned
43
-     *
44
-     * @access protected
45
-     * @param string $timezone_string
46
-     * @return string
47
-     * @throws \EE_Error
48
-     */
49
-    public static function get_valid_timezone_string($timezone_string = '')
50
-    {
51
-        // if passed a value, then use that, else get WP option
52
-        $timezone_string = ! empty($timezone_string) ? $timezone_string : get_option('timezone_string');
53
-        // value from above exists, use that, else get timezone string from gmt_offset
54
-        $timezone_string = ! empty($timezone_string) ? $timezone_string : EEH_DTT_Helper::get_timezone_string_from_gmt_offset();
55
-        EEH_DTT_Helper::validate_timezone($timezone_string);
56
-        return $timezone_string;
57
-    }
58
-
59
-
60
-    /**
61
-     * This only purpose for this static method is to validate that the incoming timezone is a valid php timezone.
62
-     *
63
-     * @static
64
-     * @access public
65
-     * @param  string $timezone_string Timezone string to check
66
-     * @param bool    $throw_error
67
-     * @return bool
68
-     * @throws \EE_Error
69
-     */
70
-    public static function validate_timezone($timezone_string, $throw_error = true)
71
-    {
72
-        // easiest way to test a timezone string is just see if it throws an error when you try to create a DateTimeZone object with it
73
-        try {
74
-            new DateTimeZone($timezone_string);
75
-        } catch (Exception $e) {
76
-            // sometimes we take exception to exceptions
77
-            if (! $throw_error) {
78
-                return false;
79
-            }
80
-            throw new EE_Error(
81
-                sprintf(
82
-                    __('The timezone given (%1$s), is invalid, please check with %2$sthis list%3$s for what valid timezones can be used',
83
-                        'event_espresso'),
84
-                    $timezone_string,
85
-                    '<a href="http://www.php.net/manual/en/timezones.php">',
86
-                    '</a>'
87
-                )
88
-            );
89
-        }
90
-        return true;
91
-    }
92
-
93
-
94
-    /**
95
-     * _create_timezone_object_from_timezone_name
96
-     *
97
-     * @access protected
98
-     * @param string $gmt_offset
99
-     * @return string
100
-     */
101
-    public static function get_timezone_string_from_gmt_offset($gmt_offset = '')
102
-    {
103
-        $timezone_string = 'UTC';
104
-        $gmt_offset      = ! empty($gmt_offset) ? $gmt_offset : get_option('gmt_offset');
105
-        if ($gmt_offset !== '') {
106
-            // convert GMT offset to seconds
107
-            $gmt_offset = $gmt_offset * HOUR_IN_SECONDS;
108
-            // account for WP offsets that aren't valid UTC
109
-            $gmt_offset = EEH_DTT_Helper::adjust_invalid_gmt_offsets($gmt_offset);
110
-            // although we don't know the TZ abbreviation, we know the UTC offset
111
-            $timezone_string = timezone_name_from_abbr(null, $gmt_offset);
112
-        }
113
-        // better have a valid timezone string by now, but if not, sigh... loop thru  the timezone_abbreviations_list()...
114
-        $timezone_string = $timezone_string !== false
115
-            ? $timezone_string
116
-            : EEH_DTT_Helper::get_timezone_string_from_abbreviations_list($gmt_offset);
117
-        return $timezone_string;
118
-    }
119
-
120
-    /**
121
-     * Gets the site's GMT offset based on either the timezone string
122
-     * (in which case teh gmt offset will vary depending on the location's
123
-     * observance of daylight savings time) or the gmt_offset wp option
124
-     *
125
-     * @return int seconds offset
126
-     */
127
-    public static function get_site_timezone_gmt_offset()
128
-    {
129
-        $timezone_string = get_option('timezone_string');
130
-        if ($timezone_string) {
131
-            try {
132
-                $timezone = new DateTimeZone($timezone_string);
133
-                return $timezone->getOffset(new DateTime()); //in WordPress DateTime defaults to UTC
134
-            } catch (Exception $e) {
135
-            }
136
-        }
137
-        $offset = get_option('gmt_offset');
138
-        return (int)($offset * HOUR_IN_SECONDS);
139
-    }
140
-
141
-
142
-    /**
143
-     * _create_timezone_object_from_timezone_name
144
-     *
145
-     * @access public
146
-     * @param int $gmt_offset
147
-     * @return int
148
-     */
149
-    public static function adjust_invalid_gmt_offsets($gmt_offset = 0)
150
-    {
151
-        //make sure $gmt_offset is int
152
-        $gmt_offset = (int)$gmt_offset;
153
-        switch ($gmt_offset) {
154
-
155
-            //			case -30600 :
156
-            //				$gmt_offset = -28800;
157
-            //				break;
158
-
159
-            case -27000 :
160
-                $gmt_offset = -25200;
161
-                break;
162
-
163
-            case -23400 :
164
-                $gmt_offset = -21600;
165
-                break;
166
-
167
-            case -19800 :
168
-                $gmt_offset = -18000;
169
-                break;
170
-
171
-            case -9000 :
172
-                $gmt_offset = -7200;
173
-                break;
174
-
175
-            case -5400 :
176
-                $gmt_offset = -3600;
177
-                break;
178
-
179
-            case -1800 :
180
-                $gmt_offset = 0;
181
-                break;
182
-
183
-            case 1800 :
184
-                $gmt_offset = 3600;
185
-                break;
186
-
187
-            case 49500 :
188
-                $gmt_offset = 50400;
189
-                break;
190
-
191
-        }
192
-        return $gmt_offset;
193
-    }
194
-
195
-
196
-    /**
197
-     * get_timezone_string_from_abbreviations_list
198
-     *
199
-     * @access public
200
-     * @param int $gmt_offset
201
-     * @return string
202
-     * @throws \EE_Error
203
-     */
204
-    public static function get_timezone_string_from_abbreviations_list($gmt_offset = 0)
205
-    {
206
-        $abbreviations = timezone_abbreviations_list();
207
-        foreach ($abbreviations as $abbreviation) {
208
-            foreach ($abbreviation as $city) {
209
-                if ($city['offset'] === $gmt_offset && $city['dst'] === false) {
210
-                    // check if the timezone is valid but don't throw any errors if it isn't
211
-                    if (EEH_DTT_Helper::validate_timezone($city['timezone_id'], false)) {
212
-                        return $city['timezone_id'];
213
-                    }
214
-                }
215
-            }
216
-        }
217
-        throw new EE_Error(
218
-            sprintf(
219
-                __('The provided GMT offset (%1$s), is invalid, please check with %2$sthis list%3$s for what valid timezones can be used',
220
-                    'event_espresso'),
221
-                $gmt_offset,
222
-                '<a href="http://www.php.net/manual/en/timezones.php">',
223
-                '</a>'
224
-            )
225
-        );
226
-    }
227
-
228
-
229
-    /**
230
-     * @access public
231
-     * @param string $timezone_string
232
-     */
233
-    public static function timezone_select_input($timezone_string = '')
234
-    {
235
-        // get WP date time format
236
-        $datetime_format = get_option('date_format') . ' ' . get_option('time_format');
237
-        // if passed a value, then use that, else get WP option
238
-        $timezone_string = ! empty($timezone_string) ? $timezone_string : get_option('timezone_string');
239
-        // check if the timezone is valid but don't throw any errors if it isn't
240
-        $timezone_string = EEH_DTT_Helper::validate_timezone($timezone_string, false);
241
-        $gmt_offset      = get_option('gmt_offset');
242
-
243
-        $check_zone_info = true;
244
-        if (empty($timezone_string)) {
245
-            // Create a UTC+- zone if no timezone string exists
246
-            $check_zone_info = false;
247
-            if ($gmt_offset > 0) {
248
-                $timezone_string = 'UTC+' . $gmt_offset;
249
-            } elseif ($gmt_offset < 0) {
250
-                $timezone_string = 'UTC' . $gmt_offset;
251
-            } else {
252
-                $timezone_string = 'UTC';
253
-            }
254
-        }
255
-        ?>
29
+	/**
30
+	 * return the timezone set for the WP install
31
+	 *
32
+	 * @return string valid timezone string for PHP DateTimeZone() class
33
+	 */
34
+	public static function get_timezone()
35
+	{
36
+		return EEH_DTT_Helper::get_valid_timezone_string();
37
+	}
38
+
39
+
40
+	/**
41
+	 * get_valid_timezone_string
42
+	 *    ensures that a valid timezone string is returned
43
+	 *
44
+	 * @access protected
45
+	 * @param string $timezone_string
46
+	 * @return string
47
+	 * @throws \EE_Error
48
+	 */
49
+	public static function get_valid_timezone_string($timezone_string = '')
50
+	{
51
+		// if passed a value, then use that, else get WP option
52
+		$timezone_string = ! empty($timezone_string) ? $timezone_string : get_option('timezone_string');
53
+		// value from above exists, use that, else get timezone string from gmt_offset
54
+		$timezone_string = ! empty($timezone_string) ? $timezone_string : EEH_DTT_Helper::get_timezone_string_from_gmt_offset();
55
+		EEH_DTT_Helper::validate_timezone($timezone_string);
56
+		return $timezone_string;
57
+	}
58
+
59
+
60
+	/**
61
+	 * This only purpose for this static method is to validate that the incoming timezone is a valid php timezone.
62
+	 *
63
+	 * @static
64
+	 * @access public
65
+	 * @param  string $timezone_string Timezone string to check
66
+	 * @param bool    $throw_error
67
+	 * @return bool
68
+	 * @throws \EE_Error
69
+	 */
70
+	public static function validate_timezone($timezone_string, $throw_error = true)
71
+	{
72
+		// easiest way to test a timezone string is just see if it throws an error when you try to create a DateTimeZone object with it
73
+		try {
74
+			new DateTimeZone($timezone_string);
75
+		} catch (Exception $e) {
76
+			// sometimes we take exception to exceptions
77
+			if (! $throw_error) {
78
+				return false;
79
+			}
80
+			throw new EE_Error(
81
+				sprintf(
82
+					__('The timezone given (%1$s), is invalid, please check with %2$sthis list%3$s for what valid timezones can be used',
83
+						'event_espresso'),
84
+					$timezone_string,
85
+					'<a href="http://www.php.net/manual/en/timezones.php">',
86
+					'</a>'
87
+				)
88
+			);
89
+		}
90
+		return true;
91
+	}
92
+
93
+
94
+	/**
95
+	 * _create_timezone_object_from_timezone_name
96
+	 *
97
+	 * @access protected
98
+	 * @param string $gmt_offset
99
+	 * @return string
100
+	 */
101
+	public static function get_timezone_string_from_gmt_offset($gmt_offset = '')
102
+	{
103
+		$timezone_string = 'UTC';
104
+		$gmt_offset      = ! empty($gmt_offset) ? $gmt_offset : get_option('gmt_offset');
105
+		if ($gmt_offset !== '') {
106
+			// convert GMT offset to seconds
107
+			$gmt_offset = $gmt_offset * HOUR_IN_SECONDS;
108
+			// account for WP offsets that aren't valid UTC
109
+			$gmt_offset = EEH_DTT_Helper::adjust_invalid_gmt_offsets($gmt_offset);
110
+			// although we don't know the TZ abbreviation, we know the UTC offset
111
+			$timezone_string = timezone_name_from_abbr(null, $gmt_offset);
112
+		}
113
+		// better have a valid timezone string by now, but if not, sigh... loop thru  the timezone_abbreviations_list()...
114
+		$timezone_string = $timezone_string !== false
115
+			? $timezone_string
116
+			: EEH_DTT_Helper::get_timezone_string_from_abbreviations_list($gmt_offset);
117
+		return $timezone_string;
118
+	}
119
+
120
+	/**
121
+	 * Gets the site's GMT offset based on either the timezone string
122
+	 * (in which case teh gmt offset will vary depending on the location's
123
+	 * observance of daylight savings time) or the gmt_offset wp option
124
+	 *
125
+	 * @return int seconds offset
126
+	 */
127
+	public static function get_site_timezone_gmt_offset()
128
+	{
129
+		$timezone_string = get_option('timezone_string');
130
+		if ($timezone_string) {
131
+			try {
132
+				$timezone = new DateTimeZone($timezone_string);
133
+				return $timezone->getOffset(new DateTime()); //in WordPress DateTime defaults to UTC
134
+			} catch (Exception $e) {
135
+			}
136
+		}
137
+		$offset = get_option('gmt_offset');
138
+		return (int)($offset * HOUR_IN_SECONDS);
139
+	}
140
+
141
+
142
+	/**
143
+	 * _create_timezone_object_from_timezone_name
144
+	 *
145
+	 * @access public
146
+	 * @param int $gmt_offset
147
+	 * @return int
148
+	 */
149
+	public static function adjust_invalid_gmt_offsets($gmt_offset = 0)
150
+	{
151
+		//make sure $gmt_offset is int
152
+		$gmt_offset = (int)$gmt_offset;
153
+		switch ($gmt_offset) {
154
+
155
+			//			case -30600 :
156
+			//				$gmt_offset = -28800;
157
+			//				break;
158
+
159
+			case -27000 :
160
+				$gmt_offset = -25200;
161
+				break;
162
+
163
+			case -23400 :
164
+				$gmt_offset = -21600;
165
+				break;
166
+
167
+			case -19800 :
168
+				$gmt_offset = -18000;
169
+				break;
170
+
171
+			case -9000 :
172
+				$gmt_offset = -7200;
173
+				break;
174
+
175
+			case -5400 :
176
+				$gmt_offset = -3600;
177
+				break;
178
+
179
+			case -1800 :
180
+				$gmt_offset = 0;
181
+				break;
182
+
183
+			case 1800 :
184
+				$gmt_offset = 3600;
185
+				break;
186
+
187
+			case 49500 :
188
+				$gmt_offset = 50400;
189
+				break;
190
+
191
+		}
192
+		return $gmt_offset;
193
+	}
194
+
195
+
196
+	/**
197
+	 * get_timezone_string_from_abbreviations_list
198
+	 *
199
+	 * @access public
200
+	 * @param int $gmt_offset
201
+	 * @return string
202
+	 * @throws \EE_Error
203
+	 */
204
+	public static function get_timezone_string_from_abbreviations_list($gmt_offset = 0)
205
+	{
206
+		$abbreviations = timezone_abbreviations_list();
207
+		foreach ($abbreviations as $abbreviation) {
208
+			foreach ($abbreviation as $city) {
209
+				if ($city['offset'] === $gmt_offset && $city['dst'] === false) {
210
+					// check if the timezone is valid but don't throw any errors if it isn't
211
+					if (EEH_DTT_Helper::validate_timezone($city['timezone_id'], false)) {
212
+						return $city['timezone_id'];
213
+					}
214
+				}
215
+			}
216
+		}
217
+		throw new EE_Error(
218
+			sprintf(
219
+				__('The provided GMT offset (%1$s), is invalid, please check with %2$sthis list%3$s for what valid timezones can be used',
220
+					'event_espresso'),
221
+				$gmt_offset,
222
+				'<a href="http://www.php.net/manual/en/timezones.php">',
223
+				'</a>'
224
+			)
225
+		);
226
+	}
227
+
228
+
229
+	/**
230
+	 * @access public
231
+	 * @param string $timezone_string
232
+	 */
233
+	public static function timezone_select_input($timezone_string = '')
234
+	{
235
+		// get WP date time format
236
+		$datetime_format = get_option('date_format') . ' ' . get_option('time_format');
237
+		// if passed a value, then use that, else get WP option
238
+		$timezone_string = ! empty($timezone_string) ? $timezone_string : get_option('timezone_string');
239
+		// check if the timezone is valid but don't throw any errors if it isn't
240
+		$timezone_string = EEH_DTT_Helper::validate_timezone($timezone_string, false);
241
+		$gmt_offset      = get_option('gmt_offset');
242
+
243
+		$check_zone_info = true;
244
+		if (empty($timezone_string)) {
245
+			// Create a UTC+- zone if no timezone string exists
246
+			$check_zone_info = false;
247
+			if ($gmt_offset > 0) {
248
+				$timezone_string = 'UTC+' . $gmt_offset;
249
+			} elseif ($gmt_offset < 0) {
250
+				$timezone_string = 'UTC' . $gmt_offset;
251
+			} else {
252
+				$timezone_string = 'UTC';
253
+			}
254
+		}
255
+		?>
256 256
 
257 257
         <p>
258 258
             <label for="timezone_string"><?php _e('timezone'); ?></label>
@@ -265,13 +265,13 @@  discard block
 block discarded – undo
265 265
 
266 266
         <p>
267 267
         <span><?php
268
-            printf(
269
-                __('%1$sUTC%2$s time is %3$s'),
270
-                '<abbr title="Coordinated Universal Time">',
271
-                '</abbr>',
272
-                '<code>' . date_i18n($datetime_format, false, true) . '</code>'
273
-            );
274
-            ?></span>
268
+			printf(
269
+				__('%1$sUTC%2$s time is %3$s'),
270
+				'<abbr title="Coordinated Universal Time">',
271
+				'</abbr>',
272
+				'<code>' . date_i18n($datetime_format, false, true) . '</code>'
273
+			);
274
+			?></span>
275 275
         <?php if (! empty($timezone_string) || ! empty($gmt_offset)) : ?>
276 276
         <br/><span><?php printf(__('Local time is %1$s'), '<code>' . date_i18n($datetime_format) . '</code>'); ?></span>
277 277
     <?php endif; ?>
@@ -280,687 +280,687 @@  discard block
 block discarded – undo
280 280
         <br/>
281 281
         <span>
282 282
 					<?php
283
-                    // Set TZ so localtime works.
284
-                    date_default_timezone_set($timezone_string);
285
-                    $now = localtime(time(), true);
286
-                    if ($now['tm_isdst']) {
287
-                        _e('This timezone is currently in daylight saving time.');
288
-                    } else {
289
-                        _e('This timezone is currently in standard time.');
290
-                    }
291
-                    ?>
283
+					// Set TZ so localtime works.
284
+					date_default_timezone_set($timezone_string);
285
+					$now = localtime(time(), true);
286
+					if ($now['tm_isdst']) {
287
+						_e('This timezone is currently in daylight saving time.');
288
+					} else {
289
+						_e('This timezone is currently in standard time.');
290
+					}
291
+					?>
292 292
             <br/>
293 293
             <?php
294
-            if (function_exists('timezone_transitions_get')) {
295
-                $found                   = false;
296
-                $date_time_zone_selected = new DateTimeZone($timezone_string);
297
-                $tz_offset               = timezone_offset_get($date_time_zone_selected, date_create());
298
-                $right_now               = time();
299
-                $tr['isdst']             = false;
300
-                foreach (timezone_transitions_get($date_time_zone_selected) as $tr) {
301
-                    if ($tr['ts'] > $right_now) {
302
-                        $found = true;
303
-                        break;
304
-                    }
305
-                }
306
-
307
-                if ($found) {
308
-                    $message = $tr['isdst'] ?
309
-                        __(' Daylight saving time begins on: %s.') :
310
-                        __(' Standard time begins  on: %s.');
311
-                    // Add the difference between the current offset and the new offset to ts to get the correct transition time from date_i18n().
312
-                    printf($message,
313
-                        '<code >' . date_i18n($datetime_format, $tr['ts'] + ($tz_offset - $tr['offset'])) . '</code >');
314
-                } else {
315
-                    _e('This timezone does not observe daylight saving time.');
316
-                }
317
-            }
318
-            // Set back to UTC.
319
-            date_default_timezone_set('UTC');
320
-            ?>
294
+			if (function_exists('timezone_transitions_get')) {
295
+				$found                   = false;
296
+				$date_time_zone_selected = new DateTimeZone($timezone_string);
297
+				$tz_offset               = timezone_offset_get($date_time_zone_selected, date_create());
298
+				$right_now               = time();
299
+				$tr['isdst']             = false;
300
+				foreach (timezone_transitions_get($date_time_zone_selected) as $tr) {
301
+					if ($tr['ts'] > $right_now) {
302
+						$found = true;
303
+						break;
304
+					}
305
+				}
306
+
307
+				if ($found) {
308
+					$message = $tr['isdst'] ?
309
+						__(' Daylight saving time begins on: %s.') :
310
+						__(' Standard time begins  on: %s.');
311
+					// Add the difference between the current offset and the new offset to ts to get the correct transition time from date_i18n().
312
+					printf($message,
313
+						'<code >' . date_i18n($datetime_format, $tr['ts'] + ($tz_offset - $tr['offset'])) . '</code >');
314
+				} else {
315
+					_e('This timezone does not observe daylight saving time.');
316
+				}
317
+			}
318
+			// Set back to UTC.
319
+			date_default_timezone_set('UTC');
320
+			?>
321 321
 				</span></p>
322 322
         <?php
323
-    endif;
324
-    }
325
-
326
-
327
-    /**
328
-     * This method will take an incoming unix timestamp and add the offset to it for the given timezone_string.
329
-     * If no unix timestamp is given then time() is used.  If no timezone is given then the set timezone string for
330
-     * the site is used.
331
-     * This is used typically when using a Unix timestamp any core WP functions that expect their specially
332
-     * computed timestamp (i.e. date_i18n() )
333
-     *
334
-     * @param int    $unix_timestamp                  if 0, then time() will be used.
335
-     * @param string $timezone_string                 timezone_string. If empty, then the current set timezone for the
336
-     *                                                site will be used.
337
-     * @return int      $unix_timestamp with the offset applied for the given timezone.
338
-     */
339
-    public static function get_timestamp_with_offset($unix_timestamp = 0, $timezone_string = '')
340
-    {
341
-        $unix_timestamp  = $unix_timestamp === 0 ? time() : (int)$unix_timestamp;
342
-        $timezone_string = self::get_valid_timezone_string($timezone_string);
343
-        $TimeZone        = new DateTimeZone($timezone_string);
344
-
345
-        $DateTime = new DateTime('@' . $unix_timestamp, $TimeZone);
346
-        $offset   = timezone_offset_get($TimeZone, $DateTime);
347
-        return (int)$DateTime->format('U') + (int)$offset;
348
-    }
349
-
350
-
351
-    /**
352
-     *    _set_date_time_field
353
-     *    modifies EE_Base_Class EE_Datetime_Field objects
354
-     *
355
-     * @param  EE_Base_Class $obj                 EE_Base_Class object
356
-     * @param    DateTime    $DateTime            PHP DateTime object
357
-     * @param  string        $datetime_field_name the datetime fieldname to be manipulated
358
-     * @return    EE_Base_Class
359
-     */
360
-    protected static function _set_date_time_field(EE_Base_Class $obj, DateTime $DateTime, $datetime_field_name)
361
-    {
362
-        // grab current datetime format
363
-        $current_format = $obj->get_format();
364
-        // set new full timestamp format
365
-        $obj->set_date_format(EE_Datetime_Field::mysql_date_format);
366
-        $obj->set_time_format(EE_Datetime_Field::mysql_time_format);
367
-        // set the new date value using a full timestamp format so that no data is lost
368
-        $obj->set($datetime_field_name, $DateTime->format(EE_Datetime_Field::mysql_timestamp_format));
369
-        // reset datetime formats
370
-        $obj->set_date_format($current_format[0]);
371
-        $obj->set_time_format($current_format[1]);
372
-        return $obj;
373
-    }
374
-
375
-
376
-    /**
377
-     *    date_time_add
378
-     *    helper for doing simple datetime calculations on a given datetime from EE_Base_Class
379
-     *    and modifying it IN the EE_Base_Class so you don't have to do anything else.
380
-     *
381
-     * @param  EE_Base_Class $obj                 EE_Base_Class object
382
-     * @param  string        $datetime_field_name name of the EE_Datetime_Filed datatype db column to be manipulated
383
-     * @param  string        $period              what you are adding. The options are (years, months, days, hours,
384
-     *                                            minutes, seconds) defaults to years
385
-     * @param  integer       $value               what you want to increment the time by
386
-     * @return EE_Base_Class           return the EE_Base_Class object so right away you can do something with it
387
-     *                                 (chaining)
388
-     */
389
-    public static function date_time_add(EE_Base_Class $obj, $datetime_field_name, $period = 'years', $value = 1)
390
-    {
391
-        //get the raw UTC date.
392
-        $DateTime = $obj->get_DateTime_object($datetime_field_name);
393
-        $DateTime = EEH_DTT_Helper::calc_date($DateTime, $period, $value);
394
-        return EEH_DTT_Helper::_set_date_time_field($obj, $DateTime, $datetime_field_name);
395
-    }
396
-
397
-
398
-    /**
399
-     *    date_time_subtract
400
-     *    same as date_time_add except subtracting value instead of adding.
401
-     *
402
-     * @param \EE_Base_Class $obj
403
-     * @param  string        $datetime_field_name name of the EE_Datetime_Filed datatype db column to be manipulated
404
-     * @param string         $period
405
-     * @param int            $value
406
-     * @return \EE_Base_Class
407
-     */
408
-    public static function date_time_subtract(EE_Base_Class $obj, $datetime_field_name, $period = 'years', $value = 1)
409
-    {
410
-        //get the raw UTC date
411
-        $DateTime = $obj->get_DateTime_object($datetime_field_name);
412
-        $DateTime = EEH_DTT_Helper::calc_date($DateTime, $period, $value, '-');
413
-        return EEH_DTT_Helper::_set_date_time_field($obj, $DateTime, $datetime_field_name);
414
-    }
415
-
416
-
417
-    /**
418
-     * Simply takes an incoming DateTime object and does calculations on it based on the incoming parameters
419
-     *
420
-     * @param  DateTime $DateTime DateTime object
421
-     * @param  string   $period   a value to indicate what interval is being used in the calculation. The options are
422
-     *                            'years', 'months', 'days', 'hours', 'minutes', 'seconds'. Defaults to years.
423
-     * @param  integer  $value    What you want to increment the date by
424
-     * @param  string   $operand  What operand you wish to use for the calculation
425
-     * @return \DateTime return whatever type came in.
426
-     * @throws \EE_Error
427
-     */
428
-    protected static function _modify_datetime_object(DateTime $DateTime, $period = 'years', $value = 1, $operand = '+')
429
-    {
430
-        if (! $DateTime instanceof DateTime) {
431
-            throw new EE_Error(
432
-                sprintf(
433
-                    __('Expected a PHP DateTime object, but instead received %1$s', 'event_espresso'),
434
-                    print_r($DateTime, true)
435
-                )
436
-            );
437
-        }
438
-        switch ($period) {
439
-            case 'years' :
440
-                $value = 'P' . $value . 'Y';
441
-                break;
442
-            case 'months' :
443
-                $value = 'P' . $value . 'M';
444
-                break;
445
-            case 'weeks' :
446
-                $value = 'P' . $value . 'W';
447
-                break;
448
-            case 'days' :
449
-                $value = 'P' . $value . 'D';
450
-                break;
451
-            case 'hours' :
452
-                $value = 'PT' . $value . 'H';
453
-                break;
454
-            case 'minutes' :
455
-                $value = 'PT' . $value . 'M';
456
-                break;
457
-            case 'seconds' :
458
-                $value = 'PT' . $value . 'S';
459
-                break;
460
-        }
461
-        switch ($operand) {
462
-            case '+':
463
-                $DateTime->add(new DateInterval($value));
464
-                break;
465
-            case '-':
466
-                $DateTime->sub(new DateInterval($value));
467
-                break;
468
-        }
469
-        return $DateTime;
470
-    }
471
-
472
-
473
-    /**
474
-     * Simply takes an incoming Unix timestamp and does calculations on it based on the incoming parameters
475
-     *
476
-     * @param  int     $timestamp Unix timestamp
477
-     * @param  string  $period    a value to indicate what interval is being used in the calculation. The options are
478
-     *                            'years', 'months', 'days', 'hours', 'minutes', 'seconds'. Defaults to years.
479
-     * @param  integer $value     What you want to increment the date by
480
-     * @param  string  $operand   What operand you wish to use for the calculation
481
-     * @return \DateTime return whatever type came in.
482
-     * @throws \EE_Error
483
-     */
484
-    protected static function _modify_timestamp($timestamp, $period = 'years', $value = 1, $operand = '+')
485
-    {
486
-        if (! preg_match(EE_Datetime_Field::unix_timestamp_regex, $timestamp)) {
487
-            throw new EE_Error(
488
-                sprintf(
489
-                    __('Expected a Unix timestamp, but instead received %1$s', 'event_espresso'),
490
-                    print_r($timestamp, true)
491
-                )
492
-            );
493
-        }
494
-        switch ($period) {
495
-            case 'years' :
496
-                $value = YEAR_IN_SECONDS * $value;
497
-                break;
498
-            case 'months' :
499
-                $value = YEAR_IN_SECONDS / 12 * $value;
500
-                break;
501
-            case 'weeks' :
502
-                $value = WEEK_IN_SECONDS * $value;
503
-                break;
504
-            case 'days' :
505
-                $value = DAY_IN_SECONDS * $value;
506
-                break;
507
-            case 'hours' :
508
-                $value = HOUR_IN_SECONDS * $value;
509
-                break;
510
-            case 'minutes' :
511
-                $value = MINUTE_IN_SECONDS * $value;
512
-                break;
513
-        }
514
-        switch ($operand) {
515
-            case '+':
516
-                $timestamp += $value;
517
-                break;
518
-            case '-':
519
-                $timestamp -= $value;
520
-                break;
521
-        }
522
-        return $timestamp;
523
-    }
524
-
525
-
526
-    /**
527
-     * Simply takes an incoming UTC timestamp or DateTime object and does calculations on it based on the incoming
528
-     * parameters and returns the new timestamp or DateTime.
529
-     *
530
-     * @param  int | DateTime $DateTime_or_timestamp DateTime object or Unix timestamp
531
-     * @param  string         $period                a value to indicate what interval is being used in the
532
-     *                                               calculation. The options are 'years', 'months', 'days', 'hours',
533
-     *                                               'minutes', 'seconds'. Defaults to years.
534
-     * @param  integer        $value                 What you want to increment the date by
535
-     * @param  string         $operand               What operand you wish to use for the calculation
536
-     * @return mixed string|DateTime          return whatever type came in.
537
-     */
538
-    public static function calc_date($DateTime_or_timestamp, $period = 'years', $value = 1, $operand = '+')
539
-    {
540
-        if ($DateTime_or_timestamp instanceof DateTime) {
541
-            return EEH_DTT_Helper::_modify_datetime_object($DateTime_or_timestamp, $period, $value, $operand);
542
-        } else if (preg_match(EE_Datetime_Field::unix_timestamp_regex, $DateTime_or_timestamp)) {
543
-            return EEH_DTT_Helper::_modify_timestamp($DateTime_or_timestamp, $period, $value, $operand);
544
-        } else {
545
-            //error
546
-            return $DateTime_or_timestamp;
547
-        }
548
-    }
549
-
550
-
551
-    /**
552
-     * The purpose of this helper method is to receive an incoming format string in php date/time format
553
-     * and spit out the js and moment.js equivalent formats.
554
-     * Note, if no format string is given, then it is assumed the user wants what is set for WP.
555
-     * Note, js date and time formats are those used by the jquery-ui datepicker and the jquery-ui date-
556
-     * time picker.
557
-     *
558
-     * @see http://stackoverflow.com/posts/16725290/ for the code inspiration.
559
-     * @param null $date_format_string
560
-     * @param null $time_format_string
561
-     * @return array
562
-     *                array(
563
-     *                'js' => array (
564
-     *                'date' => //date format
565
-     *                'time' => //time format
566
-     *                ),
567
-     *                'moment' => //date and time format.
568
-     *                )
569
-     */
570
-    public static function convert_php_to_js_and_moment_date_formats(
571
-        $date_format_string = null,
572
-        $time_format_string = null
573
-    ) {
574
-        if ($date_format_string === null) {
575
-            $date_format_string = get_option('date_format');
576
-        }
577
-
578
-        if ($time_format_string === null) {
579
-            $time_format_string = get_option('time_format');
580
-        }
581
-
582
-        $date_format = self::_php_to_js_moment_converter($date_format_string);
583
-        $time_format = self::_php_to_js_moment_converter($time_format_string);
584
-
585
-        return array(
586
-            'js'     => array(
587
-                'date' => $date_format['js'],
588
-                'time' => $time_format['js'],
589
-            ),
590
-            'moment' => $date_format['moment'] . ' ' . $time_format['moment'],
591
-        );
592
-    }
593
-
594
-
595
-    /**
596
-     * This converts incoming format string into js and moment variations.
597
-     *
598
-     * @param string $format_string incoming php format string
599
-     * @return array js and moment formats.
600
-     */
601
-    protected static function _php_to_js_moment_converter($format_string)
602
-    {
603
-        /**
604
-         * This is a map of symbols for formats.
605
-         * The index is the php symbol, the equivalent values are in the array.
606
-         *
607
-         * @var array
608
-         */
609
-        $symbols_map      = array(
610
-            // Day
611
-            //01
612
-            'd' => array(
613
-                'js'     => 'dd',
614
-                'moment' => 'DD',
615
-            ),
616
-            //Mon
617
-            'D' => array(
618
-                'js'     => 'D',
619
-                'moment' => 'ddd',
620
-            ),
621
-            //1,2,...31
622
-            'j' => array(
623
-                'js'     => 'd',
624
-                'moment' => 'D',
625
-            ),
626
-            //Monday
627
-            'l' => array(
628
-                'js'     => 'DD',
629
-                'moment' => 'dddd',
630
-            ),
631
-            //ISO numeric representation of the day of the week (1-6)
632
-            'N' => array(
633
-                'js'     => '',
634
-                'moment' => 'E',
635
-            ),
636
-            //st,nd.rd
637
-            'S' => array(
638
-                'js'     => '',
639
-                'moment' => 'o',
640
-            ),
641
-            //numeric representation of day of week (0-6)
642
-            'w' => array(
643
-                'js'     => '',
644
-                'moment' => 'd',
645
-            ),
646
-            //day of year starting from 0 (0-365)
647
-            'z' => array(
648
-                'js'     => 'o',
649
-                'moment' => 'DDD' //note moment does not start with 0 so will need to modify by subtracting 1
650
-            ),
651
-            // Week
652
-            //ISO-8601 week number of year (weeks starting on monday)
653
-            'W' => array(
654
-                'js'     => '',
655
-                'moment' => 'w',
656
-            ),
657
-            // Month
658
-            // January...December
659
-            'F' => array(
660
-                'js'     => 'MM',
661
-                'moment' => 'MMMM',
662
-            ),
663
-            //01...12
664
-            'm' => array(
665
-                'js'     => 'mm',
666
-                'moment' => 'MM',
667
-            ),
668
-            //Jan...Dec
669
-            'M' => array(
670
-                'js'     => 'M',
671
-                'moment' => 'MMM',
672
-            ),
673
-            //1-12
674
-            'n' => array(
675
-                'js'     => 'm',
676
-                'moment' => 'M',
677
-            ),
678
-            //number of days in given month
679
-            't' => array(
680
-                'js'     => '',
681
-                'moment' => '',
682
-            ),
683
-            // Year
684
-            //whether leap year or not 1/0
685
-            'L' => array(
686
-                'js'     => '',
687
-                'moment' => '',
688
-            ),
689
-            //ISO-8601 year number
690
-            'o' => array(
691
-                'js'     => '',
692
-                'moment' => 'GGGG',
693
-            ),
694
-            //1999...2003
695
-            'Y' => array(
696
-                'js'     => 'yy',
697
-                'moment' => 'YYYY',
698
-            ),
699
-            //99...03
700
-            'y' => array(
701
-                'js'     => 'y',
702
-                'moment' => 'YY',
703
-            ),
704
-            // Time
705
-            // am/pm
706
-            'a' => array(
707
-                'js'     => 'tt',
708
-                'moment' => 'a',
709
-            ),
710
-            // AM/PM
711
-            'A' => array(
712
-                'js'     => 'TT',
713
-                'moment' => 'A',
714
-            ),
715
-            // Swatch Internet Time?!?
716
-            'B' => array(
717
-                'js'     => '',
718
-                'moment' => '',
719
-            ),
720
-            //1...12
721
-            'g' => array(
722
-                'js'     => 'h',
723
-                'moment' => 'h',
724
-            ),
725
-            //0...23
726
-            'G' => array(
727
-                'js'     => 'H',
728
-                'moment' => 'H',
729
-            ),
730
-            //01...12
731
-            'h' => array(
732
-                'js'     => 'hh',
733
-                'moment' => 'hh',
734
-            ),
735
-            //00...23
736
-            'H' => array(
737
-                'js'     => 'HH',
738
-                'moment' => 'HH',
739
-            ),
740
-            //00..59
741
-            'i' => array(
742
-                'js'     => 'mm',
743
-                'moment' => 'mm',
744
-            ),
745
-            //seconds... 00...59
746
-            's' => array(
747
-                'js'     => 'ss',
748
-                'moment' => 'ss',
749
-            ),
750
-            //microseconds
751
-            'u' => array(
752
-                'js'     => '',
753
-                'moment' => '',
754
-            ),
755
-        );
756
-        $jquery_ui_format = "";
757
-        $moment_format    = "";
758
-        $escaping         = false;
759
-        for ($i = 0; $i < strlen($format_string); $i++) {
760
-            $char = $format_string[$i];
761
-            if ($char === '\\') { // PHP date format escaping character
762
-                $i++;
763
-                if ($escaping) {
764
-                    $jquery_ui_format .= $format_string[$i];
765
-                    $moment_format .= $format_string[$i];
766
-                } else {
767
-                    $jquery_ui_format .= '\'' . $format_string[$i];
768
-                    $moment_format .= $format_string[$i];
769
-                }
770
-                $escaping = true;
771
-            } else {
772
-                if ($escaping) {
773
-                    $jquery_ui_format .= "'";
774
-                    $moment_format .= "'";
775
-                    $escaping = false;
776
-                }
777
-                if (isset($symbols_map[$char])) {
778
-                    $jquery_ui_format .= $symbols_map[$char]['js'];
779
-                    $moment_format .= $symbols_map[$char]['moment'];
780
-                } else {
781
-                    $jquery_ui_format .= $char;
782
-                    $moment_format .= $char;
783
-                }
784
-            }
785
-        }
786
-        return array('js' => $jquery_ui_format, 'moment' => $moment_format);
787
-    }
788
-
789
-
790
-    /**
791
-     * This takes an incoming format string and validates it to ensure it will work fine with PHP.
792
-     *
793
-     * @param string $format_string   Incoming format string for php date().
794
-     * @return mixed bool|array  If all is okay then TRUE is returned.  Otherwise an array of validation
795
-     *                                errors is returned.  So for client code calling, check for is_array() to
796
-     *                                indicate failed validations.
797
-     */
798
-    public static function validate_format_string($format_string)
799
-    {
800
-        $error_msg = array();
801
-        //time format checks
802
-        switch (true) {
803
-            case   strpos($format_string, 'h') !== false  :
804
-            case   strpos($format_string, 'g') !== false :
805
-                /**
806
-                 * if the time string has a lowercase 'h' which == 12 hour time format and there
807
-                 * is not any ante meridiem format ('a' or 'A').  Then throw an error because its
808
-                 * too ambiguous and PHP won't be able to figure out whether 1 = 1pm or 1am.
809
-                 */
810
-                if (strpos(strtoupper($format_string), 'A') === false) {
811
-                    $error_msg[] = __('There is a  time format for 12 hour time but no  "a" or "A" to indicate am/pm.  Without this distinction, PHP is unable to determine if a "1" for the hour value equals "1pm" or "1am".',
812
-                        'event_espresso');
813
-                }
814
-                break;
815
-
816
-        }
817
-
818
-        return empty($error_msg) ? true : $error_msg;
819
-    }
820
-
821
-
822
-    /**
823
-     *     If the the first date starts at midnight on one day, and the next date ends at midnight on the
824
-     *     very next day then this method will return true.
825
-     *    If $date_1 = 2015-12-15 00:00:00 and $date_2 = 2015-12-16 00:00:00 then this function will return true.
826
-     *    If $date_1 = 2015-12-15 03:00:00 and $date_2 = 2015-12_16 03:00:00 then this function will return false.
827
-     *    If $date_1 = 2015-12-15 00:00:00 and $date_2 = 2015-12-15 00:00:00 then this function will return true.
828
-     *
829
-     * @param mixed $date_1
830
-     * @param mixed $date_2
831
-     * @return bool
832
-     */
833
-    public static function dates_represent_one_24_hour_date($date_1, $date_2)
834
-    {
835
-
836
-        if (
837
-            (! $date_1 instanceof DateTime || ! $date_2 instanceof DateTime) ||
838
-            ($date_1->format(EE_Datetime_Field::mysql_time_format) != '00:00:00' || $date_2->format(EE_Datetime_Field::mysql_time_format) != '00:00:00')
839
-        ) {
840
-            return false;
841
-        }
842
-        return $date_2->format('U') - $date_1->format('U') == 86400 ? true : false;
843
-    }
844
-
845
-
846
-    /**
847
-     * This returns the appropriate query interval string that can be used in sql queries involving mysql Date
848
-     * Functions.
849
-     *
850
-     * @param string $timezone_string    A timezone string in a valid format to instantiate a DateTimeZone object.
851
-     * @param string $field_for_interval The Database field that is the interval is applied to in the query.
852
-     * @return string
853
-     */
854
-    public static function get_sql_query_interval_for_offset($timezone_string, $field_for_interval)
855
-    {
856
-        try {
857
-            /** need to account for timezone offset on the selects */
858
-            $DateTimeZone = new DateTimeZone($timezone_string);
859
-        } catch (Exception $e) {
860
-            $DateTimeZone = null;
861
-        }
862
-
863
-        /**
864
-         * Note get_option( 'gmt_offset') returns a value in hours, whereas DateTimeZone::getOffset returns values in seconds.
865
-         * Hence we do the calc for DateTimeZone::getOffset.
866
-         */
867
-        $offset         = $DateTimeZone instanceof DateTimeZone ? ($DateTimeZone->getOffset(new DateTime('now'))) / HOUR_IN_SECONDS : get_option('gmt_offset');
868
-        $query_interval = $offset < 0
869
-            ? 'DATE_SUB(' . $field_for_interval . ', INTERVAL ' . $offset * -1 . ' HOUR)'
870
-            : 'DATE_ADD(' . $field_for_interval . ', INTERVAL ' . $offset . ' HOUR)';
871
-        return $query_interval;
872
-    }
873
-
874
-    /**
875
-     * Retrieves the site's default timezone and returns it formatted so it's ready for display
876
-     * to users. If you want to customize how its displayed feel free to fetch the 'timezone_string'
877
-     * and 'gmt_offset' WordPress options directly; or use the filter
878
-     * FHEE__EEH_DTT_Helper__get_timezone_string_for_display
879
-     * (although note that we remove any HTML that may be added)
880
-     *
881
-     * @return string
882
-     */
883
-    public static function get_timezone_string_for_display()
884
-    {
885
-        $pretty_timezone = apply_filters('FHEE__EEH_DTT_Helper__get_timezone_string_for_display', '');
886
-        if (! empty($pretty_timezone)) {
887
-            return esc_html($pretty_timezone);
888
-        }
889
-        $timezone_string = get_option('timezone_string');
890
-        if ($timezone_string) {
891
-            static $mo_loaded = false;
892
-            // Load translations for continents and cities just like wp_timezone_choice does
893
-            if (! $mo_loaded) {
894
-                $locale = get_locale();
895
-                $mofile = WP_LANG_DIR . '/continents-cities-' . $locale . '.mo';
896
-                load_textdomain('continents-cities', $mofile);
897
-                $mo_loaded = true;
898
-            }
899
-            //well that was easy.
900
-            $parts = explode('/', $timezone_string);
901
-            //remove the continent
902
-            unset($parts[0]);
903
-            $t_parts = array();
904
-            foreach ($parts as $part) {
905
-                $t_parts[] = translate(str_replace('_', ' ', $part), 'continents-cities');
906
-            }
907
-            return implode(' - ', $t_parts);
908
-        }
909
-        //they haven't set the timezone string, so let's return a string like "UTC+1"
910
-        $gmt_offset = get_option('gmt_offset');
911
-        if (intval($gmt_offset) >= 0) {
912
-            $prefix = '+';
913
-        } else {
914
-            $prefix = '';
915
-        }
916
-        $parts = explode('.', (string)$gmt_offset);
917
-        if (count($parts) === 1) {
918
-            $parts[1] = '00';
919
-        } else {
920
-            //convert the part after the decimal, eg "5" (from x.5) or "25" (from x.25)
921
-            //to minutes, eg 30 or 15, respectively
922
-            $hour_fraction = (float)('0.' . $parts[1]);
923
-            $parts[1]      = (string)$hour_fraction * 60;
924
-        }
925
-        return sprintf(__('UTC%1$s', 'event_espresso'), $prefix . implode(':', $parts));
926
-    }
927
-
928
-
929
-
930
-    /**
931
-     * So PHP does this awesome thing where if you are trying to get a timestamp
932
-     * for a month using a string like "February" or "February 2017",
933
-     * and you don't specify a day as part of your string,
934
-     * then PHP will use whatever the current day of the month is.
935
-     * IF the current day of the month happens to be the 30th or 31st,
936
-     * then PHP gets really confused by a date like February 30,
937
-     * so instead of saying
938
-     *      "Hey February only has 28 days (this year)...
939
-     *      ...you must have meant the last day of the month!"
940
-     * PHP does the next most logical thing, and bumps the date up to March 2nd,
941
-     * because someone requesting February 30th obviously meant March 1st!
942
-     * The way around this is to always set the day to the first,
943
-     * so that the month will stay on the month you wanted.
944
-     * this method will add that "1" into your date regardless of the format.
945
-     *
946
-     * @param string $month
947
-     * @return string
948
-     */
949
-    public static function first_of_month_timestamp($month = '')
950
-    {
951
-        $month = (string)$month;
952
-        $year = '';
953
-        // check if the incoming string has a year in it or not
954
-       if (preg_match('/\b\d{4}\b/', $month, $matches)) {
955
-           $year = $matches[0];
956
-           // ten remove that from the month string as well as any spaces
957
-           $month = trim(str_replace($year, '', $month));
958
-           // add a space before the year
959
-           $year = " {$year}";
960
-        }
961
-        // return timestamp for something like "February 1 2017"
962
-        return strtotime("{$month} 1{$year}");
963
-    }
323
+	endif;
324
+	}
325
+
326
+
327
+	/**
328
+	 * This method will take an incoming unix timestamp and add the offset to it for the given timezone_string.
329
+	 * If no unix timestamp is given then time() is used.  If no timezone is given then the set timezone string for
330
+	 * the site is used.
331
+	 * This is used typically when using a Unix timestamp any core WP functions that expect their specially
332
+	 * computed timestamp (i.e. date_i18n() )
333
+	 *
334
+	 * @param int    $unix_timestamp                  if 0, then time() will be used.
335
+	 * @param string $timezone_string                 timezone_string. If empty, then the current set timezone for the
336
+	 *                                                site will be used.
337
+	 * @return int      $unix_timestamp with the offset applied for the given timezone.
338
+	 */
339
+	public static function get_timestamp_with_offset($unix_timestamp = 0, $timezone_string = '')
340
+	{
341
+		$unix_timestamp  = $unix_timestamp === 0 ? time() : (int)$unix_timestamp;
342
+		$timezone_string = self::get_valid_timezone_string($timezone_string);
343
+		$TimeZone        = new DateTimeZone($timezone_string);
344
+
345
+		$DateTime = new DateTime('@' . $unix_timestamp, $TimeZone);
346
+		$offset   = timezone_offset_get($TimeZone, $DateTime);
347
+		return (int)$DateTime->format('U') + (int)$offset;
348
+	}
349
+
350
+
351
+	/**
352
+	 *    _set_date_time_field
353
+	 *    modifies EE_Base_Class EE_Datetime_Field objects
354
+	 *
355
+	 * @param  EE_Base_Class $obj                 EE_Base_Class object
356
+	 * @param    DateTime    $DateTime            PHP DateTime object
357
+	 * @param  string        $datetime_field_name the datetime fieldname to be manipulated
358
+	 * @return    EE_Base_Class
359
+	 */
360
+	protected static function _set_date_time_field(EE_Base_Class $obj, DateTime $DateTime, $datetime_field_name)
361
+	{
362
+		// grab current datetime format
363
+		$current_format = $obj->get_format();
364
+		// set new full timestamp format
365
+		$obj->set_date_format(EE_Datetime_Field::mysql_date_format);
366
+		$obj->set_time_format(EE_Datetime_Field::mysql_time_format);
367
+		// set the new date value using a full timestamp format so that no data is lost
368
+		$obj->set($datetime_field_name, $DateTime->format(EE_Datetime_Field::mysql_timestamp_format));
369
+		// reset datetime formats
370
+		$obj->set_date_format($current_format[0]);
371
+		$obj->set_time_format($current_format[1]);
372
+		return $obj;
373
+	}
374
+
375
+
376
+	/**
377
+	 *    date_time_add
378
+	 *    helper for doing simple datetime calculations on a given datetime from EE_Base_Class
379
+	 *    and modifying it IN the EE_Base_Class so you don't have to do anything else.
380
+	 *
381
+	 * @param  EE_Base_Class $obj                 EE_Base_Class object
382
+	 * @param  string        $datetime_field_name name of the EE_Datetime_Filed datatype db column to be manipulated
383
+	 * @param  string        $period              what you are adding. The options are (years, months, days, hours,
384
+	 *                                            minutes, seconds) defaults to years
385
+	 * @param  integer       $value               what you want to increment the time by
386
+	 * @return EE_Base_Class           return the EE_Base_Class object so right away you can do something with it
387
+	 *                                 (chaining)
388
+	 */
389
+	public static function date_time_add(EE_Base_Class $obj, $datetime_field_name, $period = 'years', $value = 1)
390
+	{
391
+		//get the raw UTC date.
392
+		$DateTime = $obj->get_DateTime_object($datetime_field_name);
393
+		$DateTime = EEH_DTT_Helper::calc_date($DateTime, $period, $value);
394
+		return EEH_DTT_Helper::_set_date_time_field($obj, $DateTime, $datetime_field_name);
395
+	}
396
+
397
+
398
+	/**
399
+	 *    date_time_subtract
400
+	 *    same as date_time_add except subtracting value instead of adding.
401
+	 *
402
+	 * @param \EE_Base_Class $obj
403
+	 * @param  string        $datetime_field_name name of the EE_Datetime_Filed datatype db column to be manipulated
404
+	 * @param string         $period
405
+	 * @param int            $value
406
+	 * @return \EE_Base_Class
407
+	 */
408
+	public static function date_time_subtract(EE_Base_Class $obj, $datetime_field_name, $period = 'years', $value = 1)
409
+	{
410
+		//get the raw UTC date
411
+		$DateTime = $obj->get_DateTime_object($datetime_field_name);
412
+		$DateTime = EEH_DTT_Helper::calc_date($DateTime, $period, $value, '-');
413
+		return EEH_DTT_Helper::_set_date_time_field($obj, $DateTime, $datetime_field_name);
414
+	}
415
+
416
+
417
+	/**
418
+	 * Simply takes an incoming DateTime object and does calculations on it based on the incoming parameters
419
+	 *
420
+	 * @param  DateTime $DateTime DateTime object
421
+	 * @param  string   $period   a value to indicate what interval is being used in the calculation. The options are
422
+	 *                            'years', 'months', 'days', 'hours', 'minutes', 'seconds'. Defaults to years.
423
+	 * @param  integer  $value    What you want to increment the date by
424
+	 * @param  string   $operand  What operand you wish to use for the calculation
425
+	 * @return \DateTime return whatever type came in.
426
+	 * @throws \EE_Error
427
+	 */
428
+	protected static function _modify_datetime_object(DateTime $DateTime, $period = 'years', $value = 1, $operand = '+')
429
+	{
430
+		if (! $DateTime instanceof DateTime) {
431
+			throw new EE_Error(
432
+				sprintf(
433
+					__('Expected a PHP DateTime object, but instead received %1$s', 'event_espresso'),
434
+					print_r($DateTime, true)
435
+				)
436
+			);
437
+		}
438
+		switch ($period) {
439
+			case 'years' :
440
+				$value = 'P' . $value . 'Y';
441
+				break;
442
+			case 'months' :
443
+				$value = 'P' . $value . 'M';
444
+				break;
445
+			case 'weeks' :
446
+				$value = 'P' . $value . 'W';
447
+				break;
448
+			case 'days' :
449
+				$value = 'P' . $value . 'D';
450
+				break;
451
+			case 'hours' :
452
+				$value = 'PT' . $value . 'H';
453
+				break;
454
+			case 'minutes' :
455
+				$value = 'PT' . $value . 'M';
456
+				break;
457
+			case 'seconds' :
458
+				$value = 'PT' . $value . 'S';
459
+				break;
460
+		}
461
+		switch ($operand) {
462
+			case '+':
463
+				$DateTime->add(new DateInterval($value));
464
+				break;
465
+			case '-':
466
+				$DateTime->sub(new DateInterval($value));
467
+				break;
468
+		}
469
+		return $DateTime;
470
+	}
471
+
472
+
473
+	/**
474
+	 * Simply takes an incoming Unix timestamp and does calculations on it based on the incoming parameters
475
+	 *
476
+	 * @param  int     $timestamp Unix timestamp
477
+	 * @param  string  $period    a value to indicate what interval is being used in the calculation. The options are
478
+	 *                            'years', 'months', 'days', 'hours', 'minutes', 'seconds'. Defaults to years.
479
+	 * @param  integer $value     What you want to increment the date by
480
+	 * @param  string  $operand   What operand you wish to use for the calculation
481
+	 * @return \DateTime return whatever type came in.
482
+	 * @throws \EE_Error
483
+	 */
484
+	protected static function _modify_timestamp($timestamp, $period = 'years', $value = 1, $operand = '+')
485
+	{
486
+		if (! preg_match(EE_Datetime_Field::unix_timestamp_regex, $timestamp)) {
487
+			throw new EE_Error(
488
+				sprintf(
489
+					__('Expected a Unix timestamp, but instead received %1$s', 'event_espresso'),
490
+					print_r($timestamp, true)
491
+				)
492
+			);
493
+		}
494
+		switch ($period) {
495
+			case 'years' :
496
+				$value = YEAR_IN_SECONDS * $value;
497
+				break;
498
+			case 'months' :
499
+				$value = YEAR_IN_SECONDS / 12 * $value;
500
+				break;
501
+			case 'weeks' :
502
+				$value = WEEK_IN_SECONDS * $value;
503
+				break;
504
+			case 'days' :
505
+				$value = DAY_IN_SECONDS * $value;
506
+				break;
507
+			case 'hours' :
508
+				$value = HOUR_IN_SECONDS * $value;
509
+				break;
510
+			case 'minutes' :
511
+				$value = MINUTE_IN_SECONDS * $value;
512
+				break;
513
+		}
514
+		switch ($operand) {
515
+			case '+':
516
+				$timestamp += $value;
517
+				break;
518
+			case '-':
519
+				$timestamp -= $value;
520
+				break;
521
+		}
522
+		return $timestamp;
523
+	}
524
+
525
+
526
+	/**
527
+	 * Simply takes an incoming UTC timestamp or DateTime object and does calculations on it based on the incoming
528
+	 * parameters and returns the new timestamp or DateTime.
529
+	 *
530
+	 * @param  int | DateTime $DateTime_or_timestamp DateTime object or Unix timestamp
531
+	 * @param  string         $period                a value to indicate what interval is being used in the
532
+	 *                                               calculation. The options are 'years', 'months', 'days', 'hours',
533
+	 *                                               'minutes', 'seconds'. Defaults to years.
534
+	 * @param  integer        $value                 What you want to increment the date by
535
+	 * @param  string         $operand               What operand you wish to use for the calculation
536
+	 * @return mixed string|DateTime          return whatever type came in.
537
+	 */
538
+	public static function calc_date($DateTime_or_timestamp, $period = 'years', $value = 1, $operand = '+')
539
+	{
540
+		if ($DateTime_or_timestamp instanceof DateTime) {
541
+			return EEH_DTT_Helper::_modify_datetime_object($DateTime_or_timestamp, $period, $value, $operand);
542
+		} else if (preg_match(EE_Datetime_Field::unix_timestamp_regex, $DateTime_or_timestamp)) {
543
+			return EEH_DTT_Helper::_modify_timestamp($DateTime_or_timestamp, $period, $value, $operand);
544
+		} else {
545
+			//error
546
+			return $DateTime_or_timestamp;
547
+		}
548
+	}
549
+
550
+
551
+	/**
552
+	 * The purpose of this helper method is to receive an incoming format string in php date/time format
553
+	 * and spit out the js and moment.js equivalent formats.
554
+	 * Note, if no format string is given, then it is assumed the user wants what is set for WP.
555
+	 * Note, js date and time formats are those used by the jquery-ui datepicker and the jquery-ui date-
556
+	 * time picker.
557
+	 *
558
+	 * @see http://stackoverflow.com/posts/16725290/ for the code inspiration.
559
+	 * @param null $date_format_string
560
+	 * @param null $time_format_string
561
+	 * @return array
562
+	 *                array(
563
+	 *                'js' => array (
564
+	 *                'date' => //date format
565
+	 *                'time' => //time format
566
+	 *                ),
567
+	 *                'moment' => //date and time format.
568
+	 *                )
569
+	 */
570
+	public static function convert_php_to_js_and_moment_date_formats(
571
+		$date_format_string = null,
572
+		$time_format_string = null
573
+	) {
574
+		if ($date_format_string === null) {
575
+			$date_format_string = get_option('date_format');
576
+		}
577
+
578
+		if ($time_format_string === null) {
579
+			$time_format_string = get_option('time_format');
580
+		}
581
+
582
+		$date_format = self::_php_to_js_moment_converter($date_format_string);
583
+		$time_format = self::_php_to_js_moment_converter($time_format_string);
584
+
585
+		return array(
586
+			'js'     => array(
587
+				'date' => $date_format['js'],
588
+				'time' => $time_format['js'],
589
+			),
590
+			'moment' => $date_format['moment'] . ' ' . $time_format['moment'],
591
+		);
592
+	}
593
+
594
+
595
+	/**
596
+	 * This converts incoming format string into js and moment variations.
597
+	 *
598
+	 * @param string $format_string incoming php format string
599
+	 * @return array js and moment formats.
600
+	 */
601
+	protected static function _php_to_js_moment_converter($format_string)
602
+	{
603
+		/**
604
+		 * This is a map of symbols for formats.
605
+		 * The index is the php symbol, the equivalent values are in the array.
606
+		 *
607
+		 * @var array
608
+		 */
609
+		$symbols_map      = array(
610
+			// Day
611
+			//01
612
+			'd' => array(
613
+				'js'     => 'dd',
614
+				'moment' => 'DD',
615
+			),
616
+			//Mon
617
+			'D' => array(
618
+				'js'     => 'D',
619
+				'moment' => 'ddd',
620
+			),
621
+			//1,2,...31
622
+			'j' => array(
623
+				'js'     => 'd',
624
+				'moment' => 'D',
625
+			),
626
+			//Monday
627
+			'l' => array(
628
+				'js'     => 'DD',
629
+				'moment' => 'dddd',
630
+			),
631
+			//ISO numeric representation of the day of the week (1-6)
632
+			'N' => array(
633
+				'js'     => '',
634
+				'moment' => 'E',
635
+			),
636
+			//st,nd.rd
637
+			'S' => array(
638
+				'js'     => '',
639
+				'moment' => 'o',
640
+			),
641
+			//numeric representation of day of week (0-6)
642
+			'w' => array(
643
+				'js'     => '',
644
+				'moment' => 'd',
645
+			),
646
+			//day of year starting from 0 (0-365)
647
+			'z' => array(
648
+				'js'     => 'o',
649
+				'moment' => 'DDD' //note moment does not start with 0 so will need to modify by subtracting 1
650
+			),
651
+			// Week
652
+			//ISO-8601 week number of year (weeks starting on monday)
653
+			'W' => array(
654
+				'js'     => '',
655
+				'moment' => 'w',
656
+			),
657
+			// Month
658
+			// January...December
659
+			'F' => array(
660
+				'js'     => 'MM',
661
+				'moment' => 'MMMM',
662
+			),
663
+			//01...12
664
+			'm' => array(
665
+				'js'     => 'mm',
666
+				'moment' => 'MM',
667
+			),
668
+			//Jan...Dec
669
+			'M' => array(
670
+				'js'     => 'M',
671
+				'moment' => 'MMM',
672
+			),
673
+			//1-12
674
+			'n' => array(
675
+				'js'     => 'm',
676
+				'moment' => 'M',
677
+			),
678
+			//number of days in given month
679
+			't' => array(
680
+				'js'     => '',
681
+				'moment' => '',
682
+			),
683
+			// Year
684
+			//whether leap year or not 1/0
685
+			'L' => array(
686
+				'js'     => '',
687
+				'moment' => '',
688
+			),
689
+			//ISO-8601 year number
690
+			'o' => array(
691
+				'js'     => '',
692
+				'moment' => 'GGGG',
693
+			),
694
+			//1999...2003
695
+			'Y' => array(
696
+				'js'     => 'yy',
697
+				'moment' => 'YYYY',
698
+			),
699
+			//99...03
700
+			'y' => array(
701
+				'js'     => 'y',
702
+				'moment' => 'YY',
703
+			),
704
+			// Time
705
+			// am/pm
706
+			'a' => array(
707
+				'js'     => 'tt',
708
+				'moment' => 'a',
709
+			),
710
+			// AM/PM
711
+			'A' => array(
712
+				'js'     => 'TT',
713
+				'moment' => 'A',
714
+			),
715
+			// Swatch Internet Time?!?
716
+			'B' => array(
717
+				'js'     => '',
718
+				'moment' => '',
719
+			),
720
+			//1...12
721
+			'g' => array(
722
+				'js'     => 'h',
723
+				'moment' => 'h',
724
+			),
725
+			//0...23
726
+			'G' => array(
727
+				'js'     => 'H',
728
+				'moment' => 'H',
729
+			),
730
+			//01...12
731
+			'h' => array(
732
+				'js'     => 'hh',
733
+				'moment' => 'hh',
734
+			),
735
+			//00...23
736
+			'H' => array(
737
+				'js'     => 'HH',
738
+				'moment' => 'HH',
739
+			),
740
+			//00..59
741
+			'i' => array(
742
+				'js'     => 'mm',
743
+				'moment' => 'mm',
744
+			),
745
+			//seconds... 00...59
746
+			's' => array(
747
+				'js'     => 'ss',
748
+				'moment' => 'ss',
749
+			),
750
+			//microseconds
751
+			'u' => array(
752
+				'js'     => '',
753
+				'moment' => '',
754
+			),
755
+		);
756
+		$jquery_ui_format = "";
757
+		$moment_format    = "";
758
+		$escaping         = false;
759
+		for ($i = 0; $i < strlen($format_string); $i++) {
760
+			$char = $format_string[$i];
761
+			if ($char === '\\') { // PHP date format escaping character
762
+				$i++;
763
+				if ($escaping) {
764
+					$jquery_ui_format .= $format_string[$i];
765
+					$moment_format .= $format_string[$i];
766
+				} else {
767
+					$jquery_ui_format .= '\'' . $format_string[$i];
768
+					$moment_format .= $format_string[$i];
769
+				}
770
+				$escaping = true;
771
+			} else {
772
+				if ($escaping) {
773
+					$jquery_ui_format .= "'";
774
+					$moment_format .= "'";
775
+					$escaping = false;
776
+				}
777
+				if (isset($symbols_map[$char])) {
778
+					$jquery_ui_format .= $symbols_map[$char]['js'];
779
+					$moment_format .= $symbols_map[$char]['moment'];
780
+				} else {
781
+					$jquery_ui_format .= $char;
782
+					$moment_format .= $char;
783
+				}
784
+			}
785
+		}
786
+		return array('js' => $jquery_ui_format, 'moment' => $moment_format);
787
+	}
788
+
789
+
790
+	/**
791
+	 * This takes an incoming format string and validates it to ensure it will work fine with PHP.
792
+	 *
793
+	 * @param string $format_string   Incoming format string for php date().
794
+	 * @return mixed bool|array  If all is okay then TRUE is returned.  Otherwise an array of validation
795
+	 *                                errors is returned.  So for client code calling, check for is_array() to
796
+	 *                                indicate failed validations.
797
+	 */
798
+	public static function validate_format_string($format_string)
799
+	{
800
+		$error_msg = array();
801
+		//time format checks
802
+		switch (true) {
803
+			case   strpos($format_string, 'h') !== false  :
804
+			case   strpos($format_string, 'g') !== false :
805
+				/**
806
+				 * if the time string has a lowercase 'h' which == 12 hour time format and there
807
+				 * is not any ante meridiem format ('a' or 'A').  Then throw an error because its
808
+				 * too ambiguous and PHP won't be able to figure out whether 1 = 1pm or 1am.
809
+				 */
810
+				if (strpos(strtoupper($format_string), 'A') === false) {
811
+					$error_msg[] = __('There is a  time format for 12 hour time but no  "a" or "A" to indicate am/pm.  Without this distinction, PHP is unable to determine if a "1" for the hour value equals "1pm" or "1am".',
812
+						'event_espresso');
813
+				}
814
+				break;
815
+
816
+		}
817
+
818
+		return empty($error_msg) ? true : $error_msg;
819
+	}
820
+
821
+
822
+	/**
823
+	 *     If the the first date starts at midnight on one day, and the next date ends at midnight on the
824
+	 *     very next day then this method will return true.
825
+	 *    If $date_1 = 2015-12-15 00:00:00 and $date_2 = 2015-12-16 00:00:00 then this function will return true.
826
+	 *    If $date_1 = 2015-12-15 03:00:00 and $date_2 = 2015-12_16 03:00:00 then this function will return false.
827
+	 *    If $date_1 = 2015-12-15 00:00:00 and $date_2 = 2015-12-15 00:00:00 then this function will return true.
828
+	 *
829
+	 * @param mixed $date_1
830
+	 * @param mixed $date_2
831
+	 * @return bool
832
+	 */
833
+	public static function dates_represent_one_24_hour_date($date_1, $date_2)
834
+	{
835
+
836
+		if (
837
+			(! $date_1 instanceof DateTime || ! $date_2 instanceof DateTime) ||
838
+			($date_1->format(EE_Datetime_Field::mysql_time_format) != '00:00:00' || $date_2->format(EE_Datetime_Field::mysql_time_format) != '00:00:00')
839
+		) {
840
+			return false;
841
+		}
842
+		return $date_2->format('U') - $date_1->format('U') == 86400 ? true : false;
843
+	}
844
+
845
+
846
+	/**
847
+	 * This returns the appropriate query interval string that can be used in sql queries involving mysql Date
848
+	 * Functions.
849
+	 *
850
+	 * @param string $timezone_string    A timezone string in a valid format to instantiate a DateTimeZone object.
851
+	 * @param string $field_for_interval The Database field that is the interval is applied to in the query.
852
+	 * @return string
853
+	 */
854
+	public static function get_sql_query_interval_for_offset($timezone_string, $field_for_interval)
855
+	{
856
+		try {
857
+			/** need to account for timezone offset on the selects */
858
+			$DateTimeZone = new DateTimeZone($timezone_string);
859
+		} catch (Exception $e) {
860
+			$DateTimeZone = null;
861
+		}
862
+
863
+		/**
864
+		 * Note get_option( 'gmt_offset') returns a value in hours, whereas DateTimeZone::getOffset returns values in seconds.
865
+		 * Hence we do the calc for DateTimeZone::getOffset.
866
+		 */
867
+		$offset         = $DateTimeZone instanceof DateTimeZone ? ($DateTimeZone->getOffset(new DateTime('now'))) / HOUR_IN_SECONDS : get_option('gmt_offset');
868
+		$query_interval = $offset < 0
869
+			? 'DATE_SUB(' . $field_for_interval . ', INTERVAL ' . $offset * -1 . ' HOUR)'
870
+			: 'DATE_ADD(' . $field_for_interval . ', INTERVAL ' . $offset . ' HOUR)';
871
+		return $query_interval;
872
+	}
873
+
874
+	/**
875
+	 * Retrieves the site's default timezone and returns it formatted so it's ready for display
876
+	 * to users. If you want to customize how its displayed feel free to fetch the 'timezone_string'
877
+	 * and 'gmt_offset' WordPress options directly; or use the filter
878
+	 * FHEE__EEH_DTT_Helper__get_timezone_string_for_display
879
+	 * (although note that we remove any HTML that may be added)
880
+	 *
881
+	 * @return string
882
+	 */
883
+	public static function get_timezone_string_for_display()
884
+	{
885
+		$pretty_timezone = apply_filters('FHEE__EEH_DTT_Helper__get_timezone_string_for_display', '');
886
+		if (! empty($pretty_timezone)) {
887
+			return esc_html($pretty_timezone);
888
+		}
889
+		$timezone_string = get_option('timezone_string');
890
+		if ($timezone_string) {
891
+			static $mo_loaded = false;
892
+			// Load translations for continents and cities just like wp_timezone_choice does
893
+			if (! $mo_loaded) {
894
+				$locale = get_locale();
895
+				$mofile = WP_LANG_DIR . '/continents-cities-' . $locale . '.mo';
896
+				load_textdomain('continents-cities', $mofile);
897
+				$mo_loaded = true;
898
+			}
899
+			//well that was easy.
900
+			$parts = explode('/', $timezone_string);
901
+			//remove the continent
902
+			unset($parts[0]);
903
+			$t_parts = array();
904
+			foreach ($parts as $part) {
905
+				$t_parts[] = translate(str_replace('_', ' ', $part), 'continents-cities');
906
+			}
907
+			return implode(' - ', $t_parts);
908
+		}
909
+		//they haven't set the timezone string, so let's return a string like "UTC+1"
910
+		$gmt_offset = get_option('gmt_offset');
911
+		if (intval($gmt_offset) >= 0) {
912
+			$prefix = '+';
913
+		} else {
914
+			$prefix = '';
915
+		}
916
+		$parts = explode('.', (string)$gmt_offset);
917
+		if (count($parts) === 1) {
918
+			$parts[1] = '00';
919
+		} else {
920
+			//convert the part after the decimal, eg "5" (from x.5) or "25" (from x.25)
921
+			//to minutes, eg 30 or 15, respectively
922
+			$hour_fraction = (float)('0.' . $parts[1]);
923
+			$parts[1]      = (string)$hour_fraction * 60;
924
+		}
925
+		return sprintf(__('UTC%1$s', 'event_espresso'), $prefix . implode(':', $parts));
926
+	}
927
+
928
+
929
+
930
+	/**
931
+	 * So PHP does this awesome thing where if you are trying to get a timestamp
932
+	 * for a month using a string like "February" or "February 2017",
933
+	 * and you don't specify a day as part of your string,
934
+	 * then PHP will use whatever the current day of the month is.
935
+	 * IF the current day of the month happens to be the 30th or 31st,
936
+	 * then PHP gets really confused by a date like February 30,
937
+	 * so instead of saying
938
+	 *      "Hey February only has 28 days (this year)...
939
+	 *      ...you must have meant the last day of the month!"
940
+	 * PHP does the next most logical thing, and bumps the date up to March 2nd,
941
+	 * because someone requesting February 30th obviously meant March 1st!
942
+	 * The way around this is to always set the day to the first,
943
+	 * so that the month will stay on the month you wanted.
944
+	 * this method will add that "1" into your date regardless of the format.
945
+	 *
946
+	 * @param string $month
947
+	 * @return string
948
+	 */
949
+	public static function first_of_month_timestamp($month = '')
950
+	{
951
+		$month = (string)$month;
952
+		$year = '';
953
+		// check if the incoming string has a year in it or not
954
+	   if (preg_match('/\b\d{4}\b/', $month, $matches)) {
955
+		   $year = $matches[0];
956
+		   // ten remove that from the month string as well as any spaces
957
+		   $month = trim(str_replace($year, '', $month));
958
+		   // add a space before the year
959
+		   $year = " {$year}";
960
+		}
961
+		// return timestamp for something like "February 1 2017"
962
+		return strtotime("{$month} 1{$year}");
963
+	}
964 964
 
965 965
 
966 966
 }// end class EEH_DTT_Helper
967 967
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +38 added lines, -39 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if (! defined('EVENT_ESPRESSO_VERSION')) {
2
+if ( ! defined('EVENT_ESPRESSO_VERSION')) {
3 3
     exit('NO direct script access allowed');
4 4
 }
5 5
 
@@ -74,7 +74,7 @@  discard block
 block discarded – undo
74 74
             new DateTimeZone($timezone_string);
75 75
         } catch (Exception $e) {
76 76
             // sometimes we take exception to exceptions
77
-            if (! $throw_error) {
77
+            if ( ! $throw_error) {
78 78
                 return false;
79 79
             }
80 80
             throw new EE_Error(
@@ -135,7 +135,7 @@  discard block
 block discarded – undo
135 135
             }
136 136
         }
137 137
         $offset = get_option('gmt_offset');
138
-        return (int)($offset * HOUR_IN_SECONDS);
138
+        return (int) ($offset * HOUR_IN_SECONDS);
139 139
     }
140 140
 
141 141
 
@@ -149,7 +149,7 @@  discard block
 block discarded – undo
149 149
     public static function adjust_invalid_gmt_offsets($gmt_offset = 0)
150 150
     {
151 151
         //make sure $gmt_offset is int
152
-        $gmt_offset = (int)$gmt_offset;
152
+        $gmt_offset = (int) $gmt_offset;
153 153
         switch ($gmt_offset) {
154 154
 
155 155
             //			case -30600 :
@@ -233,7 +233,7 @@  discard block
 block discarded – undo
233 233
     public static function timezone_select_input($timezone_string = '')
234 234
     {
235 235
         // get WP date time format
236
-        $datetime_format = get_option('date_format') . ' ' . get_option('time_format');
236
+        $datetime_format = get_option('date_format').' '.get_option('time_format');
237 237
         // if passed a value, then use that, else get WP option
238 238
         $timezone_string = ! empty($timezone_string) ? $timezone_string : get_option('timezone_string');
239 239
         // check if the timezone is valid but don't throw any errors if it isn't
@@ -245,9 +245,9 @@  discard block
 block discarded – undo
245 245
             // Create a UTC+- zone if no timezone string exists
246 246
             $check_zone_info = false;
247 247
             if ($gmt_offset > 0) {
248
-                $timezone_string = 'UTC+' . $gmt_offset;
248
+                $timezone_string = 'UTC+'.$gmt_offset;
249 249
             } elseif ($gmt_offset < 0) {
250
-                $timezone_string = 'UTC' . $gmt_offset;
250
+                $timezone_string = 'UTC'.$gmt_offset;
251 251
             } else {
252 252
                 $timezone_string = 'UTC';
253 253
             }
@@ -269,11 +269,11 @@  discard block
 block discarded – undo
269 269
                 __('%1$sUTC%2$s time is %3$s'),
270 270
                 '<abbr title="Coordinated Universal Time">',
271 271
                 '</abbr>',
272
-                '<code>' . date_i18n($datetime_format, false, true) . '</code>'
272
+                '<code>'.date_i18n($datetime_format, false, true).'</code>'
273 273
             );
274 274
             ?></span>
275
-        <?php if (! empty($timezone_string) || ! empty($gmt_offset)) : ?>
276
-        <br/><span><?php printf(__('Local time is %1$s'), '<code>' . date_i18n($datetime_format) . '</code>'); ?></span>
275
+        <?php if ( ! empty($timezone_string) || ! empty($gmt_offset)) : ?>
276
+        <br/><span><?php printf(__('Local time is %1$s'), '<code>'.date_i18n($datetime_format).'</code>'); ?></span>
277 277
     <?php endif; ?>
278 278
 
279 279
         <?php if ($check_zone_info && $timezone_string) : ?>
@@ -306,11 +306,10 @@  discard block
 block discarded – undo
306 306
 
307 307
                 if ($found) {
308 308
                     $message = $tr['isdst'] ?
309
-                        __(' Daylight saving time begins on: %s.') :
310
-                        __(' Standard time begins  on: %s.');
309
+                        __(' Daylight saving time begins on: %s.') : __(' Standard time begins  on: %s.');
311 310
                     // Add the difference between the current offset and the new offset to ts to get the correct transition time from date_i18n().
312 311
                     printf($message,
313
-                        '<code >' . date_i18n($datetime_format, $tr['ts'] + ($tz_offset - $tr['offset'])) . '</code >');
312
+                        '<code >'.date_i18n($datetime_format, $tr['ts'] + ($tz_offset - $tr['offset'])).'</code >');
314 313
                 } else {
315 314
                     _e('This timezone does not observe daylight saving time.');
316 315
                 }
@@ -338,13 +337,13 @@  discard block
 block discarded – undo
338 337
      */
339 338
     public static function get_timestamp_with_offset($unix_timestamp = 0, $timezone_string = '')
340 339
     {
341
-        $unix_timestamp  = $unix_timestamp === 0 ? time() : (int)$unix_timestamp;
340
+        $unix_timestamp  = $unix_timestamp === 0 ? time() : (int) $unix_timestamp;
342 341
         $timezone_string = self::get_valid_timezone_string($timezone_string);
343 342
         $TimeZone        = new DateTimeZone($timezone_string);
344 343
 
345
-        $DateTime = new DateTime('@' . $unix_timestamp, $TimeZone);
344
+        $DateTime = new DateTime('@'.$unix_timestamp, $TimeZone);
346 345
         $offset   = timezone_offset_get($TimeZone, $DateTime);
347
-        return (int)$DateTime->format('U') + (int)$offset;
346
+        return (int) $DateTime->format('U') + (int) $offset;
348 347
     }
349 348
 
350 349
 
@@ -427,7 +426,7 @@  discard block
 block discarded – undo
427 426
      */
428 427
     protected static function _modify_datetime_object(DateTime $DateTime, $period = 'years', $value = 1, $operand = '+')
429 428
     {
430
-        if (! $DateTime instanceof DateTime) {
429
+        if ( ! $DateTime instanceof DateTime) {
431 430
             throw new EE_Error(
432 431
                 sprintf(
433 432
                     __('Expected a PHP DateTime object, but instead received %1$s', 'event_espresso'),
@@ -437,25 +436,25 @@  discard block
 block discarded – undo
437 436
         }
438 437
         switch ($period) {
439 438
             case 'years' :
440
-                $value = 'P' . $value . 'Y';
439
+                $value = 'P'.$value.'Y';
441 440
                 break;
442 441
             case 'months' :
443
-                $value = 'P' . $value . 'M';
442
+                $value = 'P'.$value.'M';
444 443
                 break;
445 444
             case 'weeks' :
446
-                $value = 'P' . $value . 'W';
445
+                $value = 'P'.$value.'W';
447 446
                 break;
448 447
             case 'days' :
449
-                $value = 'P' . $value . 'D';
448
+                $value = 'P'.$value.'D';
450 449
                 break;
451 450
             case 'hours' :
452
-                $value = 'PT' . $value . 'H';
451
+                $value = 'PT'.$value.'H';
453 452
                 break;
454 453
             case 'minutes' :
455
-                $value = 'PT' . $value . 'M';
454
+                $value = 'PT'.$value.'M';
456 455
                 break;
457 456
             case 'seconds' :
458
-                $value = 'PT' . $value . 'S';
457
+                $value = 'PT'.$value.'S';
459 458
                 break;
460 459
         }
461 460
         switch ($operand) {
@@ -483,7 +482,7 @@  discard block
 block discarded – undo
483 482
      */
484 483
     protected static function _modify_timestamp($timestamp, $period = 'years', $value = 1, $operand = '+')
485 484
     {
486
-        if (! preg_match(EE_Datetime_Field::unix_timestamp_regex, $timestamp)) {
485
+        if ( ! preg_match(EE_Datetime_Field::unix_timestamp_regex, $timestamp)) {
487 486
             throw new EE_Error(
488 487
                 sprintf(
489 488
                     __('Expected a Unix timestamp, but instead received %1$s', 'event_espresso'),
@@ -587,7 +586,7 @@  discard block
 block discarded – undo
587 586
                 'date' => $date_format['js'],
588 587
                 'time' => $time_format['js'],
589 588
             ),
590
-            'moment' => $date_format['moment'] . ' ' . $time_format['moment'],
589
+            'moment' => $date_format['moment'].' '.$time_format['moment'],
591 590
         );
592 591
     }
593 592
 
@@ -606,7 +605,7 @@  discard block
 block discarded – undo
606 605
          *
607 606
          * @var array
608 607
          */
609
-        $symbols_map      = array(
608
+        $symbols_map = array(
610 609
             // Day
611 610
             //01
612 611
             'd' => array(
@@ -764,7 +763,7 @@  discard block
 block discarded – undo
764 763
                     $jquery_ui_format .= $format_string[$i];
765 764
                     $moment_format .= $format_string[$i];
766 765
                 } else {
767
-                    $jquery_ui_format .= '\'' . $format_string[$i];
766
+                    $jquery_ui_format .= '\''.$format_string[$i];
768 767
                     $moment_format .= $format_string[$i];
769 768
                 }
770 769
                 $escaping = true;
@@ -834,7 +833,7 @@  discard block
 block discarded – undo
834 833
     {
835 834
 
836 835
         if (
837
-            (! $date_1 instanceof DateTime || ! $date_2 instanceof DateTime) ||
836
+            ( ! $date_1 instanceof DateTime || ! $date_2 instanceof DateTime) ||
838 837
             ($date_1->format(EE_Datetime_Field::mysql_time_format) != '00:00:00' || $date_2->format(EE_Datetime_Field::mysql_time_format) != '00:00:00')
839 838
         ) {
840 839
             return false;
@@ -866,8 +865,8 @@  discard block
 block discarded – undo
866 865
          */
867 866
         $offset         = $DateTimeZone instanceof DateTimeZone ? ($DateTimeZone->getOffset(new DateTime('now'))) / HOUR_IN_SECONDS : get_option('gmt_offset');
868 867
         $query_interval = $offset < 0
869
-            ? 'DATE_SUB(' . $field_for_interval . ', INTERVAL ' . $offset * -1 . ' HOUR)'
870
-            : 'DATE_ADD(' . $field_for_interval . ', INTERVAL ' . $offset . ' HOUR)';
868
+            ? 'DATE_SUB('.$field_for_interval.', INTERVAL '.$offset * -1.' HOUR)'
869
+            : 'DATE_ADD('.$field_for_interval.', INTERVAL '.$offset.' HOUR)';
871 870
         return $query_interval;
872 871
     }
873 872
 
@@ -883,16 +882,16 @@  discard block
 block discarded – undo
883 882
     public static function get_timezone_string_for_display()
884 883
     {
885 884
         $pretty_timezone = apply_filters('FHEE__EEH_DTT_Helper__get_timezone_string_for_display', '');
886
-        if (! empty($pretty_timezone)) {
885
+        if ( ! empty($pretty_timezone)) {
887 886
             return esc_html($pretty_timezone);
888 887
         }
889 888
         $timezone_string = get_option('timezone_string');
890 889
         if ($timezone_string) {
891 890
             static $mo_loaded = false;
892 891
             // Load translations for continents and cities just like wp_timezone_choice does
893
-            if (! $mo_loaded) {
892
+            if ( ! $mo_loaded) {
894 893
                 $locale = get_locale();
895
-                $mofile = WP_LANG_DIR . '/continents-cities-' . $locale . '.mo';
894
+                $mofile = WP_LANG_DIR.'/continents-cities-'.$locale.'.mo';
896 895
                 load_textdomain('continents-cities', $mofile);
897 896
                 $mo_loaded = true;
898 897
             }
@@ -913,16 +912,16 @@  discard block
 block discarded – undo
913 912
         } else {
914 913
             $prefix = '';
915 914
         }
916
-        $parts = explode('.', (string)$gmt_offset);
915
+        $parts = explode('.', (string) $gmt_offset);
917 916
         if (count($parts) === 1) {
918 917
             $parts[1] = '00';
919 918
         } else {
920 919
             //convert the part after the decimal, eg "5" (from x.5) or "25" (from x.25)
921 920
             //to minutes, eg 30 or 15, respectively
922
-            $hour_fraction = (float)('0.' . $parts[1]);
923
-            $parts[1]      = (string)$hour_fraction * 60;
921
+            $hour_fraction = (float) ('0.'.$parts[1]);
922
+            $parts[1]      = (string) $hour_fraction * 60;
924 923
         }
925
-        return sprintf(__('UTC%1$s', 'event_espresso'), $prefix . implode(':', $parts));
924
+        return sprintf(__('UTC%1$s', 'event_espresso'), $prefix.implode(':', $parts));
926 925
     }
927 926
 
928 927
 
@@ -948,7 +947,7 @@  discard block
 block discarded – undo
948 947
      */
949 948
     public static function first_of_month_timestamp($month = '')
950 949
     {
951
-        $month = (string)$month;
950
+        $month = (string) $month;
952 951
         $year = '';
953 952
         // check if the incoming string has a year in it or not
954 953
        if (preg_match('/\b\d{4}\b/', $month, $matches)) {
Please login to merge, or discard this patch.
modules/events_archive_filters/EED_Events_Archive_Filters.module.php 1 patch
Spacing   +167 added lines, -167 removed lines patch added patch discarded remove patch
@@ -29,7 +29,7 @@  discard block
 block discarded – undo
29 29
 	 * @return EED_Events_Archive_Filters
30 30
 	 */
31 31
 	public static function instance() {
32
-		return parent::get_instance( __CLASS__ );
32
+		return parent::get_instance(__CLASS__);
33 33
 	}
34 34
 
35 35
 
@@ -71,7 +71,7 @@  discard block
 block discarded – undo
71 71
 	 *	@var 	$_types
72 72
 	 * 	@access 	protected
73 73
 	 */
74
-	protected static $_types = array( 'grid', 'text', 'dates' );
74
+	protected static $_types = array('grid', 'text', 'dates');
75 75
 
76 76
 
77 77
 //	public static $espresso_event_list_ID = 0;
@@ -125,7 +125,7 @@  discard block
 block discarded – undo
125 125
 	 *  @access 	public
126 126
 	 *  @return 	void
127 127
 	 */
128
-	public function run( $WP ) {
128
+	public function run($WP) {
129 129
 //		do_action( 'AHEE__EED_Events_Archive_Filters__before_run' );
130 130
 //		// set config
131 131
 //		if ( ! isset( EE_Registry::instance()->CFG->template_settings->EED_Events_Archive_Filters ) || ! EE_Registry::instance()->CFG->template_settings->EED_Events_Archive_Filters instanceof EE_Events_Archive_Config ) {
@@ -170,9 +170,9 @@  discard block
 block discarded – undo
170 170
 	 */
171 171
 	private function _filter_query_parts() {
172 172
 		// build event list query
173
-		add_filter( 'posts_join', array( $this, 'posts_join' ), 1, 2 );
174
-		add_filter( 'posts_where', array( $this, 'posts_where' ), 1, 2 );
175
-		add_filter( 'posts_orderby', array( $this, 'posts_orderby' ), 1, 2 );
173
+		add_filter('posts_join', array($this, 'posts_join'), 1, 2);
174
+		add_filter('posts_where', array($this, 'posts_where'), 1, 2);
175
+		add_filter('posts_orderby', array($this, 'posts_orderby'), 1, 2);
176 176
 	}
177 177
 
178 178
 	/**
@@ -182,13 +182,13 @@  discard block
 block discarded – undo
182 182
 	 *  @return 	string
183 183
 	 */
184 184
 	public static function set_type() {
185
-		do_action( 'AHEE__EED_Events_Archive_Filters__before_set_type' );
186
-		EED_Events_Archive_Filters::$_types = apply_filters( 'EED_Events_Archive_Filters__set_type__types', EED_Events_Archive_Filters::$_types );
187
-		$view = isset( EE_Registry::instance()->CFG->EED_Events_Archive_Filters['default_type'] ) ? EE_Registry::instance()->CFG->EED_Events_Archive_Filters['default_type'] : 'grid';
188
-		$elf_type = EE_Registry::instance()->REQ->is_set( 'elf_type' ) ? sanitize_text_field( EE_Registry::instance()->REQ->get( 'elf_type' )) : '';
189
-		$view = ! empty( $elf_type ) ? $elf_type : $view;
190
-		$view = apply_filters( 'EED_Events_Archive_Filters__set_type__type', $view );
191
-		if ( ! empty( $view ) && in_array( $view, EED_Events_Archive_Filters::$_types )) {
185
+		do_action('AHEE__EED_Events_Archive_Filters__before_set_type');
186
+		EED_Events_Archive_Filters::$_types = apply_filters('EED_Events_Archive_Filters__set_type__types', EED_Events_Archive_Filters::$_types);
187
+		$view = isset(EE_Registry::instance()->CFG->EED_Events_Archive_Filters['default_type']) ? EE_Registry::instance()->CFG->EED_Events_Archive_Filters['default_type'] : 'grid';
188
+		$elf_type = EE_Registry::instance()->REQ->is_set('elf_type') ? sanitize_text_field(EE_Registry::instance()->REQ->get('elf_type')) : '';
189
+		$view = ! empty($elf_type) ? $elf_type : $view;
190
+		$view = apply_filters('EED_Events_Archive_Filters__set_type__type', $view);
191
+		if ( ! empty($view) && in_array($view, EED_Events_Archive_Filters::$_types)) {
192 192
 			self::$_type = $view;
193 193
 		}
194 194
 	}
@@ -200,11 +200,11 @@  discard block
 block discarded – undo
200 200
 	 *  @param	boolean	$req_only if TRUE, then ignore defaults and only return $_POST value
201 201
 	 *  @return 	boolean
202 202
 	 */
203
-	private static function _show_expired( $req_only = FALSE ) {
203
+	private static function _show_expired($req_only = FALSE) {
204 204
 		// get default value for "display_expired_events" as set in the EE General Settings > Templates > Event Listings
205
-		$show_expired = ! $req_only && isset( EE_Registry::instance()->CFG->EED_Events_Archive_Filters['display_expired_events'] ) ? EE_Registry::instance()->CFG->EED_Events_Archive_Filters['display_expired_events'] : FALSE;
205
+		$show_expired = ! $req_only && isset(EE_Registry::instance()->CFG->EED_Events_Archive_Filters['display_expired_events']) ? EE_Registry::instance()->CFG->EED_Events_Archive_Filters['display_expired_events'] : FALSE;
206 206
 		// override default expired option if set via filter
207
-		$show_expired = EE_Registry::instance()->REQ->is_set( 'elf_expired_chk' ) ? absint( EE_Registry::instance()->REQ->get( 'elf_expired_chk' )) : $show_expired;
207
+		$show_expired = EE_Registry::instance()->REQ->is_set('elf_expired_chk') ? absint(EE_Registry::instance()->REQ->get('elf_expired_chk')) : $show_expired;
208 208
 		return $show_expired ? TRUE : FALSE;
209 209
 	}
210 210
 
@@ -215,7 +215,7 @@  discard block
 block discarded – undo
215 215
 	 *  @return 	string
216 216
 	 */
217 217
 	private static function _event_category_slug() {
218
-		return EE_Registry::instance()->REQ->is_set( 'elf_category_dd' ) ? sanitize_text_field( EE_Registry::instance()->REQ->get( 'elf_category_dd' )) : '';
218
+		return EE_Registry::instance()->REQ->is_set('elf_category_dd') ? sanitize_text_field(EE_Registry::instance()->REQ->get('elf_category_dd')) : '';
219 219
 	}
220 220
 
221 221
 	/**
@@ -225,7 +225,7 @@  discard block
 block discarded – undo
225 225
 	 *  @return 	string
226 226
 	 */
227 227
 	private static function _display_month() {
228
-		return EE_Registry::instance()->REQ->is_set( 'elf_month_dd' ) ? sanitize_text_field( EE_Registry::instance()->REQ->get( 'elf_month_dd' )) : '';
228
+		return EE_Registry::instance()->REQ->is_set('elf_month_dd') ? sanitize_text_field(EE_Registry::instance()->REQ->get('elf_month_dd')) : '';
229 229
 	}
230 230
 
231 231
 
@@ -239,7 +239,7 @@  discard block
 block discarded – undo
239 239
 	public function get_post_data() {
240 240
 		$this->_elf_month = EED_Events_Archive_Filters::_display_month();
241 241
 		$this->_elf_category = EED_Events_Archive_Filters::_event_category_slug();
242
-		$this->_show_expired = EED_Events_Archive_Filters::_show_expired( TRUE );
242
+		$this->_show_expired = EED_Events_Archive_Filters::_show_expired(TRUE);
243 243
 //		EEH_Debug_Tools::printr( EE_Registry::instance()->REQ, 'EE_Registry::instance()->REQ  <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span>', 'auto' );
244 244
 //		echo '<h4>$this->_elf_month : ' . $this->_elf_month . '  <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span></h4>';
245 245
 //		echo '<h4>$this->_elf_category : ' . $this->_elf_category . '  <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span></h4>';
@@ -256,11 +256,11 @@  discard block
 block discarded – undo
256 256
 	 *  @access 	public
257 257
 	 *  @return 	void
258 258
 	 */
259
-	public function posts_join( $SQL, WP_Query $wp_query ) {
260
-		if ( isset( $wp_query->query ) && isset( $wp_query->query['post_type'] ) && $wp_query->query['post_type'] == 'espresso_events' ) {
259
+	public function posts_join($SQL, WP_Query $wp_query) {
260
+		if (isset($wp_query->query) && isset($wp_query->query['post_type']) && $wp_query->query['post_type'] == 'espresso_events') {
261 261
 			// Category
262 262
 //			$elf_category = EE_Registry::instance()->REQ->is_set( 'elf_category_dd' ) ? sanitize_text_field( EE_Registry::instance()->REQ->get( 'elf_category_dd' )) : '';
263
-			$SQL .= EED_Events_Archive_Filters::posts_join_sql_for_terms( EED_Events_Archive_Filters::_event_category_slug() );
263
+			$SQL .= EED_Events_Archive_Filters::posts_join_sql_for_terms(EED_Events_Archive_Filters::_event_category_slug());
264 264
 		}
265 265
 		return $SQL;
266 266
 	}
@@ -273,9 +273,9 @@  discard block
 block discarded – undo
273 273
 	 *  @param	mixed boolean|string	$join_terms pass TRUE or term string, doesn't really matter since this value doesn't really get used for anything yet
274 274
 	 *  @return 	string
275 275
 	 */
276
-	public static function posts_join_sql_for_terms( $join_terms = NULL ) {
277
-		$SQL= '';
278
-		if ( ! empty( $join_terms )) {
276
+	public static function posts_join_sql_for_terms($join_terms = NULL) {
277
+		$SQL = '';
278
+		if ( ! empty($join_terms)) {
279 279
 			global $wpdb;
280 280
 			$SQL .= " LEFT JOIN $wpdb->term_relationships ON ($wpdb->posts.ID = $wpdb->term_relationships.object_id)";
281 281
 			$SQL .= " LEFT JOIN $wpdb->term_taxonomy ON ($wpdb->term_relationships.term_taxonomy_id = $wpdb->term_taxonomy.term_taxonomy_id)";
@@ -293,28 +293,28 @@  discard block
 block discarded – undo
293 293
 	 *  @param	array	$orderby_params
294 294
 	 *  @return 	string
295 295
 	 */
296
-	public static function posts_join_for_orderby( $orderby_params = array() ) {
296
+	public static function posts_join_for_orderby($orderby_params = array()) {
297 297
 		global $wpdb;
298
-		$SQL= '';
299
-		$orderby_params = is_array( $orderby_params ) ? $orderby_params : array( $orderby_params );
300
-		foreach( $orderby_params as $orderby ) {
301
-			switch ( $orderby ) {
298
+		$SQL = '';
299
+		$orderby_params = is_array($orderby_params) ? $orderby_params : array($orderby_params);
300
+		foreach ($orderby_params as $orderby) {
301
+			switch ($orderby) {
302 302
 
303 303
 				case 'ticket_start' :
304 304
 				case 'ticket_end' :
305
-					$SQL .= ' LEFT JOIN ' . EEM_Datetime_Ticket::instance()->table() . ' ON (' . EEM_Datetime::instance()->table() . '.DTT_ID = ' . EEM_Datetime_Ticket::instance()->table() . '.DTT_ID )';
306
-					$SQL .= ' LEFT JOIN ' . EEM_Ticket::instance()->table() . ' ON (' . EEM_Datetime_Ticket::instance()->table() . '.TKT_ID = ' . EEM_Ticket::instance()->table() . '.TKT_ID )';
305
+					$SQL .= ' LEFT JOIN '.EEM_Datetime_Ticket::instance()->table().' ON ('.EEM_Datetime::instance()->table().'.DTT_ID = '.EEM_Datetime_Ticket::instance()->table().'.DTT_ID )';
306
+					$SQL .= ' LEFT JOIN '.EEM_Ticket::instance()->table().' ON ('.EEM_Datetime_Ticket::instance()->table().'.TKT_ID = '.EEM_Ticket::instance()->table().'.TKT_ID )';
307 307
 					break;
308 308
 
309 309
 				case 'venue_title' :
310 310
 				case 'city' :
311
-					$SQL .= ' LEFT JOIN ' . EEM_Event_Venue::instance()->table() . ' ON (' . $wpdb->posts . '.ID = ' . EEM_Event_Venue::instance()->table() . '.EVT_ID )';
312
-					$SQL .= ' LEFT JOIN ' . EEM_Venue::instance()->table() . ' ON (' . EEM_Event_Venue::instance()->table() . '.VNU_ID = ' . EEM_Venue::instance()->table() . '.VNU_ID )';
311
+					$SQL .= ' LEFT JOIN '.EEM_Event_Venue::instance()->table().' ON ('.$wpdb->posts.'.ID = '.EEM_Event_Venue::instance()->table().'.EVT_ID )';
312
+					$SQL .= ' LEFT JOIN '.EEM_Venue::instance()->table().' ON ('.EEM_Event_Venue::instance()->table().'.VNU_ID = '.EEM_Venue::instance()->table().'.VNU_ID )';
313 313
 					break;
314 314
 
315 315
 				case 'state' :
316
-					$SQL .= ' LEFT JOIN ' . EEM_Event_Venue::instance()->table() . ' ON (' . $wpdb->posts . '.ID = ' . EEM_Event_Venue::instance()->table() . '.EVT_ID )';
317
-					$SQL .= ' LEFT JOIN ' . EEM_Event_Venue::instance()->second_table() . ' ON (' . EEM_Event_Venue::instance()->table() . '.VNU_ID = ' . EEM_Event_Venue::instance()->second_table() . '.VNU_ID )';
316
+					$SQL .= ' LEFT JOIN '.EEM_Event_Venue::instance()->table().' ON ('.$wpdb->posts.'.ID = '.EEM_Event_Venue::instance()->table().'.EVT_ID )';
317
+					$SQL .= ' LEFT JOIN '.EEM_Event_Venue::instance()->second_table().' ON ('.EEM_Event_Venue::instance()->table().'.VNU_ID = '.EEM_Event_Venue::instance()->second_table().'.VNU_ID )';
318 318
 					break;
319 319
 
320 320
 				break;
@@ -331,16 +331,16 @@  discard block
 block discarded – undo
331 331
 	 *  @access 	public
332 332
 	 *  @return 	void
333 333
 	 */
334
-	public function posts_where( $SQL, WP_Query $wp_query ) {
335
-		if ( isset( $wp_query->query_vars ) && isset( $wp_query->query_vars['post_type'] ) && $wp_query->query_vars['post_type'] == 'espresso_events'  ) {
334
+	public function posts_where($SQL, WP_Query $wp_query) {
335
+		if (isset($wp_query->query_vars) && isset($wp_query->query_vars['post_type']) && $wp_query->query_vars['post_type'] == 'espresso_events') {
336 336
 			// Show Expired ?
337
-			$SQL .= EED_Events_Archive_Filters::posts_where_sql_for_show_expired( EED_Events_Archive_Filters::_show_expired() );
337
+			$SQL .= EED_Events_Archive_Filters::posts_where_sql_for_show_expired(EED_Events_Archive_Filters::_show_expired());
338 338
 			// Category
339 339
 			//$elf_category = EED_Events_Archive_Filters::_event_category_slug();
340
-			$SQL .=  EED_Events_Archive_Filters::posts_where_sql_for_event_category_slug( EED_Events_Archive_Filters::_event_category_slug() );
340
+			$SQL .= EED_Events_Archive_Filters::posts_where_sql_for_event_category_slug(EED_Events_Archive_Filters::_event_category_slug());
341 341
 			// Start Date
342 342
 			//$elf_month = EED_Events_Archive_Filters::_display_month();
343
-			$SQL .= EED_Events_Archive_Filters::posts_where_sql_for_event_list_month( EED_Events_Archive_Filters::_display_month() );
343
+			$SQL .= EED_Events_Archive_Filters::posts_where_sql_for_event_list_month(EED_Events_Archive_Filters::_display_month());
344 344
 		}
345 345
 		return $SQL;
346 346
 	}
@@ -353,8 +353,8 @@  discard block
 block discarded – undo
353 353
 	 *  @param	boolean	$show_expired if TRUE, then displayed past events
354 354
 	 *  @return 	string
355 355
 	 */
356
-	public static function posts_where_sql_for_show_expired( $show_expired = FALSE ) {
357
-		return  ! $show_expired ? ' AND ' . EEM_Datetime::instance()->table() . '.DTT_EVT_end > "' . date('Y-m-d H:s:i') . '" ' : '';
356
+	public static function posts_where_sql_for_show_expired($show_expired = FALSE) {
357
+		return  ! $show_expired ? ' AND '.EEM_Datetime::instance()->table().'.DTT_EVT_end > "'.date('Y-m-d H:s:i').'" ' : '';
358 358
 	}
359 359
 
360 360
 
@@ -365,9 +365,9 @@  discard block
 block discarded – undo
365 365
 	 *  @param	boolean	$event_category_slug
366 366
 	 *  @return 	string
367 367
 	 */
368
-	public static function posts_where_sql_for_event_category_slug( $event_category_slug = NULL ) {
368
+	public static function posts_where_sql_for_event_category_slug($event_category_slug = NULL) {
369 369
 		global $wpdb;
370
-		return  ! empty( $event_category_slug ) ? ' AND ' . $wpdb->terms . '.slug = "' . $event_category_slug . '" ' : '';
370
+		return  ! empty($event_category_slug) ? ' AND '.$wpdb->terms.'.slug = "'.$event_category_slug.'" ' : '';
371 371
 	}
372 372
 
373 373
 	/**
@@ -377,15 +377,15 @@  discard block
 block discarded – undo
377 377
 	 *  @param	boolean	$month
378 378
 	 *  @return 	string
379 379
 	 */
380
-	public static function posts_where_sql_for_event_list_month( $month = NULL ) {
381
-		$SQL= '';
382
-		if ( ! empty( $month )) {
380
+	public static function posts_where_sql_for_event_list_month($month = NULL) {
381
+		$SQL = '';
382
+		if ( ! empty($month)) {
383 383
 			// event start date is LESS than the end of the month ( so nothing that doesn't start until next month )
384
-			$SQL = ' AND ' . EEM_Datetime::instance()->table() . '.DTT_EVT_start';
385
-			$SQL .= ' <= "' . date('Y-m-t 23:59:59', \EEH_DTT_Helper::first_of_month_timestamp($month)) . '"';
384
+			$SQL = ' AND '.EEM_Datetime::instance()->table().'.DTT_EVT_start';
385
+			$SQL .= ' <= "'.date('Y-m-t 23:59:59', \EEH_DTT_Helper::first_of_month_timestamp($month)).'"';
386 386
 			// event end date is GREATER than the start of the month ( so nothing that ended before this month )
387
-			$SQL .= ' AND ' . EEM_Datetime::instance()->table() . '.DTT_EVT_end';
388
-			$SQL .= ' >= "' . date('Y-m-d 0:0:00', \EEH_DTT_Helper::first_of_month_timestamp($month)) . '" ';
387
+			$SQL .= ' AND '.EEM_Datetime::instance()->table().'.DTT_EVT_end';
388
+			$SQL .= ' >= "'.date('Y-m-d 0:0:00', \EEH_DTT_Helper::first_of_month_timestamp($month)).'" ';
389 389
 		}
390 390
 		return $SQL;
391 391
 	}
@@ -397,9 +397,9 @@  discard block
 block discarded – undo
397 397
 	 *  @access 	public
398 398
 	 *  @return 	void
399 399
 	 */
400
-	public function posts_orderby( $SQL, WP_Query $wp_query ) {
401
-		if ( isset( $wp_query->query ) && isset( $wp_query->query['post_type'] ) && $wp_query->query['post_type'] == 'espresso_events' ) {
402
-			$SQL = EED_Events_Archive_Filters::posts_orderby_sql( array( 'start_date' ));
400
+	public function posts_orderby($SQL, WP_Query $wp_query) {
401
+		if (isset($wp_query->query) && isset($wp_query->query['post_type']) && $wp_query->query['post_type'] == 'espresso_events') {
402
+			$SQL = EED_Events_Archive_Filters::posts_orderby_sql(array('start_date'));
403 403
 		}
404 404
 		return $SQL;
405 405
 	}
@@ -428,54 +428,54 @@  discard block
 block discarded – undo
428 428
 	 *  @param	boolean	$orderby_params
429 429
 	 *  @return 	string
430 430
 	 */
431
-	public static function posts_orderby_sql( $orderby_params = array(), $sort = 'ASC' ) {
431
+	public static function posts_orderby_sql($orderby_params = array(), $sort = 'ASC') {
432 432
 		global $wpdb;
433 433
 		$SQL = '';
434 434
 		$cntr = 1;
435
-		$orderby_params = is_array( $orderby_params ) ? $orderby_params : array( $orderby_params );
436
-		foreach( $orderby_params as $orderby ) {
437
-			$glue = $cntr == 1 || $cntr == count( $orderby_params ) ? ' ' : ', ';
438
-			switch ( $orderby ) {
435
+		$orderby_params = is_array($orderby_params) ? $orderby_params : array($orderby_params);
436
+		foreach ($orderby_params as $orderby) {
437
+			$glue = $cntr == 1 || $cntr == count($orderby_params) ? ' ' : ', ';
438
+			switch ($orderby) {
439 439
 
440 440
 				case 'id' :
441 441
 				case 'ID' :
442
-					$SQL .= $glue . $wpdb->posts . '.ID ' . $sort;
442
+					$SQL .= $glue.$wpdb->posts.'.ID '.$sort;
443 443
 					break;
444 444
 
445 445
 				case 'start_date' :
446
-					$SQL .= $glue . EEM_Datetime::instance()->table() . '.DTT_EVT_start ' . $sort;
446
+					$SQL .= $glue.EEM_Datetime::instance()->table().'.DTT_EVT_start '.$sort;
447 447
 					break;
448 448
 
449 449
 				case 'end_date' :
450
-					$SQL .= $glue . EEM_Datetime::instance()->table() . '.DTT_EVT_end ' . $sort;
450
+					$SQL .= $glue.EEM_Datetime::instance()->table().'.DTT_EVT_end '.$sort;
451 451
 					break;
452 452
 
453 453
 				case 'event_name' :
454
-					$SQL .= $glue . $wpdb->posts . '.post_title ' . $sort;
454
+					$SQL .= $glue.$wpdb->posts.'.post_title '.$sort;
455 455
 					break;
456 456
 
457 457
 				case 'category_slug' :
458
-					$SQL .= $glue . $wpdb->terms . '.slug ' . $sort;
458
+					$SQL .= $glue.$wpdb->terms.'.slug '.$sort;
459 459
 					break;
460 460
 
461 461
 				case 'ticket_start' :
462
-					$SQL .= $glue . EEM_Ticket::instance()->table() . '.TKT_start_date ' . $sort;
462
+					$SQL .= $glue.EEM_Ticket::instance()->table().'.TKT_start_date '.$sort;
463 463
 					break;
464 464
 
465 465
 				case 'ticket_end' :
466
-					$SQL .= $glue . EEM_Ticket::instance()->table() . '.TKT_end_date ' . $sort;
466
+					$SQL .= $glue.EEM_Ticket::instance()->table().'.TKT_end_date '.$sort;
467 467
 					break;
468 468
 
469 469
 				case 'venue_title' :
470
-					$SQL .= $glue . 'venue_title ' . $sort;
470
+					$SQL .= $glue.'venue_title '.$sort;
471 471
 					break;
472 472
 
473 473
 				case 'city' :
474
-					$SQL .= $glue . EEM_Venue::instance()->second_table() . '.VNU_city ' . $sort;
474
+					$SQL .= $glue.EEM_Venue::instance()->second_table().'.VNU_city '.$sort;
475 475
 				break;
476 476
 
477 477
 				case 'state' :
478
-					$SQL .= $glue . EEM_State::instance()->table() . '.STA_name ' . $sort;
478
+					$SQL .= $glue.EEM_State::instance()->table().'.STA_name '.$sort;
479 479
 				break;
480 480
 
481 481
 			}
@@ -495,26 +495,26 @@  discard block
 block discarded – undo
495 495
 	 */
496 496
 	public function template_redirect() {
497 497
 		// add event list filters
498
-		add_action( 'loop_start', array( $this, 'event_list_template_filters' ));
498
+		add_action('loop_start', array($this, 'event_list_template_filters'));
499 499
 		// and pagination
500
-		add_action( 'loop_start', array( $this, 'event_list_pagination' ));
501
-		add_action( 'loop_end', array( $this, 'event_list_pagination' ));
500
+		add_action('loop_start', array($this, 'event_list_pagination'));
501
+		add_action('loop_end', array($this, 'event_list_pagination'));
502 502
 		// if NOT a custom template
503
-		if ( EE_Registry::instance()->load_core( 'Front_Controller', array(), false, true )->get_selected_template() != 'archive-espresso_events.php' ) {
503
+		if (EE_Registry::instance()->load_core('Front_Controller', array(), false, true)->get_selected_template() != 'archive-espresso_events.php') {
504 504
 			// don't know if theme uses the_excerpt
505
-			add_filter( 'the_excerpt', array( $this, 'event_details' ), 100 );
506
-			add_filter( 'the_excerpt', array( $this, 'event_tickets' ), 110 );
507
-			add_filter( 'the_excerpt', array( $this, 'event_datetimes' ), 120 );
508
-			add_filter( 'the_excerpt', array( $this, 'event_venues' ), 130 );
505
+			add_filter('the_excerpt', array($this, 'event_details'), 100);
506
+			add_filter('the_excerpt', array($this, 'event_tickets'), 110);
507
+			add_filter('the_excerpt', array($this, 'event_datetimes'), 120);
508
+			add_filter('the_excerpt', array($this, 'event_venues'), 130);
509 509
 			// or the_content
510
-			add_filter( 'the_content', array( $this, 'event_details' ), 100 );
511
-			add_filter( 'the_content', array( $this, 'event_tickets' ), 110 );
512
-			add_filter( 'the_content', array( $this, 'event_datetimes' ), 120 );
513
-			add_filter( 'the_content', array( $this, 'event_venues' ), 130 );
510
+			add_filter('the_content', array($this, 'event_details'), 100);
511
+			add_filter('the_content', array($this, 'event_tickets'), 110);
512
+			add_filter('the_content', array($this, 'event_datetimes'), 120);
513
+			add_filter('the_content', array($this, 'event_venues'), 130);
514 514
 		} else {
515
-			remove_all_filters( 'excerpt_length' );
516
-			add_filter( 'excerpt_length', array( $this, 'excerpt_length' ), 10 );
517
-			add_filter( 'excerpt_more', array( $this, 'excerpt_more' ), 10 );
515
+			remove_all_filters('excerpt_length');
516
+			add_filter('excerpt_length', array($this, 'excerpt_length'), 10);
517
+			add_filter('excerpt_more', array($this, 'excerpt_more'), 10);
518 518
 		}
519 519
 	}
520 520
 
@@ -527,7 +527,7 @@  discard block
 block discarded – undo
527 527
 	 *  	@return 		void
528 528
 	 */
529 529
 	public function event_list_pagination() {
530
-		echo '<div class="ee-pagination-dv clear">' . espresso_event_list_pagination() . '</div>';
530
+		echo '<div class="ee-pagination-dv clear">'.espresso_event_list_pagination().'</div>';
531 531
 	}
532 532
 
533 533
 
@@ -538,8 +538,8 @@  discard block
 block discarded – undo
538 538
 	 * 	@param		string 	$content
539 539
 	 *  	@return 		void
540 540
 	 */
541
-	public function event_details( $content ) {
542
-		return EEH_Template::display_template( EE_TEMPLATES . EE_Config::get_current_theme() . DS . 'content-espresso_events-details.php', array( 'the_content' => $content ), TRUE );
541
+	public function event_details($content) {
542
+		return EEH_Template::display_template(EE_TEMPLATES.EE_Config::get_current_theme().DS.'content-espresso_events-details.php', array('the_content' => $content), TRUE);
543 543
 	}
544 544
 
545 545
 
@@ -550,8 +550,8 @@  discard block
 block discarded – undo
550 550
 	 * 	@param		string 	$content
551 551
 	 *  	@return 		void
552 552
 	 */
553
-	public function event_tickets( $content ) {
554
-		return $content . EEH_Template::display_template( EE_TEMPLATES . EE_Config::get_current_theme() . DS . 'content-espresso_events-tickets.php', array(), TRUE );
553
+	public function event_tickets($content) {
554
+		return $content.EEH_Template::display_template(EE_TEMPLATES.EE_Config::get_current_theme().DS.'content-espresso_events-tickets.php', array(), TRUE);
555 555
 	}
556 556
 
557 557
 	/**
@@ -561,8 +561,8 @@  discard block
 block discarded – undo
561 561
 	 * 	@param		string 	$content
562 562
 	 *  	@return 		void
563 563
 	 */
564
-	public function event_datetimes( $content ) {
565
-		return $content . EEH_Template::display_template( EE_TEMPLATES . EE_Config::get_current_theme() . DS . 'content-espresso_events-datetimes.php', array(), TRUE );
564
+	public function event_datetimes($content) {
565
+		return $content.EEH_Template::display_template(EE_TEMPLATES.EE_Config::get_current_theme().DS.'content-espresso_events-datetimes.php', array(), TRUE);
566 566
 	}
567 567
 
568 568
 	/**
@@ -572,8 +572,8 @@  discard block
 block discarded – undo
572 572
 	 * 	@param		string 	$content
573 573
 	 *  	@return 		void
574 574
 	 */
575
-	public function event_venues( $content ) {
576
-		return $content . EEH_Template::display_template( EE_TEMPLATES . EE_Config::get_current_theme() . DS . 'content-espresso_events-venues.php', array(), TRUE );
575
+	public function event_venues($content) {
576
+		return $content.EEH_Template::display_template(EE_TEMPLATES.EE_Config::get_current_theme().DS.'content-espresso_events-venues.php', array(), TRUE);
577 577
 	}
578 578
 
579 579
 
@@ -588,12 +588,12 @@  discard block
 block discarded – undo
588 588
 	 *  @return 	void
589 589
 	 */
590 590
 	private function _load_assests() {
591
-		do_action( 'AHEE__EED_Events_Archive_Filters__before_load_assests' );
592
-		add_filter( 'FHEE_load_css', '__return_true' );
593
-		add_filter( 'FHEE_load_EE_Session', '__return_true' );
594
-		add_action('wp_enqueue_scripts', array( $this, 'wp_enqueue_scripts' ), 10 );
595
-		if ( EE_Registry::instance()->CFG->map_settings->use_google_maps ) {
596
-			add_action('wp_enqueue_scripts', array( 'EEH_Maps', 'espresso_google_map_js' ), 11 );
591
+		do_action('AHEE__EED_Events_Archive_Filters__before_load_assests');
592
+		add_filter('FHEE_load_css', '__return_true');
593
+		add_filter('FHEE_load_EE_Session', '__return_true');
594
+		add_action('wp_enqueue_scripts', array($this, 'wp_enqueue_scripts'), 10);
595
+		if (EE_Registry::instance()->CFG->map_settings->use_google_maps) {
596
+			add_action('wp_enqueue_scripts', array('EEH_Maps', 'espresso_google_map_js'), 11);
597 597
 		}
598 598
 		//add_filter( 'the_excerpt', array( $this, 'the_excerpt' ), 999 );
599 599
 	}
@@ -608,8 +608,8 @@  discard block
 block discarded – undo
608 608
 	 *  @access 	private
609 609
 	 *  @return 	string
610 610
 	 */
611
-	private function _get_template( $which = 'part' ) {
612
-		return EE_TEMPLATES . EE_Config::get_current_theme() . DS . 'archive-espresso_events.php';
611
+	private function _get_template($which = 'part') {
612
+		return EE_TEMPLATES.EE_Config::get_current_theme().DS.'archive-espresso_events.php';
613 613
 	}
614 614
 
615 615
 
@@ -620,13 +620,13 @@  discard block
 block discarded – undo
620 620
 	 *  @access 	public
621 621
 	 *  @return 	void
622 622
 	 */
623
-	public function excerpt_length( $length ) {
623
+	public function excerpt_length($length) {
624 624
 
625
-		if ( self::$_type == 'grid' ) {
625
+		if (self::$_type == 'grid') {
626 626
 			return 36;
627 627
 		}
628 628
 
629
-		switch ( EE_Registry::instance()->CFG->template_settings->EED_Events_Archive_Filters->event_list_grid_size ) {
629
+		switch (EE_Registry::instance()->CFG->template_settings->EED_Events_Archive_Filters->event_list_grid_size) {
630 630
 			case 'tiny' :
631 631
 				return 12;
632 632
 				break;
@@ -650,7 +650,7 @@  discard block
 block discarded – undo
650 650
 	 *  @access 	public
651 651
 	 *  @return 	void
652 652
 	 */
653
-	public function excerpt_more( $more ) {
653
+	public function excerpt_more($more) {
654 654
 		return '&hellip;';
655 655
 	}
656 656
 
@@ -680,22 +680,22 @@  discard block
 block discarded – undo
680 680
 	 */
681 681
 	public function wp_enqueue_scripts() {
682 682
 		// get some style
683
-		if ( apply_filters( 'FHEE_enable_default_espresso_css', FALSE ) ) {
683
+		if (apply_filters('FHEE_enable_default_espresso_css', FALSE)) {
684 684
 			// first check uploads folder
685
-			if ( is_readable( get_stylesheet_directory() . EE_Config::get_current_theme() . DS . 'archive-espresso_events.css' )) {
686
-				wp_register_style( 'archive-espresso_events', get_stylesheet_directory_uri() . EE_Config::get_current_theme() . DS . 'archive-espresso_events.css', array( 'dashicons', 'espresso_default' ));
685
+			if (is_readable(get_stylesheet_directory().EE_Config::get_current_theme().DS.'archive-espresso_events.css')) {
686
+				wp_register_style('archive-espresso_events', get_stylesheet_directory_uri().EE_Config::get_current_theme().DS.'archive-espresso_events.css', array('dashicons', 'espresso_default'));
687 687
 			} else {
688
-				wp_register_style( 'archive-espresso_events', EE_TEMPLATES_URL . EE_Config::get_current_theme() . DS . 'archive-espresso_events.css', array( 'dashicons', 'espresso_default' ));
688
+				wp_register_style('archive-espresso_events', EE_TEMPLATES_URL.EE_Config::get_current_theme().DS.'archive-espresso_events.css', array('dashicons', 'espresso_default'));
689 689
 			}
690
-			if ( is_readable( get_stylesheet_directory() . EE_Config::get_current_theme() . DS . 'archive-espresso_events.js' )) {
691
-				wp_register_script( 'archive-espresso_events', get_stylesheet_directory_uri() . EE_Config::get_current_theme() . DS . 'archive-espresso_events.js', array( 'jquery-masonry' ), '1.0', TRUE  );
690
+			if (is_readable(get_stylesheet_directory().EE_Config::get_current_theme().DS.'archive-espresso_events.js')) {
691
+				wp_register_script('archive-espresso_events', get_stylesheet_directory_uri().EE_Config::get_current_theme().DS.'archive-espresso_events.js', array('jquery-masonry'), '1.0', TRUE);
692 692
 			} else {
693
-				wp_register_script( 'archive-espresso_events', EVENTS_ARCHIVE_ASSETS_URL . 'archive-espresso_events.js', array( 'jquery-masonry' ), '1.0', TRUE );
693
+				wp_register_script('archive-espresso_events', EVENTS_ARCHIVE_ASSETS_URL.'archive-espresso_events.js', array('jquery-masonry'), '1.0', TRUE);
694 694
 			}
695
-			wp_enqueue_style( 'archive-espresso_events' );
696
-			wp_enqueue_script( 'jquery-masonry' );
697
-			wp_enqueue_script( 'archive-espresso_events' );
698
-			add_action( 'wp_footer', array( 'EED_Events_Archive_Filters', 'localize_grid_event_lists' ), 1 );
695
+			wp_enqueue_style('archive-espresso_events');
696
+			wp_enqueue_script('jquery-masonry');
697
+			wp_enqueue_script('archive-espresso_events');
698
+			add_action('wp_footer', array('EED_Events_Archive_Filters', 'localize_grid_event_lists'), 1);
699 699
 		}
700 700
 	}
701 701
 
@@ -710,7 +710,7 @@  discard block
 block discarded – undo
710 710
 	 *  @return 	void
711 711
 	 */
712 712
 	public static function localize_grid_event_lists() {
713
-		wp_localize_script( 'archive-espresso_events', 'espresso_grid_event_lists', EED_Events_Archive_Filters::$espresso_grid_event_lists );
713
+		wp_localize_script('archive-espresso_events', 'espresso_grid_event_lists', EED_Events_Archive_Filters::$espresso_grid_event_lists);
714 714
 	}
715 715
 
716 716
 
@@ -725,9 +725,9 @@  discard block
 block discarded – undo
725 725
 	 */
726 726
 	public static function template_settings_form() {
727 727
 		$EE = EE_Registry::instance();
728
-		$EE->CFG->template_settings->EED_Events_Archive_Filters = isset( $EE->CFG->template_settings->EED_Events_Archive_Filters ) ? $EE->CFG->template_settings->EED_Events_Archive_Filters : new EE_Events_Archive_Config();
729
-		$EE->CFG->template_settings->EED_Events_Archive_Filters = apply_filters( 'FHEE__Event_List__template_settings_form__event_list_config', $EE->CFG->template_settings->EED_Events_Archive_Filters );
730
-		EEH_Template::display_template( EVENTS_ARCHIVE_TEMPLATES_PATH . 'admin-event-list-settings.template.php', $EE->CFG->template_settings->EED_Events_Archive_Filters );
728
+		$EE->CFG->template_settings->EED_Events_Archive_Filters = isset($EE->CFG->template_settings->EED_Events_Archive_Filters) ? $EE->CFG->template_settings->EED_Events_Archive_Filters : new EE_Events_Archive_Config();
729
+		$EE->CFG->template_settings->EED_Events_Archive_Filters = apply_filters('FHEE__Event_List__template_settings_form__event_list_config', $EE->CFG->template_settings->EED_Events_Archive_Filters);
730
+		EEH_Template::display_template(EVENTS_ARCHIVE_TEMPLATES_PATH.'admin-event-list-settings.template.php', $EE->CFG->template_settings->EED_Events_Archive_Filters);
731 731
 	}
732 732
 
733 733
 
@@ -741,16 +741,16 @@  discard block
 block discarded – undo
741 741
 	 *  @static
742 742
 	 *  @return 	void
743 743
 	 */
744
-	public static function set_default_settings( $CFG ) {
744
+	public static function set_default_settings($CFG) {
745 745
 		//EEH_Debug_Tools::printr( $CFG, '$CFG  <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span>', 'auto' );
746
-		$CFG->display_description = isset( $CFG->display_description ) && ! empty( $CFG->display_description ) ? $CFG->display_description : 1;
747
-		$CFG->display_address = isset( $CFG->display_address ) && ! empty( $CFG->display_address ) ? $CFG->display_address : TRUE;
748
-		$CFG->display_venue_details = isset( $CFG->display_venue_details ) && ! empty( $CFG->display_venue_details ) ? $CFG->display_venue_details : TRUE;
749
-		$CFG->display_expired_events = isset( $CFG->display_expired_events ) && ! empty( $CFG->display_expired_events ) ? $CFG->display_expired_events : FALSE;
750
-		$CFG->default_type = isset( $CFG->default_type ) && ! empty( $CFG->default_type ) ? $CFG->default_type : 'grid';
751
-		$CFG->event_list_grid_size = isset( $CFG->event_list_grid_size ) && ! empty( $CFG->event_list_grid_size ) ? $CFG->event_list_grid_size : 'medium';
752
-		$CFG->templates['full'] = isset( $CFG->templates['full'] ) && ! empty( $CFG->templates['full'] ) ? $CFG->templates['full'] : EE_TEMPLATES . EE_Config::get_current_theme() . DS . 'archive-espresso_events.php';
753
-		$CFG->templates['part'] = isset( $CFG->templates['part'] ) && ! empty( $CFG->templates['part'] ) ? $CFG->templates['part'] : EE_TEMPLATES . EE_Config::get_current_theme() . DS . 'archive-espresso_events-grid-view.php';
746
+		$CFG->display_description = isset($CFG->display_description) && ! empty($CFG->display_description) ? $CFG->display_description : 1;
747
+		$CFG->display_address = isset($CFG->display_address) && ! empty($CFG->display_address) ? $CFG->display_address : TRUE;
748
+		$CFG->display_venue_details = isset($CFG->display_venue_details) && ! empty($CFG->display_venue_details) ? $CFG->display_venue_details : TRUE;
749
+		$CFG->display_expired_events = isset($CFG->display_expired_events) && ! empty($CFG->display_expired_events) ? $CFG->display_expired_events : FALSE;
750
+		$CFG->default_type = isset($CFG->default_type) && ! empty($CFG->default_type) ? $CFG->default_type : 'grid';
751
+		$CFG->event_list_grid_size = isset($CFG->event_list_grid_size) && ! empty($CFG->event_list_grid_size) ? $CFG->event_list_grid_size : 'medium';
752
+		$CFG->templates['full'] = isset($CFG->templates['full']) && ! empty($CFG->templates['full']) ? $CFG->templates['full'] : EE_TEMPLATES.EE_Config::get_current_theme().DS.'archive-espresso_events.php';
753
+		$CFG->templates['part'] = isset($CFG->templates['part']) && ! empty($CFG->templates['part']) ? $CFG->templates['part'] : EE_TEMPLATES.EE_Config::get_current_theme().DS.'archive-espresso_events-grid-view.php';
754 754
 		return $CFG;
755 755
 	}
756 756
 
@@ -762,7 +762,7 @@  discard block
 block discarded – undo
762 762
 	 *  @access 	public
763 763
 	 *  @return 	void
764 764
 	 */
765
-	public function filter_config( $CFG ) {
765
+	public function filter_config($CFG) {
766 766
 		return $CFG;
767 767
 	}
768 768
 
@@ -775,32 +775,32 @@  discard block
 block discarded – undo
775 775
 	 *  @access 	public
776 776
 	 *  @return 	void
777 777
 	 */
778
-	public static function update_template_settings( $CFG, $REQ ) {
778
+	public static function update_template_settings($CFG, $REQ) {
779 779
 //		EEH_Debug_Tools::printr( $REQ, '$REQ  <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span>', 'auto' );
780 780
 //		EEH_Debug_Tools::printr( $CFG, '$CFG  <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span>', 'auto' );
781 781
 		//$CFG->template_settings->EED_Events_Archive_Filters = new stdClass();
782
-		$CFG->EED_Events_Archive_Filters->display_description = isset( $REQ['display_description_in_event_list'] ) ? absint( $REQ['display_description_in_event_list'] ) : 1;
783
-		$CFG->EED_Events_Archive_Filters->display_address = isset( $REQ['display_address_in_event_list'] ) ? absint( $REQ['display_address_in_event_list'] ) : TRUE;
784
-		$CFG->EED_Events_Archive_Filters->display_venue_details = isset( $REQ['display_venue_details_in_event_list'] ) ? absint( $REQ['display_venue_details_in_event_list'] ) : TRUE;
785
-		$CFG->EED_Events_Archive_Filters->display_expired_events = isset( $REQ['display_expired_events'] ) ? absint( $REQ['display_expired_events'] ) : FALSE;
786
-		$CFG->EED_Events_Archive_Filters->default_type = isset( $REQ['default_type'] ) ? sanitize_text_field( $REQ['default_type'] ) : 'grid';
787
-		$CFG->EED_Events_Archive_Filters->event_list_grid_size = isset( $REQ['event_list_grid_size'] ) ? sanitize_text_field( $REQ['event_list_grid_size'] ) : 'medium';
782
+		$CFG->EED_Events_Archive_Filters->display_description = isset($REQ['display_description_in_event_list']) ? absint($REQ['display_description_in_event_list']) : 1;
783
+		$CFG->EED_Events_Archive_Filters->display_address = isset($REQ['display_address_in_event_list']) ? absint($REQ['display_address_in_event_list']) : TRUE;
784
+		$CFG->EED_Events_Archive_Filters->display_venue_details = isset($REQ['display_venue_details_in_event_list']) ? absint($REQ['display_venue_details_in_event_list']) : TRUE;
785
+		$CFG->EED_Events_Archive_Filters->display_expired_events = isset($REQ['display_expired_events']) ? absint($REQ['display_expired_events']) : FALSE;
786
+		$CFG->EED_Events_Archive_Filters->default_type = isset($REQ['default_type']) ? sanitize_text_field($REQ['default_type']) : 'grid';
787
+		$CFG->EED_Events_Archive_Filters->event_list_grid_size = isset($REQ['event_list_grid_size']) ? sanitize_text_field($REQ['event_list_grid_size']) : 'medium';
788 788
 		$CFG->EED_Events_Archive_Filters->templates = array(
789
-				'full'  => EE_TEMPLATES . EE_Config::get_current_theme() . DS . 'archive-espresso_events.php'
789
+				'full'  => EE_TEMPLATES.EE_Config::get_current_theme().DS.'archive-espresso_events.php'
790 790
 			);
791 791
 
792
-		switch ( $CFG->EED_Events_Archive_Filters->default_type ) {
792
+		switch ($CFG->EED_Events_Archive_Filters->default_type) {
793 793
 			case 'dates' :
794
-					$CFG->EED_Events_Archive_Filters->templates['part'] = EE_TEMPLATES . EE_Config::get_current_theme() . DS . 'archive-espresso_events-dates-view.php';
794
+					$CFG->EED_Events_Archive_Filters->templates['part'] = EE_TEMPLATES.EE_Config::get_current_theme().DS.'archive-espresso_events-dates-view.php';
795 795
 				break;
796 796
 			case 'text' :
797
-					$CFG->EED_Events_Archive_Filters->templates['part'] = EE_TEMPLATES . EE_Config::get_current_theme() . DS . 'archive-espresso_events-text-view.php';
797
+					$CFG->EED_Events_Archive_Filters->templates['part'] = EE_TEMPLATES.EE_Config::get_current_theme().DS.'archive-espresso_events-text-view.php';
798 798
 				break;
799 799
 			default :
800
-					$CFG->EED_Events_Archive_Filters->templates['part'] = EE_TEMPLATES . EE_Config::get_current_theme() . DS . 'archive-espresso_events-grid-view.php';
800
+					$CFG->EED_Events_Archive_Filters->templates['part'] = EE_TEMPLATES.EE_Config::get_current_theme().DS.'archive-espresso_events-grid-view.php';
801 801
 		}
802 802
 
803
-		$CFG->EED_Events_Archive_Filters = isset( $REQ['reset_event_list_settings'] ) && absint( $REQ['reset_event_list_settings'] ) == 1 ? new EE_Events_Archive_Config() : $CFG->EED_Events_Archive_Filters;
803
+		$CFG->EED_Events_Archive_Filters = isset($REQ['reset_event_list_settings']) && absint($REQ['reset_event_list_settings']) == 1 ? new EE_Events_Archive_Config() : $CFG->EED_Events_Archive_Filters;
804 804
 		return $CFG;
805 805
 	}
806 806
 
@@ -815,7 +815,7 @@  discard block
 block discarded – undo
815 815
 	 *  @return 	void
816 816
 	 */
817 817
 	public static function get_template_part() {
818
-		switch ( self::$_type ) {
818
+		switch (self::$_type) {
819 819
 			case 'dates' :
820 820
 					return 'archive-espresso_events-dates-view.php';
821 821
 				break;
@@ -839,13 +839,13 @@  discard block
 block discarded – undo
839 839
 	 */
840 840
 	public function event_list_template_filters() {
841 841
 		$args = array(
842
-			'form_url' => get_post_type_archive_link( 'espresso_events' ), //add_query_arg( array( 'post_type' => 'espresso_events' ), home_url() ),
842
+			'form_url' => get_post_type_archive_link('espresso_events'), //add_query_arg( array( 'post_type' => 'espresso_events' ), home_url() ),
843 843
 			'elf_month' => EED_Events_Archive_Filters::_display_month(),
844 844
 			'elf_category' => EED_Events_Archive_Filters::_event_category_slug(),
845 845
 			'elf_show_expired' => EED_Events_Archive_Filters::_show_expired(),
846 846
 			'elf_type' => self::$_type
847 847
 		);
848
-		EEH_Template::display_template( EE_TEMPLATES . EE_Config::get_current_theme() . DS . 'archive-espresso_events-filters.php', $args );
848
+		EEH_Template::display_template(EE_TEMPLATES.EE_Config::get_current_theme().DS.'archive-espresso_events-filters.php', $args);
849 849
 	}
850 850
 
851 851
 
@@ -858,16 +858,16 @@  discard block
 block discarded – undo
858 858
 	 *  @access 	public
859 859
 	 *  @return 	void
860 860
 	 */
861
-	public static function event_list_css( $extra_class = '' ) {
861
+	public static function event_list_css($extra_class = '') {
862 862
 		$EE = EE_Registry::instance();
863
-		$event_list_css = ! empty( $extra_class ) ? array( $extra_class ) : array();
863
+		$event_list_css = ! empty($extra_class) ? array($extra_class) : array();
864 864
 		$event_list_css[] = 'espresso-event-list-event';
865
-		if ( self::$_type == 'grid' ) {
866
-			$event_list_grid_size = isset( $EE->CFG->template_settings->EED_Events_Archive_Filters->event_list_grid_size ) ? $EE->CFG->template_settings->EED_Events_Archive_Filters->event_list_grid_size : 'medium';
867
-			$event_list_css[] = $event_list_grid_size . '-event-list-grid';
865
+		if (self::$_type == 'grid') {
866
+			$event_list_grid_size = isset($EE->CFG->template_settings->EED_Events_Archive_Filters->event_list_grid_size) ? $EE->CFG->template_settings->EED_Events_Archive_Filters->event_list_grid_size : 'medium';
867
+			$event_list_css[] = $event_list_grid_size.'-event-list-grid';
868 868
 		}
869
-		$event_list_css = apply_filters( 'EED_Events_Archive_Filters__event_list_css__event_list_css_array', $event_list_css );
870
-		return implode( ' ', $event_list_css );
869
+		$event_list_css = apply_filters('EED_Events_Archive_Filters__event_list_css__event_list_css_array', $event_list_css);
870
+		return implode(' ', $event_list_css);
871 871
 	}
872 872
 
873 873
 
@@ -893,9 +893,9 @@  discard block
 block discarded – undo
893 893
 	 *  @access 	public
894 894
 	 *  @return 	void
895 895
 	 */
896
-	public static function display_description( $value ) {
896
+	public static function display_description($value) {
897 897
 		$EE = EE_Registry::instance();
898
-		$display_description= isset( $EE->CFG->template_settings->EED_Events_Archive_Filters->display_description ) ? $EE->CFG->template_settings->EED_Events_Archive_Filters->display_description : 1;
898
+		$display_description = isset($EE->CFG->template_settings->EED_Events_Archive_Filters->display_description) ? $EE->CFG->template_settings->EED_Events_Archive_Filters->display_description : 1;
899 899
 		return $display_description === $value ? TRUE : FALSE;
900 900
 	}
901 901
 
@@ -909,9 +909,9 @@  discard block
 block discarded – undo
909 909
 	 */
910 910
 	public static function display_venue_details() {
911 911
 		$EE = EE_Registry::instance();
912
-		$display_venue_details= isset( $EE->CFG->template_settings->EED_Events_Archive_Filters->display_venue_details ) ? $EE->CFG->template_settings->EED_Events_Archive_Filters->display_venue_details : TRUE;
912
+		$display_venue_details = isset($EE->CFG->template_settings->EED_Events_Archive_Filters->display_venue_details) ? $EE->CFG->template_settings->EED_Events_Archive_Filters->display_venue_details : TRUE;
913 913
 		$venue_name = EEH_Venue_View::venue_name();
914
-		return $display_venue_details && ! empty( $venue_name ) ? TRUE : FALSE;
914
+		return $display_venue_details && ! empty($venue_name) ? TRUE : FALSE;
915 915
 	}
916 916
 
917 917
 
@@ -923,9 +923,9 @@  discard block
 block discarded – undo
923 923
 	 */
924 924
 	public static function display_address() {
925 925
 		$EE = EE_Registry::instance();
926
-		$display_address= isset( $EE->CFG->template_settings->EED_Events_Archive_Filters->display_address ) ? $EE->CFG->template_settings->EED_Events_Archive_Filters->display_address : FALSE;
926
+		$display_address = isset($EE->CFG->template_settings->EED_Events_Archive_Filters->display_address) ? $EE->CFG->template_settings->EED_Events_Archive_Filters->display_address : FALSE;
927 927
 		$venue_name = EEH_Venue_View::venue_name();
928
-		return $display_address && ! empty( $venue_name ) ? TRUE : FALSE;
928
+		return $display_address && ! empty($venue_name) ? TRUE : FALSE;
929 929
 	}
930 930
 
931 931
 
@@ -939,22 +939,22 @@  discard block
 block discarded – undo
939 939
 	public static function pagination() {
940 940
 		global $wp_query;
941 941
 		$big = 999999999; // need an unlikely integer
942
-		$pagination = paginate_links( array(
943
-			'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
942
+		$pagination = paginate_links(array(
943
+			'base' => str_replace($big, '%#%', esc_url(get_pagenum_link($big))),
944 944
 			'format' => '?paged=%#%',
945
-			'current' => max( 1, get_query_var('paged') ),
945
+			'current' => max(1, get_query_var('paged')),
946 946
 			'total' => $wp_query->max_num_pages,
947 947
 			'show_all'     => TRUE,
948 948
 			'end_size'     => 10,
949 949
 			'mid_size'     => 6,
950 950
 			'prev_next'    => TRUE,
951
-			'prev_text'    => __( '&lsaquo; PREV', 'event_espresso' ),
952
-			'next_text'    => __( 'NEXT &rsaquo;', 'event_espresso' ),
951
+			'prev_text'    => __('&lsaquo; PREV', 'event_espresso'),
952
+			'next_text'    => __('NEXT &rsaquo;', 'event_espresso'),
953 953
 			'type'         => 'plain',
954 954
 			'add_args'     => FALSE,
955 955
 			'add_fragment' => ''
956 956
 		));
957
-		return ! empty( $pagination ) ? '<div class="ee-pagination-dv clear">' . $pagination . '</div>' : '';
957
+		return ! empty($pagination) ? '<div class="ee-pagination-dv clear">'.$pagination.'</div>' : '';
958 958
 	}
959 959
 
960 960
 
@@ -968,7 +968,7 @@  discard block
 block discarded – undo
968 968
 	 *  @return 	void
969 969
 	 */
970 970
 	public static function event_list_title() {
971
-		return apply_filters( 'EED_Events_Archive_Filters__event_list_title__event_list_title', __( 'Upcoming Events', 'event_espresso' ));
971
+		return apply_filters('EED_Events_Archive_Filters__event_list_title__event_list_title', __('Upcoming Events', 'event_espresso'));
972 972
 	}
973 973
 
974 974
 
Please login to merge, or discard this patch.
core/helpers/EEH_Event_Query.helper.php 2 patches
Indentation   +147 added lines, -147 removed lines patch added patch discarded remove patch
@@ -91,9 +91,9 @@  discard block
 block discarded – undo
91 91
 	 */
92 92
 	public static function apply_query_filters( WP_Query $WP_Query ) {
93 93
 		return (
94
-		    isset( $WP_Query->query, $WP_Query->query['post_type'] )
95
-            && $WP_Query->query['post_type'] === 'espresso_events'
96
-        ) ||  apply_filters( 'FHEE__EEH_Event_Query__apply_query_filters', false ) ;
94
+			isset( $WP_Query->query, $WP_Query->query['post_type'] )
95
+			&& $WP_Query->query['post_type'] === 'espresso_events'
96
+		) ||  apply_filters( 'FHEE__EEH_Event_Query__apply_query_filters', false ) ;
97 97
 	}
98 98
 
99 99
 
@@ -104,8 +104,8 @@  discard block
 block discarded – undo
104 104
 	 */
105 105
 	public static function filter_query_parts( WP_Query $WP_Query ) {
106 106
 		// ONLY add our filters if this isn't the main wp_query,
107
-        // because if this is the main wp_query we already have
108
-        // our cpt strategies take care of adding things in.
107
+		// because if this is the main wp_query we already have
108
+		// our cpt strategies take care of adding things in.
109 109
 		if ( $WP_Query instanceof WP_Query && ! $WP_Query->is_main_query() ) {
110 110
 			// build event list query
111 111
 			add_filter( 'posts_fields', array( 'EEH_Event_Query', 'posts_fields' ), 10, 2 );
@@ -127,13 +127,13 @@  discard block
 block discarded – undo
127 127
 	 * @param string $orderby
128 128
 	 * @param string $sort
129 129
 	 */
130
-    public static function set_query_params(
131
-        $month = '',
132
-        $category = '',
133
-        $show_expired = false,
134
-        $orderby = 'start_date',
135
-        $sort = 'ASC'
136
-    ) {
130
+	public static function set_query_params(
131
+		$month = '',
132
+		$category = '',
133
+		$show_expired = false,
134
+		$orderby = 'start_date',
135
+		$sort = 'ASC'
136
+	) {
137 137
 		self::$_query_params = array();
138 138
 		EEH_Event_Query::$_event_query_month = EEH_Event_Query::_display_month( $month );
139 139
 		EEH_Event_Query::$_event_query_category = EEH_Event_Query::_event_category_slug( $category );
@@ -151,8 +151,8 @@  discard block
 block discarded – undo
151 151
 	 * @return    string
152 152
 	 */
153 153
 	private static function _display_month( $month = '' ) {
154
-        return sanitize_text_field(EE_Registry::instance()->REQ->get('event_query_month', $month));
155
-    }
154
+		return sanitize_text_field(EE_Registry::instance()->REQ->get('event_query_month', $month));
155
+	}
156 156
 
157 157
 
158 158
 
@@ -177,9 +177,9 @@  discard block
 block discarded – undo
177 177
 	private static function _show_expired( $show_expired = false ) {
178 178
 		// override default expired option if set via filter
179 179
 		return filter_var(
180
-		    EE_Registry::instance()->REQ->get('event_query_show_expired', $show_expired),
181
-            FILTER_VALIDATE_BOOLEAN
182
-        );
180
+			EE_Registry::instance()->REQ->get('event_query_show_expired', $show_expired),
181
+			FILTER_VALIDATE_BOOLEAN
182
+		);
183 183
 	}
184 184
 
185 185
 
@@ -193,8 +193,8 @@  discard block
 block discarded – undo
193 193
 	private static function _orderby( $orderby = 'start_date' ) {
194 194
 		$event_query_orderby = EE_Registry::instance()->REQ->get('event_query_orderby', $orderby);
195 195
 		$event_query_orderby = is_array( $event_query_orderby )
196
-            ? $event_query_orderby
197
-            : explode( ',', $event_query_orderby );
196
+			? $event_query_orderby
197
+			: explode( ',', $event_query_orderby );
198 198
 		$event_query_orderby = array_map( 'trim', $event_query_orderby );
199 199
 		$event_query_orderby = array_map( 'sanitize_text_field', $event_query_orderby );
200 200
 		return $event_query_orderby;
@@ -211,8 +211,8 @@  discard block
 block discarded – undo
211 211
 	private static function _sort( $sort = 'ASC' ) {
212 212
 		$sort = EE_Registry::instance()->REQ->get('event_query_sort', $sort);
213 213
 		return in_array( $sort, array( 'ASC', 'asc', 'DESC', 'desc' ), true)
214
-            ? strtoupper( $sort )
215
-            : 'ASC';
214
+			? strtoupper( $sort )
215
+			: 'ASC';
216 216
 	}
217 217
 
218 218
 
@@ -235,14 +235,14 @@  discard block
 block discarded – undo
235 235
 
236 236
 
237 237
 
238
-    /**
239
-     *    posts_fields
240
-     *
241
-     * @param          $SQL
242
-     * @param WP_Query $wp_query
243
-     * @return    string
244
-     * @throws \EE_Error
245
-     */
238
+	/**
239
+	 *    posts_fields
240
+	 *
241
+	 * @param          $SQL
242
+	 * @param WP_Query $wp_query
243
+	 * @return    string
244
+	 * @throws \EE_Error
245
+	 */
246 246
 	public static function posts_fields( $SQL, WP_Query $wp_query ) {
247 247
 		if ( EEH_Event_Query::apply_query_filters( $wp_query ) ) {
248 248
 			// adds something like ", wp_esp_datetime.* " to WP Query SELECT statement
@@ -253,13 +253,13 @@  discard block
 block discarded – undo
253 253
 
254 254
 
255 255
 
256
-    /**
257
-     *    posts_join_sql_for_terms
258
-     *
259
-     * @param array $orderby_params
260
-     * @return    string
261
-     * @throws \EE_Error
262
-     */
256
+	/**
257
+	 *    posts_join_sql_for_terms
258
+	 *
259
+	 * @param array $orderby_params
260
+	 * @return    string
261
+	 * @throws \EE_Error
262
+	 */
263 263
 	public static function posts_fields_sql_for_orderby( $orderby_params = array() ) {
264 264
 		$SQL = ', MIN( ' . EEM_Datetime::instance()->table() . '.DTT_EVT_start ) as event_start_date ' ;
265 265
 		foreach( (array)$orderby_params as $orderby ) {
@@ -292,14 +292,14 @@  discard block
 block discarded – undo
292 292
 
293 293
 
294 294
 
295
-    /**
296
-     *    posts_join
297
-     *
298
-     * @param string   $SQL
299
-     * @param WP_Query $wp_query
300
-     * @return    string
301
-     * @throws \EE_Error
302
-     */
295
+	/**
296
+	 *    posts_join
297
+	 *
298
+	 * @param string   $SQL
299
+	 * @param WP_Query $wp_query
300
+	 * @return    string
301
+	 * @throws \EE_Error
302
+	 */
303 303
 	public static function posts_join( $SQL = '', WP_Query $wp_query ) {
304 304
 		if ( EEH_Event_Query::apply_query_filters( $wp_query ) ) {
305 305
 			// Category
@@ -312,14 +312,14 @@  discard block
 block discarded – undo
312 312
 
313 313
 
314 314
 
315
-    /**
316
-     *    posts_join_sql_for_terms
317
-     *
318
-     * @param string     $SQL
319
-     * @param    boolean $show_expired if TRUE, then displayed past events
320
-     * @return string
321
-     * @throws \EE_Error
322
-     */
315
+	/**
316
+	 *    posts_join_sql_for_terms
317
+	 *
318
+	 * @param string     $SQL
319
+	 * @param    boolean $show_expired if TRUE, then displayed past events
320
+	 * @return string
321
+	 * @throws \EE_Error
322
+	 */
323 323
 	public static function posts_join_sql_for_show_expired( $SQL = '', $show_expired = FALSE ) {
324 324
 		if ( ! $show_expired ) {
325 325
 			$join = EEM_Event::instance()->table() . '.ID = ';
@@ -353,24 +353,24 @@  discard block
 block discarded – undo
353 353
 
354 354
 
355 355
 
356
-    /**
357
-     *    posts_join_for_orderby
358
-     *    usage:  $SQL .= EEH_Event_Query::posts_join_for_orderby( $orderby_params );
359
-     *
360
-     * @param    string $SQL
361
-     * @param    array  $orderby_params
362
-     * @return    string
363
-     * @throws \EE_Error
364
-     */
356
+	/**
357
+	 *    posts_join_for_orderby
358
+	 *    usage:  $SQL .= EEH_Event_Query::posts_join_for_orderby( $orderby_params );
359
+	 *
360
+	 * @param    string $SQL
361
+	 * @param    array  $orderby_params
362
+	 * @return    string
363
+	 * @throws \EE_Error
364
+	 */
365 365
 	public static function posts_join_for_orderby( $SQL = '', $orderby_params = array() ) {
366 366
 		foreach ( (array)$orderby_params as $orderby ) {
367 367
 			switch ( $orderby ) {
368 368
 				case 'ticket_start' :
369 369
 				case 'ticket_end' :
370 370
 					$SQL .= EEH_Event_Query::_posts_join_for_datetime(
371
-					    $SQL,
372
-                        EEM_Datetime_Ticket::instance()->table() . '.' . EEM_Datetime::instance()->primary_key_name()
373
-                    );
371
+						$SQL,
372
+						EEM_Datetime_Ticket::instance()->table() . '.' . EEM_Datetime::instance()->primary_key_name()
373
+					);
374 374
 					$SQL .= ' LEFT JOIN ' . EEM_Ticket::instance()->table();
375 375
 					$SQL .= ' ON (';
376 376
 					$SQL .= EEM_Datetime_Ticket::instance()->table() . '.' . EEM_Ticket::instance()->primary_key_name();
@@ -398,14 +398,14 @@  discard block
 block discarded – undo
398 398
 
399 399
 
400 400
 
401
-    /**
402
-     *    _posts_join_for_datetime
403
-     *
404
-     * @param string $SQL
405
-     * @param string $join
406
-     * @return string
407
-     * @throws \EE_Error
408
-     */
401
+	/**
402
+	 *    _posts_join_for_datetime
403
+	 *
404
+	 * @param string $SQL
405
+	 * @param string $join
406
+	 * @return string
407
+	 * @throws \EE_Error
408
+	 */
409 409
 	protected static function _posts_join_for_datetime( $SQL = '', $join = '' ) {
410 410
 		if ( ! empty( $join )) {
411 411
 			$join .= ' = ' . EEM_Datetime::instance()->table() . '.' . EEM_Event::instance()->primary_key_name();
@@ -418,13 +418,13 @@  discard block
 block discarded – undo
418 418
 
419 419
 
420 420
 
421
-    /**
422
-     *    _posts_join_for_event_venue
423
-     *
424
-     * @param string $SQL
425
-     * @return string
426
-     * @throws \EE_Error
427
-     */
421
+	/**
422
+	 *    _posts_join_for_event_venue
423
+	 *
424
+	 * @param string $SQL
425
+	 * @return string
426
+	 * @throws \EE_Error
427
+	 */
428 428
 	protected static function _posts_join_for_event_venue( $SQL = '' ) {
429 429
 		// Event Venue table name
430 430
 		$event_venue_table = EEM_Event_Venue::instance()->table();
@@ -454,13 +454,13 @@  discard block
 block discarded – undo
454 454
 
455 455
 
456 456
 
457
-    /**
458
-     *    _posts_join_for_venue_state
459
-     *
460
-     * @param string $SQL
461
-     * @return string
462
-     * @throws \EE_Error
463
-     */
457
+	/**
458
+	 *    _posts_join_for_venue_state
459
+	 *
460
+	 * @param string $SQL
461
+	 * @return string
462
+	 * @throws \EE_Error
463
+	 */
464 464
 	protected static function _posts_join_for_venue_state( $SQL = '' ) {
465 465
 		// Venue Meta table name
466 466
 		$venue_meta_table = EEM_Venue::instance()->second_table();
@@ -484,14 +484,14 @@  discard block
 block discarded – undo
484 484
 
485 485
 
486 486
 
487
-    /**
488
-     *    posts_where
489
-     *
490
-     * @param string   $SQL
491
-     * @param WP_Query $wp_query
492
-     * @return    string
493
-     * @throws \EE_Error
494
-     */
487
+	/**
488
+	 *    posts_where
489
+	 *
490
+	 * @param string   $SQL
491
+	 * @param WP_Query $wp_query
492
+	 * @return    string
493
+	 * @throws \EE_Error
494
+	 */
495 495
 	public static function posts_where( $SQL = '', WP_Query $wp_query ) {
496 496
 		if ( EEH_Event_Query::apply_query_filters( $wp_query ) ) {
497 497
 			// Show Expired ?
@@ -506,17 +506,17 @@  discard block
 block discarded – undo
506 506
 
507 507
 
508 508
 
509
-    /**
510
-     *    posts_where_sql_for_show_expired
511
-     *
512
-     * @param    boolean $show_expired if TRUE, then displayed past events
513
-     * @return    string
514
-     * @throws \EE_Error
515
-     */
509
+	/**
510
+	 *    posts_where_sql_for_show_expired
511
+	 *
512
+	 * @param    boolean $show_expired if TRUE, then displayed past events
513
+	 * @return    string
514
+	 * @throws \EE_Error
515
+	 */
516 516
 	public static function posts_where_sql_for_show_expired( $show_expired = FALSE ) {
517 517
 		return ! $show_expired
518
-            ? ' AND ' . EEM_Datetime::instance()->table() . '.DTT_EVT_end > \'' . current_time( 'mysql', TRUE ) . '\' '
519
-            : '';
518
+			? ' AND ' . EEM_Datetime::instance()->table() . '.DTT_EVT_end > \'' . current_time( 'mysql', TRUE ) . '\' '
519
+			: '';
520 520
 	}
521 521
 
522 522
 
@@ -531,19 +531,19 @@  discard block
 block discarded – undo
531 531
 		global $wpdb;
532 532
 		$event_category_slug = esc_sql($event_category_slug);
533 533
 		return ! empty( $event_category_slug )
534
-            ? " AND {$wpdb->terms}.slug = '{$event_category_slug}' "
535
-            : '';
534
+			? " AND {$wpdb->terms}.slug = '{$event_category_slug}' "
535
+			: '';
536 536
 	}
537 537
 
538 538
 
539 539
 
540
-    /**
541
-     *    posts_where_sql_for_event_list_month
542
-     *
543
-     * @param    boolean $month
544
-     * @return    string
545
-     * @throws \EE_Error
546
-     */
540
+	/**
541
+	 *    posts_where_sql_for_event_list_month
542
+	 *
543
+	 * @param    boolean $month
544
+	 * @return    string
545
+	 * @throws \EE_Error
546
+	 */
547 547
 	public static function posts_where_sql_for_event_list_month( $month = NULL ) {
548 548
 		$SQL = '';
549 549
 		if ( ! empty( $month ) ) {
@@ -558,55 +558,55 @@  discard block
 block discarded – undo
558 558
 
559 559
 
560 560
 
561
-    /**
562
-     *    posts_orderby
563
-     *
564
-     * @param string   $SQL
565
-     * @param WP_Query $wp_query
566
-     * @return    string
567
-     * @throws \EE_Error
568
-     */
561
+	/**
562
+	 *    posts_orderby
563
+	 *
564
+	 * @param string   $SQL
565
+	 * @param WP_Query $wp_query
566
+	 * @return    string
567
+	 * @throws \EE_Error
568
+	 */
569 569
 	public static function posts_orderby( $SQL = '', WP_Query $wp_query ) {
570 570
 		if ( EEH_Event_Query::apply_query_filters( $wp_query ) ) {
571 571
 			$SQL = EEH_Event_Query::posts_orderby_sql(
572
-			    EEH_Event_Query::$_event_query_orderby,
573
-                EEH_Event_Query::$_event_query_sort
574
-            );
572
+				EEH_Event_Query::$_event_query_orderby,
573
+				EEH_Event_Query::$_event_query_sort
574
+			);
575 575
 		}
576 576
 		return $SQL;
577 577
 	}
578 578
 
579 579
 
580 580
 
581
-    /**
582
-     *    posts_orderby_sql
583
-     *    possible parameters:
584
-     *    ID
585
-     *    start_date
586
-     *    end_date
587
-     *    event_name
588
-     *    category_slug
589
-     *    ticket_start
590
-     *    ticket_end
591
-     *    venue_title
592
-     *    city
593
-     *    state
594
-     *    **IMPORTANT**
595
-     *    make sure to also send the $orderby_params array to the posts_join_for_orderby() method
596
-     *    or else some of the table references below will result in MySQL errors
597
-     *
598
-     * @param array|bool $orderby_params
599
-     * @param string     $sort
600
-     * @return string
601
-     * @throws \EE_Error
602
-     */
581
+	/**
582
+	 *    posts_orderby_sql
583
+	 *    possible parameters:
584
+	 *    ID
585
+	 *    start_date
586
+	 *    end_date
587
+	 *    event_name
588
+	 *    category_slug
589
+	 *    ticket_start
590
+	 *    ticket_end
591
+	 *    venue_title
592
+	 *    city
593
+	 *    state
594
+	 *    **IMPORTANT**
595
+	 *    make sure to also send the $orderby_params array to the posts_join_for_orderby() method
596
+	 *    or else some of the table references below will result in MySQL errors
597
+	 *
598
+	 * @param array|bool $orderby_params
599
+	 * @param string     $sort
600
+	 * @return string
601
+	 * @throws \EE_Error
602
+	 */
603 603
 	public static function posts_orderby_sql( $orderby_params = array(), $sort = 'ASC' ) {
604 604
 		global $wpdb;
605 605
 		$SQL = '';
606 606
 		$counter = 0;
607 607
 		$sort = in_array($sort, array('ASC', 'asc', 'DESC', 'desc'), true)
608
-            ? strtoupper($sort)
609
-            : 'ASC';
608
+			? strtoupper($sort)
609
+			: 'ASC';
610 610
 		//make sure 'orderby' is set in query params
611 611
 		if ( ! isset( self::$_query_params['orderby'] )) {
612 612
 			self::$_query_params['orderby'] = array();
Please login to merge, or discard this patch.
Spacing   +119 added lines, -119 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1
-<?php if ( ! defined( 'EVENT_ESPRESSO_VERSION' ) ) {
2
-	exit( 'No direct script access allowed' );
1
+<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) {
2
+	exit('No direct script access allowed');
3 3
 }
4 4
 /**
5 5
  * Event Espresso
@@ -78,7 +78,7 @@  discard block
 block discarded – undo
78 78
 	 */
79 79
 	public static function add_query_filters() {
80 80
 		//add query filters
81
-		add_action( 'pre_get_posts', array( 'EEH_Event_Query', 'filter_query_parts' ), 10, 1 );
81
+		add_action('pre_get_posts', array('EEH_Event_Query', 'filter_query_parts'), 10, 1);
82 82
 	}
83 83
 
84 84
 
@@ -89,11 +89,11 @@  discard block
 block discarded – undo
89 89
 	 * @param \WP_Query $WP_Query
90 90
 	 * @return bool
91 91
 	 */
92
-	public static function apply_query_filters( WP_Query $WP_Query ) {
92
+	public static function apply_query_filters(WP_Query $WP_Query) {
93 93
 		return (
94
-		    isset( $WP_Query->query, $WP_Query->query['post_type'] )
94
+		    isset($WP_Query->query, $WP_Query->query['post_type'])
95 95
             && $WP_Query->query['post_type'] === 'espresso_events'
96
-        ) ||  apply_filters( 'FHEE__EEH_Event_Query__apply_query_filters', false ) ;
96
+        ) || apply_filters('FHEE__EEH_Event_Query__apply_query_filters', false);
97 97
 	}
98 98
 
99 99
 
@@ -102,17 +102,17 @@  discard block
 block discarded – undo
102 102
 	 *
103 103
 	 * @param \WP_Query $WP_Query
104 104
 	 */
105
-	public static function filter_query_parts( WP_Query $WP_Query ) {
105
+	public static function filter_query_parts(WP_Query $WP_Query) {
106 106
 		// ONLY add our filters if this isn't the main wp_query,
107 107
         // because if this is the main wp_query we already have
108 108
         // our cpt strategies take care of adding things in.
109
-		if ( $WP_Query instanceof WP_Query && ! $WP_Query->is_main_query() ) {
109
+		if ($WP_Query instanceof WP_Query && ! $WP_Query->is_main_query()) {
110 110
 			// build event list query
111
-			add_filter( 'posts_fields', array( 'EEH_Event_Query', 'posts_fields' ), 10, 2 );
112
-			add_filter( 'posts_join', array( 'EEH_Event_Query', 'posts_join' ), 10, 2 );
113
-			add_filter( 'posts_where', array( 'EEH_Event_Query', 'posts_where' ), 10, 2 );
114
-			add_filter( 'posts_orderby', array( 'EEH_Event_Query', 'posts_orderby' ), 10, 2 );
115
-			add_filter( 'posts_clauses_request', array( 'EEH_Event_Query', 'posts_clauses' ), 10, 2 );
111
+			add_filter('posts_fields', array('EEH_Event_Query', 'posts_fields'), 10, 2);
112
+			add_filter('posts_join', array('EEH_Event_Query', 'posts_join'), 10, 2);
113
+			add_filter('posts_where', array('EEH_Event_Query', 'posts_where'), 10, 2);
114
+			add_filter('posts_orderby', array('EEH_Event_Query', 'posts_orderby'), 10, 2);
115
+			add_filter('posts_clauses_request', array('EEH_Event_Query', 'posts_clauses'), 10, 2);
116 116
 		}
117 117
 	}
118 118
 
@@ -135,11 +135,11 @@  discard block
 block discarded – undo
135 135
         $sort = 'ASC'
136 136
     ) {
137 137
 		self::$_query_params = array();
138
-		EEH_Event_Query::$_event_query_month = EEH_Event_Query::_display_month( $month );
139
-		EEH_Event_Query::$_event_query_category = EEH_Event_Query::_event_category_slug( $category );
140
-		EEH_Event_Query::$_event_query_show_expired = EEH_Event_Query::_show_expired( $show_expired );
141
-		EEH_Event_Query::$_event_query_orderby = EEH_Event_Query::_orderby( $orderby );
142
-		EEH_Event_Query::$_event_query_sort = EEH_Event_Query::_sort( $sort );
138
+		EEH_Event_Query::$_event_query_month = EEH_Event_Query::_display_month($month);
139
+		EEH_Event_Query::$_event_query_category = EEH_Event_Query::_event_category_slug($category);
140
+		EEH_Event_Query::$_event_query_show_expired = EEH_Event_Query::_show_expired($show_expired);
141
+		EEH_Event_Query::$_event_query_orderby = EEH_Event_Query::_orderby($orderby);
142
+		EEH_Event_Query::$_event_query_sort = EEH_Event_Query::_sort($sort);
143 143
 	}
144 144
 
145 145
 
@@ -150,7 +150,7 @@  discard block
 block discarded – undo
150 150
 	 * @param string $month
151 151
 	 * @return    string
152 152
 	 */
153
-	private static function _display_month( $month = '' ) {
153
+	private static function _display_month($month = '') {
154 154
         return sanitize_text_field(EE_Registry::instance()->REQ->get('event_query_month', $month));
155 155
     }
156 156
 
@@ -162,7 +162,7 @@  discard block
 block discarded – undo
162 162
 	 * @param string $category
163 163
 	 * @return    string
164 164
 	 */
165
-	private static function _event_category_slug( $category = '' ) {
165
+	private static function _event_category_slug($category = '') {
166 166
 		return sanitize_title_with_dashes(EE_Registry::instance()->REQ->get('event_query_category', $category));
167 167
 	}
168 168
 
@@ -174,7 +174,7 @@  discard block
 block discarded – undo
174 174
 	 * @param bool $show_expired
175 175
 	 * @return    boolean
176 176
 	 */
177
-	private static function _show_expired( $show_expired = false ) {
177
+	private static function _show_expired($show_expired = false) {
178 178
 		// override default expired option if set via filter
179 179
 		return filter_var(
180 180
 		    EE_Registry::instance()->REQ->get('event_query_show_expired', $show_expired),
@@ -190,13 +190,13 @@  discard block
 block discarded – undo
190 190
 	 * @param    string $orderby
191 191
 	 * @return    array
192 192
 	 */
193
-	private static function _orderby( $orderby = 'start_date' ) {
193
+	private static function _orderby($orderby = 'start_date') {
194 194
 		$event_query_orderby = EE_Registry::instance()->REQ->get('event_query_orderby', $orderby);
195
-		$event_query_orderby = is_array( $event_query_orderby )
195
+		$event_query_orderby = is_array($event_query_orderby)
196 196
             ? $event_query_orderby
197
-            : explode( ',', $event_query_orderby );
198
-		$event_query_orderby = array_map( 'trim', $event_query_orderby );
199
-		$event_query_orderby = array_map( 'sanitize_text_field', $event_query_orderby );
197
+            : explode(',', $event_query_orderby);
198
+		$event_query_orderby = array_map('trim', $event_query_orderby);
199
+		$event_query_orderby = array_map('sanitize_text_field', $event_query_orderby);
200 200
 		return $event_query_orderby;
201 201
 	}
202 202
 
@@ -208,10 +208,10 @@  discard block
 block discarded – undo
208 208
 	 * @param string $sort
209 209
 	 * @return string
210 210
 	 */
211
-	private static function _sort( $sort = 'ASC' ) {
211
+	private static function _sort($sort = 'ASC') {
212 212
 		$sort = EE_Registry::instance()->REQ->get('event_query_sort', $sort);
213
-		return in_array( $sort, array( 'ASC', 'asc', 'DESC', 'desc' ), true)
214
-            ? strtoupper( $sort )
213
+		return in_array($sort, array('ASC', 'asc', 'DESC', 'desc'), true)
214
+            ? strtoupper($sort)
215 215
             : 'ASC';
216 216
 	}
217 217
 
@@ -225,10 +225,10 @@  discard block
 block discarded – undo
225 225
 	 *
226 226
 	 * @return array   array of clauses
227 227
 	 */
228
-	public static function posts_clauses( $clauses, WP_Query $wp_query ) {
229
-		if ( EEH_Event_Query::apply_query_filters( $wp_query ) ) {
228
+	public static function posts_clauses($clauses, WP_Query $wp_query) {
229
+		if (EEH_Event_Query::apply_query_filters($wp_query)) {
230 230
 			global $wpdb;
231
-			$clauses['groupby'] = $wpdb->posts . '.ID ';
231
+			$clauses['groupby'] = $wpdb->posts.'.ID ';
232 232
 		}
233 233
 		return $clauses;
234 234
 	}
@@ -243,10 +243,10 @@  discard block
 block discarded – undo
243 243
      * @return    string
244 244
      * @throws \EE_Error
245 245
      */
246
-	public static function posts_fields( $SQL, WP_Query $wp_query ) {
247
-		if ( EEH_Event_Query::apply_query_filters( $wp_query ) ) {
246
+	public static function posts_fields($SQL, WP_Query $wp_query) {
247
+		if (EEH_Event_Query::apply_query_filters($wp_query)) {
248 248
 			// adds something like ", wp_esp_datetime.* " to WP Query SELECT statement
249
-			$SQL .= EEH_Event_Query::posts_fields_sql_for_orderby( EEH_Event_Query::$_event_query_orderby );
249
+			$SQL .= EEH_Event_Query::posts_fields_sql_for_orderby(EEH_Event_Query::$_event_query_orderby);
250 250
 		}
251 251
 		return $SQL;
252 252
 	}
@@ -260,29 +260,29 @@  discard block
 block discarded – undo
260 260
      * @return    string
261 261
      * @throws \EE_Error
262 262
      */
263
-	public static function posts_fields_sql_for_orderby( $orderby_params = array() ) {
264
-		$SQL = ', MIN( ' . EEM_Datetime::instance()->table() . '.DTT_EVT_start ) as event_start_date ' ;
265
-		foreach( (array)$orderby_params as $orderby ) {
266
-			switch ( $orderby ) {
263
+	public static function posts_fields_sql_for_orderby($orderby_params = array()) {
264
+		$SQL = ', MIN( '.EEM_Datetime::instance()->table().'.DTT_EVT_start ) as event_start_date ';
265
+		foreach ((array) $orderby_params as $orderby) {
266
+			switch ($orderby) {
267 267
 
268 268
 				case 'ticket_start' :
269
-					$SQL .= ', ' . EEM_Ticket::instance()->table() . '.TKT_start_date' ;
269
+					$SQL .= ', '.EEM_Ticket::instance()->table().'.TKT_start_date';
270 270
 					break;
271 271
 
272 272
 				case 'ticket_end' :
273
-					$SQL .= ', ' . EEM_Ticket::instance()->table() . '.TKT_end_date' ;
273
+					$SQL .= ', '.EEM_Ticket::instance()->table().'.TKT_end_date';
274 274
 					break;
275 275
 
276 276
 				case 'venue_title' :
277
-					$SQL .= ', Venue.post_title AS venue_title' ;
277
+					$SQL .= ', Venue.post_title AS venue_title';
278 278
 					break;
279 279
 
280 280
 				case 'city' :
281
-					$SQL .= ', ' . EEM_Venue::instance()->second_table() . '.VNU_city' ;
281
+					$SQL .= ', '.EEM_Venue::instance()->second_table().'.VNU_city';
282 282
 					break;
283 283
 
284 284
 				case 'state' :
285
-					$SQL .= ', ' . EEM_State::instance()->table() . '.STA_name' ;
285
+					$SQL .= ', '.EEM_State::instance()->table().'.STA_name';
286 286
 					break;
287 287
 
288 288
 			}
@@ -300,12 +300,12 @@  discard block
 block discarded – undo
300 300
      * @return    string
301 301
      * @throws \EE_Error
302 302
      */
303
-	public static function posts_join( $SQL = '', WP_Query $wp_query ) {
304
-		if ( EEH_Event_Query::apply_query_filters( $wp_query ) ) {
303
+	public static function posts_join($SQL = '', WP_Query $wp_query) {
304
+		if (EEH_Event_Query::apply_query_filters($wp_query)) {
305 305
 			// Category
306
-			$SQL = EEH_Event_Query::posts_join_sql_for_show_expired( $SQL, EEH_Event_Query::$_event_query_show_expired );
307
-			$SQL = EEH_Event_Query::posts_join_sql_for_terms( $SQL, EEH_Event_Query::$_event_query_category );
308
-			$SQL = EEH_Event_Query::posts_join_for_orderby( $SQL, EEH_Event_Query::$_event_query_orderby );
306
+			$SQL = EEH_Event_Query::posts_join_sql_for_show_expired($SQL, EEH_Event_Query::$_event_query_show_expired);
307
+			$SQL = EEH_Event_Query::posts_join_sql_for_terms($SQL, EEH_Event_Query::$_event_query_category);
308
+			$SQL = EEH_Event_Query::posts_join_for_orderby($SQL, EEH_Event_Query::$_event_query_orderby);
309 309
 		}
310 310
 		return $SQL;
311 311
 	}
@@ -320,13 +320,13 @@  discard block
 block discarded – undo
320 320
      * @return string
321 321
      * @throws \EE_Error
322 322
      */
323
-	public static function posts_join_sql_for_show_expired( $SQL = '', $show_expired = FALSE ) {
324
-		if ( ! $show_expired ) {
325
-			$join = EEM_Event::instance()->table() . '.ID = ';
326
-			$join .= EEM_Datetime::instance()->table() . '.' . EEM_Event::instance()->primary_key_name();
323
+	public static function posts_join_sql_for_show_expired($SQL = '', $show_expired = FALSE) {
324
+		if ( ! $show_expired) {
325
+			$join = EEM_Event::instance()->table().'.ID = ';
326
+			$join .= EEM_Datetime::instance()->table().'.'.EEM_Event::instance()->primary_key_name();
327 327
 			// don't add if this is already in the SQL
328
-			if ( strpos( $SQL, $join ) === FALSE ) {
329
-				$SQL .= ' INNER JOIN ' . EEM_Datetime::instance()->table() . ' ON ( ' . $join . ' ) ';
328
+			if (strpos($SQL, $join) === FALSE) {
329
+				$SQL .= ' INNER JOIN '.EEM_Datetime::instance()->table().' ON ( '.$join.' ) ';
330 330
 			}
331 331
 		}
332 332
 		return $SQL;
@@ -341,8 +341,8 @@  discard block
 block discarded – undo
341 341
 	 * @param 	string $join_terms pass TRUE or term string, doesn't really matter since this value doesn't really get used for anything yet
342 342
 	 * @return 	string
343 343
 	 */
344
-	public static function posts_join_sql_for_terms( $SQL = '', $join_terms = '' ) {
345
-		if ( ! empty( $join_terms ) ) {
344
+	public static function posts_join_sql_for_terms($SQL = '', $join_terms = '') {
345
+		if ( ! empty($join_terms)) {
346 346
 			global $wpdb;
347 347
 			$SQL .= " LEFT JOIN $wpdb->term_relationships ON ($wpdb->posts.ID = $wpdb->term_relationships.object_id)";
348 348
 			$SQL .= " LEFT JOIN $wpdb->term_taxonomy ON ($wpdb->term_relationships.term_taxonomy_id = $wpdb->term_taxonomy.term_taxonomy_id)";
@@ -362,33 +362,33 @@  discard block
 block discarded – undo
362 362
      * @return    string
363 363
      * @throws \EE_Error
364 364
      */
365
-	public static function posts_join_for_orderby( $SQL = '', $orderby_params = array() ) {
366
-		foreach ( (array)$orderby_params as $orderby ) {
367
-			switch ( $orderby ) {
365
+	public static function posts_join_for_orderby($SQL = '', $orderby_params = array()) {
366
+		foreach ((array) $orderby_params as $orderby) {
367
+			switch ($orderby) {
368 368
 				case 'ticket_start' :
369 369
 				case 'ticket_end' :
370 370
 					$SQL .= EEH_Event_Query::_posts_join_for_datetime(
371 371
 					    $SQL,
372
-                        EEM_Datetime_Ticket::instance()->table() . '.' . EEM_Datetime::instance()->primary_key_name()
372
+                        EEM_Datetime_Ticket::instance()->table().'.'.EEM_Datetime::instance()->primary_key_name()
373 373
                     );
374
-					$SQL .= ' LEFT JOIN ' . EEM_Ticket::instance()->table();
374
+					$SQL .= ' LEFT JOIN '.EEM_Ticket::instance()->table();
375 375
 					$SQL .= ' ON (';
376
-					$SQL .= EEM_Datetime_Ticket::instance()->table() . '.' . EEM_Ticket::instance()->primary_key_name();
376
+					$SQL .= EEM_Datetime_Ticket::instance()->table().'.'.EEM_Ticket::instance()->primary_key_name();
377 377
 					$SQL .= ' = ';
378
-					$SQL .= EEM_Ticket::instance()->table() . '.' . EEM_Ticket::instance()->primary_key_name();
379
-					$SQL .=  ' )';
378
+					$SQL .= EEM_Ticket::instance()->table().'.'.EEM_Ticket::instance()->primary_key_name();
379
+					$SQL .= ' )';
380 380
 					break;
381 381
 				case 'venue_title' :
382 382
 				case 'city' :
383
-					$SQL .= EEH_Event_Query::_posts_join_for_event_venue( $SQL );
383
+					$SQL .= EEH_Event_Query::_posts_join_for_event_venue($SQL);
384 384
 					break;
385 385
 				case 'state' :
386
-					$SQL .= EEH_Event_Query::_posts_join_for_event_venue( $SQL );
387
-					$SQL .= EEH_Event_Query::_posts_join_for_venue_state( $SQL );
386
+					$SQL .= EEH_Event_Query::_posts_join_for_event_venue($SQL);
387
+					$SQL .= EEH_Event_Query::_posts_join_for_venue_state($SQL);
388 388
 					break;
389 389
 				case 'start_date' :
390 390
 				default :
391
-					$SQL .= EEH_Event_Query::_posts_join_for_datetime( $SQL, EEM_Event::instance()->table() . '.ID' );
391
+					$SQL .= EEH_Event_Query::_posts_join_for_datetime($SQL, EEM_Event::instance()->table().'.ID');
392 392
 					break;
393 393
 
394 394
 			}
@@ -406,11 +406,11 @@  discard block
 block discarded – undo
406 406
      * @return string
407 407
      * @throws \EE_Error
408 408
      */
409
-	protected static function _posts_join_for_datetime( $SQL = '', $join = '' ) {
410
-		if ( ! empty( $join )) {
411
-			$join .= ' = ' . EEM_Datetime::instance()->table() . '.' . EEM_Event::instance()->primary_key_name();
412
-			if ( strpos( $SQL, $join ) === FALSE ) {
413
-				return ' INNER JOIN ' . EEM_Datetime::instance()->table() . ' ON ( ' . $join . ' )';
409
+	protected static function _posts_join_for_datetime($SQL = '', $join = '') {
410
+		if ( ! empty($join)) {
411
+			$join .= ' = '.EEM_Datetime::instance()->table().'.'.EEM_Event::instance()->primary_key_name();
412
+			if (strpos($SQL, $join) === FALSE) {
413
+				return ' INNER JOIN '.EEM_Datetime::instance()->table().' ON ( '.$join.' )';
414 414
 			}
415 415
 		}
416 416
 		return '';
@@ -425,14 +425,14 @@  discard block
 block discarded – undo
425 425
      * @return string
426 426
      * @throws \EE_Error
427 427
      */
428
-	protected static function _posts_join_for_event_venue( $SQL = '' ) {
428
+	protected static function _posts_join_for_event_venue($SQL = '') {
429 429
 		// Event Venue table name
430 430
 		$event_venue_table = EEM_Event_Venue::instance()->table();
431 431
 		// generate conditions for:  Event <=> Event Venue  JOIN clause
432
-		$event_to_event_venue_join = EEM_Event::instance()->table() . '.ID = ';
433
-		$event_to_event_venue_join .= $event_venue_table . '.' . EEM_Event::instance()->primary_key_name();
432
+		$event_to_event_venue_join = EEM_Event::instance()->table().'.ID = ';
433
+		$event_to_event_venue_join .= $event_venue_table.'.'.EEM_Event::instance()->primary_key_name();
434 434
 		// don't add joins if they have already been added
435
-		if ( strpos( $SQL, $event_to_event_venue_join ) === FALSE ) {
435
+		if (strpos($SQL, $event_to_event_venue_join) === FALSE) {
436 436
 			// Venue table name
437 437
 			$venue_table = EEM_Venue::instance()->table();
438 438
 			// Venue table pk
@@ -445,10 +445,10 @@  discard block
 block discarded – undo
445 445
 			$venue_SQL .= " LEFT JOIN $venue_table as Venue ON ( $event_venue_table.$venue_table_pk = Venue.ID )";
446 446
 			// generate JOIN clause for: Venue <=> Venue Meta
447 447
 			$venue_SQL .= " LEFT JOIN $venue_meta_table ON ( Venue.ID = $venue_meta_table.$venue_table_pk )";
448
-			unset( $event_venue_table, $event_to_event_venue_join, $venue_table, $venue_table_pk, $venue_meta_table );
448
+			unset($event_venue_table, $event_to_event_venue_join, $venue_table, $venue_table_pk, $venue_meta_table);
449 449
 			return $venue_SQL;
450 450
 		}
451
-		unset( $event_venue_table, $event_to_event_venue_join );
451
+		unset($event_venue_table, $event_to_event_venue_join);
452 452
 		return '';
453 453
 	}
454 454
 
@@ -461,7 +461,7 @@  discard block
 block discarded – undo
461 461
      * @return string
462 462
      * @throws \EE_Error
463 463
      */
464
-	protected static function _posts_join_for_venue_state( $SQL = '' ) {
464
+	protected static function _posts_join_for_venue_state($SQL = '') {
465 465
 		// Venue Meta table name
466 466
 		$venue_meta_table = EEM_Venue::instance()->second_table();
467 467
 		// State table name
@@ -469,16 +469,16 @@  discard block
 block discarded – undo
469 469
 		// State table pk
470 470
 		$state_table_pk = EEM_State::instance()->primary_key_name();
471 471
 		// verify vars
472
-		if ( $venue_meta_table && $state_table && $state_table_pk ) {
472
+		if ($venue_meta_table && $state_table && $state_table_pk) {
473 473
 			// like: wp_esp_venue_meta.STA_ID = wp_esp_state.STA_ID
474 474
 			$join = "$venue_meta_table.$state_table_pk = $state_table.$state_table_pk";
475 475
 			// don't add join if it has already been added
476
-			if ( strpos( $SQL, $join ) === FALSE ) {
477
-				unset( $state_table_pk, $venue_meta_table, $venue_table_pk );
476
+			if (strpos($SQL, $join) === FALSE) {
477
+				unset($state_table_pk, $venue_meta_table, $venue_table_pk);
478 478
 				return " LEFT JOIN $state_table ON ( $join )";
479 479
 			}
480 480
 		}
481
-		unset( $join, $state_table, $state_table_pk, $venue_meta_table, $venue_table_pk );
481
+		unset($join, $state_table, $state_table_pk, $venue_meta_table, $venue_table_pk);
482 482
 		return '';
483 483
 	}
484 484
 
@@ -492,14 +492,14 @@  discard block
 block discarded – undo
492 492
      * @return    string
493 493
      * @throws \EE_Error
494 494
      */
495
-	public static function posts_where( $SQL = '', WP_Query $wp_query ) {
496
-		if ( EEH_Event_Query::apply_query_filters( $wp_query ) ) {
495
+	public static function posts_where($SQL = '', WP_Query $wp_query) {
496
+		if (EEH_Event_Query::apply_query_filters($wp_query)) {
497 497
 			// Show Expired ?
498
-			$SQL .= EEH_Event_Query::posts_where_sql_for_show_expired( EEH_Event_Query::$_event_query_show_expired );
498
+			$SQL .= EEH_Event_Query::posts_where_sql_for_show_expired(EEH_Event_Query::$_event_query_show_expired);
499 499
 			// Category
500
-			$SQL .= EEH_Event_Query::posts_where_sql_for_event_category_slug( EEH_Event_Query::$_event_query_category );
500
+			$SQL .= EEH_Event_Query::posts_where_sql_for_event_category_slug(EEH_Event_Query::$_event_query_category);
501 501
 			// Start Date
502
-			$SQL .= EEH_Event_Query::posts_where_sql_for_event_list_month( EEH_Event_Query::$_event_query_month );
502
+			$SQL .= EEH_Event_Query::posts_where_sql_for_event_list_month(EEH_Event_Query::$_event_query_month);
503 503
 		}
504 504
 		return $SQL;
505 505
 	}
@@ -513,9 +513,9 @@  discard block
 block discarded – undo
513 513
      * @return    string
514 514
      * @throws \EE_Error
515 515
      */
516
-	public static function posts_where_sql_for_show_expired( $show_expired = FALSE ) {
516
+	public static function posts_where_sql_for_show_expired($show_expired = FALSE) {
517 517
 		return ! $show_expired
518
-            ? ' AND ' . EEM_Datetime::instance()->table() . '.DTT_EVT_end > \'' . current_time( 'mysql', TRUE ) . '\' '
518
+            ? ' AND '.EEM_Datetime::instance()->table().'.DTT_EVT_end > \''.current_time('mysql', TRUE).'\' '
519 519
             : '';
520 520
 	}
521 521
 
@@ -527,10 +527,10 @@  discard block
 block discarded – undo
527 527
 	 * @param    boolean $event_category_slug
528 528
 	 * @return    string
529 529
 	 */
530
-	public static function posts_where_sql_for_event_category_slug( $event_category_slug = NULL ) {
530
+	public static function posts_where_sql_for_event_category_slug($event_category_slug = NULL) {
531 531
 		global $wpdb;
532 532
 		$event_category_slug = esc_sql($event_category_slug);
533
-		return ! empty( $event_category_slug )
533
+		return ! empty($event_category_slug)
534 534
             ? " AND {$wpdb->terms}.slug = '{$event_category_slug}' "
535 535
             : '';
536 536
 	}
@@ -544,16 +544,16 @@  discard block
 block discarded – undo
544 544
      * @return    string
545 545
      * @throws \EE_Error
546 546
      */
547
-	public static function posts_where_sql_for_event_list_month( $month = NULL ) {
547
+	public static function posts_where_sql_for_event_list_month($month = NULL) {
548 548
 		$SQL = '';
549
-		if ( ! empty( $month ) ) {
549
+		if ( ! empty($month)) {
550 550
 			$datetime_table = EEM_Datetime::instance()->table();
551 551
 			// event start date is LESS than the end of the month ( so nothing that doesn't start until next month )
552 552
 			$SQL = " AND {$datetime_table}.DTT_EVT_start <= '";
553
-			$SQL .= date( 'Y-m-t 23:59:59', \EEH_DTT_Helper::first_of_month_timestamp($month)) . "'";
553
+			$SQL .= date('Y-m-t 23:59:59', \EEH_DTT_Helper::first_of_month_timestamp($month))."'";
554 554
 			// event end date is GREATER than the start of the month ( so nothing that ended before this month )
555 555
 			$SQL .= " AND {$datetime_table}.DTT_EVT_end >= '";
556
-			$SQL .= date( 'Y-m-01 0:0:00', \EEH_DTT_Helper::first_of_month_timestamp($month)) . "' ";
556
+			$SQL .= date('Y-m-01 0:0:00', \EEH_DTT_Helper::first_of_month_timestamp($month))."' ";
557 557
 		}
558 558
 		return $SQL;
559 559
 	}
@@ -568,8 +568,8 @@  discard block
 block discarded – undo
568 568
      * @return    string
569 569
      * @throws \EE_Error
570 570
      */
571
-	public static function posts_orderby( $SQL = '', WP_Query $wp_query ) {
572
-		if ( EEH_Event_Query::apply_query_filters( $wp_query ) ) {
571
+	public static function posts_orderby($SQL = '', WP_Query $wp_query) {
572
+		if (EEH_Event_Query::apply_query_filters($wp_query)) {
573 573
 			$SQL = EEH_Event_Query::posts_orderby_sql(
574 574
 			    EEH_Event_Query::$_event_query_orderby,
575 575
                 EEH_Event_Query::$_event_query_sort
@@ -602,7 +602,7 @@  discard block
 block discarded – undo
602 602
      * @return string
603 603
      * @throws \EE_Error
604 604
      */
605
-	public static function posts_orderby_sql( $orderby_params = array(), $sort = 'ASC' ) {
605
+	public static function posts_orderby_sql($orderby_params = array(), $sort = 'ASC') {
606 606
 		global $wpdb;
607 607
 		$SQL = '';
608 608
 		$counter = 0;
@@ -610,58 +610,58 @@  discard block
 block discarded – undo
610 610
             ? strtoupper($sort)
611 611
             : 'ASC';
612 612
 		//make sure 'orderby' is set in query params
613
-		if ( ! isset( self::$_query_params['orderby'] )) {
613
+		if ( ! isset(self::$_query_params['orderby'])) {
614 614
 			self::$_query_params['orderby'] = array();
615 615
 		}
616 616
 		// loop thru $orderby_params (type cast as array)
617
-		foreach ( (array)$orderby_params as $orderby ) {
617
+		foreach ((array) $orderby_params as $orderby) {
618 618
 			// check if we have already added this param
619
-			if ( isset( self::$_query_params['orderby'][ $orderby ] )) {
619
+			if (isset(self::$_query_params['orderby'][$orderby])) {
620 620
 				// if so then remove from the $orderby_params so that the count() method below is accurate
621
-				unset( $orderby_params[ $orderby ] );
621
+				unset($orderby_params[$orderby]);
622 622
 				// then bump ahead to the next param
623 623
 				continue;
624 624
 			}
625 625
 			// this will ad a comma depending on whether this is the first or last param
626
-			$glue = $counter === 0 || $counter === count( $orderby_params ) ? ' ' : ', ';
626
+			$glue = $counter === 0 || $counter === count($orderby_params) ? ' ' : ', ';
627 627
 			// ok what's we dealing with?
628
-			switch ( $orderby ) {
628
+			switch ($orderby) {
629 629
 				case 'id' :
630 630
 				case 'ID' :
631
-					$SQL .= $glue . $wpdb->posts . '.ID ' . $sort;
631
+					$SQL .= $glue.$wpdb->posts.'.ID '.$sort;
632 632
 					break;
633 633
 				case 'end_date' :
634
-					$SQL .= $glue . EEM_Datetime::instance()->table() . '.DTT_EVT_end ' . $sort;
634
+					$SQL .= $glue.EEM_Datetime::instance()->table().'.DTT_EVT_end '.$sort;
635 635
 					break;
636 636
 				case 'event_name' :
637
-					$SQL .= $glue . $wpdb->posts . '.post_title ' . $sort;
637
+					$SQL .= $glue.$wpdb->posts.'.post_title '.$sort;
638 638
 					break;
639 639
 				case 'category_slug' :
640
-					$SQL .= $glue . $wpdb->terms . '.slug ' . $sort;
640
+					$SQL .= $glue.$wpdb->terms.'.slug '.$sort;
641 641
 					break;
642 642
 				case 'ticket_start' :
643
-					$SQL .= $glue . EEM_Ticket::instance()->table() . '.TKT_start_date ' . $sort;
643
+					$SQL .= $glue.EEM_Ticket::instance()->table().'.TKT_start_date '.$sort;
644 644
 					break;
645 645
 				case 'ticket_end' :
646
-					$SQL .= $glue . EEM_Ticket::instance()->table() . '.TKT_end_date ' . $sort;
646
+					$SQL .= $glue.EEM_Ticket::instance()->table().'.TKT_end_date '.$sort;
647 647
 					break;
648 648
 				case 'venue_title' :
649
-					$SQL .= $glue . 'venue_title ' . $sort;
649
+					$SQL .= $glue.'venue_title '.$sort;
650 650
 					break;
651 651
 				case 'city' :
652
-					$SQL .= $glue . EEM_Venue::instance()->second_table() . '.VNU_city ' . $sort;
652
+					$SQL .= $glue.EEM_Venue::instance()->second_table().'.VNU_city '.$sort;
653 653
 					break;
654 654
 				case 'state' :
655
-					$SQL .= $glue . EEM_State::instance()->table() . '.STA_name ' . $sort;
655
+					$SQL .= $glue.EEM_State::instance()->table().'.STA_name '.$sort;
656 656
 					break;
657 657
 				case 'start_date' :
658 658
 				default :
659
-					$SQL .= $glue . ' event_start_date ' . $sort;
659
+					$SQL .= $glue.' event_start_date '.$sort;
660 660
 					break;
661 661
 			}
662 662
 			// add to array of orderby params that have been added
663
-			self::$_query_params['orderby'][ $orderby ] = TRUE;
664
-			$counter ++;
663
+			self::$_query_params['orderby'][$orderby] = TRUE;
664
+			$counter++;
665 665
 		}
666 666
 		return $SQL;
667 667
 	}
Please login to merge, or discard this patch.
form_sections/strategies/display/EE_Select_Display_Strategy.strategy.php 2 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -81,7 +81,7 @@
 block discarded – undo
81 81
 	/**
82 82
 	 * Checks if that value is the one selected
83 83
 	 * @param string|int $value unnormalized value option (string)
84
-	 * @return string
84
+	 * @return boolean
85 85
 	 */
86 86
 	protected function _check_if_option_selected( $value ){
87 87
 		return $this->_input->raw_value() === $value ? TRUE : FALSE;
Please login to merge, or discard this patch.
Spacing   +27 added lines, -27 removed lines patch added patch discarded remove patch
@@ -11,49 +11,49 @@  discard block
 block discarded – undo
11 11
  * @since 				$VID:$
12 12
  *
13 13
  */
14
-class EE_Select_Display_Strategy extends EE_Display_Strategy_Base{
14
+class EE_Select_Display_Strategy extends EE_Display_Strategy_Base {
15 15
 
16 16
 	/**
17 17
 	 *
18 18
 	 * @throws EE_Error
19 19
 	 * @return string of html to display the field
20 20
 	 */
21
-	function display(){
22
-		if( ! $this->_input instanceof EE_Form_Input_With_Options_Base){
23
-			throw new EE_Error( sprintf( __( 'Cannot use Select Display Strategy with an input that doesn\'t have options', 'event_espresso' )));
21
+	function display() {
22
+		if ( ! $this->_input instanceof EE_Form_Input_With_Options_Base) {
23
+			throw new EE_Error(sprintf(__('Cannot use Select Display Strategy with an input that doesn\'t have options', 'event_espresso')));
24 24
 		}
25 25
 
26
-		$html = EEH_HTML::nl( 0, 'select' );
26
+		$html = EEH_HTML::nl(0, 'select');
27 27
 		$html .= '<select';
28
-		$html .= ' id="' . $this->_input->html_id() . '"';
29
-		$html .= ' name="' . $this->_input->html_name() . '"';
30
-		$class = $this->_input->required() ? $this->_input->required_css_class() . ' ' . $this->_input->html_class() : $this->_input->html_class();
31
-		$html .= ' class="' . $class . '"';
28
+		$html .= ' id="'.$this->_input->html_id().'"';
29
+		$html .= ' name="'.$this->_input->html_name().'"';
30
+		$class = $this->_input->required() ? $this->_input->required_css_class().' '.$this->_input->html_class() : $this->_input->html_class();
31
+		$html .= ' class="'.$class.'"';
32 32
 		// add html5 required
33 33
 		$html .= $this->_input->required() ? ' required' : '';
34
-		$html .= ' style="' . $this->_input->html_style() . '"';
35
-		$html .= ' ' . $this->_input->other_html_attributes();
34
+		$html .= ' style="'.$this->_input->html_style().'"';
35
+		$html .= ' '.$this->_input->other_html_attributes();
36 36
 		$html .= '>';
37 37
 
38
-		if ( EEH_Array::is_multi_dimensional_array( $this->_input->options() )) {
39
-			EEH_HTML::indent( 1, 'optgroup' );
40
-			foreach( $this->_input->options() as $opt_group_label => $opt_group ){
38
+		if (EEH_Array::is_multi_dimensional_array($this->_input->options())) {
39
+			EEH_HTML::indent(1, 'optgroup');
40
+			foreach ($this->_input->options() as $opt_group_label => $opt_group) {
41 41
 			    if ( ! empty($opt_group_label)) {
42
-                    $html .= EEH_HTML::nl(0, 'optgroup') . '<optgroup label="' . esc_attr($opt_group_label) . '">';
42
+                    $html .= EEH_HTML::nl(0, 'optgroup').'<optgroup label="'.esc_attr($opt_group_label).'">';
43 43
                 }
44
-				EEH_HTML::indent( 1, 'option' );
45
-				$html .= $this->_display_options( $opt_group );
44
+				EEH_HTML::indent(1, 'option');
45
+				$html .= $this->_display_options($opt_group);
46 46
 				EEH_HTML::indent( -1, 'option' );
47 47
                 if ( ! empty($opt_group_label)) {
48
-                    $html .= EEH_HTML::nl( 0, 'optgroup' ) . '</optgroup>';
48
+                    $html .= EEH_HTML::nl(0, 'optgroup').'</optgroup>';
49 49
 			    }
50 50
 			}
51 51
 			EEH_HTML::indent( -1, 'optgroup' );
52 52
 		} else {
53
-			$html.=$this->_display_options( $this->_input->options() );
53
+			$html .= $this->_display_options($this->_input->options());
54 54
 		}
55 55
 
56
-		$html.= EEH_HTML::nl( 0, 'select' ) . '</select>';
56
+		$html .= EEH_HTML::nl(0, 'select').'</select>';
57 57
 		return $html;
58 58
 	}
59 59
 
@@ -64,13 +64,13 @@  discard block
 block discarded – undo
64 64
 	 * @param array $options
65 65
 	 * @return string
66 66
 	 */
67
-	protected function _display_options($options){
67
+	protected function _display_options($options) {
68 68
 		$html = '';
69
-		EEH_HTML::indent( 1, 'option' );
70
-		foreach( $options as $value => $display_text ){
71
-			$unnormalized_value = $this->_input->get_normalization_strategy()->unnormalize_one( $value );
72
-			$selected = $this->_check_if_option_selected( $unnormalized_value ) ? ' selected="selected"' : '';
73
-			$html.= EEH_HTML::nl( 0, 'option' ) . '<option value="' . esc_attr( $unnormalized_value ) . '"' . $selected . '>' . $display_text . '</option>';
69
+		EEH_HTML::indent(1, 'option');
70
+		foreach ($options as $value => $display_text) {
71
+			$unnormalized_value = $this->_input->get_normalization_strategy()->unnormalize_one($value);
72
+			$selected = $this->_check_if_option_selected($unnormalized_value) ? ' selected="selected"' : '';
73
+			$html .= EEH_HTML::nl(0, 'option').'<option value="'.esc_attr($unnormalized_value).'"'.$selected.'>'.$display_text.'</option>';
74 74
 		}
75 75
 		EEH_HTML::indent( -1, 'option' );
76 76
 		return $html;
@@ -83,7 +83,7 @@  discard block
 block discarded – undo
83 83
 	 * @param string|int $value unnormalized value option (string)
84 84
 	 * @return string
85 85
 	 */
86
-	protected function _check_if_option_selected( $value ){
86
+	protected function _check_if_option_selected($value) {
87 87
 		return $this->_input->raw_value() === $value ? TRUE : FALSE;
88 88
 	}
89 89
 
Please login to merge, or discard this patch.