Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: Campaign Goal Block #7702

Merged
merged 32 commits into from
Feb 14, 2025
Merged
Changes from 1 commit
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
f7b29b7
initial commit
alaca Jan 22, 2025
9c6d894
feature: render block
alaca Jan 23, 2025
088e26e
feature: add icon and btn
alaca Jan 23, 2025
673c59d
feature: add description and hide select component if default form is…
alaca Jan 23, 2025
76ead3f
chore: add unreleased tags
alaca Jan 23, 2025
572a377
refactor: move campaign forms fetching logic outside the useCampaign …
alaca Jan 29, 2025
f66d535
initial commit
alaca Jan 30, 2025
298b35b
refactor: remove unused attributes
alaca Jan 30, 2025
9385381
feature: add helper functions for displaying goal values and description
alaca Jan 30, 2025
7f1a040
refactor: add goalStats prop
alaca Jan 30, 2025
6859f65
refactor: use CampaignGoalData instead of CampaignDonationQuery for g…
alaca Jan 30, 2025
86ee2a8
refactor: use the new goalStats prop
alaca Jan 30, 2025
5034344
feature: add goalStats props
alaca Jan 30, 2025
069c39d
feature: render block
alaca Jan 31, 2025
15f0721
fix: missing campaign goal stats
alaca Feb 3, 2025
92e51e3
Merge branch 'refs/heads/epic/campaigns' into feature/campaign-goal-b…
alaca Feb 3, 2025
ca7d6c9
feature: add text control with goal description
alaca Feb 3, 2025
0c163b7
refactor: fix undefined campaign goalStats; use campaign method to ge…
alaca Feb 3, 2025
3a49194
Merge branch 'refs/heads/epic/campaigns' into feature/campaign-goal-b…
alaca Feb 3, 2025
e2cd894
feature: set language using navigator object
alaca Feb 3, 2025
0926bad
refactor: render block using ssr
alaca Feb 3, 2025
9b59101
Merge branch 'refs/heads/epic/campaigns' into feature/campaign-goal-b…
alaca Feb 7, 2025
04cbdd1
refactor: block settings
alaca Feb 7, 2025
4754280
refactor: everything
alaca Feb 10, 2025
0c409e5
refactor: remove leftover
alaca Feb 11, 2025
c88ad97
feature: format currency
alaca Feb 11, 2025
b1b67c0
refactor: load campaign options on both admin and frontend
alaca Feb 11, 2025
455de2a
Merge branch 'epic/campaigns' into feature/campaign-goal-block-GIVE-1510
jonwaldstein Feb 13, 2025
da65f7d
refactor: getCampaignDetailsWindowData
alaca Feb 14, 2025
eca6853
refactor: remove leftover
alaca Feb 14, 2025
b85d99b
refactor: use data attribute instead of class
alaca Feb 14, 2025
376eba2
refactor: use givewp instead of give
alaca Feb 14, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
feature: render block
alaca committed Jan 31, 2025
commit 069c39d230bff31d2d24571c2c49c7ee13e99e15
61 changes: 52 additions & 9 deletions src/Campaigns/Blocks/CampaignGoal/render.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
<?php

use Give\Campaigns\DataTransferObjects\CampaignGoalData;
use Give\Campaigns\Models\Campaign;
use Give\Campaigns\Repositories\CampaignRepository;
use Give\DonationForms\Blocks\DonationFormBlock\Controllers\BlockRenderController;
use Give\Campaigns\ValueObjects\CampaignGoalType;
use Give\Framework\Support\ValueObjects\Money;

/**
* @var array $attributes
@@ -16,12 +18,53 @@
return;
}

$params = [
'formId' => $attributes['useDefaultForm']
? $campaign->defaultFormId
: $attributes['selectedForm'],
'openFormButton' => $attributes['buttonText'],
'formFormat' => 'modal',
];
$stats = (new CampaignGoalData($campaign))->toArray();

$getGoalDescription = function(CampaignGoalType $goalType) {
$data = [
'amount' => __('Amount raised', 'give'),
'donations' => __('Number of donations', 'give'),
'donors' => __('Number of donors', 'give'),
'amountFromSubscriptions' => __('Recurring amount raised', 'give'),
'subscriptions' => __('Number of recurring donations', 'give'),
'donorsFromSubscriptions' => __('Number of recurring donors', 'give'),
];

return $data[$goalType->getvalue()];
};

$getGoalFormattedValue = function($goalType, $value) {
switch ($goalType) {
case 'amount':
case 'amountFromSubscriptions':
$amount = Money::fromDecimal($value, give_get_currency());
return $amount->formatToLocale();
default:
return $value;
}
};

?>

<div class="give-campaign-goal">
<div class="give-campaign-goal__container">
<div class="give-campaign-goal__container-item">
<span><?= $getGoalDescription($campaign->goalType); ?></span>
<strong>
<?= $getGoalFormattedValue($campaign->goalType, $stats['actual']); ?>
</strong>
</div>
<div class="give-campaign-goal__container-item">
<span><?= esc_html__('Our goal', 'give'); ?></span>
<strong><?= $getGoalFormattedValue($campaign->goalType, $campaign->goal); ?></strong>
</div>
</div>
<div class="give-campaign-goal__progress-bar">
<div class="give-campaign-goal__progress-bar-container">
<div class="give-campaign-goal__progress-bar-progress"
style="width: <?= $stats['percentage']; ?>%">
</div>
</div>
</div>
</div>

echo (new BlockRenderController())->render($params);