Yearly goals
tilttek/reading-questsA reader may set a goal for a calendar year: a number of books finished, or an amount of pages or minutes read. The
application keeps the goal with the reader; ReadingGoals reads where it stands from the journal.
use Tilttek\ReadingQuests\ReadingGoal;
use Tilttek\ReadingQuests\ReadingGoals;
use Tilttek\ReadingQuests\ReadingUnit;
$goals = new ReadingGoals($journal, $clock, new DateTimeZone('America/Toronto'));
$progress = $goals->progress('member:44', ReadingGoal::books(2027, 24));
$progress->done; // books finished in 2027
$progress->remaining(); // 0 once reached
$progress->percent(); // 0 to 100
$progress->expected; // what an even pace through the year would have reached by now
$progress->ahead(); // negative when behind that pace
$goals->progress('member:44', ReadingGoal::amount(2027, 6_000, ReadingUnit::Pages));
- The year runs from 1 January to the next 1 January, at midnight in the timezone given, UTC by default, and is read on the moment of each activity. A goal is for a year from 1970 to 9998, and asks for 1 to 1 000 000 000.
- Changing the target during the year loses nothing:
withTarget()gives the same goal with another target, and the progress is read again from the journal. - A book goal counts
book.finished, a book read again counting again; an amount goal totalsbook.read. The journal does not filter by unit: a site measures in pages or in minutes, not both, and an amount goal is in the site's unit. - The pace is the reader's own. The figures go to the reader alone; the library ranks no one, and a reader behind the pace is told how far, nothing more.
ReadingGoals::progress() reads the totals of one member over one year through Journal::totals(). A page that shows
the goals of many readers at once keeps its own totals in a projection of tilttek/activity instead.