Skip to content

Commit

Permalink
Ready to read status
Browse files Browse the repository at this point in the history
  • Loading branch information
ragusa87 committed Aug 11, 2024
1 parent 5a5342b commit 83370fd
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 1 deletion.
3 changes: 3 additions & 0 deletions src/Controller/Kobo/KoboStateController.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ public function state(KoboDevice $kobo, string $uuid, Request $request): Respons
case ReadingStateStatusInfo::STATUS_FINISHED:
$this->bookProgressionService->setProgression($book, $kobo->getUser(), 1.0);
break;
case ReadingStateStatusInfo::STATUS_READY_TO_READ:
$this->bookProgressionService->setProgression($book, $kobo->getUser(), 0.0);
break;
case ReadingStateStatusInfo::STATUS_READING:
$progress = $state->currentBookmark?->progressPercent;
$progress = $progress !== null ? $progress / 100 : null;
Expand Down
1 change: 1 addition & 0 deletions src/Kobo/Request/ReadingStateStatusInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ class ReadingStateStatusInfo
{
public const STATUS_READING = 'Reading';
public const STATUS_FINISHED = 'Finished';
public const STATUS_READY_TO_READ = 'ReadyToRead';

public ?\DateTimeImmutable $lastModified = null;

Expand Down
6 changes: 5 additions & 1 deletion tests/Controller/Kobo/KoboStateControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,11 @@ private function getReadingStates(string $bookUuid, int $percent = 50): ReadingS
$state->currentBookmark->lastModified = new \DateTime();
$state->entitlementId = $bookUuid;
$state->statusInfo = new ReadingStateStatusInfo();
$state->statusInfo->status = $percent === 100 ? ReadingStateStatusInfo::STATUS_FINISHED : ReadingStateStatusInfo::STATUS_READING;
$state->statusInfo->status = match($percent) {
0 => ReadingStateStatusInfo::STATUS_READY_TO_READ,
100 => ReadingStateStatusInfo::STATUS_FINISHED,
default => ReadingStateStatusInfo::STATUS_READING,
};
$state->statusInfo->lastModified = $state->lastModified;
$state->statistics = new ReadingStateStatistics();
$state->statistics->remainingTimeMinutes = (int) (100 * ($percent/100));
Expand Down

0 comments on commit 83370fd

Please sign in to comment.