1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-28 17:52:43 +01:00
phorge-phorge/src/applications/ponder/query/PonderQuestionSearchEngine.php

179 lines
4.9 KiB
PHP
Raw Normal View History

<?php
final class PonderQuestionSearchEngine
extends PhabricatorApplicationSearchEngine {
public function getResultTypeDescription() {
return pht('Ponder Questions');
}
public function getApplicationClassName() {
return 'PhabricatorPonderApplication';
}
public function buildSavedQueryFromRequest(AphrontRequest $request) {
$saved = new PhabricatorSavedQuery();
$saved->setParameter(
'authorPHIDs',
$this->readUsersFromRequest($request, 'authors'));
$saved->setParameter(
'answererPHIDs',
$this->readUsersFromRequest($request, 'answerers'));
$saved->setParameter('status', $request->getStr('status'));
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);
}
$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;
}
}
return $query;
}
public function buildSearchForm(
AphrontFormView $form,
PhabricatorSavedQuery $saved_query) {
$author_phids = $saved_query->getParameter('authorPHIDs', array());
$answerer_phids = $saved_query->getParameter('answererPHIDs', array());
$status = $saved_query->getParameter(
'status', PonderQuestionStatus::STATUS_OPEN);
$phids = array_merge($author_phids, $answerer_phids);
$handles = id(new PhabricatorHandleQuery())
->setViewer($this->requireViewer())
->withPHIDs($phids)
->execute();
$form
->appendChild(
id(new AphrontFormTokenizerControl())
Modernize "users" typeahead datasource Summary: Ref T4420. Modernize users. Test Plan: - Edited "Commit Authors" on Audit search. - Edited "Created By" on calendar search. - Edited "invited" on calendar search. - Edited "To" on "New conpherence message". - Edited user on "Add user to conpherence thread". - Edited "Authors" on countdown search. - Edited "Author" on differential search. - Edited "Responsible users" on differential search. - Edited "Owner" on Diffusion lint search. - Edited "include users" on Feed search. - Edited "Authors" on file search. - Edited "Authors" on Herald rule search. - Edited a couple of user-selecting Herald fields on rules. - Edited "user" on legalpad signature exemption. - Edited "creator" on legalpad search. - Edited "contributors" on legalpad search. - Edited "signers" on legalpad signature search. - Edited "Authors" on macro search. - Edited "Reassign/claim" on task detail. - Edited "assigned to" on task edit. - Edited "assigned to", "users projects", "authors" on task search. - Edited "creators" on oauthserver. - Edited "authors" on paste search. - Edited "actors" and "users" on activity log search. - Edited "authors" on pholio search. - Edited "users" on phrequent search. - Edited "authors", "answered by" on Ponder search. - Edited "add members" on project membership editor. - Edited "members" on project search. - Edited "pushers" on releeph product edit. - Edited "requestors" on releeph request search. - Edited "pushers" on diffusion push log. - Edited "authors", "owners", "subscribers" on global search. - Edited "authors" on slowvote search. - Edited users in custom policy. - Grepped for "common/authors", no hits. - Grepped for "common/users", no (relevant) hits. - Grepped for "common/accounts", no (relevant) hits. Reviewers: btrahan Reviewed By: btrahan Subscribers: epriestley Maniphest Tasks: T4420 Differential Revision: https://secure.phabricator.com/D9885
2014-07-18 00:44:18 +02:00
->setDatasource(new PhabricatorPeopleDatasource())
->setName('authors')
->setLabel(pht('Authors'))
->setValue(array_select_keys($handles, $author_phids)))
->appendChild(
id(new AphrontFormTokenizerControl())
Modernize "users" typeahead datasource Summary: Ref T4420. Modernize users. Test Plan: - Edited "Commit Authors" on Audit search. - Edited "Created By" on calendar search. - Edited "invited" on calendar search. - Edited "To" on "New conpherence message". - Edited user on "Add user to conpherence thread". - Edited "Authors" on countdown search. - Edited "Author" on differential search. - Edited "Responsible users" on differential search. - Edited "Owner" on Diffusion lint search. - Edited "include users" on Feed search. - Edited "Authors" on file search. - Edited "Authors" on Herald rule search. - Edited a couple of user-selecting Herald fields on rules. - Edited "user" on legalpad signature exemption. - Edited "creator" on legalpad search. - Edited "contributors" on legalpad search. - Edited "signers" on legalpad signature search. - Edited "Authors" on macro search. - Edited "Reassign/claim" on task detail. - Edited "assigned to" on task edit. - Edited "assigned to", "users projects", "authors" on task search. - Edited "creators" on oauthserver. - Edited "authors" on paste search. - Edited "actors" and "users" on activity log search. - Edited "authors" on pholio search. - Edited "users" on phrequent search. - Edited "authors", "answered by" on Ponder search. - Edited "add members" on project membership editor. - Edited "members" on project search. - Edited "pushers" on releeph product edit. - Edited "requestors" on releeph request search. - Edited "pushers" on diffusion push log. - Edited "authors", "owners", "subscribers" on global search. - Edited "authors" on slowvote search. - Edited users in custom policy. - Grepped for "common/authors", no hits. - Grepped for "common/users", no (relevant) hits. - Grepped for "common/accounts", no (relevant) hits. Reviewers: btrahan Reviewed By: btrahan Subscribers: epriestley Maniphest Tasks: T4420 Differential Revision: https://secure.phabricator.com/D9885
2014-07-18 00:44:18 +02:00
->setDatasource(new PhabricatorPeopleDatasource())
->setName('answerers')
->setLabel(pht('Answered By'))
->setValue(array_select_keys($handles, $answerer_phids)))
->appendChild(
id(new AphrontFormSelectControl())
->setLabel(pht('Status'))
->setName('status')
->setValue($status)
->setOptions(PonderQuestionStatus::getQuestionStatusMap()));
}
protected function getURI($path) {
return '/ponder/'.$path;
}
protected function getBuiltinQueryNames() {
$names = array(
'open' => pht('Open Questions'),
'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;
case 'open':
return $query->setParameter('status', PonderQuestionQuery::STATUS_OPEN);
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);
}
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) {
$item = new PHUIObjectItemView();
$item->setObjectName('Q'.$question->getID());
$item->setHeader($question->getTitle());
$item->setHref('/Q'.$question->getID());
$item->setObject($question);
$item->setBarColor(
PonderQuestionStatus::getQuestionStatusTagColor(
$question->getStatus()));
$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);
}
return $view;
}
}