00001 <?php 00002 00003 class MOption extends MFormControl 00004 { 00005 public $checked; 00006 public $showValues; 00007 public $type = 'circle'; 00008 public $control; // owner control of this Option 00009 00010 00011 public function __construct( $name = '', $value = null, $label = '', $checked = false, $id = false ) 00012 { 00013 parent::__construct( $name, $value, $label ); 00014 00015 $this->checked = $checked; 00016 } 00017 00018 00019 public function setChecked( $checked ) 00020 { 00021 if ( ! is_bool( $checked ) ) 00022 { 00023 throw new Exception( _M('MOption::setChecked expects an boolean as parameter!') ); 00024 } 00025 00026 $this->checked = $checked; 00027 } 00028 00029 00030 public function setControl( $control ) 00031 { 00032 $this->control = $control; 00033 } 00034 00035 00036 public function generate() 00037 { 00038 if ( is_array( $this->control->value ) ) 00039 { 00040 $found = array_search( $this->value, $this->control->value ); 00041 $checked = ( ! is_null($found) ) && ( $found !== false ); 00042 } 00043 else 00044 { 00045 $checked = ( $this->value == $this->control->value ); 00046 } 00047 00048 $this->checked = $this->checked || $checked; 00049 $this->showValues = $this->control->showValues; 00050 00051 return $this->getRender( 'option' ); 00052 } 00053 } 00054 00055 00056 class MOptionGroup extends MControl 00057 { 00058 public $label; 00059 public $name; 00060 public $options; // array of option objects 00061 public $content; 00062 00063 00064 public function __construct( $name, $label = '', $options = NULL ) 00065 { 00066 parent::__construct(); 00067 00068 $this->label = $label; 00069 $this->name = $name; 00070 $this->options = $options; 00071 } 00072 00073 00074 public function generate() 00075 { 00076 foreach ( $this->options as $o ) 00077 { 00078 $this->content .= $o->generate(); 00079 } 00080 00081 $this->setClass( 'm-combo' ); 00082 00083 return $this->getRender( 'optiongroup' ); 00084 } 00085 } 00086 00087 ?>