Files
shadowdaoandClaude Sonnet 5.5 5ea1e1d273
Test and Release / test (push) Successful in 1m14s
Test and Release / release (push) Successful in 4s
End-at-target goals (auto-close when target reached) and fit-to-window rewards menu overlay
- Core\GoalTargetPolicy; atomic close in the capture path; friendly 'goal reached' message
- In-flight checkouts still capture; new orders for a closed goal are refused
- Rewards menu overlay: card hugs content, text scales to the window, resize-aware, scroll only as a last resort

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-15 12:53:07 -08:00

35 lines
1.3 KiB
PHP

<?php
declare( strict_types=1 );
namespace StreamGoals\Core;
/** Pure rules for "end at target" goals (no WordPress / database access). */
final class GoalTargetPolicy {
/** Donation column summed towards the goal: total (fees included) or base. Whitelisted values only. */
public static function amountColumn( array $goal ): string {
return ! empty( $goal['counts_fees'] ) ? 'total_minor' : 'base_minor';
}
/** True when the goal should now be auto-closed: flag on, currently active, target set and reached or exceeded. */
public static function shouldClose( array $goal, int $raisedMinor ): bool {
return ! empty( $goal['close_at_target'] )
&& 'active' === ( $goal['status'] ?? '' )
&& (int) ( $goal['target_minor'] ?? 0 ) > 0
&& $raisedMinor >= (int) $goal['target_minor'];
}
/** True for a goal that is closed to donors because it reached its target (flag on + complete). */
public static function isClosedAtTarget( array $goal ): bool {
return ! empty( $goal['close_at_target'] ) && 'complete' === ( $goal['status'] ?? '' );
}
/** Checkbox value from a raw form field: 1 when ticked, else 0. */
public static function flagFromPost( mixed $raw ): int {
if ( is_array( $raw ) || null === $raw ) {
return 0;
}
return in_array( strtolower( trim( (string) $raw ) ), array( '1', 'on', 'true', 'yes' ), true ) ? 1 : 0;
}
}