php-censor/src/B8Framework/Form/Element/Checkbox.php
2017-01-14 16:12:53 +07:00

47 lines
994 B
PHP

<?php
namespace b8\Form\Element;
use b8\View, b8\Form\Input;
class Checkbox extends Input
{
protected $_checked;
protected $_checkedValue;
public function getCheckedValue()
{
return $this->_checkedValue;
}
public function setCheckedValue($value)
{
$this->_checkedValue = $value;
}
public function setValue($value)
{
if (is_bool($value) && $value === true) {
$this->_value = $this->getCheckedValue();
$this->_checked = true;
return;
}
if ($value == $this->getCheckedValue()) {
$this->_value = $this->getCheckedValue();
$this->_checked = true;
return;
}
$this->_value = $value;
$this->_checked = false;
}
public function onPreRender(View &$view)
{
parent::onPreRender($view);
$view->checkedValue = $this->getCheckedValue();
$view->checked = $this->_checked;
}
}