Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NEW: add duration extrafields #31595

Merged
merged 7 commits into from
Oct 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
35 changes: 28 additions & 7 deletions htdocs/core/class/extrafields.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -80,6 +81,7 @@ class ExtraFields
'double' => 'Float',
'date' => 'Date',
'datetime' => 'DateAndTime',
'duration' => 'Duration',
//'datetimegmt'=>'DateAndTimeUTC',
'boolean' => 'Boolean',
'price' => 'ExtrafieldPrice',
Expand Down Expand Up @@ -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', ...)
Expand Down Expand Up @@ -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', ...)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 = '';
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 = '';
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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 !== '') {
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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";
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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)) {
Expand Down
4 changes: 3 additions & 1 deletion htdocs/core/lib/functions.lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -4921,6 +4922,7 @@ function getPictoForType($key, $morecss = '')
'boolean' => 'check-square',
'date' => 'calendar',
'datetime' => 'calendar',
'duration' => 'hourglass',
'phone' => 'phone',
'mail' => 'email',
'url' => 'url',
Expand Down Expand Up @@ -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',
Expand Down
Loading