addClass(ZBX_STYLE_CHECKBOX_LIST); $this->name = $name; $this->values = []; } /** * Set unique ID, is used as suffix for generated check-box IDs. * * @param string $uniqid Unique id string. */ public function setUniqid(string $uniqid) { $this->uniqid = $uniqid; return $this; } /** * @param array $values * * @return CCheckBoxList */ public function setChecked(array $values) { $values = array_flip($values); foreach ($this->values as &$value) { $value['checked'] = array_key_exists($value['value'], $values); } unset($value); return $this; } /** * @param array $values * * @return CCheckBoxList */ public function setOptions(array $values) { $this->values = []; foreach ($values as $value) { $this->values[] = $value + [ 'name' => '', 'value' => null, 'checked' => false ]; } return $this; } /** * Sets the width of the checkbox list. * * @return CCheckBoxList */ public function setWidth($value) { $this->addStyle('width: '.$value.'px;'); return $this; } /** * Set checkboxes enabled state. * * @param bool $enabled State of checkboxes. */ public function setEnabled($enabled) { $this->enabled = $enabled; return $this; } /* * @param bool $destroy * * @return string */ public function toString($destroy = true) { $uniqid = ($this->uniqid === '') ? '' : '_'.$this->uniqid; foreach ($this->values as $value) { $checkbox = (new CCheckBox($this->name.'['.$value['value'].']', $value['value'])) ->setLabel($value['name']) ->setChecked($value['checked']) ->setEnabled($this->enabled); $checkbox->setId($checkbox->getId().$uniqid); parent::addItem($checkbox); } return parent::toString($destroy); } }