2026-11-15 10:26:03 -08:00
|
|
|
<?php
|
|
|
|
|
declare( strict_types=1 );
|
|
|
|
|
|
|
|
|
|
namespace StreamGoals\Admin;
|
|
|
|
|
|
|
|
|
|
use StreamGoals\Core\Money;
|
|
|
|
|
|
|
|
|
|
/** Pure goal templates used by the setup wizard. */
|
|
|
|
|
final class Templates {
|
|
|
|
|
|
|
|
|
|
public const LABELS = array(
|
|
|
|
|
'simple' => array( 'Simple goal', 'A progress bar towards a fundraising target. Nothing else.' ),
|
|
|
|
|
'subathon' => array( 'Subathon timer: +1 min per $1', 'A countdown that gets longer with every donation (1 minute added for every $1).' ),
|
|
|
|
|
'counter' => array( 'Counter: +1 per $10', 'A counter that goes up by 1 for every $10 donated (for example "pies thrown").' ),
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
public static function exists( string $key ): bool {
|
|
|
|
|
return isset( self::LABELS[ $key ] );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @return array{goal:array,rules:array<int,array{type:string,config:array}>}
|
|
|
|
|
*/
|
|
|
|
|
public static function build( string $key, string $currency, int $targetMinor, string $title = '' ): array {
|
|
|
|
|
$one = 10 ** Money::exponent( $currency ); // one whole currency unit, in minor units
|
|
|
|
|
$name = '' !== trim( $title ) ? trim( $title ) : ( 'subathon' === $key ? 'Subathon' : ( 'counter' === $key ? 'Donation counter' : 'My first goal' ) );
|
|
|
|
|
$goal = array( 'title' => $name, 'target_minor' => $targetMinor, 'currency' => $currency, 'status' => 'active', 'counts_fees' => 0 );
|
|
|
|
|
$rules = array();
|
|
|
|
|
if ( 'subathon' === $key ) {
|
|
|
|
|
$rules[] = array( 'type' => 'add_time', 'config' => array(
|
2026-11-15 11:40:06 -08:00
|
|
|
'seconds_per_unit' => 60, 'unit_minor' => $one, 'cap_seconds_per_donation' => null, 'max_total_seconds' => null, 'max_timer_seconds' => null, 'basis' => 'base',
|
2026-11-15 10:26:03 -08:00
|
|
|
) );
|
|
|
|
|
} elseif ( 'counter' === $key ) {
|
|
|
|
|
$rules[] = array( 'type' => 'counter', 'config' => array(
|
|
|
|
|
'step' => 1, 'per_minor' => 10 * $one, 'carry_over' => true, 'basis' => 'base', 'label' => 'Count',
|
|
|
|
|
) );
|
|
|
|
|
}
|
|
|
|
|
return array( 'goal' => $goal, 'rules' => $rules );
|
|
|
|
|
}
|
|
|
|
|
}
|