| 1 |
<?php |
| 2 |
/** |
| 3 |
* Display the donations widget on the dashboard. |
| 4 |
* |
| 5 |
* @author Studio 164a |
| 6 |
* @package Charitable/Admin View/Dashboard Widgets |
| 7 |
* @since 1.2.0 |
| 8 |
*/ |
| 9 |
|
| 10 |
$statuses = charitable_get_valid_donation_statuses(); |
| 11 |
|
| 12 |
$donations = get_posts( array( |
| 13 |
'post_type' => Charitable::DONATION_POST_TYPE, |
| 14 |
'posts_per_page' => 5, |
| 15 |
'post_status' => array_keys( $statuses ), |
| 16 |
'fields' => 'ids', |
| 17 |
) ); |
| 18 |
|
| 19 |
$table = charitable_get_table( 'campaign_donations' ); |
| 20 |
|
| 21 |
$today = $table->get_donations_summary_by_period( date( 'Y-m-d%' ) ); |
| 22 |
$this_month = $table->get_donations_summary_by_period( date( 'Y-m%' ) ); |
| 23 |
$last_month = $table->get_donations_summary_by_period( date( 'Y-m%', strtotime( '-1 month' ) ) ); |
| 24 |
$this_year = $table->get_donations_summary_by_period( date( 'Y-%' ) ); |
| 25 |
|
| 26 |
?> |
| 27 |
<div class="charitable-donation-statistics"> |
| 28 |
<div class="cell"> |
| 29 |
<h3 class="amount"> |
| 30 |
<?php echo charitable_format_money( $today->amount ); ?> |
| 31 |
</h3> |
| 32 |
<p class="summary"> |
| 33 |
<?php |
| 34 |
printf( |
| 35 |
/* translators: %d: number of donations */ |
| 36 |
_n( '%d donation <span class="time-period">today</span>', '%d donations <span class="time-period">today</span>', $today->count, 'charitable' ), |
| 37 |
$today->count |
| 38 |
); |
| 39 |
?> |
| 40 |
</p> |
| 41 |
</div> |
| 42 |
<div class="cell"> |
| 43 |
<h3 class="amount"> |
| 44 |
<?php echo charitable_format_money( $this_month->amount ); ?> |
| 45 |
</h3> |
| 46 |
<p class="summary"> |
| 47 |
<?php |
| 48 |
printf( |
| 49 |
/* translators: %d: number of donations */ |
| 50 |
_n( '%d donation <span class="time-period">this month</span>', '%d donations <span class="time-period">this month</span>', $this_month->count, 'charitable' ), |
| 51 |
$this_month->count |
| 52 |
); |
| 53 |
?> |
| 54 |
</p> |
| 55 |
</div> |
| 56 |
<div class="cell"> |
| 57 |
<h3 class="amount"> |
| 58 |
<?php echo charitable_format_money( $last_month->amount ); ?> |
| 59 |
</h3> |
| 60 |
<p class="summary"> |
| 61 |
<?php |
| 62 |
printf( |
| 63 |
/* translators: %d: number of donations */ |
| 64 |
_n( '%d donation <span class="time-period">last month</span>', '%d donations <span class="time-period">last month</span>', $last_month->count, 'charitable' ), |
| 65 |
$last_month->count |
| 66 |
); |
| 67 |
?> |
| 68 |
</p> |
| 69 |
</div> |
| 70 |
<div class="cell"> |
| 71 |
<h3 class="amount"> |
| 72 |
<?php echo charitable_format_money( $this_year->amount ); ?> |
| 73 |
</h3> |
| 74 |
<p class="summary"> |
| 75 |
<?php |
| 76 |
printf( |
| 77 |
/* translators: %d: number of donations */ |
| 78 |
_n( '%d donation <span class="time-period">this year</span>', '%d donations <span class="time-period">this year</span>', $this_year->count, 'charitable' ), |
| 79 |
$this_year->count |
| 80 |
); |
| 81 |
?> |
| 82 |
</p> |
| 83 |
</div> |
| 84 |
</div> |
| 85 |
<?php if ( count( $donations ) ) : ?> |
| 86 |
<div class="recent-donations"> |
| 87 |
<table> |
| 88 |
<caption><h3><?php _e( 'Recent Donations', 'charitable' ); ?></h3></caption> |
| 89 |
<?php |
| 90 |
foreach ( $donations as $donation_id ) : |
| 91 |
$donation = charitable_get_donation( $donation_id ); |
| 92 |
?> |
| 93 |
<tr> |
| 94 |
<td class="donation-date"><?php echo $donation->get_date(); ?></td> |
| 95 |
<td class="donation-id">#<?php echo $donation->get_number(); ?></td> |
| 96 |
<td class="donation-status"><?php echo $donation->get_status_label(); ?></td> |
| 97 |
<td class="donation-total"><?php echo charitable_format_money( $donation->get_total_donation_amount() ); ?></td> |
| 98 |
</tr> |
| 99 |
<?php |
| 100 |
endforeach; |
| 101 |
?> |
| 102 |
</table> |
| 103 |
</div> |
| 104 |
<?php endif ?> |
| 105 |
|