openrat-cms

OpenRat Content Management System
git clone http://git.code.weiherhei.de/openrat-cms.git
Log | Files | Refs | README

Radio.class.php (1651B)


      1 <?php
      2 
      3 namespace template_engine\components;
      4 
      5 use template_engine\components\html\FieldComponent;
      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 RadioComponent extends FieldComponent
     12 {
     13 
     14 	// Bisher nicht in Benutzung.
     15 	public $readonly = false;
     16 
     17 	public $value;
     18 
     19 	public $prefix='';
     20 
     21 	public $suffix='';
     22 
     23 	public $class = '';
     24 
     25 	public $onchange;
     26 
     27 	public $children;
     28 
     29 	public $checked;
     30 
     31 	public $label = '';
     32 
     33 
     34 
     35 	public function createElement()
     36 	{
     37 
     38 		$radio = (new CMSElement('input'))->addAttribute('type','radio');
     39 
     40 
     41 		$radio->addAttribute('name',$this->name);
     42 		if   ($this->readonly)
     43 			$radio->addAttribute('disabled','disabled');
     44 		$radio->addAttribute('value',$this->value);
     45 
     46 		$condition = '@$'.PHPBlockElement::value($this->name).'==\''.$this->value.'\'';
     47 		$radio->addConditionalAttribute('checked', $condition, 'checked');
     48 
     49 		//$radio->addAttribute('checked',Value::createExpression(ValueExpression::TYPE_DATA_VAR,$this->name));
     50 
     51 		if ( $this->readonly && $this->required ) {
     52 			$hidden = (new CMSElement('input'))->addAttribute('type','hidden')->addAttribute('name',$this->name)->addAttribute('value','1');
     53 			$radio->addChild( $hidden );
     54 		}
     55 
     56 		if   ( $this->class )
     57 			$radio->addStyleClass($this->class);
     58 
     59 		if   ( $this->label ) {
     60 			$label = new CMSElement('label');
     61 			$label->addStyleClass('form-row')->addStyleClass('form-radio');
     62 			$label->addChild( (new CMSElement('span'))->addStyleClass('form-label')->content($this->label));
     63 			$radio->asChildOf($label);
     64 			return $label;
     65 		}
     66 
     67 		return $radio;
     68     }
     69 }