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
|
|
|
}
|
|
|
|
|
2015-07-22 16:14:49 +02:00
|
|
|
public function newQuery() {
|
2015-08-05 18:31:37 +02:00
|
|
|
return id(new PonderQuestionQuery())
|
|
|
|
->needProjectPHIDs(true);
|
2013-07-18 21:40:51 +02:00
|
|
|
}
|
|
|
|
|
2015-07-22 16:14:49 +02:00
|
|
|
protected function buildQueryFromParameters(array $map) {
|
|
|
|
$query = $this->newQuery();
|
2013-07-18 21:40:51 +02:00
|
|
|
|
2015-07-22 16:14:49 +02:00
|
|
|
if ($map['authorPHIDs']) {
|
|
|
|
$query->withAuthorPHIDs($map['authorPHIDs']);
|
2013-07-18 21:40:51 +02:00
|
|
|
}
|
|
|
|
|
2015-07-22 16:14:49 +02:00
|
|
|
if ($map['answerers']) {
|
|
|
|
$query->withAnswererPHIDs($map['answerers']);
|
2013-07-18 21:40:51 +02:00
|
|
|
}
|
|
|
|
|
2015-08-08 19:23:33 +02:00
|
|
|
if ($map['statuses']) {
|
|
|
|
$query->withStatuses($map['statuses']);
|
2013-07-28 03:37:17 +02:00
|
|
|
}
|
|
|
|
|
2013-07-18 21:40:51 +02:00
|
|
|
return $query;
|
|
|
|
}
|
|
|
|
|
2015-07-22 16:14:49 +02:00
|
|
|
protected function buildCustomSearchFields() {
|
|
|
|
return array(
|
|
|
|
id(new PhabricatorUsersSearchField())
|
|
|
|
->setKey('authorPHIDs')
|
|
|
|
->setAliases(array('authors'))
|
|
|
|
->setLabel(pht('Authors')),
|
|
|
|
id(new PhabricatorUsersSearchField())
|
|
|
|
->setKey('answerers')
|
|
|
|
->setAliases(array('answerers'))
|
|
|
|
->setLabel(pht('Answered By')),
|
2015-08-08 19:23:33 +02:00
|
|
|
id(new PhabricatorSearchCheckboxesField())
|
2015-07-22 16:14:49 +02:00
|
|
|
->setLabel(pht('Status'))
|
2015-08-08 19:23:33 +02:00
|
|
|
->setKey('statuses')
|
2015-07-22 16:14:49 +02:00
|
|
|
->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(
|
2015-08-12 16:56:10 +02:00
|
|
|
'recent' => pht('Recent Questions'),
|
2013-07-28 03:37:17 +02:00
|
|
|
'open' => pht('Open Questions'),
|
2015-08-08 19:23:33 +02:00
|
|
|
'resolved' => pht('Resolved 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':
|
2015-08-08 19:23:33 +02:00
|
|
|
return $query->setParameter(
|
|
|
|
'statuses', array(PonderQuestionStatus::STATUS_OPEN));
|
2015-08-12 16:56:10 +02:00
|
|
|
case 'recent':
|
|
|
|
return $query->setParameter(
|
|
|
|
'statuses', array(
|
|
|
|
PonderQuestionStatus::STATUS_OPEN,
|
|
|
|
PonderQuestionStatus::STATUS_CLOSED_RESOLVED,
|
|
|
|
));
|
2015-08-08 19:23:33 +02:00
|
|
|
case 'resolved':
|
|
|
|
return $query->setParameter(
|
|
|
|
'statuses', array(PonderQuestionStatus::STATUS_CLOSED_RESOLVED));
|
2013-07-18 21:40:51 +02:00
|
|
|
case 'authored':
|
|
|
|
return $query->setParameter(
|
|
|
|
'authorPHIDs',
|
|
|
|
array($this->requireViewer()->getPHID()));
|
|
|
|
case 'answered':
|
|
|
|
return $query->setParameter(
|
2015-08-21 15:58:06 +02:00
|
|
|
'answerers',
|
2013-07-18 21:40:51 +02:00
|
|
|
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();
|
|
|
|
|
2015-08-05 18:31:37 +02:00
|
|
|
$proj_phids = array();
|
|
|
|
foreach ($questions as $question) {
|
|
|
|
foreach ($question->getProjectPHIDs() as $project_phid) {
|
|
|
|
$proj_phids[] = $project_phid;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$proj_handles = id(new PhabricatorHandleQuery())
|
|
|
|
->setViewer($viewer)
|
|
|
|
->withPHIDs($proj_phids)
|
|
|
|
->execute();
|
|
|
|
|
2014-05-09 21:25:52 +02:00
|
|
|
$view = id(new PHUIObjectItemListView())
|
|
|
|
->setUser($viewer);
|
|
|
|
|
|
|
|
foreach ($questions as $question) {
|
2015-05-29 00:17:34 +02:00
|
|
|
$color = PonderQuestionStatus::getQuestionStatusTagColor(
|
2015-11-02 20:54:38 +01:00
|
|
|
$question->getStatus());
|
2015-05-29 00:17:34 +02:00
|
|
|
$icon = PonderQuestionStatus::getQuestionStatusIcon(
|
2015-11-02 20:54:38 +01:00
|
|
|
$question->getStatus());
|
2015-05-29 00:17:34 +02:00
|
|
|
$full_status = PonderQuestionStatus::getQuestionStatusFullName(
|
2015-11-02 20:54:38 +01:00
|
|
|
$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
|
|
|
|
2015-08-05 18:31:37 +02:00
|
|
|
$project_handles = array_select_keys(
|
|
|
|
$proj_handles,
|
|
|
|
$question->getProjectPHIDs());
|
|
|
|
|
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(
|
2015-11-02 20:54:38 +01:00
|
|
|
pht(
|
|
|
|
'%s Answer(s)',
|
|
|
|
new PhutilNumber($question->getAnswerCount())));
|
2014-05-09 21:25:52 +02:00
|
|
|
|
2015-08-05 18:31:37 +02:00
|
|
|
if ($project_handles) {
|
|
|
|
$item->addAttribute(
|
|
|
|
id(new PHUIHandleTagListView())
|
|
|
|
->setLimit(4)
|
|
|
|
->setSlim(true)
|
|
|
|
->setHandles($project_handles));
|
|
|
|
}
|
|
|
|
|
2014-05-09 21:25:52 +02:00
|
|
|
$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
|
|
|
}
|