Merge pull request #15346 from ATM-Consulting/FIX_12.0_date_extrafields_are_not_filterable_on_lists
NEW Can filter on extrafields date on lists
This commit is contained in:
commit
238fd5accb
@ -924,15 +924,15 @@ class ExtraFields
|
|||||||
* Return HTML string to put an input field into a page
|
* Return HTML string to put an input field into a page
|
||||||
* Code very similar with showInputField of common object
|
* Code very similar with showInputField of common object
|
||||||
*
|
*
|
||||||
* @param string $key Key of attribute
|
* @param string $key Key of attribute
|
||||||
* @param string $value Preselected value to show (for date type it must be in timestamp format, for amount or price it must be a php numeric value)
|
* @param string|array $value Preselected value to show (for date type it must be in timestamp format, for amount or price it must be a php numeric value); for dates in filter mode, a range array('start'=><timestamp>, 'end'=><timestamp>) should be provided
|
||||||
* @param string $moreparam To add more parametes on html input tag
|
* @param string $moreparam To add more parameters on html input tag
|
||||||
* @param string $keysuffix Prefix string to add after name and id of field (can be used to avoid duplicate names)
|
* @param string $keysuffix Prefix string to add after name and id of field (can be used to avoid duplicate names)
|
||||||
* @param string $keyprefix Suffix string to add before name and id of field (can be used to avoid duplicate names)
|
* @param string $keyprefix Suffix string to add before name and id of field (can be used to avoid duplicate names)
|
||||||
* @param string $morecss More css (to defined size of field. Old behaviour: may also be a numeric)
|
* @param string $morecss More css (to defined size of field. Old behaviour: may also be a numeric)
|
||||||
* @param int $objectid Current object id
|
* @param int $objectid Current object id
|
||||||
* @param string $extrafieldsobjectkey If defined (for example $object->table_element), use the new method to get extrafields data
|
* @param string $extrafieldsobjectkey If defined (for example $object->table_element), use the new method to get extrafields data
|
||||||
* @param string $mode 1=Used for search filters
|
* @param string $mode 1=Used for search filters
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function showInputField($key, $value, $moreparam = '', $keysuffix = '', $keyprefix = '', $morecss = '', $objectid = 0, $extrafieldsobjectkey = '', $mode = 0)
|
public function showInputField($key, $value, $moreparam = '', $keysuffix = '', $keyprefix = '', $morecss = '', $objectid = 0, $extrafieldsobjectkey = '', $mode = 0)
|
||||||
@ -1024,8 +1024,22 @@ class ExtraFields
|
|||||||
// Do not show current date when field not required (see selectDate() method)
|
// Do not show current date when field not required (see selectDate() method)
|
||||||
if (!$required && $value == '') $value = '-1';
|
if (!$required && $value == '') $value = '-1';
|
||||||
|
|
||||||
// TODO Must also support $moreparam
|
if ($mode == 1) {
|
||||||
$out = $form->selectDate($value, $keyprefix.$key.$keysuffix, $showtime, $showtime, $required, '', 1, (($keyprefix != 'search_' && $keyprefix != 'search_options_') ? 1 : 0), 0, 1);
|
// search filter on a date extrafield shows two inputs to select a date range
|
||||||
|
$prefill = array(
|
||||||
|
'start' => isset($value['start']) ? $value['start'] : '',
|
||||||
|
'end' => isset($value['end']) ? $value['end'] : '');
|
||||||
|
$out = '<div ' . ($moreparam ? $moreparam : '') . '><div class="nowrap">'
|
||||||
|
. $langs->trans('From') . ' '
|
||||||
|
. $form->selectDate($prefill['start'], $keyprefix . $key . $keysuffix . '_start', 0, 0, 1)
|
||||||
|
. '</div><div class="nowrap">'
|
||||||
|
. $langs->trans('to') . ' '
|
||||||
|
. $form->selectDate($prefill['end'], $keyprefix . $key . $keysuffix . '_end', 0, 0, 1)
|
||||||
|
. '</div></div>';
|
||||||
|
} else {
|
||||||
|
// TODO Must also support $moreparam
|
||||||
|
$out = $form->selectDate($value, $keyprefix.$key.$keysuffix, $showtime, $showtime, $required, '', 1, (($keyprefix != 'search_' && $keyprefix != 'search_options_') ? 1 : 0), 0, 1);
|
||||||
|
}
|
||||||
} elseif (in_array($type, array('int', 'integer')))
|
} elseif (in_array($type, array('int', 'integer')))
|
||||||
{
|
{
|
||||||
$tmp = explode(',', $size);
|
$tmp = explode(',', $size);
|
||||||
@ -2104,9 +2118,28 @@ class ExtraFields
|
|||||||
|
|
||||||
if (in_array($key_type, array('date', 'datetime')))
|
if (in_array($key_type, array('date', 'datetime')))
|
||||||
{
|
{
|
||||||
if (!GETPOSTISSET($keysuffix."options_".$key.$keyprefix."year")) continue; // Value was not provided, we should not set it.
|
$dateparamname_start = $keysuffix . 'options_' . $key . $keyprefix . '_start';
|
||||||
// Clean parameters
|
$dateparamname_end = $keysuffix . 'options_' . $key . $keyprefix . '_end';
|
||||||
$value_key = dol_mktime(GETPOST($keysuffix."options_".$key.$keyprefix."hour", 'int'), GETPOST($keysuffix."options_".$key.$keyprefix."min", 'int'), 0, GETPOST($keysuffix."options_".$key.$keyprefix."month", 'int'), GETPOST($keysuffix."options_".$key.$keyprefix."day", 'int'), GETPOST($keysuffix."options_".$key.$keyprefix."year", 'int'));
|
if (GETPOSTISSET($dateparamname_start . 'year') && GETPOSTISSET($dateparamname_end . 'year')) {
|
||||||
|
// values provided as a date pair (start date + end date), each date being broken down as year, month, day, etc.
|
||||||
|
$value_key = array(
|
||||||
|
'start' => dol_mktime(
|
||||||
|
0, 0, 0,
|
||||||
|
GETPOST($dateparamname_start . 'month', 'int'),
|
||||||
|
GETPOST($dateparamname_start . 'day', 'int'),
|
||||||
|
GETPOST($dateparamname_start . 'year', 'int')),
|
||||||
|
'end' => dol_mktime(
|
||||||
|
23, 59, 59,
|
||||||
|
GETPOST($dateparamname_end . 'month', 'int'),
|
||||||
|
GETPOST($dateparamname_end . 'day', 'int'),
|
||||||
|
GETPOST($dateparamname_end . 'year', 'int'))
|
||||||
|
);
|
||||||
|
} elseif (GETPOSTISSET($keysuffix."options_".$key.$keyprefix."year")) {
|
||||||
|
// Clean parameters
|
||||||
|
$value_key = dol_mktime(GETPOST($keysuffix."options_".$key.$keyprefix."hour", 'int'), GETPOST($keysuffix."options_".$key.$keyprefix."min", 'int'), 0, GETPOST($keysuffix."options_".$key.$keyprefix."month", 'int'), GETPOST($keysuffix."options_".$key.$keyprefix."day", 'int'), GETPOST($keysuffix."options_".$key.$keyprefix."year", 'int'));
|
||||||
|
} else {
|
||||||
|
continue; // Value was not provided, we should not set it.
|
||||||
|
}
|
||||||
} elseif (in_array($key_type, array('checkbox', 'chkbxlst')))
|
} elseif (in_array($key_type, array('checkbox', 'chkbxlst')))
|
||||||
{
|
{
|
||||||
if (!GETPOSTISSET($keysuffix."options_".$key.$keyprefix)) continue; // Value was not provided, we should not set it.
|
if (!GETPOSTISSET($keysuffix."options_".$key.$keyprefix)) continue; // Value was not provided, we should not set it.
|
||||||
|
|||||||
@ -35,8 +35,8 @@ if (!empty($extrafieldsobjectkey)) // $extrafieldsobject is the $object->table_e
|
|||||||
print '<input class="flat'.($searchclass ? ' '.$searchclass : '').'" size="4" type="text" name="'.$search_options_pattern.$tmpkey.'" value="'.dol_escape_htmltag($search_array_options[$search_options_pattern.$tmpkey]).'">';
|
print '<input class="flat'.($searchclass ? ' '.$searchclass : '').'" size="4" type="text" name="'.$search_options_pattern.$tmpkey.'" value="'.dol_escape_htmltag($search_array_options[$search_options_pattern.$tmpkey]).'">';
|
||||||
} elseif (in_array($typeofextrafield, array('datetime', 'timestamp')))
|
} elseif (in_array($typeofextrafield, array('datetime', 'timestamp')))
|
||||||
{
|
{
|
||||||
// TODO
|
$morecss = '';
|
||||||
// Use showInputField in a particular manner to have input with a comparison operator, not input for a specific value date-hour-minutes
|
echo $extrafields->showInputField($key, $search_array_options[$search_options_pattern.$tmpkey], '', '', $search_options_pattern, $morecss, 0, $extrafieldsobjectkey, 1);
|
||||||
} else {
|
} else {
|
||||||
// for the type as 'checkbox', 'chkbxlst', 'sellist' we should use code instead of id (example: I declare a 'chkbxlst' to have a link with dictionnairy, I have to extend it with the 'code' instead 'rowid')
|
// for the type as 'checkbox', 'chkbxlst', 'sellist' we should use code instead of id (example: I declare a 'chkbxlst' to have a link with dictionnairy, I have to extend it with the 'code' instead 'rowid')
|
||||||
$morecss = '';
|
$morecss = '';
|
||||||
|
|||||||
@ -16,6 +16,22 @@ if (!empty($search_array_options) && is_array($search_array_options)) // $extraf
|
|||||||
{
|
{
|
||||||
$crit = $val;
|
$crit = $val;
|
||||||
$tmpkey = preg_replace('/'.$search_options_pattern.'/', '', $key);
|
$tmpkey = preg_replace('/'.$search_options_pattern.'/', '', $key);
|
||||||
|
if (is_array($val) && array_key_exists('start', $val) && array_key_exists('end', $val)) {
|
||||||
|
// date range from list filters is stored as array('start' => <timestamp>, 'end' => <timestamp>)
|
||||||
|
// start date
|
||||||
|
$param .= '&' . $search_options_pattern.$tmpkey.'_startyear=' . dol_print_date($val['start'], '%Y');
|
||||||
|
$param .= '&' . $search_options_pattern.$tmpkey.'_startmonth=' . dol_print_date($val['start'], '%m');
|
||||||
|
$param .= '&' . $search_options_pattern.$tmpkey.'_startday=' . dol_print_date($val['start'], '%d');
|
||||||
|
$param .= '&' . $search_options_pattern.$tmpkey.'_starthour=' . dol_print_date($val['start'], '%H');
|
||||||
|
$param .= '&' . $search_options_pattern.$tmpkey.'_startmin=' . dol_print_date($val['start'], '%M');
|
||||||
|
// end date
|
||||||
|
$param .= '&' . $search_options_pattern.$tmpkey.'_endyear=' . dol_print_date($val['end'], '%Y');
|
||||||
|
$param .= '&' . $search_options_pattern.$tmpkey.'_endmonth=' . dol_print_date($val['end'], '%m');
|
||||||
|
$param .= '&' . $search_options_pattern.$tmpkey.'_endday=' . dol_print_date($val['end'], '%d');
|
||||||
|
$param .= '&' . $search_options_pattern.$tmpkey.'_endhour=' . dol_print_date($val['end'], '%H');
|
||||||
|
$param .= '&' . $search_options_pattern.$tmpkey.'_endmin=' . dol_print_date($val['end'], '%M');
|
||||||
|
$val = '';
|
||||||
|
}
|
||||||
if ($val != '') $param .= '&'.$search_options_pattern.$tmpkey.'='.urlencode($val);
|
if ($val != '') $param .= '&'.$search_options_pattern.$tmpkey.'='.urlencode($val);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -23,7 +23,15 @@ if (!empty($extrafieldsobjectkey) && !empty($search_array_options) && is_array($
|
|||||||
|
|
||||||
if ($crit != '' && in_array($typ, array('date', 'datetime', 'timestamp')))
|
if ($crit != '' && in_array($typ, array('date', 'datetime', 'timestamp')))
|
||||||
{
|
{
|
||||||
$sql .= " AND ".$extrafieldsobjectprefix.$tmpkey." = '".$db->idate($crit)."'";
|
if (is_numeric($crit)) {
|
||||||
|
$sql .= " AND ".$extrafieldsobjectprefix.$tmpkey." = '".$db->idate($crit)."'";
|
||||||
|
} elseif (is_array($crit)) {
|
||||||
|
$sql .= ' AND (' . $extrafieldsobjectprefix.$tmpkey
|
||||||
|
.' BETWEEN "'
|
||||||
|
. $db->idate($crit['start'])
|
||||||
|
. '" AND "'
|
||||||
|
. $db->idate($crit['end']) . '")';
|
||||||
|
}
|
||||||
} elseif (in_array($typ, array('boolean')))
|
} elseif (in_array($typ, array('boolean')))
|
||||||
{
|
{
|
||||||
if ($crit !== '-1' && $crit !== '') {
|
if ($crit !== '-1' && $crit !== '') {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user