sss
This commit is contained in:
63
src/inputs/RadioButton.php
Normal file
63
src/inputs/RadioButton.php
Normal file
@ -0,0 +1,63 @@
|
||||
<?php
|
||||
|
||||
namespace itguild\forms\inputs;
|
||||
use itguild\forms\templates\Simple\SimpleTemplate;
|
||||
use itguild\forms\traits\CreateOption;
|
||||
use itguild\forms\traits\CreateParams;
|
||||
use itguild\forms\inputs\BaseInput;
|
||||
class RadioButton extends BaseInput
|
||||
{
|
||||
use CreateParams;
|
||||
use CreateOption;
|
||||
private $name;
|
||||
private $paramsArray;
|
||||
private $options = [];
|
||||
private $value;
|
||||
|
||||
|
||||
public function __construct(string $name, array $paramsArray = [])
|
||||
{
|
||||
$this->name = $name;
|
||||
$this->paramsArray = $paramsArray;
|
||||
$this->inputTemplate = new SimpleTemplate();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return $this
|
||||
*/
|
||||
public function create(): self
|
||||
{
|
||||
$paramsString = $this->createParams($this->paramsArray);
|
||||
$optionsString = $this->createOption($this->options, $this->value);
|
||||
$radioButton = "<input name='$this->name' type='radio' $paramsString>$optionsString";
|
||||
$label = "";
|
||||
if($this->hasLabel == true) {
|
||||
$label = "<label >$this->labelTitle</label>";
|
||||
}
|
||||
$this->html = str_replace('{input}', $radioButton, $this->inputTemplate->getInputTemplate());
|
||||
$this->html = str_replace('{label}', $label, $this->html);
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $name
|
||||
* @param array $paramsArray
|
||||
* @return void
|
||||
*/
|
||||
public static function build(string $name, array $paramsArray = []): void
|
||||
{
|
||||
$radioButton = new self($name, $paramsArray);
|
||||
$radioButton->create()->render();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param $options
|
||||
* @return $this
|
||||
*/
|
||||
public function setOptions($options)
|
||||
{
|
||||
$this->options = array_merge($options, $this->options);
|
||||
return $this;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user