| @@ -19,8 +19,11 @@ | ||
| 19 | 19 | * @var int[] |
| 20 | 20 | */ |
| 21 | 21 | private $valid_entry_ids = array(); |
| 22 | 22 | |
| 23 | + /** | |
| 24 | + * @param array $args | |
| 25 | + */ | |
| 23 | 26 | public function __construct( $args ) { |
| 24 | 27 | $this->table = FrmAppHelper::get_simple_request( |
| 25 | 28 | array( |
| 26 | 29 | 'param' => 'trans_type', |
| @@ -87,22 +90,20 @@ | ||
| 87 | 90 | |
| 88 | 91 | $table_name = $this->table === 'subscriptions' ? 'frm_subscriptions' : 'frm_payments'; |
| 89 | 92 | $form_id = FrmAppHelper::get_param( 'form', 0, 'get', 'absint' ); |
| 90 | 93 | |
| 91 | - if ( $form_id ) { | |
| 92 | - // @codingStandardsIgnoreStart | |
| 93 | - $query = $wpdb->prepare( | |
| 94 | - "FROM `{$wpdb->prefix}{$table_name}` p | |
| 95 | - JOIN `{$wpdb->prefix}frm_items` i ON p.item_id = i.id | |
| 96 | - WHERE i.form_id = %d", | |
| 97 | - $form_id | |
| 98 | - ); | |
| 99 | - // @codingStandardsIgnoreEnd | |
| 100 | - } else { | |
| 101 | - $query = "FROM `{$wpdb->prefix}{$table_name}` p"; | |
| 94 | + if ( ! $form_id ) { | |
| 95 | + return "FROM `{$wpdb->prefix}{$table_name}` p"; | |
| 102 | 96 | } |
| 103 | 97 | |
| 104 | - return $query; | |
| 98 | + // @codingStandardsIgnoreStart | |
| 99 | + return $wpdb->prepare( | |
| 100 | + "FROM `{$wpdb->prefix}{$table_name}` p | |
| 101 | + JOIN `{$wpdb->prefix}frm_items` i ON p.item_id = i.id | |
| 102 | + WHERE i.form_id = %d", | |
| 103 | + $form_id | |
| 104 | + ); | |
| 105 | + // @codingStandardsIgnoreEnd | |
| 105 | 106 | } |
| 106 | 107 | |
| 107 | 108 | /** |
| 108 | 109 | * @return void |
| @@ -107,9 +108,9 @@ | ||
| 107 | 108 | /** |
| 108 | 109 | * @return void |
| 109 | 110 | */ |
| 110 | 111 | public function no_items() { |
| 111 | - esc_html_e( 'No payments found.', 'formidable' ); | |
| 112 | + include FrmTransLiteAppHelper::plugin_path() . '/views/lists/no-payments.php'; | |
| 112 | 113 | } |
| 113 | 114 | |
| 114 | 115 | /** |
| 115 | 116 | * @return array |
| @@ -119,10 +120,9 @@ | ||
| 119 | 120 | 'payments' => __( 'Payments', 'formidable' ), |
| 120 | 121 | 'subscriptions' => __( 'Subscriptions', 'formidable' ), |
| 121 | 122 | ); |
| 122 | 123 | |
| 123 | - $links = array(); | |
| 124 | - | |
| 124 | + $links = array(); | |
| 125 | 125 | $frm_payment = new FrmTransLitePayment(); |
| 126 | 126 | $frm_sub = new FrmTransLiteSubscription(); |
| 127 | 127 | $counts = array( |
| 128 | 128 | 'payments' => $frm_payment->get_count(), |
| @@ -136,19 +136,17 @@ | ||
| 136 | 136 | ) |
| 137 | 137 | ); |
| 138 | 138 | |
| 139 | 139 | foreach ( $statuses as $status => $name ) { |
| 140 | - if ( $status === $type ) { | |
| 141 | - $class = ' class="current"'; | |
| 142 | - } else { | |
| 143 | - $class = ''; | |
| 144 | - } | |
| 140 | + $class = $status === $type ? ' class="current"' : ''; | |
| 145 | 141 | |
| 146 | - if ( $counts[ $status ] || 'published' === $status ) { | |
| 142 | + if ( $counts[ $status ] || 'payments' === $status ) { | |
| 143 | + // phpcs:disable Generic.WhiteSpace.ScopeIndent | |
| 147 | 144 | $links[ $status ] = '<a href="' . esc_url( '?page=formidable-payments&trans_type=' . $status ) . '" ' . $class . '>' |
| 148 | 145 | // translators: %1$s: Transaction type (Payments or Subscriptions), %2$s: Span start tag, %3$s: Count, %4$s: Span close tag. |
| 149 | 146 | . sprintf( esc_html__( '%1$s %2$s(%3$s)%4$s', 'formidable' ), esc_html( $name ), '<span class="count">', number_format_i18n( $counts[ $status ] ), '</span>' ) |
| 150 | 147 | . '</a>'; |
| 148 | + // phpcs:enable Generic.WhiteSpace.ScopeIndent | |
| 151 | 149 | } |
| 152 | 150 | |
| 153 | 151 | unset( $status, $name ); |
| 154 | 152 | } |
| @@ -174,8 +172,9 @@ | ||
| 174 | 172 | 'receipt_id' => 'receipt_id', |
| 175 | 173 | 'sub_id' => 'sub_id', |
| 176 | 174 | 'begin_date' => 'begin_date', |
| 177 | 175 | 'expire_date' => 'expire_date', |
| 176 | + 'paysys' => 'paysys', | |
| 178 | 177 | 'status' => 'status', |
| 179 | 178 | 'next_bill_date' => 'next_bill_date', |
| 180 | 179 | ); |
| 181 | 180 | } |
| @@ -180,8 +179,25 @@ | ||
| 180 | 179 | ); |
| 181 | 180 | } |
| 182 | 181 | |
| 183 | 182 | /** |
| 183 | + * If the Payments submodule or the PayPal add-on is active, add a bulk delete action. | |
| 184 | + * | |
| 185 | + * @since 6.27 | |
| 186 | + * | |
| 187 | + * @return array | |
| 188 | + */ | |
| 189 | + public function get_bulk_actions() { | |
| 190 | + $actions = array(); | |
| 191 | + | |
| 192 | + if ( $this->payments_addon_list_helper_exists() ) { | |
| 193 | + $actions['bulk_delete'] = __( 'Delete', 'formidable' ); | |
| 194 | + } | |
| 195 | + | |
| 196 | + return $actions; | |
| 197 | + } | |
| 198 | + | |
| 199 | + /** | |
| 184 | 200 | * @param string $which |
| 185 | 201 | * |
| 186 | 202 | * @return void |
| 187 | 203 | */ |
| @@ -213,13 +229,12 @@ | ||
| 213 | 229 | * @return void |
| 214 | 230 | */ |
| 215 | 231 | public function display_rows() { |
| 216 | 232 | $date_format = FrmTransLiteAppHelper::get_date_format(); |
| 217 | - | |
| 218 | - $alt = 0; | |
| 219 | - | |
| 220 | - $form_ids = $this->get_form_ids(); | |
| 221 | - $args = compact( 'form_ids', 'date_format' ); | |
| 233 | + $gateways = FrmTransLiteAppHelper::get_gateways(); | |
| 234 | + $alt = 0; | |
| 235 | + $form_ids = $this->get_form_ids(); | |
| 236 | + $args = compact( 'form_ids', 'date_format', 'gateways' ); | |
| 222 | 237 | // $form_ids is indexed by entry ID. |
| 223 | 238 | $this->valid_entry_ids = array_keys( $form_ids ); |
| 224 | 239 | |
| 225 | 240 | foreach ( $this->items as $item ) { |
| @@ -260,14 +275,29 @@ | ||
| 260 | 275 | } |
| 261 | 276 | |
| 262 | 277 | protected function get_column_info() { |
| 263 | 278 | $column_info = parent::get_column_info(); |
| 264 | - // Remove the checkbox column. | |
| 265 | - unset( $column_info[0]['cb'] ); | |
| 279 | + | |
| 280 | + if ( ! $this->payments_addon_list_helper_exists() ) { | |
| 281 | + // Remove the checkbox column for Lite only. | |
| 282 | + unset( $column_info[0]['cb'] ); | |
| 283 | + } | |
| 284 | + | |
| 266 | 285 | return $column_info; |
| 267 | 286 | } |
| 268 | 287 | |
| 269 | 288 | /** |
| 289 | + * Check for Payments submodule (Stripe, Authorize.Net add-ons), as well as PayPal. | |
| 290 | + * | |
| 291 | + * @since 6.27 | |
| 292 | + * | |
| 293 | + * @return bool | |
| 294 | + */ | |
| 295 | + private function payments_addon_list_helper_exists() { | |
| 296 | + return class_exists( 'FrmTransListHelper' ) || class_exists( 'FrmPaymentsListHelper' ); | |
| 297 | + } | |
| 298 | + | |
| 299 | + /** | |
| 270 | 300 | * @param object $item |
| 271 | 301 | * @param array $args |
| 272 | 302 | * |
| 273 | 303 | * @return string |
| @@ -280,9 +310,9 @@ | ||
| 280 | 310 | $val = $this->$function_name( $item, $args ); |
| 281 | 311 | } else { |
| 282 | 312 | $val = $item->$column_name ? $item->$column_name : ''; |
| 283 | 313 | |
| 284 | - if ( strpos( $column_name, '_date' ) !== false ) { | |
| 314 | + if ( str_contains( $column_name, '_date' ) ) { | |
| 285 | 315 | if ( ! empty( $item->$column_name ) && $item->$column_name !== '0000-00-00' ) { |
| 286 | 316 | $val = FrmTransLiteAppHelper::format_the_date( $item->$column_name, $args['date_format'] ); |
| 287 | 317 | } else { |
| 288 | 318 | $val = ''; |
| @@ -335,9 +365,9 @@ | ||
| 335 | 365 | */ |
| 336 | 366 | private function get_row_classes( $atts ) { |
| 337 | 367 | $class = 'column-' . $atts['column_name']; |
| 338 | 368 | |
| 339 | - if ( in_array( $atts['column_name'], $atts['hidden'] ) ) { | |
| 369 | + if ( in_array( $atts['column_name'], $atts['hidden'], true ) ) { | |
| 340 | 370 | $class .= ' frm_hidden'; |
| 341 | 371 | } |
| 342 | 372 | |
| 343 | 373 | return 'class="' . esc_attr( $class ) . '"'; |
| @@ -343,12 +373,26 @@ | ||
| 343 | 373 | return 'class="' . esc_attr( $class ) . '"'; |
| 344 | 374 | } |
| 345 | 375 | |
| 346 | 376 | /** |
| 377 | + * Get the checkbox for bulk actions. | |
| 378 | + * This is only required when the Payments submodule or PayPal is active. | |
| 379 | + * | |
| 380 | + * @since 6.27 | |
| 381 | + * | |
| 347 | 382 | * @param object $item |
| 348 | 383 | * |
| 349 | 384 | * @return string |
| 350 | 385 | */ |
| 386 | + private function get_cb_column( $item ) { | |
| 387 | + return '<input type="checkbox" name="item-action[]" value="' . esc_attr( $item->id ) . '" />'; | |
| 388 | + } | |
| 389 | + | |
| 390 | + /** | |
| 391 | + * @param object $item | |
| 392 | + * | |
| 393 | + * @return string | |
| 394 | + */ | |
| 351 | 395 | private function get_receipt_id_column( $item ) { |
| 352 | 396 | return $this->get_action_column( $item, 'receipt_id' ); |
| 353 | 397 | } |
| 354 | 398 | |
| @@ -358,30 +402,45 @@ | ||
| 358 | 402 | * |
| 359 | 403 | * @return string |
| 360 | 404 | */ |
| 361 | 405 | private function get_action_column( $item, $field ) { |
| 362 | - $link = add_query_arg( | |
| 406 | + $link = $this->get_view_payment_link( $item, $field ); | |
| 407 | + return '<strong>' . $link . '</strong><br />' . $this->row_actions( $this->get_row_actions( $item ) ); | |
| 408 | + } | |
| 409 | + | |
| 410 | + /** | |
| 411 | + * @since 6.27 | |
| 412 | + * | |
| 413 | + * @param object $item | |
| 414 | + * @param string $field | |
| 415 | + * | |
| 416 | + * @return string | |
| 417 | + */ | |
| 418 | + private function get_view_payment_link( $item, $field ) { | |
| 419 | + $link_params = array( | |
| 420 | + 'class' => 'rot-title', | |
| 421 | + 'href' => esc_url( $this->get_url_to_payment( $item->id, 'show' ) ), | |
| 422 | + 'title' => __( 'View', 'formidable' ), | |
| 423 | + ); | |
| 424 | + return '<a ' . FrmAppHelper::array_to_html_params( $link_params ) . '>' . esc_html( $item->{ $field } ) . '</a>'; | |
| 425 | + } | |
| 426 | + | |
| 427 | + /** | |
| 428 | + * @param int|string $payment_id | |
| 429 | + * @param string $action Supports 'show' and 'edit'. | |
| 430 | + * | |
| 431 | + * @return string | |
| 432 | + */ | |
| 433 | + private function get_url_to_payment( $payment_id, $action = 'show' ) { | |
| 434 | + return add_query_arg( | |
| 363 | 435 | array( |
| 364 | - 'action' => 'show', | |
| 365 | - 'id' => $item->id, | |
| 436 | + 'action' => $action, | |
| 437 | + 'id' => $payment_id, | |
| 366 | 438 | 'type' => $this->table, |
| 367 | 439 | 'page' => FrmAppHelper::simple_get( 'page' ), |
| 368 | 440 | ), |
| 369 | 441 | admin_url( 'admin.php' ) |
| 370 | 442 | ); |
| 371 | - | |
| 372 | - $link_params = array( | |
| 373 | - 'class' => 'rot-title', | |
| 374 | - 'href' => esc_url( $link ), | |
| 375 | - 'title' => __( 'View', 'formidable' ), | |
| 376 | - ); | |
| 377 | - $link = '<a ' . FrmAppHelper::array_to_html_params( $link_params ) . '>' | |
| 378 | - . $item->{$field} | |
| 379 | - . '</a>'; | |
| 380 | - | |
| 381 | - return '<strong>' . $link . '</strong>' | |
| 382 | - . '<br />' | |
| 383 | - . $this->row_actions( $this->get_row_actions( $item ) ); | |
| 384 | 443 | } |
| 385 | 444 | |
| 386 | 445 | /** |
| 387 | 446 | * @param object $item |
| @@ -395,19 +454,32 @@ | ||
| 395 | 454 | |
| 396 | 455 | $actions = array(); |
| 397 | 456 | $actions['view'] = '<a href="' . esc_url( $view_link ) . '">' . esc_html__( 'View', 'formidable' ) . '</a>'; |
| 398 | 457 | |
| 399 | - if ( $this->table !== 'subscriptions' && 'stripe' !== $item->paysys && class_exists( 'FrmPaymentsController', false ) ) { | |
| 458 | + if ( $this->supports_edit_link() ) { | |
| 400 | 459 | $edit_link = $base_link . 'edit&id=' . $item->id; |
| 401 | 460 | $actions['edit'] = '<a href="' . esc_url( $edit_link ) . '">' . esc_html__( 'Edit', 'formidable' ) . '</a>'; |
| 402 | 461 | } |
| 403 | 462 | |
| 404 | - $actions['delete'] = '<a href="' . esc_url( wp_nonce_url( $delete_link ) ) . '" data-frmverify="' . esc_attr__( 'Permanently delete this payment?', 'formidable' ) . '" data-frmverify-btn="frm-button-red">' . esc_html__( 'Delete', 'formidable' ) . '</a>'; | |
| 463 | + $actions['delete'] = '<a href="' . esc_url( wp_nonce_url( $delete_link ) ) . '" data-frmverify="' . esc_attr__( 'Permanently delete this payment?', 'formidable' ) . '" data-frmverify-btn="frm-button-red">' . esc_html__( 'Delete', 'formidable' ) . '</a>'; // phpcs:ignore SlevomatCodingStandard.Files.LineLength.LineTooLong | |
| 405 | 464 | |
| 406 | 465 | return $actions; |
| 407 | 466 | } |
| 408 | 467 | |
| 409 | 468 | /** |
| 469 | + * @since 6.27 | |
| 470 | + * | |
| 471 | + * @return bool | |
| 472 | + */ | |
| 473 | + private function supports_edit_link() { | |
| 474 | + if ( $this->table === 'subscriptions' ) { | |
| 475 | + return false; | |
| 476 | + } | |
| 477 | + | |
| 478 | + return class_exists( 'FrmTransAppController', false ) || class_exists( 'FrmPaymentsController', false ); | |
| 479 | + } | |
| 480 | + | |
| 481 | + /** | |
| 410 | 482 | * Get the column value for displaying an entry ID. |
| 411 | 483 | * |
| 412 | 484 | * @param object $item A payment or subscription object. |
| 413 | 485 | * |
| @@ -413,9 +485,10 @@ | ||
| 413 | 485 | * |
| 414 | 486 | * @return string |
| 415 | 487 | */ |
| 416 | 488 | private function get_item_id_column( $item ) { |
| 417 | - $entry_id = (int) $item->item_id; | |
| 489 | + $entry_id = (int) $item->item_id; | |
| 490 | + // phpcs:ignore WordPress.PHP.StrictInArray.MissingTrueStrict | |
| 418 | 491 | $entry_is_deleted = ! in_array( $entry_id, $this->valid_entry_ids ); |
| 419 | 492 | |
| 420 | 493 | if ( $entry_is_deleted ) { |
| 421 | 494 | // translators: %d: ID of the deleted entry. |
| @@ -432,10 +505,9 @@ | ||
| 432 | 505 | * @return mixed |
| 433 | 506 | */ |
| 434 | 507 | private function get_form_id_column( $item, $atts ) { |
| 435 | 508 | if ( isset( $atts['form_ids'][ $item->item_id ] ) ) { |
| 436 | - $form_link = FrmFormsHelper::edit_form_link( $atts['form_ids'][ $item->item_id ]->form_id ); | |
| 437 | - return $form_link; | |
| 509 | + return FrmFormsHelper::edit_form_link( $atts['form_ids'][ $item->item_id ]->form_id ); | |
| 438 | 510 | } |
| 439 | 511 | |
| 440 | 512 | return ''; |
| 441 | 513 | } |
| @@ -445,9 +517,8 @@ | ||
| 445 | 517 | * |
| 446 | 518 | * @return string |
| 447 | 519 | */ |
| 448 | 520 | private function get_user_id_column( $item ) { |
| 449 | - global $wpdb; | |
| 450 | 521 | $val = FrmDb::get_var( 'frm_items', array( 'id' => $item->item_id ), 'user_id' ); |
| 451 | 522 | return FrmTransLiteAppHelper::get_user_link( $val ); |
| 452 | 523 | } |
| 453 | 524 | |
| @@ -463,10 +534,9 @@ | ||
| 463 | 534 | } |
| 464 | 535 | |
| 465 | 536 | $date = FrmAppHelper::get_localized_date( $atts['date_format'], $item->created_at ); |
| 466 | 537 | $date_title = FrmAppHelper::get_localized_date( $atts['date_format'] . ' g:i:s A', $item->created_at ); |
| 467 | - $val = '<abbr title="' . esc_attr( $date_title ) . '">' . $date . '</abbr>'; | |
| 468 | - return $val; | |
| 538 | + return '<abbr title="' . esc_attr( $date_title ) . '">' . $date . '</abbr>'; | |
| 469 | 539 | } |
| 470 | 540 | |
| 471 | 541 | /** |
| 472 | 542 | * @param object $item |
| @@ -502,9 +572,9 @@ | ||
| 502 | 572 | */ |
| 503 | 573 | private function get_status_column( $item ) { |
| 504 | 574 | $status = esc_html( FrmTransLiteAppHelper::show_status( FrmTransLiteAppHelper::get_payment_status( $item ) ) ); |
| 505 | 575 | |
| 506 | - if ( 'processing' === $item->status ) { | |
| 576 | + if ( 'processing' === ( $item->status ?? '' ) ) { | |
| 507 | 577 | $status .= $this->get_processing_tooltip(); |
| 508 | 578 | } |
| 509 | 579 | |
| 510 | 580 | return $status; |
| @@ -549,16 +619,12 @@ | ||
| 549 | 619 | * |
| 550 | 620 | * @return string |
| 551 | 621 | */ |
| 552 | 622 | private function get_paysys_column( $item, $atts ) { |
| 553 | - switch ( $item->paysys ) { | |
| 554 | - case 'stripe': | |
| 555 | - return 'Stripe'; | |
| 556 | - case 'paypal': | |
| 557 | - return 'PayPal'; | |
| 558 | - case 'square': | |
| 559 | - return 'Square'; | |
| 623 | + if ( isset( $atts['gateways'][ $item->paysys ] ) ) { | |
| 624 | + return $atts['gateways'][ $item->paysys ]['label']; | |
| 560 | 625 | } |
| 626 | + | |
| 561 | 627 | return $item->paysys; |
| 562 | 628 | } |
| 563 | 629 | |
| 564 | 630 | /** |
| @@ -572,6 +638,24 @@ | ||
| 572 | 638 | * @return string |
| 573 | 639 | */ |
| 574 | 640 | private function get_mode_column( $item ) { |
| 575 | 641 | return esc_html( FrmTransLiteAppHelper::get_test_mode_display_string( $item ) ); |
| 642 | + } | |
| 643 | + | |
| 644 | + /** | |
| 645 | + * Render the tabs for the payments list, if the user has access to coupons. | |
| 646 | + * | |
| 647 | + * @since 6.27 | |
| 648 | + * | |
| 649 | + * @param string $active_tab | |
| 650 | + * | |
| 651 | + * @return void | |
| 652 | + */ | |
| 653 | + public static function render_tabs( $active_tab = 'payments' ) { | |
| 654 | + if ( ! current_user_can( 'frm_change_settings' ) ) { | |
| 655 | + // Coupons are only available to people who can access global settings. | |
| 656 | + return; | |
| 657 | + } | |
| 658 | + | |
| 659 | + include FrmTransLiteAppHelper::plugin_path() . '/views/lists/tabs.php'; | |
| 576 | 660 | } |
| 577 | 661 | } |