<?php

/**
 * @package SP Page Builder
 * @author JoomShaper http://www.joomshaper.com
 * @copyright Copyright (c) 2010 - 2018 JoomShaper
 * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPLv2 or later
 */
//no direct accees
defined('_JEXEC') or die('resticted aceess');

// is enable or installed sp soccer
$db = JFactory::getDbo();
$db->setQuery("SELECT enabled FROM #__extensions WHERE element = 'com_spsoccer'");
$is_enabled = $db->loadResult();

if ($is_enabled) {

    if (!function_exists('getSoccerPlayers')) {

        function getSoccerPlayers() {

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

            $query
                    ->select(array('spsoccer_player_id', 'title'))
                    ->from($db->quoteName('#__spsoccer_players'))
                    ->where($db->quoteName('enabled') . ' = ' . $db->quote(1))
                    ->order($db->quoteName('ordering') . ' DESC');

            $db->setQuery($query);

            $player_lists = $db->loadObjectList();

            //print_r($polls);
            if (!empty($player_lists)) {
                foreach ($player_lists as $key => $player_list) {
                    $players[$player_list->spsoccer_player_id] = $player_list->title;
                }
            } else {
                $players['0'] = 'No Upcoming match found';
            }


            return $players;
        }

    }

    SpAddonsConfig::addonConfig(
            array(
                'type' => 'content',
                'addon_name' => 'sp_top_player',
                'category' => 'Calcio',
                'title' => JText::_('COM_SPPAGEBUILDER_ADDON_TOP_PLYER'),
                'desc' => JText::_('COM_SPPAGEBUILDER_ADDON_TOP_PLYER_DESC'),
                'attr' => array(
                    'general' => array(
                        'admin_label'=>array(
                            'type'=>'text',
                            'title'=>JText::_('COM_SPPAGEBUILDER_ADDON_ADMIN_LABEL'),
                            'desc'=>JText::_('COM_SPPAGEBUILDER_ADDON_ADMIN_LABEL_DESC'),
                            'std'=> ''
                        ),
                        //repeatable
                        'sp_top_player_item' => array(
                            'title' => JText::_('COM_SPPAGEBUILDER_ADDON_REPEATABLE_ITEMS'),
                            'attr' => array(
                                'title' => array(
                                    'type' => 'text',
                                    'title' => JText::_('COM_SPPAGEBUILDER_ADDON_TOP_PLYER_ITEM_TITLE'),
                                    'desc' => JText::_('COM_SPPAGEBUILDER_ADDON_TOP_PLYER_ITEM_TITLE_DESC'),
                                    'std' => 'Player title',
                                ),
                                'player' => array(
                                    'type' => 'select',
                                    'title' => JText::_('Select players'),
                                    'desc' => JText::_('Players comes from SP Soccer'),
                                    'values' => getSoccerPlayers(),
                                    'std' => ''
                                ),
                                'team_title' => array(
                                    'type' => 'text',
                                    'title' => JText::_('COM_SPPAGEBUILDER_ADDON_TEAM_TITLE'),
                                    'desc' => JText::_('COM_SPPAGEBUILDER_ADDON_TEAM_TITLE_DESC'),
                                    'std' => 'Bercelona'
                                ),
                                'team_logo' => array(
                                    'type' => 'media',
                                    'title' => JText::_('COM_SPPAGEBUILDER_ADDON_TEAM_LOGO'),
                                    'desc' => JText::_('COM_SPPAGEBUILDER_ADDON_TEAM_LOGO_DESC'),
                                    'std' => 'https://sppagebuilder.com/addons/clients/client1.png'
                                ),
                            )
                        ),
                        'class' => array(
                            'type' => 'text',
                            'title' => JText::_('COM_SPPAGEBUILDER_ADDON_CLASS'),
                            'desc' => JText::_('COM_SPPAGEBUILDER_ADDON_CLASS_DESC'),
                            'std' => ''
                        ),
                    )
                )
            )
    );
}