Make bonus rules visible: highlighted BONUS line on the alerts overlay, streamgoals_bonus action
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
1e2ca96eed
commit
c7f2dcffeb
9 files changed
+187
-3
No files matched your search
@@ -62,6 +62,31 @@ final class WpdbDataSource implements OverlayDataSource {
|
||||
return array( 'label' => $label, 'value' => $total );
|
||||
}
|
||||
|
||||
public function bonusesFor( array $donationIds ): array {
|
||||
global $wpdb;
|
||||
$ids = array_values( array_unique( array_filter( array_map( 'intval', $donationIds ), static fn( $i ) => $i > 0 ) ) );
|
||||
if ( ! $ids ) {
|
||||
return array();
|
||||
}
|
||||
$in = implode( ',', array_fill( 0, count( $ids ), '%d' ) );
|
||||
$rows = $wpdb->get_results( $wpdb->prepare(
|
||||
"SELECT e.donation_id, r.config FROM {$this->t('rule_events')} e
|
||||
INNER JOIN {$this->t('rules')} r ON r.id = e.rule_id
|
||||
WHERE r.type = 'bonus' AND e.reversed = 0 AND e.delta > 0 AND e.donation_id IN ($in)
|
||||
ORDER BY e.id ASC",
|
||||
$ids
|
||||
), ARRAY_A );
|
||||
$out = array();
|
||||
foreach ( (array) $rows as $row ) {
|
||||
$cfg = json_decode( (string) $row['config'], true );
|
||||
$ev = is_array( $cfg ) && isset( $cfg['event'] ) && is_string( $cfg['event'] ) ? $cfg['event'] : '';
|
||||
if ( '' !== $ev ) {
|
||||
$out[ (int) $row['donation_id'] ][] = $ev;
|
||||
}
|
||||
}
|
||||
return $out;
|
||||
}
|
||||
|
||||
public function donations( ?int $sinceId, int $limit ): array {
|
||||
global $wpdb;
|
||||
$cols = 'id, base_minor, currency, donor_name, is_anonymous, message, status, moderation';
|
||||
|
||||
Reference in new issue
Block a user