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>
This commit is contained in:
1 parent
1c6d93ad5f
commit
5ea1e1d273
9 files changed
+216
-19
No files matched your search
@@ -0,0 +1,34 @@
|
||||
<?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;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user