mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-27 09:12:41 +01:00
Make Ponder use ApplicationTransaction rendering for answers
Summary: Ref T3373. This breaks some stuff, but future diffs will fix it. Test Plan: Viewed some questions, saw answer text. Reviewers: btrahan Reviewed By: btrahan CC: aran, chad Maniphest Tasks: T3373 Differential Revision: https://secure.phabricator.com/D6604
This commit is contained in:
parent
8fa5944768
commit
61e7043664
3 changed files with 122 additions and 30 deletions
|
@ -1877,6 +1877,7 @@ phutil_register_library_map(array(
|
||||||
'PonderAnswerSaveController' => 'applications/ponder/controller/PonderAnswerSaveController.php',
|
'PonderAnswerSaveController' => 'applications/ponder/controller/PonderAnswerSaveController.php',
|
||||||
'PonderAnswerTransaction' => 'applications/ponder/storage/PonderAnswerTransaction.php',
|
'PonderAnswerTransaction' => 'applications/ponder/storage/PonderAnswerTransaction.php',
|
||||||
'PonderAnswerTransactionComment' => 'applications/ponder/storage/PonderAnswerTransactionComment.php',
|
'PonderAnswerTransactionComment' => 'applications/ponder/storage/PonderAnswerTransactionComment.php',
|
||||||
|
'PonderAnswerTransactionQuery' => 'applications/ponder/query/PonderAnswerTransactionQuery.php',
|
||||||
'PonderAnswerViewController' => 'applications/ponder/controller/PonderAnswerViewController.php',
|
'PonderAnswerViewController' => 'applications/ponder/controller/PonderAnswerViewController.php',
|
||||||
'PonderAnsweredMail' => 'applications/ponder/mail/PonderAnsweredMail.php',
|
'PonderAnsweredMail' => 'applications/ponder/mail/PonderAnsweredMail.php',
|
||||||
'PonderComment' => 'applications/ponder/storage/PonderComment.php',
|
'PonderComment' => 'applications/ponder/storage/PonderComment.php',
|
||||||
|
@ -3997,6 +3998,7 @@ phutil_register_library_map(array(
|
||||||
'PonderAnswerSaveController' => 'PonderController',
|
'PonderAnswerSaveController' => 'PonderController',
|
||||||
'PonderAnswerTransaction' => 'PhabricatorApplicationTransaction',
|
'PonderAnswerTransaction' => 'PhabricatorApplicationTransaction',
|
||||||
'PonderAnswerTransactionComment' => 'PhabricatorApplicationTransactionComment',
|
'PonderAnswerTransactionComment' => 'PhabricatorApplicationTransactionComment',
|
||||||
|
'PonderAnswerTransactionQuery' => 'PhabricatorApplicationTransactionQuery',
|
||||||
'PonderAnswerViewController' => 'PonderController',
|
'PonderAnswerViewController' => 'PonderController',
|
||||||
'PonderAnsweredMail' => 'PonderMail',
|
'PonderAnsweredMail' => 'PonderMail',
|
||||||
'PonderComment' =>
|
'PonderComment' =>
|
||||||
|
|
|
@ -16,42 +16,16 @@ final class PonderQuestionViewController extends PonderController {
|
||||||
$question = id(new PonderQuestionQuery())
|
$question = id(new PonderQuestionQuery())
|
||||||
->setViewer($user)
|
->setViewer($user)
|
||||||
->withIDs(array($this->questionID))
|
->withIDs(array($this->questionID))
|
||||||
|
->needAnswers(true)
|
||||||
->executeOne();
|
->executeOne();
|
||||||
if (!$question) {
|
if (!$question) {
|
||||||
return new Aphront404Response();
|
return new Aphront404Response();
|
||||||
}
|
}
|
||||||
$question->attachRelated();
|
|
||||||
$question->attachVotes($user->getPHID());
|
$question->attachVotes($user->getPHID());
|
||||||
$object_phids = array($user->getPHID(), $question->getAuthorPHID());
|
|
||||||
|
|
||||||
$answers = $question->getAnswers();
|
|
||||||
$comments = $question->getComments();
|
|
||||||
foreach ($comments as $comment) {
|
|
||||||
$object_phids[] = $comment->getAuthorPHID();
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach ($answers as $answer) {
|
|
||||||
$object_phids[] = $answer->getAuthorPHID();
|
|
||||||
|
|
||||||
$comments = $answer->getComments();
|
|
||||||
foreach ($comments as $comment) {
|
|
||||||
$object_phids[] = $comment->getAuthorPHID();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$object_phids = array_merge($object_phids);
|
|
||||||
|
|
||||||
$this->loadHandles($object_phids);
|
|
||||||
$handles = $this->getLoadedHandles();
|
|
||||||
|
|
||||||
$question_xactions = $this->buildQuestionTransactions($question);
|
$question_xactions = $this->buildQuestionTransactions($question);
|
||||||
|
$answers = $this->buildAnswers($question->getAnswers());
|
||||||
$responses_panel = new PonderAnswerListView();
|
|
||||||
$responses_panel
|
|
||||||
->setQuestion($question)
|
|
||||||
->setHandles($handles)
|
|
||||||
->setUser($user)
|
|
||||||
->setAnswers($answers);
|
|
||||||
|
|
||||||
$answer_add_panel = new PonderAddAnswerView();
|
$answer_add_panel = new PonderAddAnswerView();
|
||||||
$answer_add_panel
|
$answer_add_panel
|
||||||
|
@ -79,7 +53,7 @@ final class PonderQuestionViewController extends PonderController {
|
||||||
$actions,
|
$actions,
|
||||||
$properties,
|
$properties,
|
||||||
$question_xactions,
|
$question_xactions,
|
||||||
$responses_panel,
|
$answers,
|
||||||
$answer_add_panel
|
$answer_add_panel
|
||||||
),
|
),
|
||||||
array(
|
array(
|
||||||
|
@ -196,4 +170,110 @@ final class PonderQuestionViewController extends PonderController {
|
||||||
return $timeline;
|
return $timeline;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function buildAnswers(array $answers) {
|
||||||
|
$request = $this->getRequest();
|
||||||
|
$viewer = $request->getUser();
|
||||||
|
|
||||||
|
$out = array();
|
||||||
|
|
||||||
|
$phids = mpull($answers, 'getAuthorPHID');
|
||||||
|
$this->loadHandles($phids);
|
||||||
|
|
||||||
|
$xactions = id(new PonderAnswerTransactionQuery())
|
||||||
|
->setViewer($viewer)
|
||||||
|
->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');
|
||||||
|
|
||||||
|
foreach ($answers as $answer) {
|
||||||
|
$author_phid = $answer->getAuthorPHID();
|
||||||
|
$xactions = idx($xaction_groups, $answer->getPHID(), array());
|
||||||
|
|
||||||
|
$out[] = phutil_tag('br');
|
||||||
|
$out[] = phutil_tag('br');
|
||||||
|
$out[] = id(new PhabricatorHeaderView())
|
||||||
|
->setHeader($this->getHandle($author_phid)->getFullName())
|
||||||
|
->setImage($this->getHandle($author_phid)->getImageURI());
|
||||||
|
|
||||||
|
$out[] = $this->buildAnswerActions($answer);
|
||||||
|
$out[] = $this->buildAnswerProperties($answer);
|
||||||
|
$out[] = id(new PhabricatorApplicationTransactionView())
|
||||||
|
->setUser($viewer)
|
||||||
|
->setTransactions($xactions)
|
||||||
|
->setMarkupEngine($engine);
|
||||||
|
|
||||||
|
// TODO: Add comment form
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
$out[] = phutil_tag('br');
|
||||||
|
$out[] = phutil_tag('br');
|
||||||
|
|
||||||
|
return $out;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function buildAnswerActions(PonderAnswer $answer) {
|
||||||
|
$request = $this->getRequest();
|
||||||
|
$viewer = $request->getUser();
|
||||||
|
|
||||||
|
$can_edit = PhabricatorPolicyFilter::hasCapability(
|
||||||
|
$viewer,
|
||||||
|
$answer,
|
||||||
|
PhabricatorPolicyCapability::CAN_EDIT);
|
||||||
|
|
||||||
|
$view = id(new PhabricatorActionListView())
|
||||||
|
->setUser($request->getUser())
|
||||||
|
->setObject($answer)
|
||||||
|
->setObjectURI($request->getRequestURI());
|
||||||
|
|
||||||
|
/*
|
||||||
|
|
||||||
|
TODO
|
||||||
|
|
||||||
|
$view->addAction(
|
||||||
|
id(new PhabricatorActionView())
|
||||||
|
->setIcon('edit')
|
||||||
|
->setName(pht('Edit Answer'))
|
||||||
|
->setHref($this->getApplicationURI("/answer/edit/{$id}/"))
|
||||||
|
->setDisabled(!$can_edit)
|
||||||
|
->setWorkflow(!$can_edit));
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
return $view;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function buildAnswerProperties(PonderAnswer $answer) {
|
||||||
|
$viewer = $this->getRequest()->getUser();
|
||||||
|
$view = id(new PhabricatorPropertyListView())
|
||||||
|
->setUser($viewer)
|
||||||
|
->setObject($answer);
|
||||||
|
|
||||||
|
$view->addProperty(
|
||||||
|
pht('Created'),
|
||||||
|
phabricator_datetime($answer->getDateCreated(), $viewer));
|
||||||
|
|
||||||
|
$view->invokeWillRenderEvent();
|
||||||
|
|
||||||
|
$view->addTextContent(
|
||||||
|
PhabricatorMarkupEngine::renderOneObject(
|
||||||
|
$answer,
|
||||||
|
$answer->getMarkupField(),
|
||||||
|
$viewer));
|
||||||
|
|
||||||
|
return $view;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,10 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
final class PonderAnswerTransactionQuery
|
||||||
|
extends PhabricatorApplicationTransactionQuery {
|
||||||
|
|
||||||
|
protected function getTemplateApplicationTransaction() {
|
||||||
|
return new PonderAnswerTransaction();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in a new issue