Page MenuHomePhabricator

D13834.id.diff
No OneTemporary

D13834.id.diff

diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php
--- a/src/__phutil_library_map__.php
+++ b/src/__phutil_library_map__.php
@@ -3404,6 +3404,7 @@
'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 @@
'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 @@
'PonderDAO' => 'PhabricatorLiskDAO',
'PonderDefaultViewCapability' => 'PhabricatorPolicyCapability',
'PonderEditor' => 'PhabricatorApplicationTransactionEditor',
+ 'PonderHelpfulSaveController' => 'PonderController',
'PonderModerateCapability' => 'PhabricatorPolicyCapability',
'PonderQuestion' => array(
'PonderDAO',
@@ -7625,7 +7626,6 @@
'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
--- a/src/applications/ponder/application/PhabricatorPonderApplication.php
+++ b/src/applications/ponder/application/PhabricatorPonderApplication.php
@@ -61,6 +61,8 @@
=> 'PonderAnswerCommentController',
'answer/history/(?P<id>\d+)/'
=> 'PonderAnswerHistoryController',
+ 'answer/helpful/(?P<action>add|remove)/(?P<id>[1-9]\d*)/'
+ => 'PonderHelpfulSaveController',
'question/edit/(?:(?P<id>\d+)/)?'
=> 'PonderQuestionEditController',
'question/create/'
@@ -73,7 +75,6 @@
=> 'PhabricatorMarkupPreviewController',
'question/status/(?P<id>[1-9]\d*)/'
=> 'PonderQuestionStatusController',
- 'vote/' => 'PonderVoteSaveController',
),
);
}
diff --git a/src/applications/ponder/constants/PonderVote.php b/src/applications/ponder/constants/PonderVote.php
--- a/src/applications/ponder/constants/PonderVote.php
+++ b/src/applications/ponder/constants/PonderVote.php
@@ -4,6 +4,5 @@
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
--- /dev/null
+++ b/src/applications/ponder/controller/PonderHelpfulSaveController.php
@@ -0,0 +1,60 @@
+<?php
+
+final class PonderHelpfulSaveController extends PonderController {
+
+ public function handleRequest(AphrontRequest $request) {
+ $viewer = $request->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
--- a/src/applications/ponder/controller/PonderQuestionViewController.php
+++ b/src/applications/ponder/controller/PonderQuestionViewController.php
@@ -291,6 +291,28 @@
->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 @@
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
--- a/src/applications/ponder/controller/PonderVoteSaveController.php
+++ /dev/null
@@ -1,32 +0,0 @@
-<?php
-
-final class PonderVoteSaveController extends PonderController {
-
- public function handleRequest(AphrontRequest $request) {
- $viewer = $request->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
--- a/src/applications/ponder/query/PonderAnswerQuery.php
+++ b/src/applications/ponder/query/PonderAnswerQuery.php
@@ -101,7 +101,6 @@
$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
--- a/src/applications/ponder/query/PonderQuestionQuery.php
+++ b/src/applications/ponder/query/PonderQuestionQuery.php
@@ -98,6 +98,7 @@
$aquery = id(new PonderAnswerQuery())
->setViewer($this->getViewer())
->setOrderVector(array('-id'))
+ ->needViewerVotes(true)
->withQuestionIDs(mpull($questions, 'getID'));
$answers = $aquery->execute();

File Metadata

Mime Type
text/plain
Expires
Sun, May 19, 12:40 PM (4 w, 5 h ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
6302243
Default Alt Text
D13834.id.diff (8 KB)

Event Timeline