<?php
/**
 * RadioButtonList
 * @date 13.07.2006
 * @name RadioButtonList
 * @author Margo Poolak <margo 'dot' poolak 'at' mail 'dot' ee>
 * @copyright Copyright &copy;2006 Margo Poolak. All Rights Reserved.
 * @version 2.0
 * @package System.Web.UI.HtmlControls
 * @category 
 * 
 * Generates the html input fields text, password, checkbox, radio etc.
 *
 */
class RadioButtonList extends HtmlControl
{
	protected $name;
	protected $items;
	protected $selectedValue;
	/*
	*
	*/	
	function __construct($name = '')
	{
		if(isset($name))
		{
			$this->setName($name);
		}
	}
	/*
	* Overrides the THtmlControl setName() method
	*/	
	function setName($name)
	{
		$this->name = $name;
	}
	/*
	*
	*/	
	function setSelectedValue($value)
	{
		$this->selectedValue = $value;
	}
	/*
	* Sets new item value and text init
	*/
	function setItem($value,$text='')
	{
		
		if(is_array($value))
		{
			foreach($value as $v=>$k)
			{
				$this->items[] = array('value'=>$v,'text'=>$k);
			}
		}
		else
		{
			$this->items[] = array('text'=>$text,'value'=>$value);
		}
	}
	/*
	*
	*/	
	function render()
	{
		$html = '';
		foreach($this->items as $item)
		{
			$radioButton = new THtmlInput('radio');
			$radioButton->setName($this->name);			
			if($item['value'] == $this->selectedValue)
				$radioButton->setSelected();
			$radioButton->setText($item['value']);
			$html.= '<label>'.$radioButton->render().utf8_encode($item['text']).'</label>';
		}
		return $html;
	}
}
?>