Skip to content

tilttek/celebrations

✅ published

A rewards inbox: every achievement a member earns, from any package, waits there, is grouped with its kind and is celebrated once.

tilttek/celebrations gathers what a member earns across a site — a badge, a level, a quest accomplished, a set completed — into one inbox. The application's listeners turn the events of its packages into an Achievement: the member, the source that gave it, badges, its kind, badge, what was earned, badge.first-roll, and the occurrence that makes it unique, badge.first-roll#1. An achievement told twice — a notice delivered again, a retried message — is kept once, so the member is never congratulated twice for the same thing.

Pending entries are grouped by source and kind: three badges earned during one session make one "3 new badges", not three windows. The window shows the next group, the earliest earned first, then the next one, until the member has seen them all; the bell reads the count. A reward taken back — a badge revoked — is withdrawn and never shown. An achievement may carry the moment after which it is no longer worth showing — a seasonal trophy after its season —: its entry then lapses, while the reward itself stands, for the inbox only decides what is celebrated, never what is held.

Each member chooses: to turn the window off and keep the inbox, how much it moves — fully, reduced or not at all —, and whether it plays a sound, which is off unless the member turns it on. A device that asks for reduced motion (prefers-reduced-motion) always reduces it.

It is for a community site, a game site or any application that gives rewards through several packages. It is a plain PHP library whose dependencies are phil/resource, the opaque reference of a member, and psr/clock; it depends on no rewards package, which its achievements only name. Members are references the application gives: the library never reads a name, an e-mail or an account, and its events carry identifiers only.

Status

PartState
Achievement: what a member earned, from which source, with its parameters and its moment to stop being shownImplemented and tested
Celebrations: receive once, withdraw, group, count, next, mark seen, history, preferences, eraseImplemented and tested
Entry, EntryState: pending, seen, withdrawn or lapsed, with the order of receptionImplemented and tested
Group, Celebration: the entries of one source and kind, and what the window shows nextImplemented and tested
Preferences, Motion: the window on or off, the motion, the sound, the device's reduced motionImplemented and tested
Contract\CelebrationStore, with Store\InMemoryCelebrationStoreImplemented and tested
Contract\CelebrationObserver, CelebrationChanged: what is told, identifiers onlyImplemented and tested
Limits: pending entries and entries per member, entries shown per groupImplemented and tested
A Symfony bundle: Doctrine store, listeners for the rewards packages, the window as a Stimulus controller, translationsNot started

Documentation

DocumentWhat it covers
InstallationRequirements, installing and wiring.
The inboxReceiving achievements once, groups, seen, withdrawn and lapsed entries, bounds, history and erasure.
CelebratingThe next celebration, the members' preferences, motion and sound, and listeners for other packages.
Extension pointsThe store, observers, limits and the clock.
ExceptionsCelebrationException and its exception, with their messages.
TestingThe library's tests and bench, and testing code that uses the inbox.
ReferenceEvery public type, with its role.

Quick start

composer require tilttek/celebrations
use Phil\Resource\ResourceReference;
use Tilttek\Celebrations\Achievement;
use Tilttek\Celebrations\Celebrations;
use Tilttek\Celebrations\Store\InMemoryCelebrationStore;

$celebrations = new Celebrations(new InMemoryCelebrationStore(), $clock);
$member = ResourceReference::of('member', '42');

$celebrations->receive(new Achievement($member, 'badges', 'badge', 'badge.first-roll', 'badge.first-roll#1', $earnedAt));
$celebrations->receive(new Achievement($member, 'badges', 'badge', 'badge.night-owl', 'badge.night-owl#1', $earnedAt));
$celebrations->receive(new Achievement($member, 'progression', 'level', 'track.reader', 'track.reader#5', $earnedAt, ['level' => 5]));

$celebrations->count($member);                         // 3, for the bell

$next = $celebrations->next($member, deviceReducesMotion: false);
$next->group->count;                                   // 2: "2 new badges"
$next->remaining;                                      // 1 more group after this one
$celebrations->markSeen($member, $next->group->sequences());

Requirements

PHP 8.5 or later.

Contributing

Contributions are welcome on the PHIL monorepo: read the contribution guide and the code of conduct. Report a vulnerability privately, as the security policy explains, never in a public issue.

License

MIT, © Philippe Gamache, doing business as Le Gnome Archiviste; a Tilttek project. See LICENSE.