diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index c2b29ef90af..01430ba7212 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -43,7 +43,7 @@ repos: - id: end-of-file-fixer # Check that there are no completely merged file conflicts - id: check-merge-conflict - stages: [pre-commit, pre-rebase, pre-commit, pre-merge-commit] + stages: [commit, pre-rebase, pre-commit, pre-merge-commit] # Check that files with shebangs have the executable bit set (in git) - id: check-executables-have-shebangs # Check that shell files are executables @@ -252,7 +252,7 @@ repos: rev: 3.1.0 hooks: - id: sqlfluff-lint - stages: [pre-commit, manual] # manual needed for ci + stages: [commit, manual] # manual needed for ci exclude: (?x)^ (dev/initdemo/mysqldump_.*\.sql |htdocs/core/menus/init_menu_auguria\.sql diff --git a/htdocs/core/class/extrafields.class.php b/htdocs/core/class/extrafields.class.php index be615ae0316..89cebe8a7c5 100644 --- a/htdocs/core/class/extrafields.class.php +++ b/htdocs/core/class/extrafields.class.php @@ -12,6 +12,7 @@ * Copyright (C) 2018-2024 Frédéric France * Copyright (C) 2022 Antonin MARCHAL * Copyright (C) 2024 MDW + * Copyright (C) 2024 Benoît PASCAL * * 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 @@ class ExtraFields * * @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 @@ class ExtraFields * * @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 @@ class ExtraFields * 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 @@ class ExtraFields } elseif ($type == 'link') { $typedb = 'int'; $lengthdb = '11'; + } elseif ($type == 'duration') { + $typedb = 'int'; + $lengthdb = '11'; } elseif ($type == 'point') { $typedb = 'point'; $lengthdb = ''; @@ -634,7 +639,7 @@ class ExtraFields * * @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 @@ class ExtraFields } elseif ($type == 'link') { $typedb = 'int'; $lengthdb = '11'; + } elseif ($type == 'duration') { + $typedb = 'int'; + $lengthdb = '11'; } elseif ($type == 'point') { $typedb = 'point'; $lengthdb = ''; @@ -1283,6 +1291,9 @@ class ExtraFields } $out = ' '; $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 @@ class ExtraFields 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 @@ class ExtraFields } 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 @@ class ExtraFields 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 @@ class ExtraFields 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 @@ class ExtraFields } 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)) { diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index fc55b2a6274..2865533aafd 100644 --- a/htdocs/core/lib/functions.lib.php +++ b/htdocs/core/lib/functions.lib.php @@ -24,6 +24,7 @@ * Copyright (C) 2024 MDW * Copyright (C) 2024 Lenin Rivas * Copyright (C) 2024 Josep Lluís Amador Teruel + * Copyright (C) 2024 Benoît PASCAL * * 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',