joomla-component/admin/src/Field/TranslationsField.php

99 lines
3.1 KiB
PHP
Raw Normal View History

2023-07-26 09:09:42 +00:00
<?php
/*----------------------------------------------------------------------------------| io.vdm.dev |----/
Vast Development Method
/-------------------------------------------------------------------------------------------------------/
@package getBible.net
@created 3rd 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
/------------------------------------------------------------------------------------------------------*/
namespace TrueChristianBible\Component\GetBible\Administrator\Field;
2023-07-26 09:09:42 +00:00
use Joomla\CMS\Factory;
use Joomla\CMS\Form\Field\ListField;
use Joomla\CMS\Language\Text;
use Joomla\CMS\HTML\HTMLHelper as Html;
use Joomla\CMS\Component\ComponentHelper;
use TrueChristianBible\Component\GetBible\Administrator\Helper\GetbibleHelper;
2023-07-26 09:09:42 +00:00
// No direct access to this file
\defined('_JEXEC') or die;
2023-07-26 09:09:42 +00:00
/**
* Translations Form Field class for the Getbible component
*
* @since 1.6
2023-07-26 09:09:42 +00:00
*/
class TranslationsField extends ListField
2023-07-26 09:09:42 +00:00
{
/**
* The translations field type.
*
* @var string
2023-07-26 09:09:42 +00:00
*/
public $type = 'Translations';
2023-07-26 09:09:42 +00:00
/**
* Method to get a list of options for a list input.
*
* @return array An array of Html options.
* @since 1.6
2023-07-26 09:09:42 +00:00
*/
protected function getOptions()
{
// Get the user object.
$user = Factory::getApplication()->getIdentity();
2023-07-26 09:09:42 +00:00
// Get the databse object.
$db = Factory::getDBO();
2023-07-26 09:09:42 +00:00
$query = $db->getQuery(true);
$query->select($db->quoteName(array('a.abbreviation','a.translation'),array('abbreviation','abbreviation_translation')));
$query->from($db->quoteName('#__getbible_translation', 'a'));
$query->where($db->quoteName('a.published') . ' = 1');
$query->order('a.translation ASC');
// Implement View Level Access (if set in table)
if (!$user->authorise('core.options', 'com_getbible'))
{
$columns = $db->getTableColumns('#__getbible_translation');
if(isset($columns['access']))
{
$groups = implode(',', $user->getAuthorisedViewLevels());
$query->where('a.access IN (' . $groups . ')');
}
}
$db->setQuery((string)$query);
$items = $db->loadObjectList();
$options = [];
if (!empty($items))
2023-07-26 09:09:42 +00:00
{
if ($this->multiple === false)
{
$options[] = Html::_('select.option', '', Text::_('COM_GETBIBLE_SELECT_AN_OPTION'));
2023-07-26 09:09:42 +00:00
}
foreach($items as $item)
{
$options[] = Html::_('select.option', $item->abbreviation, $item->abbreviation_translation.' (' .$item->abbreviation.')');
2023-07-26 09:09:42 +00:00
}
}
// if none was found we load the KJV as the default
if (empty($options))
{
$options = [];
if ($this->multiple === false)
{
$options[] = Html::_('select.option', '', Text::_('COM_GETBIBLE_SELECT_AN_OPTION'));
}
$options[] = Html::_('select.option', 'kjv', 'King James Version (kjv)'); // this is the default at all times.
}
2023-07-26 09:09:42 +00:00
return $options;
}
}