@@ -114,7 +114,7 @@ discard block |
||
| 114 | 114 | $class = parent::_get_row_class($item); |
| 115 | 115 | // add status class |
| 116 | 116 | $class .= $item instanceof EE_Event |
| 117 | - ? ' ee-status-strip event-status-' . $item->get_active_status() |
|
| 117 | + ? ' ee-status-strip event-status-'.$item->get_active_status() |
|
| 118 | 118 | : ''; |
| 119 | 119 | if ($this->_has_checkbox_column) { |
| 120 | 120 | $class .= ' has-checkbox-column'; |
@@ -143,7 +143,7 @@ discard block |
||
| 143 | 143 | */ |
| 144 | 144 | public function column_cb($item) |
| 145 | 145 | { |
| 146 | - if (! $item instanceof EE_Event) { |
|
| 146 | + if ( ! $item instanceof EE_Event) { |
|
| 147 | 147 | return ''; |
| 148 | 148 | } |
| 149 | 149 | $this->_dtt = $item->primary_datetime(); // set this for use in other columns |
@@ -166,7 +166,7 @@ discard block |
||
| 166 | 166 | public function column_id(EE_Event $item) |
| 167 | 167 | { |
| 168 | 168 | $content = $item->ID(); |
| 169 | - $content .= ' <span class="show-on-mobile-view-only">' . $item->name() . '</span>'; |
|
| 169 | + $content .= ' <span class="show-on-mobile-view-only">'.$item->name().'</span>'; |
|
| 170 | 170 | return $content; |
| 171 | 171 | } |
| 172 | 172 | |
@@ -189,7 +189,7 @@ discard block |
||
| 189 | 189 | $actions = $this->_column_name_action_setup($item); |
| 190 | 190 | $status = ''; // $item->status() !== 'publish' ? ' (' . $item->status() . ')' : ''; |
| 191 | 191 | $content = '<strong><a class="row-title" href="' |
| 192 | - . $edit_link . '">' |
|
| 192 | + . $edit_link.'">' |
|
| 193 | 193 | . $item->name() |
| 194 | 194 | . '</a></strong>' |
| 195 | 195 | . $status; |
@@ -218,7 +218,7 @@ discard block |
||
| 218 | 218 | protected function _column_name_action_setup(EE_Event $item) |
| 219 | 219 | { |
| 220 | 220 | // todo: remove when attendees is active |
| 221 | - if (! defined('REG_ADMIN_URL')) { |
|
| 221 | + if ( ! defined('REG_ADMIN_URL')) { |
|
| 222 | 222 | define('REG_ADMIN_URL', EVENTS_ADMIN_URL); |
| 223 | 223 | } |
| 224 | 224 | $actions = array(); |
@@ -237,8 +237,8 @@ discard block |
||
| 237 | 237 | 'post' => $item->ID(), |
| 238 | 238 | ); |
| 239 | 239 | $edit_link = EE_Admin_Page::add_query_args_and_nonce($edit_query_args, EVENTS_ADMIN_URL); |
| 240 | - $actions['edit'] = '<a href="' . $edit_link . '"' |
|
| 241 | - . ' title="' . esc_attr__('Edit Event', 'event_espresso') . '">' |
|
| 240 | + $actions['edit'] = '<a href="'.$edit_link.'"' |
|
| 241 | + . ' title="'.esc_attr__('Edit Event', 'event_espresso').'">' |
|
| 242 | 242 | . esc_html__('Edit', 'event_espresso') |
| 243 | 243 | . '</a>'; |
| 244 | 244 | } |
@@ -258,8 +258,8 @@ discard block |
||
| 258 | 258 | 'event_id' => $item->ID(), |
| 259 | 259 | ); |
| 260 | 260 | $attendees_link = EE_Admin_Page::add_query_args_and_nonce($attendees_query_args, REG_ADMIN_URL); |
| 261 | - $actions['attendees'] = '<a href="' . $attendees_link . '"' |
|
| 262 | - . ' title="' . esc_attr__('View Registrations', 'event_espresso') . '">' |
|
| 261 | + $actions['attendees'] = '<a href="'.$attendees_link.'"' |
|
| 262 | + . ' title="'.esc_attr__('View Registrations', 'event_espresso').'">' |
|
| 263 | 263 | . esc_html__('Registrations', 'event_espresso') |
| 264 | 264 | . '</a>'; |
| 265 | 265 | } |
@@ -312,8 +312,8 @@ discard block |
||
| 312 | 312 | ); |
| 313 | 313 | } |
| 314 | 314 | $view_link = get_permalink($item->ID()); |
| 315 | - $actions['view'] = '<a href="' . $view_link . '"' |
|
| 316 | - . ' title="' . esc_attr__('View Event', 'event_espresso') . '">' |
|
| 315 | + $actions['view'] = '<a href="'.$view_link.'"' |
|
| 316 | + . ' title="'.esc_attr__('View Event', 'event_espresso').'">' |
|
| 317 | 317 | . esc_html__('View', 'event_espresso') |
| 318 | 318 | . '</a>'; |
| 319 | 319 | if ($item->get('status') === 'trash') { |
@@ -324,8 +324,8 @@ discard block |
||
| 324 | 324 | $item->ID() |
| 325 | 325 | ) |
| 326 | 326 | ) { |
| 327 | - $actions['restore_from_trash'] = '<a href="' . $restore_event_link . '"' |
|
| 328 | - . ' title="' . esc_attr__('Restore from Trash', 'event_espresso') |
|
| 327 | + $actions['restore_from_trash'] = '<a href="'.$restore_event_link.'"' |
|
| 328 | + . ' title="'.esc_attr__('Restore from Trash', 'event_espresso') |
|
| 329 | 329 | . '">' |
| 330 | 330 | . esc_html__('Restore from Trash', 'event_espresso') |
| 331 | 331 | . '</a>'; |
@@ -338,8 +338,8 @@ discard block |
||
| 338 | 338 | $item->ID() |
| 339 | 339 | ) |
| 340 | 340 | ) { |
| 341 | - $actions['delete'] = '<a href="' . $delete_event_link . '"' |
|
| 342 | - . ' title="' . esc_attr__('Delete Permanently', 'event_espresso') . '">' |
|
| 341 | + $actions['delete'] = '<a href="'.$delete_event_link.'"' |
|
| 342 | + . ' title="'.esc_attr__('Delete Permanently', 'event_espresso').'">' |
|
| 343 | 343 | . esc_html__('Delete Permanently', 'event_espresso') |
| 344 | 344 | . '</a>'; |
| 345 | 345 | } |
@@ -351,8 +351,8 @@ discard block |
||
| 351 | 351 | $item->ID() |
| 352 | 352 | ) |
| 353 | 353 | ) { |
| 354 | - $actions['move to trash'] = '<a href="' . $trash_event_link . '"' |
|
| 355 | - . ' title="' . esc_attr__('Trash Event', 'event_espresso') . '">' |
|
| 354 | + $actions['move to trash'] = '<a href="'.$trash_event_link.'"' |
|
| 355 | + . ' title="'.esc_attr__('Trash Event', 'event_espresso').'">' |
|
| 356 | 356 | . esc_html__('Trash', 'event_espresso') |
| 357 | 357 | . '</a>'; |
| 358 | 358 | } |
@@ -377,8 +377,8 @@ discard block |
||
| 377 | 377 | 'EVT_wp_user' => $item->wp_user(), |
| 378 | 378 | ); |
| 379 | 379 | $filter_url = EE_Admin_Page::add_query_args_and_nonce($query_args, EVENTS_ADMIN_URL); |
| 380 | - return $gravatar . ' <a href="' . $filter_url . '"' |
|
| 381 | - . ' title="' . esc_attr__('Click to filter events by this author.', 'event_espresso') . '">' |
|
| 380 | + return $gravatar.' <a href="'.$filter_url.'"' |
|
| 381 | + . ' title="'.esc_attr__('Click to filter events by this author.', 'event_espresso').'">' |
|
| 382 | 382 | . $event_author->display_name |
| 383 | 383 | . '</a>'; |
| 384 | 384 | } |
@@ -395,7 +395,7 @@ discard block |
||
| 395 | 395 | return implode( |
| 396 | 396 | ', ', |
| 397 | 397 | array_map( |
| 398 | - function (EE_Term $category) { |
|
| 398 | + function(EE_Term $category) { |
|
| 399 | 399 | return $category->name(); |
| 400 | 400 | }, |
| 401 | 401 | $event_categories |
@@ -470,7 +470,7 @@ discard block |
||
| 470 | 470 | 'ee_read_registrations', |
| 471 | 471 | 'espresso_registrations_view_registration' |
| 472 | 472 | ) |
| 473 | - ? '<a href="' . $attendees_link . '">' . $registered_attendees . '</a>' |
|
| 473 | + ? '<a href="'.$attendees_link.'">'.$registered_attendees.'</a>' |
|
| 474 | 474 | : $registered_attendees; |
| 475 | 475 | } |
| 476 | 476 | |
@@ -500,13 +500,13 @@ discard block |
||
| 500 | 500 | public function column_actions(EE_Event $item) |
| 501 | 501 | { |
| 502 | 502 | // todo: remove when attendees is active |
| 503 | - if (! defined('REG_ADMIN_URL')) { |
|
| 503 | + if ( ! defined('REG_ADMIN_URL')) { |
|
| 504 | 504 | define('REG_ADMIN_URL', EVENTS_ADMIN_URL); |
| 505 | 505 | } |
| 506 | 506 | $action_links = array(); |
| 507 | 507 | $view_link = get_permalink($item->ID()); |
| 508 | - $action_links[] = '<a href="' . $view_link . '"' |
|
| 509 | - . ' title="' . esc_attr__('View Event', 'event_espresso') . '" target="_blank">'; |
|
| 508 | + $action_links[] = '<a href="'.$view_link.'"' |
|
| 509 | + . ' title="'.esc_attr__('View Event', 'event_espresso').'" target="_blank">'; |
|
| 510 | 510 | $action_links[] = '<div class="dashicons dashicons-search"></div></a>'; |
| 511 | 511 | if ( |
| 512 | 512 | EE_Registry::instance()->CAP->current_user_can( |
@@ -520,8 +520,8 @@ discard block |
||
| 520 | 520 | 'post' => $item->ID(), |
| 521 | 521 | ); |
| 522 | 522 | $edit_link = EE_Admin_Page::add_query_args_and_nonce($edit_query_args, EVENTS_ADMIN_URL); |
| 523 | - $action_links[] = '<a href="' . $edit_link . '"' |
|
| 524 | - . ' title="' . esc_attr__('Edit Event', 'event_espresso') . '">' |
|
| 523 | + $action_links[] = '<a href="'.$edit_link.'"' |
|
| 524 | + . ' title="'.esc_attr__('Edit Event', 'event_espresso').'">' |
|
| 525 | 525 | . '<div class="ee-icon ee-icon-calendar-edit"></div>' |
| 526 | 526 | . '</a>'; |
| 527 | 527 | } |
@@ -540,8 +540,8 @@ discard block |
||
| 540 | 540 | 'event_id' => $item->ID(), |
| 541 | 541 | ); |
| 542 | 542 | $attendees_link = EE_Admin_Page::add_query_args_and_nonce($attendees_query_args, REG_ADMIN_URL); |
| 543 | - $action_links[] = '<a href="' . $attendees_link . '"' |
|
| 544 | - . ' title="' . esc_attr__('View Registrants', 'event_espresso') . '">' |
|
| 543 | + $action_links[] = '<a href="'.$attendees_link.'"' |
|
| 544 | + . ' title="'.esc_attr__('View Registrants', 'event_espresso').'">' |
|
| 545 | 545 | . '<div class="dashicons dashicons-groups"></div>' |
| 546 | 546 | . '</a>'; |
| 547 | 547 | } |
@@ -576,7 +576,7 @@ discard block |
||
| 576 | 576 | } |
| 577 | 577 | $column_array = []; |
| 578 | 578 | foreach ($this->_columns as $column => $column_label) { |
| 579 | - $column_array[ $column ] = $column_label; |
|
| 579 | + $column_array[$column] = $column_label; |
|
| 580 | 580 | if ($column === 'venue') { |
| 581 | 581 | $column_array['event_category'] = esc_html__('Event Category', 'event_espresso'); |
| 582 | 582 | } |
@@ -14,567 +14,567 @@ |
||
| 14 | 14 | */ |
| 15 | 15 | class Events_Admin_List_Table extends EE_Admin_List_Table |
| 16 | 16 | { |
| 17 | - /** |
|
| 18 | - * @var EE_Datetime |
|
| 19 | - */ |
|
| 20 | - private $_dtt; |
|
| 21 | - |
|
| 22 | - |
|
| 23 | - /** |
|
| 24 | - * Initial setup of data properties for the list table. |
|
| 25 | - */ |
|
| 26 | - protected function _setup_data() |
|
| 27 | - { |
|
| 28 | - $this->_data = $this->_admin_page->get_events($this->_per_page, $this->_current_page); |
|
| 29 | - $this->_all_data_count = $this->_admin_page->get_events(0, 0, true); |
|
| 30 | - } |
|
| 31 | - |
|
| 32 | - |
|
| 33 | - /** |
|
| 34 | - * Set up of additional properties for the list table. |
|
| 35 | - */ |
|
| 36 | - protected function _set_properties() |
|
| 37 | - { |
|
| 38 | - $this->_wp_list_args = array( |
|
| 39 | - 'singular' => esc_html__('event', 'event_espresso'), |
|
| 40 | - 'plural' => esc_html__('events', 'event_espresso'), |
|
| 41 | - 'ajax' => true, // for now |
|
| 42 | - 'screen' => $this->_admin_page->get_current_screen()->id, |
|
| 43 | - ); |
|
| 44 | - $this->_columns = array( |
|
| 45 | - 'cb' => '<input type="checkbox" />', |
|
| 46 | - 'id' => esc_html__('ID', 'event_espresso'), |
|
| 47 | - 'name' => esc_html__('Name', 'event_espresso'), |
|
| 48 | - 'author' => esc_html__('Author', 'event_espresso'), |
|
| 49 | - 'venue' => esc_html__('Venue', 'event_espresso'), |
|
| 50 | - 'start_date_time' => esc_html__('Event Start', 'event_espresso'), |
|
| 51 | - 'reg_begins' => esc_html__('On Sale', 'event_espresso'), |
|
| 52 | - 'attendees' => '<span class="dashicons dashicons-groups ee-icon-color-ee-green ee-icon-size-20">' |
|
| 53 | - . '<span class="screen-reader-text">' |
|
| 54 | - . esc_html__('Approved Registrations', 'event_espresso') |
|
| 55 | - . '</span>' |
|
| 56 | - . '</span>', |
|
| 57 | - // 'tkts_sold' => esc_html__('Tickets Sold', 'event_espresso'), |
|
| 58 | - 'actions' => esc_html__('Actions', 'event_espresso'), |
|
| 59 | - ); |
|
| 60 | - $this->addConditionalColumns(); |
|
| 61 | - $this->_sortable_columns = array( |
|
| 62 | - 'id' => array('EVT_ID' => true), |
|
| 63 | - 'name' => array('EVT_name' => false), |
|
| 64 | - 'author' => array('EVT_wp_user' => false), |
|
| 65 | - 'venue' => array('Venue.VNU_name' => false), |
|
| 66 | - 'start_date_time' => array('Datetime.DTT_EVT_start' => false), |
|
| 67 | - 'reg_begins' => array('Datetime.Ticket.TKT_start_date' => false), |
|
| 68 | - ); |
|
| 69 | - |
|
| 70 | - $this->_primary_column = 'id'; |
|
| 71 | - $this->_hidden_columns = array('author', 'event_category'); |
|
| 72 | - } |
|
| 73 | - |
|
| 74 | - |
|
| 75 | - /** |
|
| 76 | - * @return array |
|
| 77 | - */ |
|
| 78 | - protected function _get_table_filters() |
|
| 79 | - { |
|
| 80 | - return array(); // no filters with decaf |
|
| 81 | - } |
|
| 82 | - |
|
| 83 | - |
|
| 84 | - /** |
|
| 85 | - * Setup of views properties. |
|
| 86 | - * |
|
| 87 | - * @throws InvalidDataTypeException |
|
| 88 | - * @throws InvalidInterfaceException |
|
| 89 | - * @throws InvalidArgumentException |
|
| 90 | - */ |
|
| 91 | - protected function _add_view_counts() |
|
| 92 | - { |
|
| 93 | - $this->_views['all']['count'] = $this->_admin_page->total_events(); |
|
| 94 | - $this->_views['draft']['count'] = $this->_admin_page->total_events_draft(); |
|
| 95 | - if ( |
|
| 96 | - EE_Registry::instance()->CAP->current_user_can( |
|
| 97 | - 'ee_delete_events', |
|
| 98 | - 'espresso_events_trash_events' |
|
| 99 | - ) |
|
| 100 | - ) { |
|
| 101 | - $this->_views['trash']['count'] = $this->_admin_page->total_trashed_events(); |
|
| 102 | - } |
|
| 103 | - } |
|
| 104 | - |
|
| 105 | - |
|
| 106 | - /** |
|
| 107 | - * @param EE_Event $item |
|
| 108 | - * @return string |
|
| 109 | - * @throws EE_Error |
|
| 110 | - */ |
|
| 111 | - protected function _get_row_class($item) |
|
| 112 | - { |
|
| 113 | - $class = parent::_get_row_class($item); |
|
| 114 | - // add status class |
|
| 115 | - $class .= $item instanceof EE_Event |
|
| 116 | - ? ' ee-status-strip event-status-' . $item->get_active_status() |
|
| 117 | - : ''; |
|
| 118 | - if ($this->_has_checkbox_column) { |
|
| 119 | - $class .= ' has-checkbox-column'; |
|
| 120 | - } |
|
| 121 | - return $class; |
|
| 122 | - } |
|
| 123 | - |
|
| 124 | - |
|
| 125 | - /** |
|
| 126 | - * @param EE_Event $item |
|
| 127 | - * @return string |
|
| 128 | - * @throws EE_Error |
|
| 129 | - */ |
|
| 130 | - public function column_status(EE_Event $item) |
|
| 131 | - { |
|
| 132 | - return '<span class="ee-status-strip ee-status-strip-td event-status-' |
|
| 133 | - . $item->get_active_status() |
|
| 134 | - . '"></span>'; |
|
| 135 | - } |
|
| 136 | - |
|
| 137 | - |
|
| 138 | - /** |
|
| 139 | - * @param EE_Event $item |
|
| 140 | - * @return string |
|
| 141 | - * @throws EE_Error |
|
| 142 | - */ |
|
| 143 | - public function column_cb($item) |
|
| 144 | - { |
|
| 145 | - if (! $item instanceof EE_Event) { |
|
| 146 | - return ''; |
|
| 147 | - } |
|
| 148 | - $this->_dtt = $item->primary_datetime(); // set this for use in other columns |
|
| 149 | - return sprintf( |
|
| 150 | - '<input type="checkbox" name="EVT_IDs[]" value="%s" />', |
|
| 151 | - $item->ID() |
|
| 152 | - ); |
|
| 153 | - } |
|
| 154 | - |
|
| 155 | - |
|
| 156 | - /** |
|
| 157 | - * @param EE_Event $item |
|
| 158 | - * @return mixed|string |
|
| 159 | - * @throws EE_Error |
|
| 160 | - */ |
|
| 161 | - public function column_id(EE_Event $item) |
|
| 162 | - { |
|
| 163 | - $content = $item->ID(); |
|
| 164 | - $content .= ' <span class="show-on-mobile-view-only">' . $item->name() . '</span>'; |
|
| 165 | - return $content; |
|
| 166 | - } |
|
| 167 | - |
|
| 168 | - |
|
| 169 | - /** |
|
| 170 | - * @param EE_Event $item |
|
| 171 | - * @return string |
|
| 172 | - * @throws EE_Error |
|
| 173 | - * @throws InvalidArgumentException |
|
| 174 | - * @throws InvalidDataTypeException |
|
| 175 | - * @throws InvalidInterfaceException |
|
| 176 | - */ |
|
| 177 | - public function column_name(EE_Event $item) |
|
| 178 | - { |
|
| 179 | - $edit_query_args = array( |
|
| 180 | - 'action' => 'edit', |
|
| 181 | - 'post' => $item->ID(), |
|
| 182 | - ); |
|
| 183 | - $edit_link = EE_Admin_Page::add_query_args_and_nonce($edit_query_args, EVENTS_ADMIN_URL); |
|
| 184 | - $actions = $this->_column_name_action_setup($item); |
|
| 185 | - $status = ''; // $item->status() !== 'publish' ? ' (' . $item->status() . ')' : ''; |
|
| 186 | - $content = '<strong><a class="row-title" href="' |
|
| 187 | - . $edit_link . '">' |
|
| 188 | - . $item->name() |
|
| 189 | - . '</a></strong>' |
|
| 190 | - . $status; |
|
| 191 | - $content .= '<br><span class="ee-status-text-small">' |
|
| 192 | - . EEH_Template::pretty_status( |
|
| 193 | - $item->get_active_status(), |
|
| 194 | - false, |
|
| 195 | - 'sentence' |
|
| 196 | - ) |
|
| 197 | - . '</span>'; |
|
| 198 | - $content .= $this->row_actions($actions); |
|
| 199 | - return $content; |
|
| 200 | - } |
|
| 201 | - |
|
| 202 | - |
|
| 203 | - /** |
|
| 204 | - * Just a method for setting up the actions for the name column |
|
| 205 | - * |
|
| 206 | - * @param EE_Event $item |
|
| 207 | - * @return array array of actions |
|
| 208 | - * @throws EE_Error |
|
| 209 | - * @throws InvalidArgumentException |
|
| 210 | - * @throws InvalidDataTypeException |
|
| 211 | - * @throws InvalidInterfaceException |
|
| 212 | - */ |
|
| 213 | - protected function _column_name_action_setup(EE_Event $item) |
|
| 214 | - { |
|
| 215 | - // todo: remove when attendees is active |
|
| 216 | - if (! defined('REG_ADMIN_URL')) { |
|
| 217 | - define('REG_ADMIN_URL', EVENTS_ADMIN_URL); |
|
| 218 | - } |
|
| 219 | - $actions = array(); |
|
| 220 | - $restore_event_link = ''; |
|
| 221 | - $delete_event_link = ''; |
|
| 222 | - $trash_event_link = ''; |
|
| 223 | - if ( |
|
| 224 | - EE_Registry::instance()->CAP->current_user_can( |
|
| 225 | - 'ee_edit_event', |
|
| 226 | - 'espresso_events_edit', |
|
| 227 | - $item->ID() |
|
| 228 | - ) |
|
| 229 | - ) { |
|
| 230 | - $edit_query_args = array( |
|
| 231 | - 'action' => 'edit', |
|
| 232 | - 'post' => $item->ID(), |
|
| 233 | - ); |
|
| 234 | - $edit_link = EE_Admin_Page::add_query_args_and_nonce($edit_query_args, EVENTS_ADMIN_URL); |
|
| 235 | - $actions['edit'] = '<a href="' . $edit_link . '"' |
|
| 236 | - . ' title="' . esc_attr__('Edit Event', 'event_espresso') . '">' |
|
| 237 | - . esc_html__('Edit', 'event_espresso') |
|
| 238 | - . '</a>'; |
|
| 239 | - } |
|
| 240 | - if ( |
|
| 241 | - EE_Registry::instance()->CAP->current_user_can( |
|
| 242 | - 'ee_read_registrations', |
|
| 243 | - 'espresso_registrations_view_registration' |
|
| 244 | - ) |
|
| 245 | - && EE_Registry::instance()->CAP->current_user_can( |
|
| 246 | - 'ee_read_event', |
|
| 247 | - 'espresso_registrations_view_registration', |
|
| 248 | - $item->ID() |
|
| 249 | - ) |
|
| 250 | - ) { |
|
| 251 | - $attendees_query_args = array( |
|
| 252 | - 'action' => 'default', |
|
| 253 | - 'event_id' => $item->ID(), |
|
| 254 | - ); |
|
| 255 | - $attendees_link = EE_Admin_Page::add_query_args_and_nonce($attendees_query_args, REG_ADMIN_URL); |
|
| 256 | - $actions['attendees'] = '<a href="' . $attendees_link . '"' |
|
| 257 | - . ' title="' . esc_attr__('View Registrations', 'event_espresso') . '">' |
|
| 258 | - . esc_html__('Registrations', 'event_espresso') |
|
| 259 | - . '</a>'; |
|
| 260 | - } |
|
| 261 | - if ( |
|
| 262 | - EE_Registry::instance()->CAP->current_user_can( |
|
| 263 | - 'ee_delete_event', |
|
| 264 | - 'espresso_events_trash_event', |
|
| 265 | - $item->ID() |
|
| 266 | - ) |
|
| 267 | - ) { |
|
| 268 | - $trash_event_query_args = array( |
|
| 269 | - 'action' => 'trash_event', |
|
| 270 | - 'EVT_ID' => $item->ID(), |
|
| 271 | - ); |
|
| 272 | - $trash_event_link = EE_Admin_Page::add_query_args_and_nonce( |
|
| 273 | - $trash_event_query_args, |
|
| 274 | - EVENTS_ADMIN_URL |
|
| 275 | - ); |
|
| 276 | - } |
|
| 277 | - if ( |
|
| 278 | - EE_Registry::instance()->CAP->current_user_can( |
|
| 279 | - 'ee_delete_event', |
|
| 280 | - 'espresso_events_restore_event', |
|
| 281 | - $item->ID() |
|
| 282 | - ) |
|
| 283 | - ) { |
|
| 284 | - $restore_event_query_args = array( |
|
| 285 | - 'action' => 'restore_event', |
|
| 286 | - 'EVT_ID' => $item->ID(), |
|
| 287 | - ); |
|
| 288 | - $restore_event_link = EE_Admin_Page::add_query_args_and_nonce( |
|
| 289 | - $restore_event_query_args, |
|
| 290 | - EVENTS_ADMIN_URL |
|
| 291 | - ); |
|
| 292 | - } |
|
| 293 | - if ( |
|
| 294 | - EE_Registry::instance()->CAP->current_user_can( |
|
| 295 | - 'ee_delete_event', |
|
| 296 | - 'espresso_events_delete_event', |
|
| 297 | - $item->ID() |
|
| 298 | - ) |
|
| 299 | - ) { |
|
| 300 | - $delete_event_query_args = array( |
|
| 301 | - 'action' => 'delete_event', |
|
| 302 | - 'EVT_ID' => $item->ID(), |
|
| 303 | - ); |
|
| 304 | - $delete_event_link = EE_Admin_Page::add_query_args_and_nonce( |
|
| 305 | - $delete_event_query_args, |
|
| 306 | - EVENTS_ADMIN_URL |
|
| 307 | - ); |
|
| 308 | - } |
|
| 309 | - $view_link = get_permalink($item->ID()); |
|
| 310 | - $actions['view'] = '<a href="' . $view_link . '"' |
|
| 311 | - . ' title="' . esc_attr__('View Event', 'event_espresso') . '">' |
|
| 312 | - . esc_html__('View', 'event_espresso') |
|
| 313 | - . '</a>'; |
|
| 314 | - if ($item->get('status') === 'trash') { |
|
| 315 | - if ( |
|
| 316 | - EE_Registry::instance()->CAP->current_user_can( |
|
| 317 | - 'ee_delete_event', |
|
| 318 | - 'espresso_events_restore_event', |
|
| 319 | - $item->ID() |
|
| 320 | - ) |
|
| 321 | - ) { |
|
| 322 | - $actions['restore_from_trash'] = '<a href="' . $restore_event_link . '"' |
|
| 323 | - . ' title="' . esc_attr__('Restore from Trash', 'event_espresso') |
|
| 324 | - . '">' |
|
| 325 | - . esc_html__('Restore from Trash', 'event_espresso') |
|
| 326 | - . '</a>'; |
|
| 327 | - } |
|
| 328 | - if ( |
|
| 329 | - EE_Registry::instance()->CAP->current_user_can( |
|
| 330 | - 'ee_delete_event', |
|
| 331 | - 'espresso_events_delete_event', |
|
| 332 | - $item->ID() |
|
| 333 | - ) |
|
| 334 | - ) { |
|
| 335 | - $actions['delete'] = '<a href="' . $delete_event_link . '"' |
|
| 336 | - . ' title="' . esc_attr__('Delete Permanently', 'event_espresso') . '">' |
|
| 337 | - . esc_html__('Delete Permanently', 'event_espresso') |
|
| 338 | - . '</a>'; |
|
| 339 | - } |
|
| 340 | - } else { |
|
| 341 | - if ( |
|
| 342 | - EE_Registry::instance()->CAP->current_user_can( |
|
| 343 | - 'ee_delete_event', |
|
| 344 | - 'espresso_events_trash_event', |
|
| 345 | - $item->ID() |
|
| 346 | - ) |
|
| 347 | - ) { |
|
| 348 | - $actions['move to trash'] = '<a href="' . $trash_event_link . '"' |
|
| 349 | - . ' title="' . esc_attr__('Trash Event', 'event_espresso') . '">' |
|
| 350 | - . esc_html__('Trash', 'event_espresso') |
|
| 351 | - . '</a>'; |
|
| 352 | - } |
|
| 353 | - } |
|
| 354 | - return $actions; |
|
| 355 | - } |
|
| 356 | - |
|
| 357 | - |
|
| 358 | - /** |
|
| 359 | - * @param EE_Event $item |
|
| 360 | - * @return string |
|
| 361 | - * @throws EE_Error |
|
| 362 | - */ |
|
| 363 | - public function column_author(EE_Event $item) |
|
| 364 | - { |
|
| 365 | - // user author info |
|
| 366 | - $event_author = get_userdata($item->wp_user()); |
|
| 367 | - $gravatar = get_avatar($item->wp_user(), '15'); |
|
| 368 | - // filter link |
|
| 369 | - $query_args = array( |
|
| 370 | - 'action' => 'default', |
|
| 371 | - 'EVT_wp_user' => $item->wp_user(), |
|
| 372 | - ); |
|
| 373 | - $filter_url = EE_Admin_Page::add_query_args_and_nonce($query_args, EVENTS_ADMIN_URL); |
|
| 374 | - return $gravatar . ' <a href="' . $filter_url . '"' |
|
| 375 | - . ' title="' . esc_attr__('Click to filter events by this author.', 'event_espresso') . '">' |
|
| 376 | - . $event_author->display_name |
|
| 377 | - . '</a>'; |
|
| 378 | - } |
|
| 379 | - |
|
| 380 | - |
|
| 381 | - /** |
|
| 382 | - * @param EE_Event $event |
|
| 383 | - * @return string |
|
| 384 | - * @throws EE_Error |
|
| 385 | - */ |
|
| 386 | - public function column_event_category(EE_Event $event) |
|
| 387 | - { |
|
| 388 | - $event_categories = $event->get_all_event_categories(); |
|
| 389 | - return implode( |
|
| 390 | - ', ', |
|
| 391 | - array_map( |
|
| 392 | - function (EE_Term $category) { |
|
| 393 | - return $category->name(); |
|
| 394 | - }, |
|
| 395 | - $event_categories |
|
| 396 | - ) |
|
| 397 | - ); |
|
| 398 | - } |
|
| 399 | - |
|
| 400 | - |
|
| 401 | - /** |
|
| 402 | - * @param EE_Event $item |
|
| 403 | - * @return string |
|
| 404 | - * @throws EE_Error |
|
| 405 | - */ |
|
| 406 | - public function column_venue(EE_Event $item) |
|
| 407 | - { |
|
| 408 | - $venue = $item->get_first_related('Venue'); |
|
| 409 | - return ! empty($venue) |
|
| 410 | - ? $venue->name() |
|
| 411 | - : ''; |
|
| 412 | - } |
|
| 413 | - |
|
| 414 | - |
|
| 415 | - /** |
|
| 416 | - * @param EE_Event $item |
|
| 417 | - * @return string |
|
| 418 | - * @throws EE_Error |
|
| 419 | - */ |
|
| 420 | - public function column_start_date_time(EE_Event $item) |
|
| 421 | - { |
|
| 422 | - return $this->_dtt instanceof EE_Datetime |
|
| 423 | - ? $this->_dtt->get_i18n_datetime('DTT_EVT_start') |
|
| 424 | - : esc_html__('No Date was saved for this Event', 'event_espresso'); |
|
| 425 | - } |
|
| 426 | - |
|
| 427 | - |
|
| 428 | - /** |
|
| 429 | - * @param EE_Event $item |
|
| 430 | - * @return string |
|
| 431 | - * @throws EE_Error |
|
| 432 | - */ |
|
| 433 | - public function column_reg_begins(EE_Event $item) |
|
| 434 | - { |
|
| 435 | - $reg_start = $item->get_ticket_with_earliest_start_time(); |
|
| 436 | - return $reg_start instanceof EE_Ticket |
|
| 437 | - ? $reg_start->get_i18n_datetime('TKT_start_date') |
|
| 438 | - : esc_html__('No Tickets have been setup for this Event', 'event_espresso'); |
|
| 439 | - } |
|
| 440 | - |
|
| 441 | - |
|
| 442 | - /** |
|
| 443 | - * @param EE_Event $item |
|
| 444 | - * @return int|string |
|
| 445 | - * @throws EE_Error |
|
| 446 | - * @throws InvalidArgumentException |
|
| 447 | - * @throws InvalidDataTypeException |
|
| 448 | - * @throws InvalidInterfaceException |
|
| 449 | - */ |
|
| 450 | - public function column_attendees(EE_Event $item) |
|
| 451 | - { |
|
| 452 | - $attendees_query_args = array( |
|
| 453 | - 'action' => 'default', |
|
| 454 | - 'event_id' => $item->ID(), |
|
| 455 | - ); |
|
| 456 | - $attendees_link = EE_Admin_Page::add_query_args_and_nonce($attendees_query_args, REG_ADMIN_URL); |
|
| 457 | - $registered_attendees = EEM_Registration::instance()->get_event_registration_count($item->ID()); |
|
| 458 | - return EE_Registry::instance()->CAP->current_user_can( |
|
| 459 | - 'ee_read_event', |
|
| 460 | - 'espresso_registrations_view_registration', |
|
| 461 | - $item->ID() |
|
| 462 | - ) |
|
| 463 | - && EE_Registry::instance()->CAP->current_user_can( |
|
| 464 | - 'ee_read_registrations', |
|
| 465 | - 'espresso_registrations_view_registration' |
|
| 466 | - ) |
|
| 467 | - ? '<a href="' . $attendees_link . '">' . $registered_attendees . '</a>' |
|
| 468 | - : $registered_attendees; |
|
| 469 | - } |
|
| 470 | - |
|
| 471 | - |
|
| 472 | - /** |
|
| 473 | - * @param EE_Event $item |
|
| 474 | - * @return float |
|
| 475 | - * @throws EE_Error |
|
| 476 | - * @throws InvalidArgumentException |
|
| 477 | - * @throws InvalidDataTypeException |
|
| 478 | - * @throws InvalidInterfaceException |
|
| 479 | - */ |
|
| 480 | - public function column_tkts_sold(EE_Event $item) |
|
| 481 | - { |
|
| 482 | - return EEM_Ticket::instance()->sum(array(array('Datetime.EVT_ID' => $item->ID())), 'TKT_sold'); |
|
| 483 | - } |
|
| 484 | - |
|
| 485 | - |
|
| 486 | - /** |
|
| 487 | - * @param EE_Event $item |
|
| 488 | - * @return string |
|
| 489 | - * @throws EE_Error |
|
| 490 | - * @throws InvalidArgumentException |
|
| 491 | - * @throws InvalidDataTypeException |
|
| 492 | - * @throws InvalidInterfaceException |
|
| 493 | - */ |
|
| 494 | - public function column_actions(EE_Event $item) |
|
| 495 | - { |
|
| 496 | - // todo: remove when attendees is active |
|
| 497 | - if (! defined('REG_ADMIN_URL')) { |
|
| 498 | - define('REG_ADMIN_URL', EVENTS_ADMIN_URL); |
|
| 499 | - } |
|
| 500 | - $action_links = array(); |
|
| 501 | - $view_link = get_permalink($item->ID()); |
|
| 502 | - $action_links[] = '<a href="' . $view_link . '"' |
|
| 503 | - . ' title="' . esc_attr__('View Event', 'event_espresso') . '" target="_blank">'; |
|
| 504 | - $action_links[] = '<div class="dashicons dashicons-search"></div></a>'; |
|
| 505 | - if ( |
|
| 506 | - EE_Registry::instance()->CAP->current_user_can( |
|
| 507 | - 'ee_edit_event', |
|
| 508 | - 'espresso_events_edit', |
|
| 509 | - $item->ID() |
|
| 510 | - ) |
|
| 511 | - ) { |
|
| 512 | - $edit_query_args = array( |
|
| 513 | - 'action' => 'edit', |
|
| 514 | - 'post' => $item->ID(), |
|
| 515 | - ); |
|
| 516 | - $edit_link = EE_Admin_Page::add_query_args_and_nonce($edit_query_args, EVENTS_ADMIN_URL); |
|
| 517 | - $action_links[] = '<a href="' . $edit_link . '"' |
|
| 518 | - . ' title="' . esc_attr__('Edit Event', 'event_espresso') . '">' |
|
| 519 | - . '<div class="ee-icon ee-icon-calendar-edit"></div>' |
|
| 520 | - . '</a>'; |
|
| 521 | - } |
|
| 522 | - if ( |
|
| 523 | - EE_Registry::instance()->CAP->current_user_can( |
|
| 524 | - 'ee_read_registrations', |
|
| 525 | - 'espresso_registrations_view_registration' |
|
| 526 | - ) && EE_Registry::instance()->CAP->current_user_can( |
|
| 527 | - 'ee_read_event', |
|
| 528 | - 'espresso_registrations_view_registration', |
|
| 529 | - $item->ID() |
|
| 530 | - ) |
|
| 531 | - ) { |
|
| 532 | - $attendees_query_args = array( |
|
| 533 | - 'action' => 'default', |
|
| 534 | - 'event_id' => $item->ID(), |
|
| 535 | - ); |
|
| 536 | - $attendees_link = EE_Admin_Page::add_query_args_and_nonce($attendees_query_args, REG_ADMIN_URL); |
|
| 537 | - $action_links[] = '<a href="' . $attendees_link . '"' |
|
| 538 | - . ' title="' . esc_attr__('View Registrants', 'event_espresso') . '">' |
|
| 539 | - . '<div class="dashicons dashicons-groups"></div>' |
|
| 540 | - . '</a>'; |
|
| 541 | - } |
|
| 542 | - $action_links = apply_filters( |
|
| 543 | - 'FHEE__Events_Admin_List_Table__column_actions__action_links', |
|
| 544 | - $action_links, |
|
| 545 | - $item |
|
| 546 | - ); |
|
| 547 | - return $this->_action_string( |
|
| 548 | - implode("\n\t", $action_links), |
|
| 549 | - $item, |
|
| 550 | - 'div' |
|
| 551 | - ); |
|
| 552 | - } |
|
| 553 | - |
|
| 554 | - |
|
| 555 | - /** |
|
| 556 | - * Helper for adding columns conditionally |
|
| 557 | - * |
|
| 558 | - * @throws EE_Error |
|
| 559 | - * @throws InvalidArgumentException |
|
| 560 | - * @throws InvalidDataTypeException |
|
| 561 | - * @throws InvalidInterfaceException |
|
| 562 | - */ |
|
| 563 | - private function addConditionalColumns() |
|
| 564 | - { |
|
| 565 | - $event_category_count = EEM_Term::instance()->count( |
|
| 566 | - [['Term_Taxonomy.taxonomy' => EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY]] |
|
| 567 | - ); |
|
| 568 | - if ($event_category_count === 0) { |
|
| 569 | - return; |
|
| 570 | - } |
|
| 571 | - $column_array = []; |
|
| 572 | - foreach ($this->_columns as $column => $column_label) { |
|
| 573 | - $column_array[ $column ] = $column_label; |
|
| 574 | - if ($column === 'venue') { |
|
| 575 | - $column_array['event_category'] = esc_html__('Event Category', 'event_espresso'); |
|
| 576 | - } |
|
| 577 | - } |
|
| 578 | - $this->_columns = $column_array; |
|
| 579 | - } |
|
| 17 | + /** |
|
| 18 | + * @var EE_Datetime |
|
| 19 | + */ |
|
| 20 | + private $_dtt; |
|
| 21 | + |
|
| 22 | + |
|
| 23 | + /** |
|
| 24 | + * Initial setup of data properties for the list table. |
|
| 25 | + */ |
|
| 26 | + protected function _setup_data() |
|
| 27 | + { |
|
| 28 | + $this->_data = $this->_admin_page->get_events($this->_per_page, $this->_current_page); |
|
| 29 | + $this->_all_data_count = $this->_admin_page->get_events(0, 0, true); |
|
| 30 | + } |
|
| 31 | + |
|
| 32 | + |
|
| 33 | + /** |
|
| 34 | + * Set up of additional properties for the list table. |
|
| 35 | + */ |
|
| 36 | + protected function _set_properties() |
|
| 37 | + { |
|
| 38 | + $this->_wp_list_args = array( |
|
| 39 | + 'singular' => esc_html__('event', 'event_espresso'), |
|
| 40 | + 'plural' => esc_html__('events', 'event_espresso'), |
|
| 41 | + 'ajax' => true, // for now |
|
| 42 | + 'screen' => $this->_admin_page->get_current_screen()->id, |
|
| 43 | + ); |
|
| 44 | + $this->_columns = array( |
|
| 45 | + 'cb' => '<input type="checkbox" />', |
|
| 46 | + 'id' => esc_html__('ID', 'event_espresso'), |
|
| 47 | + 'name' => esc_html__('Name', 'event_espresso'), |
|
| 48 | + 'author' => esc_html__('Author', 'event_espresso'), |
|
| 49 | + 'venue' => esc_html__('Venue', 'event_espresso'), |
|
| 50 | + 'start_date_time' => esc_html__('Event Start', 'event_espresso'), |
|
| 51 | + 'reg_begins' => esc_html__('On Sale', 'event_espresso'), |
|
| 52 | + 'attendees' => '<span class="dashicons dashicons-groups ee-icon-color-ee-green ee-icon-size-20">' |
|
| 53 | + . '<span class="screen-reader-text">' |
|
| 54 | + . esc_html__('Approved Registrations', 'event_espresso') |
|
| 55 | + . '</span>' |
|
| 56 | + . '</span>', |
|
| 57 | + // 'tkts_sold' => esc_html__('Tickets Sold', 'event_espresso'), |
|
| 58 | + 'actions' => esc_html__('Actions', 'event_espresso'), |
|
| 59 | + ); |
|
| 60 | + $this->addConditionalColumns(); |
|
| 61 | + $this->_sortable_columns = array( |
|
| 62 | + 'id' => array('EVT_ID' => true), |
|
| 63 | + 'name' => array('EVT_name' => false), |
|
| 64 | + 'author' => array('EVT_wp_user' => false), |
|
| 65 | + 'venue' => array('Venue.VNU_name' => false), |
|
| 66 | + 'start_date_time' => array('Datetime.DTT_EVT_start' => false), |
|
| 67 | + 'reg_begins' => array('Datetime.Ticket.TKT_start_date' => false), |
|
| 68 | + ); |
|
| 69 | + |
|
| 70 | + $this->_primary_column = 'id'; |
|
| 71 | + $this->_hidden_columns = array('author', 'event_category'); |
|
| 72 | + } |
|
| 73 | + |
|
| 74 | + |
|
| 75 | + /** |
|
| 76 | + * @return array |
|
| 77 | + */ |
|
| 78 | + protected function _get_table_filters() |
|
| 79 | + { |
|
| 80 | + return array(); // no filters with decaf |
|
| 81 | + } |
|
| 82 | + |
|
| 83 | + |
|
| 84 | + /** |
|
| 85 | + * Setup of views properties. |
|
| 86 | + * |
|
| 87 | + * @throws InvalidDataTypeException |
|
| 88 | + * @throws InvalidInterfaceException |
|
| 89 | + * @throws InvalidArgumentException |
|
| 90 | + */ |
|
| 91 | + protected function _add_view_counts() |
|
| 92 | + { |
|
| 93 | + $this->_views['all']['count'] = $this->_admin_page->total_events(); |
|
| 94 | + $this->_views['draft']['count'] = $this->_admin_page->total_events_draft(); |
|
| 95 | + if ( |
|
| 96 | + EE_Registry::instance()->CAP->current_user_can( |
|
| 97 | + 'ee_delete_events', |
|
| 98 | + 'espresso_events_trash_events' |
|
| 99 | + ) |
|
| 100 | + ) { |
|
| 101 | + $this->_views['trash']['count'] = $this->_admin_page->total_trashed_events(); |
|
| 102 | + } |
|
| 103 | + } |
|
| 104 | + |
|
| 105 | + |
|
| 106 | + /** |
|
| 107 | + * @param EE_Event $item |
|
| 108 | + * @return string |
|
| 109 | + * @throws EE_Error |
|
| 110 | + */ |
|
| 111 | + protected function _get_row_class($item) |
|
| 112 | + { |
|
| 113 | + $class = parent::_get_row_class($item); |
|
| 114 | + // add status class |
|
| 115 | + $class .= $item instanceof EE_Event |
|
| 116 | + ? ' ee-status-strip event-status-' . $item->get_active_status() |
|
| 117 | + : ''; |
|
| 118 | + if ($this->_has_checkbox_column) { |
|
| 119 | + $class .= ' has-checkbox-column'; |
|
| 120 | + } |
|
| 121 | + return $class; |
|
| 122 | + } |
|
| 123 | + |
|
| 124 | + |
|
| 125 | + /** |
|
| 126 | + * @param EE_Event $item |
|
| 127 | + * @return string |
|
| 128 | + * @throws EE_Error |
|
| 129 | + */ |
|
| 130 | + public function column_status(EE_Event $item) |
|
| 131 | + { |
|
| 132 | + return '<span class="ee-status-strip ee-status-strip-td event-status-' |
|
| 133 | + . $item->get_active_status() |
|
| 134 | + . '"></span>'; |
|
| 135 | + } |
|
| 136 | + |
|
| 137 | + |
|
| 138 | + /** |
|
| 139 | + * @param EE_Event $item |
|
| 140 | + * @return string |
|
| 141 | + * @throws EE_Error |
|
| 142 | + */ |
|
| 143 | + public function column_cb($item) |
|
| 144 | + { |
|
| 145 | + if (! $item instanceof EE_Event) { |
|
| 146 | + return ''; |
|
| 147 | + } |
|
| 148 | + $this->_dtt = $item->primary_datetime(); // set this for use in other columns |
|
| 149 | + return sprintf( |
|
| 150 | + '<input type="checkbox" name="EVT_IDs[]" value="%s" />', |
|
| 151 | + $item->ID() |
|
| 152 | + ); |
|
| 153 | + } |
|
| 154 | + |
|
| 155 | + |
|
| 156 | + /** |
|
| 157 | + * @param EE_Event $item |
|
| 158 | + * @return mixed|string |
|
| 159 | + * @throws EE_Error |
|
| 160 | + */ |
|
| 161 | + public function column_id(EE_Event $item) |
|
| 162 | + { |
|
| 163 | + $content = $item->ID(); |
|
| 164 | + $content .= ' <span class="show-on-mobile-view-only">' . $item->name() . '</span>'; |
|
| 165 | + return $content; |
|
| 166 | + } |
|
| 167 | + |
|
| 168 | + |
|
| 169 | + /** |
|
| 170 | + * @param EE_Event $item |
|
| 171 | + * @return string |
|
| 172 | + * @throws EE_Error |
|
| 173 | + * @throws InvalidArgumentException |
|
| 174 | + * @throws InvalidDataTypeException |
|
| 175 | + * @throws InvalidInterfaceException |
|
| 176 | + */ |
|
| 177 | + public function column_name(EE_Event $item) |
|
| 178 | + { |
|
| 179 | + $edit_query_args = array( |
|
| 180 | + 'action' => 'edit', |
|
| 181 | + 'post' => $item->ID(), |
|
| 182 | + ); |
|
| 183 | + $edit_link = EE_Admin_Page::add_query_args_and_nonce($edit_query_args, EVENTS_ADMIN_URL); |
|
| 184 | + $actions = $this->_column_name_action_setup($item); |
|
| 185 | + $status = ''; // $item->status() !== 'publish' ? ' (' . $item->status() . ')' : ''; |
|
| 186 | + $content = '<strong><a class="row-title" href="' |
|
| 187 | + . $edit_link . '">' |
|
| 188 | + . $item->name() |
|
| 189 | + . '</a></strong>' |
|
| 190 | + . $status; |
|
| 191 | + $content .= '<br><span class="ee-status-text-small">' |
|
| 192 | + . EEH_Template::pretty_status( |
|
| 193 | + $item->get_active_status(), |
|
| 194 | + false, |
|
| 195 | + 'sentence' |
|
| 196 | + ) |
|
| 197 | + . '</span>'; |
|
| 198 | + $content .= $this->row_actions($actions); |
|
| 199 | + return $content; |
|
| 200 | + } |
|
| 201 | + |
|
| 202 | + |
|
| 203 | + /** |
|
| 204 | + * Just a method for setting up the actions for the name column |
|
| 205 | + * |
|
| 206 | + * @param EE_Event $item |
|
| 207 | + * @return array array of actions |
|
| 208 | + * @throws EE_Error |
|
| 209 | + * @throws InvalidArgumentException |
|
| 210 | + * @throws InvalidDataTypeException |
|
| 211 | + * @throws InvalidInterfaceException |
|
| 212 | + */ |
|
| 213 | + protected function _column_name_action_setup(EE_Event $item) |
|
| 214 | + { |
|
| 215 | + // todo: remove when attendees is active |
|
| 216 | + if (! defined('REG_ADMIN_URL')) { |
|
| 217 | + define('REG_ADMIN_URL', EVENTS_ADMIN_URL); |
|
| 218 | + } |
|
| 219 | + $actions = array(); |
|
| 220 | + $restore_event_link = ''; |
|
| 221 | + $delete_event_link = ''; |
|
| 222 | + $trash_event_link = ''; |
|
| 223 | + if ( |
|
| 224 | + EE_Registry::instance()->CAP->current_user_can( |
|
| 225 | + 'ee_edit_event', |
|
| 226 | + 'espresso_events_edit', |
|
| 227 | + $item->ID() |
|
| 228 | + ) |
|
| 229 | + ) { |
|
| 230 | + $edit_query_args = array( |
|
| 231 | + 'action' => 'edit', |
|
| 232 | + 'post' => $item->ID(), |
|
| 233 | + ); |
|
| 234 | + $edit_link = EE_Admin_Page::add_query_args_and_nonce($edit_query_args, EVENTS_ADMIN_URL); |
|
| 235 | + $actions['edit'] = '<a href="' . $edit_link . '"' |
|
| 236 | + . ' title="' . esc_attr__('Edit Event', 'event_espresso') . '">' |
|
| 237 | + . esc_html__('Edit', 'event_espresso') |
|
| 238 | + . '</a>'; |
|
| 239 | + } |
|
| 240 | + if ( |
|
| 241 | + EE_Registry::instance()->CAP->current_user_can( |
|
| 242 | + 'ee_read_registrations', |
|
| 243 | + 'espresso_registrations_view_registration' |
|
| 244 | + ) |
|
| 245 | + && EE_Registry::instance()->CAP->current_user_can( |
|
| 246 | + 'ee_read_event', |
|
| 247 | + 'espresso_registrations_view_registration', |
|
| 248 | + $item->ID() |
|
| 249 | + ) |
|
| 250 | + ) { |
|
| 251 | + $attendees_query_args = array( |
|
| 252 | + 'action' => 'default', |
|
| 253 | + 'event_id' => $item->ID(), |
|
| 254 | + ); |
|
| 255 | + $attendees_link = EE_Admin_Page::add_query_args_and_nonce($attendees_query_args, REG_ADMIN_URL); |
|
| 256 | + $actions['attendees'] = '<a href="' . $attendees_link . '"' |
|
| 257 | + . ' title="' . esc_attr__('View Registrations', 'event_espresso') . '">' |
|
| 258 | + . esc_html__('Registrations', 'event_espresso') |
|
| 259 | + . '</a>'; |
|
| 260 | + } |
|
| 261 | + if ( |
|
| 262 | + EE_Registry::instance()->CAP->current_user_can( |
|
| 263 | + 'ee_delete_event', |
|
| 264 | + 'espresso_events_trash_event', |
|
| 265 | + $item->ID() |
|
| 266 | + ) |
|
| 267 | + ) { |
|
| 268 | + $trash_event_query_args = array( |
|
| 269 | + 'action' => 'trash_event', |
|
| 270 | + 'EVT_ID' => $item->ID(), |
|
| 271 | + ); |
|
| 272 | + $trash_event_link = EE_Admin_Page::add_query_args_and_nonce( |
|
| 273 | + $trash_event_query_args, |
|
| 274 | + EVENTS_ADMIN_URL |
|
| 275 | + ); |
|
| 276 | + } |
|
| 277 | + if ( |
|
| 278 | + EE_Registry::instance()->CAP->current_user_can( |
|
| 279 | + 'ee_delete_event', |
|
| 280 | + 'espresso_events_restore_event', |
|
| 281 | + $item->ID() |
|
| 282 | + ) |
|
| 283 | + ) { |
|
| 284 | + $restore_event_query_args = array( |
|
| 285 | + 'action' => 'restore_event', |
|
| 286 | + 'EVT_ID' => $item->ID(), |
|
| 287 | + ); |
|
| 288 | + $restore_event_link = EE_Admin_Page::add_query_args_and_nonce( |
|
| 289 | + $restore_event_query_args, |
|
| 290 | + EVENTS_ADMIN_URL |
|
| 291 | + ); |
|
| 292 | + } |
|
| 293 | + if ( |
|
| 294 | + EE_Registry::instance()->CAP->current_user_can( |
|
| 295 | + 'ee_delete_event', |
|
| 296 | + 'espresso_events_delete_event', |
|
| 297 | + $item->ID() |
|
| 298 | + ) |
|
| 299 | + ) { |
|
| 300 | + $delete_event_query_args = array( |
|
| 301 | + 'action' => 'delete_event', |
|
| 302 | + 'EVT_ID' => $item->ID(), |
|
| 303 | + ); |
|
| 304 | + $delete_event_link = EE_Admin_Page::add_query_args_and_nonce( |
|
| 305 | + $delete_event_query_args, |
|
| 306 | + EVENTS_ADMIN_URL |
|
| 307 | + ); |
|
| 308 | + } |
|
| 309 | + $view_link = get_permalink($item->ID()); |
|
| 310 | + $actions['view'] = '<a href="' . $view_link . '"' |
|
| 311 | + . ' title="' . esc_attr__('View Event', 'event_espresso') . '">' |
|
| 312 | + . esc_html__('View', 'event_espresso') |
|
| 313 | + . '</a>'; |
|
| 314 | + if ($item->get('status') === 'trash') { |
|
| 315 | + if ( |
|
| 316 | + EE_Registry::instance()->CAP->current_user_can( |
|
| 317 | + 'ee_delete_event', |
|
| 318 | + 'espresso_events_restore_event', |
|
| 319 | + $item->ID() |
|
| 320 | + ) |
|
| 321 | + ) { |
|
| 322 | + $actions['restore_from_trash'] = '<a href="' . $restore_event_link . '"' |
|
| 323 | + . ' title="' . esc_attr__('Restore from Trash', 'event_espresso') |
|
| 324 | + . '">' |
|
| 325 | + . esc_html__('Restore from Trash', 'event_espresso') |
|
| 326 | + . '</a>'; |
|
| 327 | + } |
|
| 328 | + if ( |
|
| 329 | + EE_Registry::instance()->CAP->current_user_can( |
|
| 330 | + 'ee_delete_event', |
|
| 331 | + 'espresso_events_delete_event', |
|
| 332 | + $item->ID() |
|
| 333 | + ) |
|
| 334 | + ) { |
|
| 335 | + $actions['delete'] = '<a href="' . $delete_event_link . '"' |
|
| 336 | + . ' title="' . esc_attr__('Delete Permanently', 'event_espresso') . '">' |
|
| 337 | + . esc_html__('Delete Permanently', 'event_espresso') |
|
| 338 | + . '</a>'; |
|
| 339 | + } |
|
| 340 | + } else { |
|
| 341 | + if ( |
|
| 342 | + EE_Registry::instance()->CAP->current_user_can( |
|
| 343 | + 'ee_delete_event', |
|
| 344 | + 'espresso_events_trash_event', |
|
| 345 | + $item->ID() |
|
| 346 | + ) |
|
| 347 | + ) { |
|
| 348 | + $actions['move to trash'] = '<a href="' . $trash_event_link . '"' |
|
| 349 | + . ' title="' . esc_attr__('Trash Event', 'event_espresso') . '">' |
|
| 350 | + . esc_html__('Trash', 'event_espresso') |
|
| 351 | + . '</a>'; |
|
| 352 | + } |
|
| 353 | + } |
|
| 354 | + return $actions; |
|
| 355 | + } |
|
| 356 | + |
|
| 357 | + |
|
| 358 | + /** |
|
| 359 | + * @param EE_Event $item |
|
| 360 | + * @return string |
|
| 361 | + * @throws EE_Error |
|
| 362 | + */ |
|
| 363 | + public function column_author(EE_Event $item) |
|
| 364 | + { |
|
| 365 | + // user author info |
|
| 366 | + $event_author = get_userdata($item->wp_user()); |
|
| 367 | + $gravatar = get_avatar($item->wp_user(), '15'); |
|
| 368 | + // filter link |
|
| 369 | + $query_args = array( |
|
| 370 | + 'action' => 'default', |
|
| 371 | + 'EVT_wp_user' => $item->wp_user(), |
|
| 372 | + ); |
|
| 373 | + $filter_url = EE_Admin_Page::add_query_args_and_nonce($query_args, EVENTS_ADMIN_URL); |
|
| 374 | + return $gravatar . ' <a href="' . $filter_url . '"' |
|
| 375 | + . ' title="' . esc_attr__('Click to filter events by this author.', 'event_espresso') . '">' |
|
| 376 | + . $event_author->display_name |
|
| 377 | + . '</a>'; |
|
| 378 | + } |
|
| 379 | + |
|
| 380 | + |
|
| 381 | + /** |
|
| 382 | + * @param EE_Event $event |
|
| 383 | + * @return string |
|
| 384 | + * @throws EE_Error |
|
| 385 | + */ |
|
| 386 | + public function column_event_category(EE_Event $event) |
|
| 387 | + { |
|
| 388 | + $event_categories = $event->get_all_event_categories(); |
|
| 389 | + return implode( |
|
| 390 | + ', ', |
|
| 391 | + array_map( |
|
| 392 | + function (EE_Term $category) { |
|
| 393 | + return $category->name(); |
|
| 394 | + }, |
|
| 395 | + $event_categories |
|
| 396 | + ) |
|
| 397 | + ); |
|
| 398 | + } |
|
| 399 | + |
|
| 400 | + |
|
| 401 | + /** |
|
| 402 | + * @param EE_Event $item |
|
| 403 | + * @return string |
|
| 404 | + * @throws EE_Error |
|
| 405 | + */ |
|
| 406 | + public function column_venue(EE_Event $item) |
|
| 407 | + { |
|
| 408 | + $venue = $item->get_first_related('Venue'); |
|
| 409 | + return ! empty($venue) |
|
| 410 | + ? $venue->name() |
|
| 411 | + : ''; |
|
| 412 | + } |
|
| 413 | + |
|
| 414 | + |
|
| 415 | + /** |
|
| 416 | + * @param EE_Event $item |
|
| 417 | + * @return string |
|
| 418 | + * @throws EE_Error |
|
| 419 | + */ |
|
| 420 | + public function column_start_date_time(EE_Event $item) |
|
| 421 | + { |
|
| 422 | + return $this->_dtt instanceof EE_Datetime |
|
| 423 | + ? $this->_dtt->get_i18n_datetime('DTT_EVT_start') |
|
| 424 | + : esc_html__('No Date was saved for this Event', 'event_espresso'); |
|
| 425 | + } |
|
| 426 | + |
|
| 427 | + |
|
| 428 | + /** |
|
| 429 | + * @param EE_Event $item |
|
| 430 | + * @return string |
|
| 431 | + * @throws EE_Error |
|
| 432 | + */ |
|
| 433 | + public function column_reg_begins(EE_Event $item) |
|
| 434 | + { |
|
| 435 | + $reg_start = $item->get_ticket_with_earliest_start_time(); |
|
| 436 | + return $reg_start instanceof EE_Ticket |
|
| 437 | + ? $reg_start->get_i18n_datetime('TKT_start_date') |
|
| 438 | + : esc_html__('No Tickets have been setup for this Event', 'event_espresso'); |
|
| 439 | + } |
|
| 440 | + |
|
| 441 | + |
|
| 442 | + /** |
|
| 443 | + * @param EE_Event $item |
|
| 444 | + * @return int|string |
|
| 445 | + * @throws EE_Error |
|
| 446 | + * @throws InvalidArgumentException |
|
| 447 | + * @throws InvalidDataTypeException |
|
| 448 | + * @throws InvalidInterfaceException |
|
| 449 | + */ |
|
| 450 | + public function column_attendees(EE_Event $item) |
|
| 451 | + { |
|
| 452 | + $attendees_query_args = array( |
|
| 453 | + 'action' => 'default', |
|
| 454 | + 'event_id' => $item->ID(), |
|
| 455 | + ); |
|
| 456 | + $attendees_link = EE_Admin_Page::add_query_args_and_nonce($attendees_query_args, REG_ADMIN_URL); |
|
| 457 | + $registered_attendees = EEM_Registration::instance()->get_event_registration_count($item->ID()); |
|
| 458 | + return EE_Registry::instance()->CAP->current_user_can( |
|
| 459 | + 'ee_read_event', |
|
| 460 | + 'espresso_registrations_view_registration', |
|
| 461 | + $item->ID() |
|
| 462 | + ) |
|
| 463 | + && EE_Registry::instance()->CAP->current_user_can( |
|
| 464 | + 'ee_read_registrations', |
|
| 465 | + 'espresso_registrations_view_registration' |
|
| 466 | + ) |
|
| 467 | + ? '<a href="' . $attendees_link . '">' . $registered_attendees . '</a>' |
|
| 468 | + : $registered_attendees; |
|
| 469 | + } |
|
| 470 | + |
|
| 471 | + |
|
| 472 | + /** |
|
| 473 | + * @param EE_Event $item |
|
| 474 | + * @return float |
|
| 475 | + * @throws EE_Error |
|
| 476 | + * @throws InvalidArgumentException |
|
| 477 | + * @throws InvalidDataTypeException |
|
| 478 | + * @throws InvalidInterfaceException |
|
| 479 | + */ |
|
| 480 | + public function column_tkts_sold(EE_Event $item) |
|
| 481 | + { |
|
| 482 | + return EEM_Ticket::instance()->sum(array(array('Datetime.EVT_ID' => $item->ID())), 'TKT_sold'); |
|
| 483 | + } |
|
| 484 | + |
|
| 485 | + |
|
| 486 | + /** |
|
| 487 | + * @param EE_Event $item |
|
| 488 | + * @return string |
|
| 489 | + * @throws EE_Error |
|
| 490 | + * @throws InvalidArgumentException |
|
| 491 | + * @throws InvalidDataTypeException |
|
| 492 | + * @throws InvalidInterfaceException |
|
| 493 | + */ |
|
| 494 | + public function column_actions(EE_Event $item) |
|
| 495 | + { |
|
| 496 | + // todo: remove when attendees is active |
|
| 497 | + if (! defined('REG_ADMIN_URL')) { |
|
| 498 | + define('REG_ADMIN_URL', EVENTS_ADMIN_URL); |
|
| 499 | + } |
|
| 500 | + $action_links = array(); |
|
| 501 | + $view_link = get_permalink($item->ID()); |
|
| 502 | + $action_links[] = '<a href="' . $view_link . '"' |
|
| 503 | + . ' title="' . esc_attr__('View Event', 'event_espresso') . '" target="_blank">'; |
|
| 504 | + $action_links[] = '<div class="dashicons dashicons-search"></div></a>'; |
|
| 505 | + if ( |
|
| 506 | + EE_Registry::instance()->CAP->current_user_can( |
|
| 507 | + 'ee_edit_event', |
|
| 508 | + 'espresso_events_edit', |
|
| 509 | + $item->ID() |
|
| 510 | + ) |
|
| 511 | + ) { |
|
| 512 | + $edit_query_args = array( |
|
| 513 | + 'action' => 'edit', |
|
| 514 | + 'post' => $item->ID(), |
|
| 515 | + ); |
|
| 516 | + $edit_link = EE_Admin_Page::add_query_args_and_nonce($edit_query_args, EVENTS_ADMIN_URL); |
|
| 517 | + $action_links[] = '<a href="' . $edit_link . '"' |
|
| 518 | + . ' title="' . esc_attr__('Edit Event', 'event_espresso') . '">' |
|
| 519 | + . '<div class="ee-icon ee-icon-calendar-edit"></div>' |
|
| 520 | + . '</a>'; |
|
| 521 | + } |
|
| 522 | + if ( |
|
| 523 | + EE_Registry::instance()->CAP->current_user_can( |
|
| 524 | + 'ee_read_registrations', |
|
| 525 | + 'espresso_registrations_view_registration' |
|
| 526 | + ) && EE_Registry::instance()->CAP->current_user_can( |
|
| 527 | + 'ee_read_event', |
|
| 528 | + 'espresso_registrations_view_registration', |
|
| 529 | + $item->ID() |
|
| 530 | + ) |
|
| 531 | + ) { |
|
| 532 | + $attendees_query_args = array( |
|
| 533 | + 'action' => 'default', |
|
| 534 | + 'event_id' => $item->ID(), |
|
| 535 | + ); |
|
| 536 | + $attendees_link = EE_Admin_Page::add_query_args_and_nonce($attendees_query_args, REG_ADMIN_URL); |
|
| 537 | + $action_links[] = '<a href="' . $attendees_link . '"' |
|
| 538 | + . ' title="' . esc_attr__('View Registrants', 'event_espresso') . '">' |
|
| 539 | + . '<div class="dashicons dashicons-groups"></div>' |
|
| 540 | + . '</a>'; |
|
| 541 | + } |
|
| 542 | + $action_links = apply_filters( |
|
| 543 | + 'FHEE__Events_Admin_List_Table__column_actions__action_links', |
|
| 544 | + $action_links, |
|
| 545 | + $item |
|
| 546 | + ); |
|
| 547 | + return $this->_action_string( |
|
| 548 | + implode("\n\t", $action_links), |
|
| 549 | + $item, |
|
| 550 | + 'div' |
|
| 551 | + ); |
|
| 552 | + } |
|
| 553 | + |
|
| 554 | + |
|
| 555 | + /** |
|
| 556 | + * Helper for adding columns conditionally |
|
| 557 | + * |
|
| 558 | + * @throws EE_Error |
|
| 559 | + * @throws InvalidArgumentException |
|
| 560 | + * @throws InvalidDataTypeException |
|
| 561 | + * @throws InvalidInterfaceException |
|
| 562 | + */ |
|
| 563 | + private function addConditionalColumns() |
|
| 564 | + { |
|
| 565 | + $event_category_count = EEM_Term::instance()->count( |
|
| 566 | + [['Term_Taxonomy.taxonomy' => EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY]] |
|
| 567 | + ); |
|
| 568 | + if ($event_category_count === 0) { |
|
| 569 | + return; |
|
| 570 | + } |
|
| 571 | + $column_array = []; |
|
| 572 | + foreach ($this->_columns as $column => $column_label) { |
|
| 573 | + $column_array[ $column ] = $column_label; |
|
| 574 | + if ($column === 'venue') { |
|
| 575 | + $column_array['event_category'] = esc_html__('Event Category', 'event_espresso'); |
|
| 576 | + } |
|
| 577 | + } |
|
| 578 | + $this->_columns = $column_array; |
|
| 579 | + } |
|
| 580 | 580 | } |
@@ -12,382 +12,382 @@ |
||
| 12 | 12 | */ |
| 13 | 13 | class EE_Attendee_Contact_List_Table extends EE_Admin_List_Table |
| 14 | 14 | { |
| 15 | - /** |
|
| 16 | - * Initial setup of data (called by parent). |
|
| 17 | - */ |
|
| 18 | - protected function _setup_data() |
|
| 19 | - { |
|
| 20 | - $this->_data = $this->_view !== 'trash' |
|
| 21 | - ? $this->_admin_page->get_attendees($this->_per_page) |
|
| 22 | - : $this->_admin_page->get_attendees($this->_per_page, false, true); |
|
| 23 | - $this->_all_data_count = $this->_view !== 'trash' |
|
| 24 | - ? $this->_admin_page->get_attendees($this->_per_page, true) |
|
| 25 | - : $this->_admin_page->get_attendees($this->_per_page, true, true); |
|
| 26 | - } |
|
| 27 | - |
|
| 28 | - |
|
| 29 | - /** |
|
| 30 | - * Initial setup of properties. |
|
| 31 | - */ |
|
| 32 | - protected function _set_properties() |
|
| 33 | - { |
|
| 34 | - $this->_wp_list_args = array( |
|
| 35 | - 'singular' => esc_html__('attendee', 'event_espresso'), |
|
| 36 | - 'plural' => esc_html__('attendees', 'event_espresso'), |
|
| 37 | - 'ajax' => true, |
|
| 38 | - 'screen' => $this->_admin_page->get_current_screen()->id, |
|
| 39 | - ); |
|
| 40 | - |
|
| 41 | - $this->_columns = array( |
|
| 42 | - 'cb' => '<input type="checkbox" />', // Render a checkbox instead of text |
|
| 43 | - 'ATT_ID' => esc_html__('ID', 'event_espresso'), |
|
| 44 | - 'ATT_fname' => esc_html__('First Name', 'event_espresso'), |
|
| 45 | - 'ATT_lname' => esc_html__('Last Name', 'event_espresso'), |
|
| 46 | - 'ATT_email' => esc_html__('Email Address', 'event_espresso'), |
|
| 47 | - 'Registration_Count' => esc_html__('# Registrations', 'event_espresso'), |
|
| 48 | - 'ATT_phone' => esc_html__('Phone', 'event_espresso'), |
|
| 49 | - 'ATT_address' => esc_html__('Address', 'event_espresso'), |
|
| 50 | - 'ATT_city' => esc_html__('City', 'event_espresso'), |
|
| 51 | - 'STA_ID' => esc_html__('State/Province', 'event_espresso'), |
|
| 52 | - 'CNT_ISO' => esc_html__('Country', 'event_espresso'), |
|
| 53 | - ); |
|
| 54 | - |
|
| 55 | - $this->_sortable_columns = array( |
|
| 56 | - 'ATT_ID' => array('ATT_ID' => false), |
|
| 57 | - 'ATT_lname' => array('ATT_lname' => true), // true means its already sorted |
|
| 58 | - 'ATT_fname' => array('ATT_fname' => false), |
|
| 59 | - 'ATT_email' => array('ATT_email' => false), |
|
| 60 | - 'Registration_Count' => array('Registration_Count' => false), |
|
| 61 | - 'ATT_city' => array('ATT_city' => false), |
|
| 62 | - 'STA_ID' => array('STA_ID' => false), |
|
| 63 | - 'CNT_ISO' => array('CNT_ISO' => false), |
|
| 64 | - ); |
|
| 65 | - |
|
| 66 | - $this->_hidden_columns = array( |
|
| 67 | - 'ATT_phone', |
|
| 68 | - 'ATT_address', |
|
| 69 | - 'ATT_city', |
|
| 70 | - 'STA_ID', |
|
| 71 | - 'CNT_ISO', |
|
| 72 | - ); |
|
| 73 | - } |
|
| 74 | - |
|
| 75 | - |
|
| 76 | - /** |
|
| 77 | - * Initial setup of filters |
|
| 78 | - * |
|
| 79 | - * @return array |
|
| 80 | - */ |
|
| 81 | - protected function _get_table_filters() |
|
| 82 | - { |
|
| 83 | - return array(); |
|
| 84 | - } |
|
| 85 | - |
|
| 86 | - |
|
| 87 | - /** |
|
| 88 | - * Initial setup of counts for views |
|
| 89 | - * |
|
| 90 | - * @throws InvalidArgumentException |
|
| 91 | - * @throws InvalidDataTypeException |
|
| 92 | - * @throws InvalidInterfaceException |
|
| 93 | - */ |
|
| 94 | - protected function _add_view_counts() |
|
| 95 | - { |
|
| 96 | - $this->_views['in_use']['count'] = $this->_admin_page->get_attendees($this->_per_page, true); |
|
| 97 | - if ( |
|
| 98 | - EE_Registry::instance()->CAP->current_user_can( |
|
| 99 | - 'ee_delete_contacts', |
|
| 100 | - 'espresso_registrations_delete_registration' |
|
| 101 | - ) |
|
| 102 | - ) { |
|
| 103 | - $this->_views['trash']['count'] = $this->_admin_page->get_attendees($this->_per_page, true, true); |
|
| 104 | - } |
|
| 105 | - } |
|
| 106 | - |
|
| 107 | - |
|
| 108 | - /** |
|
| 109 | - * Get count of attendees. |
|
| 110 | - * |
|
| 111 | - * @return int |
|
| 112 | - * @throws EE_Error |
|
| 113 | - * @throws InvalidArgumentException |
|
| 114 | - * @throws InvalidDataTypeException |
|
| 115 | - * @throws InvalidInterfaceException |
|
| 116 | - */ |
|
| 117 | - protected function _get_attendees_count() |
|
| 118 | - { |
|
| 119 | - return EEM_Attendee::instance()->count(); |
|
| 120 | - } |
|
| 121 | - |
|
| 122 | - |
|
| 123 | - /** |
|
| 124 | - * Checkbox column |
|
| 125 | - * |
|
| 126 | - * @param EE_Attendee $attendee Unable to typehint this method because overrides parent. |
|
| 127 | - * @return string |
|
| 128 | - * @throws EE_Error |
|
| 129 | - */ |
|
| 130 | - public function column_cb($attendee) |
|
| 131 | - { |
|
| 132 | - if (! $attendee instanceof EE_Attendee) { |
|
| 133 | - return ''; |
|
| 134 | - } |
|
| 135 | - return sprintf( |
|
| 136 | - '<input type="checkbox" name="checkbox[%1$s]" value="%1$s" />', |
|
| 137 | - $attendee->ID() |
|
| 138 | - ); |
|
| 139 | - } |
|
| 140 | - |
|
| 141 | - |
|
| 142 | - /** |
|
| 143 | - * ATT_ID column |
|
| 144 | - * |
|
| 145 | - * @param EE_Attendee $attendee |
|
| 146 | - * @return string |
|
| 147 | - * @throws EE_Error |
|
| 148 | - */ |
|
| 149 | - public function column_ATT_ID(EE_Attendee $attendee) |
|
| 150 | - { |
|
| 151 | - $content = $attendee->ID(); |
|
| 152 | - $attendee_name = $attendee instanceof EE_Attendee ? $attendee->full_name() : ''; |
|
| 153 | - $content .= ' <span class="show-on-mobile-view-only">' . $attendee_name . '</span>'; |
|
| 154 | - return $content; |
|
| 155 | - } |
|
| 156 | - |
|
| 157 | - |
|
| 158 | - /** |
|
| 159 | - * ATT_lname column |
|
| 160 | - * |
|
| 161 | - * @param EE_Attendee $attendee |
|
| 162 | - * @return string |
|
| 163 | - * @throws InvalidArgumentException |
|
| 164 | - * @throws InvalidDataTypeException |
|
| 165 | - * @throws InvalidInterfaceException |
|
| 166 | - * @throws EE_Error |
|
| 167 | - */ |
|
| 168 | - public function column_ATT_lname(EE_Attendee $attendee) |
|
| 169 | - { |
|
| 170 | - // edit attendee link |
|
| 171 | - $edit_lnk_url = EE_Admin_Page::add_query_args_and_nonce( |
|
| 172 | - array( |
|
| 173 | - 'action' => 'edit_attendee', |
|
| 174 | - 'post' => $attendee->ID(), |
|
| 175 | - ), |
|
| 176 | - REG_ADMIN_URL |
|
| 177 | - ); |
|
| 178 | - $name_link = EE_Registry::instance()->CAP->current_user_can( |
|
| 179 | - 'ee_edit_contacts', |
|
| 180 | - 'espresso_registrations_edit_attendee' |
|
| 181 | - ) |
|
| 182 | - ? '<a href="' . $edit_lnk_url . '" title="' |
|
| 183 | - . esc_attr__('Edit Contact', 'event_espresso') . '">' |
|
| 184 | - . $attendee->lname() . '</a>' |
|
| 185 | - : $attendee->lname(); |
|
| 186 | - return $name_link; |
|
| 187 | - } |
|
| 188 | - |
|
| 189 | - |
|
| 190 | - /** |
|
| 191 | - * ATT_fname column |
|
| 192 | - * |
|
| 193 | - * @param EE_Attendee $attendee |
|
| 194 | - * @return string |
|
| 195 | - * @throws InvalidArgumentException |
|
| 196 | - * @throws InvalidDataTypeException |
|
| 197 | - * @throws InvalidInterfaceException |
|
| 198 | - * @throws EE_Error |
|
| 199 | - */ |
|
| 200 | - public function column_ATT_fname(EE_Attendee $attendee) |
|
| 201 | - { |
|
| 202 | - // Build row actions |
|
| 203 | - $actions = array(); |
|
| 204 | - // edit attendee link |
|
| 205 | - if ( |
|
| 206 | - EE_Registry::instance()->CAP->current_user_can( |
|
| 207 | - 'ee_edit_contacts', |
|
| 208 | - 'espresso_registrations_edit_attendee' |
|
| 209 | - ) |
|
| 210 | - ) { |
|
| 211 | - $edit_lnk_url = EE_Admin_Page::add_query_args_and_nonce( |
|
| 212 | - array( |
|
| 213 | - 'action' => 'edit_attendee', |
|
| 214 | - 'post' => $attendee->ID(), |
|
| 215 | - ), |
|
| 216 | - REG_ADMIN_URL |
|
| 217 | - ); |
|
| 218 | - $actions['edit'] = '<a href="' . $edit_lnk_url . '" title="' |
|
| 219 | - . esc_attr__('Edit Contact', 'event_espresso') . '">' |
|
| 220 | - . esc_html__('Edit', 'event_espresso') . '</a>'; |
|
| 221 | - } |
|
| 222 | - |
|
| 223 | - if ($this->_view === 'in_use') { |
|
| 224 | - // trash attendee link |
|
| 225 | - if ( |
|
| 226 | - EE_Registry::instance()->CAP->current_user_can( |
|
| 227 | - 'ee_delete_contacts', |
|
| 228 | - 'espresso_registrations_trash_attendees' |
|
| 229 | - ) |
|
| 230 | - ) { |
|
| 231 | - $trash_lnk_url = EE_Admin_Page::add_query_args_and_nonce( |
|
| 232 | - array( |
|
| 233 | - 'action' => 'trash_attendee', |
|
| 234 | - 'ATT_ID' => $attendee->ID(), |
|
| 235 | - ), |
|
| 236 | - REG_ADMIN_URL |
|
| 237 | - ); |
|
| 238 | - $actions['trash'] = '<a href="' . $trash_lnk_url . '" title="' |
|
| 239 | - . esc_attr__('Move Contact to Trash', 'event_espresso') |
|
| 240 | - . '">' . esc_html__('Trash', 'event_espresso') . '</a>'; |
|
| 241 | - } |
|
| 242 | - } else { |
|
| 243 | - if ( |
|
| 244 | - EE_Registry::instance()->CAP->current_user_can( |
|
| 245 | - 'ee_delete_contacts', |
|
| 246 | - 'espresso_registrations_restore_attendees' |
|
| 247 | - ) |
|
| 248 | - ) { |
|
| 249 | - // restore attendee link |
|
| 250 | - $restore_lnk_url = EE_Admin_Page::add_query_args_and_nonce( |
|
| 251 | - array( |
|
| 252 | - 'action' => 'restore_attendees', |
|
| 253 | - 'ATT_ID' => $attendee->ID(), |
|
| 254 | - ), |
|
| 255 | - REG_ADMIN_URL |
|
| 256 | - ); |
|
| 257 | - $actions['restore'] = '<a href="' . $restore_lnk_url . '" title="' |
|
| 258 | - . esc_attr__('Restore Contact', 'event_espresso') . '">' |
|
| 259 | - . esc_html__('Restore', 'event_espresso') . '</a>'; |
|
| 260 | - } |
|
| 261 | - } |
|
| 262 | - |
|
| 263 | - $edit_lnk_url = EE_Admin_Page::add_query_args_and_nonce( |
|
| 264 | - array( |
|
| 265 | - 'action' => 'edit_attendee', |
|
| 266 | - 'post' => $attendee->ID(), |
|
| 267 | - ), |
|
| 268 | - REG_ADMIN_URL |
|
| 269 | - ); |
|
| 270 | - $name_link = EE_Registry::instance()->CAP->current_user_can( |
|
| 271 | - 'ee_edit_contacts', |
|
| 272 | - 'espresso_registrations_edit_attendee' |
|
| 273 | - ) |
|
| 274 | - ? '<a href="' . $edit_lnk_url . '" title="' |
|
| 275 | - . esc_attr__('Edit Contact', 'event_espresso') . '">' . $attendee->fname() . '</a>' |
|
| 276 | - : $attendee->fname(); |
|
| 277 | - |
|
| 278 | - // Return the name contents |
|
| 279 | - return sprintf('%1$s %2$s', $name_link, $this->row_actions($actions)); |
|
| 280 | - } |
|
| 281 | - |
|
| 282 | - |
|
| 283 | - /** |
|
| 284 | - * Email Column |
|
| 285 | - * |
|
| 286 | - * @param EE_Attendee $attendee |
|
| 287 | - * @return string |
|
| 288 | - * @throws EE_Error |
|
| 289 | - */ |
|
| 290 | - public function column_ATT_email(EE_Attendee $attendee) |
|
| 291 | - { |
|
| 292 | - return '<a href="mailto:' . $attendee->email() . '">' . $attendee->email() . '</a>'; |
|
| 293 | - } |
|
| 294 | - |
|
| 295 | - |
|
| 296 | - /** |
|
| 297 | - * Column displaying count of registrations attached to Attendee. |
|
| 298 | - * |
|
| 299 | - * @param EE_Attendee $attendee |
|
| 300 | - * @return string |
|
| 301 | - * @throws EE_Error |
|
| 302 | - */ |
|
| 303 | - public function column_Registration_Count(EE_Attendee $attendee) |
|
| 304 | - { |
|
| 305 | - $link = EEH_URL::add_query_args_and_nonce( |
|
| 306 | - array( |
|
| 307 | - 'action' => 'default', |
|
| 308 | - 'ATT_ID' => $attendee->ID(), |
|
| 309 | - ), |
|
| 310 | - REG_ADMIN_URL |
|
| 311 | - ); |
|
| 312 | - return '<a href="' . $link . '">' . $attendee->getCustomSelect('Registration_Count') . '</a>'; |
|
| 313 | - } |
|
| 314 | - |
|
| 315 | - |
|
| 316 | - /** |
|
| 317 | - * ATT_address column |
|
| 318 | - * |
|
| 319 | - * @param EE_Attendee $attendee |
|
| 320 | - * @return mixed |
|
| 321 | - * @throws EE_Error |
|
| 322 | - */ |
|
| 323 | - public function column_ATT_address(EE_Attendee $attendee) |
|
| 324 | - { |
|
| 325 | - return $attendee->address(); |
|
| 326 | - } |
|
| 327 | - |
|
| 328 | - |
|
| 329 | - /** |
|
| 330 | - * ATT_city column |
|
| 331 | - * |
|
| 332 | - * @param EE_Attendee $attendee |
|
| 333 | - * @return mixed |
|
| 334 | - * @throws EE_Error |
|
| 335 | - */ |
|
| 336 | - public function column_ATT_city(EE_Attendee $attendee) |
|
| 337 | - { |
|
| 338 | - return $attendee->city(); |
|
| 339 | - } |
|
| 340 | - |
|
| 341 | - |
|
| 342 | - /** |
|
| 343 | - * State Column |
|
| 344 | - * |
|
| 345 | - * @param EE_Attendee $attendee |
|
| 346 | - * @return string |
|
| 347 | - * @throws EE_Error |
|
| 348 | - * @throws InvalidArgumentException |
|
| 349 | - * @throws InvalidDataTypeException |
|
| 350 | - * @throws InvalidInterfaceException |
|
| 351 | - */ |
|
| 352 | - public function column_STA_ID(EE_Attendee $attendee) |
|
| 353 | - { |
|
| 354 | - $states = EEM_State::instance()->get_all_states(); |
|
| 355 | - $state = isset($states[ $attendee->state_ID() ]) |
|
| 356 | - ? $states[ $attendee->state_ID() ]->get('STA_name') |
|
| 357 | - : $attendee->state_ID(); |
|
| 358 | - return ! is_numeric($state) ? $state : ''; |
|
| 359 | - } |
|
| 360 | - |
|
| 361 | - |
|
| 362 | - /** |
|
| 363 | - * Country Column |
|
| 364 | - * |
|
| 365 | - * @param EE_Attendee $attendee |
|
| 366 | - * @return string |
|
| 367 | - * @throws EE_Error |
|
| 368 | - * @throws InvalidArgumentException |
|
| 369 | - * @throws InvalidDataTypeException |
|
| 370 | - * @throws InvalidInterfaceException |
|
| 371 | - */ |
|
| 372 | - public function column_CNT_ISO(EE_Attendee $attendee) |
|
| 373 | - { |
|
| 374 | - $countries = EEM_Country::instance()->get_all_countries(); |
|
| 375 | - $country = isset($countries[ $attendee->country_ID() ]) |
|
| 376 | - ? $countries[ $attendee->country_ID() ]->get('CNT_name') |
|
| 377 | - : $attendee->country_ID(); |
|
| 378 | - return ! is_numeric($country) ? $country : ''; |
|
| 379 | - } |
|
| 380 | - |
|
| 381 | - |
|
| 382 | - /** |
|
| 383 | - * Phone Number column |
|
| 384 | - * |
|
| 385 | - * @param EE_Attendee $attendee |
|
| 386 | - * @return mixed |
|
| 387 | - * @throws EE_Error |
|
| 388 | - */ |
|
| 389 | - public function column_ATT_phone(EE_Attendee $attendee) |
|
| 390 | - { |
|
| 391 | - return $attendee->phone(); |
|
| 392 | - } |
|
| 15 | + /** |
|
| 16 | + * Initial setup of data (called by parent). |
|
| 17 | + */ |
|
| 18 | + protected function _setup_data() |
|
| 19 | + { |
|
| 20 | + $this->_data = $this->_view !== 'trash' |
|
| 21 | + ? $this->_admin_page->get_attendees($this->_per_page) |
|
| 22 | + : $this->_admin_page->get_attendees($this->_per_page, false, true); |
|
| 23 | + $this->_all_data_count = $this->_view !== 'trash' |
|
| 24 | + ? $this->_admin_page->get_attendees($this->_per_page, true) |
|
| 25 | + : $this->_admin_page->get_attendees($this->_per_page, true, true); |
|
| 26 | + } |
|
| 27 | + |
|
| 28 | + |
|
| 29 | + /** |
|
| 30 | + * Initial setup of properties. |
|
| 31 | + */ |
|
| 32 | + protected function _set_properties() |
|
| 33 | + { |
|
| 34 | + $this->_wp_list_args = array( |
|
| 35 | + 'singular' => esc_html__('attendee', 'event_espresso'), |
|
| 36 | + 'plural' => esc_html__('attendees', 'event_espresso'), |
|
| 37 | + 'ajax' => true, |
|
| 38 | + 'screen' => $this->_admin_page->get_current_screen()->id, |
|
| 39 | + ); |
|
| 40 | + |
|
| 41 | + $this->_columns = array( |
|
| 42 | + 'cb' => '<input type="checkbox" />', // Render a checkbox instead of text |
|
| 43 | + 'ATT_ID' => esc_html__('ID', 'event_espresso'), |
|
| 44 | + 'ATT_fname' => esc_html__('First Name', 'event_espresso'), |
|
| 45 | + 'ATT_lname' => esc_html__('Last Name', 'event_espresso'), |
|
| 46 | + 'ATT_email' => esc_html__('Email Address', 'event_espresso'), |
|
| 47 | + 'Registration_Count' => esc_html__('# Registrations', 'event_espresso'), |
|
| 48 | + 'ATT_phone' => esc_html__('Phone', 'event_espresso'), |
|
| 49 | + 'ATT_address' => esc_html__('Address', 'event_espresso'), |
|
| 50 | + 'ATT_city' => esc_html__('City', 'event_espresso'), |
|
| 51 | + 'STA_ID' => esc_html__('State/Province', 'event_espresso'), |
|
| 52 | + 'CNT_ISO' => esc_html__('Country', 'event_espresso'), |
|
| 53 | + ); |
|
| 54 | + |
|
| 55 | + $this->_sortable_columns = array( |
|
| 56 | + 'ATT_ID' => array('ATT_ID' => false), |
|
| 57 | + 'ATT_lname' => array('ATT_lname' => true), // true means its already sorted |
|
| 58 | + 'ATT_fname' => array('ATT_fname' => false), |
|
| 59 | + 'ATT_email' => array('ATT_email' => false), |
|
| 60 | + 'Registration_Count' => array('Registration_Count' => false), |
|
| 61 | + 'ATT_city' => array('ATT_city' => false), |
|
| 62 | + 'STA_ID' => array('STA_ID' => false), |
|
| 63 | + 'CNT_ISO' => array('CNT_ISO' => false), |
|
| 64 | + ); |
|
| 65 | + |
|
| 66 | + $this->_hidden_columns = array( |
|
| 67 | + 'ATT_phone', |
|
| 68 | + 'ATT_address', |
|
| 69 | + 'ATT_city', |
|
| 70 | + 'STA_ID', |
|
| 71 | + 'CNT_ISO', |
|
| 72 | + ); |
|
| 73 | + } |
|
| 74 | + |
|
| 75 | + |
|
| 76 | + /** |
|
| 77 | + * Initial setup of filters |
|
| 78 | + * |
|
| 79 | + * @return array |
|
| 80 | + */ |
|
| 81 | + protected function _get_table_filters() |
|
| 82 | + { |
|
| 83 | + return array(); |
|
| 84 | + } |
|
| 85 | + |
|
| 86 | + |
|
| 87 | + /** |
|
| 88 | + * Initial setup of counts for views |
|
| 89 | + * |
|
| 90 | + * @throws InvalidArgumentException |
|
| 91 | + * @throws InvalidDataTypeException |
|
| 92 | + * @throws InvalidInterfaceException |
|
| 93 | + */ |
|
| 94 | + protected function _add_view_counts() |
|
| 95 | + { |
|
| 96 | + $this->_views['in_use']['count'] = $this->_admin_page->get_attendees($this->_per_page, true); |
|
| 97 | + if ( |
|
| 98 | + EE_Registry::instance()->CAP->current_user_can( |
|
| 99 | + 'ee_delete_contacts', |
|
| 100 | + 'espresso_registrations_delete_registration' |
|
| 101 | + ) |
|
| 102 | + ) { |
|
| 103 | + $this->_views['trash']['count'] = $this->_admin_page->get_attendees($this->_per_page, true, true); |
|
| 104 | + } |
|
| 105 | + } |
|
| 106 | + |
|
| 107 | + |
|
| 108 | + /** |
|
| 109 | + * Get count of attendees. |
|
| 110 | + * |
|
| 111 | + * @return int |
|
| 112 | + * @throws EE_Error |
|
| 113 | + * @throws InvalidArgumentException |
|
| 114 | + * @throws InvalidDataTypeException |
|
| 115 | + * @throws InvalidInterfaceException |
|
| 116 | + */ |
|
| 117 | + protected function _get_attendees_count() |
|
| 118 | + { |
|
| 119 | + return EEM_Attendee::instance()->count(); |
|
| 120 | + } |
|
| 121 | + |
|
| 122 | + |
|
| 123 | + /** |
|
| 124 | + * Checkbox column |
|
| 125 | + * |
|
| 126 | + * @param EE_Attendee $attendee Unable to typehint this method because overrides parent. |
|
| 127 | + * @return string |
|
| 128 | + * @throws EE_Error |
|
| 129 | + */ |
|
| 130 | + public function column_cb($attendee) |
|
| 131 | + { |
|
| 132 | + if (! $attendee instanceof EE_Attendee) { |
|
| 133 | + return ''; |
|
| 134 | + } |
|
| 135 | + return sprintf( |
|
| 136 | + '<input type="checkbox" name="checkbox[%1$s]" value="%1$s" />', |
|
| 137 | + $attendee->ID() |
|
| 138 | + ); |
|
| 139 | + } |
|
| 140 | + |
|
| 141 | + |
|
| 142 | + /** |
|
| 143 | + * ATT_ID column |
|
| 144 | + * |
|
| 145 | + * @param EE_Attendee $attendee |
|
| 146 | + * @return string |
|
| 147 | + * @throws EE_Error |
|
| 148 | + */ |
|
| 149 | + public function column_ATT_ID(EE_Attendee $attendee) |
|
| 150 | + { |
|
| 151 | + $content = $attendee->ID(); |
|
| 152 | + $attendee_name = $attendee instanceof EE_Attendee ? $attendee->full_name() : ''; |
|
| 153 | + $content .= ' <span class="show-on-mobile-view-only">' . $attendee_name . '</span>'; |
|
| 154 | + return $content; |
|
| 155 | + } |
|
| 156 | + |
|
| 157 | + |
|
| 158 | + /** |
|
| 159 | + * ATT_lname column |
|
| 160 | + * |
|
| 161 | + * @param EE_Attendee $attendee |
|
| 162 | + * @return string |
|
| 163 | + * @throws InvalidArgumentException |
|
| 164 | + * @throws InvalidDataTypeException |
|
| 165 | + * @throws InvalidInterfaceException |
|
| 166 | + * @throws EE_Error |
|
| 167 | + */ |
|
| 168 | + public function column_ATT_lname(EE_Attendee $attendee) |
|
| 169 | + { |
|
| 170 | + // edit attendee link |
|
| 171 | + $edit_lnk_url = EE_Admin_Page::add_query_args_and_nonce( |
|
| 172 | + array( |
|
| 173 | + 'action' => 'edit_attendee', |
|
| 174 | + 'post' => $attendee->ID(), |
|
| 175 | + ), |
|
| 176 | + REG_ADMIN_URL |
|
| 177 | + ); |
|
| 178 | + $name_link = EE_Registry::instance()->CAP->current_user_can( |
|
| 179 | + 'ee_edit_contacts', |
|
| 180 | + 'espresso_registrations_edit_attendee' |
|
| 181 | + ) |
|
| 182 | + ? '<a href="' . $edit_lnk_url . '" title="' |
|
| 183 | + . esc_attr__('Edit Contact', 'event_espresso') . '">' |
|
| 184 | + . $attendee->lname() . '</a>' |
|
| 185 | + : $attendee->lname(); |
|
| 186 | + return $name_link; |
|
| 187 | + } |
|
| 188 | + |
|
| 189 | + |
|
| 190 | + /** |
|
| 191 | + * ATT_fname column |
|
| 192 | + * |
|
| 193 | + * @param EE_Attendee $attendee |
|
| 194 | + * @return string |
|
| 195 | + * @throws InvalidArgumentException |
|
| 196 | + * @throws InvalidDataTypeException |
|
| 197 | + * @throws InvalidInterfaceException |
|
| 198 | + * @throws EE_Error |
|
| 199 | + */ |
|
| 200 | + public function column_ATT_fname(EE_Attendee $attendee) |
|
| 201 | + { |
|
| 202 | + // Build row actions |
|
| 203 | + $actions = array(); |
|
| 204 | + // edit attendee link |
|
| 205 | + if ( |
|
| 206 | + EE_Registry::instance()->CAP->current_user_can( |
|
| 207 | + 'ee_edit_contacts', |
|
| 208 | + 'espresso_registrations_edit_attendee' |
|
| 209 | + ) |
|
| 210 | + ) { |
|
| 211 | + $edit_lnk_url = EE_Admin_Page::add_query_args_and_nonce( |
|
| 212 | + array( |
|
| 213 | + 'action' => 'edit_attendee', |
|
| 214 | + 'post' => $attendee->ID(), |
|
| 215 | + ), |
|
| 216 | + REG_ADMIN_URL |
|
| 217 | + ); |
|
| 218 | + $actions['edit'] = '<a href="' . $edit_lnk_url . '" title="' |
|
| 219 | + . esc_attr__('Edit Contact', 'event_espresso') . '">' |
|
| 220 | + . esc_html__('Edit', 'event_espresso') . '</a>'; |
|
| 221 | + } |
|
| 222 | + |
|
| 223 | + if ($this->_view === 'in_use') { |
|
| 224 | + // trash attendee link |
|
| 225 | + if ( |
|
| 226 | + EE_Registry::instance()->CAP->current_user_can( |
|
| 227 | + 'ee_delete_contacts', |
|
| 228 | + 'espresso_registrations_trash_attendees' |
|
| 229 | + ) |
|
| 230 | + ) { |
|
| 231 | + $trash_lnk_url = EE_Admin_Page::add_query_args_and_nonce( |
|
| 232 | + array( |
|
| 233 | + 'action' => 'trash_attendee', |
|
| 234 | + 'ATT_ID' => $attendee->ID(), |
|
| 235 | + ), |
|
| 236 | + REG_ADMIN_URL |
|
| 237 | + ); |
|
| 238 | + $actions['trash'] = '<a href="' . $trash_lnk_url . '" title="' |
|
| 239 | + . esc_attr__('Move Contact to Trash', 'event_espresso') |
|
| 240 | + . '">' . esc_html__('Trash', 'event_espresso') . '</a>'; |
|
| 241 | + } |
|
| 242 | + } else { |
|
| 243 | + if ( |
|
| 244 | + EE_Registry::instance()->CAP->current_user_can( |
|
| 245 | + 'ee_delete_contacts', |
|
| 246 | + 'espresso_registrations_restore_attendees' |
|
| 247 | + ) |
|
| 248 | + ) { |
|
| 249 | + // restore attendee link |
|
| 250 | + $restore_lnk_url = EE_Admin_Page::add_query_args_and_nonce( |
|
| 251 | + array( |
|
| 252 | + 'action' => 'restore_attendees', |
|
| 253 | + 'ATT_ID' => $attendee->ID(), |
|
| 254 | + ), |
|
| 255 | + REG_ADMIN_URL |
|
| 256 | + ); |
|
| 257 | + $actions['restore'] = '<a href="' . $restore_lnk_url . '" title="' |
|
| 258 | + . esc_attr__('Restore Contact', 'event_espresso') . '">' |
|
| 259 | + . esc_html__('Restore', 'event_espresso') . '</a>'; |
|
| 260 | + } |
|
| 261 | + } |
|
| 262 | + |
|
| 263 | + $edit_lnk_url = EE_Admin_Page::add_query_args_and_nonce( |
|
| 264 | + array( |
|
| 265 | + 'action' => 'edit_attendee', |
|
| 266 | + 'post' => $attendee->ID(), |
|
| 267 | + ), |
|
| 268 | + REG_ADMIN_URL |
|
| 269 | + ); |
|
| 270 | + $name_link = EE_Registry::instance()->CAP->current_user_can( |
|
| 271 | + 'ee_edit_contacts', |
|
| 272 | + 'espresso_registrations_edit_attendee' |
|
| 273 | + ) |
|
| 274 | + ? '<a href="' . $edit_lnk_url . '" title="' |
|
| 275 | + . esc_attr__('Edit Contact', 'event_espresso') . '">' . $attendee->fname() . '</a>' |
|
| 276 | + : $attendee->fname(); |
|
| 277 | + |
|
| 278 | + // Return the name contents |
|
| 279 | + return sprintf('%1$s %2$s', $name_link, $this->row_actions($actions)); |
|
| 280 | + } |
|
| 281 | + |
|
| 282 | + |
|
| 283 | + /** |
|
| 284 | + * Email Column |
|
| 285 | + * |
|
| 286 | + * @param EE_Attendee $attendee |
|
| 287 | + * @return string |
|
| 288 | + * @throws EE_Error |
|
| 289 | + */ |
|
| 290 | + public function column_ATT_email(EE_Attendee $attendee) |
|
| 291 | + { |
|
| 292 | + return '<a href="mailto:' . $attendee->email() . '">' . $attendee->email() . '</a>'; |
|
| 293 | + } |
|
| 294 | + |
|
| 295 | + |
|
| 296 | + /** |
|
| 297 | + * Column displaying count of registrations attached to Attendee. |
|
| 298 | + * |
|
| 299 | + * @param EE_Attendee $attendee |
|
| 300 | + * @return string |
|
| 301 | + * @throws EE_Error |
|
| 302 | + */ |
|
| 303 | + public function column_Registration_Count(EE_Attendee $attendee) |
|
| 304 | + { |
|
| 305 | + $link = EEH_URL::add_query_args_and_nonce( |
|
| 306 | + array( |
|
| 307 | + 'action' => 'default', |
|
| 308 | + 'ATT_ID' => $attendee->ID(), |
|
| 309 | + ), |
|
| 310 | + REG_ADMIN_URL |
|
| 311 | + ); |
|
| 312 | + return '<a href="' . $link . '">' . $attendee->getCustomSelect('Registration_Count') . '</a>'; |
|
| 313 | + } |
|
| 314 | + |
|
| 315 | + |
|
| 316 | + /** |
|
| 317 | + * ATT_address column |
|
| 318 | + * |
|
| 319 | + * @param EE_Attendee $attendee |
|
| 320 | + * @return mixed |
|
| 321 | + * @throws EE_Error |
|
| 322 | + */ |
|
| 323 | + public function column_ATT_address(EE_Attendee $attendee) |
|
| 324 | + { |
|
| 325 | + return $attendee->address(); |
|
| 326 | + } |
|
| 327 | + |
|
| 328 | + |
|
| 329 | + /** |
|
| 330 | + * ATT_city column |
|
| 331 | + * |
|
| 332 | + * @param EE_Attendee $attendee |
|
| 333 | + * @return mixed |
|
| 334 | + * @throws EE_Error |
|
| 335 | + */ |
|
| 336 | + public function column_ATT_city(EE_Attendee $attendee) |
|
| 337 | + { |
|
| 338 | + return $attendee->city(); |
|
| 339 | + } |
|
| 340 | + |
|
| 341 | + |
|
| 342 | + /** |
|
| 343 | + * State Column |
|
| 344 | + * |
|
| 345 | + * @param EE_Attendee $attendee |
|
| 346 | + * @return string |
|
| 347 | + * @throws EE_Error |
|
| 348 | + * @throws InvalidArgumentException |
|
| 349 | + * @throws InvalidDataTypeException |
|
| 350 | + * @throws InvalidInterfaceException |
|
| 351 | + */ |
|
| 352 | + public function column_STA_ID(EE_Attendee $attendee) |
|
| 353 | + { |
|
| 354 | + $states = EEM_State::instance()->get_all_states(); |
|
| 355 | + $state = isset($states[ $attendee->state_ID() ]) |
|
| 356 | + ? $states[ $attendee->state_ID() ]->get('STA_name') |
|
| 357 | + : $attendee->state_ID(); |
|
| 358 | + return ! is_numeric($state) ? $state : ''; |
|
| 359 | + } |
|
| 360 | + |
|
| 361 | + |
|
| 362 | + /** |
|
| 363 | + * Country Column |
|
| 364 | + * |
|
| 365 | + * @param EE_Attendee $attendee |
|
| 366 | + * @return string |
|
| 367 | + * @throws EE_Error |
|
| 368 | + * @throws InvalidArgumentException |
|
| 369 | + * @throws InvalidDataTypeException |
|
| 370 | + * @throws InvalidInterfaceException |
|
| 371 | + */ |
|
| 372 | + public function column_CNT_ISO(EE_Attendee $attendee) |
|
| 373 | + { |
|
| 374 | + $countries = EEM_Country::instance()->get_all_countries(); |
|
| 375 | + $country = isset($countries[ $attendee->country_ID() ]) |
|
| 376 | + ? $countries[ $attendee->country_ID() ]->get('CNT_name') |
|
| 377 | + : $attendee->country_ID(); |
|
| 378 | + return ! is_numeric($country) ? $country : ''; |
|
| 379 | + } |
|
| 380 | + |
|
| 381 | + |
|
| 382 | + /** |
|
| 383 | + * Phone Number column |
|
| 384 | + * |
|
| 385 | + * @param EE_Attendee $attendee |
|
| 386 | + * @return mixed |
|
| 387 | + * @throws EE_Error |
|
| 388 | + */ |
|
| 389 | + public function column_ATT_phone(EE_Attendee $attendee) |
|
| 390 | + { |
|
| 391 | + return $attendee->phone(); |
|
| 392 | + } |
|
| 393 | 393 | } |
@@ -129,7 +129,7 @@ discard block |
||
| 129 | 129 | */ |
| 130 | 130 | public function column_cb($attendee) |
| 131 | 131 | { |
| 132 | - if (! $attendee instanceof EE_Attendee) { |
|
| 132 | + if ( ! $attendee instanceof EE_Attendee) { |
|
| 133 | 133 | return ''; |
| 134 | 134 | } |
| 135 | 135 | return sprintf( |
@@ -150,7 +150,7 @@ discard block |
||
| 150 | 150 | { |
| 151 | 151 | $content = $attendee->ID(); |
| 152 | 152 | $attendee_name = $attendee instanceof EE_Attendee ? $attendee->full_name() : ''; |
| 153 | - $content .= ' <span class="show-on-mobile-view-only">' . $attendee_name . '</span>'; |
|
| 153 | + $content .= ' <span class="show-on-mobile-view-only">'.$attendee_name.'</span>'; |
|
| 154 | 154 | return $content; |
| 155 | 155 | } |
| 156 | 156 | |
@@ -179,9 +179,9 @@ discard block |
||
| 179 | 179 | 'ee_edit_contacts', |
| 180 | 180 | 'espresso_registrations_edit_attendee' |
| 181 | 181 | ) |
| 182 | - ? '<a href="' . $edit_lnk_url . '" title="' |
|
| 183 | - . esc_attr__('Edit Contact', 'event_espresso') . '">' |
|
| 184 | - . $attendee->lname() . '</a>' |
|
| 182 | + ? '<a href="'.$edit_lnk_url.'" title="' |
|
| 183 | + . esc_attr__('Edit Contact', 'event_espresso').'">' |
|
| 184 | + . $attendee->lname().'</a>' |
|
| 185 | 185 | : $attendee->lname(); |
| 186 | 186 | return $name_link; |
| 187 | 187 | } |
@@ -215,9 +215,9 @@ discard block |
||
| 215 | 215 | ), |
| 216 | 216 | REG_ADMIN_URL |
| 217 | 217 | ); |
| 218 | - $actions['edit'] = '<a href="' . $edit_lnk_url . '" title="' |
|
| 219 | - . esc_attr__('Edit Contact', 'event_espresso') . '">' |
|
| 220 | - . esc_html__('Edit', 'event_espresso') . '</a>'; |
|
| 218 | + $actions['edit'] = '<a href="'.$edit_lnk_url.'" title="' |
|
| 219 | + . esc_attr__('Edit Contact', 'event_espresso').'">' |
|
| 220 | + . esc_html__('Edit', 'event_espresso').'</a>'; |
|
| 221 | 221 | } |
| 222 | 222 | |
| 223 | 223 | if ($this->_view === 'in_use') { |
@@ -235,9 +235,9 @@ discard block |
||
| 235 | 235 | ), |
| 236 | 236 | REG_ADMIN_URL |
| 237 | 237 | ); |
| 238 | - $actions['trash'] = '<a href="' . $trash_lnk_url . '" title="' |
|
| 238 | + $actions['trash'] = '<a href="'.$trash_lnk_url.'" title="' |
|
| 239 | 239 | . esc_attr__('Move Contact to Trash', 'event_espresso') |
| 240 | - . '">' . esc_html__('Trash', 'event_espresso') . '</a>'; |
|
| 240 | + . '">'.esc_html__('Trash', 'event_espresso').'</a>'; |
|
| 241 | 241 | } |
| 242 | 242 | } else { |
| 243 | 243 | if ( |
@@ -254,9 +254,9 @@ discard block |
||
| 254 | 254 | ), |
| 255 | 255 | REG_ADMIN_URL |
| 256 | 256 | ); |
| 257 | - $actions['restore'] = '<a href="' . $restore_lnk_url . '" title="' |
|
| 258 | - . esc_attr__('Restore Contact', 'event_espresso') . '">' |
|
| 259 | - . esc_html__('Restore', 'event_espresso') . '</a>'; |
|
| 257 | + $actions['restore'] = '<a href="'.$restore_lnk_url.'" title="' |
|
| 258 | + . esc_attr__('Restore Contact', 'event_espresso').'">' |
|
| 259 | + . esc_html__('Restore', 'event_espresso').'</a>'; |
|
| 260 | 260 | } |
| 261 | 261 | } |
| 262 | 262 | |
@@ -271,8 +271,8 @@ discard block |
||
| 271 | 271 | 'ee_edit_contacts', |
| 272 | 272 | 'espresso_registrations_edit_attendee' |
| 273 | 273 | ) |
| 274 | - ? '<a href="' . $edit_lnk_url . '" title="' |
|
| 275 | - . esc_attr__('Edit Contact', 'event_espresso') . '">' . $attendee->fname() . '</a>' |
|
| 274 | + ? '<a href="'.$edit_lnk_url.'" title="' |
|
| 275 | + . esc_attr__('Edit Contact', 'event_espresso').'">'.$attendee->fname().'</a>' |
|
| 276 | 276 | : $attendee->fname(); |
| 277 | 277 | |
| 278 | 278 | // Return the name contents |
@@ -289,7 +289,7 @@ discard block |
||
| 289 | 289 | */ |
| 290 | 290 | public function column_ATT_email(EE_Attendee $attendee) |
| 291 | 291 | { |
| 292 | - return '<a href="mailto:' . $attendee->email() . '">' . $attendee->email() . '</a>'; |
|
| 292 | + return '<a href="mailto:'.$attendee->email().'">'.$attendee->email().'</a>'; |
|
| 293 | 293 | } |
| 294 | 294 | |
| 295 | 295 | |
@@ -309,7 +309,7 @@ discard block |
||
| 309 | 309 | ), |
| 310 | 310 | REG_ADMIN_URL |
| 311 | 311 | ); |
| 312 | - return '<a href="' . $link . '">' . $attendee->getCustomSelect('Registration_Count') . '</a>'; |
|
| 312 | + return '<a href="'.$link.'">'.$attendee->getCustomSelect('Registration_Count').'</a>'; |
|
| 313 | 313 | } |
| 314 | 314 | |
| 315 | 315 | |
@@ -352,8 +352,8 @@ discard block |
||
| 352 | 352 | public function column_STA_ID(EE_Attendee $attendee) |
| 353 | 353 | { |
| 354 | 354 | $states = EEM_State::instance()->get_all_states(); |
| 355 | - $state = isset($states[ $attendee->state_ID() ]) |
|
| 356 | - ? $states[ $attendee->state_ID() ]->get('STA_name') |
|
| 355 | + $state = isset($states[$attendee->state_ID()]) |
|
| 356 | + ? $states[$attendee->state_ID()]->get('STA_name') |
|
| 357 | 357 | : $attendee->state_ID(); |
| 358 | 358 | return ! is_numeric($state) ? $state : ''; |
| 359 | 359 | } |
@@ -372,8 +372,8 @@ discard block |
||
| 372 | 372 | public function column_CNT_ISO(EE_Attendee $attendee) |
| 373 | 373 | { |
| 374 | 374 | $countries = EEM_Country::instance()->get_all_countries(); |
| 375 | - $country = isset($countries[ $attendee->country_ID() ]) |
|
| 376 | - ? $countries[ $attendee->country_ID() ]->get('CNT_name') |
|
| 375 | + $country = isset($countries[$attendee->country_ID()]) |
|
| 376 | + ? $countries[$attendee->country_ID()]->get('CNT_name') |
|
| 377 | 377 | : $attendee->country_ID(); |
| 378 | 378 | return ! is_numeric($country) ? $country : ''; |
| 379 | 379 | } |
@@ -296,7 +296,7 @@ discard block |
||
| 296 | 296 | */ |
| 297 | 297 | public function timestamp($dt_frmt = '', $tm_frmt = '') |
| 298 | 298 | { |
| 299 | - return $this->get_i18n_datetime('PAY_timestamp', trim($dt_frmt . ' ' . $tm_frmt)); |
|
| 299 | + return $this->get_i18n_datetime('PAY_timestamp', trim($dt_frmt.' '.$tm_frmt)); |
|
| 300 | 300 | } |
| 301 | 301 | |
| 302 | 302 | |
@@ -481,7 +481,7 @@ discard block |
||
| 481 | 481 | : ''; |
| 482 | 482 | break; |
| 483 | 483 | } |
| 484 | - return $icon . $status[ $this->STS_ID() ]; |
|
| 484 | + return $icon.$status[$this->STS_ID()]; |
|
| 485 | 485 | } |
| 486 | 486 | |
| 487 | 487 | |
@@ -627,7 +627,7 @@ discard block |
||
| 627 | 627 | public function redirect_form($inside_form_html = null) |
| 628 | 628 | { |
| 629 | 629 | $redirect_url = $this->redirect_url(); |
| 630 | - if (! empty($redirect_url)) { |
|
| 630 | + if ( ! empty($redirect_url)) { |
|
| 631 | 631 | // what ? no inner form content? |
| 632 | 632 | if ($inside_form_html === null) { |
| 633 | 633 | $inside_form_html = EEH_HTML::p( |
@@ -657,7 +657,7 @@ discard block |
||
| 657 | 657 | $get_params = null; |
| 658 | 658 | parse_str($querystring, $get_params); |
| 659 | 659 | $inside_form_html .= $this->_args_as_inputs($get_params); |
| 660 | - $redirect_url = str_replace('?' . $querystring, '', $redirect_url); |
|
| 660 | + $redirect_url = str_replace('?'.$querystring, '', $redirect_url); |
|
| 661 | 661 | } |
| 662 | 662 | $form = EEH_HTML::nl(1) |
| 663 | 663 | . '<form method="' |
@@ -665,9 +665,9 @@ discard block |
||
| 665 | 665 | . '" name="gateway_form" action="' |
| 666 | 666 | . $redirect_url |
| 667 | 667 | . '">'; |
| 668 | - $form .= EEH_HTML::nl(1) . $this->redirect_args_as_inputs(); |
|
| 668 | + $form .= EEH_HTML::nl(1).$this->redirect_args_as_inputs(); |
|
| 669 | 669 | $form .= $inside_form_html; |
| 670 | - $form .= EEH_HTML::nl(-1) . '</form>' . EEH_HTML::nl(-1); |
|
| 670 | + $form .= EEH_HTML::nl(-1).'</form>'.EEH_HTML::nl(-1); |
|
| 671 | 671 | return $form; |
| 672 | 672 | } else { |
| 673 | 673 | return null; |
@@ -725,8 +725,8 @@ discard block |
||
| 725 | 725 | return $html; |
| 726 | 726 | } |
| 727 | 727 | return EEH_HTML::nl() |
| 728 | - . '<input type="hidden" name="' . $name . '"' |
|
| 729 | - . ' value="' . esc_attr($value) . '"/>'; |
|
| 728 | + . '<input type="hidden" name="'.$name.'"' |
|
| 729 | + . ' value="'.esc_attr($value).'"/>'; |
|
| 730 | 730 | } |
| 731 | 731 | |
| 732 | 732 | |
@@ -11,874 +11,874 @@ |
||
| 11 | 11 | */ |
| 12 | 12 | class EE_Payment extends EE_Base_Class implements EEI_Payment |
| 13 | 13 | { |
| 14 | - /** |
|
| 15 | - * @param array $props_n_values incoming values |
|
| 16 | - * @param string $timezone incoming timezone (if not set the timezone set for the website will be |
|
| 17 | - * used.) |
|
| 18 | - * @param array $date_formats incoming date_formats in an array where the first value is the |
|
| 19 | - * date_format and the second value is the time format |
|
| 20 | - * @return EE_Payment |
|
| 21 | - * @throws \EE_Error |
|
| 22 | - */ |
|
| 23 | - public static function new_instance($props_n_values = array(), $timezone = null, $date_formats = array()) |
|
| 24 | - { |
|
| 25 | - $has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone, $date_formats); |
|
| 26 | - return $has_object ? $has_object : new self($props_n_values, false, $timezone, $date_formats); |
|
| 27 | - } |
|
| 28 | - |
|
| 29 | - |
|
| 30 | - /** |
|
| 31 | - * @param array $props_n_values incoming values from the database |
|
| 32 | - * @param string $timezone incoming timezone as set by the model. If not set the timezone for |
|
| 33 | - * the website will be used. |
|
| 34 | - * @return EE_Payment |
|
| 35 | - * @throws \EE_Error |
|
| 36 | - */ |
|
| 37 | - public static function new_instance_from_db($props_n_values = array(), $timezone = null) |
|
| 38 | - { |
|
| 39 | - return new self($props_n_values, true, $timezone); |
|
| 40 | - } |
|
| 41 | - |
|
| 42 | - |
|
| 43 | - /** |
|
| 44 | - * Set Transaction ID |
|
| 45 | - * |
|
| 46 | - * @access public |
|
| 47 | - * @param int $TXN_ID |
|
| 48 | - * @throws \EE_Error |
|
| 49 | - */ |
|
| 50 | - public function set_transaction_id($TXN_ID = 0) |
|
| 51 | - { |
|
| 52 | - $this->set('TXN_ID', $TXN_ID); |
|
| 53 | - } |
|
| 54 | - |
|
| 55 | - |
|
| 56 | - /** |
|
| 57 | - * Gets the transaction related to this payment |
|
| 58 | - * |
|
| 59 | - * @return EE_Transaction |
|
| 60 | - * @throws \EE_Error |
|
| 61 | - */ |
|
| 62 | - public function transaction() |
|
| 63 | - { |
|
| 64 | - return $this->get_first_related('Transaction'); |
|
| 65 | - } |
|
| 66 | - |
|
| 67 | - |
|
| 68 | - /** |
|
| 69 | - * Set Status |
|
| 70 | - * |
|
| 71 | - * @access public |
|
| 72 | - * @param string $STS_ID |
|
| 73 | - * @throws \EE_Error |
|
| 74 | - */ |
|
| 75 | - public function set_status($STS_ID = '') |
|
| 76 | - { |
|
| 77 | - $this->set('STS_ID', $STS_ID); |
|
| 78 | - } |
|
| 79 | - |
|
| 80 | - |
|
| 81 | - /** |
|
| 82 | - * Set Payment Timestamp |
|
| 83 | - * |
|
| 84 | - * @access public |
|
| 85 | - * @param int $timestamp |
|
| 86 | - * @throws \EE_Error |
|
| 87 | - */ |
|
| 88 | - public function set_timestamp($timestamp = 0) |
|
| 89 | - { |
|
| 90 | - $this->set('PAY_timestamp', $timestamp); |
|
| 91 | - } |
|
| 92 | - |
|
| 93 | - |
|
| 94 | - /** |
|
| 95 | - * Set Payment Method |
|
| 96 | - * |
|
| 97 | - * @access public |
|
| 98 | - * @param string $PAY_source |
|
| 99 | - * @throws \EE_Error |
|
| 100 | - */ |
|
| 101 | - public function set_source($PAY_source = '') |
|
| 102 | - { |
|
| 103 | - $this->set('PAY_source', $PAY_source); |
|
| 104 | - } |
|
| 105 | - |
|
| 106 | - |
|
| 107 | - /** |
|
| 108 | - * Set Payment Amount |
|
| 109 | - * |
|
| 110 | - * @access public |
|
| 111 | - * @param float $amount |
|
| 112 | - * @throws \EE_Error |
|
| 113 | - */ |
|
| 114 | - public function set_amount($amount = 0.00) |
|
| 115 | - { |
|
| 116 | - $this->set('PAY_amount', (float) $amount); |
|
| 117 | - } |
|
| 118 | - |
|
| 119 | - |
|
| 120 | - /** |
|
| 121 | - * Set Payment Gateway Response |
|
| 122 | - * |
|
| 123 | - * @access public |
|
| 124 | - * @param string $gateway_response |
|
| 125 | - * @throws \EE_Error |
|
| 126 | - */ |
|
| 127 | - public function set_gateway_response($gateway_response = '') |
|
| 128 | - { |
|
| 129 | - $this->set('PAY_gateway_response', $gateway_response); |
|
| 130 | - } |
|
| 131 | - |
|
| 132 | - |
|
| 133 | - /** |
|
| 134 | - * Returns the name of the payment method used on this payment (previously known merely as 'gateway') |
|
| 135 | - * but since 4.6.0, payment methods are models and the payment keeps a foreign key to the payment method |
|
| 136 | - * used on it |
|
| 137 | - * |
|
| 138 | - * @deprecated |
|
| 139 | - * @return string |
|
| 140 | - * @throws \EE_Error |
|
| 141 | - */ |
|
| 142 | - public function gateway() |
|
| 143 | - { |
|
| 144 | - EE_Error::doing_it_wrong( |
|
| 145 | - 'EE_Payment::gateway', |
|
| 146 | - esc_html__( |
|
| 147 | - 'The method EE_Payment::gateway() has been deprecated. Consider instead using EE_Payment::payment_method()->name()', |
|
| 148 | - 'event_espresso' |
|
| 149 | - ), |
|
| 150 | - '4.6.0' |
|
| 151 | - ); |
|
| 152 | - return $this->payment_method() ? $this->payment_method()->name() : esc_html__('Unknown', 'event_espresso'); |
|
| 153 | - } |
|
| 154 | - |
|
| 155 | - |
|
| 156 | - /** |
|
| 157 | - * Set Gateway Transaction ID |
|
| 158 | - * |
|
| 159 | - * @access public |
|
| 160 | - * @param string $txn_id_chq_nmbr |
|
| 161 | - * @throws \EE_Error |
|
| 162 | - */ |
|
| 163 | - public function set_txn_id_chq_nmbr($txn_id_chq_nmbr = '') |
|
| 164 | - { |
|
| 165 | - $this->set('PAY_txn_id_chq_nmbr', $txn_id_chq_nmbr); |
|
| 166 | - } |
|
| 167 | - |
|
| 168 | - |
|
| 169 | - /** |
|
| 170 | - * Set Purchase Order Number |
|
| 171 | - * |
|
| 172 | - * @access public |
|
| 173 | - * @param string $po_number |
|
| 174 | - * @throws \EE_Error |
|
| 175 | - */ |
|
| 176 | - public function set_po_number($po_number = '') |
|
| 177 | - { |
|
| 178 | - $this->set('PAY_po_number', $po_number); |
|
| 179 | - } |
|
| 180 | - |
|
| 181 | - |
|
| 182 | - /** |
|
| 183 | - * Set Extra Accounting Field |
|
| 184 | - * |
|
| 185 | - * @access public |
|
| 186 | - * @param string $extra_accntng |
|
| 187 | - * @throws \EE_Error |
|
| 188 | - */ |
|
| 189 | - public function set_extra_accntng($extra_accntng = '') |
|
| 190 | - { |
|
| 191 | - $this->set('PAY_extra_accntng', $extra_accntng); |
|
| 192 | - } |
|
| 193 | - |
|
| 194 | - |
|
| 195 | - /** |
|
| 196 | - * Set Payment made via admin flag |
|
| 197 | - * |
|
| 198 | - * @access public |
|
| 199 | - * @param bool $via_admin |
|
| 200 | - * @throws \EE_Error |
|
| 201 | - */ |
|
| 202 | - public function set_payment_made_via_admin($via_admin = false) |
|
| 203 | - { |
|
| 204 | - if ($via_admin) { |
|
| 205 | - $this->set('PAY_source', EEM_Payment_Method::scope_admin); |
|
| 206 | - } else { |
|
| 207 | - $this->set('PAY_source', EEM_Payment_Method::scope_cart); |
|
| 208 | - } |
|
| 209 | - } |
|
| 210 | - |
|
| 211 | - |
|
| 212 | - /** |
|
| 213 | - * Set Payment Details |
|
| 214 | - * |
|
| 215 | - * @access public |
|
| 216 | - * @param string|array $details |
|
| 217 | - * @throws \EE_Error |
|
| 218 | - */ |
|
| 219 | - public function set_details($details = '') |
|
| 220 | - { |
|
| 221 | - if (is_array($details)) { |
|
| 222 | - array_walk_recursive($details, array($this, '_strip_all_tags_within_array')); |
|
| 223 | - } else { |
|
| 224 | - $details = wp_strip_all_tags($details); |
|
| 225 | - } |
|
| 226 | - $this->set('PAY_details', $details); |
|
| 227 | - } |
|
| 228 | - |
|
| 229 | - |
|
| 230 | - /** |
|
| 231 | - * Sets redirect_url |
|
| 232 | - * |
|
| 233 | - * @param string $redirect_url |
|
| 234 | - * @throws \EE_Error |
|
| 235 | - */ |
|
| 236 | - public function set_redirect_url($redirect_url) |
|
| 237 | - { |
|
| 238 | - $this->set('PAY_redirect_url', $redirect_url); |
|
| 239 | - } |
|
| 240 | - |
|
| 241 | - |
|
| 242 | - /** |
|
| 243 | - * Sets redirect_args |
|
| 244 | - * |
|
| 245 | - * @param array $redirect_args |
|
| 246 | - * @throws \EE_Error |
|
| 247 | - */ |
|
| 248 | - public function set_redirect_args($redirect_args) |
|
| 249 | - { |
|
| 250 | - $this->set('PAY_redirect_args', $redirect_args); |
|
| 251 | - } |
|
| 252 | - |
|
| 253 | - |
|
| 254 | - /** |
|
| 255 | - * get Payment Transaction ID |
|
| 256 | - * |
|
| 257 | - * @access public |
|
| 258 | - * @throws \EE_Error |
|
| 259 | - */ |
|
| 260 | - public function TXN_ID() |
|
| 261 | - { |
|
| 262 | - return $this->get('TXN_ID'); |
|
| 263 | - } |
|
| 264 | - |
|
| 265 | - |
|
| 266 | - /** |
|
| 267 | - * get Payment Status |
|
| 268 | - * |
|
| 269 | - * @access public |
|
| 270 | - * @throws \EE_Error |
|
| 271 | - */ |
|
| 272 | - public function status() |
|
| 273 | - { |
|
| 274 | - return $this->get('STS_ID'); |
|
| 275 | - } |
|
| 276 | - |
|
| 277 | - |
|
| 278 | - /** |
|
| 279 | - * get Payment Status |
|
| 280 | - * |
|
| 281 | - * @access public |
|
| 282 | - * @throws \EE_Error |
|
| 283 | - */ |
|
| 284 | - public function STS_ID() |
|
| 285 | - { |
|
| 286 | - return $this->get('STS_ID'); |
|
| 287 | - } |
|
| 288 | - |
|
| 289 | - |
|
| 290 | - /** |
|
| 291 | - * get Payment Timestamp |
|
| 292 | - * |
|
| 293 | - * @access public |
|
| 294 | - * @param string $dt_frmt |
|
| 295 | - * @param string $tm_frmt |
|
| 296 | - * @return string |
|
| 297 | - * @throws \EE_Error |
|
| 298 | - */ |
|
| 299 | - public function timestamp($dt_frmt = '', $tm_frmt = '') |
|
| 300 | - { |
|
| 301 | - return $this->get_i18n_datetime('PAY_timestamp', trim($dt_frmt . ' ' . $tm_frmt)); |
|
| 302 | - } |
|
| 303 | - |
|
| 304 | - |
|
| 305 | - /** |
|
| 306 | - * get Payment Source |
|
| 307 | - * |
|
| 308 | - * @access public |
|
| 309 | - * @throws \EE_Error |
|
| 310 | - */ |
|
| 311 | - public function source() |
|
| 312 | - { |
|
| 313 | - return $this->get('PAY_source'); |
|
| 314 | - } |
|
| 315 | - |
|
| 316 | - |
|
| 317 | - /** |
|
| 318 | - * get Payment Amount |
|
| 319 | - * |
|
| 320 | - * @access public |
|
| 321 | - * @return float |
|
| 322 | - * @throws \EE_Error |
|
| 323 | - */ |
|
| 324 | - public function amount() |
|
| 325 | - { |
|
| 326 | - return (float) $this->get('PAY_amount'); |
|
| 327 | - } |
|
| 328 | - |
|
| 329 | - |
|
| 330 | - /** |
|
| 331 | - * @return mixed |
|
| 332 | - * @throws \EE_Error |
|
| 333 | - */ |
|
| 334 | - public function amount_no_code() |
|
| 335 | - { |
|
| 336 | - return $this->get_pretty('PAY_amount', 'no_currency_code'); |
|
| 337 | - } |
|
| 338 | - |
|
| 339 | - |
|
| 340 | - /** |
|
| 341 | - * get Payment Gateway Response |
|
| 342 | - * |
|
| 343 | - * @access public |
|
| 344 | - * @throws \EE_Error |
|
| 345 | - */ |
|
| 346 | - public function gateway_response() |
|
| 347 | - { |
|
| 348 | - return $this->get('PAY_gateway_response'); |
|
| 349 | - } |
|
| 350 | - |
|
| 351 | - |
|
| 352 | - /** |
|
| 353 | - * get Payment Gateway Transaction ID |
|
| 354 | - * |
|
| 355 | - * @access public |
|
| 356 | - * @throws \EE_Error |
|
| 357 | - */ |
|
| 358 | - public function txn_id_chq_nmbr() |
|
| 359 | - { |
|
| 360 | - return $this->get('PAY_txn_id_chq_nmbr'); |
|
| 361 | - } |
|
| 362 | - |
|
| 363 | - |
|
| 364 | - /** |
|
| 365 | - * get Purchase Order Number |
|
| 366 | - * |
|
| 367 | - * @access public |
|
| 368 | - * @throws \EE_Error |
|
| 369 | - */ |
|
| 370 | - public function po_number() |
|
| 371 | - { |
|
| 372 | - return $this->get('PAY_po_number'); |
|
| 373 | - } |
|
| 374 | - |
|
| 375 | - |
|
| 376 | - /** |
|
| 377 | - * get Extra Accounting Field |
|
| 378 | - * |
|
| 379 | - * @access public |
|
| 380 | - * @throws \EE_Error |
|
| 381 | - */ |
|
| 382 | - public function extra_accntng() |
|
| 383 | - { |
|
| 384 | - return $this->get('PAY_extra_accntng'); |
|
| 385 | - } |
|
| 386 | - |
|
| 387 | - |
|
| 388 | - /** |
|
| 389 | - * get Payment made via admin source |
|
| 390 | - * |
|
| 391 | - * @access public |
|
| 392 | - * @throws \EE_Error |
|
| 393 | - */ |
|
| 394 | - public function payment_made_via_admin() |
|
| 395 | - { |
|
| 396 | - return ($this->get('PAY_source') === EEM_Payment_Method::scope_admin); |
|
| 397 | - } |
|
| 398 | - |
|
| 399 | - |
|
| 400 | - /** |
|
| 401 | - * get Payment Details |
|
| 402 | - * |
|
| 403 | - * @access public |
|
| 404 | - * @throws \EE_Error |
|
| 405 | - */ |
|
| 406 | - public function details() |
|
| 407 | - { |
|
| 408 | - return $this->get('PAY_details'); |
|
| 409 | - } |
|
| 410 | - |
|
| 411 | - |
|
| 412 | - /** |
|
| 413 | - * Gets redirect_url |
|
| 414 | - * |
|
| 415 | - * @return string |
|
| 416 | - * @throws \EE_Error |
|
| 417 | - */ |
|
| 418 | - public function redirect_url() |
|
| 419 | - { |
|
| 420 | - return $this->get('PAY_redirect_url'); |
|
| 421 | - } |
|
| 422 | - |
|
| 423 | - |
|
| 424 | - /** |
|
| 425 | - * Gets redirect_args |
|
| 426 | - * |
|
| 427 | - * @return array |
|
| 428 | - * @throws \EE_Error |
|
| 429 | - */ |
|
| 430 | - public function redirect_args() |
|
| 431 | - { |
|
| 432 | - return $this->get('PAY_redirect_args'); |
|
| 433 | - } |
|
| 434 | - |
|
| 435 | - |
|
| 436 | - /** |
|
| 437 | - * echoes $this->pretty_status() |
|
| 438 | - * |
|
| 439 | - * @param bool $show_icons |
|
| 440 | - * @return void |
|
| 441 | - * @throws \EE_Error |
|
| 442 | - */ |
|
| 443 | - public function e_pretty_status($show_icons = false) |
|
| 444 | - { |
|
| 445 | - echo wp_kses($this->pretty_status($show_icons), AllowedTags::getAllowedTags()); |
|
| 446 | - } |
|
| 447 | - |
|
| 448 | - |
|
| 449 | - /** |
|
| 450 | - * returns a pretty version of the status, good for displaying to users |
|
| 451 | - * |
|
| 452 | - * @param bool $show_icons |
|
| 453 | - * @return string |
|
| 454 | - * @throws \EE_Error |
|
| 455 | - */ |
|
| 456 | - public function pretty_status($show_icons = false) |
|
| 457 | - { |
|
| 458 | - $status = EEM_Status::instance()->localized_status( |
|
| 459 | - array($this->STS_ID() => esc_html__('unknown', 'event_espresso')), |
|
| 460 | - false, |
|
| 461 | - 'sentence' |
|
| 462 | - ); |
|
| 463 | - $icon = ''; |
|
| 464 | - switch ($this->STS_ID()) { |
|
| 465 | - case EEM_Payment::status_id_approved: |
|
| 466 | - $icon = $show_icons |
|
| 467 | - ? '<span class="dashicons dashicons-yes ee-icon-size-24 green-text"></span>' |
|
| 468 | - : ''; |
|
| 469 | - break; |
|
| 470 | - case EEM_Payment::status_id_pending: |
|
| 471 | - $icon = $show_icons |
|
| 472 | - ? '<span class="dashicons dashicons-clock ee-icon-size-16 orange-text"></span>' |
|
| 473 | - : ''; |
|
| 474 | - break; |
|
| 475 | - case EEM_Payment::status_id_cancelled: |
|
| 476 | - $icon = $show_icons |
|
| 477 | - ? '<span class="dashicons dashicons-no ee-icon-size-16 lt-grey-text"></span>' |
|
| 478 | - : ''; |
|
| 479 | - break; |
|
| 480 | - case EEM_Payment::status_id_declined: |
|
| 481 | - $icon = $show_icons |
|
| 482 | - ? '<span class="dashicons dashicons-no ee-icon-size-16 red-text"></span>' |
|
| 483 | - : ''; |
|
| 484 | - break; |
|
| 485 | - } |
|
| 486 | - return $icon . $status[ $this->STS_ID() ]; |
|
| 487 | - } |
|
| 488 | - |
|
| 489 | - |
|
| 490 | - /** |
|
| 491 | - * For determining the status of the payment |
|
| 492 | - * |
|
| 493 | - * @return boolean whether the payment is approved or not |
|
| 494 | - * @throws \EE_Error |
|
| 495 | - */ |
|
| 496 | - public function is_approved() |
|
| 497 | - { |
|
| 498 | - return $this->status_is(EEM_Payment::status_id_approved); |
|
| 499 | - } |
|
| 500 | - |
|
| 501 | - |
|
| 502 | - /** |
|
| 503 | - * Generally determines if the status of this payment equals |
|
| 504 | - * the $STS_ID string |
|
| 505 | - * |
|
| 506 | - * @param string $STS_ID an ID from the esp_status table/ |
|
| 507 | - * one of the status_id_* on the EEM_Payment model |
|
| 508 | - * @return boolean whether the status of this payment equals the status id |
|
| 509 | - * @throws \EE_Error |
|
| 510 | - */ |
|
| 511 | - protected function status_is($STS_ID) |
|
| 512 | - { |
|
| 513 | - return $STS_ID === $this->STS_ID() ? true : false; |
|
| 514 | - } |
|
| 515 | - |
|
| 516 | - |
|
| 517 | - /** |
|
| 518 | - * For determining the status of the payment |
|
| 519 | - * |
|
| 520 | - * @return boolean whether the payment is pending or not |
|
| 521 | - * @throws \EE_Error |
|
| 522 | - */ |
|
| 523 | - public function is_pending() |
|
| 524 | - { |
|
| 525 | - return $this->status_is(EEM_Payment::status_id_pending); |
|
| 526 | - } |
|
| 527 | - |
|
| 528 | - |
|
| 529 | - /** |
|
| 530 | - * For determining the status of the payment |
|
| 531 | - * |
|
| 532 | - * @return boolean |
|
| 533 | - * @throws \EE_Error |
|
| 534 | - */ |
|
| 535 | - public function is_cancelled() |
|
| 536 | - { |
|
| 537 | - return $this->status_is(EEM_Payment::status_id_cancelled); |
|
| 538 | - } |
|
| 539 | - |
|
| 540 | - |
|
| 541 | - /** |
|
| 542 | - * For determining the status of the payment |
|
| 543 | - * |
|
| 544 | - * @return boolean |
|
| 545 | - * @throws \EE_Error |
|
| 546 | - */ |
|
| 547 | - public function is_declined() |
|
| 548 | - { |
|
| 549 | - return $this->status_is(EEM_Payment::status_id_declined); |
|
| 550 | - } |
|
| 551 | - |
|
| 552 | - |
|
| 553 | - /** |
|
| 554 | - * For determining the status of the payment |
|
| 555 | - * |
|
| 556 | - * @return boolean |
|
| 557 | - * @throws \EE_Error |
|
| 558 | - */ |
|
| 559 | - public function is_failed() |
|
| 560 | - { |
|
| 561 | - return $this->status_is(EEM_Payment::status_id_failed); |
|
| 562 | - } |
|
| 563 | - |
|
| 564 | - |
|
| 565 | - /** |
|
| 566 | - * For determining if the payment is actually a refund ( ie: has a negative value ) |
|
| 567 | - * |
|
| 568 | - * @return boolean |
|
| 569 | - * @throws \EE_Error |
|
| 570 | - */ |
|
| 571 | - public function is_a_refund() |
|
| 572 | - { |
|
| 573 | - return $this->amount() < 0 ? true : false; |
|
| 574 | - } |
|
| 575 | - |
|
| 576 | - |
|
| 577 | - /** |
|
| 578 | - * Get the status object of this object |
|
| 579 | - * |
|
| 580 | - * @return EE_Status |
|
| 581 | - * @throws \EE_Error |
|
| 582 | - */ |
|
| 583 | - public function status_obj() |
|
| 584 | - { |
|
| 585 | - return $this->get_first_related('Status'); |
|
| 586 | - } |
|
| 587 | - |
|
| 588 | - |
|
| 589 | - /** |
|
| 590 | - * Gets all the extra meta info on this payment |
|
| 591 | - * |
|
| 592 | - * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
| 593 | - * @return EE_Extra_Meta |
|
| 594 | - * @throws \EE_Error |
|
| 595 | - */ |
|
| 596 | - public function extra_meta($query_params = array()) |
|
| 597 | - { |
|
| 598 | - return $this->get_many_related('Extra_Meta', $query_params); |
|
| 599 | - } |
|
| 600 | - |
|
| 601 | - |
|
| 602 | - /** |
|
| 603 | - * Gets the last-used payment method on this transaction |
|
| 604 | - * (we COULD just use the last-made payment, but some payment methods, namely |
|
| 605 | - * offline ones, dont' create payments) |
|
| 606 | - * |
|
| 607 | - * @return EE_Payment_Method |
|
| 608 | - * @throws \EE_Error |
|
| 609 | - */ |
|
| 610 | - public function payment_method() |
|
| 611 | - { |
|
| 612 | - return $this->get_first_related('Payment_Method'); |
|
| 613 | - } |
|
| 614 | - |
|
| 615 | - |
|
| 616 | - /** |
|
| 617 | - * Gets the HTML for redirecting the user to an offsite gateway |
|
| 618 | - * You can pass it special content to put inside the form, or use |
|
| 619 | - * the default inner content (or possibly generate this all yourself using |
|
| 620 | - * redirect_url() and redirect_args() or redirect_args_as_inputs()). |
|
| 621 | - * Creates a POST request by default, but if no redirect args are specified, creates a GET request instead |
|
| 622 | - * (and any querystring variables in the redirect_url are converted into html inputs |
|
| 623 | - * so browsers submit them properly) |
|
| 624 | - * |
|
| 625 | - * @param string $inside_form_html |
|
| 626 | - * @return string html |
|
| 627 | - * @throws \EE_Error |
|
| 628 | - */ |
|
| 629 | - public function redirect_form($inside_form_html = null) |
|
| 630 | - { |
|
| 631 | - $redirect_url = $this->redirect_url(); |
|
| 632 | - if (! empty($redirect_url)) { |
|
| 633 | - // what ? no inner form content? |
|
| 634 | - if ($inside_form_html === null) { |
|
| 635 | - $inside_form_html = EEH_HTML::p( |
|
| 636 | - sprintf( |
|
| 637 | - esc_html__( |
|
| 638 | - 'If you are not automatically redirected to the payment website within 10 seconds... %1$s %2$s Click Here %3$s', |
|
| 639 | - 'event_espresso' |
|
| 640 | - ), |
|
| 641 | - EEH_HTML::br(2), |
|
| 642 | - '<input type="submit" value="', |
|
| 643 | - '">' |
|
| 644 | - ), |
|
| 645 | - '', |
|
| 646 | - '', |
|
| 647 | - 'text-align:center;' |
|
| 648 | - ); |
|
| 649 | - } |
|
| 650 | - $method = apply_filters( |
|
| 651 | - 'FHEE__EE_Payment__redirect_form__method', |
|
| 652 | - $this->redirect_args() ? 'POST' : 'GET', |
|
| 653 | - $this |
|
| 654 | - ); |
|
| 655 | - // if it's a GET request, we need to remove all the GET params in the querystring |
|
| 656 | - // and put them into the form instead |
|
| 657 | - if ($method === 'GET') { |
|
| 658 | - $querystring = parse_url($redirect_url, PHP_URL_QUERY); |
|
| 659 | - $get_params = null; |
|
| 660 | - parse_str($querystring, $get_params); |
|
| 661 | - $inside_form_html .= $this->_args_as_inputs($get_params); |
|
| 662 | - $redirect_url = str_replace('?' . $querystring, '', $redirect_url); |
|
| 663 | - } |
|
| 664 | - $form = EEH_HTML::nl(1) |
|
| 665 | - . '<form method="' |
|
| 666 | - . $method |
|
| 667 | - . '" name="gateway_form" action="' |
|
| 668 | - . $redirect_url |
|
| 669 | - . '">'; |
|
| 670 | - $form .= EEH_HTML::nl(1) . $this->redirect_args_as_inputs(); |
|
| 671 | - $form .= $inside_form_html; |
|
| 672 | - $form .= EEH_HTML::nl(-1) . '</form>' . EEH_HTML::nl(-1); |
|
| 673 | - return $form; |
|
| 674 | - } else { |
|
| 675 | - return null; |
|
| 676 | - } |
|
| 677 | - } |
|
| 678 | - |
|
| 679 | - |
|
| 680 | - /** |
|
| 681 | - * Changes all the name-value pairs of the redirect args into html inputs |
|
| 682 | - * and returns the html as a string |
|
| 683 | - * |
|
| 684 | - * @return string |
|
| 685 | - * @throws \EE_Error |
|
| 686 | - */ |
|
| 687 | - public function redirect_args_as_inputs() |
|
| 688 | - { |
|
| 689 | - return $this->_args_as_inputs($this->redirect_args()); |
|
| 690 | - } |
|
| 691 | - |
|
| 692 | - |
|
| 693 | - /** |
|
| 694 | - * Converts a 2d array of key-value pairs into html hidden inputs |
|
| 695 | - * and returns the string of html |
|
| 696 | - * |
|
| 697 | - * @param array $args key-value pairs |
|
| 698 | - * @return string |
|
| 699 | - */ |
|
| 700 | - protected function _args_as_inputs($args) |
|
| 701 | - { |
|
| 702 | - $html = ''; |
|
| 703 | - if ($args !== null && is_array($args)) { |
|
| 704 | - foreach ($args as $name => $value) { |
|
| 705 | - $html .= $this->generateInput($name, $value); |
|
| 706 | - } |
|
| 707 | - } |
|
| 708 | - return $html; |
|
| 709 | - } |
|
| 710 | - |
|
| 711 | - /** |
|
| 712 | - * Converts either a single name and value or array of values into html hidden inputs |
|
| 713 | - * and returns the string of html |
|
| 714 | - * |
|
| 715 | - * @param string $name |
|
| 716 | - * @param string|array $value |
|
| 717 | - * @return string |
|
| 718 | - */ |
|
| 719 | - private function generateInput($name, $value) |
|
| 720 | - { |
|
| 721 | - if (is_array($value)) { |
|
| 722 | - $html = ''; |
|
| 723 | - $name = "{$name}[]"; |
|
| 724 | - foreach ($value as $array_value) { |
|
| 725 | - $html .= $this->generateInput($name, $array_value); |
|
| 726 | - } |
|
| 727 | - return $html; |
|
| 728 | - } |
|
| 729 | - return EEH_HTML::nl() |
|
| 730 | - . '<input type="hidden" name="' . $name . '"' |
|
| 731 | - . ' value="' . esc_attr($value) . '"/>'; |
|
| 732 | - } |
|
| 733 | - |
|
| 734 | - |
|
| 735 | - /** |
|
| 736 | - * Returns the currency of the payment. |
|
| 737 | - * (At the time of writing, this will always be the currency in the configuration; |
|
| 738 | - * however in the future it is anticipated that this will be stored on the payment |
|
| 739 | - * object itself) |
|
| 740 | - * |
|
| 741 | - * @return string for the currency code |
|
| 742 | - */ |
|
| 743 | - public function currency_code() |
|
| 744 | - { |
|
| 745 | - return EE_Config::instance()->currency->code; |
|
| 746 | - } |
|
| 747 | - |
|
| 748 | - |
|
| 749 | - /** |
|
| 750 | - * apply wp_strip_all_tags to all elements within an array |
|
| 751 | - * |
|
| 752 | - * @access private |
|
| 753 | - * @param mixed $item |
|
| 754 | - */ |
|
| 755 | - private function _strip_all_tags_within_array(&$item) |
|
| 756 | - { |
|
| 757 | - if (is_object($item)) { |
|
| 758 | - $item = (array) $item; |
|
| 759 | - } |
|
| 760 | - if (is_array($item)) { |
|
| 761 | - array_walk_recursive($item, array($this, '_strip_all_tags_within_array')); |
|
| 762 | - } else { |
|
| 763 | - $item = wp_strip_all_tags($item); |
|
| 764 | - } |
|
| 765 | - } |
|
| 766 | - |
|
| 767 | - |
|
| 768 | - /** |
|
| 769 | - * Returns TRUE is this payment was set to approved during this request (or |
|
| 770 | - * is approved and was created during this request). False otherwise. |
|
| 771 | - * |
|
| 772 | - * @return boolean |
|
| 773 | - * @throws \EE_Error |
|
| 774 | - */ |
|
| 775 | - public function just_approved() |
|
| 776 | - { |
|
| 777 | - $original_status = EEH_Array::is_set( |
|
| 778 | - $this->_props_n_values_provided_in_constructor, |
|
| 779 | - 'STS_ID', |
|
| 780 | - $this->get_model()->field_settings_for('STS_ID')->get_default_value() |
|
| 781 | - ); |
|
| 782 | - $current_status = $this->status(); |
|
| 783 | - if ( |
|
| 784 | - $original_status !== EEM_Payment::status_id_approved |
|
| 785 | - && $current_status === EEM_Payment::status_id_approved |
|
| 786 | - ) { |
|
| 787 | - return true; |
|
| 788 | - } else { |
|
| 789 | - return false; |
|
| 790 | - } |
|
| 791 | - } |
|
| 792 | - |
|
| 793 | - |
|
| 794 | - /** |
|
| 795 | - * Overrides parents' get_pretty() function just for legacy reasons |
|
| 796 | - * (to allow ticket https://events.codebasehq.com/projects/event-espresso/tickets/7420) |
|
| 797 | - * |
|
| 798 | - * @param string $field_name |
|
| 799 | - * @param string $extra_cache_ref This allows the user to specify an extra cache ref for the given property |
|
| 800 | - * (in cases where the same property may be used for different outputs |
|
| 801 | - * - i.e. datetime, money etc.) |
|
| 802 | - * @return mixed |
|
| 803 | - * @throws \EE_Error |
|
| 804 | - */ |
|
| 805 | - public function get_pretty($field_name, $extra_cache_ref = null) |
|
| 806 | - { |
|
| 807 | - if ($field_name === 'PAY_gateway') { |
|
| 808 | - return $this->payment_method() ? $this->payment_method()->name() : esc_html__('Unknown', 'event_espresso'); |
|
| 809 | - } |
|
| 810 | - return $this->_get_cached_property($field_name, true, $extra_cache_ref); |
|
| 811 | - } |
|
| 812 | - |
|
| 813 | - |
|
| 814 | - /** |
|
| 815 | - * Gets details regarding which registrations this payment was applied to |
|
| 816 | - * |
|
| 817 | - * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
| 818 | - * @return EE_Registration_Payment[] |
|
| 819 | - * @throws \EE_Error |
|
| 820 | - */ |
|
| 821 | - public function registration_payments($query_params = array()) |
|
| 822 | - { |
|
| 823 | - return $this->get_many_related('Registration_Payment', $query_params); |
|
| 824 | - } |
|
| 825 | - |
|
| 826 | - |
|
| 827 | - /** |
|
| 828 | - * Gets the first event for this payment (it's possible that it could be for multiple) |
|
| 829 | - * |
|
| 830 | - * @return EE_Event|null |
|
| 831 | - */ |
|
| 832 | - public function get_first_event() |
|
| 833 | - { |
|
| 834 | - $transaction = $this->transaction(); |
|
| 835 | - if ($transaction instanceof EE_Transaction) { |
|
| 836 | - $primary_registrant = $transaction->primary_registration(); |
|
| 837 | - if ($primary_registrant instanceof EE_Registration) { |
|
| 838 | - return $primary_registrant->event_obj(); |
|
| 839 | - } |
|
| 840 | - } |
|
| 841 | - return null; |
|
| 842 | - } |
|
| 843 | - |
|
| 844 | - |
|
| 845 | - /** |
|
| 846 | - * Gets the name of the first event for which is being paid |
|
| 847 | - * |
|
| 848 | - * @return string |
|
| 849 | - */ |
|
| 850 | - public function get_first_event_name() |
|
| 851 | - { |
|
| 852 | - $event = $this->get_first_event(); |
|
| 853 | - return $event instanceof EE_Event ? $event->name() : esc_html__('Event', 'event_espresso'); |
|
| 854 | - } |
|
| 855 | - |
|
| 856 | - |
|
| 857 | - /** |
|
| 858 | - * Returns the payment's transaction's primary registration |
|
| 859 | - * |
|
| 860 | - * @return EE_Registration|null |
|
| 861 | - */ |
|
| 862 | - public function get_primary_registration() |
|
| 863 | - { |
|
| 864 | - if ($this->transaction() instanceof EE_Transaction) { |
|
| 865 | - return $this->transaction()->primary_registration(); |
|
| 866 | - } |
|
| 867 | - return null; |
|
| 868 | - } |
|
| 869 | - |
|
| 870 | - |
|
| 871 | - /** |
|
| 872 | - * Gets the payment's transaction's primary registration's attendee, or null |
|
| 873 | - * |
|
| 874 | - * @return EE_Attendee|null |
|
| 875 | - */ |
|
| 876 | - public function get_primary_attendee() |
|
| 877 | - { |
|
| 878 | - $primary_reg = $this->get_primary_registration(); |
|
| 879 | - if ($primary_reg instanceof EE_Registration) { |
|
| 880 | - return $primary_reg->attendee(); |
|
| 881 | - } |
|
| 882 | - return null; |
|
| 883 | - } |
|
| 14 | + /** |
|
| 15 | + * @param array $props_n_values incoming values |
|
| 16 | + * @param string $timezone incoming timezone (if not set the timezone set for the website will be |
|
| 17 | + * used.) |
|
| 18 | + * @param array $date_formats incoming date_formats in an array where the first value is the |
|
| 19 | + * date_format and the second value is the time format |
|
| 20 | + * @return EE_Payment |
|
| 21 | + * @throws \EE_Error |
|
| 22 | + */ |
|
| 23 | + public static function new_instance($props_n_values = array(), $timezone = null, $date_formats = array()) |
|
| 24 | + { |
|
| 25 | + $has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone, $date_formats); |
|
| 26 | + return $has_object ? $has_object : new self($props_n_values, false, $timezone, $date_formats); |
|
| 27 | + } |
|
| 28 | + |
|
| 29 | + |
|
| 30 | + /** |
|
| 31 | + * @param array $props_n_values incoming values from the database |
|
| 32 | + * @param string $timezone incoming timezone as set by the model. If not set the timezone for |
|
| 33 | + * the website will be used. |
|
| 34 | + * @return EE_Payment |
|
| 35 | + * @throws \EE_Error |
|
| 36 | + */ |
|
| 37 | + public static function new_instance_from_db($props_n_values = array(), $timezone = null) |
|
| 38 | + { |
|
| 39 | + return new self($props_n_values, true, $timezone); |
|
| 40 | + } |
|
| 41 | + |
|
| 42 | + |
|
| 43 | + /** |
|
| 44 | + * Set Transaction ID |
|
| 45 | + * |
|
| 46 | + * @access public |
|
| 47 | + * @param int $TXN_ID |
|
| 48 | + * @throws \EE_Error |
|
| 49 | + */ |
|
| 50 | + public function set_transaction_id($TXN_ID = 0) |
|
| 51 | + { |
|
| 52 | + $this->set('TXN_ID', $TXN_ID); |
|
| 53 | + } |
|
| 54 | + |
|
| 55 | + |
|
| 56 | + /** |
|
| 57 | + * Gets the transaction related to this payment |
|
| 58 | + * |
|
| 59 | + * @return EE_Transaction |
|
| 60 | + * @throws \EE_Error |
|
| 61 | + */ |
|
| 62 | + public function transaction() |
|
| 63 | + { |
|
| 64 | + return $this->get_first_related('Transaction'); |
|
| 65 | + } |
|
| 66 | + |
|
| 67 | + |
|
| 68 | + /** |
|
| 69 | + * Set Status |
|
| 70 | + * |
|
| 71 | + * @access public |
|
| 72 | + * @param string $STS_ID |
|
| 73 | + * @throws \EE_Error |
|
| 74 | + */ |
|
| 75 | + public function set_status($STS_ID = '') |
|
| 76 | + { |
|
| 77 | + $this->set('STS_ID', $STS_ID); |
|
| 78 | + } |
|
| 79 | + |
|
| 80 | + |
|
| 81 | + /** |
|
| 82 | + * Set Payment Timestamp |
|
| 83 | + * |
|
| 84 | + * @access public |
|
| 85 | + * @param int $timestamp |
|
| 86 | + * @throws \EE_Error |
|
| 87 | + */ |
|
| 88 | + public function set_timestamp($timestamp = 0) |
|
| 89 | + { |
|
| 90 | + $this->set('PAY_timestamp', $timestamp); |
|
| 91 | + } |
|
| 92 | + |
|
| 93 | + |
|
| 94 | + /** |
|
| 95 | + * Set Payment Method |
|
| 96 | + * |
|
| 97 | + * @access public |
|
| 98 | + * @param string $PAY_source |
|
| 99 | + * @throws \EE_Error |
|
| 100 | + */ |
|
| 101 | + public function set_source($PAY_source = '') |
|
| 102 | + { |
|
| 103 | + $this->set('PAY_source', $PAY_source); |
|
| 104 | + } |
|
| 105 | + |
|
| 106 | + |
|
| 107 | + /** |
|
| 108 | + * Set Payment Amount |
|
| 109 | + * |
|
| 110 | + * @access public |
|
| 111 | + * @param float $amount |
|
| 112 | + * @throws \EE_Error |
|
| 113 | + */ |
|
| 114 | + public function set_amount($amount = 0.00) |
|
| 115 | + { |
|
| 116 | + $this->set('PAY_amount', (float) $amount); |
|
| 117 | + } |
|
| 118 | + |
|
| 119 | + |
|
| 120 | + /** |
|
| 121 | + * Set Payment Gateway Response |
|
| 122 | + * |
|
| 123 | + * @access public |
|
| 124 | + * @param string $gateway_response |
|
| 125 | + * @throws \EE_Error |
|
| 126 | + */ |
|
| 127 | + public function set_gateway_response($gateway_response = '') |
|
| 128 | + { |
|
| 129 | + $this->set('PAY_gateway_response', $gateway_response); |
|
| 130 | + } |
|
| 131 | + |
|
| 132 | + |
|
| 133 | + /** |
|
| 134 | + * Returns the name of the payment method used on this payment (previously known merely as 'gateway') |
|
| 135 | + * but since 4.6.0, payment methods are models and the payment keeps a foreign key to the payment method |
|
| 136 | + * used on it |
|
| 137 | + * |
|
| 138 | + * @deprecated |
|
| 139 | + * @return string |
|
| 140 | + * @throws \EE_Error |
|
| 141 | + */ |
|
| 142 | + public function gateway() |
|
| 143 | + { |
|
| 144 | + EE_Error::doing_it_wrong( |
|
| 145 | + 'EE_Payment::gateway', |
|
| 146 | + esc_html__( |
|
| 147 | + 'The method EE_Payment::gateway() has been deprecated. Consider instead using EE_Payment::payment_method()->name()', |
|
| 148 | + 'event_espresso' |
|
| 149 | + ), |
|
| 150 | + '4.6.0' |
|
| 151 | + ); |
|
| 152 | + return $this->payment_method() ? $this->payment_method()->name() : esc_html__('Unknown', 'event_espresso'); |
|
| 153 | + } |
|
| 154 | + |
|
| 155 | + |
|
| 156 | + /** |
|
| 157 | + * Set Gateway Transaction ID |
|
| 158 | + * |
|
| 159 | + * @access public |
|
| 160 | + * @param string $txn_id_chq_nmbr |
|
| 161 | + * @throws \EE_Error |
|
| 162 | + */ |
|
| 163 | + public function set_txn_id_chq_nmbr($txn_id_chq_nmbr = '') |
|
| 164 | + { |
|
| 165 | + $this->set('PAY_txn_id_chq_nmbr', $txn_id_chq_nmbr); |
|
| 166 | + } |
|
| 167 | + |
|
| 168 | + |
|
| 169 | + /** |
|
| 170 | + * Set Purchase Order Number |
|
| 171 | + * |
|
| 172 | + * @access public |
|
| 173 | + * @param string $po_number |
|
| 174 | + * @throws \EE_Error |
|
| 175 | + */ |
|
| 176 | + public function set_po_number($po_number = '') |
|
| 177 | + { |
|
| 178 | + $this->set('PAY_po_number', $po_number); |
|
| 179 | + } |
|
| 180 | + |
|
| 181 | + |
|
| 182 | + /** |
|
| 183 | + * Set Extra Accounting Field |
|
| 184 | + * |
|
| 185 | + * @access public |
|
| 186 | + * @param string $extra_accntng |
|
| 187 | + * @throws \EE_Error |
|
| 188 | + */ |
|
| 189 | + public function set_extra_accntng($extra_accntng = '') |
|
| 190 | + { |
|
| 191 | + $this->set('PAY_extra_accntng', $extra_accntng); |
|
| 192 | + } |
|
| 193 | + |
|
| 194 | + |
|
| 195 | + /** |
|
| 196 | + * Set Payment made via admin flag |
|
| 197 | + * |
|
| 198 | + * @access public |
|
| 199 | + * @param bool $via_admin |
|
| 200 | + * @throws \EE_Error |
|
| 201 | + */ |
|
| 202 | + public function set_payment_made_via_admin($via_admin = false) |
|
| 203 | + { |
|
| 204 | + if ($via_admin) { |
|
| 205 | + $this->set('PAY_source', EEM_Payment_Method::scope_admin); |
|
| 206 | + } else { |
|
| 207 | + $this->set('PAY_source', EEM_Payment_Method::scope_cart); |
|
| 208 | + } |
|
| 209 | + } |
|
| 210 | + |
|
| 211 | + |
|
| 212 | + /** |
|
| 213 | + * Set Payment Details |
|
| 214 | + * |
|
| 215 | + * @access public |
|
| 216 | + * @param string|array $details |
|
| 217 | + * @throws \EE_Error |
|
| 218 | + */ |
|
| 219 | + public function set_details($details = '') |
|
| 220 | + { |
|
| 221 | + if (is_array($details)) { |
|
| 222 | + array_walk_recursive($details, array($this, '_strip_all_tags_within_array')); |
|
| 223 | + } else { |
|
| 224 | + $details = wp_strip_all_tags($details); |
|
| 225 | + } |
|
| 226 | + $this->set('PAY_details', $details); |
|
| 227 | + } |
|
| 228 | + |
|
| 229 | + |
|
| 230 | + /** |
|
| 231 | + * Sets redirect_url |
|
| 232 | + * |
|
| 233 | + * @param string $redirect_url |
|
| 234 | + * @throws \EE_Error |
|
| 235 | + */ |
|
| 236 | + public function set_redirect_url($redirect_url) |
|
| 237 | + { |
|
| 238 | + $this->set('PAY_redirect_url', $redirect_url); |
|
| 239 | + } |
|
| 240 | + |
|
| 241 | + |
|
| 242 | + /** |
|
| 243 | + * Sets redirect_args |
|
| 244 | + * |
|
| 245 | + * @param array $redirect_args |
|
| 246 | + * @throws \EE_Error |
|
| 247 | + */ |
|
| 248 | + public function set_redirect_args($redirect_args) |
|
| 249 | + { |
|
| 250 | + $this->set('PAY_redirect_args', $redirect_args); |
|
| 251 | + } |
|
| 252 | + |
|
| 253 | + |
|
| 254 | + /** |
|
| 255 | + * get Payment Transaction ID |
|
| 256 | + * |
|
| 257 | + * @access public |
|
| 258 | + * @throws \EE_Error |
|
| 259 | + */ |
|
| 260 | + public function TXN_ID() |
|
| 261 | + { |
|
| 262 | + return $this->get('TXN_ID'); |
|
| 263 | + } |
|
| 264 | + |
|
| 265 | + |
|
| 266 | + /** |
|
| 267 | + * get Payment Status |
|
| 268 | + * |
|
| 269 | + * @access public |
|
| 270 | + * @throws \EE_Error |
|
| 271 | + */ |
|
| 272 | + public function status() |
|
| 273 | + { |
|
| 274 | + return $this->get('STS_ID'); |
|
| 275 | + } |
|
| 276 | + |
|
| 277 | + |
|
| 278 | + /** |
|
| 279 | + * get Payment Status |
|
| 280 | + * |
|
| 281 | + * @access public |
|
| 282 | + * @throws \EE_Error |
|
| 283 | + */ |
|
| 284 | + public function STS_ID() |
|
| 285 | + { |
|
| 286 | + return $this->get('STS_ID'); |
|
| 287 | + } |
|
| 288 | + |
|
| 289 | + |
|
| 290 | + /** |
|
| 291 | + * get Payment Timestamp |
|
| 292 | + * |
|
| 293 | + * @access public |
|
| 294 | + * @param string $dt_frmt |
|
| 295 | + * @param string $tm_frmt |
|
| 296 | + * @return string |
|
| 297 | + * @throws \EE_Error |
|
| 298 | + */ |
|
| 299 | + public function timestamp($dt_frmt = '', $tm_frmt = '') |
|
| 300 | + { |
|
| 301 | + return $this->get_i18n_datetime('PAY_timestamp', trim($dt_frmt . ' ' . $tm_frmt)); |
|
| 302 | + } |
|
| 303 | + |
|
| 304 | + |
|
| 305 | + /** |
|
| 306 | + * get Payment Source |
|
| 307 | + * |
|
| 308 | + * @access public |
|
| 309 | + * @throws \EE_Error |
|
| 310 | + */ |
|
| 311 | + public function source() |
|
| 312 | + { |
|
| 313 | + return $this->get('PAY_source'); |
|
| 314 | + } |
|
| 315 | + |
|
| 316 | + |
|
| 317 | + /** |
|
| 318 | + * get Payment Amount |
|
| 319 | + * |
|
| 320 | + * @access public |
|
| 321 | + * @return float |
|
| 322 | + * @throws \EE_Error |
|
| 323 | + */ |
|
| 324 | + public function amount() |
|
| 325 | + { |
|
| 326 | + return (float) $this->get('PAY_amount'); |
|
| 327 | + } |
|
| 328 | + |
|
| 329 | + |
|
| 330 | + /** |
|
| 331 | + * @return mixed |
|
| 332 | + * @throws \EE_Error |
|
| 333 | + */ |
|
| 334 | + public function amount_no_code() |
|
| 335 | + { |
|
| 336 | + return $this->get_pretty('PAY_amount', 'no_currency_code'); |
|
| 337 | + } |
|
| 338 | + |
|
| 339 | + |
|
| 340 | + /** |
|
| 341 | + * get Payment Gateway Response |
|
| 342 | + * |
|
| 343 | + * @access public |
|
| 344 | + * @throws \EE_Error |
|
| 345 | + */ |
|
| 346 | + public function gateway_response() |
|
| 347 | + { |
|
| 348 | + return $this->get('PAY_gateway_response'); |
|
| 349 | + } |
|
| 350 | + |
|
| 351 | + |
|
| 352 | + /** |
|
| 353 | + * get Payment Gateway Transaction ID |
|
| 354 | + * |
|
| 355 | + * @access public |
|
| 356 | + * @throws \EE_Error |
|
| 357 | + */ |
|
| 358 | + public function txn_id_chq_nmbr() |
|
| 359 | + { |
|
| 360 | + return $this->get('PAY_txn_id_chq_nmbr'); |
|
| 361 | + } |
|
| 362 | + |
|
| 363 | + |
|
| 364 | + /** |
|
| 365 | + * get Purchase Order Number |
|
| 366 | + * |
|
| 367 | + * @access public |
|
| 368 | + * @throws \EE_Error |
|
| 369 | + */ |
|
| 370 | + public function po_number() |
|
| 371 | + { |
|
| 372 | + return $this->get('PAY_po_number'); |
|
| 373 | + } |
|
| 374 | + |
|
| 375 | + |
|
| 376 | + /** |
|
| 377 | + * get Extra Accounting Field |
|
| 378 | + * |
|
| 379 | + * @access public |
|
| 380 | + * @throws \EE_Error |
|
| 381 | + */ |
|
| 382 | + public function extra_accntng() |
|
| 383 | + { |
|
| 384 | + return $this->get('PAY_extra_accntng'); |
|
| 385 | + } |
|
| 386 | + |
|
| 387 | + |
|
| 388 | + /** |
|
| 389 | + * get Payment made via admin source |
|
| 390 | + * |
|
| 391 | + * @access public |
|
| 392 | + * @throws \EE_Error |
|
| 393 | + */ |
|
| 394 | + public function payment_made_via_admin() |
|
| 395 | + { |
|
| 396 | + return ($this->get('PAY_source') === EEM_Payment_Method::scope_admin); |
|
| 397 | + } |
|
| 398 | + |
|
| 399 | + |
|
| 400 | + /** |
|
| 401 | + * get Payment Details |
|
| 402 | + * |
|
| 403 | + * @access public |
|
| 404 | + * @throws \EE_Error |
|
| 405 | + */ |
|
| 406 | + public function details() |
|
| 407 | + { |
|
| 408 | + return $this->get('PAY_details'); |
|
| 409 | + } |
|
| 410 | + |
|
| 411 | + |
|
| 412 | + /** |
|
| 413 | + * Gets redirect_url |
|
| 414 | + * |
|
| 415 | + * @return string |
|
| 416 | + * @throws \EE_Error |
|
| 417 | + */ |
|
| 418 | + public function redirect_url() |
|
| 419 | + { |
|
| 420 | + return $this->get('PAY_redirect_url'); |
|
| 421 | + } |
|
| 422 | + |
|
| 423 | + |
|
| 424 | + /** |
|
| 425 | + * Gets redirect_args |
|
| 426 | + * |
|
| 427 | + * @return array |
|
| 428 | + * @throws \EE_Error |
|
| 429 | + */ |
|
| 430 | + public function redirect_args() |
|
| 431 | + { |
|
| 432 | + return $this->get('PAY_redirect_args'); |
|
| 433 | + } |
|
| 434 | + |
|
| 435 | + |
|
| 436 | + /** |
|
| 437 | + * echoes $this->pretty_status() |
|
| 438 | + * |
|
| 439 | + * @param bool $show_icons |
|
| 440 | + * @return void |
|
| 441 | + * @throws \EE_Error |
|
| 442 | + */ |
|
| 443 | + public function e_pretty_status($show_icons = false) |
|
| 444 | + { |
|
| 445 | + echo wp_kses($this->pretty_status($show_icons), AllowedTags::getAllowedTags()); |
|
| 446 | + } |
|
| 447 | + |
|
| 448 | + |
|
| 449 | + /** |
|
| 450 | + * returns a pretty version of the status, good for displaying to users |
|
| 451 | + * |
|
| 452 | + * @param bool $show_icons |
|
| 453 | + * @return string |
|
| 454 | + * @throws \EE_Error |
|
| 455 | + */ |
|
| 456 | + public function pretty_status($show_icons = false) |
|
| 457 | + { |
|
| 458 | + $status = EEM_Status::instance()->localized_status( |
|
| 459 | + array($this->STS_ID() => esc_html__('unknown', 'event_espresso')), |
|
| 460 | + false, |
|
| 461 | + 'sentence' |
|
| 462 | + ); |
|
| 463 | + $icon = ''; |
|
| 464 | + switch ($this->STS_ID()) { |
|
| 465 | + case EEM_Payment::status_id_approved: |
|
| 466 | + $icon = $show_icons |
|
| 467 | + ? '<span class="dashicons dashicons-yes ee-icon-size-24 green-text"></span>' |
|
| 468 | + : ''; |
|
| 469 | + break; |
|
| 470 | + case EEM_Payment::status_id_pending: |
|
| 471 | + $icon = $show_icons |
|
| 472 | + ? '<span class="dashicons dashicons-clock ee-icon-size-16 orange-text"></span>' |
|
| 473 | + : ''; |
|
| 474 | + break; |
|
| 475 | + case EEM_Payment::status_id_cancelled: |
|
| 476 | + $icon = $show_icons |
|
| 477 | + ? '<span class="dashicons dashicons-no ee-icon-size-16 lt-grey-text"></span>' |
|
| 478 | + : ''; |
|
| 479 | + break; |
|
| 480 | + case EEM_Payment::status_id_declined: |
|
| 481 | + $icon = $show_icons |
|
| 482 | + ? '<span class="dashicons dashicons-no ee-icon-size-16 red-text"></span>' |
|
| 483 | + : ''; |
|
| 484 | + break; |
|
| 485 | + } |
|
| 486 | + return $icon . $status[ $this->STS_ID() ]; |
|
| 487 | + } |
|
| 488 | + |
|
| 489 | + |
|
| 490 | + /** |
|
| 491 | + * For determining the status of the payment |
|
| 492 | + * |
|
| 493 | + * @return boolean whether the payment is approved or not |
|
| 494 | + * @throws \EE_Error |
|
| 495 | + */ |
|
| 496 | + public function is_approved() |
|
| 497 | + { |
|
| 498 | + return $this->status_is(EEM_Payment::status_id_approved); |
|
| 499 | + } |
|
| 500 | + |
|
| 501 | + |
|
| 502 | + /** |
|
| 503 | + * Generally determines if the status of this payment equals |
|
| 504 | + * the $STS_ID string |
|
| 505 | + * |
|
| 506 | + * @param string $STS_ID an ID from the esp_status table/ |
|
| 507 | + * one of the status_id_* on the EEM_Payment model |
|
| 508 | + * @return boolean whether the status of this payment equals the status id |
|
| 509 | + * @throws \EE_Error |
|
| 510 | + */ |
|
| 511 | + protected function status_is($STS_ID) |
|
| 512 | + { |
|
| 513 | + return $STS_ID === $this->STS_ID() ? true : false; |
|
| 514 | + } |
|
| 515 | + |
|
| 516 | + |
|
| 517 | + /** |
|
| 518 | + * For determining the status of the payment |
|
| 519 | + * |
|
| 520 | + * @return boolean whether the payment is pending or not |
|
| 521 | + * @throws \EE_Error |
|
| 522 | + */ |
|
| 523 | + public function is_pending() |
|
| 524 | + { |
|
| 525 | + return $this->status_is(EEM_Payment::status_id_pending); |
|
| 526 | + } |
|
| 527 | + |
|
| 528 | + |
|
| 529 | + /** |
|
| 530 | + * For determining the status of the payment |
|
| 531 | + * |
|
| 532 | + * @return boolean |
|
| 533 | + * @throws \EE_Error |
|
| 534 | + */ |
|
| 535 | + public function is_cancelled() |
|
| 536 | + { |
|
| 537 | + return $this->status_is(EEM_Payment::status_id_cancelled); |
|
| 538 | + } |
|
| 539 | + |
|
| 540 | + |
|
| 541 | + /** |
|
| 542 | + * For determining the status of the payment |
|
| 543 | + * |
|
| 544 | + * @return boolean |
|
| 545 | + * @throws \EE_Error |
|
| 546 | + */ |
|
| 547 | + public function is_declined() |
|
| 548 | + { |
|
| 549 | + return $this->status_is(EEM_Payment::status_id_declined); |
|
| 550 | + } |
|
| 551 | + |
|
| 552 | + |
|
| 553 | + /** |
|
| 554 | + * For determining the status of the payment |
|
| 555 | + * |
|
| 556 | + * @return boolean |
|
| 557 | + * @throws \EE_Error |
|
| 558 | + */ |
|
| 559 | + public function is_failed() |
|
| 560 | + { |
|
| 561 | + return $this->status_is(EEM_Payment::status_id_failed); |
|
| 562 | + } |
|
| 563 | + |
|
| 564 | + |
|
| 565 | + /** |
|
| 566 | + * For determining if the payment is actually a refund ( ie: has a negative value ) |
|
| 567 | + * |
|
| 568 | + * @return boolean |
|
| 569 | + * @throws \EE_Error |
|
| 570 | + */ |
|
| 571 | + public function is_a_refund() |
|
| 572 | + { |
|
| 573 | + return $this->amount() < 0 ? true : false; |
|
| 574 | + } |
|
| 575 | + |
|
| 576 | + |
|
| 577 | + /** |
|
| 578 | + * Get the status object of this object |
|
| 579 | + * |
|
| 580 | + * @return EE_Status |
|
| 581 | + * @throws \EE_Error |
|
| 582 | + */ |
|
| 583 | + public function status_obj() |
|
| 584 | + { |
|
| 585 | + return $this->get_first_related('Status'); |
|
| 586 | + } |
|
| 587 | + |
|
| 588 | + |
|
| 589 | + /** |
|
| 590 | + * Gets all the extra meta info on this payment |
|
| 591 | + * |
|
| 592 | + * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
| 593 | + * @return EE_Extra_Meta |
|
| 594 | + * @throws \EE_Error |
|
| 595 | + */ |
|
| 596 | + public function extra_meta($query_params = array()) |
|
| 597 | + { |
|
| 598 | + return $this->get_many_related('Extra_Meta', $query_params); |
|
| 599 | + } |
|
| 600 | + |
|
| 601 | + |
|
| 602 | + /** |
|
| 603 | + * Gets the last-used payment method on this transaction |
|
| 604 | + * (we COULD just use the last-made payment, but some payment methods, namely |
|
| 605 | + * offline ones, dont' create payments) |
|
| 606 | + * |
|
| 607 | + * @return EE_Payment_Method |
|
| 608 | + * @throws \EE_Error |
|
| 609 | + */ |
|
| 610 | + public function payment_method() |
|
| 611 | + { |
|
| 612 | + return $this->get_first_related('Payment_Method'); |
|
| 613 | + } |
|
| 614 | + |
|
| 615 | + |
|
| 616 | + /** |
|
| 617 | + * Gets the HTML for redirecting the user to an offsite gateway |
|
| 618 | + * You can pass it special content to put inside the form, or use |
|
| 619 | + * the default inner content (or possibly generate this all yourself using |
|
| 620 | + * redirect_url() and redirect_args() or redirect_args_as_inputs()). |
|
| 621 | + * Creates a POST request by default, but if no redirect args are specified, creates a GET request instead |
|
| 622 | + * (and any querystring variables in the redirect_url are converted into html inputs |
|
| 623 | + * so browsers submit them properly) |
|
| 624 | + * |
|
| 625 | + * @param string $inside_form_html |
|
| 626 | + * @return string html |
|
| 627 | + * @throws \EE_Error |
|
| 628 | + */ |
|
| 629 | + public function redirect_form($inside_form_html = null) |
|
| 630 | + { |
|
| 631 | + $redirect_url = $this->redirect_url(); |
|
| 632 | + if (! empty($redirect_url)) { |
|
| 633 | + // what ? no inner form content? |
|
| 634 | + if ($inside_form_html === null) { |
|
| 635 | + $inside_form_html = EEH_HTML::p( |
|
| 636 | + sprintf( |
|
| 637 | + esc_html__( |
|
| 638 | + 'If you are not automatically redirected to the payment website within 10 seconds... %1$s %2$s Click Here %3$s', |
|
| 639 | + 'event_espresso' |
|
| 640 | + ), |
|
| 641 | + EEH_HTML::br(2), |
|
| 642 | + '<input type="submit" value="', |
|
| 643 | + '">' |
|
| 644 | + ), |
|
| 645 | + '', |
|
| 646 | + '', |
|
| 647 | + 'text-align:center;' |
|
| 648 | + ); |
|
| 649 | + } |
|
| 650 | + $method = apply_filters( |
|
| 651 | + 'FHEE__EE_Payment__redirect_form__method', |
|
| 652 | + $this->redirect_args() ? 'POST' : 'GET', |
|
| 653 | + $this |
|
| 654 | + ); |
|
| 655 | + // if it's a GET request, we need to remove all the GET params in the querystring |
|
| 656 | + // and put them into the form instead |
|
| 657 | + if ($method === 'GET') { |
|
| 658 | + $querystring = parse_url($redirect_url, PHP_URL_QUERY); |
|
| 659 | + $get_params = null; |
|
| 660 | + parse_str($querystring, $get_params); |
|
| 661 | + $inside_form_html .= $this->_args_as_inputs($get_params); |
|
| 662 | + $redirect_url = str_replace('?' . $querystring, '', $redirect_url); |
|
| 663 | + } |
|
| 664 | + $form = EEH_HTML::nl(1) |
|
| 665 | + . '<form method="' |
|
| 666 | + . $method |
|
| 667 | + . '" name="gateway_form" action="' |
|
| 668 | + . $redirect_url |
|
| 669 | + . '">'; |
|
| 670 | + $form .= EEH_HTML::nl(1) . $this->redirect_args_as_inputs(); |
|
| 671 | + $form .= $inside_form_html; |
|
| 672 | + $form .= EEH_HTML::nl(-1) . '</form>' . EEH_HTML::nl(-1); |
|
| 673 | + return $form; |
|
| 674 | + } else { |
|
| 675 | + return null; |
|
| 676 | + } |
|
| 677 | + } |
|
| 678 | + |
|
| 679 | + |
|
| 680 | + /** |
|
| 681 | + * Changes all the name-value pairs of the redirect args into html inputs |
|
| 682 | + * and returns the html as a string |
|
| 683 | + * |
|
| 684 | + * @return string |
|
| 685 | + * @throws \EE_Error |
|
| 686 | + */ |
|
| 687 | + public function redirect_args_as_inputs() |
|
| 688 | + { |
|
| 689 | + return $this->_args_as_inputs($this->redirect_args()); |
|
| 690 | + } |
|
| 691 | + |
|
| 692 | + |
|
| 693 | + /** |
|
| 694 | + * Converts a 2d array of key-value pairs into html hidden inputs |
|
| 695 | + * and returns the string of html |
|
| 696 | + * |
|
| 697 | + * @param array $args key-value pairs |
|
| 698 | + * @return string |
|
| 699 | + */ |
|
| 700 | + protected function _args_as_inputs($args) |
|
| 701 | + { |
|
| 702 | + $html = ''; |
|
| 703 | + if ($args !== null && is_array($args)) { |
|
| 704 | + foreach ($args as $name => $value) { |
|
| 705 | + $html .= $this->generateInput($name, $value); |
|
| 706 | + } |
|
| 707 | + } |
|
| 708 | + return $html; |
|
| 709 | + } |
|
| 710 | + |
|
| 711 | + /** |
|
| 712 | + * Converts either a single name and value or array of values into html hidden inputs |
|
| 713 | + * and returns the string of html |
|
| 714 | + * |
|
| 715 | + * @param string $name |
|
| 716 | + * @param string|array $value |
|
| 717 | + * @return string |
|
| 718 | + */ |
|
| 719 | + private function generateInput($name, $value) |
|
| 720 | + { |
|
| 721 | + if (is_array($value)) { |
|
| 722 | + $html = ''; |
|
| 723 | + $name = "{$name}[]"; |
|
| 724 | + foreach ($value as $array_value) { |
|
| 725 | + $html .= $this->generateInput($name, $array_value); |
|
| 726 | + } |
|
| 727 | + return $html; |
|
| 728 | + } |
|
| 729 | + return EEH_HTML::nl() |
|
| 730 | + . '<input type="hidden" name="' . $name . '"' |
|
| 731 | + . ' value="' . esc_attr($value) . '"/>'; |
|
| 732 | + } |
|
| 733 | + |
|
| 734 | + |
|
| 735 | + /** |
|
| 736 | + * Returns the currency of the payment. |
|
| 737 | + * (At the time of writing, this will always be the currency in the configuration; |
|
| 738 | + * however in the future it is anticipated that this will be stored on the payment |
|
| 739 | + * object itself) |
|
| 740 | + * |
|
| 741 | + * @return string for the currency code |
|
| 742 | + */ |
|
| 743 | + public function currency_code() |
|
| 744 | + { |
|
| 745 | + return EE_Config::instance()->currency->code; |
|
| 746 | + } |
|
| 747 | + |
|
| 748 | + |
|
| 749 | + /** |
|
| 750 | + * apply wp_strip_all_tags to all elements within an array |
|
| 751 | + * |
|
| 752 | + * @access private |
|
| 753 | + * @param mixed $item |
|
| 754 | + */ |
|
| 755 | + private function _strip_all_tags_within_array(&$item) |
|
| 756 | + { |
|
| 757 | + if (is_object($item)) { |
|
| 758 | + $item = (array) $item; |
|
| 759 | + } |
|
| 760 | + if (is_array($item)) { |
|
| 761 | + array_walk_recursive($item, array($this, '_strip_all_tags_within_array')); |
|
| 762 | + } else { |
|
| 763 | + $item = wp_strip_all_tags($item); |
|
| 764 | + } |
|
| 765 | + } |
|
| 766 | + |
|
| 767 | + |
|
| 768 | + /** |
|
| 769 | + * Returns TRUE is this payment was set to approved during this request (or |
|
| 770 | + * is approved and was created during this request). False otherwise. |
|
| 771 | + * |
|
| 772 | + * @return boolean |
|
| 773 | + * @throws \EE_Error |
|
| 774 | + */ |
|
| 775 | + public function just_approved() |
|
| 776 | + { |
|
| 777 | + $original_status = EEH_Array::is_set( |
|
| 778 | + $this->_props_n_values_provided_in_constructor, |
|
| 779 | + 'STS_ID', |
|
| 780 | + $this->get_model()->field_settings_for('STS_ID')->get_default_value() |
|
| 781 | + ); |
|
| 782 | + $current_status = $this->status(); |
|
| 783 | + if ( |
|
| 784 | + $original_status !== EEM_Payment::status_id_approved |
|
| 785 | + && $current_status === EEM_Payment::status_id_approved |
|
| 786 | + ) { |
|
| 787 | + return true; |
|
| 788 | + } else { |
|
| 789 | + return false; |
|
| 790 | + } |
|
| 791 | + } |
|
| 792 | + |
|
| 793 | + |
|
| 794 | + /** |
|
| 795 | + * Overrides parents' get_pretty() function just for legacy reasons |
|
| 796 | + * (to allow ticket https://events.codebasehq.com/projects/event-espresso/tickets/7420) |
|
| 797 | + * |
|
| 798 | + * @param string $field_name |
|
| 799 | + * @param string $extra_cache_ref This allows the user to specify an extra cache ref for the given property |
|
| 800 | + * (in cases where the same property may be used for different outputs |
|
| 801 | + * - i.e. datetime, money etc.) |
|
| 802 | + * @return mixed |
|
| 803 | + * @throws \EE_Error |
|
| 804 | + */ |
|
| 805 | + public function get_pretty($field_name, $extra_cache_ref = null) |
|
| 806 | + { |
|
| 807 | + if ($field_name === 'PAY_gateway') { |
|
| 808 | + return $this->payment_method() ? $this->payment_method()->name() : esc_html__('Unknown', 'event_espresso'); |
|
| 809 | + } |
|
| 810 | + return $this->_get_cached_property($field_name, true, $extra_cache_ref); |
|
| 811 | + } |
|
| 812 | + |
|
| 813 | + |
|
| 814 | + /** |
|
| 815 | + * Gets details regarding which registrations this payment was applied to |
|
| 816 | + * |
|
| 817 | + * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
| 818 | + * @return EE_Registration_Payment[] |
|
| 819 | + * @throws \EE_Error |
|
| 820 | + */ |
|
| 821 | + public function registration_payments($query_params = array()) |
|
| 822 | + { |
|
| 823 | + return $this->get_many_related('Registration_Payment', $query_params); |
|
| 824 | + } |
|
| 825 | + |
|
| 826 | + |
|
| 827 | + /** |
|
| 828 | + * Gets the first event for this payment (it's possible that it could be for multiple) |
|
| 829 | + * |
|
| 830 | + * @return EE_Event|null |
|
| 831 | + */ |
|
| 832 | + public function get_first_event() |
|
| 833 | + { |
|
| 834 | + $transaction = $this->transaction(); |
|
| 835 | + if ($transaction instanceof EE_Transaction) { |
|
| 836 | + $primary_registrant = $transaction->primary_registration(); |
|
| 837 | + if ($primary_registrant instanceof EE_Registration) { |
|
| 838 | + return $primary_registrant->event_obj(); |
|
| 839 | + } |
|
| 840 | + } |
|
| 841 | + return null; |
|
| 842 | + } |
|
| 843 | + |
|
| 844 | + |
|
| 845 | + /** |
|
| 846 | + * Gets the name of the first event for which is being paid |
|
| 847 | + * |
|
| 848 | + * @return string |
|
| 849 | + */ |
|
| 850 | + public function get_first_event_name() |
|
| 851 | + { |
|
| 852 | + $event = $this->get_first_event(); |
|
| 853 | + return $event instanceof EE_Event ? $event->name() : esc_html__('Event', 'event_espresso'); |
|
| 854 | + } |
|
| 855 | + |
|
| 856 | + |
|
| 857 | + /** |
|
| 858 | + * Returns the payment's transaction's primary registration |
|
| 859 | + * |
|
| 860 | + * @return EE_Registration|null |
|
| 861 | + */ |
|
| 862 | + public function get_primary_registration() |
|
| 863 | + { |
|
| 864 | + if ($this->transaction() instanceof EE_Transaction) { |
|
| 865 | + return $this->transaction()->primary_registration(); |
|
| 866 | + } |
|
| 867 | + return null; |
|
| 868 | + } |
|
| 869 | + |
|
| 870 | + |
|
| 871 | + /** |
|
| 872 | + * Gets the payment's transaction's primary registration's attendee, or null |
|
| 873 | + * |
|
| 874 | + * @return EE_Attendee|null |
|
| 875 | + */ |
|
| 876 | + public function get_primary_attendee() |
|
| 877 | + { |
|
| 878 | + $primary_reg = $this->get_primary_registration(); |
|
| 879 | + if ($primary_reg instanceof EE_Registration) { |
|
| 880 | + return $primary_reg->attendee(); |
|
| 881 | + } |
|
| 882 | + return null; |
|
| 883 | + } |
|
| 884 | 884 | } |
@@ -445,11 +445,11 @@ discard block |
||
| 445 | 445 | */ |
| 446 | 446 | public function type_obj() |
| 447 | 447 | { |
| 448 | - if (! $this->_type_obj) { |
|
| 448 | + if ( ! $this->_type_obj) { |
|
| 449 | 449 | EE_Registry::instance()->load_lib('Payment_Method_Manager'); |
| 450 | 450 | if (EE_Payment_Method_Manager::instance()->payment_method_type_exists($this->type())) { |
| 451 | 451 | $class_name = EE_Payment_Method_Manager::instance()->payment_method_class_from_type($this->type()); |
| 452 | - if (! class_exists($class_name)) { |
|
| 452 | + if ( ! class_exists($class_name)) { |
|
| 453 | 453 | throw new EE_Error( |
| 454 | 454 | sprintf( |
| 455 | 455 | esc_html__( |
@@ -458,7 +458,7 @@ discard block |
||
| 458 | 458 | ), |
| 459 | 459 | $class_name, |
| 460 | 460 | '<br />', |
| 461 | - '<a href="' . admin_url('plugins.php') . '">', |
|
| 461 | + '<a href="'.admin_url('plugins.php').'">', |
|
| 462 | 462 | '</a>' |
| 463 | 463 | ) |
| 464 | 464 | ); |
@@ -499,7 +499,7 @@ discard block |
||
| 499 | 499 | foreach ($fields as $key => $value) { |
| 500 | 500 | if (strpos($key, 'PMD_') === 0) { |
| 501 | 501 | $key_sans_model_prefix = str_replace('PMD_', '', $key); |
| 502 | - $combined_settings_array [ $key_sans_model_prefix ] = $value; |
|
| 502 | + $combined_settings_array [$key_sans_model_prefix] = $value; |
|
| 503 | 503 | } |
| 504 | 504 | } |
| 505 | 505 | $combined_settings_array = array_merge($extra_meta, $combined_settings_array); |
@@ -522,14 +522,14 @@ discard block |
||
| 522 | 522 | <div id="' |
| 523 | 523 | . $this->slug() |
| 524 | 524 | . '-payment-option-dv" class="' |
| 525 | - . $payment_occurs . '-payment-gateway reg-page-payment-option-dv' . $css_class . '"> |
|
| 525 | + . $payment_occurs.'-payment-gateway reg-page-payment-option-dv'.$css_class.'"> |
|
| 526 | 526 | <a id="payment-gateway-button-' . $this->slug() |
| 527 | 527 | . '" class="reg-page-payment-option-lnk" rel="' |
| 528 | - . $this->slug() . '" href="' . $url . '" > |
|
| 529 | - <img src="' . $this->button_url() . '" alt="' . sprintf( |
|
| 528 | + . $this->slug().'" href="'.$url.'" > |
|
| 529 | + <img src="' . $this->button_url().'" alt="'.sprintf( |
|
| 530 | 530 | esc_attr__('Pay using %s', 'event_espresso'), |
| 531 | 531 | $this->get_pretty('PMD_name', 'form_input') |
| 532 | - ) . '" /> |
|
| 532 | + ).'" /> |
|
| 533 | 533 | </a> |
| 534 | 534 | </div> |
| 535 | 535 | '; |
@@ -13,582 +13,582 @@ |
||
| 13 | 13 | */ |
| 14 | 14 | class EE_Payment_Method extends EE_Base_Class |
| 15 | 15 | { |
| 16 | - /** |
|
| 17 | - * Payment Method type object, which has all the info about this type of payment method, |
|
| 18 | - * including functions for processing payments, to get settings forms, etc. |
|
| 19 | - * |
|
| 20 | - * @var EE_PMT_Base |
|
| 21 | - */ |
|
| 22 | - protected $_type_obj; |
|
| 23 | - |
|
| 24 | - |
|
| 25 | - /** |
|
| 26 | - * @param array $props_n_values |
|
| 27 | - * @return EE_Payment_Method |
|
| 28 | - * @throws \EE_Error |
|
| 29 | - */ |
|
| 30 | - public static function new_instance($props_n_values = array()) |
|
| 31 | - { |
|
| 32 | - $has_object = parent::_check_for_object($props_n_values, __CLASS__); |
|
| 33 | - return $has_object ? $has_object : new self($props_n_values, false); |
|
| 34 | - } |
|
| 35 | - |
|
| 36 | - |
|
| 37 | - /** |
|
| 38 | - * @param array $props_n_values |
|
| 39 | - * @return EE_Payment_Method |
|
| 40 | - * @throws \EE_Error |
|
| 41 | - */ |
|
| 42 | - public static function new_instance_from_db($props_n_values = array()) |
|
| 43 | - { |
|
| 44 | - return new self($props_n_values, true); |
|
| 45 | - } |
|
| 46 | - |
|
| 47 | - |
|
| 48 | - |
|
| 49 | - /** |
|
| 50 | - * Checks if there is a payment method class of the given 'PMD_type', and if so returns the classname. |
|
| 51 | - * Otherwise returns a normal EE_Payment_Method |
|
| 52 | - * |
|
| 53 | - * @param array $props_n_values where 'PMD_type' is a gateway name like 'Paypal_Standard','Invoice',etc (basically |
|
| 54 | - * the classname minus 'EEPM_') |
|
| 55 | - * @return string |
|
| 56 | - */ |
|
| 57 | - // private static function _payment_method_type($props_n_values) |
|
| 58 | - // { |
|
| 59 | - // EE_Registry::instance()->load_lib('Payment_Method_Manager'); |
|
| 60 | - // $type_string = isset($props_n_values['PMD_type']) ? $props_n_values['PMD_type'] : null; |
|
| 61 | - // if (EE_Payment_Method_Manager::instance()->payment_method_type_exists($type_string)) { |
|
| 62 | - // return 'EEPM_' . $type_string; |
|
| 63 | - // } else { |
|
| 64 | - // return __CLASS__; |
|
| 65 | - // } |
|
| 66 | - // } |
|
| 67 | - |
|
| 68 | - |
|
| 69 | - /** |
|
| 70 | - * Gets whether this payment method can be used anywhere at all (ie frontend cart, admin, etc) |
|
| 71 | - * |
|
| 72 | - * @return boolean |
|
| 73 | - */ |
|
| 74 | - public function active() |
|
| 75 | - { |
|
| 76 | - return array_intersect(array_keys(EEM_Payment_Method::instance()->scopes()), $this->scope()); |
|
| 77 | - } |
|
| 78 | - |
|
| 79 | - |
|
| 80 | - /** |
|
| 81 | - * Sets this PM as active by making it usable within the CART scope. Offline gateways |
|
| 82 | - * are also usable from the admin-scope as well. DOES NOT SAVE it |
|
| 83 | - * |
|
| 84 | - * @throws \EE_Error |
|
| 85 | - */ |
|
| 86 | - public function set_active() |
|
| 87 | - { |
|
| 88 | - $default_scopes = array(EEM_Payment_Method::scope_cart); |
|
| 89 | - if ( |
|
| 90 | - $this->type_obj() && |
|
| 91 | - $this->type_obj()->payment_occurs() === EE_PMT_Base::offline |
|
| 92 | - ) { |
|
| 93 | - $default_scopes[] = EEM_Payment_Method::scope_admin; |
|
| 94 | - } |
|
| 95 | - $this->set_scope($default_scopes); |
|
| 96 | - } |
|
| 97 | - |
|
| 98 | - |
|
| 99 | - /** |
|
| 100 | - * Makes this payment method apply to NO scopes at all. DOES NOT SAVE it. |
|
| 101 | - */ |
|
| 102 | - public function deactivate() |
|
| 103 | - { |
|
| 104 | - $this->set_scope(array()); |
|
| 105 | - } |
|
| 106 | - |
|
| 107 | - |
|
| 108 | - /** |
|
| 109 | - * Gets button_url |
|
| 110 | - * |
|
| 111 | - * @return string |
|
| 112 | - */ |
|
| 113 | - public function button_url() |
|
| 114 | - { |
|
| 115 | - return $this->get('PMD_button_url'); |
|
| 116 | - } |
|
| 117 | - |
|
| 118 | - |
|
| 119 | - /** |
|
| 120 | - * Sets button_url |
|
| 121 | - * |
|
| 122 | - * @param string $button_url |
|
| 123 | - */ |
|
| 124 | - public function set_button_url($button_url) |
|
| 125 | - { |
|
| 126 | - $this->set('PMD_button_url', $button_url); |
|
| 127 | - } |
|
| 128 | - |
|
| 129 | - |
|
| 130 | - /** |
|
| 131 | - * Gets debug_mode |
|
| 132 | - * |
|
| 133 | - * @return boolean |
|
| 134 | - */ |
|
| 135 | - public function debug_mode() |
|
| 136 | - { |
|
| 137 | - return $this->get('PMD_debug_mode'); |
|
| 138 | - } |
|
| 139 | - |
|
| 140 | - |
|
| 141 | - /** |
|
| 142 | - * Sets debug_mode |
|
| 143 | - * |
|
| 144 | - * @param boolean $debug_mode |
|
| 145 | - */ |
|
| 146 | - public function set_debug_mode($debug_mode) |
|
| 147 | - { |
|
| 148 | - $this->set('PMD_debug_mode', $debug_mode); |
|
| 149 | - } |
|
| 150 | - |
|
| 151 | - |
|
| 152 | - /** |
|
| 153 | - * Gets description |
|
| 154 | - * |
|
| 155 | - * @return string |
|
| 156 | - */ |
|
| 157 | - public function description() |
|
| 158 | - { |
|
| 159 | - return $this->get('PMD_desc'); |
|
| 160 | - } |
|
| 161 | - |
|
| 162 | - |
|
| 163 | - /** |
|
| 164 | - * Sets description |
|
| 165 | - * |
|
| 166 | - * @param string $description |
|
| 167 | - */ |
|
| 168 | - public function set_description($description) |
|
| 169 | - { |
|
| 170 | - $this->set('PMD_desc', $description); |
|
| 171 | - } |
|
| 172 | - |
|
| 173 | - |
|
| 174 | - /** |
|
| 175 | - * Gets name |
|
| 176 | - * |
|
| 177 | - * @return string |
|
| 178 | - */ |
|
| 179 | - public function name() |
|
| 180 | - { |
|
| 181 | - return $this->get('PMD_name'); |
|
| 182 | - } |
|
| 183 | - |
|
| 184 | - |
|
| 185 | - /** |
|
| 186 | - * Sets name |
|
| 187 | - * |
|
| 188 | - * @param string $name |
|
| 189 | - */ |
|
| 190 | - public function set_name($name) |
|
| 191 | - { |
|
| 192 | - $this->set('PMD_name', $name); |
|
| 193 | - } |
|
| 194 | - |
|
| 195 | - |
|
| 196 | - /** |
|
| 197 | - * Gets open_by_default |
|
| 198 | - * |
|
| 199 | - * @return boolean |
|
| 200 | - */ |
|
| 201 | - public function open_by_default() |
|
| 202 | - { |
|
| 203 | - return $this->get('PMD_open_by_default'); |
|
| 204 | - } |
|
| 205 | - |
|
| 206 | - |
|
| 207 | - /** |
|
| 208 | - * Sets open_by_default |
|
| 209 | - * |
|
| 210 | - * @param boolean $open_by_default |
|
| 211 | - */ |
|
| 212 | - public function set_open_by_default($open_by_default) |
|
| 213 | - { |
|
| 214 | - $this->set('PMD_open_by_default', $open_by_default); |
|
| 215 | - } |
|
| 216 | - |
|
| 217 | - |
|
| 218 | - /** |
|
| 219 | - * Gets order |
|
| 220 | - * |
|
| 221 | - * @return int |
|
| 222 | - */ |
|
| 223 | - public function order() |
|
| 224 | - { |
|
| 225 | - return $this->get('PMD_order'); |
|
| 226 | - } |
|
| 227 | - |
|
| 228 | - |
|
| 229 | - /** |
|
| 230 | - * Sets order |
|
| 231 | - * |
|
| 232 | - * @param int $order |
|
| 233 | - */ |
|
| 234 | - public function set_order($order) |
|
| 235 | - { |
|
| 236 | - $this->set('PMD_order', $order); |
|
| 237 | - } |
|
| 238 | - |
|
| 239 | - |
|
| 240 | - /** |
|
| 241 | - * Gets slug |
|
| 242 | - * |
|
| 243 | - * @return string |
|
| 244 | - */ |
|
| 245 | - public function slug() |
|
| 246 | - { |
|
| 247 | - return $this->get('PMD_slug'); |
|
| 248 | - } |
|
| 249 | - |
|
| 250 | - |
|
| 251 | - /** |
|
| 252 | - * Sets slug |
|
| 253 | - * |
|
| 254 | - * @param string $slug |
|
| 255 | - */ |
|
| 256 | - public function set_slug($slug) |
|
| 257 | - { |
|
| 258 | - $this->set('PMD_slug', $slug); |
|
| 259 | - } |
|
| 260 | - |
|
| 261 | - |
|
| 262 | - /** |
|
| 263 | - * Gets type |
|
| 264 | - * |
|
| 265 | - * @return string |
|
| 266 | - */ |
|
| 267 | - public function type() |
|
| 268 | - { |
|
| 269 | - return $this->get('PMD_type'); |
|
| 270 | - } |
|
| 271 | - |
|
| 272 | - |
|
| 273 | - /** |
|
| 274 | - * Sets type |
|
| 275 | - * |
|
| 276 | - * @param string $type |
|
| 277 | - */ |
|
| 278 | - public function set_type($type) |
|
| 279 | - { |
|
| 280 | - $this->set('PMD_type', $type); |
|
| 281 | - } |
|
| 282 | - |
|
| 283 | - |
|
| 284 | - /** |
|
| 285 | - * Gets wp_user |
|
| 286 | - * |
|
| 287 | - * @return int |
|
| 288 | - */ |
|
| 289 | - public function wp_user() |
|
| 290 | - { |
|
| 291 | - return $this->get('PMD_wp_user'); |
|
| 292 | - } |
|
| 293 | - |
|
| 294 | - |
|
| 295 | - /** |
|
| 296 | - * Sets wp_user |
|
| 297 | - * |
|
| 298 | - * @param int $wp_user_id |
|
| 299 | - */ |
|
| 300 | - public function set_wp_user($wp_user_id) |
|
| 301 | - { |
|
| 302 | - $this->set('PMD_wp_user', $wp_user_id); |
|
| 303 | - } |
|
| 304 | - |
|
| 305 | - /** |
|
| 306 | - * Overrides parent so when PMD_type is changed we refresh the _type_obj |
|
| 307 | - * |
|
| 308 | - * @param string $field_name |
|
| 309 | - * @param mixed $field_value |
|
| 310 | - * @param boolean $use_default |
|
| 311 | - */ |
|
| 312 | - public function set($field_name, $field_value, $use_default = false) |
|
| 313 | - { |
|
| 314 | - if ($field_name === 'PMD_type') { |
|
| 315 | - // the type has probably changed, so forget about its old type object |
|
| 316 | - $this->_type_obj = null; |
|
| 317 | - } |
|
| 318 | - parent::set($field_name, $field_value, $use_default); |
|
| 319 | - } |
|
| 320 | - |
|
| 321 | - |
|
| 322 | - /** |
|
| 323 | - * Gets admin_name |
|
| 324 | - * |
|
| 325 | - * @return string |
|
| 326 | - */ |
|
| 327 | - public function admin_name() |
|
| 328 | - { |
|
| 329 | - return $this->get('PMD_admin_name'); |
|
| 330 | - } |
|
| 331 | - |
|
| 332 | - |
|
| 333 | - /** |
|
| 334 | - * Sets admin_name |
|
| 335 | - * |
|
| 336 | - * @param string $admin_name |
|
| 337 | - */ |
|
| 338 | - public function set_admin_name($admin_name) |
|
| 339 | - { |
|
| 340 | - $this->set('PMD_admin_name', $admin_name); |
|
| 341 | - } |
|
| 342 | - |
|
| 343 | - |
|
| 344 | - /** |
|
| 345 | - * Gets admin_desc |
|
| 346 | - * |
|
| 347 | - * @return string |
|
| 348 | - */ |
|
| 349 | - public function admin_desc() |
|
| 350 | - { |
|
| 351 | - return $this->get('PMD_admin_desc'); |
|
| 352 | - } |
|
| 353 | - |
|
| 354 | - |
|
| 355 | - /** |
|
| 356 | - * Sets admin_desc |
|
| 357 | - * |
|
| 358 | - * @param string $admin_desc |
|
| 359 | - */ |
|
| 360 | - public function set_admin_desc($admin_desc) |
|
| 361 | - { |
|
| 362 | - $this->set('PMD_admin_desc', $admin_desc); |
|
| 363 | - } |
|
| 364 | - |
|
| 365 | - |
|
| 366 | - /** |
|
| 367 | - * Gets scope |
|
| 368 | - * |
|
| 369 | - * @return array |
|
| 370 | - */ |
|
| 371 | - public function scope() |
|
| 372 | - { |
|
| 373 | - return $this->get('PMD_scope'); |
|
| 374 | - } |
|
| 375 | - |
|
| 376 | - |
|
| 377 | - /** |
|
| 378 | - * Sets scope |
|
| 379 | - * |
|
| 380 | - * @param array $scope |
|
| 381 | - */ |
|
| 382 | - public function set_scope($scope) |
|
| 383 | - { |
|
| 384 | - $this->set('PMD_scope', $scope); |
|
| 385 | - } |
|
| 386 | - |
|
| 387 | - |
|
| 388 | - /** |
|
| 389 | - * Gets the payment method type for this payment method instance |
|
| 390 | - * |
|
| 391 | - * @return EE_PMT_Base |
|
| 392 | - * @throws EE_Error |
|
| 393 | - */ |
|
| 394 | - public function type_obj() |
|
| 395 | - { |
|
| 396 | - if (! $this->_type_obj) { |
|
| 397 | - EE_Registry::instance()->load_lib('Payment_Method_Manager'); |
|
| 398 | - if (EE_Payment_Method_Manager::instance()->payment_method_type_exists($this->type())) { |
|
| 399 | - $class_name = EE_Payment_Method_Manager::instance()->payment_method_class_from_type($this->type()); |
|
| 400 | - if (! class_exists($class_name)) { |
|
| 401 | - throw new EE_Error( |
|
| 402 | - sprintf( |
|
| 403 | - esc_html__( |
|
| 404 | - 'An attempt to use the "%1$s" payment method failed, so it was deactivated.%2$sWas the "%1$s" Plugin recently deactivated? It can be reactivated on the %3$sPlugins Admin Page%4$s', |
|
| 405 | - 'event_espresso' |
|
| 406 | - ), |
|
| 407 | - $class_name, |
|
| 408 | - '<br />', |
|
| 409 | - '<a href="' . admin_url('plugins.php') . '">', |
|
| 410 | - '</a>' |
|
| 411 | - ) |
|
| 412 | - ); |
|
| 413 | - } |
|
| 414 | - $r = new ReflectionClass($class_name); |
|
| 415 | - $this->_type_obj = $r->newInstanceArgs(array($this)); |
|
| 416 | - } else { |
|
| 417 | - throw new EE_Error( |
|
| 418 | - sprintf( |
|
| 419 | - esc_html__( |
|
| 420 | - 'A payment method of type "%1$s" does not exist. Only ones existing are: %2$s', |
|
| 421 | - 'event_espresso' |
|
| 422 | - ), |
|
| 423 | - $this->type(), |
|
| 424 | - implode(',', EE_Payment_Method_Manager::instance()->payment_method_type_names()) |
|
| 425 | - ) |
|
| 426 | - ); |
|
| 427 | - } |
|
| 428 | - } |
|
| 429 | - return $this->_type_obj; |
|
| 430 | - } |
|
| 431 | - |
|
| 432 | - |
|
| 433 | - /** |
|
| 434 | - * Returns a simple array of key-value pairs combining the payment method's fields (without the 'PMD_' prefix) |
|
| 435 | - * and the extra meta. Mostly used for passing off ot gateways. * |
|
| 436 | - * |
|
| 437 | - * @return array |
|
| 438 | - */ |
|
| 439 | - public function settings_array() |
|
| 440 | - { |
|
| 441 | - $fields = $this->model_field_array(); |
|
| 442 | - $extra_meta = $this->all_extra_meta_array(); |
|
| 443 | - // remove the model's prefix from the fields |
|
| 444 | - $combined_settings_array = array(); |
|
| 445 | - foreach ($fields as $key => $value) { |
|
| 446 | - if (strpos($key, 'PMD_') === 0) { |
|
| 447 | - $key_sans_model_prefix = str_replace('PMD_', '', $key); |
|
| 448 | - $combined_settings_array [ $key_sans_model_prefix ] = $value; |
|
| 449 | - } |
|
| 450 | - } |
|
| 451 | - $combined_settings_array = array_merge($extra_meta, $combined_settings_array); |
|
| 452 | - return $combined_settings_array; |
|
| 453 | - } |
|
| 454 | - |
|
| 455 | - |
|
| 456 | - /** |
|
| 457 | - * Gets the HTML for displaying the payment method on a page. |
|
| 458 | - * |
|
| 459 | - * @param string $url |
|
| 460 | - * @param string $css_class |
|
| 461 | - * @return string of HTML for displaying the button |
|
| 462 | - * @throws \EE_Error |
|
| 463 | - */ |
|
| 464 | - public function button_html($url = '', $css_class = '') |
|
| 465 | - { |
|
| 466 | - $payment_occurs = $this->type_obj()->payment_occurs(); |
|
| 467 | - return ' |
|
| 16 | + /** |
|
| 17 | + * Payment Method type object, which has all the info about this type of payment method, |
|
| 18 | + * including functions for processing payments, to get settings forms, etc. |
|
| 19 | + * |
|
| 20 | + * @var EE_PMT_Base |
|
| 21 | + */ |
|
| 22 | + protected $_type_obj; |
|
| 23 | + |
|
| 24 | + |
|
| 25 | + /** |
|
| 26 | + * @param array $props_n_values |
|
| 27 | + * @return EE_Payment_Method |
|
| 28 | + * @throws \EE_Error |
|
| 29 | + */ |
|
| 30 | + public static function new_instance($props_n_values = array()) |
|
| 31 | + { |
|
| 32 | + $has_object = parent::_check_for_object($props_n_values, __CLASS__); |
|
| 33 | + return $has_object ? $has_object : new self($props_n_values, false); |
|
| 34 | + } |
|
| 35 | + |
|
| 36 | + |
|
| 37 | + /** |
|
| 38 | + * @param array $props_n_values |
|
| 39 | + * @return EE_Payment_Method |
|
| 40 | + * @throws \EE_Error |
|
| 41 | + */ |
|
| 42 | + public static function new_instance_from_db($props_n_values = array()) |
|
| 43 | + { |
|
| 44 | + return new self($props_n_values, true); |
|
| 45 | + } |
|
| 46 | + |
|
| 47 | + |
|
| 48 | + |
|
| 49 | + /** |
|
| 50 | + * Checks if there is a payment method class of the given 'PMD_type', and if so returns the classname. |
|
| 51 | + * Otherwise returns a normal EE_Payment_Method |
|
| 52 | + * |
|
| 53 | + * @param array $props_n_values where 'PMD_type' is a gateway name like 'Paypal_Standard','Invoice',etc (basically |
|
| 54 | + * the classname minus 'EEPM_') |
|
| 55 | + * @return string |
|
| 56 | + */ |
|
| 57 | + // private static function _payment_method_type($props_n_values) |
|
| 58 | + // { |
|
| 59 | + // EE_Registry::instance()->load_lib('Payment_Method_Manager'); |
|
| 60 | + // $type_string = isset($props_n_values['PMD_type']) ? $props_n_values['PMD_type'] : null; |
|
| 61 | + // if (EE_Payment_Method_Manager::instance()->payment_method_type_exists($type_string)) { |
|
| 62 | + // return 'EEPM_' . $type_string; |
|
| 63 | + // } else { |
|
| 64 | + // return __CLASS__; |
|
| 65 | + // } |
|
| 66 | + // } |
|
| 67 | + |
|
| 68 | + |
|
| 69 | + /** |
|
| 70 | + * Gets whether this payment method can be used anywhere at all (ie frontend cart, admin, etc) |
|
| 71 | + * |
|
| 72 | + * @return boolean |
|
| 73 | + */ |
|
| 74 | + public function active() |
|
| 75 | + { |
|
| 76 | + return array_intersect(array_keys(EEM_Payment_Method::instance()->scopes()), $this->scope()); |
|
| 77 | + } |
|
| 78 | + |
|
| 79 | + |
|
| 80 | + /** |
|
| 81 | + * Sets this PM as active by making it usable within the CART scope. Offline gateways |
|
| 82 | + * are also usable from the admin-scope as well. DOES NOT SAVE it |
|
| 83 | + * |
|
| 84 | + * @throws \EE_Error |
|
| 85 | + */ |
|
| 86 | + public function set_active() |
|
| 87 | + { |
|
| 88 | + $default_scopes = array(EEM_Payment_Method::scope_cart); |
|
| 89 | + if ( |
|
| 90 | + $this->type_obj() && |
|
| 91 | + $this->type_obj()->payment_occurs() === EE_PMT_Base::offline |
|
| 92 | + ) { |
|
| 93 | + $default_scopes[] = EEM_Payment_Method::scope_admin; |
|
| 94 | + } |
|
| 95 | + $this->set_scope($default_scopes); |
|
| 96 | + } |
|
| 97 | + |
|
| 98 | + |
|
| 99 | + /** |
|
| 100 | + * Makes this payment method apply to NO scopes at all. DOES NOT SAVE it. |
|
| 101 | + */ |
|
| 102 | + public function deactivate() |
|
| 103 | + { |
|
| 104 | + $this->set_scope(array()); |
|
| 105 | + } |
|
| 106 | + |
|
| 107 | + |
|
| 108 | + /** |
|
| 109 | + * Gets button_url |
|
| 110 | + * |
|
| 111 | + * @return string |
|
| 112 | + */ |
|
| 113 | + public function button_url() |
|
| 114 | + { |
|
| 115 | + return $this->get('PMD_button_url'); |
|
| 116 | + } |
|
| 117 | + |
|
| 118 | + |
|
| 119 | + /** |
|
| 120 | + * Sets button_url |
|
| 121 | + * |
|
| 122 | + * @param string $button_url |
|
| 123 | + */ |
|
| 124 | + public function set_button_url($button_url) |
|
| 125 | + { |
|
| 126 | + $this->set('PMD_button_url', $button_url); |
|
| 127 | + } |
|
| 128 | + |
|
| 129 | + |
|
| 130 | + /** |
|
| 131 | + * Gets debug_mode |
|
| 132 | + * |
|
| 133 | + * @return boolean |
|
| 134 | + */ |
|
| 135 | + public function debug_mode() |
|
| 136 | + { |
|
| 137 | + return $this->get('PMD_debug_mode'); |
|
| 138 | + } |
|
| 139 | + |
|
| 140 | + |
|
| 141 | + /** |
|
| 142 | + * Sets debug_mode |
|
| 143 | + * |
|
| 144 | + * @param boolean $debug_mode |
|
| 145 | + */ |
|
| 146 | + public function set_debug_mode($debug_mode) |
|
| 147 | + { |
|
| 148 | + $this->set('PMD_debug_mode', $debug_mode); |
|
| 149 | + } |
|
| 150 | + |
|
| 151 | + |
|
| 152 | + /** |
|
| 153 | + * Gets description |
|
| 154 | + * |
|
| 155 | + * @return string |
|
| 156 | + */ |
|
| 157 | + public function description() |
|
| 158 | + { |
|
| 159 | + return $this->get('PMD_desc'); |
|
| 160 | + } |
|
| 161 | + |
|
| 162 | + |
|
| 163 | + /** |
|
| 164 | + * Sets description |
|
| 165 | + * |
|
| 166 | + * @param string $description |
|
| 167 | + */ |
|
| 168 | + public function set_description($description) |
|
| 169 | + { |
|
| 170 | + $this->set('PMD_desc', $description); |
|
| 171 | + } |
|
| 172 | + |
|
| 173 | + |
|
| 174 | + /** |
|
| 175 | + * Gets name |
|
| 176 | + * |
|
| 177 | + * @return string |
|
| 178 | + */ |
|
| 179 | + public function name() |
|
| 180 | + { |
|
| 181 | + return $this->get('PMD_name'); |
|
| 182 | + } |
|
| 183 | + |
|
| 184 | + |
|
| 185 | + /** |
|
| 186 | + * Sets name |
|
| 187 | + * |
|
| 188 | + * @param string $name |
|
| 189 | + */ |
|
| 190 | + public function set_name($name) |
|
| 191 | + { |
|
| 192 | + $this->set('PMD_name', $name); |
|
| 193 | + } |
|
| 194 | + |
|
| 195 | + |
|
| 196 | + /** |
|
| 197 | + * Gets open_by_default |
|
| 198 | + * |
|
| 199 | + * @return boolean |
|
| 200 | + */ |
|
| 201 | + public function open_by_default() |
|
| 202 | + { |
|
| 203 | + return $this->get('PMD_open_by_default'); |
|
| 204 | + } |
|
| 205 | + |
|
| 206 | + |
|
| 207 | + /** |
|
| 208 | + * Sets open_by_default |
|
| 209 | + * |
|
| 210 | + * @param boolean $open_by_default |
|
| 211 | + */ |
|
| 212 | + public function set_open_by_default($open_by_default) |
|
| 213 | + { |
|
| 214 | + $this->set('PMD_open_by_default', $open_by_default); |
|
| 215 | + } |
|
| 216 | + |
|
| 217 | + |
|
| 218 | + /** |
|
| 219 | + * Gets order |
|
| 220 | + * |
|
| 221 | + * @return int |
|
| 222 | + */ |
|
| 223 | + public function order() |
|
| 224 | + { |
|
| 225 | + return $this->get('PMD_order'); |
|
| 226 | + } |
|
| 227 | + |
|
| 228 | + |
|
| 229 | + /** |
|
| 230 | + * Sets order |
|
| 231 | + * |
|
| 232 | + * @param int $order |
|
| 233 | + */ |
|
| 234 | + public function set_order($order) |
|
| 235 | + { |
|
| 236 | + $this->set('PMD_order', $order); |
|
| 237 | + } |
|
| 238 | + |
|
| 239 | + |
|
| 240 | + /** |
|
| 241 | + * Gets slug |
|
| 242 | + * |
|
| 243 | + * @return string |
|
| 244 | + */ |
|
| 245 | + public function slug() |
|
| 246 | + { |
|
| 247 | + return $this->get('PMD_slug'); |
|
| 248 | + } |
|
| 249 | + |
|
| 250 | + |
|
| 251 | + /** |
|
| 252 | + * Sets slug |
|
| 253 | + * |
|
| 254 | + * @param string $slug |
|
| 255 | + */ |
|
| 256 | + public function set_slug($slug) |
|
| 257 | + { |
|
| 258 | + $this->set('PMD_slug', $slug); |
|
| 259 | + } |
|
| 260 | + |
|
| 261 | + |
|
| 262 | + /** |
|
| 263 | + * Gets type |
|
| 264 | + * |
|
| 265 | + * @return string |
|
| 266 | + */ |
|
| 267 | + public function type() |
|
| 268 | + { |
|
| 269 | + return $this->get('PMD_type'); |
|
| 270 | + } |
|
| 271 | + |
|
| 272 | + |
|
| 273 | + /** |
|
| 274 | + * Sets type |
|
| 275 | + * |
|
| 276 | + * @param string $type |
|
| 277 | + */ |
|
| 278 | + public function set_type($type) |
|
| 279 | + { |
|
| 280 | + $this->set('PMD_type', $type); |
|
| 281 | + } |
|
| 282 | + |
|
| 283 | + |
|
| 284 | + /** |
|
| 285 | + * Gets wp_user |
|
| 286 | + * |
|
| 287 | + * @return int |
|
| 288 | + */ |
|
| 289 | + public function wp_user() |
|
| 290 | + { |
|
| 291 | + return $this->get('PMD_wp_user'); |
|
| 292 | + } |
|
| 293 | + |
|
| 294 | + |
|
| 295 | + /** |
|
| 296 | + * Sets wp_user |
|
| 297 | + * |
|
| 298 | + * @param int $wp_user_id |
|
| 299 | + */ |
|
| 300 | + public function set_wp_user($wp_user_id) |
|
| 301 | + { |
|
| 302 | + $this->set('PMD_wp_user', $wp_user_id); |
|
| 303 | + } |
|
| 304 | + |
|
| 305 | + /** |
|
| 306 | + * Overrides parent so when PMD_type is changed we refresh the _type_obj |
|
| 307 | + * |
|
| 308 | + * @param string $field_name |
|
| 309 | + * @param mixed $field_value |
|
| 310 | + * @param boolean $use_default |
|
| 311 | + */ |
|
| 312 | + public function set($field_name, $field_value, $use_default = false) |
|
| 313 | + { |
|
| 314 | + if ($field_name === 'PMD_type') { |
|
| 315 | + // the type has probably changed, so forget about its old type object |
|
| 316 | + $this->_type_obj = null; |
|
| 317 | + } |
|
| 318 | + parent::set($field_name, $field_value, $use_default); |
|
| 319 | + } |
|
| 320 | + |
|
| 321 | + |
|
| 322 | + /** |
|
| 323 | + * Gets admin_name |
|
| 324 | + * |
|
| 325 | + * @return string |
|
| 326 | + */ |
|
| 327 | + public function admin_name() |
|
| 328 | + { |
|
| 329 | + return $this->get('PMD_admin_name'); |
|
| 330 | + } |
|
| 331 | + |
|
| 332 | + |
|
| 333 | + /** |
|
| 334 | + * Sets admin_name |
|
| 335 | + * |
|
| 336 | + * @param string $admin_name |
|
| 337 | + */ |
|
| 338 | + public function set_admin_name($admin_name) |
|
| 339 | + { |
|
| 340 | + $this->set('PMD_admin_name', $admin_name); |
|
| 341 | + } |
|
| 342 | + |
|
| 343 | + |
|
| 344 | + /** |
|
| 345 | + * Gets admin_desc |
|
| 346 | + * |
|
| 347 | + * @return string |
|
| 348 | + */ |
|
| 349 | + public function admin_desc() |
|
| 350 | + { |
|
| 351 | + return $this->get('PMD_admin_desc'); |
|
| 352 | + } |
|
| 353 | + |
|
| 354 | + |
|
| 355 | + /** |
|
| 356 | + * Sets admin_desc |
|
| 357 | + * |
|
| 358 | + * @param string $admin_desc |
|
| 359 | + */ |
|
| 360 | + public function set_admin_desc($admin_desc) |
|
| 361 | + { |
|
| 362 | + $this->set('PMD_admin_desc', $admin_desc); |
|
| 363 | + } |
|
| 364 | + |
|
| 365 | + |
|
| 366 | + /** |
|
| 367 | + * Gets scope |
|
| 368 | + * |
|
| 369 | + * @return array |
|
| 370 | + */ |
|
| 371 | + public function scope() |
|
| 372 | + { |
|
| 373 | + return $this->get('PMD_scope'); |
|
| 374 | + } |
|
| 375 | + |
|
| 376 | + |
|
| 377 | + /** |
|
| 378 | + * Sets scope |
|
| 379 | + * |
|
| 380 | + * @param array $scope |
|
| 381 | + */ |
|
| 382 | + public function set_scope($scope) |
|
| 383 | + { |
|
| 384 | + $this->set('PMD_scope', $scope); |
|
| 385 | + } |
|
| 386 | + |
|
| 387 | + |
|
| 388 | + /** |
|
| 389 | + * Gets the payment method type for this payment method instance |
|
| 390 | + * |
|
| 391 | + * @return EE_PMT_Base |
|
| 392 | + * @throws EE_Error |
|
| 393 | + */ |
|
| 394 | + public function type_obj() |
|
| 395 | + { |
|
| 396 | + if (! $this->_type_obj) { |
|
| 397 | + EE_Registry::instance()->load_lib('Payment_Method_Manager'); |
|
| 398 | + if (EE_Payment_Method_Manager::instance()->payment_method_type_exists($this->type())) { |
|
| 399 | + $class_name = EE_Payment_Method_Manager::instance()->payment_method_class_from_type($this->type()); |
|
| 400 | + if (! class_exists($class_name)) { |
|
| 401 | + throw new EE_Error( |
|
| 402 | + sprintf( |
|
| 403 | + esc_html__( |
|
| 404 | + 'An attempt to use the "%1$s" payment method failed, so it was deactivated.%2$sWas the "%1$s" Plugin recently deactivated? It can be reactivated on the %3$sPlugins Admin Page%4$s', |
|
| 405 | + 'event_espresso' |
|
| 406 | + ), |
|
| 407 | + $class_name, |
|
| 408 | + '<br />', |
|
| 409 | + '<a href="' . admin_url('plugins.php') . '">', |
|
| 410 | + '</a>' |
|
| 411 | + ) |
|
| 412 | + ); |
|
| 413 | + } |
|
| 414 | + $r = new ReflectionClass($class_name); |
|
| 415 | + $this->_type_obj = $r->newInstanceArgs(array($this)); |
|
| 416 | + } else { |
|
| 417 | + throw new EE_Error( |
|
| 418 | + sprintf( |
|
| 419 | + esc_html__( |
|
| 420 | + 'A payment method of type "%1$s" does not exist. Only ones existing are: %2$s', |
|
| 421 | + 'event_espresso' |
|
| 422 | + ), |
|
| 423 | + $this->type(), |
|
| 424 | + implode(',', EE_Payment_Method_Manager::instance()->payment_method_type_names()) |
|
| 425 | + ) |
|
| 426 | + ); |
|
| 427 | + } |
|
| 428 | + } |
|
| 429 | + return $this->_type_obj; |
|
| 430 | + } |
|
| 431 | + |
|
| 432 | + |
|
| 433 | + /** |
|
| 434 | + * Returns a simple array of key-value pairs combining the payment method's fields (without the 'PMD_' prefix) |
|
| 435 | + * and the extra meta. Mostly used for passing off ot gateways. * |
|
| 436 | + * |
|
| 437 | + * @return array |
|
| 438 | + */ |
|
| 439 | + public function settings_array() |
|
| 440 | + { |
|
| 441 | + $fields = $this->model_field_array(); |
|
| 442 | + $extra_meta = $this->all_extra_meta_array(); |
|
| 443 | + // remove the model's prefix from the fields |
|
| 444 | + $combined_settings_array = array(); |
|
| 445 | + foreach ($fields as $key => $value) { |
|
| 446 | + if (strpos($key, 'PMD_') === 0) { |
|
| 447 | + $key_sans_model_prefix = str_replace('PMD_', '', $key); |
|
| 448 | + $combined_settings_array [ $key_sans_model_prefix ] = $value; |
|
| 449 | + } |
|
| 450 | + } |
|
| 451 | + $combined_settings_array = array_merge($extra_meta, $combined_settings_array); |
|
| 452 | + return $combined_settings_array; |
|
| 453 | + } |
|
| 454 | + |
|
| 455 | + |
|
| 456 | + /** |
|
| 457 | + * Gets the HTML for displaying the payment method on a page. |
|
| 458 | + * |
|
| 459 | + * @param string $url |
|
| 460 | + * @param string $css_class |
|
| 461 | + * @return string of HTML for displaying the button |
|
| 462 | + * @throws \EE_Error |
|
| 463 | + */ |
|
| 464 | + public function button_html($url = '', $css_class = '') |
|
| 465 | + { |
|
| 466 | + $payment_occurs = $this->type_obj()->payment_occurs(); |
|
| 467 | + return ' |
|
| 468 | 468 | <div id="' |
| 469 | - . $this->slug() |
|
| 470 | - . '-payment-option-dv" class="' |
|
| 471 | - . $payment_occurs . '-payment-gateway reg-page-payment-option-dv' . $css_class . '"> |
|
| 469 | + . $this->slug() |
|
| 470 | + . '-payment-option-dv" class="' |
|
| 471 | + . $payment_occurs . '-payment-gateway reg-page-payment-option-dv' . $css_class . '"> |
|
| 472 | 472 | <a id="payment-gateway-button-' . $this->slug() |
| 473 | - . '" class="reg-page-payment-option-lnk" rel="' |
|
| 474 | - . $this->slug() . '" href="' . $url . '" > |
|
| 473 | + . '" class="reg-page-payment-option-lnk" rel="' |
|
| 474 | + . $this->slug() . '" href="' . $url . '" > |
|
| 475 | 475 | <img src="' . $this->button_url() . '" alt="' . sprintf( |
| 476 | - esc_attr__('Pay using %s', 'event_espresso'), |
|
| 477 | - $this->get_pretty('PMD_name', 'form_input') |
|
| 478 | - ) . '" /> |
|
| 476 | + esc_attr__('Pay using %s', 'event_espresso'), |
|
| 477 | + $this->get_pretty('PMD_name', 'form_input') |
|
| 478 | + ) . '" /> |
|
| 479 | 479 | </a> |
| 480 | 480 | </div> |
| 481 | 481 | '; |
| 482 | - } |
|
| 483 | - |
|
| 484 | - |
|
| 485 | - /** |
|
| 486 | - * Gets all the currencies which are an option for this payment method |
|
| 487 | - * (as defined by the gateway and the currently active currencies) |
|
| 488 | - * |
|
| 489 | - * @return EE_Currency[] |
|
| 490 | - * @throws \EE_Error |
|
| 491 | - */ |
|
| 492 | - public function get_all_usable_currencies() |
|
| 493 | - { |
|
| 494 | - return EEM_Currency::instance()->get_all_currencies_usable_by($this->type_obj()); |
|
| 495 | - } |
|
| 496 | - |
|
| 497 | - |
|
| 498 | - /** |
|
| 499 | - * Reports whether or not this payment method can be used for this payment method |
|
| 500 | - * |
|
| 501 | - * @param string $currency_code currency ID (code) |
|
| 502 | - * @return boolean |
|
| 503 | - * @throws \EE_Error |
|
| 504 | - */ |
|
| 505 | - public function usable_for_currency($currency_code) |
|
| 506 | - { |
|
| 507 | - foreach ($this->get_all_usable_currencies() as $currency_obj) { |
|
| 508 | - if ($currency_obj->ID() === $currency_code) { |
|
| 509 | - return true; |
|
| 510 | - } |
|
| 511 | - } |
|
| 512 | - return false; |
|
| 513 | - } |
|
| 514 | - |
|
| 515 | - |
|
| 516 | - /** |
|
| 517 | - * Returns TRUE if this payment method's gateway is an instance of EE_Onsite_Gateway |
|
| 518 | - * |
|
| 519 | - * @return bool |
|
| 520 | - * @throws \EE_Error |
|
| 521 | - */ |
|
| 522 | - public function is_on_site() |
|
| 523 | - { |
|
| 524 | - return $this->type_obj()->payment_occurs() === EE_PMT_Base::onsite; |
|
| 525 | - } |
|
| 526 | - |
|
| 527 | - |
|
| 528 | - /** |
|
| 529 | - * Returns TRUE if this payment method's gateway is an instance of EE_Offsite_Gateway |
|
| 530 | - * |
|
| 531 | - * @return bool |
|
| 532 | - * @throws \EE_Error |
|
| 533 | - */ |
|
| 534 | - public function is_off_site() |
|
| 535 | - { |
|
| 536 | - return $this->type_obj()->payment_occurs() === EE_PMT_Base::offsite; |
|
| 537 | - } |
|
| 538 | - |
|
| 539 | - |
|
| 540 | - /** |
|
| 541 | - * Returns TRUE if this payment method does not utilize a gateway |
|
| 542 | - * |
|
| 543 | - * @return bool |
|
| 544 | - * @throws \EE_Error |
|
| 545 | - */ |
|
| 546 | - public function is_off_line() |
|
| 547 | - { |
|
| 548 | - return $this->type_obj()->payment_occurs() === EE_PMT_Base::offline; |
|
| 549 | - } |
|
| 550 | - |
|
| 551 | - /** |
|
| 552 | - * Overrides default __sleep so the object type is NOT cached. |
|
| 553 | - * This way we can rely on the normal EE_Payment_Method::type_obj() logic |
|
| 554 | - * to load the required classes, and don't need them at the time of unserialization |
|
| 555 | - * |
|
| 556 | - * @return array |
|
| 557 | - */ |
|
| 558 | - public function __sleep() |
|
| 559 | - { |
|
| 560 | - $properties = get_object_vars($this); |
|
| 561 | - unset($properties['_type_obj']); |
|
| 562 | - return array_keys($properties); |
|
| 563 | - } |
|
| 564 | - |
|
| 565 | - |
|
| 566 | - /** |
|
| 567 | - * Overrides parent to add some logging for when payment methods get deactivated |
|
| 568 | - * |
|
| 569 | - * @param array $set_cols_n_values |
|
| 570 | - * @return int @see EE_Base_Class::save() |
|
| 571 | - * @throws \EE_Error |
|
| 572 | - */ |
|
| 573 | - public function save($set_cols_n_values = array()) |
|
| 574 | - { |
|
| 575 | - $results = parent::save($set_cols_n_values); |
|
| 576 | - if ($this->get_original('PMD_scope') !== $this->get('PMD_scope')) { |
|
| 577 | - /** @var CurrentPage $current_page */ |
|
| 578 | - $current_page = LoaderFactory::getLoader()->getShared(CurrentPage::class); |
|
| 579 | - EE_Log::instance()->log( |
|
| 580 | - __FILE__, |
|
| 581 | - __FUNCTION__, |
|
| 582 | - sprintf( |
|
| 583 | - esc_html__('Set new scope on payment method %1$s to %2$s from %3$s on URL %4$s', 'event_espresso'), |
|
| 584 | - $this->name(), |
|
| 585 | - serialize($this->get_original('PMD_scope')), |
|
| 586 | - serialize($this->get('PMD_scope')), |
|
| 587 | - $current_page->getPermalink() |
|
| 588 | - ), |
|
| 589 | - 'payment_method_change' |
|
| 590 | - ); |
|
| 591 | - } |
|
| 592 | - return $results; |
|
| 593 | - } |
|
| 482 | + } |
|
| 483 | + |
|
| 484 | + |
|
| 485 | + /** |
|
| 486 | + * Gets all the currencies which are an option for this payment method |
|
| 487 | + * (as defined by the gateway and the currently active currencies) |
|
| 488 | + * |
|
| 489 | + * @return EE_Currency[] |
|
| 490 | + * @throws \EE_Error |
|
| 491 | + */ |
|
| 492 | + public function get_all_usable_currencies() |
|
| 493 | + { |
|
| 494 | + return EEM_Currency::instance()->get_all_currencies_usable_by($this->type_obj()); |
|
| 495 | + } |
|
| 496 | + |
|
| 497 | + |
|
| 498 | + /** |
|
| 499 | + * Reports whether or not this payment method can be used for this payment method |
|
| 500 | + * |
|
| 501 | + * @param string $currency_code currency ID (code) |
|
| 502 | + * @return boolean |
|
| 503 | + * @throws \EE_Error |
|
| 504 | + */ |
|
| 505 | + public function usable_for_currency($currency_code) |
|
| 506 | + { |
|
| 507 | + foreach ($this->get_all_usable_currencies() as $currency_obj) { |
|
| 508 | + if ($currency_obj->ID() === $currency_code) { |
|
| 509 | + return true; |
|
| 510 | + } |
|
| 511 | + } |
|
| 512 | + return false; |
|
| 513 | + } |
|
| 514 | + |
|
| 515 | + |
|
| 516 | + /** |
|
| 517 | + * Returns TRUE if this payment method's gateway is an instance of EE_Onsite_Gateway |
|
| 518 | + * |
|
| 519 | + * @return bool |
|
| 520 | + * @throws \EE_Error |
|
| 521 | + */ |
|
| 522 | + public function is_on_site() |
|
| 523 | + { |
|
| 524 | + return $this->type_obj()->payment_occurs() === EE_PMT_Base::onsite; |
|
| 525 | + } |
|
| 526 | + |
|
| 527 | + |
|
| 528 | + /** |
|
| 529 | + * Returns TRUE if this payment method's gateway is an instance of EE_Offsite_Gateway |
|
| 530 | + * |
|
| 531 | + * @return bool |
|
| 532 | + * @throws \EE_Error |
|
| 533 | + */ |
|
| 534 | + public function is_off_site() |
|
| 535 | + { |
|
| 536 | + return $this->type_obj()->payment_occurs() === EE_PMT_Base::offsite; |
|
| 537 | + } |
|
| 538 | + |
|
| 539 | + |
|
| 540 | + /** |
|
| 541 | + * Returns TRUE if this payment method does not utilize a gateway |
|
| 542 | + * |
|
| 543 | + * @return bool |
|
| 544 | + * @throws \EE_Error |
|
| 545 | + */ |
|
| 546 | + public function is_off_line() |
|
| 547 | + { |
|
| 548 | + return $this->type_obj()->payment_occurs() === EE_PMT_Base::offline; |
|
| 549 | + } |
|
| 550 | + |
|
| 551 | + /** |
|
| 552 | + * Overrides default __sleep so the object type is NOT cached. |
|
| 553 | + * This way we can rely on the normal EE_Payment_Method::type_obj() logic |
|
| 554 | + * to load the required classes, and don't need them at the time of unserialization |
|
| 555 | + * |
|
| 556 | + * @return array |
|
| 557 | + */ |
|
| 558 | + public function __sleep() |
|
| 559 | + { |
|
| 560 | + $properties = get_object_vars($this); |
|
| 561 | + unset($properties['_type_obj']); |
|
| 562 | + return array_keys($properties); |
|
| 563 | + } |
|
| 564 | + |
|
| 565 | + |
|
| 566 | + /** |
|
| 567 | + * Overrides parent to add some logging for when payment methods get deactivated |
|
| 568 | + * |
|
| 569 | + * @param array $set_cols_n_values |
|
| 570 | + * @return int @see EE_Base_Class::save() |
|
| 571 | + * @throws \EE_Error |
|
| 572 | + */ |
|
| 573 | + public function save($set_cols_n_values = array()) |
|
| 574 | + { |
|
| 575 | + $results = parent::save($set_cols_n_values); |
|
| 576 | + if ($this->get_original('PMD_scope') !== $this->get('PMD_scope')) { |
|
| 577 | + /** @var CurrentPage $current_page */ |
|
| 578 | + $current_page = LoaderFactory::getLoader()->getShared(CurrentPage::class); |
|
| 579 | + EE_Log::instance()->log( |
|
| 580 | + __FILE__, |
|
| 581 | + __FUNCTION__, |
|
| 582 | + sprintf( |
|
| 583 | + esc_html__('Set new scope on payment method %1$s to %2$s from %3$s on URL %4$s', 'event_espresso'), |
|
| 584 | + $this->name(), |
|
| 585 | + serialize($this->get_original('PMD_scope')), |
|
| 586 | + serialize($this->get('PMD_scope')), |
|
| 587 | + $current_page->getPermalink() |
|
| 588 | + ), |
|
| 589 | + 'payment_method_change' |
|
| 590 | + ); |
|
| 591 | + } |
|
| 592 | + return $results; |
|
| 593 | + } |
|
| 594 | 594 | } |
@@ -126,7 +126,7 @@ discard block |
||
| 126 | 126 | self::priority_low => esc_html__('low', 'event_espresso'), |
| 127 | 127 | ); |
| 128 | 128 | |
| 129 | - $this->_fields = array( |
|
| 129 | + $this->_fields = array( |
|
| 130 | 130 | 'Message' => array( |
| 131 | 131 | 'MSG_ID' => new EE_Primary_Key_Int_Field('MSG_ID', esc_html__('Message ID', 'event_espresso')), |
| 132 | 132 | 'MSG_token' => new EE_Plain_Text_Field( |
@@ -436,7 +436,7 @@ discard block |
||
| 436 | 436 | ); |
| 437 | 437 | break; |
| 438 | 438 | default: |
| 439 | - $query_params[0]['AND**filter_by'][ 'OR**filter_by_' . $request_key ][ $model_name . '.' . $request_key ] = $request_value; |
|
| 439 | + $query_params[0]['AND**filter_by']['OR**filter_by_'.$request_key][$model_name.'.'.$request_key] = $request_value; |
|
| 440 | 440 | break; |
| 441 | 441 | } |
| 442 | 442 | } |
@@ -499,8 +499,8 @@ discard block |
||
| 499 | 499 | if ($label_parts) { |
| 500 | 500 | // prepend to the last element of $label_parts an "and". |
| 501 | 501 | if (count($label_parts) > 1) { |
| 502 | - $label_parts_index_to_prepend = count($label_parts) - 1; |
|
| 503 | - $label_parts[ $label_parts_index_to_prepend ] = 'and' . $label_parts[ $label_parts_index_to_prepend ]; |
|
| 502 | + $label_parts_index_to_prepend = count($label_parts) - 1; |
|
| 503 | + $label_parts[$label_parts_index_to_prepend] = 'and'.$label_parts[$label_parts_index_to_prepend]; |
|
| 504 | 504 | } |
| 505 | 505 | |
| 506 | 506 | $pretty_label .= sprintf( |
@@ -560,7 +560,7 @@ discard block |
||
| 560 | 560 | $is_debugging = defined('EE_DEBUG_MESSAGES') && EE_DEBUG_MESSAGES; |
| 561 | 561 | } |
| 562 | 562 | |
| 563 | - if (! is_null($set_debug)) { |
|
| 563 | + if ( ! is_null($set_debug)) { |
|
| 564 | 564 | $is_debugging = filter_var($set_debug, FILTER_VALIDATE_BOOLEAN); |
| 565 | 565 | } |
| 566 | 566 | |
@@ -627,13 +627,13 @@ discard block |
||
| 627 | 627 | ) |
| 628 | 628 | ); |
| 629 | 629 | |
| 630 | - if (! empty($message_ids_to_delete) && is_array($message_ids_to_delete)) { |
|
| 630 | + if ( ! empty($message_ids_to_delete) && is_array($message_ids_to_delete)) { |
|
| 631 | 631 | global $wpdb; |
| 632 | 632 | $number_deleted = $wpdb->query(' |
| 633 | 633 | DELETE |
| 634 | - FROM ' . $this->table() . ' |
|
| 634 | + FROM ' . $this->table().' |
|
| 635 | 635 | WHERE |
| 636 | - MSG_ID IN (' . implode(",", $message_ids_to_delete) . ') |
|
| 636 | + MSG_ID IN (' . implode(",", $message_ids_to_delete).') |
|
| 637 | 637 | '); |
| 638 | 638 | } |
| 639 | 639 | |
@@ -12,649 +12,649 @@ |
||
| 12 | 12 | */ |
| 13 | 13 | class EEM_Message extends EEM_Base implements EEI_Query_Filter |
| 14 | 14 | { |
| 15 | - // private instance of the Message object |
|
| 16 | - protected static $_instance = null; |
|
| 17 | - |
|
| 18 | - |
|
| 19 | - /** |
|
| 20 | - * This priority indicates a message should be generated and sent ASAP |
|
| 21 | - * |
|
| 22 | - * @type int |
|
| 23 | - */ |
|
| 24 | - const priority_high = 10; |
|
| 25 | - |
|
| 26 | - |
|
| 27 | - /** |
|
| 28 | - * This priority indicates a message should be generated ASAP and queued for sending. |
|
| 29 | - * |
|
| 30 | - * @type |
|
| 31 | - */ |
|
| 32 | - const priority_medium = 20; |
|
| 33 | - |
|
| 34 | - |
|
| 35 | - /** |
|
| 36 | - * This priority indicates a message should be queued for generating. |
|
| 37 | - * |
|
| 38 | - * @type int |
|
| 39 | - */ |
|
| 40 | - const priority_low = 30; |
|
| 41 | - |
|
| 42 | - |
|
| 43 | - /** |
|
| 44 | - * indicates this message was sent at the time modified |
|
| 45 | - */ |
|
| 46 | - const status_sent = 'MSN'; |
|
| 47 | - |
|
| 48 | - |
|
| 49 | - /** |
|
| 50 | - * indicates this message is waiting to be sent |
|
| 51 | - */ |
|
| 52 | - const status_idle = 'MID'; |
|
| 53 | - |
|
| 54 | - |
|
| 55 | - /** |
|
| 56 | - * indicates an attempt was a made to send this message |
|
| 57 | - * at the scheduled time, but it failed at the time modified. This differs from MDO status in that it will ALWAYS |
|
| 58 | - * appear to the end user. |
|
| 59 | - */ |
|
| 60 | - const status_failed = 'MFL'; |
|
| 61 | - |
|
| 62 | - |
|
| 63 | - /** |
|
| 64 | - * indicates the message has been flagged for resending (at the time modified). |
|
| 65 | - */ |
|
| 66 | - const status_resend = 'MRS'; |
|
| 67 | - |
|
| 68 | - |
|
| 69 | - /** |
|
| 70 | - * indicates the message has been flagged for generation but has not been generated yet. Messages always start as |
|
| 71 | - * this status when added to the queue. |
|
| 72 | - */ |
|
| 73 | - const status_incomplete = 'MIC'; |
|
| 74 | - |
|
| 75 | - |
|
| 76 | - /** |
|
| 77 | - * Indicates everything was generated fine for the message, however, the messenger was unable to send. |
|
| 78 | - * This status means that its possible to retry sending the message. |
|
| 79 | - */ |
|
| 80 | - const status_retry = 'MRT'; |
|
| 81 | - |
|
| 82 | - |
|
| 83 | - /** |
|
| 84 | - * This is used for more informational messages that may not indicate anything is broken but still cannot be |
|
| 85 | - * generated or sent correctly. An example of a message that would get flagged this way would be when a not |
|
| 86 | - * approved message was queued for generation, but at time of generation, the attached registration(s) are |
|
| 87 | - * approved. So the message queued for generation is no longer valid. Messages for this status will only persist |
|
| 88 | - * in the db and be viewable in the message activity list table when the messages system is in debug mode. |
|
| 89 | - * |
|
| 90 | - * @see EEM_Message::debug() |
|
| 91 | - */ |
|
| 92 | - const status_debug_only = 'MDO'; |
|
| 93 | - |
|
| 94 | - |
|
| 95 | - /** |
|
| 96 | - * This status is given to messages it is processed by the messenger send method. |
|
| 97 | - * Messages with this status should rarely be seen in the Message List table, but if they are, that's usually |
|
| 98 | - * indicative of a PHP timeout or memory limit issue. |
|
| 99 | - */ |
|
| 100 | - const status_messenger_executing = 'MEX'; |
|
| 101 | - |
|
| 102 | - |
|
| 103 | - /** |
|
| 104 | - * Private constructor to prevent direct creation. |
|
| 105 | - * |
|
| 106 | - * @param string $timezone string representing the timezone we want to set for returned Date Time Strings (and |
|
| 107 | - * any incoming timezone data that gets saved). Note this just sends the timezone info to |
|
| 108 | - * the date time model field objects. Default is null (and will be assumed using the set |
|
| 109 | - * timezone in the 'timezone_string' wp option) |
|
| 110 | - * @throws EE_Error |
|
| 111 | - * @throws EE_Error |
|
| 112 | - * @throws EE_Error |
|
| 113 | - */ |
|
| 114 | - protected function __construct($timezone = null) |
|
| 115 | - { |
|
| 116 | - $this->singular_item = esc_html__('Message', 'event_espresso'); |
|
| 117 | - $this->plural_item = esc_html__('Messages', 'event_espresso'); |
|
| 118 | - |
|
| 119 | - $this->_tables = array( |
|
| 120 | - 'Message' => new EE_Primary_Table('esp_message', 'MSG_ID'), |
|
| 121 | - ); |
|
| 122 | - |
|
| 123 | - $allowed_priority = array( |
|
| 124 | - self::priority_high => esc_html__('high', 'event_espresso'), |
|
| 125 | - self::priority_medium => esc_html__('medium', 'event_espresso'), |
|
| 126 | - self::priority_low => esc_html__('low', 'event_espresso'), |
|
| 127 | - ); |
|
| 128 | - |
|
| 129 | - $this->_fields = array( |
|
| 130 | - 'Message' => array( |
|
| 131 | - 'MSG_ID' => new EE_Primary_Key_Int_Field('MSG_ID', esc_html__('Message ID', 'event_espresso')), |
|
| 132 | - 'MSG_token' => new EE_Plain_Text_Field( |
|
| 133 | - 'MSG_token', |
|
| 134 | - esc_html__( |
|
| 135 | - 'Unique Token used to represent this row in publicly viewable contexts (eg. a url).', |
|
| 136 | - 'event_espresso' |
|
| 137 | - ), |
|
| 138 | - false, |
|
| 139 | - EEH_URL::generate_unique_token() |
|
| 140 | - ), |
|
| 141 | - 'GRP_ID' => new EE_Foreign_Key_Int_Field( |
|
| 142 | - 'GRP_ID', |
|
| 143 | - esc_html__('Foreign key to the EEM_Message_Template_Group table.', 'event_espresso'), |
|
| 144 | - true, |
|
| 145 | - 0, |
|
| 146 | - 'Message_Template_Group' |
|
| 147 | - ), |
|
| 148 | - 'TXN_ID' => new EE_Foreign_Key_Int_Field( |
|
| 149 | - 'TXN_ID', |
|
| 150 | - esc_html__( |
|
| 151 | - 'Foreign key to the related EE_Transaction. This is required to give context for regenerating the specific message', |
|
| 152 | - 'event_espresso' |
|
| 153 | - ), |
|
| 154 | - true, |
|
| 155 | - 0, |
|
| 156 | - 'Transaction' |
|
| 157 | - ), |
|
| 158 | - 'MSG_messenger' => new EE_Plain_Text_Field( |
|
| 159 | - 'MSG_messenger', |
|
| 160 | - esc_html__( |
|
| 161 | - 'Corresponds to the EE_messenger::name used to send this message. This will also be used to attempt any resending of the message.', |
|
| 162 | - 'event_espresso' |
|
| 163 | - ), |
|
| 164 | - false, |
|
| 165 | - 'email' |
|
| 166 | - ), |
|
| 167 | - 'MSG_message_type' => new EE_Plain_Text_Field( |
|
| 168 | - 'MSG_message_type', |
|
| 169 | - esc_html__('Corresponds to the EE_message_type::name used to generate this message.', 'event_espresso'), |
|
| 170 | - false, |
|
| 171 | - 'receipt' |
|
| 172 | - ), |
|
| 173 | - 'MSG_context' => new EE_Plain_Text_Field('MSG_context', esc_html__('Context', 'event_espresso'), false), |
|
| 174 | - 'MSG_recipient_ID' => new EE_Foreign_Key_Int_Field( |
|
| 175 | - 'MSG_recipient_ID', |
|
| 176 | - esc_html__('Recipient ID', 'event_espresso'), |
|
| 177 | - true, |
|
| 178 | - null, |
|
| 179 | - array('Registration', 'Attendee', 'WP_User') |
|
| 180 | - ), |
|
| 181 | - 'MSG_recipient_type' => new EE_Any_Foreign_Model_Name_Field( |
|
| 182 | - 'MSG_recipient_type', |
|
| 183 | - esc_html__('Recipient Type', 'event_espresso'), |
|
| 184 | - true, |
|
| 185 | - null, |
|
| 186 | - array('Registration', 'Attendee', 'WP_User') |
|
| 187 | - ), |
|
| 188 | - 'MSG_content' => new EE_Maybe_Serialized_Text_Field( |
|
| 189 | - 'MSG_content', |
|
| 190 | - esc_html__('Content', 'event_espresso'), |
|
| 191 | - true, |
|
| 192 | - '' |
|
| 193 | - ), |
|
| 194 | - 'MSG_to' => new EE_Maybe_Serialized_Text_Field( |
|
| 195 | - 'MSG_to', |
|
| 196 | - esc_html__('Address To', 'event_espresso'), |
|
| 197 | - true |
|
| 198 | - ), |
|
| 199 | - 'MSG_from' => new EE_Maybe_Serialized_Text_Field( |
|
| 200 | - 'MSG_from', |
|
| 201 | - esc_html__('Address From', 'event_espresso'), |
|
| 202 | - true |
|
| 203 | - ), |
|
| 204 | - 'MSG_subject' => new EE_Maybe_Serialized_Text_Field( |
|
| 205 | - 'MSG_subject', |
|
| 206 | - esc_html__('Subject', 'event_espresso'), |
|
| 207 | - true, |
|
| 208 | - '' |
|
| 209 | - ), |
|
| 210 | - 'MSG_priority' => new EE_Enum_Integer_Field( |
|
| 211 | - 'MSG_priority', |
|
| 212 | - esc_html__('Priority', 'event_espresso'), |
|
| 213 | - false, |
|
| 214 | - self::priority_low, |
|
| 215 | - $allowed_priority |
|
| 216 | - ), |
|
| 217 | - 'STS_ID' => new EE_Foreign_Key_String_Field( |
|
| 218 | - 'STS_ID', |
|
| 219 | - esc_html__('Status', 'event_espresso'), |
|
| 220 | - false, |
|
| 221 | - self::status_incomplete, |
|
| 222 | - 'Status' |
|
| 223 | - ), |
|
| 224 | - 'MSG_created' => new EE_Datetime_Field( |
|
| 225 | - 'MSG_created', |
|
| 226 | - esc_html__('Created', 'event_espresso'), |
|
| 227 | - false, |
|
| 228 | - EE_Datetime_Field::now |
|
| 229 | - ), |
|
| 230 | - 'MSG_modified' => new EE_Datetime_Field( |
|
| 231 | - 'MSG_modified', |
|
| 232 | - esc_html__('Modified', 'event_espresso'), |
|
| 233 | - true, |
|
| 234 | - EE_Datetime_Field::now |
|
| 235 | - ), |
|
| 236 | - ), |
|
| 237 | - ); |
|
| 238 | - $this->_model_relations = array( |
|
| 239 | - 'Attendee' => new EE_Belongs_To_Any_Relation(), |
|
| 240 | - 'Registration' => new EE_Belongs_To_Any_Relation(), |
|
| 241 | - 'WP_User' => new EE_Belongs_To_Any_Relation(), |
|
| 242 | - 'Message_Template_Group' => new EE_Belongs_To_Relation(), |
|
| 243 | - 'Transaction' => new EE_Belongs_To_Relation(), |
|
| 244 | - ); |
|
| 245 | - parent::__construct($timezone); |
|
| 246 | - } |
|
| 247 | - |
|
| 248 | - |
|
| 249 | - /** |
|
| 250 | - * @return EE_Message |
|
| 251 | - * @throws EE_Error |
|
| 252 | - */ |
|
| 253 | - public function create_default_object() |
|
| 254 | - { |
|
| 255 | - /** @type EE_Message $message */ |
|
| 256 | - $message = parent::create_default_object(); |
|
| 257 | - if ($message instanceof EE_Message) { |
|
| 258 | - return EE_Message_Factory::set_messenger_and_message_type($message); |
|
| 259 | - } |
|
| 260 | - return null; |
|
| 261 | - } |
|
| 262 | - |
|
| 263 | - |
|
| 264 | - /** |
|
| 265 | - * @param mixed $cols_n_values |
|
| 266 | - * @return EE_Message |
|
| 267 | - * @throws EE_Error |
|
| 268 | - * @throws EE_Error |
|
| 269 | - */ |
|
| 270 | - public function instantiate_class_from_array_or_object($cols_n_values) |
|
| 271 | - { |
|
| 272 | - /** @type EE_Message $message */ |
|
| 273 | - $message = parent::instantiate_class_from_array_or_object($cols_n_values); |
|
| 274 | - if ($message instanceof EE_Message) { |
|
| 275 | - return EE_Message_Factory::set_messenger_and_message_type($message); |
|
| 276 | - } |
|
| 277 | - return null; |
|
| 278 | - } |
|
| 279 | - |
|
| 280 | - |
|
| 281 | - /** |
|
| 282 | - * Returns whether or not a message of that type was sent for a given attendee. |
|
| 283 | - * |
|
| 284 | - * @param EE_Attendee|int $attendee |
|
| 285 | - * @param string $message_type the message type slug |
|
| 286 | - * @return boolean |
|
| 287 | - * @throws EE_Error |
|
| 288 | - * @throws EE_Error |
|
| 289 | - * @throws EE_Error |
|
| 290 | - */ |
|
| 291 | - public function message_sent_for_attendee($attendee, $message_type) |
|
| 292 | - { |
|
| 293 | - $attendee_ID = EEM_Attendee::instance()->ensure_is_ID($attendee); |
|
| 294 | - return $this->exists(array( |
|
| 295 | - array( |
|
| 296 | - 'Attendee.ATT_ID' => $attendee_ID, |
|
| 297 | - 'MSG_message_type' => $message_type, |
|
| 298 | - 'STS_ID' => array('IN', $this->stati_indicating_sent()), |
|
| 299 | - ), |
|
| 300 | - )); |
|
| 301 | - } |
|
| 302 | - |
|
| 303 | - |
|
| 304 | - /** |
|
| 305 | - * Returns whether or not a message of that type was sent for a given registration |
|
| 306 | - * |
|
| 307 | - * @param EE_Registration|int $registration |
|
| 308 | - * @param string $message_type the message type slug |
|
| 309 | - * @return boolean |
|
| 310 | - * @throws EE_Error |
|
| 311 | - * @throws EE_Error |
|
| 312 | - * @throws EE_Error |
|
| 313 | - */ |
|
| 314 | - public function message_sent_for_registration($registration, $message_type) |
|
| 315 | - { |
|
| 316 | - $registrationID = EEM_Registration::instance()->ensure_is_ID($registration); |
|
| 317 | - return $this->exists(array( |
|
| 318 | - array( |
|
| 319 | - 'Registration.REG_ID' => $registrationID, |
|
| 320 | - 'MSG_message_type' => $message_type, |
|
| 321 | - 'STS_ID' => array('IN', $this->stati_indicating_sent()), |
|
| 322 | - ), |
|
| 323 | - )); |
|
| 324 | - } |
|
| 325 | - |
|
| 326 | - |
|
| 327 | - /** |
|
| 328 | - * This retrieves an EE_Message object from the db matching the given token string. |
|
| 329 | - * |
|
| 330 | - * @param string $token |
|
| 331 | - * @return EE_Message |
|
| 332 | - * @throws EE_Error |
|
| 333 | - */ |
|
| 334 | - public function get_one_by_token($token) |
|
| 335 | - { |
|
| 336 | - return $this->get_one(array( |
|
| 337 | - array( |
|
| 338 | - 'MSG_token' => $token, |
|
| 339 | - ), |
|
| 340 | - )); |
|
| 341 | - } |
|
| 342 | - |
|
| 343 | - |
|
| 344 | - /** |
|
| 345 | - * Returns stati that indicate the message HAS been sent |
|
| 346 | - * |
|
| 347 | - * @return array of strings for possible stati |
|
| 348 | - */ |
|
| 349 | - public function stati_indicating_sent() |
|
| 350 | - { |
|
| 351 | - return apply_filters('FHEE__EEM_Message__stati_indicating_sent', array(self::status_sent)); |
|
| 352 | - } |
|
| 353 | - |
|
| 354 | - |
|
| 355 | - /** |
|
| 356 | - * Returns stati that indicate the message is waiting to be sent. |
|
| 357 | - * |
|
| 358 | - * @return array of strings for possible stati. |
|
| 359 | - */ |
|
| 360 | - public function stati_indicating_to_send() |
|
| 361 | - { |
|
| 362 | - return apply_filters( |
|
| 363 | - 'FHEE__EEM_Message__stati_indicating_to_send', |
|
| 364 | - array(self::status_idle, self::status_resend) |
|
| 365 | - ); |
|
| 366 | - } |
|
| 367 | - |
|
| 368 | - |
|
| 369 | - /** |
|
| 370 | - * Returns stati that indicate the message has failed sending |
|
| 371 | - * |
|
| 372 | - * @return array array of strings for possible stati. |
|
| 373 | - */ |
|
| 374 | - public function stati_indicating_failed_sending() |
|
| 375 | - { |
|
| 376 | - $failed_stati = array( |
|
| 377 | - self::status_failed, |
|
| 378 | - self::status_retry, |
|
| 379 | - self::status_messenger_executing, |
|
| 380 | - ); |
|
| 381 | - // if WP_DEBUG is set, then let's include debug_only fails |
|
| 382 | - if (WP_DEBUG) { |
|
| 383 | - $failed_stati[] = self::status_debug_only; |
|
| 384 | - } |
|
| 385 | - return apply_filters('FHEE__EEM_Message__stati_indicating_failed_sending', $failed_stati); |
|
| 386 | - } |
|
| 387 | - |
|
| 388 | - |
|
| 389 | - /** |
|
| 390 | - * Returns filterable array of all EEM_Message statuses. |
|
| 391 | - * |
|
| 392 | - * @return array |
|
| 393 | - */ |
|
| 394 | - public function all_statuses() |
|
| 395 | - { |
|
| 396 | - return apply_filters( |
|
| 397 | - 'FHEE__EEM_Message__all_statuses', |
|
| 398 | - array( |
|
| 399 | - EEM_Message::status_sent, |
|
| 400 | - EEM_Message::status_incomplete, |
|
| 401 | - EEM_Message::status_idle, |
|
| 402 | - EEM_Message::status_resend, |
|
| 403 | - EEM_Message::status_retry, |
|
| 404 | - EEM_Message::status_failed, |
|
| 405 | - EEM_Message::status_messenger_executing, |
|
| 406 | - EEM_Message::status_debug_only, |
|
| 407 | - ) |
|
| 408 | - ); |
|
| 409 | - } |
|
| 410 | - |
|
| 411 | - /** |
|
| 412 | - * Detects any specific query variables in the request and uses those to setup appropriate |
|
| 413 | - * filter for any queries. |
|
| 414 | - * |
|
| 415 | - * @return array |
|
| 416 | - */ |
|
| 417 | - public function filter_by_query_params() |
|
| 418 | - { |
|
| 419 | - /** @var RequestInterface $request */ |
|
| 420 | - $request = EEM_Base::$loader->getShared(RequestInterface::class); |
|
| 421 | - // expected possible query_vars, the key in this array matches an expected key in the request, |
|
| 422 | - // the value, matches the corresponding EEM_Base child reference. |
|
| 423 | - $expected_vars = $this->_expected_vars_for_query_inject(); |
|
| 424 | - $query_params[0] = array(); |
|
| 425 | - foreach ($expected_vars as $request_key => $model_name) { |
|
| 426 | - $request_value = $request->getRequestParam($request_key); |
|
| 427 | - if ($request_value) { |
|
| 428 | - // special case |
|
| 429 | - switch ($request_key) { |
|
| 430 | - case '_REG_ID': |
|
| 431 | - $query_params[0]['AND**filter_by']['OR**filter_by_REG_ID'] = array( |
|
| 432 | - 'Transaction.Registration.REG_ID' => $request_value, |
|
| 433 | - ); |
|
| 434 | - break; |
|
| 435 | - case 'EVT_ID': |
|
| 436 | - $query_params[0]['AND**filter_by']['OR**filter_by_EVT_ID'] = array( |
|
| 437 | - 'Transaction.Registration.EVT_ID' => $request_value, |
|
| 438 | - ); |
|
| 439 | - break; |
|
| 440 | - default: |
|
| 441 | - $query_params[0]['AND**filter_by'][ 'OR**filter_by_' . $request_key ][ $model_name . '.' . $request_key ] = $request_value; |
|
| 442 | - break; |
|
| 443 | - } |
|
| 444 | - } |
|
| 445 | - } |
|
| 446 | - return $query_params; |
|
| 447 | - } |
|
| 448 | - |
|
| 449 | - |
|
| 450 | - /** |
|
| 451 | - * @return string |
|
| 452 | - * @throws EE_Error |
|
| 453 | - * @throws ReflectionException |
|
| 454 | - */ |
|
| 455 | - public function get_pretty_label_for_results() |
|
| 456 | - { |
|
| 457 | - /** @var RequestInterface $request */ |
|
| 458 | - $request = EEM_Base::$loader->getShared(RequestInterface::class); |
|
| 459 | - $expected_vars = $this->_expected_vars_for_query_inject(); |
|
| 460 | - $pretty_label = ''; |
|
| 461 | - $label_parts = array(); |
|
| 462 | - foreach ($expected_vars as $request_key => $model_name) { |
|
| 463 | - $model_name = strpos($model_name, 'EEM_', true) === 0 ? $model_name : "EEM_{$model_name}"; |
|
| 464 | - $model = EEM_Base::$loader->getShared($model_name); |
|
| 465 | - $model_field_value = $request->getRequestParam($request_key); |
|
| 466 | - if ($model instanceof EEM_Base && $model_field_value !== '') { |
|
| 467 | - switch ($request_key) { |
|
| 468 | - case '_REG_ID': |
|
| 469 | - $label_parts[] = sprintf( |
|
| 470 | - esc_html__('Registration with the ID: %s', 'event_espresso'), |
|
| 471 | - $model_field_value |
|
| 472 | - ); |
|
| 473 | - break; |
|
| 474 | - case 'ATT_ID': |
|
| 475 | - /** @var EE_Attendee $attendee */ |
|
| 476 | - $attendee = $model->get_one_by_ID($model_field_value); |
|
| 477 | - $label_parts[] = $attendee instanceof EE_Attendee |
|
| 478 | - ? sprintf(esc_html__('Attendee %s', 'event_espresso'), $attendee->full_name()) |
|
| 479 | - : sprintf(esc_html__('Attendee ID: %s', 'event_espresso'), $model_field_value); |
|
| 480 | - break; |
|
| 481 | - case 'ID': |
|
| 482 | - /** @var EE_WP_User $wpUser */ |
|
| 483 | - $wpUser = $model->get_one_by_ID($model_field_value); |
|
| 484 | - $label_parts[] = $wpUser instanceof EE_WP_User |
|
| 485 | - ? sprintf(esc_html__('WP User: %s', 'event_espresso'), $wpUser->name()) |
|
| 486 | - : sprintf(esc_html__('WP User ID: %s', 'event_espresso'), $model_field_value); |
|
| 487 | - break; |
|
| 488 | - case 'TXN_ID': |
|
| 489 | - $label_parts[] = sprintf( |
|
| 490 | - esc_html__('Transaction with the ID: %s', 'event_espresso'), |
|
| 491 | - $model_field_value |
|
| 492 | - ); |
|
| 493 | - break; |
|
| 494 | - case 'EVT_ID': |
|
| 495 | - /** @var EE_Event $Event */ |
|
| 496 | - $Event = $model->get_one_by_ID($model_field_value); |
|
| 497 | - $label_parts[] = $Event instanceof EE_Event |
|
| 498 | - ? sprintf(esc_html__('for the Event: %s', 'event_espresso'), $Event->name()) |
|
| 499 | - : sprintf(esc_html__('for the Event with ID: %s', 'event_espresso'), $model_field_value); |
|
| 500 | - break; |
|
| 501 | - } |
|
| 502 | - } |
|
| 503 | - } |
|
| 504 | - |
|
| 505 | - if ($label_parts) { |
|
| 506 | - // prepend to the last element of $label_parts an "and". |
|
| 507 | - if (count($label_parts) > 1) { |
|
| 508 | - $label_parts_index_to_prepend = count($label_parts) - 1; |
|
| 509 | - $label_parts[ $label_parts_index_to_prepend ] = 'and' . $label_parts[ $label_parts_index_to_prepend ]; |
|
| 510 | - } |
|
| 511 | - |
|
| 512 | - $pretty_label .= sprintf( |
|
| 513 | - esc_html_x( |
|
| 514 | - 'Showing messages for %s', |
|
| 515 | - 'A label for the messages returned in a query that are filtered by items in the query. This could be Transaction, Event, Attendee, Registration, or WP_User.', |
|
| 516 | - 'event_espresso' |
|
| 517 | - ), |
|
| 518 | - implode(', ', $label_parts) |
|
| 519 | - ); |
|
| 520 | - } |
|
| 521 | - return $pretty_label; |
|
| 522 | - } |
|
| 523 | - |
|
| 524 | - |
|
| 525 | - /** |
|
| 526 | - * This returns the array of expected variables for the EEI_Query_Filter methods being implemented |
|
| 527 | - * The array is in the format: |
|
| 528 | - * array( |
|
| 529 | - * {$field_name} => {$model_name} |
|
| 530 | - * ); |
|
| 531 | - * |
|
| 532 | - * @since 4.9.0 |
|
| 533 | - * @return array |
|
| 534 | - */ |
|
| 535 | - protected function _expected_vars_for_query_inject() |
|
| 536 | - { |
|
| 537 | - return array( |
|
| 538 | - '_REG_ID' => 'Registration', |
|
| 539 | - 'ATT_ID' => 'Attendee', |
|
| 540 | - 'ID' => 'WP_User', |
|
| 541 | - 'TXN_ID' => 'Transaction', |
|
| 542 | - 'EVT_ID' => 'Event', |
|
| 543 | - ); |
|
| 544 | - } |
|
| 545 | - |
|
| 546 | - |
|
| 547 | - /** |
|
| 548 | - * This returns whether EEM_Message is in debug mode or not. |
|
| 549 | - * Currently "debug mode" is used to control the handling of the EEM_Message::debug_only status when |
|
| 550 | - * generating/sending messages. Debug mode can be set by either: |
|
| 551 | - * 1. Sending in a value for the $set_debug argument |
|
| 552 | - * 2. Defining `EE_DEBUG_MESSAGES` constant in wp-config.php |
|
| 553 | - * 3. Overriding the above via the provided filter. |
|
| 554 | - * |
|
| 555 | - * @param bool|null $set_debug If provided, then the debug mode will be set internally until reset via the |
|
| 556 | - * provided boolean. When no argument is provided (default null) then the debug |
|
| 557 | - * mode will be returned. |
|
| 558 | - * @return bool true means Messages is in debug mode. false means messages system is not in debug mode. |
|
| 559 | - */ |
|
| 560 | - public static function debug($set_debug = null) |
|
| 561 | - { |
|
| 562 | - static $is_debugging = null; |
|
| 563 | - |
|
| 564 | - // initialize (use constant if set). |
|
| 565 | - if (is_null($set_debug) && is_null($is_debugging)) { |
|
| 566 | - $is_debugging = defined('EE_DEBUG_MESSAGES') && EE_DEBUG_MESSAGES; |
|
| 567 | - } |
|
| 568 | - |
|
| 569 | - if (! is_null($set_debug)) { |
|
| 570 | - $is_debugging = filter_var($set_debug, FILTER_VALIDATE_BOOLEAN); |
|
| 571 | - } |
|
| 572 | - |
|
| 573 | - // return filtered value |
|
| 574 | - return apply_filters('FHEE__EEM_Message__debug', $is_debugging); |
|
| 575 | - } |
|
| 576 | - |
|
| 577 | - |
|
| 578 | - /** |
|
| 579 | - * Deletes old messages meeting certain criteria for removal from the database. |
|
| 580 | - * By default, this will delete messages that: |
|
| 581 | - * - are older than the value of the delete_threshold in months. |
|
| 582 | - * - have a STS_ID other than EEM_Message::status_idle |
|
| 583 | - * |
|
| 584 | - * @param int $delete_threshold This integer will be used to set the boundary for what messages are deleted in |
|
| 585 | - * months. |
|
| 586 | - * @return bool|false|int Either the number of records affected or false if there was an error (you can call |
|
| 587 | - * $wpdb->last_error to find out what the error was. |
|
| 588 | - * @throws EE_Error |
|
| 589 | - * @throws EE_Error |
|
| 590 | - * @throws EE_Error |
|
| 591 | - */ |
|
| 592 | - public function delete_old_messages($delete_threshold = 6) |
|
| 593 | - { |
|
| 594 | - $number_deleted = 0; |
|
| 595 | - /** |
|
| 596 | - * Allows code to change the boundary for what messages are kept. |
|
| 597 | - * Uses the value of the `delete_threshold` variable by default. |
|
| 598 | - * |
|
| 599 | - * @param int $seconds seconds that will be subtracted from the timestamp for now. |
|
| 600 | - * @return int |
|
| 601 | - */ |
|
| 602 | - $time_to_leave_alone = absint( |
|
| 603 | - apply_filters( |
|
| 604 | - 'FHEE__EEM_Message__delete_old_messages__time_to_leave_alone', |
|
| 605 | - ((int) $delete_threshold) * MONTH_IN_SECONDS |
|
| 606 | - ) |
|
| 607 | - ); |
|
| 608 | - |
|
| 609 | - |
|
| 610 | - /** |
|
| 611 | - * Allows code to change what message stati are ignored when deleting. |
|
| 612 | - * Defaults to only ignore EEM_Message::status_idle messages. |
|
| 613 | - * |
|
| 614 | - * @param string $message_stati_to_keep An array of message statuses that will be ignored when deleting. |
|
| 615 | - */ |
|
| 616 | - $message_stati_to_keep = (array) apply_filters( |
|
| 617 | - 'FHEE__EEM_Message__delete_old_messages__message_stati_to_keep', |
|
| 618 | - array( |
|
| 619 | - EEM_Message::status_idle |
|
| 620 | - ) |
|
| 621 | - ); |
|
| 622 | - |
|
| 623 | - // first get all the ids of messages being deleted |
|
| 624 | - $message_ids_to_delete = EEM_Message::instance()->get_col( |
|
| 625 | - array( |
|
| 626 | - 0 => array( |
|
| 627 | - 'STS_ID' => array('NOT_IN', $message_stati_to_keep), |
|
| 628 | - 'MSG_modified' => array('<', time() - $time_to_leave_alone) |
|
| 629 | - ), |
|
| 630 | - 'limit' => apply_filters( |
|
| 631 | - 'EEM_Message__delete_old_messages__limit', |
|
| 632 | - 2000, |
|
| 633 | - $delete_threshold |
|
| 634 | - ) |
|
| 635 | - ) |
|
| 636 | - ); |
|
| 637 | - |
|
| 638 | - if (! empty($message_ids_to_delete) && is_array($message_ids_to_delete)) { |
|
| 639 | - global $wpdb; |
|
| 640 | - $number_deleted = $wpdb->query(' |
|
| 15 | + // private instance of the Message object |
|
| 16 | + protected static $_instance = null; |
|
| 17 | + |
|
| 18 | + |
|
| 19 | + /** |
|
| 20 | + * This priority indicates a message should be generated and sent ASAP |
|
| 21 | + * |
|
| 22 | + * @type int |
|
| 23 | + */ |
|
| 24 | + const priority_high = 10; |
|
| 25 | + |
|
| 26 | + |
|
| 27 | + /** |
|
| 28 | + * This priority indicates a message should be generated ASAP and queued for sending. |
|
| 29 | + * |
|
| 30 | + * @type |
|
| 31 | + */ |
|
| 32 | + const priority_medium = 20; |
|
| 33 | + |
|
| 34 | + |
|
| 35 | + /** |
|
| 36 | + * This priority indicates a message should be queued for generating. |
|
| 37 | + * |
|
| 38 | + * @type int |
|
| 39 | + */ |
|
| 40 | + const priority_low = 30; |
|
| 41 | + |
|
| 42 | + |
|
| 43 | + /** |
|
| 44 | + * indicates this message was sent at the time modified |
|
| 45 | + */ |
|
| 46 | + const status_sent = 'MSN'; |
|
| 47 | + |
|
| 48 | + |
|
| 49 | + /** |
|
| 50 | + * indicates this message is waiting to be sent |
|
| 51 | + */ |
|
| 52 | + const status_idle = 'MID'; |
|
| 53 | + |
|
| 54 | + |
|
| 55 | + /** |
|
| 56 | + * indicates an attempt was a made to send this message |
|
| 57 | + * at the scheduled time, but it failed at the time modified. This differs from MDO status in that it will ALWAYS |
|
| 58 | + * appear to the end user. |
|
| 59 | + */ |
|
| 60 | + const status_failed = 'MFL'; |
|
| 61 | + |
|
| 62 | + |
|
| 63 | + /** |
|
| 64 | + * indicates the message has been flagged for resending (at the time modified). |
|
| 65 | + */ |
|
| 66 | + const status_resend = 'MRS'; |
|
| 67 | + |
|
| 68 | + |
|
| 69 | + /** |
|
| 70 | + * indicates the message has been flagged for generation but has not been generated yet. Messages always start as |
|
| 71 | + * this status when added to the queue. |
|
| 72 | + */ |
|
| 73 | + const status_incomplete = 'MIC'; |
|
| 74 | + |
|
| 75 | + |
|
| 76 | + /** |
|
| 77 | + * Indicates everything was generated fine for the message, however, the messenger was unable to send. |
|
| 78 | + * This status means that its possible to retry sending the message. |
|
| 79 | + */ |
|
| 80 | + const status_retry = 'MRT'; |
|
| 81 | + |
|
| 82 | + |
|
| 83 | + /** |
|
| 84 | + * This is used for more informational messages that may not indicate anything is broken but still cannot be |
|
| 85 | + * generated or sent correctly. An example of a message that would get flagged this way would be when a not |
|
| 86 | + * approved message was queued for generation, but at time of generation, the attached registration(s) are |
|
| 87 | + * approved. So the message queued for generation is no longer valid. Messages for this status will only persist |
|
| 88 | + * in the db and be viewable in the message activity list table when the messages system is in debug mode. |
|
| 89 | + * |
|
| 90 | + * @see EEM_Message::debug() |
|
| 91 | + */ |
|
| 92 | + const status_debug_only = 'MDO'; |
|
| 93 | + |
|
| 94 | + |
|
| 95 | + /** |
|
| 96 | + * This status is given to messages it is processed by the messenger send method. |
|
| 97 | + * Messages with this status should rarely be seen in the Message List table, but if they are, that's usually |
|
| 98 | + * indicative of a PHP timeout or memory limit issue. |
|
| 99 | + */ |
|
| 100 | + const status_messenger_executing = 'MEX'; |
|
| 101 | + |
|
| 102 | + |
|
| 103 | + /** |
|
| 104 | + * Private constructor to prevent direct creation. |
|
| 105 | + * |
|
| 106 | + * @param string $timezone string representing the timezone we want to set for returned Date Time Strings (and |
|
| 107 | + * any incoming timezone data that gets saved). Note this just sends the timezone info to |
|
| 108 | + * the date time model field objects. Default is null (and will be assumed using the set |
|
| 109 | + * timezone in the 'timezone_string' wp option) |
|
| 110 | + * @throws EE_Error |
|
| 111 | + * @throws EE_Error |
|
| 112 | + * @throws EE_Error |
|
| 113 | + */ |
|
| 114 | + protected function __construct($timezone = null) |
|
| 115 | + { |
|
| 116 | + $this->singular_item = esc_html__('Message', 'event_espresso'); |
|
| 117 | + $this->plural_item = esc_html__('Messages', 'event_espresso'); |
|
| 118 | + |
|
| 119 | + $this->_tables = array( |
|
| 120 | + 'Message' => new EE_Primary_Table('esp_message', 'MSG_ID'), |
|
| 121 | + ); |
|
| 122 | + |
|
| 123 | + $allowed_priority = array( |
|
| 124 | + self::priority_high => esc_html__('high', 'event_espresso'), |
|
| 125 | + self::priority_medium => esc_html__('medium', 'event_espresso'), |
|
| 126 | + self::priority_low => esc_html__('low', 'event_espresso'), |
|
| 127 | + ); |
|
| 128 | + |
|
| 129 | + $this->_fields = array( |
|
| 130 | + 'Message' => array( |
|
| 131 | + 'MSG_ID' => new EE_Primary_Key_Int_Field('MSG_ID', esc_html__('Message ID', 'event_espresso')), |
|
| 132 | + 'MSG_token' => new EE_Plain_Text_Field( |
|
| 133 | + 'MSG_token', |
|
| 134 | + esc_html__( |
|
| 135 | + 'Unique Token used to represent this row in publicly viewable contexts (eg. a url).', |
|
| 136 | + 'event_espresso' |
|
| 137 | + ), |
|
| 138 | + false, |
|
| 139 | + EEH_URL::generate_unique_token() |
|
| 140 | + ), |
|
| 141 | + 'GRP_ID' => new EE_Foreign_Key_Int_Field( |
|
| 142 | + 'GRP_ID', |
|
| 143 | + esc_html__('Foreign key to the EEM_Message_Template_Group table.', 'event_espresso'), |
|
| 144 | + true, |
|
| 145 | + 0, |
|
| 146 | + 'Message_Template_Group' |
|
| 147 | + ), |
|
| 148 | + 'TXN_ID' => new EE_Foreign_Key_Int_Field( |
|
| 149 | + 'TXN_ID', |
|
| 150 | + esc_html__( |
|
| 151 | + 'Foreign key to the related EE_Transaction. This is required to give context for regenerating the specific message', |
|
| 152 | + 'event_espresso' |
|
| 153 | + ), |
|
| 154 | + true, |
|
| 155 | + 0, |
|
| 156 | + 'Transaction' |
|
| 157 | + ), |
|
| 158 | + 'MSG_messenger' => new EE_Plain_Text_Field( |
|
| 159 | + 'MSG_messenger', |
|
| 160 | + esc_html__( |
|
| 161 | + 'Corresponds to the EE_messenger::name used to send this message. This will also be used to attempt any resending of the message.', |
|
| 162 | + 'event_espresso' |
|
| 163 | + ), |
|
| 164 | + false, |
|
| 165 | + 'email' |
|
| 166 | + ), |
|
| 167 | + 'MSG_message_type' => new EE_Plain_Text_Field( |
|
| 168 | + 'MSG_message_type', |
|
| 169 | + esc_html__('Corresponds to the EE_message_type::name used to generate this message.', 'event_espresso'), |
|
| 170 | + false, |
|
| 171 | + 'receipt' |
|
| 172 | + ), |
|
| 173 | + 'MSG_context' => new EE_Plain_Text_Field('MSG_context', esc_html__('Context', 'event_espresso'), false), |
|
| 174 | + 'MSG_recipient_ID' => new EE_Foreign_Key_Int_Field( |
|
| 175 | + 'MSG_recipient_ID', |
|
| 176 | + esc_html__('Recipient ID', 'event_espresso'), |
|
| 177 | + true, |
|
| 178 | + null, |
|
| 179 | + array('Registration', 'Attendee', 'WP_User') |
|
| 180 | + ), |
|
| 181 | + 'MSG_recipient_type' => new EE_Any_Foreign_Model_Name_Field( |
|
| 182 | + 'MSG_recipient_type', |
|
| 183 | + esc_html__('Recipient Type', 'event_espresso'), |
|
| 184 | + true, |
|
| 185 | + null, |
|
| 186 | + array('Registration', 'Attendee', 'WP_User') |
|
| 187 | + ), |
|
| 188 | + 'MSG_content' => new EE_Maybe_Serialized_Text_Field( |
|
| 189 | + 'MSG_content', |
|
| 190 | + esc_html__('Content', 'event_espresso'), |
|
| 191 | + true, |
|
| 192 | + '' |
|
| 193 | + ), |
|
| 194 | + 'MSG_to' => new EE_Maybe_Serialized_Text_Field( |
|
| 195 | + 'MSG_to', |
|
| 196 | + esc_html__('Address To', 'event_espresso'), |
|
| 197 | + true |
|
| 198 | + ), |
|
| 199 | + 'MSG_from' => new EE_Maybe_Serialized_Text_Field( |
|
| 200 | + 'MSG_from', |
|
| 201 | + esc_html__('Address From', 'event_espresso'), |
|
| 202 | + true |
|
| 203 | + ), |
|
| 204 | + 'MSG_subject' => new EE_Maybe_Serialized_Text_Field( |
|
| 205 | + 'MSG_subject', |
|
| 206 | + esc_html__('Subject', 'event_espresso'), |
|
| 207 | + true, |
|
| 208 | + '' |
|
| 209 | + ), |
|
| 210 | + 'MSG_priority' => new EE_Enum_Integer_Field( |
|
| 211 | + 'MSG_priority', |
|
| 212 | + esc_html__('Priority', 'event_espresso'), |
|
| 213 | + false, |
|
| 214 | + self::priority_low, |
|
| 215 | + $allowed_priority |
|
| 216 | + ), |
|
| 217 | + 'STS_ID' => new EE_Foreign_Key_String_Field( |
|
| 218 | + 'STS_ID', |
|
| 219 | + esc_html__('Status', 'event_espresso'), |
|
| 220 | + false, |
|
| 221 | + self::status_incomplete, |
|
| 222 | + 'Status' |
|
| 223 | + ), |
|
| 224 | + 'MSG_created' => new EE_Datetime_Field( |
|
| 225 | + 'MSG_created', |
|
| 226 | + esc_html__('Created', 'event_espresso'), |
|
| 227 | + false, |
|
| 228 | + EE_Datetime_Field::now |
|
| 229 | + ), |
|
| 230 | + 'MSG_modified' => new EE_Datetime_Field( |
|
| 231 | + 'MSG_modified', |
|
| 232 | + esc_html__('Modified', 'event_espresso'), |
|
| 233 | + true, |
|
| 234 | + EE_Datetime_Field::now |
|
| 235 | + ), |
|
| 236 | + ), |
|
| 237 | + ); |
|
| 238 | + $this->_model_relations = array( |
|
| 239 | + 'Attendee' => new EE_Belongs_To_Any_Relation(), |
|
| 240 | + 'Registration' => new EE_Belongs_To_Any_Relation(), |
|
| 241 | + 'WP_User' => new EE_Belongs_To_Any_Relation(), |
|
| 242 | + 'Message_Template_Group' => new EE_Belongs_To_Relation(), |
|
| 243 | + 'Transaction' => new EE_Belongs_To_Relation(), |
|
| 244 | + ); |
|
| 245 | + parent::__construct($timezone); |
|
| 246 | + } |
|
| 247 | + |
|
| 248 | + |
|
| 249 | + /** |
|
| 250 | + * @return EE_Message |
|
| 251 | + * @throws EE_Error |
|
| 252 | + */ |
|
| 253 | + public function create_default_object() |
|
| 254 | + { |
|
| 255 | + /** @type EE_Message $message */ |
|
| 256 | + $message = parent::create_default_object(); |
|
| 257 | + if ($message instanceof EE_Message) { |
|
| 258 | + return EE_Message_Factory::set_messenger_and_message_type($message); |
|
| 259 | + } |
|
| 260 | + return null; |
|
| 261 | + } |
|
| 262 | + |
|
| 263 | + |
|
| 264 | + /** |
|
| 265 | + * @param mixed $cols_n_values |
|
| 266 | + * @return EE_Message |
|
| 267 | + * @throws EE_Error |
|
| 268 | + * @throws EE_Error |
|
| 269 | + */ |
|
| 270 | + public function instantiate_class_from_array_or_object($cols_n_values) |
|
| 271 | + { |
|
| 272 | + /** @type EE_Message $message */ |
|
| 273 | + $message = parent::instantiate_class_from_array_or_object($cols_n_values); |
|
| 274 | + if ($message instanceof EE_Message) { |
|
| 275 | + return EE_Message_Factory::set_messenger_and_message_type($message); |
|
| 276 | + } |
|
| 277 | + return null; |
|
| 278 | + } |
|
| 279 | + |
|
| 280 | + |
|
| 281 | + /** |
|
| 282 | + * Returns whether or not a message of that type was sent for a given attendee. |
|
| 283 | + * |
|
| 284 | + * @param EE_Attendee|int $attendee |
|
| 285 | + * @param string $message_type the message type slug |
|
| 286 | + * @return boolean |
|
| 287 | + * @throws EE_Error |
|
| 288 | + * @throws EE_Error |
|
| 289 | + * @throws EE_Error |
|
| 290 | + */ |
|
| 291 | + public function message_sent_for_attendee($attendee, $message_type) |
|
| 292 | + { |
|
| 293 | + $attendee_ID = EEM_Attendee::instance()->ensure_is_ID($attendee); |
|
| 294 | + return $this->exists(array( |
|
| 295 | + array( |
|
| 296 | + 'Attendee.ATT_ID' => $attendee_ID, |
|
| 297 | + 'MSG_message_type' => $message_type, |
|
| 298 | + 'STS_ID' => array('IN', $this->stati_indicating_sent()), |
|
| 299 | + ), |
|
| 300 | + )); |
|
| 301 | + } |
|
| 302 | + |
|
| 303 | + |
|
| 304 | + /** |
|
| 305 | + * Returns whether or not a message of that type was sent for a given registration |
|
| 306 | + * |
|
| 307 | + * @param EE_Registration|int $registration |
|
| 308 | + * @param string $message_type the message type slug |
|
| 309 | + * @return boolean |
|
| 310 | + * @throws EE_Error |
|
| 311 | + * @throws EE_Error |
|
| 312 | + * @throws EE_Error |
|
| 313 | + */ |
|
| 314 | + public function message_sent_for_registration($registration, $message_type) |
|
| 315 | + { |
|
| 316 | + $registrationID = EEM_Registration::instance()->ensure_is_ID($registration); |
|
| 317 | + return $this->exists(array( |
|
| 318 | + array( |
|
| 319 | + 'Registration.REG_ID' => $registrationID, |
|
| 320 | + 'MSG_message_type' => $message_type, |
|
| 321 | + 'STS_ID' => array('IN', $this->stati_indicating_sent()), |
|
| 322 | + ), |
|
| 323 | + )); |
|
| 324 | + } |
|
| 325 | + |
|
| 326 | + |
|
| 327 | + /** |
|
| 328 | + * This retrieves an EE_Message object from the db matching the given token string. |
|
| 329 | + * |
|
| 330 | + * @param string $token |
|
| 331 | + * @return EE_Message |
|
| 332 | + * @throws EE_Error |
|
| 333 | + */ |
|
| 334 | + public function get_one_by_token($token) |
|
| 335 | + { |
|
| 336 | + return $this->get_one(array( |
|
| 337 | + array( |
|
| 338 | + 'MSG_token' => $token, |
|
| 339 | + ), |
|
| 340 | + )); |
|
| 341 | + } |
|
| 342 | + |
|
| 343 | + |
|
| 344 | + /** |
|
| 345 | + * Returns stati that indicate the message HAS been sent |
|
| 346 | + * |
|
| 347 | + * @return array of strings for possible stati |
|
| 348 | + */ |
|
| 349 | + public function stati_indicating_sent() |
|
| 350 | + { |
|
| 351 | + return apply_filters('FHEE__EEM_Message__stati_indicating_sent', array(self::status_sent)); |
|
| 352 | + } |
|
| 353 | + |
|
| 354 | + |
|
| 355 | + /** |
|
| 356 | + * Returns stati that indicate the message is waiting to be sent. |
|
| 357 | + * |
|
| 358 | + * @return array of strings for possible stati. |
|
| 359 | + */ |
|
| 360 | + public function stati_indicating_to_send() |
|
| 361 | + { |
|
| 362 | + return apply_filters( |
|
| 363 | + 'FHEE__EEM_Message__stati_indicating_to_send', |
|
| 364 | + array(self::status_idle, self::status_resend) |
|
| 365 | + ); |
|
| 366 | + } |
|
| 367 | + |
|
| 368 | + |
|
| 369 | + /** |
|
| 370 | + * Returns stati that indicate the message has failed sending |
|
| 371 | + * |
|
| 372 | + * @return array array of strings for possible stati. |
|
| 373 | + */ |
|
| 374 | + public function stati_indicating_failed_sending() |
|
| 375 | + { |
|
| 376 | + $failed_stati = array( |
|
| 377 | + self::status_failed, |
|
| 378 | + self::status_retry, |
|
| 379 | + self::status_messenger_executing, |
|
| 380 | + ); |
|
| 381 | + // if WP_DEBUG is set, then let's include debug_only fails |
|
| 382 | + if (WP_DEBUG) { |
|
| 383 | + $failed_stati[] = self::status_debug_only; |
|
| 384 | + } |
|
| 385 | + return apply_filters('FHEE__EEM_Message__stati_indicating_failed_sending', $failed_stati); |
|
| 386 | + } |
|
| 387 | + |
|
| 388 | + |
|
| 389 | + /** |
|
| 390 | + * Returns filterable array of all EEM_Message statuses. |
|
| 391 | + * |
|
| 392 | + * @return array |
|
| 393 | + */ |
|
| 394 | + public function all_statuses() |
|
| 395 | + { |
|
| 396 | + return apply_filters( |
|
| 397 | + 'FHEE__EEM_Message__all_statuses', |
|
| 398 | + array( |
|
| 399 | + EEM_Message::status_sent, |
|
| 400 | + EEM_Message::status_incomplete, |
|
| 401 | + EEM_Message::status_idle, |
|
| 402 | + EEM_Message::status_resend, |
|
| 403 | + EEM_Message::status_retry, |
|
| 404 | + EEM_Message::status_failed, |
|
| 405 | + EEM_Message::status_messenger_executing, |
|
| 406 | + EEM_Message::status_debug_only, |
|
| 407 | + ) |
|
| 408 | + ); |
|
| 409 | + } |
|
| 410 | + |
|
| 411 | + /** |
|
| 412 | + * Detects any specific query variables in the request and uses those to setup appropriate |
|
| 413 | + * filter for any queries. |
|
| 414 | + * |
|
| 415 | + * @return array |
|
| 416 | + */ |
|
| 417 | + public function filter_by_query_params() |
|
| 418 | + { |
|
| 419 | + /** @var RequestInterface $request */ |
|
| 420 | + $request = EEM_Base::$loader->getShared(RequestInterface::class); |
|
| 421 | + // expected possible query_vars, the key in this array matches an expected key in the request, |
|
| 422 | + // the value, matches the corresponding EEM_Base child reference. |
|
| 423 | + $expected_vars = $this->_expected_vars_for_query_inject(); |
|
| 424 | + $query_params[0] = array(); |
|
| 425 | + foreach ($expected_vars as $request_key => $model_name) { |
|
| 426 | + $request_value = $request->getRequestParam($request_key); |
|
| 427 | + if ($request_value) { |
|
| 428 | + // special case |
|
| 429 | + switch ($request_key) { |
|
| 430 | + case '_REG_ID': |
|
| 431 | + $query_params[0]['AND**filter_by']['OR**filter_by_REG_ID'] = array( |
|
| 432 | + 'Transaction.Registration.REG_ID' => $request_value, |
|
| 433 | + ); |
|
| 434 | + break; |
|
| 435 | + case 'EVT_ID': |
|
| 436 | + $query_params[0]['AND**filter_by']['OR**filter_by_EVT_ID'] = array( |
|
| 437 | + 'Transaction.Registration.EVT_ID' => $request_value, |
|
| 438 | + ); |
|
| 439 | + break; |
|
| 440 | + default: |
|
| 441 | + $query_params[0]['AND**filter_by'][ 'OR**filter_by_' . $request_key ][ $model_name . '.' . $request_key ] = $request_value; |
|
| 442 | + break; |
|
| 443 | + } |
|
| 444 | + } |
|
| 445 | + } |
|
| 446 | + return $query_params; |
|
| 447 | + } |
|
| 448 | + |
|
| 449 | + |
|
| 450 | + /** |
|
| 451 | + * @return string |
|
| 452 | + * @throws EE_Error |
|
| 453 | + * @throws ReflectionException |
|
| 454 | + */ |
|
| 455 | + public function get_pretty_label_for_results() |
|
| 456 | + { |
|
| 457 | + /** @var RequestInterface $request */ |
|
| 458 | + $request = EEM_Base::$loader->getShared(RequestInterface::class); |
|
| 459 | + $expected_vars = $this->_expected_vars_for_query_inject(); |
|
| 460 | + $pretty_label = ''; |
|
| 461 | + $label_parts = array(); |
|
| 462 | + foreach ($expected_vars as $request_key => $model_name) { |
|
| 463 | + $model_name = strpos($model_name, 'EEM_', true) === 0 ? $model_name : "EEM_{$model_name}"; |
|
| 464 | + $model = EEM_Base::$loader->getShared($model_name); |
|
| 465 | + $model_field_value = $request->getRequestParam($request_key); |
|
| 466 | + if ($model instanceof EEM_Base && $model_field_value !== '') { |
|
| 467 | + switch ($request_key) { |
|
| 468 | + case '_REG_ID': |
|
| 469 | + $label_parts[] = sprintf( |
|
| 470 | + esc_html__('Registration with the ID: %s', 'event_espresso'), |
|
| 471 | + $model_field_value |
|
| 472 | + ); |
|
| 473 | + break; |
|
| 474 | + case 'ATT_ID': |
|
| 475 | + /** @var EE_Attendee $attendee */ |
|
| 476 | + $attendee = $model->get_one_by_ID($model_field_value); |
|
| 477 | + $label_parts[] = $attendee instanceof EE_Attendee |
|
| 478 | + ? sprintf(esc_html__('Attendee %s', 'event_espresso'), $attendee->full_name()) |
|
| 479 | + : sprintf(esc_html__('Attendee ID: %s', 'event_espresso'), $model_field_value); |
|
| 480 | + break; |
|
| 481 | + case 'ID': |
|
| 482 | + /** @var EE_WP_User $wpUser */ |
|
| 483 | + $wpUser = $model->get_one_by_ID($model_field_value); |
|
| 484 | + $label_parts[] = $wpUser instanceof EE_WP_User |
|
| 485 | + ? sprintf(esc_html__('WP User: %s', 'event_espresso'), $wpUser->name()) |
|
| 486 | + : sprintf(esc_html__('WP User ID: %s', 'event_espresso'), $model_field_value); |
|
| 487 | + break; |
|
| 488 | + case 'TXN_ID': |
|
| 489 | + $label_parts[] = sprintf( |
|
| 490 | + esc_html__('Transaction with the ID: %s', 'event_espresso'), |
|
| 491 | + $model_field_value |
|
| 492 | + ); |
|
| 493 | + break; |
|
| 494 | + case 'EVT_ID': |
|
| 495 | + /** @var EE_Event $Event */ |
|
| 496 | + $Event = $model->get_one_by_ID($model_field_value); |
|
| 497 | + $label_parts[] = $Event instanceof EE_Event |
|
| 498 | + ? sprintf(esc_html__('for the Event: %s', 'event_espresso'), $Event->name()) |
|
| 499 | + : sprintf(esc_html__('for the Event with ID: %s', 'event_espresso'), $model_field_value); |
|
| 500 | + break; |
|
| 501 | + } |
|
| 502 | + } |
|
| 503 | + } |
|
| 504 | + |
|
| 505 | + if ($label_parts) { |
|
| 506 | + // prepend to the last element of $label_parts an "and". |
|
| 507 | + if (count($label_parts) > 1) { |
|
| 508 | + $label_parts_index_to_prepend = count($label_parts) - 1; |
|
| 509 | + $label_parts[ $label_parts_index_to_prepend ] = 'and' . $label_parts[ $label_parts_index_to_prepend ]; |
|
| 510 | + } |
|
| 511 | + |
|
| 512 | + $pretty_label .= sprintf( |
|
| 513 | + esc_html_x( |
|
| 514 | + 'Showing messages for %s', |
|
| 515 | + 'A label for the messages returned in a query that are filtered by items in the query. This could be Transaction, Event, Attendee, Registration, or WP_User.', |
|
| 516 | + 'event_espresso' |
|
| 517 | + ), |
|
| 518 | + implode(', ', $label_parts) |
|
| 519 | + ); |
|
| 520 | + } |
|
| 521 | + return $pretty_label; |
|
| 522 | + } |
|
| 523 | + |
|
| 524 | + |
|
| 525 | + /** |
|
| 526 | + * This returns the array of expected variables for the EEI_Query_Filter methods being implemented |
|
| 527 | + * The array is in the format: |
|
| 528 | + * array( |
|
| 529 | + * {$field_name} => {$model_name} |
|
| 530 | + * ); |
|
| 531 | + * |
|
| 532 | + * @since 4.9.0 |
|
| 533 | + * @return array |
|
| 534 | + */ |
|
| 535 | + protected function _expected_vars_for_query_inject() |
|
| 536 | + { |
|
| 537 | + return array( |
|
| 538 | + '_REG_ID' => 'Registration', |
|
| 539 | + 'ATT_ID' => 'Attendee', |
|
| 540 | + 'ID' => 'WP_User', |
|
| 541 | + 'TXN_ID' => 'Transaction', |
|
| 542 | + 'EVT_ID' => 'Event', |
|
| 543 | + ); |
|
| 544 | + } |
|
| 545 | + |
|
| 546 | + |
|
| 547 | + /** |
|
| 548 | + * This returns whether EEM_Message is in debug mode or not. |
|
| 549 | + * Currently "debug mode" is used to control the handling of the EEM_Message::debug_only status when |
|
| 550 | + * generating/sending messages. Debug mode can be set by either: |
|
| 551 | + * 1. Sending in a value for the $set_debug argument |
|
| 552 | + * 2. Defining `EE_DEBUG_MESSAGES` constant in wp-config.php |
|
| 553 | + * 3. Overriding the above via the provided filter. |
|
| 554 | + * |
|
| 555 | + * @param bool|null $set_debug If provided, then the debug mode will be set internally until reset via the |
|
| 556 | + * provided boolean. When no argument is provided (default null) then the debug |
|
| 557 | + * mode will be returned. |
|
| 558 | + * @return bool true means Messages is in debug mode. false means messages system is not in debug mode. |
|
| 559 | + */ |
|
| 560 | + public static function debug($set_debug = null) |
|
| 561 | + { |
|
| 562 | + static $is_debugging = null; |
|
| 563 | + |
|
| 564 | + // initialize (use constant if set). |
|
| 565 | + if (is_null($set_debug) && is_null($is_debugging)) { |
|
| 566 | + $is_debugging = defined('EE_DEBUG_MESSAGES') && EE_DEBUG_MESSAGES; |
|
| 567 | + } |
|
| 568 | + |
|
| 569 | + if (! is_null($set_debug)) { |
|
| 570 | + $is_debugging = filter_var($set_debug, FILTER_VALIDATE_BOOLEAN); |
|
| 571 | + } |
|
| 572 | + |
|
| 573 | + // return filtered value |
|
| 574 | + return apply_filters('FHEE__EEM_Message__debug', $is_debugging); |
|
| 575 | + } |
|
| 576 | + |
|
| 577 | + |
|
| 578 | + /** |
|
| 579 | + * Deletes old messages meeting certain criteria for removal from the database. |
|
| 580 | + * By default, this will delete messages that: |
|
| 581 | + * - are older than the value of the delete_threshold in months. |
|
| 582 | + * - have a STS_ID other than EEM_Message::status_idle |
|
| 583 | + * |
|
| 584 | + * @param int $delete_threshold This integer will be used to set the boundary for what messages are deleted in |
|
| 585 | + * months. |
|
| 586 | + * @return bool|false|int Either the number of records affected or false if there was an error (you can call |
|
| 587 | + * $wpdb->last_error to find out what the error was. |
|
| 588 | + * @throws EE_Error |
|
| 589 | + * @throws EE_Error |
|
| 590 | + * @throws EE_Error |
|
| 591 | + */ |
|
| 592 | + public function delete_old_messages($delete_threshold = 6) |
|
| 593 | + { |
|
| 594 | + $number_deleted = 0; |
|
| 595 | + /** |
|
| 596 | + * Allows code to change the boundary for what messages are kept. |
|
| 597 | + * Uses the value of the `delete_threshold` variable by default. |
|
| 598 | + * |
|
| 599 | + * @param int $seconds seconds that will be subtracted from the timestamp for now. |
|
| 600 | + * @return int |
|
| 601 | + */ |
|
| 602 | + $time_to_leave_alone = absint( |
|
| 603 | + apply_filters( |
|
| 604 | + 'FHEE__EEM_Message__delete_old_messages__time_to_leave_alone', |
|
| 605 | + ((int) $delete_threshold) * MONTH_IN_SECONDS |
|
| 606 | + ) |
|
| 607 | + ); |
|
| 608 | + |
|
| 609 | + |
|
| 610 | + /** |
|
| 611 | + * Allows code to change what message stati are ignored when deleting. |
|
| 612 | + * Defaults to only ignore EEM_Message::status_idle messages. |
|
| 613 | + * |
|
| 614 | + * @param string $message_stati_to_keep An array of message statuses that will be ignored when deleting. |
|
| 615 | + */ |
|
| 616 | + $message_stati_to_keep = (array) apply_filters( |
|
| 617 | + 'FHEE__EEM_Message__delete_old_messages__message_stati_to_keep', |
|
| 618 | + array( |
|
| 619 | + EEM_Message::status_idle |
|
| 620 | + ) |
|
| 621 | + ); |
|
| 622 | + |
|
| 623 | + // first get all the ids of messages being deleted |
|
| 624 | + $message_ids_to_delete = EEM_Message::instance()->get_col( |
|
| 625 | + array( |
|
| 626 | + 0 => array( |
|
| 627 | + 'STS_ID' => array('NOT_IN', $message_stati_to_keep), |
|
| 628 | + 'MSG_modified' => array('<', time() - $time_to_leave_alone) |
|
| 629 | + ), |
|
| 630 | + 'limit' => apply_filters( |
|
| 631 | + 'EEM_Message__delete_old_messages__limit', |
|
| 632 | + 2000, |
|
| 633 | + $delete_threshold |
|
| 634 | + ) |
|
| 635 | + ) |
|
| 636 | + ); |
|
| 637 | + |
|
| 638 | + if (! empty($message_ids_to_delete) && is_array($message_ids_to_delete)) { |
|
| 639 | + global $wpdb; |
|
| 640 | + $number_deleted = $wpdb->query(' |
|
| 641 | 641 | DELETE |
| 642 | 642 | FROM ' . $this->table() . ' |
| 643 | 643 | WHERE |
| 644 | 644 | MSG_ID IN (' . implode(",", $message_ids_to_delete) . ') |
| 645 | 645 | '); |
| 646 | - } |
|
| 647 | - |
|
| 648 | - /** |
|
| 649 | - * This will get called if the number of records deleted 0 or greater. So a successful deletion is one where |
|
| 650 | - * there were no errors. An unsuccessful deletion is where there were errors. Keep that in mind for the actions |
|
| 651 | - * below. |
|
| 652 | - */ |
|
| 653 | - if ($number_deleted !== false) { |
|
| 654 | - do_action('AHEE__EEM_Message__delete_old_messages__after_successful_deletion', $message_ids_to_delete, $number_deleted); |
|
| 655 | - } else { |
|
| 656 | - do_action('AHEE__EEM_Message__delete_old_messages__after_deletion_fail', $message_ids_to_delete, $number_deleted); |
|
| 657 | - } |
|
| 658 | - return $number_deleted; |
|
| 659 | - } |
|
| 646 | + } |
|
| 647 | + |
|
| 648 | + /** |
|
| 649 | + * This will get called if the number of records deleted 0 or greater. So a successful deletion is one where |
|
| 650 | + * there were no errors. An unsuccessful deletion is where there were errors. Keep that in mind for the actions |
|
| 651 | + * below. |
|
| 652 | + */ |
|
| 653 | + if ($number_deleted !== false) { |
|
| 654 | + do_action('AHEE__EEM_Message__delete_old_messages__after_successful_deletion', $message_ids_to_delete, $number_deleted); |
|
| 655 | + } else { |
|
| 656 | + do_action('AHEE__EEM_Message__delete_old_messages__after_deletion_fail', $message_ids_to_delete, $number_deleted); |
|
| 657 | + } |
|
| 658 | + return $number_deleted; |
|
| 659 | + } |
|
| 660 | 660 | } |
@@ -5,12 +5,12 @@ |
||
| 5 | 5 | */ |
| 6 | 6 | class EE_WP_Post_Type_Field extends EE_DB_Only_Text_Field |
| 7 | 7 | { |
| 8 | - /** |
|
| 9 | - * @param string $post_type the exact string to be used for the post type |
|
| 10 | - * of all these post type model objects/rows |
|
| 11 | - */ |
|
| 12 | - public function __construct($post_type) |
|
| 13 | - { |
|
| 14 | - parent::__construct('post_type', esc_html__("Post Type", 'event_espresso'), false, $post_type); |
|
| 15 | - } |
|
| 8 | + /** |
|
| 9 | + * @param string $post_type the exact string to be used for the post type |
|
| 10 | + * of all these post type model objects/rows |
|
| 11 | + */ |
|
| 12 | + public function __construct($post_type) |
|
| 13 | + { |
|
| 14 | + parent::__construct('post_type', esc_html__("Post Type", 'event_espresso'), false, $post_type); |
|
| 15 | + } |
|
| 16 | 16 | } |
@@ -278,7 +278,7 @@ discard block |
||
| 278 | 278 | 'WP_User' => new EE_Belongs_To_Relation(), |
| 279 | 279 | ); |
| 280 | 280 | // this model is generally available for reading |
| 281 | - $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Public(); |
|
| 281 | + $this->_cap_restriction_generators[EEM_Base::caps_read] = new EE_Restriction_Generator_Public(); |
|
| 282 | 282 | $this->model_chain_to_password = ''; |
| 283 | 283 | parent::__construct($timezone); |
| 284 | 284 | } |
@@ -371,7 +371,7 @@ discard block |
||
| 371 | 371 | */ |
| 372 | 372 | public function get_all_event_question_groups($EVT_ID = 0) |
| 373 | 373 | { |
| 374 | - if (! isset($EVT_ID) || ! absint($EVT_ID)) { |
|
| 374 | + if ( ! isset($EVT_ID) || ! absint($EVT_ID)) { |
|
| 375 | 375 | EE_Error::add_error( |
| 376 | 376 | esc_html__( |
| 377 | 377 | 'An error occurred. No Event Question Groups could be retrieved because an Event ID was not received.', |
@@ -405,7 +405,7 @@ discard block |
||
| 405 | 405 | */ |
| 406 | 406 | public function get_event_question_groups($EVT_ID = 0, $for_primary_attendee = true) |
| 407 | 407 | { |
| 408 | - if (! isset($EVT_ID) || ! absint($EVT_ID)) { |
|
| 408 | + if ( ! isset($EVT_ID) || ! absint($EVT_ID)) { |
|
| 409 | 409 | EE_Error::add_error( |
| 410 | 410 | esc_html__( |
| 411 | 411 | // @codingStandardsIgnoreStart |
@@ -448,7 +448,7 @@ discard block |
||
| 448 | 448 | */ |
| 449 | 449 | public function get_question_groups_for_event($EVT_ID, EE_Registration $registration) |
| 450 | 450 | { |
| 451 | - if (! isset($EVT_ID) || ! absint($EVT_ID)) { |
|
| 451 | + if ( ! isset($EVT_ID) || ! absint($EVT_ID)) { |
|
| 452 | 452 | EE_Error::add_error( |
| 453 | 453 | esc_html__( |
| 454 | 454 | 'An error occurred. No Question Groups could be retrieved because an Event ID was not received.', |
@@ -867,11 +867,11 @@ discard block |
||
| 867 | 867 | $questions = array(); |
| 868 | 868 | // get all question groups for event |
| 869 | 869 | $qgs = $this->get_question_groups_for_event($EVT_ID, $registration); |
| 870 | - if (! empty($qgs)) { |
|
| 870 | + if ( ! empty($qgs)) { |
|
| 871 | 871 | foreach ($qgs as $qg) { |
| 872 | 872 | $qsts = $qg->questions(); |
| 873 | - $questions[ $qg->ID() ] = $qg->model_field_array(); |
|
| 874 | - $questions[ $qg->ID() ]['QSG_questions'] = array(); |
|
| 873 | + $questions[$qg->ID()] = $qg->model_field_array(); |
|
| 874 | + $questions[$qg->ID()]['QSG_questions'] = array(); |
|
| 875 | 875 | foreach ($qsts as $qst) { |
| 876 | 876 | if ($qst->is_system_question()) { |
| 877 | 877 | continue; |
@@ -885,26 +885,26 @@ discard block |
||
| 885 | 885 | $answer = $answer instanceof EE_Answer ? $answer : EEM_Answer::instance()->create_default_object(); |
| 886 | 886 | $qst_name = $qstn_id = $qst->ID(); |
| 887 | 887 | $ans_id = $answer->ID(); |
| 888 | - $qst_name = ! empty($ans_id) ? '[' . $qst_name . '][' . $ans_id . ']' : '[' . $qst_name . ']'; |
|
| 888 | + $qst_name = ! empty($ans_id) ? '['.$qst_name.']['.$ans_id.']' : '['.$qst_name.']'; |
|
| 889 | 889 | $input_name = ''; |
| 890 | 890 | $input_id = sanitize_key($qst->display_text()); |
| 891 | 891 | $input_class = ''; |
| 892 | - $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ] = $qst->model_field_array(); |
|
| 893 | - $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['QST_input_name'] = 'qstn' |
|
| 892 | + $questions[$qg->ID()]['QSG_questions'][$qst->ID()] = $qst->model_field_array(); |
|
| 893 | + $questions[$qg->ID()]['QSG_questions'][$qst->ID()]['QST_input_name'] = 'qstn' |
|
| 894 | 894 | . $input_name |
| 895 | 895 | . $qst_name; |
| 896 | - $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['QST_input_id'] = $input_id . '-' . $qstn_id; |
|
| 897 | - $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['QST_input_class'] = $input_class; |
|
| 898 | - $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['QST_options'] = array(); |
|
| 899 | - $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['qst_obj'] = $qst; |
|
| 900 | - $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['ans_obj'] = $answer; |
|
| 896 | + $questions[$qg->ID()]['QSG_questions'][$qst->ID()]['QST_input_id'] = $input_id.'-'.$qstn_id; |
|
| 897 | + $questions[$qg->ID()]['QSG_questions'][$qst->ID()]['QST_input_class'] = $input_class; |
|
| 898 | + $questions[$qg->ID()]['QSG_questions'][$qst->ID()]['QST_options'] = array(); |
|
| 899 | + $questions[$qg->ID()]['QSG_questions'][$qst->ID()]['qst_obj'] = $qst; |
|
| 900 | + $questions[$qg->ID()]['QSG_questions'][$qst->ID()]['ans_obj'] = $answer; |
|
| 901 | 901 | // leave responses as-is, don't convert stuff into html entities please! |
| 902 | - $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['htmlentities'] = false; |
|
| 902 | + $questions[$qg->ID()]['QSG_questions'][$qst->ID()]['htmlentities'] = false; |
|
| 903 | 903 | if ($qst->type() == 'RADIO_BTN' || $qst->type() == 'CHECKBOX' || $qst->type() == 'DROPDOWN') { |
| 904 | 904 | $QSOs = $qst->options(true, $answer->value()); |
| 905 | 905 | if (is_array($QSOs)) { |
| 906 | 906 | foreach ($QSOs as $QSO_ID => $QSO) { |
| 907 | - $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['QST_options'][ $QSO_ID ] = $QSO->model_field_array(); |
|
| 907 | + $questions[$qg->ID()]['QSG_questions'][$qst->ID()]['QST_options'][$QSO_ID] = $QSO->model_field_array(); |
|
| 908 | 908 | } |
| 909 | 909 | } |
| 910 | 910 | } |
@@ -14,955 +14,955 @@ |
||
| 14 | 14 | */ |
| 15 | 15 | class EEM_Event extends EEM_CPT_Base |
| 16 | 16 | { |
| 17 | - /** |
|
| 18 | - * constant used by status(), indicating that no more tickets can be purchased for any of the datetimes for the |
|
| 19 | - * event |
|
| 20 | - */ |
|
| 21 | - const sold_out = 'sold_out'; |
|
| 22 | - |
|
| 23 | - /** |
|
| 24 | - * constant used by status(), indicating that upcoming event dates have been postponed (may be pushed to a later |
|
| 25 | - * date) |
|
| 26 | - */ |
|
| 27 | - const postponed = 'postponed'; |
|
| 28 | - |
|
| 29 | - /** |
|
| 30 | - * constant used by status(), indicating that the event will no longer occur |
|
| 31 | - */ |
|
| 32 | - const cancelled = 'cancelled'; |
|
| 33 | - |
|
| 34 | - |
|
| 35 | - /** |
|
| 36 | - * @var string |
|
| 37 | - */ |
|
| 38 | - protected static $_default_reg_status; |
|
| 39 | - |
|
| 40 | - |
|
| 41 | - /** |
|
| 42 | - * This is the default for the additional limit field. |
|
| 43 | - * @var int |
|
| 44 | - */ |
|
| 45 | - protected static $_default_additional_limit = 10; |
|
| 46 | - |
|
| 47 | - |
|
| 48 | - /** |
|
| 49 | - * private instance of the Event object |
|
| 50 | - * |
|
| 51 | - * @var EEM_Event |
|
| 52 | - */ |
|
| 53 | - protected static $_instance; |
|
| 54 | - |
|
| 55 | - |
|
| 56 | - |
|
| 57 | - |
|
| 58 | - /** |
|
| 59 | - * Adds a relationship to Term_Taxonomy for each CPT_Base |
|
| 60 | - * |
|
| 61 | - * @param string $timezone |
|
| 62 | - * @throws \EE_Error |
|
| 63 | - */ |
|
| 64 | - protected function __construct($timezone = null) |
|
| 65 | - { |
|
| 66 | - EE_Registry::instance()->load_model('Registration'); |
|
| 67 | - $this->singular_item = esc_html__('Event', 'event_espresso'); |
|
| 68 | - $this->plural_item = esc_html__('Events', 'event_espresso'); |
|
| 69 | - // to remove Cancelled events from the frontend, copy the following filter to your functions.php file |
|
| 70 | - // add_filter( 'AFEE__EEM_Event__construct___custom_stati__cancelled__Public', '__return_false' ); |
|
| 71 | - // to remove Postponed events from the frontend, copy the following filter to your functions.php file |
|
| 72 | - // add_filter( 'AFEE__EEM_Event__construct___custom_stati__postponed__Public', '__return_false' ); |
|
| 73 | - // to remove Sold Out events from the frontend, copy the following filter to your functions.php file |
|
| 74 | - // add_filter( 'AFEE__EEM_Event__construct___custom_stati__sold_out__Public', '__return_false' ); |
|
| 75 | - $this->_custom_stati = apply_filters( |
|
| 76 | - 'AFEE__EEM_Event__construct___custom_stati', |
|
| 77 | - array( |
|
| 78 | - EEM_Event::cancelled => array( |
|
| 79 | - 'label' => esc_html__('Cancelled', 'event_espresso'), |
|
| 80 | - 'public' => apply_filters('AFEE__EEM_Event__construct___custom_stati__cancelled__Public', true), |
|
| 81 | - ), |
|
| 82 | - EEM_Event::postponed => array( |
|
| 83 | - 'label' => esc_html__('Postponed', 'event_espresso'), |
|
| 84 | - 'public' => apply_filters('AFEE__EEM_Event__construct___custom_stati__postponed__Public', true), |
|
| 85 | - ), |
|
| 86 | - EEM_Event::sold_out => array( |
|
| 87 | - 'label' => esc_html__('Sold Out', 'event_espresso'), |
|
| 88 | - 'public' => apply_filters('AFEE__EEM_Event__construct___custom_stati__sold_out__Public', true), |
|
| 89 | - ), |
|
| 90 | - ) |
|
| 91 | - ); |
|
| 92 | - self::$_default_reg_status = empty(self::$_default_reg_status) ? EEM_Registration::status_id_pending_payment |
|
| 93 | - : self::$_default_reg_status; |
|
| 94 | - $this->_tables = array( |
|
| 95 | - 'Event_CPT' => new EE_Primary_Table('posts', 'ID'), |
|
| 96 | - 'Event_Meta' => new EE_Secondary_Table('esp_event_meta', 'EVTM_ID', 'EVT_ID'), |
|
| 97 | - ); |
|
| 98 | - $this->_fields = array( |
|
| 99 | - 'Event_CPT' => array( |
|
| 100 | - 'EVT_ID' => new EE_Primary_Key_Int_Field( |
|
| 101 | - 'ID', |
|
| 102 | - esc_html__('Post ID for Event', 'event_espresso') |
|
| 103 | - ), |
|
| 104 | - 'EVT_name' => new EE_Plain_Text_Field( |
|
| 105 | - 'post_title', |
|
| 106 | - esc_html__('Event Name', 'event_espresso'), |
|
| 107 | - false, |
|
| 108 | - '' |
|
| 109 | - ), |
|
| 110 | - 'EVT_desc' => new EE_Post_Content_Field( |
|
| 111 | - 'post_content', |
|
| 112 | - esc_html__('Event Description', 'event_espresso'), |
|
| 113 | - false, |
|
| 114 | - '' |
|
| 115 | - ), |
|
| 116 | - 'EVT_slug' => new EE_Slug_Field( |
|
| 117 | - 'post_name', |
|
| 118 | - esc_html__('Event Slug', 'event_espresso'), |
|
| 119 | - false, |
|
| 120 | - '' |
|
| 121 | - ), |
|
| 122 | - 'EVT_created' => new EE_Datetime_Field( |
|
| 123 | - 'post_date', |
|
| 124 | - esc_html__('Date/Time Event Created', 'event_espresso'), |
|
| 125 | - false, |
|
| 126 | - EE_Datetime_Field::now |
|
| 127 | - ), |
|
| 128 | - 'EVT_short_desc' => new EE_Simple_HTML_Field( |
|
| 129 | - 'post_excerpt', |
|
| 130 | - esc_html__('Event Short Description', 'event_espresso'), |
|
| 131 | - false, |
|
| 132 | - '' |
|
| 133 | - ), |
|
| 134 | - 'EVT_modified' => new EE_Datetime_Field( |
|
| 135 | - 'post_modified', |
|
| 136 | - esc_html__('Date/Time Event Modified', 'event_espresso'), |
|
| 137 | - false, |
|
| 138 | - EE_Datetime_Field::now |
|
| 139 | - ), |
|
| 140 | - 'EVT_wp_user' => new EE_WP_User_Field( |
|
| 141 | - 'post_author', |
|
| 142 | - esc_html__('Event Creator ID', 'event_espresso'), |
|
| 143 | - false |
|
| 144 | - ), |
|
| 145 | - 'parent' => new EE_Integer_Field( |
|
| 146 | - 'post_parent', |
|
| 147 | - esc_html__('Event Parent ID', 'event_espresso'), |
|
| 148 | - false, |
|
| 149 | - 0 |
|
| 150 | - ), |
|
| 151 | - 'EVT_order' => new EE_Integer_Field( |
|
| 152 | - 'menu_order', |
|
| 153 | - esc_html__('Event Menu Order', 'event_espresso'), |
|
| 154 | - false, |
|
| 155 | - 1 |
|
| 156 | - ), |
|
| 157 | - 'post_type' => new EE_WP_Post_Type_Field('espresso_events'), |
|
| 158 | - // EE_Plain_Text_Field( 'post_type', esc_html__( 'Event Post Type', 'event_espresso' ), FALSE, 'espresso_events' ), |
|
| 159 | - 'status' => new EE_WP_Post_Status_Field( |
|
| 160 | - 'post_status', |
|
| 161 | - esc_html__('Event Status', 'event_espresso'), |
|
| 162 | - false, |
|
| 163 | - 'draft', |
|
| 164 | - $this->_custom_stati |
|
| 165 | - ), |
|
| 166 | - 'password' => new EE_Password_Field( |
|
| 167 | - 'post_password', |
|
| 168 | - esc_html__('Password', 'event_espresso'), |
|
| 169 | - false, |
|
| 170 | - '', |
|
| 171 | - array( |
|
| 172 | - 'EVT_desc', |
|
| 173 | - 'EVT_short_desc', |
|
| 174 | - 'EVT_display_desc', |
|
| 175 | - 'EVT_display_ticket_selector', |
|
| 176 | - 'EVT_visible_on', |
|
| 177 | - 'EVT_additional_limit', |
|
| 178 | - 'EVT_default_registration_status', |
|
| 179 | - 'EVT_member_only', |
|
| 180 | - 'EVT_phone', |
|
| 181 | - 'EVT_allow_overflow', |
|
| 182 | - 'EVT_timezone_string', |
|
| 183 | - 'EVT_external_URL', |
|
| 184 | - 'EVT_donations' |
|
| 185 | - ) |
|
| 186 | - ) |
|
| 187 | - ), |
|
| 188 | - 'Event_Meta' => array( |
|
| 189 | - 'EVTM_ID' => new EE_DB_Only_Float_Field( |
|
| 190 | - 'EVTM_ID', |
|
| 191 | - esc_html__('Event Meta Row ID', 'event_espresso'), |
|
| 192 | - false |
|
| 193 | - ), |
|
| 194 | - 'EVT_ID_fk' => new EE_DB_Only_Int_Field( |
|
| 195 | - 'EVT_ID', |
|
| 196 | - esc_html__('Foreign key to Event ID from Event Meta table', 'event_espresso'), |
|
| 197 | - false |
|
| 198 | - ), |
|
| 199 | - 'EVT_display_desc' => new EE_Boolean_Field( |
|
| 200 | - 'EVT_display_desc', |
|
| 201 | - esc_html__('Display Description Flag', 'event_espresso'), |
|
| 202 | - false, |
|
| 203 | - true |
|
| 204 | - ), |
|
| 205 | - 'EVT_display_ticket_selector' => new EE_Boolean_Field( |
|
| 206 | - 'EVT_display_ticket_selector', |
|
| 207 | - esc_html__('Display Ticket Selector Flag', 'event_espresso'), |
|
| 208 | - false, |
|
| 209 | - true |
|
| 210 | - ), |
|
| 211 | - 'EVT_visible_on' => new EE_Datetime_Field( |
|
| 212 | - 'EVT_visible_on', |
|
| 213 | - esc_html__('Event Visible Date', 'event_espresso'), |
|
| 214 | - true, |
|
| 215 | - EE_Datetime_Field::now |
|
| 216 | - ), |
|
| 217 | - 'EVT_additional_limit' => new EE_Integer_Field( |
|
| 218 | - 'EVT_additional_limit', |
|
| 219 | - esc_html__('Limit of Additional Registrations on Same Transaction', 'event_espresso'), |
|
| 220 | - true, |
|
| 221 | - self::$_default_additional_limit |
|
| 222 | - ), |
|
| 223 | - 'EVT_default_registration_status' => new EE_Enum_Text_Field( |
|
| 224 | - 'EVT_default_registration_status', |
|
| 225 | - esc_html__('Default Registration Status on this Event', 'event_espresso'), |
|
| 226 | - false, |
|
| 227 | - EEM_Event::$_default_reg_status, |
|
| 228 | - EEM_Registration::reg_status_array() |
|
| 229 | - ), |
|
| 230 | - 'EVT_member_only' => new EE_Boolean_Field( |
|
| 231 | - 'EVT_member_only', |
|
| 232 | - esc_html__('Member-Only Event Flag', 'event_espresso'), |
|
| 233 | - false, |
|
| 234 | - false |
|
| 235 | - ), |
|
| 236 | - 'EVT_phone' => new EE_Plain_Text_Field( |
|
| 237 | - 'EVT_phone', |
|
| 238 | - esc_html__('Event Phone Number', 'event_espresso'), |
|
| 239 | - false, |
|
| 240 | - '' |
|
| 241 | - ), |
|
| 242 | - 'EVT_allow_overflow' => new EE_Boolean_Field( |
|
| 243 | - 'EVT_allow_overflow', |
|
| 244 | - esc_html__('Allow Overflow on Event', 'event_espresso'), |
|
| 245 | - false, |
|
| 246 | - false |
|
| 247 | - ), |
|
| 248 | - 'EVT_timezone_string' => new EE_Plain_Text_Field( |
|
| 249 | - 'EVT_timezone_string', |
|
| 250 | - esc_html__('Timezone (name) for Event times', 'event_espresso'), |
|
| 251 | - false, |
|
| 252 | - '' |
|
| 253 | - ), |
|
| 254 | - 'EVT_external_URL' => new EE_Plain_Text_Field( |
|
| 255 | - 'EVT_external_URL', |
|
| 256 | - esc_html__('URL of Event Page if hosted elsewhere', 'event_espresso'), |
|
| 257 | - true |
|
| 258 | - ), |
|
| 259 | - 'EVT_donations' => new EE_Boolean_Field( |
|
| 260 | - 'EVT_donations', |
|
| 261 | - esc_html__('Accept Donations?', 'event_espresso'), |
|
| 262 | - false, |
|
| 263 | - false |
|
| 264 | - ), |
|
| 265 | - ), |
|
| 266 | - ); |
|
| 267 | - $this->_model_relations = array( |
|
| 268 | - 'Registration' => new EE_Has_Many_Relation(), |
|
| 269 | - 'Datetime' => new EE_Has_Many_Relation(), |
|
| 270 | - 'Question_Group' => new EE_HABTM_Relation('Event_Question_Group'), |
|
| 271 | - 'Event_Question_Group' => new EE_Has_Many_Relation(), |
|
| 272 | - 'Venue' => new EE_HABTM_Relation('Event_Venue'), |
|
| 273 | - 'Term_Relationship' => new EE_Has_Many_Relation(), |
|
| 274 | - 'Term_Taxonomy' => new EE_HABTM_Relation('Term_Relationship'), |
|
| 275 | - 'Message_Template_Group' => new EE_HABTM_Relation('Event_Message_Template'), |
|
| 276 | - 'Attendee' => new EE_HABTM_Relation('Registration'), |
|
| 277 | - 'WP_User' => new EE_Belongs_To_Relation(), |
|
| 278 | - ); |
|
| 279 | - // this model is generally available for reading |
|
| 280 | - $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Public(); |
|
| 281 | - $this->model_chain_to_password = ''; |
|
| 282 | - parent::__construct($timezone); |
|
| 283 | - } |
|
| 284 | - |
|
| 285 | - |
|
| 286 | - |
|
| 287 | - /** |
|
| 288 | - * @param string $default_reg_status |
|
| 289 | - */ |
|
| 290 | - public static function set_default_reg_status($default_reg_status) |
|
| 291 | - { |
|
| 292 | - self::$_default_reg_status = $default_reg_status; |
|
| 293 | - // if EEM_Event has already been instantiated, |
|
| 294 | - // then we need to reset the `EVT_default_reg_status` field to use the new default. |
|
| 295 | - if (self::$_instance instanceof EEM_Event) { |
|
| 296 | - $default_reg_status = new EE_Enum_Text_Field( |
|
| 297 | - 'EVT_default_registration_status', |
|
| 298 | - esc_html__('Default Registration Status on this Event', 'event_espresso'), |
|
| 299 | - false, |
|
| 300 | - $default_reg_status, |
|
| 301 | - EEM_Registration::reg_status_array() |
|
| 302 | - ); |
|
| 303 | - $default_reg_status->_construct_finalize( |
|
| 304 | - 'Event_Meta', |
|
| 305 | - 'EVT_default_registration_status', |
|
| 306 | - 'EEM_Event' |
|
| 307 | - ); |
|
| 308 | - self::$_instance->_fields['Event_Meta']['EVT_default_registration_status'] = $default_reg_status; |
|
| 309 | - } |
|
| 310 | - } |
|
| 311 | - |
|
| 312 | - |
|
| 313 | - /** |
|
| 314 | - * Used to override the default for the additional limit field. |
|
| 315 | - * @param $additional_limit |
|
| 316 | - */ |
|
| 317 | - public static function set_default_additional_limit($additional_limit) |
|
| 318 | - { |
|
| 319 | - self::$_default_additional_limit = (int) $additional_limit; |
|
| 320 | - if (self::$_instance instanceof EEM_Event) { |
|
| 321 | - self::$_instance->_fields['Event_Meta']['EVT_additional_limit'] = new EE_Integer_Field( |
|
| 322 | - 'EVT_additional_limit', |
|
| 323 | - esc_html__('Limit of Additional Registrations on Same Transaction', 'event_espresso'), |
|
| 324 | - true, |
|
| 325 | - self::$_default_additional_limit |
|
| 326 | - ); |
|
| 327 | - self::$_instance->_fields['Event_Meta']['EVT_additional_limit']->_construct_finalize( |
|
| 328 | - 'Event_Meta', |
|
| 329 | - 'EVT_additional_limit', |
|
| 330 | - 'EEM_Event' |
|
| 331 | - ); |
|
| 332 | - } |
|
| 333 | - } |
|
| 334 | - |
|
| 335 | - |
|
| 336 | - /** |
|
| 337 | - * Return what is currently set as the default additional limit for the event. |
|
| 338 | - * @return int |
|
| 339 | - */ |
|
| 340 | - public static function get_default_additional_limit() |
|
| 341 | - { |
|
| 342 | - return apply_filters('FHEE__EEM_Event__get_default_additional_limit', self::$_default_additional_limit); |
|
| 343 | - } |
|
| 344 | - |
|
| 345 | - |
|
| 346 | - /** |
|
| 347 | - * get_question_groups |
|
| 348 | - * |
|
| 349 | - * @return array |
|
| 350 | - * @throws \EE_Error |
|
| 351 | - */ |
|
| 352 | - public function get_all_question_groups() |
|
| 353 | - { |
|
| 354 | - return EE_Registry::instance()->load_model('Question_Group')->get_all( |
|
| 355 | - array( |
|
| 356 | - array('QSG_deleted' => false), |
|
| 357 | - 'order_by' => array('QSG_order' => 'ASC'), |
|
| 358 | - ) |
|
| 359 | - ); |
|
| 360 | - } |
|
| 361 | - |
|
| 362 | - |
|
| 363 | - |
|
| 364 | - /** |
|
| 365 | - * get_question_groups |
|
| 366 | - * |
|
| 367 | - * @param int $EVT_ID |
|
| 368 | - * @return array|bool |
|
| 369 | - * @throws \EE_Error |
|
| 370 | - */ |
|
| 371 | - public function get_all_event_question_groups($EVT_ID = 0) |
|
| 372 | - { |
|
| 373 | - if (! isset($EVT_ID) || ! absint($EVT_ID)) { |
|
| 374 | - EE_Error::add_error( |
|
| 375 | - esc_html__( |
|
| 376 | - 'An error occurred. No Event Question Groups could be retrieved because an Event ID was not received.', |
|
| 377 | - 'event_espresso' |
|
| 378 | - ), |
|
| 379 | - __FILE__, |
|
| 380 | - __FUNCTION__, |
|
| 381 | - __LINE__ |
|
| 382 | - ); |
|
| 383 | - return false; |
|
| 384 | - } |
|
| 385 | - return EE_Registry::instance()->load_model('Event_Question_Group')->get_all( |
|
| 386 | - array( |
|
| 387 | - array('EVT_ID' => $EVT_ID), |
|
| 388 | - ) |
|
| 389 | - ); |
|
| 390 | - } |
|
| 391 | - |
|
| 392 | - |
|
| 393 | - /** |
|
| 394 | - * get_question_groups |
|
| 395 | - * |
|
| 396 | - * @param int $EVT_ID |
|
| 397 | - * @param boolean $for_primary_attendee |
|
| 398 | - * @return array|bool |
|
| 399 | - * @throws EE_Error |
|
| 400 | - * @throws InvalidArgumentException |
|
| 401 | - * @throws ReflectionException |
|
| 402 | - * @throws InvalidDataTypeException |
|
| 403 | - * @throws InvalidInterfaceException |
|
| 404 | - */ |
|
| 405 | - public function get_event_question_groups($EVT_ID = 0, $for_primary_attendee = true) |
|
| 406 | - { |
|
| 407 | - if (! isset($EVT_ID) || ! absint($EVT_ID)) { |
|
| 408 | - EE_Error::add_error( |
|
| 409 | - esc_html__( |
|
| 410 | - // @codingStandardsIgnoreStart |
|
| 411 | - 'An error occurred. No Event Question Groups could be retrieved because an Event ID was not received.', |
|
| 412 | - // @codingStandardsIgnoreEnd |
|
| 413 | - 'event_espresso' |
|
| 414 | - ), |
|
| 415 | - __FILE__, |
|
| 416 | - __FUNCTION__, |
|
| 417 | - __LINE__ |
|
| 418 | - ); |
|
| 419 | - return false; |
|
| 420 | - } |
|
| 421 | - $query_params = [ |
|
| 422 | - [ |
|
| 423 | - 'EVT_ID' => $EVT_ID, |
|
| 424 | - EEM_Event_Question_Group::instance()->fieldNameForContext($for_primary_attendee) => true |
|
| 425 | - ] |
|
| 426 | - ]; |
|
| 427 | - if ($for_primary_attendee) { |
|
| 428 | - $query_params[0]['EQG_primary'] = true; |
|
| 429 | - } else { |
|
| 430 | - $query_params[0]['EQG_additional'] = true; |
|
| 431 | - } |
|
| 432 | - return EE_Registry::instance()->load_model('Event_Question_Group')->get_all($query_params); |
|
| 433 | - } |
|
| 434 | - |
|
| 435 | - |
|
| 436 | - /** |
|
| 437 | - * get_question_groups |
|
| 438 | - * |
|
| 439 | - * @param int $EVT_ID |
|
| 440 | - * @param EE_Registration $registration |
|
| 441 | - * @return array|bool |
|
| 442 | - * @throws EE_Error |
|
| 443 | - * @throws InvalidArgumentException |
|
| 444 | - * @throws InvalidDataTypeException |
|
| 445 | - * @throws InvalidInterfaceException |
|
| 446 | - * @throws ReflectionException |
|
| 447 | - */ |
|
| 448 | - public function get_question_groups_for_event($EVT_ID, EE_Registration $registration) |
|
| 449 | - { |
|
| 450 | - if (! isset($EVT_ID) || ! absint($EVT_ID)) { |
|
| 451 | - EE_Error::add_error( |
|
| 452 | - esc_html__( |
|
| 453 | - 'An error occurred. No Question Groups could be retrieved because an Event ID was not received.', |
|
| 454 | - 'event_espresso' |
|
| 455 | - ), |
|
| 456 | - __FILE__, |
|
| 457 | - __FUNCTION__, |
|
| 458 | - __LINE__ |
|
| 459 | - ); |
|
| 460 | - return false; |
|
| 461 | - } |
|
| 462 | - return EE_Registry::instance()->load_model('Question_Group')->get_all( |
|
| 463 | - [ |
|
| 464 | - [ |
|
| 465 | - 'Event_Question_Group.EVT_ID' => $EVT_ID, |
|
| 466 | - 'Event_Question_Group.' |
|
| 467 | - . EEM_Event_Question_Group::instance()->fieldNameForContext( |
|
| 468 | - $registration->is_primary_registrant() |
|
| 469 | - ) => true |
|
| 470 | - ], |
|
| 471 | - 'order_by' => ['QSG_order' => 'ASC'], |
|
| 472 | - ] |
|
| 473 | - ); |
|
| 474 | - } |
|
| 475 | - |
|
| 476 | - |
|
| 477 | - |
|
| 478 | - /** |
|
| 479 | - * get_question_target_db_column |
|
| 480 | - * |
|
| 481 | - * @param string $QSG_IDs csv list of $QSG IDs |
|
| 482 | - * @return array|bool |
|
| 483 | - * @throws \EE_Error |
|
| 484 | - */ |
|
| 485 | - public function get_questions_in_groups($QSG_IDs = '') |
|
| 486 | - { |
|
| 487 | - if (empty($QSG_IDs)) { |
|
| 488 | - EE_Error::add_error( |
|
| 489 | - esc_html__('An error occurred. No Question Group IDs were received.', 'event_espresso'), |
|
| 490 | - __FILE__, |
|
| 491 | - __FUNCTION__, |
|
| 492 | - __LINE__ |
|
| 493 | - ); |
|
| 494 | - return false; |
|
| 495 | - } |
|
| 496 | - return EE_Registry::instance()->load_model('Question')->get_all( |
|
| 497 | - array( |
|
| 498 | - array( |
|
| 499 | - 'Question_Group.QSG_ID' => array('IN', $QSG_IDs), |
|
| 500 | - 'QST_deleted' => false, |
|
| 501 | - 'QST_admin_only' => is_admin(), |
|
| 502 | - ), |
|
| 503 | - 'order_by' => 'QST_order', |
|
| 504 | - ) |
|
| 505 | - ); |
|
| 506 | - } |
|
| 507 | - |
|
| 508 | - |
|
| 509 | - |
|
| 510 | - /** |
|
| 511 | - * get_options_for_question |
|
| 512 | - * |
|
| 513 | - * @param string $QST_IDs csv list of $QST IDs |
|
| 514 | - * @return array|bool |
|
| 515 | - * @throws \EE_Error |
|
| 516 | - */ |
|
| 517 | - public function get_options_for_question($QST_IDs) |
|
| 518 | - { |
|
| 519 | - if (empty($QST_IDs)) { |
|
| 520 | - EE_Error::add_error( |
|
| 521 | - esc_html__('An error occurred. No Question IDs were received.', 'event_espresso'), |
|
| 522 | - __FILE__, |
|
| 523 | - __FUNCTION__, |
|
| 524 | - __LINE__ |
|
| 525 | - ); |
|
| 526 | - return false; |
|
| 527 | - } |
|
| 528 | - return EE_Registry::instance()->load_model('Question_Option')->get_all( |
|
| 529 | - array( |
|
| 530 | - array( |
|
| 531 | - 'Question.QST_ID' => array('IN', $QST_IDs), |
|
| 532 | - 'QSO_deleted' => false, |
|
| 533 | - ), |
|
| 534 | - 'order_by' => 'QSO_ID', |
|
| 535 | - ) |
|
| 536 | - ); |
|
| 537 | - } |
|
| 538 | - |
|
| 539 | - |
|
| 540 | - |
|
| 541 | - |
|
| 542 | - |
|
| 543 | - |
|
| 544 | - |
|
| 545 | - /** |
|
| 546 | - * Gets all events that are published |
|
| 547 | - * and have event start time earlier than now and an event end time later than now |
|
| 548 | - * |
|
| 549 | - * @param array $query_params An array of query params to further filter on |
|
| 550 | - * (note that status and DTT_EVT_start and DTT_EVT_end will be overridden) |
|
| 551 | - * @param bool $count whether to return the count or not (default FALSE) |
|
| 552 | - * @return EE_Event[]|int |
|
| 553 | - * @throws \EE_Error |
|
| 554 | - */ |
|
| 555 | - public function get_active_events($query_params, $count = false) |
|
| 556 | - { |
|
| 557 | - if (array_key_exists(0, $query_params)) { |
|
| 558 | - $where_params = $query_params[0]; |
|
| 559 | - unset($query_params[0]); |
|
| 560 | - } else { |
|
| 561 | - $where_params = array(); |
|
| 562 | - } |
|
| 563 | - // if we have count make sure we don't include group by |
|
| 564 | - if ($count && isset($query_params['group_by'])) { |
|
| 565 | - unset($query_params['group_by']); |
|
| 566 | - } |
|
| 567 | - // let's add specific query_params for active_events |
|
| 568 | - // keep in mind this will override any sent status in the query AND any date queries. |
|
| 569 | - $where_params['status'] = array('IN', array('publish', EEM_Event::sold_out)); |
|
| 570 | - // if already have where params for DTT_EVT_start or DTT_EVT_end then append these conditions |
|
| 571 | - if (isset($where_params['Datetime.DTT_EVT_start'])) { |
|
| 572 | - $where_params['Datetime.DTT_EVT_start******'] = array( |
|
| 573 | - '<', |
|
| 574 | - EEM_Datetime::instance()->current_time_for_query('DTT_EVT_start'), |
|
| 575 | - ); |
|
| 576 | - } else { |
|
| 577 | - $where_params['Datetime.DTT_EVT_start'] = array( |
|
| 578 | - '<', |
|
| 579 | - EEM_Datetime::instance()->current_time_for_query('DTT_EVT_start'), |
|
| 580 | - ); |
|
| 581 | - } |
|
| 582 | - if (isset($where_params['Datetime.DTT_EVT_end'])) { |
|
| 583 | - $where_params['Datetime.DTT_EVT_end*****'] = array( |
|
| 584 | - '>', |
|
| 585 | - EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'), |
|
| 586 | - ); |
|
| 587 | - } else { |
|
| 588 | - $where_params['Datetime.DTT_EVT_end'] = array( |
|
| 589 | - '>', |
|
| 590 | - EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'), |
|
| 591 | - ); |
|
| 592 | - } |
|
| 593 | - $query_params[0] = $where_params; |
|
| 594 | - // don't use $query_params with count() |
|
| 595 | - // because we don't want to include additional query clauses like "GROUP BY" |
|
| 596 | - return $count |
|
| 597 | - ? $this->count(array($where_params), 'EVT_ID', true) |
|
| 598 | - : $this->get_all($query_params); |
|
| 599 | - } |
|
| 600 | - |
|
| 601 | - |
|
| 602 | - |
|
| 603 | - /** |
|
| 604 | - * get all events that are published and have an event start time later than now |
|
| 605 | - * |
|
| 606 | - * @param array $query_params An array of query params to further filter on |
|
| 607 | - * (Note that status and DTT_EVT_start will be overridden) |
|
| 608 | - * @param bool $count whether to return the count or not (default FALSE) |
|
| 609 | - * @return EE_Event[]|int |
|
| 610 | - * @throws \EE_Error |
|
| 611 | - */ |
|
| 612 | - public function get_upcoming_events($query_params, $count = false) |
|
| 613 | - { |
|
| 614 | - if (array_key_exists(0, $query_params)) { |
|
| 615 | - $where_params = $query_params[0]; |
|
| 616 | - unset($query_params[0]); |
|
| 617 | - } else { |
|
| 618 | - $where_params = array(); |
|
| 619 | - } |
|
| 620 | - // if we have count make sure we don't include group by |
|
| 621 | - if ($count && isset($query_params['group_by'])) { |
|
| 622 | - unset($query_params['group_by']); |
|
| 623 | - } |
|
| 624 | - // let's add specific query_params for active_events |
|
| 625 | - // keep in mind this will override any sent status in the query AND any date queries. |
|
| 626 | - // we need to pull events with a status of publish and sold_out |
|
| 627 | - $event_status = array('publish', EEM_Event::sold_out); |
|
| 628 | - // check if the user can read private events and if so add the 'private status to the were params' |
|
| 629 | - if (EE_Registry::instance()->CAP->current_user_can('ee_read_private_events', 'get_upcoming_events')) { |
|
| 630 | - $event_status[] = 'private'; |
|
| 631 | - } |
|
| 632 | - $where_params['status'] = array('IN', $event_status); |
|
| 633 | - // if there are already query_params matching DTT_EVT_start then we need to modify that to add them. |
|
| 634 | - if (isset($where_params['Datetime.DTT_EVT_start'])) { |
|
| 635 | - $where_params['Datetime.DTT_EVT_start*****'] = array( |
|
| 636 | - '>', |
|
| 637 | - EEM_Datetime::instance()->current_time_for_query('DTT_EVT_start'), |
|
| 638 | - ); |
|
| 639 | - } else { |
|
| 640 | - $where_params['Datetime.DTT_EVT_start'] = array( |
|
| 641 | - '>', |
|
| 642 | - EEM_Datetime::instance()->current_time_for_query('DTT_EVT_start'), |
|
| 643 | - ); |
|
| 644 | - } |
|
| 645 | - $query_params[0] = $where_params; |
|
| 646 | - // don't use $query_params with count() |
|
| 647 | - // because we don't want to include additional query clauses like "GROUP BY" |
|
| 648 | - return $count |
|
| 649 | - ? $this->count(array($where_params), 'EVT_ID', true) |
|
| 650 | - : $this->get_all($query_params); |
|
| 651 | - } |
|
| 652 | - |
|
| 653 | - |
|
| 654 | - |
|
| 655 | - /** |
|
| 656 | - * Gets all events that are published |
|
| 657 | - * and have an event end time later than now |
|
| 658 | - * |
|
| 659 | - * @param array $query_params An array of query params to further filter on |
|
| 660 | - * (note that status and DTT_EVT_end will be overridden) |
|
| 661 | - * @param bool $count whether to return the count or not (default FALSE) |
|
| 662 | - * @return EE_Event[]|int |
|
| 663 | - * @throws \EE_Error |
|
| 664 | - */ |
|
| 665 | - public function get_active_and_upcoming_events($query_params, $count = false) |
|
| 666 | - { |
|
| 667 | - if (array_key_exists(0, $query_params)) { |
|
| 668 | - $where_params = $query_params[0]; |
|
| 669 | - unset($query_params[0]); |
|
| 670 | - } else { |
|
| 671 | - $where_params = array(); |
|
| 672 | - } |
|
| 673 | - // if we have count make sure we don't include group by |
|
| 674 | - if ($count && isset($query_params['group_by'])) { |
|
| 675 | - unset($query_params['group_by']); |
|
| 676 | - } |
|
| 677 | - // let's add specific query_params for active_events |
|
| 678 | - // keep in mind this will override any sent status in the query AND any date queries. |
|
| 679 | - $where_params['status'] = array('IN', array('publish', EEM_Event::sold_out)); |
|
| 680 | - // add where params for DTT_EVT_end |
|
| 681 | - if (isset($where_params['Datetime.DTT_EVT_end'])) { |
|
| 682 | - $where_params['Datetime.DTT_EVT_end*****'] = array( |
|
| 683 | - '>', |
|
| 684 | - EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'), |
|
| 685 | - ); |
|
| 686 | - } else { |
|
| 687 | - $where_params['Datetime.DTT_EVT_end'] = array( |
|
| 688 | - '>', |
|
| 689 | - EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'), |
|
| 690 | - ); |
|
| 691 | - } |
|
| 692 | - $query_params[0] = $where_params; |
|
| 693 | - // don't use $query_params with count() |
|
| 694 | - // because we don't want to include additional query clauses like "GROUP BY" |
|
| 695 | - return $count |
|
| 696 | - ? $this->count(array($where_params), 'EVT_ID', true) |
|
| 697 | - : $this->get_all($query_params); |
|
| 698 | - } |
|
| 699 | - |
|
| 700 | - |
|
| 701 | - |
|
| 702 | - /** |
|
| 703 | - * This only returns events that are expired. |
|
| 704 | - * They may still be published but all their datetimes have expired. |
|
| 705 | - * |
|
| 706 | - * @param array $query_params An array of query params to further filter on |
|
| 707 | - * (note that status and DTT_EVT_end will be overridden) |
|
| 708 | - * @param bool $count whether to return the count or not (default FALSE) |
|
| 709 | - * @return EE_Event[]|int |
|
| 710 | - * @throws \EE_Error |
|
| 711 | - */ |
|
| 712 | - public function get_expired_events($query_params, $count = false) |
|
| 713 | - { |
|
| 714 | - $where_params = isset($query_params[0]) ? $query_params[0] : array(); |
|
| 715 | - // if we have count make sure we don't include group by |
|
| 716 | - if ($count && isset($query_params['group_by'])) { |
|
| 717 | - unset($query_params['group_by']); |
|
| 718 | - } |
|
| 719 | - // let's add specific query_params for active_events |
|
| 720 | - // keep in mind this will override any sent status in the query AND any date queries. |
|
| 721 | - if (isset($where_params['status'])) { |
|
| 722 | - unset($where_params['status']); |
|
| 723 | - } |
|
| 724 | - $exclude_query = $query_params; |
|
| 725 | - if (isset($exclude_query[0])) { |
|
| 726 | - unset($exclude_query[0]); |
|
| 727 | - } |
|
| 728 | - $exclude_query[0] = array( |
|
| 729 | - 'Datetime.DTT_EVT_end' => array( |
|
| 730 | - '>', |
|
| 731 | - EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'), |
|
| 732 | - ), |
|
| 733 | - ); |
|
| 734 | - // first get all events that have datetimes where its not expired. |
|
| 735 | - $event_ids = $this->_get_all_wpdb_results($exclude_query, OBJECT_K, 'Event_CPT.ID'); |
|
| 736 | - $event_ids = array_keys($event_ids); |
|
| 737 | - // if we have any additional query_params, let's add them to the 'AND' condition |
|
| 738 | - $and_condition = array( |
|
| 739 | - 'Datetime.DTT_EVT_end' => array('<', EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end')), |
|
| 740 | - 'EVT_ID' => array('NOT IN', $event_ids), |
|
| 741 | - ); |
|
| 742 | - if (isset($where_params['OR'])) { |
|
| 743 | - $and_condition['OR'] = $where_params['OR']; |
|
| 744 | - unset($where_params['OR']); |
|
| 745 | - } |
|
| 746 | - if (isset($where_params['Datetime.DTT_EVT_end'])) { |
|
| 747 | - $and_condition['Datetime.DTT_EVT_end****'] = $where_params['Datetime.DTT_EVT_end']; |
|
| 748 | - unset($where_params['Datetime.DTT_EVT_end']); |
|
| 749 | - } |
|
| 750 | - if (isset($where_params['Datetime.DTT_EVT_start'])) { |
|
| 751 | - $and_condition['Datetime.DTT_EVT_start'] = $where_params['Datetime.DTT_EVT_start']; |
|
| 752 | - unset($where_params['Datetime.DTT_EVT_start']); |
|
| 753 | - } |
|
| 754 | - // merge remaining $where params with the and conditions. |
|
| 755 | - $where_params['AND'] = array_merge($and_condition, $where_params); |
|
| 756 | - $query_params[0] = $where_params; |
|
| 757 | - // don't use $query_params with count() |
|
| 758 | - // because we don't want to include additional query clauses like "GROUP BY" |
|
| 759 | - return $count |
|
| 760 | - ? $this->count(array($where_params), 'EVT_ID', true) |
|
| 761 | - : $this->get_all($query_params); |
|
| 762 | - } |
|
| 763 | - |
|
| 764 | - |
|
| 765 | - |
|
| 766 | - /** |
|
| 767 | - * This basically just returns the events that do not have the publish status. |
|
| 768 | - * |
|
| 769 | - * @param array $query_params An array of query params to further filter on |
|
| 770 | - * (note that status will be overwritten) |
|
| 771 | - * @param boolean $count whether to return the count or not (default FALSE) |
|
| 772 | - * @return EE_Event[]|int |
|
| 773 | - * @throws \EE_Error |
|
| 774 | - */ |
|
| 775 | - public function get_inactive_events($query_params, $count = false) |
|
| 776 | - { |
|
| 777 | - $where_params = isset($query_params[0]) ? $query_params[0] : array(); |
|
| 778 | - // let's add in specific query_params for inactive events. |
|
| 779 | - if (isset($where_params['status'])) { |
|
| 780 | - unset($where_params['status']); |
|
| 781 | - } |
|
| 782 | - // if we have count make sure we don't include group by |
|
| 783 | - if ($count && isset($query_params['group_by'])) { |
|
| 784 | - unset($query_params['group_by']); |
|
| 785 | - } |
|
| 786 | - // if we have any additional query_params, let's add them to the 'AND' condition |
|
| 787 | - $where_params['AND']['status'] = array('!=', 'publish'); |
|
| 788 | - if (isset($where_params['OR'])) { |
|
| 789 | - $where_params['AND']['OR'] = $where_params['OR']; |
|
| 790 | - unset($where_params['OR']); |
|
| 791 | - } |
|
| 792 | - if (isset($where_params['Datetime.DTT_EVT_end'])) { |
|
| 793 | - $where_params['AND']['Datetime.DTT_EVT_end****'] = $where_params['Datetime.DTT_EVT_end']; |
|
| 794 | - unset($where_params['Datetime.DTT_EVT_end']); |
|
| 795 | - } |
|
| 796 | - if (isset($where_params['Datetime.DTT_EVT_start'])) { |
|
| 797 | - $where_params['AND']['Datetime.DTT_EVT_start'] = $where_params['Datetime.DTT_EVT_start']; |
|
| 798 | - unset($where_params['Datetime.DTT_EVT_start']); |
|
| 799 | - } |
|
| 800 | - $query_params[0] = $where_params; |
|
| 801 | - // don't use $query_params with count() |
|
| 802 | - // because we don't want to include additional query clauses like "GROUP BY" |
|
| 803 | - return $count |
|
| 804 | - ? $this->count(array($where_params), 'EVT_ID', true) |
|
| 805 | - : $this->get_all($query_params); |
|
| 806 | - } |
|
| 807 | - |
|
| 808 | - |
|
| 809 | - |
|
| 810 | - /** |
|
| 811 | - * This is just injecting into the parent add_relationship_to so we do special handling on price relationships |
|
| 812 | - * because we don't want to override any existing global default prices but instead insert NEW prices that get |
|
| 813 | - * attached to the event. See parent for param descriptions |
|
| 814 | - * |
|
| 815 | - * @param $id_or_obj |
|
| 816 | - * @param $other_model_id_or_obj |
|
| 817 | - * @param string $relationName |
|
| 818 | - * @param array $where_query |
|
| 819 | - * @return EE_Base_Class |
|
| 820 | - * @throws EE_Error |
|
| 821 | - */ |
|
| 822 | - public function add_relationship_to($id_or_obj, $other_model_id_or_obj, $relationName, $where_query = array()) |
|
| 823 | - { |
|
| 824 | - if ($relationName === 'Price') { |
|
| 825 | - // let's get the PRC object for the given ID to make sure that we aren't dealing with a default |
|
| 826 | - $prc_chk = $this->get_related_model_obj($relationName)->ensure_is_obj($other_model_id_or_obj); |
|
| 827 | - // if EVT_ID = 0, then this is a default |
|
| 828 | - if ((int) $prc_chk->get('EVT_ID') === 0) { |
|
| 829 | - // let's set the prc_id as 0 so we force an insert on the add_relation_to carried out by relation |
|
| 830 | - $prc_chk->set('PRC_ID', 0); |
|
| 831 | - } |
|
| 832 | - // run parent |
|
| 833 | - return parent::add_relationship_to($id_or_obj, $prc_chk, $relationName, $where_query); |
|
| 834 | - } |
|
| 835 | - // otherwise carry on as normal |
|
| 836 | - return parent::add_relationship_to($id_or_obj, $other_model_id_or_obj, $relationName, $where_query); |
|
| 837 | - } |
|
| 838 | - |
|
| 839 | - |
|
| 840 | - |
|
| 841 | - /******************** DEPRECATED METHODS ********************/ |
|
| 842 | - |
|
| 843 | - |
|
| 844 | - |
|
| 845 | - /** |
|
| 846 | - * _get_question_target_db_column |
|
| 847 | - * |
|
| 848 | - * @deprecated as of 4.8.32.rc.001. Instead consider using |
|
| 849 | - * EE_Registration_Custom_Questions_Form located in |
|
| 850 | - * admin_pages/registrations/form_sections/EE_Registration_Custom_Questions_Form.form.php |
|
| 851 | - * @access public |
|
| 852 | - * @param EE_Registration $registration (so existing answers for registration are included) |
|
| 853 | - * @param int $EVT_ID so all question groups are included for event (not just answers from |
|
| 854 | - * registration). |
|
| 855 | - * @throws EE_Error |
|
| 856 | - * @return array |
|
| 857 | - */ |
|
| 858 | - public function assemble_array_of_groups_questions_and_options(EE_Registration $registration, $EVT_ID = 0) |
|
| 859 | - { |
|
| 860 | - if (empty($EVT_ID)) { |
|
| 861 | - throw new EE_Error(esc_html__( |
|
| 862 | - 'An error occurred. No EVT_ID is included. Needed to know which question groups to retrieve.', |
|
| 863 | - 'event_espresso' |
|
| 864 | - )); |
|
| 865 | - } |
|
| 866 | - $questions = array(); |
|
| 867 | - // get all question groups for event |
|
| 868 | - $qgs = $this->get_question_groups_for_event($EVT_ID, $registration); |
|
| 869 | - if (! empty($qgs)) { |
|
| 870 | - foreach ($qgs as $qg) { |
|
| 871 | - $qsts = $qg->questions(); |
|
| 872 | - $questions[ $qg->ID() ] = $qg->model_field_array(); |
|
| 873 | - $questions[ $qg->ID() ]['QSG_questions'] = array(); |
|
| 874 | - foreach ($qsts as $qst) { |
|
| 875 | - if ($qst->is_system_question()) { |
|
| 876 | - continue; |
|
| 877 | - } |
|
| 878 | - $answer = EEM_Answer::instance()->get_one(array( |
|
| 879 | - array( |
|
| 880 | - 'QST_ID' => $qst->ID(), |
|
| 881 | - 'REG_ID' => $registration->ID(), |
|
| 882 | - ), |
|
| 883 | - )); |
|
| 884 | - $answer = $answer instanceof EE_Answer ? $answer : EEM_Answer::instance()->create_default_object(); |
|
| 885 | - $qst_name = $qstn_id = $qst->ID(); |
|
| 886 | - $ans_id = $answer->ID(); |
|
| 887 | - $qst_name = ! empty($ans_id) ? '[' . $qst_name . '][' . $ans_id . ']' : '[' . $qst_name . ']'; |
|
| 888 | - $input_name = ''; |
|
| 889 | - $input_id = sanitize_key($qst->display_text()); |
|
| 890 | - $input_class = ''; |
|
| 891 | - $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ] = $qst->model_field_array(); |
|
| 892 | - $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['QST_input_name'] = 'qstn' |
|
| 893 | - . $input_name |
|
| 894 | - . $qst_name; |
|
| 895 | - $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['QST_input_id'] = $input_id . '-' . $qstn_id; |
|
| 896 | - $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['QST_input_class'] = $input_class; |
|
| 897 | - $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['QST_options'] = array(); |
|
| 898 | - $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['qst_obj'] = $qst; |
|
| 899 | - $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['ans_obj'] = $answer; |
|
| 900 | - // leave responses as-is, don't convert stuff into html entities please! |
|
| 901 | - $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['htmlentities'] = false; |
|
| 902 | - if ($qst->type() == 'RADIO_BTN' || $qst->type() == 'CHECKBOX' || $qst->type() == 'DROPDOWN') { |
|
| 903 | - $QSOs = $qst->options(true, $answer->value()); |
|
| 904 | - if (is_array($QSOs)) { |
|
| 905 | - foreach ($QSOs as $QSO_ID => $QSO) { |
|
| 906 | - $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['QST_options'][ $QSO_ID ] = $QSO->model_field_array(); |
|
| 907 | - } |
|
| 908 | - } |
|
| 909 | - } |
|
| 910 | - } |
|
| 911 | - } |
|
| 912 | - } |
|
| 913 | - return $questions; |
|
| 914 | - } |
|
| 915 | - |
|
| 916 | - |
|
| 917 | - /** |
|
| 918 | - * @param mixed $cols_n_values either an array of where each key is the name of a field, and the value is its value |
|
| 919 | - * or an stdClass where each property is the name of a column, |
|
| 920 | - * @return EE_Base_Class |
|
| 921 | - * @throws \EE_Error |
|
| 922 | - */ |
|
| 923 | - public function instantiate_class_from_array_or_object($cols_n_values) |
|
| 924 | - { |
|
| 925 | - $classInstance = parent::instantiate_class_from_array_or_object($cols_n_values); |
|
| 926 | - if ($classInstance instanceof EE_Event) { |
|
| 927 | - // events have their timezone defined in the DB, so use it immediately |
|
| 928 | - $this->set_timezone($classInstance->get_timezone()); |
|
| 929 | - } |
|
| 930 | - return $classInstance; |
|
| 931 | - } |
|
| 932 | - |
|
| 933 | - |
|
| 934 | - /** |
|
| 935 | - * Deletes the model objects that meet the query params. Note: this method is overridden |
|
| 936 | - * in EEM_Soft_Delete_Base so that soft-deleted model objects are instead only flagged |
|
| 937 | - * as archived, not actually deleted |
|
| 938 | - * |
|
| 939 | - * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
| 940 | - * @param boolean $allow_blocking if TRUE, matched objects will only be deleted if there is no related model info |
|
| 941 | - * that blocks it (ie, there' sno other data that depends on this data); if false, |
|
| 942 | - * deletes regardless of other objects which may depend on it. Its generally |
|
| 943 | - * advisable to always leave this as TRUE, otherwise you could easily corrupt your |
|
| 944 | - * DB |
|
| 945 | - * @return int number of rows deleted |
|
| 946 | - * @throws EE_Error |
|
| 947 | - */ |
|
| 948 | - public function delete_permanently($query_params, $allow_blocking = true) |
|
| 949 | - { |
|
| 950 | - $deleted = parent::delete_permanently($query_params, $allow_blocking); |
|
| 951 | - if ($deleted) { |
|
| 952 | - // get list of events with no prices |
|
| 953 | - $espresso_no_ticket_prices = get_option('ee_no_ticket_prices', []); |
|
| 954 | - $where = isset($query_params[0]) ? $query_params[0] : []; |
|
| 955 | - $where_event = isset($where['EVT_ID']) ? $where['EVT_ID'] : ['', '']; |
|
| 956 | - $where_event_ids = isset($where_event[1]) ? $where_event[1] : ''; |
|
| 957 | - $event_ids = is_string($where_event_ids) |
|
| 958 | - ? explode(',', $where_event_ids) |
|
| 959 | - : (array) $where_event_ids; |
|
| 960 | - array_walk($event_ids, 'trim'); |
|
| 961 | - $event_ids = array_filter($event_ids); |
|
| 962 | - // remove events from list of events with no prices |
|
| 963 | - $espresso_no_ticket_prices = array_diff($espresso_no_ticket_prices, $event_ids); |
|
| 964 | - update_option('ee_no_ticket_prices', $espresso_no_ticket_prices); |
|
| 965 | - } |
|
| 966 | - return $deleted; |
|
| 967 | - } |
|
| 17 | + /** |
|
| 18 | + * constant used by status(), indicating that no more tickets can be purchased for any of the datetimes for the |
|
| 19 | + * event |
|
| 20 | + */ |
|
| 21 | + const sold_out = 'sold_out'; |
|
| 22 | + |
|
| 23 | + /** |
|
| 24 | + * constant used by status(), indicating that upcoming event dates have been postponed (may be pushed to a later |
|
| 25 | + * date) |
|
| 26 | + */ |
|
| 27 | + const postponed = 'postponed'; |
|
| 28 | + |
|
| 29 | + /** |
|
| 30 | + * constant used by status(), indicating that the event will no longer occur |
|
| 31 | + */ |
|
| 32 | + const cancelled = 'cancelled'; |
|
| 33 | + |
|
| 34 | + |
|
| 35 | + /** |
|
| 36 | + * @var string |
|
| 37 | + */ |
|
| 38 | + protected static $_default_reg_status; |
|
| 39 | + |
|
| 40 | + |
|
| 41 | + /** |
|
| 42 | + * This is the default for the additional limit field. |
|
| 43 | + * @var int |
|
| 44 | + */ |
|
| 45 | + protected static $_default_additional_limit = 10; |
|
| 46 | + |
|
| 47 | + |
|
| 48 | + /** |
|
| 49 | + * private instance of the Event object |
|
| 50 | + * |
|
| 51 | + * @var EEM_Event |
|
| 52 | + */ |
|
| 53 | + protected static $_instance; |
|
| 54 | + |
|
| 55 | + |
|
| 56 | + |
|
| 57 | + |
|
| 58 | + /** |
|
| 59 | + * Adds a relationship to Term_Taxonomy for each CPT_Base |
|
| 60 | + * |
|
| 61 | + * @param string $timezone |
|
| 62 | + * @throws \EE_Error |
|
| 63 | + */ |
|
| 64 | + protected function __construct($timezone = null) |
|
| 65 | + { |
|
| 66 | + EE_Registry::instance()->load_model('Registration'); |
|
| 67 | + $this->singular_item = esc_html__('Event', 'event_espresso'); |
|
| 68 | + $this->plural_item = esc_html__('Events', 'event_espresso'); |
|
| 69 | + // to remove Cancelled events from the frontend, copy the following filter to your functions.php file |
|
| 70 | + // add_filter( 'AFEE__EEM_Event__construct___custom_stati__cancelled__Public', '__return_false' ); |
|
| 71 | + // to remove Postponed events from the frontend, copy the following filter to your functions.php file |
|
| 72 | + // add_filter( 'AFEE__EEM_Event__construct___custom_stati__postponed__Public', '__return_false' ); |
|
| 73 | + // to remove Sold Out events from the frontend, copy the following filter to your functions.php file |
|
| 74 | + // add_filter( 'AFEE__EEM_Event__construct___custom_stati__sold_out__Public', '__return_false' ); |
|
| 75 | + $this->_custom_stati = apply_filters( |
|
| 76 | + 'AFEE__EEM_Event__construct___custom_stati', |
|
| 77 | + array( |
|
| 78 | + EEM_Event::cancelled => array( |
|
| 79 | + 'label' => esc_html__('Cancelled', 'event_espresso'), |
|
| 80 | + 'public' => apply_filters('AFEE__EEM_Event__construct___custom_stati__cancelled__Public', true), |
|
| 81 | + ), |
|
| 82 | + EEM_Event::postponed => array( |
|
| 83 | + 'label' => esc_html__('Postponed', 'event_espresso'), |
|
| 84 | + 'public' => apply_filters('AFEE__EEM_Event__construct___custom_stati__postponed__Public', true), |
|
| 85 | + ), |
|
| 86 | + EEM_Event::sold_out => array( |
|
| 87 | + 'label' => esc_html__('Sold Out', 'event_espresso'), |
|
| 88 | + 'public' => apply_filters('AFEE__EEM_Event__construct___custom_stati__sold_out__Public', true), |
|
| 89 | + ), |
|
| 90 | + ) |
|
| 91 | + ); |
|
| 92 | + self::$_default_reg_status = empty(self::$_default_reg_status) ? EEM_Registration::status_id_pending_payment |
|
| 93 | + : self::$_default_reg_status; |
|
| 94 | + $this->_tables = array( |
|
| 95 | + 'Event_CPT' => new EE_Primary_Table('posts', 'ID'), |
|
| 96 | + 'Event_Meta' => new EE_Secondary_Table('esp_event_meta', 'EVTM_ID', 'EVT_ID'), |
|
| 97 | + ); |
|
| 98 | + $this->_fields = array( |
|
| 99 | + 'Event_CPT' => array( |
|
| 100 | + 'EVT_ID' => new EE_Primary_Key_Int_Field( |
|
| 101 | + 'ID', |
|
| 102 | + esc_html__('Post ID for Event', 'event_espresso') |
|
| 103 | + ), |
|
| 104 | + 'EVT_name' => new EE_Plain_Text_Field( |
|
| 105 | + 'post_title', |
|
| 106 | + esc_html__('Event Name', 'event_espresso'), |
|
| 107 | + false, |
|
| 108 | + '' |
|
| 109 | + ), |
|
| 110 | + 'EVT_desc' => new EE_Post_Content_Field( |
|
| 111 | + 'post_content', |
|
| 112 | + esc_html__('Event Description', 'event_espresso'), |
|
| 113 | + false, |
|
| 114 | + '' |
|
| 115 | + ), |
|
| 116 | + 'EVT_slug' => new EE_Slug_Field( |
|
| 117 | + 'post_name', |
|
| 118 | + esc_html__('Event Slug', 'event_espresso'), |
|
| 119 | + false, |
|
| 120 | + '' |
|
| 121 | + ), |
|
| 122 | + 'EVT_created' => new EE_Datetime_Field( |
|
| 123 | + 'post_date', |
|
| 124 | + esc_html__('Date/Time Event Created', 'event_espresso'), |
|
| 125 | + false, |
|
| 126 | + EE_Datetime_Field::now |
|
| 127 | + ), |
|
| 128 | + 'EVT_short_desc' => new EE_Simple_HTML_Field( |
|
| 129 | + 'post_excerpt', |
|
| 130 | + esc_html__('Event Short Description', 'event_espresso'), |
|
| 131 | + false, |
|
| 132 | + '' |
|
| 133 | + ), |
|
| 134 | + 'EVT_modified' => new EE_Datetime_Field( |
|
| 135 | + 'post_modified', |
|
| 136 | + esc_html__('Date/Time Event Modified', 'event_espresso'), |
|
| 137 | + false, |
|
| 138 | + EE_Datetime_Field::now |
|
| 139 | + ), |
|
| 140 | + 'EVT_wp_user' => new EE_WP_User_Field( |
|
| 141 | + 'post_author', |
|
| 142 | + esc_html__('Event Creator ID', 'event_espresso'), |
|
| 143 | + false |
|
| 144 | + ), |
|
| 145 | + 'parent' => new EE_Integer_Field( |
|
| 146 | + 'post_parent', |
|
| 147 | + esc_html__('Event Parent ID', 'event_espresso'), |
|
| 148 | + false, |
|
| 149 | + 0 |
|
| 150 | + ), |
|
| 151 | + 'EVT_order' => new EE_Integer_Field( |
|
| 152 | + 'menu_order', |
|
| 153 | + esc_html__('Event Menu Order', 'event_espresso'), |
|
| 154 | + false, |
|
| 155 | + 1 |
|
| 156 | + ), |
|
| 157 | + 'post_type' => new EE_WP_Post_Type_Field('espresso_events'), |
|
| 158 | + // EE_Plain_Text_Field( 'post_type', esc_html__( 'Event Post Type', 'event_espresso' ), FALSE, 'espresso_events' ), |
|
| 159 | + 'status' => new EE_WP_Post_Status_Field( |
|
| 160 | + 'post_status', |
|
| 161 | + esc_html__('Event Status', 'event_espresso'), |
|
| 162 | + false, |
|
| 163 | + 'draft', |
|
| 164 | + $this->_custom_stati |
|
| 165 | + ), |
|
| 166 | + 'password' => new EE_Password_Field( |
|
| 167 | + 'post_password', |
|
| 168 | + esc_html__('Password', 'event_espresso'), |
|
| 169 | + false, |
|
| 170 | + '', |
|
| 171 | + array( |
|
| 172 | + 'EVT_desc', |
|
| 173 | + 'EVT_short_desc', |
|
| 174 | + 'EVT_display_desc', |
|
| 175 | + 'EVT_display_ticket_selector', |
|
| 176 | + 'EVT_visible_on', |
|
| 177 | + 'EVT_additional_limit', |
|
| 178 | + 'EVT_default_registration_status', |
|
| 179 | + 'EVT_member_only', |
|
| 180 | + 'EVT_phone', |
|
| 181 | + 'EVT_allow_overflow', |
|
| 182 | + 'EVT_timezone_string', |
|
| 183 | + 'EVT_external_URL', |
|
| 184 | + 'EVT_donations' |
|
| 185 | + ) |
|
| 186 | + ) |
|
| 187 | + ), |
|
| 188 | + 'Event_Meta' => array( |
|
| 189 | + 'EVTM_ID' => new EE_DB_Only_Float_Field( |
|
| 190 | + 'EVTM_ID', |
|
| 191 | + esc_html__('Event Meta Row ID', 'event_espresso'), |
|
| 192 | + false |
|
| 193 | + ), |
|
| 194 | + 'EVT_ID_fk' => new EE_DB_Only_Int_Field( |
|
| 195 | + 'EVT_ID', |
|
| 196 | + esc_html__('Foreign key to Event ID from Event Meta table', 'event_espresso'), |
|
| 197 | + false |
|
| 198 | + ), |
|
| 199 | + 'EVT_display_desc' => new EE_Boolean_Field( |
|
| 200 | + 'EVT_display_desc', |
|
| 201 | + esc_html__('Display Description Flag', 'event_espresso'), |
|
| 202 | + false, |
|
| 203 | + true |
|
| 204 | + ), |
|
| 205 | + 'EVT_display_ticket_selector' => new EE_Boolean_Field( |
|
| 206 | + 'EVT_display_ticket_selector', |
|
| 207 | + esc_html__('Display Ticket Selector Flag', 'event_espresso'), |
|
| 208 | + false, |
|
| 209 | + true |
|
| 210 | + ), |
|
| 211 | + 'EVT_visible_on' => new EE_Datetime_Field( |
|
| 212 | + 'EVT_visible_on', |
|
| 213 | + esc_html__('Event Visible Date', 'event_espresso'), |
|
| 214 | + true, |
|
| 215 | + EE_Datetime_Field::now |
|
| 216 | + ), |
|
| 217 | + 'EVT_additional_limit' => new EE_Integer_Field( |
|
| 218 | + 'EVT_additional_limit', |
|
| 219 | + esc_html__('Limit of Additional Registrations on Same Transaction', 'event_espresso'), |
|
| 220 | + true, |
|
| 221 | + self::$_default_additional_limit |
|
| 222 | + ), |
|
| 223 | + 'EVT_default_registration_status' => new EE_Enum_Text_Field( |
|
| 224 | + 'EVT_default_registration_status', |
|
| 225 | + esc_html__('Default Registration Status on this Event', 'event_espresso'), |
|
| 226 | + false, |
|
| 227 | + EEM_Event::$_default_reg_status, |
|
| 228 | + EEM_Registration::reg_status_array() |
|
| 229 | + ), |
|
| 230 | + 'EVT_member_only' => new EE_Boolean_Field( |
|
| 231 | + 'EVT_member_only', |
|
| 232 | + esc_html__('Member-Only Event Flag', 'event_espresso'), |
|
| 233 | + false, |
|
| 234 | + false |
|
| 235 | + ), |
|
| 236 | + 'EVT_phone' => new EE_Plain_Text_Field( |
|
| 237 | + 'EVT_phone', |
|
| 238 | + esc_html__('Event Phone Number', 'event_espresso'), |
|
| 239 | + false, |
|
| 240 | + '' |
|
| 241 | + ), |
|
| 242 | + 'EVT_allow_overflow' => new EE_Boolean_Field( |
|
| 243 | + 'EVT_allow_overflow', |
|
| 244 | + esc_html__('Allow Overflow on Event', 'event_espresso'), |
|
| 245 | + false, |
|
| 246 | + false |
|
| 247 | + ), |
|
| 248 | + 'EVT_timezone_string' => new EE_Plain_Text_Field( |
|
| 249 | + 'EVT_timezone_string', |
|
| 250 | + esc_html__('Timezone (name) for Event times', 'event_espresso'), |
|
| 251 | + false, |
|
| 252 | + '' |
|
| 253 | + ), |
|
| 254 | + 'EVT_external_URL' => new EE_Plain_Text_Field( |
|
| 255 | + 'EVT_external_URL', |
|
| 256 | + esc_html__('URL of Event Page if hosted elsewhere', 'event_espresso'), |
|
| 257 | + true |
|
| 258 | + ), |
|
| 259 | + 'EVT_donations' => new EE_Boolean_Field( |
|
| 260 | + 'EVT_donations', |
|
| 261 | + esc_html__('Accept Donations?', 'event_espresso'), |
|
| 262 | + false, |
|
| 263 | + false |
|
| 264 | + ), |
|
| 265 | + ), |
|
| 266 | + ); |
|
| 267 | + $this->_model_relations = array( |
|
| 268 | + 'Registration' => new EE_Has_Many_Relation(), |
|
| 269 | + 'Datetime' => new EE_Has_Many_Relation(), |
|
| 270 | + 'Question_Group' => new EE_HABTM_Relation('Event_Question_Group'), |
|
| 271 | + 'Event_Question_Group' => new EE_Has_Many_Relation(), |
|
| 272 | + 'Venue' => new EE_HABTM_Relation('Event_Venue'), |
|
| 273 | + 'Term_Relationship' => new EE_Has_Many_Relation(), |
|
| 274 | + 'Term_Taxonomy' => new EE_HABTM_Relation('Term_Relationship'), |
|
| 275 | + 'Message_Template_Group' => new EE_HABTM_Relation('Event_Message_Template'), |
|
| 276 | + 'Attendee' => new EE_HABTM_Relation('Registration'), |
|
| 277 | + 'WP_User' => new EE_Belongs_To_Relation(), |
|
| 278 | + ); |
|
| 279 | + // this model is generally available for reading |
|
| 280 | + $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Public(); |
|
| 281 | + $this->model_chain_to_password = ''; |
|
| 282 | + parent::__construct($timezone); |
|
| 283 | + } |
|
| 284 | + |
|
| 285 | + |
|
| 286 | + |
|
| 287 | + /** |
|
| 288 | + * @param string $default_reg_status |
|
| 289 | + */ |
|
| 290 | + public static function set_default_reg_status($default_reg_status) |
|
| 291 | + { |
|
| 292 | + self::$_default_reg_status = $default_reg_status; |
|
| 293 | + // if EEM_Event has already been instantiated, |
|
| 294 | + // then we need to reset the `EVT_default_reg_status` field to use the new default. |
|
| 295 | + if (self::$_instance instanceof EEM_Event) { |
|
| 296 | + $default_reg_status = new EE_Enum_Text_Field( |
|
| 297 | + 'EVT_default_registration_status', |
|
| 298 | + esc_html__('Default Registration Status on this Event', 'event_espresso'), |
|
| 299 | + false, |
|
| 300 | + $default_reg_status, |
|
| 301 | + EEM_Registration::reg_status_array() |
|
| 302 | + ); |
|
| 303 | + $default_reg_status->_construct_finalize( |
|
| 304 | + 'Event_Meta', |
|
| 305 | + 'EVT_default_registration_status', |
|
| 306 | + 'EEM_Event' |
|
| 307 | + ); |
|
| 308 | + self::$_instance->_fields['Event_Meta']['EVT_default_registration_status'] = $default_reg_status; |
|
| 309 | + } |
|
| 310 | + } |
|
| 311 | + |
|
| 312 | + |
|
| 313 | + /** |
|
| 314 | + * Used to override the default for the additional limit field. |
|
| 315 | + * @param $additional_limit |
|
| 316 | + */ |
|
| 317 | + public static function set_default_additional_limit($additional_limit) |
|
| 318 | + { |
|
| 319 | + self::$_default_additional_limit = (int) $additional_limit; |
|
| 320 | + if (self::$_instance instanceof EEM_Event) { |
|
| 321 | + self::$_instance->_fields['Event_Meta']['EVT_additional_limit'] = new EE_Integer_Field( |
|
| 322 | + 'EVT_additional_limit', |
|
| 323 | + esc_html__('Limit of Additional Registrations on Same Transaction', 'event_espresso'), |
|
| 324 | + true, |
|
| 325 | + self::$_default_additional_limit |
|
| 326 | + ); |
|
| 327 | + self::$_instance->_fields['Event_Meta']['EVT_additional_limit']->_construct_finalize( |
|
| 328 | + 'Event_Meta', |
|
| 329 | + 'EVT_additional_limit', |
|
| 330 | + 'EEM_Event' |
|
| 331 | + ); |
|
| 332 | + } |
|
| 333 | + } |
|
| 334 | + |
|
| 335 | + |
|
| 336 | + /** |
|
| 337 | + * Return what is currently set as the default additional limit for the event. |
|
| 338 | + * @return int |
|
| 339 | + */ |
|
| 340 | + public static function get_default_additional_limit() |
|
| 341 | + { |
|
| 342 | + return apply_filters('FHEE__EEM_Event__get_default_additional_limit', self::$_default_additional_limit); |
|
| 343 | + } |
|
| 344 | + |
|
| 345 | + |
|
| 346 | + /** |
|
| 347 | + * get_question_groups |
|
| 348 | + * |
|
| 349 | + * @return array |
|
| 350 | + * @throws \EE_Error |
|
| 351 | + */ |
|
| 352 | + public function get_all_question_groups() |
|
| 353 | + { |
|
| 354 | + return EE_Registry::instance()->load_model('Question_Group')->get_all( |
|
| 355 | + array( |
|
| 356 | + array('QSG_deleted' => false), |
|
| 357 | + 'order_by' => array('QSG_order' => 'ASC'), |
|
| 358 | + ) |
|
| 359 | + ); |
|
| 360 | + } |
|
| 361 | + |
|
| 362 | + |
|
| 363 | + |
|
| 364 | + /** |
|
| 365 | + * get_question_groups |
|
| 366 | + * |
|
| 367 | + * @param int $EVT_ID |
|
| 368 | + * @return array|bool |
|
| 369 | + * @throws \EE_Error |
|
| 370 | + */ |
|
| 371 | + public function get_all_event_question_groups($EVT_ID = 0) |
|
| 372 | + { |
|
| 373 | + if (! isset($EVT_ID) || ! absint($EVT_ID)) { |
|
| 374 | + EE_Error::add_error( |
|
| 375 | + esc_html__( |
|
| 376 | + 'An error occurred. No Event Question Groups could be retrieved because an Event ID was not received.', |
|
| 377 | + 'event_espresso' |
|
| 378 | + ), |
|
| 379 | + __FILE__, |
|
| 380 | + __FUNCTION__, |
|
| 381 | + __LINE__ |
|
| 382 | + ); |
|
| 383 | + return false; |
|
| 384 | + } |
|
| 385 | + return EE_Registry::instance()->load_model('Event_Question_Group')->get_all( |
|
| 386 | + array( |
|
| 387 | + array('EVT_ID' => $EVT_ID), |
|
| 388 | + ) |
|
| 389 | + ); |
|
| 390 | + } |
|
| 391 | + |
|
| 392 | + |
|
| 393 | + /** |
|
| 394 | + * get_question_groups |
|
| 395 | + * |
|
| 396 | + * @param int $EVT_ID |
|
| 397 | + * @param boolean $for_primary_attendee |
|
| 398 | + * @return array|bool |
|
| 399 | + * @throws EE_Error |
|
| 400 | + * @throws InvalidArgumentException |
|
| 401 | + * @throws ReflectionException |
|
| 402 | + * @throws InvalidDataTypeException |
|
| 403 | + * @throws InvalidInterfaceException |
|
| 404 | + */ |
|
| 405 | + public function get_event_question_groups($EVT_ID = 0, $for_primary_attendee = true) |
|
| 406 | + { |
|
| 407 | + if (! isset($EVT_ID) || ! absint($EVT_ID)) { |
|
| 408 | + EE_Error::add_error( |
|
| 409 | + esc_html__( |
|
| 410 | + // @codingStandardsIgnoreStart |
|
| 411 | + 'An error occurred. No Event Question Groups could be retrieved because an Event ID was not received.', |
|
| 412 | + // @codingStandardsIgnoreEnd |
|
| 413 | + 'event_espresso' |
|
| 414 | + ), |
|
| 415 | + __FILE__, |
|
| 416 | + __FUNCTION__, |
|
| 417 | + __LINE__ |
|
| 418 | + ); |
|
| 419 | + return false; |
|
| 420 | + } |
|
| 421 | + $query_params = [ |
|
| 422 | + [ |
|
| 423 | + 'EVT_ID' => $EVT_ID, |
|
| 424 | + EEM_Event_Question_Group::instance()->fieldNameForContext($for_primary_attendee) => true |
|
| 425 | + ] |
|
| 426 | + ]; |
|
| 427 | + if ($for_primary_attendee) { |
|
| 428 | + $query_params[0]['EQG_primary'] = true; |
|
| 429 | + } else { |
|
| 430 | + $query_params[0]['EQG_additional'] = true; |
|
| 431 | + } |
|
| 432 | + return EE_Registry::instance()->load_model('Event_Question_Group')->get_all($query_params); |
|
| 433 | + } |
|
| 434 | + |
|
| 435 | + |
|
| 436 | + /** |
|
| 437 | + * get_question_groups |
|
| 438 | + * |
|
| 439 | + * @param int $EVT_ID |
|
| 440 | + * @param EE_Registration $registration |
|
| 441 | + * @return array|bool |
|
| 442 | + * @throws EE_Error |
|
| 443 | + * @throws InvalidArgumentException |
|
| 444 | + * @throws InvalidDataTypeException |
|
| 445 | + * @throws InvalidInterfaceException |
|
| 446 | + * @throws ReflectionException |
|
| 447 | + */ |
|
| 448 | + public function get_question_groups_for_event($EVT_ID, EE_Registration $registration) |
|
| 449 | + { |
|
| 450 | + if (! isset($EVT_ID) || ! absint($EVT_ID)) { |
|
| 451 | + EE_Error::add_error( |
|
| 452 | + esc_html__( |
|
| 453 | + 'An error occurred. No Question Groups could be retrieved because an Event ID was not received.', |
|
| 454 | + 'event_espresso' |
|
| 455 | + ), |
|
| 456 | + __FILE__, |
|
| 457 | + __FUNCTION__, |
|
| 458 | + __LINE__ |
|
| 459 | + ); |
|
| 460 | + return false; |
|
| 461 | + } |
|
| 462 | + return EE_Registry::instance()->load_model('Question_Group')->get_all( |
|
| 463 | + [ |
|
| 464 | + [ |
|
| 465 | + 'Event_Question_Group.EVT_ID' => $EVT_ID, |
|
| 466 | + 'Event_Question_Group.' |
|
| 467 | + . EEM_Event_Question_Group::instance()->fieldNameForContext( |
|
| 468 | + $registration->is_primary_registrant() |
|
| 469 | + ) => true |
|
| 470 | + ], |
|
| 471 | + 'order_by' => ['QSG_order' => 'ASC'], |
|
| 472 | + ] |
|
| 473 | + ); |
|
| 474 | + } |
|
| 475 | + |
|
| 476 | + |
|
| 477 | + |
|
| 478 | + /** |
|
| 479 | + * get_question_target_db_column |
|
| 480 | + * |
|
| 481 | + * @param string $QSG_IDs csv list of $QSG IDs |
|
| 482 | + * @return array|bool |
|
| 483 | + * @throws \EE_Error |
|
| 484 | + */ |
|
| 485 | + public function get_questions_in_groups($QSG_IDs = '') |
|
| 486 | + { |
|
| 487 | + if (empty($QSG_IDs)) { |
|
| 488 | + EE_Error::add_error( |
|
| 489 | + esc_html__('An error occurred. No Question Group IDs were received.', 'event_espresso'), |
|
| 490 | + __FILE__, |
|
| 491 | + __FUNCTION__, |
|
| 492 | + __LINE__ |
|
| 493 | + ); |
|
| 494 | + return false; |
|
| 495 | + } |
|
| 496 | + return EE_Registry::instance()->load_model('Question')->get_all( |
|
| 497 | + array( |
|
| 498 | + array( |
|
| 499 | + 'Question_Group.QSG_ID' => array('IN', $QSG_IDs), |
|
| 500 | + 'QST_deleted' => false, |
|
| 501 | + 'QST_admin_only' => is_admin(), |
|
| 502 | + ), |
|
| 503 | + 'order_by' => 'QST_order', |
|
| 504 | + ) |
|
| 505 | + ); |
|
| 506 | + } |
|
| 507 | + |
|
| 508 | + |
|
| 509 | + |
|
| 510 | + /** |
|
| 511 | + * get_options_for_question |
|
| 512 | + * |
|
| 513 | + * @param string $QST_IDs csv list of $QST IDs |
|
| 514 | + * @return array|bool |
|
| 515 | + * @throws \EE_Error |
|
| 516 | + */ |
|
| 517 | + public function get_options_for_question($QST_IDs) |
|
| 518 | + { |
|
| 519 | + if (empty($QST_IDs)) { |
|
| 520 | + EE_Error::add_error( |
|
| 521 | + esc_html__('An error occurred. No Question IDs were received.', 'event_espresso'), |
|
| 522 | + __FILE__, |
|
| 523 | + __FUNCTION__, |
|
| 524 | + __LINE__ |
|
| 525 | + ); |
|
| 526 | + return false; |
|
| 527 | + } |
|
| 528 | + return EE_Registry::instance()->load_model('Question_Option')->get_all( |
|
| 529 | + array( |
|
| 530 | + array( |
|
| 531 | + 'Question.QST_ID' => array('IN', $QST_IDs), |
|
| 532 | + 'QSO_deleted' => false, |
|
| 533 | + ), |
|
| 534 | + 'order_by' => 'QSO_ID', |
|
| 535 | + ) |
|
| 536 | + ); |
|
| 537 | + } |
|
| 538 | + |
|
| 539 | + |
|
| 540 | + |
|
| 541 | + |
|
| 542 | + |
|
| 543 | + |
|
| 544 | + |
|
| 545 | + /** |
|
| 546 | + * Gets all events that are published |
|
| 547 | + * and have event start time earlier than now and an event end time later than now |
|
| 548 | + * |
|
| 549 | + * @param array $query_params An array of query params to further filter on |
|
| 550 | + * (note that status and DTT_EVT_start and DTT_EVT_end will be overridden) |
|
| 551 | + * @param bool $count whether to return the count or not (default FALSE) |
|
| 552 | + * @return EE_Event[]|int |
|
| 553 | + * @throws \EE_Error |
|
| 554 | + */ |
|
| 555 | + public function get_active_events($query_params, $count = false) |
|
| 556 | + { |
|
| 557 | + if (array_key_exists(0, $query_params)) { |
|
| 558 | + $where_params = $query_params[0]; |
|
| 559 | + unset($query_params[0]); |
|
| 560 | + } else { |
|
| 561 | + $where_params = array(); |
|
| 562 | + } |
|
| 563 | + // if we have count make sure we don't include group by |
|
| 564 | + if ($count && isset($query_params['group_by'])) { |
|
| 565 | + unset($query_params['group_by']); |
|
| 566 | + } |
|
| 567 | + // let's add specific query_params for active_events |
|
| 568 | + // keep in mind this will override any sent status in the query AND any date queries. |
|
| 569 | + $where_params['status'] = array('IN', array('publish', EEM_Event::sold_out)); |
|
| 570 | + // if already have where params for DTT_EVT_start or DTT_EVT_end then append these conditions |
|
| 571 | + if (isset($where_params['Datetime.DTT_EVT_start'])) { |
|
| 572 | + $where_params['Datetime.DTT_EVT_start******'] = array( |
|
| 573 | + '<', |
|
| 574 | + EEM_Datetime::instance()->current_time_for_query('DTT_EVT_start'), |
|
| 575 | + ); |
|
| 576 | + } else { |
|
| 577 | + $where_params['Datetime.DTT_EVT_start'] = array( |
|
| 578 | + '<', |
|
| 579 | + EEM_Datetime::instance()->current_time_for_query('DTT_EVT_start'), |
|
| 580 | + ); |
|
| 581 | + } |
|
| 582 | + if (isset($where_params['Datetime.DTT_EVT_end'])) { |
|
| 583 | + $where_params['Datetime.DTT_EVT_end*****'] = array( |
|
| 584 | + '>', |
|
| 585 | + EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'), |
|
| 586 | + ); |
|
| 587 | + } else { |
|
| 588 | + $where_params['Datetime.DTT_EVT_end'] = array( |
|
| 589 | + '>', |
|
| 590 | + EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'), |
|
| 591 | + ); |
|
| 592 | + } |
|
| 593 | + $query_params[0] = $where_params; |
|
| 594 | + // don't use $query_params with count() |
|
| 595 | + // because we don't want to include additional query clauses like "GROUP BY" |
|
| 596 | + return $count |
|
| 597 | + ? $this->count(array($where_params), 'EVT_ID', true) |
|
| 598 | + : $this->get_all($query_params); |
|
| 599 | + } |
|
| 600 | + |
|
| 601 | + |
|
| 602 | + |
|
| 603 | + /** |
|
| 604 | + * get all events that are published and have an event start time later than now |
|
| 605 | + * |
|
| 606 | + * @param array $query_params An array of query params to further filter on |
|
| 607 | + * (Note that status and DTT_EVT_start will be overridden) |
|
| 608 | + * @param bool $count whether to return the count or not (default FALSE) |
|
| 609 | + * @return EE_Event[]|int |
|
| 610 | + * @throws \EE_Error |
|
| 611 | + */ |
|
| 612 | + public function get_upcoming_events($query_params, $count = false) |
|
| 613 | + { |
|
| 614 | + if (array_key_exists(0, $query_params)) { |
|
| 615 | + $where_params = $query_params[0]; |
|
| 616 | + unset($query_params[0]); |
|
| 617 | + } else { |
|
| 618 | + $where_params = array(); |
|
| 619 | + } |
|
| 620 | + // if we have count make sure we don't include group by |
|
| 621 | + if ($count && isset($query_params['group_by'])) { |
|
| 622 | + unset($query_params['group_by']); |
|
| 623 | + } |
|
| 624 | + // let's add specific query_params for active_events |
|
| 625 | + // keep in mind this will override any sent status in the query AND any date queries. |
|
| 626 | + // we need to pull events with a status of publish and sold_out |
|
| 627 | + $event_status = array('publish', EEM_Event::sold_out); |
|
| 628 | + // check if the user can read private events and if so add the 'private status to the were params' |
|
| 629 | + if (EE_Registry::instance()->CAP->current_user_can('ee_read_private_events', 'get_upcoming_events')) { |
|
| 630 | + $event_status[] = 'private'; |
|
| 631 | + } |
|
| 632 | + $where_params['status'] = array('IN', $event_status); |
|
| 633 | + // if there are already query_params matching DTT_EVT_start then we need to modify that to add them. |
|
| 634 | + if (isset($where_params['Datetime.DTT_EVT_start'])) { |
|
| 635 | + $where_params['Datetime.DTT_EVT_start*****'] = array( |
|
| 636 | + '>', |
|
| 637 | + EEM_Datetime::instance()->current_time_for_query('DTT_EVT_start'), |
|
| 638 | + ); |
|
| 639 | + } else { |
|
| 640 | + $where_params['Datetime.DTT_EVT_start'] = array( |
|
| 641 | + '>', |
|
| 642 | + EEM_Datetime::instance()->current_time_for_query('DTT_EVT_start'), |
|
| 643 | + ); |
|
| 644 | + } |
|
| 645 | + $query_params[0] = $where_params; |
|
| 646 | + // don't use $query_params with count() |
|
| 647 | + // because we don't want to include additional query clauses like "GROUP BY" |
|
| 648 | + return $count |
|
| 649 | + ? $this->count(array($where_params), 'EVT_ID', true) |
|
| 650 | + : $this->get_all($query_params); |
|
| 651 | + } |
|
| 652 | + |
|
| 653 | + |
|
| 654 | + |
|
| 655 | + /** |
|
| 656 | + * Gets all events that are published |
|
| 657 | + * and have an event end time later than now |
|
| 658 | + * |
|
| 659 | + * @param array $query_params An array of query params to further filter on |
|
| 660 | + * (note that status and DTT_EVT_end will be overridden) |
|
| 661 | + * @param bool $count whether to return the count or not (default FALSE) |
|
| 662 | + * @return EE_Event[]|int |
|
| 663 | + * @throws \EE_Error |
|
| 664 | + */ |
|
| 665 | + public function get_active_and_upcoming_events($query_params, $count = false) |
|
| 666 | + { |
|
| 667 | + if (array_key_exists(0, $query_params)) { |
|
| 668 | + $where_params = $query_params[0]; |
|
| 669 | + unset($query_params[0]); |
|
| 670 | + } else { |
|
| 671 | + $where_params = array(); |
|
| 672 | + } |
|
| 673 | + // if we have count make sure we don't include group by |
|
| 674 | + if ($count && isset($query_params['group_by'])) { |
|
| 675 | + unset($query_params['group_by']); |
|
| 676 | + } |
|
| 677 | + // let's add specific query_params for active_events |
|
| 678 | + // keep in mind this will override any sent status in the query AND any date queries. |
|
| 679 | + $where_params['status'] = array('IN', array('publish', EEM_Event::sold_out)); |
|
| 680 | + // add where params for DTT_EVT_end |
|
| 681 | + if (isset($where_params['Datetime.DTT_EVT_end'])) { |
|
| 682 | + $where_params['Datetime.DTT_EVT_end*****'] = array( |
|
| 683 | + '>', |
|
| 684 | + EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'), |
|
| 685 | + ); |
|
| 686 | + } else { |
|
| 687 | + $where_params['Datetime.DTT_EVT_end'] = array( |
|
| 688 | + '>', |
|
| 689 | + EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'), |
|
| 690 | + ); |
|
| 691 | + } |
|
| 692 | + $query_params[0] = $where_params; |
|
| 693 | + // don't use $query_params with count() |
|
| 694 | + // because we don't want to include additional query clauses like "GROUP BY" |
|
| 695 | + return $count |
|
| 696 | + ? $this->count(array($where_params), 'EVT_ID', true) |
|
| 697 | + : $this->get_all($query_params); |
|
| 698 | + } |
|
| 699 | + |
|
| 700 | + |
|
| 701 | + |
|
| 702 | + /** |
|
| 703 | + * This only returns events that are expired. |
|
| 704 | + * They may still be published but all their datetimes have expired. |
|
| 705 | + * |
|
| 706 | + * @param array $query_params An array of query params to further filter on |
|
| 707 | + * (note that status and DTT_EVT_end will be overridden) |
|
| 708 | + * @param bool $count whether to return the count or not (default FALSE) |
|
| 709 | + * @return EE_Event[]|int |
|
| 710 | + * @throws \EE_Error |
|
| 711 | + */ |
|
| 712 | + public function get_expired_events($query_params, $count = false) |
|
| 713 | + { |
|
| 714 | + $where_params = isset($query_params[0]) ? $query_params[0] : array(); |
|
| 715 | + // if we have count make sure we don't include group by |
|
| 716 | + if ($count && isset($query_params['group_by'])) { |
|
| 717 | + unset($query_params['group_by']); |
|
| 718 | + } |
|
| 719 | + // let's add specific query_params for active_events |
|
| 720 | + // keep in mind this will override any sent status in the query AND any date queries. |
|
| 721 | + if (isset($where_params['status'])) { |
|
| 722 | + unset($where_params['status']); |
|
| 723 | + } |
|
| 724 | + $exclude_query = $query_params; |
|
| 725 | + if (isset($exclude_query[0])) { |
|
| 726 | + unset($exclude_query[0]); |
|
| 727 | + } |
|
| 728 | + $exclude_query[0] = array( |
|
| 729 | + 'Datetime.DTT_EVT_end' => array( |
|
| 730 | + '>', |
|
| 731 | + EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'), |
|
| 732 | + ), |
|
| 733 | + ); |
|
| 734 | + // first get all events that have datetimes where its not expired. |
|
| 735 | + $event_ids = $this->_get_all_wpdb_results($exclude_query, OBJECT_K, 'Event_CPT.ID'); |
|
| 736 | + $event_ids = array_keys($event_ids); |
|
| 737 | + // if we have any additional query_params, let's add them to the 'AND' condition |
|
| 738 | + $and_condition = array( |
|
| 739 | + 'Datetime.DTT_EVT_end' => array('<', EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end')), |
|
| 740 | + 'EVT_ID' => array('NOT IN', $event_ids), |
|
| 741 | + ); |
|
| 742 | + if (isset($where_params['OR'])) { |
|
| 743 | + $and_condition['OR'] = $where_params['OR']; |
|
| 744 | + unset($where_params['OR']); |
|
| 745 | + } |
|
| 746 | + if (isset($where_params['Datetime.DTT_EVT_end'])) { |
|
| 747 | + $and_condition['Datetime.DTT_EVT_end****'] = $where_params['Datetime.DTT_EVT_end']; |
|
| 748 | + unset($where_params['Datetime.DTT_EVT_end']); |
|
| 749 | + } |
|
| 750 | + if (isset($where_params['Datetime.DTT_EVT_start'])) { |
|
| 751 | + $and_condition['Datetime.DTT_EVT_start'] = $where_params['Datetime.DTT_EVT_start']; |
|
| 752 | + unset($where_params['Datetime.DTT_EVT_start']); |
|
| 753 | + } |
|
| 754 | + // merge remaining $where params with the and conditions. |
|
| 755 | + $where_params['AND'] = array_merge($and_condition, $where_params); |
|
| 756 | + $query_params[0] = $where_params; |
|
| 757 | + // don't use $query_params with count() |
|
| 758 | + // because we don't want to include additional query clauses like "GROUP BY" |
|
| 759 | + return $count |
|
| 760 | + ? $this->count(array($where_params), 'EVT_ID', true) |
|
| 761 | + : $this->get_all($query_params); |
|
| 762 | + } |
|
| 763 | + |
|
| 764 | + |
|
| 765 | + |
|
| 766 | + /** |
|
| 767 | + * This basically just returns the events that do not have the publish status. |
|
| 768 | + * |
|
| 769 | + * @param array $query_params An array of query params to further filter on |
|
| 770 | + * (note that status will be overwritten) |
|
| 771 | + * @param boolean $count whether to return the count or not (default FALSE) |
|
| 772 | + * @return EE_Event[]|int |
|
| 773 | + * @throws \EE_Error |
|
| 774 | + */ |
|
| 775 | + public function get_inactive_events($query_params, $count = false) |
|
| 776 | + { |
|
| 777 | + $where_params = isset($query_params[0]) ? $query_params[0] : array(); |
|
| 778 | + // let's add in specific query_params for inactive events. |
|
| 779 | + if (isset($where_params['status'])) { |
|
| 780 | + unset($where_params['status']); |
|
| 781 | + } |
|
| 782 | + // if we have count make sure we don't include group by |
|
| 783 | + if ($count && isset($query_params['group_by'])) { |
|
| 784 | + unset($query_params['group_by']); |
|
| 785 | + } |
|
| 786 | + // if we have any additional query_params, let's add them to the 'AND' condition |
|
| 787 | + $where_params['AND']['status'] = array('!=', 'publish'); |
|
| 788 | + if (isset($where_params['OR'])) { |
|
| 789 | + $where_params['AND']['OR'] = $where_params['OR']; |
|
| 790 | + unset($where_params['OR']); |
|
| 791 | + } |
|
| 792 | + if (isset($where_params['Datetime.DTT_EVT_end'])) { |
|
| 793 | + $where_params['AND']['Datetime.DTT_EVT_end****'] = $where_params['Datetime.DTT_EVT_end']; |
|
| 794 | + unset($where_params['Datetime.DTT_EVT_end']); |
|
| 795 | + } |
|
| 796 | + if (isset($where_params['Datetime.DTT_EVT_start'])) { |
|
| 797 | + $where_params['AND']['Datetime.DTT_EVT_start'] = $where_params['Datetime.DTT_EVT_start']; |
|
| 798 | + unset($where_params['Datetime.DTT_EVT_start']); |
|
| 799 | + } |
|
| 800 | + $query_params[0] = $where_params; |
|
| 801 | + // don't use $query_params with count() |
|
| 802 | + // because we don't want to include additional query clauses like "GROUP BY" |
|
| 803 | + return $count |
|
| 804 | + ? $this->count(array($where_params), 'EVT_ID', true) |
|
| 805 | + : $this->get_all($query_params); |
|
| 806 | + } |
|
| 807 | + |
|
| 808 | + |
|
| 809 | + |
|
| 810 | + /** |
|
| 811 | + * This is just injecting into the parent add_relationship_to so we do special handling on price relationships |
|
| 812 | + * because we don't want to override any existing global default prices but instead insert NEW prices that get |
|
| 813 | + * attached to the event. See parent for param descriptions |
|
| 814 | + * |
|
| 815 | + * @param $id_or_obj |
|
| 816 | + * @param $other_model_id_or_obj |
|
| 817 | + * @param string $relationName |
|
| 818 | + * @param array $where_query |
|
| 819 | + * @return EE_Base_Class |
|
| 820 | + * @throws EE_Error |
|
| 821 | + */ |
|
| 822 | + public function add_relationship_to($id_or_obj, $other_model_id_or_obj, $relationName, $where_query = array()) |
|
| 823 | + { |
|
| 824 | + if ($relationName === 'Price') { |
|
| 825 | + // let's get the PRC object for the given ID to make sure that we aren't dealing with a default |
|
| 826 | + $prc_chk = $this->get_related_model_obj($relationName)->ensure_is_obj($other_model_id_or_obj); |
|
| 827 | + // if EVT_ID = 0, then this is a default |
|
| 828 | + if ((int) $prc_chk->get('EVT_ID') === 0) { |
|
| 829 | + // let's set the prc_id as 0 so we force an insert on the add_relation_to carried out by relation |
|
| 830 | + $prc_chk->set('PRC_ID', 0); |
|
| 831 | + } |
|
| 832 | + // run parent |
|
| 833 | + return parent::add_relationship_to($id_or_obj, $prc_chk, $relationName, $where_query); |
|
| 834 | + } |
|
| 835 | + // otherwise carry on as normal |
|
| 836 | + return parent::add_relationship_to($id_or_obj, $other_model_id_or_obj, $relationName, $where_query); |
|
| 837 | + } |
|
| 838 | + |
|
| 839 | + |
|
| 840 | + |
|
| 841 | + /******************** DEPRECATED METHODS ********************/ |
|
| 842 | + |
|
| 843 | + |
|
| 844 | + |
|
| 845 | + /** |
|
| 846 | + * _get_question_target_db_column |
|
| 847 | + * |
|
| 848 | + * @deprecated as of 4.8.32.rc.001. Instead consider using |
|
| 849 | + * EE_Registration_Custom_Questions_Form located in |
|
| 850 | + * admin_pages/registrations/form_sections/EE_Registration_Custom_Questions_Form.form.php |
|
| 851 | + * @access public |
|
| 852 | + * @param EE_Registration $registration (so existing answers for registration are included) |
|
| 853 | + * @param int $EVT_ID so all question groups are included for event (not just answers from |
|
| 854 | + * registration). |
|
| 855 | + * @throws EE_Error |
|
| 856 | + * @return array |
|
| 857 | + */ |
|
| 858 | + public function assemble_array_of_groups_questions_and_options(EE_Registration $registration, $EVT_ID = 0) |
|
| 859 | + { |
|
| 860 | + if (empty($EVT_ID)) { |
|
| 861 | + throw new EE_Error(esc_html__( |
|
| 862 | + 'An error occurred. No EVT_ID is included. Needed to know which question groups to retrieve.', |
|
| 863 | + 'event_espresso' |
|
| 864 | + )); |
|
| 865 | + } |
|
| 866 | + $questions = array(); |
|
| 867 | + // get all question groups for event |
|
| 868 | + $qgs = $this->get_question_groups_for_event($EVT_ID, $registration); |
|
| 869 | + if (! empty($qgs)) { |
|
| 870 | + foreach ($qgs as $qg) { |
|
| 871 | + $qsts = $qg->questions(); |
|
| 872 | + $questions[ $qg->ID() ] = $qg->model_field_array(); |
|
| 873 | + $questions[ $qg->ID() ]['QSG_questions'] = array(); |
|
| 874 | + foreach ($qsts as $qst) { |
|
| 875 | + if ($qst->is_system_question()) { |
|
| 876 | + continue; |
|
| 877 | + } |
|
| 878 | + $answer = EEM_Answer::instance()->get_one(array( |
|
| 879 | + array( |
|
| 880 | + 'QST_ID' => $qst->ID(), |
|
| 881 | + 'REG_ID' => $registration->ID(), |
|
| 882 | + ), |
|
| 883 | + )); |
|
| 884 | + $answer = $answer instanceof EE_Answer ? $answer : EEM_Answer::instance()->create_default_object(); |
|
| 885 | + $qst_name = $qstn_id = $qst->ID(); |
|
| 886 | + $ans_id = $answer->ID(); |
|
| 887 | + $qst_name = ! empty($ans_id) ? '[' . $qst_name . '][' . $ans_id . ']' : '[' . $qst_name . ']'; |
|
| 888 | + $input_name = ''; |
|
| 889 | + $input_id = sanitize_key($qst->display_text()); |
|
| 890 | + $input_class = ''; |
|
| 891 | + $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ] = $qst->model_field_array(); |
|
| 892 | + $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['QST_input_name'] = 'qstn' |
|
| 893 | + . $input_name |
|
| 894 | + . $qst_name; |
|
| 895 | + $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['QST_input_id'] = $input_id . '-' . $qstn_id; |
|
| 896 | + $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['QST_input_class'] = $input_class; |
|
| 897 | + $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['QST_options'] = array(); |
|
| 898 | + $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['qst_obj'] = $qst; |
|
| 899 | + $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['ans_obj'] = $answer; |
|
| 900 | + // leave responses as-is, don't convert stuff into html entities please! |
|
| 901 | + $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['htmlentities'] = false; |
|
| 902 | + if ($qst->type() == 'RADIO_BTN' || $qst->type() == 'CHECKBOX' || $qst->type() == 'DROPDOWN') { |
|
| 903 | + $QSOs = $qst->options(true, $answer->value()); |
|
| 904 | + if (is_array($QSOs)) { |
|
| 905 | + foreach ($QSOs as $QSO_ID => $QSO) { |
|
| 906 | + $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['QST_options'][ $QSO_ID ] = $QSO->model_field_array(); |
|
| 907 | + } |
|
| 908 | + } |
|
| 909 | + } |
|
| 910 | + } |
|
| 911 | + } |
|
| 912 | + } |
|
| 913 | + return $questions; |
|
| 914 | + } |
|
| 915 | + |
|
| 916 | + |
|
| 917 | + /** |
|
| 918 | + * @param mixed $cols_n_values either an array of where each key is the name of a field, and the value is its value |
|
| 919 | + * or an stdClass where each property is the name of a column, |
|
| 920 | + * @return EE_Base_Class |
|
| 921 | + * @throws \EE_Error |
|
| 922 | + */ |
|
| 923 | + public function instantiate_class_from_array_or_object($cols_n_values) |
|
| 924 | + { |
|
| 925 | + $classInstance = parent::instantiate_class_from_array_or_object($cols_n_values); |
|
| 926 | + if ($classInstance instanceof EE_Event) { |
|
| 927 | + // events have their timezone defined in the DB, so use it immediately |
|
| 928 | + $this->set_timezone($classInstance->get_timezone()); |
|
| 929 | + } |
|
| 930 | + return $classInstance; |
|
| 931 | + } |
|
| 932 | + |
|
| 933 | + |
|
| 934 | + /** |
|
| 935 | + * Deletes the model objects that meet the query params. Note: this method is overridden |
|
| 936 | + * in EEM_Soft_Delete_Base so that soft-deleted model objects are instead only flagged |
|
| 937 | + * as archived, not actually deleted |
|
| 938 | + * |
|
| 939 | + * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
| 940 | + * @param boolean $allow_blocking if TRUE, matched objects will only be deleted if there is no related model info |
|
| 941 | + * that blocks it (ie, there' sno other data that depends on this data); if false, |
|
| 942 | + * deletes regardless of other objects which may depend on it. Its generally |
|
| 943 | + * advisable to always leave this as TRUE, otherwise you could easily corrupt your |
|
| 944 | + * DB |
|
| 945 | + * @return int number of rows deleted |
|
| 946 | + * @throws EE_Error |
|
| 947 | + */ |
|
| 948 | + public function delete_permanently($query_params, $allow_blocking = true) |
|
| 949 | + { |
|
| 950 | + $deleted = parent::delete_permanently($query_params, $allow_blocking); |
|
| 951 | + if ($deleted) { |
|
| 952 | + // get list of events with no prices |
|
| 953 | + $espresso_no_ticket_prices = get_option('ee_no_ticket_prices', []); |
|
| 954 | + $where = isset($query_params[0]) ? $query_params[0] : []; |
|
| 955 | + $where_event = isset($where['EVT_ID']) ? $where['EVT_ID'] : ['', '']; |
|
| 956 | + $where_event_ids = isset($where_event[1]) ? $where_event[1] : ''; |
|
| 957 | + $event_ids = is_string($where_event_ids) |
|
| 958 | + ? explode(',', $where_event_ids) |
|
| 959 | + : (array) $where_event_ids; |
|
| 960 | + array_walk($event_ids, 'trim'); |
|
| 961 | + $event_ids = array_filter($event_ids); |
|
| 962 | + // remove events from list of events with no prices |
|
| 963 | + $espresso_no_ticket_prices = array_diff($espresso_no_ticket_prices, $event_ids); |
|
| 964 | + update_option('ee_no_ticket_prices', $espresso_no_ticket_prices); |
|
| 965 | + } |
|
| 966 | + return $deleted; |
|
| 967 | + } |
|
| 968 | 968 | } |
@@ -30,86 +30,86 @@ |
||
| 30 | 30 | */ |
| 31 | 31 | class ConfirmDeletion |
| 32 | 32 | { |
| 33 | - /** |
|
| 34 | - * @var NodeGroupDao |
|
| 35 | - */ |
|
| 36 | - private $dao; |
|
| 33 | + /** |
|
| 34 | + * @var NodeGroupDao |
|
| 35 | + */ |
|
| 36 | + private $dao; |
|
| 37 | 37 | |
| 38 | - /** |
|
| 39 | - * ConfirmDeletion constructor. |
|
| 40 | - * @param NodeGroupDao $dao |
|
| 41 | - */ |
|
| 42 | - public function __construct( |
|
| 43 | - NodeGroupDao $dao |
|
| 44 | - ) { |
|
| 38 | + /** |
|
| 39 | + * ConfirmDeletion constructor. |
|
| 40 | + * @param NodeGroupDao $dao |
|
| 41 | + */ |
|
| 42 | + public function __construct( |
|
| 43 | + NodeGroupDao $dao |
|
| 44 | + ) { |
|
| 45 | 45 | |
| 46 | - $this->dao = $dao; |
|
| 47 | - } |
|
| 46 | + $this->dao = $dao; |
|
| 47 | + } |
|
| 48 | 48 | |
| 49 | - /** |
|
| 50 | - * Redirects to the batch job for deleting events if the form submission is valid, otherwise back to the deletion |
|
| 51 | - * preview page. |
|
| 52 | - * @since 4.10.12.p |
|
| 53 | - * @param $request_data |
|
| 54 | - * @param $admin_base_url |
|
| 55 | - * @throws EE_Error |
|
| 56 | - * @throws InvalidArgumentException |
|
| 57 | - * @throws InvalidDataTypeException |
|
| 58 | - * @throws InvalidInterfaceException |
|
| 59 | - * @throws ReflectionException |
|
| 60 | - * @throws UnexpectedEntityException |
|
| 61 | - */ |
|
| 62 | - public function handle($request_data, $admin_base_url) |
|
| 63 | - { |
|
| 64 | - $deletion_job_code = isset($request_data['deletion_job_code']) ? sanitize_key($request_data['deletion_job_code']) : ''; |
|
| 65 | - $models_and_ids_to_delete = $this->dao->getModelsAndIdsFromGroup($deletion_job_code); |
|
| 66 | - $form = new ConfirmEventDeletionForm($models_and_ids_to_delete['Event']); |
|
| 67 | - // Initialize the form from the request, and check if its valid. |
|
| 68 | - $form->receive_form_submission($request_data); |
|
| 69 | - if ($form->is_valid()) { |
|
| 70 | - // Redirect the user to the deletion batch job. |
|
| 71 | - EEH_URL::safeRedirectAndExit( |
|
| 72 | - EE_Admin_Page::add_query_args_and_nonce( |
|
| 73 | - array( |
|
| 74 | - 'page' => 'espresso_batch', |
|
| 75 | - 'batch' => EED_Batch::batch_job, |
|
| 76 | - 'deletion_job_code' => $deletion_job_code, |
|
| 77 | - 'job_handler' => urlencode('EventEspressoBatchRequest\JobHandlers\ExecuteBatchDeletion'), |
|
| 78 | - 'return_url' => urlencode( |
|
| 79 | - add_query_arg( |
|
| 80 | - [ |
|
| 81 | - 'status' => 'trash' |
|
| 82 | - ], |
|
| 83 | - EVENTS_ADMIN_URL |
|
| 84 | - ) |
|
| 85 | - ) |
|
| 86 | - ), |
|
| 87 | - admin_url() |
|
| 88 | - ) |
|
| 89 | - ); |
|
| 90 | - } |
|
| 91 | - // Dont' use $form->submission_error_message() because it adds the form input's label in front |
|
| 92 | - // of each validation error which ends up looking quite confusing. |
|
| 93 | - $validation_errors = $form->get_validation_errors_accumulated(); |
|
| 94 | - foreach ($validation_errors as $validation_error) { |
|
| 95 | - EE_Error::add_error( |
|
| 96 | - $validation_error->getMessage(), |
|
| 97 | - __FILE__, |
|
| 98 | - __FUNCTION__, |
|
| 99 | - __LINE__ |
|
| 100 | - ); |
|
| 101 | - } |
|
| 49 | + /** |
|
| 50 | + * Redirects to the batch job for deleting events if the form submission is valid, otherwise back to the deletion |
|
| 51 | + * preview page. |
|
| 52 | + * @since 4.10.12.p |
|
| 53 | + * @param $request_data |
|
| 54 | + * @param $admin_base_url |
|
| 55 | + * @throws EE_Error |
|
| 56 | + * @throws InvalidArgumentException |
|
| 57 | + * @throws InvalidDataTypeException |
|
| 58 | + * @throws InvalidInterfaceException |
|
| 59 | + * @throws ReflectionException |
|
| 60 | + * @throws UnexpectedEntityException |
|
| 61 | + */ |
|
| 62 | + public function handle($request_data, $admin_base_url) |
|
| 63 | + { |
|
| 64 | + $deletion_job_code = isset($request_data['deletion_job_code']) ? sanitize_key($request_data['deletion_job_code']) : ''; |
|
| 65 | + $models_and_ids_to_delete = $this->dao->getModelsAndIdsFromGroup($deletion_job_code); |
|
| 66 | + $form = new ConfirmEventDeletionForm($models_and_ids_to_delete['Event']); |
|
| 67 | + // Initialize the form from the request, and check if its valid. |
|
| 68 | + $form->receive_form_submission($request_data); |
|
| 69 | + if ($form->is_valid()) { |
|
| 70 | + // Redirect the user to the deletion batch job. |
|
| 71 | + EEH_URL::safeRedirectAndExit( |
|
| 72 | + EE_Admin_Page::add_query_args_and_nonce( |
|
| 73 | + array( |
|
| 74 | + 'page' => 'espresso_batch', |
|
| 75 | + 'batch' => EED_Batch::batch_job, |
|
| 76 | + 'deletion_job_code' => $deletion_job_code, |
|
| 77 | + 'job_handler' => urlencode('EventEspressoBatchRequest\JobHandlers\ExecuteBatchDeletion'), |
|
| 78 | + 'return_url' => urlencode( |
|
| 79 | + add_query_arg( |
|
| 80 | + [ |
|
| 81 | + 'status' => 'trash' |
|
| 82 | + ], |
|
| 83 | + EVENTS_ADMIN_URL |
|
| 84 | + ) |
|
| 85 | + ) |
|
| 86 | + ), |
|
| 87 | + admin_url() |
|
| 88 | + ) |
|
| 89 | + ); |
|
| 90 | + } |
|
| 91 | + // Dont' use $form->submission_error_message() because it adds the form input's label in front |
|
| 92 | + // of each validation error which ends up looking quite confusing. |
|
| 93 | + $validation_errors = $form->get_validation_errors_accumulated(); |
|
| 94 | + foreach ($validation_errors as $validation_error) { |
|
| 95 | + EE_Error::add_error( |
|
| 96 | + $validation_error->getMessage(), |
|
| 97 | + __FILE__, |
|
| 98 | + __FUNCTION__, |
|
| 99 | + __LINE__ |
|
| 100 | + ); |
|
| 101 | + } |
|
| 102 | 102 | |
| 103 | - EEH_URL::safeRedirectAndExit( |
|
| 104 | - EE_Admin_Page::add_query_args_and_nonce( |
|
| 105 | - [ |
|
| 106 | - 'action' => 'preview_deletion', |
|
| 107 | - 'deletion_job_code' => $deletion_job_code |
|
| 108 | - ], |
|
| 109 | - $admin_base_url |
|
| 110 | - ) |
|
| 111 | - ); |
|
| 112 | - } |
|
| 103 | + EEH_URL::safeRedirectAndExit( |
|
| 104 | + EE_Admin_Page::add_query_args_and_nonce( |
|
| 105 | + [ |
|
| 106 | + 'action' => 'preview_deletion', |
|
| 107 | + 'deletion_job_code' => $deletion_job_code |
|
| 108 | + ], |
|
| 109 | + $admin_base_url |
|
| 110 | + ) |
|
| 111 | + ); |
|
| 112 | + } |
|
| 113 | 113 | } |
| 114 | 114 | // End of file ConfirmDeletion.php |
| 115 | 115 | // Location: EventEspresso\core\domain\services\admin\events\data/ConfirmDeletion.php |
@@ -93,7 +93,7 @@ discard block |
||
| 93 | 93 | */ |
| 94 | 94 | public function get_table_name() |
| 95 | 95 | { |
| 96 | - return $this->get_table_prefix() . $this->_table_name; |
|
| 96 | + return $this->get_table_prefix().$this->_table_name; |
|
| 97 | 97 | } |
| 98 | 98 | |
| 99 | 99 | |
@@ -105,7 +105,7 @@ discard block |
||
| 105 | 105 | */ |
| 106 | 106 | public function get_table_alias() |
| 107 | 107 | { |
| 108 | - if (! $this->_table_alias) { |
|
| 108 | + if ( ! $this->_table_alias) { |
|
| 109 | 109 | throw new EE_Error("You must call _construct_finalize_with_alias before using the EE_Table_Base. Did you forget to call parent::__construct at the end of your EEMerimental_Base child's __construct?"); |
| 110 | 110 | } |
| 111 | 111 | return $this->_table_alias; |
@@ -128,7 +128,7 @@ discard block |
||
| 128 | 128 | */ |
| 129 | 129 | public function get_fully_qualified_pk_column() |
| 130 | 130 | { |
| 131 | - return $this->get_table_alias() . "." . $this->get_pk_column(); |
|
| 131 | + return $this->get_table_alias().".".$this->get_pk_column(); |
|
| 132 | 132 | } |
| 133 | 133 | |
| 134 | 134 | |
@@ -139,8 +139,8 @@ discard block |
||
| 139 | 139 | */ |
| 140 | 140 | public function get_select_join_limit($limit) |
| 141 | 141 | { |
| 142 | - $limit = is_array($limit) ? 'LIMIT ' . implode(',', array_map('intval', $limit)) : 'LIMIT ' . (int) $limit; |
|
| 143 | - return SP . '(SELECT * FROM ' . $this->_table_name . SP . $limit . ') AS ' . $this->_table_alias; |
|
| 142 | + $limit = is_array($limit) ? 'LIMIT '.implode(',', array_map('intval', $limit)) : 'LIMIT '.(int) $limit; |
|
| 143 | + return SP.'(SELECT * FROM '.$this->_table_name.SP.$limit.') AS '.$this->_table_alias; |
|
| 144 | 144 | } |
| 145 | 145 | |
| 146 | 146 | |
@@ -6,151 +6,151 @@ |
||
| 6 | 6 | */ |
| 7 | 7 | abstract class EE_Table_Base |
| 8 | 8 | { |
| 9 | - /** |
|
| 10 | - * This holds the table_name without the table prefix. |
|
| 11 | - * |
|
| 12 | - * @var string |
|
| 13 | - */ |
|
| 14 | - public $_table_name; |
|
| 15 | - |
|
| 16 | - |
|
| 17 | - /** |
|
| 18 | - * This holds what is used as the alias for the table in queries. |
|
| 19 | - * |
|
| 20 | - * @var string |
|
| 21 | - */ |
|
| 22 | - public $_table_alias; |
|
| 23 | - |
|
| 24 | - |
|
| 25 | - /** |
|
| 26 | - * Table's private key column |
|
| 27 | - * |
|
| 28 | - * @var string |
|
| 29 | - */ |
|
| 30 | - protected $_pk_column; |
|
| 31 | - |
|
| 32 | - |
|
| 33 | - /** |
|
| 34 | - * Whether this table is a global table (in multisite) or specific to site. |
|
| 35 | - * |
|
| 36 | - * @var bool |
|
| 37 | - */ |
|
| 38 | - protected $_global; |
|
| 39 | - |
|
| 40 | - |
|
| 41 | - /** |
|
| 42 | - * @param string $table_name with or without wpdb prefix |
|
| 43 | - * @param string $pk_column |
|
| 44 | - * @param boolean $global whether the table is "global" as in there is only 1 table on an entire multisite |
|
| 45 | - * install, or whether each site on a multisite install has a copy of this table |
|
| 46 | - * @global wpdb $wpdb |
|
| 47 | - */ |
|
| 48 | - public function __construct($table_name, $pk_column, $global = false) |
|
| 49 | - { |
|
| 50 | - $this->_global = $global; |
|
| 51 | - $prefix = $this->get_table_prefix(); |
|
| 52 | - // if they added the prefix, let's remove it because we delay adding the prefix until right when its needed. |
|
| 53 | - if (strpos($table_name, $prefix) === 0) { |
|
| 54 | - $table_name = substr_replace($table_name, '', 0, strlen($prefix)); |
|
| 55 | - } |
|
| 56 | - $this->_table_name = $table_name; |
|
| 57 | - $this->_pk_column = $pk_column; |
|
| 58 | - } |
|
| 59 | - |
|
| 60 | - |
|
| 61 | - /** |
|
| 62 | - * This returns the table prefix for the current model state. |
|
| 63 | - * |
|
| 64 | - * @return string |
|
| 65 | - * @global wpdb $wpdb |
|
| 66 | - */ |
|
| 67 | - public function get_table_prefix() |
|
| 68 | - { |
|
| 69 | - global $wpdb; |
|
| 70 | - if ($this->_global) { |
|
| 71 | - return $wpdb->base_prefix; |
|
| 72 | - } |
|
| 73 | - return $wpdb->get_blog_prefix(EEM_Base::get_model_query_blog_id()); |
|
| 74 | - } |
|
| 75 | - |
|
| 76 | - |
|
| 77 | - /** |
|
| 78 | - * Used to set the table_alias property |
|
| 79 | - * |
|
| 80 | - * @param string $table_alias |
|
| 81 | - */ |
|
| 82 | - public function _construct_finalize_with_alias($table_alias) |
|
| 83 | - { |
|
| 84 | - $this->_table_alias = $table_alias; |
|
| 85 | - } |
|
| 86 | - |
|
| 87 | - |
|
| 88 | - /** |
|
| 89 | - * Returns the fully qualified table name for the database (includes the table prefix current for the blog). |
|
| 90 | - * |
|
| 91 | - * @return string |
|
| 92 | - */ |
|
| 93 | - public function get_table_name() |
|
| 94 | - { |
|
| 95 | - return $this->get_table_prefix() . $this->_table_name; |
|
| 96 | - } |
|
| 97 | - |
|
| 98 | - |
|
| 99 | - /** |
|
| 100 | - * Provides what is currently set as the alias for the table to be used in queries. |
|
| 101 | - * |
|
| 102 | - * @return string |
|
| 103 | - * @throws EE_Error |
|
| 104 | - */ |
|
| 105 | - public function get_table_alias() |
|
| 106 | - { |
|
| 107 | - if (! $this->_table_alias) { |
|
| 108 | - throw new EE_Error("You must call _construct_finalize_with_alias before using the EE_Table_Base. Did you forget to call parent::__construct at the end of your EEMerimental_Base child's __construct?"); |
|
| 109 | - } |
|
| 110 | - return $this->_table_alias; |
|
| 111 | - } |
|
| 112 | - |
|
| 113 | - |
|
| 114 | - /** |
|
| 115 | - * @return string name of column of PK |
|
| 116 | - */ |
|
| 117 | - public function get_pk_column() |
|
| 118 | - { |
|
| 119 | - return $this->_pk_column; |
|
| 120 | - } |
|
| 121 | - |
|
| 122 | - |
|
| 123 | - /** |
|
| 124 | - * returns a string with the table alias, a period, and the private key's column. |
|
| 125 | - * |
|
| 126 | - * @return string |
|
| 127 | - */ |
|
| 128 | - public function get_fully_qualified_pk_column() |
|
| 129 | - { |
|
| 130 | - return $this->get_table_alias() . "." . $this->get_pk_column(); |
|
| 131 | - } |
|
| 132 | - |
|
| 133 | - |
|
| 134 | - /** |
|
| 135 | - * returns the special sql for a inner select with a limit. |
|
| 136 | - * |
|
| 137 | - * @return string SQL select |
|
| 138 | - */ |
|
| 139 | - public function get_select_join_limit($limit) |
|
| 140 | - { |
|
| 141 | - $limit = is_array($limit) ? 'LIMIT ' . implode(',', array_map('intval', $limit)) : 'LIMIT ' . (int) $limit; |
|
| 142 | - return SP . '(SELECT * FROM ' . $this->_table_name . SP . $limit . ') AS ' . $this->_table_alias; |
|
| 143 | - } |
|
| 144 | - |
|
| 145 | - |
|
| 146 | - /** |
|
| 147 | - * Returns whether or not htis is a global table (ie, on multisite there's |
|
| 148 | - * only one of these tables, on the main blog) |
|
| 149 | - * |
|
| 150 | - * @return boolean |
|
| 151 | - */ |
|
| 152 | - public function is_global() |
|
| 153 | - { |
|
| 154 | - return $this->_global; |
|
| 155 | - } |
|
| 9 | + /** |
|
| 10 | + * This holds the table_name without the table prefix. |
|
| 11 | + * |
|
| 12 | + * @var string |
|
| 13 | + */ |
|
| 14 | + public $_table_name; |
|
| 15 | + |
|
| 16 | + |
|
| 17 | + /** |
|
| 18 | + * This holds what is used as the alias for the table in queries. |
|
| 19 | + * |
|
| 20 | + * @var string |
|
| 21 | + */ |
|
| 22 | + public $_table_alias; |
|
| 23 | + |
|
| 24 | + |
|
| 25 | + /** |
|
| 26 | + * Table's private key column |
|
| 27 | + * |
|
| 28 | + * @var string |
|
| 29 | + */ |
|
| 30 | + protected $_pk_column; |
|
| 31 | + |
|
| 32 | + |
|
| 33 | + /** |
|
| 34 | + * Whether this table is a global table (in multisite) or specific to site. |
|
| 35 | + * |
|
| 36 | + * @var bool |
|
| 37 | + */ |
|
| 38 | + protected $_global; |
|
| 39 | + |
|
| 40 | + |
|
| 41 | + /** |
|
| 42 | + * @param string $table_name with or without wpdb prefix |
|
| 43 | + * @param string $pk_column |
|
| 44 | + * @param boolean $global whether the table is "global" as in there is only 1 table on an entire multisite |
|
| 45 | + * install, or whether each site on a multisite install has a copy of this table |
|
| 46 | + * @global wpdb $wpdb |
|
| 47 | + */ |
|
| 48 | + public function __construct($table_name, $pk_column, $global = false) |
|
| 49 | + { |
|
| 50 | + $this->_global = $global; |
|
| 51 | + $prefix = $this->get_table_prefix(); |
|
| 52 | + // if they added the prefix, let's remove it because we delay adding the prefix until right when its needed. |
|
| 53 | + if (strpos($table_name, $prefix) === 0) { |
|
| 54 | + $table_name = substr_replace($table_name, '', 0, strlen($prefix)); |
|
| 55 | + } |
|
| 56 | + $this->_table_name = $table_name; |
|
| 57 | + $this->_pk_column = $pk_column; |
|
| 58 | + } |
|
| 59 | + |
|
| 60 | + |
|
| 61 | + /** |
|
| 62 | + * This returns the table prefix for the current model state. |
|
| 63 | + * |
|
| 64 | + * @return string |
|
| 65 | + * @global wpdb $wpdb |
|
| 66 | + */ |
|
| 67 | + public function get_table_prefix() |
|
| 68 | + { |
|
| 69 | + global $wpdb; |
|
| 70 | + if ($this->_global) { |
|
| 71 | + return $wpdb->base_prefix; |
|
| 72 | + } |
|
| 73 | + return $wpdb->get_blog_prefix(EEM_Base::get_model_query_blog_id()); |
|
| 74 | + } |
|
| 75 | + |
|
| 76 | + |
|
| 77 | + /** |
|
| 78 | + * Used to set the table_alias property |
|
| 79 | + * |
|
| 80 | + * @param string $table_alias |
|
| 81 | + */ |
|
| 82 | + public function _construct_finalize_with_alias($table_alias) |
|
| 83 | + { |
|
| 84 | + $this->_table_alias = $table_alias; |
|
| 85 | + } |
|
| 86 | + |
|
| 87 | + |
|
| 88 | + /** |
|
| 89 | + * Returns the fully qualified table name for the database (includes the table prefix current for the blog). |
|
| 90 | + * |
|
| 91 | + * @return string |
|
| 92 | + */ |
|
| 93 | + public function get_table_name() |
|
| 94 | + { |
|
| 95 | + return $this->get_table_prefix() . $this->_table_name; |
|
| 96 | + } |
|
| 97 | + |
|
| 98 | + |
|
| 99 | + /** |
|
| 100 | + * Provides what is currently set as the alias for the table to be used in queries. |
|
| 101 | + * |
|
| 102 | + * @return string |
|
| 103 | + * @throws EE_Error |
|
| 104 | + */ |
|
| 105 | + public function get_table_alias() |
|
| 106 | + { |
|
| 107 | + if (! $this->_table_alias) { |
|
| 108 | + throw new EE_Error("You must call _construct_finalize_with_alias before using the EE_Table_Base. Did you forget to call parent::__construct at the end of your EEMerimental_Base child's __construct?"); |
|
| 109 | + } |
|
| 110 | + return $this->_table_alias; |
|
| 111 | + } |
|
| 112 | + |
|
| 113 | + |
|
| 114 | + /** |
|
| 115 | + * @return string name of column of PK |
|
| 116 | + */ |
|
| 117 | + public function get_pk_column() |
|
| 118 | + { |
|
| 119 | + return $this->_pk_column; |
|
| 120 | + } |
|
| 121 | + |
|
| 122 | + |
|
| 123 | + /** |
|
| 124 | + * returns a string with the table alias, a period, and the private key's column. |
|
| 125 | + * |
|
| 126 | + * @return string |
|
| 127 | + */ |
|
| 128 | + public function get_fully_qualified_pk_column() |
|
| 129 | + { |
|
| 130 | + return $this->get_table_alias() . "." . $this->get_pk_column(); |
|
| 131 | + } |
|
| 132 | + |
|
| 133 | + |
|
| 134 | + /** |
|
| 135 | + * returns the special sql for a inner select with a limit. |
|
| 136 | + * |
|
| 137 | + * @return string SQL select |
|
| 138 | + */ |
|
| 139 | + public function get_select_join_limit($limit) |
|
| 140 | + { |
|
| 141 | + $limit = is_array($limit) ? 'LIMIT ' . implode(',', array_map('intval', $limit)) : 'LIMIT ' . (int) $limit; |
|
| 142 | + return SP . '(SELECT * FROM ' . $this->_table_name . SP . $limit . ') AS ' . $this->_table_alias; |
|
| 143 | + } |
|
| 144 | + |
|
| 145 | + |
|
| 146 | + /** |
|
| 147 | + * Returns whether or not htis is a global table (ie, on multisite there's |
|
| 148 | + * only one of these tables, on the main blog) |
|
| 149 | + * |
|
| 150 | + * @return boolean |
|
| 151 | + */ |
|
| 152 | + public function is_global() |
|
| 153 | + { |
|
| 154 | + return $this->_global; |
|
| 155 | + } |
|
| 156 | 156 | } |