From 7557173df43eebe1a510db475184b96d353ede83 Mon Sep 17 00:00:00 2001 From: Alexander Guth Date: Wed, 17 Jul 2019 23:12:32 +0200 Subject: [PATCH] Fix text filter scope (#4445) Credit to @alxy. Fixes https://github.com/octobercms/october/pull/4241#issuecomment-510140574 --- modules/backend/widgets/Filter.php | 22 +++++-------------- .../widgets/filter/partials/_scope_text.htm | 2 +- 2 files changed, 6 insertions(+), 18 deletions(-) diff --git a/modules/backend/widgets/Filter.php b/modules/backend/widgets/Filter.php index c32a72fab..fa47aaaa6 100644 --- a/modules/backend/widgets/Filter.php +++ b/modules/backend/widgets/Filter.php @@ -116,7 +116,7 @@ class Filter extends WidgetBase $after = $scope->value[0]->format('Y-m-d H:i:s'); $before = $scope->value[1]->format('Y-m-d H:i:s'); - if(strcasecmp($after, '0000-00-00 00:00:00') > 0) { + if (strcasecmp($after, '0000-00-00 00:00:00') > 0) { $params['afterStr'] = Backend::dateTime($scope->value[0], ['formatAlias' => 'dateMin']); $params['after'] = $after; } @@ -125,7 +125,7 @@ class Filter extends WidgetBase $params['after'] = null; } - if(strcasecmp($before, '2999-12-31 23:59:59') < 0) { + if (strcasecmp($before, '2999-12-31 23:59:59') < 0) { $params['beforeStr'] = Backend::dateTime($scope->value[1], ['formatAlias' => 'dateMin']); $params['before'] = $before; } @@ -261,15 +261,7 @@ class Filter extends WidgetBase break; case 'text': - $values = post('options.value'); - - if ($values !== null && $values !== '') { - list($value) = $values; - } - else { - $value = null; - } - + $value = post('options.value.' . $scope->scopeName) ?: null; $this->setScopeValue($scope, $value); break; } @@ -567,7 +559,6 @@ class Filter extends WidgetBase public function addScopes(array $scopes) { foreach ($scopes as $name => $config) { - $scopeObj = $this->makeFilterScope($name, $config); /* @@ -715,7 +706,6 @@ class Filter extends WidgetBase list($after, $before) = array_values($scope->value); if ($after && $after instanceof Carbon && $before && $before instanceof Carbon) { - /* * Condition */ @@ -763,7 +753,6 @@ class Filter extends WidgetBase list($min, $max) = array_values($scope->value); if ($min && $max) { - /* * Condition * @@ -811,7 +800,6 @@ class Filter extends WidgetBase * Condition */ if ($scopeConditions = $scope->conditions) { - /* * Switch scope: multiple conditions, value either 1 or 2 */ @@ -976,7 +964,7 @@ class Filter extends WidgetBase if (null !== $ajaxDates) { if (!is_array($ajaxDates)) { - if(preg_match($dateRegex, $ajaxDates)) { + if (preg_match($dateRegex, $ajaxDates)) { $dates = [$ajaxDates]; } } else { @@ -984,7 +972,7 @@ class Filter extends WidgetBase if (preg_match($dateRegex, $date)) { $dates[] = Carbon::createFromFormat('Y-m-d H:i:s', $date); } elseif (empty($date)) { - if($i == 0) { + if ($i == 0) { $dates[] = Carbon::createFromFormat('Y-m-d H:i:s', '0000-00-00 00:00:00'); } else { $dates[] = Carbon::createFromFormat('Y-m-d H:i:s', '2999-12-31 23:59:59'); diff --git a/modules/backend/widgets/filter/partials/_scope_text.htm b/modules/backend/widgets/filter/partials/_scope_text.htm index d6e65d773..c1dcdab5e 100644 --- a/modules/backend/widgets/filter/partials/_scope_text.htm +++ b/modules/backend/widgets/filter/partials/_scope_text.htm @@ -2,7 +2,7 @@