You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
54 lines
1.3 KiB
PHTML
54 lines
1.3 KiB
PHTML
5 years ago
|
<?php
|
||
|
|
||
|
namespace Artmark\Forms\Fields;
|
||
|
|
||
|
use Artmark\Forms\AbstractVisibleField;
|
||
|
|
||
|
/**
|
||
|
* Description of TextField
|
||
|
*
|
||
|
* @author Andrey Pokidov <pokidov@e-traffic.ru>
|
||
|
*/
|
||
|
class CheckboxField extends AbstractVisibleField
|
||
|
{
|
||
|
private $checked = false;
|
||
|
|
||
|
public function __construct($form, $name)
|
||
|
{
|
||
|
parent::__construct($form, 'checkbox', $name);
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Возвращает ранее заданное значение поля
|
||
|
* @return boolean Метод возвращает true, если поле отмечено флагом, иначе - false
|
||
|
*/
|
||
|
public function value()
|
||
|
{
|
||
|
return $this->checked;
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Устанавливает новое значение для поля
|
||
|
* @param boolean $newValue Необходимо передать true, если необходимо установить флаг, false, чтобы убрать флаг
|
||
|
* @return $this
|
||
|
*/
|
||
|
public function setValue($newValue)
|
||
|
{
|
||
|
$this->checked = !empty($newValue);
|
||
|
return $this;
|
||
|
}
|
||
|
|
||
|
public function getAssociativeAttributes()
|
||
|
{
|
||
|
$attributes = parent::getAssociativeAttributes();
|
||
|
|
||
|
$attributes['value'] = 1;
|
||
|
|
||
|
if ($this->checked) {
|
||
|
$attributes['checked'] = null;
|
||
|
}
|
||
|
|
||
|
return $attributes;
|
||
|
}
|
||
|
}
|