1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-10 08:52:39 +01:00

Add Projects to Ponder Search View

Summary: Ref T3578 Allows display of projects if available on individual ponder search results.

Test Plan: Added projects to my questions, see them display on search results.

Reviewers: epriestley

Reviewed By: epriestley

Subscribers: Korvin

Maniphest Tasks: T3578

Differential Revision: https://secure.phabricator.com/D13793
This commit is contained in:
Chad Little 2015-08-05 09:31:37 -07:00
parent 135d0c9ee7
commit fdc1662bfd
4 changed files with 66 additions and 2 deletions

View file

@ -8,6 +8,8 @@ final class PonderQuestionQuery
private $authorPHIDs;
private $answererPHIDs;
private $needProjectPHIDs;
private $status = 'status-any';
const STATUS_ANY = 'status-any';
@ -52,6 +54,11 @@ final class PonderQuestionQuery
return $this;
}
public function needProjectPHIDs($need_projects) {
$this->needProjectPHIDs = $need_projects;
return $this;
}
protected function buildWhereClauseParts(AphrontDatabaseConnection $conn) {
$where = parent::buildWhereClauseParts($conn);
@ -109,6 +116,9 @@ final class PonderQuestionQuery
}
protected function willFilterPage(array $questions) {
$phids = mpull($questions, 'getPHID');
if ($this->needAnswers) {
$aquery = id(new PonderAnswerQuery())
->setViewer($this->getViewer())
@ -133,7 +143,7 @@ final class PonderQuestionQuery
$etype = PonderQuestionHasVotingUserEdgeType::EDGECONST;
$edges = id(new PhabricatorEdgeQuery())
->withSourcePHIDs(mpull($questions, 'getPHID'))
->withSourcePHIDs($phids)
->withDestinationPHIDs(array($viewer_phid))
->withEdgeTypes(array($etype))
->needEdgeData(true)
@ -148,6 +158,22 @@ final class PonderQuestionQuery
}
}
if ($this->needProjectPHIDs) {
$edge_query = id(new PhabricatorEdgeQuery())
->withSourcePHIDs($phids)
->withEdgeTypes(
array(
PhabricatorProjectObjectHasProjectEdgeType::EDGECONST,
));
$edge_query->execute();
foreach ($questions as $question) {
$project_phids = $edge_query->getDestinationPHIDs(
array($question->getPHID()));
$question->attachProjectPHIDs($project_phids);
}
}
return $questions;
}

View file

@ -12,7 +12,8 @@ final class PonderQuestionSearchEngine
}
public function newQuery() {
return new PonderQuestionQuery();
return id(new PonderQuestionQuery())
->needProjectPHIDs(true);
}
protected function buildQueryFromParameters(array $map) {
@ -112,6 +113,18 @@ final class PonderQuestionSearchEngine
$viewer = $this->requireViewer();
$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();
$view = id(new PHUIObjectItemListView())
->setUser($viewer);
@ -129,6 +142,10 @@ final class PonderQuestionSearchEngine
$item->setObject($question);
$item->setStatusIcon($icon.' '.$color, $full_status);
$project_handles = array_select_keys(
$proj_handles,
$question->getProjectPHIDs());
$created_date = phabricator_date($question->getDateCreated(), $viewer);
$item->addIcon('none', $created_date);
$item->addByline(
@ -139,6 +156,14 @@ final class PonderQuestionSearchEngine
$item->addAttribute(
pht('%d Answer(s)', $question->getAnswerCount()));
if ($project_handles) {
$item->addAttribute(
id(new PHUIHandleTagListView())
->setLimit(4)
->setSlim(true)
->setHandles($project_handles));
}
$view->addItem($item);
}

View file

@ -33,6 +33,8 @@ final class PonderQuestion extends PonderDAO
private $vote;
private $comments;
private $projectPHIDs = self::ATTACHABLE;
public static function initializeNewQuestion(PhabricatorUser $actor) {
$app = id(new PhabricatorApplicationQuery())
->setViewer($actor)
@ -164,6 +166,15 @@ final class PonderQuestion extends PonderDAO
return $this->answers;
}
public function getProjectPHIDs() {
return $this->assertAttached($this->projectPHIDs);
}
public function attachProjectPHIDs(array $phids) {
$this->projectPHIDs = $phids;
return $this;
}
public function getMarkupField() {
return self::MARKUP_FIELD_CONTENT;
}

View file

@ -32,6 +32,8 @@ final class PhabricatorUSEnglishTranslation
'%d path(s)' => array('%d path', '%d paths'),
'%d diff(s)' => array('%d diff', '%d diffs'),
'%d Answer(s)' => array('%d Answer', '%d Answers'),
'%s DIFF LINK(S)' => array('DIFF LINK', 'DIFF LINKS'),
'You successfully created %d diff(s).' => array(
'You successfully created %d diff.',