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 CWidgetFieldMs extends CWidgetField { 23 24 /** 25 * Is selecting multiple objects or a single one? 26 * 27 * @var bool 28 */ 29 protected $multiple = true; 30 31 /** 32 * Additional filter parameters used for data selection. 33 * 34 * @var array 35 */ 36 protected $filter_parameters = []; 37 38 /** 39 * Multiselect widget field. 40 * Will create text box field with select button, that will allow to select specified resource. 41 * 42 * @param string $name Field name in form. 43 * @param string $label Label for the field in form. 44 */ 45 public function __construct($name, $label) { 46 parent::__construct($name, $label); 47 48 $this->setDefault([]); 49 } 50 51 /** 52 * Set additional validation flags. 53 * 54 * @param int $flags 55 * 56 * @return CWidgetFieldMs 57 */ 58 public function setFlags($flags) { 59 parent::setFlags($flags); 60 61 if ($flags & self::FLAG_NOT_EMPTY) { 62 $strict_validation_rules = $this->getValidationRules(); 63 self::setValidationRuleFlag($strict_validation_rules, API_NOT_EMPTY); 64 $this->setStrictValidationRules($strict_validation_rules); 65 } 66 else { 67 $this->setStrictValidationRules(null); 68 } 69 70 return $this; 71 } 72 73 /** 74 * @return CWidgetFieldMs 75 */ 76 public function setValue($value) { 77 $this->value = (array) $value; 78 79 return $this; 80 } 81 82 /** 83 * Is selecting multiple values or a single value? 84 * 85 * @return bool 86 */ 87 public function isMultiple() { 88 return $this->multiple; 89 } 90 91 /** 92 * Set field to multiple objects mode. 93 * 94 * @param bool $multiple 95 * 96 * @return CWidgetFieldMs 97 */ 98 public function setMultiple($multiple) { 99 $this->multiple = $multiple; 100 101 return $this; 102 } 103 104 /** 105 * Get additional filter parameters. 106 * 107 * @return array 108 */ 109 public function getFilterParameters() { 110 return $this->filter_parameters; 111 } 112 113 /** 114 * Set an additional filter parameter for data selection. 115 * 116 * @param string $name 117 * @param mixed $value 118 * 119 * @return CWidgetFieldMs 120 */ 121 public function setFilterParameter($name, $value) { 122 $this->filter_parameters[$name] = $value; 123 124 return $this; 125 } 126} 127