4
0

update 2023-07-13 13:31:28

This commit is contained in:
Robot 2023-07-13 13:31:28 +02:00
parent 1f6cb785ee
commit 06bf530db8
Signed by: Robot
GPG Key ID: 14DECD44E7E1BB95
6 changed files with 230 additions and 18 deletions

View File

@ -134,6 +134,7 @@ class Data implements ServiceProviderInterface
return new Chapter(
$container->get('GetBible.Load'),
$container->get('GetBible.Config'),
$container->get('GetBible.Prompt'),
$container->get('GetBible.Utilities.String')
);
}

View File

@ -101,6 +101,7 @@
return new Chapter(
$container->get('GetBible.Load'),
$container->get('GetBible.Config'),
$container->get('GetBible.Prompt'),
$container->get('GetBible.Utilities.String')
);
}

View File

@ -13,8 +13,10 @@
class Chapter << (F,LightGreen) >> #Green {
# Load $load
# Config $config
# Prompt $prompt
# StringHelper $stringHelper
# array $chapters
# array $validVerses
+ __construct(Load $load, Config $config, ...)
+ getBookName(?string $abbreviation = null, ?int $book = null, ...) : string
+ getChapterNumber(?string $abbreviation = null, ?int $book = null, ...) : string
@ -30,9 +32,11 @@ class Chapter << (F,LightGreen) >> #Green {
- 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
- processVersesArray(?string $abbreviation = null, ?int $book = null, ...) : ?array
- extractVerseNumbers(string $verseNumber) : array
- validateSelectedVerses(array $verseNumbers) : string
- getValidVerseRange() : ?array
- isValidWordNumber(int $verseNumber, int $wordNumber) : bool
- getTextFromVerses(array $verses, array $verseNumber) : array
- getArrayFromVerses(array $verses, array $verseNumber) : array
- getWordNumberArray(?string $abbreviation = null, ?int $book = null, ...) : ?array
@ -51,6 +55,7 @@ note right of Chapter::__construct
arguments:
Load $load
Config $config
Prompt $prompt
StringHelper $stringHelper
end note
@ -229,9 +234,9 @@ note left of Chapter::processVersesArray
return: ?array
arguments:
?string $abbreviation
?int $book
?int $chapter
?string $abbreviation = null
?int $book = null
?int $chapter = null
end note
note right of Chapter::extractVerseNumbers
@ -248,6 +253,20 @@ note left of Chapter::validateSelectedVerses
return: string
end note
note right of Chapter::getValidVerseRange
Get the valid verse range
since: 2.0.1
return: ?array
end note
note left of Chapter::isValidWordNumber
Check if a word exist in a verse
since: 2.0.1
return: bool
end note
note right of Chapter::getTextFromVerses
Get the verse text from the verses array based on the verse numbers

View File

@ -14,6 +14,7 @@ namespace VDM\Joomla\GetBible\Data;
use VDM\Joomla\GetBible\Database\Load;
use VDM\Joomla\GetBible\Openai\Config;
use VDM\Joomla\GetBible\Data\Prompt;
use VDM\Joomla\GetBible\Utilities\StringHelper;
@ -40,6 +41,14 @@ final class Chapter
*/
protected Config $config;
/**
* The Prompt class
*
* @var Prompt
* @since 2.0.1
*/
protected Prompt $prompt;
/**
* The StringHelper class
*
@ -56,19 +65,29 @@ final class Chapter
*/
protected array $chapters = [];
/**
* The valid verse range
*
* @var array
* @since 2.0.1
*/
protected array $validVerses = [];
/**
* Constructor
*
* @param Load $load The load object.
* @param Config $config The config object.
* @param Prompt $prompt The prompt object.
* @param StringHelper $stringHelper The string helper object.
*
* @since 2.0.1
*/
public function __construct(Load $load, Config $config, StringHelper $stringHelper)
public function __construct(Load $load, Config $config, Prompt $prompt, StringHelper $stringHelper)
{
$this->load = $load;
$this->config = $config;
$this->prompt = $prompt;
$this->stringHelper = $stringHelper;
}
@ -204,7 +223,7 @@ final class Chapter
$max_verse = max($verses);
$verse_bucket[] = $min_verse;
if ($min_verse != $max_verse)
if ($min_verse != $max_verse && $this->prompt->getIntegration() == 2)
{
$verse_bucket[] = $max_verse;
}
@ -300,7 +319,7 @@ final class Chapter
*/
public function getWordNumber(?string $abbreviation = null,?int $book = null, ?int $chapter = null): string
{
if (!$this->active($abbreviation, $book, $chapter))
if (($this->prompt->getIntegration() != 1 && $this->prompt->getIntegration() != 3) || !$this->active($abbreviation, $book, $chapter))
{
return '';
}
@ -350,7 +369,7 @@ final class Chapter
*/
public function getWordText(?string $abbreviation = null,?int $book = null, ?int $chapter = null): string
{
if (!$this->active($abbreviation, $book, $chapter))
if (($this->prompt->getIntegration() != 1 && $this->prompt->getIntegration() != 3) || !$this->active($abbreviation, $book, $chapter))
{
return '';
}
@ -555,7 +574,7 @@ final class Chapter
* @return array|null The processed verse text
* @since 2.0.1
*/
private function processVersesArray(?string $abbreviation, ?int $book, ?int $chapter): ?array
private function processVersesArray(?string $abbreviation = null, ?int $book = null, ?int $chapter = null): ?array
{
$verse_numbers = $this->getVerseNumber($abbreviation, $book, $chapter);
$verses = $this->get($abbreviation, $book, $chapter)->verses ?? null;
@ -635,6 +654,68 @@ final class Chapter
return '';
}
/**
* Get the valid verse range
*
* @return array|null The valid verse range.
* @since 2.0.1
*/
private function getValidVerseRange(): ?array
{
if ($this->validVerses !== [])
{
return $this->validVerses;
}
$verse_numbers = $this->getVerseNumber();
if (empty($verse_numbers))
{
return null;
}
$verse_numbers = $this->extractVerseNumbers($verse_numbers);
if(count($verse_numbers) == 1)
{
// if there's only one number in the array, return it as is
$this->validVerses = $verse_numbers;
}
elseif(count($verse_numbers) == 2)
{
// if there are two numbers, generate a range
sort($verse_numbers); // sort the array in ascending order to make sure the range goes from lower to higher
$this->validVerses = range($verse_numbers[0], $verse_numbers[1]);
}
if ($this->validVerses !== [])
{
return $this->validVerses;
}
return null;
}
/**
* Check if a word exist in a verse
*
* @param int $verseNumber The verse number.
* @param int $wordNumber The word number.
*
* @return bool True on success
* @since 2.0.1
*/
private function isValidWordNumber($verseNumber, $wordNumber): bool
{
$verse_text = $this->get()->verse_text_array ?? null;
if (($verse_text = $this->processVersesArray()) === null)
{
return false;
}
return isset($verse_text[$verseNumber][$wordNumber]);
}
/**
* Get the verse text from the verses array based on the verse numbers
*
@ -773,7 +854,9 @@ final class Chapter
{
if (strpos($str, '-') !== false)
{
return array_map('trim', explode('-', $str));
$array = array_map('trim', explode('-', $str));
sort($array);
return $array;
}
else
{
@ -792,12 +875,23 @@ final class Chapter
*/
private function buildWordNumberArray(array $verse, array $words): array
{
if (($valid = $this->getValidVerseRange()) == null)
{
return [];
}
$word_number_array = [];
$integration = $this->prompt->getIntegration();
foreach ($verse as $key => $verse)
{
if (isset($words[$key]))
if (isset($words[$key]) && in_array($verse, $valid) &&
$this->isValidWordNumber($verse, $words[$key]))
{
$word_number_array[$verse][] = $words[$key];
if ($integration == 1)
{
break;
}
}
}

View File

@ -14,6 +14,14 @@
*/
protected Config $config;
/**
* The Prompt class
*
* @var Prompt
* @since 2.0.1
*/
protected Prompt $prompt;
/**
* The StringHelper class
*
@ -30,19 +38,29 @@
*/
protected array $chapters = [];
/**
* The valid verse range
*
* @var array
* @since 2.0.1
*/
protected array $validVerses = [];
/**
* Constructor
*
* @param Load $load The load object.
* @param Config $config The config object.
* @param Prompt $prompt The prompt object.
* @param StringHelper $stringHelper The string helper object.
*
* @since 2.0.1
*/
public function __construct(Load $load, Config $config, StringHelper $stringHelper)
public function __construct(Load $load, Config $config, Prompt $prompt, StringHelper $stringHelper)
{
$this->load = $load;
$this->config = $config;
$this->prompt = $prompt;
$this->stringHelper = $stringHelper;
}
@ -178,7 +196,7 @@
$max_verse = max($verses);
$verse_bucket[] = $min_verse;
if ($min_verse != $max_verse)
if ($min_verse != $max_verse && $this->prompt->getIntegration() == 2)
{
$verse_bucket[] = $max_verse;
}
@ -274,7 +292,7 @@
*/
public function getWordNumber(?string $abbreviation = null,?int $book = null, ?int $chapter = null): string
{
if (!$this->active($abbreviation, $book, $chapter))
if (($this->prompt->getIntegration() != 1 && $this->prompt->getIntegration() != 3) || !$this->active($abbreviation, $book, $chapter))
{
return '';
}
@ -324,7 +342,7 @@
*/
public function getWordText(?string $abbreviation = null,?int $book = null, ?int $chapter = null): string
{
if (!$this->active($abbreviation, $book, $chapter))
if (($this->prompt->getIntegration() != 1 && $this->prompt->getIntegration() != 3) || !$this->active($abbreviation, $book, $chapter))
{
return '';
}
@ -529,7 +547,7 @@
* @return array|null The processed verse text
* @since 2.0.1
*/
private function processVersesArray(?string $abbreviation, ?int $book, ?int $chapter): ?array
private function processVersesArray(?string $abbreviation = null, ?int $book = null, ?int $chapter = null): ?array
{
$verse_numbers = $this->getVerseNumber($abbreviation, $book, $chapter);
$verses = $this->get($abbreviation, $book, $chapter)->verses ?? null;
@ -609,6 +627,68 @@
return '';
}
/**
* Get the valid verse range
*
* @return array|null The valid verse range.
* @since 2.0.1
*/
private function getValidVerseRange(): ?array
{
if ($this->validVerses !== [])
{
return $this->validVerses;
}
$verse_numbers = $this->getVerseNumber();
if (empty($verse_numbers))
{
return null;
}
$verse_numbers = $this->extractVerseNumbers($verse_numbers);
if(count($verse_numbers) == 1)
{
// if there's only one number in the array, return it as is
$this->validVerses = $verse_numbers;
}
elseif(count($verse_numbers) == 2)
{
// if there are two numbers, generate a range
sort($verse_numbers); // sort the array in ascending order to make sure the range goes from lower to higher
$this->validVerses = range($verse_numbers[0], $verse_numbers[1]);
}
if ($this->validVerses !== [])
{
return $this->validVerses;
}
return null;
}
/**
* Check if a word exist in a verse
*
* @param int $verseNumber The verse number.
* @param int $wordNumber The word number.
*
* @return bool True on success
* @since 2.0.1
*/
private function isValidWordNumber($verseNumber, $wordNumber): bool
{
$verse_text = $this->get()->verse_text_array ?? null;
if (($verse_text = $this->processVersesArray()) === null)
{
return false;
}
return isset($verse_text[$verseNumber][$wordNumber]);
}
/**
* Get the verse text from the verses array based on the verse numbers
*
@ -747,7 +827,9 @@
{
if (strpos($str, '-') !== false)
{
return array_map('trim', explode('-', $str));
$array = array_map('trim', explode('-', $str));
sort($array);
return $array;
}
else
{
@ -766,12 +848,23 @@
*/
private function buildWordNumberArray(array $verse, array $words): array
{
if (($valid = $this->getValidVerseRange()) == null)
{
return [];
}
$word_number_array = [];
$integration = $this->prompt->getIntegration();
foreach ($verse as $key => $verse)
{
if (isset($words[$key]))
if (isset($words[$key]) && in_array($verse, $valid) &&
$this->isValidWordNumber($verse, $words[$key]))
{
$word_number_array[$verse][] = $words[$key];
if ($integration == 1)
{
break;
}
}
}

View File

@ -19,6 +19,10 @@
"as": "default"
},
"use_selection2": {
"use": "3f785d63-a592-463d-9f5f-b2b5a8edd561",
"as": "default"
},
"use_selection3": {
"use": "a5b32737-207d-4cf6-b8ae-ee815612c3a0",
"as": "default"
}