| 1 |
<?php |
| 2 |
if ( ! defined( 'ABSPATH' ) ) { |
| 3 |
die( 'You are not allowed to call this page directly.' ); |
| 4 |
} |
| 5 |
|
| 6 |
class FrmTransLiteListHelper extends FrmListHelper { |
| 7 |
|
| 8 |
/** |
| 9 |
* @var string |
| 10 |
*/ |
| 11 |
private $table = ''; |
| 12 |
|
| 13 |
/** |
| 14 |
* An array of all valid entry ids. |
| 15 |
* This is retrieved all at once with a single database query. |
| 16 |
* This is used to determine if a specific entry is deleted. |
| 17 |
* When an entry is deleted, there is no link to the deleted entry. |
| 18 |
* |
| 19 |
* @var int[] |
| 20 |
*/ |
| 21 |
private $valid_entry_ids = array(); |
| 22 |
|
| 23 |
/** |
| 24 |
* @param array $args |
| 25 |
*/ |
| 26 |
public function __construct( $args ) { |
| 27 |
$this->table = FrmAppHelper::get_simple_request( |
| 28 |
array( |
| 29 |
'param' => 'trans_type', |
| 30 |
'type' => 'request', |
| 31 |
) |
| 32 |
); |
| 33 |
|
| 34 |
parent::__construct( $args ); |
| 35 |
$this->screen->set_screen_reader_content( |
| 36 |
array( |
| 37 |
'heading_list' => esc_html__( 'Payments list', 'formidable' ), |
| 38 |
) |
| 39 |
); |
| 40 |
} |
| 41 |
|
| 42 |
/** |
| 43 |
* @return void |
| 44 |
*/ |
| 45 |
public function prepare_items() { |
| 46 |
global $wpdb; |
| 47 |
|
| 48 |
$orderby = FrmAppHelper::get_param( 'orderby', 'id', 'get', 'sanitize_title' ); |
| 49 |
$order = FrmAppHelper::get_param( 'order', 'DESC', 'get', 'sanitize_text_field' ); |
| 50 |
|
| 51 |
if ( ! is_string( $orderby ) ) { |
| 52 |
$orderby = 'id'; |
| 53 |
} |
| 54 |
|
| 55 |
if ( ! is_string( $order ) || ! in_array( strtoupper( $order ), array( 'ASC', 'DESC' ), true ) ) { |
| 56 |
$order = 'DESC'; |
| 57 |
} |
| 58 |
|
| 59 |
$page = $this->get_pagenum(); |
| 60 |
$per_page = $this->get_items_per_page( 'formidable_page_formidable_payments_per_page' ); |
| 61 |
$start = ( $page - 1 ) * $per_page; |
| 62 |
$start = FrmAppHelper::get_param( 'start', $start, 'get', 'absint' ); |
| 63 |
$query = $this->get_table_query(); |
| 64 |
$order_query = FrmDb::esc_order( "ORDER BY p.{$orderby} $order" ); |
| 65 |
|
| 66 |
// @codingStandardsIgnoreStart |
| 67 |
$this->items = $wpdb->get_results( |
| 68 |
$wpdb->prepare( |
| 69 |
'SELECT p.* ' . $query . $order_query . ' LIMIT %d, %d', |
| 70 |
$start, |
| 71 |
$per_page |
| 72 |
) |
| 73 |
); |
| 74 |
$total_items = $wpdb->get_var( 'SELECT COUNT(*) ' . $query ); |
| 75 |
// @codingStandardsIgnoreEnd |
| 76 |
|
| 77 |
$this->set_pagination_args( |
| 78 |
array( |
| 79 |
'total_items' => $total_items, |
| 80 |
'per_page' => $per_page, |
| 81 |
) |
| 82 |
); |
| 83 |
} |
| 84 |
|
| 85 |
/** |
| 86 |
* @return string |
| 87 |
*/ |
| 88 |
private function get_table_query() { |
| 89 |
global $wpdb; |
| 90 |
|
| 91 |
$table_name = $this->table === 'subscriptions' ? 'frm_subscriptions' : 'frm_payments'; |
| 92 |
$form_id = FrmAppHelper::get_param( 'form', 0, 'get', 'absint' ); |
| 93 |
|
| 94 |
if ( ! $form_id ) { |
| 95 |
return "FROM `{$wpdb->prefix}{$table_name}` p"; |
| 96 |
} |
| 97 |
|
| 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 |
| 106 |
} |
| 107 |
|
| 108 |
/** |
| 109 |
* @return void |
| 110 |
*/ |
| 111 |
public function no_items() { |
| 112 |
include FrmTransLiteAppHelper::plugin_path() . '/views/lists/no-payments.php'; |
| 113 |
} |
| 114 |
|
| 115 |
/** |
| 116 |
* @return array |
| 117 |
*/ |
| 118 |
public function get_views() { |
| 119 |
$statuses = array( |
| 120 |
'payments' => __( 'Payments', 'formidable' ), |
| 121 |
'subscriptions' => __( 'Subscriptions', 'formidable' ), |
| 122 |
); |
| 123 |
|
| 124 |
$links = array(); |
| 125 |
$frm_payment = new FrmTransLitePayment(); |
| 126 |
$frm_sub = new FrmTransLiteSubscription(); |
| 127 |
$counts = array( |
| 128 |
'payments' => $frm_payment->get_count(), |
| 129 |
'subscriptions' => $frm_sub->get_count(), |
| 130 |
); |
| 131 |
$type = FrmAppHelper::get_simple_request( |
| 132 |
array( |
| 133 |
'param' => 'trans_type', |
| 134 |
'type' => 'request', |
| 135 |
'default' => 'payments', |
| 136 |
) |
| 137 |
); |
| 138 |
|
| 139 |
foreach ( $statuses as $status => $name ) { |
| 140 |
$class = $status === $type ? ' class="current"' : ''; |
| 141 |
|
| 142 |
if ( $counts[ $status ] || 'payments' === $status ) { |
| 143 |
// phpcs:disable Generic.WhiteSpace.ScopeIndent |
| 144 |
$links[ $status ] = '<a href="' . esc_url( '?page=formidable-payments&trans_type=' . $status ) . '" ' . $class . '>' |
| 145 |
// translators: %1$s: Transaction type (Payments or Subscriptions), %2$s: Span start tag, %3$s: Count, %4$s: Span close tag. |
| 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>' ) |
| 147 |
. '</a>'; |
| 148 |
// phpcs:enable Generic.WhiteSpace.ScopeIndent |
| 149 |
} |
| 150 |
|
| 151 |
unset( $status, $name ); |
| 152 |
} |
| 153 |
|
| 154 |
return $links; |
| 155 |
} |
| 156 |
|
| 157 |
/** |
| 158 |
* @return array |
| 159 |
*/ |
| 160 |
public function get_columns() { |
| 161 |
return FrmTransLiteListsController::payment_columns(); |
| 162 |
} |
| 163 |
|
| 164 |
/** |
| 165 |
* @return array |
| 166 |
*/ |
| 167 |
public function get_sortable_columns() { |
| 168 |
return array( |
| 169 |
'item_id' => 'item_id', |
| 170 |
'amount' => 'amount', |
| 171 |
'created_at' => 'created_at', |
| 172 |
'receipt_id' => 'receipt_id', |
| 173 |
'sub_id' => 'sub_id', |
| 174 |
'begin_date' => 'begin_date', |
| 175 |
'expire_date' => 'expire_date', |
| 176 |
'paysys' => 'paysys', |
| 177 |
'status' => 'status', |
| 178 |
'next_bill_date' => 'next_bill_date', |
| 179 |
); |
| 180 |
} |
| 181 |
|
| 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 |
/** |
| 200 |
* @param string $which |
| 201 |
* |
| 202 |
* @return void |
| 203 |
*/ |
| 204 |
public function extra_tablenav( $which ) { |
| 205 |
$footer = $which !== 'top'; |
| 206 |
|
| 207 |
if ( $footer ) { |
| 208 |
return; |
| 209 |
} |
| 210 |
|
| 211 |
$form_id = FrmAppHelper::simple_get( 'form', 'absint', 0 ); |
| 212 |
|
| 213 |
if ( $form_id ) { |
| 214 |
// Don't show the switcher if it's already in the header. |
| 215 |
return; |
| 216 |
} |
| 217 |
|
| 218 |
FrmFormsHelper::forms_dropdown( |
| 219 |
'form', |
| 220 |
$form_id, |
| 221 |
array( 'blank' => __( 'View all forms', 'formidable' ) ) |
| 222 |
); |
| 223 |
|
| 224 |
echo '<input type="hidden" name="trans_type" value="' . esc_attr( FrmAppHelper::get_param( 'trans_type', 'payments', 'get', 'sanitize_text_field' ) ) . '">'; |
| 225 |
echo '<input id="post-query-submit" class="button" type="submit" value="Filter" name="filter_action" />'; |
| 226 |
} |
| 227 |
|
| 228 |
/** |
| 229 |
* @return void |
| 230 |
*/ |
| 231 |
public function display_rows() { |
| 232 |
$date_format = FrmTransLiteAppHelper::get_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' ); |
| 237 |
// $form_ids is indexed by entry ID. |
| 238 |
$this->valid_entry_ids = array_keys( $form_ids ); |
| 239 |
|
| 240 |
foreach ( $this->items as $item ) { |
| 241 |
echo '<tr id="payment-' . esc_attr( $item->id ) . '" '; |
| 242 |
|
| 243 |
$is_alternate = 0 === $alt % 2; |
| 244 |
++$alt; |
| 245 |
|
| 246 |
if ( $is_alternate ) { |
| 247 |
echo 'class="alternate"'; |
| 248 |
} |
| 249 |
|
| 250 |
echo '>'; |
| 251 |
$this->display_columns( $item, $args ); |
| 252 |
echo '</tr>'; |
| 253 |
|
| 254 |
unset( $item ); |
| 255 |
} |
| 256 |
} |
| 257 |
|
| 258 |
/** |
| 259 |
* @param object $item |
| 260 |
* @param array $args |
| 261 |
* |
| 262 |
* @return void |
| 263 |
*/ |
| 264 |
private function display_columns( $item, $args ) { |
| 265 |
list( $columns, $hidden ) = $this->get_column_info(); |
| 266 |
|
| 267 |
foreach ( $columns as $column_name => $column_display_name ) { |
| 268 |
$attributes = self::get_row_classes( compact( 'column_name', 'hidden' ) ); |
| 269 |
$args['column_name'] = $column_name; |
| 270 |
$val = $this->get_column_value( $item, $args ); |
| 271 |
|
| 272 |
echo '<td ' . $attributes . '>' . $val . '</td>'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| 273 |
unset( $val ); |
| 274 |
} |
| 275 |
} |
| 276 |
|
| 277 |
protected function get_column_info() { |
| 278 |
$column_info = parent::get_column_info(); |
| 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 |
|
| 285 |
return $column_info; |
| 286 |
} |
| 287 |
|
| 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 |
/** |
| 300 |
* @param object $item |
| 301 |
* @param array $args |
| 302 |
* |
| 303 |
* @return string |
| 304 |
*/ |
| 305 |
private function get_column_value( $item, $args ) { |
| 306 |
$column_name = $args['column_name']; |
| 307 |
$function_name = 'get_' . $column_name . '_column'; |
| 308 |
|
| 309 |
if ( method_exists( $this, $function_name ) ) { |
| 310 |
$val = $this->$function_name( $item, $args ); |
| 311 |
} else { |
| 312 |
$val = $item->$column_name ? $item->$column_name : ''; |
| 313 |
|
| 314 |
if ( str_contains( $column_name, '_date' ) ) { |
| 315 |
if ( ! empty( $item->$column_name ) && $item->$column_name !== '0000-00-00' ) { |
| 316 |
$val = FrmTransLiteAppHelper::format_the_date( $item->$column_name, $args['date_format'] ); |
| 317 |
} else { |
| 318 |
$val = ''; |
| 319 |
} |
| 320 |
} |
| 321 |
} |
| 322 |
|
| 323 |
return $val; |
| 324 |
} |
| 325 |
|
| 326 |
/** |
| 327 |
* @return array |
| 328 |
*/ |
| 329 |
private function get_form_ids() { |
| 330 |
$entry_ids = array(); |
| 331 |
|
| 332 |
foreach ( $this->items as $item ) { |
| 333 |
$entry_ids[] = absint( $item->item_id ); |
| 334 |
unset( $item ); |
| 335 |
} |
| 336 |
|
| 337 |
global $wpdb; |
| 338 |
// @codingStandardsIgnoreStart |
| 339 |
$forms = $wpdb->get_results( |
| 340 |
"SELECT |
| 341 |
fo.id as form_id, |
| 342 |
fo.name, |
| 343 |
e.id |
| 344 |
FROM {$wpdb->prefix}frm_items e |
| 345 |
LEFT JOIN {$wpdb->prefix}frm_forms fo ON e.form_id = fo.id |
| 346 |
WHERE e.id in (" . implode( ',', $entry_ids ) . ')' |
| 347 |
); |
| 348 |
// @codingStandardsIgnoreEnd |
| 349 |
unset( $entry_ids ); |
| 350 |
|
| 351 |
$form_ids = array(); |
| 352 |
|
| 353 |
foreach ( $forms as $form ) { |
| 354 |
$form_ids[ $form->id ] = $form; |
| 355 |
unset( $form ); |
| 356 |
} |
| 357 |
|
| 358 |
return $form_ids; |
| 359 |
} |
| 360 |
|
| 361 |
/** |
| 362 |
* @param array $atts |
| 363 |
* |
| 364 |
* @return string |
| 365 |
*/ |
| 366 |
private function get_row_classes( $atts ) { |
| 367 |
$class = 'column-' . $atts['column_name']; |
| 368 |
|
| 369 |
if ( in_array( $atts['column_name'], $atts['hidden'], true ) ) { |
| 370 |
$class .= ' frm_hidden'; |
| 371 |
} |
| 372 |
|
| 373 |
return 'class="' . esc_attr( $class ) . '"'; |
| 374 |
} |
| 375 |
|
| 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 |
* |
| 382 |
* @param object $item |
| 383 |
* |
| 384 |
* @return string |
| 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 |
*/ |
| 395 |
private function get_receipt_id_column( $item ) { |
| 396 |
return $this->get_action_column( $item, 'receipt_id' ); |
| 397 |
} |
| 398 |
|
| 399 |
/** |
| 400 |
* @param object $item |
| 401 |
* @param string $field |
| 402 |
* |
| 403 |
* @return string |
| 404 |
*/ |
| 405 |
private function get_action_column( $item, $field ) { |
| 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( |
| 435 |
array( |
| 436 |
'action' => $action, |
| 437 |
'id' => $payment_id, |
| 438 |
'type' => $this->table, |
| 439 |
'page' => FrmAppHelper::simple_get( 'page' ), |
| 440 |
), |
| 441 |
admin_url( 'admin.php' ) |
| 442 |
); |
| 443 |
} |
| 444 |
|
| 445 |
/** |
| 446 |
* @param object $item |
| 447 |
* |
| 448 |
* @return array |
| 449 |
*/ |
| 450 |
private function get_row_actions( $item ) { |
| 451 |
$base_link = '?page=formidable-payments&action='; |
| 452 |
$view_link = $base_link . 'show&id=' . $item->id . '&type=' . $this->table; |
| 453 |
$delete_link = $base_link . 'destroy&id=' . $item->id . '&type=' . $this->table; |
| 454 |
|
| 455 |
$actions = array(); |
| 456 |
$actions['view'] = '<a href="' . esc_url( $view_link ) . '">' . esc_html__( 'View', 'formidable' ) . '</a>'; |
| 457 |
|
| 458 |
if ( $this->supports_edit_link() ) { |
| 459 |
$edit_link = $base_link . 'edit&id=' . $item->id; |
| 460 |
$actions['edit'] = '<a href="' . esc_url( $edit_link ) . '">' . esc_html__( 'Edit', 'formidable' ) . '</a>'; |
| 461 |
} |
| 462 |
|
| 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 |
| 464 |
|
| 465 |
return $actions; |
| 466 |
} |
| 467 |
|
| 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 |
/** |
| 482 |
* Get the column value for displaying an entry ID. |
| 483 |
* |
| 484 |
* @param object $item A payment or subscription object. |
| 485 |
* |
| 486 |
* @return string |
| 487 |
*/ |
| 488 |
private function get_item_id_column( $item ) { |
| 489 |
$entry_id = (int) $item->item_id; |
| 490 |
// phpcs:ignore WordPress.PHP.StrictInArray.MissingTrueStrict |
| 491 |
$entry_is_deleted = ! in_array( $entry_id, $this->valid_entry_ids ); |
| 492 |
|
| 493 |
if ( $entry_is_deleted ) { |
| 494 |
// translators: %d: ID of the deleted entry. |
| 495 |
return sprintf( __( '%d (Deleted)', 'formidable' ), $entry_id ); |
| 496 |
} |
| 497 |
|
| 498 |
return '<a href="' . esc_url( '?page=formidable-entries&frm_action=show&action=show&id=' . $entry_id ) . '">' . absint( $entry_id ) . '</a>'; |
| 499 |
} |
| 500 |
|
| 501 |
/** |
| 502 |
* @param object $item |
| 503 |
* @param array $atts |
| 504 |
* |
| 505 |
* @return mixed |
| 506 |
*/ |
| 507 |
private function get_form_id_column( $item, $atts ) { |
| 508 |
if ( isset( $atts['form_ids'][ $item->item_id ] ) ) { |
| 509 |
return FrmFormsHelper::edit_form_link( $atts['form_ids'][ $item->item_id ]->form_id ); |
| 510 |
} |
| 511 |
|
| 512 |
return ''; |
| 513 |
} |
| 514 |
|
| 515 |
/** |
| 516 |
* @param object $item |
| 517 |
* |
| 518 |
* @return string |
| 519 |
*/ |
| 520 |
private function get_user_id_column( $item ) { |
| 521 |
$val = FrmDb::get_var( 'frm_items', array( 'id' => $item->item_id ), 'user_id' ); |
| 522 |
return FrmTransLiteAppHelper::get_user_link( $val ); |
| 523 |
} |
| 524 |
|
| 525 |
/** |
| 526 |
* @param object $item |
| 527 |
* @param array $atts |
| 528 |
* |
| 529 |
* @return string |
| 530 |
*/ |
| 531 |
private function get_created_at_column( $item, $atts ) { |
| 532 |
if ( empty( $item->created_at ) || $item->created_at === '0000-00-00 00:00:00' ) { |
| 533 |
return ''; |
| 534 |
} |
| 535 |
|
| 536 |
$date = FrmAppHelper::get_localized_date( $atts['date_format'], $item->created_at ); |
| 537 |
$date_title = FrmAppHelper::get_localized_date( $atts['date_format'] . ' g:i:s A', $item->created_at ); |
| 538 |
return '<abbr title="' . esc_attr( $date_title ) . '">' . $date . '</abbr>'; |
| 539 |
} |
| 540 |
|
| 541 |
/** |
| 542 |
* @param object $item |
| 543 |
* |
| 544 |
* @return string |
| 545 |
*/ |
| 546 |
private function get_amount_column( $item ) { |
| 547 |
if ( $this->table === 'subscriptions' ) { |
| 548 |
return FrmTransLiteAppHelper::format_billing_cycle( $item ); |
| 549 |
} |
| 550 |
return FrmTransLiteAppHelper::formatted_amount( $item ); |
| 551 |
} |
| 552 |
|
| 553 |
/** |
| 554 |
* @param object $item |
| 555 |
* |
| 556 |
* @return string |
| 557 |
*/ |
| 558 |
private function get_end_count_column( $item ) { |
| 559 |
$limit = $item->end_count >= 9999 ? __( 'unlimited', 'formidable' ) : $item->end_count; |
| 560 |
$frm_payment = new FrmTransLitePayment(); |
| 561 |
$completed_payments = $frm_payment->get_all_by( $item->id, 'sub_id' ); |
| 562 |
$count = FrmTransLiteAppHelper::count_completed_payments( $completed_payments ); |
| 563 |
|
| 564 |
// translators: %1$s: Count, %2$s: Limit. |
| 565 |
return sprintf( __( '%1$s of %2$s', 'formidable' ), $count, $limit ); |
| 566 |
} |
| 567 |
|
| 568 |
/** |
| 569 |
* @param object $item |
| 570 |
* |
| 571 |
* @return string |
| 572 |
*/ |
| 573 |
private function get_status_column( $item ) { |
| 574 |
$status = esc_html( FrmTransLiteAppHelper::show_status( FrmTransLiteAppHelper::get_payment_status( $item ) ) ); |
| 575 |
|
| 576 |
if ( 'processing' === ( $item->status ?? '' ) ) { |
| 577 |
$status .= $this->get_processing_tooltip(); |
| 578 |
} |
| 579 |
|
| 580 |
return $status; |
| 581 |
} |
| 582 |
|
| 583 |
/** |
| 584 |
* @since 6.5, introduced in v2.04 of the Payments submodule. |
| 585 |
* |
| 586 |
* @return string |
| 587 |
*/ |
| 588 |
private function get_processing_tooltip() { |
| 589 |
return FrmAppHelper::clip( |
| 590 |
function () { |
| 591 |
FrmAppHelper::tooltip_icon( __( 'This payment method may take between 4-5 business days to process.', 'formidable' ) ); |
| 592 |
} |
| 593 |
); |
| 594 |
} |
| 595 |
|
| 596 |
/** |
| 597 |
* @param object $item |
| 598 |
* |
| 599 |
* @return string |
| 600 |
*/ |
| 601 |
private function get_sub_id_column( $item ) { |
| 602 |
if ( empty( $item->sub_id ) ) { |
| 603 |
return ''; |
| 604 |
} |
| 605 |
|
| 606 |
if ( $this->table === 'subscriptions' ) { |
| 607 |
return $this->get_action_column( $item, 'sub_id' ); |
| 608 |
} |
| 609 |
|
| 610 |
return '<a href="' . esc_url( '?page=formidable-payments&action=show&type=subscriptions&id=' . $item->sub_id ) . '">' . $item->sub_id . '</a>'; |
| 611 |
} |
| 612 |
|
| 613 |
/** |
| 614 |
* Get the string for the "Processor" column. |
| 615 |
* Convert the supported pay systems to their proper case. |
| 616 |
* |
| 617 |
* @param object $item |
| 618 |
* @param array $atts |
| 619 |
* |
| 620 |
* @return string |
| 621 |
*/ |
| 622 |
private function get_paysys_column( $item, $atts ) { |
| 623 |
if ( isset( $atts['gateways'][ $item->paysys ] ) ) { |
| 624 |
return $atts['gateways'][ $item->paysys ]['label']; |
| 625 |
} |
| 626 |
|
| 627 |
return $item->paysys; |
| 628 |
} |
| 629 |
|
| 630 |
/** |
| 631 |
* Display 'Test' or 'Live' in a mode column if the value is known. |
| 632 |
* Old payment entries will have a NULL 'test' column value. |
| 633 |
* |
| 634 |
* @since 6.6 |
| 635 |
* |
| 636 |
* @param stdClass $item Payment or Subscription object. |
| 637 |
* |
| 638 |
* @return string |
| 639 |
*/ |
| 640 |
private function get_mode_column( $item ) { |
| 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'; |
| 660 |
} |
| 661 |
} |
| 662 |
|