openrat-cms

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

Checkbox.class.php (1536B)


      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 CheckboxComponent extends Component
     12 {
     13 	
     14 	public $default = false;
     15 	public $name;
     16 	public $readonly = false;
     17 	public $required = false;
     18 	public $label;
     19 
     20 	public function createElement()
     21 	{
     22 		$checkbox = (new CMSElement('input'))->addAttribute('type','checkbox');
     23 
     24 		$checkbox->addAttribute('name',$this->name);
     25         if	( $this->readonly )
     26 			$checkbox->addAttribute('disabled','disabled');
     27 		$checkbox->addAttribute('value','1');
     28 
     29 		if   ( $this->default )
     30 			$condition = ''.PHPBlockElement::value($this->default);
     31 		else
     32 			$condition = '@$'.PHPBlockElement::value($this->name);
     33 
     34 		$checkbox->addConditionalAttribute('checked', $condition, 'checked');
     35 
     36 		if   ( $this->required )
     37 			$checkbox->addAttribute( 'required','required');
     38 
     39 		if ( $this->readonly && $this->required ) {
     40 			$hidden = (new CMSElement('input'))->addAttribute('type','hidden')->addAttribute('name',$this->name)->addAttribute('value','1');
     41 			$checkbox->addChild( $hidden );
     42 		}
     43 
     44 		if   ( $this->label ) {
     45 			$label = new CMSElement('label');
     46 			$label->addStyleClass('form-row')->addStyleClass('form-checkbox');
     47 			$label->addChild( (new CMSElement('span'))->addStyleClass('form-label')->content($this->label));
     48 			$label->addChild($checkbox);
     49 			return $label;
     50 		}
     51 
     52 		return $checkbox;
     53     }
     54 }