@@ -99,34 +99,34 @@ discard block |
||
99 | 99 | */ |
100 | 100 | public function set_extra_accntng($extra_accounting_info); |
101 | 101 | |
102 | - /** |
|
103 | - * Gets the first event for this payment (it's possible that it could be for multiple) |
|
104 | - * |
|
105 | - * @param EE_Payment $payment |
|
106 | - * @return EE_Event|null |
|
107 | - */ |
|
108 | - public function get_first_event(); |
|
109 | - |
|
110 | - /** |
|
111 | - * Gets the name of the first event for which is being paid |
|
112 | - * |
|
113 | - * @param EE_Payment $payment |
|
114 | - * @return string |
|
115 | - */ |
|
116 | - public function get_first_event_name(); |
|
117 | - |
|
118 | - /** |
|
119 | - * Returns the payment's transaction's primary registration |
|
120 | - * |
|
121 | - * @return EE_Registration|null |
|
122 | - */ |
|
123 | - public function get_primary_registration(); |
|
124 | - |
|
125 | - /** |
|
126 | - * Gets the payment's transaction's primary registration's attendee, or null |
|
127 | - * @return EE_Attendee|null |
|
128 | - */ |
|
129 | - public function get_primary_attendee(); |
|
102 | + /** |
|
103 | + * Gets the first event for this payment (it's possible that it could be for multiple) |
|
104 | + * |
|
105 | + * @param EE_Payment $payment |
|
106 | + * @return EE_Event|null |
|
107 | + */ |
|
108 | + public function get_first_event(); |
|
109 | + |
|
110 | + /** |
|
111 | + * Gets the name of the first event for which is being paid |
|
112 | + * |
|
113 | + * @param EE_Payment $payment |
|
114 | + * @return string |
|
115 | + */ |
|
116 | + public function get_first_event_name(); |
|
117 | + |
|
118 | + /** |
|
119 | + * Returns the payment's transaction's primary registration |
|
120 | + * |
|
121 | + * @return EE_Registration|null |
|
122 | + */ |
|
123 | + public function get_primary_registration(); |
|
124 | + |
|
125 | + /** |
|
126 | + * Gets the payment's transaction's primary registration's attendee, or null |
|
127 | + * @return EE_Attendee|null |
|
128 | + */ |
|
129 | + public function get_primary_attendee(); |
|
130 | 130 | } |
131 | 131 | |
132 | 132 | |
@@ -164,13 +164,13 @@ discard block |
||
164 | 164 | |
165 | 165 | |
166 | 166 | |
167 | - /** |
|
168 | - * Function that returns an instance of this class. |
|
169 | - * |
|
170 | - * @param null $timezone |
|
171 | - * @param ModelFieldFactory $model_field_factory If not provided, this class needs to find it itself |
|
172 | - * @return EEMI_Payment |
|
173 | - */ |
|
167 | + /** |
|
168 | + * Function that returns an instance of this class. |
|
169 | + * |
|
170 | + * @param null $timezone |
|
171 | + * @param ModelFieldFactory $model_field_factory If not provided, this class needs to find it itself |
|
172 | + * @return EEMI_Payment |
|
173 | + */ |
|
174 | 174 | public static function instance($timezone = null, ModelFieldFactory $model_field_factory = null); |
175 | 175 | |
176 | 176 | /** |
@@ -165,7 +165,7 @@ |
||
165 | 165 | |
166 | 166 | /** |
167 | 167 | * @param EE_Event $item |
168 | - * @return mixed|string |
|
168 | + * @return string |
|
169 | 169 | */ |
170 | 170 | public function column_id(EE_Event $item) |
171 | 171 | { |
@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | if (! defined('EVENT_ESPRESSO_VERSION')) { |
3 | - exit('NO direct script access allowed'); |
|
3 | + exit('NO direct script access allowed'); |
|
4 | 4 | } |
5 | 5 | |
6 | 6 | /** |
@@ -26,406 +26,406 @@ discard block |
||
26 | 26 | { |
27 | 27 | |
28 | 28 | |
29 | - /** |
|
30 | - * @var EE_Datetime |
|
31 | - */ |
|
32 | - private $_dtt; |
|
33 | - |
|
34 | - |
|
35 | - /** |
|
36 | - * Events_Admin_List_Table constructor. |
|
37 | - * |
|
38 | - * @param EE_Admin_Page $admin_page |
|
39 | - */ |
|
40 | - public function __construct($admin_page) |
|
41 | - { |
|
42 | - parent::__construct($admin_page); |
|
43 | - require_once(EE_HELPERS . 'EEH_DTT_Helper.helper.php'); |
|
44 | - } |
|
45 | - |
|
46 | - |
|
47 | - /** |
|
48 | - * Initial setup of data properties for the list table. |
|
49 | - */ |
|
50 | - protected function _setup_data() |
|
51 | - { |
|
52 | - $this->_data = $this->_admin_page->get_events($this->_per_page, $this->_current_page); |
|
53 | - $this->_all_data_count = $this->_admin_page->get_events(0, 0, true); |
|
54 | - } |
|
55 | - |
|
56 | - |
|
57 | - /** |
|
58 | - * Set up of additional properties for the list table. |
|
59 | - */ |
|
60 | - protected function _set_properties() |
|
61 | - { |
|
62 | - $this->_wp_list_args = array( |
|
63 | - 'singular' => __('event', 'event_espresso'), |
|
64 | - 'plural' => __('events', 'event_espresso'), |
|
65 | - 'ajax' => true, //for now |
|
66 | - 'screen' => $this->_admin_page->get_current_screen()->id, |
|
67 | - ); |
|
68 | - |
|
69 | - |
|
70 | - $this->_columns = array( |
|
71 | - 'cb' => '<input type="checkbox" />', |
|
72 | - 'id' => __('ID', 'event_espresso'), |
|
73 | - 'name' => __('Name', 'event_espresso'), |
|
74 | - 'author' => __('Author', 'event_espresso'), |
|
75 | - 'venue' => __('Venue', 'event_espresso'), |
|
76 | - 'start_date_time' => __('Event Start', 'event_espresso'), |
|
77 | - 'reg_begins' => __('On Sale', 'event_espresso'), |
|
78 | - 'attendees' => '<span class="dashicons dashicons-groups ee-icon-color-ee-green ee-icon-size-20"></span>', |
|
79 | - //'tkts_sold' => __('Tickets Sold', 'event_espresso'), |
|
80 | - 'actions' => __('Actions', 'event_espresso'), |
|
81 | - ); |
|
82 | - |
|
83 | - |
|
84 | - $this->_sortable_columns = array( |
|
85 | - 'id' => array('EVT_ID' => true), |
|
86 | - 'name' => array('EVT_name' => false), |
|
87 | - 'author' => array('EVT_wp_user' => false), |
|
88 | - 'venue' => array('Venue.VNU_name' => false), |
|
89 | - 'start_date_time' => array('Datetime.DTT_EVT_start' => false), |
|
90 | - 'reg_begins' => array('Datetime.Ticket.TKT_start_date' => false), |
|
91 | - ); |
|
92 | - |
|
93 | - $this->_primary_column = 'id'; |
|
94 | - |
|
95 | - $this->_hidden_columns = array('author'); |
|
96 | - } |
|
97 | - |
|
98 | - |
|
99 | - /** |
|
100 | - * @return array |
|
101 | - */ |
|
102 | - protected function _get_table_filters() |
|
103 | - { |
|
104 | - return array(); //no filters with decaf |
|
105 | - } |
|
106 | - |
|
107 | - |
|
108 | - /** |
|
109 | - * Setup of views properties. |
|
110 | - */ |
|
111 | - protected function _add_view_counts() |
|
112 | - { |
|
113 | - $this->_views['all']['count'] = $this->_admin_page->total_events(); |
|
114 | - $this->_views['draft']['count'] = $this->_admin_page->total_events_draft(); |
|
115 | - if (EE_Registry::instance()->CAP->current_user_can('ee_delete_events', 'espresso_events_trash_events')) { |
|
116 | - $this->_views['trash']['count'] = $this->_admin_page->total_trashed_events(); |
|
117 | - } |
|
118 | - } |
|
119 | - |
|
120 | - |
|
121 | - /** |
|
122 | - * @param EE_Event $item |
|
123 | - * @return string |
|
124 | - */ |
|
125 | - protected function _get_row_class($item) |
|
126 | - { |
|
127 | - $class = parent::_get_row_class($item); |
|
128 | - //add status class |
|
129 | - $class .= $item instanceof EE_Event ? ' ee-status-strip event-status-' . $item->get_active_status() : ''; |
|
130 | - if ($this->_has_checkbox_column) { |
|
131 | - $class .= ' has-checkbox-column'; |
|
132 | - } |
|
133 | - return $class; |
|
134 | - } |
|
135 | - |
|
136 | - |
|
137 | - /** |
|
138 | - * @param EE_Event $item |
|
139 | - * @return string |
|
140 | - */ |
|
141 | - public function column_status(EE_Event $item) |
|
142 | - { |
|
143 | - return '<span class="ee-status-strip ee-status-strip-td event-status-' . $item->get_active_status() . '"></span>'; |
|
144 | - }/**/ |
|
145 | - |
|
146 | - |
|
147 | - /** |
|
148 | - * @param EE_Event $item |
|
149 | - * @return string |
|
150 | - */ |
|
151 | - public function column_cb($item) |
|
152 | - { |
|
153 | - if (! $item instanceof EE_Event) { |
|
154 | - return ''; |
|
155 | - } |
|
156 | - $this->_dtt = $item->primary_datetime(); //set this for use in other columns |
|
157 | - |
|
158 | - //does event have any attached registrations? |
|
159 | - $regs = $item->count_related('Registration'); |
|
160 | - return $regs > 0 && $this->_view == 'trash' ? '<span class="ee-lock-icon"></span>' : sprintf( |
|
161 | - '<input type="checkbox" name="EVT_IDs[]" value="%s" />', $item->ID() |
|
162 | - ); |
|
163 | - } |
|
164 | - |
|
165 | - |
|
166 | - /** |
|
167 | - * @param EE_Event $item |
|
168 | - * @return mixed|string |
|
169 | - */ |
|
170 | - public function column_id(EE_Event $item) |
|
171 | - { |
|
172 | - $content = $item->ID(); |
|
173 | - $content .= ' <span class="show-on-mobile-view-only">' . $item->name() . '</span>'; |
|
174 | - return $content; |
|
175 | - } |
|
176 | - |
|
177 | - |
|
178 | - /** |
|
179 | - * @param EE_Event $item |
|
180 | - * @return string |
|
181 | - */ |
|
182 | - public function column_name(EE_Event $item) |
|
183 | - { |
|
184 | - $edit_query_args = array( |
|
185 | - 'action' => 'edit', |
|
186 | - 'post' => $item->ID(), |
|
187 | - ); |
|
188 | - $edit_link = EE_Admin_Page::add_query_args_and_nonce($edit_query_args, EVENTS_ADMIN_URL); |
|
189 | - $actions = $this->_column_name_action_setup($item); |
|
190 | - $status = ''; //$item->status() !== 'publish' ? ' (' . $item->status() . ')' : ''; |
|
191 | - $content = '<strong><a class="row-title" href="' . $edit_link . '">' . $item->name() . '</a></strong>' . $status; |
|
192 | - $content .= '<br><span class="ee-status-text-small">' . EEH_Template::pretty_status($item->get_active_status(), |
|
193 | - false, 'sentence') . '</span>'; |
|
194 | - $content .= $this->row_actions($actions); |
|
195 | - return $content; |
|
196 | - |
|
197 | - } |
|
198 | - |
|
199 | - |
|
200 | - /** |
|
201 | - * Just a method for setting up the actions for the name column |
|
202 | - * |
|
203 | - * @param EE_Event $item |
|
204 | - * @return array array of actions |
|
205 | - */ |
|
206 | - protected function _column_name_action_setup(EE_Event $item) |
|
207 | - { |
|
208 | - //todo: remove when attendees is active |
|
209 | - if (! defined('REG_ADMIN_URL')) { |
|
210 | - define('REG_ADMIN_URL', EVENTS_ADMIN_URL); |
|
211 | - } |
|
212 | - |
|
213 | - $actions = array(); |
|
214 | - |
|
215 | - if (EE_Registry::instance()->CAP->current_user_can('ee_edit_event', 'espresso_events_edit', $item->ID())) { |
|
216 | - $edit_query_args = array( |
|
217 | - 'action' => 'edit', |
|
218 | - 'post' => $item->ID(), |
|
219 | - ); |
|
220 | - $edit_link = EE_Admin_Page::add_query_args_and_nonce($edit_query_args, EVENTS_ADMIN_URL); |
|
221 | - $actions['edit'] = '<a href="' . $edit_link . '" title="' . esc_attr__('Edit Event', |
|
222 | - 'event_espresso') . '">' . __('Edit', 'event_espresso') . '</a>'; |
|
223 | - |
|
224 | - } |
|
225 | - |
|
226 | - if (EE_Registry::instance()->CAP->current_user_can('ee_read_registration', |
|
227 | - 'espresso_registrations_view_registration', $item->ID())) { |
|
228 | - $attendees_query_args = array( |
|
229 | - 'action' => 'default', |
|
230 | - 'event_id' => $item->ID(), |
|
231 | - ); |
|
232 | - $attendees_link = EE_Admin_Page::add_query_args_and_nonce($attendees_query_args, REG_ADMIN_URL); |
|
233 | - $actions['attendees'] = '<a href="' . $attendees_link . '" title="' . esc_attr__('View Registrations', |
|
234 | - 'event_espresso') . '">' . __('Registrations', 'event_espresso') . '</a>'; |
|
235 | - } |
|
236 | - |
|
237 | - if (EE_Registry::instance()->CAP->current_user_can('ee_delete_event', 'espresso_events_trash_event', |
|
238 | - $item->ID())) { |
|
239 | - $trash_event_query_args = array( |
|
240 | - 'action' => 'trash_event', |
|
241 | - 'EVT_ID' => $item->ID(), |
|
242 | - ); |
|
243 | - $trash_event_link = EE_Admin_Page::add_query_args_and_nonce($trash_event_query_args, |
|
244 | - EVENTS_ADMIN_URL); |
|
245 | - } |
|
246 | - |
|
247 | - if (EE_Registry::instance()->CAP->current_user_can('ee_delete_event', 'espresso_events_restore_event', |
|
248 | - $item->ID())) { |
|
249 | - $restore_event_query_args = array( |
|
250 | - 'action' => 'restore_event', |
|
251 | - 'EVT_ID' => $item->ID(), |
|
252 | - ); |
|
253 | - $restore_event_link = EE_Admin_Page::add_query_args_and_nonce($restore_event_query_args, |
|
254 | - EVENTS_ADMIN_URL); |
|
255 | - } |
|
256 | - |
|
257 | - if (EE_Registry::instance()->CAP->current_user_can('ee_delete_event', 'espresso_events_delete_event', |
|
258 | - $item->ID())) { |
|
259 | - $delete_event_query_args = array( |
|
260 | - 'action' => 'delete_event', |
|
261 | - 'EVT_ID' => $item->ID(), |
|
262 | - ); |
|
263 | - $delete_event_link = EE_Admin_Page::add_query_args_and_nonce($delete_event_query_args, |
|
264 | - EVENTS_ADMIN_URL); |
|
265 | - } |
|
266 | - |
|
267 | - $view_link = get_permalink($item->ID()); |
|
268 | - |
|
269 | - $actions['view'] = '<a href="' . $view_link . '" title="' . esc_attr__('View Event', |
|
270 | - 'event_espresso') . '">' . __('View', 'event_espresso') . '</a>'; |
|
271 | - |
|
272 | - switch ($item->get('status')) { |
|
273 | - case 'trash' : |
|
274 | - if (EE_Registry::instance()->CAP->current_user_can('ee_delete_event', 'espresso_events_restore_event', |
|
275 | - $item->ID())) { |
|
276 | - $actions['restore_from_trash'] = '<a href="' . $restore_event_link . '" title="' . esc_attr__('Restore from Trash', |
|
277 | - 'event_espresso') . '">' . __('Restore from Trash', 'event_espresso') . '</a>'; |
|
278 | - } |
|
279 | - if ($item->count_related('Registration') === 0 && EE_Registry::instance()->CAP->current_user_can('ee_delete_event', |
|
280 | - 'espresso_events_delete_event', $item->ID())) { |
|
281 | - $actions['delete'] = '<a href="' . $delete_event_link . '" title="' . esc_attr__('Delete Permanently', |
|
282 | - 'event_espresso') . '">' . __('Delete Permanently', 'event_espresso') . '</a>'; |
|
283 | - } |
|
284 | - break; |
|
285 | - default : |
|
286 | - if (EE_Registry::instance()->CAP->current_user_can('ee_delete_event', 'espresso_events_trash_event', |
|
287 | - $item->ID())) { |
|
288 | - $actions['move to trash'] = '<a href="' . $trash_event_link . '" title="' . esc_attr__('Trash Event', |
|
289 | - 'event_espresso') . '">' . __('Trash', 'event_espresso') . '</a>'; |
|
290 | - } |
|
291 | - } |
|
292 | - return $actions; |
|
293 | - } |
|
294 | - |
|
295 | - |
|
296 | - /** |
|
297 | - * @param EE_Event $item |
|
298 | - * @return string |
|
299 | - */ |
|
300 | - public function column_author(EE_Event $item) |
|
301 | - { |
|
302 | - //user author info |
|
303 | - $event_author = get_userdata($item->wp_user()); |
|
304 | - $gravatar = get_avatar($item->wp_user(), '15'); |
|
305 | - //filter link |
|
306 | - $query_args = array( |
|
307 | - 'action' => 'default', |
|
308 | - 'EVT_wp_user' => $item->wp_user(), |
|
309 | - ); |
|
310 | - $filter_url = EE_Admin_Page::add_query_args_and_nonce($query_args, EVENTS_ADMIN_URL); |
|
311 | - return $gravatar . ' <a href="' . $filter_url . '" title="' . esc_attr__('Click to filter events by this author.', |
|
312 | - 'event_espresso') . '">' . $event_author->display_name . '</a>'; |
|
313 | - } |
|
314 | - |
|
315 | - |
|
316 | - /** |
|
317 | - * @param EE_Event $item |
|
318 | - * @return string |
|
319 | - */ |
|
320 | - public function column_venue(EE_Event $item) |
|
321 | - { |
|
322 | - $venue = $item->get_first_related('Venue'); |
|
323 | - return ! empty($venue) ? $venue->name() : ''; |
|
324 | - } |
|
325 | - |
|
326 | - |
|
327 | - /** |
|
328 | - * @param EE_Event $item |
|
329 | - * @throws EE_Error |
|
330 | - */ |
|
331 | - public function column_start_date_time(EE_Event $item) |
|
332 | - { |
|
333 | - echo ! empty($this->_dtt) ? $this->_dtt->get_i18n_datetime('DTT_EVT_start') : __('No Date was saved for this Event', |
|
334 | - 'event_espresso'); |
|
335 | - //display in user's timezone? |
|
336 | - echo ! empty($this->_dtt) ? $this->_dtt->display_in_my_timezone('DTT_EVT_start', 'get_i18n_datetime', '', |
|
337 | - 'My Timezone: ') : ''; |
|
338 | - |
|
339 | - } |
|
340 | - |
|
341 | - |
|
342 | - /** |
|
343 | - * @param EE_Event $item |
|
344 | - * @throws EE_Error |
|
345 | - */ |
|
346 | - public function column_reg_begins(EE_Event $item) |
|
347 | - { |
|
348 | - $reg_start = $item->get_ticket_with_earliest_start_time(); |
|
349 | - echo ! empty($reg_start) ? $reg_start->get_i18n_datetime('TKT_start_date') : __('No Tickets have been setup for this Event', |
|
350 | - 'event_espresso'); |
|
351 | - //display in user's timezone? |
|
352 | - echo ! empty($reg_start) ? $reg_start->display_in_my_timezone('TKT_start_date', 'get_i18n_datetime', '', |
|
353 | - 'My Timezone: ') : '';/**/ |
|
354 | - } |
|
355 | - |
|
356 | - |
|
357 | - /** |
|
358 | - * @param EE_Event $item |
|
359 | - * @return int|string |
|
360 | - */ |
|
361 | - public function column_attendees(EE_Event $item) |
|
362 | - { |
|
363 | - $attendees_query_args = array( |
|
364 | - 'action' => 'default', |
|
365 | - 'event_id' => $item->ID(), |
|
366 | - ); |
|
367 | - $attendees_link = EE_Admin_Page::add_query_args_and_nonce($attendees_query_args, REG_ADMIN_URL); |
|
368 | - $registered_attendees = EEM_Registration::instance()->get_event_registration_count($item->ID()); |
|
369 | - return EE_Registry::instance()->CAP->current_user_can('ee_read_registration', |
|
370 | - 'espresso_registrations_view_registration', |
|
371 | - $item->ID()) ? '<a href="' . $attendees_link . '">' . $registered_attendees . '</a>' : $registered_attendees; |
|
372 | - } |
|
373 | - |
|
374 | - |
|
375 | - /** |
|
376 | - * @param EE_Event $item |
|
377 | - * @return float |
|
378 | - */ |
|
379 | - public function column_tkts_sold(EE_Event $item) |
|
380 | - { |
|
381 | - return EEM_Ticket::instance()->sum(array(array('Datetime.EVT_ID' => $item->ID())), 'TKT_sold'); |
|
382 | - } |
|
383 | - |
|
384 | - |
|
385 | - /** |
|
386 | - * @param EE_Event $item |
|
387 | - * @return string |
|
388 | - */ |
|
389 | - public function column_actions(EE_Event $item) |
|
390 | - { |
|
391 | - //todo: remove when attendees is active |
|
392 | - if (! defined('REG_ADMIN_URL')) { |
|
393 | - define('REG_ADMIN_URL', EVENTS_ADMIN_URL); |
|
394 | - } |
|
395 | - $actionlinks = array(); |
|
396 | - |
|
397 | - $view_link = get_permalink($item->ID()); |
|
398 | - |
|
399 | - $actionlinks[] = '<a href="' . $view_link . '" title="' . esc_attr__('View Event', |
|
400 | - 'event_espresso') . '" target="_blank">'; |
|
401 | - $actionlinks[] = '<div class="dashicons dashicons-search"></div></a>'; |
|
402 | - |
|
403 | - if (EE_Registry::instance()->CAP->current_user_can('ee_edit_event', 'espresso_events_edit', $item->ID())) { |
|
404 | - $edit_query_args = array( |
|
405 | - 'action' => 'edit', |
|
406 | - 'post' => $item->ID(), |
|
407 | - ); |
|
408 | - $edit_link = EE_Admin_Page::add_query_args_and_nonce($edit_query_args, EVENTS_ADMIN_URL); |
|
409 | - $actionlinks[] = '<a href="' . $edit_link . '" title="' . esc_attr__('Edit Event', |
|
410 | - 'event_espresso') . '"><div class="ee-icon ee-icon-calendar-edit"></div></a>'; |
|
411 | - } |
|
412 | - |
|
413 | - if (EE_Registry::instance()->CAP->current_user_can('ee_read_registration', |
|
414 | - 'espresso_registrations_view_registration', $item->ID())) { |
|
415 | - $attendees_query_args = array( |
|
416 | - 'action' => 'default', |
|
417 | - 'event_id' => $item->ID(), |
|
418 | - ); |
|
419 | - $attendees_link = EE_Admin_Page::add_query_args_and_nonce($attendees_query_args, REG_ADMIN_URL); |
|
420 | - $actionlinks[] = '<a href="' . $attendees_link . '" title="' . esc_attr__('View Registrants', |
|
421 | - 'event_espresso') . '"><div class="dashicons dashicons-groups"></div></a>'; |
|
422 | - } |
|
423 | - |
|
424 | - $actionlinks = apply_filters('FHEE__Events_Admin_List_Table__column_actions__action_links', $actionlinks, |
|
425 | - $item); |
|
426 | - |
|
427 | - return $this->_action_string(implode("\n\t", $actionlinks), $item, 'div'); |
|
428 | - } |
|
29 | + /** |
|
30 | + * @var EE_Datetime |
|
31 | + */ |
|
32 | + private $_dtt; |
|
33 | + |
|
34 | + |
|
35 | + /** |
|
36 | + * Events_Admin_List_Table constructor. |
|
37 | + * |
|
38 | + * @param EE_Admin_Page $admin_page |
|
39 | + */ |
|
40 | + public function __construct($admin_page) |
|
41 | + { |
|
42 | + parent::__construct($admin_page); |
|
43 | + require_once(EE_HELPERS . 'EEH_DTT_Helper.helper.php'); |
|
44 | + } |
|
45 | + |
|
46 | + |
|
47 | + /** |
|
48 | + * Initial setup of data properties for the list table. |
|
49 | + */ |
|
50 | + protected function _setup_data() |
|
51 | + { |
|
52 | + $this->_data = $this->_admin_page->get_events($this->_per_page, $this->_current_page); |
|
53 | + $this->_all_data_count = $this->_admin_page->get_events(0, 0, true); |
|
54 | + } |
|
55 | + |
|
56 | + |
|
57 | + /** |
|
58 | + * Set up of additional properties for the list table. |
|
59 | + */ |
|
60 | + protected function _set_properties() |
|
61 | + { |
|
62 | + $this->_wp_list_args = array( |
|
63 | + 'singular' => __('event', 'event_espresso'), |
|
64 | + 'plural' => __('events', 'event_espresso'), |
|
65 | + 'ajax' => true, //for now |
|
66 | + 'screen' => $this->_admin_page->get_current_screen()->id, |
|
67 | + ); |
|
68 | + |
|
69 | + |
|
70 | + $this->_columns = array( |
|
71 | + 'cb' => '<input type="checkbox" />', |
|
72 | + 'id' => __('ID', 'event_espresso'), |
|
73 | + 'name' => __('Name', 'event_espresso'), |
|
74 | + 'author' => __('Author', 'event_espresso'), |
|
75 | + 'venue' => __('Venue', 'event_espresso'), |
|
76 | + 'start_date_time' => __('Event Start', 'event_espresso'), |
|
77 | + 'reg_begins' => __('On Sale', 'event_espresso'), |
|
78 | + 'attendees' => '<span class="dashicons dashicons-groups ee-icon-color-ee-green ee-icon-size-20"></span>', |
|
79 | + //'tkts_sold' => __('Tickets Sold', 'event_espresso'), |
|
80 | + 'actions' => __('Actions', 'event_espresso'), |
|
81 | + ); |
|
82 | + |
|
83 | + |
|
84 | + $this->_sortable_columns = array( |
|
85 | + 'id' => array('EVT_ID' => true), |
|
86 | + 'name' => array('EVT_name' => false), |
|
87 | + 'author' => array('EVT_wp_user' => false), |
|
88 | + 'venue' => array('Venue.VNU_name' => false), |
|
89 | + 'start_date_time' => array('Datetime.DTT_EVT_start' => false), |
|
90 | + 'reg_begins' => array('Datetime.Ticket.TKT_start_date' => false), |
|
91 | + ); |
|
92 | + |
|
93 | + $this->_primary_column = 'id'; |
|
94 | + |
|
95 | + $this->_hidden_columns = array('author'); |
|
96 | + } |
|
97 | + |
|
98 | + |
|
99 | + /** |
|
100 | + * @return array |
|
101 | + */ |
|
102 | + protected function _get_table_filters() |
|
103 | + { |
|
104 | + return array(); //no filters with decaf |
|
105 | + } |
|
106 | + |
|
107 | + |
|
108 | + /** |
|
109 | + * Setup of views properties. |
|
110 | + */ |
|
111 | + protected function _add_view_counts() |
|
112 | + { |
|
113 | + $this->_views['all']['count'] = $this->_admin_page->total_events(); |
|
114 | + $this->_views['draft']['count'] = $this->_admin_page->total_events_draft(); |
|
115 | + if (EE_Registry::instance()->CAP->current_user_can('ee_delete_events', 'espresso_events_trash_events')) { |
|
116 | + $this->_views['trash']['count'] = $this->_admin_page->total_trashed_events(); |
|
117 | + } |
|
118 | + } |
|
119 | + |
|
120 | + |
|
121 | + /** |
|
122 | + * @param EE_Event $item |
|
123 | + * @return string |
|
124 | + */ |
|
125 | + protected function _get_row_class($item) |
|
126 | + { |
|
127 | + $class = parent::_get_row_class($item); |
|
128 | + //add status class |
|
129 | + $class .= $item instanceof EE_Event ? ' ee-status-strip event-status-' . $item->get_active_status() : ''; |
|
130 | + if ($this->_has_checkbox_column) { |
|
131 | + $class .= ' has-checkbox-column'; |
|
132 | + } |
|
133 | + return $class; |
|
134 | + } |
|
135 | + |
|
136 | + |
|
137 | + /** |
|
138 | + * @param EE_Event $item |
|
139 | + * @return string |
|
140 | + */ |
|
141 | + public function column_status(EE_Event $item) |
|
142 | + { |
|
143 | + return '<span class="ee-status-strip ee-status-strip-td event-status-' . $item->get_active_status() . '"></span>'; |
|
144 | + }/**/ |
|
145 | + |
|
146 | + |
|
147 | + /** |
|
148 | + * @param EE_Event $item |
|
149 | + * @return string |
|
150 | + */ |
|
151 | + public function column_cb($item) |
|
152 | + { |
|
153 | + if (! $item instanceof EE_Event) { |
|
154 | + return ''; |
|
155 | + } |
|
156 | + $this->_dtt = $item->primary_datetime(); //set this for use in other columns |
|
157 | + |
|
158 | + //does event have any attached registrations? |
|
159 | + $regs = $item->count_related('Registration'); |
|
160 | + return $regs > 0 && $this->_view == 'trash' ? '<span class="ee-lock-icon"></span>' : sprintf( |
|
161 | + '<input type="checkbox" name="EVT_IDs[]" value="%s" />', $item->ID() |
|
162 | + ); |
|
163 | + } |
|
164 | + |
|
165 | + |
|
166 | + /** |
|
167 | + * @param EE_Event $item |
|
168 | + * @return mixed|string |
|
169 | + */ |
|
170 | + public function column_id(EE_Event $item) |
|
171 | + { |
|
172 | + $content = $item->ID(); |
|
173 | + $content .= ' <span class="show-on-mobile-view-only">' . $item->name() . '</span>'; |
|
174 | + return $content; |
|
175 | + } |
|
176 | + |
|
177 | + |
|
178 | + /** |
|
179 | + * @param EE_Event $item |
|
180 | + * @return string |
|
181 | + */ |
|
182 | + public function column_name(EE_Event $item) |
|
183 | + { |
|
184 | + $edit_query_args = array( |
|
185 | + 'action' => 'edit', |
|
186 | + 'post' => $item->ID(), |
|
187 | + ); |
|
188 | + $edit_link = EE_Admin_Page::add_query_args_and_nonce($edit_query_args, EVENTS_ADMIN_URL); |
|
189 | + $actions = $this->_column_name_action_setup($item); |
|
190 | + $status = ''; //$item->status() !== 'publish' ? ' (' . $item->status() . ')' : ''; |
|
191 | + $content = '<strong><a class="row-title" href="' . $edit_link . '">' . $item->name() . '</a></strong>' . $status; |
|
192 | + $content .= '<br><span class="ee-status-text-small">' . EEH_Template::pretty_status($item->get_active_status(), |
|
193 | + false, 'sentence') . '</span>'; |
|
194 | + $content .= $this->row_actions($actions); |
|
195 | + return $content; |
|
196 | + |
|
197 | + } |
|
198 | + |
|
199 | + |
|
200 | + /** |
|
201 | + * Just a method for setting up the actions for the name column |
|
202 | + * |
|
203 | + * @param EE_Event $item |
|
204 | + * @return array array of actions |
|
205 | + */ |
|
206 | + protected function _column_name_action_setup(EE_Event $item) |
|
207 | + { |
|
208 | + //todo: remove when attendees is active |
|
209 | + if (! defined('REG_ADMIN_URL')) { |
|
210 | + define('REG_ADMIN_URL', EVENTS_ADMIN_URL); |
|
211 | + } |
|
212 | + |
|
213 | + $actions = array(); |
|
214 | + |
|
215 | + if (EE_Registry::instance()->CAP->current_user_can('ee_edit_event', 'espresso_events_edit', $item->ID())) { |
|
216 | + $edit_query_args = array( |
|
217 | + 'action' => 'edit', |
|
218 | + 'post' => $item->ID(), |
|
219 | + ); |
|
220 | + $edit_link = EE_Admin_Page::add_query_args_and_nonce($edit_query_args, EVENTS_ADMIN_URL); |
|
221 | + $actions['edit'] = '<a href="' . $edit_link . '" title="' . esc_attr__('Edit Event', |
|
222 | + 'event_espresso') . '">' . __('Edit', 'event_espresso') . '</a>'; |
|
223 | + |
|
224 | + } |
|
225 | + |
|
226 | + if (EE_Registry::instance()->CAP->current_user_can('ee_read_registration', |
|
227 | + 'espresso_registrations_view_registration', $item->ID())) { |
|
228 | + $attendees_query_args = array( |
|
229 | + 'action' => 'default', |
|
230 | + 'event_id' => $item->ID(), |
|
231 | + ); |
|
232 | + $attendees_link = EE_Admin_Page::add_query_args_and_nonce($attendees_query_args, REG_ADMIN_URL); |
|
233 | + $actions['attendees'] = '<a href="' . $attendees_link . '" title="' . esc_attr__('View Registrations', |
|
234 | + 'event_espresso') . '">' . __('Registrations', 'event_espresso') . '</a>'; |
|
235 | + } |
|
236 | + |
|
237 | + if (EE_Registry::instance()->CAP->current_user_can('ee_delete_event', 'espresso_events_trash_event', |
|
238 | + $item->ID())) { |
|
239 | + $trash_event_query_args = array( |
|
240 | + 'action' => 'trash_event', |
|
241 | + 'EVT_ID' => $item->ID(), |
|
242 | + ); |
|
243 | + $trash_event_link = EE_Admin_Page::add_query_args_and_nonce($trash_event_query_args, |
|
244 | + EVENTS_ADMIN_URL); |
|
245 | + } |
|
246 | + |
|
247 | + if (EE_Registry::instance()->CAP->current_user_can('ee_delete_event', 'espresso_events_restore_event', |
|
248 | + $item->ID())) { |
|
249 | + $restore_event_query_args = array( |
|
250 | + 'action' => 'restore_event', |
|
251 | + 'EVT_ID' => $item->ID(), |
|
252 | + ); |
|
253 | + $restore_event_link = EE_Admin_Page::add_query_args_and_nonce($restore_event_query_args, |
|
254 | + EVENTS_ADMIN_URL); |
|
255 | + } |
|
256 | + |
|
257 | + if (EE_Registry::instance()->CAP->current_user_can('ee_delete_event', 'espresso_events_delete_event', |
|
258 | + $item->ID())) { |
|
259 | + $delete_event_query_args = array( |
|
260 | + 'action' => 'delete_event', |
|
261 | + 'EVT_ID' => $item->ID(), |
|
262 | + ); |
|
263 | + $delete_event_link = EE_Admin_Page::add_query_args_and_nonce($delete_event_query_args, |
|
264 | + EVENTS_ADMIN_URL); |
|
265 | + } |
|
266 | + |
|
267 | + $view_link = get_permalink($item->ID()); |
|
268 | + |
|
269 | + $actions['view'] = '<a href="' . $view_link . '" title="' . esc_attr__('View Event', |
|
270 | + 'event_espresso') . '">' . __('View', 'event_espresso') . '</a>'; |
|
271 | + |
|
272 | + switch ($item->get('status')) { |
|
273 | + case 'trash' : |
|
274 | + if (EE_Registry::instance()->CAP->current_user_can('ee_delete_event', 'espresso_events_restore_event', |
|
275 | + $item->ID())) { |
|
276 | + $actions['restore_from_trash'] = '<a href="' . $restore_event_link . '" title="' . esc_attr__('Restore from Trash', |
|
277 | + 'event_espresso') . '">' . __('Restore from Trash', 'event_espresso') . '</a>'; |
|
278 | + } |
|
279 | + if ($item->count_related('Registration') === 0 && EE_Registry::instance()->CAP->current_user_can('ee_delete_event', |
|
280 | + 'espresso_events_delete_event', $item->ID())) { |
|
281 | + $actions['delete'] = '<a href="' . $delete_event_link . '" title="' . esc_attr__('Delete Permanently', |
|
282 | + 'event_espresso') . '">' . __('Delete Permanently', 'event_espresso') . '</a>'; |
|
283 | + } |
|
284 | + break; |
|
285 | + default : |
|
286 | + if (EE_Registry::instance()->CAP->current_user_can('ee_delete_event', 'espresso_events_trash_event', |
|
287 | + $item->ID())) { |
|
288 | + $actions['move to trash'] = '<a href="' . $trash_event_link . '" title="' . esc_attr__('Trash Event', |
|
289 | + 'event_espresso') . '">' . __('Trash', 'event_espresso') . '</a>'; |
|
290 | + } |
|
291 | + } |
|
292 | + return $actions; |
|
293 | + } |
|
294 | + |
|
295 | + |
|
296 | + /** |
|
297 | + * @param EE_Event $item |
|
298 | + * @return string |
|
299 | + */ |
|
300 | + public function column_author(EE_Event $item) |
|
301 | + { |
|
302 | + //user author info |
|
303 | + $event_author = get_userdata($item->wp_user()); |
|
304 | + $gravatar = get_avatar($item->wp_user(), '15'); |
|
305 | + //filter link |
|
306 | + $query_args = array( |
|
307 | + 'action' => 'default', |
|
308 | + 'EVT_wp_user' => $item->wp_user(), |
|
309 | + ); |
|
310 | + $filter_url = EE_Admin_Page::add_query_args_and_nonce($query_args, EVENTS_ADMIN_URL); |
|
311 | + return $gravatar . ' <a href="' . $filter_url . '" title="' . esc_attr__('Click to filter events by this author.', |
|
312 | + 'event_espresso') . '">' . $event_author->display_name . '</a>'; |
|
313 | + } |
|
314 | + |
|
315 | + |
|
316 | + /** |
|
317 | + * @param EE_Event $item |
|
318 | + * @return string |
|
319 | + */ |
|
320 | + public function column_venue(EE_Event $item) |
|
321 | + { |
|
322 | + $venue = $item->get_first_related('Venue'); |
|
323 | + return ! empty($venue) ? $venue->name() : ''; |
|
324 | + } |
|
325 | + |
|
326 | + |
|
327 | + /** |
|
328 | + * @param EE_Event $item |
|
329 | + * @throws EE_Error |
|
330 | + */ |
|
331 | + public function column_start_date_time(EE_Event $item) |
|
332 | + { |
|
333 | + echo ! empty($this->_dtt) ? $this->_dtt->get_i18n_datetime('DTT_EVT_start') : __('No Date was saved for this Event', |
|
334 | + 'event_espresso'); |
|
335 | + //display in user's timezone? |
|
336 | + echo ! empty($this->_dtt) ? $this->_dtt->display_in_my_timezone('DTT_EVT_start', 'get_i18n_datetime', '', |
|
337 | + 'My Timezone: ') : ''; |
|
338 | + |
|
339 | + } |
|
340 | + |
|
341 | + |
|
342 | + /** |
|
343 | + * @param EE_Event $item |
|
344 | + * @throws EE_Error |
|
345 | + */ |
|
346 | + public function column_reg_begins(EE_Event $item) |
|
347 | + { |
|
348 | + $reg_start = $item->get_ticket_with_earliest_start_time(); |
|
349 | + echo ! empty($reg_start) ? $reg_start->get_i18n_datetime('TKT_start_date') : __('No Tickets have been setup for this Event', |
|
350 | + 'event_espresso'); |
|
351 | + //display in user's timezone? |
|
352 | + echo ! empty($reg_start) ? $reg_start->display_in_my_timezone('TKT_start_date', 'get_i18n_datetime', '', |
|
353 | + 'My Timezone: ') : '';/**/ |
|
354 | + } |
|
355 | + |
|
356 | + |
|
357 | + /** |
|
358 | + * @param EE_Event $item |
|
359 | + * @return int|string |
|
360 | + */ |
|
361 | + public function column_attendees(EE_Event $item) |
|
362 | + { |
|
363 | + $attendees_query_args = array( |
|
364 | + 'action' => 'default', |
|
365 | + 'event_id' => $item->ID(), |
|
366 | + ); |
|
367 | + $attendees_link = EE_Admin_Page::add_query_args_and_nonce($attendees_query_args, REG_ADMIN_URL); |
|
368 | + $registered_attendees = EEM_Registration::instance()->get_event_registration_count($item->ID()); |
|
369 | + return EE_Registry::instance()->CAP->current_user_can('ee_read_registration', |
|
370 | + 'espresso_registrations_view_registration', |
|
371 | + $item->ID()) ? '<a href="' . $attendees_link . '">' . $registered_attendees . '</a>' : $registered_attendees; |
|
372 | + } |
|
373 | + |
|
374 | + |
|
375 | + /** |
|
376 | + * @param EE_Event $item |
|
377 | + * @return float |
|
378 | + */ |
|
379 | + public function column_tkts_sold(EE_Event $item) |
|
380 | + { |
|
381 | + return EEM_Ticket::instance()->sum(array(array('Datetime.EVT_ID' => $item->ID())), 'TKT_sold'); |
|
382 | + } |
|
383 | + |
|
384 | + |
|
385 | + /** |
|
386 | + * @param EE_Event $item |
|
387 | + * @return string |
|
388 | + */ |
|
389 | + public function column_actions(EE_Event $item) |
|
390 | + { |
|
391 | + //todo: remove when attendees is active |
|
392 | + if (! defined('REG_ADMIN_URL')) { |
|
393 | + define('REG_ADMIN_URL', EVENTS_ADMIN_URL); |
|
394 | + } |
|
395 | + $actionlinks = array(); |
|
396 | + |
|
397 | + $view_link = get_permalink($item->ID()); |
|
398 | + |
|
399 | + $actionlinks[] = '<a href="' . $view_link . '" title="' . esc_attr__('View Event', |
|
400 | + 'event_espresso') . '" target="_blank">'; |
|
401 | + $actionlinks[] = '<div class="dashicons dashicons-search"></div></a>'; |
|
402 | + |
|
403 | + if (EE_Registry::instance()->CAP->current_user_can('ee_edit_event', 'espresso_events_edit', $item->ID())) { |
|
404 | + $edit_query_args = array( |
|
405 | + 'action' => 'edit', |
|
406 | + 'post' => $item->ID(), |
|
407 | + ); |
|
408 | + $edit_link = EE_Admin_Page::add_query_args_and_nonce($edit_query_args, EVENTS_ADMIN_URL); |
|
409 | + $actionlinks[] = '<a href="' . $edit_link . '" title="' . esc_attr__('Edit Event', |
|
410 | + 'event_espresso') . '"><div class="ee-icon ee-icon-calendar-edit"></div></a>'; |
|
411 | + } |
|
412 | + |
|
413 | + if (EE_Registry::instance()->CAP->current_user_can('ee_read_registration', |
|
414 | + 'espresso_registrations_view_registration', $item->ID())) { |
|
415 | + $attendees_query_args = array( |
|
416 | + 'action' => 'default', |
|
417 | + 'event_id' => $item->ID(), |
|
418 | + ); |
|
419 | + $attendees_link = EE_Admin_Page::add_query_args_and_nonce($attendees_query_args, REG_ADMIN_URL); |
|
420 | + $actionlinks[] = '<a href="' . $attendees_link . '" title="' . esc_attr__('View Registrants', |
|
421 | + 'event_espresso') . '"><div class="dashicons dashicons-groups"></div></a>'; |
|
422 | + } |
|
423 | + |
|
424 | + $actionlinks = apply_filters('FHEE__Events_Admin_List_Table__column_actions__action_links', $actionlinks, |
|
425 | + $item); |
|
426 | + |
|
427 | + return $this->_action_string(implode("\n\t", $actionlinks), $item, 'div'); |
|
428 | + } |
|
429 | 429 | |
430 | 430 | |
431 | 431 | } |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if (! defined('EVENT_ESPRESSO_VERSION')) { |
|
2 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
3 | 3 | exit('NO direct script access allowed'); |
4 | 4 | } |
5 | 5 | |
@@ -40,7 +40,7 @@ discard block |
||
40 | 40 | public function __construct($admin_page) |
41 | 41 | { |
42 | 42 | parent::__construct($admin_page); |
43 | - require_once(EE_HELPERS . 'EEH_DTT_Helper.helper.php'); |
|
43 | + require_once(EE_HELPERS.'EEH_DTT_Helper.helper.php'); |
|
44 | 44 | } |
45 | 45 | |
46 | 46 | |
@@ -126,7 +126,7 @@ discard block |
||
126 | 126 | { |
127 | 127 | $class = parent::_get_row_class($item); |
128 | 128 | //add status class |
129 | - $class .= $item instanceof EE_Event ? ' ee-status-strip event-status-' . $item->get_active_status() : ''; |
|
129 | + $class .= $item instanceof EE_Event ? ' ee-status-strip event-status-'.$item->get_active_status() : ''; |
|
130 | 130 | if ($this->_has_checkbox_column) { |
131 | 131 | $class .= ' has-checkbox-column'; |
132 | 132 | } |
@@ -140,7 +140,7 @@ discard block |
||
140 | 140 | */ |
141 | 141 | public function column_status(EE_Event $item) |
142 | 142 | { |
143 | - return '<span class="ee-status-strip ee-status-strip-td event-status-' . $item->get_active_status() . '"></span>'; |
|
143 | + return '<span class="ee-status-strip ee-status-strip-td event-status-'.$item->get_active_status().'"></span>'; |
|
144 | 144 | }/**/ |
145 | 145 | |
146 | 146 | |
@@ -150,7 +150,7 @@ discard block |
||
150 | 150 | */ |
151 | 151 | public function column_cb($item) |
152 | 152 | { |
153 | - if (! $item instanceof EE_Event) { |
|
153 | + if ( ! $item instanceof EE_Event) { |
|
154 | 154 | return ''; |
155 | 155 | } |
156 | 156 | $this->_dtt = $item->primary_datetime(); //set this for use in other columns |
@@ -170,7 +170,7 @@ discard block |
||
170 | 170 | public function column_id(EE_Event $item) |
171 | 171 | { |
172 | 172 | $content = $item->ID(); |
173 | - $content .= ' <span class="show-on-mobile-view-only">' . $item->name() . '</span>'; |
|
173 | + $content .= ' <span class="show-on-mobile-view-only">'.$item->name().'</span>'; |
|
174 | 174 | return $content; |
175 | 175 | } |
176 | 176 | |
@@ -188,9 +188,9 @@ discard block |
||
188 | 188 | $edit_link = EE_Admin_Page::add_query_args_and_nonce($edit_query_args, EVENTS_ADMIN_URL); |
189 | 189 | $actions = $this->_column_name_action_setup($item); |
190 | 190 | $status = ''; //$item->status() !== 'publish' ? ' (' . $item->status() . ')' : ''; |
191 | - $content = '<strong><a class="row-title" href="' . $edit_link . '">' . $item->name() . '</a></strong>' . $status; |
|
192 | - $content .= '<br><span class="ee-status-text-small">' . EEH_Template::pretty_status($item->get_active_status(), |
|
193 | - false, 'sentence') . '</span>'; |
|
191 | + $content = '<strong><a class="row-title" href="'.$edit_link.'">'.$item->name().'</a></strong>'.$status; |
|
192 | + $content .= '<br><span class="ee-status-text-small">'.EEH_Template::pretty_status($item->get_active_status(), |
|
193 | + false, 'sentence').'</span>'; |
|
194 | 194 | $content .= $this->row_actions($actions); |
195 | 195 | return $content; |
196 | 196 | |
@@ -206,7 +206,7 @@ discard block |
||
206 | 206 | protected function _column_name_action_setup(EE_Event $item) |
207 | 207 | { |
208 | 208 | //todo: remove when attendees is active |
209 | - if (! defined('REG_ADMIN_URL')) { |
|
209 | + if ( ! defined('REG_ADMIN_URL')) { |
|
210 | 210 | define('REG_ADMIN_URL', EVENTS_ADMIN_URL); |
211 | 211 | } |
212 | 212 | |
@@ -218,8 +218,8 @@ discard block |
||
218 | 218 | 'post' => $item->ID(), |
219 | 219 | ); |
220 | 220 | $edit_link = EE_Admin_Page::add_query_args_and_nonce($edit_query_args, EVENTS_ADMIN_URL); |
221 | - $actions['edit'] = '<a href="' . $edit_link . '" title="' . esc_attr__('Edit Event', |
|
222 | - 'event_espresso') . '">' . __('Edit', 'event_espresso') . '</a>'; |
|
221 | + $actions['edit'] = '<a href="'.$edit_link.'" title="'.esc_attr__('Edit Event', |
|
222 | + 'event_espresso').'">'.__('Edit', 'event_espresso').'</a>'; |
|
223 | 223 | |
224 | 224 | } |
225 | 225 | |
@@ -230,8 +230,8 @@ discard block |
||
230 | 230 | 'event_id' => $item->ID(), |
231 | 231 | ); |
232 | 232 | $attendees_link = EE_Admin_Page::add_query_args_and_nonce($attendees_query_args, REG_ADMIN_URL); |
233 | - $actions['attendees'] = '<a href="' . $attendees_link . '" title="' . esc_attr__('View Registrations', |
|
234 | - 'event_espresso') . '">' . __('Registrations', 'event_espresso') . '</a>'; |
|
233 | + $actions['attendees'] = '<a href="'.$attendees_link.'" title="'.esc_attr__('View Registrations', |
|
234 | + 'event_espresso').'">'.__('Registrations', 'event_espresso').'</a>'; |
|
235 | 235 | } |
236 | 236 | |
237 | 237 | if (EE_Registry::instance()->CAP->current_user_can('ee_delete_event', 'espresso_events_trash_event', |
@@ -240,7 +240,7 @@ discard block |
||
240 | 240 | 'action' => 'trash_event', |
241 | 241 | 'EVT_ID' => $item->ID(), |
242 | 242 | ); |
243 | - $trash_event_link = EE_Admin_Page::add_query_args_and_nonce($trash_event_query_args, |
|
243 | + $trash_event_link = EE_Admin_Page::add_query_args_and_nonce($trash_event_query_args, |
|
244 | 244 | EVENTS_ADMIN_URL); |
245 | 245 | } |
246 | 246 | |
@@ -250,7 +250,7 @@ discard block |
||
250 | 250 | 'action' => 'restore_event', |
251 | 251 | 'EVT_ID' => $item->ID(), |
252 | 252 | ); |
253 | - $restore_event_link = EE_Admin_Page::add_query_args_and_nonce($restore_event_query_args, |
|
253 | + $restore_event_link = EE_Admin_Page::add_query_args_and_nonce($restore_event_query_args, |
|
254 | 254 | EVENTS_ADMIN_URL); |
255 | 255 | } |
256 | 256 | |
@@ -260,33 +260,33 @@ discard block |
||
260 | 260 | 'action' => 'delete_event', |
261 | 261 | 'EVT_ID' => $item->ID(), |
262 | 262 | ); |
263 | - $delete_event_link = EE_Admin_Page::add_query_args_and_nonce($delete_event_query_args, |
|
263 | + $delete_event_link = EE_Admin_Page::add_query_args_and_nonce($delete_event_query_args, |
|
264 | 264 | EVENTS_ADMIN_URL); |
265 | 265 | } |
266 | 266 | |
267 | 267 | $view_link = get_permalink($item->ID()); |
268 | 268 | |
269 | - $actions['view'] = '<a href="' . $view_link . '" title="' . esc_attr__('View Event', |
|
270 | - 'event_espresso') . '">' . __('View', 'event_espresso') . '</a>'; |
|
269 | + $actions['view'] = '<a href="'.$view_link.'" title="'.esc_attr__('View Event', |
|
270 | + 'event_espresso').'">'.__('View', 'event_espresso').'</a>'; |
|
271 | 271 | |
272 | 272 | switch ($item->get('status')) { |
273 | 273 | case 'trash' : |
274 | 274 | if (EE_Registry::instance()->CAP->current_user_can('ee_delete_event', 'espresso_events_restore_event', |
275 | 275 | $item->ID())) { |
276 | - $actions['restore_from_trash'] = '<a href="' . $restore_event_link . '" title="' . esc_attr__('Restore from Trash', |
|
277 | - 'event_espresso') . '">' . __('Restore from Trash', 'event_espresso') . '</a>'; |
|
276 | + $actions['restore_from_trash'] = '<a href="'.$restore_event_link.'" title="'.esc_attr__('Restore from Trash', |
|
277 | + 'event_espresso').'">'.__('Restore from Trash', 'event_espresso').'</a>'; |
|
278 | 278 | } |
279 | 279 | if ($item->count_related('Registration') === 0 && EE_Registry::instance()->CAP->current_user_can('ee_delete_event', |
280 | 280 | 'espresso_events_delete_event', $item->ID())) { |
281 | - $actions['delete'] = '<a href="' . $delete_event_link . '" title="' . esc_attr__('Delete Permanently', |
|
282 | - 'event_espresso') . '">' . __('Delete Permanently', 'event_espresso') . '</a>'; |
|
281 | + $actions['delete'] = '<a href="'.$delete_event_link.'" title="'.esc_attr__('Delete Permanently', |
|
282 | + 'event_espresso').'">'.__('Delete Permanently', 'event_espresso').'</a>'; |
|
283 | 283 | } |
284 | 284 | break; |
285 | 285 | default : |
286 | 286 | if (EE_Registry::instance()->CAP->current_user_can('ee_delete_event', 'espresso_events_trash_event', |
287 | 287 | $item->ID())) { |
288 | - $actions['move to trash'] = '<a href="' . $trash_event_link . '" title="' . esc_attr__('Trash Event', |
|
289 | - 'event_espresso') . '">' . __('Trash', 'event_espresso') . '</a>'; |
|
288 | + $actions['move to trash'] = '<a href="'.$trash_event_link.'" title="'.esc_attr__('Trash Event', |
|
289 | + 'event_espresso').'">'.__('Trash', 'event_espresso').'</a>'; |
|
290 | 290 | } |
291 | 291 | } |
292 | 292 | return $actions; |
@@ -308,8 +308,8 @@ discard block |
||
308 | 308 | 'EVT_wp_user' => $item->wp_user(), |
309 | 309 | ); |
310 | 310 | $filter_url = EE_Admin_Page::add_query_args_and_nonce($query_args, EVENTS_ADMIN_URL); |
311 | - return $gravatar . ' <a href="' . $filter_url . '" title="' . esc_attr__('Click to filter events by this author.', |
|
312 | - 'event_espresso') . '">' . $event_author->display_name . '</a>'; |
|
311 | + return $gravatar.' <a href="'.$filter_url.'" title="'.esc_attr__('Click to filter events by this author.', |
|
312 | + 'event_espresso').'">'.$event_author->display_name.'</a>'; |
|
313 | 313 | } |
314 | 314 | |
315 | 315 | |
@@ -350,7 +350,7 @@ discard block |
||
350 | 350 | 'event_espresso'); |
351 | 351 | //display in user's timezone? |
352 | 352 | echo ! empty($reg_start) ? $reg_start->display_in_my_timezone('TKT_start_date', 'get_i18n_datetime', '', |
353 | - 'My Timezone: ') : '';/**/ |
|
353 | + 'My Timezone: ') : ''; /**/ |
|
354 | 354 | } |
355 | 355 | |
356 | 356 | |
@@ -368,7 +368,7 @@ discard block |
||
368 | 368 | $registered_attendees = EEM_Registration::instance()->get_event_registration_count($item->ID()); |
369 | 369 | return EE_Registry::instance()->CAP->current_user_can('ee_read_registration', |
370 | 370 | 'espresso_registrations_view_registration', |
371 | - $item->ID()) ? '<a href="' . $attendees_link . '">' . $registered_attendees . '</a>' : $registered_attendees; |
|
371 | + $item->ID()) ? '<a href="'.$attendees_link.'">'.$registered_attendees.'</a>' : $registered_attendees; |
|
372 | 372 | } |
373 | 373 | |
374 | 374 | |
@@ -389,15 +389,15 @@ discard block |
||
389 | 389 | public function column_actions(EE_Event $item) |
390 | 390 | { |
391 | 391 | //todo: remove when attendees is active |
392 | - if (! defined('REG_ADMIN_URL')) { |
|
392 | + if ( ! defined('REG_ADMIN_URL')) { |
|
393 | 393 | define('REG_ADMIN_URL', EVENTS_ADMIN_URL); |
394 | 394 | } |
395 | 395 | $actionlinks = array(); |
396 | 396 | |
397 | 397 | $view_link = get_permalink($item->ID()); |
398 | 398 | |
399 | - $actionlinks[] = '<a href="' . $view_link . '" title="' . esc_attr__('View Event', |
|
400 | - 'event_espresso') . '" target="_blank">'; |
|
399 | + $actionlinks[] = '<a href="'.$view_link.'" title="'.esc_attr__('View Event', |
|
400 | + 'event_espresso').'" target="_blank">'; |
|
401 | 401 | $actionlinks[] = '<div class="dashicons dashicons-search"></div></a>'; |
402 | 402 | |
403 | 403 | if (EE_Registry::instance()->CAP->current_user_can('ee_edit_event', 'espresso_events_edit', $item->ID())) { |
@@ -406,8 +406,8 @@ discard block |
||
406 | 406 | 'post' => $item->ID(), |
407 | 407 | ); |
408 | 408 | $edit_link = EE_Admin_Page::add_query_args_and_nonce($edit_query_args, EVENTS_ADMIN_URL); |
409 | - $actionlinks[] = '<a href="' . $edit_link . '" title="' . esc_attr__('Edit Event', |
|
410 | - 'event_espresso') . '"><div class="ee-icon ee-icon-calendar-edit"></div></a>'; |
|
409 | + $actionlinks[] = '<a href="'.$edit_link.'" title="'.esc_attr__('Edit Event', |
|
410 | + 'event_espresso').'"><div class="ee-icon ee-icon-calendar-edit"></div></a>'; |
|
411 | 411 | } |
412 | 412 | |
413 | 413 | if (EE_Registry::instance()->CAP->current_user_can('ee_read_registration', |
@@ -417,8 +417,8 @@ discard block |
||
417 | 417 | 'event_id' => $item->ID(), |
418 | 418 | ); |
419 | 419 | $attendees_link = EE_Admin_Page::add_query_args_and_nonce($attendees_query_args, REG_ADMIN_URL); |
420 | - $actionlinks[] = '<a href="' . $attendees_link . '" title="' . esc_attr__('View Registrants', |
|
421 | - 'event_espresso') . '"><div class="dashicons dashicons-groups"></div></a>'; |
|
420 | + $actionlinks[] = '<a href="'.$attendees_link.'" title="'.esc_attr__('View Registrants', |
|
421 | + 'event_espresso').'"><div class="dashicons dashicons-groups"></div></a>'; |
|
422 | 422 | } |
423 | 423 | |
424 | 424 | $actionlinks = apply_filters('FHEE__Events_Admin_List_Table__column_actions__action_links', $actionlinks, |
@@ -17,243 +17,243 @@ |
||
17 | 17 | final class EE_Module_Request_Router implements InterminableInterface |
18 | 18 | { |
19 | 19 | |
20 | - /** |
|
21 | - * @var array $_previous_routes |
|
22 | - */ |
|
23 | - private static $_previous_routes = array(); |
|
20 | + /** |
|
21 | + * @var array $_previous_routes |
|
22 | + */ |
|
23 | + private static $_previous_routes = array(); |
|
24 | 24 | |
25 | - /** |
|
26 | - * @var WP_Query $WP_Query |
|
27 | - */ |
|
28 | - public $WP_Query; |
|
25 | + /** |
|
26 | + * @var WP_Query $WP_Query |
|
27 | + */ |
|
28 | + public $WP_Query; |
|
29 | 29 | |
30 | 30 | |
31 | 31 | |
32 | - /** |
|
33 | - * EE_Module_Request_Router constructor. |
|
34 | - */ |
|
35 | - public function __construct() |
|
36 | - { |
|
37 | - } |
|
32 | + /** |
|
33 | + * EE_Module_Request_Router constructor. |
|
34 | + */ |
|
35 | + public function __construct() |
|
36 | + { |
|
37 | + } |
|
38 | 38 | |
39 | 39 | |
40 | 40 | |
41 | - /** |
|
42 | - * on the first call to this method, it checks the EE_Request_Handler for a "route" |
|
43 | - * on subsequent calls to this method, |
|
44 | - * instead of checking the EE_Request_Handler for a route, it checks the previous routes array, |
|
45 | - * and checks if the last called route has any forwarding routes registered for it |
|
46 | - * |
|
47 | - * @param WP_Query $WP_Query |
|
48 | - * @return NULL|string |
|
49 | - * @throws EE_Error |
|
50 | - * @throws ReflectionException |
|
51 | - */ |
|
52 | - public function get_route(WP_Query $WP_Query) |
|
53 | - { |
|
54 | - $this->WP_Query = $WP_Query; |
|
55 | - // assume this if first route being called |
|
56 | - $previous_route = false; |
|
57 | - // but is it really ??? |
|
58 | - if (! empty(self::$_previous_routes)) { |
|
59 | - // get last run route |
|
60 | - $previous_routes = array_values(self::$_previous_routes); |
|
61 | - $previous_route = array_pop($previous_routes); |
|
62 | - } |
|
63 | - // has another route already been run ? |
|
64 | - if ($previous_route) { |
|
65 | - // check if forwarding has been set |
|
66 | - $current_route = $this->get_forward($previous_route); |
|
67 | - try { |
|
68 | - //check for recursive forwarding |
|
69 | - if (isset(self::$_previous_routes[$current_route])) { |
|
70 | - throw new EE_Error( |
|
71 | - sprintf( |
|
72 | - __( |
|
73 | - 'An error occurred. The %s route has already been called, and therefore can not be forwarded to, because an infinite loop would be created and break the interweb.', |
|
74 | - 'event_espresso' |
|
75 | - ), |
|
76 | - $current_route |
|
77 | - ) |
|
78 | - ); |
|
79 | - } |
|
80 | - } catch (EE_Error $e) { |
|
81 | - $e->get_error(); |
|
82 | - return null; |
|
83 | - } |
|
84 | - } else { |
|
85 | - // first route called |
|
86 | - $current_route = null; |
|
87 | - // grab all routes |
|
88 | - $routes = EE_Config::get_routes(); |
|
89 | - //d( $routes ); |
|
90 | - foreach ($routes as $key => $route) { |
|
91 | - // check request for module route |
|
92 | - if (EE_Registry::instance()->REQ->is_set($key)) { |
|
93 | - //echo '<b style="color:#2EA2CC;">key : <span style="color:#E76700">' . $key . '</span></b><br />'; |
|
94 | - $current_route = sanitize_text_field(EE_Registry::instance()->REQ->get($key)); |
|
95 | - if ($current_route) { |
|
96 | - $current_route = array($key, $current_route); |
|
97 | - //echo '<b style="color:#2EA2CC;">current_route : <span style="color:#E76700">' . $current_route . '</span></b><br />'; |
|
98 | - break; |
|
99 | - } |
|
100 | - } |
|
101 | - } |
|
102 | - } |
|
103 | - // sorry, but I can't read what you route ! |
|
104 | - if (empty($current_route)) { |
|
105 | - return null; |
|
106 | - } |
|
107 | - //add route to previous routes array |
|
108 | - self::$_previous_routes[] = $current_route; |
|
109 | - return $current_route; |
|
110 | - } |
|
41 | + /** |
|
42 | + * on the first call to this method, it checks the EE_Request_Handler for a "route" |
|
43 | + * on subsequent calls to this method, |
|
44 | + * instead of checking the EE_Request_Handler for a route, it checks the previous routes array, |
|
45 | + * and checks if the last called route has any forwarding routes registered for it |
|
46 | + * |
|
47 | + * @param WP_Query $WP_Query |
|
48 | + * @return NULL|string |
|
49 | + * @throws EE_Error |
|
50 | + * @throws ReflectionException |
|
51 | + */ |
|
52 | + public function get_route(WP_Query $WP_Query) |
|
53 | + { |
|
54 | + $this->WP_Query = $WP_Query; |
|
55 | + // assume this if first route being called |
|
56 | + $previous_route = false; |
|
57 | + // but is it really ??? |
|
58 | + if (! empty(self::$_previous_routes)) { |
|
59 | + // get last run route |
|
60 | + $previous_routes = array_values(self::$_previous_routes); |
|
61 | + $previous_route = array_pop($previous_routes); |
|
62 | + } |
|
63 | + // has another route already been run ? |
|
64 | + if ($previous_route) { |
|
65 | + // check if forwarding has been set |
|
66 | + $current_route = $this->get_forward($previous_route); |
|
67 | + try { |
|
68 | + //check for recursive forwarding |
|
69 | + if (isset(self::$_previous_routes[$current_route])) { |
|
70 | + throw new EE_Error( |
|
71 | + sprintf( |
|
72 | + __( |
|
73 | + 'An error occurred. The %s route has already been called, and therefore can not be forwarded to, because an infinite loop would be created and break the interweb.', |
|
74 | + 'event_espresso' |
|
75 | + ), |
|
76 | + $current_route |
|
77 | + ) |
|
78 | + ); |
|
79 | + } |
|
80 | + } catch (EE_Error $e) { |
|
81 | + $e->get_error(); |
|
82 | + return null; |
|
83 | + } |
|
84 | + } else { |
|
85 | + // first route called |
|
86 | + $current_route = null; |
|
87 | + // grab all routes |
|
88 | + $routes = EE_Config::get_routes(); |
|
89 | + //d( $routes ); |
|
90 | + foreach ($routes as $key => $route) { |
|
91 | + // check request for module route |
|
92 | + if (EE_Registry::instance()->REQ->is_set($key)) { |
|
93 | + //echo '<b style="color:#2EA2CC;">key : <span style="color:#E76700">' . $key . '</span></b><br />'; |
|
94 | + $current_route = sanitize_text_field(EE_Registry::instance()->REQ->get($key)); |
|
95 | + if ($current_route) { |
|
96 | + $current_route = array($key, $current_route); |
|
97 | + //echo '<b style="color:#2EA2CC;">current_route : <span style="color:#E76700">' . $current_route . '</span></b><br />'; |
|
98 | + break; |
|
99 | + } |
|
100 | + } |
|
101 | + } |
|
102 | + } |
|
103 | + // sorry, but I can't read what you route ! |
|
104 | + if (empty($current_route)) { |
|
105 | + return null; |
|
106 | + } |
|
107 | + //add route to previous routes array |
|
108 | + self::$_previous_routes[] = $current_route; |
|
109 | + return $current_route; |
|
110 | + } |
|
111 | 111 | |
112 | 112 | |
113 | 113 | |
114 | - /** |
|
115 | - * this method simply takes a valid route, and resolves what module class method the route points to |
|
116 | - * |
|
117 | - * @param string $key |
|
118 | - * @param string $current_route |
|
119 | - * @return mixed EED_Module | boolean |
|
120 | - * @throws EE_Error |
|
121 | - * @throws ReflectionException |
|
122 | - */ |
|
123 | - public function resolve_route($key, $current_route) |
|
124 | - { |
|
125 | - // get module method that route has been mapped to |
|
126 | - $module_method = EE_Config::get_route($current_route, $key); |
|
127 | - //EEH_Debug_Tools::printr( $module_method, '$module_method <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span>', 'auto' ); |
|
128 | - // verify result was returned |
|
129 | - if (empty($module_method)) { |
|
130 | - $msg = sprintf( |
|
131 | - __('The requested route %s could not be mapped to any registered modules.', 'event_espresso'), |
|
132 | - $current_route |
|
133 | - ); |
|
134 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
135 | - return false; |
|
136 | - } |
|
137 | - // verify that result is an array |
|
138 | - if (! is_array($module_method)) { |
|
139 | - $msg = sprintf(__('The %s route has not been properly registered.', 'event_espresso'), $current_route); |
|
140 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
141 | - return false; |
|
142 | - } |
|
143 | - // grab module name |
|
144 | - $module_name = $module_method[0]; |
|
145 | - // verify that a class method was registered properly |
|
146 | - if (! isset($module_method[1])) { |
|
147 | - $msg = sprintf( |
|
148 | - __('A class method for the %s route has not been properly registered.', 'event_espresso'), |
|
149 | - $current_route |
|
150 | - ); |
|
151 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
152 | - return false; |
|
153 | - } |
|
154 | - // grab method |
|
155 | - $method = $module_method[1]; |
|
156 | - // verify that class exists |
|
157 | - if (! class_exists($module_name)) { |
|
158 | - $msg = sprintf(__('The requested %s class could not be found.', 'event_espresso'), $module_name); |
|
159 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
160 | - return false; |
|
161 | - } |
|
162 | - // verify that method exists |
|
163 | - if (! method_exists($module_name, $method)) { |
|
164 | - $msg = sprintf( |
|
165 | - __('The class method %s for the %s route is in invalid.', 'event_espresso'), $method, $current_route |
|
166 | - ); |
|
167 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
168 | - return false; |
|
169 | - } |
|
170 | - // instantiate module and call route method |
|
171 | - return $this->_module_router($module_name, $method); |
|
172 | - } |
|
114 | + /** |
|
115 | + * this method simply takes a valid route, and resolves what module class method the route points to |
|
116 | + * |
|
117 | + * @param string $key |
|
118 | + * @param string $current_route |
|
119 | + * @return mixed EED_Module | boolean |
|
120 | + * @throws EE_Error |
|
121 | + * @throws ReflectionException |
|
122 | + */ |
|
123 | + public function resolve_route($key, $current_route) |
|
124 | + { |
|
125 | + // get module method that route has been mapped to |
|
126 | + $module_method = EE_Config::get_route($current_route, $key); |
|
127 | + //EEH_Debug_Tools::printr( $module_method, '$module_method <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span>', 'auto' ); |
|
128 | + // verify result was returned |
|
129 | + if (empty($module_method)) { |
|
130 | + $msg = sprintf( |
|
131 | + __('The requested route %s could not be mapped to any registered modules.', 'event_espresso'), |
|
132 | + $current_route |
|
133 | + ); |
|
134 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
135 | + return false; |
|
136 | + } |
|
137 | + // verify that result is an array |
|
138 | + if (! is_array($module_method)) { |
|
139 | + $msg = sprintf(__('The %s route has not been properly registered.', 'event_espresso'), $current_route); |
|
140 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
141 | + return false; |
|
142 | + } |
|
143 | + // grab module name |
|
144 | + $module_name = $module_method[0]; |
|
145 | + // verify that a class method was registered properly |
|
146 | + if (! isset($module_method[1])) { |
|
147 | + $msg = sprintf( |
|
148 | + __('A class method for the %s route has not been properly registered.', 'event_espresso'), |
|
149 | + $current_route |
|
150 | + ); |
|
151 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
152 | + return false; |
|
153 | + } |
|
154 | + // grab method |
|
155 | + $method = $module_method[1]; |
|
156 | + // verify that class exists |
|
157 | + if (! class_exists($module_name)) { |
|
158 | + $msg = sprintf(__('The requested %s class could not be found.', 'event_espresso'), $module_name); |
|
159 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
160 | + return false; |
|
161 | + } |
|
162 | + // verify that method exists |
|
163 | + if (! method_exists($module_name, $method)) { |
|
164 | + $msg = sprintf( |
|
165 | + __('The class method %s for the %s route is in invalid.', 'event_espresso'), $method, $current_route |
|
166 | + ); |
|
167 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
168 | + return false; |
|
169 | + } |
|
170 | + // instantiate module and call route method |
|
171 | + return $this->_module_router($module_name, $method); |
|
172 | + } |
|
173 | 173 | |
174 | 174 | |
175 | 175 | |
176 | - /** |
|
177 | - * this method instantiates modules and calls the method that was defined when the route was registered |
|
178 | - * |
|
179 | - * @param string $module_name |
|
180 | - * @return EED_Module|object|null |
|
181 | - * @throws ReflectionException |
|
182 | - */ |
|
183 | - public static function module_factory($module_name) |
|
184 | - { |
|
185 | - if ($module_name === 'EED_Module') { |
|
186 | - EE_Error::add_error( |
|
187 | - sprintf( |
|
188 | - __( |
|
189 | - 'EED_Module is an abstract parent class an can not be instantiated. Please provide a proper module name.', |
|
190 | - 'event_espresso' |
|
191 | - ), $module_name |
|
192 | - ), __FILE__, __FUNCTION__, __LINE__ |
|
193 | - ); |
|
194 | - return null; |
|
195 | - } |
|
196 | - // instantiate module class |
|
197 | - $module = new $module_name(); |
|
198 | - // ensure that class is actually a module |
|
199 | - if (! $module instanceof EED_Module) { |
|
200 | - EE_Error::add_error( |
|
201 | - sprintf(__('The requested %s module is not of the class EED_Module.', 'event_espresso'), $module_name), |
|
202 | - __FILE__, __FUNCTION__, __LINE__ |
|
203 | - ); |
|
204 | - return null; |
|
205 | - } |
|
206 | - return $module; |
|
207 | - } |
|
176 | + /** |
|
177 | + * this method instantiates modules and calls the method that was defined when the route was registered |
|
178 | + * |
|
179 | + * @param string $module_name |
|
180 | + * @return EED_Module|object|null |
|
181 | + * @throws ReflectionException |
|
182 | + */ |
|
183 | + public static function module_factory($module_name) |
|
184 | + { |
|
185 | + if ($module_name === 'EED_Module') { |
|
186 | + EE_Error::add_error( |
|
187 | + sprintf( |
|
188 | + __( |
|
189 | + 'EED_Module is an abstract parent class an can not be instantiated. Please provide a proper module name.', |
|
190 | + 'event_espresso' |
|
191 | + ), $module_name |
|
192 | + ), __FILE__, __FUNCTION__, __LINE__ |
|
193 | + ); |
|
194 | + return null; |
|
195 | + } |
|
196 | + // instantiate module class |
|
197 | + $module = new $module_name(); |
|
198 | + // ensure that class is actually a module |
|
199 | + if (! $module instanceof EED_Module) { |
|
200 | + EE_Error::add_error( |
|
201 | + sprintf(__('The requested %s module is not of the class EED_Module.', 'event_espresso'), $module_name), |
|
202 | + __FILE__, __FUNCTION__, __LINE__ |
|
203 | + ); |
|
204 | + return null; |
|
205 | + } |
|
206 | + return $module; |
|
207 | + } |
|
208 | 208 | |
209 | 209 | |
210 | 210 | |
211 | - /** |
|
212 | - * this method instantiates modules and calls the method that was defined when the route was registered |
|
213 | - * |
|
214 | - * @param string $module_name |
|
215 | - * @param string $method |
|
216 | - * @return EED_Module|null |
|
217 | - * @throws EE_Error |
|
218 | - * @throws ReflectionException |
|
219 | - */ |
|
220 | - private function _module_router($module_name, $method) |
|
221 | - { |
|
222 | - // instantiate module class |
|
223 | - $module = EE_Module_Request_Router::module_factory($module_name); |
|
224 | - if ($module instanceof EED_Module) { |
|
225 | - // and call whatever action the route was for |
|
226 | - try { |
|
227 | - call_user_func(array($module, $method), $this->WP_Query); |
|
228 | - } catch (EE_Error $e) { |
|
229 | - $e->get_error(); |
|
230 | - return null; |
|
231 | - } |
|
232 | - } |
|
233 | - return $module; |
|
234 | - } |
|
211 | + /** |
|
212 | + * this method instantiates modules and calls the method that was defined when the route was registered |
|
213 | + * |
|
214 | + * @param string $module_name |
|
215 | + * @param string $method |
|
216 | + * @return EED_Module|null |
|
217 | + * @throws EE_Error |
|
218 | + * @throws ReflectionException |
|
219 | + */ |
|
220 | + private function _module_router($module_name, $method) |
|
221 | + { |
|
222 | + // instantiate module class |
|
223 | + $module = EE_Module_Request_Router::module_factory($module_name); |
|
224 | + if ($module instanceof EED_Module) { |
|
225 | + // and call whatever action the route was for |
|
226 | + try { |
|
227 | + call_user_func(array($module, $method), $this->WP_Query); |
|
228 | + } catch (EE_Error $e) { |
|
229 | + $e->get_error(); |
|
230 | + return null; |
|
231 | + } |
|
232 | + } |
|
233 | + return $module; |
|
234 | + } |
|
235 | 235 | |
236 | 236 | |
237 | 237 | |
238 | - /** |
|
239 | - * @param $current_route |
|
240 | - * @return string |
|
241 | - */ |
|
242 | - public function get_forward($current_route) |
|
243 | - { |
|
244 | - return EE_Config::get_forward($current_route); |
|
245 | - } |
|
238 | + /** |
|
239 | + * @param $current_route |
|
240 | + * @return string |
|
241 | + */ |
|
242 | + public function get_forward($current_route) |
|
243 | + { |
|
244 | + return EE_Config::get_forward($current_route); |
|
245 | + } |
|
246 | 246 | |
247 | 247 | |
248 | 248 | |
249 | - /** |
|
250 | - * @param $current_route |
|
251 | - * @return string |
|
252 | - */ |
|
253 | - public function get_view($current_route) |
|
254 | - { |
|
255 | - return EE_Config::get_view($current_route); |
|
256 | - } |
|
249 | + /** |
|
250 | + * @param $current_route |
|
251 | + * @return string |
|
252 | + */ |
|
253 | + public function get_view($current_route) |
|
254 | + { |
|
255 | + return EE_Config::get_view($current_route); |
|
256 | + } |
|
257 | 257 | |
258 | 258 | |
259 | 259 | } |
@@ -55,7 +55,7 @@ discard block |
||
55 | 55 | // assume this if first route being called |
56 | 56 | $previous_route = false; |
57 | 57 | // but is it really ??? |
58 | - if (! empty(self::$_previous_routes)) { |
|
58 | + if ( ! empty(self::$_previous_routes)) { |
|
59 | 59 | // get last run route |
60 | 60 | $previous_routes = array_values(self::$_previous_routes); |
61 | 61 | $previous_route = array_pop($previous_routes); |
@@ -135,36 +135,36 @@ discard block |
||
135 | 135 | return false; |
136 | 136 | } |
137 | 137 | // verify that result is an array |
138 | - if (! is_array($module_method)) { |
|
138 | + if ( ! is_array($module_method)) { |
|
139 | 139 | $msg = sprintf(__('The %s route has not been properly registered.', 'event_espresso'), $current_route); |
140 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
140 | + EE_Error::add_error($msg.'||'.$msg, __FILE__, __FUNCTION__, __LINE__); |
|
141 | 141 | return false; |
142 | 142 | } |
143 | 143 | // grab module name |
144 | 144 | $module_name = $module_method[0]; |
145 | 145 | // verify that a class method was registered properly |
146 | - if (! isset($module_method[1])) { |
|
146 | + if ( ! isset($module_method[1])) { |
|
147 | 147 | $msg = sprintf( |
148 | 148 | __('A class method for the %s route has not been properly registered.', 'event_espresso'), |
149 | 149 | $current_route |
150 | 150 | ); |
151 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
151 | + EE_Error::add_error($msg.'||'.$msg, __FILE__, __FUNCTION__, __LINE__); |
|
152 | 152 | return false; |
153 | 153 | } |
154 | 154 | // grab method |
155 | 155 | $method = $module_method[1]; |
156 | 156 | // verify that class exists |
157 | - if (! class_exists($module_name)) { |
|
157 | + if ( ! class_exists($module_name)) { |
|
158 | 158 | $msg = sprintf(__('The requested %s class could not be found.', 'event_espresso'), $module_name); |
159 | 159 | EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
160 | 160 | return false; |
161 | 161 | } |
162 | 162 | // verify that method exists |
163 | - if (! method_exists($module_name, $method)) { |
|
163 | + if ( ! method_exists($module_name, $method)) { |
|
164 | 164 | $msg = sprintf( |
165 | 165 | __('The class method %s for the %s route is in invalid.', 'event_espresso'), $method, $current_route |
166 | 166 | ); |
167 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
167 | + EE_Error::add_error($msg.'||'.$msg, __FILE__, __FUNCTION__, __LINE__); |
|
168 | 168 | return false; |
169 | 169 | } |
170 | 170 | // instantiate module and call route method |
@@ -196,7 +196,7 @@ discard block |
||
196 | 196 | // instantiate module class |
197 | 197 | $module = new $module_name(); |
198 | 198 | // ensure that class is actually a module |
199 | - if (! $module instanceof EED_Module) { |
|
199 | + if ( ! $module instanceof EED_Module) { |
|
200 | 200 | EE_Error::add_error( |
201 | 201 | sprintf(__('The requested %s module is not of the class EED_Module.', 'event_espresso'), $module_name), |
202 | 202 | __FILE__, __FUNCTION__, __LINE__ |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php if (! defined('EVENT_ESPRESSO_VERSION')) { |
2 | - exit('No direct script access allowed'); |
|
2 | + exit('No direct script access allowed'); |
|
3 | 3 | } |
4 | 4 | |
5 | 5 | /** |
@@ -23,104 +23,104 @@ discard block |
||
23 | 23 | { |
24 | 24 | |
25 | 25 | |
26 | - /** |
|
27 | - * REG_date |
|
28 | - */ |
|
29 | - function column_REG_date(EE_Registration $item) |
|
30 | - { |
|
26 | + /** |
|
27 | + * REG_date |
|
28 | + */ |
|
29 | + function column_REG_date(EE_Registration $item) |
|
30 | + { |
|
31 | 31 | |
32 | - //Build row actions |
|
33 | - $actions = array(); |
|
32 | + //Build row actions |
|
33 | + $actions = array(); |
|
34 | 34 | |
35 | - //Build row actions |
|
36 | - $check_in_url = EE_Admin_Page::add_query_args_and_nonce(array( |
|
37 | - 'action' => 'event_registrations', |
|
38 | - 'event_id' => $item->event_ID(), |
|
39 | - ), REG_ADMIN_URL); |
|
40 | - $actions['check_in'] = EE_Registry::instance()->CAP->current_user_can('ee_read_checkin', |
|
41 | - 'espresso_registrations_registration_checkins', $item->ID()) ? ' |
|
35 | + //Build row actions |
|
36 | + $check_in_url = EE_Admin_Page::add_query_args_and_nonce(array( |
|
37 | + 'action' => 'event_registrations', |
|
38 | + 'event_id' => $item->event_ID(), |
|
39 | + ), REG_ADMIN_URL); |
|
40 | + $actions['check_in'] = EE_Registry::instance()->CAP->current_user_can('ee_read_checkin', |
|
41 | + 'espresso_registrations_registration_checkins', $item->ID()) ? ' |
|
42 | 42 | <a href="' . $check_in_url . '" title="' . esc_attr__('The Check-In List allows you to easily toggle check-in status for this event', |
43 | - 'event_espresso') . '">' . __('View Check-ins', 'event_espresso') . '</a>' : __('View Check-ins', |
|
44 | - 'event_espresso'); |
|
43 | + 'event_espresso') . '">' . __('View Check-ins', 'event_espresso') . '</a>' : __('View Check-ins', |
|
44 | + 'event_espresso'); |
|
45 | 45 | |
46 | - $view_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array( |
|
47 | - 'action' => 'view_transaction', |
|
48 | - 'TXN_ID' => $item->transaction()->ID(), |
|
49 | - ), TXN_ADMIN_URL); |
|
50 | - $REG_date = EE_Regisry::instance()->CAP->current_user_can('ee_read_transaction', |
|
51 | - 'espresso_transactions_view_transaction') ? '<a href="' . $view_lnk_url . '" title="' . esc_attr__('View Transaction Details', |
|
52 | - 'event_espresso') . '">' . $item->get_i18n_datetime('REG_date') . '</a>' : $item->get_i18n_datetime('REG_date'); |
|
46 | + $view_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array( |
|
47 | + 'action' => 'view_transaction', |
|
48 | + 'TXN_ID' => $item->transaction()->ID(), |
|
49 | + ), TXN_ADMIN_URL); |
|
50 | + $REG_date = EE_Regisry::instance()->CAP->current_user_can('ee_read_transaction', |
|
51 | + 'espresso_transactions_view_transaction') ? '<a href="' . $view_lnk_url . '" title="' . esc_attr__('View Transaction Details', |
|
52 | + 'event_espresso') . '">' . $item->get_i18n_datetime('REG_date') . '</a>' : $item->get_i18n_datetime('REG_date'); |
|
53 | 53 | |
54 | - return sprintf('%1$s %2$s', $REG_date, $this->row_actions($actions)); |
|
54 | + return sprintf('%1$s %2$s', $REG_date, $this->row_actions($actions)); |
|
55 | 55 | |
56 | - } |
|
56 | + } |
|
57 | 57 | |
58 | 58 | |
59 | - /** |
|
60 | - * column_default |
|
61 | - * |
|
62 | - * @param \EE_Registration $item |
|
63 | - * @return string |
|
64 | - */ |
|
65 | - public function column_DTT_EVT_start(EE_Registration $item) |
|
66 | - { |
|
67 | - $remove_defaults = array('default_where_conditions' => 'none'); |
|
68 | - $ticket = $item->ticket(); |
|
69 | - $datetimes = $ticket instanceof EE_Ticket ? $ticket->datetimes($remove_defaults) : array(); |
|
70 | - $EVT_ID = $item->event_ID(); |
|
71 | - $datetime_string = ''; |
|
72 | - foreach ($datetimes as $datetime) { |
|
73 | - if ( |
|
74 | - EE_Registry::instance()->CAP->current_user_can( |
|
75 | - 'ee_read_checkin', |
|
76 | - 'espresso_registrations_registration_checkins', |
|
77 | - $item->ID() |
|
78 | - ) |
|
79 | - ) { |
|
80 | - // open "a" tag and "href" |
|
81 | - $datetime_string .= '<a href="'; |
|
82 | - // checkin URL |
|
83 | - $datetime_string .= EE_Admin_Page::add_query_args_and_nonce( |
|
84 | - array( |
|
85 | - 'action' => 'event_registrations', |
|
86 | - 'event_id' => $EVT_ID, |
|
87 | - 'DTT_ID' => $datetime->ID(), |
|
88 | - ), |
|
89 | - REG_ADMIN_URL |
|
90 | - ); |
|
91 | - // close "href" |
|
92 | - $datetime_string .= '"'; |
|
93 | - // open "title" tag |
|
94 | - $datetime_string .= ' title="'; |
|
95 | - // link title text |
|
96 | - $datetime_string .= esc_attr__('View Checkins for this Event', 'event_espresso'); |
|
97 | - // close "title" tag and end of "a" tag opening |
|
98 | - $datetime_string .= '">'; |
|
99 | - // link text |
|
100 | - $datetime_string .= $datetime->get_i18n_datetime('DTT_EVT_start'); |
|
101 | - // close "a" tag |
|
102 | - $datetime_string .= '</a>'; |
|
103 | - } else { |
|
104 | - $datetime_string .= $datetime->get_i18n_datetime('DTT_EVT_start'); |
|
105 | - } |
|
106 | - // add a "View Registrations" link that filters list by event AND datetime |
|
107 | - $datetime_string .= $this->row_actions( |
|
108 | - array( |
|
109 | - 'event_datetime_filter' => '<a href="' . EE_Admin_Page::add_query_args_and_nonce( |
|
110 | - array('event_id' => $EVT_ID, 'datetime_id' => $datetime->ID()), |
|
111 | - REG_ADMIN_URL |
|
112 | - ) . '" title="' . sprintf( |
|
113 | - esc_attr__( |
|
114 | - 'Filter this list to only show registrations for this datetime %s', |
|
115 | - 'event_espresso' |
|
116 | - ), |
|
117 | - $datetime->name() |
|
118 | - ) . '">' . __('View Registrations', 'event_espresso') . '</a>', |
|
119 | - ) |
|
120 | - ); |
|
121 | - } |
|
122 | - return $datetime_string; |
|
123 | - } |
|
59 | + /** |
|
60 | + * column_default |
|
61 | + * |
|
62 | + * @param \EE_Registration $item |
|
63 | + * @return string |
|
64 | + */ |
|
65 | + public function column_DTT_EVT_start(EE_Registration $item) |
|
66 | + { |
|
67 | + $remove_defaults = array('default_where_conditions' => 'none'); |
|
68 | + $ticket = $item->ticket(); |
|
69 | + $datetimes = $ticket instanceof EE_Ticket ? $ticket->datetimes($remove_defaults) : array(); |
|
70 | + $EVT_ID = $item->event_ID(); |
|
71 | + $datetime_string = ''; |
|
72 | + foreach ($datetimes as $datetime) { |
|
73 | + if ( |
|
74 | + EE_Registry::instance()->CAP->current_user_can( |
|
75 | + 'ee_read_checkin', |
|
76 | + 'espresso_registrations_registration_checkins', |
|
77 | + $item->ID() |
|
78 | + ) |
|
79 | + ) { |
|
80 | + // open "a" tag and "href" |
|
81 | + $datetime_string .= '<a href="'; |
|
82 | + // checkin URL |
|
83 | + $datetime_string .= EE_Admin_Page::add_query_args_and_nonce( |
|
84 | + array( |
|
85 | + 'action' => 'event_registrations', |
|
86 | + 'event_id' => $EVT_ID, |
|
87 | + 'DTT_ID' => $datetime->ID(), |
|
88 | + ), |
|
89 | + REG_ADMIN_URL |
|
90 | + ); |
|
91 | + // close "href" |
|
92 | + $datetime_string .= '"'; |
|
93 | + // open "title" tag |
|
94 | + $datetime_string .= ' title="'; |
|
95 | + // link title text |
|
96 | + $datetime_string .= esc_attr__('View Checkins for this Event', 'event_espresso'); |
|
97 | + // close "title" tag and end of "a" tag opening |
|
98 | + $datetime_string .= '">'; |
|
99 | + // link text |
|
100 | + $datetime_string .= $datetime->get_i18n_datetime('DTT_EVT_start'); |
|
101 | + // close "a" tag |
|
102 | + $datetime_string .= '</a>'; |
|
103 | + } else { |
|
104 | + $datetime_string .= $datetime->get_i18n_datetime('DTT_EVT_start'); |
|
105 | + } |
|
106 | + // add a "View Registrations" link that filters list by event AND datetime |
|
107 | + $datetime_string .= $this->row_actions( |
|
108 | + array( |
|
109 | + 'event_datetime_filter' => '<a href="' . EE_Admin_Page::add_query_args_and_nonce( |
|
110 | + array('event_id' => $EVT_ID, 'datetime_id' => $datetime->ID()), |
|
111 | + REG_ADMIN_URL |
|
112 | + ) . '" title="' . sprintf( |
|
113 | + esc_attr__( |
|
114 | + 'Filter this list to only show registrations for this datetime %s', |
|
115 | + 'event_espresso' |
|
116 | + ), |
|
117 | + $datetime->name() |
|
118 | + ) . '">' . __('View Registrations', 'event_espresso') . '</a>', |
|
119 | + ) |
|
120 | + ); |
|
121 | + } |
|
122 | + return $datetime_string; |
|
123 | + } |
|
124 | 124 | |
125 | 125 | |
126 | 126 | } //end Extend_EE_Registrations_List_Table |
@@ -1,4 +1,4 @@ discard block |
||
1 | -<?php if (! defined('EVENT_ESPRESSO_VERSION')) { |
|
1 | +<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
2 | 2 | exit('No direct script access allowed'); |
3 | 3 | } |
4 | 4 | |
@@ -33,23 +33,23 @@ discard block |
||
33 | 33 | $actions = array(); |
34 | 34 | |
35 | 35 | //Build row actions |
36 | - $check_in_url = EE_Admin_Page::add_query_args_and_nonce(array( |
|
36 | + $check_in_url = EE_Admin_Page::add_query_args_and_nonce(array( |
|
37 | 37 | 'action' => 'event_registrations', |
38 | 38 | 'event_id' => $item->event_ID(), |
39 | 39 | ), REG_ADMIN_URL); |
40 | 40 | $actions['check_in'] = EE_Registry::instance()->CAP->current_user_can('ee_read_checkin', |
41 | 41 | 'espresso_registrations_registration_checkins', $item->ID()) ? ' |
42 | - <a href="' . $check_in_url . '" title="' . esc_attr__('The Check-In List allows you to easily toggle check-in status for this event', |
|
43 | - 'event_espresso') . '">' . __('View Check-ins', 'event_espresso') . '</a>' : __('View Check-ins', |
|
42 | + <a href="' . $check_in_url.'" title="'.esc_attr__('The Check-In List allows you to easily toggle check-in status for this event', |
|
43 | + 'event_espresso').'">'.__('View Check-ins', 'event_espresso').'</a>' : __('View Check-ins', |
|
44 | 44 | 'event_espresso'); |
45 | 45 | |
46 | 46 | $view_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array( |
47 | 47 | 'action' => 'view_transaction', |
48 | 48 | 'TXN_ID' => $item->transaction()->ID(), |
49 | 49 | ), TXN_ADMIN_URL); |
50 | - $REG_date = EE_Regisry::instance()->CAP->current_user_can('ee_read_transaction', |
|
51 | - 'espresso_transactions_view_transaction') ? '<a href="' . $view_lnk_url . '" title="' . esc_attr__('View Transaction Details', |
|
52 | - 'event_espresso') . '">' . $item->get_i18n_datetime('REG_date') . '</a>' : $item->get_i18n_datetime('REG_date'); |
|
50 | + $REG_date = EE_Regisry::instance()->CAP->current_user_can('ee_read_transaction', |
|
51 | + 'espresso_transactions_view_transaction') ? '<a href="'.$view_lnk_url.'" title="'.esc_attr__('View Transaction Details', |
|
52 | + 'event_espresso').'">'.$item->get_i18n_datetime('REG_date').'</a>' : $item->get_i18n_datetime('REG_date'); |
|
53 | 53 | |
54 | 54 | return sprintf('%1$s %2$s', $REG_date, $this->row_actions($actions)); |
55 | 55 | |
@@ -106,16 +106,16 @@ discard block |
||
106 | 106 | // add a "View Registrations" link that filters list by event AND datetime |
107 | 107 | $datetime_string .= $this->row_actions( |
108 | 108 | array( |
109 | - 'event_datetime_filter' => '<a href="' . EE_Admin_Page::add_query_args_and_nonce( |
|
109 | + 'event_datetime_filter' => '<a href="'.EE_Admin_Page::add_query_args_and_nonce( |
|
110 | 110 | array('event_id' => $EVT_ID, 'datetime_id' => $datetime->ID()), |
111 | 111 | REG_ADMIN_URL |
112 | - ) . '" title="' . sprintf( |
|
112 | + ).'" title="'.sprintf( |
|
113 | 113 | esc_attr__( |
114 | 114 | 'Filter this list to only show registrations for this datetime %s', |
115 | 115 | 'event_espresso' |
116 | 116 | ), |
117 | 117 | $datetime->name() |
118 | - ) . '">' . __('View Registrations', 'event_espresso') . '</a>', |
|
118 | + ).'">'.__('View Registrations', 'event_espresso').'</a>', |
|
119 | 119 | ) |
120 | 120 | ); |
121 | 121 | } |
@@ -1,4 +1,4 @@ |
||
1 | -<?php use EventEspresso\core\services\orm\ModelFieldFactory; |
|
1 | +<?php |
|
2 | 2 | |
3 | 3 | if (! defined('EVENT_ESPRESSO_VERSION')) { |
4 | 4 | exit('No direct script access allowed'); |
@@ -1,7 +1,7 @@ discard block |
||
1 | 1 | <?php use EventEspresso\core\services\orm\ModelFieldFactory; |
2 | 2 | |
3 | 3 | if (! defined('EVENT_ESPRESSO_VERSION')) { |
4 | - exit('No direct script access allowed'); |
|
4 | + exit('No direct script access allowed'); |
|
5 | 5 | } |
6 | 6 | require_once(EE_MODELS . 'EEM_CPT_Base.model.php'); |
7 | 7 | |
@@ -18,772 +18,772 @@ discard block |
||
18 | 18 | class EEM_Event extends EEM_CPT_Base |
19 | 19 | { |
20 | 20 | |
21 | - /** |
|
22 | - * constant used by status(), indicating that no more tickets can be purchased for any of the datetimes for the |
|
23 | - * event |
|
24 | - */ |
|
25 | - const sold_out = 'sold_out'; |
|
26 | - |
|
27 | - /** |
|
28 | - * constant used by status(), indicating that upcoming event dates have been postponed (may be pushed to a later |
|
29 | - * date) |
|
30 | - */ |
|
31 | - const postponed = 'postponed'; |
|
32 | - |
|
33 | - /** |
|
34 | - * constant used by status(), indicating that the event will no longer occur |
|
35 | - */ |
|
36 | - const cancelled = 'cancelled'; |
|
37 | - |
|
38 | - |
|
39 | - /** |
|
40 | - * @var string |
|
41 | - */ |
|
42 | - protected static $_default_reg_status; |
|
43 | - |
|
44 | - |
|
45 | - /** |
|
46 | - * This is the default for the additional limit field. |
|
47 | - * @var int |
|
48 | - */ |
|
49 | - protected static $_default_additional_limit = 10; |
|
50 | - |
|
51 | - |
|
52 | - /** |
|
53 | - * private instance of the Event object |
|
54 | - * |
|
55 | - * @var EEM_Event |
|
56 | - */ |
|
57 | - protected static $_instance; |
|
58 | - |
|
59 | - |
|
60 | - |
|
61 | - |
|
62 | - /** |
|
63 | - * Adds a relationship to Term_Taxonomy for each CPT_Base |
|
64 | - * |
|
65 | - * @param string $timezone |
|
66 | - * @throws \EE_Error |
|
67 | - */ |
|
68 | - protected function __construct($timezone = null) |
|
69 | - { |
|
70 | - EE_Registry::instance()->load_model('Registration'); |
|
71 | - $this->singular_item = esc_html__('Event', 'event_espresso'); |
|
72 | - $this->plural_item = esc_html__('Events', 'event_espresso'); |
|
73 | - // to remove Cancelled events from the frontend, copy the following filter to your functions.php file |
|
74 | - // add_filter( 'AFEE__EEM_Event__construct___custom_stati__cancelled__Public', '__return_false' ); |
|
75 | - // to remove Postponed events from the frontend, copy the following filter to your functions.php file |
|
76 | - // add_filter( 'AFEE__EEM_Event__construct___custom_stati__postponed__Public', '__return_false' ); |
|
77 | - // to remove Sold Out events from the frontend, copy the following filter to your functions.php file |
|
78 | - // add_filter( 'AFEE__EEM_Event__construct___custom_stati__sold_out__Public', '__return_false' ); |
|
79 | - $this->_custom_stati = apply_filters( |
|
80 | - 'AFEE__EEM_Event__construct___custom_stati', |
|
81 | - array( |
|
82 | - EEM_Event::cancelled => array( |
|
83 | - 'label' => esc_html__('Cancelled', 'event_espresso'), |
|
84 | - 'public' => apply_filters('AFEE__EEM_Event__construct___custom_stati__cancelled__Public', true), |
|
85 | - ), |
|
86 | - EEM_Event::postponed => array( |
|
87 | - 'label' => esc_html__('Postponed', 'event_espresso'), |
|
88 | - 'public' => apply_filters('AFEE__EEM_Event__construct___custom_stati__postponed__Public', true), |
|
89 | - ), |
|
90 | - EEM_Event::sold_out => array( |
|
91 | - 'label' => esc_html__('Sold Out', 'event_espresso'), |
|
92 | - 'public' => apply_filters('AFEE__EEM_Event__construct___custom_stati__sold_out__Public', true), |
|
93 | - ), |
|
94 | - ) |
|
95 | - ); |
|
96 | - self::$_default_reg_status = empty(self::$_default_reg_status) ? EEM_Registration::status_id_pending_payment |
|
97 | - : self::$_default_reg_status; |
|
98 | - $this->_tables = array( |
|
99 | - 'Event_CPT' => new EE_Primary_Table('posts', 'ID'), |
|
100 | - 'Event_Meta' => new EE_Secondary_Table('esp_event_meta', 'EVTM_ID', 'EVT_ID'), |
|
101 | - ); |
|
102 | - $this->_fields = array( |
|
103 | - 'Event_CPT' => array( |
|
104 | - 'EVT_ID' => new EE_Primary_Key_Int_Field('ID', |
|
105 | - esc_html__('Post ID for Event', 'event_espresso')), |
|
106 | - 'EVT_name' => new EE_Plain_Text_Field('post_title', esc_html__('Event Name', 'event_espresso'), |
|
107 | - false, |
|
108 | - ''), |
|
109 | - 'EVT_desc' => new EE_Post_Content_Field('post_content', |
|
110 | - esc_html__('Event Description', 'event_espresso'), |
|
111 | - false, ''), |
|
112 | - 'EVT_slug' => new EE_Slug_Field('post_name', esc_html__('Event Slug', 'event_espresso'), false, |
|
113 | - ''), |
|
114 | - 'EVT_created' => new EE_Datetime_Field('post_date', |
|
115 | - esc_html__('Date/Time Event Created', 'event_espresso'), |
|
116 | - false, EE_Datetime_Field::now), |
|
117 | - 'EVT_short_desc' => new EE_Simple_HTML_Field('post_excerpt', |
|
118 | - esc_html__('Event Short Description', 'event_espresso'), false, ''), |
|
119 | - 'EVT_modified' => new EE_Datetime_Field('post_modified', |
|
120 | - esc_html__('Date/Time Event Modified', 'event_espresso'), false, EE_Datetime_Field::now), |
|
121 | - 'EVT_wp_user' => new EE_WP_User_Field('post_author', |
|
122 | - esc_html__('Event Creator ID', 'event_espresso'), |
|
123 | - false), |
|
124 | - 'parent' => new EE_Integer_Field('post_parent', esc_html__('Event Parent ID', 'event_espresso'), |
|
125 | - false, |
|
126 | - 0), |
|
127 | - 'EVT_order' => new EE_Integer_Field('menu_order', esc_html__('Event Menu Order', 'event_espresso'), |
|
128 | - false, |
|
129 | - 1), |
|
130 | - 'post_type' => new EE_WP_Post_Type_Field('espresso_events'), |
|
131 | - // EE_Plain_Text_Field( 'post_type', esc_html__( 'Event Post Type', 'event_espresso' ), FALSE, 'espresso_events' ), |
|
132 | - 'status' => new EE_WP_Post_Status_Field('post_status', |
|
133 | - esc_html__('Event Status', 'event_espresso'), |
|
134 | - false, 'draft', $this->_custom_stati), |
|
135 | - ), |
|
136 | - 'Event_Meta' => array( |
|
137 | - 'EVTM_ID' => new EE_DB_Only_Float_Field('EVTM_ID', |
|
138 | - esc_html__('Event Meta Row ID', 'event_espresso'), false), |
|
139 | - 'EVT_ID_fk' => new EE_DB_Only_Int_Field('EVT_ID', |
|
140 | - esc_html__('Foreign key to Event ID from Event Meta table', 'event_espresso'), false), |
|
141 | - 'EVT_display_desc' => new EE_Boolean_Field('EVT_display_desc', |
|
142 | - esc_html__('Display Description Flag', 'event_espresso'), false, 1), |
|
143 | - 'EVT_display_ticket_selector' => new EE_Boolean_Field('EVT_display_ticket_selector', |
|
144 | - esc_html__('Display Ticket Selector Flag', 'event_espresso'), false, 1), |
|
145 | - 'EVT_visible_on' => new EE_Datetime_Field('EVT_visible_on', |
|
146 | - esc_html__('Event Visible Date', 'event_espresso'), true, EE_Datetime_Field::now), |
|
147 | - 'EVT_additional_limit' => new EE_Integer_Field( |
|
148 | - 'EVT_additional_limit', |
|
149 | - esc_html__('Limit of Additional Registrations on Same Transaction', 'event_espresso'), |
|
150 | - true, |
|
151 | - self::$_default_additional_limit |
|
152 | - ), |
|
153 | - 'EVT_default_registration_status' => new EE_Enum_Text_Field( |
|
154 | - 'EVT_default_registration_status', |
|
155 | - esc_html__('Default Registration Status on this Event', 'event_espresso'), false, |
|
156 | - EEM_Event::$_default_reg_status, EEM_Registration::reg_status_array() |
|
157 | - ), |
|
158 | - 'EVT_member_only' => new EE_Boolean_Field('EVT_member_only', |
|
159 | - esc_html__('Member-Only Event Flag', 'event_espresso'), false, false), |
|
160 | - 'EVT_phone' => new EE_Plain_Text_Field('EVT_phone', |
|
161 | - esc_html__('Event Phone Number', 'event_espresso'), false,''), |
|
162 | - 'EVT_allow_overflow' => new EE_Boolean_Field('EVT_allow_overflow', |
|
163 | - esc_html__('Allow Overflow on Event', 'event_espresso'), false, false), |
|
164 | - 'EVT_timezone_string' => new EE_Plain_Text_Field('EVT_timezone_string', |
|
165 | - esc_html__('Timezone (name) for Event times', 'event_espresso'), false,''), |
|
166 | - 'EVT_external_URL' => new EE_Plain_Text_Field('EVT_external_URL', |
|
167 | - esc_html__('URL of Event Page if hosted elsewhere', 'event_espresso'), true), |
|
168 | - 'EVT_donations' => new EE_Boolean_Field('EVT_donations', |
|
169 | - esc_html__('Accept Donations?', 'event_espresso'), false, false), |
|
170 | - ), |
|
171 | - ); |
|
172 | - $this->_model_relations = array( |
|
173 | - 'Registration' => new EE_Has_Many_Relation(), |
|
174 | - 'Datetime' => new EE_Has_Many_Relation(), |
|
175 | - 'Question_Group' => new EE_HABTM_Relation('Event_Question_Group'), |
|
176 | - 'Venue' => new EE_HABTM_Relation('Event_Venue'), |
|
177 | - 'Term_Relationship' => new EE_Has_Many_Relation(), |
|
178 | - 'Term_Taxonomy' => new EE_HABTM_Relation('Term_Relationship'), |
|
179 | - 'Message_Template_Group' => new EE_HABTM_Relation('Event_Message_Template'), |
|
180 | - 'Attendee' => new EE_HABTM_Relation('Registration'), |
|
181 | - 'WP_User' => new EE_Belongs_To_Relation(), |
|
182 | - ); |
|
183 | - //this model is generally available for reading |
|
184 | - $this->_cap_restriction_generators[EEM_Base::caps_read] = new EE_Restriction_Generator_Public(); |
|
185 | - parent::__construct($timezone); |
|
186 | - } |
|
187 | - |
|
188 | - |
|
189 | - |
|
190 | - /** |
|
191 | - * @param string $default_reg_status |
|
192 | - */ |
|
193 | - public static function set_default_reg_status($default_reg_status) |
|
194 | - { |
|
195 | - self::$_default_reg_status = $default_reg_status; |
|
196 | - // if EEM_Event has already been instantiated, |
|
197 | - // then we need to reset the `EVT_default_reg_status` field to use the new default. |
|
198 | - if (self::$_instance instanceof EEM_Event) { |
|
199 | - $default_reg_status = new EE_Enum_Text_Field( |
|
200 | - 'EVT_default_registration_status', |
|
201 | - esc_html__('Default Registration Status on this Event', 'event_espresso'), |
|
202 | - false, |
|
203 | - $default_reg_status, |
|
204 | - EEM_Registration::reg_status_array() |
|
205 | - ); |
|
206 | - $default_reg_status->_construct_finalize( |
|
207 | - 'Event_Meta', |
|
208 | - 'EVT_default_registration_status', |
|
209 | - 'EEM_Event' |
|
210 | - ); |
|
211 | - self::$_instance->_fields['Event_Meta']['EVT_default_registration_status'] = $default_reg_status; |
|
212 | - } |
|
213 | - } |
|
214 | - |
|
215 | - |
|
216 | - /** |
|
217 | - * Used to override the default for the additional limit field. |
|
218 | - * @param $additional_limit |
|
219 | - */ |
|
220 | - public static function set_default_additional_limit($additional_limit) |
|
221 | - { |
|
222 | - self::$_default_additional_limit = (int) $additional_limit; |
|
223 | - if (self::$_instance instanceof EEM_Event) { |
|
224 | - self::$_instance->_fields['Event_Meta']['EVT_additional_limit'] = new EE_Integer_Field( |
|
225 | - 'EVT_additional_limit', |
|
226 | - __('Limit of Additional Registrations on Same Transaction', 'event_espresso'), |
|
227 | - true, |
|
228 | - self::$_default_additional_limit |
|
229 | - ); |
|
230 | - self::$_instance->_fields['Event_Meta']['EVT_additional_limit']->_construct_finalize( |
|
231 | - 'Event_Meta', |
|
232 | - 'EVT_additional_limit', |
|
233 | - 'EEM_Event' |
|
234 | - ); |
|
235 | - } |
|
236 | - } |
|
237 | - |
|
238 | - |
|
239 | - /** |
|
240 | - * Return what is currently set as the default additional limit for the event. |
|
241 | - * @return int |
|
242 | - */ |
|
243 | - public static function get_default_additional_limit() |
|
244 | - { |
|
245 | - return apply_filters('FHEE__EEM_Event__get_default_additional_limit', self::$_default_additional_limit); |
|
246 | - } |
|
247 | - |
|
248 | - |
|
249 | - /** |
|
250 | - * get_question_groups |
|
251 | - * |
|
252 | - * @return array |
|
253 | - * @throws \EE_Error |
|
254 | - */ |
|
255 | - public function get_all_question_groups() |
|
256 | - { |
|
257 | - return EE_Registry::instance()->load_model('Question_Group')->get_all( |
|
258 | - array( |
|
259 | - array('QSG_deleted' => false), |
|
260 | - 'order_by' => array('QSG_order' => 'ASC'), |
|
261 | - ) |
|
262 | - ); |
|
263 | - } |
|
264 | - |
|
265 | - |
|
266 | - |
|
267 | - /** |
|
268 | - * get_question_groups |
|
269 | - * |
|
270 | - * @param int $EVT_ID |
|
271 | - * @return array|bool |
|
272 | - * @throws \EE_Error |
|
273 | - */ |
|
274 | - public function get_all_event_question_groups($EVT_ID = 0) |
|
275 | - { |
|
276 | - if (! isset($EVT_ID) || ! absint($EVT_ID)) { |
|
277 | - EE_Error::add_error( |
|
278 | - esc_html__( |
|
279 | - 'An error occurred. No Event Question Groups could be retrieved because an Event ID was not received.', |
|
280 | - 'event_espresso' |
|
281 | - ), |
|
282 | - __FILE__, __FUNCTION__, __LINE__ |
|
283 | - ); |
|
284 | - return false; |
|
285 | - } |
|
286 | - return EE_Registry::instance()->load_model('Event_Question_Group')->get_all( |
|
287 | - array( |
|
288 | - array('EVT_ID' => $EVT_ID), |
|
289 | - ) |
|
290 | - ); |
|
291 | - } |
|
292 | - |
|
293 | - |
|
294 | - |
|
295 | - /** |
|
296 | - * get_question_groups |
|
297 | - * |
|
298 | - * @param int $EVT_ID |
|
299 | - * @param boolean $for_primary_attendee |
|
300 | - * @return array|bool |
|
301 | - * @throws \EE_Error |
|
302 | - */ |
|
303 | - public function get_event_question_groups($EVT_ID = 0, $for_primary_attendee = true) |
|
304 | - { |
|
305 | - if (! isset($EVT_ID) || ! absint($EVT_ID)) { |
|
306 | - EE_Error::add_error( |
|
307 | - esc_html__( |
|
308 | - 'An error occurred. No Event Question Groups could be retrieved because an Event ID was not received.', |
|
309 | - 'event_espresso' |
|
310 | - ), |
|
311 | - __FILE__, __FUNCTION__, __LINE__ |
|
312 | - ); |
|
313 | - return false; |
|
314 | - } |
|
315 | - return EE_Registry::instance()->load_model('Event_Question_Group')->get_all( |
|
316 | - array( |
|
317 | - array( |
|
318 | - 'EVT_ID' => $EVT_ID, |
|
319 | - 'EQG_primary' => $for_primary_attendee, |
|
320 | - ), |
|
321 | - ) |
|
322 | - ); |
|
323 | - } |
|
324 | - |
|
325 | - |
|
326 | - |
|
327 | - /** |
|
328 | - * get_question_groups |
|
329 | - * |
|
330 | - * @param int $EVT_ID |
|
331 | - * @param EE_Registration $registration |
|
332 | - * @return array|bool |
|
333 | - * @throws \EE_Error |
|
334 | - */ |
|
335 | - public function get_question_groups_for_event($EVT_ID = 0, EE_Registration $registration) |
|
336 | - { |
|
337 | - if (! isset($EVT_ID) || ! absint($EVT_ID)) { |
|
338 | - EE_Error::add_error( |
|
339 | - esc_html__( |
|
340 | - 'An error occurred. No Question Groups could be retrieved because an Event ID was not received.', |
|
341 | - 'event_espresso' |
|
342 | - ), |
|
343 | - __FILE__, __FUNCTION__, __LINE__ |
|
344 | - ); |
|
345 | - return false; |
|
346 | - } |
|
347 | - $where_params = array( |
|
348 | - 'Event_Question_Group.EVT_ID' => $EVT_ID, |
|
349 | - 'Event_Question_Group.EQG_primary' => $registration->count() === 1 ? true : false, |
|
350 | - 'QSG_deleted' => false, |
|
351 | - ); |
|
352 | - return EE_Registry::instance()->load_model('Question_Group')->get_all( |
|
353 | - array( |
|
354 | - $where_params, |
|
355 | - 'order_by' => array('QSG_order' => 'ASC'), |
|
356 | - ) |
|
357 | - ); |
|
358 | - } |
|
359 | - |
|
360 | - |
|
361 | - |
|
362 | - /** |
|
363 | - * get_question_target_db_column |
|
364 | - * |
|
365 | - * @param string $QSG_IDs csv list of $QSG IDs |
|
366 | - * @return array|bool |
|
367 | - * @throws \EE_Error |
|
368 | - */ |
|
369 | - public function get_questions_in_groups($QSG_IDs = '') |
|
370 | - { |
|
371 | - if (empty($QSG_IDs)) { |
|
372 | - EE_Error::add_error( |
|
373 | - esc_html__('An error occurred. No Question Group IDs were received.', 'event_espresso'), |
|
374 | - __FILE__, __FUNCTION__, __LINE__ |
|
375 | - ); |
|
376 | - return false; |
|
377 | - } |
|
378 | - return EE_Registry::instance()->load_model('Question')->get_all( |
|
379 | - array( |
|
380 | - array( |
|
381 | - 'Question_Group.QSG_ID' => array('IN', $QSG_IDs), |
|
382 | - 'QST_deleted' => false, |
|
383 | - 'QST_admin_only' => is_admin(), |
|
384 | - ), |
|
385 | - 'order_by' => 'QST_order', |
|
386 | - ) |
|
387 | - ); |
|
388 | - } |
|
389 | - |
|
390 | - |
|
391 | - |
|
392 | - /** |
|
393 | - * get_options_for_question |
|
394 | - * |
|
395 | - * @param string $QST_IDs csv list of $QST IDs |
|
396 | - * @return array|bool |
|
397 | - * @throws \EE_Error |
|
398 | - */ |
|
399 | - public function get_options_for_question($QST_IDs) |
|
400 | - { |
|
401 | - if (empty($QST_IDs)) { |
|
402 | - EE_Error::add_error( |
|
403 | - esc_html__('An error occurred. No Question IDs were received.', 'event_espresso'), |
|
404 | - __FILE__, __FUNCTION__, __LINE__ |
|
405 | - ); |
|
406 | - return false; |
|
407 | - } |
|
408 | - return EE_Registry::instance()->load_model('Question_Option')->get_all( |
|
409 | - array( |
|
410 | - array( |
|
411 | - 'Question.QST_ID' => array('IN', $QST_IDs), |
|
412 | - 'QSO_deleted' => false, |
|
413 | - ), |
|
414 | - 'order_by' => 'QSO_ID', |
|
415 | - ) |
|
416 | - ); |
|
417 | - } |
|
418 | - |
|
419 | - |
|
420 | - |
|
421 | - |
|
422 | - |
|
423 | - |
|
424 | - |
|
425 | - /** |
|
426 | - * Gets all events that are published |
|
427 | - * and have event start time earlier than now and an event end time later than now |
|
428 | - * |
|
429 | - * @param array $query_params An array of query params to further filter on |
|
430 | - * (note that status and DTT_EVT_start and DTT_EVT_end will be overridden) |
|
431 | - * @param bool $count whether to return the count or not (default FALSE) |
|
432 | - * @return EE_Event[]|int |
|
433 | - * @throws \EE_Error |
|
434 | - */ |
|
435 | - public function get_active_events($query_params, $count = false) |
|
436 | - { |
|
437 | - if (array_key_exists(0, $query_params)) { |
|
438 | - $where_params = $query_params[0]; |
|
439 | - unset($query_params[0]); |
|
440 | - } else { |
|
441 | - $where_params = array(); |
|
442 | - } |
|
443 | - // if we have count make sure we don't include group by |
|
444 | - if ($count && isset($query_params['group_by'])) { |
|
445 | - unset($query_params['group_by']); |
|
446 | - } |
|
447 | - // let's add specific query_params for active_events |
|
448 | - // keep in mind this will override any sent status in the query AND any date queries. |
|
449 | - $where_params['status'] = array('IN', array('publish', EEM_Event::sold_out)); |
|
450 | - //if already have where params for DTT_EVT_start or DTT_EVT_end then append these conditions |
|
451 | - if (isset($where_params['Datetime.DTT_EVT_start'])) { |
|
452 | - $where_params['Datetime.DTT_EVT_start******'] = array( |
|
453 | - '<', |
|
454 | - EEM_Datetime::instance()->current_time_for_query('DTT_EVT_start'), |
|
455 | - ); |
|
456 | - } else { |
|
457 | - $where_params['Datetime.DTT_EVT_start'] = array( |
|
458 | - '<', |
|
459 | - EEM_Datetime::instance()->current_time_for_query('DTT_EVT_start'), |
|
460 | - ); |
|
461 | - } |
|
462 | - if (isset($where_params['Datetime.DTT_EVT_end'])) { |
|
463 | - $where_params['Datetime.DTT_EVT_end*****'] = array( |
|
464 | - '>', |
|
465 | - EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'), |
|
466 | - ); |
|
467 | - } else { |
|
468 | - $where_params['Datetime.DTT_EVT_end'] = array( |
|
469 | - '>', |
|
470 | - EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'), |
|
471 | - ); |
|
472 | - } |
|
473 | - $query_params[0] = $where_params; |
|
474 | - // don't use $query_params with count() |
|
475 | - // because we don't want to include additional query clauses like "GROUP BY" |
|
476 | - return $count |
|
477 | - ? $this->count(array($where_params), 'EVT_ID', true) |
|
478 | - : $this->get_all($query_params); |
|
479 | - } |
|
480 | - |
|
481 | - |
|
482 | - |
|
483 | - /** |
|
484 | - * get all events that are published and have an event start time later than now |
|
485 | - * |
|
486 | - * @param array $query_params An array of query params to further filter on |
|
487 | - * (Note that status and DTT_EVT_start will be overridden) |
|
488 | - * @param bool $count whether to return the count or not (default FALSE) |
|
489 | - * @return EE_Event[]|int |
|
490 | - * @throws \EE_Error |
|
491 | - */ |
|
492 | - public function get_upcoming_events($query_params, $count = false) |
|
493 | - { |
|
494 | - if (array_key_exists(0, $query_params)) { |
|
495 | - $where_params = $query_params[0]; |
|
496 | - unset($query_params[0]); |
|
497 | - } else { |
|
498 | - $where_params = array(); |
|
499 | - } |
|
500 | - // if we have count make sure we don't include group by |
|
501 | - if ($count && isset($query_params['group_by'])) { |
|
502 | - unset($query_params['group_by']); |
|
503 | - } |
|
504 | - // let's add specific query_params for active_events |
|
505 | - // keep in mind this will override any sent status in the query AND any date queries. |
|
506 | - $where_params['status'] = array('IN', array('publish', EEM_Event::sold_out)); |
|
507 | - // if there are already query_params matching DTT_EVT_start then we need to modify that to add them. |
|
508 | - if (isset($where_params['Datetime.DTT_EVT_start'])) { |
|
509 | - $where_params['Datetime.DTT_EVT_start*****'] = array( |
|
510 | - '>', |
|
511 | - EEM_Datetime::instance()->current_time_for_query('DTT_EVT_start'), |
|
512 | - ); |
|
513 | - } else { |
|
514 | - $where_params['Datetime.DTT_EVT_start'] = array( |
|
515 | - '>', |
|
516 | - EEM_Datetime::instance()->current_time_for_query('DTT_EVT_start'), |
|
517 | - ); |
|
518 | - } |
|
519 | - $query_params[0] = $where_params; |
|
520 | - // don't use $query_params with count() |
|
521 | - // because we don't want to include additional query clauses like "GROUP BY" |
|
522 | - return $count |
|
523 | - ? $this->count(array($where_params), 'EVT_ID', true) |
|
524 | - : $this->get_all($query_params); |
|
525 | - } |
|
526 | - |
|
527 | - |
|
528 | - |
|
529 | - /** |
|
530 | - * Gets all events that are published |
|
531 | - * and have an event end time later than now |
|
532 | - * |
|
533 | - * @param array $query_params An array of query params to further filter on |
|
534 | - * (note that status and DTT_EVT_end will be overridden) |
|
535 | - * @param bool $count whether to return the count or not (default FALSE) |
|
536 | - * @return EE_Event[]|int |
|
537 | - * @throws \EE_Error |
|
538 | - */ |
|
539 | - public function get_active_and_upcoming_events($query_params, $count = false) |
|
540 | - { |
|
541 | - if (array_key_exists(0, $query_params)) { |
|
542 | - $where_params = $query_params[0]; |
|
543 | - unset($query_params[0]); |
|
544 | - } else { |
|
545 | - $where_params = array(); |
|
546 | - } |
|
547 | - // if we have count make sure we don't include group by |
|
548 | - if ($count && isset($query_params['group_by'])) { |
|
549 | - unset($query_params['group_by']); |
|
550 | - } |
|
551 | - // let's add specific query_params for active_events |
|
552 | - // keep in mind this will override any sent status in the query AND any date queries. |
|
553 | - $where_params['status'] = array('IN', array('publish', EEM_Event::sold_out)); |
|
554 | - // add where params for DTT_EVT_end |
|
555 | - if (isset($where_params['Datetime.DTT_EVT_end'])) { |
|
556 | - $where_params['Datetime.DTT_EVT_end*****'] = array( |
|
557 | - '>', |
|
558 | - EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'), |
|
559 | - ); |
|
560 | - } else { |
|
561 | - $where_params['Datetime.DTT_EVT_end'] = array( |
|
562 | - '>', |
|
563 | - EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'), |
|
564 | - ); |
|
565 | - } |
|
566 | - $query_params[0] = $where_params; |
|
567 | - // don't use $query_params with count() |
|
568 | - // because we don't want to include additional query clauses like "GROUP BY" |
|
569 | - return $count |
|
570 | - ? $this->count(array($where_params), 'EVT_ID', true) |
|
571 | - : $this->get_all($query_params); |
|
572 | - } |
|
573 | - |
|
574 | - |
|
575 | - |
|
576 | - /** |
|
577 | - * This only returns events that are expired. |
|
578 | - * They may still be published but all their datetimes have expired. |
|
579 | - * |
|
580 | - * @param array $query_params An array of query params to further filter on |
|
581 | - * (note that status and DTT_EVT_end will be overridden) |
|
582 | - * @param bool $count whether to return the count or not (default FALSE) |
|
583 | - * @return EE_Event[]|int |
|
584 | - * @throws \EE_Error |
|
585 | - */ |
|
586 | - public function get_expired_events($query_params, $count = false) |
|
587 | - { |
|
588 | - $where_params = isset($query_params[0]) ? $query_params[0] : array(); |
|
589 | - // if we have count make sure we don't include group by |
|
590 | - if ($count && isset($query_params['group_by'])) { |
|
591 | - unset($query_params['group_by']); |
|
592 | - } |
|
593 | - // let's add specific query_params for active_events |
|
594 | - // keep in mind this will override any sent status in the query AND any date queries. |
|
595 | - if (isset($where_params['status'])) { |
|
596 | - unset($where_params['status']); |
|
597 | - } |
|
598 | - $exclude_query = $query_params; |
|
599 | - if (isset($exclude_query[0])) { |
|
600 | - unset($exclude_query[0]); |
|
601 | - } |
|
602 | - $exclude_query[0] = array( |
|
603 | - 'Datetime.DTT_EVT_end' => array( |
|
604 | - '>', |
|
605 | - EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'), |
|
606 | - ), |
|
607 | - ); |
|
608 | - // first get all events that have datetimes where its not expired. |
|
609 | - $event_ids = $this->_get_all_wpdb_results($exclude_query, OBJECT_K, 'Event_CPT.ID'); |
|
610 | - $event_ids = array_keys($event_ids); |
|
611 | - // if we have any additional query_params, let's add them to the 'AND' condition |
|
612 | - $and_condition = array( |
|
613 | - 'Datetime.DTT_EVT_end' => array('<', EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end')), |
|
614 | - 'EVT_ID' => array('NOT IN', $event_ids), |
|
615 | - ); |
|
616 | - if (isset($where_params['OR'])) { |
|
617 | - $and_condition['OR'] = $where_params['OR']; |
|
618 | - unset($where_params['OR']); |
|
619 | - } |
|
620 | - if (isset($where_params['Datetime.DTT_EVT_end'])) { |
|
621 | - $and_condition['Datetime.DTT_EVT_end****'] = $where_params['Datetime.DTT_EVT_end']; |
|
622 | - unset($where_params['Datetime.DTT_EVT_end']); |
|
623 | - } |
|
624 | - if (isset($where_params['Datetime.DTT_EVT_start'])) { |
|
625 | - $and_condition['Datetime.DTT_EVT_start'] = $where_params['Datetime.DTT_EVT_start']; |
|
626 | - unset($where_params['Datetime.DTT_EVT_start']); |
|
627 | - } |
|
628 | - // merge remaining $where params with the and conditions. |
|
629 | - $where_params['AND'] = array_merge($and_condition, $where_params); |
|
630 | - $query_params[0] = $where_params; |
|
631 | - // don't use $query_params with count() |
|
632 | - // because we don't want to include additional query clauses like "GROUP BY" |
|
633 | - return $count |
|
634 | - ? $this->count(array($where_params), 'EVT_ID', true) |
|
635 | - : $this->get_all($query_params); |
|
636 | - } |
|
637 | - |
|
638 | - |
|
639 | - |
|
640 | - /** |
|
641 | - * This basically just returns the events that do not have the publish status. |
|
642 | - * |
|
643 | - * @param array $query_params An array of query params to further filter on |
|
644 | - * (note that status will be overwritten) |
|
645 | - * @param boolean $count whether to return the count or not (default FALSE) |
|
646 | - * @return EE_Event[]|int |
|
647 | - * @throws \EE_Error |
|
648 | - */ |
|
649 | - public function get_inactive_events($query_params, $count = false) |
|
650 | - { |
|
651 | - $where_params = isset($query_params[0]) ? $query_params[0] : array(); |
|
652 | - // let's add in specific query_params for inactive events. |
|
653 | - if (isset($where_params['status'])) { |
|
654 | - unset($where_params['status']); |
|
655 | - } |
|
656 | - // if we have count make sure we don't include group by |
|
657 | - if ($count && isset($query_params['group_by'])) { |
|
658 | - unset($query_params['group_by']); |
|
659 | - } |
|
660 | - // if we have any additional query_params, let's add them to the 'AND' condition |
|
661 | - $where_params['AND']['status'] = array('!=', 'publish'); |
|
662 | - if (isset($where_params['OR'])) { |
|
663 | - $where_params['AND']['OR'] = $where_params['OR']; |
|
664 | - unset($where_params['OR']); |
|
665 | - } |
|
666 | - if (isset($where_params['Datetime.DTT_EVT_end'])) { |
|
667 | - $where_params['AND']['Datetime.DTT_EVT_end****'] = $where_params['Datetime.DTT_EVT_end']; |
|
668 | - unset($where_params['Datetime.DTT_EVT_end']); |
|
669 | - } |
|
670 | - if (isset($where_params['Datetime.DTT_EVT_start'])) { |
|
671 | - $where_params['AND']['Datetime.DTT_EVT_start'] = $where_params['Datetime.DTT_EVT_start']; |
|
672 | - unset($where_params['Datetime.DTT_EVT_start']); |
|
673 | - } |
|
674 | - $query_params[0] = $where_params; |
|
675 | - // don't use $query_params with count() |
|
676 | - // because we don't want to include additional query clauses like "GROUP BY" |
|
677 | - return $count |
|
678 | - ? $this->count(array($where_params), 'EVT_ID', true) |
|
679 | - : $this->get_all($query_params); |
|
680 | - } |
|
681 | - |
|
682 | - |
|
683 | - |
|
684 | - /** |
|
685 | - * This is just injecting into the parent add_relationship_to so we do special handling on price relationships |
|
686 | - * because we don't want to override any existing global default prices but instead insert NEW prices that get |
|
687 | - * attached to the event. See parent for param descriptions |
|
688 | - * |
|
689 | - * @param $id_or_obj |
|
690 | - * @param $other_model_id_or_obj |
|
691 | - * @param string $relationName |
|
692 | - * @param array $where_query |
|
693 | - * @return EE_Base_Class |
|
694 | - * @throws EE_Error |
|
695 | - */ |
|
696 | - public function add_relationship_to($id_or_obj, $other_model_id_or_obj, $relationName, $where_query = array()) |
|
697 | - { |
|
698 | - if ($relationName === 'Price') { |
|
699 | - //let's get the PRC object for the given ID to make sure that we aren't dealing with a default |
|
700 | - $prc_chk = $this->get_related_model_obj($relationName)->ensure_is_obj($other_model_id_or_obj); |
|
701 | - //if EVT_ID = 0, then this is a default |
|
702 | - if ((int) $prc_chk->get('EVT_ID') === 0) { |
|
703 | - //let's set the prc_id as 0 so we force an insert on the add_relation_to carried out by relation |
|
704 | - $prc_chk->set('PRC_ID', 0); |
|
705 | - } |
|
706 | - //run parent |
|
707 | - return parent::add_relationship_to($id_or_obj, $prc_chk, $relationName, $where_query); |
|
708 | - } |
|
709 | - //otherwise carry on as normal |
|
710 | - return parent::add_relationship_to($id_or_obj, $other_model_id_or_obj, $relationName, $where_query); |
|
711 | - } |
|
712 | - |
|
713 | - |
|
714 | - |
|
715 | - /******************** DEPRECATED METHODS ********************/ |
|
716 | - |
|
717 | - |
|
718 | - |
|
719 | - /** |
|
720 | - * _get_question_target_db_column |
|
721 | - * |
|
722 | - * @deprecated as of 4.8.32.rc.001. Instead consider using |
|
723 | - * EE_Registration_Custom_Questions_Form located in |
|
724 | - * admin_pages/registrations/form_sections/EE_Registration_Custom_Questions_Form.form.php |
|
725 | - * @access public |
|
726 | - * @param EE_Registration $registration (so existing answers for registration are included) |
|
727 | - * @param int $EVT_ID so all question groups are included for event (not just answers from |
|
728 | - * registration). |
|
729 | - * @throws EE_Error |
|
730 | - * @return array |
|
731 | - */ |
|
732 | - public function assemble_array_of_groups_questions_and_options(EE_Registration $registration, $EVT_ID = 0) |
|
733 | - { |
|
734 | - if (empty($EVT_ID)) { |
|
735 | - throw new EE_Error(__('An error occurred. No EVT_ID is included. Needed to know which question groups to retrieve.', |
|
736 | - 'event_espresso')); |
|
737 | - } |
|
738 | - $questions = array(); |
|
739 | - // get all question groups for event |
|
740 | - $qgs = $this->get_question_groups_for_event($EVT_ID, $registration); |
|
741 | - if (! empty($qgs)) { |
|
742 | - foreach ($qgs as $qg) { |
|
743 | - $qsts = $qg->questions(); |
|
744 | - $questions[$qg->ID()] = $qg->model_field_array(); |
|
745 | - $questions[$qg->ID()]['QSG_questions'] = array(); |
|
746 | - foreach ($qsts as $qst) { |
|
747 | - if ($qst->is_system_question()) { |
|
748 | - continue; |
|
749 | - } |
|
750 | - $answer = EEM_Answer::instance()->get_one(array( |
|
751 | - array( |
|
752 | - 'QST_ID' => $qst->ID(), |
|
753 | - 'REG_ID' => $registration->ID(), |
|
754 | - ), |
|
755 | - )); |
|
756 | - $answer = $answer instanceof EE_Answer ? $answer : EEM_Answer::instance()->create_default_object(); |
|
757 | - $qst_name = $qstn_id = $qst->ID(); |
|
758 | - $ans_id = $answer->ID(); |
|
759 | - $qst_name = ! empty($ans_id) ? '[' . $qst_name . '][' . $ans_id . ']' : '[' . $qst_name . ']'; |
|
760 | - $input_name = ''; |
|
761 | - $input_id = sanitize_key($qst->display_text()); |
|
762 | - $input_class = ''; |
|
763 | - $questions[$qg->ID()]['QSG_questions'][$qst->ID()] = $qst->model_field_array(); |
|
764 | - $questions[$qg->ID()]['QSG_questions'][$qst->ID()]['QST_input_name'] = 'qstn' |
|
765 | - . $input_name |
|
766 | - . $qst_name; |
|
767 | - $questions[$qg->ID()]['QSG_questions'][$qst->ID()]['QST_input_id'] = $input_id . '-' . $qstn_id; |
|
768 | - $questions[$qg->ID()]['QSG_questions'][$qst->ID()]['QST_input_class'] = $input_class; |
|
769 | - $questions[$qg->ID()]['QSG_questions'][$qst->ID()]['QST_options'] = array(); |
|
770 | - $questions[$qg->ID()]['QSG_questions'][$qst->ID()]['qst_obj'] = $qst; |
|
771 | - $questions[$qg->ID()]['QSG_questions'][$qst->ID()]['ans_obj'] = $answer; |
|
772 | - //leave responses as-is, don't convert stuff into html entities please! |
|
773 | - $questions[$qg->ID()]['QSG_questions'][$qst->ID()]['htmlentities'] = false; |
|
774 | - if ($qst->type() == 'RADIO_BTN' || $qst->type() == 'CHECKBOX' || $qst->type() == 'DROPDOWN') { |
|
775 | - $QSOs = $qst->options(true, $answer->value()); |
|
776 | - if (is_array($QSOs)) { |
|
777 | - foreach ($QSOs as $QSO_ID => $QSO) { |
|
778 | - $questions[$qg->ID()]['QSG_questions'][$qst->ID()]['QST_options'][$QSO_ID] = $QSO->model_field_array(); |
|
779 | - } |
|
780 | - } |
|
781 | - } |
|
782 | - } |
|
783 | - } |
|
784 | - } |
|
785 | - return $questions; |
|
786 | - } |
|
21 | + /** |
|
22 | + * constant used by status(), indicating that no more tickets can be purchased for any of the datetimes for the |
|
23 | + * event |
|
24 | + */ |
|
25 | + const sold_out = 'sold_out'; |
|
26 | + |
|
27 | + /** |
|
28 | + * constant used by status(), indicating that upcoming event dates have been postponed (may be pushed to a later |
|
29 | + * date) |
|
30 | + */ |
|
31 | + const postponed = 'postponed'; |
|
32 | + |
|
33 | + /** |
|
34 | + * constant used by status(), indicating that the event will no longer occur |
|
35 | + */ |
|
36 | + const cancelled = 'cancelled'; |
|
37 | + |
|
38 | + |
|
39 | + /** |
|
40 | + * @var string |
|
41 | + */ |
|
42 | + protected static $_default_reg_status; |
|
43 | + |
|
44 | + |
|
45 | + /** |
|
46 | + * This is the default for the additional limit field. |
|
47 | + * @var int |
|
48 | + */ |
|
49 | + protected static $_default_additional_limit = 10; |
|
50 | + |
|
51 | + |
|
52 | + /** |
|
53 | + * private instance of the Event object |
|
54 | + * |
|
55 | + * @var EEM_Event |
|
56 | + */ |
|
57 | + protected static $_instance; |
|
58 | + |
|
59 | + |
|
60 | + |
|
61 | + |
|
62 | + /** |
|
63 | + * Adds a relationship to Term_Taxonomy for each CPT_Base |
|
64 | + * |
|
65 | + * @param string $timezone |
|
66 | + * @throws \EE_Error |
|
67 | + */ |
|
68 | + protected function __construct($timezone = null) |
|
69 | + { |
|
70 | + EE_Registry::instance()->load_model('Registration'); |
|
71 | + $this->singular_item = esc_html__('Event', 'event_espresso'); |
|
72 | + $this->plural_item = esc_html__('Events', 'event_espresso'); |
|
73 | + // to remove Cancelled events from the frontend, copy the following filter to your functions.php file |
|
74 | + // add_filter( 'AFEE__EEM_Event__construct___custom_stati__cancelled__Public', '__return_false' ); |
|
75 | + // to remove Postponed events from the frontend, copy the following filter to your functions.php file |
|
76 | + // add_filter( 'AFEE__EEM_Event__construct___custom_stati__postponed__Public', '__return_false' ); |
|
77 | + // to remove Sold Out events from the frontend, copy the following filter to your functions.php file |
|
78 | + // add_filter( 'AFEE__EEM_Event__construct___custom_stati__sold_out__Public', '__return_false' ); |
|
79 | + $this->_custom_stati = apply_filters( |
|
80 | + 'AFEE__EEM_Event__construct___custom_stati', |
|
81 | + array( |
|
82 | + EEM_Event::cancelled => array( |
|
83 | + 'label' => esc_html__('Cancelled', 'event_espresso'), |
|
84 | + 'public' => apply_filters('AFEE__EEM_Event__construct___custom_stati__cancelled__Public', true), |
|
85 | + ), |
|
86 | + EEM_Event::postponed => array( |
|
87 | + 'label' => esc_html__('Postponed', 'event_espresso'), |
|
88 | + 'public' => apply_filters('AFEE__EEM_Event__construct___custom_stati__postponed__Public', true), |
|
89 | + ), |
|
90 | + EEM_Event::sold_out => array( |
|
91 | + 'label' => esc_html__('Sold Out', 'event_espresso'), |
|
92 | + 'public' => apply_filters('AFEE__EEM_Event__construct___custom_stati__sold_out__Public', true), |
|
93 | + ), |
|
94 | + ) |
|
95 | + ); |
|
96 | + self::$_default_reg_status = empty(self::$_default_reg_status) ? EEM_Registration::status_id_pending_payment |
|
97 | + : self::$_default_reg_status; |
|
98 | + $this->_tables = array( |
|
99 | + 'Event_CPT' => new EE_Primary_Table('posts', 'ID'), |
|
100 | + 'Event_Meta' => new EE_Secondary_Table('esp_event_meta', 'EVTM_ID', 'EVT_ID'), |
|
101 | + ); |
|
102 | + $this->_fields = array( |
|
103 | + 'Event_CPT' => array( |
|
104 | + 'EVT_ID' => new EE_Primary_Key_Int_Field('ID', |
|
105 | + esc_html__('Post ID for Event', 'event_espresso')), |
|
106 | + 'EVT_name' => new EE_Plain_Text_Field('post_title', esc_html__('Event Name', 'event_espresso'), |
|
107 | + false, |
|
108 | + ''), |
|
109 | + 'EVT_desc' => new EE_Post_Content_Field('post_content', |
|
110 | + esc_html__('Event Description', 'event_espresso'), |
|
111 | + false, ''), |
|
112 | + 'EVT_slug' => new EE_Slug_Field('post_name', esc_html__('Event Slug', 'event_espresso'), false, |
|
113 | + ''), |
|
114 | + 'EVT_created' => new EE_Datetime_Field('post_date', |
|
115 | + esc_html__('Date/Time Event Created', 'event_espresso'), |
|
116 | + false, EE_Datetime_Field::now), |
|
117 | + 'EVT_short_desc' => new EE_Simple_HTML_Field('post_excerpt', |
|
118 | + esc_html__('Event Short Description', 'event_espresso'), false, ''), |
|
119 | + 'EVT_modified' => new EE_Datetime_Field('post_modified', |
|
120 | + esc_html__('Date/Time Event Modified', 'event_espresso'), false, EE_Datetime_Field::now), |
|
121 | + 'EVT_wp_user' => new EE_WP_User_Field('post_author', |
|
122 | + esc_html__('Event Creator ID', 'event_espresso'), |
|
123 | + false), |
|
124 | + 'parent' => new EE_Integer_Field('post_parent', esc_html__('Event Parent ID', 'event_espresso'), |
|
125 | + false, |
|
126 | + 0), |
|
127 | + 'EVT_order' => new EE_Integer_Field('menu_order', esc_html__('Event Menu Order', 'event_espresso'), |
|
128 | + false, |
|
129 | + 1), |
|
130 | + 'post_type' => new EE_WP_Post_Type_Field('espresso_events'), |
|
131 | + // EE_Plain_Text_Field( 'post_type', esc_html__( 'Event Post Type', 'event_espresso' ), FALSE, 'espresso_events' ), |
|
132 | + 'status' => new EE_WP_Post_Status_Field('post_status', |
|
133 | + esc_html__('Event Status', 'event_espresso'), |
|
134 | + false, 'draft', $this->_custom_stati), |
|
135 | + ), |
|
136 | + 'Event_Meta' => array( |
|
137 | + 'EVTM_ID' => new EE_DB_Only_Float_Field('EVTM_ID', |
|
138 | + esc_html__('Event Meta Row ID', 'event_espresso'), false), |
|
139 | + 'EVT_ID_fk' => new EE_DB_Only_Int_Field('EVT_ID', |
|
140 | + esc_html__('Foreign key to Event ID from Event Meta table', 'event_espresso'), false), |
|
141 | + 'EVT_display_desc' => new EE_Boolean_Field('EVT_display_desc', |
|
142 | + esc_html__('Display Description Flag', 'event_espresso'), false, 1), |
|
143 | + 'EVT_display_ticket_selector' => new EE_Boolean_Field('EVT_display_ticket_selector', |
|
144 | + esc_html__('Display Ticket Selector Flag', 'event_espresso'), false, 1), |
|
145 | + 'EVT_visible_on' => new EE_Datetime_Field('EVT_visible_on', |
|
146 | + esc_html__('Event Visible Date', 'event_espresso'), true, EE_Datetime_Field::now), |
|
147 | + 'EVT_additional_limit' => new EE_Integer_Field( |
|
148 | + 'EVT_additional_limit', |
|
149 | + esc_html__('Limit of Additional Registrations on Same Transaction', 'event_espresso'), |
|
150 | + true, |
|
151 | + self::$_default_additional_limit |
|
152 | + ), |
|
153 | + 'EVT_default_registration_status' => new EE_Enum_Text_Field( |
|
154 | + 'EVT_default_registration_status', |
|
155 | + esc_html__('Default Registration Status on this Event', 'event_espresso'), false, |
|
156 | + EEM_Event::$_default_reg_status, EEM_Registration::reg_status_array() |
|
157 | + ), |
|
158 | + 'EVT_member_only' => new EE_Boolean_Field('EVT_member_only', |
|
159 | + esc_html__('Member-Only Event Flag', 'event_espresso'), false, false), |
|
160 | + 'EVT_phone' => new EE_Plain_Text_Field('EVT_phone', |
|
161 | + esc_html__('Event Phone Number', 'event_espresso'), false,''), |
|
162 | + 'EVT_allow_overflow' => new EE_Boolean_Field('EVT_allow_overflow', |
|
163 | + esc_html__('Allow Overflow on Event', 'event_espresso'), false, false), |
|
164 | + 'EVT_timezone_string' => new EE_Plain_Text_Field('EVT_timezone_string', |
|
165 | + esc_html__('Timezone (name) for Event times', 'event_espresso'), false,''), |
|
166 | + 'EVT_external_URL' => new EE_Plain_Text_Field('EVT_external_URL', |
|
167 | + esc_html__('URL of Event Page if hosted elsewhere', 'event_espresso'), true), |
|
168 | + 'EVT_donations' => new EE_Boolean_Field('EVT_donations', |
|
169 | + esc_html__('Accept Donations?', 'event_espresso'), false, false), |
|
170 | + ), |
|
171 | + ); |
|
172 | + $this->_model_relations = array( |
|
173 | + 'Registration' => new EE_Has_Many_Relation(), |
|
174 | + 'Datetime' => new EE_Has_Many_Relation(), |
|
175 | + 'Question_Group' => new EE_HABTM_Relation('Event_Question_Group'), |
|
176 | + 'Venue' => new EE_HABTM_Relation('Event_Venue'), |
|
177 | + 'Term_Relationship' => new EE_Has_Many_Relation(), |
|
178 | + 'Term_Taxonomy' => new EE_HABTM_Relation('Term_Relationship'), |
|
179 | + 'Message_Template_Group' => new EE_HABTM_Relation('Event_Message_Template'), |
|
180 | + 'Attendee' => new EE_HABTM_Relation('Registration'), |
|
181 | + 'WP_User' => new EE_Belongs_To_Relation(), |
|
182 | + ); |
|
183 | + //this model is generally available for reading |
|
184 | + $this->_cap_restriction_generators[EEM_Base::caps_read] = new EE_Restriction_Generator_Public(); |
|
185 | + parent::__construct($timezone); |
|
186 | + } |
|
187 | + |
|
188 | + |
|
189 | + |
|
190 | + /** |
|
191 | + * @param string $default_reg_status |
|
192 | + */ |
|
193 | + public static function set_default_reg_status($default_reg_status) |
|
194 | + { |
|
195 | + self::$_default_reg_status = $default_reg_status; |
|
196 | + // if EEM_Event has already been instantiated, |
|
197 | + // then we need to reset the `EVT_default_reg_status` field to use the new default. |
|
198 | + if (self::$_instance instanceof EEM_Event) { |
|
199 | + $default_reg_status = new EE_Enum_Text_Field( |
|
200 | + 'EVT_default_registration_status', |
|
201 | + esc_html__('Default Registration Status on this Event', 'event_espresso'), |
|
202 | + false, |
|
203 | + $default_reg_status, |
|
204 | + EEM_Registration::reg_status_array() |
|
205 | + ); |
|
206 | + $default_reg_status->_construct_finalize( |
|
207 | + 'Event_Meta', |
|
208 | + 'EVT_default_registration_status', |
|
209 | + 'EEM_Event' |
|
210 | + ); |
|
211 | + self::$_instance->_fields['Event_Meta']['EVT_default_registration_status'] = $default_reg_status; |
|
212 | + } |
|
213 | + } |
|
214 | + |
|
215 | + |
|
216 | + /** |
|
217 | + * Used to override the default for the additional limit field. |
|
218 | + * @param $additional_limit |
|
219 | + */ |
|
220 | + public static function set_default_additional_limit($additional_limit) |
|
221 | + { |
|
222 | + self::$_default_additional_limit = (int) $additional_limit; |
|
223 | + if (self::$_instance instanceof EEM_Event) { |
|
224 | + self::$_instance->_fields['Event_Meta']['EVT_additional_limit'] = new EE_Integer_Field( |
|
225 | + 'EVT_additional_limit', |
|
226 | + __('Limit of Additional Registrations on Same Transaction', 'event_espresso'), |
|
227 | + true, |
|
228 | + self::$_default_additional_limit |
|
229 | + ); |
|
230 | + self::$_instance->_fields['Event_Meta']['EVT_additional_limit']->_construct_finalize( |
|
231 | + 'Event_Meta', |
|
232 | + 'EVT_additional_limit', |
|
233 | + 'EEM_Event' |
|
234 | + ); |
|
235 | + } |
|
236 | + } |
|
237 | + |
|
238 | + |
|
239 | + /** |
|
240 | + * Return what is currently set as the default additional limit for the event. |
|
241 | + * @return int |
|
242 | + */ |
|
243 | + public static function get_default_additional_limit() |
|
244 | + { |
|
245 | + return apply_filters('FHEE__EEM_Event__get_default_additional_limit', self::$_default_additional_limit); |
|
246 | + } |
|
247 | + |
|
248 | + |
|
249 | + /** |
|
250 | + * get_question_groups |
|
251 | + * |
|
252 | + * @return array |
|
253 | + * @throws \EE_Error |
|
254 | + */ |
|
255 | + public function get_all_question_groups() |
|
256 | + { |
|
257 | + return EE_Registry::instance()->load_model('Question_Group')->get_all( |
|
258 | + array( |
|
259 | + array('QSG_deleted' => false), |
|
260 | + 'order_by' => array('QSG_order' => 'ASC'), |
|
261 | + ) |
|
262 | + ); |
|
263 | + } |
|
264 | + |
|
265 | + |
|
266 | + |
|
267 | + /** |
|
268 | + * get_question_groups |
|
269 | + * |
|
270 | + * @param int $EVT_ID |
|
271 | + * @return array|bool |
|
272 | + * @throws \EE_Error |
|
273 | + */ |
|
274 | + public function get_all_event_question_groups($EVT_ID = 0) |
|
275 | + { |
|
276 | + if (! isset($EVT_ID) || ! absint($EVT_ID)) { |
|
277 | + EE_Error::add_error( |
|
278 | + esc_html__( |
|
279 | + 'An error occurred. No Event Question Groups could be retrieved because an Event ID was not received.', |
|
280 | + 'event_espresso' |
|
281 | + ), |
|
282 | + __FILE__, __FUNCTION__, __LINE__ |
|
283 | + ); |
|
284 | + return false; |
|
285 | + } |
|
286 | + return EE_Registry::instance()->load_model('Event_Question_Group')->get_all( |
|
287 | + array( |
|
288 | + array('EVT_ID' => $EVT_ID), |
|
289 | + ) |
|
290 | + ); |
|
291 | + } |
|
292 | + |
|
293 | + |
|
294 | + |
|
295 | + /** |
|
296 | + * get_question_groups |
|
297 | + * |
|
298 | + * @param int $EVT_ID |
|
299 | + * @param boolean $for_primary_attendee |
|
300 | + * @return array|bool |
|
301 | + * @throws \EE_Error |
|
302 | + */ |
|
303 | + public function get_event_question_groups($EVT_ID = 0, $for_primary_attendee = true) |
|
304 | + { |
|
305 | + if (! isset($EVT_ID) || ! absint($EVT_ID)) { |
|
306 | + EE_Error::add_error( |
|
307 | + esc_html__( |
|
308 | + 'An error occurred. No Event Question Groups could be retrieved because an Event ID was not received.', |
|
309 | + 'event_espresso' |
|
310 | + ), |
|
311 | + __FILE__, __FUNCTION__, __LINE__ |
|
312 | + ); |
|
313 | + return false; |
|
314 | + } |
|
315 | + return EE_Registry::instance()->load_model('Event_Question_Group')->get_all( |
|
316 | + array( |
|
317 | + array( |
|
318 | + 'EVT_ID' => $EVT_ID, |
|
319 | + 'EQG_primary' => $for_primary_attendee, |
|
320 | + ), |
|
321 | + ) |
|
322 | + ); |
|
323 | + } |
|
324 | + |
|
325 | + |
|
326 | + |
|
327 | + /** |
|
328 | + * get_question_groups |
|
329 | + * |
|
330 | + * @param int $EVT_ID |
|
331 | + * @param EE_Registration $registration |
|
332 | + * @return array|bool |
|
333 | + * @throws \EE_Error |
|
334 | + */ |
|
335 | + public function get_question_groups_for_event($EVT_ID = 0, EE_Registration $registration) |
|
336 | + { |
|
337 | + if (! isset($EVT_ID) || ! absint($EVT_ID)) { |
|
338 | + EE_Error::add_error( |
|
339 | + esc_html__( |
|
340 | + 'An error occurred. No Question Groups could be retrieved because an Event ID was not received.', |
|
341 | + 'event_espresso' |
|
342 | + ), |
|
343 | + __FILE__, __FUNCTION__, __LINE__ |
|
344 | + ); |
|
345 | + return false; |
|
346 | + } |
|
347 | + $where_params = array( |
|
348 | + 'Event_Question_Group.EVT_ID' => $EVT_ID, |
|
349 | + 'Event_Question_Group.EQG_primary' => $registration->count() === 1 ? true : false, |
|
350 | + 'QSG_deleted' => false, |
|
351 | + ); |
|
352 | + return EE_Registry::instance()->load_model('Question_Group')->get_all( |
|
353 | + array( |
|
354 | + $where_params, |
|
355 | + 'order_by' => array('QSG_order' => 'ASC'), |
|
356 | + ) |
|
357 | + ); |
|
358 | + } |
|
359 | + |
|
360 | + |
|
361 | + |
|
362 | + /** |
|
363 | + * get_question_target_db_column |
|
364 | + * |
|
365 | + * @param string $QSG_IDs csv list of $QSG IDs |
|
366 | + * @return array|bool |
|
367 | + * @throws \EE_Error |
|
368 | + */ |
|
369 | + public function get_questions_in_groups($QSG_IDs = '') |
|
370 | + { |
|
371 | + if (empty($QSG_IDs)) { |
|
372 | + EE_Error::add_error( |
|
373 | + esc_html__('An error occurred. No Question Group IDs were received.', 'event_espresso'), |
|
374 | + __FILE__, __FUNCTION__, __LINE__ |
|
375 | + ); |
|
376 | + return false; |
|
377 | + } |
|
378 | + return EE_Registry::instance()->load_model('Question')->get_all( |
|
379 | + array( |
|
380 | + array( |
|
381 | + 'Question_Group.QSG_ID' => array('IN', $QSG_IDs), |
|
382 | + 'QST_deleted' => false, |
|
383 | + 'QST_admin_only' => is_admin(), |
|
384 | + ), |
|
385 | + 'order_by' => 'QST_order', |
|
386 | + ) |
|
387 | + ); |
|
388 | + } |
|
389 | + |
|
390 | + |
|
391 | + |
|
392 | + /** |
|
393 | + * get_options_for_question |
|
394 | + * |
|
395 | + * @param string $QST_IDs csv list of $QST IDs |
|
396 | + * @return array|bool |
|
397 | + * @throws \EE_Error |
|
398 | + */ |
|
399 | + public function get_options_for_question($QST_IDs) |
|
400 | + { |
|
401 | + if (empty($QST_IDs)) { |
|
402 | + EE_Error::add_error( |
|
403 | + esc_html__('An error occurred. No Question IDs were received.', 'event_espresso'), |
|
404 | + __FILE__, __FUNCTION__, __LINE__ |
|
405 | + ); |
|
406 | + return false; |
|
407 | + } |
|
408 | + return EE_Registry::instance()->load_model('Question_Option')->get_all( |
|
409 | + array( |
|
410 | + array( |
|
411 | + 'Question.QST_ID' => array('IN', $QST_IDs), |
|
412 | + 'QSO_deleted' => false, |
|
413 | + ), |
|
414 | + 'order_by' => 'QSO_ID', |
|
415 | + ) |
|
416 | + ); |
|
417 | + } |
|
418 | + |
|
419 | + |
|
420 | + |
|
421 | + |
|
422 | + |
|
423 | + |
|
424 | + |
|
425 | + /** |
|
426 | + * Gets all events that are published |
|
427 | + * and have event start time earlier than now and an event end time later than now |
|
428 | + * |
|
429 | + * @param array $query_params An array of query params to further filter on |
|
430 | + * (note that status and DTT_EVT_start and DTT_EVT_end will be overridden) |
|
431 | + * @param bool $count whether to return the count or not (default FALSE) |
|
432 | + * @return EE_Event[]|int |
|
433 | + * @throws \EE_Error |
|
434 | + */ |
|
435 | + public function get_active_events($query_params, $count = false) |
|
436 | + { |
|
437 | + if (array_key_exists(0, $query_params)) { |
|
438 | + $where_params = $query_params[0]; |
|
439 | + unset($query_params[0]); |
|
440 | + } else { |
|
441 | + $where_params = array(); |
|
442 | + } |
|
443 | + // if we have count make sure we don't include group by |
|
444 | + if ($count && isset($query_params['group_by'])) { |
|
445 | + unset($query_params['group_by']); |
|
446 | + } |
|
447 | + // let's add specific query_params for active_events |
|
448 | + // keep in mind this will override any sent status in the query AND any date queries. |
|
449 | + $where_params['status'] = array('IN', array('publish', EEM_Event::sold_out)); |
|
450 | + //if already have where params for DTT_EVT_start or DTT_EVT_end then append these conditions |
|
451 | + if (isset($where_params['Datetime.DTT_EVT_start'])) { |
|
452 | + $where_params['Datetime.DTT_EVT_start******'] = array( |
|
453 | + '<', |
|
454 | + EEM_Datetime::instance()->current_time_for_query('DTT_EVT_start'), |
|
455 | + ); |
|
456 | + } else { |
|
457 | + $where_params['Datetime.DTT_EVT_start'] = array( |
|
458 | + '<', |
|
459 | + EEM_Datetime::instance()->current_time_for_query('DTT_EVT_start'), |
|
460 | + ); |
|
461 | + } |
|
462 | + if (isset($where_params['Datetime.DTT_EVT_end'])) { |
|
463 | + $where_params['Datetime.DTT_EVT_end*****'] = array( |
|
464 | + '>', |
|
465 | + EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'), |
|
466 | + ); |
|
467 | + } else { |
|
468 | + $where_params['Datetime.DTT_EVT_end'] = array( |
|
469 | + '>', |
|
470 | + EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'), |
|
471 | + ); |
|
472 | + } |
|
473 | + $query_params[0] = $where_params; |
|
474 | + // don't use $query_params with count() |
|
475 | + // because we don't want to include additional query clauses like "GROUP BY" |
|
476 | + return $count |
|
477 | + ? $this->count(array($where_params), 'EVT_ID', true) |
|
478 | + : $this->get_all($query_params); |
|
479 | + } |
|
480 | + |
|
481 | + |
|
482 | + |
|
483 | + /** |
|
484 | + * get all events that are published and have an event start time later than now |
|
485 | + * |
|
486 | + * @param array $query_params An array of query params to further filter on |
|
487 | + * (Note that status and DTT_EVT_start will be overridden) |
|
488 | + * @param bool $count whether to return the count or not (default FALSE) |
|
489 | + * @return EE_Event[]|int |
|
490 | + * @throws \EE_Error |
|
491 | + */ |
|
492 | + public function get_upcoming_events($query_params, $count = false) |
|
493 | + { |
|
494 | + if (array_key_exists(0, $query_params)) { |
|
495 | + $where_params = $query_params[0]; |
|
496 | + unset($query_params[0]); |
|
497 | + } else { |
|
498 | + $where_params = array(); |
|
499 | + } |
|
500 | + // if we have count make sure we don't include group by |
|
501 | + if ($count && isset($query_params['group_by'])) { |
|
502 | + unset($query_params['group_by']); |
|
503 | + } |
|
504 | + // let's add specific query_params for active_events |
|
505 | + // keep in mind this will override any sent status in the query AND any date queries. |
|
506 | + $where_params['status'] = array('IN', array('publish', EEM_Event::sold_out)); |
|
507 | + // if there are already query_params matching DTT_EVT_start then we need to modify that to add them. |
|
508 | + if (isset($where_params['Datetime.DTT_EVT_start'])) { |
|
509 | + $where_params['Datetime.DTT_EVT_start*****'] = array( |
|
510 | + '>', |
|
511 | + EEM_Datetime::instance()->current_time_for_query('DTT_EVT_start'), |
|
512 | + ); |
|
513 | + } else { |
|
514 | + $where_params['Datetime.DTT_EVT_start'] = array( |
|
515 | + '>', |
|
516 | + EEM_Datetime::instance()->current_time_for_query('DTT_EVT_start'), |
|
517 | + ); |
|
518 | + } |
|
519 | + $query_params[0] = $where_params; |
|
520 | + // don't use $query_params with count() |
|
521 | + // because we don't want to include additional query clauses like "GROUP BY" |
|
522 | + return $count |
|
523 | + ? $this->count(array($where_params), 'EVT_ID', true) |
|
524 | + : $this->get_all($query_params); |
|
525 | + } |
|
526 | + |
|
527 | + |
|
528 | + |
|
529 | + /** |
|
530 | + * Gets all events that are published |
|
531 | + * and have an event end time later than now |
|
532 | + * |
|
533 | + * @param array $query_params An array of query params to further filter on |
|
534 | + * (note that status and DTT_EVT_end will be overridden) |
|
535 | + * @param bool $count whether to return the count or not (default FALSE) |
|
536 | + * @return EE_Event[]|int |
|
537 | + * @throws \EE_Error |
|
538 | + */ |
|
539 | + public function get_active_and_upcoming_events($query_params, $count = false) |
|
540 | + { |
|
541 | + if (array_key_exists(0, $query_params)) { |
|
542 | + $where_params = $query_params[0]; |
|
543 | + unset($query_params[0]); |
|
544 | + } else { |
|
545 | + $where_params = array(); |
|
546 | + } |
|
547 | + // if we have count make sure we don't include group by |
|
548 | + if ($count && isset($query_params['group_by'])) { |
|
549 | + unset($query_params['group_by']); |
|
550 | + } |
|
551 | + // let's add specific query_params for active_events |
|
552 | + // keep in mind this will override any sent status in the query AND any date queries. |
|
553 | + $where_params['status'] = array('IN', array('publish', EEM_Event::sold_out)); |
|
554 | + // add where params for DTT_EVT_end |
|
555 | + if (isset($where_params['Datetime.DTT_EVT_end'])) { |
|
556 | + $where_params['Datetime.DTT_EVT_end*****'] = array( |
|
557 | + '>', |
|
558 | + EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'), |
|
559 | + ); |
|
560 | + } else { |
|
561 | + $where_params['Datetime.DTT_EVT_end'] = array( |
|
562 | + '>', |
|
563 | + EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'), |
|
564 | + ); |
|
565 | + } |
|
566 | + $query_params[0] = $where_params; |
|
567 | + // don't use $query_params with count() |
|
568 | + // because we don't want to include additional query clauses like "GROUP BY" |
|
569 | + return $count |
|
570 | + ? $this->count(array($where_params), 'EVT_ID', true) |
|
571 | + : $this->get_all($query_params); |
|
572 | + } |
|
573 | + |
|
574 | + |
|
575 | + |
|
576 | + /** |
|
577 | + * This only returns events that are expired. |
|
578 | + * They may still be published but all their datetimes have expired. |
|
579 | + * |
|
580 | + * @param array $query_params An array of query params to further filter on |
|
581 | + * (note that status and DTT_EVT_end will be overridden) |
|
582 | + * @param bool $count whether to return the count or not (default FALSE) |
|
583 | + * @return EE_Event[]|int |
|
584 | + * @throws \EE_Error |
|
585 | + */ |
|
586 | + public function get_expired_events($query_params, $count = false) |
|
587 | + { |
|
588 | + $where_params = isset($query_params[0]) ? $query_params[0] : array(); |
|
589 | + // if we have count make sure we don't include group by |
|
590 | + if ($count && isset($query_params['group_by'])) { |
|
591 | + unset($query_params['group_by']); |
|
592 | + } |
|
593 | + // let's add specific query_params for active_events |
|
594 | + // keep in mind this will override any sent status in the query AND any date queries. |
|
595 | + if (isset($where_params['status'])) { |
|
596 | + unset($where_params['status']); |
|
597 | + } |
|
598 | + $exclude_query = $query_params; |
|
599 | + if (isset($exclude_query[0])) { |
|
600 | + unset($exclude_query[0]); |
|
601 | + } |
|
602 | + $exclude_query[0] = array( |
|
603 | + 'Datetime.DTT_EVT_end' => array( |
|
604 | + '>', |
|
605 | + EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'), |
|
606 | + ), |
|
607 | + ); |
|
608 | + // first get all events that have datetimes where its not expired. |
|
609 | + $event_ids = $this->_get_all_wpdb_results($exclude_query, OBJECT_K, 'Event_CPT.ID'); |
|
610 | + $event_ids = array_keys($event_ids); |
|
611 | + // if we have any additional query_params, let's add them to the 'AND' condition |
|
612 | + $and_condition = array( |
|
613 | + 'Datetime.DTT_EVT_end' => array('<', EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end')), |
|
614 | + 'EVT_ID' => array('NOT IN', $event_ids), |
|
615 | + ); |
|
616 | + if (isset($where_params['OR'])) { |
|
617 | + $and_condition['OR'] = $where_params['OR']; |
|
618 | + unset($where_params['OR']); |
|
619 | + } |
|
620 | + if (isset($where_params['Datetime.DTT_EVT_end'])) { |
|
621 | + $and_condition['Datetime.DTT_EVT_end****'] = $where_params['Datetime.DTT_EVT_end']; |
|
622 | + unset($where_params['Datetime.DTT_EVT_end']); |
|
623 | + } |
|
624 | + if (isset($where_params['Datetime.DTT_EVT_start'])) { |
|
625 | + $and_condition['Datetime.DTT_EVT_start'] = $where_params['Datetime.DTT_EVT_start']; |
|
626 | + unset($where_params['Datetime.DTT_EVT_start']); |
|
627 | + } |
|
628 | + // merge remaining $where params with the and conditions. |
|
629 | + $where_params['AND'] = array_merge($and_condition, $where_params); |
|
630 | + $query_params[0] = $where_params; |
|
631 | + // don't use $query_params with count() |
|
632 | + // because we don't want to include additional query clauses like "GROUP BY" |
|
633 | + return $count |
|
634 | + ? $this->count(array($where_params), 'EVT_ID', true) |
|
635 | + : $this->get_all($query_params); |
|
636 | + } |
|
637 | + |
|
638 | + |
|
639 | + |
|
640 | + /** |
|
641 | + * This basically just returns the events that do not have the publish status. |
|
642 | + * |
|
643 | + * @param array $query_params An array of query params to further filter on |
|
644 | + * (note that status will be overwritten) |
|
645 | + * @param boolean $count whether to return the count or not (default FALSE) |
|
646 | + * @return EE_Event[]|int |
|
647 | + * @throws \EE_Error |
|
648 | + */ |
|
649 | + public function get_inactive_events($query_params, $count = false) |
|
650 | + { |
|
651 | + $where_params = isset($query_params[0]) ? $query_params[0] : array(); |
|
652 | + // let's add in specific query_params for inactive events. |
|
653 | + if (isset($where_params['status'])) { |
|
654 | + unset($where_params['status']); |
|
655 | + } |
|
656 | + // if we have count make sure we don't include group by |
|
657 | + if ($count && isset($query_params['group_by'])) { |
|
658 | + unset($query_params['group_by']); |
|
659 | + } |
|
660 | + // if we have any additional query_params, let's add them to the 'AND' condition |
|
661 | + $where_params['AND']['status'] = array('!=', 'publish'); |
|
662 | + if (isset($where_params['OR'])) { |
|
663 | + $where_params['AND']['OR'] = $where_params['OR']; |
|
664 | + unset($where_params['OR']); |
|
665 | + } |
|
666 | + if (isset($where_params['Datetime.DTT_EVT_end'])) { |
|
667 | + $where_params['AND']['Datetime.DTT_EVT_end****'] = $where_params['Datetime.DTT_EVT_end']; |
|
668 | + unset($where_params['Datetime.DTT_EVT_end']); |
|
669 | + } |
|
670 | + if (isset($where_params['Datetime.DTT_EVT_start'])) { |
|
671 | + $where_params['AND']['Datetime.DTT_EVT_start'] = $where_params['Datetime.DTT_EVT_start']; |
|
672 | + unset($where_params['Datetime.DTT_EVT_start']); |
|
673 | + } |
|
674 | + $query_params[0] = $where_params; |
|
675 | + // don't use $query_params with count() |
|
676 | + // because we don't want to include additional query clauses like "GROUP BY" |
|
677 | + return $count |
|
678 | + ? $this->count(array($where_params), 'EVT_ID', true) |
|
679 | + : $this->get_all($query_params); |
|
680 | + } |
|
681 | + |
|
682 | + |
|
683 | + |
|
684 | + /** |
|
685 | + * This is just injecting into the parent add_relationship_to so we do special handling on price relationships |
|
686 | + * because we don't want to override any existing global default prices but instead insert NEW prices that get |
|
687 | + * attached to the event. See parent for param descriptions |
|
688 | + * |
|
689 | + * @param $id_or_obj |
|
690 | + * @param $other_model_id_or_obj |
|
691 | + * @param string $relationName |
|
692 | + * @param array $where_query |
|
693 | + * @return EE_Base_Class |
|
694 | + * @throws EE_Error |
|
695 | + */ |
|
696 | + public function add_relationship_to($id_or_obj, $other_model_id_or_obj, $relationName, $where_query = array()) |
|
697 | + { |
|
698 | + if ($relationName === 'Price') { |
|
699 | + //let's get the PRC object for the given ID to make sure that we aren't dealing with a default |
|
700 | + $prc_chk = $this->get_related_model_obj($relationName)->ensure_is_obj($other_model_id_or_obj); |
|
701 | + //if EVT_ID = 0, then this is a default |
|
702 | + if ((int) $prc_chk->get('EVT_ID') === 0) { |
|
703 | + //let's set the prc_id as 0 so we force an insert on the add_relation_to carried out by relation |
|
704 | + $prc_chk->set('PRC_ID', 0); |
|
705 | + } |
|
706 | + //run parent |
|
707 | + return parent::add_relationship_to($id_or_obj, $prc_chk, $relationName, $where_query); |
|
708 | + } |
|
709 | + //otherwise carry on as normal |
|
710 | + return parent::add_relationship_to($id_or_obj, $other_model_id_or_obj, $relationName, $where_query); |
|
711 | + } |
|
712 | + |
|
713 | + |
|
714 | + |
|
715 | + /******************** DEPRECATED METHODS ********************/ |
|
716 | + |
|
717 | + |
|
718 | + |
|
719 | + /** |
|
720 | + * _get_question_target_db_column |
|
721 | + * |
|
722 | + * @deprecated as of 4.8.32.rc.001. Instead consider using |
|
723 | + * EE_Registration_Custom_Questions_Form located in |
|
724 | + * admin_pages/registrations/form_sections/EE_Registration_Custom_Questions_Form.form.php |
|
725 | + * @access public |
|
726 | + * @param EE_Registration $registration (so existing answers for registration are included) |
|
727 | + * @param int $EVT_ID so all question groups are included for event (not just answers from |
|
728 | + * registration). |
|
729 | + * @throws EE_Error |
|
730 | + * @return array |
|
731 | + */ |
|
732 | + public function assemble_array_of_groups_questions_and_options(EE_Registration $registration, $EVT_ID = 0) |
|
733 | + { |
|
734 | + if (empty($EVT_ID)) { |
|
735 | + throw new EE_Error(__('An error occurred. No EVT_ID is included. Needed to know which question groups to retrieve.', |
|
736 | + 'event_espresso')); |
|
737 | + } |
|
738 | + $questions = array(); |
|
739 | + // get all question groups for event |
|
740 | + $qgs = $this->get_question_groups_for_event($EVT_ID, $registration); |
|
741 | + if (! empty($qgs)) { |
|
742 | + foreach ($qgs as $qg) { |
|
743 | + $qsts = $qg->questions(); |
|
744 | + $questions[$qg->ID()] = $qg->model_field_array(); |
|
745 | + $questions[$qg->ID()]['QSG_questions'] = array(); |
|
746 | + foreach ($qsts as $qst) { |
|
747 | + if ($qst->is_system_question()) { |
|
748 | + continue; |
|
749 | + } |
|
750 | + $answer = EEM_Answer::instance()->get_one(array( |
|
751 | + array( |
|
752 | + 'QST_ID' => $qst->ID(), |
|
753 | + 'REG_ID' => $registration->ID(), |
|
754 | + ), |
|
755 | + )); |
|
756 | + $answer = $answer instanceof EE_Answer ? $answer : EEM_Answer::instance()->create_default_object(); |
|
757 | + $qst_name = $qstn_id = $qst->ID(); |
|
758 | + $ans_id = $answer->ID(); |
|
759 | + $qst_name = ! empty($ans_id) ? '[' . $qst_name . '][' . $ans_id . ']' : '[' . $qst_name . ']'; |
|
760 | + $input_name = ''; |
|
761 | + $input_id = sanitize_key($qst->display_text()); |
|
762 | + $input_class = ''; |
|
763 | + $questions[$qg->ID()]['QSG_questions'][$qst->ID()] = $qst->model_field_array(); |
|
764 | + $questions[$qg->ID()]['QSG_questions'][$qst->ID()]['QST_input_name'] = 'qstn' |
|
765 | + . $input_name |
|
766 | + . $qst_name; |
|
767 | + $questions[$qg->ID()]['QSG_questions'][$qst->ID()]['QST_input_id'] = $input_id . '-' . $qstn_id; |
|
768 | + $questions[$qg->ID()]['QSG_questions'][$qst->ID()]['QST_input_class'] = $input_class; |
|
769 | + $questions[$qg->ID()]['QSG_questions'][$qst->ID()]['QST_options'] = array(); |
|
770 | + $questions[$qg->ID()]['QSG_questions'][$qst->ID()]['qst_obj'] = $qst; |
|
771 | + $questions[$qg->ID()]['QSG_questions'][$qst->ID()]['ans_obj'] = $answer; |
|
772 | + //leave responses as-is, don't convert stuff into html entities please! |
|
773 | + $questions[$qg->ID()]['QSG_questions'][$qst->ID()]['htmlentities'] = false; |
|
774 | + if ($qst->type() == 'RADIO_BTN' || $qst->type() == 'CHECKBOX' || $qst->type() == 'DROPDOWN') { |
|
775 | + $QSOs = $qst->options(true, $answer->value()); |
|
776 | + if (is_array($QSOs)) { |
|
777 | + foreach ($QSOs as $QSO_ID => $QSO) { |
|
778 | + $questions[$qg->ID()]['QSG_questions'][$qst->ID()]['QST_options'][$QSO_ID] = $QSO->model_field_array(); |
|
779 | + } |
|
780 | + } |
|
781 | + } |
|
782 | + } |
|
783 | + } |
|
784 | + } |
|
785 | + return $questions; |
|
786 | + } |
|
787 | 787 | |
788 | 788 | |
789 | 789 | } |
@@ -1,9 +1,9 @@ discard block |
||
1 | 1 | <?php use EventEspresso\core\services\orm\ModelFieldFactory; |
2 | 2 | |
3 | -if (! defined('EVENT_ESPRESSO_VERSION')) { |
|
3 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
4 | 4 | exit('No direct script access allowed'); |
5 | 5 | } |
6 | -require_once(EE_MODELS . 'EEM_CPT_Base.model.php'); |
|
6 | +require_once(EE_MODELS.'EEM_CPT_Base.model.php'); |
|
7 | 7 | |
8 | 8 | |
9 | 9 | |
@@ -158,11 +158,11 @@ discard block |
||
158 | 158 | 'EVT_member_only' => new EE_Boolean_Field('EVT_member_only', |
159 | 159 | esc_html__('Member-Only Event Flag', 'event_espresso'), false, false), |
160 | 160 | 'EVT_phone' => new EE_Plain_Text_Field('EVT_phone', |
161 | - esc_html__('Event Phone Number', 'event_espresso'), false,''), |
|
161 | + esc_html__('Event Phone Number', 'event_espresso'), false, ''), |
|
162 | 162 | 'EVT_allow_overflow' => new EE_Boolean_Field('EVT_allow_overflow', |
163 | 163 | esc_html__('Allow Overflow on Event', 'event_espresso'), false, false), |
164 | 164 | 'EVT_timezone_string' => new EE_Plain_Text_Field('EVT_timezone_string', |
165 | - esc_html__('Timezone (name) for Event times', 'event_espresso'), false,''), |
|
165 | + esc_html__('Timezone (name) for Event times', 'event_espresso'), false, ''), |
|
166 | 166 | 'EVT_external_URL' => new EE_Plain_Text_Field('EVT_external_URL', |
167 | 167 | esc_html__('URL of Event Page if hosted elsewhere', 'event_espresso'), true), |
168 | 168 | 'EVT_donations' => new EE_Boolean_Field('EVT_donations', |
@@ -273,7 +273,7 @@ discard block |
||
273 | 273 | */ |
274 | 274 | public function get_all_event_question_groups($EVT_ID = 0) |
275 | 275 | { |
276 | - if (! isset($EVT_ID) || ! absint($EVT_ID)) { |
|
276 | + if ( ! isset($EVT_ID) || ! absint($EVT_ID)) { |
|
277 | 277 | EE_Error::add_error( |
278 | 278 | esc_html__( |
279 | 279 | 'An error occurred. No Event Question Groups could be retrieved because an Event ID was not received.', |
@@ -302,7 +302,7 @@ discard block |
||
302 | 302 | */ |
303 | 303 | public function get_event_question_groups($EVT_ID = 0, $for_primary_attendee = true) |
304 | 304 | { |
305 | - if (! isset($EVT_ID) || ! absint($EVT_ID)) { |
|
305 | + if ( ! isset($EVT_ID) || ! absint($EVT_ID)) { |
|
306 | 306 | EE_Error::add_error( |
307 | 307 | esc_html__( |
308 | 308 | 'An error occurred. No Event Question Groups could be retrieved because an Event ID was not received.', |
@@ -334,7 +334,7 @@ discard block |
||
334 | 334 | */ |
335 | 335 | public function get_question_groups_for_event($EVT_ID = 0, EE_Registration $registration) |
336 | 336 | { |
337 | - if (! isset($EVT_ID) || ! absint($EVT_ID)) { |
|
337 | + if ( ! isset($EVT_ID) || ! absint($EVT_ID)) { |
|
338 | 338 | EE_Error::add_error( |
339 | 339 | esc_html__( |
340 | 340 | 'An error occurred. No Question Groups could be retrieved because an Event ID was not received.', |
@@ -738,7 +738,7 @@ discard block |
||
738 | 738 | $questions = array(); |
739 | 739 | // get all question groups for event |
740 | 740 | $qgs = $this->get_question_groups_for_event($EVT_ID, $registration); |
741 | - if (! empty($qgs)) { |
|
741 | + if ( ! empty($qgs)) { |
|
742 | 742 | foreach ($qgs as $qg) { |
743 | 743 | $qsts = $qg->questions(); |
744 | 744 | $questions[$qg->ID()] = $qg->model_field_array(); |
@@ -756,7 +756,7 @@ discard block |
||
756 | 756 | $answer = $answer instanceof EE_Answer ? $answer : EEM_Answer::instance()->create_default_object(); |
757 | 757 | $qst_name = $qstn_id = $qst->ID(); |
758 | 758 | $ans_id = $answer->ID(); |
759 | - $qst_name = ! empty($ans_id) ? '[' . $qst_name . '][' . $ans_id . ']' : '[' . $qst_name . ']'; |
|
759 | + $qst_name = ! empty($ans_id) ? '['.$qst_name.']['.$ans_id.']' : '['.$qst_name.']'; |
|
760 | 760 | $input_name = ''; |
761 | 761 | $input_id = sanitize_key($qst->display_text()); |
762 | 762 | $input_class = ''; |
@@ -764,7 +764,7 @@ discard block |
||
764 | 764 | $questions[$qg->ID()]['QSG_questions'][$qst->ID()]['QST_input_name'] = 'qstn' |
765 | 765 | . $input_name |
766 | 766 | . $qst_name; |
767 | - $questions[$qg->ID()]['QSG_questions'][$qst->ID()]['QST_input_id'] = $input_id . '-' . $qstn_id; |
|
767 | + $questions[$qg->ID()]['QSG_questions'][$qst->ID()]['QST_input_id'] = $input_id.'-'.$qstn_id; |
|
768 | 768 | $questions[$qg->ID()]['QSG_questions'][$qst->ID()]['QST_input_class'] = $input_class; |
769 | 769 | $questions[$qg->ID()]['QSG_questions'][$qst->ID()]['QST_options'] = array(); |
770 | 770 | $questions[$qg->ID()]['QSG_questions'][$qst->ID()]['qst_obj'] = $qst; |
@@ -132,7 +132,6 @@ discard block |
||
132 | 132 | /** |
133 | 133 | * @param string $table_column |
134 | 134 | * @param string $nice_name |
135 | - * @param string $timezone_string |
|
136 | 135 | * @param bool $nullable |
137 | 136 | * @param string $default_value |
138 | 137 | * @throws EE_Error |
@@ -179,7 +178,7 @@ discard block |
||
179 | 178 | * @param string $table_column |
180 | 179 | * @param string $nice_name |
181 | 180 | * @param bool $nullable |
182 | - * @param null $default_value |
|
181 | + * @param integer $default_value |
|
183 | 182 | * @return EE_DB_Only_Int_Field |
184 | 183 | */ |
185 | 184 | public function createDbOnlyIntField($table_column, $nice_name, $nullable, $default_value = null) |
@@ -295,7 +294,7 @@ discard block |
||
295 | 294 | * @param string $table_column |
296 | 295 | * @param string $nice_name |
297 | 296 | * @param bool $nullable |
298 | - * @param null $default_value |
|
297 | + * @param integer $default_value |
|
299 | 298 | * @param string $model_name |
300 | 299 | * @return EE_Foreign_Key_Int_Field |
301 | 300 | */ |
@@ -313,7 +312,7 @@ discard block |
||
313 | 312 | * @param string $table_column |
314 | 313 | * @param string $nice_name |
315 | 314 | * @param bool $nullable |
316 | - * @param null $default_value |
|
315 | + * @param string $default_value |
|
317 | 316 | * @param string $model_name |
318 | 317 | * @return EE_Foreign_Key_String_Field |
319 | 318 | */ |
@@ -564,7 +563,7 @@ discard block |
||
564 | 563 | * @param string $table_column |
565 | 564 | * @param string $nice_name |
566 | 565 | * @param bool $nullable |
567 | - * @param mixed $default_value |
|
566 | + * @param string $default_value |
|
568 | 567 | * @param array $values If additional stati are to be used other than the default WP statuses, |
569 | 568 | * then they can be registered via this property. |
570 | 569 | * The format of the array should be as follows: |
@@ -33,9 +33,6 @@ |
||
33 | 33 | use EE_WP_Post_Status_Field; |
34 | 34 | use EE_WP_Post_Type_Field; |
35 | 35 | use EE_WP_User_Field; |
36 | -use EventEspresso\core\exceptions\InvalidDataTypeException; |
|
37 | -use EventEspresso\core\exceptions\InvalidInterfaceException; |
|
38 | -use EventEspresso\core\services\loaders\LoaderFactory; |
|
39 | 36 | use EventEspresso\core\services\loaders\LoaderInterface; |
40 | 37 | use InvalidArgumentException; |
41 | 38 |
@@ -53,576 +53,576 @@ |
||
53 | 53 | class ModelFieldFactory |
54 | 54 | { |
55 | 55 | |
56 | - /** |
|
57 | - * @var LoaderInterface $loader |
|
58 | - */ |
|
59 | - private $loader; |
|
60 | - |
|
61 | - |
|
62 | - |
|
63 | - /** |
|
64 | - * ModelFieldFactory constructor. |
|
65 | - * |
|
66 | - * @param LoaderInterface $loader |
|
67 | - */ |
|
68 | - public function __construct(LoaderInterface $loader) |
|
69 | - { |
|
70 | - $this->loader = $loader; |
|
71 | - } |
|
72 | - |
|
73 | - |
|
74 | - |
|
75 | - /** |
|
76 | - * @param string $table_column |
|
77 | - * @param string $nice_name |
|
78 | - * @param bool $nullable |
|
79 | - * @param null $default_value |
|
80 | - * @return EE_All_Caps_Text_Field |
|
81 | - */ |
|
82 | - public function createAllCapsTextField($table_column, $nice_name, $nullable, $default_value = null) |
|
83 | - { |
|
84 | - return $this->loader->getNew( |
|
85 | - 'EE_All_Caps_Text_Field', |
|
86 | - array($table_column, $nice_name, $nullable, $default_value) |
|
87 | - ); |
|
88 | - } |
|
89 | - |
|
90 | - |
|
91 | - |
|
92 | - /** |
|
93 | - * @param string $table_column |
|
94 | - * @param string $nice_name |
|
95 | - * @param bool $nullable |
|
96 | - * @param null $default_value |
|
97 | - * @param string $model_name |
|
98 | - * @return EE_Any_Foreign_Model_Name_Field |
|
99 | - */ |
|
100 | - public function createAnyForeignModelNameField( |
|
101 | - $table_column, |
|
102 | - $nice_name, |
|
103 | - $nullable, |
|
104 | - $default_value = null, |
|
105 | - $model_name |
|
106 | - ) { |
|
107 | - return $this->loader->getNew( |
|
108 | - 'EE_Any_Foreign_Model_Name_Field', |
|
109 | - array($table_column, $nice_name, $nullable, $default_value, $model_name) |
|
110 | - ); |
|
111 | - } |
|
112 | - |
|
113 | - |
|
114 | - |
|
115 | - /** |
|
116 | - * @param string $table_column |
|
117 | - * @param string $nice_name |
|
118 | - * @param bool $nullable |
|
119 | - * @param null $default_value |
|
120 | - * @return EE_Boolean_Field |
|
121 | - */ |
|
122 | - public function createBooleanField($table_column, $nice_name, $nullable, $default_value = null) |
|
123 | - { |
|
124 | - return $this->loader->getNew( |
|
125 | - 'EE_Boolean_Field', |
|
126 | - array($table_column, $nice_name, $nullable, $default_value) |
|
127 | - ); |
|
128 | - } |
|
129 | - |
|
130 | - |
|
131 | - |
|
132 | - /** |
|
133 | - * @param string $table_column |
|
134 | - * @param string $nice_name |
|
135 | - * @param string $timezone_string |
|
136 | - * @param bool $nullable |
|
137 | - * @param string $default_value |
|
138 | - * @throws EE_Error |
|
139 | - * @throws InvalidArgumentException |
|
140 | - * @return EE_Datetime_Field |
|
141 | - */ |
|
142 | - public function createDatetimeField( |
|
143 | - $table_column, |
|
144 | - $nice_name, |
|
145 | - $nullable = false, |
|
146 | - $default_value = EE_Datetime_Field::now |
|
147 | - ) { |
|
148 | - return $this->loader->getNew( |
|
149 | - 'EE_Datetime_Field', |
|
150 | - array( |
|
151 | - $table_column, |
|
152 | - $nice_name, |
|
153 | - $nullable, |
|
154 | - $default_value |
|
155 | - ) |
|
156 | - ); |
|
157 | - } |
|
158 | - |
|
159 | - |
|
160 | - |
|
161 | - /** |
|
162 | - * @param string $table_column |
|
163 | - * @param string $nice_name |
|
164 | - * @param bool $nullable |
|
165 | - * @param null $default_value |
|
166 | - * @return EE_DB_Only_Float_Field |
|
167 | - */ |
|
168 | - public function createDbOnlyFloatField($table_column, $nice_name, $nullable, $default_value = null) |
|
169 | - { |
|
170 | - return $this->loader->getNew( |
|
171 | - 'EE_DB_Only_Float_Field', |
|
172 | - array($table_column, $nice_name, $nullable, $default_value) |
|
173 | - ); |
|
174 | - } |
|
175 | - |
|
176 | - |
|
177 | - |
|
178 | - /** |
|
179 | - * @param string $table_column |
|
180 | - * @param string $nice_name |
|
181 | - * @param bool $nullable |
|
182 | - * @param null $default_value |
|
183 | - * @return EE_DB_Only_Int_Field |
|
184 | - */ |
|
185 | - public function createDbOnlyIntField($table_column, $nice_name, $nullable, $default_value = null) |
|
186 | - { |
|
187 | - return $this->loader->getNew( |
|
188 | - 'EE_DB_Only_Int_Field', |
|
189 | - array($table_column, $nice_name, $nullable, $default_value) |
|
190 | - ); |
|
191 | - } |
|
192 | - |
|
193 | - |
|
194 | - |
|
195 | - /** |
|
196 | - * @param string $table_column |
|
197 | - * @param string $nice_name |
|
198 | - * @param bool $nullable |
|
199 | - * @param null $default_value |
|
200 | - * @return EE_DB_Only_Text_Field |
|
201 | - */ |
|
202 | - public function createDbOnlyTextField($table_column, $nice_name, $nullable, $default_value = null) |
|
203 | - { |
|
204 | - return $this->loader->getNew( |
|
205 | - 'EE_DB_Only_Text_Field', |
|
206 | - array($table_column, $nice_name, $nullable, $default_value) |
|
207 | - ); |
|
208 | - } |
|
209 | - |
|
210 | - |
|
211 | - |
|
212 | - /** |
|
213 | - * @param string $table_column |
|
214 | - * @param string $nice_name |
|
215 | - * @param bool $nullable |
|
216 | - * @param string $default_value |
|
217 | - * @return EE_Email_Field |
|
218 | - */ |
|
219 | - public function createEmailField($table_column, $nice_name, $nullable = true, $default_value = '') |
|
220 | - { |
|
221 | - return $this->loader->getNew( |
|
222 | - 'EE_Email_Field', |
|
223 | - array($table_column, $nice_name, $nullable, $default_value) |
|
224 | - ); |
|
225 | - } |
|
226 | - |
|
227 | - |
|
228 | - |
|
229 | - /** |
|
230 | - * @param string $table_column |
|
231 | - * @param string $nice_name |
|
232 | - * @param bool $nullable |
|
233 | - * @param null $default_value |
|
234 | - * @param array $allowed_enum_values keys are values to be used in the DB, |
|
235 | - * values are how they should be displayed |
|
236 | - * @return EE_Enum_Integer_Field |
|
237 | - */ |
|
238 | - public function createEnumIntegerField( |
|
239 | - $table_column, |
|
240 | - $nice_name, |
|
241 | - $nullable, |
|
242 | - $default_value = null, |
|
243 | - array $allowed_enum_values |
|
244 | - ) { |
|
245 | - return $this->loader->getNew( |
|
246 | - 'EE_Enum_Integer_Field', |
|
247 | - array($table_column, $nice_name, $nullable, $default_value, $allowed_enum_values) |
|
248 | - ); |
|
249 | - } |
|
250 | - |
|
251 | - |
|
252 | - |
|
253 | - /** |
|
254 | - * @param string $table_column |
|
255 | - * @param string $nice_name |
|
256 | - * @param bool $nullable |
|
257 | - * @param null $default_value |
|
258 | - * @param array $allowed_enum_values keys are values to be used in the DB, |
|
259 | - * values are how they should be displayed |
|
260 | - * @return EE_Enum_Text_Field |
|
261 | - */ |
|
262 | - public function createEnumTextField( |
|
263 | - $table_column, |
|
264 | - $nice_name, |
|
265 | - $nullable, |
|
266 | - $default_value, |
|
267 | - array $allowed_enum_values |
|
268 | - ) { |
|
269 | - return $this->loader->getNew( |
|
270 | - 'EE_Enum_Text_Field', |
|
271 | - array($table_column, $nice_name, $nullable, $default_value, $allowed_enum_values) |
|
272 | - ); |
|
273 | - } |
|
274 | - |
|
275 | - |
|
276 | - |
|
277 | - /** |
|
278 | - * @param string $table_column |
|
279 | - * @param string $nice_name |
|
280 | - * @param bool $nullable |
|
281 | - * @param null $default_value |
|
282 | - * @return EE_Float_Field |
|
283 | - */ |
|
284 | - public function createFloatField($table_column, $nice_name, $nullable, $default_value = null) |
|
285 | - { |
|
286 | - return $this->loader->getNew( |
|
287 | - 'EE_Float_Field', |
|
288 | - array($table_column, $nice_name, $nullable, $default_value) |
|
289 | - ); |
|
290 | - } |
|
291 | - |
|
292 | - |
|
293 | - |
|
294 | - /** |
|
295 | - * @param string $table_column |
|
296 | - * @param string $nice_name |
|
297 | - * @param bool $nullable |
|
298 | - * @param null $default_value |
|
299 | - * @param string $model_name |
|
300 | - * @return EE_Foreign_Key_Int_Field |
|
301 | - */ |
|
302 | - public function createForeignKeyIntField($table_column, $nice_name, $nullable, $default_value, $model_name) |
|
303 | - { |
|
304 | - return $this->loader->getNew( |
|
305 | - 'EE_Foreign_Key_Int_Field', |
|
306 | - array($table_column, $nice_name, $nullable, $default_value, $model_name) |
|
307 | - ); |
|
308 | - } |
|
309 | - |
|
310 | - |
|
311 | - |
|
312 | - /** |
|
313 | - * @param string $table_column |
|
314 | - * @param string $nice_name |
|
315 | - * @param bool $nullable |
|
316 | - * @param null $default_value |
|
317 | - * @param string $model_name |
|
318 | - * @return EE_Foreign_Key_String_Field |
|
319 | - */ |
|
320 | - public function createForeignKeyStringField( |
|
321 | - $table_column, |
|
322 | - $nice_name, |
|
323 | - $nullable, |
|
324 | - $default_value, |
|
325 | - $model_name |
|
326 | - ) { |
|
327 | - return $this->loader->getNew( |
|
328 | - 'EE_Foreign_Key_String_Field', |
|
329 | - array($table_column, $nice_name, $nullable, $default_value, $model_name) |
|
330 | - ); |
|
331 | - } |
|
332 | - |
|
333 | - |
|
334 | - |
|
335 | - /** |
|
336 | - * @param string $table_column |
|
337 | - * @param string $nice_name |
|
338 | - * @param bool $nullable |
|
339 | - * @param null $default_value |
|
340 | - * @return EE_Full_HTML_Field |
|
341 | - */ |
|
342 | - public function createFullHtmlField($table_column, $nice_name, $nullable, $default_value = null) |
|
343 | - { |
|
344 | - return $this->loader->getNew( |
|
345 | - 'EE_Full_HTML_Field', |
|
346 | - array($table_column, $nice_name, $nullable, $default_value) |
|
347 | - ); |
|
348 | - } |
|
349 | - |
|
350 | - |
|
351 | - |
|
352 | - /** |
|
353 | - * @param string $table_column |
|
354 | - * @param string $nice_name |
|
355 | - * @param bool $nullable |
|
356 | - * @param null $default_value |
|
357 | - * @return EE_Infinite_Integer_Field |
|
358 | - */ |
|
359 | - public function createInfiniteIntegerField($table_column, $nice_name, $nullable, $default_value = null) |
|
360 | - { |
|
361 | - return $this->loader->getNew( |
|
362 | - 'EE_Infinite_Integer_Field', |
|
363 | - array($table_column, $nice_name, $nullable, $default_value) |
|
364 | - ); |
|
365 | - } |
|
366 | - |
|
367 | - |
|
368 | - |
|
369 | - /** |
|
370 | - * @param string $table_column |
|
371 | - * @param string $nice_name |
|
372 | - * @param bool $nullable |
|
373 | - * @param integer $default_value |
|
374 | - * @return EE_Integer_Field |
|
375 | - */ |
|
376 | - public function createIntegerField($table_column, $nice_name, $nullable = false, $default_value = 0) |
|
377 | - { |
|
378 | - return $this->loader->getNew( |
|
379 | - 'EE_Integer_Field', |
|
380 | - array($table_column, $nice_name, $nullable, $default_value) |
|
381 | - ); |
|
382 | - } |
|
383 | - |
|
384 | - |
|
385 | - |
|
386 | - /** |
|
387 | - * @param string $table_column |
|
388 | - * @param string $nice_name |
|
389 | - * @param bool $nullable |
|
390 | - * @param null $default_value |
|
391 | - * @return EE_Maybe_Serialized_Simple_HTML_Field |
|
392 | - */ |
|
393 | - public function createMaybeSerializedSimpleHtmlField($table_column, $nice_name, $nullable, $default_value = null) |
|
394 | - { |
|
395 | - return $this->loader->getNew( |
|
396 | - 'EE_Maybe_Serialized_Simple_HTML_Field', |
|
397 | - array($table_column, $nice_name, $nullable, $default_value) |
|
398 | - ); |
|
399 | - } |
|
400 | - |
|
401 | - |
|
402 | - |
|
403 | - /** |
|
404 | - * @param string $table_column |
|
405 | - * @param string $nice_name |
|
406 | - * @param bool $nullable |
|
407 | - * @param null $default_value |
|
408 | - * @return EE_Maybe_Serialized_Text_Field |
|
409 | - */ |
|
410 | - public function createMaybeSerializedTextField($table_column, $nice_name, $nullable, $default_value = null) |
|
411 | - { |
|
412 | - return $this->loader->getNew( |
|
413 | - 'EE_Maybe_Serialized_Text_Field', |
|
414 | - array($table_column, $nice_name, $nullable, $default_value) |
|
415 | - ); |
|
416 | - } |
|
417 | - |
|
418 | - |
|
419 | - |
|
420 | - /** |
|
421 | - * @param string $table_column |
|
422 | - * @param string $nice_name |
|
423 | - * @param bool $nullable |
|
424 | - * @param null $default_value |
|
425 | - * @return EE_Money_Field |
|
426 | - */ |
|
427 | - public function createMoneyField($table_column, $nice_name, $nullable, $default_value = null) |
|
428 | - { |
|
429 | - return $this->loader->getNew( |
|
430 | - 'EE_Money_Field', |
|
431 | - array($table_column, $nice_name, $nullable, $default_value) |
|
432 | - ); |
|
433 | - } |
|
434 | - |
|
435 | - |
|
436 | - |
|
437 | - /** |
|
438 | - * @param string $table_column |
|
439 | - * @param string $nice_name |
|
440 | - * @param bool $nullable |
|
441 | - * @param string $default_value |
|
442 | - * @return EE_Plain_Text_Field |
|
443 | - */ |
|
444 | - public function createPlainTextField($table_column, $nice_name, $nullable = true, $default_value = '') |
|
445 | - { |
|
446 | - return $this->loader->getNew( |
|
447 | - 'EE_Plain_Text_Field', |
|
448 | - array($table_column, $nice_name, $nullable, $default_value) |
|
449 | - ); |
|
450 | - } |
|
451 | - |
|
452 | - |
|
453 | - |
|
454 | - /** |
|
455 | - * @param string $table_column |
|
456 | - * @param string $nice_name |
|
457 | - * @param bool $nullable |
|
458 | - * @param null $default_value |
|
459 | - * @return EE_Post_Content_Field |
|
460 | - */ |
|
461 | - public function createPostContentField($table_column, $nice_name, $nullable, $default_value = null) |
|
462 | - { |
|
463 | - return $this->loader->getNew( |
|
464 | - 'EE_Post_Content_Field', |
|
465 | - array($table_column, $nice_name, $nullable, $default_value) |
|
466 | - ); |
|
467 | - } |
|
468 | - |
|
469 | - |
|
470 | - |
|
471 | - /** |
|
472 | - * @param string $table_column |
|
473 | - * @param string $nice_name |
|
474 | - * @return EE_Primary_Key_Int_Field |
|
475 | - */ |
|
476 | - public function createPrimaryKeyIntField($table_column, $nice_name) |
|
477 | - { |
|
478 | - return $this->loader->getNew('EE_Primary_Key_Int_Field', array($table_column, $nice_name)); |
|
479 | - } |
|
480 | - |
|
481 | - |
|
482 | - |
|
483 | - /** |
|
484 | - * @param string $table_column |
|
485 | - * @param string $nice_name |
|
486 | - * @return EE_Primary_Key_String_Field |
|
487 | - */ |
|
488 | - public function createPrimaryKeyStringField($table_column, $nice_name) |
|
489 | - { |
|
490 | - return $this->loader->getNew('EE_Primary_Key_String_Field', array($table_column, $nice_name)); |
|
491 | - } |
|
492 | - |
|
493 | - |
|
494 | - |
|
495 | - /** |
|
496 | - * @param string $table_column |
|
497 | - * @param string $nice_name |
|
498 | - * @param bool $nullable |
|
499 | - * @param null $default_value |
|
500 | - * @return EE_Serialized_Text_Field |
|
501 | - */ |
|
502 | - public function createSerializedTextField($table_column, $nice_name, $nullable, $default_value = null) |
|
503 | - { |
|
504 | - return $this->loader->getNew( |
|
505 | - 'EE_Serialized_Text_Field', |
|
506 | - array($table_column, $nice_name, $nullable, $default_value) |
|
507 | - ); |
|
508 | - } |
|
509 | - |
|
510 | - |
|
511 | - |
|
512 | - /** |
|
513 | - * @param string $table_column |
|
514 | - * @param string $nice_name |
|
515 | - * @param bool $nullable |
|
516 | - * @param null $default_value |
|
517 | - * @return EE_Simple_HTML_Field |
|
518 | - */ |
|
519 | - public function createSimpleHtmlField($table_column, $nice_name, $nullable, $default_value = null) |
|
520 | - { |
|
521 | - return $this->loader->getNew( |
|
522 | - 'EE_Simple_HTML_Field', |
|
523 | - array($table_column, $nice_name, $nullable, $default_value) |
|
524 | - ); |
|
525 | - } |
|
526 | - |
|
527 | - |
|
528 | - |
|
529 | - /** |
|
530 | - * @param string $table_column |
|
531 | - * @param string $nice_name |
|
532 | - * @param bool $nullable |
|
533 | - * @param null $default_value |
|
534 | - * @return EE_Slug_Field |
|
535 | - */ |
|
536 | - public function createSlugField($table_column, $nice_name, $nullable = false, $default_value = null) |
|
537 | - { |
|
538 | - return $this->loader->getNew( |
|
539 | - 'EE_Slug_Field', |
|
540 | - array($table_column, $nice_name, $nullable, $default_value) |
|
541 | - ); |
|
542 | - } |
|
543 | - |
|
544 | - |
|
545 | - |
|
546 | - /** |
|
547 | - * @param string $table_column |
|
548 | - * @param string $nice_name |
|
549 | - * @param bool $nullable |
|
550 | - * @param null $default_value |
|
551 | - * @return EE_Trashed_Flag_Field |
|
552 | - */ |
|
553 | - public function createTrashedFlagField($table_column, $nice_name, $nullable, $default_value = null) |
|
554 | - { |
|
555 | - return $this->loader->getNew( |
|
556 | - 'EE_Trashed_Flag_Field', |
|
557 | - array($table_column, $nice_name, $nullable, $default_value) |
|
558 | - ); |
|
559 | - } |
|
560 | - |
|
561 | - |
|
562 | - |
|
563 | - /** |
|
564 | - * @param string $table_column |
|
565 | - * @param string $nice_name |
|
566 | - * @param bool $nullable |
|
567 | - * @param mixed $default_value |
|
568 | - * @param array $values If additional stati are to be used other than the default WP statuses, |
|
569 | - * then they can be registered via this property. |
|
570 | - * The format of the array should be as follows: |
|
571 | - * array( |
|
572 | - * 'status_reference' => array( |
|
573 | - * 'label' => __('Status Reference Label', 'event_espresso'), |
|
574 | - * 'public' => true, // whether this status should be shown on the frontend of the site |
|
575 | - * 'exclude_from_search' => false, // whether this status should be excluded from wp searches |
|
576 | - * 'show_in_admin_all_list' => true, // whether this status is included in queries |
|
577 | - * for the admin "all" view in list table views. |
|
578 | - * 'show_in_admin_status_list' => true, // show in the list of statuses with post counts at the top |
|
579 | - * of the admin list tables (i.e. Status Reference(2) ) |
|
580 | - * 'label_count' => _n_noop( |
|
581 | - * 'Status Reference <span class="count">(%s)</span>', |
|
582 | - * 'Status References <span class="count">(%s)</span>' |
|
583 | - * ), // the text to display on the admin screen |
|
584 | - * ( or you won't see your status count ). |
|
585 | - * ) |
|
586 | - * ) |
|
587 | - * @link http://codex.wordpress.org/Function_Reference/register_post_status for more info |
|
588 | - * @return EE_WP_Post_Status_Field |
|
589 | - */ |
|
590 | - public function createWpPostStatusField( |
|
591 | - $table_column, |
|
592 | - $nice_name, |
|
593 | - $nullable, |
|
594 | - $default_value = null, |
|
595 | - array $values = array() |
|
596 | - ) { |
|
597 | - return $this->loader->getNew( |
|
598 | - 'EE_WP_Post_Status_Field', |
|
599 | - array($table_column, $nice_name, $nullable, $default_value, $values) |
|
600 | - ); |
|
601 | - } |
|
602 | - |
|
603 | - |
|
604 | - |
|
605 | - /** |
|
606 | - * @param string $post_type |
|
607 | - * @return EE_WP_Post_Type_Field |
|
608 | - */ |
|
609 | - public function createWpPostTypeField($post_type) |
|
610 | - { |
|
611 | - return $this->loader->getNew('EE_WP_Post_Type_Field', array($post_type)); |
|
612 | - } |
|
613 | - |
|
614 | - |
|
615 | - |
|
616 | - /** |
|
617 | - * @param string $table_column |
|
618 | - * @param string $nice_name |
|
619 | - * @param bool $nullable |
|
620 | - * @return EE_WP_User_Field |
|
621 | - */ |
|
622 | - public function createWpUserField($table_column, $nice_name, $nullable) |
|
623 | - { |
|
624 | - return $this->loader->getNew('EE_WP_User_Field', array($table_column, $nice_name, $nullable)); |
|
625 | - } |
|
56 | + /** |
|
57 | + * @var LoaderInterface $loader |
|
58 | + */ |
|
59 | + private $loader; |
|
60 | + |
|
61 | + |
|
62 | + |
|
63 | + /** |
|
64 | + * ModelFieldFactory constructor. |
|
65 | + * |
|
66 | + * @param LoaderInterface $loader |
|
67 | + */ |
|
68 | + public function __construct(LoaderInterface $loader) |
|
69 | + { |
|
70 | + $this->loader = $loader; |
|
71 | + } |
|
72 | + |
|
73 | + |
|
74 | + |
|
75 | + /** |
|
76 | + * @param string $table_column |
|
77 | + * @param string $nice_name |
|
78 | + * @param bool $nullable |
|
79 | + * @param null $default_value |
|
80 | + * @return EE_All_Caps_Text_Field |
|
81 | + */ |
|
82 | + public function createAllCapsTextField($table_column, $nice_name, $nullable, $default_value = null) |
|
83 | + { |
|
84 | + return $this->loader->getNew( |
|
85 | + 'EE_All_Caps_Text_Field', |
|
86 | + array($table_column, $nice_name, $nullable, $default_value) |
|
87 | + ); |
|
88 | + } |
|
89 | + |
|
90 | + |
|
91 | + |
|
92 | + /** |
|
93 | + * @param string $table_column |
|
94 | + * @param string $nice_name |
|
95 | + * @param bool $nullable |
|
96 | + * @param null $default_value |
|
97 | + * @param string $model_name |
|
98 | + * @return EE_Any_Foreign_Model_Name_Field |
|
99 | + */ |
|
100 | + public function createAnyForeignModelNameField( |
|
101 | + $table_column, |
|
102 | + $nice_name, |
|
103 | + $nullable, |
|
104 | + $default_value = null, |
|
105 | + $model_name |
|
106 | + ) { |
|
107 | + return $this->loader->getNew( |
|
108 | + 'EE_Any_Foreign_Model_Name_Field', |
|
109 | + array($table_column, $nice_name, $nullable, $default_value, $model_name) |
|
110 | + ); |
|
111 | + } |
|
112 | + |
|
113 | + |
|
114 | + |
|
115 | + /** |
|
116 | + * @param string $table_column |
|
117 | + * @param string $nice_name |
|
118 | + * @param bool $nullable |
|
119 | + * @param null $default_value |
|
120 | + * @return EE_Boolean_Field |
|
121 | + */ |
|
122 | + public function createBooleanField($table_column, $nice_name, $nullable, $default_value = null) |
|
123 | + { |
|
124 | + return $this->loader->getNew( |
|
125 | + 'EE_Boolean_Field', |
|
126 | + array($table_column, $nice_name, $nullable, $default_value) |
|
127 | + ); |
|
128 | + } |
|
129 | + |
|
130 | + |
|
131 | + |
|
132 | + /** |
|
133 | + * @param string $table_column |
|
134 | + * @param string $nice_name |
|
135 | + * @param string $timezone_string |
|
136 | + * @param bool $nullable |
|
137 | + * @param string $default_value |
|
138 | + * @throws EE_Error |
|
139 | + * @throws InvalidArgumentException |
|
140 | + * @return EE_Datetime_Field |
|
141 | + */ |
|
142 | + public function createDatetimeField( |
|
143 | + $table_column, |
|
144 | + $nice_name, |
|
145 | + $nullable = false, |
|
146 | + $default_value = EE_Datetime_Field::now |
|
147 | + ) { |
|
148 | + return $this->loader->getNew( |
|
149 | + 'EE_Datetime_Field', |
|
150 | + array( |
|
151 | + $table_column, |
|
152 | + $nice_name, |
|
153 | + $nullable, |
|
154 | + $default_value |
|
155 | + ) |
|
156 | + ); |
|
157 | + } |
|
158 | + |
|
159 | + |
|
160 | + |
|
161 | + /** |
|
162 | + * @param string $table_column |
|
163 | + * @param string $nice_name |
|
164 | + * @param bool $nullable |
|
165 | + * @param null $default_value |
|
166 | + * @return EE_DB_Only_Float_Field |
|
167 | + */ |
|
168 | + public function createDbOnlyFloatField($table_column, $nice_name, $nullable, $default_value = null) |
|
169 | + { |
|
170 | + return $this->loader->getNew( |
|
171 | + 'EE_DB_Only_Float_Field', |
|
172 | + array($table_column, $nice_name, $nullable, $default_value) |
|
173 | + ); |
|
174 | + } |
|
175 | + |
|
176 | + |
|
177 | + |
|
178 | + /** |
|
179 | + * @param string $table_column |
|
180 | + * @param string $nice_name |
|
181 | + * @param bool $nullable |
|
182 | + * @param null $default_value |
|
183 | + * @return EE_DB_Only_Int_Field |
|
184 | + */ |
|
185 | + public function createDbOnlyIntField($table_column, $nice_name, $nullable, $default_value = null) |
|
186 | + { |
|
187 | + return $this->loader->getNew( |
|
188 | + 'EE_DB_Only_Int_Field', |
|
189 | + array($table_column, $nice_name, $nullable, $default_value) |
|
190 | + ); |
|
191 | + } |
|
192 | + |
|
193 | + |
|
194 | + |
|
195 | + /** |
|
196 | + * @param string $table_column |
|
197 | + * @param string $nice_name |
|
198 | + * @param bool $nullable |
|
199 | + * @param null $default_value |
|
200 | + * @return EE_DB_Only_Text_Field |
|
201 | + */ |
|
202 | + public function createDbOnlyTextField($table_column, $nice_name, $nullable, $default_value = null) |
|
203 | + { |
|
204 | + return $this->loader->getNew( |
|
205 | + 'EE_DB_Only_Text_Field', |
|
206 | + array($table_column, $nice_name, $nullable, $default_value) |
|
207 | + ); |
|
208 | + } |
|
209 | + |
|
210 | + |
|
211 | + |
|
212 | + /** |
|
213 | + * @param string $table_column |
|
214 | + * @param string $nice_name |
|
215 | + * @param bool $nullable |
|
216 | + * @param string $default_value |
|
217 | + * @return EE_Email_Field |
|
218 | + */ |
|
219 | + public function createEmailField($table_column, $nice_name, $nullable = true, $default_value = '') |
|
220 | + { |
|
221 | + return $this->loader->getNew( |
|
222 | + 'EE_Email_Field', |
|
223 | + array($table_column, $nice_name, $nullable, $default_value) |
|
224 | + ); |
|
225 | + } |
|
226 | + |
|
227 | + |
|
228 | + |
|
229 | + /** |
|
230 | + * @param string $table_column |
|
231 | + * @param string $nice_name |
|
232 | + * @param bool $nullable |
|
233 | + * @param null $default_value |
|
234 | + * @param array $allowed_enum_values keys are values to be used in the DB, |
|
235 | + * values are how they should be displayed |
|
236 | + * @return EE_Enum_Integer_Field |
|
237 | + */ |
|
238 | + public function createEnumIntegerField( |
|
239 | + $table_column, |
|
240 | + $nice_name, |
|
241 | + $nullable, |
|
242 | + $default_value = null, |
|
243 | + array $allowed_enum_values |
|
244 | + ) { |
|
245 | + return $this->loader->getNew( |
|
246 | + 'EE_Enum_Integer_Field', |
|
247 | + array($table_column, $nice_name, $nullable, $default_value, $allowed_enum_values) |
|
248 | + ); |
|
249 | + } |
|
250 | + |
|
251 | + |
|
252 | + |
|
253 | + /** |
|
254 | + * @param string $table_column |
|
255 | + * @param string $nice_name |
|
256 | + * @param bool $nullable |
|
257 | + * @param null $default_value |
|
258 | + * @param array $allowed_enum_values keys are values to be used in the DB, |
|
259 | + * values are how they should be displayed |
|
260 | + * @return EE_Enum_Text_Field |
|
261 | + */ |
|
262 | + public function createEnumTextField( |
|
263 | + $table_column, |
|
264 | + $nice_name, |
|
265 | + $nullable, |
|
266 | + $default_value, |
|
267 | + array $allowed_enum_values |
|
268 | + ) { |
|
269 | + return $this->loader->getNew( |
|
270 | + 'EE_Enum_Text_Field', |
|
271 | + array($table_column, $nice_name, $nullable, $default_value, $allowed_enum_values) |
|
272 | + ); |
|
273 | + } |
|
274 | + |
|
275 | + |
|
276 | + |
|
277 | + /** |
|
278 | + * @param string $table_column |
|
279 | + * @param string $nice_name |
|
280 | + * @param bool $nullable |
|
281 | + * @param null $default_value |
|
282 | + * @return EE_Float_Field |
|
283 | + */ |
|
284 | + public function createFloatField($table_column, $nice_name, $nullable, $default_value = null) |
|
285 | + { |
|
286 | + return $this->loader->getNew( |
|
287 | + 'EE_Float_Field', |
|
288 | + array($table_column, $nice_name, $nullable, $default_value) |
|
289 | + ); |
|
290 | + } |
|
291 | + |
|
292 | + |
|
293 | + |
|
294 | + /** |
|
295 | + * @param string $table_column |
|
296 | + * @param string $nice_name |
|
297 | + * @param bool $nullable |
|
298 | + * @param null $default_value |
|
299 | + * @param string $model_name |
|
300 | + * @return EE_Foreign_Key_Int_Field |
|
301 | + */ |
|
302 | + public function createForeignKeyIntField($table_column, $nice_name, $nullable, $default_value, $model_name) |
|
303 | + { |
|
304 | + return $this->loader->getNew( |
|
305 | + 'EE_Foreign_Key_Int_Field', |
|
306 | + array($table_column, $nice_name, $nullable, $default_value, $model_name) |
|
307 | + ); |
|
308 | + } |
|
309 | + |
|
310 | + |
|
311 | + |
|
312 | + /** |
|
313 | + * @param string $table_column |
|
314 | + * @param string $nice_name |
|
315 | + * @param bool $nullable |
|
316 | + * @param null $default_value |
|
317 | + * @param string $model_name |
|
318 | + * @return EE_Foreign_Key_String_Field |
|
319 | + */ |
|
320 | + public function createForeignKeyStringField( |
|
321 | + $table_column, |
|
322 | + $nice_name, |
|
323 | + $nullable, |
|
324 | + $default_value, |
|
325 | + $model_name |
|
326 | + ) { |
|
327 | + return $this->loader->getNew( |
|
328 | + 'EE_Foreign_Key_String_Field', |
|
329 | + array($table_column, $nice_name, $nullable, $default_value, $model_name) |
|
330 | + ); |
|
331 | + } |
|
332 | + |
|
333 | + |
|
334 | + |
|
335 | + /** |
|
336 | + * @param string $table_column |
|
337 | + * @param string $nice_name |
|
338 | + * @param bool $nullable |
|
339 | + * @param null $default_value |
|
340 | + * @return EE_Full_HTML_Field |
|
341 | + */ |
|
342 | + public function createFullHtmlField($table_column, $nice_name, $nullable, $default_value = null) |
|
343 | + { |
|
344 | + return $this->loader->getNew( |
|
345 | + 'EE_Full_HTML_Field', |
|
346 | + array($table_column, $nice_name, $nullable, $default_value) |
|
347 | + ); |
|
348 | + } |
|
349 | + |
|
350 | + |
|
351 | + |
|
352 | + /** |
|
353 | + * @param string $table_column |
|
354 | + * @param string $nice_name |
|
355 | + * @param bool $nullable |
|
356 | + * @param null $default_value |
|
357 | + * @return EE_Infinite_Integer_Field |
|
358 | + */ |
|
359 | + public function createInfiniteIntegerField($table_column, $nice_name, $nullable, $default_value = null) |
|
360 | + { |
|
361 | + return $this->loader->getNew( |
|
362 | + 'EE_Infinite_Integer_Field', |
|
363 | + array($table_column, $nice_name, $nullable, $default_value) |
|
364 | + ); |
|
365 | + } |
|
366 | + |
|
367 | + |
|
368 | + |
|
369 | + /** |
|
370 | + * @param string $table_column |
|
371 | + * @param string $nice_name |
|
372 | + * @param bool $nullable |
|
373 | + * @param integer $default_value |
|
374 | + * @return EE_Integer_Field |
|
375 | + */ |
|
376 | + public function createIntegerField($table_column, $nice_name, $nullable = false, $default_value = 0) |
|
377 | + { |
|
378 | + return $this->loader->getNew( |
|
379 | + 'EE_Integer_Field', |
|
380 | + array($table_column, $nice_name, $nullable, $default_value) |
|
381 | + ); |
|
382 | + } |
|
383 | + |
|
384 | + |
|
385 | + |
|
386 | + /** |
|
387 | + * @param string $table_column |
|
388 | + * @param string $nice_name |
|
389 | + * @param bool $nullable |
|
390 | + * @param null $default_value |
|
391 | + * @return EE_Maybe_Serialized_Simple_HTML_Field |
|
392 | + */ |
|
393 | + public function createMaybeSerializedSimpleHtmlField($table_column, $nice_name, $nullable, $default_value = null) |
|
394 | + { |
|
395 | + return $this->loader->getNew( |
|
396 | + 'EE_Maybe_Serialized_Simple_HTML_Field', |
|
397 | + array($table_column, $nice_name, $nullable, $default_value) |
|
398 | + ); |
|
399 | + } |
|
400 | + |
|
401 | + |
|
402 | + |
|
403 | + /** |
|
404 | + * @param string $table_column |
|
405 | + * @param string $nice_name |
|
406 | + * @param bool $nullable |
|
407 | + * @param null $default_value |
|
408 | + * @return EE_Maybe_Serialized_Text_Field |
|
409 | + */ |
|
410 | + public function createMaybeSerializedTextField($table_column, $nice_name, $nullable, $default_value = null) |
|
411 | + { |
|
412 | + return $this->loader->getNew( |
|
413 | + 'EE_Maybe_Serialized_Text_Field', |
|
414 | + array($table_column, $nice_name, $nullable, $default_value) |
|
415 | + ); |
|
416 | + } |
|
417 | + |
|
418 | + |
|
419 | + |
|
420 | + /** |
|
421 | + * @param string $table_column |
|
422 | + * @param string $nice_name |
|
423 | + * @param bool $nullable |
|
424 | + * @param null $default_value |
|
425 | + * @return EE_Money_Field |
|
426 | + */ |
|
427 | + public function createMoneyField($table_column, $nice_name, $nullable, $default_value = null) |
|
428 | + { |
|
429 | + return $this->loader->getNew( |
|
430 | + 'EE_Money_Field', |
|
431 | + array($table_column, $nice_name, $nullable, $default_value) |
|
432 | + ); |
|
433 | + } |
|
434 | + |
|
435 | + |
|
436 | + |
|
437 | + /** |
|
438 | + * @param string $table_column |
|
439 | + * @param string $nice_name |
|
440 | + * @param bool $nullable |
|
441 | + * @param string $default_value |
|
442 | + * @return EE_Plain_Text_Field |
|
443 | + */ |
|
444 | + public function createPlainTextField($table_column, $nice_name, $nullable = true, $default_value = '') |
|
445 | + { |
|
446 | + return $this->loader->getNew( |
|
447 | + 'EE_Plain_Text_Field', |
|
448 | + array($table_column, $nice_name, $nullable, $default_value) |
|
449 | + ); |
|
450 | + } |
|
451 | + |
|
452 | + |
|
453 | + |
|
454 | + /** |
|
455 | + * @param string $table_column |
|
456 | + * @param string $nice_name |
|
457 | + * @param bool $nullable |
|
458 | + * @param null $default_value |
|
459 | + * @return EE_Post_Content_Field |
|
460 | + */ |
|
461 | + public function createPostContentField($table_column, $nice_name, $nullable, $default_value = null) |
|
462 | + { |
|
463 | + return $this->loader->getNew( |
|
464 | + 'EE_Post_Content_Field', |
|
465 | + array($table_column, $nice_name, $nullable, $default_value) |
|
466 | + ); |
|
467 | + } |
|
468 | + |
|
469 | + |
|
470 | + |
|
471 | + /** |
|
472 | + * @param string $table_column |
|
473 | + * @param string $nice_name |
|
474 | + * @return EE_Primary_Key_Int_Field |
|
475 | + */ |
|
476 | + public function createPrimaryKeyIntField($table_column, $nice_name) |
|
477 | + { |
|
478 | + return $this->loader->getNew('EE_Primary_Key_Int_Field', array($table_column, $nice_name)); |
|
479 | + } |
|
480 | + |
|
481 | + |
|
482 | + |
|
483 | + /** |
|
484 | + * @param string $table_column |
|
485 | + * @param string $nice_name |
|
486 | + * @return EE_Primary_Key_String_Field |
|
487 | + */ |
|
488 | + public function createPrimaryKeyStringField($table_column, $nice_name) |
|
489 | + { |
|
490 | + return $this->loader->getNew('EE_Primary_Key_String_Field', array($table_column, $nice_name)); |
|
491 | + } |
|
492 | + |
|
493 | + |
|
494 | + |
|
495 | + /** |
|
496 | + * @param string $table_column |
|
497 | + * @param string $nice_name |
|
498 | + * @param bool $nullable |
|
499 | + * @param null $default_value |
|
500 | + * @return EE_Serialized_Text_Field |
|
501 | + */ |
|
502 | + public function createSerializedTextField($table_column, $nice_name, $nullable, $default_value = null) |
|
503 | + { |
|
504 | + return $this->loader->getNew( |
|
505 | + 'EE_Serialized_Text_Field', |
|
506 | + array($table_column, $nice_name, $nullable, $default_value) |
|
507 | + ); |
|
508 | + } |
|
509 | + |
|
510 | + |
|
511 | + |
|
512 | + /** |
|
513 | + * @param string $table_column |
|
514 | + * @param string $nice_name |
|
515 | + * @param bool $nullable |
|
516 | + * @param null $default_value |
|
517 | + * @return EE_Simple_HTML_Field |
|
518 | + */ |
|
519 | + public function createSimpleHtmlField($table_column, $nice_name, $nullable, $default_value = null) |
|
520 | + { |
|
521 | + return $this->loader->getNew( |
|
522 | + 'EE_Simple_HTML_Field', |
|
523 | + array($table_column, $nice_name, $nullable, $default_value) |
|
524 | + ); |
|
525 | + } |
|
526 | + |
|
527 | + |
|
528 | + |
|
529 | + /** |
|
530 | + * @param string $table_column |
|
531 | + * @param string $nice_name |
|
532 | + * @param bool $nullable |
|
533 | + * @param null $default_value |
|
534 | + * @return EE_Slug_Field |
|
535 | + */ |
|
536 | + public function createSlugField($table_column, $nice_name, $nullable = false, $default_value = null) |
|
537 | + { |
|
538 | + return $this->loader->getNew( |
|
539 | + 'EE_Slug_Field', |
|
540 | + array($table_column, $nice_name, $nullable, $default_value) |
|
541 | + ); |
|
542 | + } |
|
543 | + |
|
544 | + |
|
545 | + |
|
546 | + /** |
|
547 | + * @param string $table_column |
|
548 | + * @param string $nice_name |
|
549 | + * @param bool $nullable |
|
550 | + * @param null $default_value |
|
551 | + * @return EE_Trashed_Flag_Field |
|
552 | + */ |
|
553 | + public function createTrashedFlagField($table_column, $nice_name, $nullable, $default_value = null) |
|
554 | + { |
|
555 | + return $this->loader->getNew( |
|
556 | + 'EE_Trashed_Flag_Field', |
|
557 | + array($table_column, $nice_name, $nullable, $default_value) |
|
558 | + ); |
|
559 | + } |
|
560 | + |
|
561 | + |
|
562 | + |
|
563 | + /** |
|
564 | + * @param string $table_column |
|
565 | + * @param string $nice_name |
|
566 | + * @param bool $nullable |
|
567 | + * @param mixed $default_value |
|
568 | + * @param array $values If additional stati are to be used other than the default WP statuses, |
|
569 | + * then they can be registered via this property. |
|
570 | + * The format of the array should be as follows: |
|
571 | + * array( |
|
572 | + * 'status_reference' => array( |
|
573 | + * 'label' => __('Status Reference Label', 'event_espresso'), |
|
574 | + * 'public' => true, // whether this status should be shown on the frontend of the site |
|
575 | + * 'exclude_from_search' => false, // whether this status should be excluded from wp searches |
|
576 | + * 'show_in_admin_all_list' => true, // whether this status is included in queries |
|
577 | + * for the admin "all" view in list table views. |
|
578 | + * 'show_in_admin_status_list' => true, // show in the list of statuses with post counts at the top |
|
579 | + * of the admin list tables (i.e. Status Reference(2) ) |
|
580 | + * 'label_count' => _n_noop( |
|
581 | + * 'Status Reference <span class="count">(%s)</span>', |
|
582 | + * 'Status References <span class="count">(%s)</span>' |
|
583 | + * ), // the text to display on the admin screen |
|
584 | + * ( or you won't see your status count ). |
|
585 | + * ) |
|
586 | + * ) |
|
587 | + * @link http://codex.wordpress.org/Function_Reference/register_post_status for more info |
|
588 | + * @return EE_WP_Post_Status_Field |
|
589 | + */ |
|
590 | + public function createWpPostStatusField( |
|
591 | + $table_column, |
|
592 | + $nice_name, |
|
593 | + $nullable, |
|
594 | + $default_value = null, |
|
595 | + array $values = array() |
|
596 | + ) { |
|
597 | + return $this->loader->getNew( |
|
598 | + 'EE_WP_Post_Status_Field', |
|
599 | + array($table_column, $nice_name, $nullable, $default_value, $values) |
|
600 | + ); |
|
601 | + } |
|
602 | + |
|
603 | + |
|
604 | + |
|
605 | + /** |
|
606 | + * @param string $post_type |
|
607 | + * @return EE_WP_Post_Type_Field |
|
608 | + */ |
|
609 | + public function createWpPostTypeField($post_type) |
|
610 | + { |
|
611 | + return $this->loader->getNew('EE_WP_Post_Type_Field', array($post_type)); |
|
612 | + } |
|
613 | + |
|
614 | + |
|
615 | + |
|
616 | + /** |
|
617 | + * @param string $table_column |
|
618 | + * @param string $nice_name |
|
619 | + * @param bool $nullable |
|
620 | + * @return EE_WP_User_Field |
|
621 | + */ |
|
622 | + public function createWpUserField($table_column, $nice_name, $nullable) |
|
623 | + { |
|
624 | + return $this->loader->getNew('EE_WP_User_Field', array($table_column, $nice_name, $nullable)); |
|
625 | + } |
|
626 | 626 | |
627 | 627 | |
628 | 628 |
@@ -106,7 +106,7 @@ discard block |
||
106 | 106 | ), |
107 | 107 | ), |
108 | 108 | ); |
109 | - $this->_model_relations = array(); |
|
109 | + $this->_model_relations = array(); |
|
110 | 110 | foreach ($models_this_can_attach_to as $model) { |
111 | 111 | if ($model == 'WP_User') { |
112 | 112 | $this->_model_relations[$model] = new EE_Belongs_To_Relation(); |
@@ -163,7 +163,7 @@ discard block |
||
163 | 163 | */ |
164 | 164 | public function gateway_log($message, $related_obj_id, $related_obj_type) |
165 | 165 | { |
166 | - if (! EE_Registry::instance()->is_model_name($related_obj_type)) { |
|
166 | + if ( ! EE_Registry::instance()->is_model_name($related_obj_type)) { |
|
167 | 167 | throw new EE_Error( |
168 | 168 | sprintf( |
169 | 169 | esc_html__( |
@@ -212,7 +212,7 @@ discard block |
||
212 | 212 | global $wpdb; |
213 | 213 | return $wpdb->query( |
214 | 214 | $wpdb->prepare( |
215 | - 'DELETE FROM ' . $this->table() . ' WHERE LOG_type = %s AND LOG_time < %s', |
|
215 | + 'DELETE FROM '.$this->table().' WHERE LOG_type = %s AND LOG_time < %s', |
|
216 | 216 | EEM_Change_Log::type_gateway, |
217 | 217 | $datetime->format(EE_Datetime_Field::mysql_timestamp_format) |
218 | 218 | ) |
@@ -13,246 +13,246 @@ |
||
13 | 13 | class EEM_Change_Log extends EEM_Base |
14 | 14 | { |
15 | 15 | |
16 | - /** |
|
17 | - * the related object was created log type |
|
18 | - */ |
|
19 | - const type_create = 'create'; |
|
20 | - /** |
|
21 | - * the related object was updated (changed, or soft-deleted) |
|
22 | - */ |
|
23 | - const type_update = 'update'; |
|
24 | - /** |
|
25 | - * the related object was deleted permanently |
|
26 | - */ |
|
27 | - const type_delete = 'delete'; |
|
28 | - /** |
|
29 | - * the related item had something worth noting happen on it, but |
|
30 | - * only for the purposes of debugging problems |
|
31 | - */ |
|
32 | - const type_debug = 'debug'; |
|
33 | - /** |
|
34 | - * the related item had an error occur on it |
|
35 | - */ |
|
36 | - const type_error = 'error'; |
|
37 | - /** |
|
38 | - * the related item is regarding some gateway interaction, like an IPN |
|
39 | - * or request to process a payment |
|
40 | - */ |
|
41 | - const type_gateway = 'gateway'; |
|
16 | + /** |
|
17 | + * the related object was created log type |
|
18 | + */ |
|
19 | + const type_create = 'create'; |
|
20 | + /** |
|
21 | + * the related object was updated (changed, or soft-deleted) |
|
22 | + */ |
|
23 | + const type_update = 'update'; |
|
24 | + /** |
|
25 | + * the related object was deleted permanently |
|
26 | + */ |
|
27 | + const type_delete = 'delete'; |
|
28 | + /** |
|
29 | + * the related item had something worth noting happen on it, but |
|
30 | + * only for the purposes of debugging problems |
|
31 | + */ |
|
32 | + const type_debug = 'debug'; |
|
33 | + /** |
|
34 | + * the related item had an error occur on it |
|
35 | + */ |
|
36 | + const type_error = 'error'; |
|
37 | + /** |
|
38 | + * the related item is regarding some gateway interaction, like an IPN |
|
39 | + * or request to process a payment |
|
40 | + */ |
|
41 | + const type_gateway = 'gateway'; |
|
42 | 42 | |
43 | - /** |
|
44 | - * private instance of the EEM_Change_Log object |
|
45 | - * |
|
46 | - * @access private |
|
47 | - * @var EEM_Change_Log $_instance |
|
48 | - */ |
|
49 | - protected static $_instance = null; |
|
43 | + /** |
|
44 | + * private instance of the EEM_Change_Log object |
|
45 | + * |
|
46 | + * @access private |
|
47 | + * @var EEM_Change_Log $_instance |
|
48 | + */ |
|
49 | + protected static $_instance = null; |
|
50 | 50 | |
51 | 51 | |
52 | - /** |
|
53 | - * constructor |
|
54 | - * |
|
55 | - * @access protected |
|
56 | - * @param null $timezone |
|
57 | - * @throws EE_Error |
|
58 | - */ |
|
59 | - protected function __construct($timezone = null) |
|
60 | - { |
|
61 | - global $current_user; |
|
62 | - $this->singular_item = esc_html__('Log', 'event_espresso'); |
|
63 | - $this->plural_item = esc_html__('Logs', 'event_espresso'); |
|
64 | - $this->_tables = array( |
|
65 | - 'Log' => new EE_Primary_Table('esp_log', 'LOG_ID'), |
|
66 | - ); |
|
67 | - $models_this_can_attach_to = array_keys(EE_Registry::instance()->non_abstract_db_models); |
|
68 | - $this->_fields = array( |
|
69 | - 'Log' => array( |
|
70 | - 'LOG_ID' => new EE_Primary_Key_Int_Field('LOG_ID', esc_html__('Log ID', 'event_espresso')), |
|
71 | - 'LOG_time' => new EE_Datetime_Field( |
|
72 | - 'LOG_time', |
|
73 | - esc_html__("Log Time", 'event_espresso'), |
|
74 | - false, |
|
75 | - EE_Datetime_Field::now |
|
76 | - ), |
|
77 | - 'OBJ_ID' => new EE_Foreign_Key_String_Field( |
|
78 | - 'OBJ_ID', |
|
79 | - esc_html__("Object ID (int or string)", 'event_espresso'), |
|
80 | - true, |
|
81 | - null, |
|
82 | - $models_this_can_attach_to |
|
83 | - ), |
|
84 | - 'OBJ_type' => new EE_Any_Foreign_Model_Name_Field( |
|
85 | - 'OBJ_type', |
|
86 | - esc_html__("Object Type", 'event_espresso'), |
|
87 | - true, |
|
88 | - null, |
|
89 | - $models_this_can_attach_to |
|
90 | - ), |
|
91 | - 'LOG_type' => new EE_Plain_Text_Field( |
|
92 | - 'LOG_type', |
|
93 | - esc_html__("Type of log entry", "event_espresso"), |
|
94 | - false, |
|
95 | - self::type_debug |
|
96 | - ), |
|
97 | - 'LOG_message' => new EE_Maybe_Serialized_Text_Field( |
|
98 | - 'LOG_message', |
|
99 | - esc_html__("Log Message (body)", 'event_espresso'), |
|
100 | - true |
|
101 | - ), |
|
102 | - 'LOG_wp_user' => new EE_WP_User_Field( |
|
103 | - 'LOG_wp_user', |
|
104 | - esc_html__("User who was logged in while this occurred", 'event_espresso'), |
|
105 | - true |
|
106 | - ), |
|
107 | - ), |
|
108 | - ); |
|
109 | - $this->_model_relations = array(); |
|
110 | - foreach ($models_this_can_attach_to as $model) { |
|
111 | - if ($model == 'WP_User') { |
|
112 | - $this->_model_relations[$model] = new EE_Belongs_To_Relation(); |
|
113 | - } elseif ($model != 'Change_Log') { |
|
114 | - $this->_model_relations[$model] = new EE_Belongs_To_Any_Relation(); |
|
115 | - } |
|
116 | - } |
|
117 | - //use completely custom caps for this |
|
118 | - $this->_cap_restriction_generators = false; |
|
119 | - //caps-wise this is all-or-nothing: if you have the default role you can access anything, otherwise nothing |
|
120 | - foreach ($this->_cap_contexts_to_cap_action_map as $cap_context => $action) { |
|
121 | - $this->_cap_restrictions[$cap_context][EE_Restriction_Generator_Base::get_default_restrictions_cap()] |
|
122 | - = new EE_Return_None_Where_Conditions(); |
|
123 | - } |
|
124 | - parent::__construct($timezone); |
|
125 | - } |
|
52 | + /** |
|
53 | + * constructor |
|
54 | + * |
|
55 | + * @access protected |
|
56 | + * @param null $timezone |
|
57 | + * @throws EE_Error |
|
58 | + */ |
|
59 | + protected function __construct($timezone = null) |
|
60 | + { |
|
61 | + global $current_user; |
|
62 | + $this->singular_item = esc_html__('Log', 'event_espresso'); |
|
63 | + $this->plural_item = esc_html__('Logs', 'event_espresso'); |
|
64 | + $this->_tables = array( |
|
65 | + 'Log' => new EE_Primary_Table('esp_log', 'LOG_ID'), |
|
66 | + ); |
|
67 | + $models_this_can_attach_to = array_keys(EE_Registry::instance()->non_abstract_db_models); |
|
68 | + $this->_fields = array( |
|
69 | + 'Log' => array( |
|
70 | + 'LOG_ID' => new EE_Primary_Key_Int_Field('LOG_ID', esc_html__('Log ID', 'event_espresso')), |
|
71 | + 'LOG_time' => new EE_Datetime_Field( |
|
72 | + 'LOG_time', |
|
73 | + esc_html__("Log Time", 'event_espresso'), |
|
74 | + false, |
|
75 | + EE_Datetime_Field::now |
|
76 | + ), |
|
77 | + 'OBJ_ID' => new EE_Foreign_Key_String_Field( |
|
78 | + 'OBJ_ID', |
|
79 | + esc_html__("Object ID (int or string)", 'event_espresso'), |
|
80 | + true, |
|
81 | + null, |
|
82 | + $models_this_can_attach_to |
|
83 | + ), |
|
84 | + 'OBJ_type' => new EE_Any_Foreign_Model_Name_Field( |
|
85 | + 'OBJ_type', |
|
86 | + esc_html__("Object Type", 'event_espresso'), |
|
87 | + true, |
|
88 | + null, |
|
89 | + $models_this_can_attach_to |
|
90 | + ), |
|
91 | + 'LOG_type' => new EE_Plain_Text_Field( |
|
92 | + 'LOG_type', |
|
93 | + esc_html__("Type of log entry", "event_espresso"), |
|
94 | + false, |
|
95 | + self::type_debug |
|
96 | + ), |
|
97 | + 'LOG_message' => new EE_Maybe_Serialized_Text_Field( |
|
98 | + 'LOG_message', |
|
99 | + esc_html__("Log Message (body)", 'event_espresso'), |
|
100 | + true |
|
101 | + ), |
|
102 | + 'LOG_wp_user' => new EE_WP_User_Field( |
|
103 | + 'LOG_wp_user', |
|
104 | + esc_html__("User who was logged in while this occurred", 'event_espresso'), |
|
105 | + true |
|
106 | + ), |
|
107 | + ), |
|
108 | + ); |
|
109 | + $this->_model_relations = array(); |
|
110 | + foreach ($models_this_can_attach_to as $model) { |
|
111 | + if ($model == 'WP_User') { |
|
112 | + $this->_model_relations[$model] = new EE_Belongs_To_Relation(); |
|
113 | + } elseif ($model != 'Change_Log') { |
|
114 | + $this->_model_relations[$model] = new EE_Belongs_To_Any_Relation(); |
|
115 | + } |
|
116 | + } |
|
117 | + //use completely custom caps for this |
|
118 | + $this->_cap_restriction_generators = false; |
|
119 | + //caps-wise this is all-or-nothing: if you have the default role you can access anything, otherwise nothing |
|
120 | + foreach ($this->_cap_contexts_to_cap_action_map as $cap_context => $action) { |
|
121 | + $this->_cap_restrictions[$cap_context][EE_Restriction_Generator_Base::get_default_restrictions_cap()] |
|
122 | + = new EE_Return_None_Where_Conditions(); |
|
123 | + } |
|
124 | + parent::__construct($timezone); |
|
125 | + } |
|
126 | 126 | |
127 | - /** |
|
128 | - * @param string $log_type !see the acceptable values of LOG_type in EEM__Change_Log::__construct |
|
129 | - * @param mixed $message array|string of the message you want to record |
|
130 | - * @param EE_Base_Class $related_model_obj |
|
131 | - * @return EE_Change_Log |
|
132 | - * @throws EE_Error |
|
133 | - */ |
|
134 | - public function log($log_type, $message, $related_model_obj) |
|
135 | - { |
|
136 | - if ($related_model_obj instanceof EE_Base_Class) { |
|
137 | - $obj_id = $related_model_obj->ID(); |
|
138 | - $obj_type = $related_model_obj->get_model()->get_this_model_name(); |
|
139 | - } else { |
|
140 | - $obj_id = null; |
|
141 | - $obj_type = null; |
|
142 | - } |
|
143 | - /** @var EE_Change_Log $log */ |
|
144 | - $log = EE_Change_Log::new_instance(array( |
|
145 | - 'LOG_type' => $log_type, |
|
146 | - 'LOG_message' => $message, |
|
147 | - 'OBJ_ID' => $obj_id, |
|
148 | - 'OBJ_type' => $obj_type, |
|
149 | - )); |
|
150 | - $log->save(); |
|
151 | - return $log; |
|
152 | - } |
|
127 | + /** |
|
128 | + * @param string $log_type !see the acceptable values of LOG_type in EEM__Change_Log::__construct |
|
129 | + * @param mixed $message array|string of the message you want to record |
|
130 | + * @param EE_Base_Class $related_model_obj |
|
131 | + * @return EE_Change_Log |
|
132 | + * @throws EE_Error |
|
133 | + */ |
|
134 | + public function log($log_type, $message, $related_model_obj) |
|
135 | + { |
|
136 | + if ($related_model_obj instanceof EE_Base_Class) { |
|
137 | + $obj_id = $related_model_obj->ID(); |
|
138 | + $obj_type = $related_model_obj->get_model()->get_this_model_name(); |
|
139 | + } else { |
|
140 | + $obj_id = null; |
|
141 | + $obj_type = null; |
|
142 | + } |
|
143 | + /** @var EE_Change_Log $log */ |
|
144 | + $log = EE_Change_Log::new_instance(array( |
|
145 | + 'LOG_type' => $log_type, |
|
146 | + 'LOG_message' => $message, |
|
147 | + 'OBJ_ID' => $obj_id, |
|
148 | + 'OBJ_type' => $obj_type, |
|
149 | + )); |
|
150 | + $log->save(); |
|
151 | + return $log; |
|
152 | + } |
|
153 | 153 | |
154 | 154 | |
155 | - /** |
|
156 | - * Adds a gateway log for the specified object, given its ID and type |
|
157 | - * |
|
158 | - * @param string $message |
|
159 | - * @param mixed $related_obj_id |
|
160 | - * @param string $related_obj_type |
|
161 | - * @throws EE_Error |
|
162 | - * @return EE_Change_Log |
|
163 | - */ |
|
164 | - public function gateway_log($message, $related_obj_id, $related_obj_type) |
|
165 | - { |
|
166 | - if (! EE_Registry::instance()->is_model_name($related_obj_type)) { |
|
167 | - throw new EE_Error( |
|
168 | - sprintf( |
|
169 | - esc_html__( |
|
170 | - "'%s' is not a model name. A model name must be provided when making a gateway log. Eg, 'Payment', 'Payment_Method', etc", |
|
171 | - "event_espresso" |
|
172 | - ), |
|
173 | - $related_obj_type |
|
174 | - ) |
|
175 | - ); |
|
176 | - } |
|
177 | - /** @var EE_Change_Log $log */ |
|
178 | - $log = EE_Change_Log::new_instance(array( |
|
179 | - 'LOG_type' => EEM_Change_Log::type_gateway, |
|
180 | - 'LOG_message' => $message, |
|
181 | - 'OBJ_ID' => $related_obj_id, |
|
182 | - 'OBJ_type' => $related_obj_type, |
|
183 | - )); |
|
184 | - $log->save(); |
|
185 | - return $log; |
|
186 | - } |
|
155 | + /** |
|
156 | + * Adds a gateway log for the specified object, given its ID and type |
|
157 | + * |
|
158 | + * @param string $message |
|
159 | + * @param mixed $related_obj_id |
|
160 | + * @param string $related_obj_type |
|
161 | + * @throws EE_Error |
|
162 | + * @return EE_Change_Log |
|
163 | + */ |
|
164 | + public function gateway_log($message, $related_obj_id, $related_obj_type) |
|
165 | + { |
|
166 | + if (! EE_Registry::instance()->is_model_name($related_obj_type)) { |
|
167 | + throw new EE_Error( |
|
168 | + sprintf( |
|
169 | + esc_html__( |
|
170 | + "'%s' is not a model name. A model name must be provided when making a gateway log. Eg, 'Payment', 'Payment_Method', etc", |
|
171 | + "event_espresso" |
|
172 | + ), |
|
173 | + $related_obj_type |
|
174 | + ) |
|
175 | + ); |
|
176 | + } |
|
177 | + /** @var EE_Change_Log $log */ |
|
178 | + $log = EE_Change_Log::new_instance(array( |
|
179 | + 'LOG_type' => EEM_Change_Log::type_gateway, |
|
180 | + 'LOG_message' => $message, |
|
181 | + 'OBJ_ID' => $related_obj_id, |
|
182 | + 'OBJ_type' => $related_obj_type, |
|
183 | + )); |
|
184 | + $log->save(); |
|
185 | + return $log; |
|
186 | + } |
|
187 | 187 | |
188 | 188 | |
189 | - /** |
|
190 | - * Just gets the bare-bones wpdb results as an array in cases where efficiency is essential |
|
191 | - * |
|
192 | - * @param array $query_params @see EEM_Base::get_all |
|
193 | - * @return array of arrays |
|
194 | - * @throws EE_Error |
|
195 | - */ |
|
196 | - public function get_all_efficiently($query_params) |
|
197 | - { |
|
198 | - return $this->_get_all_wpdb_results($query_params); |
|
199 | - } |
|
189 | + /** |
|
190 | + * Just gets the bare-bones wpdb results as an array in cases where efficiency is essential |
|
191 | + * |
|
192 | + * @param array $query_params @see EEM_Base::get_all |
|
193 | + * @return array of arrays |
|
194 | + * @throws EE_Error |
|
195 | + */ |
|
196 | + public function get_all_efficiently($query_params) |
|
197 | + { |
|
198 | + return $this->_get_all_wpdb_results($query_params); |
|
199 | + } |
|
200 | 200 | |
201 | 201 | |
202 | - /** |
|
203 | - * Executes a database query to delete gateway logs. Does not affect model objects, so if you attempt to use |
|
204 | - * models after this, they may be out-of-sync with the database |
|
205 | - * |
|
206 | - * @param DateTime $datetime |
|
207 | - * @return false|int |
|
208 | - * @throws EE_Error |
|
209 | - */ |
|
210 | - public function delete_gateway_logs_older_than(DateTime $datetime) |
|
211 | - { |
|
212 | - global $wpdb; |
|
213 | - return $wpdb->query( |
|
214 | - $wpdb->prepare( |
|
215 | - 'DELETE FROM ' . $this->table() . ' WHERE LOG_type = %s AND LOG_time < %s', |
|
216 | - EEM_Change_Log::type_gateway, |
|
217 | - $datetime->format(EE_Datetime_Field::mysql_timestamp_format) |
|
218 | - ) |
|
219 | - ); |
|
220 | - } |
|
202 | + /** |
|
203 | + * Executes a database query to delete gateway logs. Does not affect model objects, so if you attempt to use |
|
204 | + * models after this, they may be out-of-sync with the database |
|
205 | + * |
|
206 | + * @param DateTime $datetime |
|
207 | + * @return false|int |
|
208 | + * @throws EE_Error |
|
209 | + */ |
|
210 | + public function delete_gateway_logs_older_than(DateTime $datetime) |
|
211 | + { |
|
212 | + global $wpdb; |
|
213 | + return $wpdb->query( |
|
214 | + $wpdb->prepare( |
|
215 | + 'DELETE FROM ' . $this->table() . ' WHERE LOG_type = %s AND LOG_time < %s', |
|
216 | + EEM_Change_Log::type_gateway, |
|
217 | + $datetime->format(EE_Datetime_Field::mysql_timestamp_format) |
|
218 | + ) |
|
219 | + ); |
|
220 | + } |
|
221 | 221 | |
222 | 222 | |
223 | - /** |
|
224 | - * Returns the map of type to pretty label for identifiers used for `LOG_type`. Client code can register their own |
|
225 | - * map vai the given filter. |
|
226 | - * |
|
227 | - * @return array |
|
228 | - */ |
|
229 | - public static function get_pretty_label_map_for_registered_types() |
|
230 | - { |
|
231 | - return apply_filters( |
|
232 | - 'FHEE__EEM_Change_Log__get_pretty_label_map_for_registered_types', |
|
233 | - array( |
|
234 | - self::type_create=> esc_html__("Create", "event_espresso"), |
|
235 | - self::type_update=> esc_html__("Update", "event_espresso"), |
|
236 | - self::type_delete => esc_html__("Delete", "event_espresso"), |
|
237 | - self::type_debug=> esc_html__("Debug", "event_espresso"), |
|
238 | - self::type_error=> esc_html__("Error", "event_espresso"), |
|
239 | - self::type_gateway=> esc_html__("Gateway Interaction (IPN or Direct Payment)", 'event_espresso') |
|
240 | - ) |
|
241 | - ); |
|
242 | - } |
|
223 | + /** |
|
224 | + * Returns the map of type to pretty label for identifiers used for `LOG_type`. Client code can register their own |
|
225 | + * map vai the given filter. |
|
226 | + * |
|
227 | + * @return array |
|
228 | + */ |
|
229 | + public static function get_pretty_label_map_for_registered_types() |
|
230 | + { |
|
231 | + return apply_filters( |
|
232 | + 'FHEE__EEM_Change_Log__get_pretty_label_map_for_registered_types', |
|
233 | + array( |
|
234 | + self::type_create=> esc_html__("Create", "event_espresso"), |
|
235 | + self::type_update=> esc_html__("Update", "event_espresso"), |
|
236 | + self::type_delete => esc_html__("Delete", "event_espresso"), |
|
237 | + self::type_debug=> esc_html__("Debug", "event_espresso"), |
|
238 | + self::type_error=> esc_html__("Error", "event_espresso"), |
|
239 | + self::type_gateway=> esc_html__("Gateway Interaction (IPN or Direct Payment)", 'event_espresso') |
|
240 | + ) |
|
241 | + ); |
|
242 | + } |
|
243 | 243 | |
244 | 244 | |
245 | - /** |
|
246 | - * Return the pretty (localized) label for the given log type identifier. |
|
247 | - * @param string $type_identifier |
|
248 | - * @return string |
|
249 | - */ |
|
250 | - public static function get_pretty_label_for_type($type_identifier) |
|
251 | - { |
|
252 | - $type_identifier_map = self::get_pretty_label_map_for_registered_types(); |
|
253 | - //we fallback to the incoming type identifier if there is no localized label for it. |
|
254 | - return isset($type_identifier_map[$type_identifier]) |
|
255 | - ? $type_identifier_map[$type_identifier] |
|
256 | - : $type_identifier; |
|
257 | - } |
|
245 | + /** |
|
246 | + * Return the pretty (localized) label for the given log type identifier. |
|
247 | + * @param string $type_identifier |
|
248 | + * @return string |
|
249 | + */ |
|
250 | + public static function get_pretty_label_for_type($type_identifier) |
|
251 | + { |
|
252 | + $type_identifier_map = self::get_pretty_label_map_for_registered_types(); |
|
253 | + //we fallback to the incoming type identifier if there is no localized label for it. |
|
254 | + return isset($type_identifier_map[$type_identifier]) |
|
255 | + ? $type_identifier_map[$type_identifier] |
|
256 | + : $type_identifier; |
|
257 | + } |
|
258 | 258 | } |
@@ -13,216 +13,216 @@ |
||
13 | 13 | class EE_Change_Log extends EE_Base_Class |
14 | 14 | { |
15 | 15 | |
16 | - /** |
|
17 | - * @param array $props_n_values incoming values |
|
18 | - * @param string $timezone incoming timezone (if not set the timezone set for the website will be |
|
19 | - * used.) |
|
20 | - * @param array $date_formats incoming date_formats in an array where the first value is the |
|
21 | - * date_format and the second value is the time format |
|
22 | - * @return EE_Change_Log |
|
23 | - * @throws EE_Error |
|
24 | - */ |
|
25 | - public static function new_instance($props_n_values = array(), $timezone = null, $date_formats = array()) |
|
26 | - { |
|
27 | - $has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone, $date_formats); |
|
28 | - return $has_object ? $has_object : new self($props_n_values, false, $timezone, $date_formats); |
|
29 | - } |
|
30 | - |
|
31 | - |
|
32 | - /** |
|
33 | - * @param array $props_n_values incoming values from the database |
|
34 | - * @param string $timezone incoming timezone as set by the model. If not set the timezone for |
|
35 | - * the website will be used. |
|
36 | - * @return EE_Change_Log |
|
37 | - */ |
|
38 | - public static function new_instance_from_db($props_n_values = array(), $timezone = null) |
|
39 | - { |
|
40 | - return new self($props_n_values, true, $timezone); |
|
41 | - } |
|
42 | - |
|
43 | - /** |
|
44 | - * Gets message |
|
45 | - * |
|
46 | - * @return mixed |
|
47 | - * @throws EE_Error |
|
48 | - */ |
|
49 | - public function message() |
|
50 | - { |
|
51 | - return $this->get('LOG_message'); |
|
52 | - } |
|
53 | - |
|
54 | - /** |
|
55 | - * Sets message |
|
56 | - * |
|
57 | - * @param mixed $message |
|
58 | - * @throws EE_Error |
|
59 | - */ |
|
60 | - public function set_message($message) |
|
61 | - { |
|
62 | - $this->set('LOG_message', $message); |
|
63 | - } |
|
64 | - |
|
65 | - /** |
|
66 | - * Gets time |
|
67 | - * |
|
68 | - * @return string |
|
69 | - * @throws EE_Error |
|
70 | - */ |
|
71 | - public function time() |
|
72 | - { |
|
73 | - return $this->get('LOG_time'); |
|
74 | - } |
|
75 | - |
|
76 | - /** |
|
77 | - * Sets time |
|
78 | - * |
|
79 | - * @param string $time |
|
80 | - * @throws EE_Error |
|
81 | - */ |
|
82 | - public function set_time($time) |
|
83 | - { |
|
84 | - $this->set('LOG_time', $time); |
|
85 | - } |
|
86 | - |
|
87 | - /** |
|
88 | - * Gets log_type |
|
89 | - * |
|
90 | - * @return string |
|
91 | - * @throws EE_Error |
|
92 | - */ |
|
93 | - public function log_type() |
|
94 | - { |
|
95 | - return $this->get('LOG_type'); |
|
96 | - } |
|
97 | - |
|
98 | - |
|
99 | - /** |
|
100 | - * Return the localized log type label. |
|
101 | - * @return string |
|
102 | - * @throws EE_Error |
|
103 | - */ |
|
104 | - public function log_type_label() |
|
105 | - { |
|
106 | - return EEM_Change_Log::get_pretty_label_for_type($this->log_type()); |
|
107 | - } |
|
108 | - |
|
109 | - /** |
|
110 | - * Sets log_type |
|
111 | - * |
|
112 | - * @param string $log_type |
|
113 | - * @throws EE_Error |
|
114 | - */ |
|
115 | - public function set_log_type($log_type) |
|
116 | - { |
|
117 | - $this->set('LOG_type', $log_type); |
|
118 | - } |
|
119 | - |
|
120 | - /** |
|
121 | - * Gets type of the model object related to this log |
|
122 | - * |
|
123 | - * @return string |
|
124 | - * @throws EE_Error |
|
125 | - */ |
|
126 | - public function OBJ_type() |
|
127 | - { |
|
128 | - return $this->get('OBJ_type'); |
|
129 | - } |
|
130 | - |
|
131 | - /** |
|
132 | - * Sets type |
|
133 | - * |
|
134 | - * @param string $type |
|
135 | - * @throws EE_Error |
|
136 | - */ |
|
137 | - public function set_OBJ_type($type) |
|
138 | - { |
|
139 | - $this->set('OBJ_type', $type); |
|
140 | - } |
|
141 | - |
|
142 | - /** |
|
143 | - * Gets OBJ_ID (the ID of the item related to this log) |
|
144 | - * |
|
145 | - * @return mixed |
|
146 | - * @throws EE_Error |
|
147 | - */ |
|
148 | - public function OBJ_ID() |
|
149 | - { |
|
150 | - return $this->get('OBJ_ID'); |
|
151 | - } |
|
152 | - |
|
153 | - /** |
|
154 | - * Sets OBJ_ID |
|
155 | - * |
|
156 | - * @param mixed $OBJ_ID |
|
157 | - * @throws EE_Error |
|
158 | - */ |
|
159 | - public function set_OBJ_ID($OBJ_ID) |
|
160 | - { |
|
161 | - $this->set('OBJ_ID', $OBJ_ID); |
|
162 | - } |
|
163 | - |
|
164 | - /** |
|
165 | - * Gets wp_user |
|
166 | - * |
|
167 | - * @return int |
|
168 | - * @throws EE_Error |
|
169 | - */ |
|
170 | - public function wp_user() |
|
171 | - { |
|
172 | - return $this->get('LOG_wp_user'); |
|
173 | - } |
|
174 | - |
|
175 | - /** |
|
176 | - * Sets wp_user |
|
177 | - * |
|
178 | - * @param int $wp_user_id |
|
179 | - * @throws EE_Error |
|
180 | - */ |
|
181 | - public function set_wp_user($wp_user_id) |
|
182 | - { |
|
183 | - $this->set('LOG_wp_user', $wp_user_id); |
|
184 | - } |
|
185 | - |
|
186 | - /** |
|
187 | - * Gets the model object attached to this log |
|
188 | - * |
|
189 | - * @return EE_Base_Class |
|
190 | - * @throws EE_Error |
|
191 | - */ |
|
192 | - public function object() |
|
193 | - { |
|
194 | - $model_name_of_related_obj = $this->OBJ_type(); |
|
195 | - $is_model_name = EE_Registry::instance()->is_model_name($model_name_of_related_obj); |
|
196 | - if (! $is_model_name) { |
|
197 | - return null; |
|
198 | - } else { |
|
199 | - return $this->get_first_related($model_name_of_related_obj); |
|
200 | - } |
|
201 | - } |
|
202 | - |
|
203 | - /** |
|
204 | - * Shorthand for setting the OBJ_ID and OBJ_type. Slightly handier than using |
|
205 | - * _add_relation_to because you don't have to specify what type of model you're |
|
206 | - * associating it with |
|
207 | - * |
|
208 | - * @param EE_Base_Class $object |
|
209 | - * @param boolean $save |
|
210 | - * @return bool if $save=true, NULL is $save=false |
|
211 | - * @throws EE_Error |
|
212 | - */ |
|
213 | - public function set_object($object, $save = true) |
|
214 | - { |
|
215 | - if ($object instanceof EE_Base_Class) { |
|
216 | - $this->set_OBJ_type($object->get_model()->get_this_model_name()); |
|
217 | - $this->set_OBJ_ID($object->ID()); |
|
218 | - } else { |
|
219 | - $this->set_OBJ_type(null); |
|
220 | - $this->set_OBJ_ID(null); |
|
221 | - } |
|
222 | - if ($save) { |
|
223 | - return $this->save(); |
|
224 | - } else { |
|
225 | - return null; |
|
226 | - } |
|
227 | - } |
|
16 | + /** |
|
17 | + * @param array $props_n_values incoming values |
|
18 | + * @param string $timezone incoming timezone (if not set the timezone set for the website will be |
|
19 | + * used.) |
|
20 | + * @param array $date_formats incoming date_formats in an array where the first value is the |
|
21 | + * date_format and the second value is the time format |
|
22 | + * @return EE_Change_Log |
|
23 | + * @throws EE_Error |
|
24 | + */ |
|
25 | + public static function new_instance($props_n_values = array(), $timezone = null, $date_formats = array()) |
|
26 | + { |
|
27 | + $has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone, $date_formats); |
|
28 | + return $has_object ? $has_object : new self($props_n_values, false, $timezone, $date_formats); |
|
29 | + } |
|
30 | + |
|
31 | + |
|
32 | + /** |
|
33 | + * @param array $props_n_values incoming values from the database |
|
34 | + * @param string $timezone incoming timezone as set by the model. If not set the timezone for |
|
35 | + * the website will be used. |
|
36 | + * @return EE_Change_Log |
|
37 | + */ |
|
38 | + public static function new_instance_from_db($props_n_values = array(), $timezone = null) |
|
39 | + { |
|
40 | + return new self($props_n_values, true, $timezone); |
|
41 | + } |
|
42 | + |
|
43 | + /** |
|
44 | + * Gets message |
|
45 | + * |
|
46 | + * @return mixed |
|
47 | + * @throws EE_Error |
|
48 | + */ |
|
49 | + public function message() |
|
50 | + { |
|
51 | + return $this->get('LOG_message'); |
|
52 | + } |
|
53 | + |
|
54 | + /** |
|
55 | + * Sets message |
|
56 | + * |
|
57 | + * @param mixed $message |
|
58 | + * @throws EE_Error |
|
59 | + */ |
|
60 | + public function set_message($message) |
|
61 | + { |
|
62 | + $this->set('LOG_message', $message); |
|
63 | + } |
|
64 | + |
|
65 | + /** |
|
66 | + * Gets time |
|
67 | + * |
|
68 | + * @return string |
|
69 | + * @throws EE_Error |
|
70 | + */ |
|
71 | + public function time() |
|
72 | + { |
|
73 | + return $this->get('LOG_time'); |
|
74 | + } |
|
75 | + |
|
76 | + /** |
|
77 | + * Sets time |
|
78 | + * |
|
79 | + * @param string $time |
|
80 | + * @throws EE_Error |
|
81 | + */ |
|
82 | + public function set_time($time) |
|
83 | + { |
|
84 | + $this->set('LOG_time', $time); |
|
85 | + } |
|
86 | + |
|
87 | + /** |
|
88 | + * Gets log_type |
|
89 | + * |
|
90 | + * @return string |
|
91 | + * @throws EE_Error |
|
92 | + */ |
|
93 | + public function log_type() |
|
94 | + { |
|
95 | + return $this->get('LOG_type'); |
|
96 | + } |
|
97 | + |
|
98 | + |
|
99 | + /** |
|
100 | + * Return the localized log type label. |
|
101 | + * @return string |
|
102 | + * @throws EE_Error |
|
103 | + */ |
|
104 | + public function log_type_label() |
|
105 | + { |
|
106 | + return EEM_Change_Log::get_pretty_label_for_type($this->log_type()); |
|
107 | + } |
|
108 | + |
|
109 | + /** |
|
110 | + * Sets log_type |
|
111 | + * |
|
112 | + * @param string $log_type |
|
113 | + * @throws EE_Error |
|
114 | + */ |
|
115 | + public function set_log_type($log_type) |
|
116 | + { |
|
117 | + $this->set('LOG_type', $log_type); |
|
118 | + } |
|
119 | + |
|
120 | + /** |
|
121 | + * Gets type of the model object related to this log |
|
122 | + * |
|
123 | + * @return string |
|
124 | + * @throws EE_Error |
|
125 | + */ |
|
126 | + public function OBJ_type() |
|
127 | + { |
|
128 | + return $this->get('OBJ_type'); |
|
129 | + } |
|
130 | + |
|
131 | + /** |
|
132 | + * Sets type |
|
133 | + * |
|
134 | + * @param string $type |
|
135 | + * @throws EE_Error |
|
136 | + */ |
|
137 | + public function set_OBJ_type($type) |
|
138 | + { |
|
139 | + $this->set('OBJ_type', $type); |
|
140 | + } |
|
141 | + |
|
142 | + /** |
|
143 | + * Gets OBJ_ID (the ID of the item related to this log) |
|
144 | + * |
|
145 | + * @return mixed |
|
146 | + * @throws EE_Error |
|
147 | + */ |
|
148 | + public function OBJ_ID() |
|
149 | + { |
|
150 | + return $this->get('OBJ_ID'); |
|
151 | + } |
|
152 | + |
|
153 | + /** |
|
154 | + * Sets OBJ_ID |
|
155 | + * |
|
156 | + * @param mixed $OBJ_ID |
|
157 | + * @throws EE_Error |
|
158 | + */ |
|
159 | + public function set_OBJ_ID($OBJ_ID) |
|
160 | + { |
|
161 | + $this->set('OBJ_ID', $OBJ_ID); |
|
162 | + } |
|
163 | + |
|
164 | + /** |
|
165 | + * Gets wp_user |
|
166 | + * |
|
167 | + * @return int |
|
168 | + * @throws EE_Error |
|
169 | + */ |
|
170 | + public function wp_user() |
|
171 | + { |
|
172 | + return $this->get('LOG_wp_user'); |
|
173 | + } |
|
174 | + |
|
175 | + /** |
|
176 | + * Sets wp_user |
|
177 | + * |
|
178 | + * @param int $wp_user_id |
|
179 | + * @throws EE_Error |
|
180 | + */ |
|
181 | + public function set_wp_user($wp_user_id) |
|
182 | + { |
|
183 | + $this->set('LOG_wp_user', $wp_user_id); |
|
184 | + } |
|
185 | + |
|
186 | + /** |
|
187 | + * Gets the model object attached to this log |
|
188 | + * |
|
189 | + * @return EE_Base_Class |
|
190 | + * @throws EE_Error |
|
191 | + */ |
|
192 | + public function object() |
|
193 | + { |
|
194 | + $model_name_of_related_obj = $this->OBJ_type(); |
|
195 | + $is_model_name = EE_Registry::instance()->is_model_name($model_name_of_related_obj); |
|
196 | + if (! $is_model_name) { |
|
197 | + return null; |
|
198 | + } else { |
|
199 | + return $this->get_first_related($model_name_of_related_obj); |
|
200 | + } |
|
201 | + } |
|
202 | + |
|
203 | + /** |
|
204 | + * Shorthand for setting the OBJ_ID and OBJ_type. Slightly handier than using |
|
205 | + * _add_relation_to because you don't have to specify what type of model you're |
|
206 | + * associating it with |
|
207 | + * |
|
208 | + * @param EE_Base_Class $object |
|
209 | + * @param boolean $save |
|
210 | + * @return bool if $save=true, NULL is $save=false |
|
211 | + * @throws EE_Error |
|
212 | + */ |
|
213 | + public function set_object($object, $save = true) |
|
214 | + { |
|
215 | + if ($object instanceof EE_Base_Class) { |
|
216 | + $this->set_OBJ_type($object->get_model()->get_this_model_name()); |
|
217 | + $this->set_OBJ_ID($object->ID()); |
|
218 | + } else { |
|
219 | + $this->set_OBJ_type(null); |
|
220 | + $this->set_OBJ_ID(null); |
|
221 | + } |
|
222 | + if ($save) { |
|
223 | + return $this->save(); |
|
224 | + } else { |
|
225 | + return null; |
|
226 | + } |
|
227 | + } |
|
228 | 228 | } |
@@ -193,7 +193,7 @@ |
||
193 | 193 | { |
194 | 194 | $model_name_of_related_obj = $this->OBJ_type(); |
195 | 195 | $is_model_name = EE_Registry::instance()->is_model_name($model_name_of_related_obj); |
196 | - if (! $is_model_name) { |
|
196 | + if ( ! $is_model_name) { |
|
197 | 197 | return null; |
198 | 198 | } else { |
199 | 199 | return $this->get_first_related($model_name_of_related_obj); |
@@ -126,7 +126,7 @@ discard block |
||
126 | 126 | { |
127 | 127 | add_action( |
128 | 128 | 'shutdown', |
129 | - function () use ($formatted) { |
|
129 | + function() use ($formatted) { |
|
130 | 130 | Benchmark::displayResults(true, $formatted); |
131 | 131 | } |
132 | 132 | ); |
@@ -146,7 +146,7 @@ discard block |
||
146 | 146 | { |
147 | 147 | add_action( |
148 | 148 | 'shutdown', |
149 | - function () use ($filepath, $formatted, $append) { |
|
149 | + function() use ($filepath, $formatted, $append) { |
|
150 | 150 | Benchmark::writeResultsToFile($filepath, $formatted, $append); |
151 | 151 | } |
152 | 152 | ); |
@@ -164,17 +164,17 @@ discard block |
||
164 | 164 | return ''; |
165 | 165 | } |
166 | 166 | $output = ''; |
167 | - if (! empty(Benchmark::$times)) { |
|
167 | + if ( ! empty(Benchmark::$times)) { |
|
168 | 168 | $total = 0; |
169 | 169 | $output .= $formatted |
170 | 170 | ? '<span style="color:#999999; font-size:.8em;">( time in milliseconds )</span><br />' |
171 | 171 | : ''; |
172 | 172 | foreach (Benchmark::$times as $timer_name => $total_time) { |
173 | 173 | $output .= Benchmark::formatTime($timer_name, $total_time, $formatted); |
174 | - $output .= $formatted ? '<br />' : "\n"; |
|
174 | + $output .= $formatted ? '<br />' : "\n"; |
|
175 | 175 | $total += $total_time; |
176 | 176 | } |
177 | - if($formatted) { |
|
177 | + if ($formatted) { |
|
178 | 178 | $output .= '<br />'; |
179 | 179 | $output .= '<h4>TOTAL TIME</h4>'; |
180 | 180 | $output .= Benchmark::formatTime('', $total, $formatted); |
@@ -189,9 +189,9 @@ discard block |
||
189 | 189 | $output .= '<span style="color:red">Like...HEEELLLP</span><br />'; |
190 | 190 | } |
191 | 191 | } |
192 | - if (! empty(Benchmark::$memory_usage)) { |
|
192 | + if ( ! empty(Benchmark::$memory_usage)) { |
|
193 | 193 | $output .= $formatted |
194 | - ? '<h5>Memory</h5>' . implode('<br />', Benchmark::$memory_usage) |
|
194 | + ? '<h5>Memory</h5>'.implode('<br />', Benchmark::$memory_usage) |
|
195 | 195 | : implode("\n", Benchmark::$memory_usage); |
196 | 196 | } |
197 | 197 | if (empty($output)) { |
@@ -239,12 +239,12 @@ discard block |
||
239 | 239 | $filepath = ! empty($filepath) && is_readable(dirname($filepath)) |
240 | 240 | ? $filepath |
241 | 241 | : ''; |
242 | - if( empty($filepath)) { |
|
243 | - $filepath = EVENT_ESPRESSO_UPLOAD_DIR . 'logs/benchmarking-' . date('Y-m-d') . '.html'; |
|
242 | + if (empty($filepath)) { |
|
243 | + $filepath = EVENT_ESPRESSO_UPLOAD_DIR.'logs/benchmarking-'.date('Y-m-d').'.html'; |
|
244 | 244 | } |
245 | 245 | file_put_contents( |
246 | 246 | $filepath, |
247 | - "\n" . date('Y-m-d H:i:s') . Benchmark::generateResults($formatted), |
|
247 | + "\n".date('Y-m-d H:i:s').Benchmark::generateResults($formatted), |
|
248 | 248 | $append ? FILE_APPEND | LOCK_EX : LOCK_EX |
249 | 249 | ); |
250 | 250 | } |
@@ -263,7 +263,7 @@ discard block |
||
263 | 263 | return round( |
264 | 264 | $size / pow(1024, $i = floor(log($size, 1024))), |
265 | 265 | 2 |
266 | - ) . ' ' . $unit[absint($i)]; |
|
266 | + ).' '.$unit[absint($i)]; |
|
267 | 267 | } |
268 | 268 | |
269 | 269 |
@@ -17,303 +17,303 @@ |
||
17 | 17 | class Benchmark |
18 | 18 | { |
19 | 19 | |
20 | - /** |
|
21 | - * array containing the start time for the timers |
|
22 | - */ |
|
23 | - private static $start_times; |
|
24 | - |
|
25 | - /** |
|
26 | - * array containing all the timer'd times, which can be outputted via show_times() |
|
27 | - */ |
|
28 | - private static $times = array(); |
|
29 | - |
|
30 | - /** |
|
31 | - * @var array |
|
32 | - */ |
|
33 | - protected static $memory_usage = array(); |
|
34 | - |
|
35 | - |
|
36 | - |
|
37 | - /** |
|
38 | - * whether to benchmark code or not |
|
39 | - */ |
|
40 | - public static function doNotRun() |
|
41 | - { |
|
42 | - return ! WP_DEBUG || (defined('DOING_AJAX') && DOING_AJAX); |
|
43 | - } |
|
44 | - |
|
45 | - |
|
46 | - |
|
47 | - /** |
|
48 | - * resetTimes |
|
49 | - */ |
|
50 | - public static function resetTimes() |
|
51 | - { |
|
52 | - Benchmark::$times = array(); |
|
53 | - } |
|
54 | - |
|
55 | - |
|
56 | - |
|
57 | - /** |
|
58 | - * Add Benchmark::startTimer() before a block of code you want to measure the performance of |
|
59 | - * |
|
60 | - * @param null $timer_name |
|
61 | - */ |
|
62 | - public static function startTimer($timer_name = null) |
|
63 | - { |
|
64 | - if (Benchmark::doNotRun()) { |
|
65 | - return; |
|
66 | - } |
|
67 | - $timer_name = $timer_name !== '' ? $timer_name : get_called_class(); |
|
68 | - Benchmark::$start_times[$timer_name] = microtime(true); |
|
69 | - } |
|
70 | - |
|
71 | - |
|
72 | - |
|
73 | - /** |
|
74 | - * Add Benchmark::stopTimer() after a block of code you want to measure the performance of |
|
75 | - * |
|
76 | - * @param string $timer_name |
|
77 | - */ |
|
78 | - public static function stopTimer($timer_name = '') |
|
79 | - { |
|
80 | - if (Benchmark::doNotRun()) { |
|
81 | - return; |
|
82 | - } |
|
83 | - $timer_name = $timer_name !== '' ? $timer_name : get_called_class(); |
|
84 | - if (isset(Benchmark::$start_times[$timer_name])) { |
|
85 | - $start_time = Benchmark::$start_times[$timer_name]; |
|
86 | - unset(Benchmark::$start_times[$timer_name]); |
|
87 | - } else { |
|
88 | - $start_time = array_pop(Benchmark::$start_times); |
|
89 | - } |
|
90 | - Benchmark::$times[$timer_name] = number_format(microtime(true) - $start_time, 8); |
|
91 | - } |
|
92 | - |
|
93 | - |
|
94 | - |
|
95 | - /** |
|
96 | - * Measure the memory usage by PHP so far. |
|
97 | - * |
|
98 | - * @param string $label The label to show for this time eg "Start of calling Some_Class::some_function" |
|
99 | - * @param boolean $output_now whether to echo now, or wait until EEH_Debug_Tools::show_times() is called |
|
100 | - * @param bool $formatted |
|
101 | - * @return void |
|
102 | - */ |
|
103 | - public static function measureMemory($label = 'memory usage', $output_now = false, $formatted = true) |
|
104 | - { |
|
105 | - if (Benchmark::doNotRun()) { |
|
106 | - return; |
|
107 | - } |
|
108 | - $memory_used = Benchmark::convert(memory_get_usage(true)); |
|
109 | - Benchmark::$memory_usage[$label] = $memory_used; |
|
110 | - if ($output_now) { |
|
111 | - echo $formatted |
|
112 | - ? "<br>{$label} : {$memory_used}" |
|
113 | - : "\n {$label} : {$memory_used}"; |
|
114 | - } |
|
115 | - } |
|
116 | - |
|
117 | - |
|
118 | - |
|
119 | - /** |
|
120 | - * will display the benchmarking results at shutdown |
|
121 | - * |
|
122 | - * @param bool $formatted |
|
123 | - * @return void |
|
124 | - */ |
|
125 | - public static function displayResultsAtShutdown($formatted = true) |
|
126 | - { |
|
127 | - add_action( |
|
128 | - 'shutdown', |
|
129 | - function () use ($formatted) { |
|
130 | - Benchmark::displayResults(true, $formatted); |
|
131 | - } |
|
132 | - ); |
|
133 | - } |
|
134 | - |
|
135 | - |
|
136 | - |
|
137 | - /** |
|
138 | - * will display the benchmarking results at shutdown |
|
139 | - * |
|
140 | - * @param string $filepath |
|
141 | - * @param bool $formatted |
|
142 | - * @param bool $append |
|
143 | - * @return void |
|
144 | - */ |
|
145 | - public static function writeResultsAtShutdown($filepath = '', $formatted = true, $append = true) |
|
146 | - { |
|
147 | - add_action( |
|
148 | - 'shutdown', |
|
149 | - function () use ($filepath, $formatted, $append) { |
|
150 | - Benchmark::writeResultsToFile($filepath, $formatted, $append); |
|
151 | - } |
|
152 | - ); |
|
153 | - } |
|
154 | - |
|
155 | - |
|
156 | - |
|
157 | - /** |
|
158 | - * @param bool $formatted |
|
159 | - * @return string |
|
160 | - */ |
|
161 | - private static function generateResults($formatted = true) |
|
162 | - { |
|
163 | - if (Benchmark::doNotRun()) { |
|
164 | - return ''; |
|
165 | - } |
|
166 | - $output = ''; |
|
167 | - if (! empty(Benchmark::$times)) { |
|
168 | - $total = 0; |
|
169 | - $output .= $formatted |
|
170 | - ? '<span style="color:#999999; font-size:.8em;">( time in milliseconds )</span><br />' |
|
171 | - : ''; |
|
172 | - foreach (Benchmark::$times as $timer_name => $total_time) { |
|
173 | - $output .= Benchmark::formatTime($timer_name, $total_time, $formatted); |
|
174 | - $output .= $formatted ? '<br />' : "\n"; |
|
175 | - $total += $total_time; |
|
176 | - } |
|
177 | - if($formatted) { |
|
178 | - $output .= '<br />'; |
|
179 | - $output .= '<h4>TOTAL TIME</h4>'; |
|
180 | - $output .= Benchmark::formatTime('', $total, $formatted); |
|
181 | - $output .= '<span style="color:#999999; font-size:.8em;"> milliseconds</span><br />'; |
|
182 | - $output .= '<br />'; |
|
183 | - $output .= '<h5>Performance scale (from best to worse)</h5>'; |
|
184 | - $output .= '<span style="color:mediumpurple">Like wow! How about a Scooby snack?</span><br />'; |
|
185 | - $output .= '<span style="color:deepskyblue">Like...no way man!</span><br />'; |
|
186 | - $output .= '<span style="color:limegreen">Like...groovy!</span><br />'; |
|
187 | - $output .= '<span style="color:gold">Ruh Oh</span><br />'; |
|
188 | - $output .= '<span style="color:darkorange">Zoinks!</span><br />'; |
|
189 | - $output .= '<span style="color:red">Like...HEEELLLP</span><br />'; |
|
190 | - } |
|
191 | - } |
|
192 | - if (! empty(Benchmark::$memory_usage)) { |
|
193 | - $output .= $formatted |
|
194 | - ? '<h5>Memory</h5>' . implode('<br />', Benchmark::$memory_usage) |
|
195 | - : implode("\n", Benchmark::$memory_usage); |
|
196 | - } |
|
197 | - if (empty($output)) { |
|
198 | - return ''; |
|
199 | - } |
|
200 | - $output = $formatted |
|
201 | - ? '<div style="border:1px solid #dddddd; background-color:#ffffff;' |
|
202 | - . (is_admin() |
|
203 | - ? ' margin:2em 2em 2em 180px;' |
|
204 | - : ' margin:2em;') |
|
205 | - . ' padding:2em;">' |
|
206 | - . '<h4>BENCHMARKING</h4>' |
|
207 | - . $output |
|
208 | - . '</div>' |
|
209 | - : $output; |
|
210 | - return $output; |
|
211 | - } |
|
212 | - |
|
213 | - |
|
214 | - |
|
215 | - /** |
|
216 | - * @param bool $echo |
|
217 | - * @param bool $formatted |
|
218 | - * @return string |
|
219 | - */ |
|
220 | - public static function displayResults($echo = true, $formatted = true) |
|
221 | - { |
|
222 | - $results = Benchmark::generateResults($formatted); |
|
223 | - if ($echo) { |
|
224 | - echo $results; |
|
225 | - $results = ''; |
|
226 | - } |
|
227 | - return $results; |
|
228 | - } |
|
229 | - |
|
230 | - |
|
231 | - |
|
232 | - /** |
|
233 | - * @param string $filepath |
|
234 | - * @param bool $formatted |
|
235 | - * @param bool $append |
|
236 | - */ |
|
237 | - public static function writeResultsToFile($filepath = '', $formatted = true, $append = true) |
|
238 | - { |
|
239 | - $filepath = ! empty($filepath) && is_readable(dirname($filepath)) |
|
240 | - ? $filepath |
|
241 | - : ''; |
|
242 | - if( empty($filepath)) { |
|
243 | - $filepath = EVENT_ESPRESSO_UPLOAD_DIR . 'logs/benchmarking-' . date('Y-m-d') . '.html'; |
|
244 | - } |
|
245 | - file_put_contents( |
|
246 | - $filepath, |
|
247 | - "\n" . date('Y-m-d H:i:s') . Benchmark::generateResults($formatted), |
|
248 | - $append ? FILE_APPEND | LOCK_EX : LOCK_EX |
|
249 | - ); |
|
250 | - } |
|
251 | - |
|
252 | - |
|
253 | - |
|
254 | - /** |
|
255 | - * Converts a measure of memory bytes into the most logical units (eg kb, mb, etc) |
|
256 | - * |
|
257 | - * @param int $size |
|
258 | - * @return string |
|
259 | - */ |
|
260 | - public static function convert($size) |
|
261 | - { |
|
262 | - $unit = array('b', 'kb', 'mb', 'gb', 'tb', 'pb'); |
|
263 | - return round( |
|
264 | - $size / pow(1024, $i = floor(log($size, 1024))), |
|
265 | - 2 |
|
266 | - ) . ' ' . $unit[absint($i)]; |
|
267 | - } |
|
268 | - |
|
269 | - |
|
270 | - |
|
271 | - /** |
|
272 | - * @param string $timer_name |
|
273 | - * @param float $total_time |
|
274 | - * @param bool $formatted |
|
275 | - * @return string |
|
276 | - */ |
|
277 | - public static function formatTime($timer_name, $total_time, $formatted = true) |
|
278 | - { |
|
279 | - $total_time *= 1000; |
|
280 | - switch ($total_time) { |
|
281 | - case $total_time > 12500 : |
|
282 | - $color = 'red'; |
|
283 | - $bold = 'bold'; |
|
284 | - break; |
|
285 | - case $total_time > 2500 : |
|
286 | - $color = 'darkorange'; |
|
287 | - $bold = 'bold'; |
|
288 | - break; |
|
289 | - case $total_time > 500 : |
|
290 | - $color = 'gold'; |
|
291 | - $bold = 'bold'; |
|
292 | - break; |
|
293 | - case $total_time > 100 : |
|
294 | - $color = 'limegreen'; |
|
295 | - $bold = 'normal'; |
|
296 | - break; |
|
297 | - case $total_time > 20 : |
|
298 | - $color = 'deepskyblue'; |
|
299 | - $bold = 'normal'; |
|
300 | - break; |
|
301 | - default : |
|
302 | - $color = 'mediumpurple'; |
|
303 | - $bold = 'normal'; |
|
304 | - break; |
|
305 | - } |
|
306 | - return $formatted |
|
307 | - ? '<span style="min-width: 10px; margin:0 1em; color:' |
|
308 | - . $color |
|
309 | - . '; font-weight:' |
|
310 | - . $bold |
|
311 | - . '; font-size:1.2em;">' |
|
312 | - . str_pad(number_format($total_time, 3), 9, '0', STR_PAD_LEFT) |
|
313 | - . '</span> ' |
|
314 | - . $timer_name |
|
315 | - : str_pad(number_format($total_time, 3), 9, '0', STR_PAD_LEFT); |
|
316 | - } |
|
20 | + /** |
|
21 | + * array containing the start time for the timers |
|
22 | + */ |
|
23 | + private static $start_times; |
|
24 | + |
|
25 | + /** |
|
26 | + * array containing all the timer'd times, which can be outputted via show_times() |
|
27 | + */ |
|
28 | + private static $times = array(); |
|
29 | + |
|
30 | + /** |
|
31 | + * @var array |
|
32 | + */ |
|
33 | + protected static $memory_usage = array(); |
|
34 | + |
|
35 | + |
|
36 | + |
|
37 | + /** |
|
38 | + * whether to benchmark code or not |
|
39 | + */ |
|
40 | + public static function doNotRun() |
|
41 | + { |
|
42 | + return ! WP_DEBUG || (defined('DOING_AJAX') && DOING_AJAX); |
|
43 | + } |
|
44 | + |
|
45 | + |
|
46 | + |
|
47 | + /** |
|
48 | + * resetTimes |
|
49 | + */ |
|
50 | + public static function resetTimes() |
|
51 | + { |
|
52 | + Benchmark::$times = array(); |
|
53 | + } |
|
54 | + |
|
55 | + |
|
56 | + |
|
57 | + /** |
|
58 | + * Add Benchmark::startTimer() before a block of code you want to measure the performance of |
|
59 | + * |
|
60 | + * @param null $timer_name |
|
61 | + */ |
|
62 | + public static function startTimer($timer_name = null) |
|
63 | + { |
|
64 | + if (Benchmark::doNotRun()) { |
|
65 | + return; |
|
66 | + } |
|
67 | + $timer_name = $timer_name !== '' ? $timer_name : get_called_class(); |
|
68 | + Benchmark::$start_times[$timer_name] = microtime(true); |
|
69 | + } |
|
70 | + |
|
71 | + |
|
72 | + |
|
73 | + /** |
|
74 | + * Add Benchmark::stopTimer() after a block of code you want to measure the performance of |
|
75 | + * |
|
76 | + * @param string $timer_name |
|
77 | + */ |
|
78 | + public static function stopTimer($timer_name = '') |
|
79 | + { |
|
80 | + if (Benchmark::doNotRun()) { |
|
81 | + return; |
|
82 | + } |
|
83 | + $timer_name = $timer_name !== '' ? $timer_name : get_called_class(); |
|
84 | + if (isset(Benchmark::$start_times[$timer_name])) { |
|
85 | + $start_time = Benchmark::$start_times[$timer_name]; |
|
86 | + unset(Benchmark::$start_times[$timer_name]); |
|
87 | + } else { |
|
88 | + $start_time = array_pop(Benchmark::$start_times); |
|
89 | + } |
|
90 | + Benchmark::$times[$timer_name] = number_format(microtime(true) - $start_time, 8); |
|
91 | + } |
|
92 | + |
|
93 | + |
|
94 | + |
|
95 | + /** |
|
96 | + * Measure the memory usage by PHP so far. |
|
97 | + * |
|
98 | + * @param string $label The label to show for this time eg "Start of calling Some_Class::some_function" |
|
99 | + * @param boolean $output_now whether to echo now, or wait until EEH_Debug_Tools::show_times() is called |
|
100 | + * @param bool $formatted |
|
101 | + * @return void |
|
102 | + */ |
|
103 | + public static function measureMemory($label = 'memory usage', $output_now = false, $formatted = true) |
|
104 | + { |
|
105 | + if (Benchmark::doNotRun()) { |
|
106 | + return; |
|
107 | + } |
|
108 | + $memory_used = Benchmark::convert(memory_get_usage(true)); |
|
109 | + Benchmark::$memory_usage[$label] = $memory_used; |
|
110 | + if ($output_now) { |
|
111 | + echo $formatted |
|
112 | + ? "<br>{$label} : {$memory_used}" |
|
113 | + : "\n {$label} : {$memory_used}"; |
|
114 | + } |
|
115 | + } |
|
116 | + |
|
117 | + |
|
118 | + |
|
119 | + /** |
|
120 | + * will display the benchmarking results at shutdown |
|
121 | + * |
|
122 | + * @param bool $formatted |
|
123 | + * @return void |
|
124 | + */ |
|
125 | + public static function displayResultsAtShutdown($formatted = true) |
|
126 | + { |
|
127 | + add_action( |
|
128 | + 'shutdown', |
|
129 | + function () use ($formatted) { |
|
130 | + Benchmark::displayResults(true, $formatted); |
|
131 | + } |
|
132 | + ); |
|
133 | + } |
|
134 | + |
|
135 | + |
|
136 | + |
|
137 | + /** |
|
138 | + * will display the benchmarking results at shutdown |
|
139 | + * |
|
140 | + * @param string $filepath |
|
141 | + * @param bool $formatted |
|
142 | + * @param bool $append |
|
143 | + * @return void |
|
144 | + */ |
|
145 | + public static function writeResultsAtShutdown($filepath = '', $formatted = true, $append = true) |
|
146 | + { |
|
147 | + add_action( |
|
148 | + 'shutdown', |
|
149 | + function () use ($filepath, $formatted, $append) { |
|
150 | + Benchmark::writeResultsToFile($filepath, $formatted, $append); |
|
151 | + } |
|
152 | + ); |
|
153 | + } |
|
154 | + |
|
155 | + |
|
156 | + |
|
157 | + /** |
|
158 | + * @param bool $formatted |
|
159 | + * @return string |
|
160 | + */ |
|
161 | + private static function generateResults($formatted = true) |
|
162 | + { |
|
163 | + if (Benchmark::doNotRun()) { |
|
164 | + return ''; |
|
165 | + } |
|
166 | + $output = ''; |
|
167 | + if (! empty(Benchmark::$times)) { |
|
168 | + $total = 0; |
|
169 | + $output .= $formatted |
|
170 | + ? '<span style="color:#999999; font-size:.8em;">( time in milliseconds )</span><br />' |
|
171 | + : ''; |
|
172 | + foreach (Benchmark::$times as $timer_name => $total_time) { |
|
173 | + $output .= Benchmark::formatTime($timer_name, $total_time, $formatted); |
|
174 | + $output .= $formatted ? '<br />' : "\n"; |
|
175 | + $total += $total_time; |
|
176 | + } |
|
177 | + if($formatted) { |
|
178 | + $output .= '<br />'; |
|
179 | + $output .= '<h4>TOTAL TIME</h4>'; |
|
180 | + $output .= Benchmark::formatTime('', $total, $formatted); |
|
181 | + $output .= '<span style="color:#999999; font-size:.8em;"> milliseconds</span><br />'; |
|
182 | + $output .= '<br />'; |
|
183 | + $output .= '<h5>Performance scale (from best to worse)</h5>'; |
|
184 | + $output .= '<span style="color:mediumpurple">Like wow! How about a Scooby snack?</span><br />'; |
|
185 | + $output .= '<span style="color:deepskyblue">Like...no way man!</span><br />'; |
|
186 | + $output .= '<span style="color:limegreen">Like...groovy!</span><br />'; |
|
187 | + $output .= '<span style="color:gold">Ruh Oh</span><br />'; |
|
188 | + $output .= '<span style="color:darkorange">Zoinks!</span><br />'; |
|
189 | + $output .= '<span style="color:red">Like...HEEELLLP</span><br />'; |
|
190 | + } |
|
191 | + } |
|
192 | + if (! empty(Benchmark::$memory_usage)) { |
|
193 | + $output .= $formatted |
|
194 | + ? '<h5>Memory</h5>' . implode('<br />', Benchmark::$memory_usage) |
|
195 | + : implode("\n", Benchmark::$memory_usage); |
|
196 | + } |
|
197 | + if (empty($output)) { |
|
198 | + return ''; |
|
199 | + } |
|
200 | + $output = $formatted |
|
201 | + ? '<div style="border:1px solid #dddddd; background-color:#ffffff;' |
|
202 | + . (is_admin() |
|
203 | + ? ' margin:2em 2em 2em 180px;' |
|
204 | + : ' margin:2em;') |
|
205 | + . ' padding:2em;">' |
|
206 | + . '<h4>BENCHMARKING</h4>' |
|
207 | + . $output |
|
208 | + . '</div>' |
|
209 | + : $output; |
|
210 | + return $output; |
|
211 | + } |
|
212 | + |
|
213 | + |
|
214 | + |
|
215 | + /** |
|
216 | + * @param bool $echo |
|
217 | + * @param bool $formatted |
|
218 | + * @return string |
|
219 | + */ |
|
220 | + public static function displayResults($echo = true, $formatted = true) |
|
221 | + { |
|
222 | + $results = Benchmark::generateResults($formatted); |
|
223 | + if ($echo) { |
|
224 | + echo $results; |
|
225 | + $results = ''; |
|
226 | + } |
|
227 | + return $results; |
|
228 | + } |
|
229 | + |
|
230 | + |
|
231 | + |
|
232 | + /** |
|
233 | + * @param string $filepath |
|
234 | + * @param bool $formatted |
|
235 | + * @param bool $append |
|
236 | + */ |
|
237 | + public static function writeResultsToFile($filepath = '', $formatted = true, $append = true) |
|
238 | + { |
|
239 | + $filepath = ! empty($filepath) && is_readable(dirname($filepath)) |
|
240 | + ? $filepath |
|
241 | + : ''; |
|
242 | + if( empty($filepath)) { |
|
243 | + $filepath = EVENT_ESPRESSO_UPLOAD_DIR . 'logs/benchmarking-' . date('Y-m-d') . '.html'; |
|
244 | + } |
|
245 | + file_put_contents( |
|
246 | + $filepath, |
|
247 | + "\n" . date('Y-m-d H:i:s') . Benchmark::generateResults($formatted), |
|
248 | + $append ? FILE_APPEND | LOCK_EX : LOCK_EX |
|
249 | + ); |
|
250 | + } |
|
251 | + |
|
252 | + |
|
253 | + |
|
254 | + /** |
|
255 | + * Converts a measure of memory bytes into the most logical units (eg kb, mb, etc) |
|
256 | + * |
|
257 | + * @param int $size |
|
258 | + * @return string |
|
259 | + */ |
|
260 | + public static function convert($size) |
|
261 | + { |
|
262 | + $unit = array('b', 'kb', 'mb', 'gb', 'tb', 'pb'); |
|
263 | + return round( |
|
264 | + $size / pow(1024, $i = floor(log($size, 1024))), |
|
265 | + 2 |
|
266 | + ) . ' ' . $unit[absint($i)]; |
|
267 | + } |
|
268 | + |
|
269 | + |
|
270 | + |
|
271 | + /** |
|
272 | + * @param string $timer_name |
|
273 | + * @param float $total_time |
|
274 | + * @param bool $formatted |
|
275 | + * @return string |
|
276 | + */ |
|
277 | + public static function formatTime($timer_name, $total_time, $formatted = true) |
|
278 | + { |
|
279 | + $total_time *= 1000; |
|
280 | + switch ($total_time) { |
|
281 | + case $total_time > 12500 : |
|
282 | + $color = 'red'; |
|
283 | + $bold = 'bold'; |
|
284 | + break; |
|
285 | + case $total_time > 2500 : |
|
286 | + $color = 'darkorange'; |
|
287 | + $bold = 'bold'; |
|
288 | + break; |
|
289 | + case $total_time > 500 : |
|
290 | + $color = 'gold'; |
|
291 | + $bold = 'bold'; |
|
292 | + break; |
|
293 | + case $total_time > 100 : |
|
294 | + $color = 'limegreen'; |
|
295 | + $bold = 'normal'; |
|
296 | + break; |
|
297 | + case $total_time > 20 : |
|
298 | + $color = 'deepskyblue'; |
|
299 | + $bold = 'normal'; |
|
300 | + break; |
|
301 | + default : |
|
302 | + $color = 'mediumpurple'; |
|
303 | + $bold = 'normal'; |
|
304 | + break; |
|
305 | + } |
|
306 | + return $formatted |
|
307 | + ? '<span style="min-width: 10px; margin:0 1em; color:' |
|
308 | + . $color |
|
309 | + . '; font-weight:' |
|
310 | + . $bold |
|
311 | + . '; font-size:1.2em;">' |
|
312 | + . str_pad(number_format($total_time, 3), 9, '0', STR_PAD_LEFT) |
|
313 | + . '</span> ' |
|
314 | + . $timer_name |
|
315 | + : str_pad(number_format($total_time, 3), 9, '0', STR_PAD_LEFT); |
|
316 | + } |
|
317 | 317 | |
318 | 318 | |
319 | 319 |