From fa79d503add4a42ece921050b161224ce18fa391 Mon Sep 17 00:00:00 2001 From: aB0t Date: Thu, 22 Jun 2023 08:54:55 +0200 Subject: [PATCH] update 2023-06-22 08:54:55 --- .../README.md | 21 +++++++++ .../code.php | 46 +++++++++++++++++++ .../code.power | 46 +++++++++++++++++++ 3 files changed, 113 insertions(+) diff --git a/src/f815fb33-f721-48a5-a84e-53f1986e8881/README.md b/src/f815fb33-f721-48a5-a84e-53f1986e8881/README.md index 8b486c6..3145f75 100644 --- a/src/f815fb33-f721-48a5-a84e-53f1986e8881/README.md +++ b/src/f815fb33-f721-48a5-a84e-53f1986e8881/README.md @@ -23,6 +23,8 @@ class Watcher << (F,LightGreen) >> #Green { # ?object $verse + __construct(Load $load, Insert $insert, ...) + api(string $translation, int $book, ...) : bool + + next(string $translation, int $book, ...) : ?int + + previous(int $chapter) : ?int - translation(string $translation) : ?string - book(string $translation, int $book) : ?string - chapter(string $translation, int $book, ...) : ?string @@ -61,6 +63,25 @@ note left of Watcher::api int $chapter end note +note right of Watcher::next + Get the next chapter + + since: 2.0.1 + return: ?int + + arguments: + string $translation + int $book + int $chapter +end note + +note left of Watcher::previous + Get the previous chapter + + since: 2.0.1 + return: ?int +end note + note right of Watcher::translation Get Translation Hash Value diff --git a/src/f815fb33-f721-48a5-a84e-53f1986e8881/code.php b/src/f815fb33-f721-48a5-a84e-53f1986e8881/code.php index f1856bf..91d57de 100644 --- a/src/f815fb33-f721-48a5-a84e-53f1986e8881/code.php +++ b/src/f815fb33-f721-48a5-a84e-53f1986e8881/code.php @@ -200,6 +200,52 @@ final class Watcher return false; } + /** + * Get the next chapter + * + * @param string $translation The translation. + * @param int $book The book number. + * @param int $chapter The chapter number. + * + * @return int|null Number if there is a next, else null + * @since 2.0.1 + */ + public function next(string $translation, int $book, int $chapter): ?int + { + // we load the next chapter + $next = $chapter + 1; + // check if this books has this next chapter + if (!$this->fresh && ($chapter_sha = $this->load->value( + ['abbreviation' => $translation, 'book_nr' => $book, 'chapter' => $next], + 'sha', 'chapter' + )) !== null) + { + return $next; + } + + return null; + } + + /** + * Get the previous chapter + * + * @param int $chapter The chapter number. + * + * @return int|null Number if there is a previous, else null + * @since 2.0.1 + */ + public function previous(int $chapter): ?int + { + // we load the previous chapter + $previous = $chapter - 1; + if (!$this->fresh && $previous > 0) + { + return $previous; + } + + return null; + } + /** * Get Translation Hash Value * diff --git a/src/f815fb33-f721-48a5-a84e-53f1986e8881/code.power b/src/f815fb33-f721-48a5-a84e-53f1986e8881/code.power index 61b76c8..abc307b 100644 --- a/src/f815fb33-f721-48a5-a84e-53f1986e8881/code.power +++ b/src/f815fb33-f721-48a5-a84e-53f1986e8881/code.power @@ -169,6 +169,52 @@ return false; } + /** + * Get the next chapter + * + * @param string $translation The translation. + * @param int $book The book number. + * @param int $chapter The chapter number. + * + * @return int|null Number if there is a next, else null + * @since 2.0.1 + */ + public function next(string $translation, int $book, int $chapter): ?int + { + // we load the next chapter + $next = $chapter + 1; + // check if this books has this next chapter + if (!$this->fresh && ($chapter_sha = $this->load->value( + ['abbreviation' => $translation, 'book_nr' => $book, 'chapter' => $next], + 'sha', 'chapter' + )) !== null) + { + return $next; + } + + return null; + } + + /** + * Get the previous chapter + * + * @param int $chapter The chapter number. + * + * @return int|null Number if there is a previous, else null + * @since 2.0.1 + */ + public function previous(int $chapter): ?int + { + // we load the previous chapter + $previous = $chapter - 1; + if (!$this->fresh && $previous > 0) + { + return $previous; + } + + return null; + } + /** * Get Translation Hash Value *