From b397c594182e15413d99ee703e014e3c6db4a1d4 Mon Sep 17 00:00:00 2001 From: aB0t Date: Tue, 1 Aug 2023 08:50:05 +0200 Subject: [PATCH] update 2023-08-01 08:50:05 --- .../README.md | 8 +++++ .../code.php | 33 +++++++++++++++++-- .../code.power | 33 +++++++++++++++++-- 3 files changed, 68 insertions(+), 6 deletions(-) diff --git a/src/c2a8a5fa-8e7f-443a-86d7-a8c1e4cdfa98/README.md b/src/c2a8a5fa-8e7f-443a-86d7-a8c1e4cdfa98/README.md index 59123da..197f838 100644 --- a/src/c2a8a5fa-8e7f-443a-86d7-a8c1e4cdfa98/README.md +++ b/src/c2a8a5fa-8e7f-443a-86d7-a8c1e4cdfa98/README.md @@ -13,6 +13,7 @@ class Book << (F,LightGreen) >> #Green { # Books $books + __construct(Load $load, Insert $insert, ...) + + translations(array $translations) : bool + sync(string $translation, int $book) : bool - load(string $translation, int $book) : bool - update(string $translation) : bool @@ -30,6 +31,13 @@ note right of Book::__construct Books $books end note +note right of Book::translations + Update translations books + + since: 2.0.1 + return: bool +end note + note right of Book::sync Sync the target being watched diff --git a/src/c2a8a5fa-8e7f-443a-86d7-a8c1e4cdfa98/code.php b/src/c2a8a5fa-8e7f-443a-86d7-a8c1e4cdfa98/code.php index 1f34b90..0d9c1bc 100644 --- a/src/c2a8a5fa-8e7f-443a-86d7-a8c1e4cdfa98/code.php +++ b/src/c2a8a5fa-8e7f-443a-86d7-a8c1e4cdfa98/code.php @@ -59,6 +59,32 @@ final class Book extends Watcher $this->table = 'book'; } + /** + * Update translations books + * + * @param array $translations The translations ids. + * + * @return bool True on success + * @since 2.0.1 + */ + public function translations(array $translations): bool + { + foreach ($translations as $translation) + { + if (($abbreviation = $this->load->value(['id' => $translation], 'abbreviation', 'translation')) === null) + { + return false; + } + + if (!$this->update($abbreviation)) + { + return false; + } + } + + return true; + } + /** * Sync the target being watched * @@ -161,7 +187,7 @@ final class Book extends Watcher { // check if the verse exist $match['value'] = (string) $book->nr; - if (($object = $this->getTarget($match, $local_books)) !== null) + if ($local_books !== null && ($object = $this->getTarget($match, $local_books)) !== null) { $book->id = $object->id; $book->created = $this->today; @@ -174,9 +200,10 @@ final class Book extends Watcher } // check if we have values to insert + $inserted = false; if ($insert !== []) { - $this->insert->items($insert, $this->table); + $inserted = $this->insert->items($insert, $this->table); } // update the local values @@ -185,7 +212,7 @@ final class Book extends Watcher return true; } - return false; + return $inserted; } } diff --git a/src/c2a8a5fa-8e7f-443a-86d7-a8c1e4cdfa98/code.power b/src/c2a8a5fa-8e7f-443a-86d7-a8c1e4cdfa98/code.power index 0179369..df18e8d 100644 --- a/src/c2a8a5fa-8e7f-443a-86d7-a8c1e4cdfa98/code.power +++ b/src/c2a8a5fa-8e7f-443a-86d7-a8c1e4cdfa98/code.power @@ -31,6 +31,32 @@ $this->table = 'book'; } + /** + * Update translations books + * + * @param array $translations The translations ids. + * + * @return bool True on success + * @since 2.0.1 + */ + public function translations(array $translations): bool + { + foreach ($translations as $translation) + { + if (($abbreviation = $this->load->value(['id' => $translation], 'abbreviation', 'translation')) === null) + { + return false; + } + + if (!$this->update($abbreviation)) + { + return false; + } + } + + return true; + } + /** * Sync the target being watched * @@ -133,7 +159,7 @@ { // check if the verse exist $match['value'] = (string) $book->nr; - if (($object = $this->getTarget($match, $local_books)) !== null) + if ($local_books !== null && ($object = $this->getTarget($match, $local_books)) !== null) { $book->id = $object->id; $book->created = $this->today; @@ -146,9 +172,10 @@ } // check if we have values to insert + $inserted = false; if ($insert !== []) { - $this->insert->items($insert, $this->table); + $inserted = $this->insert->items($insert, $this->table); } // update the local values @@ -157,5 +184,5 @@ return true; } - return false; + return $inserted; } \ No newline at end of file