From a54f1395c2d396f1d4f93a05abe8d8559f9fc07b Mon Sep 17 00:00:00 2001 From: epriestley Date: Sun, 3 Apr 2011 22:12:22 -0700 Subject: [PATCH] Owners search. --- .../list/PhabricatorOwnersListController.php | 45 ++++++++++++++++++- .../owners/controller/list/__init__.php | 1 + 2 files changed, 45 insertions(+), 1 deletion(-) diff --git a/src/applications/owners/controller/list/PhabricatorOwnersListController.php b/src/applications/owners/controller/list/PhabricatorOwnersListController.php index 8640a13f5a..5ca6ace1e6 100644 --- a/src/applications/owners/controller/list/PhabricatorOwnersListController.php +++ b/src/applications/owners/controller/list/PhabricatorOwnersListController.php @@ -59,16 +59,59 @@ class PhabricatorOwnersListController extends PhabricatorOwnersController { } $package = new PhabricatorOwnersPackage(); + $owner = new PhabricatorOwnersOwner(); + $path = new PhabricatorOwnersPath(); switch ($this->view) { case 'search': $packages = array(); + $conn_r = $package->establishConnection('r'); + + $where = array('1 = 1'); + $join = array(); + + if ($request->getStr('name')) { + $where[] = qsprintf( + $conn_r, + 'p.name LIKE %~', + $request->getStr('name')); + } + + if ($request->getStr('path')) { + $join[] = qsprintf( + $conn_r, + 'JOIN %T path ON path.packageID = p.id', + $path->getTableName()); + $where[] = qsprintf( + $conn_r, + 'path.path LIKE %~', + $request->getStr('path')); + } + + if ($request->getArr('owner')) { + $join[] = qsprintf( + $conn_r, + 'JOIN %T o ON o.packageID = p.id', + $owner->getTableName()); + $where[] = qsprintf( + $conn_r, + 'o.userPHID IN (%Ls)', + $request->getArr('owner')); + } + + $data = queryfx_all( + $conn_r, + 'SELECT p.* FROM %T p %Q WHERE %Q GROUP BY p.id', + $package->getTableName(), + implode(' ', $join), + '('.implode(') AND (', $where).')'); + $packages = $package->loadAllFromArray($data); + $header = 'Search Results'; $nodata = 'No packages match your query.'; break; case 'owned': - $owner = new PhabricatorOwnersOwner(); $data = queryfx_all( $package->establishConnection('r'), 'SELECT p.* FROM %T p JOIN %T o ON p.id = o.packageID diff --git a/src/applications/owners/controller/list/__init__.php b/src/applications/owners/controller/list/__init__.php index 6a75d3c690..1d8c9ddb1f 100644 --- a/src/applications/owners/controller/list/__init__.php +++ b/src/applications/owners/controller/list/__init__.php @@ -11,6 +11,7 @@ phutil_require_module('phabricator', 'applications/owners/storage/owner'); phutil_require_module('phabricator', 'applications/owners/storage/package'); phutil_require_module('phabricator', 'applications/owners/storage/path'); phutil_require_module('phabricator', 'applications/phid/handle/data'); +phutil_require_module('phabricator', 'storage/qsprintf'); phutil_require_module('phabricator', 'storage/queryfx'); phutil_require_module('phabricator', 'view/control/table'); phutil_require_module('phabricator', 'view/form/base');