Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
select.php
1<?php
3
4use \Bitrix\Main\Localization\Loc;
5
6Loc::loadMessages(__FILE__);
7
9{
14 protected $options = array();
15
20 protected $multiple = false;
21
27 public function __construct($code, array $params = array())
28 {
29 $this->code = mb_strtoupper($code);
30 $this->value = null;
31 $this->default = isset($params['default']) ? $params['default'] : null;
32 $this->id = isset($params['id']) ? $params['id'] : '';
33 $this->title = isset($params['title']) ? $params['title'] : '';
34 $this->multiple = isset($params['multiple']) && $params['multiple'];
35 $this->help = isset($params['help']) ? $params['help'] : '';
36 $this->htmlHelp = isset($params['htmlHelp']) ? $params['htmlHelp'] : '';
37 $this->options = isset($params['options']) ? (array)$params['options'] : array();
38 }
39
44 public function isEmptyValue()
45 {
46 return $this->value === '' ||
47 $this->value === 0;
48 }
49
54 public function isMulti()
55 {
56 return $this->multiple;
57 }
58
67 public function viewForm(array $params = array())
68 {
69 ?>
70 <select <?php
71 ?><?= isset($params['additional']) ? $params['additional'] . ' ' : ''?><?php
72 ?><?= isset($params['id']) ? 'id="' . \htmlspecialcharsbx($params['id']) . '" ' : ''?><?php
73 ?><?= $this->multiple ? 'multiple="multiple" size="3" ' : ''?><?php
74 ?>class="<?= isset($params['class']) ? \htmlspecialcharsbx($params['class']) : ''?>" <?php
75 ?>name="<?= $this->getName($params["name_format"])?><?= $this->multiple ? '[]' : ''?>" <?php
76 ?> />
77 <?foreach ($this->options as $code => $val):?>
78 <option value="<?= \htmlspecialcharsbx($code)?>"<?php
79 echo in_array($code, (array) $this->value) ? ' selected="selected"' : '';
80 if (!$this->value && $code == $this->default)
81 {
82 echo ' selected="selected"';
83 }
84 ?>>
85 <?= \htmlspecialcharsbx($val)?>
86 </option>
87 <?php endforeach;?>
88 </select>
89 <?php
90 }
91
97 public function getName($nameFormat)
98 {
99 return \htmlspecialcharsbx(isset($nameFormat)
100 ? str_replace('#field_code#', $this->code, $nameFormat)
101 : $this->code);
102 }
103
108 public function getOptions()
109 {
110 return $this->options;
111 }
112}
__construct($code, array $params=array())
Definition select.php:27
viewForm(array $params=array())
Definition select.php:67
static loadMessages($file)
Definition loc.php:64