1<?php 2/* 3** Zabbix 4** Copyright (C) 2001-2021 Zabbix SIA 5** 6** This program is free software; you can redistribute it and/or modify 7** it under the terms of the GNU General Public License as published by 8** the Free Software Foundation; either version 2 of the License, or 9** (at your option) any later version. 10** 11** This program is distributed in the hope that it will be useful, 12** but WITHOUT ANY WARRANTY; without even the implied warranty of 13** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14** GNU General Public License for more details. 15** 16** You should have received a copy of the GNU General Public License 17** along with this program; if not, write to the Free Software 18** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 19**/ 20 21 22class CWidgetFieldItem extends CWidgetField { 23 24 private $multiple = true; 25 26 private $filter_parameters = [ 27 'real_hosts' => true, 28 'webitems' => true 29 ]; 30 31 /** 32 * Create widget field for Items selection. 33 * 34 * @param string $name Field name in form. 35 * @param string $label Label for the field in form. 36 */ 37 public function __construct($name, $label) { 38 parent::__construct($name, $label); 39 40 $this->setSaveType(ZBX_WIDGET_FIELD_TYPE_ITEM); 41 $this->setDefault([]); 42 } 43 44 /** 45 * Set additional flags, which can be used in configuration form. 46 * 47 * @param int $flags 48 * 49 * @return $this 50 */ 51 public function setFlags($flags) { 52 parent::setFlags($flags); 53 54 if ($flags & self::FLAG_NOT_EMPTY) { 55 $strict_validation_rules = $this->getValidationRules(); 56 self::setValidationRuleFlag($strict_validation_rules, API_NOT_EMPTY); 57 $this->setStrictValidationRules($strict_validation_rules); 58 } 59 else { 60 $this->setStrictValidationRules(null); 61 } 62 63 return $this; 64 } 65 66 public function setValue($value) { 67 $this->value = (array) $value; 68 69 return $this; 70 } 71 72 /** 73 * Is field with multiple items or single. 74 * 75 * @return bool 76 */ 77 public function isMultiple() { 78 return $this->multiple; 79 } 80 81 /** 82 * Set field to multiple items mode. 83 * 84 * @param bool $multiple 85 * 86 * @return CWidgetFieldItem 87 */ 88 public function setMultiple($multiple) { 89 $this->multiple = $multiple; 90 91 return $this; 92 } 93 94 /** 95 * @return array 96 */ 97 public function getFilterParameters() { 98 return $this->filter_parameters; 99 } 100 101 /** 102 * @param string $name 103 * @param mixed $value 104 * 105 * @return CWidgetFieldItem 106 */ 107 public function setFilterParameter($name, $value) { 108 $this->filter_parameters[$name] = $value; 109 110 return $this; 111 } 112} 113