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
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
declare( strict_types=1 );
|
||||
|
||||
namespace StreamGoals\Tiers;
|
||||
|
||||
/** Unlocks the tiers a completed donation reaches. Runs BEFORE the "end at target" check. */
|
||||
final class Recorder {
|
||||
|
||||
/**
|
||||
* Never throws. Idempotent (atomic UPDATE ... WHERE reached_at IS NULL per tier). Test donations (goal_id 0) are skipped.
|
||||
*
|
||||
* @return int[] ids of the tiers this call unlocked.
|
||||
*/
|
||||
public static function forDonation( int $donationId ): array {
|
||||
try {
|
||||
global $wpdb;
|
||||
$row = $wpdb->get_row( $wpdb->prepare( 'SELECT id, goal_id, status FROM ' . $wpdb->prefix . 'sg_donations WHERE id = %d', $donationId ), ARRAY_A );
|
||||
if ( ! is_array( $row ) || 'completed' !== ( $row['status'] ?? '' ) || (int) $row['goal_id'] <= 0 ) {
|
||||
return array();
|
||||
}
|
||||
$goalId = (int) $row['goal_id'];
|
||||
$repo = new TierRepository( $wpdb );
|
||||
if ( ! $repo->forGoal( $goalId ) ) {
|
||||
return array();
|
||||
}
|
||||
$raised = ( new \StreamGoals\Core\GoalRepository( $wpdb ) )->raised_minor( $goalId );
|
||||
return $repo->markReached( $goalId, $raised, $donationId );
|
||||
} catch ( \Throwable $e ) {
|
||||
error_log( 'StreamGoals: tier unlock failed for donation ' . $donationId . ': ' . $e->getMessage() ); // phpcs:ignore WordPress.PHP.DevelopmentFunctions
|
||||
return array();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user