| 1 |
<?php |
| 2 |
|
| 3 |
/** |
| 4 |
* @var int $formId |
| 5 |
*/ |
| 6 |
|
| 7 |
use Give\DonationForms\DonationQuery; |
| 8 |
use Give\MultiFormGoals\ProgressBar\Model as ProgressBarModal; |
| 9 |
|
| 10 |
/** |
| 11 |
* @since 3.14.0 Use sumIntendedAmount() and getDonationCount() methods to retrieve the proper values for the raised amount and donations count |
| 12 |
*/ |
| 13 |
if ($form->has_goal()) : ?> |
| 14 |
<?php |
| 15 |
$goalStats = give_goal_progress_stats($formId); |
| 16 |
|
| 17 |
// Setup default raised value |
| 18 |
$raised = give_currency_filter( |
| 19 |
give_format_amount( |
| 20 |
(new DonationQuery())->form($formId)->sumIntendedAmount(), |
| 21 |
[ |
| 22 |
'sanitize' => false, |
| 23 |
'decimal' => false, |
| 24 |
] |
| 25 |
) |
| 26 |
); |
| 27 |
|
| 28 |
// Setup default count value |
| 29 |
$count = (new ProgressBarModal(['ids' => [$formId]]))->getDonationCount();; |
| 30 |
|
| 31 |
// Setup default count label |
| 32 |
$countLabel = _n('donation', 'donations', $count, 'give'); |
| 33 |
|
| 34 |
// Setup default goal value |
| 35 |
$goal = give_currency_filter( |
| 36 |
give_format_amount( |
| 37 |
$form->get_goal(), |
| 38 |
[ |
| 39 |
'sanitize' => false, |
| 40 |
'decimal' => false, |
| 41 |
] |
| 42 |
) |
| 43 |
); |
| 44 |
|
| 45 |
// Change values and labels based on goal format |
| 46 |
switch ($goalStats['format']) { |
| 47 |
case 'percentage': |
| 48 |
{ |
| 49 |
$raised = "{$goalStats['progress']}%"; |
| 50 |
break; |
| 51 |
} |
| 52 |
case 'donation': |
| 53 |
{ |
| 54 |
$count = $goalStats['actual']; |
| 55 |
$goal = $goalStats['goal']; |
| 56 |
break; |
| 57 |
} |
| 58 |
case 'donors': |
| 59 |
{ |
| 60 |
$count = $goalStats['actual']; |
| 61 |
$countLabel = _n('donor', 'donors', $count, 'give'); |
| 62 |
$goal = $goalStats['goal']; |
| 63 |
break; |
| 64 |
} |
| 65 |
} |
| 66 |
?> |
| 67 |
<div class="income-stats"> |
| 68 |
<div class="raised"> |
| 69 |
<div class="number"> |
| 70 |
<?php |
| 71 |
echo $raised; ?> |
| 72 |
</div> |
| 73 |
<div class="text"><?php |
| 74 |
_e('raised', 'give'); ?></div> |
| 75 |
</div> |
| 76 |
<div class="count"> |
| 77 |
<div class="number"> |
| 78 |
<?php |
| 79 |
echo $count; ?> |
| 80 |
</div> |
| 81 |
<div class="text"><?php |
| 82 |
echo $countLabel; ?></div> |
| 83 |
</div> |
| 84 |
<div class="goal"> |
| 85 |
<div class="number"> |
| 86 |
<?php |
| 87 |
echo $goal; ?> |
| 88 |
</div> |
| 89 |
<div class="text"><?php |
| 90 |
_e('goal', 'give'); ?></div> |
| 91 |
</div> |
| 92 |
</div> |
| 93 |
<?php |
| 94 |
endif; ?> |
| 95 |
|