Merge remote-tracking branch 'saggi-dw/date-filter'

This commit is contained in:
Anna Dabrowska
2023-07-27 11:32:01 +02:00
4 changed files with 15 additions and 1 deletions

View File

@ -30,7 +30,7 @@ class SearchConfigTest extends StructTest
$this->assertEquals('user baz', $searchConfig->applyFilterVars('$USER$ $PAGE$'));
$this->assertEquals('$user', $searchConfig->applyFilterVars('$user'));
$this->assertEquals(date('Y-m-d'), $searchConfig->applyFilterVars('$DATE(now)$'));
}
public function test_filtervars_struct()

View File

@ -80,6 +80,7 @@ $lang['Exception nolookupmix'] = 'Sie können nicht mehr als eine Suche aggregie
$lang['Exception No data saved'] = 'Keine Daten gespeichert';
$lang['Exception no sqlite'] = 'Das \'Struct Plugin\' benötigt das \'Sqlite Plugin\'. Bitte installieren und aktivieren.';
$lang['Exception column not in table'] = 'Die Spalte %s existiert im Schema %s nicht.';
$lang['Exception datefilter'] = 'Der Filter: \'<code>$Date(%s)$</code>\' enthält einen ungültigen Wert';
$lang['Warning: no filters for cloud'] = 'Filter werden in \'Struct Clouds\' nicht unterstützt';
$lang['sort'] = 'Nach dieser Spalte sortieren';
$lang['next'] = 'Nächste Seite';

View File

@ -89,6 +89,7 @@ $lang['Exception nolookupmix'] = 'You can not aggregate more than one Lookup or
$lang['Exception No data saved'] = 'No data saved';
$lang['Exception no sqlite'] = 'The struct plugin requires the sqlite plugin. Please install and enable it.';
$lang['Exception column not in table'] = 'There is no column %s in schema %s.';
$lang['Exception datefilter'] = 'The filter: \'<code>$Date(%s)$</code>\' contains an unsupported value.';
$lang['Warning: no filters for cloud'] = 'Filters are not supported for struct clouds.';

View File

@ -137,10 +137,22 @@ class SearchConfig extends Search
);
// apply struct column placeholder (we support only one!)
// or apply date formula, given as strtotime
if (preg_match('/^(.*?)(?:\$STRUCT\.(.*?)\$)(.*?)$/', $filter, $match)) {
$filter = $this->applyFilterVarsStruct($match);
} elseif (preg_match('/^(.*?)(?:\$USER\.(.*?)\$)(.*?)$/', $filter, $match)) {
$filter = $this->applyFilterVarsUser($match);
} elseif (preg_match('/^(.*?)(?:\$DATE\((.*?)\)\$?)(.*?)$/', $filter, $match)) {
$toparse = $match[2];
if ($toparse == '') {
$toparse = 'now';
}
$timestamp = strtotime($toparse);
if ($timestamp === false) {
throw new StructException('datefilter', hsc($toparse));
} else {
$filter = str_replace($filter, date('Y-m-d', $timestamp), $filter);
}
}
return $filter;