Your IP : 216.73.216.224


Current Path : /var/www/html/administrator/components/com_jchat/Field/
Upload File :
Current File : /var/www/html/administrator/components/com_jchat/Field/ChataccesslevelField.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;

/**
 * Form Field for ACL access levels
 * 
 * @package JCHAT::CONFIG::administrator::components::com_jchat 
 * @subpackage Field
 * @since 1.0
 */
class ChataccesslevelField extends ListField {
	/**
	 * The form field type.
	 *
	 * @var string
	 */
	protected $type = 'chataccesslevel';
	
	/**
	 * 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.title AS text')
			  ->from('#__viewlevels AS a')
			  ->group('a.id, a.title, a.ordering')
			  ->order($db->quoteName('title') . ' ASC');
			
			// Get the options.
		$db->setQuery ( $query );
		
		try {
			$options = $db->loadObjectList ();
		} catch(\Exception $e) {
			return array();
		}
		
		array_unshift ( $options, HTMLHelper::_ ( 'select.option', '0', Text::_ ( 'COM_JCHAT_ALL_ACCESSLEVELS' ) ) );
		
		return $options;
	}
}