<?php
/**
 * Marketplace - Component Marketplace 
 * ******************************************************************
 *
 * PHP version 7.0
 *
 * @category   Component
 * @package    Joomla
 * @author     WebKul software private limited <support@webkul.com>
 * @copyright  2010 WebKul software private limited
 * @license    http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL
 * @version    GIT:5.2
 * @filesource http://store.webkul.com
 * @link       Technical Support:  webkul.uvdesk.com
 * ******************************************************************
 */
defined('_JEXEC') or die('Restricted access');
jimport('joomla.form.formfield');
/**
 * JFormFieldCountry class
 * 
 * @category Component
 * @package  Joomla
 * @author   WebKul software private limited <support@webkul.com>
 * @license  http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL
 * @link     Technical Support:  webkul.uvdesk.com
 */
class JFormFieldCountry extends JFormField
{
    public $type = 'Country';
    /**
     * GetInput function
     *
     * @return void
     */
    public function getInput()
    {
        $db = JFactory::getDBO();
        $query = $db->getQuery(true);
        $query->select(
            $db->quoteName('lang_code', 'value').",".$db->quoteName('title', 'text')
        );
        $query->from($db->quoteName('#__languages'));
        
        $query->order('title ASC');
        $db->setQuery($query);
        try{
            $country_list = $db->loadObjectList();
        }catch(Exception $e){
            JFactory::getApplication()->enqueueMessage(
                $e->getMessage(),
                'error'
            );
            return false;
        }
        $countries = $country_list;
        foreach ($country_list as $key=> $country) {
            $countries[$key]->text=$country->text;
            $countries[$key]->value=strtolower(
                str_replace('-', '_', $country->value)
            );
        }
        $javascript = ''; 
        $options = array();
        $options[] = JHTML::_(
            'select.option', '', '- '.JText::_('SELECT_COUNTRY').' -'
        );
        $options = array_merge($options, $countries); 
        return JHtml::_(
            'select.genericlist',
            $options,
            $this->name,
            null,
            'value',
            'text',
            $this->value,
            $this->id
        );
    }
}