| 1 |
<?php |
| 2 |
|
| 3 |
namespace Better_Payment\Lite\Campaign; |
| 4 |
|
| 5 |
use Better_Payment\Lite\Campaign\Support\Money; |
| 6 |
|
| 7 |
use Better_Payment\Lite\Controller; |
| 8 |
|
| 9 |
if ( ! defined( 'ABSPATH' ) ) { |
| 10 |
exit; |
| 11 |
} |
| 12 |
|
| 13 |
/** |
| 14 |
* Adds "Stats" and "Edit in Builder" columns to the bp_campaign post list table. |
| 15 |
*/ |
| 16 |
class CampaignListColumns extends Controller { |
| 17 |
|
| 18 |
public function add_columns( array $columns ): array { |
| 19 |
// Insert stats column before the date column |
| 20 |
$date = $columns['date'] ?? null; |
| 21 |
unset( $columns['date'] ); |
| 22 |
|
| 23 |
$columns['campaign_stats'] = __( 'Campaign Stats', 'better-payment' ); |
| 24 |
$columns['campaign_builder'] = __( 'Builder', 'better-payment' ); |
| 25 |
|
| 26 |
if ( $date ) { |
| 27 |
$columns['date'] = $date; |
| 28 |
} |
| 29 |
|
| 30 |
return $columns; |
| 31 |
} |
| 32 |
|
| 33 |
public function render_column( string $column, int $post_id ) { |
| 34 |
if ( $column === 'campaign_stats' ) { |
| 35 |
$stats = CampaignStats::get_stats( $post_id ); |
| 36 |
$meta = MetaBox::get_all( $post_id ); |
| 37 |
$goal = (float) ( $meta['bpc_goal_amount'] ?? 0 ); |
| 38 |
$currency = $meta['bpc_currency'] ?? 'USD'; |
| 39 |
$raised = $stats['total_raised']; |
| 40 |
$progress = $stats['progress']; |
| 41 |
|
| 42 |
printf( |
| 43 |
'<strong>%s %s</strong> raised<br><small>%d donors | %d%%</small>', |
| 44 |
esc_html( $currency ), |
| 45 |
esc_html( Money::format( $raised ) ), |
| 46 |
(int) $stats['donor_count'], |
| 47 |
(int) $progress |
| 48 |
); |
| 49 |
|
| 50 |
if ( $goal > 0 ) { |
| 51 |
printf( '<br><small>of %s %s goal</small>', esc_html( $currency ), esc_html( Money::format( $goal ) ) ); |
| 52 |
} |
| 53 |
} |
| 54 |
|
| 55 |
if ( $column === 'campaign_builder' ) { |
| 56 |
$url = admin_url( 'admin.php?page=bp-campaign-builder&campaign_id=' . $post_id ); |
| 57 |
printf( |
| 58 |
'<a href="%s" class="button button-small">%s</a>', |
| 59 |
esc_url( $url ), |
| 60 |
esc_html__( 'Open Builder', 'better-payment' ) |
| 61 |
); |
| 62 |
} |
| 63 |
} |
| 64 |
} |
| 65 |
|