dolibarr 23.0.3
doublefield.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, $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 $autoFocus = $fieldInfos->inputAutofocus ? ' autofocus' : '';
74 $value = !$this->isEmptyValue($fieldInfos, $value) ? price((double) $value) : '';
75 $htmlName = $keyPrefix . $key . $keySuffix;
76
77 return self::$form->inputType('text', $htmlName, $value, $htmlName, $moreCss, $moreAttrib . $autoFocus);
78 }
79
92 public function printOutputField($fieldInfos, $key, $value, $keyPrefix = '', $keySuffix = '', $moreCss = '', $moreAttrib = '')
93 {
94 return !$this->isEmptyValue($fieldInfos, $value) ? price((double) $value) : '';
95 }
96
106 public function getInputCss($fieldInfos, $moreCss = '', $defaultCss = '')
107 {
108 return parent::getInputCss($fieldInfos, $moreCss, $defaultCss ? $defaultCss : 'maxwidth75');
109 }
110
120 public function verifyFieldValue($fieldInfos, $key, $value)
121 {
122 $result = parent::verifyFieldValue($fieldInfos, $key, $value);
123 if ($result && !$this->isEmptyValue($fieldInfos, $value)) {
124 if (!self::$validator->isNumeric($value)) {
125 return false;
126 }
127
128 $result = true;
129 }
130
131 return $result;
132 }
133
144 public function verifyPostFieldValue($fieldInfos, $key, $keyPrefix = '', $keySuffix = '')
145 {
146 $htmlName = $keyPrefix . $key . $keySuffix;
147 $value = GETPOST($htmlName, 'restricthtml');
148 $value = str_replace(',', '.', $value);
149
150 return $this->verifyFieldValue($fieldInfos, $key, $value);
151 }
152
164 public function getPostFieldValue($fieldInfos, $key, $defaultValue = null, $keyPrefix = '', $keySuffix = '')
165 {
166 $htmlName = $keyPrefix . $key . $keySuffix;
167
168 if (GETPOSTISSET($htmlName)) {
169 $value = (double) price2num(GETPOST($htmlName, 'alphanohtml'));
170 } else {
171 $value = $defaultValue;
172 }
173
174 return $value;
175 }
176
188 public function getPostSearchFieldValue($fieldInfos, $key, $defaultValue = null, $keyPrefix = '', $keySuffix = '')
189 {
190 $htmlName = $keyPrefix . $key . $keySuffix;
191
192 if (GETPOSTISSET($htmlName)) {
193 $value = GETPOST($htmlName, 'alpha');
194 } else {
195 $value = $defaultValue;
196 }
197
198 return $value;
199 }
200
210 public function sqlFilterSearchField($fieldInfos, $key, $value)
211 {
212 if (!$this->isEmptyValue($fieldInfos, $value)) {
213 $alias = $fieldInfos->sqlAlias ?? 't.';
214
215 return natural_search($alias . ($fieldInfos->nameInTable ?? $key), $value, 1);
216 }
217
218 return '';
219 }
220}
Class to common field.
isEmptyValue($fieldInfos, $value, $emptyValues=null)
Check if the value is deemed as empty.
Class to double field.
printInputField($fieldInfos, $key, $value, $keyPrefix='', $keySuffix='', $moreCss='', $moreAttrib='')
Return HTML string to put an input field into a page.
getInputCss($fieldInfos, $moreCss='', $defaultCss='')
Get input CSS.
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.
sqlFilterSearchField($fieldInfos, $key, $value)
Get sql filter for search 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.
getPostSearchFieldValue($fieldInfos, $key, $defaultValue=null, $keyPrefix='', $keySuffix='')
Get search field value from GET/POST.
printInputSearchField($fieldInfos, $key, $value, $keyPrefix='', $keySuffix='', $moreCss='', $moreAttrib='')
Return HTML string to put an input search field into a page.
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
price($amount, $form=0, $outlangs='', $trunc=1, $rounding=-1, $forcerounding=-1, $currency_code='')
Function to format a value into an amount for visual output Function used into PDF and HTML pages.
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.