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} */ 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( 'seconds_per_unit' => 60, 'unit_minor' => $one, 'cap_seconds_per_donation' => null, 'max_total_seconds' => null, 'max_timer_seconds' => null, 'basis' => 'base', ) ); } 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 ); } }