mirror of
https://github.com/EGroupware/egroupware.git
synced 2025-03-09 20:52:07 +01:00
allow to use Api\DateTime::sql_filter also for non-integer columns like regular DB DateTime or Timestamp columns
This commit is contained in:
parent
2877e9d193
commit
36a8e0dfa2
@ -232,9 +232,10 @@ class DateTime extends \DateTime
|
|||||||
* @param int &$end
|
* @param int &$end
|
||||||
* @param string $column name of timestamp column to use in returned sql
|
* @param string $column name of timestamp column to use in returned sql
|
||||||
* @param array $filters $name => list($syear,$smonth,$sday,$sweek,$eyear,$emonth,$eday,$eweek) pairs with offsets
|
* @param array $filters $name => list($syear,$smonth,$sday,$sweek,$eyear,$emonth,$eday,$eweek) pairs with offsets
|
||||||
|
* @param string $format ts: $column is a unix-timestamp/int, self::DATABASE: suitable for DateTime and Timestamp columns
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public static function sql_filter($name, &$start, &$end, $column, array $filters=array())
|
public static function sql_filter($name, &$start, &$end, $column, array $filters=array(), $format='ts')
|
||||||
{
|
{
|
||||||
if ($name == 'custom' && $start)
|
if ($name == 'custom' && $start)
|
||||||
{
|
{
|
||||||
@ -294,19 +295,19 @@ class DateTime extends \DateTime
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
// convert start + end from user to servertime for the filter
|
// convert start + end from user to servertime for the filter
|
||||||
$sql = '('.DateTime::user2server($start, 'ts').' <= '.$column;
|
$sql = '('.$GLOBALS['egw']->db->quote(DateTime::user2server($start, $format), $format === 'ts' ? 'int' : 'string').' <= '.$column;
|
||||||
if($end)
|
if($end)
|
||||||
{
|
{
|
||||||
$sql .=' AND '.$column.' < '.DateTime::user2server($end, 'ts');
|
$sql .=' AND '.$column.' < '.$GLOBALS['egw']->db->quote(DateTime::user2server($end, $format), $format === 'ts' ? 'int' : 'string');
|
||||||
|
|
||||||
// returned timestamps: $end is an inclusive date, eg. for today it's equal to start!
|
// returned timestamps: $end is an inclusive date, e.g. for today it's equal to start!
|
||||||
$end->add('-1day');
|
$end->add('-1day');
|
||||||
$end = $end->format('ts');
|
$end = $end->format($format);
|
||||||
}
|
}
|
||||||
$sql .= ')';
|
$sql .= ')';
|
||||||
//error_log(__METHOD__."('$name', ...) syear=$syear, smonth=$smonth, sday=$sday, sweek=$sweek, eyear=$eyear, emonth=$emonth, eday=$eday, eweek=$eweek --> start=".$start->format().', end='.$end->format().", sql='$sql'");
|
//error_log(__METHOD__."('$name', ...) syear=$syear, smonth=$smonth, sday=$sday, sweek=$sweek, eyear=$eyear, emonth=$emonth, eday=$eday, eweek=$eweek --> start=".$start->format().', end='.$end->format().", sql='$sql'");
|
||||||
|
|
||||||
$start = $start->format('ts');
|
$start = $start->format($format);
|
||||||
|
|
||||||
return $sql;
|
return $sql;
|
||||||
}
|
}
|
||||||
|
@ -3,10 +3,8 @@
|
|||||||
<overlay>
|
<overlay>
|
||||||
<template id="timesheet.index.dates" template="" lang="" group="0" version="1.2.001" >
|
<template id="timesheet.index.dates" template="" lang="" group="0" version="1.2.001" >
|
||||||
<et2-hbox>
|
<et2-hbox>
|
||||||
<et2-description value="Start"></et2-description>
|
<et2-date label="Start" id="startdate" onchange="widget.getParent().getWidgetById('enddate').set_min(widget.getValue());return true;"></et2-date>
|
||||||
<et2-date id="startdate" onchange="widget.getParent().getWidgetById('enddate').set_min(widget.getValue());return true;"></et2-date>
|
<et2-date label="End" id="enddate" onchange="widget.getParent().getWidgetById('startdate').set_max(widget.getValue());return true;"></et2-date>
|
||||||
<et2-description value="End"></et2-description>
|
|
||||||
<et2-date id="enddate" onchange="widget.getParent().getWidgetById('startdate').set_max(widget.getValue());return true;"></et2-date>
|
|
||||||
</et2-hbox>
|
</et2-hbox>
|
||||||
</template>
|
</template>
|
||||||
<template id="timesheet.index.add" template="" lang="" group="0" version="1.7.001">
|
<template id="timesheet.index.add" template="" lang="" group="0" version="1.7.001">
|
||||||
|
Loading…
Reference in New Issue
Block a user