Skip to content

tilttek/reading-quests-bundle

✅ published

Run reading quests in your Symfony app: each reader's place in a book stored, pages or minutes counted once, yearly goals kept, all exported and erased.

tilttek/reading-quests-bundle integrates tilttek/reading-quests with Symfony, on the activity journal of tilttek/activity-bundle. It keeps, for each reader and each book, the progress of phil/reading-progress — the place reached, the furthest percent, when the book was finished — in a table on a Doctrine DBAL connection, one row per reading, written at the version it was read at. ReadingTracker records a position in one call: the stored reading read, the activities book.started, book.read and book.finished recorded in the journal, the reading stored, then ReadingStarted and ReadingCompleted handed to the application's event dispatcher. The time is the server's clock, never the browser's, and the same position sent twice counts once.

ReaderGoals keeps each reader's goal for a calendar year — books finished, or pages or minutes read — and reads where they stand from the journal, in the site's timezone; a target changed during the year loses nothing. The books come from the configuration, from a table the application edits, or from the application's own catalogue. A reader who leaves is exported and erased through phil/privacy-bundle.

It is for a Symfony application whose members read long texts — rulebooks, campaign settings, stories — and earn quests and badges for it.

It requires Symfony's DependencyInjection and Config, Doctrine DBAL, the PSR clock and event dispatcher, phil/reading-progress, phil/resource, tilttek/activity-bundle and tilttek/reading-quests. The ORM and phil/privacy-bundle are optional: the schema listener and the privacy module are registered only when they are installed.

The design follows the other bundles of the monorepo: an AbstractBundle with its configuration, services declared by ReadingQuestsServices, repositories on DBAL and in memory for tests, tables added by a schema listener.

Status

PartState
Configuration tilttek_reading_quests: store, connection, measure, completion, timezone, shelf, member erasureImplemented and tested
ReadingTracker: a position recorded, stored at its version, its events dispatched; reading a book againImplemented and tested
ReaderGoals: yearly goals kept and read from the activity journalImplemented and tested
The readings, goals and books on DBAL, with their tables on SQLite, PostgreSQL, MySQL and MariaDB schemasImplemented and tested
The tables in the schema the ORM generates, for the migrationsImplemented and tested
Export and erasure of a reader for phil/privacy-bundleImplemented and tested
The DBAL repositories against MySQL and PostgreSQL serversNot started
A controller of positions and a component of the goal for the PHIL UX kitNot started

Documentation

DocumentWhat it covers
InstallationRequirements, enabling the bundle, the verbs of the journal, the migration.
ConfigurationEvery key of tilttek_reading_quests, with its default.
Recording readingReadingTracker: a position, writers at once, reading a book again.
Yearly goalsReaderGoals: setting, changing and reading a reader's goal.
The readings in the databaseThe tables, the shelf in the database, what a position costs.
EventsListening to the start and the end of a reading.
PrivacyThe export and the erasure of a reader, and what they leave.
Extension pointsThe services, aliases and tags the application uses.
TestingThe bundle's tests, its benchmark, and testing an application.
ReferenceEvery class of the bundle, with its role.

Quick start

composer require tilttek/reading-quests-bundle
# config/packages/tilttek_reading_quests.yaml
tilttek_reading_quests:
    measure: { unit: pages }
    shelf:
        books:
            core-rules: { pages: 320, facts: { system: dnd5e } }
use Phil\ReadingProgress\Document;
use Phil\ReadingProgress\Position;
use Tilttek\ReadingQuestsBundle\Application\ReadingTracker;

final readonly class SaveThePlace
{
    public function __construct(private ReadingTracker $tracker) {}

    public function __invoke(int $member, Document $rulebook, string $block, int $offset): int
    {
        return $this->tracker->record('member:'.$member, $rulebook, new Position($block, $offset))->gained;
    }
}

Then bin/console doctrine:migrations:diff writes the migration of the reading tables.

Requirements

PHP 8.5 or later, Symfony 8.2, Doctrine DBAL 4.6.

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.