From fe935d6ec1e82bea1fd002ea19b6e2f9647ddc70 Mon Sep 17 00:00:00 2001 From: Kamil Date: Tue, 17 Jul 2018 06:24:28 +0200 Subject: Add search within a range of dates for creation/moved date fields --- app/Filter/BaseDateRangeFilter.php | 54 ++++++++++++++++++++++++++++++ app/Filter/TaskCreationDateRangeFilter.php | 38 +++++++++++++++++++++ app/Filter/TaskMovedDateRangeFilter.php | 38 +++++++++++++++++++++ app/ServiceProvider/FilterProvider.php | 8 +++++ 4 files changed, 138 insertions(+) create mode 100644 app/Filter/BaseDateRangeFilter.php create mode 100644 app/Filter/TaskCreationDateRangeFilter.php create mode 100644 app/Filter/TaskMovedDateRangeFilter.php (limited to 'app') diff --git a/app/Filter/BaseDateRangeFilter.php b/app/Filter/BaseDateRangeFilter.php new file mode 100644 index 00000000..336f8c8e --- /dev/null +++ b/app/Filter/BaseDateRangeFilter.php @@ -0,0 +1,54 @@ +dateParser = $dateParser; + return $this; + } + + /** + * Apply a date filter + * + * @access protected + * @param string $field + */ + protected function applyDateFilter($field) + { + $dates = explode('..', $this->value); + + if(count($dates)=== 2){ + $timestampFrom = $this->dateParser->getTimestamp($dates[0]); + $timestampTo = $this->dateParser->getTimestamp($dates[1]); + + $this->query->gte($field, $timestampFrom); + $this->query->lte($field, $timestampTo + 86399); + } + } +} diff --git a/app/Filter/TaskCreationDateRangeFilter.php b/app/Filter/TaskCreationDateRangeFilter.php new file mode 100644 index 00000000..7696af07 --- /dev/null +++ b/app/Filter/TaskCreationDateRangeFilter.php @@ -0,0 +1,38 @@ +applyDateFilter(TaskModel::TABLE.'.date_creation'); + return $this; + } +} diff --git a/app/Filter/TaskMovedDateRangeFilter.php b/app/Filter/TaskMovedDateRangeFilter.php new file mode 100644 index 00000000..b5b826b0 --- /dev/null +++ b/app/Filter/TaskMovedDateRangeFilter.php @@ -0,0 +1,38 @@ +applyDateFilter(TaskModel::TABLE.'.date_moved'); + return $this; + } +} diff --git a/app/ServiceProvider/FilterProvider.php b/app/ServiceProvider/FilterProvider.php index 11a29e69..c61d2284 100644 --- a/app/ServiceProvider/FilterProvider.php +++ b/app/ServiceProvider/FilterProvider.php @@ -16,6 +16,7 @@ use Kanboard\Filter\TaskColumnFilter; use Kanboard\Filter\TaskCommentFilter; use Kanboard\Filter\TaskCompletionDateFilter; use Kanboard\Filter\TaskCreationDateFilter; +use Kanboard\Filter\TaskCreationDateRangeFilter; use Kanboard\Filter\TaskCreatorFilter; use Kanboard\Filter\TaskDescriptionFilter; use Kanboard\Filter\TaskDueDateFilter; @@ -24,6 +25,7 @@ use Kanboard\Filter\TaskIdFilter; use Kanboard\Filter\TaskLinkFilter; use Kanboard\Filter\TaskModificationDateFilter; use Kanboard\Filter\TaskMovedDateFilter; +use Kanboard\Filter\TaskMovedDateRangeFilter; use Kanboard\Filter\TaskPriorityFilter; use Kanboard\Filter\TaskProjectFilter; use Kanboard\Filter\TaskReferenceFilter; @@ -148,6 +150,9 @@ class FilterProvider implements ServiceProviderInterface ->withFilter(TaskCreationDateFilter::getInstance() ->setDateParser($c['dateParser']) ) + ->withFilter(TaskCreationDateRangeFilter::getInstance() + ->setDateParser($c['dateParser']) + ) ->withFilter(TaskCreatorFilter::getInstance() ->setCurrentUserId($c['userSession']->getId()) ) @@ -171,6 +176,9 @@ class FilterProvider implements ServiceProviderInterface ->withFilter(TaskMovedDateFilter::getInstance() ->setDateParser($c['dateParser']) ) + ->withFilter(TaskMovedDateRangeFilter::getInstance() + ->setDateParser($c['dateParser']) + ) ->withFilter(new TaskProjectFilter()) ->withFilter(new TaskReferenceFilter()) ->withFilter(new TaskScoreFilter()) -- cgit v1.2.3