<?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('JPATH_BASE') or die;

    // Requred Componenet and module helper

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

    class JFormFieldSessions extends JFormField {

        protected $type = 'sessions';


        protected function getInput(){

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

            $query->select($db->quoteName(array('a.spsoccer_session_id', 'a.title', 'a.slug')));
            $query->select($db->quoteName('b.title', 'tournament_name'));
            $query->from($db->quoteName('#__spsoccer_sessions', 'a'));
            $query->join('LEFT', $db->quoteName('#__spsoccer_tournaments', 'b') . ' ON (' . $db->quoteName('a.spsoccer_tournament_id') . ' = ' . $db->quoteName('b.spsoccer_tournament_id') . ')');
            $query->where($db->quoteName('a.enabled')." = 1");

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

            $session_list = $results;


            foreach($session_list as $session){
                $options[] = JHTML::_( 'select.option', $session->spsoccer_session_id, $session->title . '(' . $session->tournament_name .' )' );

                //print_r($tournament);
            }

            return JHTML::_('select.genericlist', $options, $this->name, '', 'value', 'text', $this->value);
        }
    }
