-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
NEW: add duration extrafields (#31595)
* new: add duration extrafields * style: fix style * ci: fix precommit config * style: run cs fixer * ci: adapt type to fit with php-stan * ci: adapt type to fit with php-stan * ci: adapt type to fit with php-stan --------- Co-authored-by: Benoît PASCAL <[email protected]>
- Loading branch information
1 parent
9af36e2
commit ff9e2f3
Showing
3 changed files
with
33 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,6 +12,7 @@ | |
* Copyright (C) 2018-2024 Frédéric France <[email protected]> | ||
* Copyright (C) 2022 Antonin MARCHAL <[email protected]> | ||
* Copyright (C) 2024 MDW <[email protected]> | ||
* Copyright (C) 2024 Benoît PASCAL <[email protected]> | ||
* | ||
* This program is free software; you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
|
@@ -80,6 +81,7 @@ class ExtraFields | |
'double' => 'Float', | ||
'date' => 'Date', | ||
'datetime' => 'DateAndTime', | ||
'duration' => 'Duration', | ||
//'datetimegmt'=>'DateAndTimeUTC', | ||
'boolean' => 'Boolean', | ||
'price' => 'ExtrafieldPrice', | ||
|
@@ -119,7 +121,7 @@ public function __construct($db) | |
* | ||
* @param string $attrname Code of attribute | ||
* @param string $label label of attribute | ||
* @param string $type Type of attribute ('boolean','int','varchar','text','html','date','datetime','price', 'pricecy', 'phone','mail','password','url','select','checkbox','separate',...) | ||
* @param string $type Type of attribute ('boolean', 'int', 'varchar', 'text', 'html', 'date', 'datetime', 'duration', 'price', 'pricecy', 'phone', 'mail', 'password', 'url', 'select', 'checkbox', 'separate',...) | ||
* @param int $pos Position of attribute | ||
* @param string $size Size/length definition of attribute ('5', '24,8', ...). For float, it contains 2 numeric separated with a comma. | ||
* @param string $elementtype Element type. Same value than object->table_element (Example 'member', 'product', 'thirdparty', ...) | ||
|
@@ -195,7 +197,7 @@ public function addExtraField($attrname, $label, $type, $pos, $size, $elementtyp | |
* | ||
* @param string $attrname Code of attribute | ||
* @param string $label label of attribute | ||
* @param string $type Type of attribute ('boolean','int','varchar','text','html','date','datetime','price', 'pricecy', 'phone','mail','password','url','select','checkbox','separate',...) | ||
* @param string $type Type of attribute ('boolean', 'int', 'varchar', 'text', 'html', 'date', 'datetime', 'duration', 'price', 'pricecy', 'phone', 'mail', 'password', 'url', 'select', 'checkbox', 'separate',...) | ||
* @param int $pos Position of attribute | ||
* @param string $size Size/length definition of attribute ('5', '24,8', ...). For float, it contains 2 numeric separated with a comma. | ||
* @param string $elementtype Element type. Same value than object->table_element (Example 'member', 'product', 'thirdparty', ...) | ||
|
@@ -267,7 +269,7 @@ public function updateExtraField($attrname, $label, $type, $pos, $size, $element | |
* This is a private method. For public method, use addExtraField. | ||
* | ||
* @param string $attrname code of attribute | ||
* @param string $type Type of attribute ('boolean', 'int', 'varchar', 'text', 'html', 'date', 'datetime', 'price', 'pricecy', 'phone', 'mail', 'password', 'url', 'select', 'checkbox', ...) | ||
* @param string $type Type of attribute ('boolean', 'int', 'varchar', 'text', 'html', 'date', 'datetime', 'duration', 'price', 'pricecy', 'phone', 'mail', 'password', 'url', 'select', 'checkbox', ...) | ||
* @param string $length Size/length of attribute ('5', '24,8', ...) | ||
* @param string $elementtype Element type ('member', 'product', 'thirdparty', 'contact', ...) | ||
* @param int<0,1> $unique Is field unique or not | ||
|
@@ -320,6 +322,9 @@ private function create($attrname, $type = 'varchar', $length = '255', $elementt | |
} elseif ($type == 'link') { | ||
$typedb = 'int'; | ||
$lengthdb = '11'; | ||
} elseif ($type == 'duration') { | ||
$typedb = 'int'; | ||
$lengthdb = '11'; | ||
} elseif ($type == 'point') { | ||
$typedb = 'point'; | ||
$lengthdb = ''; | ||
|
@@ -634,7 +639,7 @@ private function delete_label($attrname, $elementtype = '') | |
* | ||
* @param string $attrname Name of attribute | ||
* @param string $label Label of attribute | ||
* @param string $type Type of attribute ('boolean', 'int', 'varchar', 'text', 'html', 'date', 'datetime','price','phone','mail','password','url','select','checkbox', ...) | ||
* @param string $type Type of attribute ('boolean', 'int', 'varchar', 'text', 'html', 'date', 'datetime', 'duration', 'price', 'phone', 'mail', 'password', 'url', 'select', 'checkbox', ...) | ||
* @param string $length Size/length of attribute ('5', '24,8', ...) | ||
* @param string $elementtype Element type ('member', 'product', 'thirdparty', 'contact', ...) | ||
* @param int<0,1> $unique Is field unique or not | ||
|
@@ -703,6 +708,9 @@ public function update($attrname, $label, $type, $length, $elementtype, $unique | |
} elseif ($type == 'link') { | ||
$typedb = 'int'; | ||
$lengthdb = '11'; | ||
} elseif ($type == 'duration') { | ||
$typedb = 'int'; | ||
$lengthdb = '11'; | ||
} elseif ($type == 'point') { | ||
$typedb = 'point'; | ||
$lengthdb = ''; | ||
|
@@ -1283,6 +1291,9 @@ public function showInputField($key, $value, $moreparam = '', $keysuffix = '', $ | |
} | ||
$out = '<input type="text" class="flat '.$morecss.' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" value="'.$value.'" '.($moreparam ? $moreparam : '').'> '; | ||
$out .= $form->selectCurrency($currency, $keyprefix.$key.$keysuffix.'currency_id'); | ||
} elseif ($type == 'duration') { | ||
$value = intval($value); | ||
$out = $form->select_duration($keyprefix . $key, $value, 0, 'text', 0, 1); | ||
} elseif ($type == 'double') { | ||
if (!empty($value)) { // $value in memory is a php numeric, we format it into user number format. | ||
$value = price($value); | ||
|
@@ -1990,6 +2001,12 @@ public function showOutputField($key, $value, $moreparam = '', $extrafieldsobjec | |
if ($value !== '') { | ||
$value = dol_print_date($value, 'dayhour', 'tzuserrel'); | ||
} | ||
} elseif ($type == 'duration') { | ||
$showsize = 10; | ||
if ($value !== '') { | ||
$value = intval($value); | ||
$value = convertSecondToTime($value); | ||
} | ||
} elseif ($type == 'datetimegmt') { | ||
$showsize = 19; | ||
if ($value !== '') { | ||
|
@@ -2290,7 +2307,7 @@ public function showOutputField($key, $value, $moreparam = '', $extrafieldsobjec | |
} else { | ||
$value = ''; | ||
} | ||
} elseif (in_array($type, ['multipts','linestrg', 'polygon'])) { | ||
} elseif (in_array($type, ['multipts', 'linestrg', 'polygon'])) { | ||
if (!empty($value)) { | ||
require_once DOL_DOCUMENT_ROOT.'/core/class/dolgeophp.class.php'; | ||
$dolgeophp = new DolGeoPHP($this->db); | ||
|
@@ -2393,7 +2410,7 @@ public function getAlignFlag($key, $extrafieldsobjectkey = '') | |
|
||
if (in_array($type, array('date', 'datetime', 'datetimegmt',))) { | ||
$cssstring = "center"; | ||
} elseif (in_array($type, array('int', 'price', 'double'))) { | ||
} elseif (in_array($type, array('int', 'price', 'double', 'duration'))) { | ||
$cssstring = "right"; | ||
} elseif (in_array($type, array('boolean', 'radio', 'checkbox', 'ip', 'icon'))) { | ||
$cssstring = "center"; | ||
|
@@ -2537,7 +2554,7 @@ public function setOptionalsFromPost($extralabels, &$object, $onlykey = '', $tod | |
continue; | ||
} | ||
|
||
if (!empty($onlykey) && $onlykey == '@GETPOSTISSET' && !GETPOSTISSET('options_'.$key) && (! in_array($this->attributes[$object->table_element]['type'][$key], array('boolean', 'checkbox', 'chkbxlst', 'point', 'multipts', 'linestrg', 'polygon')))) { | ||
if (!empty($onlykey) && $onlykey == '@GETPOSTISSET' && !GETPOSTISSET('options_'.$key) && (! in_array($this->attributes[$object->table_element]['type'][$key], array('boolean', 'checkbox', 'chkbxlst', 'point', 'multipts', 'linestrg', 'polygon', 'duration')))) { | ||
//when unticking boolean field, it's not set in POST | ||
continue; | ||
} | ||
|
@@ -2609,6 +2626,10 @@ public function setOptionalsFromPost($extralabels, &$object, $onlykey = '', $tod | |
} elseif (in_array($key_type, array('datetimegmt'))) { | ||
// Clean parameters | ||
$value_key = dol_mktime(GETPOSTINT("options_".$key."hour"), GETPOSTINT("options_".$key."min"), GETPOSTINT("options_".$key."sec"), GETPOSTINT("options_".$key."month"), GETPOSTINT("options_".$key."day"), GETPOSTINT("options_".$key."year"), 'gmt'); | ||
} elseif (in_array($key_type, array('duration'))) { | ||
$value_hours = GETPOSTINT("options_" . $key . "hour"); | ||
$value_minutes = GETPOSTINT("options_" . $key . "minute"); | ||
$value_key = $value_hours * 3600 + $value_minutes * 60; | ||
} elseif (in_array($key_type, array('checkbox', 'chkbxlst'))) { | ||
$value_arr = GETPOST("options_".$key, 'array'); // check if an array | ||
if (!empty($value_arr)) { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,6 +24,7 @@ | |
* Copyright (C) 2024 MDW <[email protected]> | ||
* Copyright (C) 2024 Lenin Rivas <[email protected]> | ||
* Copyright (C) 2024 Josep Lluís Amador Teruel <[email protected]> | ||
* Copyright (C) 2024 Benoît PASCAL <[email protected]> | ||
* | ||
* This program is free software; you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
|
@@ -4921,6 +4922,7 @@ function getPictoForType($key, $morecss = '') | |
'boolean' => 'check-square', | ||
'date' => 'calendar', | ||
'datetime' => 'calendar', | ||
'duration' => 'hourglass', | ||
'phone' => 'phone', | ||
'mail' => 'email', | ||
'url' => 'url', | ||
|
@@ -5060,7 +5062,7 @@ function img_picto($titlealt, $picto, $moreatt = '', $pictoisfullpath = 0, $srco | |
'1downarrow', '1uparrow', '1leftarrow', '1rightarrow', '1uparrow_selected', '1downarrow_selected', '1leftarrow_selected', '1rightarrow_selected', | ||
'accountancy', 'accounting_account', 'account', 'accountline', 'action', 'add', 'address', 'ai', 'angle-double-down', 'angle-double-up', 'asset', | ||
'back', 'bank_account', 'barcode', 'bank', 'bell', 'bill', 'billa', 'billr', 'billd', 'birthday-cake', 'bom', 'bookcal', 'bookmark', 'briefcase-medical', 'bug', 'building', | ||
'card', 'calendarlist', 'calendar', 'calendarmonth', 'calendarweek', 'calendarday', 'calendarperuser', 'calendarpertype', | ||
'card', 'calendarlist', 'calendar', 'calendarmonth', 'calendarweek', 'calendarday', 'calendarperuser', 'calendarpertype', 'hourglass', | ||
'cash-register', 'category', 'chart', 'check', 'clock', 'clone', 'close_title', 'code', 'cog', 'collab', 'company', 'contact', 'country', 'contract', 'conversation', 'cron', 'cross', 'cubes', | ||
'check-circle', 'check-square', 'circle', 'stop-circle', 'currency', 'multicurrency', | ||
'chevron-left', 'chevron-right', 'chevron-down', 'chevron-top', | ||
|