update 2023-07-24 18:13:46
This commit is contained in:
parent
9c017aecfe
commit
e28936034f
@ -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 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 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
|
- **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)
|
- **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
|
- **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
|
||||||
|
@ -15,11 +15,15 @@ class Tagged << (F,LightGreen) >> #Green {
|
|||||||
# Insert $insert
|
# Insert $insert
|
||||||
# Update $update
|
# Update $update
|
||||||
# Linker $linker
|
# Linker $linker
|
||||||
|
# Registry $params
|
||||||
|
# CMSApplication $app
|
||||||
+ __construct(Load $load, Insert $insert, ...)
|
+ __construct(Load $load, Insert $insert, ...)
|
||||||
+ set(string $translation, int $book, ...) : ?array
|
+ set(string $translation, int $book, ...) : ?array
|
||||||
+ delete(string $tag) : ?array
|
+ delete(string $tagged) : ?array
|
||||||
|
- getByGuid(string $guid) : ?object
|
||||||
- get(string $linker, int $book, ...) : ?object
|
- get(string $linker, int $book, ...) : ?object
|
||||||
- create(string $linker, string $translation, ...) : bool
|
- create(string $linker, string $translation, ...) : bool
|
||||||
|
- createForLinker(string $linker, object $tagged, ...) : bool
|
||||||
}
|
}
|
||||||
|
|
||||||
note right of Tagged::__construct
|
note right of Tagged::__construct
|
||||||
@ -32,6 +36,8 @@ note right of Tagged::__construct
|
|||||||
Insert $insert
|
Insert $insert
|
||||||
Update $update
|
Update $update
|
||||||
Linker $linker
|
Linker $linker
|
||||||
|
?Registry $params = null
|
||||||
|
?CMSApplication $app = null
|
||||||
end note
|
end note
|
||||||
|
|
||||||
note right of Tagged::set
|
note right of Tagged::set
|
||||||
@ -55,6 +61,13 @@ note right of Tagged::delete
|
|||||||
return: ?array
|
return: ?array
|
||||||
end note
|
end note
|
||||||
|
|
||||||
|
note right of Tagged::getByGuid
|
||||||
|
Get a tagged verse
|
||||||
|
|
||||||
|
since: 2.0.1
|
||||||
|
return: ?object
|
||||||
|
end note
|
||||||
|
|
||||||
note right of Tagged::get
|
note right of Tagged::get
|
||||||
Get a tagged verse
|
Get a tagged verse
|
||||||
|
|
||||||
@ -84,6 +97,18 @@ note right of Tagged::create
|
|||||||
string $tag
|
string $tag
|
||||||
end note
|
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
|
@enduml
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -12,12 +12,16 @@
|
|||||||
namespace VDM\Joomla\GetBible;
|
namespace VDM\Joomla\GetBible;
|
||||||
|
|
||||||
|
|
||||||
|
use Joomla\Registry\Registry;
|
||||||
use Joomla\CMS\Language\Text;
|
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\Load;
|
||||||
use VDM\Joomla\GetBible\Database\Insert;
|
use VDM\Joomla\GetBible\Database\Insert;
|
||||||
use VDM\Joomla\GetBible\Database\Update;
|
use VDM\Joomla\GetBible\Database\Update;
|
||||||
use VDM\Joomla\GetBible\Linker;
|
use VDM\Joomla\GetBible\Linker;
|
||||||
use VDM\Joomla\Utilities\GuidHelper;
|
use VDM\Joomla\Utilities\GuidHelper;
|
||||||
|
use VDM\Joomla\Utilities\Component\Helper;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -59,6 +63,22 @@ final class Tagged
|
|||||||
*/
|
*/
|
||||||
protected Linker $linker;
|
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
|
* Constructor
|
||||||
*
|
*
|
||||||
@ -66,6 +86,8 @@ final class Tagged
|
|||||||
* @param Insert $insert The insert object.
|
* @param Insert $insert The insert object.
|
||||||
* @param Update $update The update object.
|
* @param Update $update The update object.
|
||||||
* @param Linker $linker The linker 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
|
* @since 2.0.1
|
||||||
*/
|
*/
|
||||||
@ -73,12 +95,16 @@ final class Tagged
|
|||||||
Load $load,
|
Load $load,
|
||||||
Insert $insert,
|
Insert $insert,
|
||||||
Update $update,
|
Update $update,
|
||||||
Linker $linker)
|
Linker $linker,
|
||||||
|
?Registry $params = null,
|
||||||
|
?CMSApplication $app = null)
|
||||||
{
|
{
|
||||||
$this->load = $load;
|
$this->load = $load;
|
||||||
$this->insert = $insert;
|
$this->insert = $insert;
|
||||||
$this->update = $update;
|
$this->update = $update;
|
||||||
$this->linker = $linker;
|
$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
|
// get tagged verse if it exist
|
||||||
if (($_tag = $this->get($linker, $book, $chapter, $verse, $tag)) !== null)
|
if (($tagged = $this->get($linker, $book, $chapter, $verse, $tag)) !== null)
|
||||||
{
|
{
|
||||||
// publish if not published
|
// 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 [
|
return [
|
||||||
'error' => Text::_('COM_GETBIBLE_TAGGED_VERSE_ALREADY_EXIST_BUT_COULD_NOT_BE_REACTIVATED')
|
'error' => Text::_('COM_GETBIBLE_TAGGED_VERSE_ALREADY_EXIST_BUT_COULD_NOT_BE_REACTIVATED')
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
$_tag->published = 1;
|
$tagged->published = 1;
|
||||||
$_tag->success = Text::_('COM_GETBIBLE_THE_VERSE_WAS_SUCCESSFULLY_TAGGED');
|
$tagged->success = Text::_('COM_GETBIBLE_THE_VERSE_WAS_SUCCESSFULLY_TAGGED');
|
||||||
return (array) $_tag;
|
return (array) $tagged;
|
||||||
}
|
}
|
||||||
// create a new tag
|
// create a new tagged verse
|
||||||
elseif ($this->create($linker, $translation, $book, $chapter, $verse, $tag)
|
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');
|
$tagged->success = Text::_('COM_GETBIBLE_THE_VERSE_WAS_SUCCESSFULLY_TAGGED');
|
||||||
return (array) $_tag;
|
return (array) $tagged;
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
@ -148,13 +174,13 @@ final class Tagged
|
|||||||
/**
|
/**
|
||||||
* Delete a tagged verse
|
* 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
|
* @return array|null True on success
|
||||||
* @since 2.0.1
|
* @since 2.0.1
|
||||||
**/
|
**/
|
||||||
public function delete(
|
public function delete(
|
||||||
string $tag
|
string $tagged
|
||||||
): ?array
|
): ?array
|
||||||
{
|
{
|
||||||
// make sure the linker has access
|
// make sure the linker has access
|
||||||
@ -167,7 +193,7 @@ final class Tagged
|
|||||||
}
|
}
|
||||||
|
|
||||||
// make sure the linker has access to delete this tag
|
// 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'))
|
&& $this->update->value(-2, 'published', $id, 'id', 'tagged_verse'))
|
||||||
{
|
{
|
||||||
return [
|
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 [
|
return [
|
||||||
'error' => Text::_('COM_GETBIBLE_THIS_TAG_CAN_NOT_BE_REMOVED')
|
'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_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
|
* Get a tagged verse
|
||||||
*
|
*
|
||||||
@ -200,8 +261,8 @@ final class Tagged
|
|||||||
string $tag
|
string $tag
|
||||||
): ?object
|
): ?object
|
||||||
{
|
{
|
||||||
// get tag if it exist
|
// get tagged verse if it exist
|
||||||
if (($_tag = $this->load->item([
|
if (($tagged = $this->load->item([
|
||||||
'linker' => $linker,
|
'linker' => $linker,
|
||||||
'book_nr' => $book,
|
'book_nr' => $book,
|
||||||
'chapter' => $chapter,
|
'chapter' => $chapter,
|
||||||
@ -209,15 +270,15 @@ final class Tagged
|
|||||||
'tag' => $tag
|
'tag' => $tag
|
||||||
], 'tagged_verse')) !== null)
|
], 'tagged_verse')) !== null)
|
||||||
{
|
{
|
||||||
$_tag->name = $this->load->value([
|
$tagged->name = $this->load->value([
|
||||||
'guid' => $tag
|
'guid' => $tag
|
||||||
], 'name', 'tag');
|
], 'name', 'tag');
|
||||||
|
|
||||||
$_tag->description = $this->load->value([
|
$tagged->description = $this->load->value([
|
||||||
'guid' => $tag
|
'guid' => $tag
|
||||||
], 'description', 'tag');
|
], 'description', 'tag');
|
||||||
|
|
||||||
return $_tag;
|
return $tagged;
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
@ -263,5 +324,41 @@ final class Tagged
|
|||||||
'guid' => $guid
|
'guid' => $guid
|
||||||
], 'tagged_verse');
|
], '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');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -30,6 +30,22 @@
|
|||||||
*/
|
*/
|
||||||
protected Linker $linker;
|
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
|
* Constructor
|
||||||
*
|
*
|
||||||
@ -37,6 +53,8 @@
|
|||||||
* @param Insert $insert The insert object.
|
* @param Insert $insert The insert object.
|
||||||
* @param Update $update The update object.
|
* @param Update $update The update object.
|
||||||
* @param Linker $linker The linker 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
|
* @since 2.0.1
|
||||||
*/
|
*/
|
||||||
@ -44,12 +62,16 @@
|
|||||||
Load $load,
|
Load $load,
|
||||||
Insert $insert,
|
Insert $insert,
|
||||||
Update $update,
|
Update $update,
|
||||||
Linker $linker)
|
Linker $linker,
|
||||||
|
?Registry $params = null,
|
||||||
|
?CMSApplication $app = null)
|
||||||
{
|
{
|
||||||
$this->load = $load;
|
$this->load = $load;
|
||||||
$this->insert = $insert;
|
$this->insert = $insert;
|
||||||
$this->update = $update;
|
$this->update = $update;
|
||||||
$this->linker = $linker;
|
$this->linker = $linker;
|
||||||
|
$this->params = $params ?: Helper::getParams('com_[[[component]]]');
|
||||||
|
$this->app = $app ?: Factory::getApplication();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -90,27 +112,27 @@
|
|||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
// get tag if it exist
|
// get tagged verse if it exist
|
||||||
if (($_tag = $this->get($linker, $book, $chapter, $verse, $tag)) !== null)
|
if (($tagged = $this->get($linker, $book, $chapter, $verse, $tag)) !== null)
|
||||||
{
|
{
|
||||||
// publish if not published
|
// 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 [
|
return [
|
||||||
'error' => Text::_('Tagged verse already exist, but could not be reactivated.')
|
'error' => Text::_('Tagged verse already exist, but could not be reactivated.')
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
$_tag->published = 1;
|
$tagged->published = 1;
|
||||||
$_tag->success = Text::_('The verse was successfully tagged.');
|
$tagged->success = Text::_('The verse was successfully tagged.');
|
||||||
return (array) $_tag;
|
return (array) $tagged;
|
||||||
}
|
}
|
||||||
// create a new tag
|
// create a new tagged verse
|
||||||
elseif ($this->create($linker, $translation, $book, $chapter, $verse, $tag)
|
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.');
|
$tagged->success = Text::_('The verse was successfully tagged.');
|
||||||
return (array) $_tag;
|
return (array) $tagged;
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
@ -119,13 +141,13 @@
|
|||||||
/**
|
/**
|
||||||
* Delete a tagged verse
|
* 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
|
* @return array|null True on success
|
||||||
* @since 2.0.1
|
* @since 2.0.1
|
||||||
**/
|
**/
|
||||||
public function delete(
|
public function delete(
|
||||||
string $tag
|
string $tagged
|
||||||
): ?array
|
): ?array
|
||||||
{
|
{
|
||||||
// make sure the linker has access
|
// make sure the linker has access
|
||||||
@ -138,7 +160,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
// make sure the linker has access to delete this tag
|
// 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'))
|
&& $this->update->value(-2, 'published', $id, 'id', 'tagged_verse'))
|
||||||
{
|
{
|
||||||
return [
|
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 [
|
return [
|
||||||
'error' => Text::_('This tag can not be removed.')
|
'success' => Text::_('The tag was successfully removed from the verse.')
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return [
|
||||||
|
'notice' => Text::sprintf("This is a global tag, set by us at <b>%s</b> 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 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
|
* Get a tagged verse
|
||||||
*
|
*
|
||||||
@ -171,8 +228,8 @@
|
|||||||
string $tag
|
string $tag
|
||||||
): ?object
|
): ?object
|
||||||
{
|
{
|
||||||
// get tag if it exist
|
// get tagged verse if it exist
|
||||||
if (($_tag = $this->load->item([
|
if (($tagged = $this->load->item([
|
||||||
'linker' => $linker,
|
'linker' => $linker,
|
||||||
'book_nr' => $book,
|
'book_nr' => $book,
|
||||||
'chapter' => $chapter,
|
'chapter' => $chapter,
|
||||||
@ -180,15 +237,15 @@
|
|||||||
'tag' => $tag
|
'tag' => $tag
|
||||||
], 'tagged_verse')) !== null)
|
], 'tagged_verse')) !== null)
|
||||||
{
|
{
|
||||||
$_tag->name = $this->load->value([
|
$tagged->name = $this->load->value([
|
||||||
'guid' => $tag
|
'guid' => $tag
|
||||||
], 'name', 'tag');
|
], 'name', 'tag');
|
||||||
|
|
||||||
$_tag->description = $this->load->value([
|
$tagged->description = $this->load->value([
|
||||||
'guid' => $tag
|
'guid' => $tag
|
||||||
], 'description', 'tag');
|
], 'description', 'tag');
|
||||||
|
|
||||||
return $_tag;
|
return $tagged;
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
@ -234,3 +291,39 @@
|
|||||||
'guid' => $guid
|
'guid' => $guid
|
||||||
], 'tagged_verse');
|
], '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');
|
||||||
|
}
|
@ -29,11 +29,15 @@
|
|||||||
"use_selection4": {
|
"use_selection4": {
|
||||||
"use": "9c513baf-b279-43fd-ae29-a585c8cbc4f0",
|
"use": "9c513baf-b279-43fd-ae29-a585c8cbc4f0",
|
||||||
"as": "default"
|
"as": "default"
|
||||||
|
},
|
||||||
|
"use_selection5": {
|
||||||
|
"use": "640b5352-fb09-425f-a26e-cd44eda03f15",
|
||||||
|
"as": "default"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"namespace": "VDM\\Joomla\\GetBible\\Tagged",
|
"namespace": "VDM\\Joomla\\GetBible\\Tagged",
|
||||||
"description": "The GetBible Tagged\r\n\r\n@since 2.0.1",
|
"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 <https:\/\/dev.vdm.io>\r\n * @git GetBible <https:\/\/git.vdm.dev\/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",
|
"licensing_template": "\/**\r\n * @package GetBible\r\n *\r\n * @created 30th May, 2023\r\n * @author Llewellyn van der Merwe <https:\/\/dev.vdm.io>\r\n * @git GetBible <https:\/\/git.vdm.dev\/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": ""
|
"composer": ""
|
||||||
}
|
}
|
@ -26,7 +26,7 @@
|
|||||||
public function __construct(?Input $input = null, ?JoomlaRegistry $params = null)
|
public function __construct(?Input $input = null, ?JoomlaRegistry $params = null)
|
||||||
{
|
{
|
||||||
$this->input = $input ?: JoomlaFactory::getApplication()->input;
|
$this->input = $input ?: JoomlaFactory::getApplication()->input;
|
||||||
$this->params = $params ?: Helper::getParams('com_getbible');
|
$this->params = $params ?: Helper::getParams('com_[[[component]]]');
|
||||||
|
|
||||||
// run parent constructor
|
// run parent constructor
|
||||||
parent::__construct();
|
parent::__construct();
|
||||||
|
122
src/4cfff1bc-02b3-4c52-9e6e-7ceefb505a32/README.md
Normal file
122
src/4cfff1bc-02b3-4c52-9e6e-7ceefb505a32/README.md
Normal file
@ -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)
|
||||||
|
|
275
src/4cfff1bc-02b3-4c52-9e6e-7ceefb505a32/code.php
Normal file
275
src/4cfff1bc-02b3-4c52-9e6e-7ceefb505a32/code.php
Normal file
@ -0,0 +1,275 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* @package GetBible
|
||||||
|
*
|
||||||
|
* @created 30th May, 2023
|
||||||
|
* @author Llewellyn van der Merwe <https://dev.vdm.io>
|
||||||
|
* @git GetBible <https://git.vdm.dev/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']);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
249
src/4cfff1bc-02b3-4c52-9e6e-7ceefb505a32/code.power
Normal file
249
src/4cfff1bc-02b3-4c52-9e6e-7ceefb505a32/code.power
Normal file
@ -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']);
|
||||||
|
}
|
18
src/4cfff1bc-02b3-4c52-9e6e-7ceefb505a32/settings.json
Normal file
18
src/4cfff1bc-02b3-4c52-9e6e-7ceefb505a32/settings.json
Normal file
@ -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 <https:\/\/dev.vdm.io>\r\n * @git GetBible <https:\/\/git.vdm.dev\/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": ""
|
||||||
|
}
|
@ -21,6 +21,7 @@ class App #Gold {
|
|||||||
+ getNote(Container $container) : Note
|
+ getNote(Container $container) : Note
|
||||||
+ getTag(Container $container) : Tag
|
+ getTag(Container $container) : Tag
|
||||||
+ getTagged(Container $container) : Tagged
|
+ getTagged(Container $container) : Tagged
|
||||||
|
+ getTaggedParagraphs(Container $container) : Paragraphs
|
||||||
}
|
}
|
||||||
|
|
||||||
note right of App::register
|
note right of App::register
|
||||||
@ -93,6 +94,13 @@ note left of App::getTagged
|
|||||||
return: Tagged
|
return: Tagged
|
||||||
end note
|
end note
|
||||||
|
|
||||||
|
note right of App::getTaggedParagraphs
|
||||||
|
Get the Paragraphs class
|
||||||
|
|
||||||
|
since: 2.0.1
|
||||||
|
return: Paragraphs
|
||||||
|
end note
|
||||||
|
|
||||||
@enduml
|
@enduml
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -23,6 +23,7 @@ use VDM\Joomla\GetBible\Linker;
|
|||||||
use VDM\Joomla\GetBible\Note;
|
use VDM\Joomla\GetBible\Note;
|
||||||
use VDM\Joomla\GetBible\Tag;
|
use VDM\Joomla\GetBible\Tag;
|
||||||
use VDM\Joomla\GetBible\Tagged;
|
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')
|
$container->alias(Tagged::class, 'GetBible.Tagged')
|
||||||
->share('GetBible.Tagged', [$this, 'getTagged'], true);
|
->share('GetBible.Tagged', [$this, 'getTagged'], true);
|
||||||
|
|
||||||
|
$container->alias(Paragraphs::class, 'GetBible.Tagged.Paragraphs')
|
||||||
|
->share('GetBible.Tagged.Paragraphs', [$this, 'getTaggedParagraphs'], true);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -218,5 +222,18 @@ class App implements ServiceProviderInterface
|
|||||||
$container->get('GetBible.Linker')
|
$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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -34,6 +34,9 @@
|
|||||||
|
|
||||||
$container->alias(Tagged::class, 'GetBible.Tagged')
|
$container->alias(Tagged::class, 'GetBible.Tagged')
|
||||||
->share('GetBible.Tagged', [$this, 'getTagged'], true);
|
->share('GetBible.Tagged', [$this, 'getTagged'], true);
|
||||||
|
|
||||||
|
$container->alias(Paragraphs::class, 'GetBible.Tagged.Paragraphs')
|
||||||
|
->share('GetBible.Tagged.Paragraphs', [$this, 'getTaggedParagraphs'], true);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -184,3 +187,16 @@
|
|||||||
$container->get('GetBible.Linker')
|
$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();
|
||||||
|
}
|
@ -47,6 +47,10 @@
|
|||||||
"use_selection8": {
|
"use_selection8": {
|
||||||
"use": "2315a1c5-bcf6-401a-8d11-60f4d6d12dbb",
|
"use": "2315a1c5-bcf6-401a-8d11-60f4d6d12dbb",
|
||||||
"as": "default"
|
"as": "default"
|
||||||
|
},
|
||||||
|
"use_selection9": {
|
||||||
|
"use": "4cfff1bc-02b3-4c52-9e6e-7ceefb505a32",
|
||||||
|
"as": "default"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"namespace": "VDM\\Joomla\\GetBible\\Service.App",
|
"namespace": "VDM\\Joomla\\GetBible\\Service.App",
|
||||||
|
@ -16,7 +16,8 @@ class Load << (F,LightGreen) >> #Green {
|
|||||||
# Database $load
|
# Database $load
|
||||||
+ __construct(Table $table, Model $model, ...)
|
+ __construct(Table $table, Model $model, ...)
|
||||||
+ value(array $keys, string $field, ...) : mixed
|
+ 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
|
+ item(array $keys, string $table) : ?object
|
||||||
+ items(array $keys, string $table) : ?array
|
+ items(array $keys, string $table) : ?array
|
||||||
- prefix(array $keys) : array
|
- prefix(array $keys) : array
|
||||||
@ -54,8 +55,8 @@ Example: $this->value(
|
|||||||
end note
|
end note
|
||||||
|
|
||||||
note right of Load::max
|
note right of Load::max
|
||||||
Get the max value from a given table
|
Get the max value based on a filtered result from a given table
|
||||||
Example: $this->value(
|
Example: $this->max(
|
||||||
[
|
[
|
||||||
'abbreviation' => 'kjv',
|
'abbreviation' => 'kjv',
|
||||||
'book_nr' => 62,
|
'book_nr' => 62,
|
||||||
@ -65,14 +66,29 @@ Example: $this->value(
|
|||||||
);
|
);
|
||||||
|
|
||||||
since: 2.0.1
|
since: 2.0.1
|
||||||
return: mixed
|
return: ?int
|
||||||
|
|
||||||
arguments:
|
arguments:
|
||||||
array $keys
|
array $filter
|
||||||
string $field
|
string $field
|
||||||
string $table
|
string $table
|
||||||
end note
|
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
|
note right of Load::item
|
||||||
Get values from a given table
|
Get values from a given table
|
||||||
Example: $this->item(
|
Example: $this->item(
|
||||||
|
@ -102,8 +102,8 @@ final class Load
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the max value from a given table
|
* Get the max value based on a filtered result from a given table
|
||||||
* Example: $this->value(
|
* Example: $this->max(
|
||||||
* [
|
* [
|
||||||
* 'abbreviation' => 'kjv',
|
* 'abbreviation' => 'kjv',
|
||||||
* 'book_nr' => 62,
|
* 'book_nr' => 62,
|
||||||
@ -112,26 +112,53 @@ final class Load
|
|||||||
* ], 'value_key', 'table_name'
|
* ], 'value_key', 'table_name'
|
||||||
* );
|
* );
|
||||||
*
|
*
|
||||||
* @param array $keys The item keys
|
* @param array $filter The filter keys
|
||||||
* @param string $field The field key
|
* @param string $field The field key
|
||||||
* @param string $table The table
|
* @param string $table The table
|
||||||
*
|
*
|
||||||
* @return mixed
|
* @return int|null
|
||||||
* @since 2.0.1
|
* @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
|
// check if this is a valid table
|
||||||
if ($this->table->exist($table, $field))
|
if ($this->table->exist($table, $field))
|
||||||
{
|
{
|
||||||
return $this->model->value(
|
return $this->load->max(
|
||||||
$this->load->value(
|
|
||||||
["all" => "MAX(`$field`)"],
|
|
||||||
['a' => $table],
|
|
||||||
$this->prefix($keys)
|
|
||||||
),
|
|
||||||
$field,
|
$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)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -76,8 +76,8 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the max value from a given table
|
* Get the max value based on a filtered result from a given table
|
||||||
* Example: $this->value(
|
* Example: $this->max(
|
||||||
* [
|
* [
|
||||||
* 'abbreviation' => 'kjv',
|
* 'abbreviation' => 'kjv',
|
||||||
* 'book_nr' => 62,
|
* 'book_nr' => 62,
|
||||||
@ -86,26 +86,53 @@
|
|||||||
* ], 'value_key', 'table_name'
|
* ], 'value_key', 'table_name'
|
||||||
* );
|
* );
|
||||||
*
|
*
|
||||||
* @param array $keys The item keys
|
* @param array $filter The filter keys
|
||||||
* @param string $field The field key
|
* @param string $field The field key
|
||||||
* @param string $table The table
|
* @param string $table The table
|
||||||
*
|
*
|
||||||
* @return mixed
|
* @return int|null
|
||||||
* @since 2.0.1
|
* @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
|
// check if this is a valid table
|
||||||
if ($this->table->exist($table, $field))
|
if ($this->table->exist($table, $field))
|
||||||
{
|
{
|
||||||
return $this->model->value(
|
return $this->load->max(
|
||||||
$this->load->value(
|
|
||||||
["all" => "MAX(`$field`)"],
|
|
||||||
['a' => $table],
|
|
||||||
$this->prefix($keys)
|
|
||||||
),
|
|
||||||
$field,
|
$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)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -23,6 +23,8 @@ class Watcher << (F,LightGreen) >> #Green {
|
|||||||
# ?object $verse
|
# ?object $verse
|
||||||
+ __construct(Load $load, Insert $insert, ...)
|
+ __construct(Load $load, Insert $insert, ...)
|
||||||
+ isNew() : bool
|
+ isNew() : bool
|
||||||
|
+ enoughVerses(string $translation = 'kjv') : bool
|
||||||
|
+ totalVerses(string $translation = 'kjv') : ?int
|
||||||
+ api(string $translation, int $book, ...) : bool
|
+ api(string $translation, int $book, ...) : bool
|
||||||
+ getNextChapter(string $translation, int $book, ...) : ?int
|
+ getNextChapter(string $translation, int $book, ...) : ?int
|
||||||
+ getPreviousChapter(int $chapter, bool $force = false) : ?int
|
+ getPreviousChapter(int $chapter, bool $force = false) : ?int
|
||||||
@ -62,6 +64,20 @@ note left of Watcher::isNew
|
|||||||
return: bool
|
return: bool
|
||||||
end note
|
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
|
note right of Watcher::api
|
||||||
Watching that the local Database and API is in sync
|
Watching that the local Database and API is in sync
|
||||||
|
|
||||||
|
@ -154,6 +154,41 @@ final class Watcher
|
|||||||
return $this->fresh;
|
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
|
* Watching that the local Database and API is in sync
|
||||||
*
|
*
|
||||||
|
@ -123,6 +123,41 @@
|
|||||||
return $this->fresh;
|
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
|
* Watching that the local Database and API is in sync
|
||||||
*
|
*
|
||||||
|
@ -120,6 +120,17 @@
|
|||||||
"spk": "Super__4a4c786d_51f4_421a_aa61_262dfd071880__Power",
|
"spk": "Super__4a4c786d_51f4_421a_aa61_262dfd071880__Power",
|
||||||
"guid": "4a4c786d-51f4-421a-aa61-262dfd071880"
|
"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": {
|
"51bb0397-fa7c-4f7a-a4c5-1f95fdacad38": {
|
||||||
"name": "Database",
|
"name": "Database",
|
||||||
"type": "class",
|
"type": "class",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user