Skip to content

Commit

Permalink
Refactor: check if the form goal is enabled before calling the goal s…
Browse files Browse the repository at this point in the history
…tats function in the GetAsyncFormDataForListView class (#7676)
  • Loading branch information
glaubersilva authored Jan 28, 2025
1 parent 6a9d676 commit 87537cc
Showing 1 changed file with 17 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,16 @@
use Give\DonationForms\AsyncData\AdminFormListView\AdminFormListViewOptions;
use Give\DonationForms\AsyncData\AsyncDataHelpers;
use Give\DonationForms\AsyncData\FormGrid\FormGridViewOptions;
use Give\DonationForms\Models\DonationForm;
use Give\DonationForms\V2\ValueObjects\DonationFormMetaKeys;

/**
* @since 3.16.0
*/
class GetAsyncFormDataForListView
{
/**
* @unreleased Check if form goal is enabled
* @since 3.16.0
*/
public function __invoke()
Expand Down Expand Up @@ -43,7 +46,7 @@ public function __invoke()

$amountRaised = 0;
$percentComplete = 0;
if ($this->isAsyncProgressBar()) {
if ($this->isAsyncProgressBar() && $this->isFormGoalEnabled($formId)) {
$goalStats = give_goal_progress_stats($formId);
$amountRaised = $goalStats['actual'];
$percentComplete = ('percentage' === $goalStats['format']) ? str_replace('%', '',
Expand Down Expand Up @@ -96,4 +99,17 @@ private function isAsyncRevenue(): bool
{
return AdminFormListViewOptions::isRevenueColumnAsync();
}

/**
* @unreleased
*/
private function isFormGoalEnabled(int $formId): bool
{
if ($donationForm = DonationForm::find($formId)) {
return $donationForm->settings->enableDonationGoal;
}

return give_is_setting_enabled(Give()->form_meta->get_meta($formId,
DonationFormMetaKeys::GOAL_OPTION()->getKeyAsCamelCase(), true));
}
}

0 comments on commit 87537cc

Please sign in to comment.