queuedCount(); } catch ( \Throwable ) { return 0; } } private static function url( array $args = array() ): string { return Admin::url( self::PAGE, $args ); } /* ---------------------------------------------------------------- render */ public static function render(): void { Admin::open( 'Rewards' ); $edit = Admin::get_int( 'edit' ); if ( 'new' === Admin::get_str( 'view' ) || $edit ) { self::renderForm( $edit ); } else { self::renderQueue(); self::renderMenu(); } Admin::close(); } private static function renderQueue(): void { $cur = Admin::currency(); $repo = self::repo(); $queued = $repo->queued( 200 ); echo '
Nothing in the queue. When a donation triggers a reward, it shows up here.
'; } else { echo '| Donor | Amount | Reward | Time | Message | |
|---|---|---|---|---|---|
| ' . esc_html( Format::donorName( $e ) ) . ' | '; echo '' . esc_html( Format::money( (int) ( $e['base_minor'] ?? 0 ), Format::currency( $e['currency'] ?? $cur ) ) ) . ' | '; echo '' . esc_html( (string) $e['title'] ) . ' × ' . (int) $e['times'] . ' | '; echo '' . esc_html( self::when( (string) $e['created_at'] ) ) . ' | '; echo '' . esc_html( (string) ( $e['message'] ?? '' ) ) . ' | '; Admin::form( 'sg_event_done', array( 'event_id' => (int) $e['id'] ), 'sg-inline' ); echo ' |
Donors pick a reward on the donation form (or just donate the amount). Rewards must be at least ' . esc_html( Format::money( self::minMinor(), $cur ) ) . ', the minimum donation.
'; echo ''; if ( ! $actions ) { echo 'No rewards yet.
| Reward | Amount | Triggers | Applies to | Order | Actions |
|---|---|---|---|---|---|
| ' . esc_html( $a['title'] ) . '';
if ( '' !== $a['description'] ) {
echo ' ' . esc_html( $a['description'] ) . ''; } echo ' | ' . esc_html( Format::money( $a['amount_minor'], $cur ) ) . ' | '; echo '' . esc_html( Matcher::EVERY === $a['mode'] ? 'Every time it adds up' : 'Exactly this amount' ) . ' | '; echo '' . esc_html( 0 === $a['goal_id'] ? 'All goals' : ( $goals[ $a['goal_id'] ] ?? 'Goal #' . $a['goal_id'] ) ) . ' | '; echo '' . (int) $a['sort'] . ' | '; echo 'Edit '; Admin::form( 'sg_action_toggle', array( 'action_id' => $id, 'enabled' => $a['enabled'] ? 0 : 1 ), 'sg-inline' ); echo ' '; Admin::form( 'sg_action_delete', array( 'action_id' => $id ), 'sg-inline sg-confirm' ); echo ''; echo ' |
That reward no longer exists. Back to rewards
'; return; } $cur = Admin::currency(); $goals = self::goalTitles(); $val = static fn( string $k, $d = '' ) => $a[ $k ] ?? $d; $mode = (string) $val( 'mode', Matcher::EXACT ); $data = array( 'currency' => $cur, 'exp' => Money::exponent( $cur ), 'editId' => $id, 'actions' => array_values( array_map( static fn( array $r ): array => array( 'id' => $r['id'], 'goal_id' => $r['goal_id'], 'title' => $r['title'], 'amount_minor' => $r['amount_minor'], 'mode' => $r['mode'] ), array_filter( self::repo()->all(), static fn( array $r ): bool => (bool) $r['enabled'] && $r['id'] !== $id ) ) ), ); echo 'What you do on stream, for example "Eat a bean". Up to 120 characters. | |
Optional. A short note shown to donors. | |
At least ' . esc_html( Format::money( self::minMinor(), $cur ) ) . ' (your minimum donation). The amount before any fee the donor chooses to cover. | |
| Triggers | ';
echo ' '; echo ' |
Lower numbers are listed first. Leave empty to put it last. |