<?php
/*
 *
 * @package		ARI Framework
 * @author		ARI Soft
 * @copyright	Copyright (c) 2011 www.ari-soft.com. All rights reserved
 * @license		GNU/GPL (http://www.gnu.org/copyleft/gpl.html)
 * 
 */

defined('_JEXEC') or die ('Restricted access');

require_once JPATH_ADMINISTRATOR . '/components/com_arismartcontent/kernel/class.AriKernel.php';
require_once JPATH_ADMINISTRATOR . '/components/com_arismartcontent/defines.php';
require_once JPATH_ADMINISTRATOR . '/components/com_arismartcontent/models/providersettings.php';

AriKernel::import('Application.ARISmartContent.Utils.Helper');
AriKernel::import('Data.DataFilter');
AriKernel::import('Xml.XmlHelper');

class JElementProvidersettings extends JElement
{
	var	$_name = 'Providersettings';
	
	function fetchElement($name, $value, &$node, $control_name)
	{
		$model =& AriModel::getInstance('Providersettings', 'AriSmartContentModel');

		$filter = array();
		$filter = new AriDataFilter(
			array(
				'sortField' => 'Name', 
				'dir' => ARI_DATAFILTER_SORT_ASC,
				'filter' => $filter
			)
		);
		$providerGroup = AriXmlHelper::getAttribute($node, 'provider_group');
		$disableZeroRecords = (bool)AriXmlHelper::getAttribute($node, 'disable_zero_records');

		$itemList = $model->getSettingsList($providerGroup, $filter);
		
		$output = '';
		if ($disableZeroRecords && count($itemList) == 0)
		{
			$zeroRecordsLbl = JText::_(AriXmlHelper::getAttribute($node, 'zero_records_label'));
			$output = $zeroRecordsLbl;
		}
		else
		{
			$noneLabel = AriXmlHelper::getAttribute($node, 'none_label');
			if ($noneLabel)
			{
				$emptyItem = new stdClass();
				$emptyItem->Id = 0;
				$emptyItem->Name = JText::_($noneLabel);
				array_unshift($itemList, $emptyItem);
			}

			$output = JHTML::_(
				'select.genericlist', 
				$itemList, 
				$control_name . '[' . $name . ']', 
				'class="inputbox"', 
				'Id', 
				'Name', 
				$value,
				$control_name . $name);
		}

		return $output;
	}
}