update 2023-06-22 09:54:56
This commit is contained in:
parent
fa79d503ad
commit
82bd393f95
@ -23,8 +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
|
||||
+ getNextChapter(string $translation, int $book, ...) : ?int
|
||||
+ getPreviousChapter(int $chapter, bool $force = false) : ?int
|
||||
- translation(string $translation) : ?string
|
||||
- book(string $translation, int $book) : ?string
|
||||
- chapter(string $translation, int $book, ...) : ?string
|
||||
@ -63,7 +63,7 @@ note left of Watcher::api
|
||||
int $chapter
|
||||
end note
|
||||
|
||||
note right of Watcher::next
|
||||
note right of Watcher::getNextChapter
|
||||
Get the next chapter
|
||||
|
||||
since: 2.0.1
|
||||
@ -73,9 +73,10 @@ note right of Watcher::next
|
||||
string $translation
|
||||
int $book
|
||||
int $chapter
|
||||
bool $force = false
|
||||
end note
|
||||
|
||||
note left of Watcher::previous
|
||||
note left of Watcher::getPreviousChapter
|
||||
Get the previous chapter
|
||||
|
||||
since: 2.0.1
|
||||
|
@ -206,16 +206,17 @@ final class Watcher
|
||||
* @param string $translation The translation.
|
||||
* @param int $book The book number.
|
||||
* @param int $chapter The chapter number.
|
||||
* @param bool $force The switch to force the getting.
|
||||
*
|
||||
* @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
|
||||
public function getNextChapter(string $translation, int $book, int $chapter, bool $force = false): ?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(
|
||||
if (($force || !$this->fresh) && ($chapter_sha = $this->load->value(
|
||||
['abbreviation' => $translation, 'book_nr' => $book, 'chapter' => $next],
|
||||
'sha', 'chapter'
|
||||
)) !== null)
|
||||
@ -230,15 +231,16 @@ final class Watcher
|
||||
* Get the previous chapter
|
||||
*
|
||||
* @param int $chapter The chapter number.
|
||||
* @param bool $force The switch to force the getting.
|
||||
*
|
||||
* @return int|null Number if there is a previous, else null
|
||||
* @since 2.0.1
|
||||
*/
|
||||
public function previous(int $chapter): ?int
|
||||
public function getPreviousChapter(int $chapter, bool $force = false): ?int
|
||||
{
|
||||
// we load the previous chapter
|
||||
$previous = $chapter - 1;
|
||||
if (!$this->fresh && $previous > 0)
|
||||
if (($force || !$this->fresh) && $previous > 0)
|
||||
{
|
||||
return $previous;
|
||||
}
|
||||
@ -408,18 +410,29 @@ final class Watcher
|
||||
return false;
|
||||
}
|
||||
|
||||
$api_verses = (array) $api->verses;
|
||||
$update = [];
|
||||
$insert = [];
|
||||
|
||||
// dynamic update all verse objects
|
||||
foreach ($verses as $verse)
|
||||
foreach ($api->verses as $verse)
|
||||
{
|
||||
if (($object = $this->getVerse((int) $verse->verse, $api_verses)) !== null)
|
||||
// check if the verse exist
|
||||
if (($object = $this->getVerse((int) $verse->verse, $verses)) !== null)
|
||||
{
|
||||
$object->id = $verse->id;
|
||||
$object->created = $this->today;
|
||||
$update[] = $object;
|
||||
$verse->id = $object->id;
|
||||
$verse->created = $this->today;
|
||||
$update[] = $verse;
|
||||
}
|
||||
else
|
||||
{
|
||||
$insert[] = $verse;
|
||||
}
|
||||
}
|
||||
|
||||
// check if we have values to insert
|
||||
if ($insert !== [])
|
||||
{
|
||||
$this->insert->items($insert, 'verse')
|
||||
}
|
||||
|
||||
// update the local verses
|
||||
|
@ -175,16 +175,17 @@
|
||||
* @param string $translation The translation.
|
||||
* @param int $book The book number.
|
||||
* @param int $chapter The chapter number.
|
||||
* @param bool $force The switch to force the getting.
|
||||
*
|
||||
* @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
|
||||
public function getNextChapter(string $translation, int $book, int $chapter, bool $force = false): ?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(
|
||||
if (($force || !$this->fresh) && ($chapter_sha = $this->load->value(
|
||||
['abbreviation' => $translation, 'book_nr' => $book, 'chapter' => $next],
|
||||
'sha', 'chapter'
|
||||
)) !== null)
|
||||
@ -199,15 +200,16 @@
|
||||
* Get the previous chapter
|
||||
*
|
||||
* @param int $chapter The chapter number.
|
||||
* @param bool $force The switch to force the getting.
|
||||
*
|
||||
* @return int|null Number if there is a previous, else null
|
||||
* @since 2.0.1
|
||||
*/
|
||||
public function previous(int $chapter): ?int
|
||||
public function getPreviousChapter(int $chapter, bool $force = false): ?int
|
||||
{
|
||||
// we load the previous chapter
|
||||
$previous = $chapter - 1;
|
||||
if (!$this->fresh && $previous > 0)
|
||||
if (($force || !$this->fresh) && $previous > 0)
|
||||
{
|
||||
return $previous;
|
||||
}
|
||||
@ -377,18 +379,29 @@
|
||||
return false;
|
||||
}
|
||||
|
||||
$api_verses = (array) $api->verses;
|
||||
$update = [];
|
||||
$insert = [];
|
||||
|
||||
// dynamic update all verse objects
|
||||
foreach ($verses as $verse)
|
||||
foreach ($api->verses as $verse)
|
||||
{
|
||||
if (($object = $this->getVerse((int) $verse->verse, $api_verses)) !== null)
|
||||
// check if the verse exist
|
||||
if (($object = $this->getVerse((int) $verse->verse, $verses)) !== null)
|
||||
{
|
||||
$object->id = $verse->id;
|
||||
$object->created = $this->today;
|
||||
$update[] = $object;
|
||||
$verse->id = $object->id;
|
||||
$verse->created = $this->today;
|
||||
$update[] = $verse;
|
||||
}
|
||||
else
|
||||
{
|
||||
$insert[] = $verse;
|
||||
}
|
||||
}
|
||||
|
||||
// check if we have values to insert
|
||||
if ($insert !== [])
|
||||
{
|
||||
$this->insert->items($insert, 'verse')
|
||||
}
|
||||
|
||||
// update the local verses
|
||||
|
Loading…
x
Reference in New Issue
Block a user