@@ -17,158 +17,158 @@ |
||
17 | 17 | { |
18 | 18 | |
19 | 19 | |
20 | - /** |
|
21 | - * @var \EE_Ticket $ticket |
|
22 | - */ |
|
23 | - protected $ticket; |
|
24 | - |
|
25 | - /** |
|
26 | - * @var \EE_Ticket_Selector_Config $template_settings |
|
27 | - */ |
|
28 | - protected $template_settings; |
|
29 | - |
|
30 | - /** |
|
31 | - * @var string $date_format |
|
32 | - */ |
|
33 | - protected $date_format; |
|
34 | - |
|
35 | - /** |
|
36 | - * @var string $time_format |
|
37 | - */ |
|
38 | - protected $time_format; |
|
39 | - |
|
40 | - /** |
|
41 | - * @var boolean $event_is_expired |
|
42 | - */ |
|
43 | - protected $event_is_expired; |
|
44 | - |
|
45 | - |
|
46 | - |
|
47 | - /** |
|
48 | - * TicketDetails constructor. |
|
49 | - * |
|
50 | - * @param \EE_Ticket $ticket |
|
51 | - * @param \EE_Ticket_Selector_Config $template_settings |
|
52 | - * @param array $template_args |
|
53 | - */ |
|
54 | - public function __construct( |
|
55 | - \EE_Ticket $ticket, |
|
56 | - \EE_Ticket_Selector_Config $template_settings, |
|
57 | - array $template_args |
|
58 | - ) |
|
59 | - { |
|
60 | - $this->ticket = $ticket; |
|
61 | - $this->template_settings = $template_settings; |
|
62 | - $this->date_format = $template_args['date_format']; |
|
63 | - $this->time_format = $template_args['time_format']; |
|
64 | - $this->event_is_expired = $template_args['event_is_expired']; |
|
65 | - } |
|
66 | - |
|
67 | - |
|
68 | - |
|
69 | - /** |
|
70 | - * @return bool |
|
71 | - */ |
|
72 | - public function showTicketDetails() |
|
73 | - { |
|
74 | - return $this->template_settings->show_ticket_details; |
|
75 | - } |
|
76 | - |
|
77 | - |
|
78 | - |
|
79 | - /** |
|
80 | - * @return string |
|
81 | - */ |
|
82 | - public function getShowHideLinks() |
|
83 | - { |
|
84 | - if ( ! $this->showTicketDetails()) { |
|
85 | - return ''; |
|
86 | - } |
|
87 | - return \EEH_HTML::link( |
|
88 | - '', |
|
89 | - sprintf(__('show%1$sdetails%1$s+', 'event_espresso'), ' '), |
|
90 | - esc_attr( |
|
91 | - apply_filters( |
|
92 | - 'FHEE__ticket_selector_chart_template__show_ticket_details_link_title', |
|
93 | - __('click to show additional ticket details', 'event_espresso') |
|
94 | - ) |
|
95 | - ), |
|
96 | - "display-{$this->cssId()}", |
|
97 | - 'display-tckt-slctr-tkt-details display-the-hidden lt-grey-text smaller-text hide-if-no-js', |
|
98 | - '', |
|
99 | - 'rel="' . $this->cssId() . '"' |
|
100 | - ) . \EEH_HTML::link( |
|
101 | - '', |
|
102 | - sprintf(__('hide%1$sdetails%1$s-', 'event_espresso'), ' '), |
|
103 | - esc_attr( |
|
104 | - apply_filters( |
|
105 | - 'FHEE__ticket_selector_chart_template__hide_ticket_details_link_title', |
|
106 | - __('click to hide additional ticket details', 'event_espresso') |
|
107 | - ) |
|
108 | - ), |
|
109 | - "hide-{$this->cssId()}", |
|
110 | - 'hide-tckt-slctr-tkt-details hide-the-displayed lt-grey-text smaller-text hide-if-no-js', |
|
111 | - 'display:none;', |
|
112 | - 'rel="' . $this->cssId() . '"' |
|
113 | - ); |
|
114 | - } |
|
115 | - |
|
116 | - |
|
117 | - |
|
118 | - /** |
|
119 | - * @return string |
|
120 | - */ |
|
121 | - public function cssId() |
|
122 | - { |
|
123 | - return apply_filters( |
|
124 | - 'FHEE__ticket_selector_chart_template__ticket_details_css_id', |
|
125 | - "tckt-slctr-tkt-details-{$this->ticket->get_event_ID()}-{$this->ticket->ID()}" |
|
126 | - ); |
|
127 | - } |
|
128 | - |
|
129 | - |
|
130 | - |
|
131 | - /** |
|
132 | - * @param float $ticket_price |
|
133 | - * @param int $remaining |
|
134 | - * @param int $cols |
|
135 | - * @return string |
|
136 | - */ |
|
137 | - public function display( |
|
138 | - $ticket_price = 0.00, |
|
139 | - $remaining, |
|
140 | - $cols = 2 |
|
141 | - ) { |
|
142 | - $template_args = array(); |
|
143 | - $template_args['ticket'] = $this->ticket; |
|
144 | - $template_args['ticket_price'] = $ticket_price; |
|
145 | - $template_args['remaining'] = $remaining; |
|
146 | - $template_args['cols'] = $cols; |
|
147 | - $template_args['show_ticket_details'] = $this->template_settings->show_ticket_details; |
|
148 | - $template_args['show_ticket_sale_columns'] = $this->template_settings->show_ticket_sale_columns; |
|
149 | - $template_args['ticket_details_row_class'] = espresso_get_object_css_class($this->ticket, '', 'details'); |
|
150 | - $template_args['ticket_details_css_id'] = $this->cssId(); |
|
151 | - $template_args['display_ticket_price'] = $ticket_price !== 0 && apply_filters( |
|
152 | - 'FHEE__ticket_selector_chart_template__display_ticket_price_details', |
|
153 | - true |
|
154 | - ); |
|
155 | - $template_args['price_breakdown_heading'] = apply_filters( |
|
156 | - 'FHEE__ticket_selector_chart_template__ticket_details_price_breakdown_heading', |
|
157 | - esc_html__('Price', 'event_espresso') |
|
158 | - ); |
|
159 | - $template_args['date_format'] = $this->date_format; |
|
160 | - $template_args['time_format'] = $this->time_format; |
|
161 | - $template_args['event_is_expired'] = $this->event_is_expired; |
|
162 | - |
|
163 | - return \EEH_Template::locate_template( |
|
164 | - apply_filters( |
|
165 | - 'FHEE__EventEspresso_modules_ticket_selector_TicketDetails__display__template_path', |
|
166 | - TICKET_SELECTOR_TEMPLATES_PATH . 'ticket_details.template.php', |
|
167 | - $this->ticket |
|
168 | - ), |
|
169 | - $template_args |
|
170 | - ); |
|
171 | - } |
|
20 | + /** |
|
21 | + * @var \EE_Ticket $ticket |
|
22 | + */ |
|
23 | + protected $ticket; |
|
24 | + |
|
25 | + /** |
|
26 | + * @var \EE_Ticket_Selector_Config $template_settings |
|
27 | + */ |
|
28 | + protected $template_settings; |
|
29 | + |
|
30 | + /** |
|
31 | + * @var string $date_format |
|
32 | + */ |
|
33 | + protected $date_format; |
|
34 | + |
|
35 | + /** |
|
36 | + * @var string $time_format |
|
37 | + */ |
|
38 | + protected $time_format; |
|
39 | + |
|
40 | + /** |
|
41 | + * @var boolean $event_is_expired |
|
42 | + */ |
|
43 | + protected $event_is_expired; |
|
44 | + |
|
45 | + |
|
46 | + |
|
47 | + /** |
|
48 | + * TicketDetails constructor. |
|
49 | + * |
|
50 | + * @param \EE_Ticket $ticket |
|
51 | + * @param \EE_Ticket_Selector_Config $template_settings |
|
52 | + * @param array $template_args |
|
53 | + */ |
|
54 | + public function __construct( |
|
55 | + \EE_Ticket $ticket, |
|
56 | + \EE_Ticket_Selector_Config $template_settings, |
|
57 | + array $template_args |
|
58 | + ) |
|
59 | + { |
|
60 | + $this->ticket = $ticket; |
|
61 | + $this->template_settings = $template_settings; |
|
62 | + $this->date_format = $template_args['date_format']; |
|
63 | + $this->time_format = $template_args['time_format']; |
|
64 | + $this->event_is_expired = $template_args['event_is_expired']; |
|
65 | + } |
|
66 | + |
|
67 | + |
|
68 | + |
|
69 | + /** |
|
70 | + * @return bool |
|
71 | + */ |
|
72 | + public function showTicketDetails() |
|
73 | + { |
|
74 | + return $this->template_settings->show_ticket_details; |
|
75 | + } |
|
76 | + |
|
77 | + |
|
78 | + |
|
79 | + /** |
|
80 | + * @return string |
|
81 | + */ |
|
82 | + public function getShowHideLinks() |
|
83 | + { |
|
84 | + if ( ! $this->showTicketDetails()) { |
|
85 | + return ''; |
|
86 | + } |
|
87 | + return \EEH_HTML::link( |
|
88 | + '', |
|
89 | + sprintf(__('show%1$sdetails%1$s+', 'event_espresso'), ' '), |
|
90 | + esc_attr( |
|
91 | + apply_filters( |
|
92 | + 'FHEE__ticket_selector_chart_template__show_ticket_details_link_title', |
|
93 | + __('click to show additional ticket details', 'event_espresso') |
|
94 | + ) |
|
95 | + ), |
|
96 | + "display-{$this->cssId()}", |
|
97 | + 'display-tckt-slctr-tkt-details display-the-hidden lt-grey-text smaller-text hide-if-no-js', |
|
98 | + '', |
|
99 | + 'rel="' . $this->cssId() . '"' |
|
100 | + ) . \EEH_HTML::link( |
|
101 | + '', |
|
102 | + sprintf(__('hide%1$sdetails%1$s-', 'event_espresso'), ' '), |
|
103 | + esc_attr( |
|
104 | + apply_filters( |
|
105 | + 'FHEE__ticket_selector_chart_template__hide_ticket_details_link_title', |
|
106 | + __('click to hide additional ticket details', 'event_espresso') |
|
107 | + ) |
|
108 | + ), |
|
109 | + "hide-{$this->cssId()}", |
|
110 | + 'hide-tckt-slctr-tkt-details hide-the-displayed lt-grey-text smaller-text hide-if-no-js', |
|
111 | + 'display:none;', |
|
112 | + 'rel="' . $this->cssId() . '"' |
|
113 | + ); |
|
114 | + } |
|
115 | + |
|
116 | + |
|
117 | + |
|
118 | + /** |
|
119 | + * @return string |
|
120 | + */ |
|
121 | + public function cssId() |
|
122 | + { |
|
123 | + return apply_filters( |
|
124 | + 'FHEE__ticket_selector_chart_template__ticket_details_css_id', |
|
125 | + "tckt-slctr-tkt-details-{$this->ticket->get_event_ID()}-{$this->ticket->ID()}" |
|
126 | + ); |
|
127 | + } |
|
128 | + |
|
129 | + |
|
130 | + |
|
131 | + /** |
|
132 | + * @param float $ticket_price |
|
133 | + * @param int $remaining |
|
134 | + * @param int $cols |
|
135 | + * @return string |
|
136 | + */ |
|
137 | + public function display( |
|
138 | + $ticket_price = 0.00, |
|
139 | + $remaining, |
|
140 | + $cols = 2 |
|
141 | + ) { |
|
142 | + $template_args = array(); |
|
143 | + $template_args['ticket'] = $this->ticket; |
|
144 | + $template_args['ticket_price'] = $ticket_price; |
|
145 | + $template_args['remaining'] = $remaining; |
|
146 | + $template_args['cols'] = $cols; |
|
147 | + $template_args['show_ticket_details'] = $this->template_settings->show_ticket_details; |
|
148 | + $template_args['show_ticket_sale_columns'] = $this->template_settings->show_ticket_sale_columns; |
|
149 | + $template_args['ticket_details_row_class'] = espresso_get_object_css_class($this->ticket, '', 'details'); |
|
150 | + $template_args['ticket_details_css_id'] = $this->cssId(); |
|
151 | + $template_args['display_ticket_price'] = $ticket_price !== 0 && apply_filters( |
|
152 | + 'FHEE__ticket_selector_chart_template__display_ticket_price_details', |
|
153 | + true |
|
154 | + ); |
|
155 | + $template_args['price_breakdown_heading'] = apply_filters( |
|
156 | + 'FHEE__ticket_selector_chart_template__ticket_details_price_breakdown_heading', |
|
157 | + esc_html__('Price', 'event_espresso') |
|
158 | + ); |
|
159 | + $template_args['date_format'] = $this->date_format; |
|
160 | + $template_args['time_format'] = $this->time_format; |
|
161 | + $template_args['event_is_expired'] = $this->event_is_expired; |
|
162 | + |
|
163 | + return \EEH_Template::locate_template( |
|
164 | + apply_filters( |
|
165 | + 'FHEE__EventEspresso_modules_ticket_selector_TicketDetails__display__template_path', |
|
166 | + TICKET_SELECTOR_TEMPLATES_PATH . 'ticket_details.template.php', |
|
167 | + $this->ticket |
|
168 | + ), |
|
169 | + $template_args |
|
170 | + ); |
|
171 | + } |
|
172 | 172 | |
173 | 173 | } |
174 | 174 | // End of file TicketDetails.php |
@@ -96,8 +96,8 @@ discard block |
||
96 | 96 | "display-{$this->cssId()}", |
97 | 97 | 'display-tckt-slctr-tkt-details display-the-hidden lt-grey-text smaller-text hide-if-no-js', |
98 | 98 | '', |
99 | - 'rel="' . $this->cssId() . '"' |
|
100 | - ) . \EEH_HTML::link( |
|
99 | + 'rel="'.$this->cssId().'"' |
|
100 | + ).\EEH_HTML::link( |
|
101 | 101 | '', |
102 | 102 | sprintf(__('hide%1$sdetails%1$s-', 'event_espresso'), ' '), |
103 | 103 | esc_attr( |
@@ -109,7 +109,7 @@ discard block |
||
109 | 109 | "hide-{$this->cssId()}", |
110 | 110 | 'hide-tckt-slctr-tkt-details hide-the-displayed lt-grey-text smaller-text hide-if-no-js', |
111 | 111 | 'display:none;', |
112 | - 'rel="' . $this->cssId() . '"' |
|
112 | + 'rel="'.$this->cssId().'"' |
|
113 | 113 | ); |
114 | 114 | } |
115 | 115 | |
@@ -163,7 +163,7 @@ discard block |
||
163 | 163 | return \EEH_Template::locate_template( |
164 | 164 | apply_filters( |
165 | 165 | 'FHEE__EventEspresso_modules_ticket_selector_TicketDetails__display__template_path', |
166 | - TICKET_SELECTOR_TEMPLATES_PATH . 'ticket_details.template.php', |
|
166 | + TICKET_SELECTOR_TEMPLATES_PATH.'ticket_details.template.php', |
|
167 | 167 | $this->ticket |
168 | 168 | ), |
169 | 169 | $template_args |
@@ -6,14 +6,14 @@ discard block |
||
6 | 6 | <input type="hidden" name="tkt-slctr-ticket-id-<?php echo $EVT_ID; ?>[]" value="<?php echo $TKT_ID; ?>"/> |
7 | 7 | <?php |
8 | 8 | if ( $ticket instanceof EE_Ticket ) { |
9 | - do_action( 'AHEE__ticket_selector_chart__template__before_ticket_selector', $event ); |
|
10 | - $ticket_description = $ticket->description(); |
|
11 | - $ticket_description .= ! empty( $ticket_description ) |
|
12 | - ? '<br />' . $ticket_status_display |
|
13 | - : $ticket_status_display; |
|
14 | - if ( ! strpos( $ticket_description, '<div' ) ) { |
|
15 | - $ticket_description = "<p>{$ticket_description}</p>"; |
|
16 | - } |
|
9 | + do_action( 'AHEE__ticket_selector_chart__template__before_ticket_selector', $event ); |
|
10 | + $ticket_description = $ticket->description(); |
|
11 | + $ticket_description .= ! empty( $ticket_description ) |
|
12 | + ? '<br />' . $ticket_status_display |
|
13 | + : $ticket_status_display; |
|
14 | + if ( ! strpos( $ticket_description, '<div' ) ) { |
|
15 | + $ticket_description = "<p>{$ticket_description}</p>"; |
|
16 | + } |
|
17 | 17 | ?> |
18 | 18 | <div id="no-tkt-slctr-ticket-dv-<?php echo $EVT_ID; ?>" class="no-tkt-slctr-ticket-dv"> |
19 | 19 | <div class="no-tkt-slctr-ticket-content-dv"> |
@@ -23,6 +23,6 @@ discard block |
||
23 | 23 | <?php } ?> |
24 | 24 | </div> |
25 | 25 | <?php |
26 | - do_action( 'AHEE__ticket_selector_chart__template__after_ticket_selector', $EVT_ID, $event ); |
|
26 | + do_action( 'AHEE__ticket_selector_chart__template__after_ticket_selector', $EVT_ID, $event ); |
|
27 | 27 | } |
28 | 28 | ?> |
@@ -5,24 +5,24 @@ |
||
5 | 5 | <input type="hidden" name="tkt-slctr-qty-<?php echo $EVT_ID; ?>[]" value="1"/> |
6 | 6 | <input type="hidden" name="tkt-slctr-ticket-id-<?php echo $EVT_ID; ?>[]" value="<?php echo $TKT_ID; ?>"/> |
7 | 7 | <?php |
8 | -if ( $ticket instanceof EE_Ticket ) { |
|
9 | - do_action( 'AHEE__ticket_selector_chart__template__before_ticket_selector', $event ); |
|
8 | +if ($ticket instanceof EE_Ticket) { |
|
9 | + do_action('AHEE__ticket_selector_chart__template__before_ticket_selector', $event); |
|
10 | 10 | $ticket_description = $ticket->description(); |
11 | - $ticket_description .= ! empty( $ticket_description ) |
|
12 | - ? '<br />' . $ticket_status_display |
|
11 | + $ticket_description .= ! empty($ticket_description) |
|
12 | + ? '<br />'.$ticket_status_display |
|
13 | 13 | : $ticket_status_display; |
14 | - if ( ! strpos( $ticket_description, '<div' ) ) { |
|
14 | + if ( ! strpos($ticket_description, '<div')) { |
|
15 | 15 | $ticket_description = "<p>{$ticket_description}</p>"; |
16 | 16 | } |
17 | 17 | ?> |
18 | 18 | <div id="no-tkt-slctr-ticket-dv-<?php echo $EVT_ID; ?>" class="no-tkt-slctr-ticket-dv"> |
19 | 19 | <div class="no-tkt-slctr-ticket-content-dv"> |
20 | 20 | <h5><?php echo $ticket->name(); ?></h5> |
21 | - <?php if ( ! empty( $ticket_description ) ) { ?> |
|
21 | + <?php if ( ! empty($ticket_description)) { ?> |
|
22 | 22 | <?php echo $ticket_description; ?> |
23 | 23 | <?php } ?> |
24 | 24 | </div> |
25 | 25 | <?php |
26 | - do_action( 'AHEE__ticket_selector_chart__template__after_ticket_selector', $EVT_ID, $event ); |
|
26 | + do_action('AHEE__ticket_selector_chart__template__after_ticket_selector', $EVT_ID, $event); |
|
27 | 27 | } |
28 | 28 | ?> |
@@ -18,46 +18,46 @@ |
||
18 | 18 | class TicketSelectorSimple extends TicketSelector |
19 | 19 | { |
20 | 20 | |
21 | - /** |
|
22 | - * @var \EE_Ticket $ticket |
|
23 | - */ |
|
24 | - protected $ticket; |
|
21 | + /** |
|
22 | + * @var \EE_Ticket $ticket |
|
23 | + */ |
|
24 | + protected $ticket; |
|
25 | 25 | |
26 | 26 | |
27 | 27 | |
28 | - /** |
|
29 | - * TicketSelectorSimple constructor. |
|
30 | - * |
|
31 | - * @param \EE_Event $event |
|
32 | - * @param \EE_Ticket $ticket |
|
33 | - * @param int $max_attendees |
|
34 | - * @param array $template_args |
|
35 | - */ |
|
36 | - public function __construct(\EE_Event $event, \EE_Ticket $ticket, $max_attendees, array $template_args) |
|
37 | - { |
|
38 | - $this->ticket = $ticket; |
|
39 | - parent::__construct($event, array($this->ticket), $max_attendees, $template_args); |
|
40 | - } |
|
28 | + /** |
|
29 | + * TicketSelectorSimple constructor. |
|
30 | + * |
|
31 | + * @param \EE_Event $event |
|
32 | + * @param \EE_Ticket $ticket |
|
33 | + * @param int $max_attendees |
|
34 | + * @param array $template_args |
|
35 | + */ |
|
36 | + public function __construct(\EE_Event $event, \EE_Ticket $ticket, $max_attendees, array $template_args) |
|
37 | + { |
|
38 | + $this->ticket = $ticket; |
|
39 | + parent::__construct($event, array($this->ticket), $max_attendees, $template_args); |
|
40 | + } |
|
41 | 41 | |
42 | 42 | |
43 | 43 | |
44 | - /** |
|
45 | - * sets any and all template args that are required for this Ticket Selector |
|
46 | - * |
|
47 | - * @return void |
|
48 | - */ |
|
49 | - protected function addTemplateArgs() |
|
50 | - { |
|
51 | - unset($this->template_args['tickets']); |
|
52 | - $this->template_args['ticket'] = $this->ticket; |
|
53 | - $ticket_selector_row = new TicketSelectorRowSimple( |
|
54 | - $this->ticket, |
|
55 | - $this->max_attendees, |
|
56 | - $this->template_args['date_format'] |
|
57 | - ); |
|
58 | - $this->template_args['ticket_status_display'] = $ticket_selector_row->getTicketStatusDisplay(); |
|
59 | - $this->template_args['template_path'] = TICKET_SELECTOR_TEMPLATES_PATH . 'simple_ticket_selector.template.php'; |
|
60 | - } |
|
44 | + /** |
|
45 | + * sets any and all template args that are required for this Ticket Selector |
|
46 | + * |
|
47 | + * @return void |
|
48 | + */ |
|
49 | + protected function addTemplateArgs() |
|
50 | + { |
|
51 | + unset($this->template_args['tickets']); |
|
52 | + $this->template_args['ticket'] = $this->ticket; |
|
53 | + $ticket_selector_row = new TicketSelectorRowSimple( |
|
54 | + $this->ticket, |
|
55 | + $this->max_attendees, |
|
56 | + $this->template_args['date_format'] |
|
57 | + ); |
|
58 | + $this->template_args['ticket_status_display'] = $ticket_selector_row->getTicketStatusDisplay(); |
|
59 | + $this->template_args['template_path'] = TICKET_SELECTOR_TEMPLATES_PATH . 'simple_ticket_selector.template.php'; |
|
60 | + } |
|
61 | 61 | |
62 | 62 | |
63 | 63 | } |
@@ -56,7 +56,7 @@ |
||
56 | 56 | $this->template_args['date_format'] |
57 | 57 | ); |
58 | 58 | $this->template_args['ticket_status_display'] = $ticket_selector_row->getTicketStatusDisplay(); |
59 | - $this->template_args['template_path'] = TICKET_SELECTOR_TEMPLATES_PATH . 'simple_ticket_selector.template.php'; |
|
59 | + $this->template_args['template_path'] = TICKET_SELECTOR_TEMPLATES_PATH.'simple_ticket_selector.template.php'; |
|
60 | 60 | } |
61 | 61 | |
62 | 62 |
@@ -16,90 +16,90 @@ |
||
16 | 16 | abstract class TicketSelector |
17 | 17 | { |
18 | 18 | |
19 | - /** |
|
20 | - * @var \EE_Event $event |
|
21 | - */ |
|
22 | - protected $event; |
|
23 | - |
|
24 | - /** |
|
25 | - * @var \EE_Ticket[] $tickets |
|
26 | - */ |
|
27 | - protected $tickets; |
|
28 | - |
|
29 | - /** |
|
30 | - * @var int max_attendees |
|
31 | - */ |
|
32 | - protected $max_attendees; |
|
33 | - |
|
34 | - /** |
|
35 | - * @var array $template_args |
|
36 | - */ |
|
37 | - protected $template_args; |
|
38 | - |
|
39 | - |
|
40 | - |
|
41 | - /** |
|
42 | - * TicketSelectorSimple constructor. |
|
43 | - * |
|
44 | - * @param \EE_Event $event |
|
45 | - * @param \EE_Ticket[] $tickets |
|
46 | - * @param int $max_attendees |
|
47 | - * @param array $template_args |
|
48 | - */ |
|
49 | - public function __construct(\EE_Event $event, array $tickets, $max_attendees, array $template_args) |
|
50 | - { |
|
51 | - $this->event = $event; |
|
52 | - $this->tickets = $tickets; |
|
53 | - $this->max_attendees = $max_attendees; |
|
54 | - $this->template_args = $template_args; |
|
55 | - $this->addTemplateArgs(); |
|
56 | - } |
|
57 | - |
|
58 | - |
|
59 | - |
|
60 | - /** |
|
61 | - * sets any and all template args that are required for this Ticket Selector |
|
62 | - * |
|
63 | - * @return void |
|
64 | - */ |
|
65 | - abstract protected function addTemplateArgs(); |
|
66 | - |
|
67 | - |
|
68 | - |
|
69 | - /** |
|
70 | - * loadTicketSelectorTemplate |
|
71 | - * |
|
72 | - * @return string |
|
73 | - */ |
|
74 | - protected function loadTicketSelectorTemplate() |
|
75 | - { |
|
76 | - try { |
|
77 | - return \EEH_Template::locate_template( |
|
78 | - apply_filters( |
|
79 | - 'FHEE__EE_Ticket_Selector__display_ticket_selector__template_path', |
|
80 | - $this->template_args['template_path'], |
|
81 | - $this->event |
|
82 | - ), |
|
83 | - $this->template_args |
|
84 | - ); |
|
85 | - } catch (\Exception $e) { |
|
86 | - \EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
|
87 | - } |
|
88 | - return ''; |
|
89 | - } |
|
90 | - |
|
91 | - |
|
92 | - |
|
93 | - /** |
|
94 | - * The __toString method allows a class to decide how it will react when it is converted to a string. |
|
95 | - * |
|
96 | - * @return string |
|
97 | - * @link http://php.net/manual/en/language.oop5.magic.php#language.oop5.magic.tostring |
|
98 | - */ |
|
99 | - public function __toString() |
|
100 | - { |
|
101 | - return $this->loadTicketSelectorTemplate(); |
|
102 | - } |
|
19 | + /** |
|
20 | + * @var \EE_Event $event |
|
21 | + */ |
|
22 | + protected $event; |
|
23 | + |
|
24 | + /** |
|
25 | + * @var \EE_Ticket[] $tickets |
|
26 | + */ |
|
27 | + protected $tickets; |
|
28 | + |
|
29 | + /** |
|
30 | + * @var int max_attendees |
|
31 | + */ |
|
32 | + protected $max_attendees; |
|
33 | + |
|
34 | + /** |
|
35 | + * @var array $template_args |
|
36 | + */ |
|
37 | + protected $template_args; |
|
38 | + |
|
39 | + |
|
40 | + |
|
41 | + /** |
|
42 | + * TicketSelectorSimple constructor. |
|
43 | + * |
|
44 | + * @param \EE_Event $event |
|
45 | + * @param \EE_Ticket[] $tickets |
|
46 | + * @param int $max_attendees |
|
47 | + * @param array $template_args |
|
48 | + */ |
|
49 | + public function __construct(\EE_Event $event, array $tickets, $max_attendees, array $template_args) |
|
50 | + { |
|
51 | + $this->event = $event; |
|
52 | + $this->tickets = $tickets; |
|
53 | + $this->max_attendees = $max_attendees; |
|
54 | + $this->template_args = $template_args; |
|
55 | + $this->addTemplateArgs(); |
|
56 | + } |
|
57 | + |
|
58 | + |
|
59 | + |
|
60 | + /** |
|
61 | + * sets any and all template args that are required for this Ticket Selector |
|
62 | + * |
|
63 | + * @return void |
|
64 | + */ |
|
65 | + abstract protected function addTemplateArgs(); |
|
66 | + |
|
67 | + |
|
68 | + |
|
69 | + /** |
|
70 | + * loadTicketSelectorTemplate |
|
71 | + * |
|
72 | + * @return string |
|
73 | + */ |
|
74 | + protected function loadTicketSelectorTemplate() |
|
75 | + { |
|
76 | + try { |
|
77 | + return \EEH_Template::locate_template( |
|
78 | + apply_filters( |
|
79 | + 'FHEE__EE_Ticket_Selector__display_ticket_selector__template_path', |
|
80 | + $this->template_args['template_path'], |
|
81 | + $this->event |
|
82 | + ), |
|
83 | + $this->template_args |
|
84 | + ); |
|
85 | + } catch (\Exception $e) { |
|
86 | + \EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
|
87 | + } |
|
88 | + return ''; |
|
89 | + } |
|
90 | + |
|
91 | + |
|
92 | + |
|
93 | + /** |
|
94 | + * The __toString method allows a class to decide how it will react when it is converted to a string. |
|
95 | + * |
|
96 | + * @return string |
|
97 | + * @link http://php.net/manual/en/language.oop5.magic.php#language.oop5.magic.tostring |
|
98 | + */ |
|
99 | + public function __toString() |
|
100 | + { |
|
101 | + return $this->loadTicketSelectorTemplate(); |
|
102 | + } |
|
103 | 103 | |
104 | 104 | |
105 | 105 |
@@ -119,19 +119,19 @@ discard block |
||
119 | 119 | |
120 | 120 | |
121 | 121 | |
122 | - /** |
|
123 | - * Form constructor. |
|
124 | - * |
|
125 | - * @param string $form_name |
|
126 | - * @param string $admin_name |
|
127 | - * @param string $slug |
|
128 | - * @param string $form_action |
|
129 | - * @param string $form_config |
|
130 | - * @param \EE_Registry $registry |
|
131 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
132 | - * @throws \DomainException |
|
133 | - * @throws \InvalidArgumentException |
|
134 | - */ |
|
122 | + /** |
|
123 | + * Form constructor. |
|
124 | + * |
|
125 | + * @param string $form_name |
|
126 | + * @param string $admin_name |
|
127 | + * @param string $slug |
|
128 | + * @param string $form_action |
|
129 | + * @param string $form_config |
|
130 | + * @param \EE_Registry $registry |
|
131 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
132 | + * @throws \DomainException |
|
133 | + * @throws \InvalidArgumentException |
|
134 | + */ |
|
135 | 135 | public function __construct( |
136 | 136 | $form_name, |
137 | 137 | $admin_name, |
@@ -172,7 +172,7 @@ discard block |
||
172 | 172 | * @throws \LogicException |
173 | 173 | */ |
174 | 174 | public function form( $for_display = false ) { |
175 | - if ( ! $this->formIsValid() ) { |
|
175 | + if ( ! $this->formIsValid() ) { |
|
176 | 176 | return null; |
177 | 177 | } |
178 | 178 | if ( $for_display ) { |
@@ -195,14 +195,14 @@ discard block |
||
195 | 195 | * @throws LogicException |
196 | 196 | */ |
197 | 197 | public function formIsValid() { |
198 | - if ( ! $this->form instanceof \EE_Form_Section_Proper ) { |
|
198 | + if ( ! $this->form instanceof \EE_Form_Section_Proper ) { |
|
199 | 199 | static $generated = false; |
200 | 200 | if ( ! $generated ) { |
201 | 201 | $generated = true; |
202 | 202 | $form = $this->generate(); |
203 | - if ( $form instanceof \EE_Form_Section_Proper) { |
|
204 | - $this->setForm($form); |
|
205 | - } |
|
203 | + if ( $form instanceof \EE_Form_Section_Proper) { |
|
204 | + $this->setForm($form); |
|
205 | + } |
|
206 | 206 | } |
207 | 207 | return $this->verifyForm(); |
208 | 208 | } |
@@ -337,11 +337,11 @@ discard block |
||
337 | 337 | |
338 | 338 | |
339 | 339 | |
340 | - /** |
|
341 | - * @param string $submit_btn_text |
|
342 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
343 | - * @throws \InvalidArgumentException |
|
344 | - */ |
|
340 | + /** |
|
341 | + * @param string $submit_btn_text |
|
342 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
343 | + * @throws \InvalidArgumentException |
|
344 | + */ |
|
345 | 345 | public function setSubmitBtnText( $submit_btn_text ) { |
346 | 346 | if ( ! is_string( $submit_btn_text ) ) { |
347 | 347 | throw new InvalidDataTypeException( '$submit_btn_text', $submit_btn_text, 'string' ); |
@@ -574,7 +574,7 @@ discard block |
||
574 | 574 | * @throws \EE_Error |
575 | 575 | */ |
576 | 576 | public function display() { |
577 | - $form_html = apply_filters( |
|
577 | + $form_html = apply_filters( |
|
578 | 578 | 'FHEE__EventEspresso_core_libraries_form_sections_form_handlers_FormHandler__display__before_form', |
579 | 579 | '' |
580 | 580 | ); |
@@ -613,11 +613,11 @@ discard block |
||
613 | 613 | */ |
614 | 614 | public function process( $submitted_form_data = array() ) { |
615 | 615 | if ( ! $this->form()->was_submitted( $submitted_form_data ) ) { |
616 | - throw new InvalidFormSubmissionException( $this->form_name ); |
|
616 | + throw new InvalidFormSubmissionException( $this->form_name ); |
|
617 | 617 | } |
618 | - $this->form( true )->receive_form_submission( $submitted_form_data ); |
|
618 | + $this->form( true )->receive_form_submission( $submitted_form_data ); |
|
619 | 619 | if ( ! $this->form()->is_valid() ) { |
620 | - throw new InvalidFormSubmissionException( |
|
620 | + throw new InvalidFormSubmissionException( |
|
621 | 621 | $this->form_name, |
622 | 622 | sprintf( |
623 | 623 | __( |
@@ -10,8 +10,8 @@ discard block |
||
10 | 10 | use EventEspresso\core\exceptions\InvalidDataTypeException; |
11 | 11 | use EventEspresso\core\exceptions\InvalidFormSubmissionException; |
12 | 12 | |
13 | -if ( ! defined( 'EVENT_ESPRESSO_VERSION' ) ) { |
|
14 | - exit( 'No direct script access allowed' ); |
|
13 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
14 | + exit('No direct script access allowed'); |
|
15 | 15 | } |
16 | 16 | |
17 | 17 | |
@@ -27,7 +27,7 @@ discard block |
||
27 | 27 | * @author Brent Christensen |
28 | 28 | * @since 4.9.0 |
29 | 29 | */ |
30 | -abstract class FormHandler implements FormHandlerInterface{ |
|
30 | +abstract class FormHandler implements FormHandlerInterface { |
|
31 | 31 | |
32 | 32 | /** |
33 | 33 | * will add opening and closing HTML form tags as well as a submit button |
@@ -140,12 +140,12 @@ discard block |
||
140 | 140 | $form_config = FormHandler::ADD_FORM_TAGS_AND_SUBMIT, |
141 | 141 | \EE_Registry $registry |
142 | 142 | ) { |
143 | - $this->setFormName( $form_name ); |
|
144 | - $this->setAdminName( $admin_name ); |
|
145 | - $this->setSlug( $slug ); |
|
146 | - $this->setFormAction( $form_action ); |
|
147 | - $this->setFormConfig( $form_config ); |
|
148 | - $this->setSubmitBtnText( __( 'Submit', 'event_espresso' ) ); |
|
143 | + $this->setFormName($form_name); |
|
144 | + $this->setAdminName($admin_name); |
|
145 | + $this->setSlug($slug); |
|
146 | + $this->setFormAction($form_action); |
|
147 | + $this->setFormConfig($form_config); |
|
148 | + $this->setSubmitBtnText(__('Submit', 'event_espresso')); |
|
149 | 149 | $this->registry = $registry; |
150 | 150 | } |
151 | 151 | |
@@ -171,11 +171,11 @@ discard block |
||
171 | 171 | * @throws \EE_Error |
172 | 172 | * @throws \LogicException |
173 | 173 | */ |
174 | - public function form( $for_display = false ) { |
|
175 | - if ( ! $this->formIsValid() ) { |
|
174 | + public function form($for_display = false) { |
|
175 | + if ( ! $this->formIsValid()) { |
|
176 | 176 | return null; |
177 | 177 | } |
178 | - if ( $for_display ) { |
|
178 | + if ($for_display) { |
|
179 | 179 | $form_config = $this->formConfig(); |
180 | 180 | if ( |
181 | 181 | $form_config === FormHandler::ADD_FORM_TAGS_AND_SUBMIT |
@@ -195,12 +195,12 @@ discard block |
||
195 | 195 | * @throws LogicException |
196 | 196 | */ |
197 | 197 | public function formIsValid() { |
198 | - if ( ! $this->form instanceof \EE_Form_Section_Proper ) { |
|
198 | + if ( ! $this->form instanceof \EE_Form_Section_Proper) { |
|
199 | 199 | static $generated = false; |
200 | - if ( ! $generated ) { |
|
200 | + if ( ! $generated) { |
|
201 | 201 | $generated = true; |
202 | 202 | $form = $this->generate(); |
203 | - if ( $form instanceof \EE_Form_Section_Proper) { |
|
203 | + if ($form instanceof \EE_Form_Section_Proper) { |
|
204 | 204 | $this->setForm($form); |
205 | 205 | } |
206 | 206 | } |
@@ -216,12 +216,12 @@ discard block |
||
216 | 216 | * @throws LogicException |
217 | 217 | */ |
218 | 218 | public function verifyForm() { |
219 | - if ( $this->form instanceof \EE_Form_Section_Proper ) { |
|
219 | + if ($this->form instanceof \EE_Form_Section_Proper) { |
|
220 | 220 | return true; |
221 | 221 | } |
222 | 222 | throw new LogicException( |
223 | 223 | sprintf( |
224 | - __( 'The "%1$s" form is invalid or missing', 'event_espresso' ), |
|
224 | + __('The "%1$s" form is invalid or missing', 'event_espresso'), |
|
225 | 225 | $this->form_name |
226 | 226 | ) |
227 | 227 | ); |
@@ -232,7 +232,7 @@ discard block |
||
232 | 232 | /** |
233 | 233 | * @param \EE_Form_Section_Proper $form |
234 | 234 | */ |
235 | - public function setForm( \EE_Form_Section_Proper $form ) { |
|
235 | + public function setForm(\EE_Form_Section_Proper $form) { |
|
236 | 236 | $this->form = $form; |
237 | 237 | } |
238 | 238 | |
@@ -250,8 +250,8 @@ discard block |
||
250 | 250 | /** |
251 | 251 | * @param boolean $displayable |
252 | 252 | */ |
253 | - public function setDisplayable( $displayable = false ) { |
|
254 | - $this->displayable = filter_var( $displayable, FILTER_VALIDATE_BOOLEAN ); |
|
253 | + public function setDisplayable($displayable = false) { |
|
254 | + $this->displayable = filter_var($displayable, FILTER_VALIDATE_BOOLEAN); |
|
255 | 255 | } |
256 | 256 | |
257 | 257 | |
@@ -271,9 +271,9 @@ discard block |
||
271 | 271 | * @param string $form_name |
272 | 272 | * @throws InvalidDataTypeException |
273 | 273 | */ |
274 | - public function setFormName( $form_name ) { |
|
275 | - if ( ! is_string( $form_name ) ) { |
|
276 | - throw new InvalidDataTypeException( '$form_name', $form_name, 'string' ); |
|
274 | + public function setFormName($form_name) { |
|
275 | + if ( ! is_string($form_name)) { |
|
276 | + throw new InvalidDataTypeException('$form_name', $form_name, 'string'); |
|
277 | 277 | } |
278 | 278 | $this->form_name = $form_name; |
279 | 279 | } |
@@ -295,9 +295,9 @@ discard block |
||
295 | 295 | * @param string $admin_name |
296 | 296 | * @throws InvalidDataTypeException |
297 | 297 | */ |
298 | - public function setAdminName( $admin_name ) { |
|
299 | - if ( ! is_string( $admin_name ) ) { |
|
300 | - throw new InvalidDataTypeException( '$admin_name', $admin_name, 'string' ); |
|
298 | + public function setAdminName($admin_name) { |
|
299 | + if ( ! is_string($admin_name)) { |
|
300 | + throw new InvalidDataTypeException('$admin_name', $admin_name, 'string'); |
|
301 | 301 | } |
302 | 302 | $this->admin_name = $admin_name; |
303 | 303 | } |
@@ -319,9 +319,9 @@ discard block |
||
319 | 319 | * @param string $slug |
320 | 320 | * @throws InvalidDataTypeException |
321 | 321 | */ |
322 | - public function setSlug( $slug ) { |
|
323 | - if ( ! is_string( $slug ) ) { |
|
324 | - throw new InvalidDataTypeException( '$slug', $slug, 'string' ); |
|
322 | + public function setSlug($slug) { |
|
323 | + if ( ! is_string($slug)) { |
|
324 | + throw new InvalidDataTypeException('$slug', $slug, 'string'); |
|
325 | 325 | } |
326 | 326 | $this->slug = $slug; |
327 | 327 | } |
@@ -342,13 +342,13 @@ discard block |
||
342 | 342 | * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
343 | 343 | * @throws \InvalidArgumentException |
344 | 344 | */ |
345 | - public function setSubmitBtnText( $submit_btn_text ) { |
|
346 | - if ( ! is_string( $submit_btn_text ) ) { |
|
347 | - throw new InvalidDataTypeException( '$submit_btn_text', $submit_btn_text, 'string' ); |
|
345 | + public function setSubmitBtnText($submit_btn_text) { |
|
346 | + if ( ! is_string($submit_btn_text)) { |
|
347 | + throw new InvalidDataTypeException('$submit_btn_text', $submit_btn_text, 'string'); |
|
348 | 348 | } |
349 | - if ( empty( $submit_btn_text ) ) { |
|
349 | + if (empty($submit_btn_text)) { |
|
350 | 350 | throw new InvalidArgumentException( |
351 | - __( 'Can not set Submit button text because an empty string was provided.', 'event_espresso' ) |
|
351 | + __('Can not set Submit button text because an empty string was provided.', 'event_espresso') |
|
352 | 352 | ); |
353 | 353 | } |
354 | 354 | $this->submit_btn_text = $submit_btn_text; |
@@ -360,8 +360,8 @@ discard block |
||
360 | 360 | * @return string |
361 | 361 | */ |
362 | 362 | public function formAction() { |
363 | - return ! empty( $this->form_args ) |
|
364 | - ? add_query_arg( $this->form_args, $this->form_action ) |
|
363 | + return ! empty($this->form_args) |
|
364 | + ? add_query_arg($this->form_args, $this->form_action) |
|
365 | 365 | : $this->form_action; |
366 | 366 | } |
367 | 367 | |
@@ -371,9 +371,9 @@ discard block |
||
371 | 371 | * @param string $form_action |
372 | 372 | * @throws InvalidDataTypeException |
373 | 373 | */ |
374 | - public function setFormAction( $form_action ) { |
|
375 | - if ( ! is_string( $form_action ) ) { |
|
376 | - throw new InvalidDataTypeException( '$form_action', $form_action, 'string' ); |
|
374 | + public function setFormAction($form_action) { |
|
375 | + if ( ! is_string($form_action)) { |
|
376 | + throw new InvalidDataTypeException('$form_action', $form_action, 'string'); |
|
377 | 377 | } |
378 | 378 | $this->form_action = $form_action; |
379 | 379 | } |
@@ -385,20 +385,20 @@ discard block |
||
385 | 385 | * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
386 | 386 | * @throws \InvalidArgumentException |
387 | 387 | */ |
388 | - public function addFormActionArgs( $form_args = array() ) { |
|
389 | - if ( is_object( $form_args ) ) { |
|
388 | + public function addFormActionArgs($form_args = array()) { |
|
389 | + if (is_object($form_args)) { |
|
390 | 390 | throw new InvalidDataTypeException( |
391 | 391 | '$form_args', |
392 | 392 | $form_args, |
393 | 393 | 'anything other than an object was expected.' |
394 | 394 | ); |
395 | 395 | } |
396 | - if ( empty( $form_args ) ) { |
|
396 | + if (empty($form_args)) { |
|
397 | 397 | throw new InvalidArgumentException( |
398 | - __( 'The redirect arguments can not be an empty array.', 'event_espresso' ) |
|
398 | + __('The redirect arguments can not be an empty array.', 'event_espresso') |
|
399 | 399 | ); |
400 | 400 | } |
401 | - $this->form_args = array_merge( $this->form_args, $form_args ); |
|
401 | + $this->form_args = array_merge($this->form_args, $form_args); |
|
402 | 402 | } |
403 | 403 | |
404 | 404 | |
@@ -416,7 +416,7 @@ discard block |
||
416 | 416 | * @param string $form_config |
417 | 417 | * @throws DomainException |
418 | 418 | */ |
419 | - public function setFormConfig( $form_config ) { |
|
419 | + public function setFormConfig($form_config) { |
|
420 | 420 | if ( |
421 | 421 | ! in_array( |
422 | 422 | $form_config, |
@@ -430,7 +430,7 @@ discard block |
||
430 | 430 | ) { |
431 | 431 | throw new DomainException( |
432 | 432 | sprintf( |
433 | - __( '"%1$s" is not a valid value for the form config. Please use one of the class constants on \EventEspresso\core\libraries\form_sections\form_handlers\Form', 'event_espresso' ), |
|
433 | + __('"%1$s" is not a valid value for the form config. Please use one of the class constants on \EventEspresso\core\libraries\form_sections\form_handlers\Form', 'event_espresso'), |
|
434 | 434 | $form_config |
435 | 435 | ) |
436 | 436 | ); |
@@ -450,7 +450,7 @@ discard block |
||
450 | 450 | * @return boolean |
451 | 451 | */ |
452 | 452 | public function initialize() { |
453 | - $this->form_has_errors = \EE_Error::has_error( true ); |
|
453 | + $this->form_has_errors = \EE_Error::has_error(true); |
|
454 | 454 | return true; |
455 | 455 | } |
456 | 456 | |
@@ -464,7 +464,7 @@ discard block |
||
464 | 464 | * @throws \EE_Error |
465 | 465 | */ |
466 | 466 | public function enqueueStylesAndScripts() { |
467 | - $this->form( false )->enqueue_js(); |
|
467 | + $this->form(false)->enqueue_js(); |
|
468 | 468 | |
469 | 469 | } |
470 | 470 | |
@@ -475,7 +475,7 @@ discard block |
||
475 | 475 | * |
476 | 476 | * @return EE_Form_Section_Proper |
477 | 477 | */ |
478 | - abstract public function generate() ; |
|
478 | + abstract public function generate(); |
|
479 | 479 | |
480 | 480 | |
481 | 481 | |
@@ -485,15 +485,15 @@ discard block |
||
485 | 485 | * @param string $text |
486 | 486 | * @return \EE_Submit_Input |
487 | 487 | */ |
488 | - public function generateSubmitButton( $text = '' ) { |
|
489 | - $text = ! empty( $text ) ? $text : $this->submitBtnText(); |
|
488 | + public function generateSubmitButton($text = '') { |
|
489 | + $text = ! empty($text) ? $text : $this->submitBtnText(); |
|
490 | 490 | return new EE_Submit_Input( |
491 | 491 | array( |
492 | - 'html_name' => 'ee-form-submit-' . $this->slug(), |
|
493 | - 'html_id' => 'ee-form-submit-' . $this->slug(), |
|
492 | + 'html_name' => 'ee-form-submit-'.$this->slug(), |
|
493 | + 'html_id' => 'ee-form-submit-'.$this->slug(), |
|
494 | 494 | 'html_class' => 'ee-form-submit', |
495 | 495 | 'html_label' => ' ', |
496 | - 'other_html_attributes' => ' rel="' . $this->slug() . '"', |
|
496 | + 'other_html_attributes' => ' rel="'.$this->slug().'"', |
|
497 | 497 | 'default' => $text |
498 | 498 | ) |
499 | 499 | ); |
@@ -509,12 +509,12 @@ discard block |
||
509 | 509 | * @throws \LogicException |
510 | 510 | * @throws \EE_Error |
511 | 511 | */ |
512 | - public function appendSubmitButton( $text = '' ) { |
|
513 | - if ( $this->form->subsection_exists( $this->slug() . '-submit-btn' ) ) { |
|
512 | + public function appendSubmitButton($text = '') { |
|
513 | + if ($this->form->subsection_exists($this->slug().'-submit-btn')) { |
|
514 | 514 | return; |
515 | 515 | } |
516 | 516 | $this->form->add_subsections( |
517 | - array( $this->slug() . '-submit-btn' => $this->generateSubmitButton( $text ) ), |
|
517 | + array($this->slug().'-submit-btn' => $this->generateSubmitButton($text)), |
|
518 | 518 | null, |
519 | 519 | false |
520 | 520 | ); |
@@ -528,18 +528,18 @@ discard block |
||
528 | 528 | * @param string $text |
529 | 529 | * @return \EE_Submit_Input |
530 | 530 | */ |
531 | - public function generateCancelButton( $text = '' ) { |
|
531 | + public function generateCancelButton($text = '') { |
|
532 | 532 | $cancel_button = new EE_Submit_Input( |
533 | 533 | array( |
534 | - 'html_name' => 'ee-form-submit-' . $this->slug(), // YES! Same name as submit !!! |
|
535 | - 'html_id' => 'ee-cancel-form-' . $this->slug(), |
|
534 | + 'html_name' => 'ee-form-submit-'.$this->slug(), // YES! Same name as submit !!! |
|
535 | + 'html_id' => 'ee-cancel-form-'.$this->slug(), |
|
536 | 536 | 'html_class' => 'ee-cancel-form', |
537 | 537 | 'html_label' => ' ', |
538 | - 'other_html_attributes' => ' rel="' . $this->slug() . '"', |
|
539 | - 'default' => ! empty( $text ) ? $text : __( 'Cancel', 'event_espresso' ) |
|
538 | + 'other_html_attributes' => ' rel="'.$this->slug().'"', |
|
539 | + 'default' => ! empty($text) ? $text : __('Cancel', 'event_espresso') |
|
540 | 540 | ) |
541 | 541 | ); |
542 | - $cancel_button->set_button_css_attributes( false ); |
|
542 | + $cancel_button->set_button_css_attributes(false); |
|
543 | 543 | return $cancel_button; |
544 | 544 | } |
545 | 545 | |
@@ -555,7 +555,7 @@ discard block |
||
555 | 555 | $this->form->add_subsections( |
556 | 556 | array( |
557 | 557 | 'clear-submit-btn-float' => new \EE_Form_Section_HTML( |
558 | - EEH_HTML::div( '', '', 'clear-float' ) . EEH_HTML::divx() |
|
558 | + EEH_HTML::div('', '', 'clear-float').EEH_HTML::divx() |
|
559 | 559 | ) |
560 | 560 | ), |
561 | 561 | null, |
@@ -583,9 +583,9 @@ discard block |
||
583 | 583 | $form_config === FormHandler::ADD_FORM_TAGS_AND_SUBMIT |
584 | 584 | || $form_config === FormHandler::ADD_FORM_TAGS_ONLY |
585 | 585 | ) { |
586 | - $form_html .= $this->form()->form_open( $this->formAction() ); |
|
586 | + $form_html .= $this->form()->form_open($this->formAction()); |
|
587 | 587 | } |
588 | - $form_html .= $this->form( true )->get_html( $this->form_has_errors ); |
|
588 | + $form_html .= $this->form(true)->get_html($this->form_has_errors); |
|
589 | 589 | if ( |
590 | 590 | $form_config === FormHandler::ADD_FORM_TAGS_AND_SUBMIT |
591 | 591 | || $form_config === FormHandler::ADD_FORM_TAGS_ONLY |
@@ -611,12 +611,12 @@ discard block |
||
611 | 611 | * @throws \LogicException |
612 | 612 | * @throws InvalidFormSubmissionException |
613 | 613 | */ |
614 | - public function process( $submitted_form_data = array() ) { |
|
615 | - if ( ! $this->form()->was_submitted( $submitted_form_data ) ) { |
|
616 | - throw new InvalidFormSubmissionException( $this->form_name ); |
|
614 | + public function process($submitted_form_data = array()) { |
|
615 | + if ( ! $this->form()->was_submitted($submitted_form_data)) { |
|
616 | + throw new InvalidFormSubmissionException($this->form_name); |
|
617 | 617 | } |
618 | - $this->form( true )->receive_form_submission( $submitted_form_data ); |
|
619 | - if ( ! $this->form()->is_valid() ) { |
|
618 | + $this->form(true)->receive_form_submission($submitted_form_data); |
|
619 | + if ( ! $this->form()->is_valid()) { |
|
620 | 620 | throw new InvalidFormSubmissionException( |
621 | 621 | $this->form_name, |
622 | 622 | sprintf( |
@@ -1,15 +1,15 @@ |
||
1 | 1 | <?php |
2 | 2 | //echo '<br/><h6 style="color:#2EA2CC;">'. __FILE__ . ' <span style="font-weight:normal;color:#E76700"> Line #: ' . __LINE__ . '</span></h6>'; |
3 | 3 | |
4 | -if ( is_single() || ( is_archive() && espresso_display_datetimes_in_event_list() ) ) : |
|
4 | +if (is_single() || (is_archive() && espresso_display_datetimes_in_event_list())) : |
|
5 | 5 | global $post; |
6 | -do_action( 'AHEE_event_details_before_event_date', $post ); |
|
6 | +do_action('AHEE_event_details_before_event_date', $post); |
|
7 | 7 | ?> |
8 | 8 | <div class="event-datetimes"> |
9 | - <?php espresso_list_of_event_dates( $post->ID );?> |
|
9 | + <?php espresso_list_of_event_dates($post->ID); ?> |
|
10 | 10 | </div> |
11 | 11 | <!-- .event-datetimes --> |
12 | 12 | <?php |
13 | -do_action( 'AHEE_event_details_after_event_date', $post ); |
|
13 | +do_action('AHEE_event_details_after_event_date', $post); |
|
14 | 14 | endif; |
15 | 15 | ?> |
16 | 16 | \ No newline at end of file |
@@ -1,5 +1,5 @@ discard block |
||
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 | |
5 | 5 | |
@@ -14,1368 +14,1368 @@ discard block |
||
14 | 14 | class EE_Event extends EE_CPT_Base implements EEI_Line_Item_Object, EEI_Admin_Links, EEI_Has_Icon, EEI_Event |
15 | 15 | { |
16 | 16 | |
17 | - /** |
|
18 | - * cached value for the the logical active status for the event |
|
19 | - * |
|
20 | - * @see get_active_status() |
|
21 | - * @var string |
|
22 | - */ |
|
23 | - protected $_active_status = ''; |
|
24 | - |
|
25 | - /** |
|
26 | - * This is just used for caching the Primary Datetime for the Event on initial retrieval |
|
27 | - * |
|
28 | - * @var EE_Datetime |
|
29 | - */ |
|
30 | - protected $_Primary_Datetime; |
|
31 | - |
|
32 | - |
|
33 | - |
|
34 | - /** |
|
35 | - * @param array $props_n_values incoming values |
|
36 | - * @param string $timezone incoming timezone (if not set the timezone set for the website will be |
|
37 | - * used.) |
|
38 | - * @param array $date_formats incoming date_formats in an array where the first value is the |
|
39 | - * date_format and the second value is the time format |
|
40 | - * @return EE_Event |
|
41 | - */ |
|
42 | - public static function new_instance($props_n_values = array(), $timezone = null, $date_formats = array()) |
|
43 | - { |
|
44 | - $has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone, $date_formats); |
|
45 | - return $has_object ? $has_object : new self($props_n_values, false, $timezone, $date_formats); |
|
46 | - } |
|
47 | - |
|
48 | - |
|
49 | - |
|
50 | - /** |
|
51 | - * @param array $props_n_values incoming values from the database |
|
52 | - * @param string $timezone incoming timezone as set by the model. If not set the timezone for |
|
53 | - * the website will be used. |
|
54 | - * @return EE_Event |
|
55 | - */ |
|
56 | - public static function new_instance_from_db($props_n_values = array(), $timezone = null) |
|
57 | - { |
|
58 | - return new self($props_n_values, true, $timezone); |
|
59 | - } |
|
60 | - |
|
61 | - |
|
62 | - |
|
63 | - /** |
|
64 | - * Overrides parent set() method so that all calls to set( 'status', $status ) can be routed to internal methods |
|
65 | - * |
|
66 | - * @param string $field_name |
|
67 | - * @param mixed $field_value |
|
68 | - * @param bool $use_default |
|
69 | - */ |
|
70 | - public function set($field_name, $field_value, $use_default = false) |
|
71 | - { |
|
72 | - switch ($field_name) { |
|
73 | - case 'status' : |
|
74 | - $this->set_status($field_value, $use_default); |
|
75 | - break; |
|
76 | - default : |
|
77 | - parent::set($field_name, $field_value, $use_default); |
|
78 | - } |
|
79 | - } |
|
80 | - |
|
81 | - |
|
82 | - |
|
83 | - /** |
|
84 | - * set_status |
|
85 | - * Checks if event status is being changed to SOLD OUT |
|
86 | - * and updates event meta data with previous event status |
|
87 | - * so that we can revert things if/when the event is no longer sold out |
|
88 | - * |
|
89 | - * @access public |
|
90 | - * @param string $new_status |
|
91 | - * @param bool $use_default |
|
92 | - * @return bool|void |
|
93 | - * @throws \EE_Error |
|
94 | - */ |
|
95 | - public function set_status($new_status = null, $use_default = false) |
|
96 | - { |
|
97 | - // get current Event status |
|
98 | - $old_status = $this->status(); |
|
99 | - // if status has changed |
|
100 | - if ($old_status != $new_status) { |
|
101 | - // TO sold_out |
|
102 | - if ($new_status == EEM_Event::sold_out) { |
|
103 | - // save the previous event status so that we can revert if the event is no longer sold out |
|
104 | - $this->add_post_meta('_previous_event_status', $old_status); |
|
105 | - do_action('AHEE__EE_Event__set_status__to_sold_out', $this, $old_status, $new_status); |
|
106 | - // OR FROM sold_out |
|
107 | - } else if ($old_status == EEM_Event::sold_out) { |
|
108 | - $this->delete_post_meta('_previous_event_status'); |
|
109 | - do_action('AHEE__EE_Event__set_status__from_sold_out', $this, $old_status, $new_status); |
|
110 | - } |
|
111 | - // update status |
|
112 | - parent::set('status', $new_status, $use_default); |
|
113 | - do_action('AHEE__EE_Event__set_status__after_update', $this); |
|
114 | - return true; |
|
115 | - } else { |
|
116 | - // even though the old value matches the new value, it's still good to |
|
117 | - // allow the parent set method to have a say |
|
118 | - parent::set('status', $new_status, $use_default); |
|
119 | - return true; |
|
120 | - } |
|
121 | - } |
|
122 | - |
|
123 | - |
|
124 | - |
|
125 | - /** |
|
126 | - * Gets all the datetimes for this event |
|
127 | - * |
|
128 | - * @param array $query_params like EEM_Base::get_all |
|
129 | - * @return EE_Datetime[] |
|
130 | - */ |
|
131 | - public function datetimes($query_params = array()) |
|
132 | - { |
|
133 | - return $this->get_many_related('Datetime', $query_params); |
|
134 | - } |
|
135 | - |
|
136 | - |
|
137 | - |
|
138 | - /** |
|
139 | - * Gets all the datetimes for this event, ordered by DTT_EVT_start in ascending order |
|
140 | - * |
|
141 | - * @return EE_Datetime[] |
|
142 | - */ |
|
143 | - public function datetimes_in_chronological_order() |
|
144 | - { |
|
145 | - return $this->get_many_related('Datetime', array('order_by' => array('DTT_EVT_start' => 'ASC'))); |
|
146 | - } |
|
147 | - |
|
148 | - |
|
149 | - |
|
150 | - /** |
|
151 | - * Gets all the datetimes for this event, ordered by the DTT_order on the datetime. |
|
152 | - * @darren, we should probably UNSET timezone on the EEM_Datetime model |
|
153 | - * after running our query, so that this timezone isn't set for EVERY query |
|
154 | - * on EEM_Datetime for the rest of the request, no? |
|
155 | - * |
|
156 | - * @param boolean $show_expired whether or not to include expired events |
|
157 | - * @param boolean $show_deleted whether or not to include deleted events |
|
158 | - * @param null $limit |
|
159 | - * @return \EE_Datetime[] |
|
160 | - * @throws \EE_Error |
|
161 | - */ |
|
162 | - public function datetimes_ordered($show_expired = true, $show_deleted = false, $limit = null) |
|
163 | - { |
|
164 | - return EEM_Datetime::instance($this->_timezone)->get_datetimes_for_event_ordered_by_DTT_order( |
|
165 | - $this->ID(), |
|
166 | - $show_expired, |
|
167 | - $show_deleted, |
|
168 | - $limit |
|
169 | - ); |
|
170 | - } |
|
171 | - |
|
172 | - |
|
173 | - |
|
174 | - /** |
|
175 | - * Returns one related datetime. Mostly only used by some legacy code. |
|
176 | - * |
|
177 | - * @return EE_Datetime |
|
178 | - */ |
|
179 | - public function first_datetime() |
|
180 | - { |
|
181 | - return $this->get_first_related('Datetime'); |
|
182 | - } |
|
183 | - |
|
184 | - |
|
185 | - |
|
186 | - /** |
|
187 | - * Returns the 'primary' datetime for the event |
|
188 | - * |
|
189 | - * @param bool $try_to_exclude_expired |
|
190 | - * @param bool $try_to_exclude_deleted |
|
191 | - * @return EE_Datetime |
|
192 | - */ |
|
193 | - public function primary_datetime($try_to_exclude_expired = true, $try_to_exclude_deleted = true) |
|
194 | - { |
|
195 | - if ( ! empty ($this->_Primary_Datetime)) { |
|
196 | - return $this->_Primary_Datetime; |
|
197 | - } |
|
198 | - $this->_Primary_Datetime = EEM_Datetime::instance($this->_timezone) |
|
199 | - ->get_primary_datetime_for_event($this->ID(), $try_to_exclude_expired, |
|
200 | - $try_to_exclude_deleted); |
|
201 | - return $this->_Primary_Datetime; |
|
202 | - } |
|
203 | - |
|
204 | - |
|
205 | - |
|
206 | - /** |
|
207 | - * Gets all the tickets available for purchase of this event |
|
208 | - * |
|
209 | - * @param array $query_params like EEM_Base::get_all |
|
210 | - * @return EE_Ticket[] |
|
211 | - */ |
|
212 | - public function tickets($query_params = array()) |
|
213 | - { |
|
214 | - //first get all datetimes |
|
215 | - $datetimes = $this->datetimes_ordered(); |
|
216 | - if ( ! $datetimes) { |
|
217 | - return array(); |
|
218 | - } |
|
219 | - $datetime_ids = array(); |
|
220 | - foreach ($datetimes as $datetime) { |
|
221 | - $datetime_ids[] = $datetime->ID(); |
|
222 | - } |
|
223 | - $where_params = array('Datetime.DTT_ID' => array('IN', $datetime_ids)); |
|
224 | - //if incoming $query_params has where conditions let's merge but not override existing. |
|
225 | - if (is_array($query_params) && isset($query_params[0])) { |
|
226 | - $where_params = array_merge($query_params[0], $where_params); |
|
227 | - unset($query_params[0]); |
|
228 | - } |
|
229 | - //now add $where_params to $query_params |
|
230 | - $query_params[0] = $where_params; |
|
231 | - return EEM_Ticket::instance()->get_all($query_params); |
|
232 | - } |
|
233 | - |
|
234 | - |
|
235 | - |
|
236 | - /** |
|
237 | - * @return bool |
|
238 | - */ |
|
239 | - public function additional_limit() |
|
240 | - { |
|
241 | - return $this->get('EVT_additional_limit'); |
|
242 | - } |
|
243 | - |
|
244 | - |
|
245 | - |
|
246 | - /** |
|
247 | - * @return bool |
|
248 | - */ |
|
249 | - public function allow_overflow() |
|
250 | - { |
|
251 | - return $this->get('EVT_allow_overflow'); |
|
252 | - } |
|
253 | - |
|
254 | - |
|
255 | - |
|
256 | - /** |
|
257 | - * @return bool |
|
258 | - */ |
|
259 | - public function created() |
|
260 | - { |
|
261 | - return $this->get('EVT_created'); |
|
262 | - } |
|
263 | - |
|
264 | - |
|
265 | - |
|
266 | - /** |
|
267 | - * @return bool |
|
268 | - */ |
|
269 | - public function description() |
|
270 | - { |
|
271 | - return $this->get('EVT_desc'); |
|
272 | - } |
|
273 | - |
|
274 | - |
|
275 | - |
|
276 | - /** |
|
277 | - * Runs do_shortcode and wpautop on the description |
|
278 | - * |
|
279 | - * @return string of html |
|
280 | - */ |
|
281 | - public function description_filtered() |
|
282 | - { |
|
283 | - return $this->get_pretty('EVT_desc'); |
|
284 | - } |
|
285 | - |
|
286 | - |
|
287 | - |
|
288 | - /** |
|
289 | - * @return bool |
|
290 | - */ |
|
291 | - public function display_description() |
|
292 | - { |
|
293 | - return $this->get('EVT_display_desc'); |
|
294 | - } |
|
295 | - |
|
296 | - |
|
297 | - |
|
298 | - /** |
|
299 | - * @return bool |
|
300 | - */ |
|
301 | - public function display_ticket_selector() |
|
302 | - { |
|
303 | - return (bool)$this->get('EVT_display_ticket_selector'); |
|
304 | - } |
|
305 | - |
|
17 | + /** |
|
18 | + * cached value for the the logical active status for the event |
|
19 | + * |
|
20 | + * @see get_active_status() |
|
21 | + * @var string |
|
22 | + */ |
|
23 | + protected $_active_status = ''; |
|
24 | + |
|
25 | + /** |
|
26 | + * This is just used for caching the Primary Datetime for the Event on initial retrieval |
|
27 | + * |
|
28 | + * @var EE_Datetime |
|
29 | + */ |
|
30 | + protected $_Primary_Datetime; |
|
31 | + |
|
32 | + |
|
33 | + |
|
34 | + /** |
|
35 | + * @param array $props_n_values incoming values |
|
36 | + * @param string $timezone incoming timezone (if not set the timezone set for the website will be |
|
37 | + * used.) |
|
38 | + * @param array $date_formats incoming date_formats in an array where the first value is the |
|
39 | + * date_format and the second value is the time format |
|
40 | + * @return EE_Event |
|
41 | + */ |
|
42 | + public static function new_instance($props_n_values = array(), $timezone = null, $date_formats = array()) |
|
43 | + { |
|
44 | + $has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone, $date_formats); |
|
45 | + return $has_object ? $has_object : new self($props_n_values, false, $timezone, $date_formats); |
|
46 | + } |
|
47 | + |
|
48 | + |
|
49 | + |
|
50 | + /** |
|
51 | + * @param array $props_n_values incoming values from the database |
|
52 | + * @param string $timezone incoming timezone as set by the model. If not set the timezone for |
|
53 | + * the website will be used. |
|
54 | + * @return EE_Event |
|
55 | + */ |
|
56 | + public static function new_instance_from_db($props_n_values = array(), $timezone = null) |
|
57 | + { |
|
58 | + return new self($props_n_values, true, $timezone); |
|
59 | + } |
|
60 | + |
|
61 | + |
|
62 | + |
|
63 | + /** |
|
64 | + * Overrides parent set() method so that all calls to set( 'status', $status ) can be routed to internal methods |
|
65 | + * |
|
66 | + * @param string $field_name |
|
67 | + * @param mixed $field_value |
|
68 | + * @param bool $use_default |
|
69 | + */ |
|
70 | + public function set($field_name, $field_value, $use_default = false) |
|
71 | + { |
|
72 | + switch ($field_name) { |
|
73 | + case 'status' : |
|
74 | + $this->set_status($field_value, $use_default); |
|
75 | + break; |
|
76 | + default : |
|
77 | + parent::set($field_name, $field_value, $use_default); |
|
78 | + } |
|
79 | + } |
|
80 | + |
|
81 | + |
|
82 | + |
|
83 | + /** |
|
84 | + * set_status |
|
85 | + * Checks if event status is being changed to SOLD OUT |
|
86 | + * and updates event meta data with previous event status |
|
87 | + * so that we can revert things if/when the event is no longer sold out |
|
88 | + * |
|
89 | + * @access public |
|
90 | + * @param string $new_status |
|
91 | + * @param bool $use_default |
|
92 | + * @return bool|void |
|
93 | + * @throws \EE_Error |
|
94 | + */ |
|
95 | + public function set_status($new_status = null, $use_default = false) |
|
96 | + { |
|
97 | + // get current Event status |
|
98 | + $old_status = $this->status(); |
|
99 | + // if status has changed |
|
100 | + if ($old_status != $new_status) { |
|
101 | + // TO sold_out |
|
102 | + if ($new_status == EEM_Event::sold_out) { |
|
103 | + // save the previous event status so that we can revert if the event is no longer sold out |
|
104 | + $this->add_post_meta('_previous_event_status', $old_status); |
|
105 | + do_action('AHEE__EE_Event__set_status__to_sold_out', $this, $old_status, $new_status); |
|
106 | + // OR FROM sold_out |
|
107 | + } else if ($old_status == EEM_Event::sold_out) { |
|
108 | + $this->delete_post_meta('_previous_event_status'); |
|
109 | + do_action('AHEE__EE_Event__set_status__from_sold_out', $this, $old_status, $new_status); |
|
110 | + } |
|
111 | + // update status |
|
112 | + parent::set('status', $new_status, $use_default); |
|
113 | + do_action('AHEE__EE_Event__set_status__after_update', $this); |
|
114 | + return true; |
|
115 | + } else { |
|
116 | + // even though the old value matches the new value, it's still good to |
|
117 | + // allow the parent set method to have a say |
|
118 | + parent::set('status', $new_status, $use_default); |
|
119 | + return true; |
|
120 | + } |
|
121 | + } |
|
122 | + |
|
123 | + |
|
124 | + |
|
125 | + /** |
|
126 | + * Gets all the datetimes for this event |
|
127 | + * |
|
128 | + * @param array $query_params like EEM_Base::get_all |
|
129 | + * @return EE_Datetime[] |
|
130 | + */ |
|
131 | + public function datetimes($query_params = array()) |
|
132 | + { |
|
133 | + return $this->get_many_related('Datetime', $query_params); |
|
134 | + } |
|
135 | + |
|
136 | + |
|
137 | + |
|
138 | + /** |
|
139 | + * Gets all the datetimes for this event, ordered by DTT_EVT_start in ascending order |
|
140 | + * |
|
141 | + * @return EE_Datetime[] |
|
142 | + */ |
|
143 | + public function datetimes_in_chronological_order() |
|
144 | + { |
|
145 | + return $this->get_many_related('Datetime', array('order_by' => array('DTT_EVT_start' => 'ASC'))); |
|
146 | + } |
|
147 | + |
|
148 | + |
|
149 | + |
|
150 | + /** |
|
151 | + * Gets all the datetimes for this event, ordered by the DTT_order on the datetime. |
|
152 | + * @darren, we should probably UNSET timezone on the EEM_Datetime model |
|
153 | + * after running our query, so that this timezone isn't set for EVERY query |
|
154 | + * on EEM_Datetime for the rest of the request, no? |
|
155 | + * |
|
156 | + * @param boolean $show_expired whether or not to include expired events |
|
157 | + * @param boolean $show_deleted whether or not to include deleted events |
|
158 | + * @param null $limit |
|
159 | + * @return \EE_Datetime[] |
|
160 | + * @throws \EE_Error |
|
161 | + */ |
|
162 | + public function datetimes_ordered($show_expired = true, $show_deleted = false, $limit = null) |
|
163 | + { |
|
164 | + return EEM_Datetime::instance($this->_timezone)->get_datetimes_for_event_ordered_by_DTT_order( |
|
165 | + $this->ID(), |
|
166 | + $show_expired, |
|
167 | + $show_deleted, |
|
168 | + $limit |
|
169 | + ); |
|
170 | + } |
|
171 | + |
|
172 | + |
|
173 | + |
|
174 | + /** |
|
175 | + * Returns one related datetime. Mostly only used by some legacy code. |
|
176 | + * |
|
177 | + * @return EE_Datetime |
|
178 | + */ |
|
179 | + public function first_datetime() |
|
180 | + { |
|
181 | + return $this->get_first_related('Datetime'); |
|
182 | + } |
|
183 | + |
|
184 | + |
|
185 | + |
|
186 | + /** |
|
187 | + * Returns the 'primary' datetime for the event |
|
188 | + * |
|
189 | + * @param bool $try_to_exclude_expired |
|
190 | + * @param bool $try_to_exclude_deleted |
|
191 | + * @return EE_Datetime |
|
192 | + */ |
|
193 | + public function primary_datetime($try_to_exclude_expired = true, $try_to_exclude_deleted = true) |
|
194 | + { |
|
195 | + if ( ! empty ($this->_Primary_Datetime)) { |
|
196 | + return $this->_Primary_Datetime; |
|
197 | + } |
|
198 | + $this->_Primary_Datetime = EEM_Datetime::instance($this->_timezone) |
|
199 | + ->get_primary_datetime_for_event($this->ID(), $try_to_exclude_expired, |
|
200 | + $try_to_exclude_deleted); |
|
201 | + return $this->_Primary_Datetime; |
|
202 | + } |
|
203 | + |
|
204 | + |
|
205 | + |
|
206 | + /** |
|
207 | + * Gets all the tickets available for purchase of this event |
|
208 | + * |
|
209 | + * @param array $query_params like EEM_Base::get_all |
|
210 | + * @return EE_Ticket[] |
|
211 | + */ |
|
212 | + public function tickets($query_params = array()) |
|
213 | + { |
|
214 | + //first get all datetimes |
|
215 | + $datetimes = $this->datetimes_ordered(); |
|
216 | + if ( ! $datetimes) { |
|
217 | + return array(); |
|
218 | + } |
|
219 | + $datetime_ids = array(); |
|
220 | + foreach ($datetimes as $datetime) { |
|
221 | + $datetime_ids[] = $datetime->ID(); |
|
222 | + } |
|
223 | + $where_params = array('Datetime.DTT_ID' => array('IN', $datetime_ids)); |
|
224 | + //if incoming $query_params has where conditions let's merge but not override existing. |
|
225 | + if (is_array($query_params) && isset($query_params[0])) { |
|
226 | + $where_params = array_merge($query_params[0], $where_params); |
|
227 | + unset($query_params[0]); |
|
228 | + } |
|
229 | + //now add $where_params to $query_params |
|
230 | + $query_params[0] = $where_params; |
|
231 | + return EEM_Ticket::instance()->get_all($query_params); |
|
232 | + } |
|
233 | + |
|
234 | + |
|
235 | + |
|
236 | + /** |
|
237 | + * @return bool |
|
238 | + */ |
|
239 | + public function additional_limit() |
|
240 | + { |
|
241 | + return $this->get('EVT_additional_limit'); |
|
242 | + } |
|
243 | + |
|
244 | + |
|
245 | + |
|
246 | + /** |
|
247 | + * @return bool |
|
248 | + */ |
|
249 | + public function allow_overflow() |
|
250 | + { |
|
251 | + return $this->get('EVT_allow_overflow'); |
|
252 | + } |
|
253 | + |
|
254 | + |
|
255 | + |
|
256 | + /** |
|
257 | + * @return bool |
|
258 | + */ |
|
259 | + public function created() |
|
260 | + { |
|
261 | + return $this->get('EVT_created'); |
|
262 | + } |
|
263 | + |
|
264 | + |
|
265 | + |
|
266 | + /** |
|
267 | + * @return bool |
|
268 | + */ |
|
269 | + public function description() |
|
270 | + { |
|
271 | + return $this->get('EVT_desc'); |
|
272 | + } |
|
273 | + |
|
274 | + |
|
275 | + |
|
276 | + /** |
|
277 | + * Runs do_shortcode and wpautop on the description |
|
278 | + * |
|
279 | + * @return string of html |
|
280 | + */ |
|
281 | + public function description_filtered() |
|
282 | + { |
|
283 | + return $this->get_pretty('EVT_desc'); |
|
284 | + } |
|
285 | + |
|
286 | + |
|
287 | + |
|
288 | + /** |
|
289 | + * @return bool |
|
290 | + */ |
|
291 | + public function display_description() |
|
292 | + { |
|
293 | + return $this->get('EVT_display_desc'); |
|
294 | + } |
|
295 | + |
|
296 | + |
|
297 | + |
|
298 | + /** |
|
299 | + * @return bool |
|
300 | + */ |
|
301 | + public function display_ticket_selector() |
|
302 | + { |
|
303 | + return (bool)$this->get('EVT_display_ticket_selector'); |
|
304 | + } |
|
305 | + |
|
306 | 306 | |
307 | 307 | |
308 | - /** |
|
309 | - * @return bool |
|
310 | - */ |
|
311 | - public function external_url() |
|
312 | - { |
|
313 | - return $this->get('EVT_external_URL'); |
|
314 | - } |
|
308 | + /** |
|
309 | + * @return bool |
|
310 | + */ |
|
311 | + public function external_url() |
|
312 | + { |
|
313 | + return $this->get('EVT_external_URL'); |
|
314 | + } |
|
315 | 315 | |
316 | 316 | |
317 | 317 | |
318 | - /** |
|
319 | - * @return bool |
|
320 | - */ |
|
321 | - public function member_only() |
|
322 | - { |
|
323 | - return $this->get('EVT_member_only'); |
|
324 | - } |
|
318 | + /** |
|
319 | + * @return bool |
|
320 | + */ |
|
321 | + public function member_only() |
|
322 | + { |
|
323 | + return $this->get('EVT_member_only'); |
|
324 | + } |
|
325 | 325 | |
326 | 326 | |
327 | 327 | |
328 | - /** |
|
329 | - * @return bool |
|
330 | - */ |
|
331 | - public function phone() |
|
332 | - { |
|
333 | - return $this->get('EVT_phone'); |
|
334 | - } |
|
328 | + /** |
|
329 | + * @return bool |
|
330 | + */ |
|
331 | + public function phone() |
|
332 | + { |
|
333 | + return $this->get('EVT_phone'); |
|
334 | + } |
|
335 | 335 | |
336 | 336 | |
337 | 337 | |
338 | - /** |
|
339 | - * @return bool |
|
340 | - */ |
|
341 | - public function modified() |
|
342 | - { |
|
343 | - return $this->get('EVT_modified'); |
|
344 | - } |
|
338 | + /** |
|
339 | + * @return bool |
|
340 | + */ |
|
341 | + public function modified() |
|
342 | + { |
|
343 | + return $this->get('EVT_modified'); |
|
344 | + } |
|
345 | 345 | |
346 | 346 | |
347 | 347 | |
348 | - /** |
|
349 | - * @return bool |
|
350 | - */ |
|
351 | - public function name() |
|
352 | - { |
|
353 | - return $this->get('EVT_name'); |
|
354 | - } |
|
348 | + /** |
|
349 | + * @return bool |
|
350 | + */ |
|
351 | + public function name() |
|
352 | + { |
|
353 | + return $this->get('EVT_name'); |
|
354 | + } |
|
355 | 355 | |
356 | 356 | |
357 | 357 | |
358 | - /** |
|
359 | - * @return bool |
|
360 | - */ |
|
361 | - public function order() |
|
362 | - { |
|
363 | - return $this->get('EVT_order'); |
|
364 | - } |
|
358 | + /** |
|
359 | + * @return bool |
|
360 | + */ |
|
361 | + public function order() |
|
362 | + { |
|
363 | + return $this->get('EVT_order'); |
|
364 | + } |
|
365 | 365 | |
366 | 366 | |
367 | 367 | |
368 | - /** |
|
369 | - * @return bool|string |
|
370 | - */ |
|
371 | - public function default_registration_status() |
|
372 | - { |
|
373 | - $event_default_registration_status = $this->get('EVT_default_registration_status'); |
|
374 | - return ! empty($event_default_registration_status) ? $event_default_registration_status |
|
375 | - : EE_Registry::instance()->CFG->registration->default_STS_ID; |
|
376 | - } |
|
368 | + /** |
|
369 | + * @return bool|string |
|
370 | + */ |
|
371 | + public function default_registration_status() |
|
372 | + { |
|
373 | + $event_default_registration_status = $this->get('EVT_default_registration_status'); |
|
374 | + return ! empty($event_default_registration_status) ? $event_default_registration_status |
|
375 | + : EE_Registry::instance()->CFG->registration->default_STS_ID; |
|
376 | + } |
|
377 | 377 | |
378 | 378 | |
379 | 379 | |
380 | - /** |
|
381 | - * @param int $num_words |
|
382 | - * @param null $more |
|
383 | - * @param bool $not_full_desc |
|
384 | - * @return bool|string |
|
385 | - */ |
|
386 | - public function short_description($num_words = 55, $more = null, $not_full_desc = false) |
|
387 | - { |
|
388 | - $short_desc = $this->get('EVT_short_desc'); |
|
389 | - if ( ! empty($short_desc) || $not_full_desc) { |
|
390 | - return $short_desc; |
|
391 | - } else { |
|
392 | - $full_desc = $this->get('EVT_desc'); |
|
393 | - return wp_trim_words($full_desc, $num_words, $more); |
|
394 | - } |
|
395 | - } |
|
380 | + /** |
|
381 | + * @param int $num_words |
|
382 | + * @param null $more |
|
383 | + * @param bool $not_full_desc |
|
384 | + * @return bool|string |
|
385 | + */ |
|
386 | + public function short_description($num_words = 55, $more = null, $not_full_desc = false) |
|
387 | + { |
|
388 | + $short_desc = $this->get('EVT_short_desc'); |
|
389 | + if ( ! empty($short_desc) || $not_full_desc) { |
|
390 | + return $short_desc; |
|
391 | + } else { |
|
392 | + $full_desc = $this->get('EVT_desc'); |
|
393 | + return wp_trim_words($full_desc, $num_words, $more); |
|
394 | + } |
|
395 | + } |
|
396 | 396 | |
397 | 397 | |
398 | 398 | |
399 | - /** |
|
400 | - * @return bool |
|
401 | - */ |
|
402 | - public function slug() |
|
403 | - { |
|
404 | - return $this->get('EVT_slug'); |
|
405 | - } |
|
399 | + /** |
|
400 | + * @return bool |
|
401 | + */ |
|
402 | + public function slug() |
|
403 | + { |
|
404 | + return $this->get('EVT_slug'); |
|
405 | + } |
|
406 | 406 | |
407 | 407 | |
408 | 408 | |
409 | - /** |
|
410 | - * @return bool |
|
411 | - */ |
|
412 | - public function timezone_string() |
|
413 | - { |
|
414 | - return $this->get('EVT_timezone_string'); |
|
415 | - } |
|
409 | + /** |
|
410 | + * @return bool |
|
411 | + */ |
|
412 | + public function timezone_string() |
|
413 | + { |
|
414 | + return $this->get('EVT_timezone_string'); |
|
415 | + } |
|
416 | 416 | |
417 | 417 | |
418 | 418 | |
419 | - /** |
|
420 | - * @return bool |
|
421 | - */ |
|
422 | - public function visible_on() |
|
423 | - { |
|
424 | - return $this->get('EVT_visible_on'); |
|
425 | - } |
|
419 | + /** |
|
420 | + * @return bool |
|
421 | + */ |
|
422 | + public function visible_on() |
|
423 | + { |
|
424 | + return $this->get('EVT_visible_on'); |
|
425 | + } |
|
426 | 426 | |
427 | 427 | |
428 | 428 | |
429 | - /** |
|
430 | - * @return int |
|
431 | - */ |
|
432 | - public function wp_user() |
|
433 | - { |
|
434 | - return $this->get('EVT_wp_user'); |
|
435 | - } |
|
429 | + /** |
|
430 | + * @return int |
|
431 | + */ |
|
432 | + public function wp_user() |
|
433 | + { |
|
434 | + return $this->get('EVT_wp_user'); |
|
435 | + } |
|
436 | 436 | |
437 | 437 | |
438 | 438 | |
439 | - /** |
|
440 | - * @return bool |
|
441 | - */ |
|
442 | - public function donations() |
|
443 | - { |
|
444 | - return $this->get('EVT_donations'); |
|
445 | - } |
|
439 | + /** |
|
440 | + * @return bool |
|
441 | + */ |
|
442 | + public function donations() |
|
443 | + { |
|
444 | + return $this->get('EVT_donations'); |
|
445 | + } |
|
446 | 446 | |
447 | 447 | |
448 | 448 | |
449 | - /** |
|
450 | - * @param $limit |
|
451 | - */ |
|
452 | - public function set_additional_limit($limit) |
|
453 | - { |
|
454 | - $this->set('EVT_additional_limit', $limit); |
|
455 | - } |
|
449 | + /** |
|
450 | + * @param $limit |
|
451 | + */ |
|
452 | + public function set_additional_limit($limit) |
|
453 | + { |
|
454 | + $this->set('EVT_additional_limit', $limit); |
|
455 | + } |
|
456 | 456 | |
457 | 457 | |
458 | 458 | |
459 | - /** |
|
460 | - * @param $created |
|
461 | - */ |
|
462 | - public function set_created($created) |
|
463 | - { |
|
464 | - $this->set('EVT_created', $created); |
|
465 | - } |
|
459 | + /** |
|
460 | + * @param $created |
|
461 | + */ |
|
462 | + public function set_created($created) |
|
463 | + { |
|
464 | + $this->set('EVT_created', $created); |
|
465 | + } |
|
466 | 466 | |
467 | 467 | |
468 | 468 | |
469 | - /** |
|
470 | - * @param $desc |
|
471 | - */ |
|
472 | - public function set_description($desc) |
|
473 | - { |
|
474 | - $this->set('EVT_desc', $desc); |
|
475 | - } |
|
469 | + /** |
|
470 | + * @param $desc |
|
471 | + */ |
|
472 | + public function set_description($desc) |
|
473 | + { |
|
474 | + $this->set('EVT_desc', $desc); |
|
475 | + } |
|
476 | 476 | |
477 | 477 | |
478 | 478 | |
479 | - /** |
|
480 | - * @param $display_desc |
|
481 | - */ |
|
482 | - public function set_display_description($display_desc) |
|
483 | - { |
|
484 | - $this->set('EVT_display_desc', $display_desc); |
|
485 | - } |
|
479 | + /** |
|
480 | + * @param $display_desc |
|
481 | + */ |
|
482 | + public function set_display_description($display_desc) |
|
483 | + { |
|
484 | + $this->set('EVT_display_desc', $display_desc); |
|
485 | + } |
|
486 | 486 | |
487 | 487 | |
488 | 488 | |
489 | - /** |
|
490 | - * @param $display_ticket_selector |
|
491 | - */ |
|
492 | - public function set_display_ticket_selector($display_ticket_selector) |
|
493 | - { |
|
494 | - $this->set('EVT_display_ticket_selector', $display_ticket_selector); |
|
495 | - } |
|
489 | + /** |
|
490 | + * @param $display_ticket_selector |
|
491 | + */ |
|
492 | + public function set_display_ticket_selector($display_ticket_selector) |
|
493 | + { |
|
494 | + $this->set('EVT_display_ticket_selector', $display_ticket_selector); |
|
495 | + } |
|
496 | 496 | |
497 | 497 | |
498 | 498 | |
499 | - /** |
|
500 | - * @param $external_url |
|
501 | - */ |
|
502 | - public function set_external_url($external_url) |
|
503 | - { |
|
504 | - $this->set('EVT_external_URL', $external_url); |
|
505 | - } |
|
499 | + /** |
|
500 | + * @param $external_url |
|
501 | + */ |
|
502 | + public function set_external_url($external_url) |
|
503 | + { |
|
504 | + $this->set('EVT_external_URL', $external_url); |
|
505 | + } |
|
506 | 506 | |
507 | 507 | |
508 | 508 | |
509 | - /** |
|
510 | - * @param $member_only |
|
511 | - */ |
|
512 | - public function set_member_only($member_only) |
|
513 | - { |
|
514 | - $this->set('EVT_member_only', $member_only); |
|
515 | - } |
|
509 | + /** |
|
510 | + * @param $member_only |
|
511 | + */ |
|
512 | + public function set_member_only($member_only) |
|
513 | + { |
|
514 | + $this->set('EVT_member_only', $member_only); |
|
515 | + } |
|
516 | 516 | |
517 | 517 | |
518 | 518 | |
519 | - /** |
|
520 | - * @param $event_phone |
|
521 | - */ |
|
522 | - public function set_event_phone($event_phone) |
|
523 | - { |
|
524 | - $this->set('EVT_phone', $event_phone); |
|
525 | - } |
|
519 | + /** |
|
520 | + * @param $event_phone |
|
521 | + */ |
|
522 | + public function set_event_phone($event_phone) |
|
523 | + { |
|
524 | + $this->set('EVT_phone', $event_phone); |
|
525 | + } |
|
526 | 526 | |
527 | 527 | |
528 | 528 | |
529 | - /** |
|
530 | - * @param $modified |
|
531 | - */ |
|
532 | - public function set_modified($modified) |
|
533 | - { |
|
534 | - $this->set('EVT_modified', $modified); |
|
535 | - } |
|
529 | + /** |
|
530 | + * @param $modified |
|
531 | + */ |
|
532 | + public function set_modified($modified) |
|
533 | + { |
|
534 | + $this->set('EVT_modified', $modified); |
|
535 | + } |
|
536 | 536 | |
537 | 537 | |
538 | 538 | |
539 | - /** |
|
540 | - * @param $name |
|
541 | - */ |
|
542 | - public function set_name($name) |
|
543 | - { |
|
544 | - $this->set('EVT_name', $name); |
|
545 | - } |
|
539 | + /** |
|
540 | + * @param $name |
|
541 | + */ |
|
542 | + public function set_name($name) |
|
543 | + { |
|
544 | + $this->set('EVT_name', $name); |
|
545 | + } |
|
546 | 546 | |
547 | 547 | |
548 | 548 | |
549 | - /** |
|
550 | - * @param $order |
|
551 | - */ |
|
552 | - public function set_order($order) |
|
553 | - { |
|
554 | - $this->set('EVT_order', $order); |
|
555 | - } |
|
549 | + /** |
|
550 | + * @param $order |
|
551 | + */ |
|
552 | + public function set_order($order) |
|
553 | + { |
|
554 | + $this->set('EVT_order', $order); |
|
555 | + } |
|
556 | 556 | |
557 | 557 | |
558 | 558 | |
559 | - /** |
|
560 | - * @param $short_desc |
|
561 | - */ |
|
562 | - public function set_short_description($short_desc) |
|
563 | - { |
|
564 | - $this->set('EVT_short_desc', $short_desc); |
|
565 | - } |
|
559 | + /** |
|
560 | + * @param $short_desc |
|
561 | + */ |
|
562 | + public function set_short_description($short_desc) |
|
563 | + { |
|
564 | + $this->set('EVT_short_desc', $short_desc); |
|
565 | + } |
|
566 | 566 | |
567 | 567 | |
568 | 568 | |
569 | - /** |
|
570 | - * @param $slug |
|
571 | - */ |
|
572 | - public function set_slug($slug) |
|
573 | - { |
|
574 | - $this->set('EVT_slug', $slug); |
|
575 | - } |
|
569 | + /** |
|
570 | + * @param $slug |
|
571 | + */ |
|
572 | + public function set_slug($slug) |
|
573 | + { |
|
574 | + $this->set('EVT_slug', $slug); |
|
575 | + } |
|
576 | 576 | |
577 | 577 | |
578 | 578 | |
579 | - /** |
|
580 | - * @param $timezone_string |
|
581 | - */ |
|
582 | - public function set_timezone_string($timezone_string) |
|
583 | - { |
|
584 | - $this->set('EVT_timezone_string', $timezone_string); |
|
585 | - } |
|
579 | + /** |
|
580 | + * @param $timezone_string |
|
581 | + */ |
|
582 | + public function set_timezone_string($timezone_string) |
|
583 | + { |
|
584 | + $this->set('EVT_timezone_string', $timezone_string); |
|
585 | + } |
|
586 | 586 | |
587 | 587 | |
588 | 588 | |
589 | - /** |
|
590 | - * @param $visible_on |
|
591 | - */ |
|
592 | - public function set_visible_on($visible_on) |
|
593 | - { |
|
594 | - $this->set('EVT_visible_on', $visible_on); |
|
595 | - } |
|
589 | + /** |
|
590 | + * @param $visible_on |
|
591 | + */ |
|
592 | + public function set_visible_on($visible_on) |
|
593 | + { |
|
594 | + $this->set('EVT_visible_on', $visible_on); |
|
595 | + } |
|
596 | 596 | |
597 | 597 | |
598 | 598 | |
599 | - /** |
|
600 | - * @param $wp_user |
|
601 | - */ |
|
602 | - public function set_wp_user($wp_user) |
|
603 | - { |
|
604 | - $this->set('EVT_wp_user', $wp_user); |
|
605 | - } |
|
599 | + /** |
|
600 | + * @param $wp_user |
|
601 | + */ |
|
602 | + public function set_wp_user($wp_user) |
|
603 | + { |
|
604 | + $this->set('EVT_wp_user', $wp_user); |
|
605 | + } |
|
606 | 606 | |
607 | 607 | |
608 | - |
|
609 | - /** |
|
610 | - * @param $default_registration_status |
|
611 | - */ |
|
612 | - public function set_default_registration_status($default_registration_status) |
|
613 | - { |
|
614 | - $this->set('EVT_default_registration_status', $default_registration_status); |
|
615 | - } |
|
616 | - |
|
617 | - |
|
618 | - |
|
619 | - /** |
|
620 | - * @param $donations |
|
621 | - */ |
|
622 | - public function set_donations($donations) |
|
623 | - { |
|
624 | - $this->set('EVT_donations', $donations); |
|
625 | - } |
|
626 | - |
|
627 | - |
|
628 | - |
|
629 | - /** |
|
630 | - * Adds a venue to this event |
|
631 | - * |
|
632 | - * @param EE_Venue /int $venue_id_or_obj |
|
633 | - * @return EE_Venue |
|
634 | - */ |
|
635 | - public function add_venue($venue_id_or_obj) |
|
636 | - { |
|
637 | - return $this->_add_relation_to($venue_id_or_obj, 'Venue'); |
|
638 | - } |
|
639 | - |
|
640 | - |
|
641 | - |
|
642 | - /** |
|
643 | - * Removes a venue from the event |
|
644 | - * |
|
645 | - * @param EE_Venue /int $venue_id_or_obj |
|
646 | - * @return EE_Venue |
|
647 | - */ |
|
648 | - public function remove_venue($venue_id_or_obj) |
|
649 | - { |
|
650 | - return $this->_remove_relation_to($venue_id_or_obj, 'Venue'); |
|
651 | - } |
|
652 | - |
|
653 | - |
|
654 | - |
|
655 | - /** |
|
656 | - * Gets all the venues related ot the event. May provide additional $query_params if desired |
|
657 | - * |
|
658 | - * @param array $query_params like EEM_Base::get_all's $query_params |
|
659 | - * @return EE_Venue[] |
|
660 | - */ |
|
661 | - public function venues($query_params = array()) |
|
662 | - { |
|
663 | - return $this->get_many_related('Venue', $query_params); |
|
664 | - } |
|
665 | - |
|
666 | - |
|
667 | - |
|
668 | - /** |
|
669 | - * check if event id is present and if event is published |
|
670 | - * |
|
671 | - * @access public |
|
672 | - * @return boolean true yes, false no |
|
673 | - */ |
|
674 | - private function _has_ID_and_is_published() |
|
675 | - { |
|
676 | - // first check if event id is present and not NULL, then check if this event is published (or any of the equivalent "published" statuses) |
|
677 | - return ($this->ID() && $this->ID() !== null |
|
678 | - && ($this->status() == 'publish' |
|
679 | - || $this->status() |
|
680 | - == EEM_Event::sold_out |
|
681 | - || $this->status() == EEM_Event::postponed |
|
682 | - || $this->status() == EEM_Event::cancelled)) ? true : false; |
|
683 | - } |
|
684 | - |
|
685 | - |
|
686 | - |
|
687 | - /** |
|
688 | - * This simply compares the internal dates with NOW and determines if the event is upcoming or not. |
|
689 | - * |
|
690 | - * @access public |
|
691 | - * @return boolean true yes, false no |
|
692 | - */ |
|
693 | - public function is_upcoming() |
|
694 | - { |
|
695 | - // check if event id is present and if this event is published |
|
696 | - if ($this->is_inactive()) { |
|
697 | - return false; |
|
698 | - } |
|
699 | - // set initial value |
|
700 | - $upcoming = false; |
|
701 | - //next let's get all datetimes and loop through them |
|
702 | - $datetimes = $this->datetimes_in_chronological_order(); |
|
703 | - foreach ($datetimes as $datetime) { |
|
704 | - if ($datetime instanceof EE_Datetime) { |
|
705 | - //if this dtt is expired then we continue cause one of the other datetimes might be upcoming. |
|
706 | - if ($datetime->is_expired()) { |
|
707 | - continue; |
|
708 | - } |
|
709 | - //if this dtt is active then we return false. |
|
710 | - if ($datetime->is_active()) { |
|
711 | - return false; |
|
712 | - } |
|
713 | - //otherwise let's check upcoming status |
|
714 | - $upcoming = $datetime->is_upcoming(); |
|
715 | - } |
|
716 | - } |
|
717 | - return $upcoming; |
|
718 | - } |
|
719 | - |
|
720 | - |
|
721 | - |
|
722 | - /** |
|
723 | - * @return bool |
|
724 | - */ |
|
725 | - public function is_active() |
|
726 | - { |
|
727 | - // check if event id is present and if this event is published |
|
728 | - if ($this->is_inactive()) { |
|
729 | - return false; |
|
730 | - } |
|
731 | - // set initial value |
|
732 | - $active = false; |
|
733 | - //next let's get all datetimes and loop through them |
|
734 | - $datetimes = $this->datetimes_in_chronological_order(); |
|
735 | - foreach ($datetimes as $datetime) { |
|
736 | - if ($datetime instanceof EE_Datetime) { |
|
737 | - //if this dtt is expired then we continue cause one of the other datetimes might be active. |
|
738 | - if ($datetime->is_expired()) { |
|
739 | - continue; |
|
740 | - } |
|
741 | - //if this dtt is upcoming then we return false. |
|
742 | - if ($datetime->is_upcoming()) { |
|
743 | - return false; |
|
744 | - } |
|
745 | - //otherwise let's check active status |
|
746 | - $active = $datetime->is_active(); |
|
747 | - } |
|
748 | - } |
|
749 | - return $active; |
|
750 | - } |
|
751 | - |
|
752 | - |
|
753 | - |
|
754 | - /** |
|
755 | - * @return bool |
|
756 | - */ |
|
757 | - public function is_expired() |
|
758 | - { |
|
759 | - // check if event id is present and if this event is published |
|
760 | - if ($this->is_inactive()) { |
|
761 | - return false; |
|
762 | - } |
|
763 | - // set initial value |
|
764 | - $expired = false; |
|
765 | - //first let's get all datetimes and loop through them |
|
766 | - $datetimes = $this->datetimes_in_chronological_order(); |
|
767 | - foreach ($datetimes as $datetime) { |
|
768 | - if ($datetime instanceof EE_Datetime) { |
|
769 | - //if this dtt is upcoming or active then we return false. |
|
770 | - if ($datetime->is_upcoming() || $datetime->is_active()) { |
|
771 | - return false; |
|
772 | - } |
|
773 | - //otherwise let's check active status |
|
774 | - $expired = $datetime->is_expired(); |
|
775 | - } |
|
776 | - } |
|
777 | - return $expired; |
|
778 | - } |
|
779 | - |
|
780 | - |
|
781 | - |
|
782 | - /** |
|
783 | - * @return bool |
|
784 | - */ |
|
785 | - public function is_inactive() |
|
786 | - { |
|
787 | - // check if event id is present and if this event is published |
|
788 | - if ($this->_has_ID_and_is_published()) { |
|
789 | - return false; |
|
790 | - } |
|
791 | - return true; |
|
792 | - } |
|
793 | - |
|
794 | - |
|
795 | - |
|
796 | - /** |
|
797 | - * perform_sold_out_status_check |
|
798 | - * checks all of this events's datetime reg_limit - sold values to determine if ANY datetimes have spaces |
|
799 | - * available... if NOT, then the event status will get toggled to 'sold_out' |
|
800 | - * |
|
801 | - * @access public |
|
802 | - * @return bool return the ACTUAL sold out state. |
|
803 | - */ |
|
804 | - public function perform_sold_out_status_check() |
|
805 | - { |
|
806 | - // get all unexpired untrashed tickets |
|
807 | - $tickets = $this->tickets(array( |
|
808 | - array( |
|
809 | - 'TKT_end_date' => array('>=', EEM_Ticket::instance()->current_time_for_query('TKT_end_date')), |
|
810 | - 'TKT_deleted' => false, |
|
811 | - ), |
|
812 | - )); |
|
813 | - // if all the tickets are just expired, then don't update the event status to sold out |
|
814 | - if (empty($tickets)) { |
|
815 | - return true; |
|
816 | - } |
|
817 | - // set initial value |
|
818 | - $spaces_remaining = 0; |
|
819 | - foreach ($tickets as $ticket) { |
|
820 | - if ($ticket instanceof EE_Ticket) { |
|
821 | - $spaces_remaining += $ticket->qty('saleable'); |
|
822 | - } |
|
823 | - } |
|
824 | - if ($spaces_remaining === 0) { |
|
825 | - $this->set_status(EEM_Event::sold_out); |
|
826 | - if ( ! is_admin() || (is_admin() && defined('DOING_AJAX'))) { |
|
827 | - $this->save(); |
|
828 | - } |
|
829 | - $sold_out = true; |
|
830 | - } else { |
|
831 | - $sold_out = false; |
|
832 | - // was event previously marked as sold out ? |
|
833 | - if ($this->status() == EEM_Event::sold_out) { |
|
834 | - // revert status to previous value, if it was set |
|
835 | - $previous_event_status = $this->get_post_meta('_previous_event_status', true); |
|
836 | - if ($previous_event_status) { |
|
837 | - $this->set_status($previous_event_status); |
|
838 | - } |
|
839 | - } |
|
840 | - } |
|
841 | - //note: I considered changing the EEM_Event status away from sold_out if this status check reveals that it's no longer sold out (yet the status is still set as sold out) but the problem is... what do we change the status BACK to? We can't always assume that the previous event status was 'published' because this status check is always done in the admin and its entirely possible the event admin manually changes to sold_out status from some other status. We also don't want a draft event to become a "publish event" because the sold out check reveals its NOT sold out. |
|
842 | - // So I'll forgo the automatic switch away from sold out status for now and instead just return the $sold out status... so this check can be used to validate the TRUE sold out status regardless of what the Event status is set to. |
|
843 | - return $sold_out; |
|
844 | - } |
|
845 | - |
|
846 | - |
|
847 | - |
|
848 | - /** |
|
849 | - * This returns the total remaining spaces for sale on this event. |
|
850 | - * ############################ |
|
851 | - * VERY IMPORTANT FOR DEVELOPERS: |
|
852 | - * While included here, this method is still being tested internally, so its signature and behaviour COULD change. |
|
853 | - * While this comment block is in place, usage is at your own risk and know that it may change in future builds. |
|
854 | - * ############################ |
|
855 | - * |
|
856 | - * @uses EE_Event::total_available_spaces() |
|
857 | - * @return float|int (EE_INF is returned as float) |
|
858 | - */ |
|
859 | - public function spaces_remaining_for_sale() |
|
860 | - { |
|
861 | - //first get total available spaces including consideration for tickets that have already sold. |
|
862 | - $spaces_available = $this->total_available_spaces(true); |
|
863 | - //if total available = 0, then exit right away because that means everything is expired. |
|
864 | - if ($spaces_available === 0) { |
|
865 | - return 0; |
|
866 | - } |
|
867 | - //subtract total approved registrations from spaces available to get how many are remaining. |
|
868 | - $spots_taken = EEM_Registration::instance()->count(array( |
|
869 | - array( |
|
870 | - 'EVT_ID' => $this->ID(), |
|
871 | - 'STS_ID' => EEM_Registration::status_id_approved, |
|
872 | - ), |
|
873 | - ), 'REG_ID', true); |
|
874 | - $spaces_remaining = $spaces_available - $spots_taken; |
|
875 | - return $spaces_remaining > 0 ? $spaces_remaining : 0; |
|
876 | - } |
|
877 | - |
|
878 | - |
|
879 | - |
|
880 | - /** |
|
881 | - * This returns the total spaces available for an event while considering all the qtys on the tickets and the reg |
|
882 | - * limits on the datetimes attached to this event. |
|
883 | - * ############################ |
|
884 | - * VERY IMPORTANT FOR DEVELOPERS: |
|
885 | - * While included here, this method is still being tested internally, so its signature and behaviour COULD change. |
|
886 | - * While this comment block is in place, usage is at your own risk and know that it may change in future builds. |
|
887 | - * ############################ |
|
888 | - * Note: by "spaces available" we are not returning how many spaces remain. That is a calculation involving using |
|
889 | - * the value from this method and subtracting the approved registrations for the event. |
|
890 | - * |
|
891 | - * @param bool $current_total_available Whether to consider any tickets that have already sold in our |
|
892 | - * calculation. If this is false, then we return the most tickets that |
|
893 | - * could ever be sold for this event with the datetime and tickets |
|
894 | - * setup on the event under optimal selling conditions. Otherwise we |
|
895 | - * return a live calculation of spaces available based on tickets |
|
896 | - * sold. Depending on setup and stage of sales, this may appear to |
|
897 | - * equal remaining tickets. However, the more tickets are sold out, |
|
898 | - * the more accurate the "live" total is. |
|
899 | - * @return int|float (Note: if EE_INF is returned its considered a float by PHP) |
|
900 | - */ |
|
901 | - public function total_available_spaces($current_total_available = false) |
|
902 | - { |
|
903 | - $spaces_available = 0; |
|
904 | - //first get all tickets on the event and include expired tickets |
|
905 | - $tickets = $this->tickets(array('default_where_conditions' => 'none')); |
|
906 | - $ticket_sums = array(); |
|
907 | - $datetime_limits = array(); |
|
908 | - //loop through tickets and normalize them |
|
909 | - foreach ($tickets as $ticket) { |
|
910 | - $datetimes = $ticket->datetimes(array('order_by' => array('DTT_reg_limit' => 'ASC'))); |
|
911 | - if (empty($datetimes)) { |
|
912 | - continue; |
|
913 | - } |
|
914 | - //first datetime should be the lowest datetime |
|
915 | - $least_datetime = reset($datetimes); |
|
916 | - //lets reset the ticket quantity to be the lower of either the lowest datetime reg limit or the ticket quantity |
|
917 | - //IF datetimes sold (and we're not doing current live total available, then use spaces remaining for datetime, not reg_limit. |
|
918 | - if ($current_total_available) { |
|
919 | - if ($ticket->is_remaining()) { |
|
920 | - $remaining = $ticket->remaining(); |
|
921 | - } else { |
|
922 | - $spaces_available += $ticket->sold(); |
|
923 | - //and we don't cache this ticket to our list because its sold out. |
|
924 | - continue; |
|
925 | - } |
|
926 | - } else { |
|
927 | - $remaining = min($ticket->qty(), $least_datetime->reg_limit()); |
|
928 | - } |
|
929 | - //if $ticket_limit == infinity then let's drop out right away and just return that because any infinity amount trumps all other "available" amounts. |
|
930 | - if ($remaining === EE_INF) { |
|
931 | - return EE_INF; |
|
932 | - } |
|
933 | - //multiply normalized $tkt quantity by the number of datetimes on the ticket as the "sum" |
|
934 | - //also include the sum of all the datetime reg limits on the ticket for breaking ties. |
|
935 | - $ticket_sums[$ticket->ID()]['sum'] = $remaining * count($datetimes); |
|
936 | - $ticket_sums[$ticket->ID()]['datetime_sums'] = 0; |
|
937 | - foreach ($datetimes as $datetime) { |
|
938 | - if ($datetime->reg_limit() === EE_INF) { |
|
939 | - $ticket_sums[$ticket->ID()]['datetime_sums'] = EE_INF; |
|
940 | - } else { |
|
941 | - $ticket_sums[$ticket->ID()]['datetime_sums'] += $current_total_available |
|
942 | - ? $datetime->spaces_remaining() : $datetime->reg_limit(); |
|
943 | - } |
|
944 | - $datetime_limits[$datetime->ID()] = $current_total_available ? $datetime->spaces_remaining() |
|
945 | - : $datetime->reg_limit(); |
|
946 | - } |
|
947 | - $ticket_sums[$ticket->ID()]['ticket'] = $ticket; |
|
948 | - } |
|
949 | - //The order is sorted by lowest available first (which is calculated for each ticket by multiplying the normalized |
|
950 | - //ticket quantity by the number of datetimes on the ticket). For tie-breakers, then the next sort is based on the |
|
951 | - //ticket with the greatest sum of all remaining datetime->spaces_remaining() ( or $datetime->reg_limit() if not |
|
952 | - //$current_total_available ) for the datetimes on the ticket. |
|
953 | - usort($ticket_sums, function ($a, $b) { |
|
954 | - if ($a['sum'] == $b['sum']) { |
|
955 | - if ($a['datetime_sums'] == $b['datetime_sums']) { |
|
956 | - return 0; |
|
957 | - } |
|
958 | - return $a['datetime_sums'] < $b['datetime_sums'] ? 1 : -1; |
|
959 | - } |
|
960 | - return ($a['sum'] < $b['sum']) ? -1 : 1; |
|
961 | - }); |
|
962 | - //now let's loop through the sorted tickets and simulate sellouts |
|
963 | - foreach ($ticket_sums as $ticket_info) { |
|
964 | - if ($ticket_info['ticket'] instanceof EE_Ticket) { |
|
965 | - $datetimes = $ticket_info['ticket']->datetimes(array('order_by' => array('DTT_reg_limit' => 'ASC'))); |
|
966 | - //need to sort these $datetimes by remaining (only if $current_total_available) |
|
967 | - //setup datetimes for simulation |
|
968 | - $ticket_datetimes_remaining = array(); |
|
969 | - foreach ($datetimes as $datetime) { |
|
970 | - $ticket_datetimes_remaining[$datetime->ID()]['rem'] = $datetime_limits[$datetime->ID()]; |
|
971 | - $ticket_datetimes_remaining[$datetime->ID()]['datetime'] = $datetime; |
|
972 | - } |
|
973 | - usort($ticket_datetimes_remaining, function ($a, $b) { |
|
974 | - if ($a['rem'] == $b['rem']) { |
|
975 | - return 0; |
|
976 | - } |
|
977 | - return ($a['rem'] < $b['rem']) ? -1 : 1; |
|
978 | - }); |
|
979 | - //get the remaining on the first datetime (which should be the one with the least remaining) and that is |
|
980 | - //what we add to the spaces_available running total. Then we need to decrease the remaining on our datetime tracker. |
|
981 | - $lowest_datetime = reset($ticket_datetimes_remaining); |
|
982 | - //need to get the lower of; what the remaining is on the lowest datetime, and the remaining on the ticket. |
|
983 | - // If this ends up being 0 (because of previous tickets in our simulation selling out), then it has already |
|
984 | - // been tracked on $spaces available and this ticket is now sold out for the simulation, so we can continue |
|
985 | - // to the next ticket. |
|
986 | - if ($current_total_available) { |
|
987 | - $remaining = min($lowest_datetime['rem'], $ticket_info['ticket']->remaining()); |
|
988 | - } else { |
|
989 | - $remaining = min($lowest_datetime['rem'], $ticket_info['ticket']->qty()); |
|
990 | - } |
|
991 | - //if $remaining is infinite that means that all datetimes on this ticket are infinite but we've made it here because all |
|
992 | - //tickets have a quantity. So we don't have to track datetimes, we can just use ticket quantities for total |
|
993 | - //available. |
|
994 | - if ($remaining === EE_INF) { |
|
995 | - $spaces_available += $ticket_info['ticket']->qty(); |
|
996 | - continue; |
|
997 | - } |
|
998 | - //if ticket has sold amounts then we also need to add that (but only if doing live counts) |
|
999 | - if ($current_total_available) { |
|
1000 | - $spaces_available += $ticket_info['ticket']->sold(); |
|
1001 | - } |
|
1002 | - if ($remaining <= 0) { |
|
1003 | - continue; |
|
1004 | - } else { |
|
1005 | - $spaces_available += $remaining; |
|
1006 | - } |
|
1007 | - //loop through the datetimes and sell them out! |
|
1008 | - foreach ($ticket_datetimes_remaining as $datetime_info) { |
|
1009 | - if ($datetime_info['datetime'] instanceof EE_Datetime) { |
|
1010 | - $datetime_limits[$datetime_info['datetime']->ID()] += -$remaining; |
|
1011 | - } |
|
1012 | - } |
|
1013 | - } |
|
1014 | - } |
|
1015 | - return $spaces_available; |
|
1016 | - } |
|
1017 | - |
|
1018 | - |
|
1019 | - |
|
1020 | - /** |
|
1021 | - * Checks if the event is set to sold out |
|
1022 | - * |
|
1023 | - * @param bool $actual whether or not to perform calculations to not only figure the actual status but also to |
|
1024 | - * flip the status if necessary to sold out If false, we just check the existing status of the |
|
1025 | - * event |
|
1026 | - * @return boolean |
|
1027 | - */ |
|
1028 | - public function is_sold_out($actual = false) |
|
1029 | - { |
|
1030 | - if ( ! $actual) { |
|
1031 | - return $this->status() == EEM_Event::sold_out; |
|
1032 | - } else { |
|
1033 | - return $this->perform_sold_out_status_check(); |
|
1034 | - } |
|
1035 | - } |
|
1036 | - |
|
1037 | - |
|
1038 | - |
|
1039 | - /** |
|
1040 | - * Checks if the event is marked as postponed |
|
1041 | - * |
|
1042 | - * @return boolean |
|
1043 | - */ |
|
1044 | - public function is_postponed() |
|
1045 | - { |
|
1046 | - return $this->status() == EEM_Event::postponed; |
|
1047 | - } |
|
1048 | - |
|
1049 | - |
|
1050 | - |
|
1051 | - /** |
|
1052 | - * Checks if the event is marked as cancelled |
|
1053 | - * |
|
1054 | - * @return boolean |
|
1055 | - */ |
|
1056 | - public function is_cancelled() |
|
1057 | - { |
|
1058 | - return $this->status() == EEM_Event::cancelled; |
|
1059 | - } |
|
1060 | - |
|
1061 | - |
|
1062 | - |
|
1063 | - /** |
|
1064 | - * Get the logical active status in a hierarchical order for all the datetimes. Note |
|
1065 | - * Basically, we order the datetimes by EVT_start_date. Then first test on whether the event is published. If its |
|
1066 | - * NOT published then we test for whether its expired or not. IF it IS published then we test first on whether an |
|
1067 | - * event has any active dates. If no active dates then we check for any upcoming dates. If no upcoming dates then |
|
1068 | - * the event is considered expired. |
|
1069 | - * NOTE: this method does NOT calculate whether the datetimes are sold out when event is published. Sold Out is a |
|
1070 | - * status set on the EVENT when it is not published and thus is done |
|
1071 | - * |
|
1072 | - * @param bool $reset |
|
1073 | - * @return bool | string - based on EE_Datetime active constants or FALSE if error. |
|
1074 | - */ |
|
1075 | - public function get_active_status($reset = false) |
|
1076 | - { |
|
1077 | - // if the active status has already been set, then just use that value (unless we are resetting it) |
|
1078 | - if ( ! empty($this->_active_status) && ! $reset) { |
|
1079 | - return $this->_active_status; |
|
1080 | - } |
|
1081 | - //first check if event id is present on this object |
|
1082 | - if ( ! $this->ID()) { |
|
1083 | - return false; |
|
1084 | - } |
|
1085 | - $where_params_for_event = array(array('EVT_ID' => $this->ID())); |
|
1086 | - //if event is published: |
|
1087 | - if ($this->status() === 'publish') { |
|
1088 | - //active? |
|
1089 | - if (EEM_Datetime::instance()->get_datetime_count_for_status(EE_Datetime::active, $where_params_for_event) |
|
1090 | - > 0 |
|
1091 | - ) { |
|
1092 | - $this->_active_status = EE_Datetime::active; |
|
1093 | - } else { |
|
1094 | - //upcoming? |
|
1095 | - if (EEM_Datetime::instance() |
|
1096 | - ->get_datetime_count_for_status(EE_Datetime::upcoming, $where_params_for_event) > 0 |
|
1097 | - ) { |
|
1098 | - $this->_active_status = EE_Datetime::upcoming; |
|
1099 | - } else { |
|
1100 | - //expired? |
|
1101 | - if (EEM_Datetime::instance() |
|
1102 | - ->get_datetime_count_for_status(EE_Datetime::expired, $where_params_for_event) > 0 |
|
1103 | - ) { |
|
1104 | - $this->_active_status = EE_Datetime::expired; |
|
1105 | - } else { |
|
1106 | - //it would be odd if things make it this far because it basically means there are no datetime's |
|
1107 | - //attached to the event. So in this case it will just be considered inactive. |
|
1108 | - $this->_active_status = EE_Datetime::inactive; |
|
1109 | - } |
|
1110 | - } |
|
1111 | - } |
|
1112 | - } else { |
|
1113 | - //the event is not published, so let's just set it's active status according to its' post status |
|
1114 | - switch ($this->status()) { |
|
1115 | - case EEM_Event::sold_out : |
|
1116 | - $this->_active_status = EE_Datetime::sold_out; |
|
1117 | - break; |
|
1118 | - case EEM_Event::cancelled : |
|
1119 | - $this->_active_status = EE_Datetime::cancelled; |
|
1120 | - break; |
|
1121 | - case EEM_Event::postponed : |
|
1122 | - $this->_active_status = EE_Datetime::postponed; |
|
1123 | - break; |
|
1124 | - default : |
|
1125 | - $this->_active_status = EE_Datetime::inactive; |
|
1126 | - } |
|
1127 | - } |
|
1128 | - return $this->_active_status; |
|
1129 | - } |
|
1130 | - |
|
1131 | - |
|
1132 | - |
|
1133 | - /** |
|
1134 | - * pretty_active_status |
|
1135 | - * |
|
1136 | - * @access public |
|
1137 | - * @param boolean $echo whether to return (FALSE), or echo out the result (TRUE) |
|
1138 | - * @return mixed void|string |
|
1139 | - */ |
|
1140 | - public function pretty_active_status($echo = true) |
|
1141 | - { |
|
1142 | - $active_status = $this->get_active_status(); |
|
1143 | - $status = '<span class="ee-status event-active-status-' |
|
1144 | - . $active_status |
|
1145 | - . '">' |
|
1146 | - . EEH_Template::pretty_status($active_status, false, 'sentence') |
|
1147 | - . '</span>'; |
|
1148 | - if ($echo) { |
|
1149 | - echo $status; |
|
1150 | - return ''; |
|
1151 | - } |
|
1152 | - return $status; |
|
1153 | - } |
|
1154 | - |
|
1155 | - |
|
1156 | - |
|
1157 | - /** |
|
1158 | - * @return bool|int |
|
1159 | - */ |
|
1160 | - public function get_number_of_tickets_sold() |
|
1161 | - { |
|
1162 | - $tkt_sold = 0; |
|
1163 | - if ( ! $this->ID()) { |
|
1164 | - return 0; |
|
1165 | - } |
|
1166 | - $datetimes = $this->datetimes(); |
|
1167 | - foreach ($datetimes as $datetime) { |
|
1168 | - if ($datetime instanceof EE_Datetime) { |
|
1169 | - $tkt_sold += $datetime->sold(); |
|
1170 | - } |
|
1171 | - } |
|
1172 | - return $tkt_sold; |
|
1173 | - } |
|
1174 | - |
|
1175 | - |
|
1176 | - |
|
1177 | - /** |
|
1178 | - * This just returns a count of all the registrations for this event |
|
1179 | - * |
|
1180 | - * @access public |
|
1181 | - * @return int |
|
1182 | - */ |
|
1183 | - public function get_count_of_all_registrations() |
|
1184 | - { |
|
1185 | - return EEM_Event::instance()->count_related($this, 'Registration'); |
|
1186 | - } |
|
1187 | - |
|
1188 | - |
|
1189 | - |
|
1190 | - /** |
|
1191 | - * This returns the ticket with the earliest start time that is available for this event (across all datetimes |
|
1192 | - * attached to the event) |
|
1193 | - * |
|
1194 | - * @return EE_Ticket |
|
1195 | - */ |
|
1196 | - public function get_ticket_with_earliest_start_time() |
|
1197 | - { |
|
1198 | - $where['Datetime.EVT_ID'] = $this->ID(); |
|
1199 | - $query_params = array($where, 'order_by' => array('TKT_start_date' => 'ASC')); |
|
1200 | - return EE_Registry::instance()->load_model('Ticket')->get_one($query_params); |
|
1201 | - } |
|
1202 | - |
|
1203 | - |
|
1204 | - |
|
1205 | - /** |
|
1206 | - * This returns the ticket with the latest end time that is available for this event (across all datetimes attached |
|
1207 | - * to the event) |
|
1208 | - * |
|
1209 | - * @return EE_Ticket |
|
1210 | - */ |
|
1211 | - public function get_ticket_with_latest_end_time() |
|
1212 | - { |
|
1213 | - $where['Datetime.EVT_ID'] = $this->ID(); |
|
1214 | - $query_params = array($where, 'order_by' => array('TKT_end_date' => 'DESC')); |
|
1215 | - return EE_Registry::instance()->load_model('Ticket')->get_one($query_params); |
|
1216 | - } |
|
1217 | - |
|
1218 | - |
|
1219 | - |
|
1220 | - /** |
|
1221 | - * This returns whether there are any tickets on sale for this event. |
|
1222 | - * |
|
1223 | - * @return bool true = YES tickets on sale. |
|
1224 | - */ |
|
1225 | - public function tickets_on_sale() |
|
1226 | - { |
|
1227 | - $earliest_ticket = $this->get_ticket_with_earliest_start_time(); |
|
1228 | - $latest_ticket = $this->get_ticket_with_latest_end_time(); |
|
1229 | - if ( ! $latest_ticket instanceof EE_Ticket && ! $earliest_ticket instanceof EE_Ticket) { |
|
1230 | - return false; |
|
1231 | - } |
|
1232 | - //check on sale for these two tickets. |
|
1233 | - if ($latest_ticket->is_on_sale() || $earliest_ticket->is_on_sale()) { |
|
1234 | - return true; |
|
1235 | - } |
|
1236 | - return false; |
|
1237 | - } |
|
1238 | - |
|
1239 | - |
|
1240 | - |
|
1241 | - /** |
|
1242 | - * Gets the URL for viewing this event on the front-end. Overrides parent |
|
1243 | - * to check for an external URL first |
|
1244 | - * |
|
1245 | - * @return string |
|
1246 | - */ |
|
1247 | - public function get_permalink() |
|
1248 | - { |
|
1249 | - if ($this->external_url()) { |
|
1250 | - return $this->external_url(); |
|
1251 | - } else { |
|
1252 | - return parent::get_permalink(); |
|
1253 | - } |
|
1254 | - } |
|
1255 | - |
|
1256 | - |
|
1257 | - |
|
1258 | - /** |
|
1259 | - * Gets the first term for 'espresso_event_categories' we can find |
|
1260 | - * |
|
1261 | - * @param array $query_params like EEM_Base::get_all |
|
1262 | - * @return EE_Term |
|
1263 | - */ |
|
1264 | - public function first_event_category($query_params = array()) |
|
1265 | - { |
|
1266 | - $query_params[0]['Term_Taxonomy.taxonomy'] = 'espresso_event_categories'; |
|
1267 | - $query_params[0]['Term_Taxonomy.Event.EVT_ID'] = $this->ID(); |
|
1268 | - return EEM_Term::instance()->get_one($query_params); |
|
1269 | - } |
|
1270 | - |
|
1271 | - |
|
1272 | - |
|
1273 | - /** |
|
1274 | - * Gets all terms for 'espresso_event_categories' we can find |
|
1275 | - * |
|
1276 | - * @param array $query_params |
|
1277 | - * @return EE_Term[] |
|
1278 | - */ |
|
1279 | - public function get_all_event_categories($query_params = array()) |
|
1280 | - { |
|
1281 | - $query_params[0]['Term_Taxonomy.taxonomy'] = 'espresso_event_categories'; |
|
1282 | - $query_params[0]['Term_Taxonomy.Event.EVT_ID'] = $this->ID(); |
|
1283 | - return EEM_Term::instance()->get_all($query_params); |
|
1284 | - } |
|
1285 | - |
|
1286 | - |
|
1287 | - |
|
1288 | - /** |
|
1289 | - * Gets all the question groups, ordering them by QSG_order ascending |
|
1290 | - * |
|
1291 | - * @param array $query_params @see EEM_Base::get_all |
|
1292 | - * @return EE_Question_Group[] |
|
1293 | - */ |
|
1294 | - public function question_groups($query_params = array()) |
|
1295 | - { |
|
1296 | - $query_params = ! empty($query_params) ? $query_params : array('order_by' => array('QSG_order' => 'ASC')); |
|
1297 | - return $this->get_many_related('Question_Group', $query_params); |
|
1298 | - } |
|
1299 | - |
|
1300 | - |
|
1301 | - |
|
1302 | - /** |
|
1303 | - * Implementation for EEI_Has_Icon interface method. |
|
1304 | - * |
|
1305 | - * @see EEI_Visual_Representation for comments |
|
1306 | - * @return string |
|
1307 | - */ |
|
1308 | - public function get_icon() |
|
1309 | - { |
|
1310 | - return '<span class="dashicons dashicons-flag"></span>'; |
|
1311 | - } |
|
1312 | - |
|
1313 | - |
|
1314 | - |
|
1315 | - /** |
|
1316 | - * Implementation for EEI_Admin_Links interface method. |
|
1317 | - * |
|
1318 | - * @see EEI_Admin_Links for comments |
|
1319 | - * @return string |
|
1320 | - */ |
|
1321 | - public function get_admin_details_link() |
|
1322 | - { |
|
1323 | - return $this->get_admin_edit_link(); |
|
1324 | - } |
|
1325 | - |
|
1326 | - |
|
1327 | - |
|
1328 | - /** |
|
1329 | - * Implementation for EEI_Admin_Links interface method. |
|
1330 | - * |
|
1331 | - * @see EEI_Admin_Links for comments |
|
1332 | - * @return string |
|
1333 | - */ |
|
1334 | - public function get_admin_edit_link() |
|
1335 | - { |
|
1336 | - return EEH_URL::add_query_args_and_nonce(array( |
|
1337 | - 'page' => 'espresso_events', |
|
1338 | - 'action' => 'edit', |
|
1339 | - 'post' => $this->ID(), |
|
1340 | - ), |
|
1341 | - admin_url('admin.php') |
|
1342 | - ); |
|
1343 | - } |
|
1344 | - |
|
1345 | - |
|
1346 | - |
|
1347 | - /** |
|
1348 | - * Implementation for EEI_Admin_Links interface method. |
|
1349 | - * |
|
1350 | - * @see EEI_Admin_Links for comments |
|
1351 | - * @return string |
|
1352 | - */ |
|
1353 | - public function get_admin_settings_link() |
|
1354 | - { |
|
1355 | - return EEH_URL::add_query_args_and_nonce(array( |
|
1356 | - 'page' => 'espresso_events', |
|
1357 | - 'action' => 'default_event_settings', |
|
1358 | - ), |
|
1359 | - admin_url('admin.php') |
|
1360 | - ); |
|
1361 | - } |
|
1362 | - |
|
1363 | - |
|
1364 | - |
|
1365 | - /** |
|
1366 | - * Implementation for EEI_Admin_Links interface method. |
|
1367 | - * |
|
1368 | - * @see EEI_Admin_Links for comments |
|
1369 | - * @return string |
|
1370 | - */ |
|
1371 | - public function get_admin_overview_link() |
|
1372 | - { |
|
1373 | - return EEH_URL::add_query_args_and_nonce(array( |
|
1374 | - 'page' => 'espresso_events', |
|
1375 | - 'action' => 'default' |
|
1376 | - ), |
|
1377 | - admin_url('admin.php') |
|
1378 | - ); |
|
1379 | - } |
|
608 | + |
|
609 | + /** |
|
610 | + * @param $default_registration_status |
|
611 | + */ |
|
612 | + public function set_default_registration_status($default_registration_status) |
|
613 | + { |
|
614 | + $this->set('EVT_default_registration_status', $default_registration_status); |
|
615 | + } |
|
616 | + |
|
617 | + |
|
618 | + |
|
619 | + /** |
|
620 | + * @param $donations |
|
621 | + */ |
|
622 | + public function set_donations($donations) |
|
623 | + { |
|
624 | + $this->set('EVT_donations', $donations); |
|
625 | + } |
|
626 | + |
|
627 | + |
|
628 | + |
|
629 | + /** |
|
630 | + * Adds a venue to this event |
|
631 | + * |
|
632 | + * @param EE_Venue /int $venue_id_or_obj |
|
633 | + * @return EE_Venue |
|
634 | + */ |
|
635 | + public function add_venue($venue_id_or_obj) |
|
636 | + { |
|
637 | + return $this->_add_relation_to($venue_id_or_obj, 'Venue'); |
|
638 | + } |
|
639 | + |
|
640 | + |
|
641 | + |
|
642 | + /** |
|
643 | + * Removes a venue from the event |
|
644 | + * |
|
645 | + * @param EE_Venue /int $venue_id_or_obj |
|
646 | + * @return EE_Venue |
|
647 | + */ |
|
648 | + public function remove_venue($venue_id_or_obj) |
|
649 | + { |
|
650 | + return $this->_remove_relation_to($venue_id_or_obj, 'Venue'); |
|
651 | + } |
|
652 | + |
|
653 | + |
|
654 | + |
|
655 | + /** |
|
656 | + * Gets all the venues related ot the event. May provide additional $query_params if desired |
|
657 | + * |
|
658 | + * @param array $query_params like EEM_Base::get_all's $query_params |
|
659 | + * @return EE_Venue[] |
|
660 | + */ |
|
661 | + public function venues($query_params = array()) |
|
662 | + { |
|
663 | + return $this->get_many_related('Venue', $query_params); |
|
664 | + } |
|
665 | + |
|
666 | + |
|
667 | + |
|
668 | + /** |
|
669 | + * check if event id is present and if event is published |
|
670 | + * |
|
671 | + * @access public |
|
672 | + * @return boolean true yes, false no |
|
673 | + */ |
|
674 | + private function _has_ID_and_is_published() |
|
675 | + { |
|
676 | + // first check if event id is present and not NULL, then check if this event is published (or any of the equivalent "published" statuses) |
|
677 | + return ($this->ID() && $this->ID() !== null |
|
678 | + && ($this->status() == 'publish' |
|
679 | + || $this->status() |
|
680 | + == EEM_Event::sold_out |
|
681 | + || $this->status() == EEM_Event::postponed |
|
682 | + || $this->status() == EEM_Event::cancelled)) ? true : false; |
|
683 | + } |
|
684 | + |
|
685 | + |
|
686 | + |
|
687 | + /** |
|
688 | + * This simply compares the internal dates with NOW and determines if the event is upcoming or not. |
|
689 | + * |
|
690 | + * @access public |
|
691 | + * @return boolean true yes, false no |
|
692 | + */ |
|
693 | + public function is_upcoming() |
|
694 | + { |
|
695 | + // check if event id is present and if this event is published |
|
696 | + if ($this->is_inactive()) { |
|
697 | + return false; |
|
698 | + } |
|
699 | + // set initial value |
|
700 | + $upcoming = false; |
|
701 | + //next let's get all datetimes and loop through them |
|
702 | + $datetimes = $this->datetimes_in_chronological_order(); |
|
703 | + foreach ($datetimes as $datetime) { |
|
704 | + if ($datetime instanceof EE_Datetime) { |
|
705 | + //if this dtt is expired then we continue cause one of the other datetimes might be upcoming. |
|
706 | + if ($datetime->is_expired()) { |
|
707 | + continue; |
|
708 | + } |
|
709 | + //if this dtt is active then we return false. |
|
710 | + if ($datetime->is_active()) { |
|
711 | + return false; |
|
712 | + } |
|
713 | + //otherwise let's check upcoming status |
|
714 | + $upcoming = $datetime->is_upcoming(); |
|
715 | + } |
|
716 | + } |
|
717 | + return $upcoming; |
|
718 | + } |
|
719 | + |
|
720 | + |
|
721 | + |
|
722 | + /** |
|
723 | + * @return bool |
|
724 | + */ |
|
725 | + public function is_active() |
|
726 | + { |
|
727 | + // check if event id is present and if this event is published |
|
728 | + if ($this->is_inactive()) { |
|
729 | + return false; |
|
730 | + } |
|
731 | + // set initial value |
|
732 | + $active = false; |
|
733 | + //next let's get all datetimes and loop through them |
|
734 | + $datetimes = $this->datetimes_in_chronological_order(); |
|
735 | + foreach ($datetimes as $datetime) { |
|
736 | + if ($datetime instanceof EE_Datetime) { |
|
737 | + //if this dtt is expired then we continue cause one of the other datetimes might be active. |
|
738 | + if ($datetime->is_expired()) { |
|
739 | + continue; |
|
740 | + } |
|
741 | + //if this dtt is upcoming then we return false. |
|
742 | + if ($datetime->is_upcoming()) { |
|
743 | + return false; |
|
744 | + } |
|
745 | + //otherwise let's check active status |
|
746 | + $active = $datetime->is_active(); |
|
747 | + } |
|
748 | + } |
|
749 | + return $active; |
|
750 | + } |
|
751 | + |
|
752 | + |
|
753 | + |
|
754 | + /** |
|
755 | + * @return bool |
|
756 | + */ |
|
757 | + public function is_expired() |
|
758 | + { |
|
759 | + // check if event id is present and if this event is published |
|
760 | + if ($this->is_inactive()) { |
|
761 | + return false; |
|
762 | + } |
|
763 | + // set initial value |
|
764 | + $expired = false; |
|
765 | + //first let's get all datetimes and loop through them |
|
766 | + $datetimes = $this->datetimes_in_chronological_order(); |
|
767 | + foreach ($datetimes as $datetime) { |
|
768 | + if ($datetime instanceof EE_Datetime) { |
|
769 | + //if this dtt is upcoming or active then we return false. |
|
770 | + if ($datetime->is_upcoming() || $datetime->is_active()) { |
|
771 | + return false; |
|
772 | + } |
|
773 | + //otherwise let's check active status |
|
774 | + $expired = $datetime->is_expired(); |
|
775 | + } |
|
776 | + } |
|
777 | + return $expired; |
|
778 | + } |
|
779 | + |
|
780 | + |
|
781 | + |
|
782 | + /** |
|
783 | + * @return bool |
|
784 | + */ |
|
785 | + public function is_inactive() |
|
786 | + { |
|
787 | + // check if event id is present and if this event is published |
|
788 | + if ($this->_has_ID_and_is_published()) { |
|
789 | + return false; |
|
790 | + } |
|
791 | + return true; |
|
792 | + } |
|
793 | + |
|
794 | + |
|
795 | + |
|
796 | + /** |
|
797 | + * perform_sold_out_status_check |
|
798 | + * checks all of this events's datetime reg_limit - sold values to determine if ANY datetimes have spaces |
|
799 | + * available... if NOT, then the event status will get toggled to 'sold_out' |
|
800 | + * |
|
801 | + * @access public |
|
802 | + * @return bool return the ACTUAL sold out state. |
|
803 | + */ |
|
804 | + public function perform_sold_out_status_check() |
|
805 | + { |
|
806 | + // get all unexpired untrashed tickets |
|
807 | + $tickets = $this->tickets(array( |
|
808 | + array( |
|
809 | + 'TKT_end_date' => array('>=', EEM_Ticket::instance()->current_time_for_query('TKT_end_date')), |
|
810 | + 'TKT_deleted' => false, |
|
811 | + ), |
|
812 | + )); |
|
813 | + // if all the tickets are just expired, then don't update the event status to sold out |
|
814 | + if (empty($tickets)) { |
|
815 | + return true; |
|
816 | + } |
|
817 | + // set initial value |
|
818 | + $spaces_remaining = 0; |
|
819 | + foreach ($tickets as $ticket) { |
|
820 | + if ($ticket instanceof EE_Ticket) { |
|
821 | + $spaces_remaining += $ticket->qty('saleable'); |
|
822 | + } |
|
823 | + } |
|
824 | + if ($spaces_remaining === 0) { |
|
825 | + $this->set_status(EEM_Event::sold_out); |
|
826 | + if ( ! is_admin() || (is_admin() && defined('DOING_AJAX'))) { |
|
827 | + $this->save(); |
|
828 | + } |
|
829 | + $sold_out = true; |
|
830 | + } else { |
|
831 | + $sold_out = false; |
|
832 | + // was event previously marked as sold out ? |
|
833 | + if ($this->status() == EEM_Event::sold_out) { |
|
834 | + // revert status to previous value, if it was set |
|
835 | + $previous_event_status = $this->get_post_meta('_previous_event_status', true); |
|
836 | + if ($previous_event_status) { |
|
837 | + $this->set_status($previous_event_status); |
|
838 | + } |
|
839 | + } |
|
840 | + } |
|
841 | + //note: I considered changing the EEM_Event status away from sold_out if this status check reveals that it's no longer sold out (yet the status is still set as sold out) but the problem is... what do we change the status BACK to? We can't always assume that the previous event status was 'published' because this status check is always done in the admin and its entirely possible the event admin manually changes to sold_out status from some other status. We also don't want a draft event to become a "publish event" because the sold out check reveals its NOT sold out. |
|
842 | + // So I'll forgo the automatic switch away from sold out status for now and instead just return the $sold out status... so this check can be used to validate the TRUE sold out status regardless of what the Event status is set to. |
|
843 | + return $sold_out; |
|
844 | + } |
|
845 | + |
|
846 | + |
|
847 | + |
|
848 | + /** |
|
849 | + * This returns the total remaining spaces for sale on this event. |
|
850 | + * ############################ |
|
851 | + * VERY IMPORTANT FOR DEVELOPERS: |
|
852 | + * While included here, this method is still being tested internally, so its signature and behaviour COULD change. |
|
853 | + * While this comment block is in place, usage is at your own risk and know that it may change in future builds. |
|
854 | + * ############################ |
|
855 | + * |
|
856 | + * @uses EE_Event::total_available_spaces() |
|
857 | + * @return float|int (EE_INF is returned as float) |
|
858 | + */ |
|
859 | + public function spaces_remaining_for_sale() |
|
860 | + { |
|
861 | + //first get total available spaces including consideration for tickets that have already sold. |
|
862 | + $spaces_available = $this->total_available_spaces(true); |
|
863 | + //if total available = 0, then exit right away because that means everything is expired. |
|
864 | + if ($spaces_available === 0) { |
|
865 | + return 0; |
|
866 | + } |
|
867 | + //subtract total approved registrations from spaces available to get how many are remaining. |
|
868 | + $spots_taken = EEM_Registration::instance()->count(array( |
|
869 | + array( |
|
870 | + 'EVT_ID' => $this->ID(), |
|
871 | + 'STS_ID' => EEM_Registration::status_id_approved, |
|
872 | + ), |
|
873 | + ), 'REG_ID', true); |
|
874 | + $spaces_remaining = $spaces_available - $spots_taken; |
|
875 | + return $spaces_remaining > 0 ? $spaces_remaining : 0; |
|
876 | + } |
|
877 | + |
|
878 | + |
|
879 | + |
|
880 | + /** |
|
881 | + * This returns the total spaces available for an event while considering all the qtys on the tickets and the reg |
|
882 | + * limits on the datetimes attached to this event. |
|
883 | + * ############################ |
|
884 | + * VERY IMPORTANT FOR DEVELOPERS: |
|
885 | + * While included here, this method is still being tested internally, so its signature and behaviour COULD change. |
|
886 | + * While this comment block is in place, usage is at your own risk and know that it may change in future builds. |
|
887 | + * ############################ |
|
888 | + * Note: by "spaces available" we are not returning how many spaces remain. That is a calculation involving using |
|
889 | + * the value from this method and subtracting the approved registrations for the event. |
|
890 | + * |
|
891 | + * @param bool $current_total_available Whether to consider any tickets that have already sold in our |
|
892 | + * calculation. If this is false, then we return the most tickets that |
|
893 | + * could ever be sold for this event with the datetime and tickets |
|
894 | + * setup on the event under optimal selling conditions. Otherwise we |
|
895 | + * return a live calculation of spaces available based on tickets |
|
896 | + * sold. Depending on setup and stage of sales, this may appear to |
|
897 | + * equal remaining tickets. However, the more tickets are sold out, |
|
898 | + * the more accurate the "live" total is. |
|
899 | + * @return int|float (Note: if EE_INF is returned its considered a float by PHP) |
|
900 | + */ |
|
901 | + public function total_available_spaces($current_total_available = false) |
|
902 | + { |
|
903 | + $spaces_available = 0; |
|
904 | + //first get all tickets on the event and include expired tickets |
|
905 | + $tickets = $this->tickets(array('default_where_conditions' => 'none')); |
|
906 | + $ticket_sums = array(); |
|
907 | + $datetime_limits = array(); |
|
908 | + //loop through tickets and normalize them |
|
909 | + foreach ($tickets as $ticket) { |
|
910 | + $datetimes = $ticket->datetimes(array('order_by' => array('DTT_reg_limit' => 'ASC'))); |
|
911 | + if (empty($datetimes)) { |
|
912 | + continue; |
|
913 | + } |
|
914 | + //first datetime should be the lowest datetime |
|
915 | + $least_datetime = reset($datetimes); |
|
916 | + //lets reset the ticket quantity to be the lower of either the lowest datetime reg limit or the ticket quantity |
|
917 | + //IF datetimes sold (and we're not doing current live total available, then use spaces remaining for datetime, not reg_limit. |
|
918 | + if ($current_total_available) { |
|
919 | + if ($ticket->is_remaining()) { |
|
920 | + $remaining = $ticket->remaining(); |
|
921 | + } else { |
|
922 | + $spaces_available += $ticket->sold(); |
|
923 | + //and we don't cache this ticket to our list because its sold out. |
|
924 | + continue; |
|
925 | + } |
|
926 | + } else { |
|
927 | + $remaining = min($ticket->qty(), $least_datetime->reg_limit()); |
|
928 | + } |
|
929 | + //if $ticket_limit == infinity then let's drop out right away and just return that because any infinity amount trumps all other "available" amounts. |
|
930 | + if ($remaining === EE_INF) { |
|
931 | + return EE_INF; |
|
932 | + } |
|
933 | + //multiply normalized $tkt quantity by the number of datetimes on the ticket as the "sum" |
|
934 | + //also include the sum of all the datetime reg limits on the ticket for breaking ties. |
|
935 | + $ticket_sums[$ticket->ID()]['sum'] = $remaining * count($datetimes); |
|
936 | + $ticket_sums[$ticket->ID()]['datetime_sums'] = 0; |
|
937 | + foreach ($datetimes as $datetime) { |
|
938 | + if ($datetime->reg_limit() === EE_INF) { |
|
939 | + $ticket_sums[$ticket->ID()]['datetime_sums'] = EE_INF; |
|
940 | + } else { |
|
941 | + $ticket_sums[$ticket->ID()]['datetime_sums'] += $current_total_available |
|
942 | + ? $datetime->spaces_remaining() : $datetime->reg_limit(); |
|
943 | + } |
|
944 | + $datetime_limits[$datetime->ID()] = $current_total_available ? $datetime->spaces_remaining() |
|
945 | + : $datetime->reg_limit(); |
|
946 | + } |
|
947 | + $ticket_sums[$ticket->ID()]['ticket'] = $ticket; |
|
948 | + } |
|
949 | + //The order is sorted by lowest available first (which is calculated for each ticket by multiplying the normalized |
|
950 | + //ticket quantity by the number of datetimes on the ticket). For tie-breakers, then the next sort is based on the |
|
951 | + //ticket with the greatest sum of all remaining datetime->spaces_remaining() ( or $datetime->reg_limit() if not |
|
952 | + //$current_total_available ) for the datetimes on the ticket. |
|
953 | + usort($ticket_sums, function ($a, $b) { |
|
954 | + if ($a['sum'] == $b['sum']) { |
|
955 | + if ($a['datetime_sums'] == $b['datetime_sums']) { |
|
956 | + return 0; |
|
957 | + } |
|
958 | + return $a['datetime_sums'] < $b['datetime_sums'] ? 1 : -1; |
|
959 | + } |
|
960 | + return ($a['sum'] < $b['sum']) ? -1 : 1; |
|
961 | + }); |
|
962 | + //now let's loop through the sorted tickets and simulate sellouts |
|
963 | + foreach ($ticket_sums as $ticket_info) { |
|
964 | + if ($ticket_info['ticket'] instanceof EE_Ticket) { |
|
965 | + $datetimes = $ticket_info['ticket']->datetimes(array('order_by' => array('DTT_reg_limit' => 'ASC'))); |
|
966 | + //need to sort these $datetimes by remaining (only if $current_total_available) |
|
967 | + //setup datetimes for simulation |
|
968 | + $ticket_datetimes_remaining = array(); |
|
969 | + foreach ($datetimes as $datetime) { |
|
970 | + $ticket_datetimes_remaining[$datetime->ID()]['rem'] = $datetime_limits[$datetime->ID()]; |
|
971 | + $ticket_datetimes_remaining[$datetime->ID()]['datetime'] = $datetime; |
|
972 | + } |
|
973 | + usort($ticket_datetimes_remaining, function ($a, $b) { |
|
974 | + if ($a['rem'] == $b['rem']) { |
|
975 | + return 0; |
|
976 | + } |
|
977 | + return ($a['rem'] < $b['rem']) ? -1 : 1; |
|
978 | + }); |
|
979 | + //get the remaining on the first datetime (which should be the one with the least remaining) and that is |
|
980 | + //what we add to the spaces_available running total. Then we need to decrease the remaining on our datetime tracker. |
|
981 | + $lowest_datetime = reset($ticket_datetimes_remaining); |
|
982 | + //need to get the lower of; what the remaining is on the lowest datetime, and the remaining on the ticket. |
|
983 | + // If this ends up being 0 (because of previous tickets in our simulation selling out), then it has already |
|
984 | + // been tracked on $spaces available and this ticket is now sold out for the simulation, so we can continue |
|
985 | + // to the next ticket. |
|
986 | + if ($current_total_available) { |
|
987 | + $remaining = min($lowest_datetime['rem'], $ticket_info['ticket']->remaining()); |
|
988 | + } else { |
|
989 | + $remaining = min($lowest_datetime['rem'], $ticket_info['ticket']->qty()); |
|
990 | + } |
|
991 | + //if $remaining is infinite that means that all datetimes on this ticket are infinite but we've made it here because all |
|
992 | + //tickets have a quantity. So we don't have to track datetimes, we can just use ticket quantities for total |
|
993 | + //available. |
|
994 | + if ($remaining === EE_INF) { |
|
995 | + $spaces_available += $ticket_info['ticket']->qty(); |
|
996 | + continue; |
|
997 | + } |
|
998 | + //if ticket has sold amounts then we also need to add that (but only if doing live counts) |
|
999 | + if ($current_total_available) { |
|
1000 | + $spaces_available += $ticket_info['ticket']->sold(); |
|
1001 | + } |
|
1002 | + if ($remaining <= 0) { |
|
1003 | + continue; |
|
1004 | + } else { |
|
1005 | + $spaces_available += $remaining; |
|
1006 | + } |
|
1007 | + //loop through the datetimes and sell them out! |
|
1008 | + foreach ($ticket_datetimes_remaining as $datetime_info) { |
|
1009 | + if ($datetime_info['datetime'] instanceof EE_Datetime) { |
|
1010 | + $datetime_limits[$datetime_info['datetime']->ID()] += -$remaining; |
|
1011 | + } |
|
1012 | + } |
|
1013 | + } |
|
1014 | + } |
|
1015 | + return $spaces_available; |
|
1016 | + } |
|
1017 | + |
|
1018 | + |
|
1019 | + |
|
1020 | + /** |
|
1021 | + * Checks if the event is set to sold out |
|
1022 | + * |
|
1023 | + * @param bool $actual whether or not to perform calculations to not only figure the actual status but also to |
|
1024 | + * flip the status if necessary to sold out If false, we just check the existing status of the |
|
1025 | + * event |
|
1026 | + * @return boolean |
|
1027 | + */ |
|
1028 | + public function is_sold_out($actual = false) |
|
1029 | + { |
|
1030 | + if ( ! $actual) { |
|
1031 | + return $this->status() == EEM_Event::sold_out; |
|
1032 | + } else { |
|
1033 | + return $this->perform_sold_out_status_check(); |
|
1034 | + } |
|
1035 | + } |
|
1036 | + |
|
1037 | + |
|
1038 | + |
|
1039 | + /** |
|
1040 | + * Checks if the event is marked as postponed |
|
1041 | + * |
|
1042 | + * @return boolean |
|
1043 | + */ |
|
1044 | + public function is_postponed() |
|
1045 | + { |
|
1046 | + return $this->status() == EEM_Event::postponed; |
|
1047 | + } |
|
1048 | + |
|
1049 | + |
|
1050 | + |
|
1051 | + /** |
|
1052 | + * Checks if the event is marked as cancelled |
|
1053 | + * |
|
1054 | + * @return boolean |
|
1055 | + */ |
|
1056 | + public function is_cancelled() |
|
1057 | + { |
|
1058 | + return $this->status() == EEM_Event::cancelled; |
|
1059 | + } |
|
1060 | + |
|
1061 | + |
|
1062 | + |
|
1063 | + /** |
|
1064 | + * Get the logical active status in a hierarchical order for all the datetimes. Note |
|
1065 | + * Basically, we order the datetimes by EVT_start_date. Then first test on whether the event is published. If its |
|
1066 | + * NOT published then we test for whether its expired or not. IF it IS published then we test first on whether an |
|
1067 | + * event has any active dates. If no active dates then we check for any upcoming dates. If no upcoming dates then |
|
1068 | + * the event is considered expired. |
|
1069 | + * NOTE: this method does NOT calculate whether the datetimes are sold out when event is published. Sold Out is a |
|
1070 | + * status set on the EVENT when it is not published and thus is done |
|
1071 | + * |
|
1072 | + * @param bool $reset |
|
1073 | + * @return bool | string - based on EE_Datetime active constants or FALSE if error. |
|
1074 | + */ |
|
1075 | + public function get_active_status($reset = false) |
|
1076 | + { |
|
1077 | + // if the active status has already been set, then just use that value (unless we are resetting it) |
|
1078 | + if ( ! empty($this->_active_status) && ! $reset) { |
|
1079 | + return $this->_active_status; |
|
1080 | + } |
|
1081 | + //first check if event id is present on this object |
|
1082 | + if ( ! $this->ID()) { |
|
1083 | + return false; |
|
1084 | + } |
|
1085 | + $where_params_for_event = array(array('EVT_ID' => $this->ID())); |
|
1086 | + //if event is published: |
|
1087 | + if ($this->status() === 'publish') { |
|
1088 | + //active? |
|
1089 | + if (EEM_Datetime::instance()->get_datetime_count_for_status(EE_Datetime::active, $where_params_for_event) |
|
1090 | + > 0 |
|
1091 | + ) { |
|
1092 | + $this->_active_status = EE_Datetime::active; |
|
1093 | + } else { |
|
1094 | + //upcoming? |
|
1095 | + if (EEM_Datetime::instance() |
|
1096 | + ->get_datetime_count_for_status(EE_Datetime::upcoming, $where_params_for_event) > 0 |
|
1097 | + ) { |
|
1098 | + $this->_active_status = EE_Datetime::upcoming; |
|
1099 | + } else { |
|
1100 | + //expired? |
|
1101 | + if (EEM_Datetime::instance() |
|
1102 | + ->get_datetime_count_for_status(EE_Datetime::expired, $where_params_for_event) > 0 |
|
1103 | + ) { |
|
1104 | + $this->_active_status = EE_Datetime::expired; |
|
1105 | + } else { |
|
1106 | + //it would be odd if things make it this far because it basically means there are no datetime's |
|
1107 | + //attached to the event. So in this case it will just be considered inactive. |
|
1108 | + $this->_active_status = EE_Datetime::inactive; |
|
1109 | + } |
|
1110 | + } |
|
1111 | + } |
|
1112 | + } else { |
|
1113 | + //the event is not published, so let's just set it's active status according to its' post status |
|
1114 | + switch ($this->status()) { |
|
1115 | + case EEM_Event::sold_out : |
|
1116 | + $this->_active_status = EE_Datetime::sold_out; |
|
1117 | + break; |
|
1118 | + case EEM_Event::cancelled : |
|
1119 | + $this->_active_status = EE_Datetime::cancelled; |
|
1120 | + break; |
|
1121 | + case EEM_Event::postponed : |
|
1122 | + $this->_active_status = EE_Datetime::postponed; |
|
1123 | + break; |
|
1124 | + default : |
|
1125 | + $this->_active_status = EE_Datetime::inactive; |
|
1126 | + } |
|
1127 | + } |
|
1128 | + return $this->_active_status; |
|
1129 | + } |
|
1130 | + |
|
1131 | + |
|
1132 | + |
|
1133 | + /** |
|
1134 | + * pretty_active_status |
|
1135 | + * |
|
1136 | + * @access public |
|
1137 | + * @param boolean $echo whether to return (FALSE), or echo out the result (TRUE) |
|
1138 | + * @return mixed void|string |
|
1139 | + */ |
|
1140 | + public function pretty_active_status($echo = true) |
|
1141 | + { |
|
1142 | + $active_status = $this->get_active_status(); |
|
1143 | + $status = '<span class="ee-status event-active-status-' |
|
1144 | + . $active_status |
|
1145 | + . '">' |
|
1146 | + . EEH_Template::pretty_status($active_status, false, 'sentence') |
|
1147 | + . '</span>'; |
|
1148 | + if ($echo) { |
|
1149 | + echo $status; |
|
1150 | + return ''; |
|
1151 | + } |
|
1152 | + return $status; |
|
1153 | + } |
|
1154 | + |
|
1155 | + |
|
1156 | + |
|
1157 | + /** |
|
1158 | + * @return bool|int |
|
1159 | + */ |
|
1160 | + public function get_number_of_tickets_sold() |
|
1161 | + { |
|
1162 | + $tkt_sold = 0; |
|
1163 | + if ( ! $this->ID()) { |
|
1164 | + return 0; |
|
1165 | + } |
|
1166 | + $datetimes = $this->datetimes(); |
|
1167 | + foreach ($datetimes as $datetime) { |
|
1168 | + if ($datetime instanceof EE_Datetime) { |
|
1169 | + $tkt_sold += $datetime->sold(); |
|
1170 | + } |
|
1171 | + } |
|
1172 | + return $tkt_sold; |
|
1173 | + } |
|
1174 | + |
|
1175 | + |
|
1176 | + |
|
1177 | + /** |
|
1178 | + * This just returns a count of all the registrations for this event |
|
1179 | + * |
|
1180 | + * @access public |
|
1181 | + * @return int |
|
1182 | + */ |
|
1183 | + public function get_count_of_all_registrations() |
|
1184 | + { |
|
1185 | + return EEM_Event::instance()->count_related($this, 'Registration'); |
|
1186 | + } |
|
1187 | + |
|
1188 | + |
|
1189 | + |
|
1190 | + /** |
|
1191 | + * This returns the ticket with the earliest start time that is available for this event (across all datetimes |
|
1192 | + * attached to the event) |
|
1193 | + * |
|
1194 | + * @return EE_Ticket |
|
1195 | + */ |
|
1196 | + public function get_ticket_with_earliest_start_time() |
|
1197 | + { |
|
1198 | + $where['Datetime.EVT_ID'] = $this->ID(); |
|
1199 | + $query_params = array($where, 'order_by' => array('TKT_start_date' => 'ASC')); |
|
1200 | + return EE_Registry::instance()->load_model('Ticket')->get_one($query_params); |
|
1201 | + } |
|
1202 | + |
|
1203 | + |
|
1204 | + |
|
1205 | + /** |
|
1206 | + * This returns the ticket with the latest end time that is available for this event (across all datetimes attached |
|
1207 | + * to the event) |
|
1208 | + * |
|
1209 | + * @return EE_Ticket |
|
1210 | + */ |
|
1211 | + public function get_ticket_with_latest_end_time() |
|
1212 | + { |
|
1213 | + $where['Datetime.EVT_ID'] = $this->ID(); |
|
1214 | + $query_params = array($where, 'order_by' => array('TKT_end_date' => 'DESC')); |
|
1215 | + return EE_Registry::instance()->load_model('Ticket')->get_one($query_params); |
|
1216 | + } |
|
1217 | + |
|
1218 | + |
|
1219 | + |
|
1220 | + /** |
|
1221 | + * This returns whether there are any tickets on sale for this event. |
|
1222 | + * |
|
1223 | + * @return bool true = YES tickets on sale. |
|
1224 | + */ |
|
1225 | + public function tickets_on_sale() |
|
1226 | + { |
|
1227 | + $earliest_ticket = $this->get_ticket_with_earliest_start_time(); |
|
1228 | + $latest_ticket = $this->get_ticket_with_latest_end_time(); |
|
1229 | + if ( ! $latest_ticket instanceof EE_Ticket && ! $earliest_ticket instanceof EE_Ticket) { |
|
1230 | + return false; |
|
1231 | + } |
|
1232 | + //check on sale for these two tickets. |
|
1233 | + if ($latest_ticket->is_on_sale() || $earliest_ticket->is_on_sale()) { |
|
1234 | + return true; |
|
1235 | + } |
|
1236 | + return false; |
|
1237 | + } |
|
1238 | + |
|
1239 | + |
|
1240 | + |
|
1241 | + /** |
|
1242 | + * Gets the URL for viewing this event on the front-end. Overrides parent |
|
1243 | + * to check for an external URL first |
|
1244 | + * |
|
1245 | + * @return string |
|
1246 | + */ |
|
1247 | + public function get_permalink() |
|
1248 | + { |
|
1249 | + if ($this->external_url()) { |
|
1250 | + return $this->external_url(); |
|
1251 | + } else { |
|
1252 | + return parent::get_permalink(); |
|
1253 | + } |
|
1254 | + } |
|
1255 | + |
|
1256 | + |
|
1257 | + |
|
1258 | + /** |
|
1259 | + * Gets the first term for 'espresso_event_categories' we can find |
|
1260 | + * |
|
1261 | + * @param array $query_params like EEM_Base::get_all |
|
1262 | + * @return EE_Term |
|
1263 | + */ |
|
1264 | + public function first_event_category($query_params = array()) |
|
1265 | + { |
|
1266 | + $query_params[0]['Term_Taxonomy.taxonomy'] = 'espresso_event_categories'; |
|
1267 | + $query_params[0]['Term_Taxonomy.Event.EVT_ID'] = $this->ID(); |
|
1268 | + return EEM_Term::instance()->get_one($query_params); |
|
1269 | + } |
|
1270 | + |
|
1271 | + |
|
1272 | + |
|
1273 | + /** |
|
1274 | + * Gets all terms for 'espresso_event_categories' we can find |
|
1275 | + * |
|
1276 | + * @param array $query_params |
|
1277 | + * @return EE_Term[] |
|
1278 | + */ |
|
1279 | + public function get_all_event_categories($query_params = array()) |
|
1280 | + { |
|
1281 | + $query_params[0]['Term_Taxonomy.taxonomy'] = 'espresso_event_categories'; |
|
1282 | + $query_params[0]['Term_Taxonomy.Event.EVT_ID'] = $this->ID(); |
|
1283 | + return EEM_Term::instance()->get_all($query_params); |
|
1284 | + } |
|
1285 | + |
|
1286 | + |
|
1287 | + |
|
1288 | + /** |
|
1289 | + * Gets all the question groups, ordering them by QSG_order ascending |
|
1290 | + * |
|
1291 | + * @param array $query_params @see EEM_Base::get_all |
|
1292 | + * @return EE_Question_Group[] |
|
1293 | + */ |
|
1294 | + public function question_groups($query_params = array()) |
|
1295 | + { |
|
1296 | + $query_params = ! empty($query_params) ? $query_params : array('order_by' => array('QSG_order' => 'ASC')); |
|
1297 | + return $this->get_many_related('Question_Group', $query_params); |
|
1298 | + } |
|
1299 | + |
|
1300 | + |
|
1301 | + |
|
1302 | + /** |
|
1303 | + * Implementation for EEI_Has_Icon interface method. |
|
1304 | + * |
|
1305 | + * @see EEI_Visual_Representation for comments |
|
1306 | + * @return string |
|
1307 | + */ |
|
1308 | + public function get_icon() |
|
1309 | + { |
|
1310 | + return '<span class="dashicons dashicons-flag"></span>'; |
|
1311 | + } |
|
1312 | + |
|
1313 | + |
|
1314 | + |
|
1315 | + /** |
|
1316 | + * Implementation for EEI_Admin_Links interface method. |
|
1317 | + * |
|
1318 | + * @see EEI_Admin_Links for comments |
|
1319 | + * @return string |
|
1320 | + */ |
|
1321 | + public function get_admin_details_link() |
|
1322 | + { |
|
1323 | + return $this->get_admin_edit_link(); |
|
1324 | + } |
|
1325 | + |
|
1326 | + |
|
1327 | + |
|
1328 | + /** |
|
1329 | + * Implementation for EEI_Admin_Links interface method. |
|
1330 | + * |
|
1331 | + * @see EEI_Admin_Links for comments |
|
1332 | + * @return string |
|
1333 | + */ |
|
1334 | + public function get_admin_edit_link() |
|
1335 | + { |
|
1336 | + return EEH_URL::add_query_args_and_nonce(array( |
|
1337 | + 'page' => 'espresso_events', |
|
1338 | + 'action' => 'edit', |
|
1339 | + 'post' => $this->ID(), |
|
1340 | + ), |
|
1341 | + admin_url('admin.php') |
|
1342 | + ); |
|
1343 | + } |
|
1344 | + |
|
1345 | + |
|
1346 | + |
|
1347 | + /** |
|
1348 | + * Implementation for EEI_Admin_Links interface method. |
|
1349 | + * |
|
1350 | + * @see EEI_Admin_Links for comments |
|
1351 | + * @return string |
|
1352 | + */ |
|
1353 | + public function get_admin_settings_link() |
|
1354 | + { |
|
1355 | + return EEH_URL::add_query_args_and_nonce(array( |
|
1356 | + 'page' => 'espresso_events', |
|
1357 | + 'action' => 'default_event_settings', |
|
1358 | + ), |
|
1359 | + admin_url('admin.php') |
|
1360 | + ); |
|
1361 | + } |
|
1362 | + |
|
1363 | + |
|
1364 | + |
|
1365 | + /** |
|
1366 | + * Implementation for EEI_Admin_Links interface method. |
|
1367 | + * |
|
1368 | + * @see EEI_Admin_Links for comments |
|
1369 | + * @return string |
|
1370 | + */ |
|
1371 | + public function get_admin_overview_link() |
|
1372 | + { |
|
1373 | + return EEH_URL::add_query_args_and_nonce(array( |
|
1374 | + 'page' => 'espresso_events', |
|
1375 | + 'action' => 'default' |
|
1376 | + ), |
|
1377 | + admin_url('admin.php') |
|
1378 | + ); |
|
1379 | + } |
|
1380 | 1380 | |
1381 | 1381 | } |
@@ -300,7 +300,7 @@ discard block |
||
300 | 300 | */ |
301 | 301 | public function display_ticket_selector() |
302 | 302 | { |
303 | - return (bool)$this->get('EVT_display_ticket_selector'); |
|
303 | + return (bool) $this->get('EVT_display_ticket_selector'); |
|
304 | 304 | } |
305 | 305 | |
306 | 306 | |
@@ -950,7 +950,7 @@ discard block |
||
950 | 950 | //ticket quantity by the number of datetimes on the ticket). For tie-breakers, then the next sort is based on the |
951 | 951 | //ticket with the greatest sum of all remaining datetime->spaces_remaining() ( or $datetime->reg_limit() if not |
952 | 952 | //$current_total_available ) for the datetimes on the ticket. |
953 | - usort($ticket_sums, function ($a, $b) { |
|
953 | + usort($ticket_sums, function($a, $b) { |
|
954 | 954 | if ($a['sum'] == $b['sum']) { |
955 | 955 | if ($a['datetime_sums'] == $b['datetime_sums']) { |
956 | 956 | return 0; |
@@ -970,7 +970,7 @@ discard block |
||
970 | 970 | $ticket_datetimes_remaining[$datetime->ID()]['rem'] = $datetime_limits[$datetime->ID()]; |
971 | 971 | $ticket_datetimes_remaining[$datetime->ID()]['datetime'] = $datetime; |
972 | 972 | } |
973 | - usort($ticket_datetimes_remaining, function ($a, $b) { |
|
973 | + usort($ticket_datetimes_remaining, function($a, $b) { |
|
974 | 974 | if ($a['rem'] == $b['rem']) { |
975 | 975 | return 0; |
976 | 976 | } |
@@ -1135,7 +1135,7 @@ |
||
1135 | 1135 | * |
1136 | 1136 | * @access public |
1137 | 1137 | * @param boolean $echo whether to return (FALSE), or echo out the result (TRUE) |
1138 | - * @return mixed void|string |
|
1138 | + * @return string void|string |
|
1139 | 1139 | */ |
1140 | 1140 | public function pretty_active_status($echo = true) |
1141 | 1141 | { |
@@ -1,6 +1,6 @@ discard block |
||
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 | /** |
@@ -25,1090 +25,1090 @@ discard block |
||
25 | 25 | { |
26 | 26 | |
27 | 27 | |
28 | - /** |
|
29 | - * @Constructor |
|
30 | - * @param bool $routing indicate whether we want to just load the object and handle routing or just load the object. |
|
31 | - * @access public |
|
32 | - */ |
|
33 | - public function __construct($routing = true) |
|
34 | - { |
|
35 | - define('REGISTRATION_FORM_CAF_ADMIN', EE_CORE_CAF_ADMIN_EXTEND . 'registration_form' . DS); |
|
36 | - define('REGISTRATION_FORM_CAF_ASSETS_PATH', REGISTRATION_FORM_CAF_ADMIN . 'assets' . DS); |
|
37 | - define('REGISTRATION_FORM_CAF_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL . 'registration_form/assets/'); |
|
38 | - define('REGISTRATION_FORM_CAF_TEMPLATE_PATH', REGISTRATION_FORM_CAF_ADMIN . 'templates' . DS); |
|
39 | - define('REGISTRATION_FORM_CAF_TEMPLATE_URL', EE_CORE_CAF_ADMIN_EXTEND_URL . 'registration_form/templates/'); |
|
40 | - parent::__construct($routing); |
|
41 | - } |
|
42 | - |
|
43 | - |
|
44 | - protected function _extend_page_config() |
|
45 | - { |
|
46 | - $this->_admin_base_path = REGISTRATION_FORM_CAF_ADMIN; |
|
47 | - $qst_id = ! empty($this->_req_data['QST_ID']) && ! is_array($this->_req_data['QST_ID']) ? $this->_req_data['QST_ID'] : 0; |
|
48 | - $qsg_id = ! empty($this->_req_data['QSG_ID']) && ! is_array($this->_req_data['QSG_ID']) ? $this->_req_data['QSG_ID'] : 0; |
|
49 | - |
|
50 | - $new_page_routes = array( |
|
51 | - 'question_groups' => array( |
|
52 | - 'func' => '_question_groups_overview_list_table', |
|
53 | - 'capability' => 'ee_read_question_groups', |
|
54 | - ), |
|
55 | - 'add_question' => array( |
|
56 | - 'func' => '_edit_question', |
|
57 | - 'capability' => 'ee_edit_questions', |
|
58 | - ), |
|
59 | - 'insert_question' => array( |
|
60 | - 'func' => '_insert_or_update_question', |
|
61 | - 'args' => array('new_question' => true), |
|
62 | - 'capability' => 'ee_edit_questions', |
|
63 | - 'noheader' => true, |
|
64 | - ), |
|
65 | - 'duplicate_question' => array( |
|
66 | - 'func' => '_duplicate_question', |
|
67 | - 'capability' => 'ee_edit_questions', |
|
68 | - 'noheader' => true, |
|
69 | - ), |
|
70 | - 'trash_question' => array( |
|
71 | - 'func' => '_trash_question', |
|
72 | - 'capability' => 'ee_delete_question', |
|
73 | - 'obj_id' => $qst_id, |
|
74 | - 'noheader' => true, |
|
75 | - ), |
|
76 | - |
|
77 | - 'restore_question' => array( |
|
78 | - 'func' => '_trash_or_restore_questions', |
|
79 | - 'capability' => 'ee_delete_question', |
|
80 | - 'obj_id' => $qst_id, |
|
81 | - 'args' => array('trash' => false), |
|
82 | - 'noheader' => true, |
|
83 | - ), |
|
84 | - |
|
85 | - 'delete_question' => array( |
|
86 | - 'func' => '_delete_question', |
|
87 | - 'capability' => 'ee_delete_question', |
|
88 | - 'obj_id' => $qst_id, |
|
89 | - 'noheader' => true, |
|
90 | - ), |
|
91 | - |
|
92 | - 'trash_questions' => array( |
|
93 | - 'func' => '_trash_or_restore_questions', |
|
94 | - 'capability' => 'ee_delete_questions', |
|
95 | - 'args' => array('trash' => true), |
|
96 | - 'noheader' => true, |
|
97 | - ), |
|
98 | - |
|
99 | - 'restore_questions' => array( |
|
100 | - 'func' => '_trash_or_restore_questions', |
|
101 | - 'capability' => 'ee_delete_questions', |
|
102 | - 'args' => array('trash' => false), |
|
103 | - 'noheader' => true, |
|
104 | - ), |
|
105 | - |
|
106 | - 'delete_questions' => array( |
|
107 | - 'func' => '_delete_questions', |
|
108 | - 'args' => array(), |
|
109 | - 'capability' => 'ee_delete_questions', |
|
110 | - 'noheader' => true, |
|
111 | - ), |
|
112 | - |
|
113 | - 'add_question_group' => array( |
|
114 | - 'func' => '_edit_question_group', |
|
115 | - 'capability' => 'ee_edit_question_groups', |
|
116 | - ), |
|
117 | - |
|
118 | - 'edit_question_group' => array( |
|
119 | - 'func' => '_edit_question_group', |
|
120 | - 'capability' => 'ee_edit_question_group', |
|
121 | - 'obj_id' => $qsg_id, |
|
122 | - 'args' => array('edit'), |
|
123 | - ), |
|
124 | - |
|
125 | - 'delete_question_groups' => array( |
|
126 | - 'func' => '_delete_question_groups', |
|
127 | - 'capability' => 'ee_delete_question_groups', |
|
128 | - 'noheader' => true, |
|
129 | - ), |
|
130 | - |
|
131 | - 'delete_question_group' => array( |
|
132 | - 'func' => '_delete_question_groups', |
|
133 | - 'capability' => 'ee_delete_question_group', |
|
134 | - 'obj_id' => $qsg_id, |
|
135 | - 'noheader' => true, |
|
136 | - ), |
|
137 | - |
|
138 | - 'trash_question_group' => array( |
|
139 | - 'func' => '_trash_or_restore_question_groups', |
|
140 | - 'args' => array('trash' => true), |
|
141 | - 'capability' => 'ee_delete_question_group', |
|
142 | - 'obj_id' => $qsg_id, |
|
143 | - 'noheader' => true, |
|
144 | - ), |
|
145 | - |
|
146 | - 'restore_question_group' => array( |
|
147 | - 'func' => '_trash_or_restore_question_groups', |
|
148 | - 'args' => array('trash' => false), |
|
149 | - 'capability' => 'ee_delete_question_group', |
|
150 | - 'obj_id' => $qsg_id, |
|
151 | - 'noheader' => true, |
|
152 | - ), |
|
153 | - |
|
154 | - 'insert_question_group' => array( |
|
155 | - 'func' => '_insert_or_update_question_group', |
|
156 | - 'args' => array('new_question_group' => true), |
|
157 | - 'capability' => 'ee_edit_question_groups', |
|
158 | - 'noheader' => true, |
|
159 | - ), |
|
160 | - |
|
161 | - 'update_question_group' => array( |
|
162 | - 'func' => '_insert_or_update_question_group', |
|
163 | - 'args' => array('new_question_group' => false), |
|
164 | - 'capability' => 'ee_edit_question_group', |
|
165 | - 'obj_id' => $qsg_id, |
|
166 | - 'noheader' => true, |
|
167 | - ), |
|
168 | - |
|
169 | - 'trash_question_groups' => array( |
|
170 | - 'func' => '_trash_or_restore_question_groups', |
|
171 | - 'args' => array('trash' => true), |
|
172 | - 'capability' => 'ee_delete_question_groups', |
|
173 | - 'noheader' => array('trash' => false), |
|
174 | - ), |
|
175 | - |
|
176 | - 'restore_question_groups' => array( |
|
177 | - 'func' => '_trash_or_restore_question_groups', |
|
178 | - 'args' => array('trash' => false), |
|
179 | - 'capability' => 'ee_delete_question_groups', |
|
180 | - 'noheader' => true, |
|
181 | - ), |
|
182 | - |
|
183 | - |
|
184 | - 'espresso_update_question_group_order' => array( |
|
185 | - 'func' => 'update_question_group_order', |
|
186 | - 'capability' => 'ee_edit_question_groups', |
|
187 | - 'noheader' => true, |
|
188 | - ), |
|
189 | - |
|
190 | - 'view_reg_form_settings' => array( |
|
191 | - 'func' => '_reg_form_settings', |
|
192 | - 'capability' => 'manage_options', |
|
193 | - ), |
|
194 | - |
|
195 | - 'update_reg_form_settings' => array( |
|
196 | - 'func' => '_update_reg_form_settings', |
|
197 | - 'capability' => 'manage_options', |
|
198 | - 'noheader' => true, |
|
199 | - ), |
|
200 | - ); |
|
201 | - $this->_page_routes = array_merge($this->_page_routes, $new_page_routes); |
|
202 | - |
|
203 | - $new_page_config = array( |
|
204 | - |
|
205 | - 'question_groups' => array( |
|
206 | - 'nav' => array( |
|
207 | - 'label' => esc_html__('Question Groups', 'event_espresso'), |
|
208 | - 'order' => 20, |
|
209 | - ), |
|
210 | - 'list_table' => 'Registration_Form_Question_Groups_Admin_List_Table', |
|
211 | - 'help_tabs' => array( |
|
212 | - 'registration_form_question_groups_help_tab' => array( |
|
213 | - 'title' => esc_html__('Question Groups', 'event_espresso'), |
|
214 | - 'filename' => 'registration_form_question_groups', |
|
215 | - ), |
|
216 | - 'registration_form_question_groups_table_column_headings_help_tab' => array( |
|
217 | - 'title' => esc_html__('Question Groups Table Column Headings', 'event_espresso'), |
|
218 | - 'filename' => 'registration_form_question_groups_table_column_headings', |
|
219 | - ), |
|
220 | - 'registration_form_question_groups_views_bulk_actions_search_help_tab' => array( |
|
221 | - 'title' => esc_html__('Question Groups Views & Bulk Actions & Search', 'event_espresso'), |
|
222 | - 'filename' => 'registration_form_question_groups_views_bulk_actions_search', |
|
223 | - ), |
|
224 | - ), |
|
225 | - 'help_tour' => array('Registration_Form_Question_Groups_Help_Tour'), |
|
226 | - 'metaboxes' => $this->_default_espresso_metaboxes, |
|
227 | - 'require_nonce' => false, |
|
228 | - 'qtips' => array( |
|
229 | - 'EE_Registration_Form_Tips', |
|
230 | - ), |
|
231 | - ), |
|
232 | - |
|
233 | - 'add_question' => array( |
|
234 | - 'nav' => array( |
|
235 | - 'label' => esc_html__('Add Question', 'event_espresso'), |
|
236 | - 'order' => 5, |
|
237 | - 'persistent' => false, |
|
238 | - ), |
|
239 | - 'metaboxes' => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')), |
|
240 | - 'help_tabs' => array( |
|
241 | - 'registration_form_add_question_help_tab' => array( |
|
242 | - 'title' => esc_html__('Add Question', 'event_espresso'), |
|
243 | - 'filename' => 'registration_form_add_question', |
|
244 | - ), |
|
245 | - ), |
|
246 | - 'help_tour' => array('Registration_Form_Add_Question_Help_Tour'), |
|
247 | - 'require_nonce' => false, |
|
248 | - ), |
|
249 | - |
|
250 | - 'add_question_group' => array( |
|
251 | - 'nav' => array( |
|
252 | - 'label' => esc_html__('Add Question Group', 'event_espresso'), |
|
253 | - 'order' => 5, |
|
254 | - 'persistent' => false, |
|
255 | - ), |
|
256 | - 'metaboxes' => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')), |
|
257 | - 'help_tabs' => array( |
|
258 | - 'registration_form_add_question_group_help_tab' => array( |
|
259 | - 'title' => esc_html__('Add Question Group', 'event_espresso'), |
|
260 | - 'filename' => 'registration_form_add_question_group', |
|
261 | - ), |
|
262 | - ), |
|
263 | - 'help_tour' => array('Registration_Form_Add_Question_Group_Help_Tour'), |
|
264 | - 'require_nonce' => false, |
|
265 | - ), |
|
266 | - |
|
267 | - 'edit_question_group' => array( |
|
268 | - 'nav' => array( |
|
269 | - 'label' => esc_html__('Edit Question Group', 'event_espresso'), |
|
270 | - 'order' => 5, |
|
271 | - 'persistent' => false, |
|
272 | - 'url' => isset($this->_req_data['question_group_id']) ? add_query_arg(array('question_group_id' => $this->_req_data['question_group_id']), |
|
273 | - $this->_current_page_view_url) : $this->_admin_base_url, |
|
274 | - ), |
|
275 | - 'metaboxes' => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')), |
|
276 | - 'help_tabs' => array( |
|
277 | - 'registration_form_edit_question_group_help_tab' => array( |
|
278 | - 'title' => esc_html__('Edit Question Group', 'event_espresso'), |
|
279 | - 'filename' => 'registration_form_edit_question_group', |
|
280 | - ), |
|
281 | - ), |
|
282 | - 'help_tour' => array('Registration_Form_Edit_Question_Group_Help_Tour'), |
|
283 | - 'require_nonce' => false, |
|
284 | - ), |
|
285 | - |
|
286 | - 'view_reg_form_settings' => array( |
|
287 | - 'nav' => array( |
|
288 | - 'label' => esc_html__('Reg Form Settings', 'event_espresso'), |
|
289 | - 'order' => 40, |
|
290 | - ), |
|
291 | - 'labels' => array( |
|
292 | - 'publishbox' => esc_html__('Update Settings', 'event_espresso'), |
|
293 | - ), |
|
294 | - 'metaboxes' => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')), |
|
295 | - 'help_tabs' => array( |
|
296 | - 'registration_form_reg_form_settings_help_tab' => array( |
|
297 | - 'title' => esc_html__('Registration Form Settings', 'event_espresso'), |
|
298 | - 'filename' => 'registration_form_reg_form_settings', |
|
299 | - ), |
|
300 | - ), |
|
301 | - 'help_tour' => array('Registration_Form_Settings_Help_Tour'), |
|
302 | - 'require_nonce' => false, |
|
303 | - ), |
|
304 | - |
|
305 | - ); |
|
306 | - $this->_page_config = array_merge($this->_page_config, $new_page_config); |
|
307 | - |
|
308 | - //change the list table we're going to use so it's the NEW list table! |
|
309 | - $this->_page_config['default']['list_table'] = 'Extend_Registration_Form_Questions_Admin_List_Table'; |
|
310 | - |
|
311 | - |
|
312 | - //additional labels |
|
313 | - $new_labels = array( |
|
314 | - 'add_question' => esc_html__('Add New Question', 'event_espresso'), |
|
315 | - 'delete_question' => esc_html__('Delete Question', 'event_espresso'), |
|
316 | - 'add_question_group' => esc_html__('Add New Question Group', 'event_espresso'), |
|
317 | - 'edit_question_group' => esc_html__('Edit Question Group', 'event_espresso'), |
|
318 | - 'delete_question_group' => esc_html__('Delete Question Group', 'event_espresso'), |
|
319 | - ); |
|
320 | - $this->_labels['buttons'] = array_merge($this->_labels['buttons'], $new_labels); |
|
321 | - |
|
322 | - } |
|
323 | - |
|
324 | - |
|
325 | - protected function _ajax_hooks() |
|
326 | - { |
|
327 | - add_action('wp_ajax_espresso_update_question_group_order', array($this, 'update_question_group_order')); |
|
328 | - } |
|
329 | - |
|
330 | - |
|
331 | - public function load_scripts_styles_question_groups() |
|
332 | - { |
|
333 | - wp_enqueue_script('espresso_ajax_table_sorting'); |
|
334 | - } |
|
335 | - |
|
336 | - |
|
337 | - public function load_scripts_styles_add_question_group() |
|
338 | - { |
|
339 | - $this->load_scripts_styles_forms(); |
|
340 | - $this->load_sortable_question_script(); |
|
341 | - } |
|
342 | - |
|
343 | - public function load_scripts_styles_edit_question_group() |
|
344 | - { |
|
345 | - $this->load_scripts_styles_forms(); |
|
346 | - $this->load_sortable_question_script(); |
|
347 | - } |
|
348 | - |
|
349 | - |
|
350 | - /** |
|
351 | - * registers and enqueues script for questions |
|
352 | - * |
|
353 | - * @return void |
|
354 | - */ |
|
355 | - public function load_sortable_question_script() |
|
356 | - { |
|
357 | - wp_register_script('ee-question-sortable', REGISTRATION_FORM_CAF_ASSETS_URL . 'ee_question_order.js', |
|
358 | - array('jquery-ui-sortable'), EVENT_ESPRESSO_VERSION, true); |
|
359 | - wp_enqueue_script('ee-question-sortable'); |
|
360 | - } |
|
361 | - |
|
362 | - |
|
363 | - protected function _set_list_table_views_default() |
|
364 | - { |
|
365 | - $this->_views = array( |
|
366 | - 'all' => array( |
|
367 | - 'slug' => 'all', |
|
368 | - 'label' => esc_html__('View All Questions', 'event_espresso'), |
|
369 | - 'count' => 0, |
|
370 | - 'bulk_action' => array( |
|
371 | - 'trash_questions' => esc_html__('Trash', 'event_espresso'), |
|
372 | - ), |
|
373 | - ), |
|
374 | - ); |
|
375 | - |
|
376 | - if (EE_Registry::instance()->CAP->current_user_can('ee_delete_questions', |
|
377 | - 'espresso_registration_form_trash_questions') |
|
378 | - ) { |
|
379 | - $this->_views['trash'] = array( |
|
380 | - 'slug' => 'trash', |
|
381 | - 'label' => esc_html__('Trash', 'event_espresso'), |
|
382 | - 'count' => 0, |
|
383 | - 'bulk_action' => array( |
|
384 | - 'delete_questions' => esc_html__('Delete Permanently', 'event_espresso'), |
|
385 | - 'restore_questions' => esc_html__('Restore', 'event_espresso'), |
|
386 | - ), |
|
387 | - ); |
|
388 | - } |
|
389 | - } |
|
390 | - |
|
391 | - |
|
392 | - protected function _set_list_table_views_question_groups() |
|
393 | - { |
|
394 | - $this->_views = array( |
|
395 | - 'all' => array( |
|
396 | - 'slug' => 'all', |
|
397 | - 'label' => esc_html__('All', 'event_espresso'), |
|
398 | - 'count' => 0, |
|
399 | - 'bulk_action' => array( |
|
400 | - 'trash_question_groups' => esc_html__('Trash', 'event_espresso'), |
|
401 | - ), |
|
402 | - ), |
|
403 | - ); |
|
404 | - |
|
405 | - if (EE_Registry::instance()->CAP->current_user_can('ee_delete_question_groups', |
|
406 | - 'espresso_registration_form_trash_question_groups') |
|
407 | - ) { |
|
408 | - $this->_views['trash'] = array( |
|
409 | - 'slug' => 'trash', |
|
410 | - 'label' => esc_html__('Trash', 'event_espresso'), |
|
411 | - 'count' => 0, |
|
412 | - 'bulk_action' => array( |
|
413 | - 'delete_question_groups' => esc_html__('Delete Permanently', 'event_espresso'), |
|
414 | - 'restore_question_groups' => esc_html__('Restore', 'event_espresso'), |
|
415 | - ), |
|
416 | - ); |
|
417 | - } |
|
418 | - } |
|
419 | - |
|
420 | - |
|
421 | - protected function _questions_overview_list_table() |
|
422 | - { |
|
423 | - $this->_admin_page_title .= ' ' . $this->get_action_link_or_button( |
|
424 | - 'add_question', |
|
425 | - 'add_question', |
|
426 | - array(), |
|
427 | - 'add-new-h2' |
|
428 | - ); |
|
429 | - parent::_questions_overview_list_table(); |
|
430 | - } |
|
431 | - |
|
432 | - |
|
433 | - protected function _question_groups_overview_list_table() |
|
434 | - { |
|
435 | - $this->_search_btn_label = esc_html__('Question Groups', 'event_espresso'); |
|
436 | - $this->_admin_page_title .= ' ' . $this->get_action_link_or_button( |
|
437 | - 'add_question_group', |
|
438 | - 'add_question_group', |
|
439 | - array(), |
|
440 | - 'add-new-h2' |
|
441 | - ); |
|
442 | - $this->display_admin_list_table_page_with_sidebar(); |
|
443 | - } |
|
444 | - |
|
445 | - |
|
446 | - protected function _delete_question() |
|
447 | - { |
|
448 | - $success = $this->_delete_items($this->_question_model); |
|
449 | - $this->_redirect_after_action( |
|
450 | - $success, |
|
451 | - $this->_question_model->item_name($success), |
|
452 | - 'deleted', |
|
453 | - array('action' => 'default', 'status' => 'all') |
|
454 | - ); |
|
455 | - } |
|
456 | - |
|
457 | - |
|
458 | - protected function _delete_questions() |
|
459 | - { |
|
460 | - $success = $this->_delete_items($this->_question_model); |
|
461 | - $this->_redirect_after_action( |
|
462 | - $success, |
|
463 | - $this->_question_model->item_name($success), |
|
464 | - 'deleted permanently', |
|
465 | - array('action' => 'default', 'status' => 'trash') |
|
466 | - ); |
|
467 | - } |
|
468 | - |
|
469 | - |
|
470 | - /** |
|
471 | - * Performs the deletion of a single or multiple questions or question groups. |
|
472 | - * |
|
473 | - * @param EEM_Soft_Delete_Base $model |
|
474 | - * @return int number of items deleted permanently |
|
475 | - */ |
|
476 | - private function _delete_items(EEM_Soft_Delete_Base $model) |
|
477 | - { |
|
478 | - $success = 0; |
|
479 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
480 | - if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) { |
|
481 | - // if array has more than one element than success message should be plural |
|
482 | - $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1; |
|
483 | - // cycle thru bulk action checkboxes |
|
484 | - while (list($ID, $value) = each($this->_req_data['checkbox'])) { |
|
485 | - if (! $this->_delete_item($ID, $model)) { |
|
486 | - $success = 0; |
|
487 | - } |
|
488 | - } |
|
489 | - |
|
490 | - } elseif (! empty($this->_req_data['QSG_ID'])) { |
|
491 | - $success = $this->_delete_item($this->_req_data['QSG_ID'], $model); |
|
492 | - |
|
493 | - } elseif (! empty($this->_req_data['QST_ID'])) { |
|
494 | - $success = $this->_delete_item($this->_req_data['QST_ID'], $model); |
|
495 | - } else { |
|
496 | - EE_Error::add_error(sprintf(esc_html__("No Questions or Question Groups were selected for deleting. This error usually shows when you've attempted to delete via bulk action but there were no selections.", |
|
497 | - "event_espresso")), __FILE__, __FUNCTION__, __LINE__); |
|
498 | - } |
|
499 | - return $success; |
|
500 | - } |
|
501 | - |
|
502 | - /** |
|
503 | - * Deletes the specified question (and its associated question options) or question group |
|
504 | - * |
|
505 | - * @param int $id |
|
506 | - * @param EEM_Soft_Delete_Base $model |
|
507 | - * @return boolean |
|
508 | - */ |
|
509 | - protected function _delete_item($id, $model) |
|
510 | - { |
|
511 | - if ($model instanceof EEM_Question) { |
|
512 | - EEM_Question_Option::instance()->delete_permanently(array(array('QST_ID' => absint($id)))); |
|
513 | - } |
|
514 | - return $model->delete_permanently_by_ID(absint($id)); |
|
515 | - } |
|
516 | - |
|
517 | - |
|
518 | - /****************************** QUESTION GROUPS ******************************/ |
|
519 | - |
|
520 | - |
|
521 | - protected function _edit_question_group($type = 'add') |
|
522 | - { |
|
523 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
524 | - $ID = isset($this->_req_data['QSG_ID']) && ! empty($this->_req_data['QSG_ID']) ? absint($this->_req_data['QSG_ID']) : false; |
|
525 | - |
|
526 | - switch ($this->_req_action) { |
|
527 | - case 'add_question_group' : |
|
528 | - $this->_admin_page_title = esc_html__('Add Question Group', 'event_espresso'); |
|
529 | - break; |
|
530 | - case 'edit_question_group' : |
|
531 | - $this->_admin_page_title = esc_html__('Edit Question Group', 'event_espresso'); |
|
532 | - break; |
|
533 | - default : |
|
534 | - $this->_admin_page_title = ucwords(str_replace('_', ' ', $this->_req_action)); |
|
535 | - } |
|
536 | - // add ID to title if editing |
|
537 | - $this->_admin_page_title = $ID ? $this->_admin_page_title . ' # ' . $ID : $this->_admin_page_title; |
|
538 | - if ($ID) { |
|
539 | - /** @var EE_Question_Group $questionGroup */ |
|
540 | - $questionGroup = $this->_question_group_model->get_one_by_ID($ID); |
|
541 | - $additional_hidden_fields = array('QSG_ID' => array('type' => 'hidden', 'value' => $ID)); |
|
542 | - $this->_set_add_edit_form_tags('update_question_group', $additional_hidden_fields); |
|
543 | - } else { |
|
544 | - /** @var EE_Question_Group $questionGroup */ |
|
545 | - $questionGroup = EEM_Question_Group::instance()->create_default_object(); |
|
546 | - $questionGroup->set_order_to_latest(); |
|
547 | - $this->_set_add_edit_form_tags('insert_question_group'); |
|
548 | - } |
|
549 | - $this->_template_args['values'] = $this->_yes_no_values; |
|
550 | - $this->_template_args['all_questions'] = $questionGroup->questions_in_and_not_in_group(); |
|
551 | - $this->_template_args['QSG_ID'] = $ID ? $ID : true; |
|
552 | - $this->_template_args['question_group'] = $questionGroup; |
|
553 | - |
|
554 | - $redirect_URL = add_query_arg(array('action' => 'question_groups'), $this->_admin_base_url); |
|
555 | - $this->_set_publish_post_box_vars('id', $ID, false, $redirect_URL); |
|
556 | - $this->_template_args['admin_page_content'] = EEH_Template::display_template(REGISTRATION_FORM_CAF_TEMPLATE_PATH . 'question_groups_main_meta_box.template.php', |
|
557 | - $this->_template_args, true); |
|
558 | - |
|
559 | - // the details template wrapper |
|
560 | - $this->display_admin_page_with_sidebar(); |
|
561 | - } |
|
562 | - |
|
563 | - |
|
564 | - protected function _delete_question_groups() |
|
565 | - { |
|
566 | - $success = $this->_delete_items($this->_question_group_model); |
|
567 | - $this->_redirect_after_action($success, $this->_question_group_model->item_name($success), |
|
568 | - 'deleted permanently', array('action' => 'question_groups', 'status' => 'trash')); |
|
569 | - } |
|
570 | - |
|
571 | - |
|
572 | - /** |
|
573 | - * @param bool $new_question_group |
|
574 | - */ |
|
575 | - protected function _insert_or_update_question_group($new_question_group = true) |
|
576 | - { |
|
577 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
578 | - $set_column_values = $this->_set_column_values_for($this->_question_group_model); |
|
579 | - if ($new_question_group) { |
|
580 | - $QSG_ID = $this->_question_group_model->insert($set_column_values); |
|
581 | - $success = $QSG_ID ? 1 : 0; |
|
582 | - } else { |
|
583 | - $QSG_ID = absint($this->_req_data['QSG_ID']); |
|
584 | - unset($set_column_values['QSG_ID']); |
|
585 | - $success = $this->_question_group_model->update($set_column_values, array(array('QSG_ID' => $QSG_ID))); |
|
586 | - } |
|
587 | - $phone_question_id = EEM_Question::instance()->get_Question_ID_from_system_string(EEM_Attendee::system_question_phone); |
|
588 | - // update the existing related questions |
|
589 | - // BUT FIRST... delete the phone question from the Question_Group_Question if it is being added to this question group (therefore removed from the existing group) |
|
590 | - if (isset($this->_req_data['questions'], $this->_req_data['questions'][$phone_question_id])) { |
|
591 | - // delete where QST ID = system phone question ID and Question Group ID is NOT this group |
|
592 | - EEM_Question_Group_Question::instance()->delete(array( |
|
593 | - array( |
|
594 | - 'QST_ID' => $phone_question_id, |
|
595 | - 'QSG_ID' => array('!=', $QSG_ID), |
|
596 | - ), |
|
597 | - )); |
|
598 | - } |
|
599 | - /** @type EE_Question_Group $question_group */ |
|
600 | - $question_group = $this->_question_group_model->get_one_by_ID($QSG_ID); |
|
601 | - $questions = $question_group->questions(); |
|
602 | - // make sure system phone question is added to list of questions for this group |
|
603 | - if (! isset($questions[$phone_question_id])) { |
|
604 | - $questions[$phone_question_id] = EEM_Question::instance()->get_one_by_ID($phone_question_id); |
|
605 | - } |
|
606 | - |
|
607 | - foreach ($questions as $question_ID => $question) { |
|
608 | - // first we always check for order. |
|
609 | - if (! empty($this->_req_data['question_orders'][$question_ID])) { |
|
610 | - //update question order |
|
611 | - $question_group->update_question_order($question_ID, $this->_req_data['question_orders'][$question_ID]); |
|
612 | - } |
|
613 | - |
|
614 | - // then we always check if adding or removing. |
|
615 | - if (isset($this->_req_data['questions'], $this->_req_data['questions'][$question_ID])) { |
|
616 | - $question_group->add_question($question_ID); |
|
617 | - } else { |
|
618 | - // not found, remove it (but only if not a system question for the personal group with the exception of lname system question - we allow removal of it) |
|
619 | - if ( |
|
620 | - in_array( |
|
621 | - $question->system_ID(), |
|
622 | - EEM_Question::instance()->required_system_questions_in_system_question_group($question_group->system_group()) |
|
623 | - ) |
|
624 | - ) { |
|
625 | - continue; |
|
626 | - } else { |
|
627 | - $question_group->remove_question($question_ID); |
|
628 | - } |
|
629 | - } |
|
630 | - } |
|
631 | - // save new related questions |
|
632 | - if (isset($this->_req_data['questions'])) { |
|
633 | - foreach ($this->_req_data['questions'] as $QST_ID) { |
|
634 | - $question_group->add_question($QST_ID); |
|
635 | - if (isset($this->_req_data['question_orders'][$QST_ID])) { |
|
636 | - $question_group->update_question_order($QST_ID, $this->_req_data['question_orders'][$QST_ID]); |
|
637 | - } |
|
638 | - } |
|
639 | - } |
|
640 | - |
|
641 | - if ($success !== false) { |
|
642 | - $msg = $new_question_group ? sprintf(esc_html__('The %s has been created', 'event_espresso'), |
|
643 | - $this->_question_group_model->item_name()) : sprintf(esc_html__('The %s has been updated', |
|
644 | - 'event_espresso'), $this->_question_group_model->item_name()); |
|
645 | - EE_Error::add_success($msg); |
|
646 | - } |
|
647 | - $this->_redirect_after_action(false, '', '', array('action' => 'edit_question_group', 'QSG_ID' => $QSG_ID), |
|
648 | - true); |
|
649 | - |
|
650 | - } |
|
651 | - |
|
652 | - /** |
|
653 | - * duplicates a question and all its question options and redirects to the new question. |
|
654 | - */ |
|
655 | - public function _duplicate_question() |
|
656 | - { |
|
657 | - $question_ID = (int)$this->_req_data['QST_ID']; |
|
658 | - $question = EEM_Question::instance()->get_one_by_ID($question_ID); |
|
659 | - if ($question instanceof EE_Question) { |
|
660 | - $new_question = $question->duplicate(); |
|
661 | - if ($new_question instanceof EE_Question) { |
|
662 | - $this->_redirect_after_action(true, esc_html__('Question', 'event_espresso'), |
|
663 | - esc_html__('Duplicated', 'event_espresso'), |
|
664 | - array('action' => 'edit_question', 'QST_ID' => $new_question->ID()), true); |
|
665 | - } else { |
|
666 | - global $wpdb; |
|
667 | - EE_Error::add_error(sprintf(esc_html__('Could not duplicate question with ID %1$d because: %2$s', |
|
668 | - 'event_espresso'), $question_ID, $wpdb->last_error), __FILE__, __FUNCTION__, __LINE__); |
|
669 | - $this->_redirect_after_action(false, '', '', array('action' => 'default'), false); |
|
670 | - } |
|
671 | - } else { |
|
672 | - EE_Error::add_error(sprintf(esc_html__('Could not duplicate question with ID %d because it didn\'t exist!', |
|
673 | - 'event_espresso'), $question_ID), __FILE__, __FUNCTION__, __LINE__); |
|
674 | - $this->_redirect_after_action(false, '', '', array('action' => 'default'), false); |
|
675 | - } |
|
676 | - } |
|
677 | - |
|
678 | - |
|
679 | - /** |
|
680 | - * @param bool $trash |
|
681 | - */ |
|
682 | - protected function _trash_or_restore_question_groups($trash = true) |
|
683 | - { |
|
684 | - $this->_trash_or_restore_items($this->_question_group_model, $trash); |
|
685 | - } |
|
686 | - |
|
687 | - |
|
688 | - /** |
|
689 | - *_trash_question |
|
690 | - */ |
|
691 | - protected function _trash_question() |
|
692 | - { |
|
693 | - $success = $this->_question_model->delete_by_ID((int)$this->_req_data['QST_ID']); |
|
694 | - $query_args = array('action' => 'default', 'status' => 'all'); |
|
695 | - $this->_redirect_after_action($success, $this->_question_model->item_name($success), 'trashed', $query_args); |
|
696 | - } |
|
697 | - |
|
698 | - |
|
699 | - /** |
|
700 | - * @param bool $trash |
|
701 | - */ |
|
702 | - protected function _trash_or_restore_questions($trash = true) |
|
703 | - { |
|
704 | - $this->_trash_or_restore_items($this->_question_model, $trash); |
|
705 | - } |
|
706 | - |
|
707 | - |
|
708 | - /** |
|
709 | - * Internally used to delete or restore items, using the request data. Meant to be |
|
710 | - * flexible between question or question groups |
|
711 | - * |
|
712 | - * @param EEM_Soft_Delete_Base $model |
|
713 | - * @param boolean $trash whether to trash or restore |
|
714 | - */ |
|
715 | - private function _trash_or_restore_items(EEM_Soft_Delete_Base $model, $trash = true) |
|
716 | - { |
|
717 | - |
|
718 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
719 | - |
|
720 | - $success = 1; |
|
721 | - //Checkboxes |
|
722 | - //echo "trash $trash"; |
|
723 | - //var_dump($this->_req_data['checkbox']);die; |
|
724 | - if (isset($this->_req_data['checkbox'])) { |
|
725 | - if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) { |
|
726 | - // if array has more than one element than success message should be plural |
|
727 | - $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1; |
|
728 | - // cycle thru bulk action checkboxes |
|
729 | - while (list($ID, $value) = each($this->_req_data['checkbox'])) { |
|
730 | - if (! $model->delete_or_restore_by_ID($trash, absint($ID))) { |
|
731 | - $success = 0; |
|
732 | - } |
|
733 | - } |
|
734 | - |
|
735 | - } else { |
|
736 | - // grab single id and delete |
|
737 | - $ID = absint($this->_req_data['checkbox']); |
|
738 | - if (! $model->delete_or_restore_by_ID($trash, $ID)) { |
|
739 | - $success = 0; |
|
740 | - } |
|
741 | - } |
|
742 | - |
|
743 | - } else { |
|
744 | - // delete via trash link |
|
745 | - // grab single id and delete |
|
746 | - $ID = absint($this->_req_data[$model->primary_key_name()]); |
|
747 | - if (! $model->delete_or_restore_by_ID($trash, $ID)) { |
|
748 | - $success = 0; |
|
749 | - } |
|
750 | - |
|
751 | - } |
|
752 | - |
|
753 | - |
|
754 | - $action = $model instanceof EEM_Question ? 'default' : 'question_groups';//strtolower( $model->item_name(2) ); |
|
755 | - //echo "action :$action"; |
|
756 | - //$action = 'questions' ? 'default' : $action; |
|
757 | - if ($trash) { |
|
758 | - $action_desc = 'trashed'; |
|
759 | - $status = 'trash'; |
|
760 | - } else { |
|
761 | - $action_desc = 'restored'; |
|
762 | - $status = 'all'; |
|
763 | - } |
|
764 | - $this->_redirect_after_action($success, $model->item_name($success), $action_desc, |
|
765 | - array('action' => $action, 'status' => $status)); |
|
766 | - } |
|
767 | - |
|
768 | - |
|
769 | - /** |
|
770 | - * @param $per_page |
|
771 | - * @param int $current_page |
|
772 | - * @param bool|false $count |
|
773 | - * @return \EE_Soft_Delete_Base_Class[]|int |
|
774 | - */ |
|
775 | - public function get_trashed_questions($per_page, $current_page = 1, $count = false) |
|
776 | - { |
|
777 | - $query_params = $this->get_query_params(EEM_Question::instance(), $per_page, $current_page); |
|
778 | - |
|
779 | - if ($count) { |
|
780 | - //note: this a subclass of EEM_Soft_Delete_Base, so this is actually only getting non-trashed items |
|
781 | - $where = isset($query_params[0]) ? array($query_params[0]) : array(); |
|
782 | - $results = $this->_question_model->count_deleted($where); |
|
783 | - } else { |
|
784 | - //note: this a subclass of EEM_Soft_Delete_Base, so this is actually only getting non-trashed items |
|
785 | - $results = $this->_question_model->get_all_deleted($query_params); |
|
786 | - } |
|
787 | - return $results; |
|
788 | - } |
|
789 | - |
|
790 | - |
|
791 | - /** |
|
792 | - * @param $per_page |
|
793 | - * @param int $current_page |
|
794 | - * @param bool|false $count |
|
795 | - * @return \EE_Soft_Delete_Base_Class[] |
|
796 | - */ |
|
797 | - public function get_question_groups($per_page, $current_page = 1, $count = false) |
|
798 | - { |
|
799 | - $questionGroupModel = EEM_Question_Group::instance(); |
|
800 | - $query_params = $this->get_query_params($questionGroupModel, $per_page, $current_page); |
|
801 | - if ($count) { |
|
802 | - $where = isset($query_params[0]) ? array($query_params[0]) : array(); |
|
803 | - $results = $questionGroupModel->count($where); |
|
804 | - } else { |
|
805 | - $results = $questionGroupModel->get_all($query_params); |
|
806 | - } |
|
807 | - return $results; |
|
808 | - } |
|
809 | - |
|
810 | - |
|
811 | - /** |
|
812 | - * @param $per_page |
|
813 | - * @param int $current_page |
|
814 | - * @param bool $count |
|
815 | - * @return \EE_Soft_Delete_Base_Class[]|int |
|
816 | - */ |
|
817 | - public function get_trashed_question_groups($per_page, $current_page = 1, $count = false) |
|
818 | - { |
|
819 | - $questionGroupModel = EEM_Question_Group::instance(); |
|
820 | - $query_params = $this->get_query_params($questionGroupModel, $per_page, $current_page); |
|
821 | - if ($count) { |
|
822 | - $where = isset($query_params[0]) ? array($query_params[0]) : array(); |
|
823 | - $query_params['limit'] = null; |
|
824 | - $results = $questionGroupModel->count_deleted($where); |
|
825 | - } else { |
|
826 | - $results = $questionGroupModel->get_all_deleted($query_params); |
|
827 | - } |
|
828 | - return $results; |
|
829 | - } |
|
830 | - |
|
831 | - |
|
832 | - /** |
|
833 | - * method for performing updates to question order |
|
834 | - * |
|
835 | - * @return array results array |
|
836 | - */ |
|
837 | - public function update_question_group_order() |
|
838 | - { |
|
839 | - |
|
840 | - $success = esc_html__('Question group order was updated successfully.', 'event_espresso'); |
|
841 | - |
|
842 | - // grab our row IDs |
|
843 | - $row_ids = isset($this->_req_data['row_ids']) && ! empty($this->_req_data['row_ids']) |
|
844 | - ? explode(',', rtrim($this->_req_data['row_ids'], ',')) |
|
845 | - : array(); |
|
846 | - |
|
847 | - $perpage = ! empty($this->_req_data['perpage']) |
|
848 | - ? (int)$this->_req_data['perpage'] |
|
849 | - : null; |
|
850 | - $curpage = ! empty($this->_req_data['curpage']) |
|
851 | - ? (int)$this->_req_data['curpage'] |
|
852 | - : null; |
|
853 | - |
|
854 | - if (! empty($row_ids)) { |
|
855 | - //figure out where we start the row_id count at for the current page. |
|
856 | - $qsgcount = empty($curpage) ? 0 : ($curpage - 1) * $perpage; |
|
857 | - |
|
858 | - $row_count = count($row_ids); |
|
859 | - for ($i = 0; $i < $row_count; $i++) { |
|
860 | - //Update the questions when re-ordering |
|
861 | - $updated = EEM_Question_Group::instance()->update( |
|
862 | - array('QSG_order' => $qsgcount), |
|
863 | - array(array('QSG_ID' => $row_ids[$i])) |
|
864 | - ); |
|
865 | - if ($updated === false) { |
|
866 | - $success = false; |
|
867 | - } |
|
868 | - $qsgcount++; |
|
869 | - } |
|
870 | - } else { |
|
871 | - $success = false; |
|
872 | - } |
|
873 | - |
|
874 | - $errors = ! $success |
|
875 | - ? esc_html__('An error occurred. The question group order was not updated.', 'event_espresso') |
|
876 | - : false; |
|
877 | - |
|
878 | - echo wp_json_encode(array('return_data' => false, 'success' => $success, 'errors' => $errors)); |
|
879 | - die(); |
|
880 | - |
|
881 | - } |
|
882 | - |
|
883 | - |
|
884 | - |
|
885 | - /*************************************** REGISTRATION SETTINGS ***************************************/ |
|
886 | - |
|
887 | - |
|
888 | - /** |
|
889 | - * _reg_form_settings |
|
890 | - * |
|
891 | - * @throws \EE_Error |
|
892 | - */ |
|
893 | - protected function _reg_form_settings() |
|
894 | - { |
|
895 | - $this->_template_args['values'] = $this->_yes_no_values; |
|
896 | - add_action( |
|
897 | - 'AHEE__Extend_Registration_Form_Admin_Page___reg_form_settings_template', |
|
898 | - array($this, 'email_validation_settings_form'), |
|
899 | - 2 |
|
900 | - ); |
|
901 | - $this->_template_args = (array)apply_filters( |
|
902 | - 'FHEE__Extend_Registration_Form_Admin_Page___reg_form_settings___template_args', |
|
903 | - $this->_template_args |
|
904 | - ); |
|
905 | - $this->_set_add_edit_form_tags('update_reg_form_settings'); |
|
906 | - $this->_set_publish_post_box_vars(null, false, false, null, false); |
|
907 | - $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
908 | - REGISTRATION_FORM_CAF_TEMPLATE_PATH . 'reg_form_settings.template.php', |
|
909 | - $this->_template_args, |
|
910 | - true |
|
911 | - ); |
|
912 | - $this->display_admin_page_with_sidebar(); |
|
913 | - } |
|
914 | - |
|
915 | - |
|
916 | - /** |
|
917 | - * _update_reg_form_settings |
|
918 | - */ |
|
919 | - protected function _update_reg_form_settings() |
|
920 | - { |
|
921 | - EE_Registry::instance()->CFG->registration = $this->update_email_validation_settings_form( |
|
922 | - EE_Registry::instance()->CFG->registration |
|
923 | - ); |
|
924 | - EE_Registry::instance()->CFG->registration = apply_filters( |
|
925 | - 'FHEE__Extend_Registration_Form_Admin_Page___update_reg_form_settings__CFG_registration', |
|
926 | - EE_Registry::instance()->CFG->registration |
|
927 | - ); |
|
928 | - $success = $this->_update_espresso_configuration( |
|
929 | - esc_html__('Registration Form Options', 'event_espresso'), |
|
930 | - EE_Registry::instance()->CFG, |
|
931 | - __FILE__, __FUNCTION__, __LINE__ |
|
932 | - ); |
|
933 | - $this->_redirect_after_action($success, esc_html__('Registration Form Options', 'event_espresso'), 'updated', |
|
934 | - array('action' => 'view_reg_form_settings')); |
|
935 | - } |
|
936 | - |
|
937 | - |
|
938 | - /** |
|
939 | - * email_validation_settings_form |
|
940 | - * |
|
941 | - * @access public |
|
942 | - * @return void |
|
943 | - * @throws \EE_Error |
|
944 | - */ |
|
945 | - public function email_validation_settings_form() |
|
946 | - { |
|
947 | - echo $this->_email_validation_settings_form()->get_html(); |
|
948 | - } |
|
949 | - |
|
950 | - |
|
951 | - /** |
|
952 | - * _email_validation_settings_form |
|
953 | - * |
|
954 | - * @access protected |
|
955 | - * @return EE_Form_Section_Proper |
|
956 | - * @throws \EE_Error |
|
957 | - */ |
|
958 | - protected function _email_validation_settings_form() |
|
959 | - { |
|
960 | - return new EE_Form_Section_Proper( |
|
961 | - array( |
|
962 | - 'name' => 'email_validation_settings', |
|
963 | - 'html_id' => 'email_validation_settings', |
|
964 | - 'layout_strategy' => new EE_Admin_Two_Column_Layout(), |
|
965 | - 'subsections' => array( |
|
966 | - 'email_validation_hdr' => new EE_Form_Section_HTML( |
|
967 | - EEH_HTML::h2(esc_html__('Email Validation Settings', 'event_espresso')) |
|
968 | - ), |
|
969 | - 'email_validation_level' => new EE_Select_Input( |
|
970 | - array( |
|
971 | - 'basic' => esc_html__('Basic', 'event_espresso'), |
|
972 | - 'wp_default' => esc_html__('WordPress Default', 'event_espresso'), |
|
973 | - 'i18n' => esc_html__('International', 'event_espresso'), |
|
974 | - 'i18n_dns' => esc_html__('International + DNS Check', 'event_espresso'), |
|
975 | - ), |
|
976 | - array( |
|
977 | - 'html_label_text' => esc_html__('Email Validation Level', 'event_espresso') |
|
978 | - . EEH_Template::get_help_tab_link('email_validation_info'), |
|
979 | - 'html_help_text' => esc_html__('These levels range from basic validation ( ie: [email protected] ) to more advanced checks against international email addresses (ie: üñîçøðé@example.com ) with additional MX and A record checks to confirm the domain actually exists. More information on on each level can be found within the help section.', |
|
980 | - 'event_espresso'), |
|
981 | - 'default' => isset(EE_Registry::instance()->CFG->registration->email_validation_level) |
|
982 | - ? EE_Registry::instance()->CFG->registration->email_validation_level |
|
983 | - : 'wp_default', |
|
984 | - 'required' => false, |
|
985 | - ) |
|
986 | - ), |
|
987 | - ), |
|
988 | - ) |
|
989 | - ); |
|
990 | - } |
|
991 | - |
|
992 | - |
|
993 | - /** |
|
994 | - * update_email_validation_settings_form |
|
995 | - * |
|
996 | - * @access public |
|
997 | - * @param \EE_Registration_Config $EE_Registration_Config |
|
998 | - * @return \EE_Registration_Config |
|
999 | - */ |
|
1000 | - public function update_email_validation_settings_form(EE_Registration_Config $EE_Registration_Config) |
|
1001 | - { |
|
1002 | - $prev_email_validation_level = $EE_Registration_Config->email_validation_level; |
|
1003 | - try { |
|
1004 | - $email_validation_settings_form = $this->_email_validation_settings_form(); |
|
1005 | - // if not displaying a form, then check for form submission |
|
1006 | - if ($email_validation_settings_form->was_submitted()) { |
|
1007 | - // capture form data |
|
1008 | - $email_validation_settings_form->receive_form_submission(); |
|
1009 | - // validate form data |
|
1010 | - if ($email_validation_settings_form->is_valid()) { |
|
1011 | - // grab validated data from form |
|
1012 | - $valid_data = $email_validation_settings_form->valid_data(); |
|
1013 | - if (isset($valid_data['email_validation_level'])) { |
|
1014 | - $email_validation_level = $valid_data['email_validation_level']; |
|
1015 | - // now if they want to use international email addresses |
|
1016 | - if ($email_validation_level === 'i18n' || $email_validation_level === 'i18n_dns') { |
|
1017 | - // in case we need to reset their email validation level, |
|
1018 | - // make sure that the previous value wasn't already set to one of the i18n options. |
|
1019 | - if ($prev_email_validation_level === 'i18n' || $prev_email_validation_level === 'i18n_dns') { |
|
1020 | - // if so, then reset it back to "basic" since that is the only other option that, |
|
1021 | - // despite offering poor validation, supports i18n email addresses |
|
1022 | - $prev_email_validation_level = 'basic'; |
|
1023 | - } |
|
1024 | - // confirm our i18n email validation will work on the server |
|
1025 | - if (! $this->_verify_pcre_support($EE_Registration_Config, $email_validation_level)) { |
|
1026 | - // or reset email validation level to previous value |
|
1027 | - $email_validation_level = $prev_email_validation_level; |
|
1028 | - } |
|
1029 | - } |
|
1030 | - $EE_Registration_Config->email_validation_level = $email_validation_level; |
|
1031 | - } else { |
|
1032 | - EE_Error::add_error( |
|
1033 | - esc_html__( |
|
1034 | - 'Invalid or missing Email Validation settings. Please refresh the form and try again.', |
|
1035 | - 'event_espresso' |
|
1036 | - ), |
|
1037 | - __FILE__, __FUNCTION__, __LINE__ |
|
1038 | - ); |
|
1039 | - } |
|
1040 | - } else { |
|
1041 | - if ($email_validation_settings_form->submission_error_message() !== '') { |
|
1042 | - EE_Error::add_error( |
|
1043 | - $email_validation_settings_form->submission_error_message(), |
|
1044 | - __FILE__, __FUNCTION__, __LINE__ |
|
1045 | - ); |
|
1046 | - } |
|
1047 | - } |
|
1048 | - } |
|
1049 | - } catch (EE_Error $e) { |
|
1050 | - $e->get_error(); |
|
1051 | - } |
|
1052 | - return $EE_Registration_Config; |
|
1053 | - } |
|
1054 | - |
|
1055 | - |
|
1056 | - /** |
|
1057 | - * confirms that the server's PHP version has the PCRE module enabled, |
|
1058 | - * and that the PCRE version works with our i18n email validation |
|
1059 | - * |
|
1060 | - * @param \EE_Registration_Config $EE_Registration_Config |
|
1061 | - * @param string $email_validation_level |
|
1062 | - * @return bool |
|
1063 | - */ |
|
1064 | - private function _verify_pcre_support(EE_Registration_Config $EE_Registration_Config, $email_validation_level) |
|
1065 | - { |
|
1066 | - // first check that PCRE is enabled |
|
1067 | - if (! defined('PREG_BAD_UTF8_ERROR')) { |
|
1068 | - EE_Error::add_error( |
|
1069 | - sprintf( |
|
1070 | - esc_html__( |
|
1071 | - 'We\'re sorry, but it appears that your server\'s version of PHP was not compiled with PCRE unicode support.%1$sPlease contact your hosting company and ask them whether the PCRE compiled with your version of PHP on your server can be been built with the "--enable-unicode-properties" and "--enable-utf8" configuration switches to enable more complex regex expressions.%1$sIf they are unable, or unwilling to do so, then your server will not support international email addresses using UTF-8 unicode characters. This means you will either have to lower your email validation level to "Basic" or "WordPress Default", or switch to a hosting company that has/can enable PCRE unicode support on the server.', |
|
1072 | - 'event_espresso' |
|
1073 | - ), |
|
1074 | - '<br />' |
|
1075 | - ), |
|
1076 | - __FILE__, |
|
1077 | - __FUNCTION__, |
|
1078 | - __LINE__ |
|
1079 | - ); |
|
1080 | - return false; |
|
1081 | - } else { |
|
1082 | - // PCRE support is enabled, but let's still |
|
1083 | - // perform a test to see if the server will support it. |
|
1084 | - // but first, save the updated validation level to the config, |
|
1085 | - // so that the validation strategy picks it up. |
|
1086 | - // this will get bumped back down if it doesn't work |
|
1087 | - $EE_Registration_Config->email_validation_level = $email_validation_level; |
|
1088 | - try { |
|
1089 | - $email_validator = new EE_Email_Validation_Strategy(); |
|
1090 | - $i18n_email_address = apply_filters( |
|
1091 | - 'FHEE__Extend_Registration_Form_Admin_Page__update_email_validation_settings_form__i18n_email_address', |
|
1092 | - 'jägerjü[email protected]' |
|
1093 | - ); |
|
1094 | - $email_validator->validate($i18n_email_address); |
|
1095 | - } catch (Exception $e) { |
|
1096 | - EE_Error::add_error( |
|
1097 | - sprintf( |
|
1098 | - esc_html__( |
|
1099 | - 'We\'re sorry, but it appears that your server\'s configuration will not support the "International" or "International + DNS Check" email validation levels.%1$sTo correct this issue, please consult with your hosting company regarding your server\'s PCRE settings.%1$sIt is recommended that your PHP version be configured to use PCRE 8.10 or newer.%1$sMore information regarding PCRE versions and installation can be found here: %2$s', |
|
1100 | - 'event_espresso' |
|
1101 | - ), |
|
1102 | - '<br />', |
|
1103 | - '<a href="http://php.net/manual/en/pcre.installation.php" target="_blank">http://php.net/manual/en/pcre.installation.php</a>' |
|
1104 | - ), |
|
1105 | - __FILE__, __FUNCTION__, __LINE__ |
|
1106 | - ); |
|
1107 | - return false; |
|
1108 | - } |
|
1109 | - } |
|
1110 | - return true; |
|
1111 | - } |
|
28 | + /** |
|
29 | + * @Constructor |
|
30 | + * @param bool $routing indicate whether we want to just load the object and handle routing or just load the object. |
|
31 | + * @access public |
|
32 | + */ |
|
33 | + public function __construct($routing = true) |
|
34 | + { |
|
35 | + define('REGISTRATION_FORM_CAF_ADMIN', EE_CORE_CAF_ADMIN_EXTEND . 'registration_form' . DS); |
|
36 | + define('REGISTRATION_FORM_CAF_ASSETS_PATH', REGISTRATION_FORM_CAF_ADMIN . 'assets' . DS); |
|
37 | + define('REGISTRATION_FORM_CAF_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL . 'registration_form/assets/'); |
|
38 | + define('REGISTRATION_FORM_CAF_TEMPLATE_PATH', REGISTRATION_FORM_CAF_ADMIN . 'templates' . DS); |
|
39 | + define('REGISTRATION_FORM_CAF_TEMPLATE_URL', EE_CORE_CAF_ADMIN_EXTEND_URL . 'registration_form/templates/'); |
|
40 | + parent::__construct($routing); |
|
41 | + } |
|
42 | + |
|
43 | + |
|
44 | + protected function _extend_page_config() |
|
45 | + { |
|
46 | + $this->_admin_base_path = REGISTRATION_FORM_CAF_ADMIN; |
|
47 | + $qst_id = ! empty($this->_req_data['QST_ID']) && ! is_array($this->_req_data['QST_ID']) ? $this->_req_data['QST_ID'] : 0; |
|
48 | + $qsg_id = ! empty($this->_req_data['QSG_ID']) && ! is_array($this->_req_data['QSG_ID']) ? $this->_req_data['QSG_ID'] : 0; |
|
49 | + |
|
50 | + $new_page_routes = array( |
|
51 | + 'question_groups' => array( |
|
52 | + 'func' => '_question_groups_overview_list_table', |
|
53 | + 'capability' => 'ee_read_question_groups', |
|
54 | + ), |
|
55 | + 'add_question' => array( |
|
56 | + 'func' => '_edit_question', |
|
57 | + 'capability' => 'ee_edit_questions', |
|
58 | + ), |
|
59 | + 'insert_question' => array( |
|
60 | + 'func' => '_insert_or_update_question', |
|
61 | + 'args' => array('new_question' => true), |
|
62 | + 'capability' => 'ee_edit_questions', |
|
63 | + 'noheader' => true, |
|
64 | + ), |
|
65 | + 'duplicate_question' => array( |
|
66 | + 'func' => '_duplicate_question', |
|
67 | + 'capability' => 'ee_edit_questions', |
|
68 | + 'noheader' => true, |
|
69 | + ), |
|
70 | + 'trash_question' => array( |
|
71 | + 'func' => '_trash_question', |
|
72 | + 'capability' => 'ee_delete_question', |
|
73 | + 'obj_id' => $qst_id, |
|
74 | + 'noheader' => true, |
|
75 | + ), |
|
76 | + |
|
77 | + 'restore_question' => array( |
|
78 | + 'func' => '_trash_or_restore_questions', |
|
79 | + 'capability' => 'ee_delete_question', |
|
80 | + 'obj_id' => $qst_id, |
|
81 | + 'args' => array('trash' => false), |
|
82 | + 'noheader' => true, |
|
83 | + ), |
|
84 | + |
|
85 | + 'delete_question' => array( |
|
86 | + 'func' => '_delete_question', |
|
87 | + 'capability' => 'ee_delete_question', |
|
88 | + 'obj_id' => $qst_id, |
|
89 | + 'noheader' => true, |
|
90 | + ), |
|
91 | + |
|
92 | + 'trash_questions' => array( |
|
93 | + 'func' => '_trash_or_restore_questions', |
|
94 | + 'capability' => 'ee_delete_questions', |
|
95 | + 'args' => array('trash' => true), |
|
96 | + 'noheader' => true, |
|
97 | + ), |
|
98 | + |
|
99 | + 'restore_questions' => array( |
|
100 | + 'func' => '_trash_or_restore_questions', |
|
101 | + 'capability' => 'ee_delete_questions', |
|
102 | + 'args' => array('trash' => false), |
|
103 | + 'noheader' => true, |
|
104 | + ), |
|
105 | + |
|
106 | + 'delete_questions' => array( |
|
107 | + 'func' => '_delete_questions', |
|
108 | + 'args' => array(), |
|
109 | + 'capability' => 'ee_delete_questions', |
|
110 | + 'noheader' => true, |
|
111 | + ), |
|
112 | + |
|
113 | + 'add_question_group' => array( |
|
114 | + 'func' => '_edit_question_group', |
|
115 | + 'capability' => 'ee_edit_question_groups', |
|
116 | + ), |
|
117 | + |
|
118 | + 'edit_question_group' => array( |
|
119 | + 'func' => '_edit_question_group', |
|
120 | + 'capability' => 'ee_edit_question_group', |
|
121 | + 'obj_id' => $qsg_id, |
|
122 | + 'args' => array('edit'), |
|
123 | + ), |
|
124 | + |
|
125 | + 'delete_question_groups' => array( |
|
126 | + 'func' => '_delete_question_groups', |
|
127 | + 'capability' => 'ee_delete_question_groups', |
|
128 | + 'noheader' => true, |
|
129 | + ), |
|
130 | + |
|
131 | + 'delete_question_group' => array( |
|
132 | + 'func' => '_delete_question_groups', |
|
133 | + 'capability' => 'ee_delete_question_group', |
|
134 | + 'obj_id' => $qsg_id, |
|
135 | + 'noheader' => true, |
|
136 | + ), |
|
137 | + |
|
138 | + 'trash_question_group' => array( |
|
139 | + 'func' => '_trash_or_restore_question_groups', |
|
140 | + 'args' => array('trash' => true), |
|
141 | + 'capability' => 'ee_delete_question_group', |
|
142 | + 'obj_id' => $qsg_id, |
|
143 | + 'noheader' => true, |
|
144 | + ), |
|
145 | + |
|
146 | + 'restore_question_group' => array( |
|
147 | + 'func' => '_trash_or_restore_question_groups', |
|
148 | + 'args' => array('trash' => false), |
|
149 | + 'capability' => 'ee_delete_question_group', |
|
150 | + 'obj_id' => $qsg_id, |
|
151 | + 'noheader' => true, |
|
152 | + ), |
|
153 | + |
|
154 | + 'insert_question_group' => array( |
|
155 | + 'func' => '_insert_or_update_question_group', |
|
156 | + 'args' => array('new_question_group' => true), |
|
157 | + 'capability' => 'ee_edit_question_groups', |
|
158 | + 'noheader' => true, |
|
159 | + ), |
|
160 | + |
|
161 | + 'update_question_group' => array( |
|
162 | + 'func' => '_insert_or_update_question_group', |
|
163 | + 'args' => array('new_question_group' => false), |
|
164 | + 'capability' => 'ee_edit_question_group', |
|
165 | + 'obj_id' => $qsg_id, |
|
166 | + 'noheader' => true, |
|
167 | + ), |
|
168 | + |
|
169 | + 'trash_question_groups' => array( |
|
170 | + 'func' => '_trash_or_restore_question_groups', |
|
171 | + 'args' => array('trash' => true), |
|
172 | + 'capability' => 'ee_delete_question_groups', |
|
173 | + 'noheader' => array('trash' => false), |
|
174 | + ), |
|
175 | + |
|
176 | + 'restore_question_groups' => array( |
|
177 | + 'func' => '_trash_or_restore_question_groups', |
|
178 | + 'args' => array('trash' => false), |
|
179 | + 'capability' => 'ee_delete_question_groups', |
|
180 | + 'noheader' => true, |
|
181 | + ), |
|
182 | + |
|
183 | + |
|
184 | + 'espresso_update_question_group_order' => array( |
|
185 | + 'func' => 'update_question_group_order', |
|
186 | + 'capability' => 'ee_edit_question_groups', |
|
187 | + 'noheader' => true, |
|
188 | + ), |
|
189 | + |
|
190 | + 'view_reg_form_settings' => array( |
|
191 | + 'func' => '_reg_form_settings', |
|
192 | + 'capability' => 'manage_options', |
|
193 | + ), |
|
194 | + |
|
195 | + 'update_reg_form_settings' => array( |
|
196 | + 'func' => '_update_reg_form_settings', |
|
197 | + 'capability' => 'manage_options', |
|
198 | + 'noheader' => true, |
|
199 | + ), |
|
200 | + ); |
|
201 | + $this->_page_routes = array_merge($this->_page_routes, $new_page_routes); |
|
202 | + |
|
203 | + $new_page_config = array( |
|
204 | + |
|
205 | + 'question_groups' => array( |
|
206 | + 'nav' => array( |
|
207 | + 'label' => esc_html__('Question Groups', 'event_espresso'), |
|
208 | + 'order' => 20, |
|
209 | + ), |
|
210 | + 'list_table' => 'Registration_Form_Question_Groups_Admin_List_Table', |
|
211 | + 'help_tabs' => array( |
|
212 | + 'registration_form_question_groups_help_tab' => array( |
|
213 | + 'title' => esc_html__('Question Groups', 'event_espresso'), |
|
214 | + 'filename' => 'registration_form_question_groups', |
|
215 | + ), |
|
216 | + 'registration_form_question_groups_table_column_headings_help_tab' => array( |
|
217 | + 'title' => esc_html__('Question Groups Table Column Headings', 'event_espresso'), |
|
218 | + 'filename' => 'registration_form_question_groups_table_column_headings', |
|
219 | + ), |
|
220 | + 'registration_form_question_groups_views_bulk_actions_search_help_tab' => array( |
|
221 | + 'title' => esc_html__('Question Groups Views & Bulk Actions & Search', 'event_espresso'), |
|
222 | + 'filename' => 'registration_form_question_groups_views_bulk_actions_search', |
|
223 | + ), |
|
224 | + ), |
|
225 | + 'help_tour' => array('Registration_Form_Question_Groups_Help_Tour'), |
|
226 | + 'metaboxes' => $this->_default_espresso_metaboxes, |
|
227 | + 'require_nonce' => false, |
|
228 | + 'qtips' => array( |
|
229 | + 'EE_Registration_Form_Tips', |
|
230 | + ), |
|
231 | + ), |
|
232 | + |
|
233 | + 'add_question' => array( |
|
234 | + 'nav' => array( |
|
235 | + 'label' => esc_html__('Add Question', 'event_espresso'), |
|
236 | + 'order' => 5, |
|
237 | + 'persistent' => false, |
|
238 | + ), |
|
239 | + 'metaboxes' => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')), |
|
240 | + 'help_tabs' => array( |
|
241 | + 'registration_form_add_question_help_tab' => array( |
|
242 | + 'title' => esc_html__('Add Question', 'event_espresso'), |
|
243 | + 'filename' => 'registration_form_add_question', |
|
244 | + ), |
|
245 | + ), |
|
246 | + 'help_tour' => array('Registration_Form_Add_Question_Help_Tour'), |
|
247 | + 'require_nonce' => false, |
|
248 | + ), |
|
249 | + |
|
250 | + 'add_question_group' => array( |
|
251 | + 'nav' => array( |
|
252 | + 'label' => esc_html__('Add Question Group', 'event_espresso'), |
|
253 | + 'order' => 5, |
|
254 | + 'persistent' => false, |
|
255 | + ), |
|
256 | + 'metaboxes' => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')), |
|
257 | + 'help_tabs' => array( |
|
258 | + 'registration_form_add_question_group_help_tab' => array( |
|
259 | + 'title' => esc_html__('Add Question Group', 'event_espresso'), |
|
260 | + 'filename' => 'registration_form_add_question_group', |
|
261 | + ), |
|
262 | + ), |
|
263 | + 'help_tour' => array('Registration_Form_Add_Question_Group_Help_Tour'), |
|
264 | + 'require_nonce' => false, |
|
265 | + ), |
|
266 | + |
|
267 | + 'edit_question_group' => array( |
|
268 | + 'nav' => array( |
|
269 | + 'label' => esc_html__('Edit Question Group', 'event_espresso'), |
|
270 | + 'order' => 5, |
|
271 | + 'persistent' => false, |
|
272 | + 'url' => isset($this->_req_data['question_group_id']) ? add_query_arg(array('question_group_id' => $this->_req_data['question_group_id']), |
|
273 | + $this->_current_page_view_url) : $this->_admin_base_url, |
|
274 | + ), |
|
275 | + 'metaboxes' => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')), |
|
276 | + 'help_tabs' => array( |
|
277 | + 'registration_form_edit_question_group_help_tab' => array( |
|
278 | + 'title' => esc_html__('Edit Question Group', 'event_espresso'), |
|
279 | + 'filename' => 'registration_form_edit_question_group', |
|
280 | + ), |
|
281 | + ), |
|
282 | + 'help_tour' => array('Registration_Form_Edit_Question_Group_Help_Tour'), |
|
283 | + 'require_nonce' => false, |
|
284 | + ), |
|
285 | + |
|
286 | + 'view_reg_form_settings' => array( |
|
287 | + 'nav' => array( |
|
288 | + 'label' => esc_html__('Reg Form Settings', 'event_espresso'), |
|
289 | + 'order' => 40, |
|
290 | + ), |
|
291 | + 'labels' => array( |
|
292 | + 'publishbox' => esc_html__('Update Settings', 'event_espresso'), |
|
293 | + ), |
|
294 | + 'metaboxes' => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')), |
|
295 | + 'help_tabs' => array( |
|
296 | + 'registration_form_reg_form_settings_help_tab' => array( |
|
297 | + 'title' => esc_html__('Registration Form Settings', 'event_espresso'), |
|
298 | + 'filename' => 'registration_form_reg_form_settings', |
|
299 | + ), |
|
300 | + ), |
|
301 | + 'help_tour' => array('Registration_Form_Settings_Help_Tour'), |
|
302 | + 'require_nonce' => false, |
|
303 | + ), |
|
304 | + |
|
305 | + ); |
|
306 | + $this->_page_config = array_merge($this->_page_config, $new_page_config); |
|
307 | + |
|
308 | + //change the list table we're going to use so it's the NEW list table! |
|
309 | + $this->_page_config['default']['list_table'] = 'Extend_Registration_Form_Questions_Admin_List_Table'; |
|
310 | + |
|
311 | + |
|
312 | + //additional labels |
|
313 | + $new_labels = array( |
|
314 | + 'add_question' => esc_html__('Add New Question', 'event_espresso'), |
|
315 | + 'delete_question' => esc_html__('Delete Question', 'event_espresso'), |
|
316 | + 'add_question_group' => esc_html__('Add New Question Group', 'event_espresso'), |
|
317 | + 'edit_question_group' => esc_html__('Edit Question Group', 'event_espresso'), |
|
318 | + 'delete_question_group' => esc_html__('Delete Question Group', 'event_espresso'), |
|
319 | + ); |
|
320 | + $this->_labels['buttons'] = array_merge($this->_labels['buttons'], $new_labels); |
|
321 | + |
|
322 | + } |
|
323 | + |
|
324 | + |
|
325 | + protected function _ajax_hooks() |
|
326 | + { |
|
327 | + add_action('wp_ajax_espresso_update_question_group_order', array($this, 'update_question_group_order')); |
|
328 | + } |
|
329 | + |
|
330 | + |
|
331 | + public function load_scripts_styles_question_groups() |
|
332 | + { |
|
333 | + wp_enqueue_script('espresso_ajax_table_sorting'); |
|
334 | + } |
|
335 | + |
|
336 | + |
|
337 | + public function load_scripts_styles_add_question_group() |
|
338 | + { |
|
339 | + $this->load_scripts_styles_forms(); |
|
340 | + $this->load_sortable_question_script(); |
|
341 | + } |
|
342 | + |
|
343 | + public function load_scripts_styles_edit_question_group() |
|
344 | + { |
|
345 | + $this->load_scripts_styles_forms(); |
|
346 | + $this->load_sortable_question_script(); |
|
347 | + } |
|
348 | + |
|
349 | + |
|
350 | + /** |
|
351 | + * registers and enqueues script for questions |
|
352 | + * |
|
353 | + * @return void |
|
354 | + */ |
|
355 | + public function load_sortable_question_script() |
|
356 | + { |
|
357 | + wp_register_script('ee-question-sortable', REGISTRATION_FORM_CAF_ASSETS_URL . 'ee_question_order.js', |
|
358 | + array('jquery-ui-sortable'), EVENT_ESPRESSO_VERSION, true); |
|
359 | + wp_enqueue_script('ee-question-sortable'); |
|
360 | + } |
|
361 | + |
|
362 | + |
|
363 | + protected function _set_list_table_views_default() |
|
364 | + { |
|
365 | + $this->_views = array( |
|
366 | + 'all' => array( |
|
367 | + 'slug' => 'all', |
|
368 | + 'label' => esc_html__('View All Questions', 'event_espresso'), |
|
369 | + 'count' => 0, |
|
370 | + 'bulk_action' => array( |
|
371 | + 'trash_questions' => esc_html__('Trash', 'event_espresso'), |
|
372 | + ), |
|
373 | + ), |
|
374 | + ); |
|
375 | + |
|
376 | + if (EE_Registry::instance()->CAP->current_user_can('ee_delete_questions', |
|
377 | + 'espresso_registration_form_trash_questions') |
|
378 | + ) { |
|
379 | + $this->_views['trash'] = array( |
|
380 | + 'slug' => 'trash', |
|
381 | + 'label' => esc_html__('Trash', 'event_espresso'), |
|
382 | + 'count' => 0, |
|
383 | + 'bulk_action' => array( |
|
384 | + 'delete_questions' => esc_html__('Delete Permanently', 'event_espresso'), |
|
385 | + 'restore_questions' => esc_html__('Restore', 'event_espresso'), |
|
386 | + ), |
|
387 | + ); |
|
388 | + } |
|
389 | + } |
|
390 | + |
|
391 | + |
|
392 | + protected function _set_list_table_views_question_groups() |
|
393 | + { |
|
394 | + $this->_views = array( |
|
395 | + 'all' => array( |
|
396 | + 'slug' => 'all', |
|
397 | + 'label' => esc_html__('All', 'event_espresso'), |
|
398 | + 'count' => 0, |
|
399 | + 'bulk_action' => array( |
|
400 | + 'trash_question_groups' => esc_html__('Trash', 'event_espresso'), |
|
401 | + ), |
|
402 | + ), |
|
403 | + ); |
|
404 | + |
|
405 | + if (EE_Registry::instance()->CAP->current_user_can('ee_delete_question_groups', |
|
406 | + 'espresso_registration_form_trash_question_groups') |
|
407 | + ) { |
|
408 | + $this->_views['trash'] = array( |
|
409 | + 'slug' => 'trash', |
|
410 | + 'label' => esc_html__('Trash', 'event_espresso'), |
|
411 | + 'count' => 0, |
|
412 | + 'bulk_action' => array( |
|
413 | + 'delete_question_groups' => esc_html__('Delete Permanently', 'event_espresso'), |
|
414 | + 'restore_question_groups' => esc_html__('Restore', 'event_espresso'), |
|
415 | + ), |
|
416 | + ); |
|
417 | + } |
|
418 | + } |
|
419 | + |
|
420 | + |
|
421 | + protected function _questions_overview_list_table() |
|
422 | + { |
|
423 | + $this->_admin_page_title .= ' ' . $this->get_action_link_or_button( |
|
424 | + 'add_question', |
|
425 | + 'add_question', |
|
426 | + array(), |
|
427 | + 'add-new-h2' |
|
428 | + ); |
|
429 | + parent::_questions_overview_list_table(); |
|
430 | + } |
|
431 | + |
|
432 | + |
|
433 | + protected function _question_groups_overview_list_table() |
|
434 | + { |
|
435 | + $this->_search_btn_label = esc_html__('Question Groups', 'event_espresso'); |
|
436 | + $this->_admin_page_title .= ' ' . $this->get_action_link_or_button( |
|
437 | + 'add_question_group', |
|
438 | + 'add_question_group', |
|
439 | + array(), |
|
440 | + 'add-new-h2' |
|
441 | + ); |
|
442 | + $this->display_admin_list_table_page_with_sidebar(); |
|
443 | + } |
|
444 | + |
|
445 | + |
|
446 | + protected function _delete_question() |
|
447 | + { |
|
448 | + $success = $this->_delete_items($this->_question_model); |
|
449 | + $this->_redirect_after_action( |
|
450 | + $success, |
|
451 | + $this->_question_model->item_name($success), |
|
452 | + 'deleted', |
|
453 | + array('action' => 'default', 'status' => 'all') |
|
454 | + ); |
|
455 | + } |
|
456 | + |
|
457 | + |
|
458 | + protected function _delete_questions() |
|
459 | + { |
|
460 | + $success = $this->_delete_items($this->_question_model); |
|
461 | + $this->_redirect_after_action( |
|
462 | + $success, |
|
463 | + $this->_question_model->item_name($success), |
|
464 | + 'deleted permanently', |
|
465 | + array('action' => 'default', 'status' => 'trash') |
|
466 | + ); |
|
467 | + } |
|
468 | + |
|
469 | + |
|
470 | + /** |
|
471 | + * Performs the deletion of a single or multiple questions or question groups. |
|
472 | + * |
|
473 | + * @param EEM_Soft_Delete_Base $model |
|
474 | + * @return int number of items deleted permanently |
|
475 | + */ |
|
476 | + private function _delete_items(EEM_Soft_Delete_Base $model) |
|
477 | + { |
|
478 | + $success = 0; |
|
479 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
480 | + if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) { |
|
481 | + // if array has more than one element than success message should be plural |
|
482 | + $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1; |
|
483 | + // cycle thru bulk action checkboxes |
|
484 | + while (list($ID, $value) = each($this->_req_data['checkbox'])) { |
|
485 | + if (! $this->_delete_item($ID, $model)) { |
|
486 | + $success = 0; |
|
487 | + } |
|
488 | + } |
|
489 | + |
|
490 | + } elseif (! empty($this->_req_data['QSG_ID'])) { |
|
491 | + $success = $this->_delete_item($this->_req_data['QSG_ID'], $model); |
|
492 | + |
|
493 | + } elseif (! empty($this->_req_data['QST_ID'])) { |
|
494 | + $success = $this->_delete_item($this->_req_data['QST_ID'], $model); |
|
495 | + } else { |
|
496 | + EE_Error::add_error(sprintf(esc_html__("No Questions or Question Groups were selected for deleting. This error usually shows when you've attempted to delete via bulk action but there were no selections.", |
|
497 | + "event_espresso")), __FILE__, __FUNCTION__, __LINE__); |
|
498 | + } |
|
499 | + return $success; |
|
500 | + } |
|
501 | + |
|
502 | + /** |
|
503 | + * Deletes the specified question (and its associated question options) or question group |
|
504 | + * |
|
505 | + * @param int $id |
|
506 | + * @param EEM_Soft_Delete_Base $model |
|
507 | + * @return boolean |
|
508 | + */ |
|
509 | + protected function _delete_item($id, $model) |
|
510 | + { |
|
511 | + if ($model instanceof EEM_Question) { |
|
512 | + EEM_Question_Option::instance()->delete_permanently(array(array('QST_ID' => absint($id)))); |
|
513 | + } |
|
514 | + return $model->delete_permanently_by_ID(absint($id)); |
|
515 | + } |
|
516 | + |
|
517 | + |
|
518 | + /****************************** QUESTION GROUPS ******************************/ |
|
519 | + |
|
520 | + |
|
521 | + protected function _edit_question_group($type = 'add') |
|
522 | + { |
|
523 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
524 | + $ID = isset($this->_req_data['QSG_ID']) && ! empty($this->_req_data['QSG_ID']) ? absint($this->_req_data['QSG_ID']) : false; |
|
525 | + |
|
526 | + switch ($this->_req_action) { |
|
527 | + case 'add_question_group' : |
|
528 | + $this->_admin_page_title = esc_html__('Add Question Group', 'event_espresso'); |
|
529 | + break; |
|
530 | + case 'edit_question_group' : |
|
531 | + $this->_admin_page_title = esc_html__('Edit Question Group', 'event_espresso'); |
|
532 | + break; |
|
533 | + default : |
|
534 | + $this->_admin_page_title = ucwords(str_replace('_', ' ', $this->_req_action)); |
|
535 | + } |
|
536 | + // add ID to title if editing |
|
537 | + $this->_admin_page_title = $ID ? $this->_admin_page_title . ' # ' . $ID : $this->_admin_page_title; |
|
538 | + if ($ID) { |
|
539 | + /** @var EE_Question_Group $questionGroup */ |
|
540 | + $questionGroup = $this->_question_group_model->get_one_by_ID($ID); |
|
541 | + $additional_hidden_fields = array('QSG_ID' => array('type' => 'hidden', 'value' => $ID)); |
|
542 | + $this->_set_add_edit_form_tags('update_question_group', $additional_hidden_fields); |
|
543 | + } else { |
|
544 | + /** @var EE_Question_Group $questionGroup */ |
|
545 | + $questionGroup = EEM_Question_Group::instance()->create_default_object(); |
|
546 | + $questionGroup->set_order_to_latest(); |
|
547 | + $this->_set_add_edit_form_tags('insert_question_group'); |
|
548 | + } |
|
549 | + $this->_template_args['values'] = $this->_yes_no_values; |
|
550 | + $this->_template_args['all_questions'] = $questionGroup->questions_in_and_not_in_group(); |
|
551 | + $this->_template_args['QSG_ID'] = $ID ? $ID : true; |
|
552 | + $this->_template_args['question_group'] = $questionGroup; |
|
553 | + |
|
554 | + $redirect_URL = add_query_arg(array('action' => 'question_groups'), $this->_admin_base_url); |
|
555 | + $this->_set_publish_post_box_vars('id', $ID, false, $redirect_URL); |
|
556 | + $this->_template_args['admin_page_content'] = EEH_Template::display_template(REGISTRATION_FORM_CAF_TEMPLATE_PATH . 'question_groups_main_meta_box.template.php', |
|
557 | + $this->_template_args, true); |
|
558 | + |
|
559 | + // the details template wrapper |
|
560 | + $this->display_admin_page_with_sidebar(); |
|
561 | + } |
|
562 | + |
|
563 | + |
|
564 | + protected function _delete_question_groups() |
|
565 | + { |
|
566 | + $success = $this->_delete_items($this->_question_group_model); |
|
567 | + $this->_redirect_after_action($success, $this->_question_group_model->item_name($success), |
|
568 | + 'deleted permanently', array('action' => 'question_groups', 'status' => 'trash')); |
|
569 | + } |
|
570 | + |
|
571 | + |
|
572 | + /** |
|
573 | + * @param bool $new_question_group |
|
574 | + */ |
|
575 | + protected function _insert_or_update_question_group($new_question_group = true) |
|
576 | + { |
|
577 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
578 | + $set_column_values = $this->_set_column_values_for($this->_question_group_model); |
|
579 | + if ($new_question_group) { |
|
580 | + $QSG_ID = $this->_question_group_model->insert($set_column_values); |
|
581 | + $success = $QSG_ID ? 1 : 0; |
|
582 | + } else { |
|
583 | + $QSG_ID = absint($this->_req_data['QSG_ID']); |
|
584 | + unset($set_column_values['QSG_ID']); |
|
585 | + $success = $this->_question_group_model->update($set_column_values, array(array('QSG_ID' => $QSG_ID))); |
|
586 | + } |
|
587 | + $phone_question_id = EEM_Question::instance()->get_Question_ID_from_system_string(EEM_Attendee::system_question_phone); |
|
588 | + // update the existing related questions |
|
589 | + // BUT FIRST... delete the phone question from the Question_Group_Question if it is being added to this question group (therefore removed from the existing group) |
|
590 | + if (isset($this->_req_data['questions'], $this->_req_data['questions'][$phone_question_id])) { |
|
591 | + // delete where QST ID = system phone question ID and Question Group ID is NOT this group |
|
592 | + EEM_Question_Group_Question::instance()->delete(array( |
|
593 | + array( |
|
594 | + 'QST_ID' => $phone_question_id, |
|
595 | + 'QSG_ID' => array('!=', $QSG_ID), |
|
596 | + ), |
|
597 | + )); |
|
598 | + } |
|
599 | + /** @type EE_Question_Group $question_group */ |
|
600 | + $question_group = $this->_question_group_model->get_one_by_ID($QSG_ID); |
|
601 | + $questions = $question_group->questions(); |
|
602 | + // make sure system phone question is added to list of questions for this group |
|
603 | + if (! isset($questions[$phone_question_id])) { |
|
604 | + $questions[$phone_question_id] = EEM_Question::instance()->get_one_by_ID($phone_question_id); |
|
605 | + } |
|
606 | + |
|
607 | + foreach ($questions as $question_ID => $question) { |
|
608 | + // first we always check for order. |
|
609 | + if (! empty($this->_req_data['question_orders'][$question_ID])) { |
|
610 | + //update question order |
|
611 | + $question_group->update_question_order($question_ID, $this->_req_data['question_orders'][$question_ID]); |
|
612 | + } |
|
613 | + |
|
614 | + // then we always check if adding or removing. |
|
615 | + if (isset($this->_req_data['questions'], $this->_req_data['questions'][$question_ID])) { |
|
616 | + $question_group->add_question($question_ID); |
|
617 | + } else { |
|
618 | + // not found, remove it (but only if not a system question for the personal group with the exception of lname system question - we allow removal of it) |
|
619 | + if ( |
|
620 | + in_array( |
|
621 | + $question->system_ID(), |
|
622 | + EEM_Question::instance()->required_system_questions_in_system_question_group($question_group->system_group()) |
|
623 | + ) |
|
624 | + ) { |
|
625 | + continue; |
|
626 | + } else { |
|
627 | + $question_group->remove_question($question_ID); |
|
628 | + } |
|
629 | + } |
|
630 | + } |
|
631 | + // save new related questions |
|
632 | + if (isset($this->_req_data['questions'])) { |
|
633 | + foreach ($this->_req_data['questions'] as $QST_ID) { |
|
634 | + $question_group->add_question($QST_ID); |
|
635 | + if (isset($this->_req_data['question_orders'][$QST_ID])) { |
|
636 | + $question_group->update_question_order($QST_ID, $this->_req_data['question_orders'][$QST_ID]); |
|
637 | + } |
|
638 | + } |
|
639 | + } |
|
640 | + |
|
641 | + if ($success !== false) { |
|
642 | + $msg = $new_question_group ? sprintf(esc_html__('The %s has been created', 'event_espresso'), |
|
643 | + $this->_question_group_model->item_name()) : sprintf(esc_html__('The %s has been updated', |
|
644 | + 'event_espresso'), $this->_question_group_model->item_name()); |
|
645 | + EE_Error::add_success($msg); |
|
646 | + } |
|
647 | + $this->_redirect_after_action(false, '', '', array('action' => 'edit_question_group', 'QSG_ID' => $QSG_ID), |
|
648 | + true); |
|
649 | + |
|
650 | + } |
|
651 | + |
|
652 | + /** |
|
653 | + * duplicates a question and all its question options and redirects to the new question. |
|
654 | + */ |
|
655 | + public function _duplicate_question() |
|
656 | + { |
|
657 | + $question_ID = (int)$this->_req_data['QST_ID']; |
|
658 | + $question = EEM_Question::instance()->get_one_by_ID($question_ID); |
|
659 | + if ($question instanceof EE_Question) { |
|
660 | + $new_question = $question->duplicate(); |
|
661 | + if ($new_question instanceof EE_Question) { |
|
662 | + $this->_redirect_after_action(true, esc_html__('Question', 'event_espresso'), |
|
663 | + esc_html__('Duplicated', 'event_espresso'), |
|
664 | + array('action' => 'edit_question', 'QST_ID' => $new_question->ID()), true); |
|
665 | + } else { |
|
666 | + global $wpdb; |
|
667 | + EE_Error::add_error(sprintf(esc_html__('Could not duplicate question with ID %1$d because: %2$s', |
|
668 | + 'event_espresso'), $question_ID, $wpdb->last_error), __FILE__, __FUNCTION__, __LINE__); |
|
669 | + $this->_redirect_after_action(false, '', '', array('action' => 'default'), false); |
|
670 | + } |
|
671 | + } else { |
|
672 | + EE_Error::add_error(sprintf(esc_html__('Could not duplicate question with ID %d because it didn\'t exist!', |
|
673 | + 'event_espresso'), $question_ID), __FILE__, __FUNCTION__, __LINE__); |
|
674 | + $this->_redirect_after_action(false, '', '', array('action' => 'default'), false); |
|
675 | + } |
|
676 | + } |
|
677 | + |
|
678 | + |
|
679 | + /** |
|
680 | + * @param bool $trash |
|
681 | + */ |
|
682 | + protected function _trash_or_restore_question_groups($trash = true) |
|
683 | + { |
|
684 | + $this->_trash_or_restore_items($this->_question_group_model, $trash); |
|
685 | + } |
|
686 | + |
|
687 | + |
|
688 | + /** |
|
689 | + *_trash_question |
|
690 | + */ |
|
691 | + protected function _trash_question() |
|
692 | + { |
|
693 | + $success = $this->_question_model->delete_by_ID((int)$this->_req_data['QST_ID']); |
|
694 | + $query_args = array('action' => 'default', 'status' => 'all'); |
|
695 | + $this->_redirect_after_action($success, $this->_question_model->item_name($success), 'trashed', $query_args); |
|
696 | + } |
|
697 | + |
|
698 | + |
|
699 | + /** |
|
700 | + * @param bool $trash |
|
701 | + */ |
|
702 | + protected function _trash_or_restore_questions($trash = true) |
|
703 | + { |
|
704 | + $this->_trash_or_restore_items($this->_question_model, $trash); |
|
705 | + } |
|
706 | + |
|
707 | + |
|
708 | + /** |
|
709 | + * Internally used to delete or restore items, using the request data. Meant to be |
|
710 | + * flexible between question or question groups |
|
711 | + * |
|
712 | + * @param EEM_Soft_Delete_Base $model |
|
713 | + * @param boolean $trash whether to trash or restore |
|
714 | + */ |
|
715 | + private function _trash_or_restore_items(EEM_Soft_Delete_Base $model, $trash = true) |
|
716 | + { |
|
717 | + |
|
718 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
719 | + |
|
720 | + $success = 1; |
|
721 | + //Checkboxes |
|
722 | + //echo "trash $trash"; |
|
723 | + //var_dump($this->_req_data['checkbox']);die; |
|
724 | + if (isset($this->_req_data['checkbox'])) { |
|
725 | + if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) { |
|
726 | + // if array has more than one element than success message should be plural |
|
727 | + $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1; |
|
728 | + // cycle thru bulk action checkboxes |
|
729 | + while (list($ID, $value) = each($this->_req_data['checkbox'])) { |
|
730 | + if (! $model->delete_or_restore_by_ID($trash, absint($ID))) { |
|
731 | + $success = 0; |
|
732 | + } |
|
733 | + } |
|
734 | + |
|
735 | + } else { |
|
736 | + // grab single id and delete |
|
737 | + $ID = absint($this->_req_data['checkbox']); |
|
738 | + if (! $model->delete_or_restore_by_ID($trash, $ID)) { |
|
739 | + $success = 0; |
|
740 | + } |
|
741 | + } |
|
742 | + |
|
743 | + } else { |
|
744 | + // delete via trash link |
|
745 | + // grab single id and delete |
|
746 | + $ID = absint($this->_req_data[$model->primary_key_name()]); |
|
747 | + if (! $model->delete_or_restore_by_ID($trash, $ID)) { |
|
748 | + $success = 0; |
|
749 | + } |
|
750 | + |
|
751 | + } |
|
752 | + |
|
753 | + |
|
754 | + $action = $model instanceof EEM_Question ? 'default' : 'question_groups';//strtolower( $model->item_name(2) ); |
|
755 | + //echo "action :$action"; |
|
756 | + //$action = 'questions' ? 'default' : $action; |
|
757 | + if ($trash) { |
|
758 | + $action_desc = 'trashed'; |
|
759 | + $status = 'trash'; |
|
760 | + } else { |
|
761 | + $action_desc = 'restored'; |
|
762 | + $status = 'all'; |
|
763 | + } |
|
764 | + $this->_redirect_after_action($success, $model->item_name($success), $action_desc, |
|
765 | + array('action' => $action, 'status' => $status)); |
|
766 | + } |
|
767 | + |
|
768 | + |
|
769 | + /** |
|
770 | + * @param $per_page |
|
771 | + * @param int $current_page |
|
772 | + * @param bool|false $count |
|
773 | + * @return \EE_Soft_Delete_Base_Class[]|int |
|
774 | + */ |
|
775 | + public function get_trashed_questions($per_page, $current_page = 1, $count = false) |
|
776 | + { |
|
777 | + $query_params = $this->get_query_params(EEM_Question::instance(), $per_page, $current_page); |
|
778 | + |
|
779 | + if ($count) { |
|
780 | + //note: this a subclass of EEM_Soft_Delete_Base, so this is actually only getting non-trashed items |
|
781 | + $where = isset($query_params[0]) ? array($query_params[0]) : array(); |
|
782 | + $results = $this->_question_model->count_deleted($where); |
|
783 | + } else { |
|
784 | + //note: this a subclass of EEM_Soft_Delete_Base, so this is actually only getting non-trashed items |
|
785 | + $results = $this->_question_model->get_all_deleted($query_params); |
|
786 | + } |
|
787 | + return $results; |
|
788 | + } |
|
789 | + |
|
790 | + |
|
791 | + /** |
|
792 | + * @param $per_page |
|
793 | + * @param int $current_page |
|
794 | + * @param bool|false $count |
|
795 | + * @return \EE_Soft_Delete_Base_Class[] |
|
796 | + */ |
|
797 | + public function get_question_groups($per_page, $current_page = 1, $count = false) |
|
798 | + { |
|
799 | + $questionGroupModel = EEM_Question_Group::instance(); |
|
800 | + $query_params = $this->get_query_params($questionGroupModel, $per_page, $current_page); |
|
801 | + if ($count) { |
|
802 | + $where = isset($query_params[0]) ? array($query_params[0]) : array(); |
|
803 | + $results = $questionGroupModel->count($where); |
|
804 | + } else { |
|
805 | + $results = $questionGroupModel->get_all($query_params); |
|
806 | + } |
|
807 | + return $results; |
|
808 | + } |
|
809 | + |
|
810 | + |
|
811 | + /** |
|
812 | + * @param $per_page |
|
813 | + * @param int $current_page |
|
814 | + * @param bool $count |
|
815 | + * @return \EE_Soft_Delete_Base_Class[]|int |
|
816 | + */ |
|
817 | + public function get_trashed_question_groups($per_page, $current_page = 1, $count = false) |
|
818 | + { |
|
819 | + $questionGroupModel = EEM_Question_Group::instance(); |
|
820 | + $query_params = $this->get_query_params($questionGroupModel, $per_page, $current_page); |
|
821 | + if ($count) { |
|
822 | + $where = isset($query_params[0]) ? array($query_params[0]) : array(); |
|
823 | + $query_params['limit'] = null; |
|
824 | + $results = $questionGroupModel->count_deleted($where); |
|
825 | + } else { |
|
826 | + $results = $questionGroupModel->get_all_deleted($query_params); |
|
827 | + } |
|
828 | + return $results; |
|
829 | + } |
|
830 | + |
|
831 | + |
|
832 | + /** |
|
833 | + * method for performing updates to question order |
|
834 | + * |
|
835 | + * @return array results array |
|
836 | + */ |
|
837 | + public function update_question_group_order() |
|
838 | + { |
|
839 | + |
|
840 | + $success = esc_html__('Question group order was updated successfully.', 'event_espresso'); |
|
841 | + |
|
842 | + // grab our row IDs |
|
843 | + $row_ids = isset($this->_req_data['row_ids']) && ! empty($this->_req_data['row_ids']) |
|
844 | + ? explode(',', rtrim($this->_req_data['row_ids'], ',')) |
|
845 | + : array(); |
|
846 | + |
|
847 | + $perpage = ! empty($this->_req_data['perpage']) |
|
848 | + ? (int)$this->_req_data['perpage'] |
|
849 | + : null; |
|
850 | + $curpage = ! empty($this->_req_data['curpage']) |
|
851 | + ? (int)$this->_req_data['curpage'] |
|
852 | + : null; |
|
853 | + |
|
854 | + if (! empty($row_ids)) { |
|
855 | + //figure out where we start the row_id count at for the current page. |
|
856 | + $qsgcount = empty($curpage) ? 0 : ($curpage - 1) * $perpage; |
|
857 | + |
|
858 | + $row_count = count($row_ids); |
|
859 | + for ($i = 0; $i < $row_count; $i++) { |
|
860 | + //Update the questions when re-ordering |
|
861 | + $updated = EEM_Question_Group::instance()->update( |
|
862 | + array('QSG_order' => $qsgcount), |
|
863 | + array(array('QSG_ID' => $row_ids[$i])) |
|
864 | + ); |
|
865 | + if ($updated === false) { |
|
866 | + $success = false; |
|
867 | + } |
|
868 | + $qsgcount++; |
|
869 | + } |
|
870 | + } else { |
|
871 | + $success = false; |
|
872 | + } |
|
873 | + |
|
874 | + $errors = ! $success |
|
875 | + ? esc_html__('An error occurred. The question group order was not updated.', 'event_espresso') |
|
876 | + : false; |
|
877 | + |
|
878 | + echo wp_json_encode(array('return_data' => false, 'success' => $success, 'errors' => $errors)); |
|
879 | + die(); |
|
880 | + |
|
881 | + } |
|
882 | + |
|
883 | + |
|
884 | + |
|
885 | + /*************************************** REGISTRATION SETTINGS ***************************************/ |
|
886 | + |
|
887 | + |
|
888 | + /** |
|
889 | + * _reg_form_settings |
|
890 | + * |
|
891 | + * @throws \EE_Error |
|
892 | + */ |
|
893 | + protected function _reg_form_settings() |
|
894 | + { |
|
895 | + $this->_template_args['values'] = $this->_yes_no_values; |
|
896 | + add_action( |
|
897 | + 'AHEE__Extend_Registration_Form_Admin_Page___reg_form_settings_template', |
|
898 | + array($this, 'email_validation_settings_form'), |
|
899 | + 2 |
|
900 | + ); |
|
901 | + $this->_template_args = (array)apply_filters( |
|
902 | + 'FHEE__Extend_Registration_Form_Admin_Page___reg_form_settings___template_args', |
|
903 | + $this->_template_args |
|
904 | + ); |
|
905 | + $this->_set_add_edit_form_tags('update_reg_form_settings'); |
|
906 | + $this->_set_publish_post_box_vars(null, false, false, null, false); |
|
907 | + $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
908 | + REGISTRATION_FORM_CAF_TEMPLATE_PATH . 'reg_form_settings.template.php', |
|
909 | + $this->_template_args, |
|
910 | + true |
|
911 | + ); |
|
912 | + $this->display_admin_page_with_sidebar(); |
|
913 | + } |
|
914 | + |
|
915 | + |
|
916 | + /** |
|
917 | + * _update_reg_form_settings |
|
918 | + */ |
|
919 | + protected function _update_reg_form_settings() |
|
920 | + { |
|
921 | + EE_Registry::instance()->CFG->registration = $this->update_email_validation_settings_form( |
|
922 | + EE_Registry::instance()->CFG->registration |
|
923 | + ); |
|
924 | + EE_Registry::instance()->CFG->registration = apply_filters( |
|
925 | + 'FHEE__Extend_Registration_Form_Admin_Page___update_reg_form_settings__CFG_registration', |
|
926 | + EE_Registry::instance()->CFG->registration |
|
927 | + ); |
|
928 | + $success = $this->_update_espresso_configuration( |
|
929 | + esc_html__('Registration Form Options', 'event_espresso'), |
|
930 | + EE_Registry::instance()->CFG, |
|
931 | + __FILE__, __FUNCTION__, __LINE__ |
|
932 | + ); |
|
933 | + $this->_redirect_after_action($success, esc_html__('Registration Form Options', 'event_espresso'), 'updated', |
|
934 | + array('action' => 'view_reg_form_settings')); |
|
935 | + } |
|
936 | + |
|
937 | + |
|
938 | + /** |
|
939 | + * email_validation_settings_form |
|
940 | + * |
|
941 | + * @access public |
|
942 | + * @return void |
|
943 | + * @throws \EE_Error |
|
944 | + */ |
|
945 | + public function email_validation_settings_form() |
|
946 | + { |
|
947 | + echo $this->_email_validation_settings_form()->get_html(); |
|
948 | + } |
|
949 | + |
|
950 | + |
|
951 | + /** |
|
952 | + * _email_validation_settings_form |
|
953 | + * |
|
954 | + * @access protected |
|
955 | + * @return EE_Form_Section_Proper |
|
956 | + * @throws \EE_Error |
|
957 | + */ |
|
958 | + protected function _email_validation_settings_form() |
|
959 | + { |
|
960 | + return new EE_Form_Section_Proper( |
|
961 | + array( |
|
962 | + 'name' => 'email_validation_settings', |
|
963 | + 'html_id' => 'email_validation_settings', |
|
964 | + 'layout_strategy' => new EE_Admin_Two_Column_Layout(), |
|
965 | + 'subsections' => array( |
|
966 | + 'email_validation_hdr' => new EE_Form_Section_HTML( |
|
967 | + EEH_HTML::h2(esc_html__('Email Validation Settings', 'event_espresso')) |
|
968 | + ), |
|
969 | + 'email_validation_level' => new EE_Select_Input( |
|
970 | + array( |
|
971 | + 'basic' => esc_html__('Basic', 'event_espresso'), |
|
972 | + 'wp_default' => esc_html__('WordPress Default', 'event_espresso'), |
|
973 | + 'i18n' => esc_html__('International', 'event_espresso'), |
|
974 | + 'i18n_dns' => esc_html__('International + DNS Check', 'event_espresso'), |
|
975 | + ), |
|
976 | + array( |
|
977 | + 'html_label_text' => esc_html__('Email Validation Level', 'event_espresso') |
|
978 | + . EEH_Template::get_help_tab_link('email_validation_info'), |
|
979 | + 'html_help_text' => esc_html__('These levels range from basic validation ( ie: [email protected] ) to more advanced checks against international email addresses (ie: üñîçøðé@example.com ) with additional MX and A record checks to confirm the domain actually exists. More information on on each level can be found within the help section.', |
|
980 | + 'event_espresso'), |
|
981 | + 'default' => isset(EE_Registry::instance()->CFG->registration->email_validation_level) |
|
982 | + ? EE_Registry::instance()->CFG->registration->email_validation_level |
|
983 | + : 'wp_default', |
|
984 | + 'required' => false, |
|
985 | + ) |
|
986 | + ), |
|
987 | + ), |
|
988 | + ) |
|
989 | + ); |
|
990 | + } |
|
991 | + |
|
992 | + |
|
993 | + /** |
|
994 | + * update_email_validation_settings_form |
|
995 | + * |
|
996 | + * @access public |
|
997 | + * @param \EE_Registration_Config $EE_Registration_Config |
|
998 | + * @return \EE_Registration_Config |
|
999 | + */ |
|
1000 | + public function update_email_validation_settings_form(EE_Registration_Config $EE_Registration_Config) |
|
1001 | + { |
|
1002 | + $prev_email_validation_level = $EE_Registration_Config->email_validation_level; |
|
1003 | + try { |
|
1004 | + $email_validation_settings_form = $this->_email_validation_settings_form(); |
|
1005 | + // if not displaying a form, then check for form submission |
|
1006 | + if ($email_validation_settings_form->was_submitted()) { |
|
1007 | + // capture form data |
|
1008 | + $email_validation_settings_form->receive_form_submission(); |
|
1009 | + // validate form data |
|
1010 | + if ($email_validation_settings_form->is_valid()) { |
|
1011 | + // grab validated data from form |
|
1012 | + $valid_data = $email_validation_settings_form->valid_data(); |
|
1013 | + if (isset($valid_data['email_validation_level'])) { |
|
1014 | + $email_validation_level = $valid_data['email_validation_level']; |
|
1015 | + // now if they want to use international email addresses |
|
1016 | + if ($email_validation_level === 'i18n' || $email_validation_level === 'i18n_dns') { |
|
1017 | + // in case we need to reset their email validation level, |
|
1018 | + // make sure that the previous value wasn't already set to one of the i18n options. |
|
1019 | + if ($prev_email_validation_level === 'i18n' || $prev_email_validation_level === 'i18n_dns') { |
|
1020 | + // if so, then reset it back to "basic" since that is the only other option that, |
|
1021 | + // despite offering poor validation, supports i18n email addresses |
|
1022 | + $prev_email_validation_level = 'basic'; |
|
1023 | + } |
|
1024 | + // confirm our i18n email validation will work on the server |
|
1025 | + if (! $this->_verify_pcre_support($EE_Registration_Config, $email_validation_level)) { |
|
1026 | + // or reset email validation level to previous value |
|
1027 | + $email_validation_level = $prev_email_validation_level; |
|
1028 | + } |
|
1029 | + } |
|
1030 | + $EE_Registration_Config->email_validation_level = $email_validation_level; |
|
1031 | + } else { |
|
1032 | + EE_Error::add_error( |
|
1033 | + esc_html__( |
|
1034 | + 'Invalid or missing Email Validation settings. Please refresh the form and try again.', |
|
1035 | + 'event_espresso' |
|
1036 | + ), |
|
1037 | + __FILE__, __FUNCTION__, __LINE__ |
|
1038 | + ); |
|
1039 | + } |
|
1040 | + } else { |
|
1041 | + if ($email_validation_settings_form->submission_error_message() !== '') { |
|
1042 | + EE_Error::add_error( |
|
1043 | + $email_validation_settings_form->submission_error_message(), |
|
1044 | + __FILE__, __FUNCTION__, __LINE__ |
|
1045 | + ); |
|
1046 | + } |
|
1047 | + } |
|
1048 | + } |
|
1049 | + } catch (EE_Error $e) { |
|
1050 | + $e->get_error(); |
|
1051 | + } |
|
1052 | + return $EE_Registration_Config; |
|
1053 | + } |
|
1054 | + |
|
1055 | + |
|
1056 | + /** |
|
1057 | + * confirms that the server's PHP version has the PCRE module enabled, |
|
1058 | + * and that the PCRE version works with our i18n email validation |
|
1059 | + * |
|
1060 | + * @param \EE_Registration_Config $EE_Registration_Config |
|
1061 | + * @param string $email_validation_level |
|
1062 | + * @return bool |
|
1063 | + */ |
|
1064 | + private function _verify_pcre_support(EE_Registration_Config $EE_Registration_Config, $email_validation_level) |
|
1065 | + { |
|
1066 | + // first check that PCRE is enabled |
|
1067 | + if (! defined('PREG_BAD_UTF8_ERROR')) { |
|
1068 | + EE_Error::add_error( |
|
1069 | + sprintf( |
|
1070 | + esc_html__( |
|
1071 | + 'We\'re sorry, but it appears that your server\'s version of PHP was not compiled with PCRE unicode support.%1$sPlease contact your hosting company and ask them whether the PCRE compiled with your version of PHP on your server can be been built with the "--enable-unicode-properties" and "--enable-utf8" configuration switches to enable more complex regex expressions.%1$sIf they are unable, or unwilling to do so, then your server will not support international email addresses using UTF-8 unicode characters. This means you will either have to lower your email validation level to "Basic" or "WordPress Default", or switch to a hosting company that has/can enable PCRE unicode support on the server.', |
|
1072 | + 'event_espresso' |
|
1073 | + ), |
|
1074 | + '<br />' |
|
1075 | + ), |
|
1076 | + __FILE__, |
|
1077 | + __FUNCTION__, |
|
1078 | + __LINE__ |
|
1079 | + ); |
|
1080 | + return false; |
|
1081 | + } else { |
|
1082 | + // PCRE support is enabled, but let's still |
|
1083 | + // perform a test to see if the server will support it. |
|
1084 | + // but first, save the updated validation level to the config, |
|
1085 | + // so that the validation strategy picks it up. |
|
1086 | + // this will get bumped back down if it doesn't work |
|
1087 | + $EE_Registration_Config->email_validation_level = $email_validation_level; |
|
1088 | + try { |
|
1089 | + $email_validator = new EE_Email_Validation_Strategy(); |
|
1090 | + $i18n_email_address = apply_filters( |
|
1091 | + 'FHEE__Extend_Registration_Form_Admin_Page__update_email_validation_settings_form__i18n_email_address', |
|
1092 | + 'jägerjü[email protected]' |
|
1093 | + ); |
|
1094 | + $email_validator->validate($i18n_email_address); |
|
1095 | + } catch (Exception $e) { |
|
1096 | + EE_Error::add_error( |
|
1097 | + sprintf( |
|
1098 | + esc_html__( |
|
1099 | + 'We\'re sorry, but it appears that your server\'s configuration will not support the "International" or "International + DNS Check" email validation levels.%1$sTo correct this issue, please consult with your hosting company regarding your server\'s PCRE settings.%1$sIt is recommended that your PHP version be configured to use PCRE 8.10 or newer.%1$sMore information regarding PCRE versions and installation can be found here: %2$s', |
|
1100 | + 'event_espresso' |
|
1101 | + ), |
|
1102 | + '<br />', |
|
1103 | + '<a href="http://php.net/manual/en/pcre.installation.php" target="_blank">http://php.net/manual/en/pcre.installation.php</a>' |
|
1104 | + ), |
|
1105 | + __FILE__, __FUNCTION__, __LINE__ |
|
1106 | + ); |
|
1107 | + return false; |
|
1108 | + } |
|
1109 | + } |
|
1110 | + return true; |
|
1111 | + } |
|
1112 | 1112 | |
1113 | 1113 | |
1114 | 1114 | } |
@@ -1,5 +1,5 @@ discard block |
||
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 | |
@@ -32,11 +32,11 @@ discard block |
||
32 | 32 | */ |
33 | 33 | public function __construct($routing = true) |
34 | 34 | { |
35 | - define('REGISTRATION_FORM_CAF_ADMIN', EE_CORE_CAF_ADMIN_EXTEND . 'registration_form' . DS); |
|
36 | - define('REGISTRATION_FORM_CAF_ASSETS_PATH', REGISTRATION_FORM_CAF_ADMIN . 'assets' . DS); |
|
37 | - define('REGISTRATION_FORM_CAF_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL . 'registration_form/assets/'); |
|
38 | - define('REGISTRATION_FORM_CAF_TEMPLATE_PATH', REGISTRATION_FORM_CAF_ADMIN . 'templates' . DS); |
|
39 | - define('REGISTRATION_FORM_CAF_TEMPLATE_URL', EE_CORE_CAF_ADMIN_EXTEND_URL . 'registration_form/templates/'); |
|
35 | + define('REGISTRATION_FORM_CAF_ADMIN', EE_CORE_CAF_ADMIN_EXTEND.'registration_form'.DS); |
|
36 | + define('REGISTRATION_FORM_CAF_ASSETS_PATH', REGISTRATION_FORM_CAF_ADMIN.'assets'.DS); |
|
37 | + define('REGISTRATION_FORM_CAF_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL.'registration_form/assets/'); |
|
38 | + define('REGISTRATION_FORM_CAF_TEMPLATE_PATH', REGISTRATION_FORM_CAF_ADMIN.'templates'.DS); |
|
39 | + define('REGISTRATION_FORM_CAF_TEMPLATE_URL', EE_CORE_CAF_ADMIN_EXTEND_URL.'registration_form/templates/'); |
|
40 | 40 | parent::__construct($routing); |
41 | 41 | } |
42 | 42 | |
@@ -47,7 +47,7 @@ discard block |
||
47 | 47 | $qst_id = ! empty($this->_req_data['QST_ID']) && ! is_array($this->_req_data['QST_ID']) ? $this->_req_data['QST_ID'] : 0; |
48 | 48 | $qsg_id = ! empty($this->_req_data['QSG_ID']) && ! is_array($this->_req_data['QSG_ID']) ? $this->_req_data['QSG_ID'] : 0; |
49 | 49 | |
50 | - $new_page_routes = array( |
|
50 | + $new_page_routes = array( |
|
51 | 51 | 'question_groups' => array( |
52 | 52 | 'func' => '_question_groups_overview_list_table', |
53 | 53 | 'capability' => 'ee_read_question_groups', |
@@ -310,7 +310,7 @@ discard block |
||
310 | 310 | |
311 | 311 | |
312 | 312 | //additional labels |
313 | - $new_labels = array( |
|
313 | + $new_labels = array( |
|
314 | 314 | 'add_question' => esc_html__('Add New Question', 'event_espresso'), |
315 | 315 | 'delete_question' => esc_html__('Delete Question', 'event_espresso'), |
316 | 316 | 'add_question_group' => esc_html__('Add New Question Group', 'event_espresso'), |
@@ -354,7 +354,7 @@ discard block |
||
354 | 354 | */ |
355 | 355 | public function load_sortable_question_script() |
356 | 356 | { |
357 | - wp_register_script('ee-question-sortable', REGISTRATION_FORM_CAF_ASSETS_URL . 'ee_question_order.js', |
|
357 | + wp_register_script('ee-question-sortable', REGISTRATION_FORM_CAF_ASSETS_URL.'ee_question_order.js', |
|
358 | 358 | array('jquery-ui-sortable'), EVENT_ESPRESSO_VERSION, true); |
359 | 359 | wp_enqueue_script('ee-question-sortable'); |
360 | 360 | } |
@@ -420,7 +420,7 @@ discard block |
||
420 | 420 | |
421 | 421 | protected function _questions_overview_list_table() |
422 | 422 | { |
423 | - $this->_admin_page_title .= ' ' . $this->get_action_link_or_button( |
|
423 | + $this->_admin_page_title .= ' '.$this->get_action_link_or_button( |
|
424 | 424 | 'add_question', |
425 | 425 | 'add_question', |
426 | 426 | array(), |
@@ -433,7 +433,7 @@ discard block |
||
433 | 433 | protected function _question_groups_overview_list_table() |
434 | 434 | { |
435 | 435 | $this->_search_btn_label = esc_html__('Question Groups', 'event_espresso'); |
436 | - $this->_admin_page_title .= ' ' . $this->get_action_link_or_button( |
|
436 | + $this->_admin_page_title .= ' '.$this->get_action_link_or_button( |
|
437 | 437 | 'add_question_group', |
438 | 438 | 'add_question_group', |
439 | 439 | array(), |
@@ -477,20 +477,20 @@ discard block |
||
477 | 477 | { |
478 | 478 | $success = 0; |
479 | 479 | do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
480 | - if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) { |
|
480 | + if ( ! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) { |
|
481 | 481 | // if array has more than one element than success message should be plural |
482 | 482 | $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1; |
483 | 483 | // cycle thru bulk action checkboxes |
484 | 484 | while (list($ID, $value) = each($this->_req_data['checkbox'])) { |
485 | - if (! $this->_delete_item($ID, $model)) { |
|
485 | + if ( ! $this->_delete_item($ID, $model)) { |
|
486 | 486 | $success = 0; |
487 | 487 | } |
488 | 488 | } |
489 | 489 | |
490 | - } elseif (! empty($this->_req_data['QSG_ID'])) { |
|
490 | + } elseif ( ! empty($this->_req_data['QSG_ID'])) { |
|
491 | 491 | $success = $this->_delete_item($this->_req_data['QSG_ID'], $model); |
492 | 492 | |
493 | - } elseif (! empty($this->_req_data['QST_ID'])) { |
|
493 | + } elseif ( ! empty($this->_req_data['QST_ID'])) { |
|
494 | 494 | $success = $this->_delete_item($this->_req_data['QST_ID'], $model); |
495 | 495 | } else { |
496 | 496 | EE_Error::add_error(sprintf(esc_html__("No Questions or Question Groups were selected for deleting. This error usually shows when you've attempted to delete via bulk action but there were no selections.", |
@@ -534,7 +534,7 @@ discard block |
||
534 | 534 | $this->_admin_page_title = ucwords(str_replace('_', ' ', $this->_req_action)); |
535 | 535 | } |
536 | 536 | // add ID to title if editing |
537 | - $this->_admin_page_title = $ID ? $this->_admin_page_title . ' # ' . $ID : $this->_admin_page_title; |
|
537 | + $this->_admin_page_title = $ID ? $this->_admin_page_title.' # '.$ID : $this->_admin_page_title; |
|
538 | 538 | if ($ID) { |
539 | 539 | /** @var EE_Question_Group $questionGroup */ |
540 | 540 | $questionGroup = $this->_question_group_model->get_one_by_ID($ID); |
@@ -553,7 +553,7 @@ discard block |
||
553 | 553 | |
554 | 554 | $redirect_URL = add_query_arg(array('action' => 'question_groups'), $this->_admin_base_url); |
555 | 555 | $this->_set_publish_post_box_vars('id', $ID, false, $redirect_URL); |
556 | - $this->_template_args['admin_page_content'] = EEH_Template::display_template(REGISTRATION_FORM_CAF_TEMPLATE_PATH . 'question_groups_main_meta_box.template.php', |
|
556 | + $this->_template_args['admin_page_content'] = EEH_Template::display_template(REGISTRATION_FORM_CAF_TEMPLATE_PATH.'question_groups_main_meta_box.template.php', |
|
557 | 557 | $this->_template_args, true); |
558 | 558 | |
559 | 559 | // the details template wrapper |
@@ -600,13 +600,13 @@ discard block |
||
600 | 600 | $question_group = $this->_question_group_model->get_one_by_ID($QSG_ID); |
601 | 601 | $questions = $question_group->questions(); |
602 | 602 | // make sure system phone question is added to list of questions for this group |
603 | - if (! isset($questions[$phone_question_id])) { |
|
603 | + if ( ! isset($questions[$phone_question_id])) { |
|
604 | 604 | $questions[$phone_question_id] = EEM_Question::instance()->get_one_by_ID($phone_question_id); |
605 | 605 | } |
606 | 606 | |
607 | 607 | foreach ($questions as $question_ID => $question) { |
608 | 608 | // first we always check for order. |
609 | - if (! empty($this->_req_data['question_orders'][$question_ID])) { |
|
609 | + if ( ! empty($this->_req_data['question_orders'][$question_ID])) { |
|
610 | 610 | //update question order |
611 | 611 | $question_group->update_question_order($question_ID, $this->_req_data['question_orders'][$question_ID]); |
612 | 612 | } |
@@ -654,7 +654,7 @@ discard block |
||
654 | 654 | */ |
655 | 655 | public function _duplicate_question() |
656 | 656 | { |
657 | - $question_ID = (int)$this->_req_data['QST_ID']; |
|
657 | + $question_ID = (int) $this->_req_data['QST_ID']; |
|
658 | 658 | $question = EEM_Question::instance()->get_one_by_ID($question_ID); |
659 | 659 | if ($question instanceof EE_Question) { |
660 | 660 | $new_question = $question->duplicate(); |
@@ -690,7 +690,7 @@ discard block |
||
690 | 690 | */ |
691 | 691 | protected function _trash_question() |
692 | 692 | { |
693 | - $success = $this->_question_model->delete_by_ID((int)$this->_req_data['QST_ID']); |
|
693 | + $success = $this->_question_model->delete_by_ID((int) $this->_req_data['QST_ID']); |
|
694 | 694 | $query_args = array('action' => 'default', 'status' => 'all'); |
695 | 695 | $this->_redirect_after_action($success, $this->_question_model->item_name($success), 'trashed', $query_args); |
696 | 696 | } |
@@ -722,12 +722,12 @@ discard block |
||
722 | 722 | //echo "trash $trash"; |
723 | 723 | //var_dump($this->_req_data['checkbox']);die; |
724 | 724 | if (isset($this->_req_data['checkbox'])) { |
725 | - if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) { |
|
725 | + if ( ! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) { |
|
726 | 726 | // if array has more than one element than success message should be plural |
727 | 727 | $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1; |
728 | 728 | // cycle thru bulk action checkboxes |
729 | 729 | while (list($ID, $value) = each($this->_req_data['checkbox'])) { |
730 | - if (! $model->delete_or_restore_by_ID($trash, absint($ID))) { |
|
730 | + if ( ! $model->delete_or_restore_by_ID($trash, absint($ID))) { |
|
731 | 731 | $success = 0; |
732 | 732 | } |
733 | 733 | } |
@@ -735,7 +735,7 @@ discard block |
||
735 | 735 | } else { |
736 | 736 | // grab single id and delete |
737 | 737 | $ID = absint($this->_req_data['checkbox']); |
738 | - if (! $model->delete_or_restore_by_ID($trash, $ID)) { |
|
738 | + if ( ! $model->delete_or_restore_by_ID($trash, $ID)) { |
|
739 | 739 | $success = 0; |
740 | 740 | } |
741 | 741 | } |
@@ -744,14 +744,14 @@ discard block |
||
744 | 744 | // delete via trash link |
745 | 745 | // grab single id and delete |
746 | 746 | $ID = absint($this->_req_data[$model->primary_key_name()]); |
747 | - if (! $model->delete_or_restore_by_ID($trash, $ID)) { |
|
747 | + if ( ! $model->delete_or_restore_by_ID($trash, $ID)) { |
|
748 | 748 | $success = 0; |
749 | 749 | } |
750 | 750 | |
751 | 751 | } |
752 | 752 | |
753 | 753 | |
754 | - $action = $model instanceof EEM_Question ? 'default' : 'question_groups';//strtolower( $model->item_name(2) ); |
|
754 | + $action = $model instanceof EEM_Question ? 'default' : 'question_groups'; //strtolower( $model->item_name(2) ); |
|
755 | 755 | //echo "action :$action"; |
756 | 756 | //$action = 'questions' ? 'default' : $action; |
757 | 757 | if ($trash) { |
@@ -845,13 +845,13 @@ discard block |
||
845 | 845 | : array(); |
846 | 846 | |
847 | 847 | $perpage = ! empty($this->_req_data['perpage']) |
848 | - ? (int)$this->_req_data['perpage'] |
|
848 | + ? (int) $this->_req_data['perpage'] |
|
849 | 849 | : null; |
850 | 850 | $curpage = ! empty($this->_req_data['curpage']) |
851 | - ? (int)$this->_req_data['curpage'] |
|
851 | + ? (int) $this->_req_data['curpage'] |
|
852 | 852 | : null; |
853 | 853 | |
854 | - if (! empty($row_ids)) { |
|
854 | + if ( ! empty($row_ids)) { |
|
855 | 855 | //figure out where we start the row_id count at for the current page. |
856 | 856 | $qsgcount = empty($curpage) ? 0 : ($curpage - 1) * $perpage; |
857 | 857 | |
@@ -898,14 +898,14 @@ discard block |
||
898 | 898 | array($this, 'email_validation_settings_form'), |
899 | 899 | 2 |
900 | 900 | ); |
901 | - $this->_template_args = (array)apply_filters( |
|
901 | + $this->_template_args = (array) apply_filters( |
|
902 | 902 | 'FHEE__Extend_Registration_Form_Admin_Page___reg_form_settings___template_args', |
903 | 903 | $this->_template_args |
904 | 904 | ); |
905 | 905 | $this->_set_add_edit_form_tags('update_reg_form_settings'); |
906 | 906 | $this->_set_publish_post_box_vars(null, false, false, null, false); |
907 | 907 | $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
908 | - REGISTRATION_FORM_CAF_TEMPLATE_PATH . 'reg_form_settings.template.php', |
|
908 | + REGISTRATION_FORM_CAF_TEMPLATE_PATH.'reg_form_settings.template.php', |
|
909 | 909 | $this->_template_args, |
910 | 910 | true |
911 | 911 | ); |
@@ -925,7 +925,7 @@ discard block |
||
925 | 925 | 'FHEE__Extend_Registration_Form_Admin_Page___update_reg_form_settings__CFG_registration', |
926 | 926 | EE_Registry::instance()->CFG->registration |
927 | 927 | ); |
928 | - $success = $this->_update_espresso_configuration( |
|
928 | + $success = $this->_update_espresso_configuration( |
|
929 | 929 | esc_html__('Registration Form Options', 'event_espresso'), |
930 | 930 | EE_Registry::instance()->CFG, |
931 | 931 | __FILE__, __FUNCTION__, __LINE__ |
@@ -1022,7 +1022,7 @@ discard block |
||
1022 | 1022 | $prev_email_validation_level = 'basic'; |
1023 | 1023 | } |
1024 | 1024 | // confirm our i18n email validation will work on the server |
1025 | - if (! $this->_verify_pcre_support($EE_Registration_Config, $email_validation_level)) { |
|
1025 | + if ( ! $this->_verify_pcre_support($EE_Registration_Config, $email_validation_level)) { |
|
1026 | 1026 | // or reset email validation level to previous value |
1027 | 1027 | $email_validation_level = $prev_email_validation_level; |
1028 | 1028 | } |
@@ -1064,7 +1064,7 @@ discard block |
||
1064 | 1064 | private function _verify_pcre_support(EE_Registration_Config $EE_Registration_Config, $email_validation_level) |
1065 | 1065 | { |
1066 | 1066 | // first check that PCRE is enabled |
1067 | - if (! defined('PREG_BAD_UTF8_ERROR')) { |
|
1067 | + if ( ! defined('PREG_BAD_UTF8_ERROR')) { |
|
1068 | 1068 | EE_Error::add_error( |
1069 | 1069 | sprintf( |
1070 | 1070 | esc_html__( |
@@ -11,7 +11,7 @@ |
||
11 | 11 | |
12 | 12 | /** |
13 | 13 | * @param string $value_to_normalize |
14 | - * @return int|mixed|string |
|
14 | + * @return integer|null |
|
15 | 15 | * @throws \EE_Validation_Error |
16 | 16 | */ |
17 | 17 | public function normalize($value_to_normalize) { |
@@ -20,8 +20,8 @@ discard block |
||
20 | 20 | } |
21 | 21 | |
22 | 22 | if ( is_null( $value_to_normalize ) || $value_to_normalize === '' ) { |
23 | - return null; |
|
24 | - } |
|
23 | + return null; |
|
24 | + } |
|
25 | 25 | |
26 | 26 | if( ! is_string( $value_to_normalize )){ |
27 | 27 | throw new EE_Validation_Error( sprintf( __( 'The value "%s" must be a string submitted for normalization, it was %s', 'event_espresso' ), print_r( $value_to_normalize, TRUE), gettype( $value_to_normalize ) ) ); |
@@ -56,9 +56,9 @@ discard block |
||
56 | 56 | * @return string |
57 | 57 | */ |
58 | 58 | public function unnormalize( $normalized_value ) { |
59 | - if ($normalized_value === null) { |
|
60 | - return ''; |
|
61 | - }elseif( empty( $normalized_value ) ){ |
|
59 | + if ($normalized_value === null) { |
|
60 | + return ''; |
|
61 | + }elseif( empty( $normalized_value ) ){ |
|
62 | 62 | return '0'; |
63 | 63 | }else{ |
64 | 64 | return "$normalized_value"; |
@@ -7,7 +7,7 @@ discard block |
||
7 | 7 | * @subpackage |
8 | 8 | * @author Mike Nelson |
9 | 9 | */ |
10 | -class EE_Int_Normalization extends EE_Normalization_Strategy_Base{ |
|
10 | +class EE_Int_Normalization extends EE_Normalization_Strategy_Base { |
|
11 | 11 | |
12 | 12 | /** |
13 | 13 | * @param string $value_to_normalize |
@@ -15,38 +15,38 @@ discard block |
||
15 | 15 | * @throws \EE_Validation_Error |
16 | 16 | */ |
17 | 17 | public function normalize($value_to_normalize) { |
18 | - if( is_int( $value_to_normalize ) ){ |
|
18 | + if (is_int($value_to_normalize)) { |
|
19 | 19 | return $value_to_normalize; |
20 | 20 | } |
21 | 21 | |
22 | - if ( is_null( $value_to_normalize ) || $value_to_normalize === '' ) { |
|
22 | + if (is_null($value_to_normalize) || $value_to_normalize === '') { |
|
23 | 23 | return null; |
24 | 24 | } |
25 | 25 | |
26 | - if( ! is_string( $value_to_normalize )){ |
|
27 | - throw new EE_Validation_Error( sprintf( __( 'The value "%s" must be a string submitted for normalization, it was %s', 'event_espresso' ), print_r( $value_to_normalize, TRUE), gettype( $value_to_normalize ) ) ); |
|
26 | + if ( ! is_string($value_to_normalize)) { |
|
27 | + throw new EE_Validation_Error(sprintf(__('The value "%s" must be a string submitted for normalization, it was %s', 'event_espresso'), print_r($value_to_normalize, TRUE), gettype($value_to_normalize))); |
|
28 | 28 | } |
29 | 29 | $thousands_separator = EE_Config::instance()->currency->thsnds; |
30 | - $value_to_normalize = str_replace( $thousands_separator, "", $value_to_normalize ); |
|
31 | - $value_to_normalize = str_replace( array(" ","\t"), '', $value_to_normalize ); |
|
32 | - if ( preg_match( '/^\d+$/', $value_to_normalize )) { |
|
33 | - return intval( $value_to_normalize ); |
|
30 | + $value_to_normalize = str_replace($thousands_separator, "", $value_to_normalize); |
|
31 | + $value_to_normalize = str_replace(array(" ", "\t"), '', $value_to_normalize); |
|
32 | + if (preg_match('/^\d+$/', $value_to_normalize)) { |
|
33 | + return intval($value_to_normalize); |
|
34 | 34 | } else { |
35 | 35 | //find if this input has a int validation strategy |
36 | 36 | //in which case, use its message |
37 | 37 | $validation_error_message = NULL; |
38 | - foreach( $this->_input->get_validation_strategies() as $validation_strategy ){ |
|
39 | - if( $validation_strategy instanceof EE_Int_Validation_Strategy ){ |
|
38 | + foreach ($this->_input->get_validation_strategies() as $validation_strategy) { |
|
39 | + if ($validation_strategy instanceof EE_Int_Validation_Strategy) { |
|
40 | 40 | $validation_error_message = $validation_strategy->get_validation_error_message(); |
41 | 41 | } |
42 | 42 | } |
43 | 43 | //this really shouldn't ever happen because fields with a int normalization strategy |
44 | 44 | //should also have a int validation strategy, but in case it doesnt use the default |
45 | - if( ! $validation_error_message ){ |
|
45 | + if ( ! $validation_error_message) { |
|
46 | 46 | $default_validation_strategy = new EE_Int_Validation_Strategy(); |
47 | 47 | $validation_error_message = $default_validation_strategy->get_validation_error_message(); |
48 | 48 | } |
49 | - throw new EE_Validation_Error( $validation_error_message, 'numeric_only' ); |
|
49 | + throw new EE_Validation_Error($validation_error_message, 'numeric_only'); |
|
50 | 50 | } |
51 | 51 | } |
52 | 52 | |
@@ -55,12 +55,12 @@ discard block |
||
55 | 55 | * @param int $normalized_value |
56 | 56 | * @return string |
57 | 57 | */ |
58 | - public function unnormalize( $normalized_value ) { |
|
58 | + public function unnormalize($normalized_value) { |
|
59 | 59 | if ($normalized_value === null) { |
60 | 60 | return ''; |
61 | - }elseif( empty( $normalized_value ) ){ |
|
61 | + }elseif (empty($normalized_value)) { |
|
62 | 62 | return '0'; |
63 | - }else{ |
|
63 | + } else { |
|
64 | 64 | return "$normalized_value"; |
65 | 65 | } |
66 | 66 | } |
@@ -58,9 +58,9 @@ |
||
58 | 58 | public function unnormalize( $normalized_value ) { |
59 | 59 | if ($normalized_value === null) { |
60 | 60 | return ''; |
61 | - }elseif( empty( $normalized_value ) ){ |
|
61 | + } elseif( empty( $normalized_value ) ){ |
|
62 | 62 | return '0'; |
63 | - }else{ |
|
63 | + } else{ |
|
64 | 64 | return "$normalized_value"; |
65 | 65 | } |
66 | 66 | } |