@@ -121,7 +121,7 @@ discard block |
||
121 | 121 | ), |
122 | 122 | ), |
123 | 123 | ); |
124 | - $this->_model_relations = array( |
|
124 | + $this->_model_relations = array( |
|
125 | 125 | 'Ticket' => new EE_HABTM_Relation('Datetime_Ticket'), |
126 | 126 | 'Event' => new EE_Belongs_To_Relation(), |
127 | 127 | 'Checkin' => new EE_Has_Many_Relation(), |
@@ -131,16 +131,16 @@ discard block |
||
131 | 131 | $this->model_chain_to_password = $path_to_event_model; |
132 | 132 | $this->_model_chain_to_wp_user = $path_to_event_model; |
133 | 133 | // this model is generally available for reading |
134 | - $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Event_Related_Public( |
|
134 | + $this->_cap_restriction_generators[EEM_Base::caps_read] = new EE_Restriction_Generator_Event_Related_Public( |
|
135 | 135 | $path_to_event_model |
136 | 136 | ); |
137 | - $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] = new EE_Restriction_Generator_Event_Related_Protected( |
|
137 | + $this->_cap_restriction_generators[EEM_Base::caps_read_admin] = new EE_Restriction_Generator_Event_Related_Protected( |
|
138 | 138 | $path_to_event_model |
139 | 139 | ); |
140 | - $this->_cap_restriction_generators[ EEM_Base::caps_edit ] = new EE_Restriction_Generator_Event_Related_Protected( |
|
140 | + $this->_cap_restriction_generators[EEM_Base::caps_edit] = new EE_Restriction_Generator_Event_Related_Protected( |
|
141 | 141 | $path_to_event_model |
142 | 142 | ); |
143 | - $this->_cap_restriction_generators[ EEM_Base::caps_delete ] = new EE_Restriction_Generator_Event_Related_Protected( |
|
143 | + $this->_cap_restriction_generators[EEM_Base::caps_delete] = new EE_Restriction_Generator_Event_Related_Protected( |
|
144 | 144 | $path_to_event_model, |
145 | 145 | EEM_Base::caps_edit |
146 | 146 | ); |
@@ -246,10 +246,10 @@ discard block |
||
246 | 246 | */ |
247 | 247 | private function validateStartAndEndTimeForBlankDate($start_time, $end_time) |
248 | 248 | { |
249 | - if (! is_array($start_time)) { |
|
249 | + if ( ! is_array($start_time)) { |
|
250 | 250 | throw new InvalidDataTypeException('start_time', $start_time, 'array'); |
251 | 251 | } |
252 | - if (! is_array($end_time)) { |
|
252 | + if ( ! is_array($end_time)) { |
|
253 | 253 | throw new InvalidDataTypeException('end_time', $end_time, 'array'); |
254 | 254 | } |
255 | 255 | if (count($start_time) !== 2) { |
@@ -283,7 +283,7 @@ discard block |
||
283 | 283 | */ |
284 | 284 | public function get_all_event_dates($EVT_ID = 0) |
285 | 285 | { |
286 | - if (! $EVT_ID) { // on add_new_event event_id gets set to 0 |
|
286 | + if ( ! $EVT_ID) { // on add_new_event event_id gets set to 0 |
|
287 | 287 | return $this->create_new_blank_datetime(); |
288 | 288 | } |
289 | 289 | $results = $this->get_datetimes_for_event_ordered_by_DTT_order($EVT_ID); |
@@ -329,7 +329,7 @@ discard block |
||
329 | 329 | 'order_by' => array('DTT_order' => 'ASC'), |
330 | 330 | 'default_where_conditions' => 'none', |
331 | 331 | ); |
332 | - if (! $include_expired) { |
|
332 | + if ( ! $include_expired) { |
|
333 | 333 | $query_params[0]['DTT_EVT_end'] = array('>=', current_time('mysql', true)); |
334 | 334 | } |
335 | 335 | if ($include_deleted) { |
@@ -448,7 +448,7 @@ discard block |
||
448 | 448 | ), |
449 | 449 | 'default_where_conditions' => EEM_Base::default_where_conditions_this_only |
450 | 450 | ); |
451 | - if (! $include_expired) { |
|
451 | + if ( ! $include_expired) { |
|
452 | 452 | $query_params[0]['DTT_EVT_end'] = array('>=', current_time('mysql', true)); |
453 | 453 | } |
454 | 454 | if ($include_deleted) { |
@@ -486,7 +486,7 @@ discard block |
||
486 | 486 | $old_assumption = $this->get_assumption_concerning_values_already_prepared_by_model_object(); |
487 | 487 | $this->assume_values_already_prepared_by_model_object(EEM_Base::prepared_for_use_in_db); |
488 | 488 | $query_params = array(array('Ticket.TKT_ID' => $TKT_ID), 'order_by' => array('DTT_EVT_start' => 'asc')); |
489 | - if (! $include_expired) { |
|
489 | + if ( ! $include_expired) { |
|
490 | 490 | $query_params[0]['DTT_EVT_end'] = array('>=', current_time('mysql', true)); |
491 | 491 | } |
492 | 492 | if ($include_deleted) { |
@@ -526,7 +526,7 @@ discard block |
||
526 | 526 | $this->assume_values_already_prepared_by_model_object(EEM_Base::prepared_for_use_in_db); |
527 | 527 | $where_params = array('Ticket.TKT_ID' => $TKT_ID); |
528 | 528 | $query_params = array($where_params, 'order_by' => array('DTT_order' => 'ASC')); |
529 | - if (! $include_expired) { |
|
529 | + if ( ! $include_expired) { |
|
530 | 530 | $query_params[0]['DTT_EVT_end'] = array('>=', current_time('mysql', true)); |
531 | 531 | } |
532 | 532 | if ($include_deleted) { |
@@ -649,10 +649,10 @@ discard block |
||
649 | 649 | $this->get_timezone(), |
650 | 650 | 'DTT_EVT_start' |
651 | 651 | ); |
652 | - $columns_to_select = array( |
|
653 | - 'dtt_year' => array('YEAR(' . $query_interval . ')', '%s'), |
|
654 | - 'dtt_month' => array('MONTHNAME(' . $query_interval . ')', '%s'), |
|
655 | - 'dtt_month_num' => array('MONTH(' . $query_interval . ')', '%s'), |
|
652 | + $columns_to_select = array( |
|
653 | + 'dtt_year' => array('YEAR('.$query_interval.')', '%s'), |
|
654 | + 'dtt_month' => array('MONTHNAME('.$query_interval.')', '%s'), |
|
655 | + 'dtt_month_num' => array('MONTH('.$query_interval.')', '%s'), |
|
656 | 656 | ); |
657 | 657 | return $this->_get_all_wpdb_results($query_params, OBJECT, $columns_to_select); |
658 | 658 | } |
@@ -731,17 +731,17 @@ discard block |
||
731 | 731 | array('DTT_EVT_end' => array('<', time())) |
732 | 732 | ), |
733 | 733 | ); |
734 | - if (! empty($stati_to_include)) { |
|
734 | + if ( ! empty($stati_to_include)) { |
|
735 | 735 | foreach (array_keys($status_query_args) as $status) { |
736 | - if (! in_array($status, $stati_to_include, true)) { |
|
737 | - unset($status_query_args[ $status ]); |
|
736 | + if ( ! in_array($status, $stati_to_include, true)) { |
|
737 | + unset($status_query_args[$status]); |
|
738 | 738 | } |
739 | 739 | } |
740 | 740 | } |
741 | 741 | // loop through and query counts for each stati. |
742 | 742 | $status_query_results = array(); |
743 | 743 | foreach ($status_query_args as $status => $status_where_conditions) { |
744 | - $status_query_results[ $status ] = EEM_Datetime::count( |
|
744 | + $status_query_results[$status] = EEM_Datetime::count( |
|
745 | 745 | array($status_where_conditions), |
746 | 746 | 'DTT_ID', |
747 | 747 | true |
@@ -762,6 +762,6 @@ discard block |
||
762 | 762 | public function get_datetime_count_for_status($status = EE_Datetime::active, array $query_params = array()) |
763 | 763 | { |
764 | 764 | $count = $this->get_datetime_counts_by_status(array($status), $query_params); |
765 | - return ! empty($count[ $status ]) ? $count[ $status ] : 0; |
|
765 | + return ! empty($count[$status]) ? $count[$status] : 0; |
|
766 | 766 | } |
767 | 767 | } |
@@ -13,755 +13,755 @@ |
||
13 | 13 | class EEM_Datetime extends EEM_Soft_Delete_Base |
14 | 14 | { |
15 | 15 | |
16 | - /** |
|
17 | - * @var EEM_Datetime $_instance |
|
18 | - */ |
|
19 | - protected static $_instance; |
|
20 | - |
|
21 | - |
|
22 | - /** |
|
23 | - * private constructor to prevent direct creation |
|
24 | - * |
|
25 | - * @param string $timezone A string representing the timezone we want to set for returned Date Time Strings |
|
26 | - * (and any incoming timezone data that gets saved). |
|
27 | - * Note this just sends the timezone info to the date time model field objects. |
|
28 | - * Default is NULL |
|
29 | - * (and will be assumed using the set timezone in the 'timezone_string' wp option) |
|
30 | - * @throws EE_Error |
|
31 | - * @throws InvalidArgumentException |
|
32 | - * @throws InvalidArgumentException |
|
33 | - */ |
|
34 | - protected function __construct($timezone) |
|
35 | - { |
|
36 | - $this->singular_item = esc_html__('Datetime', 'event_espresso'); |
|
37 | - $this->plural_item = esc_html__('Datetimes', 'event_espresso'); |
|
38 | - $this->_tables = array( |
|
39 | - 'Datetime' => new EE_Primary_Table('esp_datetime', 'DTT_ID'), |
|
40 | - ); |
|
41 | - $this->_fields = array( |
|
42 | - 'Datetime' => array( |
|
43 | - 'DTT_ID' => new EE_Primary_Key_Int_Field( |
|
44 | - 'DTT_ID', |
|
45 | - esc_html__('Datetime ID', 'event_espresso') |
|
46 | - ), |
|
47 | - 'EVT_ID' => new EE_Foreign_Key_Int_Field( |
|
48 | - 'EVT_ID', |
|
49 | - esc_html__('Event ID', 'event_espresso'), |
|
50 | - false, |
|
51 | - 0, |
|
52 | - 'Event' |
|
53 | - ), |
|
54 | - 'DTT_name' => new EE_Plain_Text_Field( |
|
55 | - 'DTT_name', |
|
56 | - esc_html__('Datetime Name', 'event_espresso'), |
|
57 | - false, |
|
58 | - '' |
|
59 | - ), |
|
60 | - 'DTT_description' => new EE_Post_Content_Field( |
|
61 | - 'DTT_description', |
|
62 | - esc_html__('Description for Datetime', 'event_espresso'), |
|
63 | - false, |
|
64 | - '' |
|
65 | - ), |
|
66 | - 'DTT_EVT_start' => new EE_Datetime_Field( |
|
67 | - 'DTT_EVT_start', |
|
68 | - esc_html__('Start time/date of Event', 'event_espresso'), |
|
69 | - false, |
|
70 | - EE_Datetime_Field::now, |
|
71 | - $timezone |
|
72 | - ), |
|
73 | - 'DTT_EVT_end' => new EE_Datetime_Field( |
|
74 | - 'DTT_EVT_end', |
|
75 | - esc_html__('End time/date of Event', 'event_espresso'), |
|
76 | - false, |
|
77 | - EE_Datetime_Field::now, |
|
78 | - $timezone |
|
79 | - ), |
|
80 | - 'DTT_reg_limit' => new EE_Infinite_Integer_Field( |
|
81 | - 'DTT_reg_limit', |
|
82 | - esc_html__('Registration Limit for this time', 'event_espresso'), |
|
83 | - true, |
|
84 | - EE_INF |
|
85 | - ), |
|
86 | - 'DTT_sold' => new EE_Integer_Field( |
|
87 | - 'DTT_sold', |
|
88 | - esc_html__('How many sales for this Datetime that have occurred', 'event_espresso'), |
|
89 | - true, |
|
90 | - 0 |
|
91 | - ), |
|
92 | - 'DTT_reserved' => new EE_Integer_Field( |
|
93 | - 'DTT_reserved', |
|
94 | - esc_html__('Quantity of tickets reserved, but not yet fully purchased', 'event_espresso'), |
|
95 | - false, |
|
96 | - 0 |
|
97 | - ), |
|
98 | - 'DTT_is_primary' => new EE_Boolean_Field( |
|
99 | - 'DTT_is_primary', |
|
100 | - esc_html__('Flag indicating datetime is primary one for event', 'event_espresso'), |
|
101 | - false, |
|
102 | - false |
|
103 | - ), |
|
104 | - 'DTT_order' => new EE_Integer_Field( |
|
105 | - 'DTT_order', |
|
106 | - esc_html__('The order in which the Datetime is displayed', 'event_espresso'), |
|
107 | - false, |
|
108 | - 0 |
|
109 | - ), |
|
110 | - 'DTT_parent' => new EE_Integer_Field( |
|
111 | - 'DTT_parent', |
|
112 | - esc_html__('Indicates what DTT_ID is the parent of this DTT_ID', 'event_espresso'), |
|
113 | - true, |
|
114 | - 0 |
|
115 | - ), |
|
116 | - 'DTT_deleted' => new EE_Trashed_Flag_Field( |
|
117 | - 'DTT_deleted', |
|
118 | - esc_html__('Flag indicating datetime is archived', 'event_espresso'), |
|
119 | - false, |
|
120 | - false |
|
121 | - ), |
|
122 | - ), |
|
123 | - ); |
|
124 | - $this->_model_relations = array( |
|
125 | - 'Ticket' => new EE_HABTM_Relation('Datetime_Ticket'), |
|
126 | - 'Event' => new EE_Belongs_To_Relation(), |
|
127 | - 'Checkin' => new EE_Has_Many_Relation(), |
|
128 | - 'Datetime_Ticket' => new EE_Has_Many_Relation(), |
|
129 | - ); |
|
130 | - $path_to_event_model = 'Event'; |
|
131 | - $this->model_chain_to_password = $path_to_event_model; |
|
132 | - $this->_model_chain_to_wp_user = $path_to_event_model; |
|
133 | - // this model is generally available for reading |
|
134 | - $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Event_Related_Public( |
|
135 | - $path_to_event_model |
|
136 | - ); |
|
137 | - $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] = new EE_Restriction_Generator_Event_Related_Protected( |
|
138 | - $path_to_event_model |
|
139 | - ); |
|
140 | - $this->_cap_restriction_generators[ EEM_Base::caps_edit ] = new EE_Restriction_Generator_Event_Related_Protected( |
|
141 | - $path_to_event_model |
|
142 | - ); |
|
143 | - $this->_cap_restriction_generators[ EEM_Base::caps_delete ] = new EE_Restriction_Generator_Event_Related_Protected( |
|
144 | - $path_to_event_model, |
|
145 | - EEM_Base::caps_edit |
|
146 | - ); |
|
147 | - parent::__construct($timezone); |
|
148 | - } |
|
149 | - |
|
150 | - |
|
151 | - /** |
|
152 | - * create new blank datetime |
|
153 | - * |
|
154 | - * @access public |
|
155 | - * @return EE_Datetime[] array on success, FALSE on fail |
|
156 | - * @throws EE_Error |
|
157 | - * @throws InvalidArgumentException |
|
158 | - * @throws InvalidDataTypeException |
|
159 | - * @throws ReflectionException |
|
160 | - * @throws InvalidInterfaceException |
|
161 | - */ |
|
162 | - public function create_new_blank_datetime() |
|
163 | - { |
|
164 | - // makes sure timezone is always set. |
|
165 | - $timezone_string = $this->get_timezone(); |
|
166 | - /** |
|
167 | - * Filters the initial start date for the new datetime. |
|
168 | - * Any time included in this value will be overridden later so use additional filters to modify the time. |
|
169 | - * |
|
170 | - * @param int $start_date Unixtimestamp representing now + 30 days in seconds. |
|
171 | - * @return int unixtimestamp |
|
172 | - */ |
|
173 | - $start_date = apply_filters( |
|
174 | - 'FHEE__EEM_Datetime__create_new_blank_datetime__start_date', |
|
175 | - $this->current_time_for_query('DTT_EVT_start', true) + MONTH_IN_SECONDS |
|
176 | - ); |
|
177 | - /** |
|
178 | - * Filters the initial end date for the new datetime. |
|
179 | - * Any time included in this value will be overridden later so use additional filters to modify the time. |
|
180 | - * |
|
181 | - * @param int $end_data Unixtimestamp representing now + 30 days in seconds. |
|
182 | - * @return int unixtimestamp |
|
183 | - */ |
|
184 | - $end_date = apply_filters( |
|
185 | - 'FHEE__EEM_Datetime__create_new_blank_datetime__end_date', |
|
186 | - $this->current_time_for_query('DTT_EVT_end', true) + MONTH_IN_SECONDS |
|
187 | - ); |
|
188 | - $blank_datetime = EE_Datetime::new_instance( |
|
189 | - array( |
|
190 | - 'DTT_EVT_start' => $start_date, |
|
191 | - 'DTT_EVT_end' => $end_date, |
|
192 | - 'DTT_order' => 1, |
|
193 | - 'DTT_reg_limit' => EE_INF, |
|
194 | - ), |
|
195 | - $timezone_string |
|
196 | - ); |
|
197 | - /** |
|
198 | - * Filters the initial start time and format for the new EE_Datetime instance. |
|
199 | - * |
|
200 | - * @param array $start_time An array having size 2. First element is the time, second element is the time |
|
201 | - * format. |
|
202 | - * @return array |
|
203 | - */ |
|
204 | - $start_time = apply_filters( |
|
205 | - 'FHEE__EEM_Datetime__create_new_blank_datetime__start_time', |
|
206 | - ['8am', 'ga'] |
|
207 | - ); |
|
208 | - /** |
|
209 | - * Filters the initial end time and format for the new EE_Datetime instance. |
|
210 | - * |
|
211 | - * @param array $end_time An array having size 2. First element is the time, second element is the time |
|
212 | - * format |
|
213 | - * @return array |
|
214 | - */ |
|
215 | - $end_time = apply_filters( |
|
216 | - 'FHEE__EEM_Datetime__create_new_blank_datetime__end_time', |
|
217 | - ['5pm', 'ga'] |
|
218 | - ); |
|
219 | - $this->validateStartAndEndTimeForBlankDate($start_time, $end_time); |
|
220 | - $blank_datetime->set_start_time( |
|
221 | - $this->convert_datetime_for_query( |
|
222 | - 'DTT_EVT_start', |
|
223 | - $start_time[0], |
|
224 | - $start_time[1], |
|
225 | - $timezone_string |
|
226 | - ) |
|
227 | - ); |
|
228 | - $blank_datetime->set_end_time( |
|
229 | - $this->convert_datetime_for_query( |
|
230 | - 'DTT_EVT_end', |
|
231 | - $end_time[0], |
|
232 | - $end_time[1], |
|
233 | - $timezone_string |
|
234 | - ) |
|
235 | - ); |
|
236 | - return array($blank_datetime); |
|
237 | - } |
|
238 | - |
|
239 | - |
|
240 | - /** |
|
241 | - * Validates whether the start_time and end_time are in the expected format. |
|
242 | - * @param array $start_time |
|
243 | - * @param array $end_time |
|
244 | - * @throws InvalidArgumentException |
|
245 | - * @throws InvalidDataTypeException |
|
246 | - */ |
|
247 | - private function validateStartAndEndTimeForBlankDate($start_time, $end_time) |
|
248 | - { |
|
249 | - if (! is_array($start_time)) { |
|
250 | - throw new InvalidDataTypeException('start_time', $start_time, 'array'); |
|
251 | - } |
|
252 | - if (! is_array($end_time)) { |
|
253 | - throw new InvalidDataTypeException('end_time', $end_time, 'array'); |
|
254 | - } |
|
255 | - if (count($start_time) !== 2) { |
|
256 | - throw new InvalidArgumentException( |
|
257 | - sprintf( |
|
258 | - 'The variable %1$s is expected to be an array with two elements. The first item in the ' |
|
259 | - . 'array should be a valid time string, the second item in the array should be a valid time format', |
|
260 | - '$start_time' |
|
261 | - ) |
|
262 | - ); |
|
263 | - } |
|
264 | - if (count($end_time) !== 2) { |
|
265 | - throw new InvalidArgumentException( |
|
266 | - sprintf( |
|
267 | - 'The variable %1$s is expected to be an array with two elements. The first item in the ' |
|
268 | - . 'array should be a valid time string, the second item in the array should be a valid time format', |
|
269 | - '$end_time' |
|
270 | - ) |
|
271 | - ); |
|
272 | - } |
|
273 | - } |
|
274 | - |
|
275 | - |
|
276 | - /** |
|
277 | - * get event start date from db |
|
278 | - * |
|
279 | - * @access public |
|
280 | - * @param int $EVT_ID |
|
281 | - * @return EE_Datetime[] array on success, FALSE on fail |
|
282 | - * @throws EE_Error |
|
283 | - */ |
|
284 | - public function get_all_event_dates($EVT_ID = 0) |
|
285 | - { |
|
286 | - if (! $EVT_ID) { // on add_new_event event_id gets set to 0 |
|
287 | - return $this->create_new_blank_datetime(); |
|
288 | - } |
|
289 | - $results = $this->get_datetimes_for_event_ordered_by_DTT_order($EVT_ID); |
|
290 | - if (empty($results)) { |
|
291 | - return $this->create_new_blank_datetime(); |
|
292 | - } |
|
293 | - return $results; |
|
294 | - } |
|
295 | - |
|
296 | - |
|
297 | - /** |
|
298 | - * get all datetimes attached to an event ordered by the DTT_order field |
|
299 | - * |
|
300 | - * @public |
|
301 | - * @param int $EVT_ID event id |
|
302 | - * @param boolean $include_expired |
|
303 | - * @param boolean $include_deleted |
|
304 | - * @param int $limit If included then limit the count of results by |
|
305 | - * the given number |
|
306 | - * @return EE_Datetime[] |
|
307 | - * @throws EE_Error |
|
308 | - */ |
|
309 | - public function get_datetimes_for_event_ordered_by_DTT_order( |
|
310 | - $EVT_ID, |
|
311 | - $include_expired = true, |
|
312 | - $include_deleted = true, |
|
313 | - $limit = null |
|
314 | - ) { |
|
315 | - // sanitize EVT_ID |
|
316 | - $EVT_ID = absint($EVT_ID); |
|
317 | - $old_assumption = $this->get_assumption_concerning_values_already_prepared_by_model_object(); |
|
318 | - $this->assume_values_already_prepared_by_model_object(EEM_Base::prepared_for_use_in_db); |
|
319 | - $where_params = array('Event.EVT_ID' => $EVT_ID); |
|
320 | - $query_params = ! empty($limit) |
|
321 | - ? array( |
|
322 | - $where_params, |
|
323 | - 'limit' => $limit, |
|
324 | - 'order_by' => array('DTT_order' => 'ASC'), |
|
325 | - 'default_where_conditions' => 'none', |
|
326 | - ) |
|
327 | - : array( |
|
328 | - $where_params, |
|
329 | - 'order_by' => array('DTT_order' => 'ASC'), |
|
330 | - 'default_where_conditions' => 'none', |
|
331 | - ); |
|
332 | - if (! $include_expired) { |
|
333 | - $query_params[0]['DTT_EVT_end'] = array('>=', current_time('mysql', true)); |
|
334 | - } |
|
335 | - if ($include_deleted) { |
|
336 | - $query_params[0]['DTT_deleted'] = array('IN', array(true, false)); |
|
337 | - } |
|
338 | - /** @var EE_Datetime[] $result */ |
|
339 | - $result = $this->get_all($query_params); |
|
340 | - $this->assume_values_already_prepared_by_model_object($old_assumption); |
|
341 | - return $result; |
|
342 | - } |
|
343 | - |
|
344 | - |
|
345 | - /** |
|
346 | - * Gets the datetimes for the event (with the given limit), and orders them by "importance". |
|
347 | - * By importance, we mean that the primary datetimes are most important (DEPRECATED FOR NOW), |
|
348 | - * and then the earlier datetimes are the most important. |
|
349 | - * Maybe we'll want this to take into account datetimes that haven't already passed, but we don't yet. |
|
350 | - * |
|
351 | - * @param int $EVT_ID |
|
352 | - * @param int $limit |
|
353 | - * @return EE_Datetime[]|EE_Base_Class[] |
|
354 | - * @throws EE_Error |
|
355 | - */ |
|
356 | - public function get_datetimes_for_event_ordered_by_importance($EVT_ID = 0, $limit = null) |
|
357 | - { |
|
358 | - return $this->get_all( |
|
359 | - array( |
|
360 | - array('Event.EVT_ID' => $EVT_ID), |
|
361 | - 'limit' => $limit, |
|
362 | - 'order_by' => array('DTT_EVT_start' => 'ASC'), |
|
363 | - 'default_where_conditions' => 'none', |
|
364 | - ) |
|
365 | - ); |
|
366 | - } |
|
367 | - |
|
368 | - |
|
369 | - /** |
|
370 | - * @param int $EVT_ID |
|
371 | - * @param boolean $include_expired |
|
372 | - * @param boolean $include_deleted |
|
373 | - * @return EE_Datetime |
|
374 | - * @throws EE_Error |
|
375 | - */ |
|
376 | - public function get_oldest_datetime_for_event($EVT_ID, $include_expired = false, $include_deleted = false) |
|
377 | - { |
|
378 | - $results = $this->get_datetimes_for_event_ordered_by_start_time( |
|
379 | - $EVT_ID, |
|
380 | - $include_expired, |
|
381 | - $include_deleted, |
|
382 | - 1 |
|
383 | - ); |
|
384 | - if ($results) { |
|
385 | - return array_shift($results); |
|
386 | - } |
|
387 | - return null; |
|
388 | - } |
|
389 | - |
|
390 | - |
|
391 | - /** |
|
392 | - * Gets the 'primary' datetime for an event. |
|
393 | - * |
|
394 | - * @param int $EVT_ID |
|
395 | - * @param bool $try_to_exclude_expired |
|
396 | - * @param bool $try_to_exclude_deleted |
|
397 | - * @return \EE_Datetime |
|
398 | - * @throws EE_Error |
|
399 | - */ |
|
400 | - public function get_primary_datetime_for_event( |
|
401 | - $EVT_ID, |
|
402 | - $try_to_exclude_expired = true, |
|
403 | - $try_to_exclude_deleted = true |
|
404 | - ) { |
|
405 | - if ($try_to_exclude_expired) { |
|
406 | - $non_expired = $this->get_oldest_datetime_for_event($EVT_ID, false, false); |
|
407 | - if ($non_expired) { |
|
408 | - return $non_expired; |
|
409 | - } |
|
410 | - } |
|
411 | - if ($try_to_exclude_deleted) { |
|
412 | - $expired_even = $this->get_oldest_datetime_for_event($EVT_ID, true); |
|
413 | - if ($expired_even) { |
|
414 | - return $expired_even; |
|
415 | - } |
|
416 | - } |
|
417 | - return $this->get_oldest_datetime_for_event($EVT_ID, true, true); |
|
418 | - } |
|
419 | - |
|
420 | - |
|
421 | - /** |
|
422 | - * Gets ALL the datetimes for an event (including trashed ones, for now), ordered |
|
423 | - * only by start date |
|
424 | - * |
|
425 | - * @param int $EVT_ID |
|
426 | - * @param boolean $include_expired |
|
427 | - * @param boolean $include_deleted |
|
428 | - * @param int $limit |
|
429 | - * @return EE_Datetime[] |
|
430 | - * @throws EE_Error |
|
431 | - */ |
|
432 | - public function get_datetimes_for_event_ordered_by_start_time( |
|
433 | - $EVT_ID, |
|
434 | - $include_expired = true, |
|
435 | - $include_deleted = true, |
|
436 | - $limit = null |
|
437 | - ) { |
|
438 | - // sanitize EVT_ID |
|
439 | - $EVT_ID = absint($EVT_ID); |
|
440 | - $old_assumption = $this->get_assumption_concerning_values_already_prepared_by_model_object(); |
|
441 | - $this->assume_values_already_prepared_by_model_object(EEM_Base::prepared_for_use_in_db); |
|
442 | - $query_params = array( |
|
443 | - array( |
|
444 | - 'Event.EVT_ID' => $EVT_ID |
|
445 | - ), |
|
446 | - 'order_by' => array( |
|
447 | - 'DTT_EVT_start' => 'asc' |
|
448 | - ), |
|
449 | - 'default_where_conditions' => EEM_Base::default_where_conditions_this_only |
|
450 | - ); |
|
451 | - if (! $include_expired) { |
|
452 | - $query_params[0]['DTT_EVT_end'] = array('>=', current_time('mysql', true)); |
|
453 | - } |
|
454 | - if ($include_deleted) { |
|
455 | - $query_params[0]['DTT_deleted'] = array('IN', array(true, false)); |
|
456 | - } |
|
457 | - if ($limit) { |
|
458 | - $query_params['limit'] = $limit; |
|
459 | - } |
|
460 | - /** @var EE_Datetime[] $result */ |
|
461 | - $result = $this->get_all($query_params); |
|
462 | - $this->assume_values_already_prepared_by_model_object($old_assumption); |
|
463 | - return $result; |
|
464 | - } |
|
465 | - |
|
466 | - |
|
467 | - /** |
|
468 | - * Gets ALL the datetimes for an ticket (including trashed ones, for now), ordered |
|
469 | - * only by start date |
|
470 | - * |
|
471 | - * @param int $TKT_ID |
|
472 | - * @param boolean $include_expired |
|
473 | - * @param boolean $include_deleted |
|
474 | - * @param int $limit |
|
475 | - * @return EE_Datetime[] |
|
476 | - * @throws EE_Error |
|
477 | - */ |
|
478 | - public function get_datetimes_for_ticket_ordered_by_start_time( |
|
479 | - $TKT_ID, |
|
480 | - $include_expired = true, |
|
481 | - $include_deleted = true, |
|
482 | - $limit = null |
|
483 | - ) { |
|
484 | - // sanitize TKT_ID |
|
485 | - $TKT_ID = absint($TKT_ID); |
|
486 | - $old_assumption = $this->get_assumption_concerning_values_already_prepared_by_model_object(); |
|
487 | - $this->assume_values_already_prepared_by_model_object(EEM_Base::prepared_for_use_in_db); |
|
488 | - $query_params = array(array('Ticket.TKT_ID' => $TKT_ID), 'order_by' => array('DTT_EVT_start' => 'asc')); |
|
489 | - if (! $include_expired) { |
|
490 | - $query_params[0]['DTT_EVT_end'] = array('>=', current_time('mysql', true)); |
|
491 | - } |
|
492 | - if ($include_deleted) { |
|
493 | - $query_params[0]['DTT_deleted'] = array('IN', array(true, false)); |
|
494 | - } |
|
495 | - if ($limit) { |
|
496 | - $query_params['limit'] = $limit; |
|
497 | - } |
|
498 | - /** @var EE_Datetime[] $result */ |
|
499 | - $result = $this->get_all($query_params); |
|
500 | - $this->assume_values_already_prepared_by_model_object($old_assumption); |
|
501 | - return $result; |
|
502 | - } |
|
503 | - |
|
504 | - |
|
505 | - /** |
|
506 | - * Gets all the datetimes for a ticket (including trashed ones, for now), ordered by the DTT_order for the |
|
507 | - * datetimes. |
|
508 | - * |
|
509 | - * @param int $TKT_ID ID of ticket to retrieve the datetimes for |
|
510 | - * @param boolean $include_expired whether to include expired datetimes or not |
|
511 | - * @param boolean $include_deleted whether to include trashed datetimes or not. |
|
512 | - * @param int|null $limit if null, no limit, if int then limit results by |
|
513 | - * that number |
|
514 | - * @return EE_Datetime[] |
|
515 | - * @throws EE_Error |
|
516 | - */ |
|
517 | - public function get_datetimes_for_ticket_ordered_by_DTT_order( |
|
518 | - $TKT_ID, |
|
519 | - $include_expired = true, |
|
520 | - $include_deleted = true, |
|
521 | - $limit = null |
|
522 | - ) { |
|
523 | - // sanitize id. |
|
524 | - $TKT_ID = absint($TKT_ID); |
|
525 | - $old_assumption = $this->get_assumption_concerning_values_already_prepared_by_model_object(); |
|
526 | - $this->assume_values_already_prepared_by_model_object(EEM_Base::prepared_for_use_in_db); |
|
527 | - $where_params = array('Ticket.TKT_ID' => $TKT_ID); |
|
528 | - $query_params = array($where_params, 'order_by' => array('DTT_order' => 'ASC')); |
|
529 | - if (! $include_expired) { |
|
530 | - $query_params[0]['DTT_EVT_end'] = array('>=', current_time('mysql', true)); |
|
531 | - } |
|
532 | - if ($include_deleted) { |
|
533 | - $query_params[0]['DTT_deleted'] = array('IN', array(true, false)); |
|
534 | - } |
|
535 | - if ($limit) { |
|
536 | - $query_params['limit'] = $limit; |
|
537 | - } |
|
538 | - /** @var EE_Datetime[] $result */ |
|
539 | - $result = $this->get_all($query_params); |
|
540 | - $this->assume_values_already_prepared_by_model_object($old_assumption); |
|
541 | - return $result; |
|
542 | - } |
|
543 | - |
|
544 | - |
|
545 | - /** |
|
546 | - * Gets the most important datetime for a particular event (ie, the primary event usually. But if for some WACK |
|
547 | - * reason it doesn't exist, we consider the earliest event the most important) |
|
548 | - * |
|
549 | - * @param int $EVT_ID |
|
550 | - * @return EE_Datetime |
|
551 | - * @throws EE_Error |
|
552 | - */ |
|
553 | - public function get_most_important_datetime_for_event($EVT_ID) |
|
554 | - { |
|
555 | - $results = $this->get_datetimes_for_event_ordered_by_importance($EVT_ID, 1); |
|
556 | - if ($results) { |
|
557 | - return array_shift($results); |
|
558 | - } |
|
559 | - return null; |
|
560 | - } |
|
561 | - |
|
562 | - |
|
563 | - /** |
|
564 | - * This returns a wpdb->results Array of all DTT month and years matching the incoming query params and |
|
565 | - * grouped by month and year. |
|
566 | - * |
|
567 | - * @param array $where_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md#0-where-conditions |
|
568 | - * @param string $evt_active_status A string representing the evt active status to filter the months by. |
|
569 | - * Can be: |
|
570 | - * - '' = no filter |
|
571 | - * - upcoming = Published events with at least one upcoming datetime. |
|
572 | - * - expired = Events with all datetimes expired. |
|
573 | - * - active = Events that are published and have at least one datetime that |
|
574 | - * starts before now and ends after now. |
|
575 | - * - inactive = Events that are either not published. |
|
576 | - * @return stdClass[] |
|
577 | - * @throws EE_Error |
|
578 | - * @throws InvalidArgumentException |
|
579 | - * @throws InvalidArgumentException |
|
580 | - */ |
|
581 | - public function get_dtt_months_and_years($where_params, $evt_active_status = '') |
|
582 | - { |
|
583 | - $current_time_for_DTT_EVT_start = $this->current_time_for_query('DTT_EVT_start'); |
|
584 | - $current_time_for_DTT_EVT_end = $this->current_time_for_query('DTT_EVT_end'); |
|
585 | - switch ($evt_active_status) { |
|
586 | - case 'upcoming': |
|
587 | - $where_params['Event.status'] = 'publish'; |
|
588 | - // if there are already query_params matching DTT_EVT_start then we need to modify that to add them. |
|
589 | - if (isset($where_params['DTT_EVT_start'])) { |
|
590 | - $where_params['DTT_EVT_start*****'] = $where_params['DTT_EVT_start']; |
|
591 | - } |
|
592 | - $where_params['DTT_EVT_start'] = array('>', $current_time_for_DTT_EVT_start); |
|
593 | - break; |
|
594 | - case 'expired': |
|
595 | - if (isset($where_params['Event.status'])) { |
|
596 | - unset($where_params['Event.status']); |
|
597 | - } |
|
598 | - // get events to exclude |
|
599 | - $exclude_query[0] = array_merge( |
|
600 | - $where_params, |
|
601 | - array('DTT_EVT_end' => array('>', $current_time_for_DTT_EVT_end)) |
|
602 | - ); |
|
603 | - // first get all events that have datetimes where its not expired. |
|
604 | - $event_ids = $this->_get_all_wpdb_results( |
|
605 | - $exclude_query, |
|
606 | - OBJECT_K, |
|
607 | - 'Datetime.EVT_ID' |
|
608 | - ); |
|
609 | - $event_ids = array_keys($event_ids); |
|
610 | - if (isset($where_params['DTT_EVT_end'])) { |
|
611 | - $where_params['DTT_EVT_end****'] = $where_params['DTT_EVT_end']; |
|
612 | - } |
|
613 | - $where_params['DTT_EVT_end'] = array('<', $current_time_for_DTT_EVT_end); |
|
614 | - $where_params['Event.EVT_ID'] = array('NOT IN', $event_ids); |
|
615 | - break; |
|
616 | - case 'active': |
|
617 | - $where_params['Event.status'] = 'publish'; |
|
618 | - if (isset($where_params['DTT_EVT_start'])) { |
|
619 | - $where_params['Datetime.DTT_EVT_start******'] = $where_params['DTT_EVT_start']; |
|
620 | - } |
|
621 | - if (isset($where_params['Datetime.DTT_EVT_end'])) { |
|
622 | - $where_params['Datetime.DTT_EVT_end*****'] = $where_params['DTT_EVT_end']; |
|
623 | - } |
|
624 | - $where_params['DTT_EVT_start'] = array('<', $current_time_for_DTT_EVT_start); |
|
625 | - $where_params['DTT_EVT_end'] = array('>', $current_time_for_DTT_EVT_end); |
|
626 | - break; |
|
627 | - case 'inactive': |
|
628 | - if (isset($where_params['Event.status'])) { |
|
629 | - unset($where_params['Event.status']); |
|
630 | - } |
|
631 | - if (isset($where_params['OR'])) { |
|
632 | - $where_params['AND']['OR'] = $where_params['OR']; |
|
633 | - } |
|
634 | - if (isset($where_params['DTT_EVT_end'])) { |
|
635 | - $where_params['AND']['DTT_EVT_end****'] = $where_params['DTT_EVT_end']; |
|
636 | - unset($where_params['DTT_EVT_end']); |
|
637 | - } |
|
638 | - if (isset($where_params['DTT_EVT_start'])) { |
|
639 | - $where_params['AND']['DTT_EVT_start'] = $where_params['DTT_EVT_start']; |
|
640 | - unset($where_params['DTT_EVT_start']); |
|
641 | - } |
|
642 | - $where_params['AND']['Event.status'] = array('!=', 'publish'); |
|
643 | - break; |
|
644 | - } |
|
645 | - $query_params[0] = $where_params; |
|
646 | - $query_params['group_by'] = array('dtt_year', 'dtt_month'); |
|
647 | - $query_params['order_by'] = array('DTT_EVT_start' => 'DESC'); |
|
648 | - $query_interval = EEH_DTT_Helper::get_sql_query_interval_for_offset( |
|
649 | - $this->get_timezone(), |
|
650 | - 'DTT_EVT_start' |
|
651 | - ); |
|
652 | - $columns_to_select = array( |
|
653 | - 'dtt_year' => array('YEAR(' . $query_interval . ')', '%s'), |
|
654 | - 'dtt_month' => array('MONTHNAME(' . $query_interval . ')', '%s'), |
|
655 | - 'dtt_month_num' => array('MONTH(' . $query_interval . ')', '%s'), |
|
656 | - ); |
|
657 | - return $this->_get_all_wpdb_results($query_params, OBJECT, $columns_to_select); |
|
658 | - } |
|
659 | - |
|
660 | - |
|
661 | - /** |
|
662 | - * Updates the DTT_sold attribute on each datetime (based on the registrations |
|
663 | - * for the tickets for each datetime) |
|
664 | - * |
|
665 | - * @param EE_Base_Class[]|EE_Datetime[] $datetimes |
|
666 | - * @throws EE_Error |
|
667 | - */ |
|
668 | - public function update_sold($datetimes) |
|
669 | - { |
|
670 | - EE_Error::doing_it_wrong( |
|
671 | - __FUNCTION__, |
|
672 | - esc_html__( |
|
673 | - 'Please use \EEM_Ticket::update_tickets_sold() instead which will in turn correctly update both the Ticket AND Datetime counts.', |
|
674 | - 'event_espresso' |
|
675 | - ), |
|
676 | - '4.9.32.rc.005' |
|
677 | - ); |
|
678 | - foreach ($datetimes as $datetime) { |
|
679 | - $datetime->update_sold(); |
|
680 | - } |
|
681 | - } |
|
682 | - |
|
683 | - |
|
684 | - /** |
|
685 | - * Gets the total number of tickets available at a particular datetime |
|
686 | - * (does NOT take into account the datetime's spaces available) |
|
687 | - * |
|
688 | - * @param int $DTT_ID |
|
689 | - * @param array $query_params |
|
690 | - * @return int of tickets available. If sold out, return less than 1. If infinite, returns EE_INF, IF there are NO |
|
691 | - * tickets attached to datetime then FALSE is returned. |
|
692 | - */ |
|
693 | - public function sum_tickets_currently_available_at_datetime($DTT_ID, array $query_params = array()) |
|
694 | - { |
|
695 | - $datetime = $this->get_one_by_ID($DTT_ID); |
|
696 | - if ($datetime instanceof EE_Datetime) { |
|
697 | - return $datetime->tickets_remaining($query_params); |
|
698 | - } |
|
699 | - return 0; |
|
700 | - } |
|
701 | - |
|
702 | - |
|
703 | - /** |
|
704 | - * This returns an array of counts of datetimes in the database for each Datetime status that can be queried. |
|
705 | - * |
|
706 | - * @param array $stati_to_include If included you can restrict the statuses we return counts for by including the |
|
707 | - * stati you want counts for as values in the array. An empty array returns counts |
|
708 | - * for all valid stati. |
|
709 | - * @param array $query_params If included can be used to refine the conditions for returning the count (i.e. |
|
710 | - * only for Datetimes connected to a specific event, or specific ticket. |
|
711 | - * @return array The value returned is an array indexed by Datetime Status and the values are the counts. The |
|
712 | - * @throws EE_Error |
|
713 | - * stati used as index keys are: EE_Datetime::active EE_Datetime::upcoming |
|
714 | - * EE_Datetime::expired |
|
715 | - */ |
|
716 | - public function get_datetime_counts_by_status(array $stati_to_include = array(), array $query_params = array()) |
|
717 | - { |
|
718 | - // only accept where conditions for this query. |
|
719 | - $_where = isset($query_params[0]) ? $query_params[0] : array(); |
|
720 | - $status_query_args = array( |
|
721 | - EE_Datetime::active => array_merge( |
|
722 | - $_where, |
|
723 | - array('DTT_EVT_start' => array('<', time()), 'DTT_EVT_end' => array('>', time())) |
|
724 | - ), |
|
725 | - EE_Datetime::upcoming => array_merge( |
|
726 | - $_where, |
|
727 | - array('DTT_EVT_start' => array('>', time())) |
|
728 | - ), |
|
729 | - EE_Datetime::expired => array_merge( |
|
730 | - $_where, |
|
731 | - array('DTT_EVT_end' => array('<', time())) |
|
732 | - ), |
|
733 | - ); |
|
734 | - if (! empty($stati_to_include)) { |
|
735 | - foreach (array_keys($status_query_args) as $status) { |
|
736 | - if (! in_array($status, $stati_to_include, true)) { |
|
737 | - unset($status_query_args[ $status ]); |
|
738 | - } |
|
739 | - } |
|
740 | - } |
|
741 | - // loop through and query counts for each stati. |
|
742 | - $status_query_results = array(); |
|
743 | - foreach ($status_query_args as $status => $status_where_conditions) { |
|
744 | - $status_query_results[ $status ] = EEM_Datetime::count( |
|
745 | - array($status_where_conditions), |
|
746 | - 'DTT_ID', |
|
747 | - true |
|
748 | - ); |
|
749 | - } |
|
750 | - return $status_query_results; |
|
751 | - } |
|
752 | - |
|
753 | - |
|
754 | - /** |
|
755 | - * Returns the specific count for a given Datetime status matching any given query_params. |
|
756 | - * |
|
757 | - * @param string $status Valid string representation for Datetime status requested. (Defaults to Active). |
|
758 | - * @param array $query_params |
|
759 | - * @return int |
|
760 | - * @throws EE_Error |
|
761 | - */ |
|
762 | - public function get_datetime_count_for_status($status = EE_Datetime::active, array $query_params = array()) |
|
763 | - { |
|
764 | - $count = $this->get_datetime_counts_by_status(array($status), $query_params); |
|
765 | - return ! empty($count[ $status ]) ? $count[ $status ] : 0; |
|
766 | - } |
|
16 | + /** |
|
17 | + * @var EEM_Datetime $_instance |
|
18 | + */ |
|
19 | + protected static $_instance; |
|
20 | + |
|
21 | + |
|
22 | + /** |
|
23 | + * private constructor to prevent direct creation |
|
24 | + * |
|
25 | + * @param string $timezone A string representing the timezone we want to set for returned Date Time Strings |
|
26 | + * (and any incoming timezone data that gets saved). |
|
27 | + * Note this just sends the timezone info to the date time model field objects. |
|
28 | + * Default is NULL |
|
29 | + * (and will be assumed using the set timezone in the 'timezone_string' wp option) |
|
30 | + * @throws EE_Error |
|
31 | + * @throws InvalidArgumentException |
|
32 | + * @throws InvalidArgumentException |
|
33 | + */ |
|
34 | + protected function __construct($timezone) |
|
35 | + { |
|
36 | + $this->singular_item = esc_html__('Datetime', 'event_espresso'); |
|
37 | + $this->plural_item = esc_html__('Datetimes', 'event_espresso'); |
|
38 | + $this->_tables = array( |
|
39 | + 'Datetime' => new EE_Primary_Table('esp_datetime', 'DTT_ID'), |
|
40 | + ); |
|
41 | + $this->_fields = array( |
|
42 | + 'Datetime' => array( |
|
43 | + 'DTT_ID' => new EE_Primary_Key_Int_Field( |
|
44 | + 'DTT_ID', |
|
45 | + esc_html__('Datetime ID', 'event_espresso') |
|
46 | + ), |
|
47 | + 'EVT_ID' => new EE_Foreign_Key_Int_Field( |
|
48 | + 'EVT_ID', |
|
49 | + esc_html__('Event ID', 'event_espresso'), |
|
50 | + false, |
|
51 | + 0, |
|
52 | + 'Event' |
|
53 | + ), |
|
54 | + 'DTT_name' => new EE_Plain_Text_Field( |
|
55 | + 'DTT_name', |
|
56 | + esc_html__('Datetime Name', 'event_espresso'), |
|
57 | + false, |
|
58 | + '' |
|
59 | + ), |
|
60 | + 'DTT_description' => new EE_Post_Content_Field( |
|
61 | + 'DTT_description', |
|
62 | + esc_html__('Description for Datetime', 'event_espresso'), |
|
63 | + false, |
|
64 | + '' |
|
65 | + ), |
|
66 | + 'DTT_EVT_start' => new EE_Datetime_Field( |
|
67 | + 'DTT_EVT_start', |
|
68 | + esc_html__('Start time/date of Event', 'event_espresso'), |
|
69 | + false, |
|
70 | + EE_Datetime_Field::now, |
|
71 | + $timezone |
|
72 | + ), |
|
73 | + 'DTT_EVT_end' => new EE_Datetime_Field( |
|
74 | + 'DTT_EVT_end', |
|
75 | + esc_html__('End time/date of Event', 'event_espresso'), |
|
76 | + false, |
|
77 | + EE_Datetime_Field::now, |
|
78 | + $timezone |
|
79 | + ), |
|
80 | + 'DTT_reg_limit' => new EE_Infinite_Integer_Field( |
|
81 | + 'DTT_reg_limit', |
|
82 | + esc_html__('Registration Limit for this time', 'event_espresso'), |
|
83 | + true, |
|
84 | + EE_INF |
|
85 | + ), |
|
86 | + 'DTT_sold' => new EE_Integer_Field( |
|
87 | + 'DTT_sold', |
|
88 | + esc_html__('How many sales for this Datetime that have occurred', 'event_espresso'), |
|
89 | + true, |
|
90 | + 0 |
|
91 | + ), |
|
92 | + 'DTT_reserved' => new EE_Integer_Field( |
|
93 | + 'DTT_reserved', |
|
94 | + esc_html__('Quantity of tickets reserved, but not yet fully purchased', 'event_espresso'), |
|
95 | + false, |
|
96 | + 0 |
|
97 | + ), |
|
98 | + 'DTT_is_primary' => new EE_Boolean_Field( |
|
99 | + 'DTT_is_primary', |
|
100 | + esc_html__('Flag indicating datetime is primary one for event', 'event_espresso'), |
|
101 | + false, |
|
102 | + false |
|
103 | + ), |
|
104 | + 'DTT_order' => new EE_Integer_Field( |
|
105 | + 'DTT_order', |
|
106 | + esc_html__('The order in which the Datetime is displayed', 'event_espresso'), |
|
107 | + false, |
|
108 | + 0 |
|
109 | + ), |
|
110 | + 'DTT_parent' => new EE_Integer_Field( |
|
111 | + 'DTT_parent', |
|
112 | + esc_html__('Indicates what DTT_ID is the parent of this DTT_ID', 'event_espresso'), |
|
113 | + true, |
|
114 | + 0 |
|
115 | + ), |
|
116 | + 'DTT_deleted' => new EE_Trashed_Flag_Field( |
|
117 | + 'DTT_deleted', |
|
118 | + esc_html__('Flag indicating datetime is archived', 'event_espresso'), |
|
119 | + false, |
|
120 | + false |
|
121 | + ), |
|
122 | + ), |
|
123 | + ); |
|
124 | + $this->_model_relations = array( |
|
125 | + 'Ticket' => new EE_HABTM_Relation('Datetime_Ticket'), |
|
126 | + 'Event' => new EE_Belongs_To_Relation(), |
|
127 | + 'Checkin' => new EE_Has_Many_Relation(), |
|
128 | + 'Datetime_Ticket' => new EE_Has_Many_Relation(), |
|
129 | + ); |
|
130 | + $path_to_event_model = 'Event'; |
|
131 | + $this->model_chain_to_password = $path_to_event_model; |
|
132 | + $this->_model_chain_to_wp_user = $path_to_event_model; |
|
133 | + // this model is generally available for reading |
|
134 | + $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Event_Related_Public( |
|
135 | + $path_to_event_model |
|
136 | + ); |
|
137 | + $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] = new EE_Restriction_Generator_Event_Related_Protected( |
|
138 | + $path_to_event_model |
|
139 | + ); |
|
140 | + $this->_cap_restriction_generators[ EEM_Base::caps_edit ] = new EE_Restriction_Generator_Event_Related_Protected( |
|
141 | + $path_to_event_model |
|
142 | + ); |
|
143 | + $this->_cap_restriction_generators[ EEM_Base::caps_delete ] = new EE_Restriction_Generator_Event_Related_Protected( |
|
144 | + $path_to_event_model, |
|
145 | + EEM_Base::caps_edit |
|
146 | + ); |
|
147 | + parent::__construct($timezone); |
|
148 | + } |
|
149 | + |
|
150 | + |
|
151 | + /** |
|
152 | + * create new blank datetime |
|
153 | + * |
|
154 | + * @access public |
|
155 | + * @return EE_Datetime[] array on success, FALSE on fail |
|
156 | + * @throws EE_Error |
|
157 | + * @throws InvalidArgumentException |
|
158 | + * @throws InvalidDataTypeException |
|
159 | + * @throws ReflectionException |
|
160 | + * @throws InvalidInterfaceException |
|
161 | + */ |
|
162 | + public function create_new_blank_datetime() |
|
163 | + { |
|
164 | + // makes sure timezone is always set. |
|
165 | + $timezone_string = $this->get_timezone(); |
|
166 | + /** |
|
167 | + * Filters the initial start date for the new datetime. |
|
168 | + * Any time included in this value will be overridden later so use additional filters to modify the time. |
|
169 | + * |
|
170 | + * @param int $start_date Unixtimestamp representing now + 30 days in seconds. |
|
171 | + * @return int unixtimestamp |
|
172 | + */ |
|
173 | + $start_date = apply_filters( |
|
174 | + 'FHEE__EEM_Datetime__create_new_blank_datetime__start_date', |
|
175 | + $this->current_time_for_query('DTT_EVT_start', true) + MONTH_IN_SECONDS |
|
176 | + ); |
|
177 | + /** |
|
178 | + * Filters the initial end date for the new datetime. |
|
179 | + * Any time included in this value will be overridden later so use additional filters to modify the time. |
|
180 | + * |
|
181 | + * @param int $end_data Unixtimestamp representing now + 30 days in seconds. |
|
182 | + * @return int unixtimestamp |
|
183 | + */ |
|
184 | + $end_date = apply_filters( |
|
185 | + 'FHEE__EEM_Datetime__create_new_blank_datetime__end_date', |
|
186 | + $this->current_time_for_query('DTT_EVT_end', true) + MONTH_IN_SECONDS |
|
187 | + ); |
|
188 | + $blank_datetime = EE_Datetime::new_instance( |
|
189 | + array( |
|
190 | + 'DTT_EVT_start' => $start_date, |
|
191 | + 'DTT_EVT_end' => $end_date, |
|
192 | + 'DTT_order' => 1, |
|
193 | + 'DTT_reg_limit' => EE_INF, |
|
194 | + ), |
|
195 | + $timezone_string |
|
196 | + ); |
|
197 | + /** |
|
198 | + * Filters the initial start time and format for the new EE_Datetime instance. |
|
199 | + * |
|
200 | + * @param array $start_time An array having size 2. First element is the time, second element is the time |
|
201 | + * format. |
|
202 | + * @return array |
|
203 | + */ |
|
204 | + $start_time = apply_filters( |
|
205 | + 'FHEE__EEM_Datetime__create_new_blank_datetime__start_time', |
|
206 | + ['8am', 'ga'] |
|
207 | + ); |
|
208 | + /** |
|
209 | + * Filters the initial end time and format for the new EE_Datetime instance. |
|
210 | + * |
|
211 | + * @param array $end_time An array having size 2. First element is the time, second element is the time |
|
212 | + * format |
|
213 | + * @return array |
|
214 | + */ |
|
215 | + $end_time = apply_filters( |
|
216 | + 'FHEE__EEM_Datetime__create_new_blank_datetime__end_time', |
|
217 | + ['5pm', 'ga'] |
|
218 | + ); |
|
219 | + $this->validateStartAndEndTimeForBlankDate($start_time, $end_time); |
|
220 | + $blank_datetime->set_start_time( |
|
221 | + $this->convert_datetime_for_query( |
|
222 | + 'DTT_EVT_start', |
|
223 | + $start_time[0], |
|
224 | + $start_time[1], |
|
225 | + $timezone_string |
|
226 | + ) |
|
227 | + ); |
|
228 | + $blank_datetime->set_end_time( |
|
229 | + $this->convert_datetime_for_query( |
|
230 | + 'DTT_EVT_end', |
|
231 | + $end_time[0], |
|
232 | + $end_time[1], |
|
233 | + $timezone_string |
|
234 | + ) |
|
235 | + ); |
|
236 | + return array($blank_datetime); |
|
237 | + } |
|
238 | + |
|
239 | + |
|
240 | + /** |
|
241 | + * Validates whether the start_time and end_time are in the expected format. |
|
242 | + * @param array $start_time |
|
243 | + * @param array $end_time |
|
244 | + * @throws InvalidArgumentException |
|
245 | + * @throws InvalidDataTypeException |
|
246 | + */ |
|
247 | + private function validateStartAndEndTimeForBlankDate($start_time, $end_time) |
|
248 | + { |
|
249 | + if (! is_array($start_time)) { |
|
250 | + throw new InvalidDataTypeException('start_time', $start_time, 'array'); |
|
251 | + } |
|
252 | + if (! is_array($end_time)) { |
|
253 | + throw new InvalidDataTypeException('end_time', $end_time, 'array'); |
|
254 | + } |
|
255 | + if (count($start_time) !== 2) { |
|
256 | + throw new InvalidArgumentException( |
|
257 | + sprintf( |
|
258 | + 'The variable %1$s is expected to be an array with two elements. The first item in the ' |
|
259 | + . 'array should be a valid time string, the second item in the array should be a valid time format', |
|
260 | + '$start_time' |
|
261 | + ) |
|
262 | + ); |
|
263 | + } |
|
264 | + if (count($end_time) !== 2) { |
|
265 | + throw new InvalidArgumentException( |
|
266 | + sprintf( |
|
267 | + 'The variable %1$s is expected to be an array with two elements. The first item in the ' |
|
268 | + . 'array should be a valid time string, the second item in the array should be a valid time format', |
|
269 | + '$end_time' |
|
270 | + ) |
|
271 | + ); |
|
272 | + } |
|
273 | + } |
|
274 | + |
|
275 | + |
|
276 | + /** |
|
277 | + * get event start date from db |
|
278 | + * |
|
279 | + * @access public |
|
280 | + * @param int $EVT_ID |
|
281 | + * @return EE_Datetime[] array on success, FALSE on fail |
|
282 | + * @throws EE_Error |
|
283 | + */ |
|
284 | + public function get_all_event_dates($EVT_ID = 0) |
|
285 | + { |
|
286 | + if (! $EVT_ID) { // on add_new_event event_id gets set to 0 |
|
287 | + return $this->create_new_blank_datetime(); |
|
288 | + } |
|
289 | + $results = $this->get_datetimes_for_event_ordered_by_DTT_order($EVT_ID); |
|
290 | + if (empty($results)) { |
|
291 | + return $this->create_new_blank_datetime(); |
|
292 | + } |
|
293 | + return $results; |
|
294 | + } |
|
295 | + |
|
296 | + |
|
297 | + /** |
|
298 | + * get all datetimes attached to an event ordered by the DTT_order field |
|
299 | + * |
|
300 | + * @public |
|
301 | + * @param int $EVT_ID event id |
|
302 | + * @param boolean $include_expired |
|
303 | + * @param boolean $include_deleted |
|
304 | + * @param int $limit If included then limit the count of results by |
|
305 | + * the given number |
|
306 | + * @return EE_Datetime[] |
|
307 | + * @throws EE_Error |
|
308 | + */ |
|
309 | + public function get_datetimes_for_event_ordered_by_DTT_order( |
|
310 | + $EVT_ID, |
|
311 | + $include_expired = true, |
|
312 | + $include_deleted = true, |
|
313 | + $limit = null |
|
314 | + ) { |
|
315 | + // sanitize EVT_ID |
|
316 | + $EVT_ID = absint($EVT_ID); |
|
317 | + $old_assumption = $this->get_assumption_concerning_values_already_prepared_by_model_object(); |
|
318 | + $this->assume_values_already_prepared_by_model_object(EEM_Base::prepared_for_use_in_db); |
|
319 | + $where_params = array('Event.EVT_ID' => $EVT_ID); |
|
320 | + $query_params = ! empty($limit) |
|
321 | + ? array( |
|
322 | + $where_params, |
|
323 | + 'limit' => $limit, |
|
324 | + 'order_by' => array('DTT_order' => 'ASC'), |
|
325 | + 'default_where_conditions' => 'none', |
|
326 | + ) |
|
327 | + : array( |
|
328 | + $where_params, |
|
329 | + 'order_by' => array('DTT_order' => 'ASC'), |
|
330 | + 'default_where_conditions' => 'none', |
|
331 | + ); |
|
332 | + if (! $include_expired) { |
|
333 | + $query_params[0]['DTT_EVT_end'] = array('>=', current_time('mysql', true)); |
|
334 | + } |
|
335 | + if ($include_deleted) { |
|
336 | + $query_params[0]['DTT_deleted'] = array('IN', array(true, false)); |
|
337 | + } |
|
338 | + /** @var EE_Datetime[] $result */ |
|
339 | + $result = $this->get_all($query_params); |
|
340 | + $this->assume_values_already_prepared_by_model_object($old_assumption); |
|
341 | + return $result; |
|
342 | + } |
|
343 | + |
|
344 | + |
|
345 | + /** |
|
346 | + * Gets the datetimes for the event (with the given limit), and orders them by "importance". |
|
347 | + * By importance, we mean that the primary datetimes are most important (DEPRECATED FOR NOW), |
|
348 | + * and then the earlier datetimes are the most important. |
|
349 | + * Maybe we'll want this to take into account datetimes that haven't already passed, but we don't yet. |
|
350 | + * |
|
351 | + * @param int $EVT_ID |
|
352 | + * @param int $limit |
|
353 | + * @return EE_Datetime[]|EE_Base_Class[] |
|
354 | + * @throws EE_Error |
|
355 | + */ |
|
356 | + public function get_datetimes_for_event_ordered_by_importance($EVT_ID = 0, $limit = null) |
|
357 | + { |
|
358 | + return $this->get_all( |
|
359 | + array( |
|
360 | + array('Event.EVT_ID' => $EVT_ID), |
|
361 | + 'limit' => $limit, |
|
362 | + 'order_by' => array('DTT_EVT_start' => 'ASC'), |
|
363 | + 'default_where_conditions' => 'none', |
|
364 | + ) |
|
365 | + ); |
|
366 | + } |
|
367 | + |
|
368 | + |
|
369 | + /** |
|
370 | + * @param int $EVT_ID |
|
371 | + * @param boolean $include_expired |
|
372 | + * @param boolean $include_deleted |
|
373 | + * @return EE_Datetime |
|
374 | + * @throws EE_Error |
|
375 | + */ |
|
376 | + public function get_oldest_datetime_for_event($EVT_ID, $include_expired = false, $include_deleted = false) |
|
377 | + { |
|
378 | + $results = $this->get_datetimes_for_event_ordered_by_start_time( |
|
379 | + $EVT_ID, |
|
380 | + $include_expired, |
|
381 | + $include_deleted, |
|
382 | + 1 |
|
383 | + ); |
|
384 | + if ($results) { |
|
385 | + return array_shift($results); |
|
386 | + } |
|
387 | + return null; |
|
388 | + } |
|
389 | + |
|
390 | + |
|
391 | + /** |
|
392 | + * Gets the 'primary' datetime for an event. |
|
393 | + * |
|
394 | + * @param int $EVT_ID |
|
395 | + * @param bool $try_to_exclude_expired |
|
396 | + * @param bool $try_to_exclude_deleted |
|
397 | + * @return \EE_Datetime |
|
398 | + * @throws EE_Error |
|
399 | + */ |
|
400 | + public function get_primary_datetime_for_event( |
|
401 | + $EVT_ID, |
|
402 | + $try_to_exclude_expired = true, |
|
403 | + $try_to_exclude_deleted = true |
|
404 | + ) { |
|
405 | + if ($try_to_exclude_expired) { |
|
406 | + $non_expired = $this->get_oldest_datetime_for_event($EVT_ID, false, false); |
|
407 | + if ($non_expired) { |
|
408 | + return $non_expired; |
|
409 | + } |
|
410 | + } |
|
411 | + if ($try_to_exclude_deleted) { |
|
412 | + $expired_even = $this->get_oldest_datetime_for_event($EVT_ID, true); |
|
413 | + if ($expired_even) { |
|
414 | + return $expired_even; |
|
415 | + } |
|
416 | + } |
|
417 | + return $this->get_oldest_datetime_for_event($EVT_ID, true, true); |
|
418 | + } |
|
419 | + |
|
420 | + |
|
421 | + /** |
|
422 | + * Gets ALL the datetimes for an event (including trashed ones, for now), ordered |
|
423 | + * only by start date |
|
424 | + * |
|
425 | + * @param int $EVT_ID |
|
426 | + * @param boolean $include_expired |
|
427 | + * @param boolean $include_deleted |
|
428 | + * @param int $limit |
|
429 | + * @return EE_Datetime[] |
|
430 | + * @throws EE_Error |
|
431 | + */ |
|
432 | + public function get_datetimes_for_event_ordered_by_start_time( |
|
433 | + $EVT_ID, |
|
434 | + $include_expired = true, |
|
435 | + $include_deleted = true, |
|
436 | + $limit = null |
|
437 | + ) { |
|
438 | + // sanitize EVT_ID |
|
439 | + $EVT_ID = absint($EVT_ID); |
|
440 | + $old_assumption = $this->get_assumption_concerning_values_already_prepared_by_model_object(); |
|
441 | + $this->assume_values_already_prepared_by_model_object(EEM_Base::prepared_for_use_in_db); |
|
442 | + $query_params = array( |
|
443 | + array( |
|
444 | + 'Event.EVT_ID' => $EVT_ID |
|
445 | + ), |
|
446 | + 'order_by' => array( |
|
447 | + 'DTT_EVT_start' => 'asc' |
|
448 | + ), |
|
449 | + 'default_where_conditions' => EEM_Base::default_where_conditions_this_only |
|
450 | + ); |
|
451 | + if (! $include_expired) { |
|
452 | + $query_params[0]['DTT_EVT_end'] = array('>=', current_time('mysql', true)); |
|
453 | + } |
|
454 | + if ($include_deleted) { |
|
455 | + $query_params[0]['DTT_deleted'] = array('IN', array(true, false)); |
|
456 | + } |
|
457 | + if ($limit) { |
|
458 | + $query_params['limit'] = $limit; |
|
459 | + } |
|
460 | + /** @var EE_Datetime[] $result */ |
|
461 | + $result = $this->get_all($query_params); |
|
462 | + $this->assume_values_already_prepared_by_model_object($old_assumption); |
|
463 | + return $result; |
|
464 | + } |
|
465 | + |
|
466 | + |
|
467 | + /** |
|
468 | + * Gets ALL the datetimes for an ticket (including trashed ones, for now), ordered |
|
469 | + * only by start date |
|
470 | + * |
|
471 | + * @param int $TKT_ID |
|
472 | + * @param boolean $include_expired |
|
473 | + * @param boolean $include_deleted |
|
474 | + * @param int $limit |
|
475 | + * @return EE_Datetime[] |
|
476 | + * @throws EE_Error |
|
477 | + */ |
|
478 | + public function get_datetimes_for_ticket_ordered_by_start_time( |
|
479 | + $TKT_ID, |
|
480 | + $include_expired = true, |
|
481 | + $include_deleted = true, |
|
482 | + $limit = null |
|
483 | + ) { |
|
484 | + // sanitize TKT_ID |
|
485 | + $TKT_ID = absint($TKT_ID); |
|
486 | + $old_assumption = $this->get_assumption_concerning_values_already_prepared_by_model_object(); |
|
487 | + $this->assume_values_already_prepared_by_model_object(EEM_Base::prepared_for_use_in_db); |
|
488 | + $query_params = array(array('Ticket.TKT_ID' => $TKT_ID), 'order_by' => array('DTT_EVT_start' => 'asc')); |
|
489 | + if (! $include_expired) { |
|
490 | + $query_params[0]['DTT_EVT_end'] = array('>=', current_time('mysql', true)); |
|
491 | + } |
|
492 | + if ($include_deleted) { |
|
493 | + $query_params[0]['DTT_deleted'] = array('IN', array(true, false)); |
|
494 | + } |
|
495 | + if ($limit) { |
|
496 | + $query_params['limit'] = $limit; |
|
497 | + } |
|
498 | + /** @var EE_Datetime[] $result */ |
|
499 | + $result = $this->get_all($query_params); |
|
500 | + $this->assume_values_already_prepared_by_model_object($old_assumption); |
|
501 | + return $result; |
|
502 | + } |
|
503 | + |
|
504 | + |
|
505 | + /** |
|
506 | + * Gets all the datetimes for a ticket (including trashed ones, for now), ordered by the DTT_order for the |
|
507 | + * datetimes. |
|
508 | + * |
|
509 | + * @param int $TKT_ID ID of ticket to retrieve the datetimes for |
|
510 | + * @param boolean $include_expired whether to include expired datetimes or not |
|
511 | + * @param boolean $include_deleted whether to include trashed datetimes or not. |
|
512 | + * @param int|null $limit if null, no limit, if int then limit results by |
|
513 | + * that number |
|
514 | + * @return EE_Datetime[] |
|
515 | + * @throws EE_Error |
|
516 | + */ |
|
517 | + public function get_datetimes_for_ticket_ordered_by_DTT_order( |
|
518 | + $TKT_ID, |
|
519 | + $include_expired = true, |
|
520 | + $include_deleted = true, |
|
521 | + $limit = null |
|
522 | + ) { |
|
523 | + // sanitize id. |
|
524 | + $TKT_ID = absint($TKT_ID); |
|
525 | + $old_assumption = $this->get_assumption_concerning_values_already_prepared_by_model_object(); |
|
526 | + $this->assume_values_already_prepared_by_model_object(EEM_Base::prepared_for_use_in_db); |
|
527 | + $where_params = array('Ticket.TKT_ID' => $TKT_ID); |
|
528 | + $query_params = array($where_params, 'order_by' => array('DTT_order' => 'ASC')); |
|
529 | + if (! $include_expired) { |
|
530 | + $query_params[0]['DTT_EVT_end'] = array('>=', current_time('mysql', true)); |
|
531 | + } |
|
532 | + if ($include_deleted) { |
|
533 | + $query_params[0]['DTT_deleted'] = array('IN', array(true, false)); |
|
534 | + } |
|
535 | + if ($limit) { |
|
536 | + $query_params['limit'] = $limit; |
|
537 | + } |
|
538 | + /** @var EE_Datetime[] $result */ |
|
539 | + $result = $this->get_all($query_params); |
|
540 | + $this->assume_values_already_prepared_by_model_object($old_assumption); |
|
541 | + return $result; |
|
542 | + } |
|
543 | + |
|
544 | + |
|
545 | + /** |
|
546 | + * Gets the most important datetime for a particular event (ie, the primary event usually. But if for some WACK |
|
547 | + * reason it doesn't exist, we consider the earliest event the most important) |
|
548 | + * |
|
549 | + * @param int $EVT_ID |
|
550 | + * @return EE_Datetime |
|
551 | + * @throws EE_Error |
|
552 | + */ |
|
553 | + public function get_most_important_datetime_for_event($EVT_ID) |
|
554 | + { |
|
555 | + $results = $this->get_datetimes_for_event_ordered_by_importance($EVT_ID, 1); |
|
556 | + if ($results) { |
|
557 | + return array_shift($results); |
|
558 | + } |
|
559 | + return null; |
|
560 | + } |
|
561 | + |
|
562 | + |
|
563 | + /** |
|
564 | + * This returns a wpdb->results Array of all DTT month and years matching the incoming query params and |
|
565 | + * grouped by month and year. |
|
566 | + * |
|
567 | + * @param array $where_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md#0-where-conditions |
|
568 | + * @param string $evt_active_status A string representing the evt active status to filter the months by. |
|
569 | + * Can be: |
|
570 | + * - '' = no filter |
|
571 | + * - upcoming = Published events with at least one upcoming datetime. |
|
572 | + * - expired = Events with all datetimes expired. |
|
573 | + * - active = Events that are published and have at least one datetime that |
|
574 | + * starts before now and ends after now. |
|
575 | + * - inactive = Events that are either not published. |
|
576 | + * @return stdClass[] |
|
577 | + * @throws EE_Error |
|
578 | + * @throws InvalidArgumentException |
|
579 | + * @throws InvalidArgumentException |
|
580 | + */ |
|
581 | + public function get_dtt_months_and_years($where_params, $evt_active_status = '') |
|
582 | + { |
|
583 | + $current_time_for_DTT_EVT_start = $this->current_time_for_query('DTT_EVT_start'); |
|
584 | + $current_time_for_DTT_EVT_end = $this->current_time_for_query('DTT_EVT_end'); |
|
585 | + switch ($evt_active_status) { |
|
586 | + case 'upcoming': |
|
587 | + $where_params['Event.status'] = 'publish'; |
|
588 | + // if there are already query_params matching DTT_EVT_start then we need to modify that to add them. |
|
589 | + if (isset($where_params['DTT_EVT_start'])) { |
|
590 | + $where_params['DTT_EVT_start*****'] = $where_params['DTT_EVT_start']; |
|
591 | + } |
|
592 | + $where_params['DTT_EVT_start'] = array('>', $current_time_for_DTT_EVT_start); |
|
593 | + break; |
|
594 | + case 'expired': |
|
595 | + if (isset($where_params['Event.status'])) { |
|
596 | + unset($where_params['Event.status']); |
|
597 | + } |
|
598 | + // get events to exclude |
|
599 | + $exclude_query[0] = array_merge( |
|
600 | + $where_params, |
|
601 | + array('DTT_EVT_end' => array('>', $current_time_for_DTT_EVT_end)) |
|
602 | + ); |
|
603 | + // first get all events that have datetimes where its not expired. |
|
604 | + $event_ids = $this->_get_all_wpdb_results( |
|
605 | + $exclude_query, |
|
606 | + OBJECT_K, |
|
607 | + 'Datetime.EVT_ID' |
|
608 | + ); |
|
609 | + $event_ids = array_keys($event_ids); |
|
610 | + if (isset($where_params['DTT_EVT_end'])) { |
|
611 | + $where_params['DTT_EVT_end****'] = $where_params['DTT_EVT_end']; |
|
612 | + } |
|
613 | + $where_params['DTT_EVT_end'] = array('<', $current_time_for_DTT_EVT_end); |
|
614 | + $where_params['Event.EVT_ID'] = array('NOT IN', $event_ids); |
|
615 | + break; |
|
616 | + case 'active': |
|
617 | + $where_params['Event.status'] = 'publish'; |
|
618 | + if (isset($where_params['DTT_EVT_start'])) { |
|
619 | + $where_params['Datetime.DTT_EVT_start******'] = $where_params['DTT_EVT_start']; |
|
620 | + } |
|
621 | + if (isset($where_params['Datetime.DTT_EVT_end'])) { |
|
622 | + $where_params['Datetime.DTT_EVT_end*****'] = $where_params['DTT_EVT_end']; |
|
623 | + } |
|
624 | + $where_params['DTT_EVT_start'] = array('<', $current_time_for_DTT_EVT_start); |
|
625 | + $where_params['DTT_EVT_end'] = array('>', $current_time_for_DTT_EVT_end); |
|
626 | + break; |
|
627 | + case 'inactive': |
|
628 | + if (isset($where_params['Event.status'])) { |
|
629 | + unset($where_params['Event.status']); |
|
630 | + } |
|
631 | + if (isset($where_params['OR'])) { |
|
632 | + $where_params['AND']['OR'] = $where_params['OR']; |
|
633 | + } |
|
634 | + if (isset($where_params['DTT_EVT_end'])) { |
|
635 | + $where_params['AND']['DTT_EVT_end****'] = $where_params['DTT_EVT_end']; |
|
636 | + unset($where_params['DTT_EVT_end']); |
|
637 | + } |
|
638 | + if (isset($where_params['DTT_EVT_start'])) { |
|
639 | + $where_params['AND']['DTT_EVT_start'] = $where_params['DTT_EVT_start']; |
|
640 | + unset($where_params['DTT_EVT_start']); |
|
641 | + } |
|
642 | + $where_params['AND']['Event.status'] = array('!=', 'publish'); |
|
643 | + break; |
|
644 | + } |
|
645 | + $query_params[0] = $where_params; |
|
646 | + $query_params['group_by'] = array('dtt_year', 'dtt_month'); |
|
647 | + $query_params['order_by'] = array('DTT_EVT_start' => 'DESC'); |
|
648 | + $query_interval = EEH_DTT_Helper::get_sql_query_interval_for_offset( |
|
649 | + $this->get_timezone(), |
|
650 | + 'DTT_EVT_start' |
|
651 | + ); |
|
652 | + $columns_to_select = array( |
|
653 | + 'dtt_year' => array('YEAR(' . $query_interval . ')', '%s'), |
|
654 | + 'dtt_month' => array('MONTHNAME(' . $query_interval . ')', '%s'), |
|
655 | + 'dtt_month_num' => array('MONTH(' . $query_interval . ')', '%s'), |
|
656 | + ); |
|
657 | + return $this->_get_all_wpdb_results($query_params, OBJECT, $columns_to_select); |
|
658 | + } |
|
659 | + |
|
660 | + |
|
661 | + /** |
|
662 | + * Updates the DTT_sold attribute on each datetime (based on the registrations |
|
663 | + * for the tickets for each datetime) |
|
664 | + * |
|
665 | + * @param EE_Base_Class[]|EE_Datetime[] $datetimes |
|
666 | + * @throws EE_Error |
|
667 | + */ |
|
668 | + public function update_sold($datetimes) |
|
669 | + { |
|
670 | + EE_Error::doing_it_wrong( |
|
671 | + __FUNCTION__, |
|
672 | + esc_html__( |
|
673 | + 'Please use \EEM_Ticket::update_tickets_sold() instead which will in turn correctly update both the Ticket AND Datetime counts.', |
|
674 | + 'event_espresso' |
|
675 | + ), |
|
676 | + '4.9.32.rc.005' |
|
677 | + ); |
|
678 | + foreach ($datetimes as $datetime) { |
|
679 | + $datetime->update_sold(); |
|
680 | + } |
|
681 | + } |
|
682 | + |
|
683 | + |
|
684 | + /** |
|
685 | + * Gets the total number of tickets available at a particular datetime |
|
686 | + * (does NOT take into account the datetime's spaces available) |
|
687 | + * |
|
688 | + * @param int $DTT_ID |
|
689 | + * @param array $query_params |
|
690 | + * @return int of tickets available. If sold out, return less than 1. If infinite, returns EE_INF, IF there are NO |
|
691 | + * tickets attached to datetime then FALSE is returned. |
|
692 | + */ |
|
693 | + public function sum_tickets_currently_available_at_datetime($DTT_ID, array $query_params = array()) |
|
694 | + { |
|
695 | + $datetime = $this->get_one_by_ID($DTT_ID); |
|
696 | + if ($datetime instanceof EE_Datetime) { |
|
697 | + return $datetime->tickets_remaining($query_params); |
|
698 | + } |
|
699 | + return 0; |
|
700 | + } |
|
701 | + |
|
702 | + |
|
703 | + /** |
|
704 | + * This returns an array of counts of datetimes in the database for each Datetime status that can be queried. |
|
705 | + * |
|
706 | + * @param array $stati_to_include If included you can restrict the statuses we return counts for by including the |
|
707 | + * stati you want counts for as values in the array. An empty array returns counts |
|
708 | + * for all valid stati. |
|
709 | + * @param array $query_params If included can be used to refine the conditions for returning the count (i.e. |
|
710 | + * only for Datetimes connected to a specific event, or specific ticket. |
|
711 | + * @return array The value returned is an array indexed by Datetime Status and the values are the counts. The |
|
712 | + * @throws EE_Error |
|
713 | + * stati used as index keys are: EE_Datetime::active EE_Datetime::upcoming |
|
714 | + * EE_Datetime::expired |
|
715 | + */ |
|
716 | + public function get_datetime_counts_by_status(array $stati_to_include = array(), array $query_params = array()) |
|
717 | + { |
|
718 | + // only accept where conditions for this query. |
|
719 | + $_where = isset($query_params[0]) ? $query_params[0] : array(); |
|
720 | + $status_query_args = array( |
|
721 | + EE_Datetime::active => array_merge( |
|
722 | + $_where, |
|
723 | + array('DTT_EVT_start' => array('<', time()), 'DTT_EVT_end' => array('>', time())) |
|
724 | + ), |
|
725 | + EE_Datetime::upcoming => array_merge( |
|
726 | + $_where, |
|
727 | + array('DTT_EVT_start' => array('>', time())) |
|
728 | + ), |
|
729 | + EE_Datetime::expired => array_merge( |
|
730 | + $_where, |
|
731 | + array('DTT_EVT_end' => array('<', time())) |
|
732 | + ), |
|
733 | + ); |
|
734 | + if (! empty($stati_to_include)) { |
|
735 | + foreach (array_keys($status_query_args) as $status) { |
|
736 | + if (! in_array($status, $stati_to_include, true)) { |
|
737 | + unset($status_query_args[ $status ]); |
|
738 | + } |
|
739 | + } |
|
740 | + } |
|
741 | + // loop through and query counts for each stati. |
|
742 | + $status_query_results = array(); |
|
743 | + foreach ($status_query_args as $status => $status_where_conditions) { |
|
744 | + $status_query_results[ $status ] = EEM_Datetime::count( |
|
745 | + array($status_where_conditions), |
|
746 | + 'DTT_ID', |
|
747 | + true |
|
748 | + ); |
|
749 | + } |
|
750 | + return $status_query_results; |
|
751 | + } |
|
752 | + |
|
753 | + |
|
754 | + /** |
|
755 | + * Returns the specific count for a given Datetime status matching any given query_params. |
|
756 | + * |
|
757 | + * @param string $status Valid string representation for Datetime status requested. (Defaults to Active). |
|
758 | + * @param array $query_params |
|
759 | + * @return int |
|
760 | + * @throws EE_Error |
|
761 | + */ |
|
762 | + public function get_datetime_count_for_status($status = EE_Datetime::active, array $query_params = array()) |
|
763 | + { |
|
764 | + $count = $this->get_datetime_counts_by_status(array($status), $query_params); |
|
765 | + return ! empty($count[ $status ]) ? $count[ $status ] : 0; |
|
766 | + } |
|
767 | 767 | } |
@@ -22,15 +22,15 @@ |
||
22 | 22 | { |
23 | 23 | |
24 | 24 | do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
25 | - if (! defined('TXN_PG_SLUG')) { |
|
25 | + if ( ! defined('TXN_PG_SLUG')) { |
|
26 | 26 | define('TXN_PG_SLUG', 'espresso_transactions'); |
27 | 27 | define('TXN_PG_NAME', ucwords(str_replace('_', '', TXN_PG_SLUG))); |
28 | - define('TXN_ADMIN', EE_ADMIN_PAGES . 'transactions/'); |
|
29 | - define('TXN_ADMIN_URL', admin_url('admin.php?page=' . TXN_PG_SLUG)); |
|
30 | - define('TXN_ASSETS_PATH', TXN_ADMIN . 'assets/'); |
|
31 | - define('TXN_ASSETS_URL', str_replace('\\', '/', EE_ADMIN_PAGES_URL . 'transactions/assets/')); |
|
32 | - define('TXN_TEMPLATE_PATH', TXN_ADMIN . 'templates/'); |
|
33 | - define('TXN_TEMPLATE_URL', str_replace('\\', '/', EE_ADMIN_PAGES_URL . 'transactions/templates/')); |
|
28 | + define('TXN_ADMIN', EE_ADMIN_PAGES.'transactions/'); |
|
29 | + define('TXN_ADMIN_URL', admin_url('admin.php?page='.TXN_PG_SLUG)); |
|
30 | + define('TXN_ASSETS_PATH', TXN_ADMIN.'assets/'); |
|
31 | + define('TXN_ASSETS_URL', str_replace('\\', '/', EE_ADMIN_PAGES_URL.'transactions/assets/')); |
|
32 | + define('TXN_TEMPLATE_PATH', TXN_ADMIN.'templates/'); |
|
33 | + define('TXN_TEMPLATE_URL', str_replace('\\', '/', EE_ADMIN_PAGES_URL.'transactions/templates/')); |
|
34 | 34 | } |
35 | 35 | parent::__construct(); |
36 | 36 | } |
@@ -13,58 +13,58 @@ |
||
13 | 13 | { |
14 | 14 | |
15 | 15 | |
16 | - /** |
|
17 | - * @Constructor |
|
18 | - * @access public |
|
19 | - * @return Transactions_Admin_Page_Init |
|
20 | - */ |
|
21 | - public function __construct() |
|
22 | - { |
|
16 | + /** |
|
17 | + * @Constructor |
|
18 | + * @access public |
|
19 | + * @return Transactions_Admin_Page_Init |
|
20 | + */ |
|
21 | + public function __construct() |
|
22 | + { |
|
23 | 23 | |
24 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
25 | - if (! defined('TXN_PG_SLUG')) { |
|
26 | - define('TXN_PG_SLUG', 'espresso_transactions'); |
|
27 | - define('TXN_PG_NAME', ucwords(str_replace('_', '', TXN_PG_SLUG))); |
|
28 | - define('TXN_ADMIN', EE_ADMIN_PAGES . 'transactions/'); |
|
29 | - define('TXN_ADMIN_URL', admin_url('admin.php?page=' . TXN_PG_SLUG)); |
|
30 | - define('TXN_ASSETS_PATH', TXN_ADMIN . 'assets/'); |
|
31 | - define('TXN_ASSETS_URL', str_replace('\\', '/', EE_ADMIN_PAGES_URL . 'transactions/assets/')); |
|
32 | - define('TXN_TEMPLATE_PATH', TXN_ADMIN . 'templates/'); |
|
33 | - define('TXN_TEMPLATE_URL', str_replace('\\', '/', EE_ADMIN_PAGES_URL . 'transactions/templates/')); |
|
34 | - } |
|
35 | - parent::__construct(); |
|
36 | - } |
|
24 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
25 | + if (! defined('TXN_PG_SLUG')) { |
|
26 | + define('TXN_PG_SLUG', 'espresso_transactions'); |
|
27 | + define('TXN_PG_NAME', ucwords(str_replace('_', '', TXN_PG_SLUG))); |
|
28 | + define('TXN_ADMIN', EE_ADMIN_PAGES . 'transactions/'); |
|
29 | + define('TXN_ADMIN_URL', admin_url('admin.php?page=' . TXN_PG_SLUG)); |
|
30 | + define('TXN_ASSETS_PATH', TXN_ADMIN . 'assets/'); |
|
31 | + define('TXN_ASSETS_URL', str_replace('\\', '/', EE_ADMIN_PAGES_URL . 'transactions/assets/')); |
|
32 | + define('TXN_TEMPLATE_PATH', TXN_ADMIN . 'templates/'); |
|
33 | + define('TXN_TEMPLATE_URL', str_replace('\\', '/', EE_ADMIN_PAGES_URL . 'transactions/templates/')); |
|
34 | + } |
|
35 | + parent::__construct(); |
|
36 | + } |
|
37 | 37 | |
38 | 38 | |
39 | - /** |
|
40 | - * _set_init_properties |
|
41 | - * |
|
42 | - * @return void |
|
43 | - */ |
|
44 | - protected function _set_init_properties() |
|
45 | - { |
|
46 | - $this->label = esc_html__('Transactions Overview', 'event_espresso'); |
|
47 | - } |
|
39 | + /** |
|
40 | + * _set_init_properties |
|
41 | + * |
|
42 | + * @return void |
|
43 | + */ |
|
44 | + protected function _set_init_properties() |
|
45 | + { |
|
46 | + $this->label = esc_html__('Transactions Overview', 'event_espresso'); |
|
47 | + } |
|
48 | 48 | |
49 | 49 | |
50 | - /** |
|
51 | - * _set_menu_map |
|
52 | - * |
|
53 | - * @return void |
|
54 | - */ |
|
55 | - protected function _set_menu_map() |
|
56 | - { |
|
57 | - $this->_menu_map = new EE_Admin_Page_Sub_Menu( |
|
58 | - array( |
|
59 | - 'menu_group' => 'main', |
|
60 | - 'menu_order' => 50, |
|
61 | - 'show_on_menu' => EE_Admin_Page_Menu_Map::BLOG_ADMIN_ONLY, |
|
62 | - 'parent_slug' => 'espresso_events', |
|
63 | - 'menu_slug' => TXN_PG_SLUG, |
|
64 | - 'menu_label' => esc_html__('Transactions', 'event_espresso'), |
|
65 | - 'capability' => 'ee_read_transactions', |
|
66 | - 'admin_init_page' => $this, |
|
67 | - ) |
|
68 | - ); |
|
69 | - } |
|
50 | + /** |
|
51 | + * _set_menu_map |
|
52 | + * |
|
53 | + * @return void |
|
54 | + */ |
|
55 | + protected function _set_menu_map() |
|
56 | + { |
|
57 | + $this->_menu_map = new EE_Admin_Page_Sub_Menu( |
|
58 | + array( |
|
59 | + 'menu_group' => 'main', |
|
60 | + 'menu_order' => 50, |
|
61 | + 'show_on_menu' => EE_Admin_Page_Menu_Map::BLOG_ADMIN_ONLY, |
|
62 | + 'parent_slug' => 'espresso_events', |
|
63 | + 'menu_slug' => TXN_PG_SLUG, |
|
64 | + 'menu_label' => esc_html__('Transactions', 'event_espresso'), |
|
65 | + 'capability' => 'ee_read_transactions', |
|
66 | + 'admin_init_page' => $this, |
|
67 | + ) |
|
68 | + ); |
|
69 | + } |
|
70 | 70 | } |
@@ -21,12 +21,12 @@ |
||
21 | 21 | { |
22 | 22 | // define some event categories related constants |
23 | 23 | define('EE_VENUES_PG_SLUG', 'espresso_venues'); |
24 | - define('EE_VENUES_ADMIN_URL', admin_url('admin.php?page=' . EE_VENUES_PG_SLUG)); |
|
25 | - define('EE_VENUES_ASSETS_URL', EE_ADMIN_PAGES_URL . 'venues/assets/'); |
|
26 | - define('EE_VENUES_TEMPLATE_PATH', EE_ADMIN_PAGES . 'venues/templates/'); |
|
24 | + define('EE_VENUES_ADMIN_URL', admin_url('admin.php?page='.EE_VENUES_PG_SLUG)); |
|
25 | + define('EE_VENUES_ASSETS_URL', EE_ADMIN_PAGES_URL.'venues/assets/'); |
|
26 | + define('EE_VENUES_TEMPLATE_PATH', EE_ADMIN_PAGES.'venues/templates/'); |
|
27 | 27 | |
28 | 28 | parent::__construct(); |
29 | - $this->_folder_path = EE_ADMIN_PAGES . $this->_folder_name . '/'; |
|
29 | + $this->_folder_path = EE_ADMIN_PAGES.$this->_folder_name.'/'; |
|
30 | 30 | } |
31 | 31 | |
32 | 32 | protected function _set_init_properties() |
@@ -17,39 +17,39 @@ |
||
17 | 17 | { |
18 | 18 | |
19 | 19 | |
20 | - public function __construct() |
|
21 | - { |
|
22 | - // define some event categories related constants |
|
23 | - define('EE_VENUES_PG_SLUG', 'espresso_venues'); |
|
24 | - define('EE_VENUES_ADMIN_URL', admin_url('admin.php?page=' . EE_VENUES_PG_SLUG)); |
|
25 | - define('EE_VENUES_ASSETS_URL', EE_ADMIN_PAGES_URL . 'venues/assets/'); |
|
26 | - define('EE_VENUES_TEMPLATE_PATH', EE_ADMIN_PAGES . 'venues/templates/'); |
|
20 | + public function __construct() |
|
21 | + { |
|
22 | + // define some event categories related constants |
|
23 | + define('EE_VENUES_PG_SLUG', 'espresso_venues'); |
|
24 | + define('EE_VENUES_ADMIN_URL', admin_url('admin.php?page=' . EE_VENUES_PG_SLUG)); |
|
25 | + define('EE_VENUES_ASSETS_URL', EE_ADMIN_PAGES_URL . 'venues/assets/'); |
|
26 | + define('EE_VENUES_TEMPLATE_PATH', EE_ADMIN_PAGES . 'venues/templates/'); |
|
27 | 27 | |
28 | - parent::__construct(); |
|
29 | - $this->_folder_path = EE_ADMIN_PAGES . $this->_folder_name . '/'; |
|
30 | - } |
|
28 | + parent::__construct(); |
|
29 | + $this->_folder_path = EE_ADMIN_PAGES . $this->_folder_name . '/'; |
|
30 | + } |
|
31 | 31 | |
32 | - protected function _set_init_properties() |
|
33 | - { |
|
34 | - $this->label = esc_html__('Event Venues', 'event_espresso'); |
|
35 | - $this->menu_label = esc_html__('Venues', 'event_espresso'); |
|
36 | - $this->menu_slug = EE_VENUES_PG_SLUG; |
|
37 | - } |
|
32 | + protected function _set_init_properties() |
|
33 | + { |
|
34 | + $this->label = esc_html__('Event Venues', 'event_espresso'); |
|
35 | + $this->menu_label = esc_html__('Venues', 'event_espresso'); |
|
36 | + $this->menu_slug = EE_VENUES_PG_SLUG; |
|
37 | + } |
|
38 | 38 | |
39 | 39 | |
40 | - protected function _set_menu_map() |
|
41 | - { |
|
42 | - $this->_menu_map = new EE_Admin_Page_Sub_Menu( |
|
43 | - array( |
|
44 | - 'menu_group' => 'management', |
|
45 | - 'menu_order' => 40, |
|
46 | - 'show_on_menu' => EE_Admin_Page_Menu_Map::BLOG_ADMIN_ONLY, |
|
47 | - 'parent_slug' => 'espresso_events', |
|
48 | - 'menu_slug' => EE_VENUES_PG_SLUG, |
|
49 | - 'menu_label' => esc_html__('Venues', 'event_espresso'), |
|
50 | - 'capability' => 'ee_read_venues', |
|
51 | - 'admin_init_page' => $this, |
|
52 | - ) |
|
53 | - ); |
|
54 | - } |
|
40 | + protected function _set_menu_map() |
|
41 | + { |
|
42 | + $this->_menu_map = new EE_Admin_Page_Sub_Menu( |
|
43 | + array( |
|
44 | + 'menu_group' => 'management', |
|
45 | + 'menu_order' => 40, |
|
46 | + 'show_on_menu' => EE_Admin_Page_Menu_Map::BLOG_ADMIN_ONLY, |
|
47 | + 'parent_slug' => 'espresso_events', |
|
48 | + 'menu_slug' => EE_VENUES_PG_SLUG, |
|
49 | + 'menu_label' => esc_html__('Venues', 'event_espresso'), |
|
50 | + 'capability' => 'ee_read_venues', |
|
51 | + 'admin_init_page' => $this, |
|
52 | + ) |
|
53 | + ); |
|
54 | + } |
|
55 | 55 | } |
@@ -24,15 +24,15 @@ |
||
24 | 24 | |
25 | 25 | do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
26 | 26 | |
27 | - if (! defined('EE_MSG_PG_SLUG')) { |
|
27 | + if ( ! defined('EE_MSG_PG_SLUG')) { |
|
28 | 28 | define('EE_MSG_PG_SLUG', 'espresso_messages'); |
29 | 29 | define('EE_MSG_PG_NAME', ucwords(str_replace('_', '', EE_MSG_PG_SLUG))); |
30 | - define('EE_MSG_ADMIN', EE_ADMIN_PAGES . 'messages/'); |
|
31 | - define('EE_MSG_ADMIN_URL', admin_url('admin.php?page=' . EE_MSG_PG_SLUG)); |
|
32 | - define('EE_MSG_ASSETS_PATH', EE_MSG_ADMIN . 'assets/'); |
|
33 | - define('EE_MSG_ASSETS_URL', EE_ADMIN_PAGES_URL . 'messages/assets/'); |
|
34 | - define('EE_MSG_TEMPLATE_PATH', EE_MSG_ADMIN . 'templates/'); |
|
35 | - define('EE_MSG_TEMPLATE_URL', EE_ADMIN_PAGES_URL . 'messages/templates/'); |
|
30 | + define('EE_MSG_ADMIN', EE_ADMIN_PAGES.'messages/'); |
|
31 | + define('EE_MSG_ADMIN_URL', admin_url('admin.php?page='.EE_MSG_PG_SLUG)); |
|
32 | + define('EE_MSG_ASSETS_PATH', EE_MSG_ADMIN.'assets/'); |
|
33 | + define('EE_MSG_ASSETS_URL', EE_ADMIN_PAGES_URL.'messages/assets/'); |
|
34 | + define('EE_MSG_TEMPLATE_PATH', EE_MSG_ADMIN.'templates/'); |
|
35 | + define('EE_MSG_TEMPLATE_URL', EE_ADMIN_PAGES_URL.'messages/templates/'); |
|
36 | 36 | } |
37 | 37 | |
38 | 38 | parent::__construct(); |
@@ -13,52 +13,52 @@ |
||
13 | 13 | */ |
14 | 14 | class Messages_Admin_Page_Init extends EE_Admin_Page_Init |
15 | 15 | { |
16 | - /** |
|
17 | - *constructor |
|
18 | - * |
|
19 | - * @Constructor |
|
20 | - * @access public |
|
21 | - * @return void |
|
22 | - */ |
|
23 | - public function __construct() |
|
24 | - { |
|
16 | + /** |
|
17 | + *constructor |
|
18 | + * |
|
19 | + * @Constructor |
|
20 | + * @access public |
|
21 | + * @return void |
|
22 | + */ |
|
23 | + public function __construct() |
|
24 | + { |
|
25 | 25 | |
26 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
26 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
27 | 27 | |
28 | - if (! defined('EE_MSG_PG_SLUG')) { |
|
29 | - define('EE_MSG_PG_SLUG', 'espresso_messages'); |
|
30 | - define('EE_MSG_PG_NAME', ucwords(str_replace('_', '', EE_MSG_PG_SLUG))); |
|
31 | - define('EE_MSG_ADMIN', EE_ADMIN_PAGES . 'messages/'); |
|
32 | - define('EE_MSG_ADMIN_URL', admin_url('admin.php?page=' . EE_MSG_PG_SLUG)); |
|
33 | - define('EE_MSG_ASSETS_PATH', EE_MSG_ADMIN . 'assets/'); |
|
34 | - define('EE_MSG_ASSETS_URL', EE_ADMIN_PAGES_URL . 'messages/assets/'); |
|
35 | - define('EE_MSG_TEMPLATE_PATH', EE_MSG_ADMIN . 'templates/'); |
|
36 | - define('EE_MSG_TEMPLATE_URL', EE_ADMIN_PAGES_URL . 'messages/templates/'); |
|
37 | - } |
|
28 | + if (! defined('EE_MSG_PG_SLUG')) { |
|
29 | + define('EE_MSG_PG_SLUG', 'espresso_messages'); |
|
30 | + define('EE_MSG_PG_NAME', ucwords(str_replace('_', '', EE_MSG_PG_SLUG))); |
|
31 | + define('EE_MSG_ADMIN', EE_ADMIN_PAGES . 'messages/'); |
|
32 | + define('EE_MSG_ADMIN_URL', admin_url('admin.php?page=' . EE_MSG_PG_SLUG)); |
|
33 | + define('EE_MSG_ASSETS_PATH', EE_MSG_ADMIN . 'assets/'); |
|
34 | + define('EE_MSG_ASSETS_URL', EE_ADMIN_PAGES_URL . 'messages/assets/'); |
|
35 | + define('EE_MSG_TEMPLATE_PATH', EE_MSG_ADMIN . 'templates/'); |
|
36 | + define('EE_MSG_TEMPLATE_URL', EE_ADMIN_PAGES_URL . 'messages/templates/'); |
|
37 | + } |
|
38 | 38 | |
39 | - parent::__construct(); |
|
40 | - } |
|
39 | + parent::__construct(); |
|
40 | + } |
|
41 | 41 | |
42 | 42 | |
43 | - protected function _set_init_properties() |
|
44 | - { |
|
45 | - $this->label = esc_html__('Messages System', 'event_espresso'); |
|
46 | - } |
|
43 | + protected function _set_init_properties() |
|
44 | + { |
|
45 | + $this->label = esc_html__('Messages System', 'event_espresso'); |
|
46 | + } |
|
47 | 47 | |
48 | 48 | |
49 | - protected function _set_menu_map() |
|
50 | - { |
|
51 | - $this->_menu_map = new EE_Admin_Page_Sub_Menu( |
|
52 | - array( |
|
53 | - 'menu_group' => 'management', |
|
54 | - 'menu_order' => 10, |
|
55 | - 'show_on_menu' => EE_Admin_Page_Menu_Map::BLOG_ADMIN_ONLY, |
|
56 | - 'parent_slug' => 'espresso_events', |
|
57 | - 'menu_slug' => EE_MSG_PG_SLUG, |
|
58 | - 'menu_label' => esc_html__('Messages', 'event_espresso'), |
|
59 | - 'capability' => 'ee_read_global_messages', |
|
60 | - 'admin_init_page' => $this, |
|
61 | - ) |
|
62 | - ); |
|
63 | - } |
|
49 | + protected function _set_menu_map() |
|
50 | + { |
|
51 | + $this->_menu_map = new EE_Admin_Page_Sub_Menu( |
|
52 | + array( |
|
53 | + 'menu_group' => 'management', |
|
54 | + 'menu_order' => 10, |
|
55 | + 'show_on_menu' => EE_Admin_Page_Menu_Map::BLOG_ADMIN_ONLY, |
|
56 | + 'parent_slug' => 'espresso_events', |
|
57 | + 'menu_slug' => EE_MSG_PG_SLUG, |
|
58 | + 'menu_label' => esc_html__('Messages', 'event_espresso'), |
|
59 | + 'capability' => 'ee_read_global_messages', |
|
60 | + 'admin_init_page' => $this, |
|
61 | + ) |
|
62 | + ); |
|
63 | + } |
|
64 | 64 | } |
@@ -23,15 +23,15 @@ |
||
23 | 23 | public function __construct() |
24 | 24 | { |
25 | 25 | do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
26 | - if (! defined('REG_PG_SLUG')) { |
|
26 | + if ( ! defined('REG_PG_SLUG')) { |
|
27 | 27 | define('REG_PG_SLUG', 'espresso_registrations'); |
28 | 28 | define('REG_PG_NAME', ucwords(str_replace('_', '', REG_PG_SLUG))); |
29 | - define('REG_ADMIN', EE_ADMIN_PAGES . 'registrations/'); |
|
30 | - define('REG_ADMIN_URL', admin_url('admin.php?page=' . REG_PG_SLUG)); |
|
31 | - define('REG_ASSETS_PATH', REG_ADMIN . 'assets/'); |
|
32 | - define('REG_ASSETS_URL', EE_ADMIN_PAGES_URL . 'registrations/assets/'); |
|
33 | - define('REG_TEMPLATE_PATH', REG_ADMIN . 'templates/'); |
|
34 | - define('REG_TEMPLATE_URL', EE_ADMIN_PAGES_URL . 'registrations/templates/'); |
|
29 | + define('REG_ADMIN', EE_ADMIN_PAGES.'registrations/'); |
|
30 | + define('REG_ADMIN_URL', admin_url('admin.php?page='.REG_PG_SLUG)); |
|
31 | + define('REG_ASSETS_PATH', REG_ADMIN.'assets/'); |
|
32 | + define('REG_ASSETS_URL', EE_ADMIN_PAGES_URL.'registrations/assets/'); |
|
33 | + define('REG_TEMPLATE_PATH', REG_ADMIN.'templates/'); |
|
34 | + define('REG_TEMPLATE_URL', EE_ADMIN_PAGES_URL.'registrations/templates/'); |
|
35 | 35 | } |
36 | 36 | |
37 | 37 | parent::__construct(); |
@@ -13,50 +13,50 @@ |
||
13 | 13 | { |
14 | 14 | |
15 | 15 | |
16 | - /** |
|
17 | - * constructor |
|
18 | - * |
|
19 | - * @Constructor |
|
20 | - * @access public |
|
21 | - * @return void |
|
22 | - */ |
|
23 | - public function __construct() |
|
24 | - { |
|
25 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
26 | - if (! defined('REG_PG_SLUG')) { |
|
27 | - define('REG_PG_SLUG', 'espresso_registrations'); |
|
28 | - define('REG_PG_NAME', ucwords(str_replace('_', '', REG_PG_SLUG))); |
|
29 | - define('REG_ADMIN', EE_ADMIN_PAGES . 'registrations/'); |
|
30 | - define('REG_ADMIN_URL', admin_url('admin.php?page=' . REG_PG_SLUG)); |
|
31 | - define('REG_ASSETS_PATH', REG_ADMIN . 'assets/'); |
|
32 | - define('REG_ASSETS_URL', EE_ADMIN_PAGES_URL . 'registrations/assets/'); |
|
33 | - define('REG_TEMPLATE_PATH', REG_ADMIN . 'templates/'); |
|
34 | - define('REG_TEMPLATE_URL', EE_ADMIN_PAGES_URL . 'registrations/templates/'); |
|
35 | - } |
|
36 | - |
|
37 | - parent::__construct(); |
|
38 | - } |
|
39 | - |
|
40 | - |
|
41 | - protected function _set_init_properties() |
|
42 | - { |
|
43 | - $this->label = esc_html__('Registrations Overview', 'event_espresso'); |
|
44 | - } |
|
45 | - |
|
46 | - |
|
47 | - protected function _set_menu_map() |
|
48 | - { |
|
49 | - $this->_menu_map = new EE_Admin_Page_Sub_Menu( |
|
50 | - array( |
|
51 | - 'menu_group' => 'main', |
|
52 | - 'menu_order' => 40, |
|
53 | - 'show_on_menu' => EE_Admin_Page_Menu_Map::BLOG_ADMIN_ONLY, |
|
54 | - 'parent_slug' => 'espresso_events', |
|
55 | - 'menu_slug' => REG_PG_SLUG, |
|
56 | - 'menu_label' => esc_html__('Registrations', 'event_espresso'), |
|
57 | - 'capability' => 'ee_read_registrations', |
|
58 | - 'admin_init_page' => $this, |
|
59 | - ) |
|
60 | - ); |
|
61 | - } |
|
16 | + /** |
|
17 | + * constructor |
|
18 | + * |
|
19 | + * @Constructor |
|
20 | + * @access public |
|
21 | + * @return void |
|
22 | + */ |
|
23 | + public function __construct() |
|
24 | + { |
|
25 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
26 | + if (! defined('REG_PG_SLUG')) { |
|
27 | + define('REG_PG_SLUG', 'espresso_registrations'); |
|
28 | + define('REG_PG_NAME', ucwords(str_replace('_', '', REG_PG_SLUG))); |
|
29 | + define('REG_ADMIN', EE_ADMIN_PAGES . 'registrations/'); |
|
30 | + define('REG_ADMIN_URL', admin_url('admin.php?page=' . REG_PG_SLUG)); |
|
31 | + define('REG_ASSETS_PATH', REG_ADMIN . 'assets/'); |
|
32 | + define('REG_ASSETS_URL', EE_ADMIN_PAGES_URL . 'registrations/assets/'); |
|
33 | + define('REG_TEMPLATE_PATH', REG_ADMIN . 'templates/'); |
|
34 | + define('REG_TEMPLATE_URL', EE_ADMIN_PAGES_URL . 'registrations/templates/'); |
|
35 | + } |
|
36 | + |
|
37 | + parent::__construct(); |
|
38 | + } |
|
39 | + |
|
40 | + |
|
41 | + protected function _set_init_properties() |
|
42 | + { |
|
43 | + $this->label = esc_html__('Registrations Overview', 'event_espresso'); |
|
44 | + } |
|
45 | + |
|
46 | + |
|
47 | + protected function _set_menu_map() |
|
48 | + { |
|
49 | + $this->_menu_map = new EE_Admin_Page_Sub_Menu( |
|
50 | + array( |
|
51 | + 'menu_group' => 'main', |
|
52 | + 'menu_order' => 40, |
|
53 | + 'show_on_menu' => EE_Admin_Page_Menu_Map::BLOG_ADMIN_ONLY, |
|
54 | + 'parent_slug' => 'espresso_events', |
|
55 | + 'menu_slug' => REG_PG_SLUG, |
|
56 | + 'menu_label' => esc_html__('Registrations', 'event_espresso'), |
|
57 | + 'capability' => 'ee_read_registrations', |
|
58 | + 'admin_init_page' => $this, |
|
59 | + ) |
|
60 | + ); |
|
61 | + } |
|
62 | 62 | } |
@@ -15,89 +15,89 @@ |
||
15 | 15 | class EE_PMT_Paypal_Express extends EE_PMT_Base |
16 | 16 | { |
17 | 17 | |
18 | - /** |
|
19 | - * EE_PMT_Paypal_Express constructor. |
|
20 | - */ |
|
21 | - public function __construct($pm_instance = null) |
|
22 | - { |
|
23 | - require_once($this->file_folder() . 'EEG_Paypal_Express.gateway.php'); |
|
24 | - $this->_gateway = new EEG_Paypal_Express(); |
|
18 | + /** |
|
19 | + * EE_PMT_Paypal_Express constructor. |
|
20 | + */ |
|
21 | + public function __construct($pm_instance = null) |
|
22 | + { |
|
23 | + require_once($this->file_folder() . 'EEG_Paypal_Express.gateway.php'); |
|
24 | + $this->_gateway = new EEG_Paypal_Express(); |
|
25 | 25 | |
26 | - $this->_pretty_name = esc_html__('PayPal Express', 'event_espresso'); |
|
27 | - $this->_template_path = $this->file_folder() . 'templates/'; |
|
28 | - $this->_default_description = esc_html__( |
|
29 | - // @codingStandardsIgnoreStart |
|
30 | - 'After clicking \'Finalize Registration\', you will be forwarded to PayPal website to Login and make your payment.', |
|
31 | - // @codingStandardsIgnoreEnd |
|
32 | - 'event_espresso' |
|
33 | - ); |
|
34 | - $this->_default_button_url = $this->file_url() . 'lib/paypal-express-checkout-logo-gold-160.png'; |
|
26 | + $this->_pretty_name = esc_html__('PayPal Express', 'event_espresso'); |
|
27 | + $this->_template_path = $this->file_folder() . 'templates/'; |
|
28 | + $this->_default_description = esc_html__( |
|
29 | + // @codingStandardsIgnoreStart |
|
30 | + 'After clicking \'Finalize Registration\', you will be forwarded to PayPal website to Login and make your payment.', |
|
31 | + // @codingStandardsIgnoreEnd |
|
32 | + 'event_espresso' |
|
33 | + ); |
|
34 | + $this->_default_button_url = $this->file_url() . 'lib/paypal-express-checkout-logo-gold-160.png'; |
|
35 | 35 | |
36 | - parent::__construct($pm_instance); |
|
37 | - } |
|
36 | + parent::__construct($pm_instance); |
|
37 | + } |
|
38 | 38 | |
39 | 39 | |
40 | - /** |
|
41 | - * Adds the help tab. |
|
42 | - * |
|
43 | - * @see EE_PMT_Base::help_tabs_config() |
|
44 | - * @return array |
|
45 | - */ |
|
46 | - public function help_tabs_config() |
|
47 | - { |
|
48 | - return array( |
|
49 | - $this->get_help_tab_name() => array( |
|
50 | - 'title' => esc_html__('PayPal Express Settings', 'event_espresso'), |
|
51 | - 'filename' => 'payment_methods_overview_paypal_express' |
|
52 | - ) |
|
53 | - ); |
|
54 | - } |
|
40 | + /** |
|
41 | + * Adds the help tab. |
|
42 | + * |
|
43 | + * @see EE_PMT_Base::help_tabs_config() |
|
44 | + * @return array |
|
45 | + */ |
|
46 | + public function help_tabs_config() |
|
47 | + { |
|
48 | + return array( |
|
49 | + $this->get_help_tab_name() => array( |
|
50 | + 'title' => esc_html__('PayPal Express Settings', 'event_espresso'), |
|
51 | + 'filename' => 'payment_methods_overview_paypal_express' |
|
52 | + ) |
|
53 | + ); |
|
54 | + } |
|
55 | 55 | |
56 | 56 | |
57 | - /** |
|
58 | - * Gets the form for all the settings related to this payment method type. |
|
59 | - * |
|
60 | - * @return EE_Payment_Method_Form |
|
61 | - */ |
|
62 | - public function generate_new_settings_form() |
|
63 | - { |
|
64 | - return new SettingsForm(array(), $this->get_help_tab_link()); |
|
65 | - } |
|
57 | + /** |
|
58 | + * Gets the form for all the settings related to this payment method type. |
|
59 | + * |
|
60 | + * @return EE_Payment_Method_Form |
|
61 | + */ |
|
62 | + public function generate_new_settings_form() |
|
63 | + { |
|
64 | + return new SettingsForm(array(), $this->get_help_tab_link()); |
|
65 | + } |
|
66 | 66 | |
67 | 67 | |
68 | - /** |
|
69 | - * Creates a billing form for this payment method type. |
|
70 | - * |
|
71 | - * @param \EE_Transaction $transaction |
|
72 | - * @return \EE_Billing_Info_Form |
|
73 | - */ |
|
74 | - public function generate_new_billing_form(EE_Transaction $transaction = null) |
|
75 | - { |
|
76 | - if ($this->_pm_instance->debug_mode()) { |
|
77 | - $form = new EE_Billing_Info_Form( |
|
78 | - $this->_pm_instance, |
|
79 | - array( |
|
80 | - 'name' => 'paypal_express_Info_Form', |
|
81 | - 'subsections' => array( |
|
82 | - 'paypal_express_debug_info' => new EE_Form_Section_Proper( |
|
83 | - array( |
|
84 | - 'layout_strategy' => new EE_Template_Layout( |
|
85 | - array( |
|
86 | - 'layout_template_file' => $this->_template_path |
|
87 | - . 'paypal_express_debug_info.template.php', |
|
88 | - 'template_args' => array( |
|
89 | - 'debug_mode' => $this->_pm_instance->debug_mode() |
|
90 | - ) |
|
91 | - ) |
|
92 | - ) |
|
93 | - ) |
|
94 | - ) |
|
95 | - ) |
|
96 | - ) |
|
97 | - ); |
|
98 | - return $form; |
|
99 | - } |
|
68 | + /** |
|
69 | + * Creates a billing form for this payment method type. |
|
70 | + * |
|
71 | + * @param \EE_Transaction $transaction |
|
72 | + * @return \EE_Billing_Info_Form |
|
73 | + */ |
|
74 | + public function generate_new_billing_form(EE_Transaction $transaction = null) |
|
75 | + { |
|
76 | + if ($this->_pm_instance->debug_mode()) { |
|
77 | + $form = new EE_Billing_Info_Form( |
|
78 | + $this->_pm_instance, |
|
79 | + array( |
|
80 | + 'name' => 'paypal_express_Info_Form', |
|
81 | + 'subsections' => array( |
|
82 | + 'paypal_express_debug_info' => new EE_Form_Section_Proper( |
|
83 | + array( |
|
84 | + 'layout_strategy' => new EE_Template_Layout( |
|
85 | + array( |
|
86 | + 'layout_template_file' => $this->_template_path |
|
87 | + . 'paypal_express_debug_info.template.php', |
|
88 | + 'template_args' => array( |
|
89 | + 'debug_mode' => $this->_pm_instance->debug_mode() |
|
90 | + ) |
|
91 | + ) |
|
92 | + ) |
|
93 | + ) |
|
94 | + ) |
|
95 | + ) |
|
96 | + ) |
|
97 | + ); |
|
98 | + return $form; |
|
99 | + } |
|
100 | 100 | |
101 | - return false; |
|
102 | - } |
|
101 | + return false; |
|
102 | + } |
|
103 | 103 | } |
@@ -20,18 +20,18 @@ |
||
20 | 20 | */ |
21 | 21 | public function __construct($pm_instance = null) |
22 | 22 | { |
23 | - require_once($this->file_folder() . 'EEG_Paypal_Express.gateway.php'); |
|
23 | + require_once($this->file_folder().'EEG_Paypal_Express.gateway.php'); |
|
24 | 24 | $this->_gateway = new EEG_Paypal_Express(); |
25 | 25 | |
26 | 26 | $this->_pretty_name = esc_html__('PayPal Express', 'event_espresso'); |
27 | - $this->_template_path = $this->file_folder() . 'templates/'; |
|
27 | + $this->_template_path = $this->file_folder().'templates/'; |
|
28 | 28 | $this->_default_description = esc_html__( |
29 | 29 | // @codingStandardsIgnoreStart |
30 | 30 | 'After clicking \'Finalize Registration\', you will be forwarded to PayPal website to Login and make your payment.', |
31 | 31 | // @codingStandardsIgnoreEnd |
32 | 32 | 'event_espresso' |
33 | 33 | ); |
34 | - $this->_default_button_url = $this->file_url() . 'lib/paypal-express-checkout-logo-gold-160.png'; |
|
34 | + $this->_default_button_url = $this->file_url().'lib/paypal-express-checkout-logo-gold-160.png'; |
|
35 | 35 | |
36 | 36 | parent::__construct($pm_instance); |
37 | 37 | } |
@@ -19,11 +19,11 @@ discard block |
||
19 | 19 | */ |
20 | 20 | public function __construct($routing = true) |
21 | 21 | { |
22 | - define('REGISTRATION_FORM_CAF_ADMIN', EE_CORE_CAF_ADMIN_EXTEND . 'registration_form/'); |
|
23 | - define('REGISTRATION_FORM_CAF_ASSETS_PATH', REGISTRATION_FORM_CAF_ADMIN . 'assets/'); |
|
24 | - define('REGISTRATION_FORM_CAF_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL . 'registration_form/assets/'); |
|
25 | - define('REGISTRATION_FORM_CAF_TEMPLATE_PATH', REGISTRATION_FORM_CAF_ADMIN . 'templates/'); |
|
26 | - define('REGISTRATION_FORM_CAF_TEMPLATE_URL', EE_CORE_CAF_ADMIN_EXTEND_URL . 'registration_form/templates/'); |
|
22 | + define('REGISTRATION_FORM_CAF_ADMIN', EE_CORE_CAF_ADMIN_EXTEND.'registration_form/'); |
|
23 | + define('REGISTRATION_FORM_CAF_ASSETS_PATH', REGISTRATION_FORM_CAF_ADMIN.'assets/'); |
|
24 | + define('REGISTRATION_FORM_CAF_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL.'registration_form/assets/'); |
|
25 | + define('REGISTRATION_FORM_CAF_TEMPLATE_PATH', REGISTRATION_FORM_CAF_ADMIN.'templates/'); |
|
26 | + define('REGISTRATION_FORM_CAF_TEMPLATE_URL', EE_CORE_CAF_ADMIN_EXTEND_URL.'registration_form/templates/'); |
|
27 | 27 | parent::__construct($routing); |
28 | 28 | } |
29 | 29 | |
@@ -362,7 +362,7 @@ discard block |
||
362 | 362 | { |
363 | 363 | wp_register_script( |
364 | 364 | 'ee-question-sortable', |
365 | - REGISTRATION_FORM_CAF_ASSETS_URL . 'ee_question_order.js', |
|
365 | + REGISTRATION_FORM_CAF_ASSETS_URL.'ee_question_order.js', |
|
366 | 366 | array('jquery-ui-sortable'), |
367 | 367 | EVENT_ESPRESSO_VERSION, |
368 | 368 | true |
@@ -448,7 +448,7 @@ discard block |
||
448 | 448 | */ |
449 | 449 | protected function _questions_overview_list_table() |
450 | 450 | { |
451 | - $this->_admin_page_title .= ' ' . $this->get_action_link_or_button( |
|
451 | + $this->_admin_page_title .= ' '.$this->get_action_link_or_button( |
|
452 | 452 | 'add_question', |
453 | 453 | 'add_question', |
454 | 454 | array(), |
@@ -469,7 +469,7 @@ discard block |
||
469 | 469 | protected function _question_groups_overview_list_table() |
470 | 470 | { |
471 | 471 | $this->_search_btn_label = esc_html__('Question Groups', 'event_espresso'); |
472 | - $this->_admin_page_title .= ' ' . $this->get_action_link_or_button( |
|
472 | + $this->_admin_page_title .= ' '.$this->get_action_link_or_button( |
|
473 | 473 | 'add_question_group', |
474 | 474 | 'add_question_group', |
475 | 475 | array(), |
@@ -531,18 +531,18 @@ discard block |
||
531 | 531 | { |
532 | 532 | $success = 0; |
533 | 533 | do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
534 | - if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) { |
|
534 | + if ( ! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) { |
|
535 | 535 | // if array has more than one element than success message should be plural |
536 | 536 | $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1; |
537 | 537 | // cycle thru bulk action checkboxes |
538 | 538 | while (list($ID, $value) = each($this->_req_data['checkbox'])) { |
539 | - if (! $this->_delete_item($ID, $model)) { |
|
539 | + if ( ! $this->_delete_item($ID, $model)) { |
|
540 | 540 | $success = 0; |
541 | 541 | } |
542 | 542 | } |
543 | - } elseif (! empty($this->_req_data['QSG_ID'])) { |
|
543 | + } elseif ( ! empty($this->_req_data['QSG_ID'])) { |
|
544 | 544 | $success = $this->_delete_item($this->_req_data['QSG_ID'], $model); |
545 | - } elseif (! empty($this->_req_data['QST_ID'])) { |
|
545 | + } elseif ( ! empty($this->_req_data['QST_ID'])) { |
|
546 | 546 | $success = $this->_delete_item($this->_req_data['QST_ID'], $model); |
547 | 547 | } else { |
548 | 548 | EE_Error::add_error( |
@@ -611,7 +611,7 @@ discard block |
||
611 | 611 | $this->_admin_page_title = ucwords(str_replace('_', ' ', $this->_req_action)); |
612 | 612 | } |
613 | 613 | // add ID to title if editing |
614 | - $this->_admin_page_title = $ID ? $this->_admin_page_title . ' # ' . $ID : $this->_admin_page_title; |
|
614 | + $this->_admin_page_title = $ID ? $this->_admin_page_title.' # '.$ID : $this->_admin_page_title; |
|
615 | 615 | if ($ID) { |
616 | 616 | /** @var EE_Question_Group $questionGroup */ |
617 | 617 | $questionGroup = $this->_question_group_model->get_one_by_ID($ID); |
@@ -631,7 +631,7 @@ discard block |
||
631 | 631 | $redirect_URL = add_query_arg(array('action' => 'question_groups'), $this->_admin_base_url); |
632 | 632 | $this->_set_publish_post_box_vars('id', $ID, false, $redirect_URL); |
633 | 633 | $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
634 | - REGISTRATION_FORM_CAF_TEMPLATE_PATH . 'question_groups_main_meta_box.template.php', |
|
634 | + REGISTRATION_FORM_CAF_TEMPLATE_PATH.'question_groups_main_meta_box.template.php', |
|
635 | 635 | $this->_template_args, |
636 | 636 | true |
637 | 637 | ); |
@@ -709,7 +709,7 @@ discard block |
||
709 | 709 | // update the existing related questions |
710 | 710 | // BUT FIRST... delete the phone question from the Question_Group_Question |
711 | 711 | // if it is being added to this question group (therefore removed from the existing group) |
712 | - if (isset($this->_req_data['questions'], $this->_req_data['questions'][ $phone_question_id ])) { |
|
712 | + if (isset($this->_req_data['questions'], $this->_req_data['questions'][$phone_question_id])) { |
|
713 | 713 | // delete where QST ID = system phone question ID and Question Group ID is NOT this group |
714 | 714 | EEM_Question_Group_Question::instance()->delete( |
715 | 715 | array( |
@@ -724,22 +724,22 @@ discard block |
||
724 | 724 | $question_group = $this->_question_group_model->get_one_by_ID($QSG_ID); |
725 | 725 | $questions = $question_group->questions(); |
726 | 726 | // make sure system phone question is added to list of questions for this group |
727 | - if (! isset($questions[ $phone_question_id ])) { |
|
728 | - $questions[ $phone_question_id ] = EEM_Question::instance()->get_one_by_ID($phone_question_id); |
|
727 | + if ( ! isset($questions[$phone_question_id])) { |
|
728 | + $questions[$phone_question_id] = EEM_Question::instance()->get_one_by_ID($phone_question_id); |
|
729 | 729 | } |
730 | 730 | |
731 | 731 | foreach ($questions as $question_ID => $question) { |
732 | 732 | // first we always check for order. |
733 | - if (! empty($this->_req_data['question_orders'][ $question_ID ])) { |
|
733 | + if ( ! empty($this->_req_data['question_orders'][$question_ID])) { |
|
734 | 734 | // update question order |
735 | 735 | $question_group->update_question_order( |
736 | 736 | $question_ID, |
737 | - $this->_req_data['question_orders'][ $question_ID ] |
|
737 | + $this->_req_data['question_orders'][$question_ID] |
|
738 | 738 | ); |
739 | 739 | } |
740 | 740 | |
741 | 741 | // then we always check if adding or removing. |
742 | - if (isset($this->_req_data['questions'], $this->_req_data['questions'][ $question_ID ])) { |
|
742 | + if (isset($this->_req_data['questions'], $this->_req_data['questions'][$question_ID])) { |
|
743 | 743 | $question_group->add_question($question_ID); |
744 | 744 | } else { |
745 | 745 | // not found, remove it (but only if not a system question for the personal group |
@@ -760,8 +760,8 @@ discard block |
||
760 | 760 | if (isset($this->_req_data['questions'])) { |
761 | 761 | foreach ($this->_req_data['questions'] as $QST_ID) { |
762 | 762 | $question_group->add_question($QST_ID); |
763 | - if (isset($this->_req_data['question_orders'][ $QST_ID ])) { |
|
764 | - $question_group->update_question_order($QST_ID, $this->_req_data['question_orders'][ $QST_ID ]); |
|
763 | + if (isset($this->_req_data['question_orders'][$QST_ID])) { |
|
764 | + $question_group->update_question_order($QST_ID, $this->_req_data['question_orders'][$QST_ID]); |
|
765 | 765 | } |
766 | 766 | } |
767 | 767 | } |
@@ -902,33 +902,33 @@ discard block |
||
902 | 902 | // echo "trash $trash"; |
903 | 903 | // var_dump($this->_req_data['checkbox']);die; |
904 | 904 | if (isset($this->_req_data['checkbox'])) { |
905 | - if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) { |
|
905 | + if ( ! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) { |
|
906 | 906 | // if array has more than one element than success message should be plural |
907 | 907 | $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1; |
908 | 908 | // cycle thru bulk action checkboxes |
909 | 909 | while (list($ID, $value) = each($this->_req_data['checkbox'])) { |
910 | - if (! $model->delete_or_restore_by_ID($trash, absint($ID))) { |
|
910 | + if ( ! $model->delete_or_restore_by_ID($trash, absint($ID))) { |
|
911 | 911 | $success = 0; |
912 | 912 | } |
913 | 913 | } |
914 | 914 | } else { |
915 | 915 | // grab single id and delete |
916 | 916 | $ID = absint($this->_req_data['checkbox']); |
917 | - if (! $model->delete_or_restore_by_ID($trash, $ID)) { |
|
917 | + if ( ! $model->delete_or_restore_by_ID($trash, $ID)) { |
|
918 | 918 | $success = 0; |
919 | 919 | } |
920 | 920 | } |
921 | 921 | } else { |
922 | 922 | // delete via trash link |
923 | 923 | // grab single id and delete |
924 | - $ID = absint($this->_req_data[ $model->primary_key_name() ]); |
|
925 | - if (! $model->delete_or_restore_by_ID($trash, $ID)) { |
|
924 | + $ID = absint($this->_req_data[$model->primary_key_name()]); |
|
925 | + if ( ! $model->delete_or_restore_by_ID($trash, $ID)) { |
|
926 | 926 | $success = 0; |
927 | 927 | } |
928 | 928 | } |
929 | 929 | |
930 | 930 | |
931 | - $action = $model instanceof EEM_Question ? 'default' : 'question_groups';// strtolower( $model->item_name(2) ); |
|
931 | + $action = $model instanceof EEM_Question ? 'default' : 'question_groups'; // strtolower( $model->item_name(2) ); |
|
932 | 932 | // echo "action :$action"; |
933 | 933 | // $action = 'questions' ? 'default' : $action; |
934 | 934 | if ($trash) { |
@@ -1048,7 +1048,7 @@ discard block |
||
1048 | 1048 | ? (int) $this->_req_data['curpage'] |
1049 | 1049 | : null; |
1050 | 1050 | |
1051 | - if (! empty($row_ids)) { |
|
1051 | + if ( ! empty($row_ids)) { |
|
1052 | 1052 | // figure out where we start the row_id count at for the current page. |
1053 | 1053 | $qsgcount = empty($curpage) ? 0 : ($curpage - 1) * $perpage; |
1054 | 1054 | |
@@ -1057,7 +1057,7 @@ discard block |
||
1057 | 1057 | // Update the questions when re-ordering |
1058 | 1058 | $updated = EEM_Question_Group::instance()->update( |
1059 | 1059 | array('QSG_order' => $qsgcount), |
1060 | - array(array('QSG_ID' => $row_ids[ $i ])) |
|
1060 | + array(array('QSG_ID' => $row_ids[$i])) |
|
1061 | 1061 | ); |
1062 | 1062 | if ($updated === false) { |
1063 | 1063 | $success = false; |
@@ -1103,7 +1103,7 @@ discard block |
||
1103 | 1103 | $this->_set_add_edit_form_tags('update_reg_form_settings'); |
1104 | 1104 | $this->_set_publish_post_box_vars(null, false, false, null, false); |
1105 | 1105 | $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
1106 | - REGISTRATION_FORM_CAF_TEMPLATE_PATH . 'reg_form_settings.template.php', |
|
1106 | + REGISTRATION_FORM_CAF_TEMPLATE_PATH.'reg_form_settings.template.php', |
|
1107 | 1107 | $this->_template_args, |
1108 | 1108 | true |
1109 | 1109 | ); |
@@ -1240,7 +1240,7 @@ discard block |
||
1240 | 1240 | $prev_email_validation_level = 'basic'; |
1241 | 1241 | } |
1242 | 1242 | // confirm our i18n email validation will work on the server |
1243 | - if (! $this->_verify_pcre_support($EE_Registration_Config, $email_validation_level)) { |
|
1243 | + if ( ! $this->_verify_pcre_support($EE_Registration_Config, $email_validation_level)) { |
|
1244 | 1244 | // or reset email validation level to previous value |
1245 | 1245 | $email_validation_level = $prev_email_validation_level; |
1246 | 1246 | } |
@@ -1286,7 +1286,7 @@ discard block |
||
1286 | 1286 | private function _verify_pcre_support(EE_Registration_Config $EE_Registration_Config, $email_validation_level) |
1287 | 1287 | { |
1288 | 1288 | // first check that PCRE is enabled |
1289 | - if (! defined('PREG_BAD_UTF8_ERROR')) { |
|
1289 | + if ( ! defined('PREG_BAD_UTF8_ERROR')) { |
|
1290 | 1290 | EE_Error::add_error( |
1291 | 1291 | sprintf( |
1292 | 1292 | esc_html__( |
@@ -14,1446 +14,1446 @@ |
||
14 | 14 | class Extend_Registration_Form_Admin_Page extends Registration_Form_Admin_Page |
15 | 15 | { |
16 | 16 | |
17 | - /** |
|
18 | - * @param bool $routing indicate whether we want to just load the object and handle routing or just load the object. |
|
19 | - */ |
|
20 | - public function __construct($routing = true) |
|
21 | - { |
|
22 | - define('REGISTRATION_FORM_CAF_ADMIN', EE_CORE_CAF_ADMIN_EXTEND . 'registration_form/'); |
|
23 | - define('REGISTRATION_FORM_CAF_ASSETS_PATH', REGISTRATION_FORM_CAF_ADMIN . 'assets/'); |
|
24 | - define('REGISTRATION_FORM_CAF_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL . 'registration_form/assets/'); |
|
25 | - define('REGISTRATION_FORM_CAF_TEMPLATE_PATH', REGISTRATION_FORM_CAF_ADMIN . 'templates/'); |
|
26 | - define('REGISTRATION_FORM_CAF_TEMPLATE_URL', EE_CORE_CAF_ADMIN_EXTEND_URL . 'registration_form/templates/'); |
|
27 | - parent::__construct($routing); |
|
28 | - } |
|
29 | - |
|
30 | - |
|
31 | - /** |
|
32 | - * @return void |
|
33 | - */ |
|
34 | - protected function _extend_page_config() |
|
35 | - { |
|
36 | - $this->_admin_base_path = REGISTRATION_FORM_CAF_ADMIN; |
|
37 | - $qst_id = ! empty($this->_req_data['QST_ID']) && ! is_array($this->_req_data['QST_ID']) |
|
38 | - ? $this->_req_data['QST_ID'] : 0; |
|
39 | - $qsg_id = ! empty($this->_req_data['QSG_ID']) && ! is_array($this->_req_data['QSG_ID']) |
|
40 | - ? $this->_req_data['QSG_ID'] : 0; |
|
41 | - |
|
42 | - $new_page_routes = array( |
|
43 | - 'question_groups' => array( |
|
44 | - 'func' => '_question_groups_overview_list_table', |
|
45 | - 'capability' => 'ee_read_question_groups', |
|
46 | - ), |
|
47 | - 'add_question' => array( |
|
48 | - 'func' => '_edit_question', |
|
49 | - 'capability' => 'ee_edit_questions', |
|
50 | - ), |
|
51 | - 'insert_question' => array( |
|
52 | - 'func' => '_insert_or_update_question', |
|
53 | - 'args' => array('new_question' => true), |
|
54 | - 'capability' => 'ee_edit_questions', |
|
55 | - 'noheader' => true, |
|
56 | - ), |
|
57 | - 'duplicate_question' => array( |
|
58 | - 'func' => '_duplicate_question', |
|
59 | - 'capability' => 'ee_edit_questions', |
|
60 | - 'noheader' => true, |
|
61 | - ), |
|
62 | - 'trash_question' => array( |
|
63 | - 'func' => '_trash_question', |
|
64 | - 'capability' => 'ee_delete_question', |
|
65 | - 'obj_id' => $qst_id, |
|
66 | - 'noheader' => true, |
|
67 | - ), |
|
68 | - |
|
69 | - 'restore_question' => array( |
|
70 | - 'func' => '_trash_or_restore_questions', |
|
71 | - 'capability' => 'ee_delete_question', |
|
72 | - 'obj_id' => $qst_id, |
|
73 | - 'args' => array('trash' => false), |
|
74 | - 'noheader' => true, |
|
75 | - ), |
|
76 | - |
|
77 | - 'delete_question' => array( |
|
78 | - 'func' => '_delete_question', |
|
79 | - 'capability' => 'ee_delete_question', |
|
80 | - 'obj_id' => $qst_id, |
|
81 | - 'noheader' => true, |
|
82 | - ), |
|
83 | - |
|
84 | - 'trash_questions' => array( |
|
85 | - 'func' => '_trash_or_restore_questions', |
|
86 | - 'capability' => 'ee_delete_questions', |
|
87 | - 'args' => array('trash' => true), |
|
88 | - 'noheader' => true, |
|
89 | - ), |
|
90 | - |
|
91 | - 'restore_questions' => array( |
|
92 | - 'func' => '_trash_or_restore_questions', |
|
93 | - 'capability' => 'ee_delete_questions', |
|
94 | - 'args' => array('trash' => false), |
|
95 | - 'noheader' => true, |
|
96 | - ), |
|
97 | - |
|
98 | - 'delete_questions' => array( |
|
99 | - 'func' => '_delete_questions', |
|
100 | - 'args' => array(), |
|
101 | - 'capability' => 'ee_delete_questions', |
|
102 | - 'noheader' => true, |
|
103 | - ), |
|
104 | - |
|
105 | - 'add_question_group' => array( |
|
106 | - 'func' => '_edit_question_group', |
|
107 | - 'capability' => 'ee_edit_question_groups', |
|
108 | - ), |
|
109 | - |
|
110 | - 'edit_question_group' => array( |
|
111 | - 'func' => '_edit_question_group', |
|
112 | - 'capability' => 'ee_edit_question_group', |
|
113 | - 'obj_id' => $qsg_id, |
|
114 | - 'args' => array('edit'), |
|
115 | - ), |
|
116 | - |
|
117 | - 'delete_question_groups' => array( |
|
118 | - 'func' => '_delete_question_groups', |
|
119 | - 'capability' => 'ee_delete_question_groups', |
|
120 | - 'noheader' => true, |
|
121 | - ), |
|
122 | - |
|
123 | - 'delete_question_group' => array( |
|
124 | - 'func' => '_delete_question_groups', |
|
125 | - 'capability' => 'ee_delete_question_group', |
|
126 | - 'obj_id' => $qsg_id, |
|
127 | - 'noheader' => true, |
|
128 | - ), |
|
129 | - |
|
130 | - 'trash_question_group' => array( |
|
131 | - 'func' => '_trash_or_restore_question_groups', |
|
132 | - 'args' => array('trash' => true), |
|
133 | - 'capability' => 'ee_delete_question_group', |
|
134 | - 'obj_id' => $qsg_id, |
|
135 | - 'noheader' => true, |
|
136 | - ), |
|
137 | - |
|
138 | - 'restore_question_group' => array( |
|
139 | - 'func' => '_trash_or_restore_question_groups', |
|
140 | - 'args' => array('trash' => false), |
|
141 | - 'capability' => 'ee_delete_question_group', |
|
142 | - 'obj_id' => $qsg_id, |
|
143 | - 'noheader' => true, |
|
144 | - ), |
|
145 | - |
|
146 | - 'insert_question_group' => array( |
|
147 | - 'func' => '_insert_or_update_question_group', |
|
148 | - 'args' => array('new_question_group' => true), |
|
149 | - 'capability' => 'ee_edit_question_groups', |
|
150 | - 'noheader' => true, |
|
151 | - ), |
|
152 | - |
|
153 | - 'update_question_group' => array( |
|
154 | - 'func' => '_insert_or_update_question_group', |
|
155 | - 'args' => array('new_question_group' => false), |
|
156 | - 'capability' => 'ee_edit_question_group', |
|
157 | - 'obj_id' => $qsg_id, |
|
158 | - 'noheader' => true, |
|
159 | - ), |
|
160 | - |
|
161 | - 'trash_question_groups' => array( |
|
162 | - 'func' => '_trash_or_restore_question_groups', |
|
163 | - 'args' => array('trash' => true), |
|
164 | - 'capability' => 'ee_delete_question_groups', |
|
165 | - 'noheader' => array('trash' => false), |
|
166 | - ), |
|
167 | - |
|
168 | - 'restore_question_groups' => array( |
|
169 | - 'func' => '_trash_or_restore_question_groups', |
|
170 | - 'args' => array('trash' => false), |
|
171 | - 'capability' => 'ee_delete_question_groups', |
|
172 | - 'noheader' => true, |
|
173 | - ), |
|
174 | - |
|
175 | - |
|
176 | - 'espresso_update_question_group_order' => array( |
|
177 | - 'func' => 'update_question_group_order', |
|
178 | - 'capability' => 'ee_edit_question_groups', |
|
179 | - 'noheader' => true, |
|
180 | - ), |
|
181 | - |
|
182 | - 'view_reg_form_settings' => array( |
|
183 | - 'func' => '_reg_form_settings', |
|
184 | - 'capability' => 'manage_options', |
|
185 | - ), |
|
186 | - |
|
187 | - 'update_reg_form_settings' => array( |
|
188 | - 'func' => '_update_reg_form_settings', |
|
189 | - 'capability' => 'manage_options', |
|
190 | - 'noheader' => true, |
|
191 | - ), |
|
192 | - ); |
|
193 | - $this->_page_routes = array_merge($this->_page_routes, $new_page_routes); |
|
194 | - |
|
195 | - $new_page_config = array( |
|
196 | - |
|
197 | - 'question_groups' => array( |
|
198 | - 'nav' => array( |
|
199 | - 'label' => esc_html__('Question Groups', 'event_espresso'), |
|
200 | - 'order' => 20, |
|
201 | - ), |
|
202 | - 'list_table' => 'Registration_Form_Question_Groups_Admin_List_Table', |
|
203 | - 'help_tabs' => array( |
|
204 | - 'registration_form_question_groups_help_tab' => array( |
|
205 | - 'title' => esc_html__('Question Groups', 'event_espresso'), |
|
206 | - 'filename' => 'registration_form_question_groups', |
|
207 | - ), |
|
208 | - 'registration_form_question_groups_table_column_headings_help_tab' => array( |
|
209 | - 'title' => esc_html__('Question Groups Table Column Headings', 'event_espresso'), |
|
210 | - 'filename' => 'registration_form_question_groups_table_column_headings', |
|
211 | - ), |
|
212 | - 'registration_form_question_groups_views_bulk_actions_search_help_tab' => array( |
|
213 | - 'title' => esc_html__('Question Groups Views & Bulk Actions & Search', 'event_espresso'), |
|
214 | - 'filename' => 'registration_form_question_groups_views_bulk_actions_search', |
|
215 | - ), |
|
216 | - ), |
|
217 | - // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836 |
|
218 | - // 'help_tour' => array('Registration_Form_Question_Groups_Help_Tour'), |
|
219 | - 'metaboxes' => $this->_default_espresso_metaboxes, |
|
220 | - 'require_nonce' => false, |
|
221 | - 'qtips' => array( |
|
222 | - 'EE_Registration_Form_Tips', |
|
223 | - ), |
|
224 | - ), |
|
225 | - |
|
226 | - 'add_question' => array( |
|
227 | - 'nav' => array( |
|
228 | - 'label' => esc_html__('Add Question', 'event_espresso'), |
|
229 | - 'order' => 5, |
|
230 | - 'persistent' => false, |
|
231 | - ), |
|
232 | - 'metaboxes' => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')), |
|
233 | - 'help_tabs' => array( |
|
234 | - 'registration_form_add_question_help_tab' => array( |
|
235 | - 'title' => esc_html__('Add Question', 'event_espresso'), |
|
236 | - 'filename' => 'registration_form_add_question', |
|
237 | - ), |
|
238 | - ), |
|
239 | - // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836 |
|
240 | - // 'help_tour' => array('Registration_Form_Add_Question_Help_Tour'), |
|
241 | - 'require_nonce' => false, |
|
242 | - ), |
|
243 | - |
|
244 | - 'add_question_group' => array( |
|
245 | - 'nav' => array( |
|
246 | - 'label' => esc_html__('Add Question Group', 'event_espresso'), |
|
247 | - 'order' => 5, |
|
248 | - 'persistent' => false, |
|
249 | - ), |
|
250 | - 'metaboxes' => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')), |
|
251 | - 'help_tabs' => array( |
|
252 | - 'registration_form_add_question_group_help_tab' => array( |
|
253 | - 'title' => esc_html__('Add Question Group', 'event_espresso'), |
|
254 | - 'filename' => 'registration_form_add_question_group', |
|
255 | - ), |
|
256 | - ), |
|
257 | - // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836 |
|
258 | - // 'help_tour' => array('Registration_Form_Add_Question_Group_Help_Tour'), |
|
259 | - 'require_nonce' => false, |
|
260 | - ), |
|
261 | - |
|
262 | - 'edit_question_group' => array( |
|
263 | - 'nav' => array( |
|
264 | - 'label' => esc_html__('Edit Question Group', 'event_espresso'), |
|
265 | - 'order' => 5, |
|
266 | - 'persistent' => false, |
|
267 | - 'url' => isset($this->_req_data['question_group_id']) ? add_query_arg( |
|
268 | - array('question_group_id' => $this->_req_data['question_group_id']), |
|
269 | - $this->_current_page_view_url |
|
270 | - ) : $this->_admin_base_url, |
|
271 | - ), |
|
272 | - 'metaboxes' => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')), |
|
273 | - 'help_tabs' => array( |
|
274 | - 'registration_form_edit_question_group_help_tab' => array( |
|
275 | - 'title' => esc_html__('Edit Question Group', 'event_espresso'), |
|
276 | - 'filename' => 'registration_form_edit_question_group', |
|
277 | - ), |
|
278 | - ), |
|
279 | - // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836 |
|
280 | - // 'help_tour' => array('Registration_Form_Edit_Question_Group_Help_Tour'), |
|
281 | - 'require_nonce' => false, |
|
282 | - ), |
|
283 | - |
|
284 | - 'view_reg_form_settings' => array( |
|
285 | - 'nav' => array( |
|
286 | - 'label' => esc_html__('Reg Form Settings', 'event_espresso'), |
|
287 | - 'order' => 40, |
|
288 | - ), |
|
289 | - 'labels' => array( |
|
290 | - 'publishbox' => esc_html__('Update Settings', 'event_espresso'), |
|
291 | - ), |
|
292 | - 'metaboxes' => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')), |
|
293 | - 'help_tabs' => array( |
|
294 | - 'registration_form_reg_form_settings_help_tab' => array( |
|
295 | - 'title' => esc_html__('Registration Form Settings', 'event_espresso'), |
|
296 | - 'filename' => 'registration_form_reg_form_settings', |
|
297 | - ), |
|
298 | - ), |
|
299 | - // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836 |
|
300 | - // 'help_tour' => array('Registration_Form_Settings_Help_Tour'), |
|
301 | - 'require_nonce' => false, |
|
302 | - ), |
|
303 | - |
|
304 | - ); |
|
305 | - $this->_page_config = array_merge($this->_page_config, $new_page_config); |
|
306 | - |
|
307 | - // change the list table we're going to use so it's the NEW list table! |
|
308 | - $this->_page_config['default']['list_table'] = 'Extend_Registration_Form_Questions_Admin_List_Table'; |
|
309 | - |
|
310 | - |
|
311 | - // additional labels |
|
312 | - $new_labels = array( |
|
313 | - 'add_question' => esc_html__('Add New Question', 'event_espresso'), |
|
314 | - 'delete_question' => esc_html__('Delete Question', 'event_espresso'), |
|
315 | - 'add_question_group' => esc_html__('Add New Question Group', 'event_espresso'), |
|
316 | - 'edit_question_group' => esc_html__('Edit Question Group', 'event_espresso'), |
|
317 | - 'delete_question_group' => esc_html__('Delete Question Group', 'event_espresso'), |
|
318 | - ); |
|
319 | - $this->_labels['buttons'] = array_merge($this->_labels['buttons'], $new_labels); |
|
320 | - } |
|
321 | - |
|
322 | - |
|
323 | - /** |
|
324 | - * @return void |
|
325 | - */ |
|
326 | - protected function _ajax_hooks() |
|
327 | - { |
|
328 | - add_action('wp_ajax_espresso_update_question_group_order', array($this, 'update_question_group_order')); |
|
329 | - } |
|
330 | - |
|
331 | - |
|
332 | - /** |
|
333 | - * @return void |
|
334 | - */ |
|
335 | - public function load_scripts_styles_question_groups() |
|
336 | - { |
|
337 | - wp_enqueue_script('espresso_ajax_table_sorting'); |
|
338 | - } |
|
339 | - |
|
340 | - |
|
341 | - /** |
|
342 | - * @return void |
|
343 | - */ |
|
344 | - public function load_scripts_styles_add_question_group() |
|
345 | - { |
|
346 | - $this->load_scripts_styles_forms(); |
|
347 | - $this->load_sortable_question_script(); |
|
348 | - } |
|
349 | - |
|
350 | - |
|
351 | - /** |
|
352 | - * @return void |
|
353 | - */ |
|
354 | - public function load_scripts_styles_edit_question_group() |
|
355 | - { |
|
356 | - $this->load_scripts_styles_forms(); |
|
357 | - $this->load_sortable_question_script(); |
|
358 | - } |
|
359 | - |
|
360 | - |
|
361 | - /** |
|
362 | - * registers and enqueues script for questions |
|
363 | - * |
|
364 | - * @return void |
|
365 | - */ |
|
366 | - public function load_sortable_question_script() |
|
367 | - { |
|
368 | - wp_register_script( |
|
369 | - 'ee-question-sortable', |
|
370 | - REGISTRATION_FORM_CAF_ASSETS_URL . 'ee_question_order.js', |
|
371 | - array('jquery-ui-sortable'), |
|
372 | - EVENT_ESPRESSO_VERSION, |
|
373 | - true |
|
374 | - ); |
|
375 | - wp_enqueue_script('ee-question-sortable'); |
|
376 | - } |
|
377 | - |
|
378 | - |
|
379 | - /** |
|
380 | - * @return void |
|
381 | - */ |
|
382 | - protected function _set_list_table_views_default() |
|
383 | - { |
|
384 | - $this->_views = array( |
|
385 | - 'all' => array( |
|
386 | - 'slug' => 'all', |
|
387 | - 'label' => esc_html__('View All Questions', 'event_espresso'), |
|
388 | - 'count' => 0, |
|
389 | - 'bulk_action' => array( |
|
390 | - 'trash_questions' => esc_html__('Trash', 'event_espresso'), |
|
391 | - ), |
|
392 | - ), |
|
393 | - ); |
|
394 | - |
|
395 | - if ( |
|
396 | - EE_Registry::instance()->CAP->current_user_can( |
|
397 | - 'ee_delete_questions', |
|
398 | - 'espresso_registration_form_trash_questions' |
|
399 | - ) |
|
400 | - ) { |
|
401 | - $this->_views['trash'] = array( |
|
402 | - 'slug' => 'trash', |
|
403 | - 'label' => esc_html__('Trash', 'event_espresso'), |
|
404 | - 'count' => 0, |
|
405 | - 'bulk_action' => array( |
|
406 | - 'delete_questions' => esc_html__('Delete Permanently', 'event_espresso'), |
|
407 | - 'restore_questions' => esc_html__('Restore', 'event_espresso'), |
|
408 | - ), |
|
409 | - ); |
|
410 | - } |
|
411 | - } |
|
412 | - |
|
413 | - |
|
414 | - /** |
|
415 | - * @return void |
|
416 | - */ |
|
417 | - protected function _set_list_table_views_question_groups() |
|
418 | - { |
|
419 | - $this->_views = array( |
|
420 | - 'all' => array( |
|
421 | - 'slug' => 'all', |
|
422 | - 'label' => esc_html__('All', 'event_espresso'), |
|
423 | - 'count' => 0, |
|
424 | - 'bulk_action' => array( |
|
425 | - 'trash_question_groups' => esc_html__('Trash', 'event_espresso'), |
|
426 | - ), |
|
427 | - ), |
|
428 | - ); |
|
429 | - |
|
430 | - if ( |
|
431 | - EE_Registry::instance()->CAP->current_user_can( |
|
432 | - 'ee_delete_question_groups', |
|
433 | - 'espresso_registration_form_trash_question_groups' |
|
434 | - ) |
|
435 | - ) { |
|
436 | - $this->_views['trash'] = array( |
|
437 | - 'slug' => 'trash', |
|
438 | - 'label' => esc_html__('Trash', 'event_espresso'), |
|
439 | - 'count' => 0, |
|
440 | - 'bulk_action' => array( |
|
441 | - 'delete_question_groups' => esc_html__('Delete Permanently', 'event_espresso'), |
|
442 | - 'restore_question_groups' => esc_html__('Restore', 'event_espresso'), |
|
443 | - ), |
|
444 | - ); |
|
445 | - } |
|
446 | - } |
|
447 | - |
|
448 | - |
|
449 | - /** |
|
450 | - * @return void |
|
451 | - * @throws EE_Error |
|
452 | - * @throws InvalidArgumentException |
|
453 | - * @throws InvalidDataTypeException |
|
454 | - * @throws InvalidInterfaceException |
|
455 | - */ |
|
456 | - protected function _questions_overview_list_table() |
|
457 | - { |
|
458 | - $this->_admin_page_title .= ' ' . $this->get_action_link_or_button( |
|
459 | - 'add_question', |
|
460 | - 'add_question', |
|
461 | - array(), |
|
462 | - 'add-new-h2' |
|
463 | - ); |
|
464 | - parent::_questions_overview_list_table(); |
|
465 | - } |
|
466 | - |
|
467 | - |
|
468 | - /** |
|
469 | - * @return void |
|
470 | - * @throws DomainException |
|
471 | - * @throws EE_Error |
|
472 | - * @throws InvalidArgumentException |
|
473 | - * @throws InvalidDataTypeException |
|
474 | - * @throws InvalidInterfaceException |
|
475 | - */ |
|
476 | - protected function _question_groups_overview_list_table() |
|
477 | - { |
|
478 | - $this->_search_btn_label = esc_html__('Question Groups', 'event_espresso'); |
|
479 | - $this->_admin_page_title .= ' ' . $this->get_action_link_or_button( |
|
480 | - 'add_question_group', |
|
481 | - 'add_question_group', |
|
482 | - array(), |
|
483 | - 'add-new-h2' |
|
484 | - ); |
|
485 | - $this->display_admin_list_table_page_with_sidebar(); |
|
486 | - } |
|
487 | - |
|
488 | - |
|
489 | - /** |
|
490 | - * @return void |
|
491 | - * @throws EE_Error |
|
492 | - * @throws InvalidArgumentException |
|
493 | - * @throws InvalidDataTypeException |
|
494 | - * @throws InvalidInterfaceException |
|
495 | - */ |
|
496 | - protected function _delete_question() |
|
497 | - { |
|
498 | - $success = $this->_delete_items($this->_question_model); |
|
499 | - $this->_redirect_after_action( |
|
500 | - $success, |
|
501 | - $this->_question_model->item_name($success), |
|
502 | - 'deleted', |
|
503 | - array('action' => 'default', 'status' => 'all') |
|
504 | - ); |
|
505 | - } |
|
506 | - |
|
507 | - |
|
508 | - /** |
|
509 | - * @return void |
|
510 | - * @throws EE_Error |
|
511 | - * @throws InvalidArgumentException |
|
512 | - * @throws InvalidDataTypeException |
|
513 | - * @throws InvalidInterfaceException |
|
514 | - */ |
|
515 | - protected function _delete_questions() |
|
516 | - { |
|
517 | - $success = $this->_delete_items($this->_question_model); |
|
518 | - $this->_redirect_after_action( |
|
519 | - $success, |
|
520 | - $this->_question_model->item_name($success), |
|
521 | - 'deleted permanently', |
|
522 | - array('action' => 'default', 'status' => 'trash') |
|
523 | - ); |
|
524 | - } |
|
525 | - |
|
526 | - |
|
527 | - /** |
|
528 | - * Performs the deletion of a single or multiple questions or question groups. |
|
529 | - * |
|
530 | - * @param EEM_Soft_Delete_Base $model |
|
531 | - * @return int number of items deleted permanently |
|
532 | - * @throws EE_Error |
|
533 | - * @throws InvalidArgumentException |
|
534 | - * @throws InvalidDataTypeException |
|
535 | - * @throws InvalidInterfaceException |
|
536 | - */ |
|
537 | - private function _delete_items(EEM_Soft_Delete_Base $model) |
|
538 | - { |
|
539 | - $success = 0; |
|
540 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
541 | - if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) { |
|
542 | - // if array has more than one element than success message should be plural |
|
543 | - $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1; |
|
544 | - // cycle thru bulk action checkboxes |
|
545 | - while (list($ID, $value) = each($this->_req_data['checkbox'])) { |
|
546 | - if (! $this->_delete_item($ID, $model)) { |
|
547 | - $success = 0; |
|
548 | - } |
|
549 | - } |
|
550 | - } elseif (! empty($this->_req_data['QSG_ID'])) { |
|
551 | - $success = $this->_delete_item($this->_req_data['QSG_ID'], $model); |
|
552 | - } elseif (! empty($this->_req_data['QST_ID'])) { |
|
553 | - $success = $this->_delete_item($this->_req_data['QST_ID'], $model); |
|
554 | - } else { |
|
555 | - EE_Error::add_error( |
|
556 | - sprintf( |
|
557 | - esc_html__( |
|
558 | - "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.", |
|
559 | - "event_espresso" |
|
560 | - ) |
|
561 | - ), |
|
562 | - __FILE__, |
|
563 | - __FUNCTION__, |
|
564 | - __LINE__ |
|
565 | - ); |
|
566 | - } |
|
567 | - return $success; |
|
568 | - } |
|
569 | - |
|
570 | - |
|
571 | - /** |
|
572 | - * Deletes the specified question (and its associated question options) or question group |
|
573 | - * |
|
574 | - * @param int $id |
|
575 | - * @param EEM_Soft_Delete_Base $model |
|
576 | - * @return boolean |
|
577 | - * @throws EE_Error |
|
578 | - * @throws InvalidArgumentException |
|
579 | - * @throws InvalidDataTypeException |
|
580 | - * @throws InvalidInterfaceException |
|
581 | - */ |
|
582 | - protected function _delete_item($id, $model) |
|
583 | - { |
|
584 | - if ($model instanceof EEM_Question) { |
|
585 | - EEM_Question_Option::instance()->delete_permanently(array(array('QST_ID' => absint($id)))); |
|
586 | - } |
|
587 | - return $model->delete_permanently_by_ID(absint($id)); |
|
588 | - } |
|
589 | - |
|
590 | - |
|
591 | - /****************************** QUESTION GROUPS ******************************/ |
|
592 | - |
|
593 | - |
|
594 | - /** |
|
595 | - * @param string $type |
|
596 | - * @return void |
|
597 | - * @throws DomainException |
|
598 | - * @throws EE_Error |
|
599 | - * @throws InvalidArgumentException |
|
600 | - * @throws InvalidDataTypeException |
|
601 | - * @throws InvalidInterfaceException |
|
602 | - */ |
|
603 | - protected function _edit_question_group($type = 'add') |
|
604 | - { |
|
605 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
606 | - $ID = isset($this->_req_data['QSG_ID']) && ! empty($this->_req_data['QSG_ID']) |
|
607 | - ? absint($this->_req_data['QSG_ID']) |
|
608 | - : false; |
|
609 | - |
|
610 | - switch ($this->_req_action) { |
|
611 | - case 'add_question_group': |
|
612 | - $this->_admin_page_title = esc_html__('Add Question Group', 'event_espresso'); |
|
613 | - break; |
|
614 | - case 'edit_question_group': |
|
615 | - $this->_admin_page_title = esc_html__('Edit Question Group', 'event_espresso'); |
|
616 | - break; |
|
617 | - default: |
|
618 | - $this->_admin_page_title = ucwords(str_replace('_', ' ', $this->_req_action)); |
|
619 | - } |
|
620 | - // add ID to title if editing |
|
621 | - $this->_admin_page_title = $ID ? $this->_admin_page_title . ' # ' . $ID : $this->_admin_page_title; |
|
622 | - if ($ID) { |
|
623 | - /** @var EE_Question_Group $questionGroup */ |
|
624 | - $questionGroup = $this->_question_group_model->get_one_by_ID($ID); |
|
625 | - $additional_hidden_fields = array('QSG_ID' => array('type' => 'hidden', 'value' => $ID)); |
|
626 | - $this->_set_add_edit_form_tags('update_question_group', $additional_hidden_fields); |
|
627 | - } else { |
|
628 | - /** @var EE_Question_Group $questionGroup */ |
|
629 | - $questionGroup = EEM_Question_Group::instance()->create_default_object(); |
|
630 | - $questionGroup->set_order_to_latest(); |
|
631 | - $this->_set_add_edit_form_tags('insert_question_group'); |
|
632 | - } |
|
633 | - $this->_template_args['values'] = $this->_yes_no_values; |
|
634 | - $this->_template_args['all_questions'] = $questionGroup->questions_in_and_not_in_group(); |
|
635 | - $this->_template_args['QSG_ID'] = $ID ? $ID : true; |
|
636 | - $this->_template_args['question_group'] = $questionGroup; |
|
637 | - |
|
638 | - $redirect_URL = add_query_arg(array('action' => 'question_groups'), $this->_admin_base_url); |
|
639 | - $this->_set_publish_post_box_vars('id', $ID, false, $redirect_URL); |
|
640 | - $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
641 | - REGISTRATION_FORM_CAF_TEMPLATE_PATH . 'question_groups_main_meta_box.template.php', |
|
642 | - $this->_template_args, |
|
643 | - true |
|
644 | - ); |
|
645 | - |
|
646 | - // the details template wrapper |
|
647 | - $this->display_admin_page_with_sidebar(); |
|
648 | - } |
|
649 | - |
|
650 | - |
|
651 | - /** |
|
652 | - * @return void |
|
653 | - * @throws EE_Error |
|
654 | - * @throws InvalidArgumentException |
|
655 | - * @throws InvalidDataTypeException |
|
656 | - * @throws InvalidInterfaceException |
|
657 | - */ |
|
658 | - protected function _delete_question_groups() |
|
659 | - { |
|
660 | - $success = $this->_delete_items($this->_question_group_model); |
|
661 | - $this->_redirect_after_action( |
|
662 | - $success, |
|
663 | - $this->_question_group_model->item_name($success), |
|
664 | - 'deleted permanently', |
|
665 | - array('action' => 'question_groups', 'status' => 'trash') |
|
666 | - ); |
|
667 | - } |
|
668 | - |
|
669 | - |
|
670 | - /** |
|
671 | - * @param bool $new_question_group |
|
672 | - * @throws EE_Error |
|
673 | - * @throws InvalidArgumentException |
|
674 | - * @throws InvalidDataTypeException |
|
675 | - * @throws InvalidInterfaceException |
|
676 | - */ |
|
677 | - protected function _insert_or_update_question_group($new_question_group = true) |
|
678 | - { |
|
679 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
680 | - $set_column_values = $this->_set_column_values_for($this->_question_group_model); |
|
681 | - if ($new_question_group) { |
|
682 | - // make sure identifier is unique |
|
683 | - $identifier_value = isset($set_column_values['QSG_identifier']) ? $set_column_values['QSG_identifier'] : ''; |
|
684 | - $identifier_exists = ! empty($identifier_value) |
|
685 | - ? $this->_question_group_model->count([['QSG_identifier' => $set_column_values['QSG_identifier']]]) > 0 |
|
686 | - : false; |
|
687 | - if ($identifier_exists) { |
|
688 | - $set_column_values['QSG_identifier'] .= uniqid('id', true); |
|
689 | - } |
|
690 | - $QSG_ID = $this->_question_group_model->insert($set_column_values); |
|
691 | - $success = $QSG_ID ? 1 : 0; |
|
692 | - if ($success === 0) { |
|
693 | - EE_Error::add_error( |
|
694 | - esc_html__('Something went wrong saving the question group.', 'event_espresso'), |
|
695 | - __FILE__, |
|
696 | - __FUNCTION__, |
|
697 | - __LINE__ |
|
698 | - ); |
|
699 | - $this->_redirect_after_action( |
|
700 | - false, |
|
701 | - '', |
|
702 | - '', |
|
703 | - array('action' => 'edit_question_group', 'QSG_ID' => $QSG_ID), |
|
704 | - true |
|
705 | - ); |
|
706 | - } |
|
707 | - } else { |
|
708 | - $QSG_ID = absint($this->_req_data['QSG_ID']); |
|
709 | - unset($set_column_values['QSG_ID']); |
|
710 | - $success = $this->_question_group_model->update($set_column_values, array(array('QSG_ID' => $QSG_ID))); |
|
711 | - } |
|
712 | - |
|
713 | - $phone_question_id = EEM_Question::instance()->get_Question_ID_from_system_string( |
|
714 | - EEM_Attendee::system_question_phone |
|
715 | - ); |
|
716 | - // update the existing related questions |
|
717 | - // BUT FIRST... delete the phone question from the Question_Group_Question |
|
718 | - // if it is being added to this question group (therefore removed from the existing group) |
|
719 | - if (isset($this->_req_data['questions'], $this->_req_data['questions'][ $phone_question_id ])) { |
|
720 | - // delete where QST ID = system phone question ID and Question Group ID is NOT this group |
|
721 | - EEM_Question_Group_Question::instance()->delete( |
|
722 | - array( |
|
723 | - array( |
|
724 | - 'QST_ID' => $phone_question_id, |
|
725 | - 'QSG_ID' => array('!=', $QSG_ID), |
|
726 | - ), |
|
727 | - ) |
|
728 | - ); |
|
729 | - } |
|
730 | - /** @type EE_Question_Group $question_group */ |
|
731 | - $question_group = $this->_question_group_model->get_one_by_ID($QSG_ID); |
|
732 | - $questions = $question_group->questions(); |
|
733 | - // make sure system phone question is added to list of questions for this group |
|
734 | - if (! isset($questions[ $phone_question_id ])) { |
|
735 | - $questions[ $phone_question_id ] = EEM_Question::instance()->get_one_by_ID($phone_question_id); |
|
736 | - } |
|
737 | - |
|
738 | - foreach ($questions as $question_ID => $question) { |
|
739 | - // first we always check for order. |
|
740 | - if (! empty($this->_req_data['question_orders'][ $question_ID ])) { |
|
741 | - // update question order |
|
742 | - $question_group->update_question_order( |
|
743 | - $question_ID, |
|
744 | - $this->_req_data['question_orders'][ $question_ID ] |
|
745 | - ); |
|
746 | - } |
|
747 | - |
|
748 | - // then we always check if adding or removing. |
|
749 | - if (isset($this->_req_data['questions'], $this->_req_data['questions'][ $question_ID ])) { |
|
750 | - $question_group->add_question($question_ID); |
|
751 | - } else { |
|
752 | - // not found, remove it (but only if not a system question for the personal group |
|
753 | - // with the exception of lname system question - we allow removal of it) |
|
754 | - if ( |
|
755 | - in_array( |
|
756 | - $question->system_ID(), |
|
757 | - EEM_Question::instance()->required_system_questions_in_system_question_group( |
|
758 | - $question_group->system_group() |
|
759 | - ) |
|
760 | - ) |
|
761 | - ) { |
|
762 | - continue; |
|
763 | - } else { |
|
764 | - $question_group->remove_question($question_ID); |
|
765 | - } |
|
766 | - } |
|
767 | - } |
|
768 | - // save new related questions |
|
769 | - if (isset($this->_req_data['questions'])) { |
|
770 | - foreach ($this->_req_data['questions'] as $QST_ID) { |
|
771 | - $question_group->add_question($QST_ID); |
|
772 | - if (isset($this->_req_data['question_orders'][ $QST_ID ])) { |
|
773 | - $question_group->update_question_order($QST_ID, $this->_req_data['question_orders'][ $QST_ID ]); |
|
774 | - } |
|
775 | - } |
|
776 | - } |
|
777 | - |
|
778 | - if ($success !== false) { |
|
779 | - $msg = $new_question_group |
|
780 | - ? sprintf( |
|
781 | - esc_html__('The %s has been created', 'event_espresso'), |
|
782 | - $this->_question_group_model->item_name() |
|
783 | - ) |
|
784 | - : sprintf( |
|
785 | - esc_html__( |
|
786 | - 'The %s has been updated', |
|
787 | - 'event_espresso' |
|
788 | - ), |
|
789 | - $this->_question_group_model->item_name() |
|
790 | - ); |
|
791 | - EE_Error::add_success($msg); |
|
792 | - } |
|
793 | - $this->_redirect_after_action( |
|
794 | - false, |
|
795 | - '', |
|
796 | - '', |
|
797 | - array('action' => 'edit_question_group', 'QSG_ID' => $QSG_ID), |
|
798 | - true |
|
799 | - ); |
|
800 | - } |
|
801 | - |
|
802 | - |
|
803 | - /** |
|
804 | - * duplicates a question and all its question options and redirects to the new question. |
|
805 | - * |
|
806 | - * @return void |
|
807 | - * @throws EE_Error |
|
808 | - * @throws InvalidArgumentException |
|
809 | - * @throws ReflectionException |
|
810 | - * @throws InvalidDataTypeException |
|
811 | - * @throws InvalidInterfaceException |
|
812 | - */ |
|
813 | - public function _duplicate_question() |
|
814 | - { |
|
815 | - $question_ID = (int) $this->_req_data['QST_ID']; |
|
816 | - $question = EEM_Question::instance()->get_one_by_ID($question_ID); |
|
817 | - if ($question instanceof EE_Question) { |
|
818 | - $new_question = $question->duplicate(); |
|
819 | - if ($new_question instanceof EE_Question) { |
|
820 | - $this->_redirect_after_action( |
|
821 | - true, |
|
822 | - esc_html__('Question', 'event_espresso'), |
|
823 | - esc_html__('Duplicated', 'event_espresso'), |
|
824 | - array('action' => 'edit_question', 'QST_ID' => $new_question->ID()), |
|
825 | - true |
|
826 | - ); |
|
827 | - } else { |
|
828 | - global $wpdb; |
|
829 | - EE_Error::add_error( |
|
830 | - sprintf( |
|
831 | - esc_html__( |
|
832 | - 'Could not duplicate question with ID %1$d because: %2$s', |
|
833 | - 'event_espresso' |
|
834 | - ), |
|
835 | - $question_ID, |
|
836 | - $wpdb->last_error |
|
837 | - ), |
|
838 | - __FILE__, |
|
839 | - __FUNCTION__, |
|
840 | - __LINE__ |
|
841 | - ); |
|
842 | - $this->_redirect_after_action(false, '', '', array('action' => 'default'), false); |
|
843 | - } |
|
844 | - } else { |
|
845 | - EE_Error::add_error( |
|
846 | - sprintf( |
|
847 | - esc_html__( |
|
848 | - 'Could not duplicate question with ID %d because it didn\'t exist!', |
|
849 | - 'event_espresso' |
|
850 | - ), |
|
851 | - $question_ID |
|
852 | - ), |
|
853 | - __FILE__, |
|
854 | - __FUNCTION__, |
|
855 | - __LINE__ |
|
856 | - ); |
|
857 | - $this->_redirect_after_action(false, '', '', array('action' => 'default'), false); |
|
858 | - } |
|
859 | - } |
|
860 | - |
|
861 | - |
|
862 | - /** |
|
863 | - * @param bool $trash |
|
864 | - * @throws EE_Error |
|
865 | - */ |
|
866 | - protected function _trash_or_restore_question_groups($trash = true) |
|
867 | - { |
|
868 | - $this->_trash_or_restore_items($this->_question_group_model, $trash); |
|
869 | - } |
|
870 | - |
|
871 | - |
|
872 | - /** |
|
873 | - *_trash_question |
|
874 | - * |
|
875 | - * @return void |
|
876 | - * @throws EE_Error |
|
877 | - */ |
|
878 | - protected function _trash_question() |
|
879 | - { |
|
880 | - $success = $this->_question_model->delete_by_ID((int) $this->_req_data['QST_ID']); |
|
881 | - $query_args = array('action' => 'default', 'status' => 'all'); |
|
882 | - $this->_redirect_after_action($success, $this->_question_model->item_name($success), 'trashed', $query_args); |
|
883 | - } |
|
884 | - |
|
885 | - |
|
886 | - /** |
|
887 | - * @param bool $trash |
|
888 | - * @throws EE_Error |
|
889 | - */ |
|
890 | - protected function _trash_or_restore_questions($trash = true) |
|
891 | - { |
|
892 | - $this->_trash_or_restore_items($this->_question_model, $trash); |
|
893 | - } |
|
894 | - |
|
895 | - |
|
896 | - /** |
|
897 | - * Internally used to delete or restore items, using the request data. Meant to be |
|
898 | - * flexible between question or question groups |
|
899 | - * |
|
900 | - * @param EEM_Soft_Delete_Base $model |
|
901 | - * @param boolean $trash whether to trash or restore |
|
902 | - * @throws EE_Error |
|
903 | - */ |
|
904 | - private function _trash_or_restore_items(EEM_Soft_Delete_Base $model, $trash = true) |
|
905 | - { |
|
906 | - |
|
907 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
908 | - |
|
909 | - $success = 1; |
|
910 | - // Checkboxes |
|
911 | - // echo "trash $trash"; |
|
912 | - // var_dump($this->_req_data['checkbox']);die; |
|
913 | - if (isset($this->_req_data['checkbox'])) { |
|
914 | - if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) { |
|
915 | - // if array has more than one element than success message should be plural |
|
916 | - $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1; |
|
917 | - // cycle thru bulk action checkboxes |
|
918 | - while (list($ID, $value) = each($this->_req_data['checkbox'])) { |
|
919 | - if (! $model->delete_or_restore_by_ID($trash, absint($ID))) { |
|
920 | - $success = 0; |
|
921 | - } |
|
922 | - } |
|
923 | - } else { |
|
924 | - // grab single id and delete |
|
925 | - $ID = absint($this->_req_data['checkbox']); |
|
926 | - if (! $model->delete_or_restore_by_ID($trash, $ID)) { |
|
927 | - $success = 0; |
|
928 | - } |
|
929 | - } |
|
930 | - } else { |
|
931 | - // delete via trash link |
|
932 | - // grab single id and delete |
|
933 | - $ID = absint($this->_req_data[ $model->primary_key_name() ]); |
|
934 | - if (! $model->delete_or_restore_by_ID($trash, $ID)) { |
|
935 | - $success = 0; |
|
936 | - } |
|
937 | - } |
|
938 | - |
|
939 | - |
|
940 | - $action = $model instanceof EEM_Question ? 'default' : 'question_groups';// strtolower( $model->item_name(2) ); |
|
941 | - // echo "action :$action"; |
|
942 | - // $action = 'questions' ? 'default' : $action; |
|
943 | - if ($trash) { |
|
944 | - $action_desc = 'trashed'; |
|
945 | - $status = 'trash'; |
|
946 | - } else { |
|
947 | - $action_desc = 'restored'; |
|
948 | - $status = 'all'; |
|
949 | - } |
|
950 | - $this->_redirect_after_action( |
|
951 | - $success, |
|
952 | - $model->item_name($success), |
|
953 | - $action_desc, |
|
954 | - array('action' => $action, 'status' => $status) |
|
955 | - ); |
|
956 | - } |
|
957 | - |
|
958 | - |
|
959 | - /** |
|
960 | - * @param $per_page |
|
961 | - * @param int $current_page |
|
962 | - * @param bool|false $count |
|
963 | - * @return EE_Soft_Delete_Base_Class[]|int |
|
964 | - * @throws EE_Error |
|
965 | - * @throws InvalidArgumentException |
|
966 | - * @throws InvalidDataTypeException |
|
967 | - * @throws InvalidInterfaceException |
|
968 | - */ |
|
969 | - public function get_trashed_questions($per_page, $current_page = 1, $count = false) |
|
970 | - { |
|
971 | - $query_params = $this->get_query_params(EEM_Question::instance(), $per_page, $current_page); |
|
972 | - |
|
973 | - if ($count) { |
|
974 | - // note: this a subclass of EEM_Soft_Delete_Base, so this is actually only getting non-trashed items |
|
975 | - $where = isset($query_params[0]) ? array($query_params[0]) : array(); |
|
976 | - $results = $this->_question_model->count_deleted($where); |
|
977 | - } else { |
|
978 | - // note: this a subclass of EEM_Soft_Delete_Base, so this is actually only getting non-trashed items |
|
979 | - $results = $this->_question_model->get_all_deleted($query_params); |
|
980 | - } |
|
981 | - return $results; |
|
982 | - } |
|
983 | - |
|
984 | - |
|
985 | - /** |
|
986 | - * @param $per_page |
|
987 | - * @param int $current_page |
|
988 | - * @param bool|false $count |
|
989 | - * @return EE_Soft_Delete_Base_Class[]|int |
|
990 | - * @throws EE_Error |
|
991 | - * @throws InvalidArgumentException |
|
992 | - * @throws InvalidDataTypeException |
|
993 | - * @throws InvalidInterfaceException |
|
994 | - */ |
|
995 | - public function get_question_groups($per_page, $current_page = 1, $count = false) |
|
996 | - { |
|
997 | - $questionGroupModel = EEM_Question_Group::instance(); |
|
998 | - $query_params = $this->get_query_params($questionGroupModel, $per_page, $current_page); |
|
999 | - if ($count) { |
|
1000 | - $where = isset($query_params[0]) ? array($query_params[0]) : array(); |
|
1001 | - $results = $questionGroupModel->count($where); |
|
1002 | - } else { |
|
1003 | - $results = $questionGroupModel->get_all($query_params); |
|
1004 | - } |
|
1005 | - return $results; |
|
1006 | - } |
|
1007 | - |
|
1008 | - |
|
1009 | - /** |
|
1010 | - * @param $per_page |
|
1011 | - * @param int $current_page |
|
1012 | - * @param bool $count |
|
1013 | - * @return EE_Soft_Delete_Base_Class[]|int |
|
1014 | - * @throws EE_Error |
|
1015 | - * @throws InvalidArgumentException |
|
1016 | - * @throws InvalidDataTypeException |
|
1017 | - * @throws InvalidInterfaceException |
|
1018 | - */ |
|
1019 | - public function get_trashed_question_groups($per_page, $current_page = 1, $count = false) |
|
1020 | - { |
|
1021 | - $questionGroupModel = EEM_Question_Group::instance(); |
|
1022 | - $query_params = $this->get_query_params($questionGroupModel, $per_page, $current_page); |
|
1023 | - if ($count) { |
|
1024 | - $where = isset($query_params[0]) ? array($query_params[0]) : array(); |
|
1025 | - $query_params['limit'] = null; |
|
1026 | - $results = $questionGroupModel->count_deleted($where); |
|
1027 | - } else { |
|
1028 | - $results = $questionGroupModel->get_all_deleted($query_params); |
|
1029 | - } |
|
1030 | - return $results; |
|
1031 | - } |
|
1032 | - |
|
1033 | - |
|
1034 | - /** |
|
1035 | - * method for performing updates to question order |
|
1036 | - * |
|
1037 | - * @return void results array |
|
1038 | - * @throws EE_Error |
|
1039 | - * @throws InvalidArgumentException |
|
1040 | - * @throws InvalidDataTypeException |
|
1041 | - * @throws InvalidInterfaceException |
|
1042 | - */ |
|
1043 | - public function update_question_group_order() |
|
1044 | - { |
|
1045 | - |
|
1046 | - $success = esc_html__('Question group order was updated successfully.', 'event_espresso'); |
|
1047 | - |
|
1048 | - // grab our row IDs |
|
1049 | - $row_ids = isset($this->_req_data['row_ids']) && ! empty($this->_req_data['row_ids']) |
|
1050 | - ? explode(',', rtrim($this->_req_data['row_ids'], ',')) |
|
1051 | - : array(); |
|
1052 | - |
|
1053 | - $perpage = ! empty($this->_req_data['perpage']) |
|
1054 | - ? (int) $this->_req_data['perpage'] |
|
1055 | - : null; |
|
1056 | - $curpage = ! empty($this->_req_data['curpage']) |
|
1057 | - ? (int) $this->_req_data['curpage'] |
|
1058 | - : null; |
|
1059 | - |
|
1060 | - if (! empty($row_ids)) { |
|
1061 | - // figure out where we start the row_id count at for the current page. |
|
1062 | - $qsgcount = empty($curpage) ? 0 : ($curpage - 1) * $perpage; |
|
1063 | - |
|
1064 | - $row_count = count($row_ids); |
|
1065 | - for ($i = 0; $i < $row_count; $i++) { |
|
1066 | - // Update the questions when re-ordering |
|
1067 | - $updated = EEM_Question_Group::instance()->update( |
|
1068 | - array('QSG_order' => $qsgcount), |
|
1069 | - array(array('QSG_ID' => $row_ids[ $i ])) |
|
1070 | - ); |
|
1071 | - if ($updated === false) { |
|
1072 | - $success = false; |
|
1073 | - } |
|
1074 | - $qsgcount++; |
|
1075 | - } |
|
1076 | - } else { |
|
1077 | - $success = false; |
|
1078 | - } |
|
1079 | - |
|
1080 | - $errors = ! $success |
|
1081 | - ? esc_html__('An error occurred. The question group order was not updated.', 'event_espresso') |
|
1082 | - : false; |
|
1083 | - |
|
1084 | - echo wp_json_encode(array('return_data' => false, 'success' => $success, 'errors' => $errors)); |
|
1085 | - die(); |
|
1086 | - } |
|
1087 | - |
|
1088 | - |
|
1089 | - |
|
1090 | - /*************************************** REGISTRATION SETTINGS ***************************************/ |
|
1091 | - |
|
1092 | - |
|
1093 | - /** |
|
1094 | - * @throws DomainException |
|
1095 | - * @throws EE_Error |
|
1096 | - * @throws InvalidArgumentException |
|
1097 | - * @throws InvalidDataTypeException |
|
1098 | - * @throws InvalidInterfaceException |
|
1099 | - */ |
|
1100 | - protected function _reg_form_settings() |
|
1101 | - { |
|
1102 | - $this->_template_args['values'] = $this->_yes_no_values; |
|
1103 | - add_action( |
|
1104 | - 'AHEE__Extend_Registration_Form_Admin_Page___reg_form_settings_template', |
|
1105 | - array($this, 'email_validation_settings_form'), |
|
1106 | - 2 |
|
1107 | - ); |
|
1108 | - add_action( |
|
1109 | - 'AHEE__Extend_Registration_Form_Admin_Page___reg_form_settings_template', |
|
1110 | - array($this, 'copy_attendee_info_settings_form'), |
|
1111 | - 4 |
|
1112 | - ); |
|
1113 | - $this->_template_args = (array) apply_filters( |
|
1114 | - 'FHEE__Extend_Registration_Form_Admin_Page___reg_form_settings___template_args', |
|
1115 | - $this->_template_args |
|
1116 | - ); |
|
1117 | - $this->_set_add_edit_form_tags('update_reg_form_settings'); |
|
1118 | - $this->_set_publish_post_box_vars(null, false, false, null, false); |
|
1119 | - $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
1120 | - REGISTRATION_FORM_CAF_TEMPLATE_PATH . 'reg_form_settings.template.php', |
|
1121 | - $this->_template_args, |
|
1122 | - true |
|
1123 | - ); |
|
1124 | - $this->display_admin_page_with_sidebar(); |
|
1125 | - } |
|
1126 | - |
|
1127 | - |
|
1128 | - /** |
|
1129 | - * @return void |
|
1130 | - * @throws EE_Error |
|
1131 | - * @throws InvalidArgumentException |
|
1132 | - * @throws ReflectionException |
|
1133 | - * @throws InvalidDataTypeException |
|
1134 | - * @throws InvalidInterfaceException |
|
1135 | - */ |
|
1136 | - protected function _update_reg_form_settings() |
|
1137 | - { |
|
1138 | - EE_Registry::instance()->CFG->registration = $this->update_email_validation_settings_form( |
|
1139 | - EE_Registry::instance()->CFG->registration |
|
1140 | - ); |
|
1141 | - EE_Registry::instance()->CFG->registration = $this->update_copy_attendee_info_settings_form( |
|
1142 | - EE_Registry::instance()->CFG->registration |
|
1143 | - ); |
|
1144 | - EE_Registry::instance()->CFG->registration = apply_filters( |
|
1145 | - 'FHEE__Extend_Registration_Form_Admin_Page___update_reg_form_settings__CFG_registration', |
|
1146 | - EE_Registry::instance()->CFG->registration |
|
1147 | - ); |
|
1148 | - $success = $this->_update_espresso_configuration( |
|
1149 | - esc_html__('Registration Form Options', 'event_espresso'), |
|
1150 | - EE_Registry::instance()->CFG, |
|
1151 | - __FILE__, |
|
1152 | - __FUNCTION__, |
|
1153 | - __LINE__ |
|
1154 | - ); |
|
1155 | - $this->_redirect_after_action( |
|
1156 | - $success, |
|
1157 | - esc_html__('Registration Form Options', 'event_espresso'), |
|
1158 | - 'updated', |
|
1159 | - array('action' => 'view_reg_form_settings') |
|
1160 | - ); |
|
1161 | - } |
|
1162 | - |
|
1163 | - |
|
1164 | - /** |
|
1165 | - * @return void |
|
1166 | - * @throws EE_Error |
|
1167 | - * @throws InvalidArgumentException |
|
1168 | - * @throws InvalidDataTypeException |
|
1169 | - * @throws InvalidInterfaceException |
|
1170 | - */ |
|
1171 | - public function copy_attendee_info_settings_form() |
|
1172 | - { |
|
1173 | - echo $this->_copy_attendee_info_settings_form()->get_html(); |
|
1174 | - } |
|
1175 | - |
|
1176 | - /** |
|
1177 | - * _copy_attendee_info_settings_form |
|
1178 | - * |
|
1179 | - * @access protected |
|
1180 | - * @return EE_Form_Section_Proper |
|
1181 | - * @throws \EE_Error |
|
1182 | - */ |
|
1183 | - protected function _copy_attendee_info_settings_form() |
|
1184 | - { |
|
1185 | - return new EE_Form_Section_Proper( |
|
1186 | - array( |
|
1187 | - 'name' => 'copy_attendee_info_settings', |
|
1188 | - 'html_id' => 'copy_attendee_info_settings', |
|
1189 | - 'layout_strategy' => new EE_Admin_Two_Column_Layout(), |
|
1190 | - 'subsections' => apply_filters( |
|
1191 | - 'FHEE__Extend_Registration_Form_Admin_Page___copy_attendee_info_settings_form__form_subsections', |
|
1192 | - array( |
|
1193 | - 'copy_attendee_info_hdr' => new EE_Form_Section_HTML( |
|
1194 | - EEH_HTML::h2(esc_html__('Copy Attendee Info Settings', 'event_espresso')) |
|
1195 | - ), |
|
1196 | - 'copy_attendee_info' => new EE_Yes_No_Input( |
|
1197 | - array( |
|
1198 | - 'html_label_text' => esc_html__( |
|
1199 | - 'Allow copy #1 attendee info to extra attendees?', |
|
1200 | - 'event_espresso' |
|
1201 | - ), |
|
1202 | - 'html_help_text' => esc_html__( |
|
1203 | - 'Set to yes if you want to enable the copy of #1 attendee info to extra attendees at Registration Form.', |
|
1204 | - 'event_espresso' |
|
1205 | - ), |
|
1206 | - 'default' => EE_Registry::instance()->CFG->registration->copyAttendeeInfo(), |
|
1207 | - 'required' => false, |
|
1208 | - 'display_html_label_text' => false, |
|
1209 | - ) |
|
1210 | - ), |
|
1211 | - ) |
|
1212 | - ), |
|
1213 | - ) |
|
1214 | - ); |
|
1215 | - } |
|
1216 | - |
|
1217 | - /** |
|
1218 | - * @param EE_Registration_Config $EE_Registration_Config |
|
1219 | - * @return EE_Registration_Config |
|
1220 | - * @throws EE_Error |
|
1221 | - * @throws InvalidArgumentException |
|
1222 | - * @throws ReflectionException |
|
1223 | - * @throws InvalidDataTypeException |
|
1224 | - * @throws InvalidInterfaceException |
|
1225 | - */ |
|
1226 | - public function update_copy_attendee_info_settings_form(EE_Registration_Config $EE_Registration_Config) |
|
1227 | - { |
|
1228 | - $prev_copy_attendee_info = $EE_Registration_Config->copyAttendeeInfo(); |
|
1229 | - try { |
|
1230 | - $copy_attendee_info_settings_form = $this->_copy_attendee_info_settings_form(); |
|
1231 | - // if not displaying a form, then check for form submission |
|
1232 | - if ($copy_attendee_info_settings_form->was_submitted()) { |
|
1233 | - // capture form data |
|
1234 | - $copy_attendee_info_settings_form->receive_form_submission(); |
|
1235 | - // validate form data |
|
1236 | - if ($copy_attendee_info_settings_form->is_valid()) { |
|
1237 | - // grab validated data from form |
|
1238 | - $valid_data = $copy_attendee_info_settings_form->valid_data(); |
|
1239 | - if (isset($valid_data['copy_attendee_info'])) { |
|
1240 | - $EE_Registration_Config->setCopyAttendeeInfo($valid_data['copy_attendee_info']); |
|
1241 | - } else { |
|
1242 | - EE_Error::add_error( |
|
1243 | - esc_html__( |
|
1244 | - 'Invalid or missing Copy Attendee Info settings. Please refresh the form and try again.', |
|
1245 | - 'event_espresso' |
|
1246 | - ), |
|
1247 | - __FILE__, |
|
1248 | - __FUNCTION__, |
|
1249 | - __LINE__ |
|
1250 | - ); |
|
1251 | - } |
|
1252 | - } else { |
|
1253 | - if ($copy_attendee_info_settings_form->submission_error_message() !== '') { |
|
1254 | - EE_Error::add_error( |
|
1255 | - $copy_attendee_info_settings_form->submission_error_message(), |
|
1256 | - __FILE__, |
|
1257 | - __FUNCTION__, |
|
1258 | - __LINE__ |
|
1259 | - ); |
|
1260 | - } |
|
1261 | - } |
|
1262 | - } |
|
1263 | - } catch (EE_Error $e) { |
|
1264 | - $e->get_error(); |
|
1265 | - } |
|
1266 | - return $EE_Registration_Config; |
|
1267 | - } |
|
1268 | - |
|
1269 | - |
|
1270 | - /** |
|
1271 | - * @return void |
|
1272 | - * @throws EE_Error |
|
1273 | - * @throws InvalidArgumentException |
|
1274 | - * @throws InvalidDataTypeException |
|
1275 | - * @throws InvalidInterfaceException |
|
1276 | - */ |
|
1277 | - public function email_validation_settings_form() |
|
1278 | - { |
|
1279 | - echo $this->_email_validation_settings_form()->get_html(); |
|
1280 | - } |
|
1281 | - |
|
1282 | - |
|
1283 | - /** |
|
1284 | - * _email_validation_settings_form |
|
1285 | - * |
|
1286 | - * @access protected |
|
1287 | - * @return EE_Form_Section_Proper |
|
1288 | - * @throws \EE_Error |
|
1289 | - */ |
|
1290 | - protected function _email_validation_settings_form() |
|
1291 | - { |
|
1292 | - return new EE_Form_Section_Proper( |
|
1293 | - array( |
|
1294 | - 'name' => 'email_validation_settings', |
|
1295 | - 'html_id' => 'email_validation_settings', |
|
1296 | - 'layout_strategy' => new EE_Admin_Two_Column_Layout(), |
|
1297 | - 'subsections' => apply_filters( |
|
1298 | - 'FHEE__Extend_Registration_Form_Admin_Page___email_validation_settings_form__form_subsections', |
|
1299 | - array( |
|
1300 | - 'email_validation_hdr' => new EE_Form_Section_HTML( |
|
1301 | - EEH_HTML::h2(esc_html__('Email Validation Settings', 'event_espresso')) |
|
1302 | - ), |
|
1303 | - 'email_validation_level' => new EE_Select_Input( |
|
1304 | - array( |
|
1305 | - 'basic' => esc_html__('Basic', 'event_espresso'), |
|
1306 | - 'wp_default' => esc_html__('WordPress Default', 'event_espresso'), |
|
1307 | - 'i18n' => esc_html__('International', 'event_espresso'), |
|
1308 | - 'i18n_dns' => esc_html__('International + DNS Check', 'event_espresso'), |
|
1309 | - ), |
|
1310 | - array( |
|
1311 | - 'html_label_text' => esc_html__('Email Validation Level', 'event_espresso') |
|
1312 | - . EEH_Template::get_help_tab_link('email_validation_info'), |
|
1313 | - 'html_help_text' => esc_html__( |
|
1314 | - '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.', |
|
1315 | - 'event_espresso' |
|
1316 | - ), |
|
1317 | - 'default' => isset( |
|
1318 | - EE_Registry::instance()->CFG->registration->email_validation_level |
|
1319 | - ) |
|
1320 | - ? EE_Registry::instance()->CFG->registration->email_validation_level |
|
1321 | - : 'wp_default', |
|
1322 | - 'required' => false, |
|
1323 | - ) |
|
1324 | - ), |
|
1325 | - ) |
|
1326 | - ), |
|
1327 | - ) |
|
1328 | - ); |
|
1329 | - } |
|
1330 | - |
|
1331 | - |
|
1332 | - /** |
|
1333 | - * @param EE_Registration_Config $EE_Registration_Config |
|
1334 | - * @return EE_Registration_Config |
|
1335 | - * @throws EE_Error |
|
1336 | - * @throws InvalidArgumentException |
|
1337 | - * @throws ReflectionException |
|
1338 | - * @throws InvalidDataTypeException |
|
1339 | - * @throws InvalidInterfaceException |
|
1340 | - */ |
|
1341 | - public function update_email_validation_settings_form(EE_Registration_Config $EE_Registration_Config) |
|
1342 | - { |
|
1343 | - $prev_email_validation_level = $EE_Registration_Config->email_validation_level; |
|
1344 | - try { |
|
1345 | - $email_validation_settings_form = $this->_email_validation_settings_form(); |
|
1346 | - // if not displaying a form, then check for form submission |
|
1347 | - if ($email_validation_settings_form->was_submitted()) { |
|
1348 | - // capture form data |
|
1349 | - $email_validation_settings_form->receive_form_submission(); |
|
1350 | - // validate form data |
|
1351 | - if ($email_validation_settings_form->is_valid()) { |
|
1352 | - // grab validated data from form |
|
1353 | - $valid_data = $email_validation_settings_form->valid_data(); |
|
1354 | - if (isset($valid_data['email_validation_level'])) { |
|
1355 | - $email_validation_level = $valid_data['email_validation_level']; |
|
1356 | - // now if they want to use international email addresses |
|
1357 | - if ($email_validation_level === 'i18n' || $email_validation_level === 'i18n_dns') { |
|
1358 | - // in case we need to reset their email validation level, |
|
1359 | - // make sure that the previous value wasn't already set to one of the i18n options. |
|
1360 | - if ($prev_email_validation_level === 'i18n' || $prev_email_validation_level === 'i18n_dns') { |
|
1361 | - // if so, then reset it back to "basic" since that is the only other option that, |
|
1362 | - // despite offering poor validation, supports i18n email addresses |
|
1363 | - $prev_email_validation_level = 'basic'; |
|
1364 | - } |
|
1365 | - // confirm our i18n email validation will work on the server |
|
1366 | - if (! $this->_verify_pcre_support($EE_Registration_Config, $email_validation_level)) { |
|
1367 | - // or reset email validation level to previous value |
|
1368 | - $email_validation_level = $prev_email_validation_level; |
|
1369 | - } |
|
1370 | - } |
|
1371 | - $EE_Registration_Config->email_validation_level = $email_validation_level; |
|
1372 | - } else { |
|
1373 | - EE_Error::add_error( |
|
1374 | - esc_html__( |
|
1375 | - 'Invalid or missing Email Validation settings. Please refresh the form and try again.', |
|
1376 | - 'event_espresso' |
|
1377 | - ), |
|
1378 | - __FILE__, |
|
1379 | - __FUNCTION__, |
|
1380 | - __LINE__ |
|
1381 | - ); |
|
1382 | - } |
|
1383 | - } else { |
|
1384 | - if ($email_validation_settings_form->submission_error_message() !== '') { |
|
1385 | - EE_Error::add_error( |
|
1386 | - $email_validation_settings_form->submission_error_message(), |
|
1387 | - __FILE__, |
|
1388 | - __FUNCTION__, |
|
1389 | - __LINE__ |
|
1390 | - ); |
|
1391 | - } |
|
1392 | - } |
|
1393 | - } |
|
1394 | - } catch (EE_Error $e) { |
|
1395 | - $e->get_error(); |
|
1396 | - } |
|
1397 | - return $EE_Registration_Config; |
|
1398 | - } |
|
1399 | - |
|
1400 | - |
|
1401 | - /** |
|
1402 | - * confirms that the server's PHP version has the PCRE module enabled, |
|
1403 | - * and that the PCRE version works with our i18n email validation |
|
1404 | - * |
|
1405 | - * @param EE_Registration_Config $EE_Registration_Config |
|
1406 | - * @param string $email_validation_level |
|
1407 | - * @return bool |
|
1408 | - */ |
|
1409 | - private function _verify_pcre_support(EE_Registration_Config $EE_Registration_Config, $email_validation_level) |
|
1410 | - { |
|
1411 | - // first check that PCRE is enabled |
|
1412 | - if (! defined('PREG_BAD_UTF8_ERROR')) { |
|
1413 | - EE_Error::add_error( |
|
1414 | - sprintf( |
|
1415 | - esc_html__( |
|
1416 | - '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.', |
|
1417 | - 'event_espresso' |
|
1418 | - ), |
|
1419 | - '<br />' |
|
1420 | - ), |
|
1421 | - __FILE__, |
|
1422 | - __FUNCTION__, |
|
1423 | - __LINE__ |
|
1424 | - ); |
|
1425 | - return false; |
|
1426 | - } else { |
|
1427 | - // PCRE support is enabled, but let's still |
|
1428 | - // perform a test to see if the server will support it. |
|
1429 | - // but first, save the updated validation level to the config, |
|
1430 | - // so that the validation strategy picks it up. |
|
1431 | - // this will get bumped back down if it doesn't work |
|
1432 | - $EE_Registration_Config->email_validation_level = $email_validation_level; |
|
1433 | - try { |
|
1434 | - $email_validator = new EE_Email_Validation_Strategy(); |
|
1435 | - $i18n_email_address = apply_filters( |
|
1436 | - 'FHEE__Extend_Registration_Form_Admin_Page__update_email_validation_settings_form__i18n_email_address', |
|
1437 | - 'jägerjü[email protected]' |
|
1438 | - ); |
|
1439 | - $email_validator->validate($i18n_email_address); |
|
1440 | - } catch (Exception $e) { |
|
1441 | - EE_Error::add_error( |
|
1442 | - sprintf( |
|
1443 | - esc_html__( |
|
1444 | - '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', |
|
1445 | - 'event_espresso' |
|
1446 | - ), |
|
1447 | - '<br />', |
|
1448 | - '<a href="http://php.net/manual/en/pcre.installation.php" target="_blank" rel="noopener noreferrer">http://php.net/manual/en/pcre.installation.php</a>' |
|
1449 | - ), |
|
1450 | - __FILE__, |
|
1451 | - __FUNCTION__, |
|
1452 | - __LINE__ |
|
1453 | - ); |
|
1454 | - return false; |
|
1455 | - } |
|
1456 | - } |
|
1457 | - return true; |
|
1458 | - } |
|
17 | + /** |
|
18 | + * @param bool $routing indicate whether we want to just load the object and handle routing or just load the object. |
|
19 | + */ |
|
20 | + public function __construct($routing = true) |
|
21 | + { |
|
22 | + define('REGISTRATION_FORM_CAF_ADMIN', EE_CORE_CAF_ADMIN_EXTEND . 'registration_form/'); |
|
23 | + define('REGISTRATION_FORM_CAF_ASSETS_PATH', REGISTRATION_FORM_CAF_ADMIN . 'assets/'); |
|
24 | + define('REGISTRATION_FORM_CAF_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL . 'registration_form/assets/'); |
|
25 | + define('REGISTRATION_FORM_CAF_TEMPLATE_PATH', REGISTRATION_FORM_CAF_ADMIN . 'templates/'); |
|
26 | + define('REGISTRATION_FORM_CAF_TEMPLATE_URL', EE_CORE_CAF_ADMIN_EXTEND_URL . 'registration_form/templates/'); |
|
27 | + parent::__construct($routing); |
|
28 | + } |
|
29 | + |
|
30 | + |
|
31 | + /** |
|
32 | + * @return void |
|
33 | + */ |
|
34 | + protected function _extend_page_config() |
|
35 | + { |
|
36 | + $this->_admin_base_path = REGISTRATION_FORM_CAF_ADMIN; |
|
37 | + $qst_id = ! empty($this->_req_data['QST_ID']) && ! is_array($this->_req_data['QST_ID']) |
|
38 | + ? $this->_req_data['QST_ID'] : 0; |
|
39 | + $qsg_id = ! empty($this->_req_data['QSG_ID']) && ! is_array($this->_req_data['QSG_ID']) |
|
40 | + ? $this->_req_data['QSG_ID'] : 0; |
|
41 | + |
|
42 | + $new_page_routes = array( |
|
43 | + 'question_groups' => array( |
|
44 | + 'func' => '_question_groups_overview_list_table', |
|
45 | + 'capability' => 'ee_read_question_groups', |
|
46 | + ), |
|
47 | + 'add_question' => array( |
|
48 | + 'func' => '_edit_question', |
|
49 | + 'capability' => 'ee_edit_questions', |
|
50 | + ), |
|
51 | + 'insert_question' => array( |
|
52 | + 'func' => '_insert_or_update_question', |
|
53 | + 'args' => array('new_question' => true), |
|
54 | + 'capability' => 'ee_edit_questions', |
|
55 | + 'noheader' => true, |
|
56 | + ), |
|
57 | + 'duplicate_question' => array( |
|
58 | + 'func' => '_duplicate_question', |
|
59 | + 'capability' => 'ee_edit_questions', |
|
60 | + 'noheader' => true, |
|
61 | + ), |
|
62 | + 'trash_question' => array( |
|
63 | + 'func' => '_trash_question', |
|
64 | + 'capability' => 'ee_delete_question', |
|
65 | + 'obj_id' => $qst_id, |
|
66 | + 'noheader' => true, |
|
67 | + ), |
|
68 | + |
|
69 | + 'restore_question' => array( |
|
70 | + 'func' => '_trash_or_restore_questions', |
|
71 | + 'capability' => 'ee_delete_question', |
|
72 | + 'obj_id' => $qst_id, |
|
73 | + 'args' => array('trash' => false), |
|
74 | + 'noheader' => true, |
|
75 | + ), |
|
76 | + |
|
77 | + 'delete_question' => array( |
|
78 | + 'func' => '_delete_question', |
|
79 | + 'capability' => 'ee_delete_question', |
|
80 | + 'obj_id' => $qst_id, |
|
81 | + 'noheader' => true, |
|
82 | + ), |
|
83 | + |
|
84 | + 'trash_questions' => array( |
|
85 | + 'func' => '_trash_or_restore_questions', |
|
86 | + 'capability' => 'ee_delete_questions', |
|
87 | + 'args' => array('trash' => true), |
|
88 | + 'noheader' => true, |
|
89 | + ), |
|
90 | + |
|
91 | + 'restore_questions' => array( |
|
92 | + 'func' => '_trash_or_restore_questions', |
|
93 | + 'capability' => 'ee_delete_questions', |
|
94 | + 'args' => array('trash' => false), |
|
95 | + 'noheader' => true, |
|
96 | + ), |
|
97 | + |
|
98 | + 'delete_questions' => array( |
|
99 | + 'func' => '_delete_questions', |
|
100 | + 'args' => array(), |
|
101 | + 'capability' => 'ee_delete_questions', |
|
102 | + 'noheader' => true, |
|
103 | + ), |
|
104 | + |
|
105 | + 'add_question_group' => array( |
|
106 | + 'func' => '_edit_question_group', |
|
107 | + 'capability' => 'ee_edit_question_groups', |
|
108 | + ), |
|
109 | + |
|
110 | + 'edit_question_group' => array( |
|
111 | + 'func' => '_edit_question_group', |
|
112 | + 'capability' => 'ee_edit_question_group', |
|
113 | + 'obj_id' => $qsg_id, |
|
114 | + 'args' => array('edit'), |
|
115 | + ), |
|
116 | + |
|
117 | + 'delete_question_groups' => array( |
|
118 | + 'func' => '_delete_question_groups', |
|
119 | + 'capability' => 'ee_delete_question_groups', |
|
120 | + 'noheader' => true, |
|
121 | + ), |
|
122 | + |
|
123 | + 'delete_question_group' => array( |
|
124 | + 'func' => '_delete_question_groups', |
|
125 | + 'capability' => 'ee_delete_question_group', |
|
126 | + 'obj_id' => $qsg_id, |
|
127 | + 'noheader' => true, |
|
128 | + ), |
|
129 | + |
|
130 | + 'trash_question_group' => array( |
|
131 | + 'func' => '_trash_or_restore_question_groups', |
|
132 | + 'args' => array('trash' => true), |
|
133 | + 'capability' => 'ee_delete_question_group', |
|
134 | + 'obj_id' => $qsg_id, |
|
135 | + 'noheader' => true, |
|
136 | + ), |
|
137 | + |
|
138 | + 'restore_question_group' => array( |
|
139 | + 'func' => '_trash_or_restore_question_groups', |
|
140 | + 'args' => array('trash' => false), |
|
141 | + 'capability' => 'ee_delete_question_group', |
|
142 | + 'obj_id' => $qsg_id, |
|
143 | + 'noheader' => true, |
|
144 | + ), |
|
145 | + |
|
146 | + 'insert_question_group' => array( |
|
147 | + 'func' => '_insert_or_update_question_group', |
|
148 | + 'args' => array('new_question_group' => true), |
|
149 | + 'capability' => 'ee_edit_question_groups', |
|
150 | + 'noheader' => true, |
|
151 | + ), |
|
152 | + |
|
153 | + 'update_question_group' => array( |
|
154 | + 'func' => '_insert_or_update_question_group', |
|
155 | + 'args' => array('new_question_group' => false), |
|
156 | + 'capability' => 'ee_edit_question_group', |
|
157 | + 'obj_id' => $qsg_id, |
|
158 | + 'noheader' => true, |
|
159 | + ), |
|
160 | + |
|
161 | + 'trash_question_groups' => array( |
|
162 | + 'func' => '_trash_or_restore_question_groups', |
|
163 | + 'args' => array('trash' => true), |
|
164 | + 'capability' => 'ee_delete_question_groups', |
|
165 | + 'noheader' => array('trash' => false), |
|
166 | + ), |
|
167 | + |
|
168 | + 'restore_question_groups' => array( |
|
169 | + 'func' => '_trash_or_restore_question_groups', |
|
170 | + 'args' => array('trash' => false), |
|
171 | + 'capability' => 'ee_delete_question_groups', |
|
172 | + 'noheader' => true, |
|
173 | + ), |
|
174 | + |
|
175 | + |
|
176 | + 'espresso_update_question_group_order' => array( |
|
177 | + 'func' => 'update_question_group_order', |
|
178 | + 'capability' => 'ee_edit_question_groups', |
|
179 | + 'noheader' => true, |
|
180 | + ), |
|
181 | + |
|
182 | + 'view_reg_form_settings' => array( |
|
183 | + 'func' => '_reg_form_settings', |
|
184 | + 'capability' => 'manage_options', |
|
185 | + ), |
|
186 | + |
|
187 | + 'update_reg_form_settings' => array( |
|
188 | + 'func' => '_update_reg_form_settings', |
|
189 | + 'capability' => 'manage_options', |
|
190 | + 'noheader' => true, |
|
191 | + ), |
|
192 | + ); |
|
193 | + $this->_page_routes = array_merge($this->_page_routes, $new_page_routes); |
|
194 | + |
|
195 | + $new_page_config = array( |
|
196 | + |
|
197 | + 'question_groups' => array( |
|
198 | + 'nav' => array( |
|
199 | + 'label' => esc_html__('Question Groups', 'event_espresso'), |
|
200 | + 'order' => 20, |
|
201 | + ), |
|
202 | + 'list_table' => 'Registration_Form_Question_Groups_Admin_List_Table', |
|
203 | + 'help_tabs' => array( |
|
204 | + 'registration_form_question_groups_help_tab' => array( |
|
205 | + 'title' => esc_html__('Question Groups', 'event_espresso'), |
|
206 | + 'filename' => 'registration_form_question_groups', |
|
207 | + ), |
|
208 | + 'registration_form_question_groups_table_column_headings_help_tab' => array( |
|
209 | + 'title' => esc_html__('Question Groups Table Column Headings', 'event_espresso'), |
|
210 | + 'filename' => 'registration_form_question_groups_table_column_headings', |
|
211 | + ), |
|
212 | + 'registration_form_question_groups_views_bulk_actions_search_help_tab' => array( |
|
213 | + 'title' => esc_html__('Question Groups Views & Bulk Actions & Search', 'event_espresso'), |
|
214 | + 'filename' => 'registration_form_question_groups_views_bulk_actions_search', |
|
215 | + ), |
|
216 | + ), |
|
217 | + // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836 |
|
218 | + // 'help_tour' => array('Registration_Form_Question_Groups_Help_Tour'), |
|
219 | + 'metaboxes' => $this->_default_espresso_metaboxes, |
|
220 | + 'require_nonce' => false, |
|
221 | + 'qtips' => array( |
|
222 | + 'EE_Registration_Form_Tips', |
|
223 | + ), |
|
224 | + ), |
|
225 | + |
|
226 | + 'add_question' => array( |
|
227 | + 'nav' => array( |
|
228 | + 'label' => esc_html__('Add Question', 'event_espresso'), |
|
229 | + 'order' => 5, |
|
230 | + 'persistent' => false, |
|
231 | + ), |
|
232 | + 'metaboxes' => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')), |
|
233 | + 'help_tabs' => array( |
|
234 | + 'registration_form_add_question_help_tab' => array( |
|
235 | + 'title' => esc_html__('Add Question', 'event_espresso'), |
|
236 | + 'filename' => 'registration_form_add_question', |
|
237 | + ), |
|
238 | + ), |
|
239 | + // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836 |
|
240 | + // 'help_tour' => array('Registration_Form_Add_Question_Help_Tour'), |
|
241 | + 'require_nonce' => false, |
|
242 | + ), |
|
243 | + |
|
244 | + 'add_question_group' => array( |
|
245 | + 'nav' => array( |
|
246 | + 'label' => esc_html__('Add Question Group', 'event_espresso'), |
|
247 | + 'order' => 5, |
|
248 | + 'persistent' => false, |
|
249 | + ), |
|
250 | + 'metaboxes' => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')), |
|
251 | + 'help_tabs' => array( |
|
252 | + 'registration_form_add_question_group_help_tab' => array( |
|
253 | + 'title' => esc_html__('Add Question Group', 'event_espresso'), |
|
254 | + 'filename' => 'registration_form_add_question_group', |
|
255 | + ), |
|
256 | + ), |
|
257 | + // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836 |
|
258 | + // 'help_tour' => array('Registration_Form_Add_Question_Group_Help_Tour'), |
|
259 | + 'require_nonce' => false, |
|
260 | + ), |
|
261 | + |
|
262 | + 'edit_question_group' => array( |
|
263 | + 'nav' => array( |
|
264 | + 'label' => esc_html__('Edit Question Group', 'event_espresso'), |
|
265 | + 'order' => 5, |
|
266 | + 'persistent' => false, |
|
267 | + 'url' => isset($this->_req_data['question_group_id']) ? add_query_arg( |
|
268 | + array('question_group_id' => $this->_req_data['question_group_id']), |
|
269 | + $this->_current_page_view_url |
|
270 | + ) : $this->_admin_base_url, |
|
271 | + ), |
|
272 | + 'metaboxes' => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')), |
|
273 | + 'help_tabs' => array( |
|
274 | + 'registration_form_edit_question_group_help_tab' => array( |
|
275 | + 'title' => esc_html__('Edit Question Group', 'event_espresso'), |
|
276 | + 'filename' => 'registration_form_edit_question_group', |
|
277 | + ), |
|
278 | + ), |
|
279 | + // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836 |
|
280 | + // 'help_tour' => array('Registration_Form_Edit_Question_Group_Help_Tour'), |
|
281 | + 'require_nonce' => false, |
|
282 | + ), |
|
283 | + |
|
284 | + 'view_reg_form_settings' => array( |
|
285 | + 'nav' => array( |
|
286 | + 'label' => esc_html__('Reg Form Settings', 'event_espresso'), |
|
287 | + 'order' => 40, |
|
288 | + ), |
|
289 | + 'labels' => array( |
|
290 | + 'publishbox' => esc_html__('Update Settings', 'event_espresso'), |
|
291 | + ), |
|
292 | + 'metaboxes' => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')), |
|
293 | + 'help_tabs' => array( |
|
294 | + 'registration_form_reg_form_settings_help_tab' => array( |
|
295 | + 'title' => esc_html__('Registration Form Settings', 'event_espresso'), |
|
296 | + 'filename' => 'registration_form_reg_form_settings', |
|
297 | + ), |
|
298 | + ), |
|
299 | + // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836 |
|
300 | + // 'help_tour' => array('Registration_Form_Settings_Help_Tour'), |
|
301 | + 'require_nonce' => false, |
|
302 | + ), |
|
303 | + |
|
304 | + ); |
|
305 | + $this->_page_config = array_merge($this->_page_config, $new_page_config); |
|
306 | + |
|
307 | + // change the list table we're going to use so it's the NEW list table! |
|
308 | + $this->_page_config['default']['list_table'] = 'Extend_Registration_Form_Questions_Admin_List_Table'; |
|
309 | + |
|
310 | + |
|
311 | + // additional labels |
|
312 | + $new_labels = array( |
|
313 | + 'add_question' => esc_html__('Add New Question', 'event_espresso'), |
|
314 | + 'delete_question' => esc_html__('Delete Question', 'event_espresso'), |
|
315 | + 'add_question_group' => esc_html__('Add New Question Group', 'event_espresso'), |
|
316 | + 'edit_question_group' => esc_html__('Edit Question Group', 'event_espresso'), |
|
317 | + 'delete_question_group' => esc_html__('Delete Question Group', 'event_espresso'), |
|
318 | + ); |
|
319 | + $this->_labels['buttons'] = array_merge($this->_labels['buttons'], $new_labels); |
|
320 | + } |
|
321 | + |
|
322 | + |
|
323 | + /** |
|
324 | + * @return void |
|
325 | + */ |
|
326 | + protected function _ajax_hooks() |
|
327 | + { |
|
328 | + add_action('wp_ajax_espresso_update_question_group_order', array($this, 'update_question_group_order')); |
|
329 | + } |
|
330 | + |
|
331 | + |
|
332 | + /** |
|
333 | + * @return void |
|
334 | + */ |
|
335 | + public function load_scripts_styles_question_groups() |
|
336 | + { |
|
337 | + wp_enqueue_script('espresso_ajax_table_sorting'); |
|
338 | + } |
|
339 | + |
|
340 | + |
|
341 | + /** |
|
342 | + * @return void |
|
343 | + */ |
|
344 | + public function load_scripts_styles_add_question_group() |
|
345 | + { |
|
346 | + $this->load_scripts_styles_forms(); |
|
347 | + $this->load_sortable_question_script(); |
|
348 | + } |
|
349 | + |
|
350 | + |
|
351 | + /** |
|
352 | + * @return void |
|
353 | + */ |
|
354 | + public function load_scripts_styles_edit_question_group() |
|
355 | + { |
|
356 | + $this->load_scripts_styles_forms(); |
|
357 | + $this->load_sortable_question_script(); |
|
358 | + } |
|
359 | + |
|
360 | + |
|
361 | + /** |
|
362 | + * registers and enqueues script for questions |
|
363 | + * |
|
364 | + * @return void |
|
365 | + */ |
|
366 | + public function load_sortable_question_script() |
|
367 | + { |
|
368 | + wp_register_script( |
|
369 | + 'ee-question-sortable', |
|
370 | + REGISTRATION_FORM_CAF_ASSETS_URL . 'ee_question_order.js', |
|
371 | + array('jquery-ui-sortable'), |
|
372 | + EVENT_ESPRESSO_VERSION, |
|
373 | + true |
|
374 | + ); |
|
375 | + wp_enqueue_script('ee-question-sortable'); |
|
376 | + } |
|
377 | + |
|
378 | + |
|
379 | + /** |
|
380 | + * @return void |
|
381 | + */ |
|
382 | + protected function _set_list_table_views_default() |
|
383 | + { |
|
384 | + $this->_views = array( |
|
385 | + 'all' => array( |
|
386 | + 'slug' => 'all', |
|
387 | + 'label' => esc_html__('View All Questions', 'event_espresso'), |
|
388 | + 'count' => 0, |
|
389 | + 'bulk_action' => array( |
|
390 | + 'trash_questions' => esc_html__('Trash', 'event_espresso'), |
|
391 | + ), |
|
392 | + ), |
|
393 | + ); |
|
394 | + |
|
395 | + if ( |
|
396 | + EE_Registry::instance()->CAP->current_user_can( |
|
397 | + 'ee_delete_questions', |
|
398 | + 'espresso_registration_form_trash_questions' |
|
399 | + ) |
|
400 | + ) { |
|
401 | + $this->_views['trash'] = array( |
|
402 | + 'slug' => 'trash', |
|
403 | + 'label' => esc_html__('Trash', 'event_espresso'), |
|
404 | + 'count' => 0, |
|
405 | + 'bulk_action' => array( |
|
406 | + 'delete_questions' => esc_html__('Delete Permanently', 'event_espresso'), |
|
407 | + 'restore_questions' => esc_html__('Restore', 'event_espresso'), |
|
408 | + ), |
|
409 | + ); |
|
410 | + } |
|
411 | + } |
|
412 | + |
|
413 | + |
|
414 | + /** |
|
415 | + * @return void |
|
416 | + */ |
|
417 | + protected function _set_list_table_views_question_groups() |
|
418 | + { |
|
419 | + $this->_views = array( |
|
420 | + 'all' => array( |
|
421 | + 'slug' => 'all', |
|
422 | + 'label' => esc_html__('All', 'event_espresso'), |
|
423 | + 'count' => 0, |
|
424 | + 'bulk_action' => array( |
|
425 | + 'trash_question_groups' => esc_html__('Trash', 'event_espresso'), |
|
426 | + ), |
|
427 | + ), |
|
428 | + ); |
|
429 | + |
|
430 | + if ( |
|
431 | + EE_Registry::instance()->CAP->current_user_can( |
|
432 | + 'ee_delete_question_groups', |
|
433 | + 'espresso_registration_form_trash_question_groups' |
|
434 | + ) |
|
435 | + ) { |
|
436 | + $this->_views['trash'] = array( |
|
437 | + 'slug' => 'trash', |
|
438 | + 'label' => esc_html__('Trash', 'event_espresso'), |
|
439 | + 'count' => 0, |
|
440 | + 'bulk_action' => array( |
|
441 | + 'delete_question_groups' => esc_html__('Delete Permanently', 'event_espresso'), |
|
442 | + 'restore_question_groups' => esc_html__('Restore', 'event_espresso'), |
|
443 | + ), |
|
444 | + ); |
|
445 | + } |
|
446 | + } |
|
447 | + |
|
448 | + |
|
449 | + /** |
|
450 | + * @return void |
|
451 | + * @throws EE_Error |
|
452 | + * @throws InvalidArgumentException |
|
453 | + * @throws InvalidDataTypeException |
|
454 | + * @throws InvalidInterfaceException |
|
455 | + */ |
|
456 | + protected function _questions_overview_list_table() |
|
457 | + { |
|
458 | + $this->_admin_page_title .= ' ' . $this->get_action_link_or_button( |
|
459 | + 'add_question', |
|
460 | + 'add_question', |
|
461 | + array(), |
|
462 | + 'add-new-h2' |
|
463 | + ); |
|
464 | + parent::_questions_overview_list_table(); |
|
465 | + } |
|
466 | + |
|
467 | + |
|
468 | + /** |
|
469 | + * @return void |
|
470 | + * @throws DomainException |
|
471 | + * @throws EE_Error |
|
472 | + * @throws InvalidArgumentException |
|
473 | + * @throws InvalidDataTypeException |
|
474 | + * @throws InvalidInterfaceException |
|
475 | + */ |
|
476 | + protected function _question_groups_overview_list_table() |
|
477 | + { |
|
478 | + $this->_search_btn_label = esc_html__('Question Groups', 'event_espresso'); |
|
479 | + $this->_admin_page_title .= ' ' . $this->get_action_link_or_button( |
|
480 | + 'add_question_group', |
|
481 | + 'add_question_group', |
|
482 | + array(), |
|
483 | + 'add-new-h2' |
|
484 | + ); |
|
485 | + $this->display_admin_list_table_page_with_sidebar(); |
|
486 | + } |
|
487 | + |
|
488 | + |
|
489 | + /** |
|
490 | + * @return void |
|
491 | + * @throws EE_Error |
|
492 | + * @throws InvalidArgumentException |
|
493 | + * @throws InvalidDataTypeException |
|
494 | + * @throws InvalidInterfaceException |
|
495 | + */ |
|
496 | + protected function _delete_question() |
|
497 | + { |
|
498 | + $success = $this->_delete_items($this->_question_model); |
|
499 | + $this->_redirect_after_action( |
|
500 | + $success, |
|
501 | + $this->_question_model->item_name($success), |
|
502 | + 'deleted', |
|
503 | + array('action' => 'default', 'status' => 'all') |
|
504 | + ); |
|
505 | + } |
|
506 | + |
|
507 | + |
|
508 | + /** |
|
509 | + * @return void |
|
510 | + * @throws EE_Error |
|
511 | + * @throws InvalidArgumentException |
|
512 | + * @throws InvalidDataTypeException |
|
513 | + * @throws InvalidInterfaceException |
|
514 | + */ |
|
515 | + protected function _delete_questions() |
|
516 | + { |
|
517 | + $success = $this->_delete_items($this->_question_model); |
|
518 | + $this->_redirect_after_action( |
|
519 | + $success, |
|
520 | + $this->_question_model->item_name($success), |
|
521 | + 'deleted permanently', |
|
522 | + array('action' => 'default', 'status' => 'trash') |
|
523 | + ); |
|
524 | + } |
|
525 | + |
|
526 | + |
|
527 | + /** |
|
528 | + * Performs the deletion of a single or multiple questions or question groups. |
|
529 | + * |
|
530 | + * @param EEM_Soft_Delete_Base $model |
|
531 | + * @return int number of items deleted permanently |
|
532 | + * @throws EE_Error |
|
533 | + * @throws InvalidArgumentException |
|
534 | + * @throws InvalidDataTypeException |
|
535 | + * @throws InvalidInterfaceException |
|
536 | + */ |
|
537 | + private function _delete_items(EEM_Soft_Delete_Base $model) |
|
538 | + { |
|
539 | + $success = 0; |
|
540 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
541 | + if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) { |
|
542 | + // if array has more than one element than success message should be plural |
|
543 | + $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1; |
|
544 | + // cycle thru bulk action checkboxes |
|
545 | + while (list($ID, $value) = each($this->_req_data['checkbox'])) { |
|
546 | + if (! $this->_delete_item($ID, $model)) { |
|
547 | + $success = 0; |
|
548 | + } |
|
549 | + } |
|
550 | + } elseif (! empty($this->_req_data['QSG_ID'])) { |
|
551 | + $success = $this->_delete_item($this->_req_data['QSG_ID'], $model); |
|
552 | + } elseif (! empty($this->_req_data['QST_ID'])) { |
|
553 | + $success = $this->_delete_item($this->_req_data['QST_ID'], $model); |
|
554 | + } else { |
|
555 | + EE_Error::add_error( |
|
556 | + sprintf( |
|
557 | + esc_html__( |
|
558 | + "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.", |
|
559 | + "event_espresso" |
|
560 | + ) |
|
561 | + ), |
|
562 | + __FILE__, |
|
563 | + __FUNCTION__, |
|
564 | + __LINE__ |
|
565 | + ); |
|
566 | + } |
|
567 | + return $success; |
|
568 | + } |
|
569 | + |
|
570 | + |
|
571 | + /** |
|
572 | + * Deletes the specified question (and its associated question options) or question group |
|
573 | + * |
|
574 | + * @param int $id |
|
575 | + * @param EEM_Soft_Delete_Base $model |
|
576 | + * @return boolean |
|
577 | + * @throws EE_Error |
|
578 | + * @throws InvalidArgumentException |
|
579 | + * @throws InvalidDataTypeException |
|
580 | + * @throws InvalidInterfaceException |
|
581 | + */ |
|
582 | + protected function _delete_item($id, $model) |
|
583 | + { |
|
584 | + if ($model instanceof EEM_Question) { |
|
585 | + EEM_Question_Option::instance()->delete_permanently(array(array('QST_ID' => absint($id)))); |
|
586 | + } |
|
587 | + return $model->delete_permanently_by_ID(absint($id)); |
|
588 | + } |
|
589 | + |
|
590 | + |
|
591 | + /****************************** QUESTION GROUPS ******************************/ |
|
592 | + |
|
593 | + |
|
594 | + /** |
|
595 | + * @param string $type |
|
596 | + * @return void |
|
597 | + * @throws DomainException |
|
598 | + * @throws EE_Error |
|
599 | + * @throws InvalidArgumentException |
|
600 | + * @throws InvalidDataTypeException |
|
601 | + * @throws InvalidInterfaceException |
|
602 | + */ |
|
603 | + protected function _edit_question_group($type = 'add') |
|
604 | + { |
|
605 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
606 | + $ID = isset($this->_req_data['QSG_ID']) && ! empty($this->_req_data['QSG_ID']) |
|
607 | + ? absint($this->_req_data['QSG_ID']) |
|
608 | + : false; |
|
609 | + |
|
610 | + switch ($this->_req_action) { |
|
611 | + case 'add_question_group': |
|
612 | + $this->_admin_page_title = esc_html__('Add Question Group', 'event_espresso'); |
|
613 | + break; |
|
614 | + case 'edit_question_group': |
|
615 | + $this->_admin_page_title = esc_html__('Edit Question Group', 'event_espresso'); |
|
616 | + break; |
|
617 | + default: |
|
618 | + $this->_admin_page_title = ucwords(str_replace('_', ' ', $this->_req_action)); |
|
619 | + } |
|
620 | + // add ID to title if editing |
|
621 | + $this->_admin_page_title = $ID ? $this->_admin_page_title . ' # ' . $ID : $this->_admin_page_title; |
|
622 | + if ($ID) { |
|
623 | + /** @var EE_Question_Group $questionGroup */ |
|
624 | + $questionGroup = $this->_question_group_model->get_one_by_ID($ID); |
|
625 | + $additional_hidden_fields = array('QSG_ID' => array('type' => 'hidden', 'value' => $ID)); |
|
626 | + $this->_set_add_edit_form_tags('update_question_group', $additional_hidden_fields); |
|
627 | + } else { |
|
628 | + /** @var EE_Question_Group $questionGroup */ |
|
629 | + $questionGroup = EEM_Question_Group::instance()->create_default_object(); |
|
630 | + $questionGroup->set_order_to_latest(); |
|
631 | + $this->_set_add_edit_form_tags('insert_question_group'); |
|
632 | + } |
|
633 | + $this->_template_args['values'] = $this->_yes_no_values; |
|
634 | + $this->_template_args['all_questions'] = $questionGroup->questions_in_and_not_in_group(); |
|
635 | + $this->_template_args['QSG_ID'] = $ID ? $ID : true; |
|
636 | + $this->_template_args['question_group'] = $questionGroup; |
|
637 | + |
|
638 | + $redirect_URL = add_query_arg(array('action' => 'question_groups'), $this->_admin_base_url); |
|
639 | + $this->_set_publish_post_box_vars('id', $ID, false, $redirect_URL); |
|
640 | + $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
641 | + REGISTRATION_FORM_CAF_TEMPLATE_PATH . 'question_groups_main_meta_box.template.php', |
|
642 | + $this->_template_args, |
|
643 | + true |
|
644 | + ); |
|
645 | + |
|
646 | + // the details template wrapper |
|
647 | + $this->display_admin_page_with_sidebar(); |
|
648 | + } |
|
649 | + |
|
650 | + |
|
651 | + /** |
|
652 | + * @return void |
|
653 | + * @throws EE_Error |
|
654 | + * @throws InvalidArgumentException |
|
655 | + * @throws InvalidDataTypeException |
|
656 | + * @throws InvalidInterfaceException |
|
657 | + */ |
|
658 | + protected function _delete_question_groups() |
|
659 | + { |
|
660 | + $success = $this->_delete_items($this->_question_group_model); |
|
661 | + $this->_redirect_after_action( |
|
662 | + $success, |
|
663 | + $this->_question_group_model->item_name($success), |
|
664 | + 'deleted permanently', |
|
665 | + array('action' => 'question_groups', 'status' => 'trash') |
|
666 | + ); |
|
667 | + } |
|
668 | + |
|
669 | + |
|
670 | + /** |
|
671 | + * @param bool $new_question_group |
|
672 | + * @throws EE_Error |
|
673 | + * @throws InvalidArgumentException |
|
674 | + * @throws InvalidDataTypeException |
|
675 | + * @throws InvalidInterfaceException |
|
676 | + */ |
|
677 | + protected function _insert_or_update_question_group($new_question_group = true) |
|
678 | + { |
|
679 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
680 | + $set_column_values = $this->_set_column_values_for($this->_question_group_model); |
|
681 | + if ($new_question_group) { |
|
682 | + // make sure identifier is unique |
|
683 | + $identifier_value = isset($set_column_values['QSG_identifier']) ? $set_column_values['QSG_identifier'] : ''; |
|
684 | + $identifier_exists = ! empty($identifier_value) |
|
685 | + ? $this->_question_group_model->count([['QSG_identifier' => $set_column_values['QSG_identifier']]]) > 0 |
|
686 | + : false; |
|
687 | + if ($identifier_exists) { |
|
688 | + $set_column_values['QSG_identifier'] .= uniqid('id', true); |
|
689 | + } |
|
690 | + $QSG_ID = $this->_question_group_model->insert($set_column_values); |
|
691 | + $success = $QSG_ID ? 1 : 0; |
|
692 | + if ($success === 0) { |
|
693 | + EE_Error::add_error( |
|
694 | + esc_html__('Something went wrong saving the question group.', 'event_espresso'), |
|
695 | + __FILE__, |
|
696 | + __FUNCTION__, |
|
697 | + __LINE__ |
|
698 | + ); |
|
699 | + $this->_redirect_after_action( |
|
700 | + false, |
|
701 | + '', |
|
702 | + '', |
|
703 | + array('action' => 'edit_question_group', 'QSG_ID' => $QSG_ID), |
|
704 | + true |
|
705 | + ); |
|
706 | + } |
|
707 | + } else { |
|
708 | + $QSG_ID = absint($this->_req_data['QSG_ID']); |
|
709 | + unset($set_column_values['QSG_ID']); |
|
710 | + $success = $this->_question_group_model->update($set_column_values, array(array('QSG_ID' => $QSG_ID))); |
|
711 | + } |
|
712 | + |
|
713 | + $phone_question_id = EEM_Question::instance()->get_Question_ID_from_system_string( |
|
714 | + EEM_Attendee::system_question_phone |
|
715 | + ); |
|
716 | + // update the existing related questions |
|
717 | + // BUT FIRST... delete the phone question from the Question_Group_Question |
|
718 | + // if it is being added to this question group (therefore removed from the existing group) |
|
719 | + if (isset($this->_req_data['questions'], $this->_req_data['questions'][ $phone_question_id ])) { |
|
720 | + // delete where QST ID = system phone question ID and Question Group ID is NOT this group |
|
721 | + EEM_Question_Group_Question::instance()->delete( |
|
722 | + array( |
|
723 | + array( |
|
724 | + 'QST_ID' => $phone_question_id, |
|
725 | + 'QSG_ID' => array('!=', $QSG_ID), |
|
726 | + ), |
|
727 | + ) |
|
728 | + ); |
|
729 | + } |
|
730 | + /** @type EE_Question_Group $question_group */ |
|
731 | + $question_group = $this->_question_group_model->get_one_by_ID($QSG_ID); |
|
732 | + $questions = $question_group->questions(); |
|
733 | + // make sure system phone question is added to list of questions for this group |
|
734 | + if (! isset($questions[ $phone_question_id ])) { |
|
735 | + $questions[ $phone_question_id ] = EEM_Question::instance()->get_one_by_ID($phone_question_id); |
|
736 | + } |
|
737 | + |
|
738 | + foreach ($questions as $question_ID => $question) { |
|
739 | + // first we always check for order. |
|
740 | + if (! empty($this->_req_data['question_orders'][ $question_ID ])) { |
|
741 | + // update question order |
|
742 | + $question_group->update_question_order( |
|
743 | + $question_ID, |
|
744 | + $this->_req_data['question_orders'][ $question_ID ] |
|
745 | + ); |
|
746 | + } |
|
747 | + |
|
748 | + // then we always check if adding or removing. |
|
749 | + if (isset($this->_req_data['questions'], $this->_req_data['questions'][ $question_ID ])) { |
|
750 | + $question_group->add_question($question_ID); |
|
751 | + } else { |
|
752 | + // not found, remove it (but only if not a system question for the personal group |
|
753 | + // with the exception of lname system question - we allow removal of it) |
|
754 | + if ( |
|
755 | + in_array( |
|
756 | + $question->system_ID(), |
|
757 | + EEM_Question::instance()->required_system_questions_in_system_question_group( |
|
758 | + $question_group->system_group() |
|
759 | + ) |
|
760 | + ) |
|
761 | + ) { |
|
762 | + continue; |
|
763 | + } else { |
|
764 | + $question_group->remove_question($question_ID); |
|
765 | + } |
|
766 | + } |
|
767 | + } |
|
768 | + // save new related questions |
|
769 | + if (isset($this->_req_data['questions'])) { |
|
770 | + foreach ($this->_req_data['questions'] as $QST_ID) { |
|
771 | + $question_group->add_question($QST_ID); |
|
772 | + if (isset($this->_req_data['question_orders'][ $QST_ID ])) { |
|
773 | + $question_group->update_question_order($QST_ID, $this->_req_data['question_orders'][ $QST_ID ]); |
|
774 | + } |
|
775 | + } |
|
776 | + } |
|
777 | + |
|
778 | + if ($success !== false) { |
|
779 | + $msg = $new_question_group |
|
780 | + ? sprintf( |
|
781 | + esc_html__('The %s has been created', 'event_espresso'), |
|
782 | + $this->_question_group_model->item_name() |
|
783 | + ) |
|
784 | + : sprintf( |
|
785 | + esc_html__( |
|
786 | + 'The %s has been updated', |
|
787 | + 'event_espresso' |
|
788 | + ), |
|
789 | + $this->_question_group_model->item_name() |
|
790 | + ); |
|
791 | + EE_Error::add_success($msg); |
|
792 | + } |
|
793 | + $this->_redirect_after_action( |
|
794 | + false, |
|
795 | + '', |
|
796 | + '', |
|
797 | + array('action' => 'edit_question_group', 'QSG_ID' => $QSG_ID), |
|
798 | + true |
|
799 | + ); |
|
800 | + } |
|
801 | + |
|
802 | + |
|
803 | + /** |
|
804 | + * duplicates a question and all its question options and redirects to the new question. |
|
805 | + * |
|
806 | + * @return void |
|
807 | + * @throws EE_Error |
|
808 | + * @throws InvalidArgumentException |
|
809 | + * @throws ReflectionException |
|
810 | + * @throws InvalidDataTypeException |
|
811 | + * @throws InvalidInterfaceException |
|
812 | + */ |
|
813 | + public function _duplicate_question() |
|
814 | + { |
|
815 | + $question_ID = (int) $this->_req_data['QST_ID']; |
|
816 | + $question = EEM_Question::instance()->get_one_by_ID($question_ID); |
|
817 | + if ($question instanceof EE_Question) { |
|
818 | + $new_question = $question->duplicate(); |
|
819 | + if ($new_question instanceof EE_Question) { |
|
820 | + $this->_redirect_after_action( |
|
821 | + true, |
|
822 | + esc_html__('Question', 'event_espresso'), |
|
823 | + esc_html__('Duplicated', 'event_espresso'), |
|
824 | + array('action' => 'edit_question', 'QST_ID' => $new_question->ID()), |
|
825 | + true |
|
826 | + ); |
|
827 | + } else { |
|
828 | + global $wpdb; |
|
829 | + EE_Error::add_error( |
|
830 | + sprintf( |
|
831 | + esc_html__( |
|
832 | + 'Could not duplicate question with ID %1$d because: %2$s', |
|
833 | + 'event_espresso' |
|
834 | + ), |
|
835 | + $question_ID, |
|
836 | + $wpdb->last_error |
|
837 | + ), |
|
838 | + __FILE__, |
|
839 | + __FUNCTION__, |
|
840 | + __LINE__ |
|
841 | + ); |
|
842 | + $this->_redirect_after_action(false, '', '', array('action' => 'default'), false); |
|
843 | + } |
|
844 | + } else { |
|
845 | + EE_Error::add_error( |
|
846 | + sprintf( |
|
847 | + esc_html__( |
|
848 | + 'Could not duplicate question with ID %d because it didn\'t exist!', |
|
849 | + 'event_espresso' |
|
850 | + ), |
|
851 | + $question_ID |
|
852 | + ), |
|
853 | + __FILE__, |
|
854 | + __FUNCTION__, |
|
855 | + __LINE__ |
|
856 | + ); |
|
857 | + $this->_redirect_after_action(false, '', '', array('action' => 'default'), false); |
|
858 | + } |
|
859 | + } |
|
860 | + |
|
861 | + |
|
862 | + /** |
|
863 | + * @param bool $trash |
|
864 | + * @throws EE_Error |
|
865 | + */ |
|
866 | + protected function _trash_or_restore_question_groups($trash = true) |
|
867 | + { |
|
868 | + $this->_trash_or_restore_items($this->_question_group_model, $trash); |
|
869 | + } |
|
870 | + |
|
871 | + |
|
872 | + /** |
|
873 | + *_trash_question |
|
874 | + * |
|
875 | + * @return void |
|
876 | + * @throws EE_Error |
|
877 | + */ |
|
878 | + protected function _trash_question() |
|
879 | + { |
|
880 | + $success = $this->_question_model->delete_by_ID((int) $this->_req_data['QST_ID']); |
|
881 | + $query_args = array('action' => 'default', 'status' => 'all'); |
|
882 | + $this->_redirect_after_action($success, $this->_question_model->item_name($success), 'trashed', $query_args); |
|
883 | + } |
|
884 | + |
|
885 | + |
|
886 | + /** |
|
887 | + * @param bool $trash |
|
888 | + * @throws EE_Error |
|
889 | + */ |
|
890 | + protected function _trash_or_restore_questions($trash = true) |
|
891 | + { |
|
892 | + $this->_trash_or_restore_items($this->_question_model, $trash); |
|
893 | + } |
|
894 | + |
|
895 | + |
|
896 | + /** |
|
897 | + * Internally used to delete or restore items, using the request data. Meant to be |
|
898 | + * flexible between question or question groups |
|
899 | + * |
|
900 | + * @param EEM_Soft_Delete_Base $model |
|
901 | + * @param boolean $trash whether to trash or restore |
|
902 | + * @throws EE_Error |
|
903 | + */ |
|
904 | + private function _trash_or_restore_items(EEM_Soft_Delete_Base $model, $trash = true) |
|
905 | + { |
|
906 | + |
|
907 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
908 | + |
|
909 | + $success = 1; |
|
910 | + // Checkboxes |
|
911 | + // echo "trash $trash"; |
|
912 | + // var_dump($this->_req_data['checkbox']);die; |
|
913 | + if (isset($this->_req_data['checkbox'])) { |
|
914 | + if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) { |
|
915 | + // if array has more than one element than success message should be plural |
|
916 | + $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1; |
|
917 | + // cycle thru bulk action checkboxes |
|
918 | + while (list($ID, $value) = each($this->_req_data['checkbox'])) { |
|
919 | + if (! $model->delete_or_restore_by_ID($trash, absint($ID))) { |
|
920 | + $success = 0; |
|
921 | + } |
|
922 | + } |
|
923 | + } else { |
|
924 | + // grab single id and delete |
|
925 | + $ID = absint($this->_req_data['checkbox']); |
|
926 | + if (! $model->delete_or_restore_by_ID($trash, $ID)) { |
|
927 | + $success = 0; |
|
928 | + } |
|
929 | + } |
|
930 | + } else { |
|
931 | + // delete via trash link |
|
932 | + // grab single id and delete |
|
933 | + $ID = absint($this->_req_data[ $model->primary_key_name() ]); |
|
934 | + if (! $model->delete_or_restore_by_ID($trash, $ID)) { |
|
935 | + $success = 0; |
|
936 | + } |
|
937 | + } |
|
938 | + |
|
939 | + |
|
940 | + $action = $model instanceof EEM_Question ? 'default' : 'question_groups';// strtolower( $model->item_name(2) ); |
|
941 | + // echo "action :$action"; |
|
942 | + // $action = 'questions' ? 'default' : $action; |
|
943 | + if ($trash) { |
|
944 | + $action_desc = 'trashed'; |
|
945 | + $status = 'trash'; |
|
946 | + } else { |
|
947 | + $action_desc = 'restored'; |
|
948 | + $status = 'all'; |
|
949 | + } |
|
950 | + $this->_redirect_after_action( |
|
951 | + $success, |
|
952 | + $model->item_name($success), |
|
953 | + $action_desc, |
|
954 | + array('action' => $action, 'status' => $status) |
|
955 | + ); |
|
956 | + } |
|
957 | + |
|
958 | + |
|
959 | + /** |
|
960 | + * @param $per_page |
|
961 | + * @param int $current_page |
|
962 | + * @param bool|false $count |
|
963 | + * @return EE_Soft_Delete_Base_Class[]|int |
|
964 | + * @throws EE_Error |
|
965 | + * @throws InvalidArgumentException |
|
966 | + * @throws InvalidDataTypeException |
|
967 | + * @throws InvalidInterfaceException |
|
968 | + */ |
|
969 | + public function get_trashed_questions($per_page, $current_page = 1, $count = false) |
|
970 | + { |
|
971 | + $query_params = $this->get_query_params(EEM_Question::instance(), $per_page, $current_page); |
|
972 | + |
|
973 | + if ($count) { |
|
974 | + // note: this a subclass of EEM_Soft_Delete_Base, so this is actually only getting non-trashed items |
|
975 | + $where = isset($query_params[0]) ? array($query_params[0]) : array(); |
|
976 | + $results = $this->_question_model->count_deleted($where); |
|
977 | + } else { |
|
978 | + // note: this a subclass of EEM_Soft_Delete_Base, so this is actually only getting non-trashed items |
|
979 | + $results = $this->_question_model->get_all_deleted($query_params); |
|
980 | + } |
|
981 | + return $results; |
|
982 | + } |
|
983 | + |
|
984 | + |
|
985 | + /** |
|
986 | + * @param $per_page |
|
987 | + * @param int $current_page |
|
988 | + * @param bool|false $count |
|
989 | + * @return EE_Soft_Delete_Base_Class[]|int |
|
990 | + * @throws EE_Error |
|
991 | + * @throws InvalidArgumentException |
|
992 | + * @throws InvalidDataTypeException |
|
993 | + * @throws InvalidInterfaceException |
|
994 | + */ |
|
995 | + public function get_question_groups($per_page, $current_page = 1, $count = false) |
|
996 | + { |
|
997 | + $questionGroupModel = EEM_Question_Group::instance(); |
|
998 | + $query_params = $this->get_query_params($questionGroupModel, $per_page, $current_page); |
|
999 | + if ($count) { |
|
1000 | + $where = isset($query_params[0]) ? array($query_params[0]) : array(); |
|
1001 | + $results = $questionGroupModel->count($where); |
|
1002 | + } else { |
|
1003 | + $results = $questionGroupModel->get_all($query_params); |
|
1004 | + } |
|
1005 | + return $results; |
|
1006 | + } |
|
1007 | + |
|
1008 | + |
|
1009 | + /** |
|
1010 | + * @param $per_page |
|
1011 | + * @param int $current_page |
|
1012 | + * @param bool $count |
|
1013 | + * @return EE_Soft_Delete_Base_Class[]|int |
|
1014 | + * @throws EE_Error |
|
1015 | + * @throws InvalidArgumentException |
|
1016 | + * @throws InvalidDataTypeException |
|
1017 | + * @throws InvalidInterfaceException |
|
1018 | + */ |
|
1019 | + public function get_trashed_question_groups($per_page, $current_page = 1, $count = false) |
|
1020 | + { |
|
1021 | + $questionGroupModel = EEM_Question_Group::instance(); |
|
1022 | + $query_params = $this->get_query_params($questionGroupModel, $per_page, $current_page); |
|
1023 | + if ($count) { |
|
1024 | + $where = isset($query_params[0]) ? array($query_params[0]) : array(); |
|
1025 | + $query_params['limit'] = null; |
|
1026 | + $results = $questionGroupModel->count_deleted($where); |
|
1027 | + } else { |
|
1028 | + $results = $questionGroupModel->get_all_deleted($query_params); |
|
1029 | + } |
|
1030 | + return $results; |
|
1031 | + } |
|
1032 | + |
|
1033 | + |
|
1034 | + /** |
|
1035 | + * method for performing updates to question order |
|
1036 | + * |
|
1037 | + * @return void results array |
|
1038 | + * @throws EE_Error |
|
1039 | + * @throws InvalidArgumentException |
|
1040 | + * @throws InvalidDataTypeException |
|
1041 | + * @throws InvalidInterfaceException |
|
1042 | + */ |
|
1043 | + public function update_question_group_order() |
|
1044 | + { |
|
1045 | + |
|
1046 | + $success = esc_html__('Question group order was updated successfully.', 'event_espresso'); |
|
1047 | + |
|
1048 | + // grab our row IDs |
|
1049 | + $row_ids = isset($this->_req_data['row_ids']) && ! empty($this->_req_data['row_ids']) |
|
1050 | + ? explode(',', rtrim($this->_req_data['row_ids'], ',')) |
|
1051 | + : array(); |
|
1052 | + |
|
1053 | + $perpage = ! empty($this->_req_data['perpage']) |
|
1054 | + ? (int) $this->_req_data['perpage'] |
|
1055 | + : null; |
|
1056 | + $curpage = ! empty($this->_req_data['curpage']) |
|
1057 | + ? (int) $this->_req_data['curpage'] |
|
1058 | + : null; |
|
1059 | + |
|
1060 | + if (! empty($row_ids)) { |
|
1061 | + // figure out where we start the row_id count at for the current page. |
|
1062 | + $qsgcount = empty($curpage) ? 0 : ($curpage - 1) * $perpage; |
|
1063 | + |
|
1064 | + $row_count = count($row_ids); |
|
1065 | + for ($i = 0; $i < $row_count; $i++) { |
|
1066 | + // Update the questions when re-ordering |
|
1067 | + $updated = EEM_Question_Group::instance()->update( |
|
1068 | + array('QSG_order' => $qsgcount), |
|
1069 | + array(array('QSG_ID' => $row_ids[ $i ])) |
|
1070 | + ); |
|
1071 | + if ($updated === false) { |
|
1072 | + $success = false; |
|
1073 | + } |
|
1074 | + $qsgcount++; |
|
1075 | + } |
|
1076 | + } else { |
|
1077 | + $success = false; |
|
1078 | + } |
|
1079 | + |
|
1080 | + $errors = ! $success |
|
1081 | + ? esc_html__('An error occurred. The question group order was not updated.', 'event_espresso') |
|
1082 | + : false; |
|
1083 | + |
|
1084 | + echo wp_json_encode(array('return_data' => false, 'success' => $success, 'errors' => $errors)); |
|
1085 | + die(); |
|
1086 | + } |
|
1087 | + |
|
1088 | + |
|
1089 | + |
|
1090 | + /*************************************** REGISTRATION SETTINGS ***************************************/ |
|
1091 | + |
|
1092 | + |
|
1093 | + /** |
|
1094 | + * @throws DomainException |
|
1095 | + * @throws EE_Error |
|
1096 | + * @throws InvalidArgumentException |
|
1097 | + * @throws InvalidDataTypeException |
|
1098 | + * @throws InvalidInterfaceException |
|
1099 | + */ |
|
1100 | + protected function _reg_form_settings() |
|
1101 | + { |
|
1102 | + $this->_template_args['values'] = $this->_yes_no_values; |
|
1103 | + add_action( |
|
1104 | + 'AHEE__Extend_Registration_Form_Admin_Page___reg_form_settings_template', |
|
1105 | + array($this, 'email_validation_settings_form'), |
|
1106 | + 2 |
|
1107 | + ); |
|
1108 | + add_action( |
|
1109 | + 'AHEE__Extend_Registration_Form_Admin_Page___reg_form_settings_template', |
|
1110 | + array($this, 'copy_attendee_info_settings_form'), |
|
1111 | + 4 |
|
1112 | + ); |
|
1113 | + $this->_template_args = (array) apply_filters( |
|
1114 | + 'FHEE__Extend_Registration_Form_Admin_Page___reg_form_settings___template_args', |
|
1115 | + $this->_template_args |
|
1116 | + ); |
|
1117 | + $this->_set_add_edit_form_tags('update_reg_form_settings'); |
|
1118 | + $this->_set_publish_post_box_vars(null, false, false, null, false); |
|
1119 | + $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
1120 | + REGISTRATION_FORM_CAF_TEMPLATE_PATH . 'reg_form_settings.template.php', |
|
1121 | + $this->_template_args, |
|
1122 | + true |
|
1123 | + ); |
|
1124 | + $this->display_admin_page_with_sidebar(); |
|
1125 | + } |
|
1126 | + |
|
1127 | + |
|
1128 | + /** |
|
1129 | + * @return void |
|
1130 | + * @throws EE_Error |
|
1131 | + * @throws InvalidArgumentException |
|
1132 | + * @throws ReflectionException |
|
1133 | + * @throws InvalidDataTypeException |
|
1134 | + * @throws InvalidInterfaceException |
|
1135 | + */ |
|
1136 | + protected function _update_reg_form_settings() |
|
1137 | + { |
|
1138 | + EE_Registry::instance()->CFG->registration = $this->update_email_validation_settings_form( |
|
1139 | + EE_Registry::instance()->CFG->registration |
|
1140 | + ); |
|
1141 | + EE_Registry::instance()->CFG->registration = $this->update_copy_attendee_info_settings_form( |
|
1142 | + EE_Registry::instance()->CFG->registration |
|
1143 | + ); |
|
1144 | + EE_Registry::instance()->CFG->registration = apply_filters( |
|
1145 | + 'FHEE__Extend_Registration_Form_Admin_Page___update_reg_form_settings__CFG_registration', |
|
1146 | + EE_Registry::instance()->CFG->registration |
|
1147 | + ); |
|
1148 | + $success = $this->_update_espresso_configuration( |
|
1149 | + esc_html__('Registration Form Options', 'event_espresso'), |
|
1150 | + EE_Registry::instance()->CFG, |
|
1151 | + __FILE__, |
|
1152 | + __FUNCTION__, |
|
1153 | + __LINE__ |
|
1154 | + ); |
|
1155 | + $this->_redirect_after_action( |
|
1156 | + $success, |
|
1157 | + esc_html__('Registration Form Options', 'event_espresso'), |
|
1158 | + 'updated', |
|
1159 | + array('action' => 'view_reg_form_settings') |
|
1160 | + ); |
|
1161 | + } |
|
1162 | + |
|
1163 | + |
|
1164 | + /** |
|
1165 | + * @return void |
|
1166 | + * @throws EE_Error |
|
1167 | + * @throws InvalidArgumentException |
|
1168 | + * @throws InvalidDataTypeException |
|
1169 | + * @throws InvalidInterfaceException |
|
1170 | + */ |
|
1171 | + public function copy_attendee_info_settings_form() |
|
1172 | + { |
|
1173 | + echo $this->_copy_attendee_info_settings_form()->get_html(); |
|
1174 | + } |
|
1175 | + |
|
1176 | + /** |
|
1177 | + * _copy_attendee_info_settings_form |
|
1178 | + * |
|
1179 | + * @access protected |
|
1180 | + * @return EE_Form_Section_Proper |
|
1181 | + * @throws \EE_Error |
|
1182 | + */ |
|
1183 | + protected function _copy_attendee_info_settings_form() |
|
1184 | + { |
|
1185 | + return new EE_Form_Section_Proper( |
|
1186 | + array( |
|
1187 | + 'name' => 'copy_attendee_info_settings', |
|
1188 | + 'html_id' => 'copy_attendee_info_settings', |
|
1189 | + 'layout_strategy' => new EE_Admin_Two_Column_Layout(), |
|
1190 | + 'subsections' => apply_filters( |
|
1191 | + 'FHEE__Extend_Registration_Form_Admin_Page___copy_attendee_info_settings_form__form_subsections', |
|
1192 | + array( |
|
1193 | + 'copy_attendee_info_hdr' => new EE_Form_Section_HTML( |
|
1194 | + EEH_HTML::h2(esc_html__('Copy Attendee Info Settings', 'event_espresso')) |
|
1195 | + ), |
|
1196 | + 'copy_attendee_info' => new EE_Yes_No_Input( |
|
1197 | + array( |
|
1198 | + 'html_label_text' => esc_html__( |
|
1199 | + 'Allow copy #1 attendee info to extra attendees?', |
|
1200 | + 'event_espresso' |
|
1201 | + ), |
|
1202 | + 'html_help_text' => esc_html__( |
|
1203 | + 'Set to yes if you want to enable the copy of #1 attendee info to extra attendees at Registration Form.', |
|
1204 | + 'event_espresso' |
|
1205 | + ), |
|
1206 | + 'default' => EE_Registry::instance()->CFG->registration->copyAttendeeInfo(), |
|
1207 | + 'required' => false, |
|
1208 | + 'display_html_label_text' => false, |
|
1209 | + ) |
|
1210 | + ), |
|
1211 | + ) |
|
1212 | + ), |
|
1213 | + ) |
|
1214 | + ); |
|
1215 | + } |
|
1216 | + |
|
1217 | + /** |
|
1218 | + * @param EE_Registration_Config $EE_Registration_Config |
|
1219 | + * @return EE_Registration_Config |
|
1220 | + * @throws EE_Error |
|
1221 | + * @throws InvalidArgumentException |
|
1222 | + * @throws ReflectionException |
|
1223 | + * @throws InvalidDataTypeException |
|
1224 | + * @throws InvalidInterfaceException |
|
1225 | + */ |
|
1226 | + public function update_copy_attendee_info_settings_form(EE_Registration_Config $EE_Registration_Config) |
|
1227 | + { |
|
1228 | + $prev_copy_attendee_info = $EE_Registration_Config->copyAttendeeInfo(); |
|
1229 | + try { |
|
1230 | + $copy_attendee_info_settings_form = $this->_copy_attendee_info_settings_form(); |
|
1231 | + // if not displaying a form, then check for form submission |
|
1232 | + if ($copy_attendee_info_settings_form->was_submitted()) { |
|
1233 | + // capture form data |
|
1234 | + $copy_attendee_info_settings_form->receive_form_submission(); |
|
1235 | + // validate form data |
|
1236 | + if ($copy_attendee_info_settings_form->is_valid()) { |
|
1237 | + // grab validated data from form |
|
1238 | + $valid_data = $copy_attendee_info_settings_form->valid_data(); |
|
1239 | + if (isset($valid_data['copy_attendee_info'])) { |
|
1240 | + $EE_Registration_Config->setCopyAttendeeInfo($valid_data['copy_attendee_info']); |
|
1241 | + } else { |
|
1242 | + EE_Error::add_error( |
|
1243 | + esc_html__( |
|
1244 | + 'Invalid or missing Copy Attendee Info settings. Please refresh the form and try again.', |
|
1245 | + 'event_espresso' |
|
1246 | + ), |
|
1247 | + __FILE__, |
|
1248 | + __FUNCTION__, |
|
1249 | + __LINE__ |
|
1250 | + ); |
|
1251 | + } |
|
1252 | + } else { |
|
1253 | + if ($copy_attendee_info_settings_form->submission_error_message() !== '') { |
|
1254 | + EE_Error::add_error( |
|
1255 | + $copy_attendee_info_settings_form->submission_error_message(), |
|
1256 | + __FILE__, |
|
1257 | + __FUNCTION__, |
|
1258 | + __LINE__ |
|
1259 | + ); |
|
1260 | + } |
|
1261 | + } |
|
1262 | + } |
|
1263 | + } catch (EE_Error $e) { |
|
1264 | + $e->get_error(); |
|
1265 | + } |
|
1266 | + return $EE_Registration_Config; |
|
1267 | + } |
|
1268 | + |
|
1269 | + |
|
1270 | + /** |
|
1271 | + * @return void |
|
1272 | + * @throws EE_Error |
|
1273 | + * @throws InvalidArgumentException |
|
1274 | + * @throws InvalidDataTypeException |
|
1275 | + * @throws InvalidInterfaceException |
|
1276 | + */ |
|
1277 | + public function email_validation_settings_form() |
|
1278 | + { |
|
1279 | + echo $this->_email_validation_settings_form()->get_html(); |
|
1280 | + } |
|
1281 | + |
|
1282 | + |
|
1283 | + /** |
|
1284 | + * _email_validation_settings_form |
|
1285 | + * |
|
1286 | + * @access protected |
|
1287 | + * @return EE_Form_Section_Proper |
|
1288 | + * @throws \EE_Error |
|
1289 | + */ |
|
1290 | + protected function _email_validation_settings_form() |
|
1291 | + { |
|
1292 | + return new EE_Form_Section_Proper( |
|
1293 | + array( |
|
1294 | + 'name' => 'email_validation_settings', |
|
1295 | + 'html_id' => 'email_validation_settings', |
|
1296 | + 'layout_strategy' => new EE_Admin_Two_Column_Layout(), |
|
1297 | + 'subsections' => apply_filters( |
|
1298 | + 'FHEE__Extend_Registration_Form_Admin_Page___email_validation_settings_form__form_subsections', |
|
1299 | + array( |
|
1300 | + 'email_validation_hdr' => new EE_Form_Section_HTML( |
|
1301 | + EEH_HTML::h2(esc_html__('Email Validation Settings', 'event_espresso')) |
|
1302 | + ), |
|
1303 | + 'email_validation_level' => new EE_Select_Input( |
|
1304 | + array( |
|
1305 | + 'basic' => esc_html__('Basic', 'event_espresso'), |
|
1306 | + 'wp_default' => esc_html__('WordPress Default', 'event_espresso'), |
|
1307 | + 'i18n' => esc_html__('International', 'event_espresso'), |
|
1308 | + 'i18n_dns' => esc_html__('International + DNS Check', 'event_espresso'), |
|
1309 | + ), |
|
1310 | + array( |
|
1311 | + 'html_label_text' => esc_html__('Email Validation Level', 'event_espresso') |
|
1312 | + . EEH_Template::get_help_tab_link('email_validation_info'), |
|
1313 | + 'html_help_text' => esc_html__( |
|
1314 | + '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.', |
|
1315 | + 'event_espresso' |
|
1316 | + ), |
|
1317 | + 'default' => isset( |
|
1318 | + EE_Registry::instance()->CFG->registration->email_validation_level |
|
1319 | + ) |
|
1320 | + ? EE_Registry::instance()->CFG->registration->email_validation_level |
|
1321 | + : 'wp_default', |
|
1322 | + 'required' => false, |
|
1323 | + ) |
|
1324 | + ), |
|
1325 | + ) |
|
1326 | + ), |
|
1327 | + ) |
|
1328 | + ); |
|
1329 | + } |
|
1330 | + |
|
1331 | + |
|
1332 | + /** |
|
1333 | + * @param EE_Registration_Config $EE_Registration_Config |
|
1334 | + * @return EE_Registration_Config |
|
1335 | + * @throws EE_Error |
|
1336 | + * @throws InvalidArgumentException |
|
1337 | + * @throws ReflectionException |
|
1338 | + * @throws InvalidDataTypeException |
|
1339 | + * @throws InvalidInterfaceException |
|
1340 | + */ |
|
1341 | + public function update_email_validation_settings_form(EE_Registration_Config $EE_Registration_Config) |
|
1342 | + { |
|
1343 | + $prev_email_validation_level = $EE_Registration_Config->email_validation_level; |
|
1344 | + try { |
|
1345 | + $email_validation_settings_form = $this->_email_validation_settings_form(); |
|
1346 | + // if not displaying a form, then check for form submission |
|
1347 | + if ($email_validation_settings_form->was_submitted()) { |
|
1348 | + // capture form data |
|
1349 | + $email_validation_settings_form->receive_form_submission(); |
|
1350 | + // validate form data |
|
1351 | + if ($email_validation_settings_form->is_valid()) { |
|
1352 | + // grab validated data from form |
|
1353 | + $valid_data = $email_validation_settings_form->valid_data(); |
|
1354 | + if (isset($valid_data['email_validation_level'])) { |
|
1355 | + $email_validation_level = $valid_data['email_validation_level']; |
|
1356 | + // now if they want to use international email addresses |
|
1357 | + if ($email_validation_level === 'i18n' || $email_validation_level === 'i18n_dns') { |
|
1358 | + // in case we need to reset their email validation level, |
|
1359 | + // make sure that the previous value wasn't already set to one of the i18n options. |
|
1360 | + if ($prev_email_validation_level === 'i18n' || $prev_email_validation_level === 'i18n_dns') { |
|
1361 | + // if so, then reset it back to "basic" since that is the only other option that, |
|
1362 | + // despite offering poor validation, supports i18n email addresses |
|
1363 | + $prev_email_validation_level = 'basic'; |
|
1364 | + } |
|
1365 | + // confirm our i18n email validation will work on the server |
|
1366 | + if (! $this->_verify_pcre_support($EE_Registration_Config, $email_validation_level)) { |
|
1367 | + // or reset email validation level to previous value |
|
1368 | + $email_validation_level = $prev_email_validation_level; |
|
1369 | + } |
|
1370 | + } |
|
1371 | + $EE_Registration_Config->email_validation_level = $email_validation_level; |
|
1372 | + } else { |
|
1373 | + EE_Error::add_error( |
|
1374 | + esc_html__( |
|
1375 | + 'Invalid or missing Email Validation settings. Please refresh the form and try again.', |
|
1376 | + 'event_espresso' |
|
1377 | + ), |
|
1378 | + __FILE__, |
|
1379 | + __FUNCTION__, |
|
1380 | + __LINE__ |
|
1381 | + ); |
|
1382 | + } |
|
1383 | + } else { |
|
1384 | + if ($email_validation_settings_form->submission_error_message() !== '') { |
|
1385 | + EE_Error::add_error( |
|
1386 | + $email_validation_settings_form->submission_error_message(), |
|
1387 | + __FILE__, |
|
1388 | + __FUNCTION__, |
|
1389 | + __LINE__ |
|
1390 | + ); |
|
1391 | + } |
|
1392 | + } |
|
1393 | + } |
|
1394 | + } catch (EE_Error $e) { |
|
1395 | + $e->get_error(); |
|
1396 | + } |
|
1397 | + return $EE_Registration_Config; |
|
1398 | + } |
|
1399 | + |
|
1400 | + |
|
1401 | + /** |
|
1402 | + * confirms that the server's PHP version has the PCRE module enabled, |
|
1403 | + * and that the PCRE version works with our i18n email validation |
|
1404 | + * |
|
1405 | + * @param EE_Registration_Config $EE_Registration_Config |
|
1406 | + * @param string $email_validation_level |
|
1407 | + * @return bool |
|
1408 | + */ |
|
1409 | + private function _verify_pcre_support(EE_Registration_Config $EE_Registration_Config, $email_validation_level) |
|
1410 | + { |
|
1411 | + // first check that PCRE is enabled |
|
1412 | + if (! defined('PREG_BAD_UTF8_ERROR')) { |
|
1413 | + EE_Error::add_error( |
|
1414 | + sprintf( |
|
1415 | + esc_html__( |
|
1416 | + '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.', |
|
1417 | + 'event_espresso' |
|
1418 | + ), |
|
1419 | + '<br />' |
|
1420 | + ), |
|
1421 | + __FILE__, |
|
1422 | + __FUNCTION__, |
|
1423 | + __LINE__ |
|
1424 | + ); |
|
1425 | + return false; |
|
1426 | + } else { |
|
1427 | + // PCRE support is enabled, but let's still |
|
1428 | + // perform a test to see if the server will support it. |
|
1429 | + // but first, save the updated validation level to the config, |
|
1430 | + // so that the validation strategy picks it up. |
|
1431 | + // this will get bumped back down if it doesn't work |
|
1432 | + $EE_Registration_Config->email_validation_level = $email_validation_level; |
|
1433 | + try { |
|
1434 | + $email_validator = new EE_Email_Validation_Strategy(); |
|
1435 | + $i18n_email_address = apply_filters( |
|
1436 | + 'FHEE__Extend_Registration_Form_Admin_Page__update_email_validation_settings_form__i18n_email_address', |
|
1437 | + 'jägerjü[email protected]' |
|
1438 | + ); |
|
1439 | + $email_validator->validate($i18n_email_address); |
|
1440 | + } catch (Exception $e) { |
|
1441 | + EE_Error::add_error( |
|
1442 | + sprintf( |
|
1443 | + esc_html__( |
|
1444 | + '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', |
|
1445 | + 'event_espresso' |
|
1446 | + ), |
|
1447 | + '<br />', |
|
1448 | + '<a href="http://php.net/manual/en/pcre.installation.php" target="_blank" rel="noopener noreferrer">http://php.net/manual/en/pcre.installation.php</a>' |
|
1449 | + ), |
|
1450 | + __FILE__, |
|
1451 | + __FUNCTION__, |
|
1452 | + __LINE__ |
|
1453 | + ); |
|
1454 | + return false; |
|
1455 | + } |
|
1456 | + } |
|
1457 | + return true; |
|
1458 | + } |
|
1459 | 1459 | } |
@@ -6,22 +6,22 @@ discard block |
||
6 | 6 | */ |
7 | 7 | function espresso_load_error_handling() |
8 | 8 | { |
9 | - static $error_handling_loaded = false; |
|
10 | - if ($error_handling_loaded) { |
|
11 | - return; |
|
12 | - } |
|
13 | - // load debugging tools |
|
14 | - if (WP_DEBUG === true && is_readable(EE_HELPERS . 'EEH_Debug_Tools.helper.php')) { |
|
15 | - require_once EE_HELPERS . 'EEH_Debug_Tools.helper.php'; |
|
16 | - \EEH_Debug_Tools::instance(); |
|
17 | - } |
|
18 | - // load error handling |
|
19 | - if (is_readable(EE_CORE . 'EE_Error.core.php')) { |
|
20 | - require_once EE_CORE . 'EE_Error.core.php'; |
|
21 | - } else { |
|
22 | - wp_die(esc_html__('The EE_Error core class could not be loaded.', 'event_espresso')); |
|
23 | - } |
|
24 | - $error_handling_loaded = true; |
|
9 | + static $error_handling_loaded = false; |
|
10 | + if ($error_handling_loaded) { |
|
11 | + return; |
|
12 | + } |
|
13 | + // load debugging tools |
|
14 | + if (WP_DEBUG === true && is_readable(EE_HELPERS . 'EEH_Debug_Tools.helper.php')) { |
|
15 | + require_once EE_HELPERS . 'EEH_Debug_Tools.helper.php'; |
|
16 | + \EEH_Debug_Tools::instance(); |
|
17 | + } |
|
18 | + // load error handling |
|
19 | + if (is_readable(EE_CORE . 'EE_Error.core.php')) { |
|
20 | + require_once EE_CORE . 'EE_Error.core.php'; |
|
21 | + } else { |
|
22 | + wp_die(esc_html__('The EE_Error core class could not be loaded.', 'event_espresso')); |
|
23 | + } |
|
24 | + $error_handling_loaded = true; |
|
25 | 25 | } |
26 | 26 | |
27 | 27 | |
@@ -35,19 +35,19 @@ discard block |
||
35 | 35 | */ |
36 | 36 | function espresso_load_required($classname, $full_path_to_file) |
37 | 37 | { |
38 | - if (is_readable($full_path_to_file)) { |
|
39 | - require_once $full_path_to_file; |
|
40 | - } else { |
|
41 | - throw new \EE_Error( |
|
42 | - sprintf( |
|
43 | - esc_html__( |
|
44 | - 'The %s class file could not be located or is not readable due to file permissions.', |
|
45 | - 'event_espresso' |
|
46 | - ), |
|
47 | - $classname |
|
48 | - ) |
|
49 | - ); |
|
50 | - } |
|
38 | + if (is_readable($full_path_to_file)) { |
|
39 | + require_once $full_path_to_file; |
|
40 | + } else { |
|
41 | + throw new \EE_Error( |
|
42 | + sprintf( |
|
43 | + esc_html__( |
|
44 | + 'The %s class file could not be located or is not readable due to file permissions.', |
|
45 | + 'event_espresso' |
|
46 | + ), |
|
47 | + $classname |
|
48 | + ) |
|
49 | + ); |
|
50 | + } |
|
51 | 51 | } |
52 | 52 | |
53 | 53 | |
@@ -66,52 +66,52 @@ discard block |
||
66 | 66 | */ |
67 | 67 | function bootstrap_espresso() |
68 | 68 | { |
69 | - require_once __DIR__ . '/espresso_definitions.php'; |
|
70 | - try { |
|
71 | - espresso_load_error_handling(); |
|
72 | - // include WordPress shims for functions introduced in later versions of WordPress |
|
73 | - espresso_load_required( |
|
74 | - '', |
|
75 | - EE_CORE . 'wordpress-shims.php' |
|
76 | - ); |
|
77 | - espresso_load_required( |
|
78 | - '', |
|
79 | - EE_CORE . 'third-party-compatibility.php' |
|
80 | - ); |
|
81 | - espresso_load_required( |
|
82 | - 'EEH_Base', |
|
83 | - EE_CORE . 'helpers/EEH_Base.helper.php' |
|
84 | - ); |
|
85 | - espresso_load_required( |
|
86 | - 'EEH_File', |
|
87 | - EE_CORE . 'interfaces/EEHI_File.interface.php' |
|
88 | - ); |
|
89 | - espresso_load_required( |
|
90 | - 'EEH_File', |
|
91 | - EE_CORE . 'helpers/EEH_File.helper.php' |
|
92 | - ); |
|
93 | - espresso_load_required( |
|
94 | - 'EEH_Array', |
|
95 | - EE_CORE . 'helpers/EEH_Array.helper.php' |
|
96 | - ); |
|
97 | - espresso_load_required( |
|
98 | - 'EE_Base', |
|
99 | - EE_CORE . 'EE_Base.core.php' |
|
100 | - ); |
|
101 | - // instantiate and configure PSR4 autoloader |
|
102 | - espresso_load_required( |
|
103 | - 'Psr4Autoloader', |
|
104 | - EE_CORE . 'Psr4Autoloader.php' |
|
105 | - ); |
|
106 | - espresso_load_required( |
|
107 | - 'EE_Psr4AutoloaderInit', |
|
108 | - EE_CORE . 'EE_Psr4AutoloaderInit.core.php' |
|
109 | - ); |
|
110 | - $AutoloaderInit = new EE_Psr4AutoloaderInit(); |
|
111 | - $AutoloaderInit->initializeAutoloader(); |
|
112 | - new EventEspresso\core\services\bootstrap\BootstrapCore(); |
|
113 | - } catch (Exception $e) { |
|
114 | - require_once EE_CORE . 'exceptions/ExceptionStackTraceDisplay.php'; |
|
115 | - new EventEspresso\core\exceptions\ExceptionStackTraceDisplay($e); |
|
116 | - } |
|
69 | + require_once __DIR__ . '/espresso_definitions.php'; |
|
70 | + try { |
|
71 | + espresso_load_error_handling(); |
|
72 | + // include WordPress shims for functions introduced in later versions of WordPress |
|
73 | + espresso_load_required( |
|
74 | + '', |
|
75 | + EE_CORE . 'wordpress-shims.php' |
|
76 | + ); |
|
77 | + espresso_load_required( |
|
78 | + '', |
|
79 | + EE_CORE . 'third-party-compatibility.php' |
|
80 | + ); |
|
81 | + espresso_load_required( |
|
82 | + 'EEH_Base', |
|
83 | + EE_CORE . 'helpers/EEH_Base.helper.php' |
|
84 | + ); |
|
85 | + espresso_load_required( |
|
86 | + 'EEH_File', |
|
87 | + EE_CORE . 'interfaces/EEHI_File.interface.php' |
|
88 | + ); |
|
89 | + espresso_load_required( |
|
90 | + 'EEH_File', |
|
91 | + EE_CORE . 'helpers/EEH_File.helper.php' |
|
92 | + ); |
|
93 | + espresso_load_required( |
|
94 | + 'EEH_Array', |
|
95 | + EE_CORE . 'helpers/EEH_Array.helper.php' |
|
96 | + ); |
|
97 | + espresso_load_required( |
|
98 | + 'EE_Base', |
|
99 | + EE_CORE . 'EE_Base.core.php' |
|
100 | + ); |
|
101 | + // instantiate and configure PSR4 autoloader |
|
102 | + espresso_load_required( |
|
103 | + 'Psr4Autoloader', |
|
104 | + EE_CORE . 'Psr4Autoloader.php' |
|
105 | + ); |
|
106 | + espresso_load_required( |
|
107 | + 'EE_Psr4AutoloaderInit', |
|
108 | + EE_CORE . 'EE_Psr4AutoloaderInit.core.php' |
|
109 | + ); |
|
110 | + $AutoloaderInit = new EE_Psr4AutoloaderInit(); |
|
111 | + $AutoloaderInit->initializeAutoloader(); |
|
112 | + new EventEspresso\core\services\bootstrap\BootstrapCore(); |
|
113 | + } catch (Exception $e) { |
|
114 | + require_once EE_CORE . 'exceptions/ExceptionStackTraceDisplay.php'; |
|
115 | + new EventEspresso\core\exceptions\ExceptionStackTraceDisplay($e); |
|
116 | + } |
|
117 | 117 | } |
@@ -11,13 +11,13 @@ discard block |
||
11 | 11 | return; |
12 | 12 | } |
13 | 13 | // load debugging tools |
14 | - if (WP_DEBUG === true && is_readable(EE_HELPERS . 'EEH_Debug_Tools.helper.php')) { |
|
15 | - require_once EE_HELPERS . 'EEH_Debug_Tools.helper.php'; |
|
14 | + if (WP_DEBUG === true && is_readable(EE_HELPERS.'EEH_Debug_Tools.helper.php')) { |
|
15 | + require_once EE_HELPERS.'EEH_Debug_Tools.helper.php'; |
|
16 | 16 | \EEH_Debug_Tools::instance(); |
17 | 17 | } |
18 | 18 | // load error handling |
19 | - if (is_readable(EE_CORE . 'EE_Error.core.php')) { |
|
20 | - require_once EE_CORE . 'EE_Error.core.php'; |
|
19 | + if (is_readable(EE_CORE.'EE_Error.core.php')) { |
|
20 | + require_once EE_CORE.'EE_Error.core.php'; |
|
21 | 21 | } else { |
22 | 22 | wp_die(esc_html__('The EE_Error core class could not be loaded.', 'event_espresso')); |
23 | 23 | } |
@@ -66,52 +66,52 @@ discard block |
||
66 | 66 | */ |
67 | 67 | function bootstrap_espresso() |
68 | 68 | { |
69 | - require_once __DIR__ . '/espresso_definitions.php'; |
|
69 | + require_once __DIR__.'/espresso_definitions.php'; |
|
70 | 70 | try { |
71 | 71 | espresso_load_error_handling(); |
72 | 72 | // include WordPress shims for functions introduced in later versions of WordPress |
73 | 73 | espresso_load_required( |
74 | 74 | '', |
75 | - EE_CORE . 'wordpress-shims.php' |
|
75 | + EE_CORE.'wordpress-shims.php' |
|
76 | 76 | ); |
77 | 77 | espresso_load_required( |
78 | 78 | '', |
79 | - EE_CORE . 'third-party-compatibility.php' |
|
79 | + EE_CORE.'third-party-compatibility.php' |
|
80 | 80 | ); |
81 | 81 | espresso_load_required( |
82 | 82 | 'EEH_Base', |
83 | - EE_CORE . 'helpers/EEH_Base.helper.php' |
|
83 | + EE_CORE.'helpers/EEH_Base.helper.php' |
|
84 | 84 | ); |
85 | 85 | espresso_load_required( |
86 | 86 | 'EEH_File', |
87 | - EE_CORE . 'interfaces/EEHI_File.interface.php' |
|
87 | + EE_CORE.'interfaces/EEHI_File.interface.php' |
|
88 | 88 | ); |
89 | 89 | espresso_load_required( |
90 | 90 | 'EEH_File', |
91 | - EE_CORE . 'helpers/EEH_File.helper.php' |
|
91 | + EE_CORE.'helpers/EEH_File.helper.php' |
|
92 | 92 | ); |
93 | 93 | espresso_load_required( |
94 | 94 | 'EEH_Array', |
95 | - EE_CORE . 'helpers/EEH_Array.helper.php' |
|
95 | + EE_CORE.'helpers/EEH_Array.helper.php' |
|
96 | 96 | ); |
97 | 97 | espresso_load_required( |
98 | 98 | 'EE_Base', |
99 | - EE_CORE . 'EE_Base.core.php' |
|
99 | + EE_CORE.'EE_Base.core.php' |
|
100 | 100 | ); |
101 | 101 | // instantiate and configure PSR4 autoloader |
102 | 102 | espresso_load_required( |
103 | 103 | 'Psr4Autoloader', |
104 | - EE_CORE . 'Psr4Autoloader.php' |
|
104 | + EE_CORE.'Psr4Autoloader.php' |
|
105 | 105 | ); |
106 | 106 | espresso_load_required( |
107 | 107 | 'EE_Psr4AutoloaderInit', |
108 | - EE_CORE . 'EE_Psr4AutoloaderInit.core.php' |
|
108 | + EE_CORE.'EE_Psr4AutoloaderInit.core.php' |
|
109 | 109 | ); |
110 | 110 | $AutoloaderInit = new EE_Psr4AutoloaderInit(); |
111 | 111 | $AutoloaderInit->initializeAutoloader(); |
112 | 112 | new EventEspresso\core\services\bootstrap\BootstrapCore(); |
113 | 113 | } catch (Exception $e) { |
114 | - require_once EE_CORE . 'exceptions/ExceptionStackTraceDisplay.php'; |
|
114 | + require_once EE_CORE.'exceptions/ExceptionStackTraceDisplay.php'; |
|
115 | 115 | new EventEspresso\core\exceptions\ExceptionStackTraceDisplay($e); |
116 | 116 | } |
117 | 117 | } |
@@ -18,156 +18,156 @@ |
||
18 | 18 | class FqcnLocator extends Locator |
19 | 19 | { |
20 | 20 | |
21 | - /** |
|
22 | - * @var array $FQCNs |
|
23 | - */ |
|
24 | - protected $FQCNs = array(); |
|
25 | - |
|
26 | - /** |
|
27 | - * @var array $namespaces |
|
28 | - */ |
|
29 | - protected $namespaces = array(); |
|
30 | - |
|
31 | - |
|
32 | - /** |
|
33 | - * @access protected |
|
34 | - * @param string $namespace |
|
35 | - * @param string $namespace_base_dir |
|
36 | - * @throws InvalidDataTypeException |
|
37 | - */ |
|
38 | - protected function setNamespace($namespace, $namespace_base_dir) |
|
39 | - { |
|
40 | - if (! is_string($namespace)) { |
|
41 | - throw new InvalidDataTypeException('$namespace', $namespace, 'string'); |
|
42 | - } |
|
43 | - if (! is_string($namespace_base_dir)) { |
|
44 | - throw new InvalidDataTypeException('$namespace_base_dir', $namespace_base_dir, 'string'); |
|
45 | - } |
|
46 | - $this->namespaces[ $namespace ] = $namespace_base_dir; |
|
47 | - } |
|
48 | - |
|
49 | - |
|
50 | - /** |
|
51 | - * @access public |
|
52 | - * @return array |
|
53 | - */ |
|
54 | - public function getFQCNs() |
|
55 | - { |
|
56 | - return $this->FQCNs; |
|
57 | - } |
|
58 | - |
|
59 | - |
|
60 | - /** |
|
61 | - * @access public |
|
62 | - * @return int |
|
63 | - */ |
|
64 | - public function count() |
|
65 | - { |
|
66 | - return count($this->FQCNs); |
|
67 | - } |
|
68 | - |
|
69 | - |
|
70 | - /** |
|
71 | - * given a valid namespace, will find all files that match the provided mask |
|
72 | - * |
|
73 | - * @access public |
|
74 | - * @param string|array $namespaces |
|
75 | - * @return array |
|
76 | - * @throws InvalidClassException |
|
77 | - * @throws InvalidDataTypeException |
|
78 | - */ |
|
79 | - public function locate($namespaces) |
|
80 | - { |
|
81 | - if (! (is_string($namespaces) || is_array($namespaces))) { |
|
82 | - throw new InvalidDataTypeException('$namespaces', $namespaces, 'string or array'); |
|
83 | - } |
|
84 | - foreach ((array) $namespaces as $namespace) { |
|
85 | - foreach ($this->findFQCNsByNamespace($namespace) as $key => $file) { |
|
86 | - $this->FQCNs[ $key ] = $file; |
|
87 | - } |
|
88 | - } |
|
89 | - return $this->FQCNs; |
|
90 | - } |
|
91 | - |
|
92 | - |
|
93 | - /** |
|
94 | - * given a partial namespace, will find all files in that folder |
|
95 | - * ** PLZ NOTE ** |
|
96 | - * This assumes that all files within the specified folder should be loaded |
|
97 | - * |
|
98 | - * @access protected |
|
99 | - * @param string $partial_namespace |
|
100 | - * @return array |
|
101 | - * @throws InvalidClassException |
|
102 | - * @throws InvalidDataTypeException |
|
103 | - */ |
|
104 | - protected function findFQCNsByNamespace($partial_namespace) |
|
105 | - { |
|
106 | - $iterator = new FilesystemIterator( |
|
107 | - $this->getDirectoryFromPartialNamespace($partial_namespace) |
|
108 | - ); |
|
109 | - $iterator->setFlags(FilesystemIterator::CURRENT_AS_FILEINFO); |
|
110 | - $iterator->setFlags(FilesystemIterator::UNIX_PATHS); |
|
111 | - if (iterator_count($iterator) === 0) { |
|
112 | - return array(); |
|
113 | - } |
|
114 | - foreach ($iterator as $file) { |
|
115 | - if ($file->isFile() && $file->getExtension() === 'php') { |
|
116 | - $file = $file->getPath() . '/' . $file->getBasename('.php'); |
|
117 | - foreach ($this->namespaces as $namespace => $base_dir) { |
|
118 | - $namespace .= Psr4Autoloader::NS; |
|
119 | - if (strpos($file, $base_dir) === 0) { |
|
120 | - $this->FQCNs[] = Psr4Autoloader::NS . str_replace( |
|
121 | - array($base_dir, '/'), |
|
122 | - array($namespace, Psr4Autoloader::NS), |
|
123 | - $file |
|
124 | - ); |
|
125 | - } |
|
126 | - } |
|
127 | - } |
|
128 | - } |
|
129 | - return $this->FQCNs; |
|
130 | - } |
|
131 | - |
|
132 | - |
|
133 | - /** |
|
134 | - * getDirectoryFromPartialNamespace |
|
135 | - * |
|
136 | - * @access protected |
|
137 | - * @param string $partial_namespace almost fully qualified class name ? |
|
138 | - * @return string |
|
139 | - * @throws InvalidDataTypeException |
|
140 | - * @throws InvalidClassException |
|
141 | - */ |
|
142 | - protected function getDirectoryFromPartialNamespace($partial_namespace) |
|
143 | - { |
|
144 | - if (empty($partial_namespace)) { |
|
145 | - throw new InvalidClassException($partial_namespace); |
|
146 | - } |
|
147 | - // load our PSR-4 Autoloader so we can get the list of registered namespaces from it |
|
148 | - $psr4_loader = \EE_Psr4AutoloaderInit::psr4_loader(); |
|
149 | - // breakup the incoming namespace into segments so we can loop thru them |
|
150 | - $namespace_segments = explode(Psr4Autoloader::NS, trim($partial_namespace, Psr4Autoloader::NS)); |
|
151 | - // we're only interested in the Vendor and secondary base, so pull those from the array |
|
152 | - $vendor_base = array_slice($namespace_segments, 0, 2); |
|
153 | - $namespace = $prefix = null; |
|
154 | - while (! empty($vendor_base)) { |
|
155 | - $namespace = implode(Psr4Autoloader::NS, $vendor_base); |
|
156 | - // check if there's a base directory registered for that namespace |
|
157 | - $prefix = $psr4_loader->prefixes($namespace . Psr4Autoloader::NS); |
|
158 | - if (! empty($prefix) && ! empty($prefix[0])) { |
|
159 | - // found one! |
|
160 | - break; |
|
161 | - } |
|
162 | - // remove base and try vendor only portion of namespace |
|
163 | - array_pop($vendor_base); |
|
164 | - } |
|
165 | - // nope? then the incoming namespace is invalid |
|
166 | - if (empty($prefix) || empty($prefix[0])) { |
|
167 | - throw new InvalidClassException($partial_namespace); |
|
168 | - } |
|
169 | - $this->setNamespace($namespace, $prefix[0]); |
|
170 | - // but if it's good, add that base directory to the rest of the path, and return it |
|
171 | - return $prefix[0] . implode('/', array_diff($namespace_segments, $vendor_base)) . '/'; |
|
172 | - } |
|
21 | + /** |
|
22 | + * @var array $FQCNs |
|
23 | + */ |
|
24 | + protected $FQCNs = array(); |
|
25 | + |
|
26 | + /** |
|
27 | + * @var array $namespaces |
|
28 | + */ |
|
29 | + protected $namespaces = array(); |
|
30 | + |
|
31 | + |
|
32 | + /** |
|
33 | + * @access protected |
|
34 | + * @param string $namespace |
|
35 | + * @param string $namespace_base_dir |
|
36 | + * @throws InvalidDataTypeException |
|
37 | + */ |
|
38 | + protected function setNamespace($namespace, $namespace_base_dir) |
|
39 | + { |
|
40 | + if (! is_string($namespace)) { |
|
41 | + throw new InvalidDataTypeException('$namespace', $namespace, 'string'); |
|
42 | + } |
|
43 | + if (! is_string($namespace_base_dir)) { |
|
44 | + throw new InvalidDataTypeException('$namespace_base_dir', $namespace_base_dir, 'string'); |
|
45 | + } |
|
46 | + $this->namespaces[ $namespace ] = $namespace_base_dir; |
|
47 | + } |
|
48 | + |
|
49 | + |
|
50 | + /** |
|
51 | + * @access public |
|
52 | + * @return array |
|
53 | + */ |
|
54 | + public function getFQCNs() |
|
55 | + { |
|
56 | + return $this->FQCNs; |
|
57 | + } |
|
58 | + |
|
59 | + |
|
60 | + /** |
|
61 | + * @access public |
|
62 | + * @return int |
|
63 | + */ |
|
64 | + public function count() |
|
65 | + { |
|
66 | + return count($this->FQCNs); |
|
67 | + } |
|
68 | + |
|
69 | + |
|
70 | + /** |
|
71 | + * given a valid namespace, will find all files that match the provided mask |
|
72 | + * |
|
73 | + * @access public |
|
74 | + * @param string|array $namespaces |
|
75 | + * @return array |
|
76 | + * @throws InvalidClassException |
|
77 | + * @throws InvalidDataTypeException |
|
78 | + */ |
|
79 | + public function locate($namespaces) |
|
80 | + { |
|
81 | + if (! (is_string($namespaces) || is_array($namespaces))) { |
|
82 | + throw new InvalidDataTypeException('$namespaces', $namespaces, 'string or array'); |
|
83 | + } |
|
84 | + foreach ((array) $namespaces as $namespace) { |
|
85 | + foreach ($this->findFQCNsByNamespace($namespace) as $key => $file) { |
|
86 | + $this->FQCNs[ $key ] = $file; |
|
87 | + } |
|
88 | + } |
|
89 | + return $this->FQCNs; |
|
90 | + } |
|
91 | + |
|
92 | + |
|
93 | + /** |
|
94 | + * given a partial namespace, will find all files in that folder |
|
95 | + * ** PLZ NOTE ** |
|
96 | + * This assumes that all files within the specified folder should be loaded |
|
97 | + * |
|
98 | + * @access protected |
|
99 | + * @param string $partial_namespace |
|
100 | + * @return array |
|
101 | + * @throws InvalidClassException |
|
102 | + * @throws InvalidDataTypeException |
|
103 | + */ |
|
104 | + protected function findFQCNsByNamespace($partial_namespace) |
|
105 | + { |
|
106 | + $iterator = new FilesystemIterator( |
|
107 | + $this->getDirectoryFromPartialNamespace($partial_namespace) |
|
108 | + ); |
|
109 | + $iterator->setFlags(FilesystemIterator::CURRENT_AS_FILEINFO); |
|
110 | + $iterator->setFlags(FilesystemIterator::UNIX_PATHS); |
|
111 | + if (iterator_count($iterator) === 0) { |
|
112 | + return array(); |
|
113 | + } |
|
114 | + foreach ($iterator as $file) { |
|
115 | + if ($file->isFile() && $file->getExtension() === 'php') { |
|
116 | + $file = $file->getPath() . '/' . $file->getBasename('.php'); |
|
117 | + foreach ($this->namespaces as $namespace => $base_dir) { |
|
118 | + $namespace .= Psr4Autoloader::NS; |
|
119 | + if (strpos($file, $base_dir) === 0) { |
|
120 | + $this->FQCNs[] = Psr4Autoloader::NS . str_replace( |
|
121 | + array($base_dir, '/'), |
|
122 | + array($namespace, Psr4Autoloader::NS), |
|
123 | + $file |
|
124 | + ); |
|
125 | + } |
|
126 | + } |
|
127 | + } |
|
128 | + } |
|
129 | + return $this->FQCNs; |
|
130 | + } |
|
131 | + |
|
132 | + |
|
133 | + /** |
|
134 | + * getDirectoryFromPartialNamespace |
|
135 | + * |
|
136 | + * @access protected |
|
137 | + * @param string $partial_namespace almost fully qualified class name ? |
|
138 | + * @return string |
|
139 | + * @throws InvalidDataTypeException |
|
140 | + * @throws InvalidClassException |
|
141 | + */ |
|
142 | + protected function getDirectoryFromPartialNamespace($partial_namespace) |
|
143 | + { |
|
144 | + if (empty($partial_namespace)) { |
|
145 | + throw new InvalidClassException($partial_namespace); |
|
146 | + } |
|
147 | + // load our PSR-4 Autoloader so we can get the list of registered namespaces from it |
|
148 | + $psr4_loader = \EE_Psr4AutoloaderInit::psr4_loader(); |
|
149 | + // breakup the incoming namespace into segments so we can loop thru them |
|
150 | + $namespace_segments = explode(Psr4Autoloader::NS, trim($partial_namespace, Psr4Autoloader::NS)); |
|
151 | + // we're only interested in the Vendor and secondary base, so pull those from the array |
|
152 | + $vendor_base = array_slice($namespace_segments, 0, 2); |
|
153 | + $namespace = $prefix = null; |
|
154 | + while (! empty($vendor_base)) { |
|
155 | + $namespace = implode(Psr4Autoloader::NS, $vendor_base); |
|
156 | + // check if there's a base directory registered for that namespace |
|
157 | + $prefix = $psr4_loader->prefixes($namespace . Psr4Autoloader::NS); |
|
158 | + if (! empty($prefix) && ! empty($prefix[0])) { |
|
159 | + // found one! |
|
160 | + break; |
|
161 | + } |
|
162 | + // remove base and try vendor only portion of namespace |
|
163 | + array_pop($vendor_base); |
|
164 | + } |
|
165 | + // nope? then the incoming namespace is invalid |
|
166 | + if (empty($prefix) || empty($prefix[0])) { |
|
167 | + throw new InvalidClassException($partial_namespace); |
|
168 | + } |
|
169 | + $this->setNamespace($namespace, $prefix[0]); |
|
170 | + // but if it's good, add that base directory to the rest of the path, and return it |
|
171 | + return $prefix[0] . implode('/', array_diff($namespace_segments, $vendor_base)) . '/'; |
|
172 | + } |
|
173 | 173 | } |
@@ -37,13 +37,13 @@ discard block |
||
37 | 37 | */ |
38 | 38 | protected function setNamespace($namespace, $namespace_base_dir) |
39 | 39 | { |
40 | - if (! is_string($namespace)) { |
|
40 | + if ( ! is_string($namespace)) { |
|
41 | 41 | throw new InvalidDataTypeException('$namespace', $namespace, 'string'); |
42 | 42 | } |
43 | - if (! is_string($namespace_base_dir)) { |
|
43 | + if ( ! is_string($namespace_base_dir)) { |
|
44 | 44 | throw new InvalidDataTypeException('$namespace_base_dir', $namespace_base_dir, 'string'); |
45 | 45 | } |
46 | - $this->namespaces[ $namespace ] = $namespace_base_dir; |
|
46 | + $this->namespaces[$namespace] = $namespace_base_dir; |
|
47 | 47 | } |
48 | 48 | |
49 | 49 | |
@@ -78,12 +78,12 @@ discard block |
||
78 | 78 | */ |
79 | 79 | public function locate($namespaces) |
80 | 80 | { |
81 | - if (! (is_string($namespaces) || is_array($namespaces))) { |
|
81 | + if ( ! (is_string($namespaces) || is_array($namespaces))) { |
|
82 | 82 | throw new InvalidDataTypeException('$namespaces', $namespaces, 'string or array'); |
83 | 83 | } |
84 | 84 | foreach ((array) $namespaces as $namespace) { |
85 | 85 | foreach ($this->findFQCNsByNamespace($namespace) as $key => $file) { |
86 | - $this->FQCNs[ $key ] = $file; |
|
86 | + $this->FQCNs[$key] = $file; |
|
87 | 87 | } |
88 | 88 | } |
89 | 89 | return $this->FQCNs; |
@@ -113,11 +113,11 @@ discard block |
||
113 | 113 | } |
114 | 114 | foreach ($iterator as $file) { |
115 | 115 | if ($file->isFile() && $file->getExtension() === 'php') { |
116 | - $file = $file->getPath() . '/' . $file->getBasename('.php'); |
|
116 | + $file = $file->getPath().'/'.$file->getBasename('.php'); |
|
117 | 117 | foreach ($this->namespaces as $namespace => $base_dir) { |
118 | 118 | $namespace .= Psr4Autoloader::NS; |
119 | 119 | if (strpos($file, $base_dir) === 0) { |
120 | - $this->FQCNs[] = Psr4Autoloader::NS . str_replace( |
|
120 | + $this->FQCNs[] = Psr4Autoloader::NS.str_replace( |
|
121 | 121 | array($base_dir, '/'), |
122 | 122 | array($namespace, Psr4Autoloader::NS), |
123 | 123 | $file |
@@ -151,11 +151,11 @@ discard block |
||
151 | 151 | // we're only interested in the Vendor and secondary base, so pull those from the array |
152 | 152 | $vendor_base = array_slice($namespace_segments, 0, 2); |
153 | 153 | $namespace = $prefix = null; |
154 | - while (! empty($vendor_base)) { |
|
154 | + while ( ! empty($vendor_base)) { |
|
155 | 155 | $namespace = implode(Psr4Autoloader::NS, $vendor_base); |
156 | 156 | // check if there's a base directory registered for that namespace |
157 | - $prefix = $psr4_loader->prefixes($namespace . Psr4Autoloader::NS); |
|
158 | - if (! empty($prefix) && ! empty($prefix[0])) { |
|
157 | + $prefix = $psr4_loader->prefixes($namespace.Psr4Autoloader::NS); |
|
158 | + if ( ! empty($prefix) && ! empty($prefix[0])) { |
|
159 | 159 | // found one! |
160 | 160 | break; |
161 | 161 | } |
@@ -168,6 +168,6 @@ discard block |
||
168 | 168 | } |
169 | 169 | $this->setNamespace($namespace, $prefix[0]); |
170 | 170 | // but if it's good, add that base directory to the rest of the path, and return it |
171 | - return $prefix[0] . implode('/', array_diff($namespace_segments, $vendor_base)) . '/'; |
|
171 | + return $prefix[0].implode('/', array_diff($namespace_segments, $vendor_base)).'/'; |
|
172 | 172 | } |
173 | 173 | } |