dolibarr 24.0.0-beta
varcharfield.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 $size = (int) $fieldInfos->size;
73 $maxLength = ''; // $size > 0 ? ' maxlength="' . $size . '"' : ''; // TODO rework, wrong method
74 $moreCss = $this->getInputCss($fieldInfos, $moreCss);
75 $moreAttrib = trim((string) $moreAttrib);
76 if (empty($moreAttrib)) $moreAttrib = ' ' . $moreAttrib;
77 $placeHolder = $fieldInfos->inputPlaceholder;
78 if (!empty($placeHolder)) $placeHolder = ' placeholder="' . dolPrintHTMLForAttribute($placeHolder) . '"';
79 $autoFocus = $fieldInfos->inputAutofocus ? ' autofocus' : '';
80 $htmlName = $keyPrefix . $key . $keySuffix;
81
82 return self::$form->inputType('text', $htmlName, (string) $value, $htmlName, $moreCss, $maxLength . $moreAttrib . $placeHolder . $autoFocus);
83 }
84
97 public function printOutputField($fieldInfos, $key, $value, $keyPrefix = '', $keySuffix = '', $moreCss = '', $moreAttrib = '')
98 {
99 return !$this->isEmptyValue($fieldInfos, $value) ? dol_htmlentitiesbr((string) $value) : '';
100 }
101
111 public function getInputCss($fieldInfos, $moreCss = '', $defaultCss = '')
112 {
113 return parent::getInputCss($fieldInfos, $moreCss, $defaultCss);
114 }
115
125 public function verifyFieldValue($fieldInfos, $key, $value)
126 {
127 return parent::verifyFieldValue($fieldInfos, $key, $value);
128 }
129
140 public function verifyPostFieldValue($fieldInfos, $key, $keyPrefix = '', $keySuffix = '')
141 {
142 return parent::verifyPostFieldValue($fieldInfos, $key, $keyPrefix, $keySuffix);
143 }
144
156 public function getPostFieldValue($fieldInfos, $key, $defaultValue = null, $keyPrefix = '', $keySuffix = '')
157 {
158 $htmlName = $keyPrefix . $key . $keySuffix;
159
160 if (GETPOSTISSET($htmlName)) {
161 $check = $key == 'lang' ? 'aZ09' : 'alphanohtml';
162 $value = GETPOST($htmlName, $check);
163 } else {
164 $value = $defaultValue;
165 }
166
167 return $value;
168 }
169
181 public function getPostSearchFieldValue($fieldInfos, $key, $defaultValue = null, $keyPrefix = '', $keySuffix = '')
182 {
183 $htmlName = $keyPrefix . $key . $keySuffix;
184
185 if (GETPOSTISSET($htmlName)) {
186 $value = GETPOST($htmlName, 'alpha');
187 } else {
188 $value = $defaultValue;
189 }
190
191 return $value;
192 }
193
203 public function sqlFilterSearchField($fieldInfos, $key, $value)
204 {
205 if (!$this->isEmptyValue($fieldInfos, $value)) {
206 $alias = $fieldInfos->sqlAlias ?? 't.';
207
208 return natural_search($alias . ($fieldInfos->nameInTable ?? $key), $value, 0);
209 }
210
211 return '';
212 }
213}
Class to common field.
isEmptyValue($fieldInfos, $value, $emptyValues=null)
Check if the value is deemed as empty.
Class to varchar field.
getPostSearchFieldValue($fieldInfos, $key, $defaultValue=null, $keyPrefix='', $keySuffix='')
Get search field value from GET/POST.
getInputCss($fieldInfos, $moreCss='', $defaultCss='')
Get input CSS.
sqlFilterSearchField($fieldInfos, $key, $value)
Get sql filter for search field.
getPostFieldValue($fieldInfos, $key, $defaultValue=null, $keyPrefix='', $keySuffix='')
Get field value from GET/POST.
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.
printInputSearchField($fieldInfos, $key, $value, $keyPrefix='', $keySuffix='', $moreCss='', $moreAttrib='')
Return HTML string to put an input search field into a page.
printInputField($fieldInfos, $key, $value, $keyPrefix='', $keySuffix='', $moreCss='', $moreAttrib='')
Return HTML string to put an input field into a page.
verifyFieldValue($fieldInfos, $key, $value)
Verify if the field value is valid.
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.
dol_htmlentitiesbr($stringtoencode, $nl2brmode=0, $pagecodefrom='UTF-8', $removelasteolbr=1)
This function is called to encode a string into a HTML string but differs from htmlentities because a...