| Current Path : /var/www/html/administrator/components/com_jchat/Field/ |
| Current File : /var/www/html/administrator/components/com_jchat/Field/ChatroomsField.php |
<?php
namespace JExtstore\Component\JChat\Administrator\Field;
/**
* @package JCHAT::CONFIG::administrator::components::com_jchat
* @subpackage Field
* @author Joomla! Extensions Store
* @copyright (C) 2024 - Joomla! Extensions Store
* @license GNU/GPLv2 http://www.gnu.org/licenses/gpl-2.0.html
*/
defined ( '_JEXEC' ) or die ( 'Restricted access' );
use Joomla\CMS\Form\Field\ListField;
use Joomla\CMS\Language\Text;
use Joomla\CMS\Factory;
use Joomla\CMS\HTML\HTMLHelper;
/**
* Templates selector
*
* @package JCHAT::CONFIG::administrator::components::com_jchat
* @subpackage Field
* @since 2.0
*/
class ChatroomsField extends ListField {
/**
* The form field type.
*
* @var string
*/
protected $type = 'chatrooms';
/**
* Method to get the field input markup for a generic list.
* Use the multiple attribute to enable multiselect.
*
* @return string The field input markup.
*/
protected function getInput() {
$attr = '';
// Initialize some field attributes.
$attr .= ! empty ( $this->class ) ? ' class="form-select ' . $this->class . '"' : ' class="form-select"';
$attr .= $this->disabled ? ' disabled' : '';
$attr .= ! empty ( $this->size ) ? ' size="' . $this->size . '"' : '';
$attr .= $this->multiple ? ' multiple' : '';
$attr .= $this->required ? ' required aria-required="true"' : '';
$attr .= $this->autofocus ? ' autofocus' : '';
// Initialize JavaScript field attributes.
$attr .= $this->onchange ? ' onchange="' . $this->onchange . '"' : '';
// Get the field options.
$options = $this->getOptions ();
return HTMLHelper::_ ( 'select.genericlist', $options, $this->name, trim ( $attr ), 'value', 'text', $this->value, $this->id );
}
/**
* Displays a list of the available access view levels
*
* @return array The field option objects.
*/
protected function getOptions() {
$db = Factory::getContainer()->get('DatabaseDriver');
$query = method_exists ( $db, 'createQuery' ) ? $db->createQuery () : $db->getQuery ( true );
$query->select('a.id AS value, a.name AS text')
->from('#__jchat_rooms AS a')
->order($db->quoteName('name') . ' ASC');
// Get the options.
$db->setQuery ( $query );
try {
$options = $db->loadObjectList ();
} catch(\Exception $e) {
return array();
}
array_unshift ( $options, HTMLHelper::_ ( 'select.option', '', Text::_ ( 'COM_JCHAT_NO_CHATROOMS' ) ) );
return $options;
}
}