dolibarr 24.0.0-beta
starsfield.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('', -1);
36
37
50 public function printInputSearchField($fieldInfos, $key, $value, $keyPrefix = '', $keySuffix = '', $moreCss = '', $moreAttrib = '')
51 {
52 global $langs;
53
54 $size = (int) $fieldInfos->size;
55 $moreCss = $this->getInputCss($fieldInfos, $moreCss);
56 $moreAttrib = trim((string) $moreAttrib);
57 if (empty($moreAttrib)) $moreAttrib = ' ' . $moreAttrib;
58 $value = (int) $value;
59 $htmlName = $keyPrefix . $key . $keySuffix;
60
61 $options = array();
62 for ($i = 0; $i <= $size; $i++) {
63 // TODO ajouter la tranduction
64 $options[$i] = $langs->trans("StarsFieldValue", $i);
65 }
66
67 return self::$form->selectarray($htmlName, $options, $value, 1, 0, 0, $moreAttrib, 0, 0, 0, '', $moreCss);
68 }
69
82 public function printInputField($fieldInfos, $key, $value, $keyPrefix = '', $keySuffix = '', $moreCss = '', $moreAttrib = '')
83 {
84 $size = (int) $fieldInfos->size;
85 $moreCss = $this->getInputCss($fieldInfos, $moreCss);
86 $moreAttrib = trim((string) $moreAttrib);
87 if (empty($moreAttrib)) $moreAttrib = ' ' . $moreAttrib;
88 $autoFocus = $fieldInfos->inputAutofocus ? ' autofocus' : '';
89 $value = (int) $value;
90 $htmlName = $keyPrefix . $key . $keySuffix;
91
92 return self::$form->inputStars($htmlName, $size, $value, $moreCss, $moreAttrib . $autoFocus);
93 }
94
107 public function printOutputField($fieldInfos, $key, $value, $keyPrefix = '', $keySuffix = '', $moreCss = '', $moreAttrib = '')
108 {
109 $size = (int) $fieldInfos->size;
110 $value = (int) $value;
111
112 return self::$form->outputStars($size, $value);
113 }
114
124 public function getInputCss($fieldInfos, $moreCss = '', $defaultCss = '')
125 {
126 return parent::getInputCss($fieldInfos, $moreCss, $defaultCss);
127 }
128
138 public function verifyFieldValue($fieldInfos, $key, $value)
139 {
140 $fieldInfos->minValue = 0;
141 $fieldInfos->maxValue = (int) $fieldInfos->size;
142
143 $result = parent::verifyFieldValue($fieldInfos, $key, $value);
144 if ($result && !$this->isEmptyValue($fieldInfos, $value)) {
145 if (!self::$validator->isNumeric($value)) {
146 return false;
147 }
148
149 $result = true;
150 }
151
152 return $result;
153 }
154
165 public function verifyPostFieldValue($fieldInfos, $key, $keyPrefix = '', $keySuffix = '')
166 {
167 $htmlName = $keyPrefix . $key . $keySuffix;
168
169 return $this->verifyFieldValue($fieldInfos, $key, GETPOST($htmlName, 'restricthtml'));
170 }
171
183 public function getPostFieldValue($fieldInfos, $key, $defaultValue = null, $keyPrefix = '', $keySuffix = '')
184 {
185 $htmlName = $keyPrefix . $key . $keySuffix;
186
187 if (GETPOSTISSET($htmlName)) {
188 $value = GETPOSTINT($htmlName);
189 } else {
190 $value = $defaultValue;
191 }
192
193 return $value;
194 }
195
207 public function getPostSearchFieldValue($fieldInfos, $key, $defaultValue = null, $keyPrefix = '', $keySuffix = '')
208 {
209 $htmlName = $keyPrefix . $key . $keySuffix;
210
211 if (GETPOSTISSET($htmlName)) {
212 $value = GETPOSTINT($htmlName);
213 } else {
214 $value = $defaultValue;
215 }
216
217 return $value;
218 }
219
229 public function sqlFilterSearchField($fieldInfos, $key, $value)
230 {
231 if (!$this->isEmptyValue($fieldInfos, $value)) {
232 $alias = $fieldInfos->sqlAlias ?? 't.';
233 $value = (int) $value;
234
235 if ($value >= 0) {
236 return natural_search($alias . ($fieldInfos->nameInTable ?? $key), (string) $value, 1);
237 }
238 }
239
240 return '';
241 }
242}
Class to common field.
isEmptyValue($fieldInfos, $value, $emptyValues=null)
Check if the value is deemed as empty.
Class to stars field.
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.
verifyPostFieldValue($fieldInfos, $key, $keyPrefix='', $keySuffix='')
Verify if the field value from GET/POST is valid.
verifyFieldValue($fieldInfos, $key, $value)
Verify if the field value is valid.
sqlFilterSearchField($fieldInfos, $key, $value)
Get sql filter for search field.
printOutputField($fieldInfos, $key, $value, $keyPrefix='', $keySuffix='', $moreCss='', $moreAttrib='')
Return HTML string to show a field into a page.
getInputCss($fieldInfos, $moreCss='', $defaultCss='')
Get input CSS.
getPostFieldValue($fieldInfos, $key, $defaultValue=null, $keyPrefix='', $keySuffix='')
Get field value from GET/POST.
printInputField($fieldInfos, $key, $value, $keyPrefix='', $keySuffix='', $moreCss='', $moreAttrib='')
Return HTML string to put an input field into a page.
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
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.