1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2025-04-12 12:28:36 +02:00
phorge-phorge/src/applications/flag/query/PhabricatorFlagSearchEngine.php
Bob Trahan 9f1314b653 Flags - add ability to group by color
Summary:
I use color to convey meaning like "good resource to keep handy for a bit on new way of doing things" or "snipe this task". Now the list can be grouped by these colors.

Note I do this in PHP 'cuz color isn't part of any index AFAIK and pragmatically speaking this dataset should be tiny in the context of "user flags".

Ref T1809

Test Plan: selected group by color and observed the flags were indeed grouped by color

Reviewers: epriestley

Reviewed By: epriestley

CC: Korvin, aran

Maniphest Tasks: T1809

Differential Revision: https://secure.phabricator.com/D7188
2013-10-01 15:06:35 -07:00

82 lines
2 KiB
PHP

<?php
final class PhabricatorFlagSearchEngine
extends PhabricatorApplicationSearchEngine {
public function buildSavedQueryFromRequest(AphrontRequest $request) {
$saved = new PhabricatorSavedQuery();
$saved->setParameter('colors', $request->getArr('colors'));
$saved->setParameter('group', $request->getStr('group'));
return $saved;
}
public function buildQueryFromSavedQuery(PhabricatorSavedQuery $saved) {
$query = id(new PhabricatorFlagQuery())
->needHandles(true)
->withOwnerPHIDs(array($this->requireViewer()->getPHID()));
$colors = $saved->getParameter('colors');
if ($colors) {
$query->withColors($colors);
}
$group = $saved->getParameter('group');
$options = $this->getGroupOptions();
if ($group && isset($options[$group])) {
$query->setGroupBy($group);
}
return $query;
}
public function buildSearchForm(
AphrontFormView $form,
PhabricatorSavedQuery $saved_query) {
$form
->appendChild(
id(new PhabricatorFlagSelectControl())
->setName('colors')
->setLabel(pht('Colors'))
->setValue($saved_query->getParameter('colors', array())))
->appendChild(
id(new AphrontFormSelectControl())
->setName('group')
->setLabel(pht('Group By'))
->setValue($saved_query->getParameter('group'))
->setOptions($this->getGroupOptions()));
}
protected function getURI($path) {
return '/flag/'.$path;
}
public function getBuiltinQueryNames() {
$names = array(
'all' => pht('Flagged'),
);
return $names;
}
public function buildSavedQueryFromBuiltin($query_key) {
$query = $this->newSavedQuery();
$query->setQueryKey($query_key);
switch ($query_key) {
case 'all':
return $query;
}
return parent::buildSavedQueryFromBuiltin($query_key);
}
private function getGroupOptions() {
return array(
PhabricatorFlagQuery::GROUP_NONE => pht('None'),
PhabricatorFlagQuery::GROUP_COLOR => pht('Color'),
);
}
}