Radiobox.class.php (1230B)
1 <?php 2 3 namespace template_engine\components; 4 5 use template_engine\components\html\Component; 6 use template_engine\element\CMSElement; 7 use template_engine\element\PHPBlockElement; 8 use template_engine\element\Value; 9 use template_engine\element\ValueExpression; 10 11 class RadioboxComponent extends Component 12 { 13 14 public $list; 15 16 public $name; 17 18 public $default; 19 20 /** 21 * @deprecated 22 */ 23 public $onchange; 24 25 public $title; 26 27 public $class; 28 29 30 public function createElement() 31 { 32 $radiobox = new PHPBlockElement(); 33 34 $radiobox->beforeBlock = 'foreach( $'.$this->list.' as $_key=>$_value)'; 35 36 if ( $this->default ) 37 $value = $this->default; 38 else 39 $value = '$'.$this->name; 40 41 $label = (new CMSElement('label'))->asChildOf( $radiobox ); 42 43 (new CMSElement('input')) 44 ->addAttribute('type','radio')->addAttribute('name',$this->name) 45 ->addAttribute('value',Value::createExpression(ValueExpression::TYPE_DATA_VAR,'_key')) 46 ->addConditionalAttribute('checked','$_key=='.$value,'checked') 47 ->asChildOf($label); 48 49 (new CMSElement('span')) 50 ->content( Value::createExpression(ValueExpression::TYPE_DATA_VAR,'_value')) 51 ->asChildOf( $label ); 52 (new CMSElement('br')) 53 ->asChildOf( $radiobox ); 54 55 return $radiobox; 56 } 57 }