<?php

/**
* @author    JoomShaper http://www.joomshaper.com
* @copyright Copyright (C) 2010 - 2013 JoomShaper
* @license   http://www.gnu.org/licenses/gpl-2.0.html GNU/GPLv2
*/

defined('_JEXEC') or die;

// Required Componenet and module helper
JLoader::register('modSpSoccerPollHelper', JPATH_ROOT . '/modules/mod_sp_soccer_poll/helper.php');

jimport('joomla.form.formfield');
jimport('joomla.filesystem.folder');
jimport('joomla.filesystem.file');

class JFormFieldPolls extends JFormField {

    protected $type = 'polls';

    protected function getInput(){

        // Get Tournaments
        $db = JFactory::getDbo();
        $query = $db->getQuery(true);

        // Select all records from the user profile table where key begins with "custom.".
        $query->select($db->quoteName(array('spsoccer_poll_id', 'title' )));
        $query->from($db->quoteName('#__spsoccer_polls'));
        $query->where($db->quoteName('enabled')." = 1");
        $query->order('ordering ASC');

        $db->setQuery($query);
        $results = $db->loadObjectList();
        $poll_list = $results;

        foreach($poll_list as $poll){
            $options[] = JHTML::_( 'select.option', $poll->spsoccer_poll_id, $poll->title );

            //print_r($tournament);
        }

        return JHTML::_('select.genericlist', $options, 'jform[params]['.$this->fieldname.']', '', 'value', 'text', $this->value);
    }
}
