2023-07-26 09:09:42 +00:00
< ? php
/*----------------------------------------------------------------------------------| io . vdm . dev |----/
Vast Development Method
/-------------------------------------------------------------------------------------------------------/
@ package getBible . net
@ created 3 rd December , 2015
@ author Llewellyn van der Merwe < https :// getbible . net >
@ git Get Bible < https :// git . vdm . dev / getBible >
@ github Get Bible < https :// github . com / getBible >
@ support Get Bible < https :// git . vdm . dev / getBible / support >
@ copyright Copyright ( C ) 2015. All Rights Reserved
@ license GNU / GPL Version 2 or later - http :// www . gnu . org / licenses / gpl - 2.0 . html
/------------------------------------------------------------------------------------------------------*/
// No direct access to this file
defined ( '_JEXEC' ) or die ( 'Restricted access' );
2024-01-22 08:48:28 +00:00
use Joomla\CMS\Factory ;
use Joomla\CMS\Language\Text ;
2024-01-22 09:15:49 +00:00
use Joomla\CMS\Component\ComponentHelper ;
2023-07-26 09:09:42 +00:00
use Joomla\CMS\MVC\Model\ItemModel ;
2024-01-22 08:48:28 +00:00
use Joomla\CMS\Plugin\PluginHelper ;
use Joomla\CMS\Router\Route ;
use Joomla\CMS\Uri\Uri ;
2023-07-26 09:09:42 +00:00
use Joomla\Utilities\ArrayHelper ;
2024-01-22 08:48:28 +00:00
use Joomla\CMS\Helper\TagsHelper ;
use VDM\Joomla\GetBible\Factory as GetBibleFactory ;
2023-07-26 09:09:42 +00:00
use VDM\Joomla\Utilities\Component\Helper ;
2024-01-22 08:48:28 +00:00
use VDM\Joomla\Utilities\StringHelper ;
use VDM\Joomla\Utilities\JsonHelper ;
use VDM\Joomla\Utilities\ArrayHelper as UtilitiesArrayHelper ;
2023-07-26 09:09:42 +00:00
/**
* Getbible App Item Model
*/
class GetbibleModelApp extends ItemModel
{
/**
* Model context string .
*
* @ var string
*/
protected $_context = 'com_getbible.app' ;
/**
* Model user data .
*
* @ var strings
*/
protected $user ;
protected $userId ;
protected $guest ;
protected $groups ;
protected $levels ;
protected $app ;
protected $input ;
protected $uikitComp ;
/**
* @ var object item
*/
protected $item ;
/**
* Method to auto - populate the model state .
*
* Note . Calling getState in this method will result in recursion .
*
* @ since 1.6
*
* @ return void
*/
protected function populateState ()
{
2024-01-22 08:48:28 +00:00
$this -> app = Factory :: getApplication ();
2023-07-26 09:09:42 +00:00
$this -> input = $this -> app -> input ;
// Get the itme main id
$id = $this -> input -> getInt ( 'id' , null );
$this -> setState ( 'app.id' , $id );
// Load the parameters.
$params = $this -> app -> getParams ();
$this -> setState ( 'params' , $params );
parent :: populateState ();
}
/**
* Method to get article data .
*
* @ param integer $pk The id of the article .
*
* @ return mixed Menu item data object on success , false on failure .
*/
public function getItem ( $pk = null )
{
2024-01-22 08:48:28 +00:00
$this -> user = Factory :: getUser ();
2023-07-26 09:09:42 +00:00
$this -> userId = $this -> user -> get ( 'id' );
$this -> guest = $this -> user -> get ( 'guest' );
$this -> groups = $this -> user -> get ( 'groups' );
$this -> authorisedGroups = $this -> user -> getAuthorisedGroups ();
$this -> levels = $this -> user -> getAuthorisedViewLevels ();
$this -> initSet = true ;
$pk = ( ! empty ( $pk )) ? $pk : ( int ) $this -> getState ( 'app.id' );
// we add a Share_His_Word option to set the session key
if (( $linker = $this -> input -> getString ( 'Share_His_Word' , null )) !== null
2024-01-22 08:48:28 +00:00
&& GetBibleFactory :: _ ( 'GetBible.Linker' ) -> valid ( $linker ))
2023-07-26 09:09:42 +00:00
{
2024-01-22 08:48:28 +00:00
GetBibleFactory :: _ ( 'GetBible.Linker' ) -> trigger ( $linker );
2023-07-26 09:09:42 +00:00
}
// we get all the Scripture Details
2023-07-26 20:29:41 +00:00
$this -> translation = $this -> input -> getString ( 'translation' ) ? ? $this -> input -> getString ( 't' , Helper :: getParams ( 'com_getbible' ) -> get ( 'default_translation' , 'kjv' ));
2023-07-26 17:53:35 +00:00
$this -> book = $this -> input -> getInt ( 'book' ) ? ? $this -> input -> getInt ( 'b' );
2023-08-04 15:13:55 +00:00
$this -> chapter = $this -> input -> getInt ( 'chapter' ) ? ? $this -> input -> getInt ( 'c' );
2023-07-26 17:53:35 +00:00
$this -> verses = $this -> input -> getString ( 'verses' ) ? ? $this -> input -> getString ( 'verse' ) ? ? $this -> input -> getString ( 'v' );
2023-07-26 09:09:42 +00:00
$pk = 0 ;
2023-07-26 20:29:41 +00:00
// set daily verse (STUFF)
2023-07-26 09:09:42 +00:00
if ( empty ( $this -> book ) && ( $ref = $this -> input -> getString ( 'ref' )) !== null )
{
2024-01-22 08:48:28 +00:00
GetBibleFactory :: _ ( 'DailyScripture' ) -> load ( $ref );
2023-07-26 09:09:42 +00:00
}
2023-07-26 20:29:41 +00:00
else
{
2024-01-22 08:48:28 +00:00
GetBibleFactory :: _ ( 'DailyScripture' ) -> setActive ( $this -> book , $this -> chapter , $this -> verses );
2023-07-26 20:29:41 +00:00
}
2023-07-26 09:09:42 +00:00
// load Daily Scripture if no book value was found
if ( empty ( $this -> book ))
{
2024-01-22 08:48:28 +00:00
$this -> book = GetBibleFactory :: _ ( 'DailyScripture' ) -> book ();
$this -> chapter = $this -> chapter ? ? GetBibleFactory :: _ ( 'DailyScripture' ) -> chapter ();
$this -> verses = $this -> verses ? ? GetBibleFactory :: _ ( 'DailyScripture' ) -> verses ();
2023-07-26 09:09:42 +00:00
}
// if we still have nothing... were done here!
if ( $this -> book === null )
{
return false ;
}
// if chapter is null change it to one
if ( $this -> chapter === null )
{
$this -> chapter = 1 ;
}
2024-01-22 08:48:28 +00:00
2023-07-26 09:09:42 +00:00
if ( $this -> _item === null )
{
2024-01-22 08:48:28 +00:00
$this -> _item = [];
2023-07-26 09:09:42 +00:00
}
if ( ! isset ( $this -> _item [ $pk ]))
{
try
{
// Get a db connection.
2024-01-22 08:48:28 +00:00
$db = Factory :: getDbo ();
2023-07-26 09:09:42 +00:00
// Create a new query object.
$query = $db -> getQuery ( true );
// Get data
// we load the queried chapter
2024-01-22 08:48:28 +00:00
if ( ! GetBibleFactory :: _ ( 'GetBible.Watcher' ) -> sync ( $this -> translation , $this -> book , $this -> chapter ))
2023-07-26 09:09:42 +00:00
{
2024-01-22 08:48:28 +00:00
$book = GetBibleFactory :: _ ( 'GetBible.Watcher' ) -> getNextBook ( $this -> translation , $this -> book );
2023-07-26 09:09:42 +00:00
$this -> chapter = 1 ;
$this -> verses = null ;
// so we try to load this one last time
2024-01-22 08:48:28 +00:00
if ( empty ( $book ) || ! GetBibleFactory :: _ ( 'GetBible.Watcher' ) -> sync ( $this -> translation , $book , $this -> chapter ))
2023-07-26 09:09:42 +00:00
{
return false ;
}
2023-07-26 17:53:35 +00:00
// we found another book
$this -> book = $book ;
// get the book name
$name = $this -> getBookName ( $this -> book , $this -> translation ) ? ? $book ;
// we state this obvious result to the user
2024-01-26 15:18:26 +00:00
$this -> app -> enqueueMessage ( Text :: sprintf ( " COM_GETBIBLE_WERE_SORRY_THE_TRANSLATION_YOU_SELECTED_DOES_NOT_INCLUDE_THE_BOOK_YOU_WERE_IN_PREVIOUSLY_HOWEVER_WE_HAVE_LOCATED_BSB_WHICH_MIGHT_BE_OF_INTEREST_TO_YOU " , $name ), 'warning' );
2023-07-26 17:53:35 +00:00
2024-01-26 15:18:26 +00:00
$this -> app -> redirect ( Route :: _ ( 'index.php?option=com_getbible&view=app&t=' . $this -> translation . '&ref=' . $name ));
2023-07-26 17:53:35 +00:00
return false ;
2023-07-26 09:09:42 +00:00
}
// [or] we load the next chapter
2024-01-22 08:48:28 +00:00
if (( $chapter_next = GetBibleFactory :: _ ( 'GetBible.Watcher' ) -> getNextChapter ( $this -> translation , $this -> book , $this -> chapter )) !== null )
2023-07-26 09:09:42 +00:00
{
2024-01-22 08:48:28 +00:00
GetBibleFactory :: _ ( 'GetBible.Watcher' ) -> sync ( $this -> translation , $this -> book , $chapter_next );
2023-07-26 09:09:42 +00:00
}
// [or] we load the previous chapter
2024-01-22 08:48:28 +00:00
if (( $chapter_previous = GetBibleFactory :: _ ( 'GetBible.Watcher' ) -> getPreviousChapter ( $this -> chapter )) !== null )
2023-07-26 09:09:42 +00:00
{
2024-01-22 08:48:28 +00:00
GetBibleFactory :: _ ( 'GetBible.Watcher' ) -> sync ( $this -> translation , $this -> book , $chapter_previous );
2023-07-26 09:09:42 +00:00
}
2023-08-13 09:50:18 +00:00
$data = ( object ) [
2023-07-26 09:09:42 +00:00
'translation' => $this -> translation ,
'book' => $this -> book ,
'chapter' => $this -> chapter ,
'verses' => $this -> verses ,
2024-01-22 08:48:28 +00:00
'daily' => GetBibleFactory :: _ ( 'DailyScripture' ) -> isDaily ()
2023-07-26 09:09:42 +00:00
];
if ( empty ( $data ))
{
2024-01-22 08:48:28 +00:00
$app = Factory :: getApplication ();
2023-07-26 09:09:42 +00:00
// If no data is found redirect to default page and show warning.
2024-01-22 08:48:28 +00:00
$app -> enqueueMessage ( Text :: _ ( 'COM_GETBIBLE_NOT_FOUND_OR_ACCESS_DENIED' ), 'warning' );
$app -> redirect ( Uri :: root ());
2023-07-26 09:09:42 +00:00
return false ;
}
// set data object to item.
$this -> _item [ $pk ] = $data ;
}
catch ( Exception $e )
{
if ( $e -> getCode () == 404 )
{
// Need to go thru the error handler to allow Redirect to work.
2024-01-22 08:48:28 +00:00
JError :: raiseError ( 404 , $e -> getMessage ());
2023-07-26 09:09:42 +00:00
}
else
{
$this -> setError ( $e );
$this -> _item [ $pk ] = false ;
}
}
}
return $this -> _item [ $pk ];
}
/**
* Custom Method
*
* @ return mixed item data object on success , false on failure .
*
*/
public function getChapter ()
{
if ( ! isset ( $this -> initSet ) || ! $this -> initSet )
{
2024-01-22 08:48:28 +00:00
$this -> user = Factory :: getUser ();
2023-07-26 09:09:42 +00:00
$this -> userId = $this -> user -> get ( 'id' );
$this -> guest = $this -> user -> get ( 'guest' );
$this -> groups = $this -> user -> get ( 'groups' );
$this -> authorisedGroups = $this -> user -> getAuthorisedGroups ();
$this -> levels = $this -> user -> getAuthorisedViewLevels ();
$this -> initSet = true ;
}
// Get a db connection.
2024-01-22 08:48:28 +00:00
$db = Factory :: getDbo ();
2023-07-26 09:09:42 +00:00
// Create a new query object.
$query = $db -> getQuery ( true );
// Get from #__getbible_chapter as a
$query -> select ( $db -> quoteName (
array ( 'a.abbreviation' , 'a.name' , 'a.chapter' , 'a.book_nr' , 'a.sha' ),
array ( 'abbreviation' , 'name' , 'chapter' , 'book_nr' , 'sha' )));
$query -> from ( $db -> quoteName ( '#__getbible_chapter' , 'a' ));
// Get from #__getbible_translation as b
$query -> select ( $db -> quoteName (
array ( 'b.translation' , 'b.lang' , 'b.language' , 'b.direction' , 'b.encoding' ),
array ( 'translation' , 'lang' , 'language' , 'direction' , 'encoding' )));
$query -> join ( 'LEFT' , ( $db -> quoteName ( '#__getbible_translation' , 'b' )) . ' ON (' . $db -> quoteName ( 'a.abbreviation' ) . ' = ' . $db -> quoteName ( 'b.abbreviation' ) . ')' );
// Get from #__getbible_book as c
$query -> select ( $db -> quoteName (
array ( 'c.name' ),
array ( 'book_name' )));
$query -> join ( 'LEFT' , ( $db -> quoteName ( '#__getbible_book' , 'c' )) . ' ON (' . $db -> quoteName ( 'a.book_nr' ) . ' = ' . $db -> quoteName ( 'c.nr' ) . ')' );
2023-08-01 05:29:00 +00:00
// Check if $this->book is a string or numeric value.
$checkValue = $this -> book ;
2024-01-22 08:48:28 +00:00
if ( isset ( $checkValue ) && StringHelper :: check ( $checkValue ))
2023-08-01 05:29:00 +00:00
{
$query -> where ( 'a.book_nr = ' . $db -> quote ( $checkValue ));
}
elseif ( is_numeric ( $checkValue ))
{
$query -> where ( 'a.book_nr = ' . $checkValue );
}
else
{
return false ;
}
// Check if $this->chapter is a string or numeric value.
$checkValue = $this -> chapter ;
2024-01-22 08:48:28 +00:00
if ( isset ( $checkValue ) && StringHelper :: check ( $checkValue ))
2023-08-01 05:29:00 +00:00
{
$query -> where ( 'a.chapter = ' . $db -> quote ( $checkValue ));
}
elseif ( is_numeric ( $checkValue ))
{
$query -> where ( 'a.chapter = ' . $checkValue );
}
else
{
return false ;
}
2023-07-26 09:09:42 +00:00
// Check if $this->translation is a string or numeric value.
$checkValue = $this -> translation ;
2024-01-22 08:48:28 +00:00
if ( isset ( $checkValue ) && StringHelper :: check ( $checkValue ))
2023-07-26 09:09:42 +00:00
{
$query -> where ( 'a.abbreviation = ' . $db -> quote ( $checkValue ));
}
elseif ( is_numeric ( $checkValue ))
{
$query -> where ( 'a.abbreviation = ' . $checkValue );
}
else
{
return false ;
}
2023-08-01 05:29:00 +00:00
// Check if $this->translation is a string or numeric value.
$checkValue = $this -> translation ;
2024-01-22 08:48:28 +00:00
if ( isset ( $checkValue ) && StringHelper :: check ( $checkValue ))
2023-07-26 09:09:42 +00:00
{
2023-08-01 05:29:00 +00:00
$query -> where ( 'c.abbreviation = ' . $db -> quote ( $checkValue ));
2023-07-26 09:09:42 +00:00
}
elseif ( is_numeric ( $checkValue ))
{
2023-08-01 05:29:00 +00:00
$query -> where ( 'c.abbreviation = ' . $checkValue );
2023-07-26 09:09:42 +00:00
}
else
{
return false ;
}
// Reset the query using our newly populated query object.
$db -> setQuery ( $query );
// Load the results as a stdClass object.
$data = $db -> loadObject ();
if ( empty ( $data ))
{
return false ;
}
// set chapterChapterVerseV to the $data object.
$data -> chapterChapterVerseV = $this -> getChapterChapterVerseAadf_V ( $data -> chapter );
$data -> verses = $data -> chapterChapterVerseV ;
// only trigger this if either search or openai is activated
if ( Helper :: getParams ( 'com_getbible' ) -> get ( 'activate_search' ) == 1 || Helper :: getParams ( 'com_getbible' ) -> get ( 'enable_open_ai' ) == 1 )
{
$data -> html_verses = $this -> modelVerses ( $data -> chapterChapterVerseV );
}
else
{
$data -> html_verses = $data -> chapterChapterVerseV ;
}
unset ( $data -> chapterChapterVerseV );
// return data object.
return $data ;
}
/**
* Method to get an array of Verse Objects .
*
* @ return mixed An array of Verse Objects on success , false on failure .
*
*/
public function getChapterChapterVerseAadf_V ( $chapter )
{
// Get a db connection.
2024-01-22 08:48:28 +00:00
$db = Factory :: getDbo ();
2023-07-26 09:09:42 +00:00
// Create a new query object.
$query = $db -> getQuery ( true );
// Get from #__getbible_verse as v
$query -> select ( $db -> quoteName (
array ( 'v.name' , 'v.book_nr' , 'v.chapter' , 'v.verse' , 'v.text' ),
array ( 'name' , 'book_nr' , 'chapter' , 'verse' , 'text' )));
$query -> from ( $db -> quoteName ( '#__getbible_verse' , 'v' ));
$query -> where ( 'v.chapter = ' . $db -> quote ( $chapter ));
2023-08-01 05:29:00 +00:00
// Check if $this->book is a string or numeric value.
$checkValue = $this -> book ;
2024-01-22 08:48:28 +00:00
if ( isset ( $checkValue ) && StringHelper :: check ( $checkValue ))
2023-07-26 09:09:42 +00:00
{
2023-08-01 05:29:00 +00:00
$query -> where ( 'v.book_nr = ' . $db -> quote ( $checkValue ));
2023-07-26 09:09:42 +00:00
}
elseif ( is_numeric ( $checkValue ))
{
2023-08-01 05:29:00 +00:00
$query -> where ( 'v.book_nr = ' . $checkValue );
2023-07-26 09:09:42 +00:00
}
else
{
return false ;
}
2023-08-01 05:29:00 +00:00
// Check if $this->translation is a string or numeric value.
$checkValue = $this -> translation ;
2024-01-22 08:48:28 +00:00
if ( isset ( $checkValue ) && StringHelper :: check ( $checkValue ))
2023-07-26 09:09:42 +00:00
{
2023-08-01 05:29:00 +00:00
$query -> where ( 'v.abbreviation = ' . $db -> quote ( $checkValue ));
2023-07-26 09:09:42 +00:00
}
elseif ( is_numeric ( $checkValue ))
{
2023-08-01 05:29:00 +00:00
$query -> where ( 'v.abbreviation = ' . $checkValue );
2023-07-26 09:09:42 +00:00
}
else
{
return false ;
}
// Reset the query using our newly populated query object.
$db -> setQuery ( $query );
$db -> execute ();
// check if there was data returned
if ( $db -> getNumRows ())
{
// Load the JEvent Dispatcher
2024-01-22 08:48:28 +00:00
PluginHelper :: importPlugin ( 'content' );
$this -> _dispatcher = Factory :: getApplication ();
2023-07-26 09:09:42 +00:00
$items = $db -> loadObjectList ();
// Convert the parameter fields into objects.
foreach ( $items as $nr => & $item )
{
// Check if item has params, or pass whole item.
2024-01-22 08:48:28 +00:00
$params = ( isset ( $item -> params ) && JsonHelper :: check ( $item -> params )) ? json_decode ( $item -> params ) : $item ;
2023-07-26 09:09:42 +00:00
// Make sure the content prepare plugins fire on text
2024-01-26 15:18:26 +00:00
$_text = new \stdClass ();
2023-07-26 09:09:42 +00:00
$_text -> text =& $item -> text ; // value must be in text
// Since all values are now in text (Joomla Limitation), we also add the field name (text) to context
$this -> _dispatcher -> triggerEvent ( " onContentPrepare " , array ( 'com_getbible.app.text' , & $_text , & $params , 0 ));
}
return $items ;
}
return false ;
}
/**
* Custom Method
*
* @ return mixed An array of objects on success , false on failure .
*
*/
public function getTranslations ()
{
if ( ! isset ( $this -> initSet ) || ! $this -> initSet )
{
2024-01-22 08:48:28 +00:00
$this -> user = Factory :: getUser ();
2023-07-26 09:09:42 +00:00
$this -> userId = $this -> user -> get ( 'id' );
$this -> guest = $this -> user -> get ( 'guest' );
$this -> groups = $this -> user -> get ( 'groups' );
$this -> authorisedGroups = $this -> user -> getAuthorisedGroups ();
$this -> levels = $this -> user -> getAuthorisedViewLevels ();
$this -> initSet = true ;
}
// Get the global params
2024-01-22 08:48:28 +00:00
$globalParams = ComponentHelper :: getParams ( 'com_getbible' , true );
2023-07-26 09:09:42 +00:00
// Get a db connection.
2024-01-22 08:48:28 +00:00
$db = Factory :: getDbo ();
2023-07-26 09:09:42 +00:00
// Create a new query object.
$query = $db -> getQuery ( true );
// Get from #__getbible_translation as a
$query -> select ( $db -> quoteName (
2023-08-03 04:40:07 +00:00
array ( 'a.id' , 'a.language' , 'a.lang' , 'a.translation' , 'a.abbreviation' , 'a.distribution_lcsh' ),
array ( 'id' , 'language' , 'lang' , 'translation' , 'abbreviation' , 'lcsh' )));
2023-07-26 09:09:42 +00:00
$query -> from ( $db -> quoteName ( '#__getbible_translation' , 'a' ));
// Get where a.published is 1
$query -> where ( 'a.published = 1' );
$query -> order ( 'a.abbreviation ASC' );
$query -> order ( 'a.lang ASC' );
$query -> order ( 'a.translation ASC' );
// Reset the query using our newly populated query object.
$db -> setQuery ( $query );
$items = $db -> loadObjectList ();
if ( empty ( $items ))
{
return false ;
}
// Insure all item fields are adapted where needed.
2024-01-22 08:48:28 +00:00
if ( UtilitiesArrayHelper :: check ( $items ))
2023-07-26 09:09:42 +00:00
{
// Load the JEvent Dispatcher
2024-01-22 08:48:28 +00:00
PluginHelper :: importPlugin ( 'content' );
$this -> _dispatcher = Factory :: getApplication ();
2023-07-26 09:09:42 +00:00
foreach ( $items as $nr => & $item )
{
// Always create a slug for sef URL's
2024-01-26 15:18:26 +00:00
$item -> slug = ( $item -> id ? ? '0' ) . ( isset ( $item -> alias ) ? ':' . $item -> alias : '' );
2023-07-26 09:09:42 +00:00
}
}
// return items
return $items ;
}
/**
* Custom Method
*
* @ return mixed An array of objects on success , false on failure .
*
*/
public function getBooks ()
{
if ( ! isset ( $this -> initSet ) || ! $this -> initSet )
{
2024-01-22 08:48:28 +00:00
$this -> user = Factory :: getUser ();
2023-07-26 09:09:42 +00:00
$this -> userId = $this -> user -> get ( 'id' );
$this -> guest = $this -> user -> get ( 'guest' );
$this -> groups = $this -> user -> get ( 'groups' );
$this -> authorisedGroups = $this -> user -> getAuthorisedGroups ();
$this -> levels = $this -> user -> getAuthorisedViewLevels ();
$this -> initSet = true ;
}
// Get the global params
2024-01-22 08:48:28 +00:00
$globalParams = ComponentHelper :: getParams ( 'com_getbible' , true );
2023-07-26 09:09:42 +00:00
// Get a db connection.
2024-01-22 08:48:28 +00:00
$db = Factory :: getDbo ();
2023-07-26 09:09:42 +00:00
// Create a new query object.
$query = $db -> getQuery ( true );
// Get from #__getbible_book as a
$query -> select ( $db -> quoteName (
array ( 'a.id' , 'a.name' , 'a.nr' , 'a.abbreviation' ),
array ( 'id' , 'name' , 'nr' , 'abbreviation' )));
$query -> from ( $db -> quoteName ( '#__getbible_book' , 'a' ));
// Check if $this->translation is a string or numeric value.
$checkValue = $this -> translation ;
2024-01-22 08:48:28 +00:00
if ( isset ( $checkValue ) && StringHelper :: check ( $checkValue ))
2023-07-26 09:09:42 +00:00
{
$query -> where ( 'a.abbreviation = ' . $db -> quote ( $checkValue ));
}
elseif ( is_numeric ( $checkValue ))
{
$query -> where ( 'a.abbreviation = ' . $checkValue );
}
else
{
return false ;
}
$query -> order ( 'a.nr ASC' );
// Reset the query using our newly populated query object.
$db -> setQuery ( $query );
$items = $db -> loadObjectList ();
if ( empty ( $items ))
{
return false ;
}
// Insure all item fields are adapted where needed.
2024-01-22 08:48:28 +00:00
if ( UtilitiesArrayHelper :: check ( $items ))
2023-07-26 09:09:42 +00:00
{
foreach ( $items as $nr => & $item )
{
// Always create a slug for sef URL's
2024-01-26 15:18:26 +00:00
$item -> slug = ( $item -> id ? ? '0' ) . ( isset ( $item -> alias ) ? ':' . $item -> alias : '' );
2023-07-26 09:09:42 +00:00
}
}
// return items
return $items ;
}
/**
* Custom Method
*
* @ return mixed An array of objects on success , false on failure .
*
*/
public function getChapters ()
{
if ( ! isset ( $this -> initSet ) || ! $this -> initSet )
{
2024-01-22 08:48:28 +00:00
$this -> user = Factory :: getUser ();
2023-07-26 09:09:42 +00:00
$this -> userId = $this -> user -> get ( 'id' );
$this -> guest = $this -> user -> get ( 'guest' );
$this -> groups = $this -> user -> get ( 'groups' );
$this -> authorisedGroups = $this -> user -> getAuthorisedGroups ();
$this -> levels = $this -> user -> getAuthorisedViewLevels ();
$this -> initSet = true ;
}
// Get the global params
2024-01-22 08:48:28 +00:00
$globalParams = ComponentHelper :: getParams ( 'com_getbible' , true );
2023-07-26 09:09:42 +00:00
// Get a db connection.
2024-01-22 08:48:28 +00:00
$db = Factory :: getDbo ();
2023-07-26 09:09:42 +00:00
// Create a new query object.
$query = $db -> getQuery ( true );
// Get from #__getbible_chapter as a
$query -> select ( $db -> quoteName (
array ( 'a.id' , 'a.name' , 'a.chapter' , 'a.abbreviation' ),
array ( 'id' , 'name' , 'chapter' , 'abbreviation' )));
$query -> from ( $db -> quoteName ( '#__getbible_chapter' , 'a' ));
// Get from #__getbible_book as b
$query -> select ( $db -> quoteName (
array ( 'b.name' ),
array ( 'book_name' )));
$query -> join ( 'LEFT' , ( $db -> quoteName ( '#__getbible_book' , 'b' )) . ' ON (' . $db -> quoteName ( 'a.book_nr' ) . ' = ' . $db -> quoteName ( 'b.nr' ) . ')' );
// Check if $this->translation is a string or numeric value.
$checkValue = $this -> translation ;
2024-01-22 08:48:28 +00:00
if ( isset ( $checkValue ) && StringHelper :: check ( $checkValue ))
2023-07-26 09:09:42 +00:00
{
$query -> where ( 'a.abbreviation = ' . $db -> quote ( $checkValue ));
}
elseif ( is_numeric ( $checkValue ))
{
$query -> where ( 'a.abbreviation = ' . $checkValue );
}
else
{
return false ;
}
// Check if $this->book is a string or numeric value.
$checkValue = $this -> book ;
2024-01-22 08:48:28 +00:00
if ( isset ( $checkValue ) && StringHelper :: check ( $checkValue ))
2023-07-26 09:09:42 +00:00
{
$query -> where ( 'a.book_nr = ' . $db -> quote ( $checkValue ));
}
elseif ( is_numeric ( $checkValue ))
{
$query -> where ( 'a.book_nr = ' . $checkValue );
}
else
{
return false ;
}
// Check if $this->translation is a string or numeric value.
$checkValue = $this -> translation ;
2024-01-22 08:48:28 +00:00
if ( isset ( $checkValue ) && StringHelper :: check ( $checkValue ))
2023-07-26 09:09:42 +00:00
{
$query -> where ( 'b.abbreviation = ' . $db -> quote ( $checkValue ));
}
elseif ( is_numeric ( $checkValue ))
{
$query -> where ( 'b.abbreviation = ' . $checkValue );
}
else
{
return false ;
}
$query -> order ( 'a.book_nr ASC' );
$query -> order ( 'a.chapter ASC' );
$query -> group ( 'a.chapter' );
// Reset the query using our newly populated query object.
$db -> setQuery ( $query );
$items = $db -> loadObjectList ();
if ( empty ( $items ))
{
return false ;
}
// Insure all item fields are adapted where needed.
2024-01-22 08:48:28 +00:00
if ( UtilitiesArrayHelper :: check ( $items ))
2023-07-26 09:09:42 +00:00
{
foreach ( $items as $nr => & $item )
{
// Always create a slug for sef URL's
2024-01-26 15:18:26 +00:00
$item -> slug = ( $item -> id ? ? '0' ) . ( isset ( $item -> alias ) ? ':' . $item -> alias : '' );
2023-07-26 09:09:42 +00:00
}
}
// return items
return $items ;
}
/**
* Custom Method
*
* @ return mixed item data object on success , false on failure .
*
*/
public function getNext ()
{
if ( ! isset ( $this -> initSet ) || ! $this -> initSet )
{
2024-01-22 08:48:28 +00:00
$this -> user = Factory :: getUser ();
2023-07-26 09:09:42 +00:00
$this -> userId = $this -> user -> get ( 'id' );
$this -> guest = $this -> user -> get ( 'guest' );
$this -> groups = $this -> user -> get ( 'groups' );
$this -> authorisedGroups = $this -> user -> getAuthorisedGroups ();
$this -> levels = $this -> user -> getAuthorisedViewLevels ();
$this -> initSet = true ;
}
// the target book
$book = $this -> book ;
// get the next chapter
2024-01-22 08:48:28 +00:00
if (( $chapter = GetBibleFactory :: _ ( 'GetBible.Watcher' ) -> getNextChapter ( $this -> translation , $this -> book , $this -> chapter , true )) === null )
2023-07-26 09:09:42 +00:00
{
2024-01-22 08:48:28 +00:00
$book = GetBibleFactory :: _ ( 'GetBible.Watcher' ) -> getNextBook ( $this -> translation , $this -> book );
2023-07-26 09:09:42 +00:00
$chapter = 1 ;
// make sure its loaded
2024-01-22 08:48:28 +00:00
if ( empty ( $book ) || ! GetBibleFactory :: _ ( 'GetBible.Watcher' ) -> sync ( $this -> translation , $book , $chapter ))
2023-07-26 09:09:42 +00:00
{
return false ;
}
}
// Get a db connection.
2024-01-22 08:48:28 +00:00
$db = Factory :: getDbo ();
2023-07-26 09:09:42 +00:00
// Create a new query object.
$query = $db -> getQuery ( true );
// Get from #__getbible_chapter as a
$query -> select ( $db -> quoteName (
array ( 'a.id' , 'a.chapter' , 'a.abbreviation' ),
array ( 'id' , 'chapter' , 'abbreviation' )));
$query -> from ( $db -> quoteName ( '#__getbible_chapter' , 'a' ));
// Get from #__getbible_book as b
$query -> select ( $db -> quoteName (
array ( 'b.name' ),
array ( 'name' )));
$query -> join ( 'LEFT' , ( $db -> quoteName ( '#__getbible_book' , 'b' )) . ' ON (' . $db -> quoteName ( 'a.book_nr' ) . ' = ' . $db -> quoteName ( 'b.nr' ) . ')' );
// Check if $this->translation is a string or numeric value.
$checkValue = $this -> translation ;
2024-01-22 08:48:28 +00:00
if ( isset ( $checkValue ) && StringHelper :: check ( $checkValue ))
2023-07-26 09:09:42 +00:00
{
$query -> where ( 'a.abbreviation = ' . $db -> quote ( $checkValue ));
}
elseif ( is_numeric ( $checkValue ))
{
$query -> where ( 'a.abbreviation = ' . $checkValue );
}
else
{
return false ;
}
// Check if $book is a string or numeric value.
$checkValue = $book ;
2024-01-22 08:48:28 +00:00
if ( isset ( $checkValue ) && StringHelper :: check ( $checkValue ))
2023-07-26 09:09:42 +00:00
{
$query -> where ( 'a.book_nr = ' . $db -> quote ( $checkValue ));
}
elseif ( is_numeric ( $checkValue ))
{
$query -> where ( 'a.book_nr = ' . $checkValue );
}
else
{
return false ;
}
// Check if $chapter is a string or numeric value.
$checkValue = $chapter ;
2024-01-22 08:48:28 +00:00
if ( isset ( $checkValue ) && StringHelper :: check ( $checkValue ))
2023-07-26 09:09:42 +00:00
{
$query -> where ( 'a.chapter = ' . $db -> quote ( $checkValue ));
}
elseif ( is_numeric ( $checkValue ))
{
$query -> where ( 'a.chapter = ' . $checkValue );
}
else
{
return false ;
}
// Check if $this->translation is a string or numeric value.
$checkValue = $this -> translation ;
2024-01-22 08:48:28 +00:00
if ( isset ( $checkValue ) && StringHelper :: check ( $checkValue ))
2023-07-26 09:09:42 +00:00
{
$query -> where ( 'b.abbreviation = ' . $db -> quote ( $checkValue ));
}
elseif ( is_numeric ( $checkValue ))
{
$query -> where ( 'b.abbreviation = ' . $checkValue );
}
else
{
return false ;
}
// Reset the query using our newly populated query object.
$db -> setQuery ( $query );
// Load the results as a stdClass object.
$data = $db -> loadObject ();
if ( empty ( $data ))
{
return false ;
}
// return data object.
return $data ;
}
/**
* Custom Method
*
* @ return mixed item data object on success , false on failure .
*
*/
public function getPrevious ()
{
if ( ! isset ( $this -> initSet ) || ! $this -> initSet )
{
2024-01-22 08:48:28 +00:00
$this -> user = Factory :: getUser ();
2023-07-26 09:09:42 +00:00
$this -> userId = $this -> user -> get ( 'id' );
$this -> guest = $this -> user -> get ( 'guest' );
$this -> groups = $this -> user -> get ( 'groups' );
$this -> authorisedGroups = $this -> user -> getAuthorisedGroups ();
$this -> levels = $this -> user -> getAuthorisedViewLevels ();
$this -> initSet = true ;
}
// the target book
$book = $this -> book ;
// get the next chapter
2024-01-22 08:48:28 +00:00
if (( $chapter = GetBibleFactory :: _ ( 'GetBible.Watcher' ) -> getPreviousChapter ( $this -> chapter , true )) === null )
2023-07-26 09:09:42 +00:00
{
2024-01-22 08:48:28 +00:00
$book = GetBibleFactory :: _ ( 'GetBible.Watcher' ) -> getPreviousBook ( $this -> translation , $this -> book );
2023-07-26 09:09:42 +00:00
// make sure its loaded
2024-01-22 08:48:28 +00:00
if ( empty ( $book ) || ! GetBibleFactory :: _ ( 'GetBible.Watcher' ) -> sync ( $this -> translation , $book , 1 ))
2023-07-26 09:09:42 +00:00
{
return false ;
}
2024-01-22 08:48:28 +00:00
$chapter = GetBibleFactory :: _ ( 'GetBible.Watcher' ) -> getLastChapter ( $this -> translation , $book );
2023-07-26 09:09:42 +00:00
}
// Get a db connection.
2024-01-22 08:48:28 +00:00
$db = Factory :: getDbo ();
2023-07-26 09:09:42 +00:00
// Create a new query object.
$query = $db -> getQuery ( true );
// Get from #__getbible_chapter as a
$query -> select ( $db -> quoteName (
array ( 'a.id' , 'a.chapter' , 'a.abbreviation' ),
array ( 'id' , 'chapter' , 'abbreviation' )));
$query -> from ( $db -> quoteName ( '#__getbible_chapter' , 'a' ));
// Get from #__getbible_book as b
$query -> select ( $db -> quoteName (
array ( 'b.name' ),
array ( 'name' )));
$query -> join ( 'LEFT' , ( $db -> quoteName ( '#__getbible_book' , 'b' )) . ' ON (' . $db -> quoteName ( 'a.book_nr' ) . ' = ' . $db -> quoteName ( 'b.nr' ) . ')' );
// Check if $this->translation is a string or numeric value.
$checkValue = $this -> translation ;
2024-01-22 08:48:28 +00:00
if ( isset ( $checkValue ) && StringHelper :: check ( $checkValue ))
2023-07-26 09:09:42 +00:00
{
$query -> where ( 'a.abbreviation = ' . $db -> quote ( $checkValue ));
}
elseif ( is_numeric ( $checkValue ))
{
$query -> where ( 'a.abbreviation = ' . $checkValue );
}
else
{
return false ;
}
// Check if $book is a string or numeric value.
$checkValue = $book ;
2024-01-22 08:48:28 +00:00
if ( isset ( $checkValue ) && StringHelper :: check ( $checkValue ))
2023-07-26 09:09:42 +00:00
{
$query -> where ( 'a.book_nr = ' . $db -> quote ( $checkValue ));
}
elseif ( is_numeric ( $checkValue ))
{
$query -> where ( 'a.book_nr = ' . $checkValue );
}
else
{
return false ;
}
// Check if $chapter is a string or numeric value.
$checkValue = $chapter ;
2024-01-22 08:48:28 +00:00
if ( isset ( $checkValue ) && StringHelper :: check ( $checkValue ))
2023-07-26 09:09:42 +00:00
{
$query -> where ( 'a.chapter = ' . $db -> quote ( $checkValue ));
}
elseif ( is_numeric ( $checkValue ))
{
$query -> where ( 'a.chapter = ' . $checkValue );
}
else
{
return false ;
}
// Check if $this->translation is a string or numeric value.
$checkValue = $this -> translation ;
2024-01-22 08:48:28 +00:00
if ( isset ( $checkValue ) && StringHelper :: check ( $checkValue ))
2023-07-26 09:09:42 +00:00
{
$query -> where ( 'b.abbreviation = ' . $db -> quote ( $checkValue ));
}
elseif ( is_numeric ( $checkValue ))
{
$query -> where ( 'b.abbreviation = ' . $checkValue );
}
else
{
return false ;
}
// Reset the query using our newly populated query object.
$db -> setQuery ( $query );
// Load the results as a stdClass object.
$data = $db -> loadObject ();
if ( empty ( $data ))
{
return false ;
}
// return data object.
return $data ;
}
/**
* Custom Method
*
* @ return mixed item data object on success , false on failure .
*
*/
public function getTranslation ()
{
if ( ! isset ( $this -> initSet ) || ! $this -> initSet )
{
2024-01-22 08:48:28 +00:00
$this -> user = Factory :: getUser ();
2023-07-26 09:09:42 +00:00
$this -> userId = $this -> user -> get ( 'id' );
$this -> guest = $this -> user -> get ( 'guest' );
$this -> groups = $this -> user -> get ( 'groups' );
$this -> authorisedGroups = $this -> user -> getAuthorisedGroups ();
$this -> levels = $this -> user -> getAuthorisedViewLevels ();
$this -> initSet = true ;
}
// Get a db connection.
2024-01-22 08:48:28 +00:00
$db = Factory :: getDbo ();
2023-07-26 09:09:42 +00:00
// Create a new query object.
$query = $db -> getQuery ( true );
// Get from #__getbible_translation as a
$query -> select ( $db -> quoteName (
array ( 'a.distribution_abbreviation' , 'a.distribution_versification' , 'a.distribution_version' , 'a.distribution_version_date' , 'a.distribution_lcsh' , 'a.encoding' , 'a.sha' , 'a.language' , 'a.lang' , 'a.distribution_sourcetype' , 'a.distribution_source' , 'a.distribution_license' , 'a.distribution_about' , 'a.distribution_history' , 'a.translation' , 'a.abbreviation' , 'a.direction' ),
array ( 'distribution_abbreviation' , 'distribution_versification' , 'distribution_version' , 'distribution_version_date' , 'distribution_lcsh' , 'encoding' , 'sha' , 'language' , 'lang' , 'distribution_sourcetype' , 'distribution_source' , 'distribution_license' , 'distribution_about' , 'distribution_history' , 'translation' , 'abbreviation' , 'direction' )));
$query -> from ( $db -> quoteName ( '#__getbible_translation' , 'a' ));
// Check if $this->translation is a string or numeric value.
$checkValue = $this -> translation ;
2024-01-22 08:48:28 +00:00
if ( isset ( $checkValue ) && StringHelper :: check ( $checkValue ))
2023-07-26 09:09:42 +00:00
{
$query -> where ( 'a.abbreviation = ' . $db -> quote ( $checkValue ));
}
elseif ( is_numeric ( $checkValue ))
{
$query -> where ( 'a.abbreviation = ' . $checkValue );
}
else
{
return false ;
}
// Reset the query using our newly populated query object.
$db -> setQuery ( $query );
// Load the results as a stdClass object.
$data = $db -> loadObject ();
if ( empty ( $data ))
{
return false ;
}
// Load the JEvent Dispatcher
2024-01-22 08:48:28 +00:00
PluginHelper :: importPlugin ( 'content' );
$this -> _dispatcher = Factory :: getApplication ();
2023-07-26 09:09:42 +00:00
// Check if we can decode distribution_history
2024-01-22 08:48:28 +00:00
if ( isset ( $data -> distribution_history ) && JsonHelper :: check ( $data -> distribution_history ))
2023-07-26 09:09:42 +00:00
{
// Decode distribution_history
$data -> distribution_history = json_decode ( $data -> distribution_history , true );
}
// Check if item has params, or pass whole item.
2024-01-22 08:48:28 +00:00
$params = ( isset ( $data -> params ) && JsonHelper :: check ( $data -> params )) ? json_decode ( $data -> params ) : $data ;
2023-07-26 09:09:42 +00:00
// Make sure the content prepare plugins fire on distribution_about
2024-01-26 15:18:26 +00:00
$_distribution_about = new \stdClass ();
2023-07-26 09:09:42 +00:00
$_distribution_about -> text =& $data -> distribution_about ; // value must be in text
// Since all values are now in text (Joomla Limitation), we also add the field name (distribution_about) to context
$this -> _dispatcher -> triggerEvent ( " onContentPrepare " , array ( 'com_getbible.app.distribution_about' , & $_distribution_about , & $params , 0 ));
// Make sure the content prepare plugins fire on distribution_license
2024-01-26 15:18:26 +00:00
$_distribution_license = new \stdClass ();
2023-07-26 09:09:42 +00:00
$_distribution_license -> text =& $data -> distribution_license ; // value must be in text
// Since all values are now in text (Joomla Limitation), we also add the field name (distribution_license) to context
$this -> _dispatcher -> triggerEvent ( " onContentPrepare " , array ( 'com_getbible.app.distribution_license' , & $_distribution_license , & $params , 0 ));
// return data object.
return $data ;
}
/**
* Custom Method
*
* @ return mixed An array of objects on success , false on failure .
*
*/
public function getNotes ()
{
if ( ! isset ( $this -> initSet ) || ! $this -> initSet )
{
2024-01-22 08:48:28 +00:00
$this -> user = Factory :: getUser ();
2023-07-26 09:09:42 +00:00
$this -> userId = $this -> user -> get ( 'id' );
$this -> guest = $this -> user -> get ( 'guest' );
$this -> groups = $this -> user -> get ( 'groups' );
$this -> authorisedGroups = $this -> user -> getAuthorisedGroups ();
$this -> levels = $this -> user -> getAuthorisedViewLevels ();
$this -> initSet = true ;
}
// Get the global params
2024-01-22 08:48:28 +00:00
$globalParams = ComponentHelper :: getParams ( 'com_getbible' , true );
2023-07-26 09:09:42 +00:00
// Get a db connection.
2024-01-22 08:48:28 +00:00
$db = Factory :: getDbo ();
2023-07-26 09:09:42 +00:00
// Create a new query object.
$query = $db -> getQuery ( true );
// Get from #__getbible_note as a
$query -> select ( $db -> quoteName (
array ( 'a.id' , 'a.verse' , 'a.book_nr' , 'a.chapter' , 'a.note' ),
array ( 'id' , 'verse' , 'book_nr' , 'chapter' , 'note' )));
$query -> from ( $db -> quoteName ( '#__getbible_note' , 'a' ));
// Check if $this->chapter is a string or numeric value.
$checkValue = $this -> chapter ;
2024-01-22 08:48:28 +00:00
if ( isset ( $checkValue ) && StringHelper :: check ( $checkValue ))
2023-07-26 09:09:42 +00:00
{
$query -> where ( 'a.chapter = ' . $db -> quote ( $checkValue ));
}
elseif ( is_numeric ( $checkValue ))
{
$query -> where ( 'a.chapter = ' . $checkValue );
}
else
{
return false ;
}
// Check if $this->book is a string or numeric value.
$checkValue = $this -> book ;
2024-01-22 08:48:28 +00:00
if ( isset ( $checkValue ) && StringHelper :: check ( $checkValue ))
2023-07-26 09:09:42 +00:00
{
$query -> where ( 'a.book_nr = ' . $db -> quote ( $checkValue ));
}
elseif ( is_numeric ( $checkValue ))
{
$query -> where ( 'a.book_nr = ' . $checkValue );
}
else
{
return false ;
}
// Get where a.access is 1
$query -> where ( 'a.access = 1' );
// Get where a.published is 1
$query -> where ( 'a.published = 1' );
// Reset the query using our newly populated query object.
$db -> setQuery ( $query );
$items = $db -> loadObjectList ();
if ( empty ( $items ))
{
return false ;
}
// Insure all item fields are adapted where needed.
2024-01-22 08:48:28 +00:00
if ( UtilitiesArrayHelper :: check ( $items ))
2023-07-26 09:09:42 +00:00
{
// Load the JEvent Dispatcher
2024-01-22 08:48:28 +00:00
PluginHelper :: importPlugin ( 'content' );
$this -> _dispatcher = Factory :: getApplication ();
2023-07-26 09:09:42 +00:00
foreach ( $items as $nr => & $item )
{
// Always create a slug for sef URL's
2024-01-26 15:18:26 +00:00
$item -> slug = ( $item -> id ? ? '0' ) . ( isset ( $item -> alias ) ? ':' . $item -> alias : '' );
2023-07-26 09:09:42 +00:00
// Check if item has params, or pass whole item.
2024-01-22 08:48:28 +00:00
$params = ( isset ( $item -> params ) && JsonHelper :: check ( $item -> params )) ? json_decode ( $item -> params ) : $item ;
2023-07-26 09:09:42 +00:00
// Make sure the content prepare plugins fire on note
2024-01-26 15:18:26 +00:00
$_note = new \stdClass ();
2023-07-26 09:09:42 +00:00
$_note -> text =& $item -> note ; // value must be in text
// Since all values are now in text (Joomla Limitation), we also add the field name (note) to context
$this -> _dispatcher -> triggerEvent ( " onContentPrepare " , array ( 'com_getbible.app.note' , & $_note , & $params , 0 ));
}
}
// return items
return $items ;
}
/**
* Custom Method
*
* @ return mixed An array of objects on success , false on failure .
*
*/
public function getLinkerNotes ()
{
if ( ! isset ( $this -> initSet ) || ! $this -> initSet )
{
2024-01-22 08:48:28 +00:00
$this -> user = Factory :: getUser ();
2023-07-26 09:09:42 +00:00
$this -> userId = $this -> user -> get ( 'id' );
$this -> guest = $this -> user -> get ( 'guest' );
$this -> groups = $this -> user -> get ( 'groups' );
$this -> authorisedGroups = $this -> user -> getAuthorisedGroups ();
$this -> levels = $this -> user -> getAuthorisedViewLevels ();
$this -> initSet = true ;
}
// Get the global params
2024-01-22 08:48:28 +00:00
$globalParams = ComponentHelper :: getParams ( 'com_getbible' , true );
2023-07-26 09:09:42 +00:00
// Get a db connection.
2024-01-22 08:48:28 +00:00
$db = Factory :: getDbo ();
2023-07-26 09:09:42 +00:00
// Create a new query object.
$query = $db -> getQuery ( true );
// Get from #__getbible_note as a
$query -> select ( $db -> quoteName (
array ( 'a.id' , 'a.verse' , 'a.book_nr' , 'a.chapter' , 'a.note' , 'a.linker' , 'a.guid' ),
array ( 'id' , 'verse' , 'book_nr' , 'chapter' , 'note' , 'linker' , 'guid' )));
$query -> from ( $db -> quoteName ( '#__getbible_note' , 'a' ));
2024-01-22 08:48:28 +00:00
// Check if GetBibleFactory::_('GetBible.Linker')->active(true) is a string or numeric value.
$checkValue = GetBibleFactory :: _ ( 'GetBible.Linker' ) -> active ( true );
if ( isset ( $checkValue ) && StringHelper :: check ( $checkValue ))
2023-07-26 09:09:42 +00:00
{
$query -> where ( 'a.linker = ' . $db -> quote ( $checkValue ));
}
elseif ( is_numeric ( $checkValue ))
{
$query -> where ( 'a.linker = ' . $checkValue );
}
else
{
return false ;
}
// Check if $this->book is a string or numeric value.
$checkValue = $this -> book ;
2024-01-22 08:48:28 +00:00
if ( isset ( $checkValue ) && StringHelper :: check ( $checkValue ))
2023-07-26 09:09:42 +00:00
{
$query -> where ( 'a.book_nr = ' . $db -> quote ( $checkValue ));
}
elseif ( is_numeric ( $checkValue ))
{
$query -> where ( 'a.book_nr = ' . $checkValue );
}
else
{
return false ;
}
// Check if $this->chapter is a string or numeric value.
$checkValue = $this -> chapter ;
2024-01-22 08:48:28 +00:00
if ( isset ( $checkValue ) && StringHelper :: check ( $checkValue ))
2023-07-26 09:09:42 +00:00
{
$query -> where ( 'a.chapter = ' . $db -> quote ( $checkValue ));
}
elseif ( is_numeric ( $checkValue ))
{
$query -> where ( 'a.chapter = ' . $checkValue );
}
else
{
return false ;
}
// Get where a.access is 0
$query -> where ( 'a.access = 0' );
// Get where a.published is 1
$query -> where ( 'a.published = 1' );
// Reset the query using our newly populated query object.
$db -> setQuery ( $query );
$items = $db -> loadObjectList ();
if ( empty ( $items ))
{
return false ;
}
// Insure all item fields are adapted where needed.
2024-01-22 08:48:28 +00:00
if ( UtilitiesArrayHelper :: check ( $items ))
2023-07-26 09:09:42 +00:00
{
// Load the JEvent Dispatcher
2024-01-22 08:48:28 +00:00
PluginHelper :: importPlugin ( 'content' );
$this -> _dispatcher = Factory :: getApplication ();
2023-07-26 09:09:42 +00:00
foreach ( $items as $nr => & $item )
{
// Always create a slug for sef URL's
2024-01-26 15:18:26 +00:00
$item -> slug = ( $item -> id ? ? '0' ) . ( isset ( $item -> alias ) ? ':' . $item -> alias : '' );
2023-07-26 09:09:42 +00:00
// Check if item has params, or pass whole item.
2024-01-22 08:48:28 +00:00
$params = ( isset ( $item -> params ) && JsonHelper :: check ( $item -> params )) ? json_decode ( $item -> params ) : $item ;
2023-07-26 09:09:42 +00:00
// Make sure the content prepare plugins fire on note
2024-01-26 15:18:26 +00:00
$_note = new \stdClass ();
2023-07-26 09:09:42 +00:00
$_note -> text =& $item -> note ; // value must be in text
// Since all values are now in text (Joomla Limitation), we also add the field name (note) to context
$this -> _dispatcher -> triggerEvent ( " onContentPrepare " , array ( 'com_getbible.app.note' , & $_note , & $params , 0 ));
}
}
// return items
return $items ;
}
/**
* Custom Method
*
* @ return mixed An array of objects on success , false on failure .
*
*/
public function getTags ()
{
if ( ! isset ( $this -> initSet ) || ! $this -> initSet )
{
2024-01-22 08:48:28 +00:00
$this -> user = Factory :: getUser ();
2023-07-26 09:09:42 +00:00
$this -> userId = $this -> user -> get ( 'id' );
$this -> guest = $this -> user -> get ( 'guest' );
$this -> groups = $this -> user -> get ( 'groups' );
$this -> authorisedGroups = $this -> user -> getAuthorisedGroups ();
$this -> levels = $this -> user -> getAuthorisedViewLevels ();
$this -> initSet = true ;
}
// Get the global params
2024-01-22 08:48:28 +00:00
$globalParams = ComponentHelper :: getParams ( 'com_getbible' , true );
2023-07-26 09:09:42 +00:00
// Get a db connection.
2024-01-22 08:48:28 +00:00
$db = Factory :: getDbo ();
2023-07-26 09:09:42 +00:00
// Create a new query object.
$query = $db -> getQuery ( true );
// Get from #__getbible_tag as a
$query -> select ( $db -> quoteName (
array ( 'a.id' , 'a.name' , 'a.description' , 'a.guid' ),
array ( 'id' , 'name' , 'description' , 'guid' )));
$query -> from ( $db -> quoteName ( '#__getbible_tag' , 'a' ));
// Get where a.access is 1
$query -> where ( 'a.access = 1' );
// Get where a.published is 1
$query -> where ( 'a.published = 1' );
// Reset the query using our newly populated query object.
$db -> setQuery ( $query );
$items = $db -> loadObjectList ();
if ( empty ( $items ))
{
return false ;
}
// Insure all item fields are adapted where needed.
2024-01-22 08:48:28 +00:00
if ( UtilitiesArrayHelper :: check ( $items ))
2023-07-26 09:09:42 +00:00
{
// Load the JEvent Dispatcher
2024-01-22 08:48:28 +00:00
PluginHelper :: importPlugin ( 'content' );
$this -> _dispatcher = Factory :: getApplication ();
2023-07-26 09:09:42 +00:00
foreach ( $items as $nr => & $item )
{
// Always create a slug for sef URL's
2024-01-26 15:18:26 +00:00
$item -> slug = ( $item -> id ? ? '0' ) . ( isset ( $item -> alias ) ? ':' . $item -> alias : '' );
2023-07-26 09:09:42 +00:00
// Check if item has params, or pass whole item.
2024-01-22 08:48:28 +00:00
$params = ( isset ( $item -> params ) && JsonHelper :: check ( $item -> params )) ? json_decode ( $item -> params ) : $item ;
2023-07-26 09:09:42 +00:00
// Make sure the content prepare plugins fire on description
2024-01-26 15:18:26 +00:00
$_description = new \stdClass ();
2023-07-26 09:09:42 +00:00
$_description -> text =& $item -> description ; // value must be in text
// Since all values are now in text (Joomla Limitation), we also add the field name (description) to context
$this -> _dispatcher -> triggerEvent ( " onContentPrepare " , array ( 'com_getbible.app.description' , & $_description , & $params , 0 ));
}
}
// return items
return $items ;
}
/**
* Custom Method
*
* @ return mixed An array of objects on success , false on failure .
*
*/
public function getTaggedVerses ()
{
if ( ! isset ( $this -> initSet ) || ! $this -> initSet )
{
2024-01-22 08:48:28 +00:00
$this -> user = Factory :: getUser ();
2023-07-26 09:09:42 +00:00
$this -> userId = $this -> user -> get ( 'id' );
$this -> guest = $this -> user -> get ( 'guest' );
$this -> groups = $this -> user -> get ( 'groups' );
$this -> authorisedGroups = $this -> user -> getAuthorisedGroups ();
$this -> levels = $this -> user -> getAuthorisedViewLevels ();
$this -> initSet = true ;
}
// Get the global params
2024-01-22 08:48:28 +00:00
$globalParams = ComponentHelper :: getParams ( 'com_getbible' , true );
2023-07-26 09:09:42 +00:00
// Get a db connection.
2024-01-22 08:48:28 +00:00
$db = Factory :: getDbo ();
2023-07-26 09:09:42 +00:00
// Create a new query object.
$query = $db -> getQuery ( true );
// Get from #__getbible_tagged_verse as a
$query -> select ( $db -> quoteName (
array ( 'a.id' , 'a.verse' , 'a.book_nr' , 'a.chapter' , 'a.guid' ),
array ( 'id' , 'verse' , 'book_nr' , 'chapter' , 'guid' )));
$query -> from ( $db -> quoteName ( '#__getbible_tagged_verse' , 'a' ));
// Get from #__getbible_tag as t
$query -> select ( $db -> quoteName (
array ( 't.name' , 't.description' , 't.guid' ),
array ( 'name' , 'description' , 'tag' )));
$query -> join ( 'LEFT' , ( $db -> quoteName ( '#__getbible_tag' , 't' )) . ' ON (' . $db -> quoteName ( 'a.tag' ) . ' = ' . $db -> quoteName ( 't.guid' ) . ')' );
// Check if $this->book is a string or numeric value.
$checkValue = $this -> book ;
2024-01-22 08:48:28 +00:00
if ( isset ( $checkValue ) && StringHelper :: check ( $checkValue ))
2023-07-26 09:09:42 +00:00
{
$query -> where ( 'a.book_nr = ' . $db -> quote ( $checkValue ));
}
elseif ( is_numeric ( $checkValue ))
{
$query -> where ( 'a.book_nr = ' . $checkValue );
}
else
{
return false ;
}
// Check if $this->chapter is a string or numeric value.
$checkValue = $this -> chapter ;
2024-01-22 08:48:28 +00:00
if ( isset ( $checkValue ) && StringHelper :: check ( $checkValue ))
2023-07-26 09:09:42 +00:00
{
$query -> where ( 'a.chapter = ' . $db -> quote ( $checkValue ));
}
elseif ( is_numeric ( $checkValue ))
{
$query -> where ( 'a.chapter = ' . $checkValue );
}
else
{
return false ;
}
// Get where a.access is 1
$query -> where ( 'a.access = 1' );
// Get where a.published is 1
$query -> where ( 'a.published = 1' );
// Get where t.published is 1
$query -> where ( 't.published = 1' );
// Reset the query using our newly populated query object.
$db -> setQuery ( $query );
$items = $db -> loadObjectList ();
if ( empty ( $items ))
{
return false ;
}
// Insure all item fields are adapted where needed.
2024-01-22 08:48:28 +00:00
if ( UtilitiesArrayHelper :: check ( $items ))
2023-07-26 09:09:42 +00:00
{
// Load the JEvent Dispatcher
2024-01-22 08:48:28 +00:00
PluginHelper :: importPlugin ( 'content' );
$this -> _dispatcher = Factory :: getApplication ();
2023-07-26 09:09:42 +00:00
foreach ( $items as $nr => & $item )
{
// Always create a slug for sef URL's
2024-01-26 15:18:26 +00:00
$item -> slug = ( $item -> id ? ? '0' ) . ( isset ( $item -> alias ) ? ':' . $item -> alias : '' );
2023-07-26 09:09:42 +00:00
// Check if item has params, or pass whole item.
2024-01-22 08:48:28 +00:00
$params = ( isset ( $item -> params ) && JsonHelper :: check ( $item -> params )) ? json_decode ( $item -> params ) : $item ;
2023-07-26 09:09:42 +00:00
// Make sure the content prepare plugins fire on description
2024-01-26 15:18:26 +00:00
$_description = new \stdClass ();
2023-07-26 09:09:42 +00:00
$_description -> text =& $item -> description ; // value must be in text
// Since all values are now in text (Joomla Limitation), we also add the field name (description) to context
$this -> _dispatcher -> triggerEvent ( " onContentPrepare " , array ( 'com_getbible.app.description' , & $_description , & $params , 0 ));
}
}
// return items
return $items ;
}
/**
* Custom Method
*
* @ return mixed An array of objects on success , false on failure .
*
*/
public function getPrompts ()
{
if ( ! isset ( $this -> initSet ) || ! $this -> initSet )
{
2024-01-22 08:48:28 +00:00
$this -> user = Factory :: getUser ();
2023-07-26 09:09:42 +00:00
$this -> userId = $this -> user -> get ( 'id' );
$this -> guest = $this -> user -> get ( 'guest' );
$this -> groups = $this -> user -> get ( 'groups' );
$this -> authorisedGroups = $this -> user -> getAuthorisedGroups ();
$this -> levels = $this -> user -> getAuthorisedViewLevels ();
$this -> initSet = true ;
}
// Get the global params
2024-01-22 08:48:28 +00:00
$globalParams = ComponentHelper :: getParams ( 'com_getbible' , true );
2023-07-26 09:09:42 +00:00
// Get a db connection.
2024-01-22 08:48:28 +00:00
$db = Factory :: getDbo ();
2023-07-26 09:09:42 +00:00
// Create a new query object.
$query = $db -> getQuery ( true );
// Get from #__getbible_prompt as a
$query -> select ( $db -> quoteName (
array ( 'a.id' , 'a.integration' , 'a.name' , 'a.guid' ),
array ( 'id' , 'integration' , 'name' , 'guid' )));
$query -> from ( $db -> quoteName ( '#__getbible_prompt' , 'a' ));
// Check if ($globalParams->get('enable_open_ai') == 1) ? ($this->translation ? [$db->quote('all'), $db->quote($this->translation)] : [$db->quote('all')]) : null is an array with values.
$array = ( $globalParams -> get ( 'enable_open_ai' ) == 1 ) ? ( $this -> translation ? [ $db -> quote ( 'all' ), $db -> quote ( $this -> translation )] : [ $db -> quote ( 'all' )]) : null ;
2024-01-22 08:48:28 +00:00
if ( isset ( $array ) && UtilitiesArrayHelper :: check ( $array ))
2023-07-26 09:09:42 +00:00
{
$query -> where ( 'a.abbreviation IN (' . implode ( ',' , $array ) . ')' );
}
else
{
return false ;
}
// Get where a.published is 1
$query -> where ( 'a.published = 1' );
$query -> order ( 'a.ordering ASC' );
// Reset the query using our newly populated query object.
$db -> setQuery ( $query );
$items = $db -> loadObjectList ();
if ( empty ( $items ))
{
return false ;
}
// Insure all item fields are adapted where needed.
2024-01-22 08:48:28 +00:00
if ( UtilitiesArrayHelper :: check ( $items ))
2023-07-26 09:09:42 +00:00
{
foreach ( $items as $nr => & $item )
{
// Always create a slug for sef URL's
2024-01-26 15:18:26 +00:00
$item -> slug = ( $item -> id ? ? '0' ) . ( isset ( $item -> alias ) ? ':' . $item -> alias : '' );
2023-07-26 09:09:42 +00:00
}
}
// return items
return $items ;
}
/**
* Custom Method
*
* @ return mixed An array of objects on success , false on failure .
*
*/
public function getLinkerTaggedVerses ()
{
if ( ! isset ( $this -> initSet ) || ! $this -> initSet )
{
2024-01-22 08:48:28 +00:00
$this -> user = Factory :: getUser ();
2023-07-26 09:09:42 +00:00
$this -> userId = $this -> user -> get ( 'id' );
$this -> guest = $this -> user -> get ( 'guest' );
$this -> groups = $this -> user -> get ( 'groups' );
$this -> authorisedGroups = $this -> user -> getAuthorisedGroups ();
$this -> levels = $this -> user -> getAuthorisedViewLevels ();
$this -> initSet = true ;
}
// Get the global params
2024-01-22 08:48:28 +00:00
$globalParams = ComponentHelper :: getParams ( 'com_getbible' , true );
2023-07-26 09:09:42 +00:00
// Get a db connection.
2024-01-22 08:48:28 +00:00
$db = Factory :: getDbo ();
2023-07-26 09:09:42 +00:00
// Create a new query object.
$query = $db -> getQuery ( true );
// Get from #__getbible_tagged_verse as a
$query -> select ( $db -> quoteName (
array ( 'a.id' , 'a.linker' , 'a.verse' , 'a.book_nr' , 'a.chapter' , 'a.access' , 'a.published' , 'a.guid' ),
array ( 'id' , 'linker' , 'verse' , 'book_nr' , 'chapter' , 'access' , 'published' , 'guid' )));
$query -> from ( $db -> quoteName ( '#__getbible_tagged_verse' , 'a' ));
// Get from #__getbible_tag as b
$query -> select ( $db -> quoteName (
array ( 'b.name' , 'b.description' ),
array ( 'name' , 'description' )));
$query -> join ( 'LEFT' , ( $db -> quoteName ( '#__getbible_tag' , 'b' )) . ' ON (' . $db -> quoteName ( 'a.tag' ) . ' = ' . $db -> quoteName ( 'b.guid' ) . ')' );
// Get from #__getbible_tag as t
$query -> select ( $db -> quoteName (
array ( 't.guid' ),
array ( 'tag' )));
$query -> join ( 'LEFT' , ( $db -> quoteName ( '#__getbible_tag' , 't' )) . ' ON (' . $db -> quoteName ( 'a.tag' ) . ' = ' . $db -> quoteName ( 't.guid' ) . ')' );
2024-01-22 08:48:28 +00:00
// Check if GetBibleFactory::_('GetBible.Linker')->active(true) is a string or numeric value.
$checkValue = GetBibleFactory :: _ ( 'GetBible.Linker' ) -> active ( true );
if ( isset ( $checkValue ) && StringHelper :: check ( $checkValue ))
2023-07-26 09:09:42 +00:00
{
$query -> where ( 'a.linker = ' . $db -> quote ( $checkValue ));
}
elseif ( is_numeric ( $checkValue ))
{
$query -> where ( 'a.linker = ' . $checkValue );
}
else
{
return false ;
}
// Check if $this->book is a string or numeric value.
$checkValue = $this -> book ;
2024-01-22 08:48:28 +00:00
if ( isset ( $checkValue ) && StringHelper :: check ( $checkValue ))
2023-07-26 09:09:42 +00:00
{
$query -> where ( 'a.book_nr = ' . $db -> quote ( $checkValue ));
}
elseif ( is_numeric ( $checkValue ))
{
$query -> where ( 'a.book_nr = ' . $checkValue );
}
else
{
return false ;
}
// Check if $this->chapter is a string or numeric value.
$checkValue = $this -> chapter ;
2024-01-22 08:48:28 +00:00
if ( isset ( $checkValue ) && StringHelper :: check ( $checkValue ))
2023-07-26 09:09:42 +00:00
{
$query -> where ( 'a.chapter = ' . $db -> quote ( $checkValue ));
}
elseif ( is_numeric ( $checkValue ))
{
$query -> where ( 'a.chapter = ' . $checkValue );
}
else
{
return false ;
}
// Get where a.access is 0
$query -> where ( 'a.access = 0' );
// Get where b.published is 1
$query -> where ( 'b.published = 1' );
// Get where t.published is 1
$query -> where ( 't.published = 1' );
$query -> order ( 'a.book_nr ASC' );
$query -> order ( 'a.chapter ASC' );
$query -> order ( 'a.verse ASC' );
// Reset the query using our newly populated query object.
$db -> setQuery ( $query );
$items = $db -> loadObjectList ();
if ( empty ( $items ))
{
return false ;
}
// Insure all item fields are adapted where needed.
2024-01-22 08:48:28 +00:00
if ( UtilitiesArrayHelper :: check ( $items ))
2023-07-26 09:09:42 +00:00
{
// Load the JEvent Dispatcher
2024-01-22 08:48:28 +00:00
PluginHelper :: importPlugin ( 'content' );
$this -> _dispatcher = Factory :: getApplication ();
2023-07-26 09:09:42 +00:00
foreach ( $items as $nr => & $item )
{
// Always create a slug for sef URL's
2024-01-26 15:18:26 +00:00
$item -> slug = ( $item -> id ? ? '0' ) . ( isset ( $item -> alias ) ? ':' . $item -> alias : '' );
2023-07-26 09:09:42 +00:00
// Check if item has params, or pass whole item.
2024-01-22 08:48:28 +00:00
$params = ( isset ( $item -> params ) && JsonHelper :: check ( $item -> params )) ? json_decode ( $item -> params ) : $item ;
2023-07-26 09:09:42 +00:00
// Make sure the content prepare plugins fire on description
2024-01-26 15:18:26 +00:00
$_description = new \stdClass ();
2023-07-26 09:09:42 +00:00
$_description -> text =& $item -> description ; // value must be in text
// Since all values are now in text (Joomla Limitation), we also add the field name (description) to context
$this -> _dispatcher -> triggerEvent ( " onContentPrepare " , array ( 'com_getbible.app.description' , & $_description , & $params , 0 ));
}
}
// return items
return $items ;
}
/**
* Custom Method
*
* @ return mixed An array of objects on success , false on failure .
*
*/
public function getLinkerTags ()
{
if ( ! isset ( $this -> initSet ) || ! $this -> initSet )
{
2024-01-22 08:48:28 +00:00
$this -> user = Factory :: getUser ();
2023-07-26 09:09:42 +00:00
$this -> userId = $this -> user -> get ( 'id' );
$this -> guest = $this -> user -> get ( 'guest' );
$this -> groups = $this -> user -> get ( 'groups' );
$this -> authorisedGroups = $this -> user -> getAuthorisedGroups ();
$this -> levels = $this -> user -> getAuthorisedViewLevels ();
$this -> initSet = true ;
}
// Get the global params
2024-01-22 08:48:28 +00:00
$globalParams = ComponentHelper :: getParams ( 'com_getbible' , true );
2023-07-26 09:09:42 +00:00
// Get a db connection.
2024-01-22 08:48:28 +00:00
$db = Factory :: getDbo ();
2023-07-26 09:09:42 +00:00
// Create a new query object.
$query = $db -> getQuery ( true );
// Get from #__getbible_tag as a
$query -> select ( $db -> quoteName (
array ( 'a.id' , 'a.linker' , 'a.name' , 'a.description' , 'a.published' , 'a.guid' ),
array ( 'id' , 'linker' , 'name' , 'description' , 'published' , 'guid' )));
$query -> from ( $db -> quoteName ( '#__getbible_tag' , 'a' ));
2024-01-22 08:48:28 +00:00
// Check if GetBibleFactory::_('GetBible.Linker')->active(true) is a string or numeric value.
$checkValue = GetBibleFactory :: _ ( 'GetBible.Linker' ) -> active ( true );
if ( isset ( $checkValue ) && StringHelper :: check ( $checkValue ))
2023-07-26 09:09:42 +00:00
{
$query -> where ( 'a.linker = ' . $db -> quote ( $checkValue ));
}
elseif ( is_numeric ( $checkValue ))
{
$query -> where ( 'a.linker = ' . $checkValue );
}
else
{
return false ;
}
// Get where a.access is 0
$query -> where ( 'a.access = 0' );
// Reset the query using our newly populated query object.
$db -> setQuery ( $query );
$items = $db -> loadObjectList ();
if ( empty ( $items ))
{
return false ;
}
// Insure all item fields are adapted where needed.
2024-01-22 08:48:28 +00:00
if ( UtilitiesArrayHelper :: check ( $items ))
2023-07-26 09:09:42 +00:00
{
// Load the JEvent Dispatcher
2024-01-22 08:48:28 +00:00
PluginHelper :: importPlugin ( 'content' );
$this -> _dispatcher = Factory :: getApplication ();
2023-07-26 09:09:42 +00:00
foreach ( $items as $nr => & $item )
{
// Always create a slug for sef URL's
2024-01-26 15:18:26 +00:00
$item -> slug = ( $item -> id ? ? '0' ) . ( isset ( $item -> alias ) ? ':' . $item -> alias : '' );
2023-07-26 09:09:42 +00:00
// Check if item has params, or pass whole item.
2024-01-22 08:48:28 +00:00
$params = ( isset ( $item -> params ) && JsonHelper :: check ( $item -> params )) ? json_decode ( $item -> params ) : $item ;
2023-07-26 09:09:42 +00:00
// Make sure the content prepare plugins fire on description
2024-01-26 15:18:26 +00:00
$_description = new \stdClass ();
2023-07-26 09:09:42 +00:00
$_description -> text =& $item -> description ; // value must be in text
// Since all values are now in text (Joomla Limitation), we also add the field name (description) to context
$this -> _dispatcher -> triggerEvent ( " onContentPrepare " , array ( 'com_getbible.app.description' , & $_description , & $params , 0 ));
}
}
// return items
return $items ;
}
2023-07-26 17:53:35 +00:00
/**
* Get the book name
*
* @ param int $book The book number
*
* @ return string | null The book name on success
*/
protected function getBookName ( int $book , string $translation ) : ? string
{
// Get a db connection.
2024-01-22 08:48:28 +00:00
$db = Factory :: getDbo ();
2023-07-26 17:53:35 +00:00
// Create a new query object.
$query = $db -> getQuery ( true );
// Get from #__getbible_book as a
$query -> select ( $db -> quoteName (
array ( 'a.name' ),
array ( 'name' )));
$query -> from ( $db -> quoteName ( '#__getbible_book' , 'a' ));
$query -> where ( 'a.abbreviation = ' . $db -> quote ( $translation ));
$query -> where ( 'a.nr = ' . $book );
// Reset the query using our newly populated query object.
$db -> setQuery ( $query );
return $db -> loadResult ();
}
2023-07-26 09:09:42 +00:00
/**
* Method to add html span tag to each word in each verse
*
* @ param array $verses The array of verses
*
* @ return array The modelled array of verses .
*/
protected function modelVerses ( array $verses ) : array
{
$result = array_map ( function ( $source ) {
// Clone the object first, then modify the clone.
$obj = clone $source ;
$words = $this -> splitSentence ( $obj -> text );
$counter = 1 ;
$words = array_map ( function ( $word ) use ( & $obj , & $counter ) {
return $this -> addSpan ( $word , $counter , $obj -> verse );
}, $words );
$obj -> text = implode ( '' , $words );
return $obj ;
}, $verses );
return $result ;
}
/**
* Add the span tag
*
* @ param string $word A word being marked
* @ param int $nr The word number
* @ param string $verse A verse number
*
* @ return string The marked word
*/
protected function addSpan ( string $word , int & $nr , string & $verse ) : string
{
$plainWord = preg_replace ( '/[^\p{L}\p{N}\s]/u' , '' , $word );
$encodedWord = urlencode ( $plainWord );
if ( $this -> hasLength ( $plainWord ))
{
$word = '<span class="getbible-word" data-word-nr="' . $nr . '" data-verse="' . $verse . '" data-url-word="' . $encodedWord . '" data-word="' . $plainWord . '"> ' . $word . ' </span>' ;
$nr ++ ;
}
return $word ;
}
/**
* Return an array of words
*
* @ param string $text The actual sentence
*
* @ return array An array of words
*/
protected function splitSentence ( string $text ) : array
{
2024-01-22 08:48:28 +00:00
return GetBibleFactory :: _ ( 'GetBible.Utilities.String' ) -> split ( $text );
2023-07-26 09:09:42 +00:00
}
/**
* Make sure a string has a length
*
* @ param string $word The actual string to check
*
* @ return bool True if its a string with characters .
*/
protected function hasLength ( string $word ) : bool
{
2024-01-22 08:48:28 +00:00
return GetBibleFactory :: _ ( 'GetBible.Utilities.String' ) -> hasLength ( $word );
2023-07-26 09:09:42 +00:00
}
}