Tiered goals: ordered milestones with unlocks, tier-aware goal bar, TIER UNLOCKED alerts, next-unlock line
- Tiers\TierPolicy (pure), TierRepository (atomic reached marking), Tiers\Recorder hooked before close-at-target - Admin tiers screen; goal target derived from the final tier - Overlay goal widget shows Tier N of M and fills within the tier; alert pill; donate form 'Next unlock' - Installer DB_VERSION 4 (sg_goal_tiers) Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
39840a20d7
commit
4c379a0245
20 files changed
+1089
-14
No files matched your search
@@ -162,7 +162,8 @@ final class DonateController {
|
||||
if ( $pinned && (int) $g['id'] !== $pinned ) {
|
||||
continue;
|
||||
}
|
||||
$goals[] = array(
|
||||
$next = self::next_unlock( $g );
|
||||
$goals[] = ( null === $next ? array() : array( 'nextUnlock' => $next ) ) + array(
|
||||
'id' => (int) $g['id'],
|
||||
'title' => (string) $g['title'],
|
||||
'currency' => strtoupper( (string) $g['currency'] ),
|
||||
@@ -206,6 +207,8 @@ final class DonateController {
|
||||
'customPlaceholder' => __( 'Other amount', 'streamgoals-donate' ),
|
||||
/* translators: %s: formatted amount, e.g. $5.00 */
|
||||
'everyLabel' => __( 'Every %s', 'streamgoals-donate' ),
|
||||
/* translators: 1: item/unlock title, 2: formatted amount still needed, e.g. $106.00 */
|
||||
'nextUnlock' => __( 'Next unlock: %1$s — %2$s to go', 'streamgoals-donate' ),
|
||||
'actionsHint' => __( 'Pick a reward, or enter your own amount below.', 'streamgoals-donate' ),
|
||||
/* translators: %s: formatted minimum amount, e.g. $1.00 */
|
||||
'minHint' => __( 'Minimum donation: %s', 'streamgoals-donate' ),
|
||||
@@ -222,6 +225,27 @@ final class DonateController {
|
||||
|
||||
/* ------------------------------------------------------------- Helpers */
|
||||
|
||||
/**
|
||||
* "Next unlock" hint for a tiered goal: the current (first unreached) tier's title and the amount still needed, in minor units.
|
||||
* Null for goals without tiers or with every tier reached. Computed when the page renders.
|
||||
*
|
||||
* @return array{title:string,remaining_minor:int}|null
|
||||
*/
|
||||
private static function next_unlock( array $goal ): ?array {
|
||||
try {
|
||||
global $wpdb;
|
||||
$tiers = ( new \StreamGoals\Tiers\TierRepository( $wpdb ) )->forGoal( (int) $goal['id'] );
|
||||
$cur = $tiers ? \StreamGoals\Tiers\TierPolicy::currentTier( $tiers ) : null;
|
||||
if ( null === $cur ) {
|
||||
return null;
|
||||
}
|
||||
$raised = ( new \StreamGoals\Core\GoalRepository( $wpdb ) )->raised_minor( (int) $goal['id'] );
|
||||
return array( 'title' => (string) $cur['title'], 'remaining_minor' => max( 1, (int) $cur['target_minor'] - $raised ) );
|
||||
} catch ( \Throwable $e ) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Enabled actions per goal id (rows with goal_id 0 apply to every goal), at or above the effective minimum.
|
||||
* Public-safe fields only. One query; reads sg_actions directly.
|
||||
|
||||
Reference in new issue
Block a user