2013-07-18 21:40:51 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
final class PonderQuestionSearchEngine
|
|
|
|
extends PhabricatorApplicationSearchEngine {
|
|
|
|
|
2014-06-12 22:22:20 +02:00
|
|
|
public function getResultTypeDescription() {
|
|
|
|
return pht('Ponder Questions');
|
|
|
|
}
|
|
|
|
|
2015-02-05 00:47:48 +01:00
|
|
|
public function getApplicationClassName() {
|
2014-07-23 02:03:09 +02:00
|
|
|
return 'PhabricatorPonderApplication';
|
2014-05-09 21:25:52 +02:00
|
|
|
}
|
|
|
|
|
2013-07-18 21:40:51 +02:00
|
|
|
public function buildSavedQueryFromRequest(AphrontRequest $request) {
|
|
|
|
$saved = new PhabricatorSavedQuery();
|
|
|
|
|
|
|
|
$saved->setParameter(
|
|
|
|
'authorPHIDs',
|
Allow construction of ApplicationSearch queries with GET
Summary:
Ref T3775 (discussion here). Ref T2625.
T3775 presents two problems:
# Existing tools which linked to `/differential/active/epriestley/` (that is, put a username in the URL) can't generate search links now.
# Humans can't edit the URL anymore, either.
I think (1) is an actual issue, and this fixes it. I think (2) is pretty fluff, and this doesn't really try to fix it, although it probably improves it.
The fix for (1) is:
- Provide a helper to read a parameter containing either a list of user PHIDs or a list of usernames, so `/?users[]=PHID-USER-xyz` (from a tokenizer) and `/?users=alincoln,htaft` (from an external program) are equivalent inputs.
- Rename all the form parameters to be more digestable (`authorPHIDs` -> `authors`). Almost all of them were in this form already anyway. This just gives us `?users=alincoln` instead of `userPHIDs=alincoln`.
- Inside ApplicationSearch, if a request has no query associated with it but does have query parameters, build a query from the request instead of issuing the user's default query. Basically, this means that `/differential/` runs the default query, while `/differential/?users=x` runs a custom query.
Test Plan: {F56612}
Reviewers: btrahan
Reviewed By: btrahan
CC: aran
Maniphest Tasks: T2625, T3775
Differential Revision: https://secure.phabricator.com/D6840
2013-08-29 20:52:29 +02:00
|
|
|
$this->readUsersFromRequest($request, 'authors'));
|
2013-07-18 21:40:51 +02:00
|
|
|
|
|
|
|
$saved->setParameter(
|
|
|
|
'answererPHIDs',
|
Allow construction of ApplicationSearch queries with GET
Summary:
Ref T3775 (discussion here). Ref T2625.
T3775 presents two problems:
# Existing tools which linked to `/differential/active/epriestley/` (that is, put a username in the URL) can't generate search links now.
# Humans can't edit the URL anymore, either.
I think (1) is an actual issue, and this fixes it. I think (2) is pretty fluff, and this doesn't really try to fix it, although it probably improves it.
The fix for (1) is:
- Provide a helper to read a parameter containing either a list of user PHIDs or a list of usernames, so `/?users[]=PHID-USER-xyz` (from a tokenizer) and `/?users=alincoln,htaft` (from an external program) are equivalent inputs.
- Rename all the form parameters to be more digestable (`authorPHIDs` -> `authors`). Almost all of them were in this form already anyway. This just gives us `?users=alincoln` instead of `userPHIDs=alincoln`.
- Inside ApplicationSearch, if a request has no query associated with it but does have query parameters, build a query from the request instead of issuing the user's default query. Basically, this means that `/differential/` runs the default query, while `/differential/?users=x` runs a custom query.
Test Plan: {F56612}
Reviewers: btrahan
Reviewed By: btrahan
CC: aran
Maniphest Tasks: T2625, T3775
Differential Revision: https://secure.phabricator.com/D6840
2013-08-29 20:52:29 +02:00
|
|
|
$this->readUsersFromRequest($request, 'answerers'));
|
2013-07-18 21:40:51 +02:00
|
|
|
|
2013-07-28 03:37:17 +02:00
|
|
|
$saved->setParameter('status', $request->getStr('status'));
|
|
|
|
|
2013-07-18 21:40:51 +02:00
|
|
|
return $saved;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function buildQueryFromSavedQuery(PhabricatorSavedQuery $saved) {
|
|
|
|
$query = id(new PonderQuestionQuery());
|
|
|
|
|
|
|
|
$author_phids = $saved->getParameter('authorPHIDs');
|
|
|
|
if ($author_phids) {
|
|
|
|
$query->withAuthorPHIDs($author_phids);
|
|
|
|
}
|
|
|
|
|
|
|
|
$answerer_phids = $saved->getParameter('answererPHIDs');
|
|
|
|
if ($answerer_phids) {
|
|
|
|
$query->withAnswererPHIDs($answerer_phids);
|
|
|
|
}
|
|
|
|
|
2013-07-28 03:37:17 +02:00
|
|
|
$status = $saved->getParameter('status');
|
|
|
|
if ($status != null) {
|
|
|
|
switch ($status) {
|
|
|
|
case 0:
|
|
|
|
$query->withStatus(PonderQuestionQuery::STATUS_OPEN);
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
$query->withStatus(PonderQuestionQuery::STATUS_CLOSED);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-07-18 21:40:51 +02:00
|
|
|
return $query;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function buildSearchForm(
|
|
|
|
AphrontFormView $form,
|
|
|
|
PhabricatorSavedQuery $saved_query) {
|
|
|
|
|
|
|
|
$author_phids = $saved_query->getParameter('authorPHIDs', array());
|
|
|
|
$answerer_phids = $saved_query->getParameter('answererPHIDs', array());
|
2013-07-28 03:37:17 +02:00
|
|
|
$status = $saved_query->getParameter(
|
|
|
|
'status', PonderQuestionStatus::STATUS_OPEN);
|
2013-07-18 21:40:51 +02:00
|
|
|
|
|
|
|
$form
|
2015-03-31 23:10:55 +02:00
|
|
|
->appendControl(
|
2013-07-18 21:40:51 +02:00
|
|
|
id(new AphrontFormTokenizerControl())
|
2014-07-18 00:44:18 +02:00
|
|
|
->setDatasource(new PhabricatorPeopleDatasource())
|
2013-07-18 21:40:51 +02:00
|
|
|
->setName('authors')
|
|
|
|
->setLabel(pht('Authors'))
|
2015-03-31 23:10:55 +02:00
|
|
|
->setValue($author_phids))
|
|
|
|
->appendControl(
|
2013-07-18 21:40:51 +02:00
|
|
|
id(new AphrontFormTokenizerControl())
|
2014-07-18 00:44:18 +02:00
|
|
|
->setDatasource(new PhabricatorPeopleDatasource())
|
2013-07-18 21:40:51 +02:00
|
|
|
->setName('answerers')
|
|
|
|
->setLabel(pht('Answered By'))
|
2015-03-31 23:10:55 +02:00
|
|
|
->setValue($answerer_phids))
|
2013-07-28 03:37:17 +02:00
|
|
|
->appendChild(
|
|
|
|
id(new AphrontFormSelectControl())
|
|
|
|
->setLabel(pht('Status'))
|
|
|
|
->setName('status')
|
|
|
|
->setValue($status)
|
|
|
|
->setOptions(PonderQuestionStatus::getQuestionStatusMap()));
|
2013-07-18 21:40:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
protected function getURI($path) {
|
|
|
|
return '/ponder/'.$path;
|
|
|
|
}
|
|
|
|
|
2015-01-06 21:34:51 +01:00
|
|
|
protected function getBuiltinQueryNames() {
|
2013-07-18 21:40:51 +02:00
|
|
|
$names = array(
|
2013-07-28 03:37:17 +02:00
|
|
|
'open' => pht('Open Questions'),
|
2013-07-18 21:40:51 +02:00
|
|
|
'all' => pht('All Questions'),
|
|
|
|
);
|
|
|
|
|
|
|
|
if ($this->requireViewer()->isLoggedIn()) {
|
|
|
|
$names['authored'] = pht('Authored');
|
|
|
|
$names['answered'] = pht('Answered');
|
|
|
|
}
|
|
|
|
|
|
|
|
return $names;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function buildSavedQueryFromBuiltin($query_key) {
|
|
|
|
|
|
|
|
$query = $this->newSavedQuery();
|
|
|
|
$query->setQueryKey($query_key);
|
|
|
|
|
|
|
|
switch ($query_key) {
|
|
|
|
case 'all':
|
|
|
|
return $query;
|
2013-07-28 03:37:17 +02:00
|
|
|
case 'open':
|
|
|
|
return $query->setParameter('status', PonderQuestionQuery::STATUS_OPEN);
|
2013-07-18 21:40:51 +02:00
|
|
|
case 'authored':
|
|
|
|
return $query->setParameter(
|
|
|
|
'authorPHIDs',
|
|
|
|
array($this->requireViewer()->getPHID()));
|
|
|
|
case 'answered':
|
|
|
|
return $query->setParameter(
|
|
|
|
'answererPHIDs',
|
|
|
|
array($this->requireViewer()->getPHID()));
|
|
|
|
}
|
|
|
|
|
|
|
|
return parent::buildSavedQueryFromBuiltin($query_key);
|
|
|
|
}
|
|
|
|
|
2014-05-09 21:25:52 +02:00
|
|
|
protected function getRequiredHandlePHIDsForResultList(
|
|
|
|
array $questions,
|
|
|
|
PhabricatorSavedQuery $query) {
|
|
|
|
return mpull($questions, 'getAuthorPHID');
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function renderResultList(
|
|
|
|
array $questions,
|
|
|
|
PhabricatorSavedQuery $query,
|
|
|
|
array $handles) {
|
|
|
|
assert_instances_of($questions, 'PonderQuestion');
|
|
|
|
|
|
|
|
$viewer = $this->requireViewer();
|
|
|
|
|
|
|
|
$view = id(new PHUIObjectItemListView())
|
|
|
|
->setUser($viewer);
|
|
|
|
|
|
|
|
foreach ($questions as $question) {
|
2015-05-29 00:17:34 +02:00
|
|
|
$color = PonderQuestionStatus::getQuestionStatusTagColor(
|
|
|
|
$question->getStatus());
|
|
|
|
$icon = PonderQuestionStatus::getQuestionStatusIcon(
|
|
|
|
$question->getStatus());
|
|
|
|
$full_status = PonderQuestionStatus::getQuestionStatusFullName(
|
|
|
|
$question->getStatus());
|
2014-05-09 21:25:52 +02:00
|
|
|
$item = new PHUIObjectItemView();
|
|
|
|
$item->setObjectName('Q'.$question->getID());
|
|
|
|
$item->setHeader($question->getTitle());
|
|
|
|
$item->setHref('/Q'.$question->getID());
|
|
|
|
$item->setObject($question);
|
2015-05-29 00:17:34 +02:00
|
|
|
$item->setStatusIcon($icon.' '.$color, $full_status);
|
2014-05-09 21:25:52 +02:00
|
|
|
|
|
|
|
$created_date = phabricator_date($question->getDateCreated(), $viewer);
|
|
|
|
$item->addIcon('none', $created_date);
|
|
|
|
$item->addByline(
|
|
|
|
pht(
|
|
|
|
'Asked by %s',
|
|
|
|
$handles[$question->getAuthorPHID()]->renderLink()));
|
|
|
|
|
|
|
|
$item->addAttribute(
|
|
|
|
pht('%d Answer(s)', $question->getAnswerCount()));
|
|
|
|
|
|
|
|
$view->addItem($item);
|
|
|
|
}
|
|
|
|
|
2015-06-19 12:46:20 +02:00
|
|
|
$result = new PhabricatorApplicationSearchResultView();
|
|
|
|
$result->setObjectList($view);
|
|
|
|
$result->setNoDataString(pht('No questions found.'));
|
|
|
|
|
|
|
|
return $result;
|
2014-05-09 21:25:52 +02:00
|
|
|
}
|
|
|
|
|
2013-07-18 21:40:51 +02:00
|
|
|
}
|