<?php
/**
* HTML選択グループオジェクトクラス
*
* PHP version 5
*
* @package    core
* @author     stk2k <stk2k@sazysoft.com>
* @copyright  2008 stk2k, sazysoft
*/

class charcoal_HTMLChoiceGroupObject extends charcoal_HTMLLeafObject
{
	private $_choices;

	/*
	 *	コンストラクタ
	 */
	public function __construct( $attributes = NULL, $caption_attributes = NULL, $choices = array(), $check_status = array() )
	{
		if ( $choices ){
			foreach( $choices as $key => $value ){
				// INPUTタグ
				$attributes['value'] = $key;
				if ( is_array($check_status) && in_array($key,$check_status) ){
					$attributes['checked'] = 'checked';
				}
				else{
					unset( $attributes['checked'] );
				}
				$input = new charcoal_HTMLInputObject( $attributes );
				$this->_choices[] = $input;
				// キャプション
				$caption_attributes['id'] = $caption_attributes['id'];
				$span = new charcoal_HTMLTextObject( s($value), $caption_attributes );
				$this->_choices[] = $span;
			}
		}
	}
 
	/*
	 *	HTML出力
	 */
	public function toHTML()
	{
		$html = '';
		$choices = $this->_choices;
		if ( $choices ){
			foreach( $choices as $c ){
				$html .= $c->toHTML() . PHP_EOL;
			}
		}

		return $html;
	}
  
}
