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() {
|
|
|
|
return new PonderQuestionQuery();
|
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-07-22 16:14:49 +02:00
|
|
|
$status = $map['status'];
|
2013-07-28 03:37:17 +02:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
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')),
|
|
|
|
id(new PhabricatorSearchSelectField())
|
|
|
|
->setLabel(pht('Status'))
|
|
|
|
->setKey('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
|
|
|
}
|