Skip to main content

SubscriberBadgeRepository

\Benecaster\Membership\SubscriberBadgeRepository

Class Premium

CRUD layer for subscriber badge grants — the supported entry point for reading and writing them. A user may hold only one grant per badge definition per source, so insert() fails for a tier_auto grant that already exists for that user and definition. manual grants with a null badge_definition_id are unconstrained and allow multiple ad-hoc grants per user.

Methods

Method Visibility Since Description
insert( array $data ): int|false Public — Inserts a new badge grant row. Returns the inserted row ID or false on failure. Expected keys: user_id, badge_definition_id, source, label, icon_slug, icon_attachment_id, color, granted_at.
delete( int $id ): bool Public — Deletes a grant by primary key. Returns true on success. Used by the admin badge removal UI.
find_tier_auto_for_user( int $user_id ): array Public — Returns all tier_auto grant rows for the given user, ordered by granted_at ASC, id ASC. Used by BadgeReconciler to compute diffs.
find_for_user( int $user_id ): array Public — Returns all grant rows (tier_auto + manual) for the given user, ordered by granted_at ASC, id ASC. Contract consumed by badge rendering, REST fields, and shortcode via benecaster_get_user_badges().