Icon.tsx
1 year ago
app.tsx
1 year ago
block.json
1 year ago
edit.tsx
1 year ago
index.tsx
1 year ago
render.php
1 year ago
styles.scss
1 year ago
render.php
45 lines
| 1 | <?php |
| 2 | |
| 3 | use Give\Campaigns\CampaignDonationQuery; |
| 4 | use Give\Campaigns\Models\Campaign; |
| 5 | use Give\Campaigns\Repositories\CampaignRepository; |
| 6 | use Give\Donations\ValueObjects\DonationMetaKeys; |
| 7 | use Give\Framework\Support\ValueObjects\Money; |
| 8 | |
| 9 | /** |
| 10 | * @since 4.0.0 |
| 11 | * |
| 12 | * @var array $attributes |
| 13 | * @var Campaign $campaign |
| 14 | */ |
| 15 | |
| 16 | if ( |
| 17 | !isset($attributes['campaignId']) |
| 18 | || !$campaign = give(CampaignRepository::class)->getById($attributes['campaignId']) |
| 19 | ) { |
| 20 | return; |
| 21 | } |
| 22 | |
| 23 | $query = (new CampaignDonationQuery($campaign)) |
| 24 | ->select( |
| 25 | $attributes['statistic'] === 'top-donation' |
| 26 | ? 'MAX(amountMeta.meta_value - IFNULL(feeAmountRecovered.meta_value, 0)) as amount' |
| 27 | : 'AVG(amountMeta.meta_value - IFNULL(feeAmountRecovered.meta_value, 0)) as amount' |
| 28 | ) |
| 29 | ->joinDonationMeta(DonationMetaKeys::AMOUNT, 'amountMeta') |
| 30 | ->joinDonationMeta(DonationMetaKeys::FEE_AMOUNT_RECOVERED, 'feeAmountRecovered'); |
| 31 | |
| 32 | $donationStat = $query->get(); |
| 33 | |
| 34 | $amount = $donationStat && $donationStat->amount |
| 35 | ? Money::fromDecimal($donationStat->amount, give_get_currency()) |
| 36 | : Money::fromDecimal(0, give_get_currency()); |
| 37 | |
| 38 | $title = $attributes['statistic'] === 'top-donation' ? __('Top Donation', 'give') : __('Average Donation', 'give'); |
| 39 | ?> |
| 40 | |
| 41 | <div <?= get_block_wrapper_attributes(['class' => 'givewp-campaign-stats-block']) ?>> |
| 42 | <span><?php echo $title ?></span> |
| 43 | <strong><?php echo esc_html($amount->formatToLocale()) ?></strong> |
| 44 | </div> |
| 45 |