diff --git a/README.md b/README.md
index 2f45d67..8e0a09d 100644
--- a/README.md
+++ b/README.md
@@ -82,6 +82,9 @@ This repository contains an index (see below) of all the approved powers within
- **class Model** | [Details](src/116eb429-bc51-4d14-b9aa-7145c86a29d1) | [Code](src/116eb429-bc51-4d14-b9aa-7145c86a29d1/code.php) | [Settings](src/116eb429-bc51-4d14-b9aa-7145c86a29d1/settings.json) | Super__116eb429_bc51_4d14_b9aa_7145c86a29d1__Power
- **class Openai** | [Details](src/ac5c7679-dd6e-4817-8e48-489e521122f1) | [Code](src/ac5c7679-dd6e-4817-8e48-489e521122f1/code.php) | [Settings](src/ac5c7679-dd6e-4817-8e48-489e521122f1/settings.json) | Super__ac5c7679_dd6e_4817_8e48_489e521122f1__Power
- **class Utilities** | [Details](src/b89d74ef-c71c-4a58-8455-5dbdfe94027a) | [Code](src/b89d74ef-c71c-4a58-8455-5dbdfe94027a/code.php) | [Settings](src/b89d74ef-c71c-4a58-8455-5dbdfe94027a/settings.json) | Super__b89d74ef_c71c_4a58_8455_5dbdfe94027a__Power
+- **Namespace**: [VDM\Joomla\GetBible\Tagged](#vdm-joomla-getbible-tagged)
+
+ - **final class Paragraphs** | [Details](src/4cfff1bc-02b3-4c52-9e6e-7ceefb505a32) | [Code](src/4cfff1bc-02b3-4c52-9e6e-7ceefb505a32/code.php) | [Settings](src/4cfff1bc-02b3-4c52-9e6e-7ceefb505a32/settings.json) | Super__4cfff1bc_02b3_4c52_9e6e_7ceefb505a32__Power
- **Namespace**: [VDM\Joomla\GetBible\Utilities](#vdm-joomla-getbible-utilities)
- **final class Http** | [Details](src/b8c66089-735e-4081-825c-8fe36b28e4a6) | [Code](src/b8c66089-735e-4081-825c-8fe36b28e4a6/code.php) | [Settings](src/b8c66089-735e-4081-825c-8fe36b28e4a6/settings.json) | Super__b8c66089_735e_4081_825c_8fe36b28e4a6__Power
diff --git a/src/2315a1c5-bcf6-401a-8d11-60f4d6d12dbb/README.md b/src/2315a1c5-bcf6-401a-8d11-60f4d6d12dbb/README.md
index c9cfbbf..c0f1c3b 100644
--- a/src/2315a1c5-bcf6-401a-8d11-60f4d6d12dbb/README.md
+++ b/src/2315a1c5-bcf6-401a-8d11-60f4d6d12dbb/README.md
@@ -15,11 +15,15 @@ class Tagged << (F,LightGreen) >> #Green {
# Insert $insert
# Update $update
# Linker $linker
+ # Registry $params
+ # CMSApplication $app
+ __construct(Load $load, Insert $insert, ...)
+ set(string $translation, int $book, ...) : ?array
- + delete(string $tag) : ?array
+ + delete(string $tagged) : ?array
+ - getByGuid(string $guid) : ?object
- get(string $linker, int $book, ...) : ?object
- create(string $linker, string $translation, ...) : bool
+ - createForLinker(string $linker, object $tagged, ...) : bool
}
note right of Tagged::__construct
@@ -32,6 +36,8 @@ note right of Tagged::__construct
Insert $insert
Update $update
Linker $linker
+ ?Registry $params = null
+ ?CMSApplication $app = null
end note
note right of Tagged::set
@@ -55,6 +61,13 @@ note right of Tagged::delete
return: ?array
end note
+note right of Tagged::getByGuid
+ Get a tagged verse
+
+ since: 2.0.1
+ return: ?object
+end note
+
note right of Tagged::get
Get a tagged verse
@@ -83,6 +96,18 @@ note right of Tagged::create
int $verse
string $tag
end note
+
+note right of Tagged::createForLinker
+ Create a Tagged verse for a linker using a system tagged verse
+
+ since: 2.0.1
+ return: bool
+
+ arguments:
+ string $linker
+ object $tagged
+ int $published = -2
+end note
@enduml
```
diff --git a/src/2315a1c5-bcf6-401a-8d11-60f4d6d12dbb/code.php b/src/2315a1c5-bcf6-401a-8d11-60f4d6d12dbb/code.php
index ded04a7..db3d06a 100644
--- a/src/2315a1c5-bcf6-401a-8d11-60f4d6d12dbb/code.php
+++ b/src/2315a1c5-bcf6-401a-8d11-60f4d6d12dbb/code.php
@@ -12,12 +12,16 @@
namespace VDM\Joomla\GetBible;
-use Joomla\CMS\Language\Text;
+use Joomla\Registry\Registry;
+use Joomla\CMS\Language\Text;
+use Joomla\CMS\Application\CMSApplication;
+use Joomla\CMS\Factory;
use VDM\Joomla\GetBible\Database\Load;
use VDM\Joomla\GetBible\Database\Insert;
use VDM\Joomla\GetBible\Database\Update;
use VDM\Joomla\GetBible\Linker;
use VDM\Joomla\Utilities\GuidHelper;
+use VDM\Joomla\Utilities\Component\Helper;
/**
@@ -59,13 +63,31 @@ final class Tagged
*/
protected Linker $linker;
+ /**
+ * The Registry class
+ *
+ * @var Registry
+ * @since 2.0.1
+ */
+ protected Registry $params;
+
+ /**
+ * Application object.
+ *
+ * @var CMSApplication
+ * @since 3.2.0
+ **/
+ protected CMSApplication $app;
+
/**
* Constructor
*
- * @param Load $load The load object.
- * @param Insert $insert The insert object.
- * @param Update $update The update object.
- * @param Linker $linker The linker object.
+ * @param Load $load The load object.
+ * @param Insert $insert The insert object.
+ * @param Update $update The update object.
+ * @param Linker $linker The linker object.
+ * @param Registry|null $params The params object.
+ * @param CMSApplication|null $app The app object.
*
* @since 2.0.1
*/
@@ -73,12 +95,16 @@ final class Tagged
Load $load,
Insert $insert,
Update $update,
- Linker $linker)
+ Linker $linker,
+ ?Registry $params = null,
+ ?CMSApplication $app = null)
{
$this->load = $load;
$this->insert = $insert;
$this->update = $update;
$this->linker = $linker;
+ $this->params = $params ?: Helper::getParams('com_getbible');
+ $this->app = $app ?: Factory::getApplication();
}
/**
@@ -119,27 +145,27 @@ final class Tagged
];
}
- // get tag if it exist
- if (($_tag = $this->get($linker, $book, $chapter, $verse, $tag)) !== null)
+ // get tagged verse if it exist
+ if (($tagged = $this->get($linker, $book, $chapter, $verse, $tag)) !== null)
{
// publish if not published
- if ($_tag->published != 1 && !$this->update->value(1, 'published', $_tag->id, 'id', 'tagged_verse'))
+ if ($tagged->published != 1 && !$this->update->value(1, 'published', $tagged->id, 'id', 'tagged_verse'))
{
return [
'error' => Text::_('COM_GETBIBLE_TAGGED_VERSE_ALREADY_EXIST_BUT_COULD_NOT_BE_REACTIVATED')
];
}
- $_tag->published = 1;
- $_tag->success = Text::_('COM_GETBIBLE_THE_VERSE_WAS_SUCCESSFULLY_TAGGED');
- return (array) $_tag;
+ $tagged->published = 1;
+ $tagged->success = Text::_('COM_GETBIBLE_THE_VERSE_WAS_SUCCESSFULLY_TAGGED');
+ return (array) $tagged;
}
- // create a new tag
+ // create a new tagged verse
elseif ($this->create($linker, $translation, $book, $chapter, $verse, $tag)
- && ($_tag = $this->get($linker, $book, $chapter, $verse, $tag)) !== null)
+ && ($tagged = $this->get($linker, $book, $chapter, $verse, $tag)) !== null)
{
- $_tag->success = Text::_('COM_GETBIBLE_THE_VERSE_WAS_SUCCESSFULLY_TAGGED');
- return (array) $_tag;
+ $tagged->success = Text::_('COM_GETBIBLE_THE_VERSE_WAS_SUCCESSFULLY_TAGGED');
+ return (array) $tagged;
}
return null;
@@ -148,13 +174,13 @@ final class Tagged
/**
* Delete a tagged verse
*
- * @param string $tag The tagged verse GUID value
+ * @param string $tagged The tagged verse GUID value
*
* @return array|null True on success
* @since 2.0.1
**/
public function delete(
- string $tag
+ string $tagged
): ?array
{
// make sure the linker has access
@@ -167,7 +193,7 @@ final class Tagged
}
// make sure the linker has access to delete this tag
- if (($id = $this->load->value(['linker' => $linker, 'guid' => $tag], 'id', 'tagged_verse')) !== null && $id > 0
+ if (($id = $this->load->value(['linker' => $linker, 'guid' => $tagged], 'id', 'tagged_verse')) !== null && $id > 0
&& $this->update->value(-2, 'published', $id, 'id', 'tagged_verse'))
{
return [
@@ -175,11 +201,46 @@ final class Tagged
];
}
+ // lets check if this is a systems tag
+ if (($_tagged = $this->getByGuid($tagged)) !== null && $_tagged->access == 1)
+ {
+ if ($this->params->get('allow_untagging') == 1
+ && $this->createForLinker($linker, $_tagged, -2))
+ {
+ return [
+ 'success' => Text::_('COM_GETBIBLE_THE_TAG_WAS_SUCCESSFULLY_REMOVED_FROM_THE_VERSE')
+ ];
+ }
+
+ return [
+ 'notice' => Text::sprintf("COM_GETBIBLE_THIS_IS_A_GLOBAL_TAG_SET_BY_US_AT_BSB_FOR_YOUR_CONVENIENCE_WE_HOLD_THE_PRIVILEGE_TO_MODIFY_THESE_TAGS_IF_YOU_BELIEVE_ITS_SET_IN_ERROR_KINDLY_INFORM_US", $this->app->get('sitename'))
+ ];
+ }
+
return [
- 'error' => Text::_('COM_GETBIBLE_THIS_TAG_CAN_NOT_BE_REMOVED')
+ 'error' => Text::_('COM_GETBIBLE_THIS_TAG_COULD_NOT_BE_REMOVED')
];
}
+ /**
+ * Get a tagged verse
+ *
+ * @param string $guid The tagged verse GUID value
+ *
+ * @return object|null Object of the tagged verse values on success
+ * @since 2.0.1
+ **/
+ private function getByGuid(string $guid): ?object
+ {
+ // get tagged verse if it exist
+ if (($tagged = $this->load->item(['guid' => $guid], 'tagged_verse')) !== null)
+ {
+ return $tagged;
+ }
+
+ return null;
+ }
+
/**
* Get a tagged verse
*
@@ -200,8 +261,8 @@ final class Tagged
string $tag
): ?object
{
- // get tag if it exist
- if (($_tag = $this->load->item([
+ // get tagged verse if it exist
+ if (($tagged = $this->load->item([
'linker' => $linker,
'book_nr' => $book,
'chapter' => $chapter,
@@ -209,15 +270,15 @@ final class Tagged
'tag' => $tag
], 'tagged_verse')) !== null)
{
- $_tag->name = $this->load->value([
+ $tagged->name = $this->load->value([
'guid' => $tag
], 'name', 'tag');
- $_tag->description = $this->load->value([
+ $tagged->description = $this->load->value([
'guid' => $tag
], 'description', 'tag');
- return $_tag;
+ return $tagged;
}
return null;
@@ -262,6 +323,42 @@ final class Tagged
'verse' => $verse,
'guid' => $guid
], 'tagged_verse');
+ }
+
+ /**
+ * Create a Tagged verse for a linker using a system tagged verse
+ *
+ * @param string $linker The linker GUID value
+ * @param object $tagged The system tagged verse
+ * @param int $published The new tagged verse state [default trashed = -2]
+ *
+ * @return bool True on success
+ * @since 2.0.1
+ **/
+ private function createForLinker(
+ string $linker,
+ object $tagged,
+ int $published = -2
+ ): bool
+ {
+ $guid = (string) GuidHelper::get();
+ while (!GuidHelper::valid($guid, 'tagged_verse', 0, 'getbible'))
+ {
+ // must always be set
+ $guid = (string) GuidHelper::get();
+ }
+
+ return $this->insert->row([
+ 'tag' => $tagged->tag,
+ 'access' => 0,
+ 'linker' => $linker,
+ 'abbreviation' => $tagged->abbreviation,
+ 'book_nr' => $tagged->book_nr,
+ 'chapter' => $tagged->chapter,
+ 'verse' => $tagged->verse,
+ 'guid' => $guid,
+ 'published' => $published
+ ], 'tagged_verse');
}
}
diff --git a/src/2315a1c5-bcf6-401a-8d11-60f4d6d12dbb/code.power b/src/2315a1c5-bcf6-401a-8d11-60f4d6d12dbb/code.power
index 16a3b40..09b9ff6 100644
--- a/src/2315a1c5-bcf6-401a-8d11-60f4d6d12dbb/code.power
+++ b/src/2315a1c5-bcf6-401a-8d11-60f4d6d12dbb/code.power
@@ -30,13 +30,31 @@
*/
protected Linker $linker;
+ /**
+ * The Registry class
+ *
+ * @var Registry
+ * @since 2.0.1
+ */
+ protected Registry $params;
+
+ /**
+ * Application object.
+ *
+ * @var CMSApplication
+ * @since 3.2.0
+ **/
+ protected CMSApplication $app;
+
/**
* Constructor
*
- * @param Load $load The load object.
- * @param Insert $insert The insert object.
- * @param Update $update The update object.
- * @param Linker $linker The linker object.
+ * @param Load $load The load object.
+ * @param Insert $insert The insert object.
+ * @param Update $update The update object.
+ * @param Linker $linker The linker object.
+ * @param Registry|null $params The params object.
+ * @param CMSApplication|null $app The app object.
*
* @since 2.0.1
*/
@@ -44,12 +62,16 @@
Load $load,
Insert $insert,
Update $update,
- Linker $linker)
+ Linker $linker,
+ ?Registry $params = null,
+ ?CMSApplication $app = null)
{
$this->load = $load;
$this->insert = $insert;
$this->update = $update;
$this->linker = $linker;
+ $this->params = $params ?: Helper::getParams('com_[[[component]]]');
+ $this->app = $app ?: Factory::getApplication();
}
/**
@@ -90,27 +112,27 @@
];
}
- // get tag if it exist
- if (($_tag = $this->get($linker, $book, $chapter, $verse, $tag)) !== null)
+ // get tagged verse if it exist
+ if (($tagged = $this->get($linker, $book, $chapter, $verse, $tag)) !== null)
{
// publish if not published
- if ($_tag->published != 1 && !$this->update->value(1, 'published', $_tag->id, 'id', 'tagged_verse'))
+ if ($tagged->published != 1 && !$this->update->value(1, 'published', $tagged->id, 'id', 'tagged_verse'))
{
return [
'error' => Text::_('Tagged verse already exist, but could not be reactivated.')
];
}
- $_tag->published = 1;
- $_tag->success = Text::_('The verse was successfully tagged.');
- return (array) $_tag;
+ $tagged->published = 1;
+ $tagged->success = Text::_('The verse was successfully tagged.');
+ return (array) $tagged;
}
- // create a new tag
+ // create a new tagged verse
elseif ($this->create($linker, $translation, $book, $chapter, $verse, $tag)
- && ($_tag = $this->get($linker, $book, $chapter, $verse, $tag)) !== null)
+ && ($tagged = $this->get($linker, $book, $chapter, $verse, $tag)) !== null)
{
- $_tag->success = Text::_('The verse was successfully tagged.');
- return (array) $_tag;
+ $tagged->success = Text::_('The verse was successfully tagged.');
+ return (array) $tagged;
}
return null;
@@ -119,13 +141,13 @@
/**
* Delete a tagged verse
*
- * @param string $tag The tagged verse GUID value
+ * @param string $tagged The tagged verse GUID value
*
* @return array|null True on success
* @since 2.0.1
**/
public function delete(
- string $tag
+ string $tagged
): ?array
{
// make sure the linker has access
@@ -138,7 +160,7 @@
}
// make sure the linker has access to delete this tag
- if (($id = $this->load->value(['linker' => $linker, 'guid' => $tag], 'id', 'tagged_verse')) !== null && $id > 0
+ if (($id = $this->load->value(['linker' => $linker, 'guid' => $tagged], 'id', 'tagged_verse')) !== null && $id > 0
&& $this->update->value(-2, 'published', $id, 'id', 'tagged_verse'))
{
return [
@@ -146,11 +168,46 @@
];
}
+ // lets check if this is a systems tag
+ if (($_tagged = $this->getByGuid($tagged)) !== null && $_tagged->access == 1)
+ {
+ if ($this->params->get('allow_untagging') == 1
+ && $this->createForLinker($linker, $_tagged, -2))
+ {
+ return [
+ 'success' => Text::_('The tag was successfully removed from the verse.')
+ ];
+ }
+
+ return [
+ 'notice' => Text::sprintf("This is a global tag, set by us at %s for your convenience. We hold the privilege to modify these tags. If you believe it's set in error, kindly inform us.", $this->app->get('sitename'))
+ ];
+ }
+
return [
- 'error' => Text::_('This tag can not be removed.')
+ 'error' => Text::_('This tag could not be removed.')
];
}
+ /**
+ * Get a tagged verse
+ *
+ * @param string $guid The tagged verse GUID value
+ *
+ * @return object|null Object of the tagged verse values on success
+ * @since 2.0.1
+ **/
+ private function getByGuid(string $guid): ?object
+ {
+ // get tagged verse if it exist
+ if (($tagged = $this->load->item(['guid' => $guid], 'tagged_verse')) !== null)
+ {
+ return $tagged;
+ }
+
+ return null;
+ }
+
/**
* Get a tagged verse
*
@@ -171,8 +228,8 @@
string $tag
): ?object
{
- // get tag if it exist
- if (($_tag = $this->load->item([
+ // get tagged verse if it exist
+ if (($tagged = $this->load->item([
'linker' => $linker,
'book_nr' => $book,
'chapter' => $chapter,
@@ -180,15 +237,15 @@
'tag' => $tag
], 'tagged_verse')) !== null)
{
- $_tag->name = $this->load->value([
+ $tagged->name = $this->load->value([
'guid' => $tag
], 'name', 'tag');
- $_tag->description = $this->load->value([
+ $tagged->description = $this->load->value([
'guid' => $tag
], 'description', 'tag');
- return $_tag;
+ return $tagged;
}
return null;
@@ -233,4 +290,40 @@
'verse' => $verse,
'guid' => $guid
], 'tagged_verse');
+ }
+
+ /**
+ * Create a Tagged verse for a linker using a system tagged verse
+ *
+ * @param string $linker The linker GUID value
+ * @param object $tagged The system tagged verse
+ * @param int $published The new tagged verse state [default trashed = -2]
+ *
+ * @return bool True on success
+ * @since 2.0.1
+ **/
+ private function createForLinker(
+ string $linker,
+ object $tagged,
+ int $published = -2
+ ): bool
+ {
+ $guid = (string) GuidHelper::get();
+ while (!GuidHelper::valid($guid, 'tagged_verse', 0, '[[[component]]]'))
+ {
+ // must always be set
+ $guid = (string) GuidHelper::get();
+ }
+
+ return $this->insert->row([
+ 'tag' => $tagged->tag,
+ 'access' => 0,
+ 'linker' => $linker,
+ 'abbreviation' => $tagged->abbreviation,
+ 'book_nr' => $tagged->book_nr,
+ 'chapter' => $tagged->chapter,
+ 'verse' => $tagged->verse,
+ 'guid' => $guid,
+ 'published' => $published
+ ], 'tagged_verse');
}
\ No newline at end of file
diff --git a/src/2315a1c5-bcf6-401a-8d11-60f4d6d12dbb/settings.json b/src/2315a1c5-bcf6-401a-8d11-60f4d6d12dbb/settings.json
index f1044d8..15c3806 100644
--- a/src/2315a1c5-bcf6-401a-8d11-60f4d6d12dbb/settings.json
+++ b/src/2315a1c5-bcf6-401a-8d11-60f4d6d12dbb/settings.json
@@ -29,11 +29,15 @@
"use_selection4": {
"use": "9c513baf-b279-43fd-ae29-a585c8cbc4f0",
"as": "default"
+ },
+ "use_selection5": {
+ "use": "640b5352-fb09-425f-a26e-cd44eda03f15",
+ "as": "default"
}
},
"namespace": "VDM\\Joomla\\GetBible\\Tagged",
"description": "The GetBible Tagged\r\n\r\n@since 2.0.1",
"licensing_template": "\/**\r\n * @package GetBible\r\n *\r\n * @created 30th May, 2023\r\n * @author Llewellyn van der Merwe \r\n * @git GetBible \r\n * @copyright Copyright (C) 2015 Vast Development Method. All rights reserved.\r\n * @license GNU General Public License version 2 or later; see LICENSE.txt\r\n *\/\r\n",
- "head": "use Joomla\\CMS\\Language\\Text;",
+ "head": "use Joomla\\Registry\\Registry;\r\nuse Joomla\\CMS\\Language\\Text;\r\nuse Joomla\\CMS\\Application\\CMSApplication;\r\nuse Joomla\\CMS\\Factory;",
"composer": ""
}
\ No newline at end of file
diff --git a/src/3af7864b-f1f3-491e-b16f-0504f890086d/code.power b/src/3af7864b-f1f3-491e-b16f-0504f890086d/code.power
index 6f2a88e..4579943 100644
--- a/src/3af7864b-f1f3-491e-b16f-0504f890086d/code.power
+++ b/src/3af7864b-f1f3-491e-b16f-0504f890086d/code.power
@@ -26,7 +26,7 @@
public function __construct(?Input $input = null, ?JoomlaRegistry $params = null)
{
$this->input = $input ?: JoomlaFactory::getApplication()->input;
- $this->params = $params ?: Helper::getParams('com_getbible');
+ $this->params = $params ?: Helper::getParams('com_[[[component]]]');
// run parent constructor
parent::__construct();
diff --git a/src/4cfff1bc-02b3-4c52-9e6e-7ceefb505a32/README.md b/src/4cfff1bc-02b3-4c52-9e6e-7ceefb505a32/README.md
new file mode 100644
index 0000000..4a14697
--- /dev/null
+++ b/src/4cfff1bc-02b3-4c52-9e6e-7ceefb505a32/README.md
@@ -0,0 +1,122 @@
+```
+██████╗ ██████╗ ██╗ ██╗███████╗██████╗
+██╔══██╗██╔═══██╗██║ ██║██╔════╝██╔══██╗
+██████╔╝██║ ██║██║ █╗ ██║█████╗ ██████╔╝
+██╔═══╝ ██║ ██║██║███╗██║██╔══╝ ██╔══██╗
+██║ ╚██████╔╝╚███╔███╔╝███████╗██║ ██║
+╚═╝ ╚═════╝ ╚══╝╚══╝ ╚══════╝╚═╝ ╚═╝
+```
+# final class Paragraphs (Details)
+> namespace: **VDM\Joomla\GetBible\Tagged**
+```uml
+@startuml
+class Paragraphs << (F,LightGreen) >> #Green {
+ - int $previousBook
+ - int $previousChapter
+ - int $previousVerse
+ - int $group
+ - array $paragraphs
+ + get(array $items, string $translation = 'kjv') : array
+ - resetProperties() : void
+ - sortIntoParagraphs(array $items) : void
+ - isNotSequential(object $item) : bool
+ - getKey(object $item) : string
+ - setDetails(object $item, string $key) : void
+ - addVerse(object $item, string $key) : void
+ - updatePrevious(object $item) : void
+ - setUrls(string $translation) : void
+ - setVerseAndName(array $paragraph) : void
+ - setUrl(array $paragraph, string $translation) : void
+}
+
+note right of Paragraphs::get
+ Main function to get sorted paragraphs.
+
+ since: 2.0.1
+ return: array
+end note
+
+note left of Paragraphs::resetProperties
+ Reset properties before getting paragraphs
+
+ since: 2.0.1
+ return: void
+end note
+
+note right of Paragraphs::sortIntoParagraphs
+ Sort items into paragraphs.
+
+ since: 2.0.1
+ return: void
+end note
+
+note left of Paragraphs::isNotSequential
+ Check if a verse is not sequential.
+
+ since: 2.0.1
+ return: bool
+end note
+
+note right of Paragraphs::getKey
+ Generate a key based on the verse item.
+
+ since: 2.0.1
+ return: string
+end note
+
+note left of Paragraphs::setDetails
+ Set details for a verse.
+
+ since: 2.0.1
+ return: void
+end note
+
+note right of Paragraphs::addVerse
+ Add a verse to the paragraphs.
+
+ since: 2.0.1
+ return: void
+end note
+
+note left of Paragraphs::updatePrevious
+ Update the previous verse, book, and chapter to the current one.
+
+ since: 2.0.1
+ return: void
+end note
+
+note right of Paragraphs::setUrls
+ Set URLs for the paragraphs.
+
+ since: 2.0.1
+ return: void
+end note
+
+note left of Paragraphs::setVerseAndName
+ Set verse and name for a paragraph.
+
+ since: 2.0.1
+ return: void
+end note
+
+note right of Paragraphs::setUrl
+ Set URL for a paragraph.
+
+ since: 2.0.1
+ return: void
+end note
+
+@enduml
+```
+
+---
+```
+ ██╗ ██████╗██████╗
+ ██║██╔════╝██╔══██╗
+ ██║██║ ██████╔╝
+██ ██║██║ ██╔══██╗
+╚█████╔╝╚██████╗██████╔╝
+ ╚════╝ ╚═════╝╚═════╝
+```
+> Build with [Joomla Component Builder](https://git.vdm.dev/joomla/Component-Builder)
+
diff --git a/src/4cfff1bc-02b3-4c52-9e6e-7ceefb505a32/code.php b/src/4cfff1bc-02b3-4c52-9e6e-7ceefb505a32/code.php
new file mode 100644
index 0000000..9b46749
--- /dev/null
+++ b/src/4cfff1bc-02b3-4c52-9e6e-7ceefb505a32/code.php
@@ -0,0 +1,275 @@
+
+ * @git GetBible
+ * @copyright Copyright (C) 2015 Vast Development Method. All rights reserved.
+ * @license GNU General Public License version 2 or later; see LICENSE.txt
+ */
+
+namespace VDM\Joomla\GetBible\Tagged;
+
+
+use Joomla\CMS\Router\Route;
+
+
+/**
+ * The GetBible Tagged Paragraphs
+ *
+ * @since 2.0.1
+ */
+final class Paragraphs
+{
+ /**
+ * The Previous Book number
+ *
+ * @var int
+ * @since 2.0.1
+ */
+ private int $previousBook = 0;
+
+ /**
+ * The Previous Chapter number
+ *
+ * @var int
+ * @since 2.0.1
+ */
+ private int $previousChapter = 0;
+
+ /**
+ * The Previous Verse number
+ *
+ * @var int
+ * @since 2.0.1
+ */
+ private int $previousVerse = 0;
+
+ /**
+ * The Current Group number
+ *
+ * @var int
+ * @since 2.0.1
+ */
+ private int $group = 0;
+
+ /**
+ * The paragraphs being build
+ *
+ * @var array
+ * @since 2.0.1
+ */
+ private array $paragraphs = [];
+
+ /**
+ * Main function to get sorted paragraphs.
+ *
+ * @param array $items The items to be sorted into paragraphs.
+ * @param string $translation The translation to be used.
+ *
+ * @return array The sorted paragraphs.
+ * @since 2.0.1
+ */
+ public function get(array $items, string $translation = 'kjv'): array
+ {
+ $this->resetProperties();
+
+ // sort the items by book, chapter, and verse
+ usort($items, function ($a, $b) {
+ if ($a->book_nr != $b->book_nr) {
+ return $a->book_nr - $b->book_nr;
+ }
+ if ($a->chapter != $b->chapter) {
+ return $a->chapter - $b->chapter;
+ }
+ return $a->verse - $b->verse;
+ });
+
+ $this->sortIntoParagraphs($items);
+ $this->setUrls($translation);
+
+ return $this->paragraphs;
+ }
+
+ /**
+ * Reset properties before getting paragraphs
+ *
+ * @return void
+ * @since 2.0.1
+ */
+ private function resetProperties(): void
+ {
+ $this->previousBook = 0;
+ $this->previousChapter = 0;
+ $this->previousVerse = 0;
+ $this->group = 0;
+ $this->paragraphs = [];
+ }
+
+ /**
+ * Sort items into paragraphs.
+ *
+ * @param array $items The items to be sorted into paragraphs.
+ *
+ * @return void
+ * @since 2.0.1
+ */
+ private function sortIntoParagraphs($items): void
+ {
+ foreach ($items as $item)
+ {
+ if ($this->isNotSequential($item))
+ {
+ $this->group++;
+ }
+
+ $key = $this->getKey($item);
+
+ if (empty($this->paragraphs[$key]))
+ {
+ $this->setDetails($item, $key);
+ }
+
+ $this->addVerse($item, $key);
+
+ $this->updatePrevious($item);
+ }
+ }
+
+ /**
+ * Check if a verse is not sequential.
+ *
+ * @param object $item The verse to be checked.
+ *
+ * @return bool Whether the verse is not sequential.
+ * @since 2.0.1
+ */
+ private function isNotSequential(object $item): bool
+ {
+ return $this->previousVerse > 0
+ && ((int) $item->book_nr > $this->previousBook
+ || (int) $item->chapter > $this->previousChapter
+ || (int) $item->verse > $this->previousVerse + 1);
+ }
+
+ /**
+ * Generate a key based on the verse item.
+ *
+ * @param object $item The verse item.
+ *
+ * @return string The generated key.
+ * @since 2.0.1
+ */
+ private function getKey(object $item): string
+ {
+ return $item->book_nr . '_' . $item->chapter . '_' . $this->group;
+ }
+
+ /**
+ * Set details for a verse.
+ *
+ * @param object $item The verse item.
+ * @param string $key The key for the paragraph.
+ *
+ * @return void
+ * @since 2.0.1
+ */
+ private function setDetails(object $item, string $key): void
+ {
+ $this->paragraphs[$key]['name'] = $item->name . ' ' . $item->chapter;
+ $this->paragraphs[$key]['book'] = $item->name;
+ $this->paragraphs[$key]['data_book'] = preg_replace('/[^\p{L}\p{N}\s]/u', '', $item->name);
+ $this->paragraphs[$key]['chapter'] = $item->chapter;
+ }
+
+ /**
+ * Add a verse to the paragraphs.
+ *
+ * @param object $item The verse item.
+ * @param string $key The key for the paragraph.
+ *
+ * @return void
+ * @since 2.0.1
+ */
+ private function addVerse(object $item, string $key): void
+ {
+ $this->paragraphs[$key]['verses'][$item->verse] = ['number' => $item->verse, 'text' => $item->text];
+ }
+
+ /**
+ * Update the previous verse, book, and chapter to the current one.
+ *
+ * @param object $item The current verse item.
+ *
+ * @return void
+ * @since 2.0.1
+ */
+ private function updatePrevious(object $item): void
+ {
+ $this->previousVerse = (int) $item->verse;
+ $this->previousBook = (int) $item->book_nr;
+ $this->previousChapter = (int) $item->chapter;
+ }
+
+ /**
+ * Set URLs for the paragraphs.
+ *
+ * @param string $translation The translation to be used.
+ *
+ * @return void
+ * @since 2.0.1
+ */
+ private function setUrls(string $translation): void
+ {
+ if ($this->paragraphs !== [])
+ {
+ foreach ($this->paragraphs as $chapter => &$paragraph)
+ {
+ $this->setVerseAndName($paragraph);
+ $this->setUrl($paragraph, $translation);
+ }
+ }
+ }
+
+ /**
+ * Set verse and name for a paragraph.
+ *
+ * @param array $paragraph The paragraph to be updated.
+ *
+ * @return void
+ * @since 2.0.1
+ */
+ private function setVerseAndName(array &$paragraph): void
+ {
+ $verse = array_keys($paragraph['verses']);
+ $first = reset($verse);
+ $last = end($verse);
+
+ if ($first == $last)
+ {
+ $paragraph['name'] .= ':' . $first;
+ $paragraph['verse'] = $first;
+ }
+ else
+ {
+ $paragraph['name'] .= ':' . $first . '-' . $last;
+ $paragraph['verse'] = $first . '-' . $last;
+ }
+ }
+
+ /**
+ * Set URL for a paragraph.
+ *
+ * @param array $paragraph The paragraph to be updated.
+ * @param string $translation The translation to be used.
+ *
+ * @return void
+ * @since 2.0.1
+ */
+ private function setUrl(array &$paragraph, string $translation): void
+ {
+ $paragraph['url'] = Route::_('index.php?option=com_getbible&view=app&t=' . $translation . '&ref=' . $paragraph['book'] . '&chapter=' . $paragraph['chapter'] . '&verse=' . $paragraph['verse']);
+ }
+}
+
diff --git a/src/4cfff1bc-02b3-4c52-9e6e-7ceefb505a32/code.power b/src/4cfff1bc-02b3-4c52-9e6e-7ceefb505a32/code.power
new file mode 100644
index 0000000..e8112ec
--- /dev/null
+++ b/src/4cfff1bc-02b3-4c52-9e6e-7ceefb505a32/code.power
@@ -0,0 +1,249 @@
+ /**
+ * The Previous Book number
+ *
+ * @var int
+ * @since 2.0.1
+ */
+ private int $previousBook = 0;
+
+ /**
+ * The Previous Chapter number
+ *
+ * @var int
+ * @since 2.0.1
+ */
+ private int $previousChapter = 0;
+
+ /**
+ * The Previous Verse number
+ *
+ * @var int
+ * @since 2.0.1
+ */
+ private int $previousVerse = 0;
+
+ /**
+ * The Current Group number
+ *
+ * @var int
+ * @since 2.0.1
+ */
+ private int $group = 0;
+
+ /**
+ * The paragraphs being build
+ *
+ * @var array
+ * @since 2.0.1
+ */
+ private array $paragraphs = [];
+
+ /**
+ * Main function to get sorted paragraphs.
+ *
+ * @param array $items The items to be sorted into paragraphs.
+ * @param string $translation The translation to be used.
+ *
+ * @return array The sorted paragraphs.
+ * @since 2.0.1
+ */
+ public function get(array $items, string $translation = 'kjv'): array
+ {
+ $this->resetProperties();
+
+ // sort the items by book, chapter, and verse
+ usort($items, function ($a, $b) {
+ if ($a->book_nr != $b->book_nr) {
+ return $a->book_nr - $b->book_nr;
+ }
+ if ($a->chapter != $b->chapter) {
+ return $a->chapter - $b->chapter;
+ }
+ return $a->verse - $b->verse;
+ });
+
+ $this->sortIntoParagraphs($items);
+ $this->setUrls($translation);
+
+ return $this->paragraphs;
+ }
+
+ /**
+ * Reset properties before getting paragraphs
+ *
+ * @return void
+ * @since 2.0.1
+ */
+ private function resetProperties(): void
+ {
+ $this->previousBook = 0;
+ $this->previousChapter = 0;
+ $this->previousVerse = 0;
+ $this->group = 0;
+ $this->paragraphs = [];
+ }
+
+ /**
+ * Sort items into paragraphs.
+ *
+ * @param array $items The items to be sorted into paragraphs.
+ *
+ * @return void
+ * @since 2.0.1
+ */
+ private function sortIntoParagraphs($items): void
+ {
+ foreach ($items as $item)
+ {
+ if ($this->isNotSequential($item))
+ {
+ $this->group++;
+ }
+
+ $key = $this->getKey($item);
+
+ if (empty($this->paragraphs[$key]))
+ {
+ $this->setDetails($item, $key);
+ }
+
+ $this->addVerse($item, $key);
+
+ $this->updatePrevious($item);
+ }
+ }
+
+ /**
+ * Check if a verse is not sequential.
+ *
+ * @param object $item The verse to be checked.
+ *
+ * @return bool Whether the verse is not sequential.
+ * @since 2.0.1
+ */
+ private function isNotSequential(object $item): bool
+ {
+ return $this->previousVerse > 0
+ && ((int) $item->book_nr > $this->previousBook
+ || (int) $item->chapter > $this->previousChapter
+ || (int) $item->verse > $this->previousVerse + 1);
+ }
+
+ /**
+ * Generate a key based on the verse item.
+ *
+ * @param object $item The verse item.
+ *
+ * @return string The generated key.
+ * @since 2.0.1
+ */
+ private function getKey(object $item): string
+ {
+ return $item->book_nr . '_' . $item->chapter . '_' . $this->group;
+ }
+
+ /**
+ * Set details for a verse.
+ *
+ * @param object $item The verse item.
+ * @param string $key The key for the paragraph.
+ *
+ * @return void
+ * @since 2.0.1
+ */
+ private function setDetails(object $item, string $key): void
+ {
+ $this->paragraphs[$key]['name'] = $item->name . ' ' . $item->chapter;
+ $this->paragraphs[$key]['book'] = $item->name;
+ $this->paragraphs[$key]['data_book'] = preg_replace('/[^\p{L}\p{N}\s]/u', '', $item->name);
+ $this->paragraphs[$key]['chapter'] = $item->chapter;
+ }
+
+ /**
+ * Add a verse to the paragraphs.
+ *
+ * @param object $item The verse item.
+ * @param string $key The key for the paragraph.
+ *
+ * @return void
+ * @since 2.0.1
+ */
+ private function addVerse(object $item, string $key): void
+ {
+ $this->paragraphs[$key]['verses'][$item->verse] = ['number' => $item->verse, 'text' => $item->text];
+ }
+
+ /**
+ * Update the previous verse, book, and chapter to the current one.
+ *
+ * @param object $item The current verse item.
+ *
+ * @return void
+ * @since 2.0.1
+ */
+ private function updatePrevious(object $item): void
+ {
+ $this->previousVerse = (int) $item->verse;
+ $this->previousBook = (int) $item->book_nr;
+ $this->previousChapter = (int) $item->chapter;
+ }
+
+ /**
+ * Set URLs for the paragraphs.
+ *
+ * @param string $translation The translation to be used.
+ *
+ * @return void
+ * @since 2.0.1
+ */
+ private function setUrls(string $translation): void
+ {
+ if ($this->paragraphs !== [])
+ {
+ foreach ($this->paragraphs as $chapter => &$paragraph)
+ {
+ $this->setVerseAndName($paragraph);
+ $this->setUrl($paragraph, $translation);
+ }
+ }
+ }
+
+ /**
+ * Set verse and name for a paragraph.
+ *
+ * @param array $paragraph The paragraph to be updated.
+ *
+ * @return void
+ * @since 2.0.1
+ */
+ private function setVerseAndName(array &$paragraph): void
+ {
+ $verse = array_keys($paragraph['verses']);
+ $first = reset($verse);
+ $last = end($verse);
+
+ if ($first == $last)
+ {
+ $paragraph['name'] .= ':' . $first;
+ $paragraph['verse'] = $first;
+ }
+ else
+ {
+ $paragraph['name'] .= ':' . $first . '-' . $last;
+ $paragraph['verse'] = $first . '-' . $last;
+ }
+ }
+
+ /**
+ * Set URL for a paragraph.
+ *
+ * @param array $paragraph The paragraph to be updated.
+ * @param string $translation The translation to be used.
+ *
+ * @return void
+ * @since 2.0.1
+ */
+ private function setUrl(array &$paragraph, string $translation): void
+ {
+ $paragraph['url'] = Route::_('index.php?option=com_[[[component]]]&view=app&t=' . $translation . '&ref=' . $paragraph['book'] . '&chapter=' . $paragraph['chapter'] . '&verse=' . $paragraph['verse']);
+ }
\ No newline at end of file
diff --git a/src/4cfff1bc-02b3-4c52-9e6e-7ceefb505a32/settings.json b/src/4cfff1bc-02b3-4c52-9e6e-7ceefb505a32/settings.json
new file mode 100644
index 0000000..d6cf6f4
--- /dev/null
+++ b/src/4cfff1bc-02b3-4c52-9e6e-7ceefb505a32/settings.json
@@ -0,0 +1,18 @@
+{
+ "add_head": "1",
+ "add_licensing_template": "2",
+ "extends": "0",
+ "guid": "4cfff1bc-02b3-4c52-9e6e-7ceefb505a32",
+ "implements": null,
+ "load_selection": null,
+ "name": "Paragraphs",
+ "power_version": "1.0.0",
+ "system_name": "Joomla.GetBible.Tagged.Paragraphs",
+ "type": "final class",
+ "use_selection": null,
+ "namespace": "VDM\\Joomla\\GetBible\\Tagged.Paragraphs",
+ "description": "The GetBible Tagged Paragraphs\r\n\r\n@since 2.0.1",
+ "licensing_template": "\/**\r\n * @package GetBible\r\n *\r\n * @created 30th May, 2023\r\n * @author Llewellyn van der Merwe \r\n * @git GetBible \r\n * @copyright Copyright (C) 2015 Vast Development Method. All rights reserved.\r\n * @license GNU General Public License version 2 or later; see LICENSE.txt\r\n *\/\r\n",
+ "head": "use Joomla\\CMS\\Router\\Route;",
+ "composer": ""
+}
\ No newline at end of file
diff --git a/src/56465044-94ed-4e00-b6db-160c67163df8/README.md b/src/56465044-94ed-4e00-b6db-160c67163df8/README.md
index aa5546d..faf71f4 100644
--- a/src/56465044-94ed-4e00-b6db-160c67163df8/README.md
+++ b/src/56465044-94ed-4e00-b6db-160c67163df8/README.md
@@ -21,6 +21,7 @@ class App #Gold {
+ getNote(Container $container) : Note
+ getTag(Container $container) : Tag
+ getTagged(Container $container) : Tagged
+ + getTaggedParagraphs(Container $container) : Paragraphs
}
note right of App::register
@@ -92,6 +93,13 @@ note left of App::getTagged
since: 2.0.1
return: Tagged
end note
+
+note right of App::getTaggedParagraphs
+ Get the Paragraphs class
+
+ since: 2.0.1
+ return: Paragraphs
+end note
@enduml
```
diff --git a/src/56465044-94ed-4e00-b6db-160c67163df8/code.php b/src/56465044-94ed-4e00-b6db-160c67163df8/code.php
index 8ceb871..6d8ec7f 100644
--- a/src/56465044-94ed-4e00-b6db-160c67163df8/code.php
+++ b/src/56465044-94ed-4e00-b6db-160c67163df8/code.php
@@ -23,6 +23,7 @@ use VDM\Joomla\GetBible\Linker;
use VDM\Joomla\GetBible\Note;
use VDM\Joomla\GetBible\Tag;
use VDM\Joomla\GetBible\Tagged;
+use VDM\Joomla\GetBible\Tagged\Paragraphs;
/**
@@ -68,6 +69,9 @@ class App implements ServiceProviderInterface
$container->alias(Tagged::class, 'GetBible.Tagged')
->share('GetBible.Tagged', [$this, 'getTagged'], true);
+
+ $container->alias(Paragraphs::class, 'GetBible.Tagged.Paragraphs')
+ ->share('GetBible.Tagged.Paragraphs', [$this, 'getTaggedParagraphs'], true);
}
/**
@@ -217,6 +221,19 @@ class App implements ServiceProviderInterface
$container->get('GetBible.Update'),
$container->get('GetBible.Linker')
);
+ }
+
+ /**
+ * Get the Paragraphs class
+ *
+ * @param Container $container The DI container.
+ *
+ * @return Paragraphs
+ * @since 2.0.1
+ */
+ public function getTaggedParagraphs(Container $container): Paragraphs
+ {
+ return new Paragraphs();
}
}
diff --git a/src/56465044-94ed-4e00-b6db-160c67163df8/code.power b/src/56465044-94ed-4e00-b6db-160c67163df8/code.power
index 07e385b..b8b7a3b 100644
--- a/src/56465044-94ed-4e00-b6db-160c67163df8/code.power
+++ b/src/56465044-94ed-4e00-b6db-160c67163df8/code.power
@@ -34,6 +34,9 @@
$container->alias(Tagged::class, 'GetBible.Tagged')
->share('GetBible.Tagged', [$this, 'getTagged'], true);
+
+ $container->alias(Paragraphs::class, 'GetBible.Tagged.Paragraphs')
+ ->share('GetBible.Tagged.Paragraphs', [$this, 'getTaggedParagraphs'], true);
}
/**
@@ -183,4 +186,17 @@
$container->get('GetBible.Update'),
$container->get('GetBible.Linker')
);
+ }
+
+ /**
+ * Get the Paragraphs class
+ *
+ * @param Container $container The DI container.
+ *
+ * @return Paragraphs
+ * @since 2.0.1
+ */
+ public function getTaggedParagraphs(Container $container): Paragraphs
+ {
+ return new Paragraphs();
}
\ No newline at end of file
diff --git a/src/56465044-94ed-4e00-b6db-160c67163df8/settings.json b/src/56465044-94ed-4e00-b6db-160c67163df8/settings.json
index bc6087b..1de5401 100644
--- a/src/56465044-94ed-4e00-b6db-160c67163df8/settings.json
+++ b/src/56465044-94ed-4e00-b6db-160c67163df8/settings.json
@@ -47,6 +47,10 @@
"use_selection8": {
"use": "2315a1c5-bcf6-401a-8d11-60f4d6d12dbb",
"as": "default"
+ },
+ "use_selection9": {
+ "use": "4cfff1bc-02b3-4c52-9e6e-7ceefb505a32",
+ "as": "default"
}
},
"namespace": "VDM\\Joomla\\GetBible\\Service.App",
diff --git a/src/c03b9c61-17d3-4774-a335-783903719f83/README.md b/src/c03b9c61-17d3-4774-a335-783903719f83/README.md
index ae12754..f5aae96 100644
--- a/src/c03b9c61-17d3-4774-a335-783903719f83/README.md
+++ b/src/c03b9c61-17d3-4774-a335-783903719f83/README.md
@@ -16,7 +16,8 @@ class Load << (F,LightGreen) >> #Green {
# Database $load
+ __construct(Table $table, Model $model, ...)
+ value(array $keys, string $field, ...) : mixed
- + max(array $keys, string $field, ...) : mixed
+ + max(array $filter, string $field, ...) : ?int
+ + count(array $filter, string $table) : ?int
+ item(array $keys, string $table) : ?object
+ items(array $keys, string $table) : ?array
- prefix(array $keys) : array
@@ -54,8 +55,8 @@ Example: $this->value(
end note
note right of Load::max
- Get the max value from a given table
-Example: $this->value(
+ Get the max value based on a filtered result from a given table
+Example: $this->max(
[
'abbreviation' => 'kjv',
'book_nr' => 62,
@@ -65,14 +66,29 @@ Example: $this->value(
);
since: 2.0.1
- return: mixed
+ return: ?int
arguments:
- array $keys
+ array $filter
string $field
string $table
end note
+note right of Load::count
+ Count the number of items based on filter result from a given table
+Example: $this->count(
+[
+'abbreviation' => 'kjv',
+'book_nr' => 62,
+'chapter' => 3,
+'verse' => 16
+], 'table_name'
+);
+
+ since: 2.0.1
+ return: ?int
+end note
+
note right of Load::item
Get values from a given table
Example: $this->item(
diff --git a/src/c03b9c61-17d3-4774-a335-783903719f83/code.php b/src/c03b9c61-17d3-4774-a335-783903719f83/code.php
index 7bc07b5..86ba1ee 100644
--- a/src/c03b9c61-17d3-4774-a335-783903719f83/code.php
+++ b/src/c03b9c61-17d3-4774-a335-783903719f83/code.php
@@ -102,8 +102,8 @@ final class Load
}
/**
- * Get the max value from a given table
- * Example: $this->value(
+ * Get the max value based on a filtered result from a given table
+ * Example: $this->max(
* [
* 'abbreviation' => 'kjv',
* 'book_nr' => 62,
@@ -112,26 +112,53 @@ final class Load
* ], 'value_key', 'table_name'
* );
*
- * @param array $keys The item keys
+ * @param array $filter The filter keys
* @param string $field The field key
* @param string $table The table
*
- * @return mixed
+ * @return int|null
* @since 2.0.1
*/
- public function max(array $keys, string $field, string $table)
+ public function max(array $filter, string $field, string $table): ?int
{
// check if this is a valid table
if ($this->table->exist($table, $field))
{
- return $this->model->value(
- $this->load->value(
- ["all" => "MAX(`$field`)"],
- ['a' => $table],
- $this->prefix($keys)
- ),
+ return $this->load->max(
$field,
- $table
+ ['a' => $table],
+ $this->prefix($filter)
+ );
+ }
+
+ return null;
+ }
+
+ /**
+ * Count the number of items based on filter result from a given table
+ * Example: $this->count(
+ * [
+ * 'abbreviation' => 'kjv',
+ * 'book_nr' => 62,
+ * 'chapter' => 3,
+ * 'verse' => 16
+ * ], 'table_name'
+ * );
+ *
+ * @param array $filter The filter keys
+ * @param string $table The table
+ *
+ * @return int|null
+ * @since 2.0.1
+ */
+ public function count(array $filter, string $table): ?int
+ {
+ // check if this is a valid table
+ if ($this->table->exist($table))
+ {
+ return $this->load->count(
+ ['a' => $table],
+ $this->prefix($filter)
);
}
diff --git a/src/c03b9c61-17d3-4774-a335-783903719f83/code.power b/src/c03b9c61-17d3-4774-a335-783903719f83/code.power
index b448145..1040256 100644
--- a/src/c03b9c61-17d3-4774-a335-783903719f83/code.power
+++ b/src/c03b9c61-17d3-4774-a335-783903719f83/code.power
@@ -76,8 +76,8 @@
}
/**
- * Get the max value from a given table
- * Example: $this->value(
+ * Get the max value based on a filtered result from a given table
+ * Example: $this->max(
* [
* 'abbreviation' => 'kjv',
* 'book_nr' => 62,
@@ -86,26 +86,53 @@
* ], 'value_key', 'table_name'
* );
*
- * @param array $keys The item keys
+ * @param array $filter The filter keys
* @param string $field The field key
* @param string $table The table
*
- * @return mixed
+ * @return int|null
* @since 2.0.1
*/
- public function max(array $keys, string $field, string $table)
+ public function max(array $filter, string $field, string $table): ?int
{
// check if this is a valid table
if ($this->table->exist($table, $field))
{
- return $this->model->value(
- $this->load->value(
- ["all" => "MAX(`$field`)"],
- ['a' => $table],
- $this->prefix($keys)
- ),
+ return $this->load->max(
$field,
- $table
+ ['a' => $table],
+ $this->prefix($filter)
+ );
+ }
+
+ return null;
+ }
+
+ /**
+ * Count the number of items based on filter result from a given table
+ * Example: $this->count(
+ * [
+ * 'abbreviation' => 'kjv',
+ * 'book_nr' => 62,
+ * 'chapter' => 3,
+ * 'verse' => 16
+ * ], 'table_name'
+ * );
+ *
+ * @param array $filter The filter keys
+ * @param string $table The table
+ *
+ * @return int|null
+ * @since 2.0.1
+ */
+ public function count(array $filter, string $table): ?int
+ {
+ // check if this is a valid table
+ if ($this->table->exist($table))
+ {
+ return $this->load->count(
+ ['a' => $table],
+ $this->prefix($filter)
);
}
diff --git a/src/f815fb33-f721-48a5-a84e-53f1986e8881/README.md b/src/f815fb33-f721-48a5-a84e-53f1986e8881/README.md
index 6b00696..6dbbba6 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, ...)
+ isNew() : bool
+ + enoughVerses(string $translation = 'kjv') : bool
+ + totalVerses(string $translation = 'kjv') : ?int
+ api(string $translation, int $book, ...) : bool
+ getNextChapter(string $translation, int $book, ...) : ?int
+ getPreviousChapter(int $chapter, bool $force = false) : ?int
@@ -62,6 +64,20 @@ note left of Watcher::isNew
return: bool
end note
+note right of Watcher::enoughVerses
+ Check if a translation has enough verses
+
+ since: 2.0.1
+ return: bool
+end note
+
+note left of Watcher::totalVerses
+ Get the total number of verses in the database of a given translation
+
+ since: 2.0.1
+ return: ?int
+end note
+
note right of Watcher::api
Watching that the local Database and API is in sync
diff --git a/src/f815fb33-f721-48a5-a84e-53f1986e8881/code.php b/src/f815fb33-f721-48a5-a84e-53f1986e8881/code.php
index 4c09de7..4c65a1b 100644
--- a/src/f815fb33-f721-48a5-a84e-53f1986e8881/code.php
+++ b/src/f815fb33-f721-48a5-a84e-53f1986e8881/code.php
@@ -154,6 +154,41 @@ final class Watcher
return $this->fresh;
}
+ /**
+ * Check if a translation has enough verses
+ *
+ * @param string $translation The translation.
+ *
+ * @return bool
+ * @since 2.0.1
+ */
+ public function enoughVerses(string $translation = 'kjv'): bool
+ {
+ $total = $this->totalVerses($translation);
+
+ if ($total < 10000)
+ {
+ return false;
+ }
+
+ return true;
+ }
+
+ /**
+ * Get the total number of verses in the database of a given translation
+ *
+ * @param string $translation The translation.
+ *
+ * @return int|null
+ * @since 2.0.1
+ */
+ public function totalVerses(string $translation = 'kjv'): ?int
+ {
+ return $this->load->count(
+ ['abbreviation' => $translation], 'verse'
+ );
+ }
+
/**
* Watching that the local Database and API is in sync
*
diff --git a/src/f815fb33-f721-48a5-a84e-53f1986e8881/code.power b/src/f815fb33-f721-48a5-a84e-53f1986e8881/code.power
index 17d2607..43a8b0d 100644
--- a/src/f815fb33-f721-48a5-a84e-53f1986e8881/code.power
+++ b/src/f815fb33-f721-48a5-a84e-53f1986e8881/code.power
@@ -123,6 +123,41 @@
return $this->fresh;
}
+ /**
+ * Check if a translation has enough verses
+ *
+ * @param string $translation The translation.
+ *
+ * @return bool
+ * @since 2.0.1
+ */
+ public function enoughVerses(string $translation = 'kjv'): bool
+ {
+ $total = $this->totalVerses($translation);
+
+ if ($total < 10000)
+ {
+ return false;
+ }
+
+ return true;
+ }
+
+ /**
+ * Get the total number of verses in the database of a given translation
+ *
+ * @param string $translation The translation.
+ *
+ * @return int|null
+ * @since 2.0.1
+ */
+ public function totalVerses(string $translation = 'kjv'): ?int
+ {
+ return $this->load->count(
+ ['abbreviation' => $translation], 'verse'
+ );
+ }
+
/**
* Watching that the local Database and API is in sync
*
diff --git a/super-powers.json b/super-powers.json
index b1f4e1b..103b583 100644
--- a/super-powers.json
+++ b/super-powers.json
@@ -120,6 +120,17 @@
"spk": "Super__4a4c786d_51f4_421a_aa61_262dfd071880__Power",
"guid": "4a4c786d-51f4-421a-aa61-262dfd071880"
},
+ "4cfff1bc-02b3-4c52-9e6e-7ceefb505a32": {
+ "name": "Paragraphs",
+ "type": "final class",
+ "namespace": "VDM\\Joomla\\GetBible\\Tagged",
+ "code": "src\/4cfff1bc-02b3-4c52-9e6e-7ceefb505a32\/code.php",
+ "power": "src\/4cfff1bc-02b3-4c52-9e6e-7ceefb505a32\/code.power",
+ "settings": "src\/4cfff1bc-02b3-4c52-9e6e-7ceefb505a32\/settings.json",
+ "path": "src\/4cfff1bc-02b3-4c52-9e6e-7ceefb505a32",
+ "spk": "Super__4cfff1bc_02b3_4c52_9e6e_7ceefb505a32__Power",
+ "guid": "4cfff1bc-02b3-4c52-9e6e-7ceefb505a32"
+ },
"51bb0397-fa7c-4f7a-a4c5-1f95fdacad38": {
"name": "Database",
"type": "class",