@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Add Mark as Helpful to PonderAnswer

Summary: Ref T6920, this adds a basic controller for marking an answer as helpful and removes the negative voting. Any current positive vote is kept as helpful. New UI is needed here, but there is a separate task for redesigning Ponder overall.

Test Plan: Mark an answer as helpful, see count go up, remove helpful, see count go down. Test endpoint manually.

Reviewers: epriestley

Reviewed By: epriestley

Subscribers: Korvin

Maniphest Tasks: T6920

Differential Revision: https://secure.phabricator.com/D13834

+91 -37
+2 -2
src/__phutil_library_map__.php
··· 3404 3404 'PonderDAO' => 'applications/ponder/storage/PonderDAO.php', 3405 3405 'PonderDefaultViewCapability' => 'applications/ponder/capability/PonderDefaultViewCapability.php', 3406 3406 'PonderEditor' => 'applications/ponder/editor/PonderEditor.php', 3407 + 'PonderHelpfulSaveController' => 'applications/ponder/controller/PonderHelpfulSaveController.php', 3407 3408 'PonderModerateCapability' => 'applications/ponder/capability/PonderModerateCapability.php', 3408 3409 'PonderQuestion' => 'applications/ponder/storage/PonderQuestion.php', 3409 3410 'PonderQuestionCommentController' => 'applications/ponder/controller/PonderQuestionCommentController.php', ··· 3429 3430 'PonderVotableInterface' => 'applications/ponder/storage/PonderVotableInterface.php', 3430 3431 'PonderVote' => 'applications/ponder/constants/PonderVote.php', 3431 3432 'PonderVoteEditor' => 'applications/ponder/editor/PonderVoteEditor.php', 3432 - 'PonderVoteSaveController' => 'applications/ponder/controller/PonderVoteSaveController.php', 3433 3433 'PonderVotingUserHasAnswerEdgeType' => 'applications/ponder/edge/PonderVotingUserHasAnswerEdgeType.php', 3434 3434 'ProjectAddProjectsEmailCommand' => 'applications/project/command/ProjectAddProjectsEmailCommand.php', 3435 3435 'ProjectBoardTaskCard' => 'applications/project/view/ProjectBoardTaskCard.php', ··· 7590 7590 'PonderDAO' => 'PhabricatorLiskDAO', 7591 7591 'PonderDefaultViewCapability' => 'PhabricatorPolicyCapability', 7592 7592 'PonderEditor' => 'PhabricatorApplicationTransactionEditor', 7593 + 'PonderHelpfulSaveController' => 'PonderController', 7593 7594 'PonderModerateCapability' => 'PhabricatorPolicyCapability', 7594 7595 'PonderQuestion' => array( 7595 7596 'PonderDAO', ··· 7625 7626 'PonderTransactionFeedStory' => 'PhabricatorApplicationTransactionFeedStory', 7626 7627 'PonderVote' => 'PonderConstants', 7627 7628 'PonderVoteEditor' => 'PhabricatorEditor', 7628 - 'PonderVoteSaveController' => 'PonderController', 7629 7629 'PonderVotingUserHasAnswerEdgeType' => 'PhabricatorEdgeType', 7630 7630 'ProjectAddProjectsEmailCommand' => 'MetaMTAEmailTransactionCommand', 7631 7631 'ProjectBoardTaskCard' => 'Phobject',
+2 -1
src/applications/ponder/application/PhabricatorPonderApplication.php
··· 61 61 => 'PonderAnswerCommentController', 62 62 'answer/history/(?P<id>\d+)/' 63 63 => 'PonderAnswerHistoryController', 64 + 'answer/helpful/(?P<action>add|remove)/(?P<id>[1-9]\d*)/' 65 + => 'PonderHelpfulSaveController', 64 66 'question/edit/(?:(?P<id>\d+)/)?' 65 67 => 'PonderQuestionEditController', 66 68 'question/create/' ··· 73 75 => 'PhabricatorMarkupPreviewController', 74 76 'question/status/(?P<id>[1-9]\d*)/' 75 77 => 'PonderQuestionStatusController', 76 - 'vote/' => 'PonderVoteSaveController', 77 78 ), 78 79 ); 79 80 }
-1
src/applications/ponder/constants/PonderVote.php
··· 4 4 5 5 const VOTE_UP = 1; 6 6 const VOTE_NONE = 0; 7 - const VOTE_DOWN = -1; 8 7 9 8 }
+60
src/applications/ponder/controller/PonderHelpfulSaveController.php
··· 1 + <?php 2 + 3 + final class PonderHelpfulSaveController extends PonderController { 4 + 5 + public function handleRequest(AphrontRequest $request) { 6 + $viewer = $request->getViewer(); 7 + $id = $request->getURIData('id'); 8 + $action = $request->getURIData('action'); 9 + 10 + $answer = id(new PonderAnswerQuery()) 11 + ->setViewer($viewer) 12 + ->withIDs(array($id)) 13 + ->needViewerVotes(true) 14 + ->executeOne(); 15 + 16 + if (!$answer) { 17 + return new Aphront404Response(); 18 + } 19 + 20 + $edit_uri = '/Q'.$answer->getQuestionID(); 21 + 22 + switch ($action) { 23 + case 'add': 24 + $newvote = PonderVote::VOTE_UP; 25 + break; 26 + case 'remove': 27 + $newvote = PonderVote::VOTE_NONE; 28 + break; 29 + } 30 + 31 + if ($request->isFormPost()) { 32 + 33 + $editor = id(new PonderVoteEditor()) 34 + ->setVotable($answer) 35 + ->setActor($viewer) 36 + ->setVote($newvote) 37 + ->saveVote(); 38 + 39 + return id(new AphrontRedirectResponse())->setURI($edit_uri); 40 + } 41 + 42 + if ($action == 'add') { 43 + $title = pht('Mark Answer as Helpful?'); 44 + $body = pht('This answer will be marked as helpful.'); 45 + $button = pht('Mark Helpful'); 46 + } else { 47 + $title = pht('Remove Helpful From Answer?'); 48 + $body = pht('This answer will no longer be marked as helpful.'); 49 + $button = pht('Remove Helpful'); 50 + } 51 + 52 + $dialog = $this->newDialog(); 53 + $dialog->setTitle($title); 54 + $dialog->appendChild($body); 55 + $dialog->addCancelButton($edit_uri); 56 + $dialog->addSubmitButton($button); 57 + 58 + return id(new AphrontDialogResponse())->setDialog($dialog); 59 + } 60 + }
+26
src/applications/ponder/controller/PonderQuestionViewController.php
··· 291 291 ->setObject($answer) 292 292 ->setObjectURI($request->getRequestURI()); 293 293 294 + $user_marked = $answer->getUserVote(); 295 + $can_vote = $viewer->isLoggedIn(); 296 + 297 + if ($user_marked) { 298 + $helpful_uri = "/answer/helpful/remove/{$id}/"; 299 + $helpful_icon = 'fa-times'; 300 + $helpful_text = pht('Remove Helpful'); 301 + } else { 302 + $helpful_uri = "/answer/helpful/add/{$id}/"; 303 + $helpful_icon = 'fa-thumbs-up'; 304 + $helpful_text = pht('Mark as Helpful'); 305 + } 306 + 307 + $view->addAction( 308 + id(new PhabricatorActionView()) 309 + ->setIcon($helpful_icon) 310 + ->setName($helpful_text) 311 + ->setHref($this->getApplicationURI($helpful_uri)) 312 + ->setRenderAsForm(true) 313 + ->setDisabled(!$can_vote) 314 + ->setWorkflow($can_vote)); 315 + 294 316 $view->addAction( 295 317 id(new PhabricatorActionView()) 296 318 ->setIcon('fa-pencil') ··· 321 343 $view->addProperty( 322 344 pht('Created'), 323 345 phabricator_datetime($answer->getDateCreated(), $viewer)); 346 + 347 + $view->addProperty( 348 + pht('Helpfuls'), 349 + $answer->getVoteCount()); 324 350 325 351 $view->invokeWillRenderEvent(); 326 352
-32
src/applications/ponder/controller/PonderVoteSaveController.php
··· 1 - <?php 2 - 3 - final class PonderVoteSaveController extends PonderController { 4 - 5 - public function handleRequest(AphrontRequest $request) { 6 - $viewer = $request->getViewer(); 7 - $phid = $request->getStr('phid'); 8 - $newvote = $request->getInt('vote'); 9 - 10 - if (1 < $newvote || $newvote < -1) { 11 - return new Aphront400Response(); 12 - } 13 - 14 - $target = null; 15 - 16 - $object = id(new PhabricatorObjectQuery()) 17 - ->setViewer($viewer) 18 - ->withPHIDs(array($phid)) 19 - ->executeOne(); 20 - if (!$object) { 21 - return new Aphront404Response(); 22 - } 23 - 24 - $editor = id(new PonderVoteEditor()) 25 - ->setVotable($object) 26 - ->setActor($viewer) 27 - ->setVote($newvote) 28 - ->saveVote(); 29 - 30 - return id(new AphrontAjaxResponse())->setContent(array()); 31 - } 32 - }
-1
src/applications/ponder/query/PonderAnswerQuery.php
··· 101 101 $edges[$answer->getPHID()][$etype], 102 102 $viewer_phid, 103 103 array()); 104 - 105 104 $answer->attachUserVote($viewer_phid, idx($user_edge, 'data', 0)); 106 105 } 107 106 }
+1
src/applications/ponder/query/PonderQuestionQuery.php
··· 98 98 $aquery = id(new PonderAnswerQuery()) 99 99 ->setViewer($this->getViewer()) 100 100 ->setOrderVector(array('-id')) 101 + ->needViewerVotes(true) 101 102 ->withQuestionIDs(mpull($questions, 'getID')); 102 103 103 104 $answers = $aquery->execute();