dolibarr 24.0.0-beta
durationfield.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';
25require_once DOL_DOCUMENT_ROOT . '/core/lib/date.lib.php';
26
27
32{
36 public $emptyValues = array('');
37
38
51 public function printInputSearchField($fieldInfos, $key, $value, $keyPrefix = '', $keySuffix = '', $moreCss = '', $moreAttrib = '')
52 {
53 // Todo make filter with min / max ? or same as a number ?
54 return $this->printInputField($fieldInfos, $key, $value, $keyPrefix, $keySuffix, $moreCss, $moreAttrib);
55 }
56
69 public function printInputField($fieldInfos, $key, $value, $keyPrefix = '', $keySuffix = '', $moreCss = '', $moreAttrib = '')
70 {
71 $htmlName = $keyPrefix . $key . $keySuffix;
72
73 // TODO Must also support $moreAttrib and $moreCss ?
74 return self::$form->select_duration($htmlName, (int) $value, 0, 'text', 0, 1);
75 }
76
89 public function printOutputField($fieldInfos, $key, $value, $keyPrefix = '', $keySuffix = '', $moreCss = '', $moreAttrib = '')
90 {
91 return !$this->isEmptyValue($fieldInfos, $value) ? convertSecondToTime((int) $value, 'allhourmin') : '';
92 }
93
103 public function getInputCss($fieldInfos, $moreCss = '', $defaultCss = '')
104 {
105 return parent::getInputCss($fieldInfos, $moreCss, $defaultCss);
106 }
107
117 public function verifyFieldValue($fieldInfos, $key, $value)
118 {
119 $result = parent::verifyFieldValue($fieldInfos, $key, $value);
120 if ($result && !$this->isEmptyValue($fieldInfos, $value)) {
121 if (!self::$validator->isDuration($value)) {
122 return false;
123 }
124
125 $result = true;
126 }
127
128 return $result;
129 }
130
141 public function verifyPostFieldValue($fieldInfos, $key, $keyPrefix = '', $keySuffix = '')
142 {
143 return parent::verifyPostFieldValue($fieldInfos, $key, $keyPrefix, $keySuffix);
144 }
145
157 public function getPostFieldValue($fieldInfos, $key, $defaultValue = null, $keyPrefix = '', $keySuffix = '')
158 {
159 $htmlName = $keyPrefix . $key . $keySuffix;
160
161 if (GETPOSTISSET($htmlName . 'hour') || GETPOSTISSET($htmlName . 'min')) {
162 $value_hours = GETPOSTINT($htmlName . "hour");
163 $value_minutes = GETPOSTINT($htmlName . "min");
164 $value = $value_hours * 3600 + $value_minutes * 60;
165 } else {
166 $value = $defaultValue;
167 }
168
169 return $value;
170 }
171
183 public function getPostSearchFieldValue($fieldInfos, $key, $defaultValue = null, $keyPrefix = '', $keySuffix = '')
184 {
185 return $this->getPostFieldValue($fieldInfos, $key, $defaultValue, $keyPrefix, $keySuffix);
186 }
187
197 public function sqlFilterSearchField($fieldInfos, $key, $value)
198 {
199 if (!$this->isEmptyValue($fieldInfos, $value)) {
200 $alias = $fieldInfos->sqlAlias ?? 't.';
201
202 return natural_search($alias . ($fieldInfos->nameInTable ?? $key), $value, 0);
203 }
204
205 return '';
206 }
207}
Class to common field.
isEmptyValue($fieldInfos, $value, $emptyValues=null)
Check if the value is deemed as empty.
Class to duration field.
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.
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.
sqlFilterSearchField($fieldInfos, $key, $value)
Get sql filter for search field.
getInputCss($fieldInfos, $moreCss='', $defaultCss='')
Get input CSS.
getPostSearchFieldValue($fieldInfos, $key, $defaultValue=null, $keyPrefix='', $keySuffix='')
Get search field value from GET/POST.
getPostFieldValue($fieldInfos, $key, $defaultValue=null, $keyPrefix='', $keySuffix='')
Get field value from GET/POST.
convertSecondToTime($iSecond, $format='all', $lengthOfDay=86400, $lengthOfWeek=7)
Return, in clear text, value of a number of seconds in days, hours and minutes.
Definition date.lib.php:248
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...