diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index c3a7d893b7..acda1020a9 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -3404,6 +3404,7 @@ phutil_register_library_map(array( 'PonderDAO' => 'applications/ponder/storage/PonderDAO.php', 'PonderDefaultViewCapability' => 'applications/ponder/capability/PonderDefaultViewCapability.php', 'PonderEditor' => 'applications/ponder/editor/PonderEditor.php', + 'PonderHelpfulSaveController' => 'applications/ponder/controller/PonderHelpfulSaveController.php', 'PonderModerateCapability' => 'applications/ponder/capability/PonderModerateCapability.php', 'PonderQuestion' => 'applications/ponder/storage/PonderQuestion.php', 'PonderQuestionCommentController' => 'applications/ponder/controller/PonderQuestionCommentController.php', @@ -3429,7 +3430,6 @@ phutil_register_library_map(array( 'PonderVotableInterface' => 'applications/ponder/storage/PonderVotableInterface.php', 'PonderVote' => 'applications/ponder/constants/PonderVote.php', 'PonderVoteEditor' => 'applications/ponder/editor/PonderVoteEditor.php', - 'PonderVoteSaveController' => 'applications/ponder/controller/PonderVoteSaveController.php', 'PonderVotingUserHasAnswerEdgeType' => 'applications/ponder/edge/PonderVotingUserHasAnswerEdgeType.php', 'ProjectAddProjectsEmailCommand' => 'applications/project/command/ProjectAddProjectsEmailCommand.php', 'ProjectBoardTaskCard' => 'applications/project/view/ProjectBoardTaskCard.php', @@ -7590,6 +7590,7 @@ phutil_register_library_map(array( 'PonderDAO' => 'PhabricatorLiskDAO', 'PonderDefaultViewCapability' => 'PhabricatorPolicyCapability', 'PonderEditor' => 'PhabricatorApplicationTransactionEditor', + 'PonderHelpfulSaveController' => 'PonderController', 'PonderModerateCapability' => 'PhabricatorPolicyCapability', 'PonderQuestion' => array( 'PonderDAO', @@ -7625,7 +7626,6 @@ phutil_register_library_map(array( 'PonderTransactionFeedStory' => 'PhabricatorApplicationTransactionFeedStory', 'PonderVote' => 'PonderConstants', 'PonderVoteEditor' => 'PhabricatorEditor', - 'PonderVoteSaveController' => 'PonderController', 'PonderVotingUserHasAnswerEdgeType' => 'PhabricatorEdgeType', 'ProjectAddProjectsEmailCommand' => 'MetaMTAEmailTransactionCommand', 'ProjectBoardTaskCard' => 'Phobject', diff --git a/src/applications/ponder/application/PhabricatorPonderApplication.php b/src/applications/ponder/application/PhabricatorPonderApplication.php index fe1073b85a..c91ba6803c 100644 --- a/src/applications/ponder/application/PhabricatorPonderApplication.php +++ b/src/applications/ponder/application/PhabricatorPonderApplication.php @@ -61,6 +61,8 @@ final class PhabricatorPonderApplication extends PhabricatorApplication { => 'PonderAnswerCommentController', 'answer/history/(?P\d+)/' => 'PonderAnswerHistoryController', + 'answer/helpful/(?Padd|remove)/(?P[1-9]\d*)/' + => 'PonderHelpfulSaveController', 'question/edit/(?:(?P\d+)/)?' => 'PonderQuestionEditController', 'question/create/' @@ -73,7 +75,6 @@ final class PhabricatorPonderApplication extends PhabricatorApplication { => 'PhabricatorMarkupPreviewController', 'question/status/(?P[1-9]\d*)/' => 'PonderQuestionStatusController', - 'vote/' => 'PonderVoteSaveController', ), ); } diff --git a/src/applications/ponder/constants/PonderVote.php b/src/applications/ponder/constants/PonderVote.php index 5ac1efdd3a..c3e9745eec 100644 --- a/src/applications/ponder/constants/PonderVote.php +++ b/src/applications/ponder/constants/PonderVote.php @@ -4,6 +4,5 @@ final class PonderVote extends PonderConstants { const VOTE_UP = 1; const VOTE_NONE = 0; - const VOTE_DOWN = -1; } diff --git a/src/applications/ponder/controller/PonderHelpfulSaveController.php b/src/applications/ponder/controller/PonderHelpfulSaveController.php new file mode 100644 index 0000000000..2345efcb6c --- /dev/null +++ b/src/applications/ponder/controller/PonderHelpfulSaveController.php @@ -0,0 +1,60 @@ +getViewer(); + $id = $request->getURIData('id'); + $action = $request->getURIData('action'); + + $answer = id(new PonderAnswerQuery()) + ->setViewer($viewer) + ->withIDs(array($id)) + ->needViewerVotes(true) + ->executeOne(); + + if (!$answer) { + return new Aphront404Response(); + } + + $edit_uri = '/Q'.$answer->getQuestionID(); + + switch ($action) { + case 'add': + $newvote = PonderVote::VOTE_UP; + break; + case 'remove': + $newvote = PonderVote::VOTE_NONE; + break; + } + + if ($request->isFormPost()) { + + $editor = id(new PonderVoteEditor()) + ->setVotable($answer) + ->setActor($viewer) + ->setVote($newvote) + ->saveVote(); + + return id(new AphrontRedirectResponse())->setURI($edit_uri); + } + + if ($action == 'add') { + $title = pht('Mark Answer as Helpful?'); + $body = pht('This answer will be marked as helpful.'); + $button = pht('Mark Helpful'); + } else { + $title = pht('Remove Helpful From Answer?'); + $body = pht('This answer will no longer be marked as helpful.'); + $button = pht('Remove Helpful'); + } + + $dialog = $this->newDialog(); + $dialog->setTitle($title); + $dialog->appendChild($body); + $dialog->addCancelButton($edit_uri); + $dialog->addSubmitButton($button); + + return id(new AphrontDialogResponse())->setDialog($dialog); + } +} diff --git a/src/applications/ponder/controller/PonderQuestionViewController.php b/src/applications/ponder/controller/PonderQuestionViewController.php index 30c56a0cc4..1fc9c05a0f 100644 --- a/src/applications/ponder/controller/PonderQuestionViewController.php +++ b/src/applications/ponder/controller/PonderQuestionViewController.php @@ -291,6 +291,28 @@ final class PonderQuestionViewController extends PonderController { ->setObject($answer) ->setObjectURI($request->getRequestURI()); + $user_marked = $answer->getUserVote(); + $can_vote = $viewer->isLoggedIn(); + + if ($user_marked) { + $helpful_uri = "/answer/helpful/remove/{$id}/"; + $helpful_icon = 'fa-times'; + $helpful_text = pht('Remove Helpful'); + } else { + $helpful_uri = "/answer/helpful/add/{$id}/"; + $helpful_icon = 'fa-thumbs-up'; + $helpful_text = pht('Mark as Helpful'); + } + + $view->addAction( + id(new PhabricatorActionView()) + ->setIcon($helpful_icon) + ->setName($helpful_text) + ->setHref($this->getApplicationURI($helpful_uri)) + ->setRenderAsForm(true) + ->setDisabled(!$can_vote) + ->setWorkflow($can_vote)); + $view->addAction( id(new PhabricatorActionView()) ->setIcon('fa-pencil') @@ -322,6 +344,10 @@ final class PonderQuestionViewController extends PonderController { pht('Created'), phabricator_datetime($answer->getDateCreated(), $viewer)); + $view->addProperty( + pht('Helpfuls'), + $answer->getVoteCount()); + $view->invokeWillRenderEvent(); $view->addSectionHeader(pht('Answer')); diff --git a/src/applications/ponder/controller/PonderVoteSaveController.php b/src/applications/ponder/controller/PonderVoteSaveController.php deleted file mode 100644 index 12aa4dfb15..0000000000 --- a/src/applications/ponder/controller/PonderVoteSaveController.php +++ /dev/null @@ -1,32 +0,0 @@ -getViewer(); - $phid = $request->getStr('phid'); - $newvote = $request->getInt('vote'); - - if (1 < $newvote || $newvote < -1) { - return new Aphront400Response(); - } - - $target = null; - - $object = id(new PhabricatorObjectQuery()) - ->setViewer($viewer) - ->withPHIDs(array($phid)) - ->executeOne(); - if (!$object) { - return new Aphront404Response(); - } - - $editor = id(new PonderVoteEditor()) - ->setVotable($object) - ->setActor($viewer) - ->setVote($newvote) - ->saveVote(); - - return id(new AphrontAjaxResponse())->setContent(array()); - } -} diff --git a/src/applications/ponder/query/PonderAnswerQuery.php b/src/applications/ponder/query/PonderAnswerQuery.php index be9c42c5ea..4e874aeb60 100644 --- a/src/applications/ponder/query/PonderAnswerQuery.php +++ b/src/applications/ponder/query/PonderAnswerQuery.php @@ -101,7 +101,6 @@ final class PonderAnswerQuery $edges[$answer->getPHID()][$etype], $viewer_phid, array()); - $answer->attachUserVote($viewer_phid, idx($user_edge, 'data', 0)); } } diff --git a/src/applications/ponder/query/PonderQuestionQuery.php b/src/applications/ponder/query/PonderQuestionQuery.php index b8eae2da81..dd5db40a48 100644 --- a/src/applications/ponder/query/PonderQuestionQuery.php +++ b/src/applications/ponder/query/PonderQuestionQuery.php @@ -98,6 +98,7 @@ final class PonderQuestionQuery $aquery = id(new PonderAnswerQuery()) ->setViewer($this->getViewer()) ->setOrderVector(array('-id')) + ->needViewerVotes(true) ->withQuestionIDs(mpull($questions, 'getID')); $answers = $aquery->execute();