dolibarr 24.0.0-beta
intfield.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
30class IntField extends CommonField
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 $size = (int) $fieldInfos->size;
73 $moreCss = $this->getInputCss($fieldInfos, $moreCss);
74 $maxLength = ''; // $size > 0 ? ' maxlength="' . $size . '"' : ''; // TODO rework, wrong method
75 $autoFocus = $fieldInfos->inputAutofocus ? ' autofocus' : '';
76 $htmlName = $keyPrefix . $key . $keySuffix;
77 $value = !is_null($value) && $value !== '' ? (int) $value : '';
78
79 return self::$form->inputType('text', $htmlName, (string) $value, $htmlName, $moreCss, $maxLength . $moreAttrib . $autoFocus);
80 }
81
94 public function printOutputField($fieldInfos, $key, $value, $keyPrefix = '', $keySuffix = '', $moreCss = '', $moreAttrib = '')
95 {
96 return !$this->isEmptyValue($fieldInfos, $value) ? (string) $value : '';
97 }
98
108 public function getInputCss($fieldInfos, $moreCss = '', $defaultCss = '')
109 {
110 return parent::getInputCss($fieldInfos, $moreCss, $defaultCss ? $defaultCss : 'maxwidth75');
111 }
112
122 public function verifyFieldValue($fieldInfos, $key, $value)
123 {
124 $result = parent::verifyFieldValue($fieldInfos, $key, $value);
125 if ($result && !$this->isEmptyValue($fieldInfos, $value)) {
126 if (!self::$validator->isNumeric($value)) {
127 return false;
128 }
129
130 $result = true;
131 }
132
133 return $result;
134 }
135
146 public function verifyPostFieldValue($fieldInfos, $key, $keyPrefix = '', $keySuffix = '')
147 {
148 return parent::verifyPostFieldValue($fieldInfos, $key, $keyPrefix, $keySuffix);
149 }
150
162 public function getPostFieldValue($fieldInfos, $key, $defaultValue = null, $keyPrefix = '', $keySuffix = '')
163 {
164 $htmlName = $keyPrefix . $key . $keySuffix;
165
166 if (GETPOSTISSET($htmlName)) {
167 $value = (int) price2num(GETPOSTINT($htmlName));
168 } else {
169 $value = $defaultValue;
170 }
171
172 return $value;
173 }
174
186 public function getPostSearchFieldValue($fieldInfos, $key, $defaultValue = null, $keyPrefix = '', $keySuffix = '')
187 {
188 $htmlName = $keyPrefix . $key . $keySuffix;
189
190 if (GETPOSTISSET($htmlName)) {
191 $value = GETPOST($htmlName, 'alpha');
192 } else {
193 $value = $defaultValue;
194 }
195
196 return $value;
197 }
198
208 public function sqlFilterSearchField($fieldInfos, $key, $value)
209 {
210 if (!$this->isEmptyValue($fieldInfos, $value)) {
211 $alias = $fieldInfos->sqlAlias ?? 't.';
212
213 return natural_search($alias . ($fieldInfos->nameInTable ?? $key), $value, 1);
214 }
215
216 return '';
217 }
218}
Class to common field.
isEmptyValue($fieldInfos, $value, $emptyValues=null)
Check if the value is deemed as empty.
Class to int field.
printInputSearchField($fieldInfos, $key, $value, $keyPrefix='', $keySuffix='', $moreCss='', $moreAttrib='')
Return HTML string to put an input search field into a page.
getInputCss($fieldInfos, $moreCss='', $defaultCss='')
Get input CSS.
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.
verifyPostFieldValue($fieldInfos, $key, $keyPrefix='', $keySuffix='')
Verify if the field value from GET/POST is valid.
printOutputField($fieldInfos, $key, $value, $keyPrefix='', $keySuffix='', $moreCss='', $moreAttrib='')
Return HTML string to show a field into a page.
verifyFieldValue($fieldInfos, $key, $value)
Verify if the field value is valid.
getPostFieldValue($fieldInfos, $key, $defaultValue=null, $keyPrefix='', $keySuffix='')
Get field value from GET/POST.
getPostSearchFieldValue($fieldInfos, $key, $defaultValue=null, $keyPrefix='', $keySuffix='')
Get search field value from GET/POST.
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
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...
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
print $langs trans("Show") . '< td style="' . $timeColor . '" align="center"> s</td > badge status0 badge status4 badge status3 Error badge status8< td align="center">< span class="badge ' . $badge . '"></span ></td >< td align="center">< a href="#" class="button button-small" onclick="openLogModal(this)" data-req="' . dol_escape_htmltag($reqSafe) . '" data-res="' . dol_escape_htmltag($resSafe) . '" data-err="' . dol_escape_htmltag($errSafe) . '">< span class="fa fa-search-plus"></span ></a ></td ></tr >< tr >< td colspan="' . $colspan . '" class="opacitymedium"></td ></tr ></table ></div ></form > logModal none logModal none s a JSON string
buildzip.php