dolibarr 24.0.0-beta
iconfield.class.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2025 Open-Dsi <support@open-dsi.fr>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <https://www.gnu.org/licenses/>.
16 */
17
24require_once DOL_DOCUMENT_ROOT . '/core/class/fields/commonfield.class.php';
25
26
31{
35 public $emptyValues = array('');
36
37
50 public function printInputSearchField($fieldInfos, $key, $value, $keyPrefix = '', $keySuffix = '', $moreCss = '', $moreAttrib = '')
51 {
52 $moreCss = $this->getInputCss($fieldInfos, $moreCss);
53 $htmlName = $keyPrefix . $key . $keySuffix;
54
55 return self::$form->inputType('text', $htmlName, (string) $value, $htmlName, $moreCss, $moreAttrib);
56 }
57
70 public function printInputField($fieldInfos, $key, $value, $keyPrefix = '', $keySuffix = '', $moreCss = '', $moreAttrib = '')
71 {
72 $moreCss = $this->getInputCss($fieldInfos, $moreCss);
73 $moreAttrib = trim((string) $moreAttrib);
74 if (empty($moreAttrib)) $moreAttrib = ' ' . $moreAttrib;
75 $placeHolder = $fieldInfos->inputPlaceholder;
76 if (!empty($placeHolder)) $placeHolder = ' placeholder="' . dolPrintHTMLForAttribute($placeHolder) . '"';
77 $autoFocus = $fieldInfos->inputAutofocus ? ' autofocus' : '';
78 $htmlName = $keyPrefix . $key . $keySuffix;
79
80 return self::$form->inputIcon($htmlName, (string) $value, $moreCss, $moreAttrib . $placeHolder . $autoFocus);
81 }
82
95 public function printOutputField($fieldInfos, $key, $value, $keyPrefix = '', $keySuffix = '', $moreCss = '', $moreAttrib = '')
96 {
97 return !$this->isEmptyValue($fieldInfos, $value) ? self::$form->outputIcon((string) $value) : '';
98 }
99
109 public function getInputCss($fieldInfos, $moreCss = '', $defaultCss = '')
110 {
111 return parent::getInputCss($fieldInfos, $moreCss, $defaultCss);
112 }
113
123 public function verifyFieldValue($fieldInfos, $key, $value)
124 {
125 return parent::verifyFieldValue($fieldInfos, $key, $value);
126 }
127
138 public function verifyPostFieldValue($fieldInfos, $key, $keyPrefix = '', $keySuffix = '')
139 {
140 return parent::verifyPostFieldValue($fieldInfos, $key, $keyPrefix, $keySuffix);
141 }
142
154 public function getPostFieldValue($fieldInfos, $key, $defaultValue = null, $keyPrefix = '', $keySuffix = '')
155 {
156 $htmlName = $keyPrefix . $key . $keySuffix;
157
158 if (GETPOSTISSET($htmlName)) {
159 $check = $key == 'lang' ? 'aZ09' : 'alphanohtml';
160 $value = GETPOST($htmlName, $check);
161 } else {
162 $value = $defaultValue;
163 }
164
165 return $value;
166 }
167
179 public function getPostSearchFieldValue($fieldInfos, $key, $defaultValue = null, $keyPrefix = '', $keySuffix = '')
180 {
181 $htmlName = $keyPrefix . $key . $keySuffix;
182
183 if (GETPOSTISSET($htmlName)) {
184 $value = GETPOST($htmlName, 'alpha');
185 } else {
186 $value = $defaultValue;
187 }
188
189 return $value;
190 }
191
201 public function sqlFilterSearchField($fieldInfos, $key, $value)
202 {
203 if (!$this->isEmptyValue($fieldInfos, $value)) {
204 $alias = $fieldInfos->sqlAlias ?? 't.';
205
206 return natural_search($alias . ($fieldInfos->nameInTable ?? $key), $value, 0);
207 }
208
209 return '';
210 }
211}
Class to common field.
isEmptyValue($fieldInfos, $value, $emptyValues=null)
Check if the value is deemed as empty.
Class to icon field.
verifyFieldValue($fieldInfos, $key, $value)
Verify if the field value is valid.
getPostFieldValue($fieldInfos, $key, $defaultValue=null, $keyPrefix='', $keySuffix='')
Get field value from GET/POST.
getInputCss($fieldInfos, $moreCss='', $defaultCss='')
Get input CSS.
printOutputField($fieldInfos, $key, $value, $keyPrefix='', $keySuffix='', $moreCss='', $moreAttrib='')
Return HTML string to show a field into a page.
verifyPostFieldValue($fieldInfos, $key, $keyPrefix='', $keySuffix='')
Verify if the field value from GET/POST is valid.
getPostSearchFieldValue($fieldInfos, $key, $defaultValue=null, $keyPrefix='', $keySuffix='')
Get search field value from GET/POST.
printInputField($fieldInfos, $key, $value, $keyPrefix='', $keySuffix='', $moreCss='', $moreAttrib='')
Return HTML string to put an input field into a page.
sqlFilterSearchField($fieldInfos, $key, $value)
Get sql filter for search field.
printInputSearchField($fieldInfos, $key, $value, $keyPrefix='', $keySuffix='', $moreCss='', $moreAttrib='')
Return HTML string to put an input search field into a page.
natural_search($fields, $value, $mode=0, $nofirstand=0, $sqltoadd='')
Generate natural SQL search string for a criteria (this criteria can be tested on one or several fiel...
dolPrintHTMLForAttribute($s, $escapeonlyhtmltags=0, $allowothertags=array())
Return a string ready to be output into an HTML attribute (alt, title, data-html, ....
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.