1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109
|
<?php
/*
** Zabbix
** Copyright (C) 2001-2016 Zabbix SIA
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
**/
class CRadioButtonList extends CList {
const ORIENTATION_HORIZONTAL = 'horizontal';
const ORIENTATION_VERTICAL = 'vertical';
private $name;
private $value;
private $orientation;
private $enabled;
private $values;
private $modern;
public function __construct($name, $value) {
parent::__construct();
$this->name = $name;
$this->value = $value;
$this->orientation = self::ORIENTATION_HORIZONTAL;
$this->enabled = true;
$this->values = [];
$this->modern = false;
$this->setId(zbx_formatDomId($name));
}
public function addValue($name, $value, $id = null, $on_change = null) {
$this->values[] = [
'name' => $name,
'value' => $value,
'id' => ($id === null ? null : zbx_formatDomId($id)),
'on_change' => $on_change
];
return $this;
}
public function makeVertical() {
$this->orientation = self::ORIENTATION_VERTICAL;
return $this;
}
public function setEnabled($enabled) {
$this->enabled = $enabled;
return $this;
}
public function setModern($modern) {
$this->modern = $modern;
return $this;
}
public function toString($destroy = true) {
if ($this->modern) {
$this->addClass(ZBX_STYLE_RADIO_SEGMENTED);
}
else {
$this->addClass($this->orientation == self::ORIENTATION_HORIZONTAL
? ZBX_STYLE_LIST_HOR_CHECK_RADIO
: ZBX_STYLE_LIST_CHECK_RADIO
);
}
foreach ($this->values as $key => $value) {
if ($value['id'] === null) {
$value['id'] = zbx_formatDomId($this->name).'_'.$key;
}
$radio = (new CInput('radio', $this->name, $value['value']))
->setEnabled($this->enabled)
->onChange($value['on_change'])
->setId($value['id']);
if ($value['value'] === $this->value) {
$radio->setAttribute('checked', 'checked');
}
if ($this->modern) {
parent::addItem([$radio, new CLabel($value['name'], $value['id'])]);
}
else {
parent::addItem(new CLabel([$radio, $value['name']], $value['id']));
}
}
return parent::toString($destroy);
}
}
|