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