From 1c43fceffbc06ebe842644b0a73054f032ee377f Mon Sep 17 00:00:00 2001 From: epriestley Date: Thu, 12 Sep 2013 13:03:39 -0700 Subject: [PATCH] Add date filtering to Maniphest "pro" search Summary: Adds date created filtering. There's a task for this somewhere that I can't immediately find. Test Plan: Filtered tasks. Reviewers: btrahan Reviewed By: btrahan CC: aran Differential Revision: https://secure.phabricator.com/D6952 --- .../maniphest/query/ManiphestTaskQuery.php | 28 +++++++++++++++++++ .../query/ManiphestTaskSearchEngine.php | 22 +++++++++++++++ 2 files changed, 50 insertions(+) diff --git a/src/applications/maniphest/query/ManiphestTaskQuery.php b/src/applications/maniphest/query/ManiphestTaskQuery.php index e39f0aeb2b..8c141539ba 100644 --- a/src/applications/maniphest/query/ManiphestTaskQuery.php +++ b/src/applications/maniphest/query/ManiphestTaskQuery.php @@ -20,6 +20,8 @@ final class ManiphestTaskQuery private $anyProjectPHIDs = array(); private $anyUserProjectPHIDs = array(); private $includeNoProject = null; + private $dateCreatedAfter; + private $dateCreatedBefore; private $fullTextSearch = ''; @@ -183,6 +185,16 @@ final class ManiphestTaskQuery return $this; } + public function withDateCreatedBefore($date_created_before) { + $this->dateCreatedBefore = $date_created_before; + return $this; + } + + public function withDateCreatedAfter($date_created_after) { + $this->dateCreatedAfter = $date_created_after; + return $this; + } + public function loadPage() { // TODO: (T603) It is possible for a user to find the PHID of a project @@ -220,6 +232,22 @@ final class ManiphestTaskQuery $where[] = $this->buildXProjectWhereClause($conn); $where[] = $this->buildFullTextWhereClause($conn); + // TODO: Add a key for this the next time we hit this table. + + if ($this->dateCreatedAfter) { + $where[] = qsprintf( + $conn, + 'dateCreated >= %d', + $this->dateCreatedAfter); + } + + if ($this->dateCreatedBefore) { + $where[] = qsprintf( + $conn, + 'dateCreated <= %d', + $this->dateCreatedBefore); + } + $where = $this->formatWhereClause($where); $join = array(); diff --git a/src/applications/maniphest/query/ManiphestTaskSearchEngine.php b/src/applications/maniphest/query/ManiphestTaskSearchEngine.php index a8836c0535..906c58f31f 100644 --- a/src/applications/maniphest/query/ManiphestTaskSearchEngine.php +++ b/src/applications/maniphest/query/ManiphestTaskSearchEngine.php @@ -53,6 +53,9 @@ final class ManiphestTaskSearchEngine 'userProjectPHIDs', $this->readUsersFromRequest($request, 'userProjects')); + $saved->setParameter('createdStart', $request->getStr('createdStart')); + $saved->setParameter('createdEnd', $request->getStr('createdEnd')); + return $saved; } @@ -127,6 +130,17 @@ final class ManiphestTaskSearchEngine $query->withAnyUserProjects($user_project_phids); } + $start = $this->parseDateTime($saved->getParameter('createdStart')); + $end = $this->parseDateTime($saved->getParameter('createdEnd')); + + if ($start) { + $query->withDateCreatedAfter($start); + } + + if ($end) { + $query->withDateCreatedBefore($end); + } + return $query; } @@ -273,6 +287,14 @@ final class ManiphestTaskSearchEngine ->setName('ids') ->setLabel(pht('Task IDs')) ->setValue(implode(', ', $ids))); + + $this->buildDateRange( + $form, + $saved, + 'createdStart', + pht('Created After'), + 'createdEnd', + pht('Created Before')); } protected function getURI($path) {