update 2023-07-13 10:31:25
This commit is contained in:
parent
ed1d74c6f6
commit
ae4b57e099
@ -45,7 +45,9 @@ This repository contains an index (see below) of all the approved powers within
|
||||
- **Namespace**: [VDM\Joomla\GetBible\Data](#vdm-joomla-getbible-data)
|
||||
|
||||
- **final class Chapter** | [Details](src/4a4c786d-51f4-421a-aa61-262dfd071880) | [Code](src/4a4c786d-51f4-421a-aa61-262dfd071880/code.php) | [Settings](src/4a4c786d-51f4-421a-aa61-262dfd071880/settings.json) | Super__4a4c786d_51f4_421a_aa61_262dfd071880__Power
|
||||
- **final class Placeholders** | [Details](src/ba2151c0-8ffa-4a07-ba6e-93f135a3e9d5) | [Code](src/ba2151c0-8ffa-4a07-ba6e-93f135a3e9d5/code.php) | [Settings](src/ba2151c0-8ffa-4a07-ba6e-93f135a3e9d5/settings.json) | Super__ba2151c0_8ffa_4a07_ba6e_93f135a3e9d5__Power
|
||||
- **final class Prompt** | [Details](src/3f785d63-a592-463d-9f5f-b2b5a8edd561) | [Code](src/3f785d63-a592-463d-9f5f-b2b5a8edd561/code.php) | [Settings](src/3f785d63-a592-463d-9f5f-b2b5a8edd561/settings.json) | Super__3f785d63_a592_463d_9f5f_b2b5a8edd561__Power
|
||||
- **final class Response** | [Details](src/44c15b17-e096-47c0-8769-42ea9b692cb2) | [Code](src/44c15b17-e096-47c0-8769-42ea9b692cb2/code.php) | [Settings](src/44c15b17-e096-47c0-8769-42ea9b692cb2/settings.json) | Super__44c15b17_e096_47c0_8769_42ea9b692cb2__Power
|
||||
- **final class Translation** | [Details](src/c4098e1a-46dd-4d60-9277-b3668a09edc8) | [Code](src/c4098e1a-46dd-4d60-9277-b3668a09edc8/code.php) | [Settings](src/c4098e1a-46dd-4d60-9277-b3668a09edc8/settings.json) | Super__c4098e1a_46dd_4d60_9277_b3668a09edc8__Power
|
||||
- **Namespace**: [VDM\Joomla\GetBible\Database](#vdm-joomla-getbible-database)
|
||||
|
||||
@ -56,6 +58,9 @@ This repository contains an index (see below) of all the approved powers within
|
||||
|
||||
- **final class Load** | [Details](src/b1bd2b4f-dede-44ad-86e9-2a595a0a9ca0) | [Code](src/b1bd2b4f-dede-44ad-86e9-2a595a0a9ca0/code.php) | [Settings](src/b1bd2b4f-dede-44ad-86e9-2a595a0a9ca0/settings.json) | Super__b1bd2b4f_dede_44ad_86e9_2a595a0a9ca0__Power
|
||||
- **final class Upsert** | [Details](src/91b37bd7-b314-48be-91cf-434ec823bd80) | [Code](src/91b37bd7-b314-48be-91cf-434ec823bd80/code.php) | [Settings](src/91b37bd7-b314-48be-91cf-434ec823bd80/settings.json) | Super__91b37bd7_b314_48be_91cf_434ec823bd80__Power
|
||||
- **Namespace**: [VDM\Joomla\GetBible\Openai](#vdm-joomla-getbible-openai)
|
||||
|
||||
- **class Config** | [Details](src/3af7864b-f1f3-491e-b16f-0504f890086d) | [Code](src/3af7864b-f1f3-491e-b16f-0504f890086d/code.php) | [Settings](src/3af7864b-f1f3-491e-b16f-0504f890086d/settings.json) | Super__3af7864b_f1f3_491e_b16f_0504f890086d__Power
|
||||
- **Namespace**: [VDM\Joomla\GetBible\Service](#vdm-joomla-getbible-service)
|
||||
|
||||
- **class AI** | [Details](src/b2c9493f-692b-426b-af22-c6865f76c2bb) | [Code](src/b2c9493f-692b-426b-af22-c6865f76c2bb/code.php) | [Settings](src/b2c9493f-692b-426b-af22-c6865f76c2bb/settings.json) | Super__b2c9493f_692b_426b_af22_c6865f76c2bb__Power
|
||||
|
@ -14,9 +14,12 @@ class Data #Gold {
|
||||
+ register(Container $container) : void
|
||||
+ getConfig(Container $container) : Config
|
||||
+ getTable(Container $container) : Table
|
||||
+ getString(Container $container) : StringHelper
|
||||
+ getTranslation(Container $container) : Translation
|
||||
+ getChapter(Container $container) : Chapter
|
||||
+ getPrompt(Container $container) : Prompt
|
||||
+ getPlaceholders(Container $container) : Placeholders
|
||||
+ getResponse(Container $container) : Response
|
||||
}
|
||||
|
||||
note right of Data::register
|
||||
@ -26,7 +29,7 @@ note right of Data::register
|
||||
return: void
|
||||
end note
|
||||
|
||||
note right of Data::getConfig
|
||||
note left of Data::getConfig
|
||||
Get the Config class
|
||||
|
||||
since: 2.0.1
|
||||
@ -40,6 +43,13 @@ note right of Data::getTable
|
||||
return: Table
|
||||
end note
|
||||
|
||||
note left of Data::getString
|
||||
Get the String Helper class
|
||||
|
||||
since: 3.2.0
|
||||
return: StringHelper
|
||||
end note
|
||||
|
||||
note right of Data::getTranslation
|
||||
Get the Translation class
|
||||
|
||||
@ -47,7 +57,7 @@ note right of Data::getTranslation
|
||||
return: Translation
|
||||
end note
|
||||
|
||||
note right of Data::getChapter
|
||||
note left of Data::getChapter
|
||||
Get the Chapter class
|
||||
|
||||
since: 3.2.0
|
||||
@ -60,6 +70,20 @@ note right of Data::getPrompt
|
||||
since: 3.2.0
|
||||
return: Prompt
|
||||
end note
|
||||
|
||||
note left of Data::getPlaceholders
|
||||
Get the Placeholders class
|
||||
|
||||
since: 3.2.0
|
||||
return: Placeholders
|
||||
end note
|
||||
|
||||
note right of Data::getResponse
|
||||
Get the Response class
|
||||
|
||||
since: 3.2.0
|
||||
return: Response
|
||||
end note
|
||||
|
||||
@enduml
|
||||
```
|
||||
|
@ -14,11 +14,14 @@ namespace VDM\Joomla\GetBible\Service;
|
||||
|
||||
use Joomla\DI\Container;
|
||||
use Joomla\DI\ServiceProviderInterface;
|
||||
use VDM\Joomla\GetBible\Openai\Config;
|
||||
use VDM\Joomla\GetBible\Table;
|
||||
use VDM\Joomla\GetBible\Config;
|
||||
use VDM\Joomla\GetBible\Utilities\StringHelper;
|
||||
use VDM\Joomla\GetBible\Data\Translation;
|
||||
use VDM\Joomla\GetBible\Data\Chapter;
|
||||
use VDM\Joomla\GetBible\Data\Prompt;
|
||||
use VDM\Joomla\GetBible\Data\Placeholders;
|
||||
use VDM\Joomla\GetBible\Data\Response;
|
||||
|
||||
|
||||
/**
|
||||
@ -44,6 +47,9 @@ class Data implements ServiceProviderInterface
|
||||
$container->alias(Table::class, 'GetBible.Table')
|
||||
->share('GetBible.Table', [$this, 'getTable'], true);
|
||||
|
||||
$container->alias(StringHelper::class, 'GetBible.Utilities.String')
|
||||
->share('GetBible.Utilities.String', [$this, 'getString'], true);
|
||||
|
||||
$container->alias(Translation::class, 'GetBible.Translation')
|
||||
->share('GetBible.Translation', [$this, 'getTranslation'], true);
|
||||
|
||||
@ -52,6 +58,12 @@ class Data implements ServiceProviderInterface
|
||||
|
||||
$container->alias(Prompt::class, 'GetBible.Prompt')
|
||||
->share('GetBible.Prompt', [$this, 'getPrompt'], true);
|
||||
|
||||
$container->alias(Placeholders::class, 'GetBible.Placeholders')
|
||||
->share('GetBible.Placeholders', [$this, 'getPlaceholders'], true);
|
||||
|
||||
$container->alias(Response::class, 'GetBible.Response')
|
||||
->share('GetBible.Response', [$this, 'getResponse'], true);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -80,6 +92,19 @@ class Data implements ServiceProviderInterface
|
||||
return new Table();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the String Helper class
|
||||
*
|
||||
* @param Container $container The DI container.
|
||||
*
|
||||
* @return StringHelper
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function getString(Container $container): StringHelper
|
||||
{
|
||||
return new StringHelper();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Translation class
|
||||
*
|
||||
@ -91,7 +116,8 @@ class Data implements ServiceProviderInterface
|
||||
public function getTranslation(Container $container): Translation
|
||||
{
|
||||
return new Translation(
|
||||
$container->get('GetBible.Load')
|
||||
$container->get('GetBible.Load'),
|
||||
$container->get('GetBible.Config')
|
||||
);
|
||||
}
|
||||
|
||||
@ -106,7 +132,9 @@ class Data implements ServiceProviderInterface
|
||||
public function getChapter(Container $container): Chapter
|
||||
{
|
||||
return new Chapter(
|
||||
$container->get('GetBible.Load')
|
||||
$container->get('GetBible.Load'),
|
||||
$container->get('GetBible.Config'),
|
||||
$container->get('GetBible.Utilities.String')
|
||||
);
|
||||
}
|
||||
|
||||
@ -121,7 +149,42 @@ class Data implements ServiceProviderInterface
|
||||
public function getPrompt(Container $container): Prompt
|
||||
{
|
||||
return new Prompt(
|
||||
$container->get('GetBible.Load')
|
||||
$container->get('GetBible.Load'),
|
||||
$container->get('GetBible.Config')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Placeholders class
|
||||
*
|
||||
* @param Container $container The DI container.
|
||||
*
|
||||
* @return Placeholders
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function getPlaceholders(Container $container): Placeholders
|
||||
{
|
||||
return new Placeholders(
|
||||
$container->get('GetBible.Translation'),
|
||||
$container->get('GetBible.Chapter'),
|
||||
$container->get('GetBible.Prompt')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Response class
|
||||
*
|
||||
* @param Container $container The DI container.
|
||||
*
|
||||
* @return Response
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function getResponse(Container $container): Response
|
||||
{
|
||||
return new Response(
|
||||
$container->get('GetBible.Prompt'),
|
||||
$container->get('GetBible.Load'),
|
||||
$container->get('GetBible.Config')
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -14,6 +14,9 @@
|
||||
$container->alias(Table::class, 'GetBible.Table')
|
||||
->share('GetBible.Table', [$this, 'getTable'], true);
|
||||
|
||||
$container->alias(StringHelper::class, 'GetBible.Utilities.String')
|
||||
->share('GetBible.Utilities.String', [$this, 'getString'], true);
|
||||
|
||||
$container->alias(Translation::class, 'GetBible.Translation')
|
||||
->share('GetBible.Translation', [$this, 'getTranslation'], true);
|
||||
|
||||
@ -22,6 +25,12 @@
|
||||
|
||||
$container->alias(Prompt::class, 'GetBible.Prompt')
|
||||
->share('GetBible.Prompt', [$this, 'getPrompt'], true);
|
||||
|
||||
$container->alias(Placeholders::class, 'GetBible.Placeholders')
|
||||
->share('GetBible.Placeholders', [$this, 'getPlaceholders'], true);
|
||||
|
||||
$container->alias(Response::class, 'GetBible.Response')
|
||||
->share('GetBible.Response', [$this, 'getResponse'], true);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -50,6 +59,19 @@
|
||||
return new Table();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the String Helper class
|
||||
*
|
||||
* @param Container $container The DI container.
|
||||
*
|
||||
* @return StringHelper
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function getString(Container $container): StringHelper
|
||||
{
|
||||
return new StringHelper();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Translation class
|
||||
*
|
||||
@ -61,7 +83,8 @@
|
||||
public function getTranslation(Container $container): Translation
|
||||
{
|
||||
return new Translation(
|
||||
$container->get('GetBible.Load')
|
||||
$container->get('GetBible.Load'),
|
||||
$container->get('GetBible.Config')
|
||||
);
|
||||
}
|
||||
|
||||
@ -76,7 +99,9 @@
|
||||
public function getChapter(Container $container): Chapter
|
||||
{
|
||||
return new Chapter(
|
||||
$container->get('GetBible.Load')
|
||||
$container->get('GetBible.Load'),
|
||||
$container->get('GetBible.Config'),
|
||||
$container->get('GetBible.Utilities.String')
|
||||
);
|
||||
}
|
||||
|
||||
@ -91,6 +116,41 @@
|
||||
public function getPrompt(Container $container): Prompt
|
||||
{
|
||||
return new Prompt(
|
||||
$container->get('GetBible.Load')
|
||||
$container->get('GetBible.Load'),
|
||||
$container->get('GetBible.Config')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Placeholders class
|
||||
*
|
||||
* @param Container $container The DI container.
|
||||
*
|
||||
* @return Placeholders
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function getPlaceholders(Container $container): Placeholders
|
||||
{
|
||||
return new Placeholders(
|
||||
$container->get('GetBible.Translation'),
|
||||
$container->get('GetBible.Chapter'),
|
||||
$container->get('GetBible.Prompt')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Response class
|
||||
*
|
||||
* @param Container $container The DI container.
|
||||
*
|
||||
* @return Response
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function getResponse(Container $container): Response
|
||||
{
|
||||
return new Response(
|
||||
$container->get('GetBible.Prompt'),
|
||||
$container->get('GetBible.Load'),
|
||||
$container->get('GetBible.Config')
|
||||
);
|
||||
}
|
@ -13,24 +13,36 @@
|
||||
"type": "class",
|
||||
"use_selection": {
|
||||
"use_selection0": {
|
||||
"use": "ff8d5fdb-2d1f-4178-bd18-a43b8efd1068",
|
||||
"use": "3af7864b-f1f3-491e-b16f-0504f890086d",
|
||||
"as": "default"
|
||||
},
|
||||
"use_selection1": {
|
||||
"use": "71075f03-4e77-4fc0-840a-ef55fd9260b2",
|
||||
"use": "ff8d5fdb-2d1f-4178-bd18-a43b8efd1068",
|
||||
"as": "default"
|
||||
},
|
||||
"use_selection2": {
|
||||
"use": "c4098e1a-46dd-4d60-9277-b3668a09edc8",
|
||||
"use": "a5b32737-207d-4cf6-b8ae-ee815612c3a0",
|
||||
"as": "default"
|
||||
},
|
||||
"use_selection3": {
|
||||
"use": "4a4c786d-51f4-421a-aa61-262dfd071880",
|
||||
"use": "c4098e1a-46dd-4d60-9277-b3668a09edc8",
|
||||
"as": "default"
|
||||
},
|
||||
"use_selection4": {
|
||||
"use": "4a4c786d-51f4-421a-aa61-262dfd071880",
|
||||
"as": "default"
|
||||
},
|
||||
"use_selection5": {
|
||||
"use": "3f785d63-a592-463d-9f5f-b2b5a8edd561",
|
||||
"as": "default"
|
||||
},
|
||||
"use_selection6": {
|
||||
"use": "ba2151c0-8ffa-4a07-ba6e-93f135a3e9d5",
|
||||
"as": "default"
|
||||
},
|
||||
"use_selection7": {
|
||||
"use": "44c15b17-e096-47c0-8769-42ea9b692cb2",
|
||||
"as": "default"
|
||||
}
|
||||
},
|
||||
"namespace": "VDM\\Joomla\\GetBible\\Service.Data",
|
||||
|
86
src/3af7864b-f1f3-491e-b16f-0504f890086d/README.md
Normal file
86
src/3af7864b-f1f3-491e-b16f-0504f890086d/README.md
Normal file
@ -0,0 +1,86 @@
|
||||
```
|
||||
██████╗ ██████╗ ██╗ ██╗███████╗██████╗
|
||||
██╔══██╗██╔═══██╗██║ ██║██╔════╝██╔══██╗
|
||||
██████╔╝██║ ██║██║ █╗ ██║█████╗ ██████╔╝
|
||||
██╔═══╝ ██║ ██║██║███╗██║██╔══╝ ██╔══██╗
|
||||
██║ ╚██████╔╝╚███╔███╔╝███████╗██║ ██║
|
||||
╚═╝ ╚═════╝ ╚══╝╚══╝ ╚══════╝╚═╝ ╚═╝
|
||||
```
|
||||
# class Config (Details)
|
||||
> namespace: **VDM\Joomla\GetBible\Openai**
|
||||
```uml
|
||||
@startuml
|
||||
class Config #Gold {
|
||||
# Input $input
|
||||
# JoomlaRegistry $params
|
||||
+ __construct(?Input $input = null, ?JoomlaRegistry $params = null)
|
||||
# getPrompt() : ?string
|
||||
# getTranslation() : ?string
|
||||
# getBook() : ?int
|
||||
# getChapter() : ?int
|
||||
# getVerse() : ?string
|
||||
# getWords() : ?string
|
||||
}
|
||||
|
||||
note right of Config::__construct
|
||||
Constructor
|
||||
|
||||
since: 3.2.0
|
||||
end note
|
||||
|
||||
note right of Config::getPrompt
|
||||
get Prompt GUID
|
||||
|
||||
since: 2.0.1
|
||||
return: ?string
|
||||
end note
|
||||
|
||||
note right of Config::getTranslation
|
||||
get Translation Abbreviation
|
||||
|
||||
since: 2.0.1
|
||||
return: ?string
|
||||
end note
|
||||
|
||||
note right of Config::getBook
|
||||
get Book Number
|
||||
|
||||
since: 2.0.1
|
||||
return: ?int
|
||||
end note
|
||||
|
||||
note right of Config::getChapter
|
||||
get Chapter Number
|
||||
|
||||
since: 2.0.1
|
||||
return: ?int
|
||||
end note
|
||||
|
||||
note right of Config::getVerse
|
||||
get Verse Number/s
|
||||
|
||||
since: 2.0.1
|
||||
return: ?string
|
||||
end note
|
||||
|
||||
note right of Config::getWords
|
||||
get Words Number/s
|
||||
|
||||
since: 2.0.1
|
||||
return: ?string
|
||||
end note
|
||||
|
||||
@enduml
|
||||
```
|
||||
|
||||
---
|
||||
```
|
||||
██╗ ██████╗██████╗
|
||||
██║██╔════╝██╔══██╗
|
||||
██║██║ ██████╔╝
|
||||
██ ██║██║ ██╔══██╗
|
||||
╚█████╔╝╚██████╗██████╔╝
|
||||
╚════╝ ╚═════╝╚═════╝
|
||||
```
|
||||
> Build with [Joomla Component Builder](https://git.vdm.dev/joomla/Component-Builder)
|
||||
|
129
src/3af7864b-f1f3-491e-b16f-0504f890086d/code.php
Normal file
129
src/3af7864b-f1f3-491e-b16f-0504f890086d/code.php
Normal file
@ -0,0 +1,129 @@
|
||||
<?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\Openai;
|
||||
|
||||
|
||||
use Joomla\Registry\Registry as JoomlaRegistry;
|
||||
use Joomla\CMS\Factory as JoomlaFactory;
|
||||
use Joomla\Input\Input;
|
||||
use VDM\Joomla\Utilities\Component\Helper;
|
||||
use VDM\Joomla\Abstraction\BaseConfig;
|
||||
|
||||
|
||||
/**
|
||||
* GetBible Openai Configurations
|
||||
*
|
||||
* @since 2.0.1
|
||||
*/
|
||||
class Config extends BaseConfig
|
||||
{
|
||||
/**
|
||||
* Hold a JInput object for easier access to the input variables.
|
||||
*
|
||||
* @var Input
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected Input $input;
|
||||
|
||||
/**
|
||||
* The Params
|
||||
*
|
||||
* @var JoomlaRegistry
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected JoomlaRegistry $params;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param Input|null $input Input
|
||||
* @param Registry|null $params The component parameters
|
||||
*
|
||||
* @throws \Exception
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function __construct(?Input $input = null, ?JoomlaRegistry $params = null)
|
||||
{
|
||||
$this->input = $input ?: JoomlaFactory::getApplication()->input;
|
||||
$this->params = $params ?: Helper::getParams('com_getbible');
|
||||
|
||||
// run parent constructor
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* get Prompt GUID
|
||||
*
|
||||
* @return string|null The translation abbreviation
|
||||
* @since 2.0.1
|
||||
*/
|
||||
protected function getPrompt(): ?string
|
||||
{
|
||||
return $this->input->getString('guid');
|
||||
}
|
||||
|
||||
/**
|
||||
* get Translation Abbreviation
|
||||
*
|
||||
* @return string|null The translation abbreviation
|
||||
* @since 2.0.1
|
||||
*/
|
||||
protected function getTranslation(): ?string
|
||||
{
|
||||
return $this->input->getWord('t') ?? $this->input->getWord('version') ?? $this->input->getWord('translation');
|
||||
}
|
||||
|
||||
/**
|
||||
* get Book Number
|
||||
*
|
||||
* @return int|null The book number
|
||||
* @since 2.0.1
|
||||
*/
|
||||
protected function getBook(): ?int
|
||||
{
|
||||
return $this->input->getInt('book');
|
||||
}
|
||||
|
||||
/**
|
||||
* get Chapter Number
|
||||
*
|
||||
* @return int|null The chapter number
|
||||
* @since 2.0.1
|
||||
*/
|
||||
protected function getChapter(): ?int
|
||||
{
|
||||
return $this->input->getInt('chapter');
|
||||
}
|
||||
|
||||
/**
|
||||
* get Verse Number/s
|
||||
*
|
||||
* @return string|null The verse number/s
|
||||
* @since 2.0.1
|
||||
*/
|
||||
protected function getVerse(): ?string
|
||||
{
|
||||
return $this->input->getString('verse');
|
||||
}
|
||||
|
||||
/**
|
||||
* get Words Number/s
|
||||
*
|
||||
* @return string|null The word number/s
|
||||
* @since 2.0.1
|
||||
*/
|
||||
protected function getWords(): ?string
|
||||
{
|
||||
return $this->input->getString('words');
|
||||
}
|
||||
}
|
||||
|
99
src/3af7864b-f1f3-491e-b16f-0504f890086d/code.power
Normal file
99
src/3af7864b-f1f3-491e-b16f-0504f890086d/code.power
Normal file
@ -0,0 +1,99 @@
|
||||
/**
|
||||
* Hold a JInput object for easier access to the input variables.
|
||||
*
|
||||
* @var Input
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected Input $input;
|
||||
|
||||
/**
|
||||
* The Params
|
||||
*
|
||||
* @var JoomlaRegistry
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected JoomlaRegistry $params;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param Input|null $input Input
|
||||
* @param Registry|null $params The component parameters
|
||||
*
|
||||
* @throws \Exception
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function __construct(?Input $input = null, ?JoomlaRegistry $params = null)
|
||||
{
|
||||
$this->input = $input ?: JoomlaFactory::getApplication()->input;
|
||||
$this->params = $params ?: Helper::getParams('com_getbible');
|
||||
|
||||
// run parent constructor
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* get Prompt GUID
|
||||
*
|
||||
* @return string|null The translation abbreviation
|
||||
* @since 2.0.1
|
||||
*/
|
||||
protected function getPrompt(): ?string
|
||||
{
|
||||
return $this->input->getString('guid');
|
||||
}
|
||||
|
||||
/**
|
||||
* get Translation Abbreviation
|
||||
*
|
||||
* @return string|null The translation abbreviation
|
||||
* @since 2.0.1
|
||||
*/
|
||||
protected function getTranslation(): ?string
|
||||
{
|
||||
return $this->input->getWord('t') ?? $this->input->getWord('version') ?? $this->input->getWord('translation');
|
||||
}
|
||||
|
||||
/**
|
||||
* get Book Number
|
||||
*
|
||||
* @return int|null The book number
|
||||
* @since 2.0.1
|
||||
*/
|
||||
protected function getBook(): ?int
|
||||
{
|
||||
return $this->input->getInt('book');
|
||||
}
|
||||
|
||||
/**
|
||||
* get Chapter Number
|
||||
*
|
||||
* @return int|null The chapter number
|
||||
* @since 2.0.1
|
||||
*/
|
||||
protected function getChapter(): ?int
|
||||
{
|
||||
return $this->input->getInt('chapter');
|
||||
}
|
||||
|
||||
/**
|
||||
* get Verse Number/s
|
||||
*
|
||||
* @return string|null The verse number/s
|
||||
* @since 2.0.1
|
||||
*/
|
||||
protected function getVerse(): ?string
|
||||
{
|
||||
return $this->input->getString('verse');
|
||||
}
|
||||
|
||||
/**
|
||||
* get Words Number/s
|
||||
*
|
||||
* @return string|null The word number/s
|
||||
* @since 2.0.1
|
||||
*/
|
||||
protected function getWords(): ?string
|
||||
{
|
||||
return $this->input->getString('words');
|
||||
}
|
23
src/3af7864b-f1f3-491e-b16f-0504f890086d/settings.json
Normal file
23
src/3af7864b-f1f3-491e-b16f-0504f890086d/settings.json
Normal file
@ -0,0 +1,23 @@
|
||||
{
|
||||
"add_head": "1",
|
||||
"add_licensing_template": "2",
|
||||
"extends": "ffbd4e1f-a342-4080-ab7d-1de3741bf319",
|
||||
"guid": "3af7864b-f1f3-491e-b16f-0504f890086d",
|
||||
"implements": null,
|
||||
"load_selection": null,
|
||||
"name": "Config",
|
||||
"power_version": "1.0.0",
|
||||
"system_name": "JCB.GetBible.Openai.Config",
|
||||
"type": "class",
|
||||
"use_selection": {
|
||||
"use_selection0": {
|
||||
"use": "640b5352-fb09-425f-a26e-cd44eda03f15",
|
||||
"as": "default"
|
||||
}
|
||||
},
|
||||
"namespace": "VDM\\Joomla\\GetBible\\Openai.Config",
|
||||
"description": "GetBible Openai Configurations\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\\Registry\\Registry as JoomlaRegistry;\r\nuse Joomla\\CMS\\Factory as JoomlaFactory;\r\nuse Joomla\\Input\\Input;",
|
||||
"composer": ""
|
||||
}
|
@ -12,9 +12,14 @@
|
||||
@startuml
|
||||
class Prompt << (F,LightGreen) >> #Green {
|
||||
# Load $load
|
||||
# Config $config
|
||||
# array $prompts
|
||||
+ __construct(Load $load)
|
||||
+ get(string $guid) : ?object
|
||||
+ __construct(Load $load, Config $config)
|
||||
+ getIntegration(?string $guid = null) : ?int
|
||||
+ getCacheBehaviour(?string $guid = null) : ?int
|
||||
+ getCacheCapacity(?string $guid = null) : ?int
|
||||
+ get(?string $guid = null) : ?object
|
||||
- active(?string $guid = null) : bool
|
||||
}
|
||||
|
||||
note right of Prompt::__construct
|
||||
@ -23,12 +28,40 @@ note right of Prompt::__construct
|
||||
since: 2.0.1
|
||||
end note
|
||||
|
||||
note right of Prompt::getIntegration
|
||||
Get the integration
|
||||
|
||||
since: 2.0.1
|
||||
return: ?int
|
||||
end note
|
||||
|
||||
note right of Prompt::getCacheBehaviour
|
||||
Get the cache behaviour
|
||||
|
||||
since: 2.0.1
|
||||
return: ?int
|
||||
end note
|
||||
|
||||
note right of Prompt::getCacheCapacity
|
||||
Get the cache capacity
|
||||
|
||||
since: 2.0.1
|
||||
return: ?int
|
||||
end note
|
||||
|
||||
note right of Prompt::get
|
||||
Get the prompt
|
||||
|
||||
since: 2.0.1
|
||||
return: ?object
|
||||
end note
|
||||
|
||||
note right of Prompt::active
|
||||
Check if this prompt is active
|
||||
|
||||
since: 2.0.1
|
||||
return: bool
|
||||
end note
|
||||
|
||||
@enduml
|
||||
```
|
||||
|
@ -13,6 +13,7 @@ namespace VDM\Joomla\GetBible\Data;
|
||||
|
||||
|
||||
use VDM\Joomla\GetBible\Database\Load;
|
||||
use VDM\Joomla\GetBible\Openai\Config;
|
||||
|
||||
|
||||
/**
|
||||
@ -31,7 +32,15 @@ final class Prompt
|
||||
protected Load $load;
|
||||
|
||||
/**
|
||||
* The the prompts
|
||||
* The Config class
|
||||
*
|
||||
* @var Config
|
||||
* @since 2.0.1
|
||||
*/
|
||||
protected Config $config;
|
||||
|
||||
/**
|
||||
* The prompts
|
||||
*
|
||||
* @var array
|
||||
* @since 2.0.1
|
||||
@ -41,13 +50,69 @@ final class Prompt
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param Load $load The load object.
|
||||
* @param Load $load The load object.
|
||||
* @param Config $config The config object.
|
||||
*
|
||||
* @since 2.0.1
|
||||
*/
|
||||
public function __construct(Load $load)
|
||||
public function __construct(Load $load, Config $config)
|
||||
{
|
||||
$this->load = $load;
|
||||
$this->config = $config;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the integration
|
||||
*
|
||||
* @param string $guid The prompt guid.
|
||||
*
|
||||
* @return int|null 1 = Word-Based, 2 = Verse-Based, 3 = Selection-Based
|
||||
* @since 2.0.1
|
||||
*/
|
||||
public function getIntegration(?string $guid = null): ?int
|
||||
{
|
||||
if ($this->active($guid))
|
||||
{
|
||||
return (int) $this->get($guid)->integration;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the cache behaviour
|
||||
*
|
||||
* @param string $guid The prompt guid.
|
||||
*
|
||||
* @return int|null 0 = None, 2 = Basic, 3 = Advanced
|
||||
* @since 2.0.1
|
||||
*/
|
||||
public function getCacheBehaviour(?string $guid = null): ?int
|
||||
{
|
||||
if ($this->active($guid))
|
||||
{
|
||||
return (int) $this->get($guid)->cache_behaviour;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the cache capacity
|
||||
*
|
||||
* @param string $guid The prompt guid.
|
||||
*
|
||||
* @return int|null The number to cache
|
||||
* @since 2.0.1
|
||||
*/
|
||||
public function getCacheCapacity(?string $guid = null): ?int
|
||||
{
|
||||
if ($this->active($guid))
|
||||
{
|
||||
return (int) $this->get($guid)->cache_capacity;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -58,14 +123,45 @@ final class Prompt
|
||||
* @return object|null True on success
|
||||
* @since 2.0.1
|
||||
*/
|
||||
public function get(string $guid): ?object
|
||||
public function get(?string $guid = null): ?object
|
||||
{
|
||||
if (!isset($this->prompts[$guid]))
|
||||
// get from cache if not found
|
||||
$guid = $guid ?? $this->config->get('prompt');
|
||||
|
||||
if ($guid === null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
if (!isset($this->responses[$guid]))
|
||||
{
|
||||
$this->prompts[$guid] = $this->load->item(['guid' => $guid], 'prompt');
|
||||
|
||||
if ($this->prompts[$guid] !== null && is_object($this->prompts[$guid]))
|
||||
{
|
||||
$this->config->set('prompt', $guid);
|
||||
}
|
||||
}
|
||||
|
||||
return $this->prompts[$guid];
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if this prompt is active
|
||||
*
|
||||
* @param string $guid The prompt guid.
|
||||
*
|
||||
* @return bool true if active
|
||||
* @since 2.0.1
|
||||
*/
|
||||
private function active(?string $guid = null): bool
|
||||
{
|
||||
if ($this->get($guid))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -7,7 +7,15 @@
|
||||
protected Load $load;
|
||||
|
||||
/**
|
||||
* The the prompts
|
||||
* The Config class
|
||||
*
|
||||
* @var Config
|
||||
* @since 2.0.1
|
||||
*/
|
||||
protected Config $config;
|
||||
|
||||
/**
|
||||
* The prompts
|
||||
*
|
||||
* @var array
|
||||
* @since 2.0.1
|
||||
@ -17,13 +25,69 @@
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param Load $load The load object.
|
||||
* @param Load $load The load object.
|
||||
* @param Config $config The config object.
|
||||
*
|
||||
* @since 2.0.1
|
||||
*/
|
||||
public function __construct(Load $load)
|
||||
public function __construct(Load $load, Config $config)
|
||||
{
|
||||
$this->load = $load;
|
||||
$this->config = $config;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the integration
|
||||
*
|
||||
* @param string $guid The prompt guid.
|
||||
*
|
||||
* @return int|null 1 = Word-Based, 2 = Verse-Based, 3 = Selection-Based
|
||||
* @since 2.0.1
|
||||
*/
|
||||
public function getIntegration(?string $guid = null): ?int
|
||||
{
|
||||
if ($this->active($guid))
|
||||
{
|
||||
return (int) $this->get($guid)->integration;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the cache behaviour
|
||||
*
|
||||
* @param string $guid The prompt guid.
|
||||
*
|
||||
* @return int|null 0 = None, 2 = Basic, 3 = Advanced
|
||||
* @since 2.0.1
|
||||
*/
|
||||
public function getCacheBehaviour(?string $guid = null): ?int
|
||||
{
|
||||
if ($this->active($guid))
|
||||
{
|
||||
return (int) $this->get($guid)->cache_behaviour;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the cache capacity
|
||||
*
|
||||
* @param string $guid The prompt guid.
|
||||
*
|
||||
* @return int|null The number to cache
|
||||
* @since 2.0.1
|
||||
*/
|
||||
public function getCacheCapacity(?string $guid = null): ?int
|
||||
{
|
||||
if ($this->active($guid))
|
||||
{
|
||||
return (int) $this->get($guid)->cache_capacity;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -34,12 +98,43 @@
|
||||
* @return object|null True on success
|
||||
* @since 2.0.1
|
||||
*/
|
||||
public function get(string $guid): ?object
|
||||
public function get(?string $guid = null): ?object
|
||||
{
|
||||
if (!isset($this->prompts[$guid]))
|
||||
// get from cache if not found
|
||||
$guid = $guid ?? $this->config->get('prompt');
|
||||
|
||||
if ($guid === null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
if (!isset($this->responses[$guid]))
|
||||
{
|
||||
$this->prompts[$guid] = $this->load->item(['guid' => $guid], 'prompt');
|
||||
|
||||
if ($this->prompts[$guid] !== null && is_object($this->prompts[$guid]))
|
||||
{
|
||||
$this->config->set('prompt', $guid);
|
||||
}
|
||||
}
|
||||
|
||||
return $this->prompts[$guid];
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if this prompt is active
|
||||
*
|
||||
* @param string $guid The prompt guid.
|
||||
*
|
||||
* @return bool true if active
|
||||
* @since 2.0.1
|
||||
*/
|
||||
private function active(?string $guid = null): bool
|
||||
{
|
||||
if ($this->get($guid))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
@ -13,6 +13,10 @@
|
||||
"use_selection0": {
|
||||
"use": "c03b9c61-17d3-4774-a335-783903719f83",
|
||||
"as": "default"
|
||||
},
|
||||
"use_selection1": {
|
||||
"use": "3af7864b-f1f3-491e-b16f-0504f890086d",
|
||||
"as": "default"
|
||||
}
|
||||
},
|
||||
"namespace": "VDM\\Joomla\\GetBible\\Data.Prompt",
|
||||
|
53
src/44c15b17-e096-47c0-8769-42ea9b692cb2/README.md
Normal file
53
src/44c15b17-e096-47c0-8769-42ea9b692cb2/README.md
Normal file
@ -0,0 +1,53 @@
|
||||
```
|
||||
██████╗ ██████╗ ██╗ ██╗███████╗██████╗
|
||||
██╔══██╗██╔═══██╗██║ ██║██╔════╝██╔══██╗
|
||||
██████╔╝██║ ██║██║ █╗ ██║█████╗ ██████╔╝
|
||||
██╔═══╝ ██║ ██║██║███╗██║██╔══╝ ██╔══██╗
|
||||
██║ ╚██████╔╝╚███╔███╔╝███████╗██║ ██║
|
||||
╚═╝ ╚═════╝ ╚══╝╚══╝ ╚══════╝╚═╝ ╚═╝
|
||||
```
|
||||
# final class Response (Details)
|
||||
> namespace: **VDM\Joomla\GetBible\Data**
|
||||
```uml
|
||||
@startuml
|
||||
class Response << (F,LightGreen) >> #Green {
|
||||
# Prompt $prompt
|
||||
# Load $load
|
||||
# Config $config
|
||||
# array $responses
|
||||
+ __construct(Prompt $prompt, Load $load, ...)
|
||||
+ get(?string $guid = null) : ?object
|
||||
}
|
||||
|
||||
note right of Response::__construct
|
||||
Constructor
|
||||
|
||||
since: 2.0.1
|
||||
|
||||
arguments:
|
||||
Prompt $prompt
|
||||
Load $load
|
||||
Config $config
|
||||
end note
|
||||
|
||||
note right of Response::get
|
||||
Get the responses
|
||||
|
||||
since: 2.0.1
|
||||
return: ?object
|
||||
end note
|
||||
|
||||
@enduml
|
||||
```
|
||||
|
||||
---
|
||||
```
|
||||
██╗ ██████╗██████╗
|
||||
██║██╔════╝██╔══██╗
|
||||
██║██║ ██████╔╝
|
||||
██ ██║██║ ██╔══██╗
|
||||
╚█████╔╝╚██████╗██████╔╝
|
||||
╚════╝ ╚═════╝╚═════╝
|
||||
```
|
||||
> Build with [Joomla Component Builder](https://git.vdm.dev/joomla/Component-Builder)
|
||||
|
127
src/44c15b17-e096-47c0-8769-42ea9b692cb2/code.php
Normal file
127
src/44c15b17-e096-47c0-8769-42ea9b692cb2/code.php
Normal file
@ -0,0 +1,127 @@
|
||||
<?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\Data;
|
||||
|
||||
|
||||
use VDM\Joomla\GetBible\Database\Load;
|
||||
use VDM\Joomla\GetBible\Openai\Config;
|
||||
|
||||
|
||||
/**
|
||||
* The GetBible Response Data
|
||||
*
|
||||
* @since 2.0.1
|
||||
*/
|
||||
final class Response
|
||||
{
|
||||
/**
|
||||
* The Prompt class
|
||||
*
|
||||
* @var Prompt
|
||||
* @since 2.0.1
|
||||
*/
|
||||
protected Prompt $prompt;
|
||||
|
||||
/**
|
||||
* The Load class
|
||||
*
|
||||
* @var Load
|
||||
* @since 2.0.1
|
||||
*/
|
||||
protected Load $load;
|
||||
|
||||
/**
|
||||
* The Config class
|
||||
*
|
||||
* @var Config
|
||||
* @since 2.0.1
|
||||
*/
|
||||
protected Config $config;
|
||||
|
||||
/**
|
||||
* The responses
|
||||
*
|
||||
* @var array
|
||||
* @since 2.0.1
|
||||
*/
|
||||
protected array $responses = [];
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param Prompt $prompt The prompt object.
|
||||
* @param Load $load The load object.
|
||||
* @param Config $config The config object.
|
||||
*
|
||||
* @since 2.0.1
|
||||
*/
|
||||
public function __construct(Prompt $prompt, Load $load, Config $config)
|
||||
{
|
||||
$this->prompt = $prompt;
|
||||
$this->load = $load;
|
||||
$this->config = $config;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the responses
|
||||
*
|
||||
* @param string|null $guid The prompt guid.
|
||||
*
|
||||
* @return object|null True on success
|
||||
* @since 2.0.1
|
||||
*/
|
||||
public function get(?string $guid = null): ?object
|
||||
{
|
||||
// get the cache behaviour
|
||||
$cache = $this->prompt->getCacheBehaviour();
|
||||
|
||||
if (empty($cache))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
// get from cache if not found
|
||||
$guid = $guid ?? $this->config->get('prompt');
|
||||
|
||||
if ($guid === null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
if (!isset($this->responses[$guid]))
|
||||
{
|
||||
$this->responses[$guid] = null;
|
||||
|
||||
$query = ['prompt' => $guid];
|
||||
|
||||
$bucket = $this->load->items($query, 'open_ai_response');
|
||||
|
||||
if (is_array($bucket) && $bucket !== [])
|
||||
{
|
||||
foreach($bucket as $nr => &$response)
|
||||
{
|
||||
$response->messages = $this->load->items([
|
||||
'prompt' => $guid,
|
||||
'open_ai_response' => $response->guid
|
||||
], 'open_ai_message');
|
||||
}
|
||||
|
||||
$this->responses[$guid] = $bucket;
|
||||
|
||||
$this->config->set('prompt', $guid);
|
||||
}
|
||||
}
|
||||
|
||||
return $this->responses[$guid];
|
||||
}
|
||||
}
|
||||
|
100
src/44c15b17-e096-47c0-8769-42ea9b692cb2/code.power
Normal file
100
src/44c15b17-e096-47c0-8769-42ea9b692cb2/code.power
Normal file
@ -0,0 +1,100 @@
|
||||
/**
|
||||
* The Prompt class
|
||||
*
|
||||
* @var Prompt
|
||||
* @since 2.0.1
|
||||
*/
|
||||
protected Prompt $prompt;
|
||||
|
||||
/**
|
||||
* The Load class
|
||||
*
|
||||
* @var Load
|
||||
* @since 2.0.1
|
||||
*/
|
||||
protected Load $load;
|
||||
|
||||
/**
|
||||
* The Config class
|
||||
*
|
||||
* @var Config
|
||||
* @since 2.0.1
|
||||
*/
|
||||
protected Config $config;
|
||||
|
||||
/**
|
||||
* The responses
|
||||
*
|
||||
* @var array
|
||||
* @since 2.0.1
|
||||
*/
|
||||
protected array $responses = [];
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param Prompt $prompt The prompt object.
|
||||
* @param Load $load The load object.
|
||||
* @param Config $config The config object.
|
||||
*
|
||||
* @since 2.0.1
|
||||
*/
|
||||
public function __construct(Prompt $prompt, Load $load, Config $config)
|
||||
{
|
||||
$this->prompt = $prompt;
|
||||
$this->load = $load;
|
||||
$this->config = $config;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the responses
|
||||
*
|
||||
* @param string|null $guid The prompt guid.
|
||||
*
|
||||
* @return object|null True on success
|
||||
* @since 2.0.1
|
||||
*/
|
||||
public function get(?string $guid = null): ?object
|
||||
{
|
||||
// get the cache behaviour
|
||||
$cache = $this->prompt->getCacheBehaviour();
|
||||
|
||||
if (empty($cache))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
// get from cache if not found
|
||||
$guid = $guid ?? $this->config->get('prompt');
|
||||
|
||||
if ($guid === null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
if (!isset($this->responses[$guid]))
|
||||
{
|
||||
$this->responses[$guid] = null;
|
||||
|
||||
$query = ['prompt' => $guid];
|
||||
|
||||
$bucket = $this->load->items($query, 'open_ai_response');
|
||||
|
||||
if (is_array($bucket) && $bucket !== [])
|
||||
{
|
||||
foreach($bucket as $nr => &$response)
|
||||
{
|
||||
$response->messages = $this->load->items([
|
||||
'prompt' => $guid,
|
||||
'open_ai_response' => $response->guid
|
||||
], 'open_ai_message');
|
||||
}
|
||||
|
||||
$this->responses[$guid] = $bucket;
|
||||
|
||||
$this->config->set('prompt', $guid);
|
||||
}
|
||||
}
|
||||
|
||||
return $this->responses[$guid];
|
||||
}
|
27
src/44c15b17-e096-47c0-8769-42ea9b692cb2/settings.json
Normal file
27
src/44c15b17-e096-47c0-8769-42ea9b692cb2/settings.json
Normal file
@ -0,0 +1,27 @@
|
||||
{
|
||||
"add_head": "0",
|
||||
"add_licensing_template": "2",
|
||||
"extends": "0",
|
||||
"guid": "44c15b17-e096-47c0-8769-42ea9b692cb2",
|
||||
"implements": null,
|
||||
"load_selection": null,
|
||||
"name": "Response",
|
||||
"power_version": "1.0.0",
|
||||
"system_name": "Joomla.GetBible.Data.Response",
|
||||
"type": "final class",
|
||||
"use_selection": {
|
||||
"use_selection0": {
|
||||
"use": "c03b9c61-17d3-4774-a335-783903719f83",
|
||||
"as": "default"
|
||||
},
|
||||
"use_selection1": {
|
||||
"use": "3af7864b-f1f3-491e-b16f-0504f890086d",
|
||||
"as": "default"
|
||||
}
|
||||
},
|
||||
"namespace": "VDM\\Joomla\\GetBible\\Data.Response",
|
||||
"description": "The GetBible Response Data\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": "",
|
||||
"composer": ""
|
||||
}
|
@ -12,15 +12,153 @@
|
||||
@startuml
|
||||
class Chapter << (F,LightGreen) >> #Green {
|
||||
# Load $load
|
||||
# Config $config
|
||||
# StringHelper $stringHelper
|
||||
# array $chapters
|
||||
+ __construct(Load $load)
|
||||
+ get(string $abbreviation, int $book, ...) : ?object
|
||||
+ __construct(Load $load, Config $config, ...)
|
||||
+ getBookName(?string $abbreviation = null, ?int $book = null, ...) : string
|
||||
+ getChapterNumber(?string $abbreviation = null, ?int $book = null, ...) : string
|
||||
+ getChapterName(?string $abbreviation = null, ?int $book = null, ...) : string
|
||||
+ getChapterText(?string $abbreviation = null, ?int $book = null, ...) : string
|
||||
+ getVerseNumber(?string $abbreviation = null, ?int $book = null, ...) : string
|
||||
+ getVerseName(?string $abbreviation = null, ?int $book = null, ...) : string
|
||||
+ getVerseText(?string $abbreviation = null, ?int $book = null, ...) : string
|
||||
+ getWordNumber(?string $abbreviation = null, ?int $book = null, ...) : string
|
||||
+ getWordText(?string $abbreviation = null, ?int $book = null, ...) : string
|
||||
+ get(?string $abbreviation = null, ?int $book = null, ...) : ?object
|
||||
- generateCacheKey(string $abbreviation, int $book, ...) : string
|
||||
- loadChapterData(string $abbreviation, int $book, ...) : ?object
|
||||
- active(?string $abbreviation = null, ?int $book = null, ...) : bool
|
||||
- processVerses(?string $abbreviation, ?int $book, ...) : string
|
||||
- processVersesArray(?string $abbreviation, ?int $book, ...) : ?array
|
||||
- extractVerseNumbers(string $verseNumber) : array
|
||||
- getTextFromVerses(array $verses, array $verseNumber) : array
|
||||
- getArrayFromVerses(array $verses, array $verseNumber) : array
|
||||
- getWordNumberArray(?string $abbreviation = null, ?int $book = null, ...) : ?array
|
||||
- splitAndTrim(string $str) : array
|
||||
- buildWordNumberArray(array $verse, array $words) : array
|
||||
- wordNumberArrayToString(array $wordNumberArray) : string
|
||||
- buildWordArray(array $verses, array $words) : array
|
||||
- wordArrayToString(array $wordArray) : string
|
||||
}
|
||||
|
||||
note right of Chapter::__construct
|
||||
Constructor
|
||||
|
||||
since: 2.0.1
|
||||
|
||||
arguments:
|
||||
Load $load
|
||||
Config $config
|
||||
StringHelper $stringHelper
|
||||
end note
|
||||
|
||||
note left of Chapter::getBookName
|
||||
Get the book name
|
||||
|
||||
since: 2.0.1
|
||||
return: string
|
||||
|
||||
arguments:
|
||||
?string $abbreviation = null
|
||||
?int $book = null
|
||||
?int $chapter = null
|
||||
end note
|
||||
|
||||
note right of Chapter::getChapterNumber
|
||||
Get the chapter number
|
||||
|
||||
since: 2.0.1
|
||||
return: string
|
||||
|
||||
arguments:
|
||||
?string $abbreviation = null
|
||||
?int $book = null
|
||||
?int $chapter = null
|
||||
end note
|
||||
|
||||
note left of Chapter::getChapterName
|
||||
Get the chapter name
|
||||
|
||||
since: 2.0.1
|
||||
return: string
|
||||
|
||||
arguments:
|
||||
?string $abbreviation = null
|
||||
?int $book = null
|
||||
?int $chapter = null
|
||||
end note
|
||||
|
||||
note right of Chapter::getChapterText
|
||||
Get the chapter text
|
||||
|
||||
since: 2.0.1
|
||||
return: string
|
||||
|
||||
arguments:
|
||||
?string $abbreviation = null
|
||||
?int $book = null
|
||||
?int $chapter = null
|
||||
end note
|
||||
|
||||
note left of Chapter::getVerseNumber
|
||||
Get the verse number/s
|
||||
|
||||
since: 2.0.1
|
||||
return: string
|
||||
|
||||
arguments:
|
||||
?string $abbreviation = null
|
||||
?int $book = null
|
||||
?int $chapter = null
|
||||
end note
|
||||
|
||||
note right of Chapter::getVerseName
|
||||
Get the verse name
|
||||
|
||||
since: 2.0.1
|
||||
return: string
|
||||
|
||||
arguments:
|
||||
?string $abbreviation = null
|
||||
?int $book = null
|
||||
?int $chapter = null
|
||||
end note
|
||||
|
||||
note left of Chapter::getVerseText
|
||||
Get the verse text
|
||||
|
||||
since: 2.0.1
|
||||
return: string
|
||||
|
||||
arguments:
|
||||
?string $abbreviation = null
|
||||
?int $book = null
|
||||
?int $chapter = null
|
||||
end note
|
||||
|
||||
note right of Chapter::getWordNumber
|
||||
Get the word number/s
|
||||
|
||||
since: 2.0.1
|
||||
return: string
|
||||
|
||||
arguments:
|
||||
?string $abbreviation = null
|
||||
?int $book = null
|
||||
?int $chapter = null
|
||||
end note
|
||||
|
||||
note left of Chapter::getWordText
|
||||
Get the word text
|
||||
|
||||
since: 2.0.1
|
||||
return: string
|
||||
|
||||
arguments:
|
||||
?string $abbreviation = null
|
||||
?int $book = null
|
||||
?int $chapter = null
|
||||
end note
|
||||
|
||||
note right of Chapter::get
|
||||
@ -29,11 +167,139 @@ note right of Chapter::get
|
||||
since: 2.0.1
|
||||
return: ?object
|
||||
|
||||
arguments:
|
||||
?string $abbreviation = null
|
||||
?int $book = null
|
||||
?int $chapter = null
|
||||
end note
|
||||
|
||||
note left of Chapter::generateCacheKey
|
||||
Generates a cache key based on the abbreviation, book, and chapter
|
||||
|
||||
since: 2.0.1
|
||||
return: string
|
||||
|
||||
arguments:
|
||||
string $abbreviation
|
||||
int $book
|
||||
int $chapter
|
||||
end note
|
||||
|
||||
note right of Chapter::loadChapterData
|
||||
Loads the chapter data from the database and updates the cache
|
||||
|
||||
since: 2.0.1
|
||||
return: ?object
|
||||
|
||||
arguments:
|
||||
string $abbreviation
|
||||
int $book
|
||||
int $chapter
|
||||
end note
|
||||
|
||||
note left of Chapter::active
|
||||
Check if this chapter is active
|
||||
|
||||
since: 2.0.1
|
||||
return: bool
|
||||
|
||||
arguments:
|
||||
?string $abbreviation = null
|
||||
?int $book = null
|
||||
?int $chapter = null
|
||||
end note
|
||||
|
||||
note right of Chapter::processVerses
|
||||
Processes the verses to extract the verse text
|
||||
|
||||
since: 2.0.1
|
||||
return: string
|
||||
|
||||
arguments:
|
||||
?string $abbreviation
|
||||
?int $book
|
||||
?int $chapter
|
||||
end note
|
||||
|
||||
note left of Chapter::processVersesArray
|
||||
Processes the verses to extract the verse text
|
||||
|
||||
since: 2.0.1
|
||||
return: ?array
|
||||
|
||||
arguments:
|
||||
?string $abbreviation
|
||||
?int $book
|
||||
?int $chapter
|
||||
end note
|
||||
|
||||
note right of Chapter::extractVerseNumbers
|
||||
Extracts the verse numbers from the input string
|
||||
|
||||
since: 2.0.1
|
||||
return: array
|
||||
end note
|
||||
|
||||
note left of Chapter::getTextFromVerses
|
||||
Get the verse text from the verses array based on the verse numbers
|
||||
|
||||
since: 2.0.1
|
||||
return: array
|
||||
end note
|
||||
|
||||
note right of Chapter::getArrayFromVerses
|
||||
Get the verses array based on the verse numbers
|
||||
|
||||
since: 2.0.1
|
||||
return: array
|
||||
end note
|
||||
|
||||
note left of Chapter::getWordNumberArray
|
||||
Get the word number/s
|
||||
|
||||
since: 2.0.1
|
||||
return: ?array
|
||||
|
||||
arguments:
|
||||
?string $abbreviation = null
|
||||
?int $book = null
|
||||
?int $chapter = null
|
||||
end note
|
||||
|
||||
note right of Chapter::splitAndTrim
|
||||
Split verse or words by '-' and trim each element.
|
||||
|
||||
since: 2.0.1
|
||||
return: array
|
||||
end note
|
||||
|
||||
note left of Chapter::buildWordNumberArray
|
||||
Build word number array from verse and words.
|
||||
|
||||
since: 2.0.1
|
||||
return: array
|
||||
end note
|
||||
|
||||
note right of Chapter::wordNumberArrayToString
|
||||
Converts word number array to string.
|
||||
|
||||
since: 2.0.1
|
||||
return: string
|
||||
end note
|
||||
|
||||
note left of Chapter::buildWordArray
|
||||
Build word array from verse and words.
|
||||
|
||||
since: 2.0.1
|
||||
return: array
|
||||
end note
|
||||
|
||||
note right of Chapter::wordArrayToString
|
||||
Converts word array to string.
|
||||
|
||||
since: 2.0.1
|
||||
return: string
|
||||
end note
|
||||
|
||||
@enduml
|
||||
```
|
||||
|
@ -13,6 +13,8 @@ namespace VDM\Joomla\GetBible\Data;
|
||||
|
||||
|
||||
use VDM\Joomla\GetBible\Database\Load;
|
||||
use VDM\Joomla\GetBible\Openai\Config;
|
||||
use VDM\Joomla\GetBible\Utilities\StringHelper;
|
||||
|
||||
|
||||
/**
|
||||
@ -30,6 +32,22 @@ final class Chapter
|
||||
*/
|
||||
protected Load $load;
|
||||
|
||||
/**
|
||||
* The Config class
|
||||
*
|
||||
* @var Config
|
||||
* @since 2.0.1
|
||||
*/
|
||||
protected Config $config;
|
||||
|
||||
/**
|
||||
* The StringHelper class
|
||||
*
|
||||
* @var StringHelper
|
||||
* @since 2.0.1
|
||||
*/
|
||||
protected StringHelper $stringHelper;
|
||||
|
||||
/**
|
||||
* The chapters
|
||||
*
|
||||
@ -41,37 +59,776 @@ final class Chapter
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param Load $load The load object.
|
||||
* @param Load $load The load object.
|
||||
* @param Config $config The config object.
|
||||
* @param StringHelper $stringHelper The string helper object.
|
||||
*
|
||||
* @since 2.0.1
|
||||
*/
|
||||
public function __construct(Load $load)
|
||||
public function __construct(Load $load, Config $config, StringHelper $stringHelper)
|
||||
{
|
||||
$this->load = $load;
|
||||
$this->config = $config;
|
||||
$this->stringHelper = $stringHelper;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the book name
|
||||
*
|
||||
* @param string|null $abbreviation The translation abbreviation.
|
||||
* @param int|null $book The book number.
|
||||
* @param int|null $chapter The chapter number.
|
||||
*
|
||||
* @return string The book name
|
||||
* @since 2.0.1
|
||||
*/
|
||||
public function getBookName(?string $abbreviation = null,?int $book = null, ?int $chapter = null): string
|
||||
{
|
||||
if ($this->active($abbreviation, $book, $chapter))
|
||||
{
|
||||
return $this->get($abbreviation, $book, $chapter)->book->name ?? '';
|
||||
}
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the chapter number
|
||||
*
|
||||
* @param string|null $abbreviation The translation abbreviation.
|
||||
* @param int|null $book The book number.
|
||||
* @param int|null $chapter The chapter number.
|
||||
*
|
||||
* @return string The chapter number
|
||||
* @since 2.0.1
|
||||
*/
|
||||
public function getChapterNumber(?string $abbreviation = null,?int $book = null, ?int $chapter = null): string
|
||||
{
|
||||
if ($this->active($abbreviation, $book, $chapter))
|
||||
{
|
||||
return $this->get($abbreviation, $book, $chapter)->chapter ?? '';
|
||||
}
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the chapter name
|
||||
*
|
||||
* @param string|null $abbreviation The translation abbreviation.
|
||||
* @param int|null $book The book number.
|
||||
* @param int|null $chapter The chapter number.
|
||||
*
|
||||
* @return string The chapter name
|
||||
* @since 2.0.1
|
||||
*/
|
||||
public function getChapterName(?string $abbreviation = null,?int $book = null, ?int $chapter = null): string
|
||||
{
|
||||
if ($this->active($abbreviation, $book, $chapter))
|
||||
{
|
||||
return $this->get($abbreviation, $book, $chapter)->name ?? '';
|
||||
}
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the chapter text
|
||||
*
|
||||
* @param string|null $abbreviation The translation abbreviation.
|
||||
* @param int|null $book The book number.
|
||||
* @param int|null $chapter The chapter number.
|
||||
*
|
||||
* @return string The chapter text
|
||||
* @since 2.0.1
|
||||
*/
|
||||
public function getChapterText(?string $abbreviation = null,?int $book = null, ?int $chapter = null): string
|
||||
{
|
||||
if (!$this->active($abbreviation, $book, $chapter))
|
||||
{
|
||||
return '';
|
||||
}
|
||||
|
||||
$verses = $this->get($abbreviation, $book, $chapter)->verses ?? null;
|
||||
|
||||
if (empty($verses) || !is_array($verses))
|
||||
{
|
||||
return '';
|
||||
}
|
||||
|
||||
$text = [];
|
||||
foreach ($verses as $verse)
|
||||
{
|
||||
$text[] = trim($verse->verse) . ' ' . trim($verse->text);
|
||||
}
|
||||
|
||||
return implode(' ', $text);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the verse number/s
|
||||
*
|
||||
* @param string|null $abbreviation The translation abbreviation.
|
||||
* @param int|null $book The book number.
|
||||
* @param int|null $chapter The chapter number.
|
||||
*
|
||||
* @return string The verse number/s
|
||||
* @since 2.0.1
|
||||
*/
|
||||
public function getVerseNumber(?string $abbreviation = null,?int $book = null, ?int $chapter = null): string
|
||||
{
|
||||
if (!$this->active($abbreviation, $book, $chapter))
|
||||
{
|
||||
return '';
|
||||
}
|
||||
|
||||
$verse_number = $this->get($abbreviation, $book, $chapter)->verse_number ?? null;
|
||||
|
||||
if ($verse_number !== null)
|
||||
{
|
||||
return $verse_number;
|
||||
}
|
||||
|
||||
$verse = $this->config->get('verse');
|
||||
|
||||
if ($verse === null)
|
||||
{
|
||||
return '';
|
||||
}
|
||||
|
||||
if (strpos($verse, '-') !== false)
|
||||
{
|
||||
$verses = $this->splitAndTrim($verse);
|
||||
$minVerse = min($verses);
|
||||
$maxVerse = max($verses);
|
||||
|
||||
if ($minVerse == $maxVerse)
|
||||
{
|
||||
$verse_number = $minVerse;
|
||||
}
|
||||
else
|
||||
{
|
||||
$verse_number = $minVerse . '-' . $maxVerse;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$verse_number = trim($verse);
|
||||
}
|
||||
|
||||
$this->get($abbreviation, $book, $chapter)->verse_number = $verse_number;
|
||||
|
||||
return $verse_number;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the verse name
|
||||
*
|
||||
* @param string|null $abbreviation The translation abbreviation.
|
||||
* @param int|null $book The book number.
|
||||
* @param int|null $chapter The chapter number.
|
||||
*
|
||||
* @return string The verse name
|
||||
* @since 2.0.1
|
||||
*/
|
||||
public function getVerseName(?string $abbreviation = null,?int $book = null, ?int $chapter = null): string
|
||||
{
|
||||
if (!$this->active($abbreviation, $book, $chapter))
|
||||
{
|
||||
return '';
|
||||
}
|
||||
|
||||
$verse_name = $this->get($abbreviation, $book, $chapter)->verse_name ?? null;
|
||||
|
||||
if ($verse_name !== null)
|
||||
{
|
||||
return $verse_name;
|
||||
}
|
||||
|
||||
$chapter_name = $this->getChapterName($abbreviation, $book, $chapter);
|
||||
$verse_number = $this->getVerseNumber($abbreviation, $book, $chapter);
|
||||
|
||||
if (empty($chapter_name) || empty($verse_number))
|
||||
{
|
||||
return '';
|
||||
}
|
||||
|
||||
$verse_name = $chapter_name . ':' . $verse_number;
|
||||
|
||||
$this->get($abbreviation, $book, $chapter)->verse_name = $verse_name;
|
||||
|
||||
return $verse_name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the verse text
|
||||
*
|
||||
* @param string|null $abbreviation The translation abbreviation.
|
||||
* @param int|null $book The book number.
|
||||
* @param int|null $chapter The chapter number.
|
||||
*
|
||||
* @return string The verse text
|
||||
* @since 2.0.1
|
||||
*/
|
||||
public function getVerseText(?string $abbreviation = null,?int $book = null, ?int $chapter = null): string
|
||||
{
|
||||
if (!$this->active($abbreviation, $book, $chapter))
|
||||
{
|
||||
return '';
|
||||
}
|
||||
|
||||
$verse_text = $this->get($abbreviation, $book, $chapter)->verse_text ?? null;
|
||||
|
||||
if ($verse_text !== null)
|
||||
{
|
||||
return $verse_text;
|
||||
}
|
||||
|
||||
return $this->processVerses($abbreviation, $book, $chapter);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the word number/s
|
||||
*
|
||||
* @param string|null $abbreviation The translation abbreviation.
|
||||
* @param int|null $book The book number.
|
||||
* @param int|null $chapter The chapter number.
|
||||
*
|
||||
* @return string The word number/s
|
||||
* @since 2.0.1
|
||||
*/
|
||||
public function getWordNumber(?string $abbreviation = null,?int $book = null, ?int $chapter = null): string
|
||||
{
|
||||
if (!$this->active($abbreviation, $book, $chapter))
|
||||
{
|
||||
return '';
|
||||
}
|
||||
|
||||
$word_number = $this->get($abbreviation, $book, $chapter)->word_number ?? null;
|
||||
|
||||
if ($word_number !== null)
|
||||
{
|
||||
return $word_number;
|
||||
}
|
||||
|
||||
$verse = $this->config->get('verse');
|
||||
$words = $this->config->get('words');
|
||||
|
||||
if ($verse === null || $words === null)
|
||||
{
|
||||
return '';
|
||||
}
|
||||
|
||||
$verse = $this->splitAndTrim($verse);
|
||||
$words = $this->splitAndTrim($words);
|
||||
|
||||
$word_number_array = $this->buildWordNumberArray($verse, $words);
|
||||
|
||||
if ($word_number_array === [])
|
||||
{
|
||||
return '';
|
||||
}
|
||||
|
||||
$word_number = $this->wordNumberArrayToString($word_number_array);
|
||||
|
||||
$this->get($abbreviation, $book, $chapter)->word_number = $word_number;
|
||||
$this->get($abbreviation, $book, $chapter)->word_number_array = $word_number_array;
|
||||
|
||||
return $word_number;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the word text
|
||||
*
|
||||
* @param string|null $abbreviation The translation abbreviation.
|
||||
* @param int|null $book The book number.
|
||||
* @param int|null $chapter The chapter number.
|
||||
*
|
||||
* @return string The verse text
|
||||
* @since 2.0.1
|
||||
*/
|
||||
public function getWordText(?string $abbreviation = null,?int $book = null, ?int $chapter = null): string
|
||||
{
|
||||
if (!$this->active($abbreviation, $book, $chapter))
|
||||
{
|
||||
return '';
|
||||
}
|
||||
|
||||
$word_text = $this->get($abbreviation, $book, $chapter)->word_text ?? null;
|
||||
|
||||
if ($word_text !== null)
|
||||
{
|
||||
return $word_text;
|
||||
}
|
||||
|
||||
$verse_text = $this->get($abbreviation, $book, $chapter)->verse_text_array ?? null;
|
||||
|
||||
if ($verse_text === null &&
|
||||
($verse_text = $this->processVersesArray($abbreviation, $book, $chapter)) === null)
|
||||
{
|
||||
return '';
|
||||
}
|
||||
|
||||
if (($word_number = $this->getWordNumberArray($abbreviation, $book, $chapter)) === null)
|
||||
{
|
||||
return '';
|
||||
}
|
||||
|
||||
$word_array = $this->buildWordArray($verse_text, $word_number);
|
||||
|
||||
if ($word_array === [])
|
||||
{
|
||||
return '';
|
||||
}
|
||||
|
||||
$word_text = $this->wordArrayToString($word_array);
|
||||
|
||||
$this->get($abbreviation, $book, $chapter)->word_text = $word_text;
|
||||
|
||||
return $word_text;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the chapter
|
||||
*
|
||||
* @param string $abbreviation The translation abbreviation.
|
||||
* @param int $book The book number.
|
||||
* @param int $chapter The chapter number.
|
||||
* @param string|null $abbreviation The translation abbreviation.
|
||||
* @param int|null $book The book number.
|
||||
* @param int|null $chapter The chapter number.
|
||||
*
|
||||
* @return object|null True on success
|
||||
* @since 2.0.1
|
||||
*/
|
||||
public function get(string $abbreviation, int $book, int $chapter): ?object
|
||||
public function get(?string $abbreviation = null,?int $book = null, ?int $chapter = null): ?object
|
||||
{
|
||||
if (!isset($this->chapters[$abbreviation . $book . $chapter]))
|
||||
{
|
||||
$bucket = $this->load->item(['abbreviation' => $abbreviation, 'book_nr' => $book, 'chapter' => $chapter], 'chapter');
|
||||
$bucket->book = $this->load->item(['abbreviation' => $abbreviation, 'nr' => $book], 'book');
|
||||
$bucket->verses = $this->load->items(['abbreviation' => $abbreviation, 'book_nr' => $book, 'chapter' => $chapter], 'verse');
|
||||
$abbreviation = $abbreviation ?? $this->config->get('translation');
|
||||
$book = $book ?? $this->config->get('book');
|
||||
$chapter = $chapter ?? $this->config->get('chapter');
|
||||
|
||||
$this->chapters[$abbreviation . $book . $chapter] = $bucket;
|
||||
if ($abbreviation === null || $book === null || $chapter === null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return $this->chapters[$abbreviation . $book . $chapter];
|
||||
$cacheKey = $this->generateCacheKey($abbreviation, $book, $chapter);
|
||||
|
||||
if (isset($this->chapters[$cacheKey]))
|
||||
{
|
||||
return $this->chapters[$cacheKey];
|
||||
}
|
||||
|
||||
return $this->loadChapterData($abbreviation, $book, $chapter);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates a cache key based on the abbreviation, book, and chapter
|
||||
*
|
||||
* @param string $abbreviation The translation abbreviation.
|
||||
* @param int $book The book number.
|
||||
* @param int $chapter The chapter number.
|
||||
*
|
||||
* @return string The generated cache key.
|
||||
* @since 2.0.1
|
||||
*/
|
||||
private function generateCacheKey($abbreviation, $book, $chapter): string
|
||||
{
|
||||
return $abbreviation . $book . $chapter;
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads the chapter data from the database and updates the cache
|
||||
*
|
||||
* @param string $abbreviation The translation abbreviation.
|
||||
* @param int $book The book number.
|
||||
* @param int $chapter The chapter number.
|
||||
* @param string $cacheKey The cache key.
|
||||
*
|
||||
* @return object|null The loaded chapter data, or null if not found or an error occurred.
|
||||
* @since 2.0.1
|
||||
*/
|
||||
private function loadChapterData($abbreviation, $book, $chapter): ?object
|
||||
{
|
||||
$chapter_data = $this->load->item(
|
||||
['abbreviation' => $abbreviation, 'book_nr' => $book, 'chapter' => $chapter],
|
||||
'chapter'
|
||||
);
|
||||
|
||||
if ($chapter_data === null || !is_object($chapter_data))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
$chapter_data->book = $this->load->item(
|
||||
['abbreviation' => $abbreviation, 'nr' => $book],
|
||||
'book'
|
||||
);
|
||||
|
||||
if ($chapter_data->book === null || !is_object($chapter_data->book))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
$chapter_data->verses = $this->load->items(
|
||||
['abbreviation' => $abbreviation, 'book_nr' => $book, 'chapter' => $chapter],
|
||||
'verse'
|
||||
);
|
||||
|
||||
if ($chapter_data->verses === null || !is_array($chapter_data->verses))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
$this->config->set('translation', $abbreviation);
|
||||
$this->config->set('book', $book);
|
||||
$this->config->set('chapter', $chapter);
|
||||
|
||||
$cacheKey = $this->generateCacheKey($abbreviation, $book, $chapter);
|
||||
|
||||
$this->chapters[$cacheKey] = $chapter_data;
|
||||
|
||||
return $this->chapters[$cacheKey];
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if this chapter is active
|
||||
*
|
||||
* @param string|null $abbreviation The translation abbreviation.
|
||||
* @param int|null $book The book number.
|
||||
* @param int|null $chapter The chapter number.
|
||||
*
|
||||
* @return object|null True on success
|
||||
* @since 2.0.1
|
||||
*/
|
||||
private function active(?string $abbreviation = null,?int $book = null, ?int $chapter = null): bool
|
||||
{
|
||||
if ($this->get($abbreviation, $book, $chapter))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Processes the verses to extract the verse text
|
||||
*
|
||||
* @param string|null $abbreviation The translation abbreviation.
|
||||
* @param int|null $book The book number.
|
||||
* @param int|null $chapter The chapter number.
|
||||
*
|
||||
* @return string The processed verse text
|
||||
* @since 2.0.1
|
||||
*/
|
||||
private function processVerses(?string $abbreviation, ?int $book, ?int $chapter): string
|
||||
{
|
||||
$verse_numbers = $this->getVerseNumber($abbreviation, $book, $chapter);
|
||||
$verses = $this->get($abbreviation, $book, $chapter)->verses ?? null;
|
||||
|
||||
if (empty($verse_numbers) || empty($verses) || !is_array($verses))
|
||||
{
|
||||
return '';
|
||||
}
|
||||
|
||||
$verse_numbers = $this->extractVerseNumbers($verse_numbers);
|
||||
|
||||
$text = $this->getTextFromVerses($verses, $verse_numbers);
|
||||
|
||||
if (empty($text))
|
||||
{
|
||||
return '';
|
||||
}
|
||||
|
||||
$verse_text = implode(' ', $text);
|
||||
|
||||
$this->get($abbreviation, $book, $chapter)->verse_text = $verse_text;
|
||||
|
||||
return $verse_text;
|
||||
}
|
||||
|
||||
/**
|
||||
* Processes the verses to extract the verse text
|
||||
*
|
||||
* @param string|null $abbreviation The translation abbreviation.
|
||||
* @param int|null $book The book number.
|
||||
* @param int|null $chapter The chapter number.
|
||||
*
|
||||
* @return array|null The processed verse text
|
||||
* @since 2.0.1
|
||||
*/
|
||||
private function processVersesArray(?string $abbreviation, ?int $book, ?int $chapter): ?array
|
||||
{
|
||||
$verse_numbers = $this->getVerseNumber($abbreviation, $book, $chapter);
|
||||
$verses = $this->get($abbreviation, $book, $chapter)->verses ?? null;
|
||||
|
||||
if (empty($verse_numbers) || empty($verses) || !is_array($verses))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
$verse_numbers = $this->extractVerseNumbers($verse_numbers);
|
||||
|
||||
$text_array = $this->getArrayFromVerses($verses, $verse_numbers);
|
||||
|
||||
if (empty($text_array))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
$this->get($abbreviation, $book, $chapter)->verse_text_array = $text_array;
|
||||
|
||||
return $text_array;
|
||||
}
|
||||
|
||||
/**
|
||||
* Extracts the verse numbers from the input string
|
||||
*
|
||||
* @param string $verseNumber The verse number string.
|
||||
*
|
||||
* @return array An array of verse numbers
|
||||
* @since 2.0.1
|
||||
*/
|
||||
private function extractVerseNumbers(string $verseNumber): array
|
||||
{
|
||||
if (strpos($verseNumber, '-') !== false)
|
||||
{
|
||||
return array_map('trim', explode('-', $verseNumber));
|
||||
}
|
||||
|
||||
return [trim($verseNumber)];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the verse text from the verses array based on the verse numbers
|
||||
*
|
||||
* @param array $verses An array of verses.
|
||||
* @param array $verseNumber An array of verse numbers.
|
||||
*
|
||||
* @return array An array of verse texts
|
||||
* @since 2.0.1
|
||||
*/
|
||||
private function getTextFromVerses(array $verses, array $verseNumber): array
|
||||
{
|
||||
$text = [];
|
||||
$add = false;
|
||||
foreach ($verses as $verse)
|
||||
{
|
||||
if ($verse->verse == $verseNumber[0])
|
||||
{
|
||||
$add = true;
|
||||
}
|
||||
elseif (!isset($verseNumber[1]))
|
||||
{
|
||||
$add = false;
|
||||
}
|
||||
|
||||
if ($add)
|
||||
{
|
||||
$text[] = trim($verse->verse) . ' ' . trim($verse->text);
|
||||
}
|
||||
|
||||
if (isset($verseNumber[1]) && $verse->verse == $verseNumber[1])
|
||||
{
|
||||
$add = false;
|
||||
}
|
||||
}
|
||||
|
||||
return $text;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the verses array based on the verse numbers
|
||||
*
|
||||
* @param array $verses An array of verses.
|
||||
* @param array $verseNumber An array of verse numbers.
|
||||
*
|
||||
* @return array An array of verse texts
|
||||
* @since 2.0.1
|
||||
*/
|
||||
private function getArrayFromVerses(array $verses, array $verseNumber): array
|
||||
{
|
||||
$text = [];
|
||||
$add = false;
|
||||
foreach ($verses as $verse)
|
||||
{
|
||||
if ($verse->verse == $verseNumber[0])
|
||||
{
|
||||
$add = true;
|
||||
}
|
||||
elseif (!isset($verseNumber[1]))
|
||||
{
|
||||
$add = false;
|
||||
}
|
||||
|
||||
if ($add)
|
||||
{
|
||||
$text[$verse->verse] = $this->stringHelper->splitToWords(trim($verse->text), false);
|
||||
}
|
||||
|
||||
if (isset($verseNumber[1]) && $verse->verse == $verseNumber[1])
|
||||
{
|
||||
$add = false;
|
||||
}
|
||||
}
|
||||
|
||||
return $text;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the word number/s
|
||||
*
|
||||
* @param string|null $abbreviation The translation abbreviation.
|
||||
* @param int|null $book The book number.
|
||||
* @param int|null $chapter The chapter number.
|
||||
*
|
||||
* @return array|null The word number/s array
|
||||
* @since 2.0.1
|
||||
*/
|
||||
private function getWordNumberArray(?string $abbreviation = null,?int $book = null, ?int $chapter = null): ?array
|
||||
{
|
||||
if (!$this->active($abbreviation, $book, $chapter))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
$word_number_array = $this->get($abbreviation, $book, $chapter)->word_number_array ?? null;
|
||||
|
||||
if ($word_number_array !== null)
|
||||
{
|
||||
return $word_number_array;
|
||||
}
|
||||
|
||||
$verse = $this->config->get('verse');
|
||||
$words = $this->config->get('words');
|
||||
|
||||
if ($verse === null || $words === null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
$verse = $this->splitAndTrim($verse);
|
||||
$words = $this->splitAndTrim($words);
|
||||
|
||||
$word_number_array = $this->buildWordNumberArray($verse, $words);
|
||||
|
||||
if ($word_number_array === [])
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
$word_number = $this->wordNumberArrayToString($word_number_array);
|
||||
|
||||
$this->get($abbreviation, $book, $chapter)->word_number = $word_number;
|
||||
$this->get($abbreviation, $book, $chapter)->word_number_array = $word_number_array;
|
||||
|
||||
return $word_number_array;
|
||||
}
|
||||
|
||||
/**
|
||||
* Split verse or words by '-' and trim each element.
|
||||
*
|
||||
* @param string $str The string to be split.
|
||||
*
|
||||
* @return array The splitted and trimmed array.
|
||||
* @since 2.0.1
|
||||
*/
|
||||
private function splitAndTrim(string $str): array
|
||||
{
|
||||
if (strpos($str, '-') !== false)
|
||||
{
|
||||
return array_map('trim', explode('-', $str));
|
||||
}
|
||||
else
|
||||
{
|
||||
return [trim($str)];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Build word number array from verse and words.
|
||||
*
|
||||
* @param array $verse The verse array.
|
||||
* @param array $words The words array.
|
||||
*
|
||||
* @return array The word number array.
|
||||
* @since 2.0.1
|
||||
*/
|
||||
private function buildWordNumberArray(array $verse, array $words): array
|
||||
{
|
||||
$word_number_array = [];
|
||||
foreach ($verse as $key => $verse)
|
||||
{
|
||||
if (isset($words[$key]))
|
||||
{
|
||||
$word_number_array[$verse][] = $words[$key];
|
||||
}
|
||||
}
|
||||
|
||||
return $word_number_array;
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts word number array to string.
|
||||
*
|
||||
* @param array $wordNumberArray The word number array.
|
||||
*
|
||||
* @return string The word number string.
|
||||
* @since 2.0.1
|
||||
*/
|
||||
private function wordNumberArrayToString(array $wordNumberArray): string
|
||||
{
|
||||
$word_number = [];
|
||||
|
||||
foreach ($wordNumberArray as $verse => $words)
|
||||
{
|
||||
$word_number[] = $verse . ':' . implode(',', $words);
|
||||
}
|
||||
|
||||
return implode(';', $word_number);
|
||||
}
|
||||
|
||||
/**
|
||||
* Build word array from verse and words.
|
||||
*
|
||||
* @param array $verse The verse array.
|
||||
* @param array $words The words array.
|
||||
*
|
||||
* @return array The word array.
|
||||
* @since 2.0.1
|
||||
*/
|
||||
private function buildWordArray(array $verses, array $words): array
|
||||
{
|
||||
$word_array = [];
|
||||
foreach ($words as $verse => $word_numbers)
|
||||
{
|
||||
foreach ($word_numbers as $word)
|
||||
{
|
||||
if (isset($verses[$verse][$word]))
|
||||
{
|
||||
$word_array[$verse][] = $verses[$verse][$word];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $word_array;
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts word array to string.
|
||||
*
|
||||
* @param array $wordArray The word array.
|
||||
*
|
||||
* @return string The word string.
|
||||
* @since 2.0.1
|
||||
*/
|
||||
private function wordArrayToString(array $wordArray): string
|
||||
{
|
||||
$word_number = [];
|
||||
|
||||
foreach ($wordArray as $verse => $words)
|
||||
{
|
||||
$word_number[] = implode(' ', $words);
|
||||
}
|
||||
|
||||
return implode(' ', $word_number);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -6,6 +6,22 @@
|
||||
*/
|
||||
protected Load $load;
|
||||
|
||||
/**
|
||||
* The Config class
|
||||
*
|
||||
* @var Config
|
||||
* @since 2.0.1
|
||||
*/
|
||||
protected Config $config;
|
||||
|
||||
/**
|
||||
* The StringHelper class
|
||||
*
|
||||
* @var StringHelper
|
||||
* @since 2.0.1
|
||||
*/
|
||||
protected StringHelper $stringHelper;
|
||||
|
||||
/**
|
||||
* The chapters
|
||||
*
|
||||
@ -17,35 +33,774 @@
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param Load $load The load object.
|
||||
* @param Load $load The load object.
|
||||
* @param Config $config The config object.
|
||||
* @param StringHelper $stringHelper The string helper object.
|
||||
*
|
||||
* @since 2.0.1
|
||||
*/
|
||||
public function __construct(Load $load)
|
||||
public function __construct(Load $load, Config $config, StringHelper $stringHelper)
|
||||
{
|
||||
$this->load = $load;
|
||||
$this->config = $config;
|
||||
$this->stringHelper = $stringHelper;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the book name
|
||||
*
|
||||
* @param string|null $abbreviation The translation abbreviation.
|
||||
* @param int|null $book The book number.
|
||||
* @param int|null $chapter The chapter number.
|
||||
*
|
||||
* @return string The book name
|
||||
* @since 2.0.1
|
||||
*/
|
||||
public function getBookName(?string $abbreviation = null,?int $book = null, ?int $chapter = null): string
|
||||
{
|
||||
if ($this->active($abbreviation, $book, $chapter))
|
||||
{
|
||||
return $this->get($abbreviation, $book, $chapter)->book->name ?? '';
|
||||
}
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the chapter number
|
||||
*
|
||||
* @param string|null $abbreviation The translation abbreviation.
|
||||
* @param int|null $book The book number.
|
||||
* @param int|null $chapter The chapter number.
|
||||
*
|
||||
* @return string The chapter number
|
||||
* @since 2.0.1
|
||||
*/
|
||||
public function getChapterNumber(?string $abbreviation = null,?int $book = null, ?int $chapter = null): string
|
||||
{
|
||||
if ($this->active($abbreviation, $book, $chapter))
|
||||
{
|
||||
return $this->get($abbreviation, $book, $chapter)->chapter ?? '';
|
||||
}
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the chapter name
|
||||
*
|
||||
* @param string|null $abbreviation The translation abbreviation.
|
||||
* @param int|null $book The book number.
|
||||
* @param int|null $chapter The chapter number.
|
||||
*
|
||||
* @return string The chapter name
|
||||
* @since 2.0.1
|
||||
*/
|
||||
public function getChapterName(?string $abbreviation = null,?int $book = null, ?int $chapter = null): string
|
||||
{
|
||||
if ($this->active($abbreviation, $book, $chapter))
|
||||
{
|
||||
return $this->get($abbreviation, $book, $chapter)->name ?? '';
|
||||
}
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the chapter text
|
||||
*
|
||||
* @param string|null $abbreviation The translation abbreviation.
|
||||
* @param int|null $book The book number.
|
||||
* @param int|null $chapter The chapter number.
|
||||
*
|
||||
* @return string The chapter text
|
||||
* @since 2.0.1
|
||||
*/
|
||||
public function getChapterText(?string $abbreviation = null,?int $book = null, ?int $chapter = null): string
|
||||
{
|
||||
if (!$this->active($abbreviation, $book, $chapter))
|
||||
{
|
||||
return '';
|
||||
}
|
||||
|
||||
$verses = $this->get($abbreviation, $book, $chapter)->verses ?? null;
|
||||
|
||||
if (empty($verses) || !is_array($verses))
|
||||
{
|
||||
return '';
|
||||
}
|
||||
|
||||
$text = [];
|
||||
foreach ($verses as $verse)
|
||||
{
|
||||
$text[] = trim($verse->verse) . ' ' . trim($verse->text);
|
||||
}
|
||||
|
||||
return implode(' ', $text);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the verse number/s
|
||||
*
|
||||
* @param string|null $abbreviation The translation abbreviation.
|
||||
* @param int|null $book The book number.
|
||||
* @param int|null $chapter The chapter number.
|
||||
*
|
||||
* @return string The verse number/s
|
||||
* @since 2.0.1
|
||||
*/
|
||||
public function getVerseNumber(?string $abbreviation = null,?int $book = null, ?int $chapter = null): string
|
||||
{
|
||||
if (!$this->active($abbreviation, $book, $chapter))
|
||||
{
|
||||
return '';
|
||||
}
|
||||
|
||||
$verse_number = $this->get($abbreviation, $book, $chapter)->verse_number ?? null;
|
||||
|
||||
if ($verse_number !== null)
|
||||
{
|
||||
return $verse_number;
|
||||
}
|
||||
|
||||
$verse = $this->config->get('verse');
|
||||
|
||||
if ($verse === null)
|
||||
{
|
||||
return '';
|
||||
}
|
||||
|
||||
if (strpos($verse, '-') !== false)
|
||||
{
|
||||
$verses = $this->splitAndTrim($verse);
|
||||
$minVerse = min($verses);
|
||||
$maxVerse = max($verses);
|
||||
|
||||
if ($minVerse == $maxVerse)
|
||||
{
|
||||
$verse_number = $minVerse;
|
||||
}
|
||||
else
|
||||
{
|
||||
$verse_number = $minVerse . '-' . $maxVerse;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$verse_number = trim($verse);
|
||||
}
|
||||
|
||||
$this->get($abbreviation, $book, $chapter)->verse_number = $verse_number;
|
||||
|
||||
return $verse_number;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the verse name
|
||||
*
|
||||
* @param string|null $abbreviation The translation abbreviation.
|
||||
* @param int|null $book The book number.
|
||||
* @param int|null $chapter The chapter number.
|
||||
*
|
||||
* @return string The verse name
|
||||
* @since 2.0.1
|
||||
*/
|
||||
public function getVerseName(?string $abbreviation = null,?int $book = null, ?int $chapter = null): string
|
||||
{
|
||||
if (!$this->active($abbreviation, $book, $chapter))
|
||||
{
|
||||
return '';
|
||||
}
|
||||
|
||||
$verse_name = $this->get($abbreviation, $book, $chapter)->verse_name ?? null;
|
||||
|
||||
if ($verse_name !== null)
|
||||
{
|
||||
return $verse_name;
|
||||
}
|
||||
|
||||
$chapter_name = $this->getChapterName($abbreviation, $book, $chapter);
|
||||
$verse_number = $this->getVerseNumber($abbreviation, $book, $chapter);
|
||||
|
||||
if (empty($chapter_name) || empty($verse_number))
|
||||
{
|
||||
return '';
|
||||
}
|
||||
|
||||
$verse_name = $chapter_name . ':' . $verse_number;
|
||||
|
||||
$this->get($abbreviation, $book, $chapter)->verse_name = $verse_name;
|
||||
|
||||
return $verse_name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the verse text
|
||||
*
|
||||
* @param string|null $abbreviation The translation abbreviation.
|
||||
* @param int|null $book The book number.
|
||||
* @param int|null $chapter The chapter number.
|
||||
*
|
||||
* @return string The verse text
|
||||
* @since 2.0.1
|
||||
*/
|
||||
public function getVerseText(?string $abbreviation = null,?int $book = null, ?int $chapter = null): string
|
||||
{
|
||||
if (!$this->active($abbreviation, $book, $chapter))
|
||||
{
|
||||
return '';
|
||||
}
|
||||
|
||||
$verse_text = $this->get($abbreviation, $book, $chapter)->verse_text ?? null;
|
||||
|
||||
if ($verse_text !== null)
|
||||
{
|
||||
return $verse_text;
|
||||
}
|
||||
|
||||
return $this->processVerses($abbreviation, $book, $chapter);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the word number/s
|
||||
*
|
||||
* @param string|null $abbreviation The translation abbreviation.
|
||||
* @param int|null $book The book number.
|
||||
* @param int|null $chapter The chapter number.
|
||||
*
|
||||
* @return string The word number/s
|
||||
* @since 2.0.1
|
||||
*/
|
||||
public function getWordNumber(?string $abbreviation = null,?int $book = null, ?int $chapter = null): string
|
||||
{
|
||||
if (!$this->active($abbreviation, $book, $chapter))
|
||||
{
|
||||
return '';
|
||||
}
|
||||
|
||||
$word_number = $this->get($abbreviation, $book, $chapter)->word_number ?? null;
|
||||
|
||||
if ($word_number !== null)
|
||||
{
|
||||
return $word_number;
|
||||
}
|
||||
|
||||
$verse = $this->config->get('verse');
|
||||
$words = $this->config->get('words');
|
||||
|
||||
if ($verse === null || $words === null)
|
||||
{
|
||||
return '';
|
||||
}
|
||||
|
||||
$verse = $this->splitAndTrim($verse);
|
||||
$words = $this->splitAndTrim($words);
|
||||
|
||||
$word_number_array = $this->buildWordNumberArray($verse, $words);
|
||||
|
||||
if ($word_number_array === [])
|
||||
{
|
||||
return '';
|
||||
}
|
||||
|
||||
$word_number = $this->wordNumberArrayToString($word_number_array);
|
||||
|
||||
$this->get($abbreviation, $book, $chapter)->word_number = $word_number;
|
||||
$this->get($abbreviation, $book, $chapter)->word_number_array = $word_number_array;
|
||||
|
||||
return $word_number;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the word text
|
||||
*
|
||||
* @param string|null $abbreviation The translation abbreviation.
|
||||
* @param int|null $book The book number.
|
||||
* @param int|null $chapter The chapter number.
|
||||
*
|
||||
* @return string The verse text
|
||||
* @since 2.0.1
|
||||
*/
|
||||
public function getWordText(?string $abbreviation = null,?int $book = null, ?int $chapter = null): string
|
||||
{
|
||||
if (!$this->active($abbreviation, $book, $chapter))
|
||||
{
|
||||
return '';
|
||||
}
|
||||
|
||||
$word_text = $this->get($abbreviation, $book, $chapter)->word_text ?? null;
|
||||
|
||||
if ($word_text !== null)
|
||||
{
|
||||
return $word_text;
|
||||
}
|
||||
|
||||
$verse_text = $this->get($abbreviation, $book, $chapter)->verse_text_array ?? null;
|
||||
|
||||
if ($verse_text === null &&
|
||||
($verse_text = $this->processVersesArray($abbreviation, $book, $chapter)) === null)
|
||||
{
|
||||
return '';
|
||||
}
|
||||
|
||||
if (($word_number = $this->getWordNumberArray($abbreviation, $book, $chapter)) === null)
|
||||
{
|
||||
return '';
|
||||
}
|
||||
|
||||
$word_array = $this->buildWordArray($verse_text, $word_number);
|
||||
|
||||
if ($word_array === [])
|
||||
{
|
||||
return '';
|
||||
}
|
||||
|
||||
$word_text = $this->wordArrayToString($word_array);
|
||||
|
||||
$this->get($abbreviation, $book, $chapter)->word_text = $word_text;
|
||||
|
||||
return $word_text;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the chapter
|
||||
*
|
||||
* @param string $abbreviation The translation abbreviation.
|
||||
* @param int $book The book number.
|
||||
* @param int $chapter The chapter number.
|
||||
* @param string|null $abbreviation The translation abbreviation.
|
||||
* @param int|null $book The book number.
|
||||
* @param int|null $chapter The chapter number.
|
||||
*
|
||||
* @return object|null True on success
|
||||
* @since 2.0.1
|
||||
*/
|
||||
public function get(string $abbreviation, int $book, int $chapter): ?object
|
||||
public function get(?string $abbreviation = null,?int $book = null, ?int $chapter = null): ?object
|
||||
{
|
||||
if (!isset($this->chapters[$abbreviation . $book . $chapter]))
|
||||
{
|
||||
$bucket = $this->load->item(['abbreviation' => $abbreviation, 'book_nr' => $book, 'chapter' => $chapter], 'chapter');
|
||||
$bucket->book = $this->load->item(['abbreviation' => $abbreviation, 'nr' => $book], 'book');
|
||||
$bucket->verses = $this->load->items(['abbreviation' => $abbreviation, 'book_nr' => $book, 'chapter' => $chapter], 'verse');
|
||||
$abbreviation = $abbreviation ?? $this->config->get('translation');
|
||||
$book = $book ?? $this->config->get('book');
|
||||
$chapter = $chapter ?? $this->config->get('chapter');
|
||||
|
||||
$this->chapters[$abbreviation . $book . $chapter] = $bucket;
|
||||
if ($abbreviation === null || $book === null || $chapter === null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return $this->chapters[$abbreviation . $book . $chapter];
|
||||
$cacheKey = $this->generateCacheKey($abbreviation, $book, $chapter);
|
||||
|
||||
if (isset($this->chapters[$cacheKey]))
|
||||
{
|
||||
return $this->chapters[$cacheKey];
|
||||
}
|
||||
|
||||
return $this->loadChapterData($abbreviation, $book, $chapter);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates a cache key based on the abbreviation, book, and chapter
|
||||
*
|
||||
* @param string $abbreviation The translation abbreviation.
|
||||
* @param int $book The book number.
|
||||
* @param int $chapter The chapter number.
|
||||
*
|
||||
* @return string The generated cache key.
|
||||
* @since 2.0.1
|
||||
*/
|
||||
private function generateCacheKey($abbreviation, $book, $chapter): string
|
||||
{
|
||||
return $abbreviation . $book . $chapter;
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads the chapter data from the database and updates the cache
|
||||
*
|
||||
* @param string $abbreviation The translation abbreviation.
|
||||
* @param int $book The book number.
|
||||
* @param int $chapter The chapter number.
|
||||
* @param string $cacheKey The cache key.
|
||||
*
|
||||
* @return object|null The loaded chapter data, or null if not found or an error occurred.
|
||||
* @since 2.0.1
|
||||
*/
|
||||
private function loadChapterData($abbreviation, $book, $chapter): ?object
|
||||
{
|
||||
$chapter_data = $this->load->item(
|
||||
['abbreviation' => $abbreviation, 'book_nr' => $book, 'chapter' => $chapter],
|
||||
'chapter'
|
||||
);
|
||||
|
||||
if ($chapter_data === null || !is_object($chapter_data))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
$chapter_data->book = $this->load->item(
|
||||
['abbreviation' => $abbreviation, 'nr' => $book],
|
||||
'book'
|
||||
);
|
||||
|
||||
if ($chapter_data->book === null || !is_object($chapter_data->book))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
$chapter_data->verses = $this->load->items(
|
||||
['abbreviation' => $abbreviation, 'book_nr' => $book, 'chapter' => $chapter],
|
||||
'verse'
|
||||
);
|
||||
|
||||
if ($chapter_data->verses === null || !is_array($chapter_data->verses))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
$this->config->set('translation', $abbreviation);
|
||||
$this->config->set('book', $book);
|
||||
$this->config->set('chapter', $chapter);
|
||||
|
||||
$cacheKey = $this->generateCacheKey($abbreviation, $book, $chapter);
|
||||
|
||||
$this->chapters[$cacheKey] = $chapter_data;
|
||||
|
||||
return $this->chapters[$cacheKey];
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if this chapter is active
|
||||
*
|
||||
* @param string|null $abbreviation The translation abbreviation.
|
||||
* @param int|null $book The book number.
|
||||
* @param int|null $chapter The chapter number.
|
||||
*
|
||||
* @return object|null True on success
|
||||
* @since 2.0.1
|
||||
*/
|
||||
private function active(?string $abbreviation = null,?int $book = null, ?int $chapter = null): bool
|
||||
{
|
||||
if ($this->get($abbreviation, $book, $chapter))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Processes the verses to extract the verse text
|
||||
*
|
||||
* @param string|null $abbreviation The translation abbreviation.
|
||||
* @param int|null $book The book number.
|
||||
* @param int|null $chapter The chapter number.
|
||||
*
|
||||
* @return string The processed verse text
|
||||
* @since 2.0.1
|
||||
*/
|
||||
private function processVerses(?string $abbreviation, ?int $book, ?int $chapter): string
|
||||
{
|
||||
$verse_numbers = $this->getVerseNumber($abbreviation, $book, $chapter);
|
||||
$verses = $this->get($abbreviation, $book, $chapter)->verses ?? null;
|
||||
|
||||
if (empty($verse_numbers) || empty($verses) || !is_array($verses))
|
||||
{
|
||||
return '';
|
||||
}
|
||||
|
||||
$verse_numbers = $this->extractVerseNumbers($verse_numbers);
|
||||
|
||||
$text = $this->getTextFromVerses($verses, $verse_numbers);
|
||||
|
||||
if (empty($text))
|
||||
{
|
||||
return '';
|
||||
}
|
||||
|
||||
$verse_text = implode(' ', $text);
|
||||
|
||||
$this->get($abbreviation, $book, $chapter)->verse_text = $verse_text;
|
||||
|
||||
return $verse_text;
|
||||
}
|
||||
|
||||
/**
|
||||
* Processes the verses to extract the verse text
|
||||
*
|
||||
* @param string|null $abbreviation The translation abbreviation.
|
||||
* @param int|null $book The book number.
|
||||
* @param int|null $chapter The chapter number.
|
||||
*
|
||||
* @return array|null The processed verse text
|
||||
* @since 2.0.1
|
||||
*/
|
||||
private function processVersesArray(?string $abbreviation, ?int $book, ?int $chapter): ?array
|
||||
{
|
||||
$verse_numbers = $this->getVerseNumber($abbreviation, $book, $chapter);
|
||||
$verses = $this->get($abbreviation, $book, $chapter)->verses ?? null;
|
||||
|
||||
if (empty($verse_numbers) || empty($verses) || !is_array($verses))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
$verse_numbers = $this->extractVerseNumbers($verse_numbers);
|
||||
|
||||
$text_array = $this->getArrayFromVerses($verses, $verse_numbers);
|
||||
|
||||
if (empty($text_array))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
$this->get($abbreviation, $book, $chapter)->verse_text_array = $text_array;
|
||||
|
||||
return $text_array;
|
||||
}
|
||||
|
||||
/**
|
||||
* Extracts the verse numbers from the input string
|
||||
*
|
||||
* @param string $verseNumber The verse number string.
|
||||
*
|
||||
* @return array An array of verse numbers
|
||||
* @since 2.0.1
|
||||
*/
|
||||
private function extractVerseNumbers(string $verseNumber): array
|
||||
{
|
||||
if (strpos($verseNumber, '-') !== false)
|
||||
{
|
||||
return array_map('trim', explode('-', $verseNumber));
|
||||
}
|
||||
|
||||
return [trim($verseNumber)];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the verse text from the verses array based on the verse numbers
|
||||
*
|
||||
* @param array $verses An array of verses.
|
||||
* @param array $verseNumber An array of verse numbers.
|
||||
*
|
||||
* @return array An array of verse texts
|
||||
* @since 2.0.1
|
||||
*/
|
||||
private function getTextFromVerses(array $verses, array $verseNumber): array
|
||||
{
|
||||
$text = [];
|
||||
$add = false;
|
||||
foreach ($verses as $verse)
|
||||
{
|
||||
if ($verse->verse == $verseNumber[0])
|
||||
{
|
||||
$add = true;
|
||||
}
|
||||
elseif (!isset($verseNumber[1]))
|
||||
{
|
||||
$add = false;
|
||||
}
|
||||
|
||||
if ($add)
|
||||
{
|
||||
$text[] = trim($verse->verse) . ' ' . trim($verse->text);
|
||||
}
|
||||
|
||||
if (isset($verseNumber[1]) && $verse->verse == $verseNumber[1])
|
||||
{
|
||||
$add = false;
|
||||
}
|
||||
}
|
||||
|
||||
return $text;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the verses array based on the verse numbers
|
||||
*
|
||||
* @param array $verses An array of verses.
|
||||
* @param array $verseNumber An array of verse numbers.
|
||||
*
|
||||
* @return array An array of verse texts
|
||||
* @since 2.0.1
|
||||
*/
|
||||
private function getArrayFromVerses(array $verses, array $verseNumber): array
|
||||
{
|
||||
$text = [];
|
||||
$add = false;
|
||||
foreach ($verses as $verse)
|
||||
{
|
||||
if ($verse->verse == $verseNumber[0])
|
||||
{
|
||||
$add = true;
|
||||
}
|
||||
elseif (!isset($verseNumber[1]))
|
||||
{
|
||||
$add = false;
|
||||
}
|
||||
|
||||
if ($add)
|
||||
{
|
||||
$text[$verse->verse] = $this->stringHelper->splitToWords(trim($verse->text), false);
|
||||
}
|
||||
|
||||
if (isset($verseNumber[1]) && $verse->verse == $verseNumber[1])
|
||||
{
|
||||
$add = false;
|
||||
}
|
||||
}
|
||||
|
||||
return $text;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the word number/s
|
||||
*
|
||||
* @param string|null $abbreviation The translation abbreviation.
|
||||
* @param int|null $book The book number.
|
||||
* @param int|null $chapter The chapter number.
|
||||
*
|
||||
* @return array|null The word number/s array
|
||||
* @since 2.0.1
|
||||
*/
|
||||
private function getWordNumberArray(?string $abbreviation = null,?int $book = null, ?int $chapter = null): ?array
|
||||
{
|
||||
if (!$this->active($abbreviation, $book, $chapter))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
$word_number_array = $this->get($abbreviation, $book, $chapter)->word_number_array ?? null;
|
||||
|
||||
if ($word_number_array !== null)
|
||||
{
|
||||
return $word_number_array;
|
||||
}
|
||||
|
||||
$verse = $this->config->get('verse');
|
||||
$words = $this->config->get('words');
|
||||
|
||||
if ($verse === null || $words === null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
$verse = $this->splitAndTrim($verse);
|
||||
$words = $this->splitAndTrim($words);
|
||||
|
||||
$word_number_array = $this->buildWordNumberArray($verse, $words);
|
||||
|
||||
if ($word_number_array === [])
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
$word_number = $this->wordNumberArrayToString($word_number_array);
|
||||
|
||||
$this->get($abbreviation, $book, $chapter)->word_number = $word_number;
|
||||
$this->get($abbreviation, $book, $chapter)->word_number_array = $word_number_array;
|
||||
|
||||
return $word_number_array;
|
||||
}
|
||||
|
||||
/**
|
||||
* Split verse or words by '-' and trim each element.
|
||||
*
|
||||
* @param string $str The string to be split.
|
||||
*
|
||||
* @return array The splitted and trimmed array.
|
||||
* @since 2.0.1
|
||||
*/
|
||||
private function splitAndTrim(string $str): array
|
||||
{
|
||||
if (strpos($str, '-') !== false)
|
||||
{
|
||||
return array_map('trim', explode('-', $str));
|
||||
}
|
||||
else
|
||||
{
|
||||
return [trim($str)];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Build word number array from verse and words.
|
||||
*
|
||||
* @param array $verse The verse array.
|
||||
* @param array $words The words array.
|
||||
*
|
||||
* @return array The word number array.
|
||||
* @since 2.0.1
|
||||
*/
|
||||
private function buildWordNumberArray(array $verse, array $words): array
|
||||
{
|
||||
$word_number_array = [];
|
||||
foreach ($verse as $key => $verse)
|
||||
{
|
||||
if (isset($words[$key]))
|
||||
{
|
||||
$word_number_array[$verse][] = $words[$key];
|
||||
}
|
||||
}
|
||||
|
||||
return $word_number_array;
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts word number array to string.
|
||||
*
|
||||
* @param array $wordNumberArray The word number array.
|
||||
*
|
||||
* @return string The word number string.
|
||||
* @since 2.0.1
|
||||
*/
|
||||
private function wordNumberArrayToString(array $wordNumberArray): string
|
||||
{
|
||||
$word_number = [];
|
||||
|
||||
foreach ($wordNumberArray as $verse => $words)
|
||||
{
|
||||
$word_number[] = $verse . ':' . implode(',', $words);
|
||||
}
|
||||
|
||||
return implode(';', $word_number);
|
||||
}
|
||||
|
||||
/**
|
||||
* Build word array from verse and words.
|
||||
*
|
||||
* @param array $verse The verse array.
|
||||
* @param array $words The words array.
|
||||
*
|
||||
* @return array The word array.
|
||||
* @since 2.0.1
|
||||
*/
|
||||
private function buildWordArray(array $verses, array $words): array
|
||||
{
|
||||
$word_array = [];
|
||||
foreach ($words as $verse => $word_numbers)
|
||||
{
|
||||
foreach ($word_numbers as $word)
|
||||
{
|
||||
if (isset($verses[$verse][$word]))
|
||||
{
|
||||
$word_array[$verse][] = $verses[$verse][$word];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $word_array;
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts word array to string.
|
||||
*
|
||||
* @param array $wordArray The word array.
|
||||
*
|
||||
* @return string The word string.
|
||||
* @since 2.0.1
|
||||
*/
|
||||
private function wordArrayToString(array $wordArray): string
|
||||
{
|
||||
$word_number = [];
|
||||
|
||||
foreach ($wordArray as $verse => $words)
|
||||
{
|
||||
$word_number[] = implode(' ', $words);
|
||||
}
|
||||
|
||||
return implode(' ', $word_number);
|
||||
}
|
@ -13,6 +13,14 @@
|
||||
"use_selection0": {
|
||||
"use": "c03b9c61-17d3-4774-a335-783903719f83",
|
||||
"as": "default"
|
||||
},
|
||||
"use_selection1": {
|
||||
"use": "3af7864b-f1f3-491e-b16f-0504f890086d",
|
||||
"as": "default"
|
||||
},
|
||||
"use_selection2": {
|
||||
"use": "a5b32737-207d-4cf6-b8ae-ee815612c3a0",
|
||||
"as": "default"
|
||||
}
|
||||
},
|
||||
"namespace": "VDM\\Joomla\\GetBible\\Data.Chapter",
|
||||
|
@ -12,6 +12,7 @@
|
||||
@startuml
|
||||
class StringHelper << (F,LightGreen) >> #Green {
|
||||
+ split(string $text) : array
|
||||
+ splitToWords(string $text, bool $punctuation = true) : array
|
||||
+ isCJK(string $text) : bool
|
||||
+ hasLength(string $word) : bool
|
||||
}
|
||||
@ -22,6 +23,12 @@ note right of StringHelper::split
|
||||
return: array
|
||||
end note
|
||||
|
||||
note right of StringHelper::splitToWords
|
||||
Return an array of only words
|
||||
|
||||
return: array
|
||||
end note
|
||||
|
||||
note right of StringHelper::isCJK
|
||||
Checks if a string contains characters typically used in East Asian languages (Chinese, Japanese, Korean)
|
||||
These languages do not typically use word boundaries in the same way as languages written in Latin script
|
||||
|
@ -46,6 +46,43 @@ final class StringHelper
|
||||
return $words;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an array of only words
|
||||
*
|
||||
* @param string $text The actual sentence
|
||||
* @param bool $punctuation Switch to keep or remove punctuation
|
||||
*
|
||||
* @return array An array of words
|
||||
*/
|
||||
public function splitToWords(string $text, bool $punctuation = true): array
|
||||
{
|
||||
$words = array_filter($this->split($text), function($word) {
|
||||
if ($this->hasLength($word)) {
|
||||
return true;
|
||||
} return false;
|
||||
});
|
||||
|
||||
if ($words === [])
|
||||
{
|
||||
return $words;
|
||||
}
|
||||
|
||||
// remove punctuation
|
||||
if (!$punctuation)
|
||||
{
|
||||
$words = array_map(function($word) {
|
||||
return preg_replace('/[^\p{L}\p{N}\s]/u', '', $word);
|
||||
}, $words);
|
||||
}
|
||||
|
||||
// make the array 1 based
|
||||
// so that the key 1 is the first word
|
||||
array_unshift($words, null);
|
||||
unset($words[0]);
|
||||
|
||||
return $words;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if a string contains characters typically used in East Asian languages (Chinese, Japanese, Korean)
|
||||
* These languages do not typically use word boundaries in the same way as languages written in Latin script
|
||||
|
@ -25,6 +25,43 @@
|
||||
return $words;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an array of only words
|
||||
*
|
||||
* @param string $text The actual sentence
|
||||
* @param bool $punctuation Switch to keep or remove punctuation
|
||||
*
|
||||
* @return array An array of words
|
||||
*/
|
||||
public function splitToWords(string $text, bool $punctuation = true): array
|
||||
{
|
||||
$words = array_filter($this->split($text), function($word) {
|
||||
if ($this->hasLength($word)) {
|
||||
return true;
|
||||
} return false;
|
||||
});
|
||||
|
||||
if ($words === [])
|
||||
{
|
||||
return $words;
|
||||
}
|
||||
|
||||
// remove punctuation
|
||||
if (!$punctuation)
|
||||
{
|
||||
$words = array_map(function($word) {
|
||||
return preg_replace('/[^\p{L}\p{N}\s]/u', '', $word);
|
||||
}, $words);
|
||||
}
|
||||
|
||||
// make the array 1 based
|
||||
// so that the key 1 is the first word
|
||||
array_unshift($words, null);
|
||||
unset($words[0]);
|
||||
|
||||
return $words;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if a string contains characters typically used in East Asian languages (Chinese, Japanese, Korean)
|
||||
* These languages do not typically use word boundaries in the same way as languages written in Latin script
|
||||
|
@ -12,7 +12,7 @@
|
||||
namespace VDM\Joomla\GetBible\Model;
|
||||
|
||||
|
||||
use VDM\Joomla\GetBible\Config;
|
||||
use VDM\Joomla\Abstraction\BaseConfig as Config;
|
||||
use VDM\Joomla\GetBible\Table;
|
||||
use VDM\Joomla\Utilities\StringHelper;
|
||||
use VDM\Joomla\Utilities\ArrayHelper;
|
||||
|
@ -13,8 +13,8 @@
|
||||
"type": "final class",
|
||||
"use_selection": {
|
||||
"use_selection0": {
|
||||
"use": "71075f03-4e77-4fc0-840a-ef55fd9260b2",
|
||||
"as": "default"
|
||||
"use": "ffbd4e1f-a342-4080-ab7d-1de3741bf319",
|
||||
"as": "Config"
|
||||
},
|
||||
"use_selection1": {
|
||||
"use": "ff8d5fdb-2d1f-4178-bd18-a43b8efd1068",
|
||||
|
@ -49,9 +49,8 @@ class AI implements ServiceProviderInterface
|
||||
public function getAI(Container $container): GetBible
|
||||
{
|
||||
return new GetBible(
|
||||
$container->get('GetBible.Translation'),
|
||||
$container->get('GetBible.Chapter'),
|
||||
$container->get('GetBible.Prompt')
|
||||
$container->get('GetBible.Prompt'),
|
||||
$container->get('GetBible.Placeholders')
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -23,8 +23,7 @@
|
||||
public function getAI(Container $container): GetBible
|
||||
{
|
||||
return new GetBible(
|
||||
$container->get('GetBible.Translation'),
|
||||
$container->get('GetBible.Chapter'),
|
||||
$container->get('GetBible.Prompt')
|
||||
$container->get('GetBible.Prompt'),
|
||||
$container->get('GetBible.Placeholders')
|
||||
);
|
||||
}
|
76
src/ba2151c0-8ffa-4a07-ba6e-93f135a3e9d5/README.md
Normal file
76
src/ba2151c0-8ffa-4a07-ba6e-93f135a3e9d5/README.md
Normal file
@ -0,0 +1,76 @@
|
||||
```
|
||||
██████╗ ██████╗ ██╗ ██╗███████╗██████╗
|
||||
██╔══██╗██╔═══██╗██║ ██║██╔════╝██╔══██╗
|
||||
██████╔╝██║ ██║██║ █╗ ██║█████╗ ██████╔╝
|
||||
██╔═══╝ ██║ ██║██║███╗██║██╔══╝ ██╔══██╗
|
||||
██║ ╚██████╔╝╚███╔███╔╝███████╗██║ ██║
|
||||
╚═╝ ╚═════╝ ╚══╝╚══╝ ╚══════╝╚═╝ ╚═╝
|
||||
```
|
||||
# final class Placeholders (Details)
|
||||
> namespace: **VDM\Joomla\GetBible\Data**
|
||||
```uml
|
||||
@startuml
|
||||
class Placeholders << (F,LightGreen) >> #Green {
|
||||
# Translation $translation
|
||||
# Chapter $chapter
|
||||
# Prompt $prompt
|
||||
+ __construct(Translation $translation, Chapter $chapter, ...)
|
||||
+ get() : array
|
||||
- all() : array
|
||||
- without() : array
|
||||
- words() : array
|
||||
}
|
||||
|
||||
note right of Placeholders::__construct
|
||||
Constructor
|
||||
|
||||
since: 2.0.1
|
||||
|
||||
arguments:
|
||||
Translation $translation
|
||||
Chapter $chapter
|
||||
Prompt $prompt
|
||||
end note
|
||||
|
||||
note right of Placeholders::get
|
||||
Get the Open AI response
|
||||
|
||||
since: 2.0.1
|
||||
return: array
|
||||
end note
|
||||
|
||||
note right of Placeholders::all
|
||||
Get All Placeholders
|
||||
|
||||
since: 2.0.1
|
||||
return: array
|
||||
end note
|
||||
|
||||
note right of Placeholders::without
|
||||
Get All Placeholders without words
|
||||
|
||||
since: 2.0.1
|
||||
return: array
|
||||
end note
|
||||
|
||||
note right of Placeholders::words
|
||||
Get Words Placeholders
|
||||
|
||||
since: 2.0.1
|
||||
return: array
|
||||
end note
|
||||
|
||||
@enduml
|
||||
```
|
||||
|
||||
---
|
||||
```
|
||||
██╗ ██████╗██████╗
|
||||
██║██╔════╝██╔══██╗
|
||||
██║██║ ██████╔╝
|
||||
██ ██║██║ ██╔══██╗
|
||||
╚█████╔╝╚██████╗██████╔╝
|
||||
╚════╝ ╚═════╝╚═════╝
|
||||
```
|
||||
> Build with [Joomla Component Builder](https://git.vdm.dev/joomla/Component-Builder)
|
||||
|
160
src/ba2151c0-8ffa-4a07-ba6e-93f135a3e9d5/code.php
Normal file
160
src/ba2151c0-8ffa-4a07-ba6e-93f135a3e9d5/code.php
Normal file
@ -0,0 +1,160 @@
|
||||
<?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\Data;
|
||||
|
||||
|
||||
use VDM\Joomla\GetBible\Data\Translation;
|
||||
use VDM\Joomla\GetBible\Data\Chapter;
|
||||
use VDM\Joomla\GetBible\Data\Prompt;
|
||||
|
||||
|
||||
/**
|
||||
* The GetBible Prompt Placeholders
|
||||
*
|
||||
* @since 2.0.1
|
||||
*/
|
||||
final class Placeholders
|
||||
{
|
||||
/**
|
||||
* The Translation class
|
||||
*
|
||||
* @var Translation
|
||||
* @since 2.0.1
|
||||
*/
|
||||
protected Translation $translation;
|
||||
|
||||
/**
|
||||
* The Chapter class
|
||||
*
|
||||
* @var Chapter
|
||||
* @since 2.0.1
|
||||
*/
|
||||
protected Chapter $chapter;
|
||||
|
||||
/**
|
||||
* The Prompt class
|
||||
*
|
||||
* @var Prompt
|
||||
* @since 2.0.1
|
||||
*/
|
||||
protected Prompt $prompt;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param Translation $translation The translation object.
|
||||
* @param Chapter $chapter The chapter object.
|
||||
* @param Prompt $prompt The prompt object.
|
||||
*
|
||||
* @since 2.0.1
|
||||
*/
|
||||
public function __construct(Translation $translation, Chapter $chapter, Prompt $prompt)
|
||||
{
|
||||
$this->translation = $translation;
|
||||
$this->chapter = $chapter;
|
||||
$this->prompt = $prompt;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Open AI response
|
||||
*
|
||||
* @param string $guid The prompt guid.
|
||||
*
|
||||
* @return array|null Array of response messages
|
||||
* @since 2.0.1
|
||||
*/
|
||||
public function get(): array
|
||||
{
|
||||
$integration = $this->prompt->getIntegration();
|
||||
$cache_behaviour = $this->prompt->getCacheBehaviour();
|
||||
|
||||
if ($integration === null || $cache_behaviour === null)
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
if (($integration == 1 || $integration == 3) && ($cache_behaviour == 0 || $cache_behaviour == 2))
|
||||
{
|
||||
return $this->all();
|
||||
}
|
||||
elseif ($integration == 2 && ($cache_behaviour == 0 || $cache_behaviour == 2))
|
||||
{
|
||||
return $this->without();
|
||||
}
|
||||
|
||||
return $this->words();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get All Placeholders
|
||||
*
|
||||
* @return array Array of Placeholders
|
||||
* @since 2.0.1
|
||||
*/
|
||||
private function all(): array
|
||||
{
|
||||
return [
|
||||
'[translation_name]' => $this->translation->getName(),
|
||||
'[translation_language]' => $this->translation->getLanguage(),
|
||||
'[translation_lcsh]' => $this->translation->getLcsh(),
|
||||
'[translation_abbreviation]' => $this->translation->getAbbreviation(),
|
||||
'[book_name]' => $this->chapter->getBookName(),
|
||||
'[chapter_number]' => $this->chapter->getChapterNumber(),
|
||||
'[chapter_name]' => $this->chapter->getChapterName(),
|
||||
'[chapter_text]' => $this->chapter->getChapterText(),
|
||||
'[verse_number]' => $this->chapter->getVerseNumber(),
|
||||
'[verse_name]' => $this->chapter->getVerseName(),
|
||||
'[verse_text]' => $this->chapter->getVerseText(),
|
||||
'[selected_words_number]' => $this->chapter->getWordNumber(),
|
||||
'[selected_word]' => $this->chapter->getWordText()
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get All Placeholders without words
|
||||
*
|
||||
* @return array Array of Placeholders
|
||||
* @since 2.0.1
|
||||
*/
|
||||
private function without(): array
|
||||
{
|
||||
return [
|
||||
'[translation_name]' => $this->translation->getName(),
|
||||
'[translation_language]' => $this->translation->getLanguage(),
|
||||
'[translation_lcsh]' => $this->translation->getLcsh(),
|
||||
'[translation_abbreviation]' => $this->translation->getAbbreviation(),
|
||||
'[book_name]' => $this->chapter->getBookName(),
|
||||
'[chapter_number]' => $this->chapter->getChapterNumber(),
|
||||
'[chapter_name]' => $this->chapter->getChapterName(),
|
||||
'[chapter_text]' => $this->chapter->getChapterText(),
|
||||
'[verse_number]' => $this->chapter->getVerseNumber(),
|
||||
'[verse_name]' => $this->chapter->getVerseName(),
|
||||
'[verse_text]' => $this->chapter->getVerseText()
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Words Placeholders
|
||||
*
|
||||
* @return array Array of Placeholders
|
||||
* @since 2.0.1
|
||||
*/
|
||||
private function words(): array
|
||||
{
|
||||
return [
|
||||
'[translation_language]' => $this->translation->getLanguage(),
|
||||
'[translation_lcsh]' => $this->translation->getLcsh(),
|
||||
'[selected_word]' => $this->chapter->getWordText()
|
||||
];
|
||||
}
|
||||
}
|
||||
|
132
src/ba2151c0-8ffa-4a07-ba6e-93f135a3e9d5/code.power
Normal file
132
src/ba2151c0-8ffa-4a07-ba6e-93f135a3e9d5/code.power
Normal file
@ -0,0 +1,132 @@
|
||||
/**
|
||||
* The Translation class
|
||||
*
|
||||
* @var Translation
|
||||
* @since 2.0.1
|
||||
*/
|
||||
protected Translation $translation;
|
||||
|
||||
/**
|
||||
* The Chapter class
|
||||
*
|
||||
* @var Chapter
|
||||
* @since 2.0.1
|
||||
*/
|
||||
protected Chapter $chapter;
|
||||
|
||||
/**
|
||||
* The Prompt class
|
||||
*
|
||||
* @var Prompt
|
||||
* @since 2.0.1
|
||||
*/
|
||||
protected Prompt $prompt;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param Translation $translation The translation object.
|
||||
* @param Chapter $chapter The chapter object.
|
||||
* @param Prompt $prompt The prompt object.
|
||||
*
|
||||
* @since 2.0.1
|
||||
*/
|
||||
public function __construct(Translation $translation, Chapter $chapter, Prompt $prompt)
|
||||
{
|
||||
$this->translation = $translation;
|
||||
$this->chapter = $chapter;
|
||||
$this->prompt = $prompt;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Open AI response
|
||||
*
|
||||
* @param string $guid The prompt guid.
|
||||
*
|
||||
* @return array|null Array of response messages
|
||||
* @since 2.0.1
|
||||
*/
|
||||
public function get(): array
|
||||
{
|
||||
$integration = $this->prompt->getIntegration();
|
||||
$cache_behaviour = $this->prompt->getCacheBehaviour();
|
||||
|
||||
if ($integration === null || $cache_behaviour === null)
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
if (($integration == 1 || $integration == 3) && ($cache_behaviour == 0 || $cache_behaviour == 2))
|
||||
{
|
||||
return $this->all();
|
||||
}
|
||||
elseif ($integration == 2 && ($cache_behaviour == 0 || $cache_behaviour == 2))
|
||||
{
|
||||
return $this->without();
|
||||
}
|
||||
|
||||
return $this->words();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get All Placeholders
|
||||
*
|
||||
* @return array Array of Placeholders
|
||||
* @since 2.0.1
|
||||
*/
|
||||
private function all(): array
|
||||
{
|
||||
return [
|
||||
'[translation_name]' => $this->translation->getName(),
|
||||
'[translation_language]' => $this->translation->getLanguage(),
|
||||
'[translation_lcsh]' => $this->translation->getLcsh(),
|
||||
'[translation_abbreviation]' => $this->translation->getAbbreviation(),
|
||||
'[book_name]' => $this->chapter->getBookName(),
|
||||
'[chapter_number]' => $this->chapter->getChapterNumber(),
|
||||
'[chapter_name]' => $this->chapter->getChapterName(),
|
||||
'[chapter_text]' => $this->chapter->getChapterText(),
|
||||
'[verse_number]' => $this->chapter->getVerseNumber(),
|
||||
'[verse_name]' => $this->chapter->getVerseName(),
|
||||
'[verse_text]' => $this->chapter->getVerseText(),
|
||||
'[selected_words_number]' => $this->chapter->getWordNumber(),
|
||||
'[selected_word]' => $this->chapter->getWordText()
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get All Placeholders without words
|
||||
*
|
||||
* @return array Array of Placeholders
|
||||
* @since 2.0.1
|
||||
*/
|
||||
private function without(): array
|
||||
{
|
||||
return [
|
||||
'[translation_name]' => $this->translation->getName(),
|
||||
'[translation_language]' => $this->translation->getLanguage(),
|
||||
'[translation_lcsh]' => $this->translation->getLcsh(),
|
||||
'[translation_abbreviation]' => $this->translation->getAbbreviation(),
|
||||
'[book_name]' => $this->chapter->getBookName(),
|
||||
'[chapter_number]' => $this->chapter->getChapterNumber(),
|
||||
'[chapter_name]' => $this->chapter->getChapterName(),
|
||||
'[chapter_text]' => $this->chapter->getChapterText(),
|
||||
'[verse_number]' => $this->chapter->getVerseNumber(),
|
||||
'[verse_name]' => $this->chapter->getVerseName(),
|
||||
'[verse_text]' => $this->chapter->getVerseText()
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Words Placeholders
|
||||
*
|
||||
* @return array Array of Placeholders
|
||||
* @since 2.0.1
|
||||
*/
|
||||
private function words(): array
|
||||
{
|
||||
return [
|
||||
'[translation_language]' => $this->translation->getLanguage(),
|
||||
'[translation_lcsh]' => $this->translation->getLcsh(),
|
||||
'[selected_word]' => $this->chapter->getWordText()
|
||||
];
|
||||
}
|
31
src/ba2151c0-8ffa-4a07-ba6e-93f135a3e9d5/settings.json
Normal file
31
src/ba2151c0-8ffa-4a07-ba6e-93f135a3e9d5/settings.json
Normal file
@ -0,0 +1,31 @@
|
||||
{
|
||||
"add_head": "0",
|
||||
"add_licensing_template": "2",
|
||||
"extends": "0",
|
||||
"guid": "ba2151c0-8ffa-4a07-ba6e-93f135a3e9d5",
|
||||
"implements": null,
|
||||
"load_selection": null,
|
||||
"name": "Placeholders",
|
||||
"power_version": "1.0.0",
|
||||
"system_name": "Joomla.GetBible.Data.Placeholders",
|
||||
"type": "final class",
|
||||
"use_selection": {
|
||||
"use_selection0": {
|
||||
"use": "c4098e1a-46dd-4d60-9277-b3668a09edc8",
|
||||
"as": "default"
|
||||
},
|
||||
"use_selection1": {
|
||||
"use": "4a4c786d-51f4-421a-aa61-262dfd071880",
|
||||
"as": "default"
|
||||
},
|
||||
"use_selection2": {
|
||||
"use": "3f785d63-a592-463d-9f5f-b2b5a8edd561",
|
||||
"as": "default"
|
||||
}
|
||||
},
|
||||
"namespace": "VDM\\Joomla\\GetBible\\Data.Placeholders",
|
||||
"description": "The GetBible Prompt Placeholders\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": "",
|
||||
"composer": ""
|
||||
}
|
@ -12,9 +12,15 @@
|
||||
@startuml
|
||||
class Translation << (F,LightGreen) >> #Green {
|
||||
# Load $load
|
||||
# Config $config
|
||||
# array $translations
|
||||
+ __construct(Load $load)
|
||||
+ get(string $abbreviation) : ?object
|
||||
+ __construct(Load $load, Config $config)
|
||||
+ getName(?string $abbreviation = null) : string
|
||||
+ getLanguage(?string $abbreviation = null) : string
|
||||
+ getLcsh(?string $abbreviation = null) : string
|
||||
+ getAbbreviation(?string $abbreviation = null) : string
|
||||
+ get(?string $abbreviation = null) : ?object
|
||||
- active(?string $abbreviation = null) : bool
|
||||
}
|
||||
|
||||
note right of Translation::__construct
|
||||
@ -23,12 +29,47 @@ note right of Translation::__construct
|
||||
since: 2.0.1
|
||||
end note
|
||||
|
||||
note right of Translation::getName
|
||||
Get the translation name
|
||||
|
||||
since: 2.0.1
|
||||
return: string
|
||||
end note
|
||||
|
||||
note right of Translation::getLanguage
|
||||
Get the translation language
|
||||
|
||||
since: 2.0.1
|
||||
return: string
|
||||
end note
|
||||
|
||||
note right of Translation::getLcsh
|
||||
Get the translation distribution lcsh
|
||||
|
||||
since: 2.0.1
|
||||
return: string
|
||||
end note
|
||||
|
||||
note right of Translation::getAbbreviation
|
||||
Get the translation abbreviation
|
||||
|
||||
since: 2.0.1
|
||||
return: string
|
||||
end note
|
||||
|
||||
note right of Translation::get
|
||||
Get the translation
|
||||
|
||||
since: 2.0.1
|
||||
return: ?object
|
||||
end note
|
||||
|
||||
note right of Translation::active
|
||||
Check if the language is active
|
||||
|
||||
since: 2.0.1
|
||||
return: bool
|
||||
end note
|
||||
|
||||
@enduml
|
||||
```
|
||||
|
@ -13,6 +13,7 @@ namespace VDM\Joomla\GetBible\Data;
|
||||
|
||||
|
||||
use VDM\Joomla\GetBible\Database\Load;
|
||||
use VDM\Joomla\GetBible\Openai\Config;
|
||||
|
||||
|
||||
/**
|
||||
@ -31,7 +32,15 @@ final class Translation
|
||||
protected Load $load;
|
||||
|
||||
/**
|
||||
* The the translations
|
||||
* The Config class
|
||||
*
|
||||
* @var Config
|
||||
* @since 2.0.1
|
||||
*/
|
||||
protected Config $config;
|
||||
|
||||
/**
|
||||
* The translations
|
||||
*
|
||||
* @var array
|
||||
* @since 2.0.1
|
||||
@ -41,31 +50,141 @@ final class Translation
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param Load $load The load object.
|
||||
* @param Load $load The load object.
|
||||
* @param Config $config The config object.
|
||||
*
|
||||
* @since 2.0.1
|
||||
*/
|
||||
public function __construct(Load $load)
|
||||
public function __construct(Load $load, Config $config)
|
||||
{
|
||||
$this->load = $load;
|
||||
$this->config = $config;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the translation name
|
||||
*
|
||||
* @param string|null $abbreviation The translation abbreviation.
|
||||
*
|
||||
* @return string The translation name
|
||||
* @since 2.0.1
|
||||
*/
|
||||
public function getName(?string $abbreviation = null): string
|
||||
{
|
||||
if ($this->active($abbreviation))
|
||||
{
|
||||
return $this->get($abbreviation)->translation ?? '';
|
||||
}
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the translation language
|
||||
*
|
||||
* @param string|null $abbreviation The translation abbreviation.
|
||||
*
|
||||
* @return string The translation language
|
||||
* @since 2.0.1
|
||||
*/
|
||||
public function getLanguage(?string $abbreviation = null): string
|
||||
{
|
||||
if ($this->active($abbreviation))
|
||||
{
|
||||
$lang = trim(preg_replace('/Bible\.?/', '', $this->get($abbreviation)->distribution_lcsh));
|
||||
return $this->get($abbreviation)->language ?? $lang;
|
||||
}
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the translation distribution lcsh
|
||||
*
|
||||
* @param string|null $abbreviation The translation abbreviation.
|
||||
*
|
||||
* @return string The translation lcsh
|
||||
* @since 2.0.1
|
||||
*/
|
||||
public function getLcsh(?string $abbreviation = null): string
|
||||
{
|
||||
if ($this->active($abbreviation))
|
||||
{
|
||||
return $this->get($abbreviation)->distribution_lcsh ?? '';
|
||||
}
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the translation abbreviation
|
||||
*
|
||||
* @param string|null $abbreviation The translation abbreviation.
|
||||
*
|
||||
* @return string The translation abbreviation
|
||||
* @since 2.0.1
|
||||
*/
|
||||
public function getAbbreviation(?string $abbreviation = null): string
|
||||
{
|
||||
if ($this->active($abbreviation))
|
||||
{
|
||||
return $this->get($abbreviation)->abbreviation ?? '';
|
||||
}
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the translation
|
||||
*
|
||||
* @param string $abbreviation The translation abbreviation.
|
||||
* @param string|null $abbreviation The translation abbreviation.
|
||||
*
|
||||
* @return object|null True on success
|
||||
* @since 2.0.1
|
||||
*/
|
||||
public function get(string $abbreviation): ?object
|
||||
public function get(?string $abbreviation = null): ?object
|
||||
{
|
||||
// get from cache if not found
|
||||
$abbreviation = $abbreviation ?? $this->config->get('translation');
|
||||
|
||||
if ($abbreviation === null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
if (!isset($this->translations[$abbreviation]))
|
||||
{
|
||||
$this->translations[$abbreviation] = $this->load->item(['abbreviation' => $abbreviation], 'translation');
|
||||
$this->translations[$abbreviation] = $this->load->item(
|
||||
['abbreviation' => $abbreviation],
|
||||
'translation'
|
||||
);
|
||||
|
||||
// set to cache for later
|
||||
if ($this->translations[$abbreviation] !== null)
|
||||
{
|
||||
$this->config->set('translation', $abbreviation);
|
||||
}
|
||||
}
|
||||
|
||||
return $this->translations[$abbreviation];
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the language is active
|
||||
*
|
||||
* @param string|null $abbreviation The translation abbreviation.
|
||||
*
|
||||
* @return bool true if active
|
||||
* @since 2.0.1
|
||||
*/
|
||||
private function active(?string $abbreviation = null): bool
|
||||
{
|
||||
if ($this->get($abbreviation))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -7,7 +7,15 @@
|
||||
protected Load $load;
|
||||
|
||||
/**
|
||||
* The the translations
|
||||
* The Config class
|
||||
*
|
||||
* @var Config
|
||||
* @since 2.0.1
|
||||
*/
|
||||
protected Config $config;
|
||||
|
||||
/**
|
||||
* The translations
|
||||
*
|
||||
* @var array
|
||||
* @since 2.0.1
|
||||
@ -17,29 +25,139 @@
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param Load $load The load object.
|
||||
* @param Load $load The load object.
|
||||
* @param Config $config The config object.
|
||||
*
|
||||
* @since 2.0.1
|
||||
*/
|
||||
public function __construct(Load $load)
|
||||
public function __construct(Load $load, Config $config)
|
||||
{
|
||||
$this->load = $load;
|
||||
$this->config = $config;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the translation name
|
||||
*
|
||||
* @param string|null $abbreviation The translation abbreviation.
|
||||
*
|
||||
* @return string The translation name
|
||||
* @since 2.0.1
|
||||
*/
|
||||
public function getName(?string $abbreviation = null): string
|
||||
{
|
||||
if ($this->active($abbreviation))
|
||||
{
|
||||
return $this->get($abbreviation)->translation ?? '';
|
||||
}
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the translation language
|
||||
*
|
||||
* @param string|null $abbreviation The translation abbreviation.
|
||||
*
|
||||
* @return string The translation language
|
||||
* @since 2.0.1
|
||||
*/
|
||||
public function getLanguage(?string $abbreviation = null): string
|
||||
{
|
||||
if ($this->active($abbreviation))
|
||||
{
|
||||
$lang = trim(preg_replace('/Bible\.?/', '', $this->get($abbreviation)->distribution_lcsh));
|
||||
return $this->get($abbreviation)->language ?? $lang;
|
||||
}
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the translation distribution lcsh
|
||||
*
|
||||
* @param string|null $abbreviation The translation abbreviation.
|
||||
*
|
||||
* @return string The translation lcsh
|
||||
* @since 2.0.1
|
||||
*/
|
||||
public function getLcsh(?string $abbreviation = null): string
|
||||
{
|
||||
if ($this->active($abbreviation))
|
||||
{
|
||||
return $this->get($abbreviation)->distribution_lcsh ?? '';
|
||||
}
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the translation abbreviation
|
||||
*
|
||||
* @param string|null $abbreviation The translation abbreviation.
|
||||
*
|
||||
* @return string The translation abbreviation
|
||||
* @since 2.0.1
|
||||
*/
|
||||
public function getAbbreviation(?string $abbreviation = null): string
|
||||
{
|
||||
if ($this->active($abbreviation))
|
||||
{
|
||||
return $this->get($abbreviation)->abbreviation ?? '';
|
||||
}
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the translation
|
||||
*
|
||||
* @param string $abbreviation The translation abbreviation.
|
||||
* @param string|null $abbreviation The translation abbreviation.
|
||||
*
|
||||
* @return object|null True on success
|
||||
* @since 2.0.1
|
||||
*/
|
||||
public function get(string $abbreviation): ?object
|
||||
public function get(?string $abbreviation = null): ?object
|
||||
{
|
||||
// get from cache if not found
|
||||
$abbreviation = $abbreviation ?? $this->config->get('translation');
|
||||
|
||||
if ($abbreviation === null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
if (!isset($this->translations[$abbreviation]))
|
||||
{
|
||||
$this->translations[$abbreviation] = $this->load->item(['abbreviation' => $abbreviation], 'translation');
|
||||
$this->translations[$abbreviation] = $this->load->item(
|
||||
['abbreviation' => $abbreviation],
|
||||
'translation'
|
||||
);
|
||||
|
||||
// set to cache for later
|
||||
if ($this->translations[$abbreviation] !== null)
|
||||
{
|
||||
$this->config->set('translation', $abbreviation);
|
||||
}
|
||||
}
|
||||
|
||||
return $this->translations[$abbreviation];
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the language is active
|
||||
*
|
||||
* @param string|null $abbreviation The translation abbreviation.
|
||||
*
|
||||
* @return bool true if active
|
||||
* @since 2.0.1
|
||||
*/
|
||||
private function active(?string $abbreviation = null): bool
|
||||
{
|
||||
if ($this->get($abbreviation))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
@ -13,6 +13,10 @@
|
||||
"use_selection0": {
|
||||
"use": "c03b9c61-17d3-4774-a335-783903719f83",
|
||||
"as": "default"
|
||||
},
|
||||
"use_selection1": {
|
||||
"use": "3af7864b-f1f3-491e-b16f-0504f890086d",
|
||||
"as": "default"
|
||||
}
|
||||
},
|
||||
"namespace": "VDM\\Joomla\\GetBible\\Data.Translation",
|
||||
|
@ -11,22 +11,16 @@
|
||||
```uml
|
||||
@startuml
|
||||
class AI << (F,LightGreen) >> #Green {
|
||||
# Translation $translation
|
||||
# Chapter $chapter
|
||||
# Prompt $prompt
|
||||
+ __construct(Translation $translation, Chapter $chapter, ...)
|
||||
+ get(string $guid, string $translation, ...) : ?array
|
||||
# Placeholders $placeholders
|
||||
+ __construct(Prompt $prompt, Placeholders $placeholders)
|
||||
+ get() : ?array
|
||||
}
|
||||
|
||||
note right of AI::__construct
|
||||
Constructor
|
||||
|
||||
since: 2.0.1
|
||||
|
||||
arguments:
|
||||
Translation $translation
|
||||
Chapter $chapter
|
||||
Prompt $prompt
|
||||
end note
|
||||
|
||||
note right of AI::get
|
||||
@ -34,14 +28,6 @@ note right of AI::get
|
||||
|
||||
since: 2.0.1
|
||||
return: ?array
|
||||
|
||||
arguments:
|
||||
string $guid
|
||||
string $translation
|
||||
int $book
|
||||
int $chapter
|
||||
string $verse
|
||||
string $words
|
||||
end note
|
||||
|
||||
@enduml
|
||||
|
@ -12,9 +12,8 @@
|
||||
namespace VDM\Joomla\GetBible;
|
||||
|
||||
|
||||
use VDM\Joomla\GetBible\Data\Translation;
|
||||
use VDM\Joomla\GetBible\Data\Chapter;
|
||||
use VDM\Joomla\GetBible\Data\Prompt;
|
||||
use VDM\Joomla\GetBible\Data\Placeholders;
|
||||
|
||||
|
||||
/**
|
||||
@ -24,22 +23,6 @@ use VDM\Joomla\GetBible\Data\Prompt;
|
||||
*/
|
||||
final class AI
|
||||
{
|
||||
/**
|
||||
* The Translation class
|
||||
*
|
||||
* @var Translation
|
||||
* @since 2.0.1
|
||||
*/
|
||||
protected Translation $translation;
|
||||
|
||||
/**
|
||||
* The Chapter class
|
||||
*
|
||||
* @var Chapter
|
||||
* @since 2.0.1
|
||||
*/
|
||||
protected Chapter $chapter;
|
||||
|
||||
/**
|
||||
* The Prompt class
|
||||
*
|
||||
@ -48,20 +31,26 @@ final class AI
|
||||
*/
|
||||
protected Prompt $prompt;
|
||||
|
||||
/**
|
||||
* The Placeholders class
|
||||
*
|
||||
* @var Placeholders
|
||||
* @since 2.0.1
|
||||
*/
|
||||
protected Placeholders $placeholders;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param Translation $translation The translation object.
|
||||
* @param Chapter $chapter The chapter object.
|
||||
* @param Prompt $prompt The prompt object.
|
||||
* @param Placeholders $placeholders The chapter object.
|
||||
*
|
||||
* @since 2.0.1
|
||||
*/
|
||||
public function __construct(Translation $translation, Chapter $chapter, Prompt $prompt)
|
||||
public function __construct(Prompt $prompt, Placeholders $placeholders)
|
||||
{
|
||||
$this->translation = $translation;
|
||||
$this->chapter = $chapter;
|
||||
$this->prompt = $prompt;
|
||||
$this->placeholders = $placeholders;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -72,12 +61,11 @@ final class AI
|
||||
* @return array|null Array of response messages
|
||||
* @since 2.0.1
|
||||
*/
|
||||
public function get(string $guid, string $translation, int $book, int $chapter, string $verse, string $words): ?array
|
||||
public function get(): ?array
|
||||
{
|
||||
return [
|
||||
'translation' => $this->translation->get($translation),
|
||||
'chapter' => $this->chapter->get($translation, $book, $chapter),
|
||||
'prompt' => $this->prompt->get($guid)
|
||||
'placeholders' => $this->placeholders->get(),
|
||||
'prompt' => $this->prompt->get()
|
||||
];
|
||||
}
|
||||
}
|
||||
|
@ -1,19 +1,3 @@
|
||||
/**
|
||||
* The Translation class
|
||||
*
|
||||
* @var Translation
|
||||
* @since 2.0.1
|
||||
*/
|
||||
protected Translation $translation;
|
||||
|
||||
/**
|
||||
* The Chapter class
|
||||
*
|
||||
* @var Chapter
|
||||
* @since 2.0.1
|
||||
*/
|
||||
protected Chapter $chapter;
|
||||
|
||||
/**
|
||||
* The Prompt class
|
||||
*
|
||||
@ -22,20 +6,26 @@
|
||||
*/
|
||||
protected Prompt $prompt;
|
||||
|
||||
/**
|
||||
* The Placeholders class
|
||||
*
|
||||
* @var Placeholders
|
||||
* @since 2.0.1
|
||||
*/
|
||||
protected Placeholders $placeholders;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param Translation $translation The translation object.
|
||||
* @param Chapter $chapter The chapter object.
|
||||
* @param Prompt $prompt The prompt object.
|
||||
* @param Placeholders $placeholders The chapter object.
|
||||
*
|
||||
* @since 2.0.1
|
||||
*/
|
||||
public function __construct(Translation $translation, Chapter $chapter, Prompt $prompt)
|
||||
public function __construct(Prompt $prompt, Placeholders $placeholders)
|
||||
{
|
||||
$this->translation = $translation;
|
||||
$this->chapter = $chapter;
|
||||
$this->prompt = $prompt;
|
||||
$this->placeholders = $placeholders;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -46,11 +36,10 @@
|
||||
* @return array|null Array of response messages
|
||||
* @since 2.0.1
|
||||
*/
|
||||
public function get(string $guid, string $translation, int $book, int $chapter, string $verse, string $words): ?array
|
||||
public function get(): ?array
|
||||
{
|
||||
return [
|
||||
'translation' => $this->translation->get($translation),
|
||||
'chapter' => $this->chapter->get($translation, $book, $chapter),
|
||||
'prompt' => $this->prompt->get($guid)
|
||||
'placeholders' => $this->placeholders->get(),
|
||||
'prompt' => $this->prompt->get()
|
||||
];
|
||||
}
|
@ -10,16 +10,12 @@
|
||||
"system_name": "Joomla.GetBible.AI",
|
||||
"type": "final class",
|
||||
"use_selection": {
|
||||
"use_selection1": {
|
||||
"use": "c4098e1a-46dd-4d60-9277-b3668a09edc8",
|
||||
"as": "default"
|
||||
},
|
||||
"use_selection2": {
|
||||
"use": "4a4c786d-51f4-421a-aa61-262dfd071880",
|
||||
"use": "3f785d63-a592-463d-9f5f-b2b5a8edd561",
|
||||
"as": "default"
|
||||
},
|
||||
"use_selection0": {
|
||||
"use": "3f785d63-a592-463d-9f5f-b2b5a8edd561",
|
||||
"use_selection1": {
|
||||
"use": "ba2151c0-8ffa-4a07-ba6e-93f135a3e9d5",
|
||||
"as": "default"
|
||||
}
|
||||
},
|
||||
|
@ -462,6 +462,15 @@ class Table extends BaseTable implements Tableinterface
|
||||
'store' => NULL,
|
||||
'tab_name' => 'Details',
|
||||
],
|
||||
'abbreviation' => [
|
||||
'name' => 'abbreviation',
|
||||
'label' => 'COM_GETBIBLE_OPEN_AI_RESPONSE_ABBREVIATION_LABEL',
|
||||
'type' => 'targettranslations',
|
||||
'title' => false,
|
||||
'list' => 'open_ai_responses',
|
||||
'store' => NULL,
|
||||
'tab_name' => 'Bible',
|
||||
],
|
||||
'n' => [
|
||||
'name' => 'n',
|
||||
'label' => 'COM_GETBIBLE_OPEN_AI_RESPONSE_N_LABEL',
|
||||
@ -489,33 +498,33 @@ class Table extends BaseTable implements Tableinterface
|
||||
'store' => NULL,
|
||||
'tab_name' => 'Prompt',
|
||||
],
|
||||
'model' => [
|
||||
'name' => 'model',
|
||||
'label' => 'COM_GETBIBLE_OPEN_AI_RESPONSE_MODEL_LABEL',
|
||||
'type' => 'list',
|
||||
'words' => [
|
||||
'name' => 'words',
|
||||
'label' => 'COM_GETBIBLE_OPEN_AI_RESPONSE_WORDS_LABEL',
|
||||
'type' => 'text',
|
||||
'title' => false,
|
||||
'list' => 'open_ai_responses',
|
||||
'store' => NULL,
|
||||
'tab_name' => 'Bible',
|
||||
],
|
||||
'chapter' => [
|
||||
'name' => 'chapter',
|
||||
'label' => 'COM_GETBIBLE_OPEN_AI_RESPONSE_CHAPTER_LABEL',
|
||||
'type' => 'text',
|
||||
'title' => false,
|
||||
'list' => 'open_ai_responses',
|
||||
'store' => NULL,
|
||||
'tab_name' => 'Bible',
|
||||
],
|
||||
'max_tokens' => [
|
||||
'name' => 'max_tokens',
|
||||
'label' => 'COM_GETBIBLE_OPEN_AI_RESPONSE_MAX_TOKENS_LABEL',
|
||||
'type' => 'number',
|
||||
'title' => false,
|
||||
'list' => 'open_ai_responses',
|
||||
'store' => NULL,
|
||||
'tab_name' => 'Prompt',
|
||||
],
|
||||
'verse' => [
|
||||
'name' => 'verse',
|
||||
'label' => 'COM_GETBIBLE_OPEN_AI_RESPONSE_VERSE_LABEL',
|
||||
'type' => 'text',
|
||||
'title' => false,
|
||||
'list' => 'open_ai_responses',
|
||||
'store' => NULL,
|
||||
'tab_name' => 'Bible',
|
||||
],
|
||||
'book' => [
|
||||
'name' => 'book',
|
||||
'label' => 'COM_GETBIBLE_OPEN_AI_RESPONSE_BOOK_LABEL',
|
||||
'type' => 'text',
|
||||
'title' => false,
|
||||
'list' => 'open_ai_responses',
|
||||
'store' => NULL,
|
||||
'tab_name' => 'Bible',
|
||||
],
|
||||
'completion_tokens' => [
|
||||
'name' => 'completion_tokens',
|
||||
'label' => 'COM_GETBIBLE_OPEN_AI_RESPONSE_COMPLETION_TOKENS_LABEL',
|
||||
@ -543,15 +552,6 @@ class Table extends BaseTable implements Tableinterface
|
||||
'store' => NULL,
|
||||
'tab_name' => 'Details',
|
||||
],
|
||||
'abbreviation' => [
|
||||
'name' => 'abbreviation',
|
||||
'label' => 'COM_GETBIBLE_OPEN_AI_RESPONSE_ABBREVIATION_LABEL',
|
||||
'type' => 'targettranslations',
|
||||
'title' => false,
|
||||
'list' => 'open_ai_responses',
|
||||
'store' => NULL,
|
||||
'tab_name' => 'Bible',
|
||||
],
|
||||
'lcsh' => [
|
||||
'name' => 'lcsh',
|
||||
'label' => 'COM_GETBIBLE_OPEN_AI_RESPONSE_LCSH_LABEL',
|
||||
@ -561,18 +561,9 @@ class Table extends BaseTable implements Tableinterface
|
||||
'store' => NULL,
|
||||
'tab_name' => 'Bible',
|
||||
],
|
||||
'max_tokens' => [
|
||||
'name' => 'max_tokens',
|
||||
'label' => 'COM_GETBIBLE_OPEN_AI_RESPONSE_MAX_TOKENS_LABEL',
|
||||
'type' => 'number',
|
||||
'title' => false,
|
||||
'list' => 'open_ai_responses',
|
||||
'store' => NULL,
|
||||
'tab_name' => 'Prompt',
|
||||
],
|
||||
'chapter' => [
|
||||
'name' => 'chapter',
|
||||
'label' => 'COM_GETBIBLE_OPEN_AI_RESPONSE_CHAPTER_LABEL',
|
||||
'book' => [
|
||||
'name' => 'book',
|
||||
'label' => 'COM_GETBIBLE_OPEN_AI_RESPONSE_BOOK_LABEL',
|
||||
'type' => 'text',
|
||||
'title' => false,
|
||||
'list' => 'open_ai_responses',
|
||||
@ -588,9 +579,9 @@ class Table extends BaseTable implements Tableinterface
|
||||
'store' => NULL,
|
||||
'tab_name' => 'Prompt',
|
||||
],
|
||||
'words' => [
|
||||
'name' => 'words',
|
||||
'label' => 'COM_GETBIBLE_OPEN_AI_RESPONSE_WORDS_LABEL',
|
||||
'verse' => [
|
||||
'name' => 'verse',
|
||||
'label' => 'COM_GETBIBLE_OPEN_AI_RESPONSE_VERSE_LABEL',
|
||||
'type' => 'text',
|
||||
'title' => false,
|
||||
'list' => 'open_ai_responses',
|
||||
@ -606,6 +597,24 @@ class Table extends BaseTable implements Tableinterface
|
||||
'store' => NULL,
|
||||
'tab_name' => 'Prompt',
|
||||
],
|
||||
'selected_words' => [
|
||||
'name' => 'selected_words',
|
||||
'label' => 'COM_GETBIBLE_OPEN_AI_RESPONSE_SELECTED_WORDS_LABEL',
|
||||
'type' => 'text',
|
||||
'title' => false,
|
||||
'list' => 'open_ai_responses',
|
||||
'store' => NULL,
|
||||
'tab_name' => 'Bible',
|
||||
],
|
||||
'model' => [
|
||||
'name' => 'model',
|
||||
'label' => 'COM_GETBIBLE_OPEN_AI_RESPONSE_MODEL_LABEL',
|
||||
'type' => 'list',
|
||||
'title' => false,
|
||||
'list' => 'open_ai_responses',
|
||||
'store' => NULL,
|
||||
'tab_name' => 'Prompt',
|
||||
],
|
||||
],
|
||||
'open_ai_message' => [
|
||||
'role' => [
|
||||
|
@ -32,6 +32,17 @@
|
||||
"spk": "Super__3439e63b_d8f1_42ce_a765_60d56b1fbe21__Power",
|
||||
"guid": "3439e63b-d8f1-42ce-a765-60d56b1fbe21"
|
||||
},
|
||||
"3af7864b-f1f3-491e-b16f-0504f890086d": {
|
||||
"name": "Config",
|
||||
"type": "class",
|
||||
"namespace": "VDM\\Joomla\\GetBible\\Openai",
|
||||
"code": "src\/3af7864b-f1f3-491e-b16f-0504f890086d\/code.php",
|
||||
"power": "src\/3af7864b-f1f3-491e-b16f-0504f890086d\/code.power",
|
||||
"settings": "src\/3af7864b-f1f3-491e-b16f-0504f890086d\/settings.json",
|
||||
"path": "src\/3af7864b-f1f3-491e-b16f-0504f890086d",
|
||||
"spk": "Super__3af7864b_f1f3_491e_b16f_0504f890086d__Power",
|
||||
"guid": "3af7864b-f1f3-491e-b16f-0504f890086d"
|
||||
},
|
||||
"3f785d63-a592-463d-9f5f-b2b5a8edd561": {
|
||||
"name": "Prompt",
|
||||
"type": "final class",
|
||||
@ -43,6 +54,17 @@
|
||||
"spk": "Super__3f785d63_a592_463d_9f5f_b2b5a8edd561__Power",
|
||||
"guid": "3f785d63-a592-463d-9f5f-b2b5a8edd561"
|
||||
},
|
||||
"44c15b17-e096-47c0-8769-42ea9b692cb2": {
|
||||
"name": "Response",
|
||||
"type": "final class",
|
||||
"namespace": "VDM\\Joomla\\GetBible\\Data",
|
||||
"code": "src\/44c15b17-e096-47c0-8769-42ea9b692cb2\/code.php",
|
||||
"power": "src\/44c15b17-e096-47c0-8769-42ea9b692cb2\/code.power",
|
||||
"settings": "src\/44c15b17-e096-47c0-8769-42ea9b692cb2\/settings.json",
|
||||
"path": "src\/44c15b17-e096-47c0-8769-42ea9b692cb2",
|
||||
"spk": "Super__44c15b17_e096_47c0_8769_42ea9b692cb2__Power",
|
||||
"guid": "44c15b17-e096-47c0-8769-42ea9b692cb2"
|
||||
},
|
||||
"491c91ce-6355-40d3-bbbd-622473c6c026": {
|
||||
"name": "Books",
|
||||
"type": "final class",
|
||||
@ -252,6 +274,17 @@
|
||||
"spk": "Super__b8c66089_735e_4081_825c_8fe36b28e4a6__Power",
|
||||
"guid": "b8c66089-735e-4081-825c-8fe36b28e4a6"
|
||||
},
|
||||
"ba2151c0-8ffa-4a07-ba6e-93f135a3e9d5": {
|
||||
"name": "Placeholders",
|
||||
"type": "final class",
|
||||
"namespace": "VDM\\Joomla\\GetBible\\Data",
|
||||
"code": "src\/ba2151c0-8ffa-4a07-ba6e-93f135a3e9d5\/code.php",
|
||||
"power": "src\/ba2151c0-8ffa-4a07-ba6e-93f135a3e9d5\/code.power",
|
||||
"settings": "src\/ba2151c0-8ffa-4a07-ba6e-93f135a3e9d5\/settings.json",
|
||||
"path": "src\/ba2151c0-8ffa-4a07-ba6e-93f135a3e9d5",
|
||||
"spk": "Super__ba2151c0_8ffa_4a07_ba6e_93f135a3e9d5__Power",
|
||||
"guid": "ba2151c0-8ffa-4a07-ba6e-93f135a3e9d5"
|
||||
},
|
||||
"be0cae8b-4b78-4f59-b97b-9e31ee6f52e0": {
|
||||
"name": "Translations",
|
||||
"type": "final class",
|
||||
|
Loading…
Reference in New Issue
Block a user