2012-08-10 10:44:04 -07:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
final class PonderQuestionViewController extends PonderController {
|
|
|
|
|
|
2015-07-22 13:23:11 -07:00
|
|
|
public function handleRequest(AphrontRequest $request) {
|
2015-08-05 09:42:39 -07:00
|
|
|
$viewer = $request->getViewer();
|
2015-07-22 13:23:11 -07:00
|
|
|
$id = $request->getURIData('id');
|
2012-08-10 10:44:04 -07:00
|
|
|
|
2013-07-28 15:38:47 -07:00
|
|
|
$question = id(new PonderQuestionQuery())
|
2015-08-05 09:42:39 -07:00
|
|
|
->setViewer($viewer)
|
2015-07-22 13:23:11 -07:00
|
|
|
->withIDs(array($id))
|
2013-07-28 16:17:51 -07:00
|
|
|
->needAnswers(true)
|
2015-08-10 14:55:43 -07:00
|
|
|
->needProjectPHIDs(true)
|
2013-07-28 15:38:47 -07:00
|
|
|
->executeOne();
|
2012-08-10 10:44:04 -07:00
|
|
|
if (!$question) {
|
|
|
|
|
return new Aphront404Response();
|
|
|
|
|
}
|
|
|
|
|
|
2013-07-28 16:17:51 -07:00
|
|
|
$answers = $this->buildAnswers($question->getAnswers());
|
2012-08-10 10:44:04 -07:00
|
|
|
|
2015-08-12 07:56:31 -07:00
|
|
|
$answer_add_panel = id(new PonderAddAnswerView())
|
|
|
|
|
->setQuestion($question)
|
|
|
|
|
->setUser($viewer)
|
|
|
|
|
->setActionURI('/ponder/answer/add/');
|
2012-08-10 10:44:04 -07:00
|
|
|
|
2015-08-05 09:42:39 -07:00
|
|
|
$header = new PHUIHeaderView();
|
|
|
|
|
$header->setHeader($question->getTitle());
|
|
|
|
|
$header->setUser($viewer);
|
|
|
|
|
$header->setPolicyObject($question);
|
2012-10-05 13:12:31 -07:00
|
|
|
|
2015-01-06 11:13:04 -08:00
|
|
|
if ($question->getStatus() == PonderQuestionStatus::STATUS_OPEN) {
|
|
|
|
|
$header->setStatus('fa-square-o', 'bluegrey', pht('Open'));
|
|
|
|
|
} else {
|
2015-08-08 10:23:33 -07:00
|
|
|
$text = PonderQuestionStatus::getQuestionStatusFullName(
|
|
|
|
|
$question->getStatus());
|
|
|
|
|
$icon = PonderQuestionStatus::getQuestionStatusIcon(
|
|
|
|
|
$question->getStatus());
|
|
|
|
|
$header->setStatus($icon, 'dark', $text);
|
2015-01-06 11:13:04 -08:00
|
|
|
}
|
|
|
|
|
|
2012-10-05 13:12:31 -07:00
|
|
|
$actions = $this->buildActionListView($question);
|
2013-10-11 07:53:56 -07:00
|
|
|
$properties = $this->buildPropertyListView($question, $actions);
|
2015-08-10 14:55:43 -07:00
|
|
|
$sidebar = $this->buildSidebar($question);
|
2012-10-05 13:12:31 -07:00
|
|
|
|
2015-08-11 10:42:40 -07:00
|
|
|
$content_id = celerity_generate_unique_node_id();
|
|
|
|
|
$timeline = $this->buildTransactionTimeline(
|
|
|
|
|
$question,
|
|
|
|
|
id(new PonderQuestionTransactionQuery())
|
|
|
|
|
->withTransactionTypes(array(PhabricatorTransactions::TYPE_COMMENT)));
|
|
|
|
|
$xactions = $timeline->getTransactions();
|
|
|
|
|
|
|
|
|
|
$add_comment = id(new PhabricatorApplicationTransactionCommentView())
|
|
|
|
|
->setUser($viewer)
|
|
|
|
|
->setObjectPHID($question->getPHID())
|
|
|
|
|
->setShowPreview(false)
|
|
|
|
|
->setHeaderText(pht('Question Comment'))
|
|
|
|
|
->setAction($this->getApplicationURI("/question/comment/{$id}/"))
|
|
|
|
|
->setSubmitButtonName(pht('Comment'));
|
|
|
|
|
|
|
|
|
|
$comment_view = phutil_tag(
|
|
|
|
|
'div',
|
|
|
|
|
array(
|
|
|
|
|
'id' => $content_id,
|
|
|
|
|
'style' => 'display: none;',
|
|
|
|
|
),
|
|
|
|
|
array(
|
|
|
|
|
$timeline,
|
|
|
|
|
$add_comment,
|
|
|
|
|
));
|
|
|
|
|
|
|
|
|
|
$footer = id(new PonderFooterView())
|
|
|
|
|
->setContentID($content_id)
|
|
|
|
|
->setCount(count($xactions));
|
|
|
|
|
|
2013-09-28 15:55:38 -07:00
|
|
|
$object_box = id(new PHUIObjectBoxView())
|
|
|
|
|
->setHeader($header)
|
2015-08-11 10:42:40 -07:00
|
|
|
->addPropertyList($properties)
|
|
|
|
|
->appendChild($footer);
|
2013-09-28 15:55:38 -07:00
|
|
|
|
2013-04-10 13:08:36 -07:00
|
|
|
$crumbs = $this->buildApplicationCrumbs($this->buildSideNavView());
|
2015-07-22 13:23:11 -07:00
|
|
|
$crumbs->addTextCrumb('Q'.$id, '/Q'.$id);
|
2013-04-10 13:08:36 -07:00
|
|
|
|
2015-08-10 14:55:43 -07:00
|
|
|
$ponder_view = id(new PHUITwoColumnView())
|
|
|
|
|
->setMainColumn(array(
|
|
|
|
|
$object_box,
|
2015-08-11 10:42:40 -07:00
|
|
|
$comment_view,
|
2015-08-10 14:55:43 -07:00
|
|
|
$answers,
|
|
|
|
|
$answer_add_panel,
|
|
|
|
|
))
|
|
|
|
|
->setSideColumn($sidebar)
|
|
|
|
|
->addClass('ponder-question-view');
|
2015-08-05 09:42:39 -07:00
|
|
|
|
|
|
|
|
return $this->buildApplicationPage(
|
|
|
|
|
array(
|
2015-08-10 14:55:43 -07:00
|
|
|
$crumbs,
|
2015-08-05 09:42:39 -07:00
|
|
|
$ponder_view,
|
2013-07-18 12:40:51 -07:00
|
|
|
),
|
2012-08-10 10:44:04 -07:00
|
|
|
array(
|
2013-05-20 07:55:23 -07:00
|
|
|
'title' => 'Q'.$question->getID().' '.$question->getTitle(),
|
2014-01-10 10:19:00 -08:00
|
|
|
'pageObjects' => array_merge(
|
|
|
|
|
array($question->getPHID()),
|
|
|
|
|
mpull($question->getAnswers(), 'getPHID')),
|
2012-08-10 10:44:04 -07:00
|
|
|
));
|
|
|
|
|
}
|
2012-10-05 13:12:31 -07:00
|
|
|
|
|
|
|
|
private function buildActionListView(PonderQuestion $question) {
|
2015-08-05 09:42:39 -07:00
|
|
|
$viewer = $this->getViewer();
|
2013-07-12 11:39:47 -07:00
|
|
|
$request = $this->getRequest();
|
2013-07-28 15:02:18 -07:00
|
|
|
$id = $question->getID();
|
|
|
|
|
|
|
|
|
|
$can_edit = PhabricatorPolicyFilter::hasCapability(
|
|
|
|
|
$viewer,
|
|
|
|
|
$question,
|
|
|
|
|
PhabricatorPolicyCapability::CAN_EDIT);
|
|
|
|
|
|
|
|
|
|
$view = id(new PhabricatorActionListView())
|
2015-08-05 09:42:39 -07:00
|
|
|
->setUser($viewer)
|
2013-07-12 11:39:47 -07:00
|
|
|
->setObject($question)
|
|
|
|
|
->setObjectURI($request->getRequestURI());
|
2013-07-27 18:37:17 -07:00
|
|
|
|
2013-07-28 15:02:18 -07:00
|
|
|
$view->addAction(
|
|
|
|
|
id(new PhabricatorActionView())
|
2014-05-12 10:08:32 -07:00
|
|
|
->setIcon('fa-pencil')
|
2013-07-28 15:02:18 -07:00
|
|
|
->setName(pht('Edit Question'))
|
|
|
|
|
->setHref($this->getApplicationURI("/question/edit/{$id}/"))
|
|
|
|
|
->setDisabled(!$can_edit)
|
|
|
|
|
->setWorkflow(!$can_edit));
|
|
|
|
|
|
|
|
|
|
if ($question->getStatus() == PonderQuestionStatus::STATUS_OPEN) {
|
2014-05-12 10:08:32 -07:00
|
|
|
$name = pht('Close Question');
|
2015-01-06 11:13:04 -08:00
|
|
|
$icon = 'fa-check-square-o';
|
2013-07-28 15:02:18 -07:00
|
|
|
} else {
|
2014-05-12 10:08:32 -07:00
|
|
|
$name = pht('Reopen Question');
|
2015-01-06 11:13:04 -08:00
|
|
|
$icon = 'fa-square-o';
|
2013-07-27 18:37:17 -07:00
|
|
|
}
|
|
|
|
|
|
2013-07-28 15:02:18 -07:00
|
|
|
$view->addAction(
|
|
|
|
|
id(new PhabricatorActionView())
|
|
|
|
|
->setName($name)
|
|
|
|
|
->setIcon($icon)
|
2015-08-08 10:23:33 -07:00
|
|
|
->setWorkflow(true)
|
2013-07-28 15:02:18 -07:00
|
|
|
->setDisabled(!$can_edit)
|
2015-08-08 10:23:33 -07:00
|
|
|
->setHref($this->getApplicationURI("/question/status/{$id}/")));
|
2013-07-28 15:02:18 -07:00
|
|
|
|
2013-07-28 18:32:55 -07:00
|
|
|
$view->addAction(
|
|
|
|
|
id(new PhabricatorActionView())
|
2014-05-12 10:08:32 -07:00
|
|
|
->setIcon('fa-list')
|
2013-07-28 18:32:55 -07:00
|
|
|
->setName(pht('View History'))
|
|
|
|
|
->setHref($this->getApplicationURI("/question/history/{$id}/")));
|
|
|
|
|
|
2013-07-28 15:02:18 -07:00
|
|
|
return $view;
|
2012-10-05 13:12:31 -07:00
|
|
|
}
|
|
|
|
|
|
2012-10-08 14:47:21 -07:00
|
|
|
private function buildPropertyListView(
|
2013-10-11 07:53:56 -07:00
|
|
|
PonderQuestion $question,
|
|
|
|
|
PhabricatorActionListView $actions) {
|
2012-10-08 14:47:21 -07:00
|
|
|
|
2015-08-05 09:42:39 -07:00
|
|
|
$viewer = $this->getViewer();
|
2013-10-11 07:53:56 -07:00
|
|
|
$view = id(new PHUIPropertyListView())
|
2013-05-09 14:40:43 -07:00
|
|
|
->setUser($viewer)
|
2013-10-11 07:53:56 -07:00
|
|
|
->setObject($question)
|
|
|
|
|
->setActionList($actions);
|
2013-07-27 18:37:17 -07:00
|
|
|
|
2012-10-05 13:12:31 -07:00
|
|
|
$view->addProperty(
|
|
|
|
|
pht('Author'),
|
2015-03-30 07:55:33 -07:00
|
|
|
$viewer->renderHandle($question->getAuthorPHID()));
|
2012-10-05 13:12:31 -07:00
|
|
|
|
|
|
|
|
$view->addProperty(
|
|
|
|
|
pht('Created'),
|
|
|
|
|
phabricator_datetime($question->getDateCreated(), $viewer));
|
|
|
|
|
|
2013-07-28 15:02:18 -07:00
|
|
|
$view->invokeWillRenderEvent();
|
|
|
|
|
|
2015-08-14 09:51:52 -07:00
|
|
|
$details = PhabricatorMarkupEngine::renderOneObject(
|
2013-07-30 15:50:27 -07:00
|
|
|
$question,
|
|
|
|
|
$question->getMarkupField(),
|
2015-08-14 09:51:52 -07:00
|
|
|
$viewer);
|
2013-07-28 15:02:18 -07:00
|
|
|
|
2015-08-14 09:51:52 -07:00
|
|
|
if ($details) {
|
|
|
|
|
$view->addSectionHeader(
|
|
|
|
|
pht('Details'),
|
|
|
|
|
PHUIPropertyListView::ICON_SUMMARY);
|
|
|
|
|
|
|
|
|
|
$view->addTextContent(
|
|
|
|
|
array(
|
|
|
|
|
phutil_tag(
|
|
|
|
|
'div',
|
|
|
|
|
array(
|
|
|
|
|
'class' => 'phabricator-remarkup',
|
|
|
|
|
),
|
|
|
|
|
$details),
|
|
|
|
|
));
|
|
|
|
|
}
|
2013-07-28 15:02:18 -07:00
|
|
|
|
2012-10-05 13:12:31 -07:00
|
|
|
return $view;
|
|
|
|
|
}
|
2013-07-28 15:02:18 -07:00
|
|
|
|
Transactions - deploy buildTransactionTimeline to remaining applications
Summary:
Ref T4712. Specifically...
- Differential
- needed getApplicationTransactionViewObject() implemented
- Audit
- needed getApplicationTransactionViewObject() implemented
- Repository
- one object needed PhabricatorApplicationTransactionInterface implemented
- setShouldTerminate(true)
- Ponder
- BONUS BUG FIX - leaving a comment on an answer had a bad redirect URI
- both PonderQuestion and PonderAnswer needed PhabricatorApplicationTransactionInterface implemented
- setShouldTerminate(true) on both "history" controllers
- left a "TODO" on buildAnswers on the question view controller, which is non-standard and should be re-written eventually
- Phortune
- BONUS BUG FIX - fix new user "createNewAccount" code to not fatal
- PhortuneAccount, PhortuneMerchant, and PhortuneCart needed PhabricatorApplicationTransactionInterface implemented
- setShouldTerminate(true) on Account view, merchant view, and cart view controller
- Fund
- Legalpad
- Nuance
- NuanceSource needed PhabricatorApplicationTransactionInterface implemented
- Releeph (this product is kind of a mess...)
- HACKQUEST - had to manually create an arcanist project to even be able to make a "product" and get started...!
- BONUS BUG FIX - make sure to "setName" on product edit
- ReleephProject (should be ReleepProduct...?), ReleephBranch, and ReleepRequest needed PhabricatorApplicationTransactionInterface implemented
- Harbormaster
- HarbormasterBuildable, HarbormasterBuild, HarbormasterBuildPlan, and HarbormasterBuildStep all needed PhabricatorApplicationTransactionInterface implemented
- setShouldTerminate(true) all over the place
Test Plan: foreach application, viewed the timeline(s) and made sure they still rendered
Reviewers: epriestley
Reviewed By: epriestley
Subscribers: Korvin, epriestley
Maniphest Tasks: T4712
Differential Revision: https://secure.phabricator.com/D10925
2014-12-03 15:35:47 -08:00
|
|
|
/**
|
|
|
|
|
* This is fairly non-standard; building N timelines at once (N = number of
|
|
|
|
|
* answers) is tricky business.
|
|
|
|
|
*
|
|
|
|
|
* TODO - re-factor this to ajax in one answer panel at a time in a more
|
|
|
|
|
* standard fashion. This is necessary to scale this application.
|
|
|
|
|
*/
|
2013-07-28 16:17:51 -07:00
|
|
|
private function buildAnswers(array $answers) {
|
2015-08-05 09:42:39 -07:00
|
|
|
$viewer = $this->getViewer();
|
2013-07-28 16:17:51 -07:00
|
|
|
|
|
|
|
|
$xactions = id(new PonderAnswerTransactionQuery())
|
|
|
|
|
->setViewer($viewer)
|
2013-07-28 18:32:55 -07:00
|
|
|
->withTransactionTypes(array(PhabricatorTransactions::TYPE_COMMENT))
|
2013-07-28 16:17:51 -07:00
|
|
|
->withObjectPHIDs(mpull($answers, 'getPHID'))
|
|
|
|
|
->execute();
|
|
|
|
|
|
|
|
|
|
$engine = id(new PhabricatorMarkupEngine())
|
|
|
|
|
->setViewer($viewer);
|
|
|
|
|
foreach ($xactions as $xaction) {
|
|
|
|
|
if ($xaction->getComment()) {
|
|
|
|
|
$engine->addObject(
|
|
|
|
|
$xaction->getComment(),
|
|
|
|
|
PhabricatorApplicationTransactionComment::MARKUP_FIELD_COMMENT);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
$engine->process();
|
|
|
|
|
|
|
|
|
|
$xaction_groups = mgroup($xactions, 'getObjectPHID');
|
2015-08-15 10:55:38 -07:00
|
|
|
$author_phids = mpull($answers, 'getAuthorPHID');
|
|
|
|
|
$handles = $this->loadViewerHandles($author_phids);
|
2013-07-28 16:17:51 -07:00
|
|
|
|
2015-08-11 10:42:40 -07:00
|
|
|
$view = array();
|
2013-07-28 16:17:51 -07:00
|
|
|
foreach ($answers as $answer) {
|
|
|
|
|
$xactions = idx($xaction_groups, $answer->getPHID(), array());
|
2013-07-28 17:40:11 -07:00
|
|
|
$id = $answer->getID();
|
2015-08-15 10:55:38 -07:00
|
|
|
$handle = $handles[$answer->getAuthorPHID()];
|
2013-07-28 16:17:51 -07:00
|
|
|
|
2015-08-11 10:42:40 -07:00
|
|
|
$view[] = id(new PonderAnswerView())
|
2013-07-28 16:17:51 -07:00
|
|
|
->setUser($viewer)
|
2015-08-11 10:42:40 -07:00
|
|
|
->setAnswer($answer)
|
2013-07-28 16:17:51 -07:00
|
|
|
->setTransactions($xactions)
|
2015-08-15 10:55:38 -07:00
|
|
|
->setHandle($handle)
|
2013-07-28 16:17:51 -07:00
|
|
|
->setMarkupEngine($engine);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $view;
|
|
|
|
|
}
|
|
|
|
|
|
2015-08-10 14:55:43 -07:00
|
|
|
private function buildSidebar(PonderQuestion $question) {
|
|
|
|
|
$viewer = $this->getViewer();
|
|
|
|
|
$status = $question->getStatus();
|
|
|
|
|
$id = $question->getID();
|
|
|
|
|
|
|
|
|
|
$questions = id(new PonderQuestionQuery())
|
|
|
|
|
->setViewer($viewer)
|
|
|
|
|
->withStatuses(array($status))
|
|
|
|
|
->withEdgeLogicPHIDs(
|
|
|
|
|
PhabricatorProjectObjectHasProjectEdgeType::EDGECONST,
|
|
|
|
|
PhabricatorQueryConstraint::OPERATOR_OR,
|
|
|
|
|
$question->getProjectPHIDs())
|
|
|
|
|
->setLimit(10)
|
|
|
|
|
->execute();
|
|
|
|
|
|
|
|
|
|
$list = id(new PHUIObjectItemListView())
|
|
|
|
|
->setUser($viewer)
|
|
|
|
|
->setNoDataString(pht('No similar questions found.'));
|
|
|
|
|
|
|
|
|
|
foreach ($questions as $question) {
|
|
|
|
|
if ($id == $question->getID()) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
$item = new PHUIObjectItemView();
|
|
|
|
|
$item->setObjectName('Q'.$question->getID());
|
|
|
|
|
$item->setHeader($question->getTitle());
|
|
|
|
|
$item->setHref('/Q'.$question->getID());
|
|
|
|
|
$item->setObject($question);
|
|
|
|
|
|
|
|
|
|
$item->addAttribute(
|
|
|
|
|
pht('%d Answer(s)', $question->getAnswerCount()));
|
|
|
|
|
|
|
|
|
|
$list->addItem($item);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$box = id(new PHUIObjectBoxView())
|
|
|
|
|
->setHeaderText(pht('Similar Questions'))
|
|
|
|
|
->setObjectList($list);
|
|
|
|
|
|
|
|
|
|
return $box;
|
|
|
|
|
}
|
|
|
|
|
|
2012-08-10 10:44:04 -07:00
|
|
|
}
|